Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script API: get DrawingSurface for the room masks #1031

Merged

Conversation

ivan-mogilko
Copy link
Contributor

For #480.

This is a minor addition, but may have numerous practical uses.
There's already a DrawingSurface interface, and room areas - walkable areas, hotspots, regions and walk-behinds - are represented as 8-bit bitmap masks, so it's trivial to connect these.

The 4 new script functions allow to get corresponding room mask as a DrawingSurface, and do with it whatever a game developer wants.
Surfaces will be 8-bit, and each color index corresponds to an area ID. Color index = 0 is "no area", or eraser.
There are necessary safety tests in the engine to make sure that indexes beyond supported area limit are simply ignored (treated as "no area").

For example, following script will expand walkable area 1:

DrawingSurface* ds = GetDrawingSurfaceForWalkableArea();
ds.DrawingColor = 1; // drawing color = area ID
ds.DrawRectangle(100, 100, 200, 200);
ds.Release();

Changes made this way are not saved between room visit, which is in line with drawing upon a room background (this was done to prevent save data bloat). If user wants these changes to persist, the usual approach is to save custom data, and use it as an instruction, performing drawing on room load event.

This allows for the game dev to draw upon room masks in script. Room masks are 8-bit bitmaps, and each color index corresponds to an area ID. Drawing pixels of color index N will correspond in expanding an area N. Color index 0 is "no area", or "eraser".
Added tests for pixel color index being higher than the supported area ID limit.
Reduced code by doing necessary checks on lowest function level.

Note: Bitmap::GetPixel() has a safety check on its own that prevents accessing pixels beyond bitmap's bounds, so there's no practical need to test that externally.
@ericoporto
Copy link
Member

OK, I had some fun with this. Click the gif below for full video.
clicking_rts

AGS Project: maskDrawing.zip

I think it works, the only thing I wanted more when drawing was being able to see the other masks like we have the shortcut with Ctrl+A for walkbehinds, which I had to improvise with an overlay, but other than this, it appears to work.

On the video above, the houses are drawn in the background and the walkbehinds are updated, along with the walkable areas. The army of rogers will keep walking randomly, using pathfinder to avoid the non-walkable areas.

@ghost
Copy link
Author

ghost commented Jan 17, 2020

, the only thing I wanted more when drawing was being able to see the other masks like we have the shortcut with Ctrl+A for walkbehinds

There's a related ticket: #724

@ivan-mogilko ivan-mogilko merged commit 7f46d26 into adventuregamestudio:master Jan 18, 2020
@ivan-mogilko ivan-mogilko deleted the dev--drawroommasks branch January 18, 2020 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants