C# XNA Lag and framerate issues XBOX 360 [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionI am a pretty good programmer and I am working on a minecraft li开发者_如何学JAVAke block building game for Xbox. I have about 10 thousands blocks in my game but when ever I run it on my xbox I have some really bad lag problems. One thing I did that kind of helped was setting all objects to null after using them but I am still having issues. How do most game developers solve this problem??? I thought of only drawing blocks that are close to the player but I think that using a loop to cycle through all the blocks in the world would slow it down even more.
You're on the right track, you definitely only want to be drawing things in the immediate vicinity if at all possible.
Quadtrees and octrees are data structures designed to slice up 2D/3D space respectively to make finding objects in a given area very easy. Sounds like this is what you are looking for.
You could use either, depending on what you wanted your definition of "nearby" to be. If you wanted to achieve the same as Minecraft, then what Minecraft does is display entire columns of blocks, so you could get away with a quadtree used to manage things on the X/Z coordinates and always show everything on the Y. If you wanted to do a 3D based definition of nearby, then you'd need a octree.
The way these work is by partitioning space using a tree structure. Each branch in the tree represents a quadrant (or octant in the case of an octree) of the available space, and each subsequent branch is a quadrant of that quadrant. Hence, it is very easy to drill down to a specific area. The leafs of the tree hold the actual data, ie. the blocks that make up your world.
精彩评论