Optimising render loop

Started by
1 comment, last by karwosts 14 years, 2 months ago
Hi, I’m currently working on a 2D game similar to gta and I need a way of optimising my render loop. At the moment I am splitting the level into 10x10 cells, these then contain pointers to all the entities currently residing within them. I then have a vector Level which is a 2D vector of cells. My initial idea was to get the player position / 10 and use this to draw the current and adjacent cells. However, after doing a few comparisons to make sure that I wasn’t trying to draw cells with indexes outside the bounds of the level vector I began to have major performance issues. At the Moment the floor of each cell is just made up of a quad with a texture applied, is it worth using a display list? Is there a better way? At the moment I’m only drawing floor textures and the player, and it seems to be about 30 fps...
Advertisement
Sounds a lot more complicated than it needs to be. Perhaps take a look at doing quad-trees? (That is, octal trees but simplified to 2D space) Each node represents some square of space, and each quadrant of that space forms another node. The space is divided ad-nausium. In addition to the sub-nodes, each node has a list of all the objects for which that node is the smallest possible node that can completely contain the objects (This needs to take into account the bounding-boxes of the objects too)

This way, you only need to draw the objects that fall in the particular nodes that are visible, which should be easy to figure out from the camera position and zoom factor.
If you would post some more detail about what you are doing someone might be able to pinpoint what might be the cause of any slowness in your design.

Using a grid like that sounds like a fine idea. Nothing you've described should cause any noticeable performance decrease, and if you only render certain grids you should get a significant performance increase, so I'll guess that you likely are doing something incorrectly, but without any idea of what checks you're doing, how many entities you're checking, or how many triangles you're pushing its hard to know for sure.

Using a quadtree is good in some circumstances, but a grid should be fine also, there are trade-offs to using either. Personally I'd stick with the grid for now until you get a little more experience, managing a quadtree is significantly harder than managing a grid system, although it can help performance/memory usage if your entities are very non-uniformly spread throughout the level.

Also I would not bother with display list unless you are pushing tons of geometry and can't/won't to learn to use Vertex Buffers. Vertex Buffers are the future of OpenGL and will have much better performance, display lists are depreciated.

What you're doing now sounds like you are fine in immediate mode until you get your other issues fixed, just drawing simple quads and simple objects you shouldn't have much trouble.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement