Jump to content
  • Advertisement
Sign in to follow this  
Sasa064

Very llow fps in xna

This topic is 2239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello,


I created a maze from a boxes and i have problem with fps, when I create Maze 25x25 boxes fps goes very low.
boxes are created out of matrix with 0 and 1 so it is a O(n^2). Can fps go up?


[indent=1] for (int j = 0; j < _creator.Height; j++)
{

[indent=1] for (int i = 0; i < _creator.Width; i++)
{
world = Matrix.CreateTranslation(4 * i - 20, 5, 4 * j - 20)
* Matrix.CreateRotationZ(40);
if (maze[j, i] == 0)
{
modelBatch.Begin(viewMatrix, projectionMatrix);
modelBatch.DrawPrimitive(new Cube(GraphicsDevice, 4.0f), world, primitiveEffect);
modelBatch.End();

[indent=1] }



[indent=1]for Cube I used Nine 3d engin

Share this post


Link to post
Share on other sites
Advertisement
You could draw multiple cubes in a single batch. start by moving your modelbatch.begin and end to the outside of the for loop. (since only the matrix changes it should be ok to draw all cubes in a single batch) (you could also try to put them just outside the inner loop to draw each column as a batch and see what works best)

After that your best bet is to cull hidden cubes (if you can't see something, don't tell the GPU to draw it)

Share this post


Link to post
Share on other sites
It looks like you're re-creating the cubes every time you want to draw them? If that's true, try creating them in advance and re-using them every frame.

Also, if all the cubes are the same, you don't need 625 of them -- you can just create the 1 cube model and then draw it 625 times. Edited by Hodgman

Share this post


Link to post
Share on other sites
You're also creating 625 * 2 matrices every frame (if this is all in your draw method), but they don't look like they ever change. If they're always in the same location as regards their world transform, you could pre-calculate the world matrices once, store them in an array, and just reference them by index, rather than re-creating them every frame.

Share this post


Link to post
Share on other sites
I'm particularly concerned about "new Cube(GraphicsDevice, 4.0f)". Passing the graphics device to a new cube kinda implies, that the cube needs the device to allocate new unmanaged resources (maybe a new vertex buffer or effect). Edited by lwm

Share this post


Link to post
Share on other sites
Sign in to follow this  

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!