Map smoothing

Several crashes were reported when a hero gets close to the border. One bug was that the size of the frame around the map was incorrect (especially when runnig in 1024x768 or 1280x1024). That’s fixed. The next bug that shows up is due to the smooth parameter in CMapHandler::terrainRect(). What exactly is this parameter supposed to do ?

Edit: never mind. I see the effect now.

Smooth map scrolling is used during the hero movement.
Then smooth flag is set to true and moveX and moveY parameters are the shift for terrain graphic (values between -31 and 31 px).
When hero is moving from one tile to another in CPlayerInterface::heroMoved we have a loop that in each iteration moves hero by a few pixels, increments (decrements) moveX/moveY variables by a few px and updates the screen (including rerendering slightly moved terrain with terrainRect call).

Current solution is very inefficient because of that multiple rerenderings (16 times for 2 px “step”). It should be rendered only once on buffer surface and then we should cut appropriate parts to blit on screen.
If you like, you may implement it :slight_smile:

Thanks

If we do that, then we cannot have animations while the hero is moving. I see that there is none currently. Could that could be desired later ?

It’s not urgent, it’s one of many improvements that should be done on some day. I’ve mentioned it by the way of smooth map scrolling.
Yes, buffering terrain would block terrain animation during hero movement but I think it’s acceptable price for significant efficiency boost, especially since original H3 also don’t have it. It may be also optional.


As for the bug itself. During smooth map scrolling we need to render slightly bigger terrain rectangle. Widening the frame by one tile in each direction should fix crash.

I’ve changed the code to move the hero at the center of the map screen (like in H3). It’s really messy because of all the coordinate translation that must be done, but it’s working ok. I’ve removed the non-smooth case because I don’t see the point in keeping that and it’s removing a lot of code.