Very llow fps in xna

Started by
3 comments, last by lwm 11 years, 7 months ago
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
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)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
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.
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.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

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

current project: Roa

This topic is closed to new replies.

Advertisement