Sign in to follow this  
Total_Titillation

Optimising render loop

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Cathbadh    100
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.

Share this post


Link to post
Share on other sites
karwosts    840
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this