Cleaning and optimizing

This weeks’ blog will not be about the Human character, as the previous ones were, but will instead be about the Demon class. The Demon class was not as well planned and structured as other parts of the project. The reasson has been that no one has taken it as their field of work, which has made it into a class where codes got dumped into. I took the responsibility to clean it as the other members are busy with other code parts in the projects and it was really necessary to clean it. The class had about 1000 rows of codes and an update function with 400 rows, which made it very hard to work with anything that was related to the Demon character.

To start this of I created a new class which got would get called from the original Demon class, which was a simple FSM (Finite State Mashine). A FSM is a way of keeping track of states and limiting users/ mashines from doing things which they should not be able to do. This can be a player who should not be able to walk and sleep at the same time, so the player got one state for each of these actions and only one of them is getting updated by the FSM. Each state is a class which is getting a property from the same interface as the others, which makes it easier for the FSM to work. By creating a FSM for the Demon we are able to have more control over the player and it will be easier to create new actions for the Demon. Every state got a StateChanger class in them which is deciding in what state which should be the next one, it also got got other variables which can be necesary to remember when switching states like selected units or what building is going to be spawned.

After the base for the SFM was done I started to sort all the things, in the Demon class, into different state classes. All building related things got into a building class and all unit commanding stuff got into commanding class. Now everything is nice and tidy in the Demon class, as it only got 100 rows of code in total while having an update function on 3 rows. There has also come up some nasty bugs from this, like some things not showing up or working. This will however be fixed next week before the Pre-beta Testing. The problem is that the code, which was in the Demon class before the cleaning, were not only written by me. This means that I don’t really know what everything needs to work correctly. So next week will be some talk between me and the other programmers so they can explain what is missing (as they should probably know better than me). Bellow is just a quick painted image of how the system looks like when looking on the classes.


Cleaning and optimizing


Fyll i dina uppgifter nedan eller klicka på en ikon för att logga in: Logo

Du kommenterar med ditt Logga ut /  Ändra )


Du kommenterar med ditt Google+-konto. Logga ut /  Ändra )


Du kommenterar med ditt Twitter-konto. Logga ut /  Ändra )


Du kommenterar med ditt Facebook-konto. Logga ut /  Ändra )


Ansluter till %s