- Joined
- Jun 27, 2014
- Messages
- 656
- Reaction score
- 166
- First Language
- English
This is from this reddit post (Warning Colorful Language Title)
https://www.reddit.com/r/RPGMaker/comments/3q3o58/the_chickenshit_bit_that_is_killing_your_rpg/
The user did not seem to have a forum account so I thought I share it here because I think it's everyone's best interest to consider any performance issues that might be contained in the rpg_core.js even more so if we can rewrite parts of the code to make it run a lot faster.
https://www.reddit.com/r/RPGMaker/comments/3q3o58/the_chickenshit_bit_that_is_killing_your_rpg/
The user did not seem to have a forum account so I thought I share it here because I think it's everyone's best interest to consider any performance issues that might be contained in the rpg_core.js even more so if we can rewrite parts of the code to make it run a lot faster.
Naive tilemap code.
Specifically, if you go to the actual Tilemap class definition; it's in js/rpg_core.js line 3732 down. It creates a Sprite object for each tile on the map (line 3996) and draws them in one-by-one (line 4050, lines 4064-4139, and a bunch of other functions).
The way you should do it is, at least in OpenGL / WebGL, upload all of your spritesheets as individual textures, upload another texture/buffer/whatever for each tile's ID (1-color, integer); and use a screen-filling fragment shader with a few uniforms to control scrolling behavior. This is very fast since your tilemap and spritesheet don't change except during scene transitions; you can tell the GL driver to just leave all the data on the GPU (GL_DRAW_STATIC).
On Canvas2D, since we don't have those nice things, I would instead recommend blitting the rendered tilemap onto itself and then redrawing just the strip of pixels on the side that need to be redrawn. IDK if that's possible. I have more OpenGL experience than Canvas2D, and I still have to figure out both RPG Maker MV as well as the graphics code it uses as it's base (PIXI) before I can get a performance-saving plugin written.
