Skip to the 2nd paragraph for the nitty gritty.
Alright, so I’m making an isometric tactics game and I’ve been occasionally running into performance problems. Because the map is isometric I can’t just load the map as a single bitmap, otherwise units cant be brawn behind the tiles if necessary. I’ve organized my map so that each XY coordinate of tiles is a single entity, with Image graphics constructed from bitmaps on load. This means I’m dealing with 400 entities minimum. As you can imagine, when you add in units, UI, and the top layers for water I can easily get 600-700 entities. Water is especially taxing. It’s not uncommon to drop below 60FPS. I could deal with it but that’s pretty intense for just rendering. Throw in AI functions and general game logic and FPS can drop to 30 for a few frames. That’s enough background.
I devised an alternative method to rendering that I’ve dubbed Isolated Rendering. When the map is loaded I render all of the tiles to a single bitmap and add it as an entity. Then I divide the screen into a grid of 25x25. This grid functions like a primitive quad tree, so I call it a DeviantTree. I calculate each tile’s position in the grid and add it to each and every node it occupies. I then lock the grid. Any units will be given the type “active”. UI elements will be typed as “ui”.
On each frame I bypass the normal rendering method entirely. I render the cached bitmap of tiles to the screen buffer. I then grab all “active” entities and push them into an array. I then loop through this array and retrieve all tiles it can possibly be drawn over and add them both to a render queue. I then loop through this queue and draw the entities to a bitmap the size of the screen called the isolationBuffer. I will then loop through the “active” entities and use a rectangle to clip the relevant pixels from the isolationBuffer and render it to the screen buffer. This means that the relevant entities won’t ever obscure an other entities that they otherwise wouldn’t. I then grab all “ui” entities and render them like flashpunk normally would, but that part isn’t implmented yet.
There are several restrictions this type of rendering imposes. I won’t be able to use flashpunk’s default particle implentation. I guess I could make it so particles are rendered to the buffer during islation… This also means that UI elements will ALWAYS be drawn on top of tiles and active entities. I can live with that. It also means that I’ll need to add some extra logic to GraphicLists to scale the hitbox in a way that all it’s children are inside it.
Isolated rendering was supposed to be faster than the normal method by a ton. I mean it would make sense right? Instead of rendering every single entity every frame, just render what entities can possibly move. After implementing it I discovered that it was in fact faster than flashpunk’s default method, but only in specific cases. I usually drop below 60FPS after about 35 “active” entities. After that point flashpunk’s default is faster.
So I’m at a loss. It’s taken me quite a lot of time getting this all sorted out. I really need some ideas on how to improve Isolated Rendering or another alternative rendering method. I’m at the end of my wits.
I’d like to show you what kind of map I’m dealing with but “new users can’t post images.” The best I can do is post the relevant code. http://pastebin.com/T0KrmGim