• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

The way that the maps are loaded (complex question)

FL

Pokémon Island Creator
2,444
Posts
13
Years
  • Seen Apr 22, 2024
In Essentials, in weak computers and/or big maps I have lag (FPS down in truth, but I'll call lag in this topic), but only for more bottom-right positions that I go in these maps.

An example in a 150x150 map. Near the point where x=10 and y=10 (top-left) I've no lag. Near x=140 and y=10 (top-right) or x=10 and y=140 (bottom-left) or x=75, y=75 (center) I've little lag. Near x=140 and y=140 I've the big lag.

My question is: Why this occurs?

My plain is to load backward the map data when the player is more near of the end that the start. In the above example, when x=10 and y=140, I will load the y dimension backward. If I manage to do this, I will remove most of the lag (except when x=75 and y=75, the center).

I know that the Essentials use a different way to load the maps, the $MapFactory (an instance of PokemonMapFactory class) have a map for every map that is near the connections of the current map in the maps variable, and the Scene_Map control a spritesets hash that uses a map id as key and have one instance for every map in $MapFactory.maps. Every Spriteset_Map class have a tilemap variable that loads the TilemapLoader, and then the CustomTilemap. The CustomTilemap is a custom tilemap (obvious), that M A N U A L L Y done the entire system of drawing the tiles from the tilesets for each map, probably this cause to Essentials games to lag more that the standard RPG Maker XP games, since the RGSS API functions for this are more quicker than Essentials way, but I've no sure. Essentials also came with a antilag system that only update the events that are in a range (near of the screen) and the autorun and parallel processing ones.

I spend several hours making research tests, without success. And yes, I also know about connections.

I've no problem sharing with the community my discoveries, so if someone know any clue, please comment.
 
Last edited:

Maruno

Lead Dev of Pokémon Essentials
5,285
Posts
16
Years
The default RMXP scripts draw their maps using the class Tilemap. This class is part of RGSS, and thus is something of a black box (there is documentation about RGSS, but no code).

I've just tried out using Tilemap rather than CustomTilemap, and discovered that it doesn't support multiple maps being loaded at once, nor daylight shading, nor screen resizing (and probably many other things that a Pokémon game requires or that Essentials has custom systems for). Since Tilemap is part of RGSS and can't be edited, it needs to be replaced. That's what CustomTilemap is for.

CustomTilemap does everything that Tilemap does, so your "M A N U A L L Y" comment is undeserved. Tilemap does the same thing; it's just that you can't see its code.

It's quite interesting how CustomTilemap draws maps. All tiles with a priority of 0 are drawn all together on a single large bitmap called "layer0" which is the size of the screen (plus a margin) and goes beneath the player. Any tiles with a priority of 1 or higher are given individual sprites which are placed above or below each other (and the player) according to their priority and their y coordinate - that last part sounds odd, but trust me, it works. It means the player's head can appear over a priority 1 tile when standing south of it, but the player will appear behind a priority 1 tile when standing in the same place as it. Really, it works.

Naturally, if your map has lots of priority tiles in or near the displayed area, there's going to be more sprites to manage. I don't know how resource-intensive that is. Layer0 is redrawn if the camera moves beyond what it shows (usually caused by the player moving), or if the autotile animation frame changes, or if the tileset changed for some reason (doesn't usually happen).

Given that Layer0 and the priority tile sprites only exist for the area shown on-screen (plus a 5 tile margin on each side), that's not a whole lot of stuff going on, to be honest. It's not all refreshing itself all the time either; only when it needs to.

Your description of the lag you experience mentions that it's worse if you're at the bottom right of large maps. I really don't see why positioning would matter to CustomTilemap at all, because one rectangle of tiles is the same as another.

I've just had a go at trying out a 500x500 map with nothing on it and no connections. FPS was a constant 38 for me regardless of my location on the map.

This leads me to believe that the lag is caused by you somehow, probably by having a lot of things going on in that corner of your map. Lots of events, more priority tiles, more autotiles, connected maps... Even if it turns out to be a problem with Essentials (which seems unlikely given my test), I doubt it's the fault of CustomTilemap because there's no reason for it to care about positioning.
 
64
Posts
10
Years
  • Age 36
  • Seen May 29, 2020
I've just had a go at trying out a 500x500 map with nothing on it and no connections. FPS was a constant 38 for me regardless of my location on the map.
Maybe it is an idea to test with a map with only one half filled, and the other half empty? Then you can tell whether having stuff on your map actually influences lag by switching between walking at the filled side and walking at the empty side. It would also be interesting to switch the empty and the filled side, then you can conclude whether the position of the filled side matters.
 

Maruno

Lead Dev of Pokémon Essentials
5,285
Posts
16
Years
Could the size of the used tileset influence this?
The tileset is used for the whole map, not just the high x/y part of it. That wouldn't be a problem. I've already mentioned the things I can think of map-wise that would increase the amount of work the program has to do. The fact that you're using a big number rather than a small number for the coordinates will have no effect at all.
 

FL

Pokémon Island Creator
2,444
Posts
13
Years
  • Seen Apr 22, 2024
I know about layer0 and that tiles with other priorities are drawed different, but I didn't know about these details! Thank you! Your knowledge is great! I tested about the priority tiles and I concluded that an area of these tiles really lags more than an area with tiles without priority. Unfortunately, this won't solve my question.

CustomTilemap does everything that Tilemap does, so your "M A N U A L L Y" comment is undeserved. Tilemap does the same thing; it's just that you can't see its code.

In fact, I don't know if the CustomTilemap had an exact replica of the API scripts or it's manually reproduced, so I can't say for sure, but I guess that it's manually reproduced. Anyway, API functions generally have a better performance that custom ones, but, I this case, I've no proof.

Your description of the lag you experience mentions that it's worse if you're at the bottom right of large maps. I really don't see why positioning would matter to CustomTilemap at all, because one rectangle of tiles is the same as another.

It's strange, isn't?

I've just had a go at trying out a 500x500 map with nothing on it and no connections. FPS was a constant 38 for me regardless of my location on the map.

Sorry if I aren't clear. I also have no lag in a 500x500 empty map. I am talking about a map with stuff spread over it (events, tilesets with other priorities, autotiles, etc...). Of corse, I tried with several maps. It's a fact that in Essentials maps with a good number of stuff laggs, specially in weak computers. I don't use and ignore connections in these my tests.

Even in my example of a map with a 150x150 with stuff spread over the map, I tested to turn it an 150x450 map, but without content in the part that I added. I have a similar lag of the 140x140 point in the new parts, by your statement this shouldn't occurs. I can't says for sure if the lag is even worse.
 

Maruno

Lead Dev of Pokémon Essentials
5,285
Posts
16
Years
Sorry if I aren't clear. I also have no lag in a 500x500 empty map. I am talking about a map with stuff spread over it (events, tilesets with other priorities, autotiles, etc...). Of corse, I tried with several maps. It's a fact that in Essentials maps with a good number of stuff laggs, specially in weak computers. I don't use and ignore connections in these my tests.

Even in my example of a map with a 150x150 with stuff spread over the map, I tested to turn it an 150x450 map, but without content in the part that I added. I have a similar lag of the 140x140 point in the new parts, by your statement this shouldn't occurs. I can't says for sure if the lag is even worse.
My point with the 500x500 blank map is that the lag isn't inherently caused by the map renderer (i.e. CustomTileset) solely due to the coordinates. It is therefore a coincidence that you experience lag at high x/y, and the lag is a result of something (or some things) you've put there. I don't know if your second paragraph has any typos in it so I can't speculate further.

Have you experimented with upping the frame rate (RGSS2Compatibility line 72) and seeing what kind of slowdown you get then? Does the FPS drop to the same amount you had before, or does it just drop by (roughly) the same amount?
 
64
Posts
10
Years
  • Age 36
  • Seen May 29, 2020
Did you try with a map that repeats a specific section of high density stuff? Like, Fill up a map of 8x8 as much as possible, then paste it on a map of 160x160 (e.g. 20x20=400 times). The map should have the lag because of all the stuff. And if Maruno is right, the lag should be the same in all 400 8x8 squares. If not, then there might indeed be something weird going on with the coordinates...
 

FL

Pokémon Island Creator
2,444
Posts
13
Years
  • Seen Apr 22, 2024
My point with the 500x500 blank map is that the lag isn't inherently caused by the map renderer (i.e. CustomTileset) solely due to the coordinates. It is therefore a coincidence that you experience lag at high x/y, and the lag is a result of something (or some things) you've put there. I don't know if your second paragraph has any typos in it so I can't speculate further.

Have you experimented with upping the frame rate (RGSS2Compatibility line 72) and seeing what kind of slowdown you get then? Does the FPS drop to the same amount you had before, or does it just drop by (roughly) the same amount?
My point is that this problem only occurs in maps that have certain content. A empty map have a filesize too low for any lag. I have maps 400x400 WITH CONTENT (events, autotiles, etc...) that don't have this problem, but I also have maps with 100x150 with content that have this problem. Except by this your logic is right.

I also thought that this is coincidence several times, but in the test that I change a map with stuff 150x150 to a 150x450 map with the new parts (a 150x300 area) totally empty, in the theory this empty part don't have any lag, right? But this isn't that happens. These empty parts have a lag undoubtedly greater than point 10,10.

So I made the test that you suggested. I raise the FPS from 40 to 120 (the maximum value) and try again several maps that have the problem. In tiny maps without lag I have around 65 FPS. In scenes I reach even 90 FPS. So, when I try again the maps, almost all maps that have lag now stops around at 15 FPS (the generally stops at 5 FPS before). There few exceptions than reman in 5 FPS or even lower values at right-bottom parts. Interesting note: There also maps that only have the FPS down at right-bottom parts, but now they have the same 15 FPS to the entire map, but I'm sure that at left-top points the players move faster than at right-bottom points, despite the same FPS.

I also tested 20 FPS: This makes some maps than have a little lag, only at bottom-right (around 12 FPS) be fixed, but the maps that have 5 FPS now have 2 FPS. This fact let's me question a curious occurrence: If there something that stuck the FPS to 1/8 of the maximum when the map have a huge content. Of corse, in some extreme cases I succeed in having a FPS down below 1/8 of the max FPS. Maybe this 1/8 possibility is just coincidence...

So I disable the priorities and events using scripts for the whole game and test again in 40 FPs. This fix almost all maps, but there's one (without connections and events) that STILL have a FPS down outside left-top points, mainly at bottom-right (but the FPS is very higher than before). This only let's me guess that is some tilesets combinations in the 3 layers because this is the only thing that I don't remove. I even put some empty squares at bottom-right to make the screen to fill the empty place (plus a margin), but I still have lag in these parts.

Did you try with a map that repeats a specific section of high density stuff? Like, Fill up a map of 8x8 as much as possible, then paste it on a map of 160x160 (e.g. 20x20=400 times). The map should have the lag because of all the stuff. And if Maruno is right, the lag should be the same in all 400 8x8 squares. If not, then there might indeed be something weird going on with the coordinates...
Good idea, I will try this.
 

FL

Pokémon Island Creator
2,444
Posts
13
Years
  • Seen Apr 22, 2024
Eureka!

After more several hours of testing I discover that in tilesets I reference a Panorama that no longer exists. I just remove the reference and the problem is fixed.

Thanks for the help!
 
Back
Top