jojobear13 / shinpokered

Mostly-vanilla hack of Pokémon Red/Blue focused on bugfixes and trainer ai
209 stars 42 forks source link

Request: Try to optimize the lag in cinnabar gym #267

Closed jojobear13 closed 12 months ago

jojobear13 commented 1 year ago

There is a noticeable lag caused when loading the map due to all the wall tiles that have to be replaced. Look into a way to optimize this.

Vortyne commented 1 year ago

blocks that are offscreen can be replaced via ReplaceTileBlock without calling RedrawMapView (the slow thing) at the end - they'll be updated when they come on-screen

might be useful to know

haven't tried it before in cinnabar but perhaps only calling redrawmapview for the replaceable blocks that are on-screen would be faster

then there would be a maximum of around 2-3 of them to be replaced with a redrawmapview in total

Vortyne commented 1 year ago

You might also try replacing all the blocks via ReplaceTileBlock - but only calling RedrawMapView once at the end of all the replacements. I've tried this in bills house with every single block being replaced and it seems to take the same amount of time as only replacing one or two.

jojobear13 commented 1 year ago

Commit 4a031f9af02d0bc8ba17e69c02f3ad72dc358ca8 improves ReplaceTileBlock. Tile blocks will only be replaced if the new one is different from the old one. RedrawMapView is only entered into if the replacement tile block can actually be seen on-screen.

Here's what this means for cinnabar gym. RedrawMapView is only run once when entering the gym because of a single locked door tile block that appears in the upper-left edge of the screen. Once that door is opened, entering the gym will no longer have any noticeable lag because all the other locked doors are off-screen. Doors that are already opened get no tile block replacement because there is no reason to replace an open floor block with the same open floor block. Naturally, unlocking all the doors means that tile block replacement is no longer done within the gym. Beating a trainer or answering a quiz question directly will run RedrawMapView a single time to make its respective door open.