Monday, 14 April 2014

Redesigning the Iron Heart engine

Over the course of the summer, I will be (and already have been doing) redesigning the Iron Heart engine to be a much leaner, meaner, engine. It will be a 45 day project in which I will completely overhaul large sections of the engine. This blog is the first of several that will describe changes made to the engine, along with why and how it benefited the engine as a whole. I will continue to use my TA's Ogre/Havok wrapper, TwoLoc, so I do not over complicate the project. The official start date of the project is May the 1st, and the end date is June 15th.

Over the course of my third year at UOIT's Game Development and Entrepreneurship program, the amount I learned about C++, effective C++ design patterns, good coding practices, and speeding up development process has been massive. Much of this is thanks to my excellent professors and learning from my peers. Where I feel I have learned the most however is from hard work and determination to become a better programmer and truly discover where I want to take this developing skill. Enough with the sappy stuff, time to get my hands dirty.

Reception at Game-Con was positive for Iron Heart. People enjoyed the fast game play, fun design, and pace of the game. However, the engine, if you want to call it that, was awful. It used very little scripting systems, had so many persistent memory leaks that caused the game to crash, barely used effective C++ design pattern's, and overall had way to many bad practices that held the game back. However, after spending a great deal of time looking at the engine, trying to understand what it truly is supposed to do, I have a few goals that I will strive towards to make the Iron Heart engine faster, more stable, more functional, and provide a better learning experience to myself. But, how and where can I fix it?

What to fix

1.) Memory leaks

Memory leaks are literally everywhere in the Iron Heart engine. It breaks it after 10-15 minutes of constant play. But what exactly are these memory leaks? In to many parts of the engine to point out, we do a "new" without a "delete" afterwards. All of these news add up over time, and cause the game to rapidly bloat, cause cache misses, and slow down the game. The memory leaks were so bad in fact they were causes our networking to slow down considerably. We can either call delete afterwards, or find a way to not use "new", to save on both time (as new is an expensive operation), and memory.

2.) Every-frame calling of "new"

This is an ugly one. There are some instances in which we call "new" every frame. That's right, every frame. It's a terrible practice because of how new is an expensive operation that cause potentially cause memory leaks (which in our case it does). We should never be calling dynamic cast new every frame, it's a slow operation that can cause to many problems. That has to go.

3.) More scripting

Speaks for its self. More scripting. Tank stats should be loaded as a script. (Currently we load some as a script, but we need to load more). More game logic needs to be dealt with as a scripting system. Not only will scripts decrease development time, but they will serve as a learning experience for scripting.

4.) Some general bad coding practices.

We have some general bad coding practices here and there. Passing in arguments where not needed, lack of comments, strange file location set up. All of these bad practices need to be reversed to make the engine more understandable, faster, and easier to use.

5.) Decentralize classes! No more snowballing!

A big problem in the Iron Heart engine is the snowballing of classes. What this means is that extra data and variables are being declared in classes that simply should not have them, but have them because one or two (out of n objects) will use that particular variable. For example, we included havok constraint data for our tank rigs in the generic object class. The generic object class was used to create our menu system. Why would a menu (say the tank selection menu), that isn't even a havok rigid body, ever need tank rigging data? It doesn't. The system needs to be decentralized so that classes have exactly what they need. This will ensure that when we create new objects, they will be as small as possible so we don't bloat out system with needless junk.

6.) Better use of state managers!

You know you have a problem when the first word in your update loop is "if". Currently, we don't use the state management system Dr. Hogue taught me in first semester for our game states (are we in menu, or game). We use if statements. Those if statements need to go and fast cause they stink something awful! Replacing them with state managers will mean not only can we localize the update data to a single area where it will be easier to debug and write, but we will save on if statements and be making the engine faster.

7.) Networking needs an overhaul. 

Currently, the networking is full of memory leaks and needs to revamped. While much of it was already fixed when I powered through it the night before Game-Con to make it better, there are still a lot of problems. Currently, packet sending ranges from picky, to spam, either of which cause latency issues. Currently, networking can't detect which tank you pick, it defaults to the Waybach Blitz tank (Assume I'm host, you're client. I pick American Dream, you pick Tesla Tank. On my side, you will show as the Waybach Blitz tank and I will show as the tank I selected, and on your side, I will show as the Waybach Blitz and you will be the tank you selected). The chat needs some debugging. However the multiplier just needs more features. Kill count, victory conditions, etc.

Why do all of this though when I could work on something else?

I truly feel, as someone who wants to develop their skills as a programmer, should not let sloppy work like this go by. This is my resume right here. When I go to show my portfolio to an employer, this is what they will see. And what they see must impress. They will ask questions, they will have expectations. I do not not want this ending up on that "hey I need a good laugh, let's laugh at this" list. I'm not expecting to make history with how amazing it is, but to be solid enough to demonstrate not only what I have learned, but that I can apply it in a way that make sense. Hard work builds character, and this engine needs some of that character.

Conclusion

I have a lot of work cut out for myself when rewriting this engine. It will be a lot of work, but it will also be yet another awesome learning experience. It will certainly be worth showing off (while not as awesome as some other engines I've seen my peers make), but it will be something I can be proud of. I'm fully confident that the final product will compile faster, run smoother, play better, and simply provide a better experience for players.

No comments:

Post a Comment