🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Performance Problems (plus solution!)

Published April 10, 2012
Advertisement
stuff2.png

The above mess is what I have so far. Please excuse the layout and the colors, it's all temporary. I am slicing so a lot of it is left unfinished.

  • Top Right: Equipment window. Works the same as the inventory and floor space windows except you can only drop the right item class into slots. I just realized I have forgotten a slot for a robe/cloak. I added 4 test items: A club, a dagger, a helmet and boots.
  • Middle Right: Player attributes window. Only has three attributes at the moment. Melee is the melee attack damage the player does. I broke this during performance optimizations mentioned later which is why despite the player boots and helmet it still reads 0 for the armor level and 0 for melee.
  • Lower Right: Floor space window just showing you what is on the floor. I guess this one will need a scroll bar as a floor tile can potentially hold infinite items (better solution?)
  • Lower Left: Message log. I have a static method which can be called from anywhere to add a new message to the log. Getting messages out is fine for now. Fixing the font, and the grammar is a job for much later.
  • Top Left: Inventory window. Shows what the player is carrying. The player can only carry a finite number of items.
  • Middle: Uh not much space left for the map is there? The resolution is 800x600 and I think that resolution should be supported. I am having trouble figuring out what the best position for the layout is to balance screen space with usability. It is possible to hide each window with a key.

    I added a new monster, a mummy, to test a creature that moves much slower than the player. It moves only one tile for every 5 tiles the player moves. I am glad I did this test as it uncovered an exploitable bug in the game. The player is able to jump towards the mummy, hit it, and jump back again before the mummy's turn. Repeated use of this technique means the mummy is unable to ever hit the player unless it can somehow corner them.

    You might say that's realistic - a faster player can kite the slower mummy. But in my opinion it renders slow creatures almost useless in rooms where the player can easily dodge round them. I think the mummy should move slower but have a similar attack speed to the player, ie it should be able to grab the player if they come too close. What I was thinking of doing to "fix" this was to allow monsters a chance to immediately counter-attack if they are attacked.


    Performance

    I started noticing some stuttering. Turns out I hadn't realized the C# garbage collector would pose a problem. I ran the .Net profiler against the program and discovered the game was creating megabytes of garbage strings and Vector2 objects every half minute. The garbage collector was having to clear that up, which took substantial time vs a frame, which was leading to frequent stuttering. The problem was that during each Draw() cycle I was creating various objects rather than reusing existing ones. I spent some time going through rewriting allocations until the profiler now looks a lot better. My biggest overhead now is creating DepthStencilState and RasterizerState objects every draw frame, I'll have to investigate if I can do that some other-way later, but for now the stuttering is fixed. I just need to bear in mind from now on to not allocate objects unnecessarily. But this is definitely a big deal for making a game in C#/XNA! Completely don't care about the garbage collector when I am making windows applications, but evidentially you have to care a lot to make games. If you ever know anyone starting off using XNA to make a game then warn them about this!
1 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement