adventuregamestudio / ags

AGS editor and engine source code
Other
701 stars 160 forks source link

Character.PlaceOnWalkableArea does not work at all times #163

Open ghost opened 10 years ago

ghost commented 10 years ago

Character.PlaceOnWalkableArea (obsolete script name: MoveToWalkableArea) script API function is supposed to bring character to nearest walkable area, but sometimes fails.

So far I found this occuring in "Duty and Beyond", room 49.

UPDATE

There are 2 issues with PlaceOnWalkableArea:

When searching for walkable area engine does not check every pixel on the mask, but does so in 5 pixel intervals. For example, "Duty and Beyond" features very thin walkable zones (1 or 2 pixel thick), which makes them susceptible to be overstepped.

Another - undocumented - exception is that PlaceOnWalkableArea ignores walkable areas lying beyond Room Edges. Probably that is because Edges are usually used to define exit zones.

ghost commented 6 years ago

The reason is most probably the fact that when searching for walkable area engine does not check every pixel on the mask, but does so in 5 pixel intervals. "Duty and Beyond" features very thin walkable zones (1 or 2 pixel thick), which makes them suspectible to be overstepped.

Another - undocumented - exception is that PlaceOnWalkableArea ignores walkable areas lying beyond Room Edges. Probably that is because Edges are usually used to define exit zones.

rofl0r commented 6 years ago

is that the underwater room with the mermaids or the one where you have to do stuff with an apple ? if the latter, this is also where i got stuck with the scummvm port.

ghost commented 6 years ago

Room 49 is a first medieval village scene. I do not really remember the game's plot.

What was your issue with mermaids? I mentioned "Duty & Beyond" only for the sake of room example. IIRC I was just teleporting between rooms to test something else out, when I found that I cannot put character on walkable area with debugging command. So this was not actual gameplay bug.

rofl0r commented 6 years ago

oh right, medieval village with the platform on the left where you supposed to grab an apple, but cannot walk away from the platform. that's exactly what happened with scummvm, while it worked OK with the "real" AGS engine. in the underwater level leading to this scenario, there's also some weird behaviour when you drive to the far right of the screen into the underwater plant boundary, and sometimes its hard to get back into the normal area. i figured that was a bug porting the pathfinder algo.

monkey0506 commented 6 years ago

This has been a long standing technical issue with the way the bitmap masks are used. If a game was made at 1920x1080 resolution, it would take ~2 MB of RAM to load an unsigned char[1920][1080] with the integer ID of the mask at any given pixel (point being, not much for even a high res game). Would it be feasible (fast enough) to load this during the room loading? Then the walkable area mask would be fully known to PlaceOnWalkableArea, the pathfinder, etc.

I have no idea if that could work, but it's just a thought. I don't think it's really necessary for other masks, but could help walkable areas I think.

ghost commented 6 years ago

@monkey0506, I am not sure I understand your proposal. Room masks are always fully loaded during room loading and fully known to these algorithms. It is PlaceOnWalkableArea that simply does not check all pixels in the mask, intentionally skipping intervals of 5 (or is it 4? I may have failed math there).

E: Can it be you are referring to a different issue, when hi-res games have their masks made 2/3 (iirc) of the size of the room?

ivan-mogilko commented 1 year ago

Fixing the stepping (by 5 pixels) in PlaceOnWalkableArea on its own is trivial, but that might slow things down in the large rooms.

The performance of this search may be improved by precalculating a "lookup grid" that splits walkable area into cells of certain size and writes down which areas are present in these cells. The the search would be done like this: