• entries
    16
  • comments
    19
  • views
    16881

Performance Problems (plus solution!)

Sign in to follow this  
omnomnom

1016 views

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!
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

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