…And this time, make it right.

This week has gone too fast! After the beta it feels like the time has just flown away and we have a lot to do with final lurking around the corner. I have mostly been trying to make the game run a lot smoother and to fix performance issues this week so there’s a lot of smaller things done but nothing too major except for two things. The one I will discussing this week is reworking the enemy handling we are using. However I will mostly tell you what will be done rather than what has been done since this issue appeared earlier on the day of writing this post and all though work has been started, it still is not done.

What I have done is moving all code related to the enemy spawning, update and drawing to a new class called EnemyManager. This was pretty easy but the more challenging part is to change how we use enemy objects. The performance issue we found was that we because of being rookies we used new and delete a lot to create and remove enemy objects from the game. This puts a lot of work on the memory of the computer resulting in a memory usage of about ~1GB in our case. To fix this I am currently in the process of changing everything so that we create all objects we need when the EnemyManager is created by using the .resize()function of all the vectors holding the different enemies creating as many as we need. Doing this will put of a lot of load from the memory and will hopefully drag it down a whole lot. This will also be done for all other reoccurring objects in the game.

So how will the Enemies work without using new and delete? It is done in the way that we did in programming 1 and how we should have done it here. Each element in the enemy vectors holds an enemy object which has a function call called IsActive(). If this returns true the enemy is updated and drawn. So if I need to create an enemy I just check for an inactive enemy and activates it on the right side of the screen. When it reaches the side of the screen or is shot it will become inactive and does not update or being rendered.

This might have been a bit messy written but it is also a bit messy to explain since it is still a work in progress but I will try to summarize it with a couple points:

  • move enemy functionality to new class
  • remove the * from all reoccurring objects.

This is not a very difficult thing to do but it is a bit time consuming since I have to rethink how some functionality works but it will be worth it in the end.Untitled.png

About Philip Olsson

2015 Programming