• Register

Guilden is a strategy game where you take control of a dynasty, join or create a guild, and rank up through various missions, world events, and sneaky tactics along the way. You will be able to build your own guild, and through your decisions, decide to make peace and help the kingdoms of Guilden, or take control of them through conquest!

Post news Report RSS DevBlog #2 Rewriting and Refactoring

The fun journey of rewriting your game! My decision to port my code from C# to C++ and why I'm glad this has been done.

Posted by on

When I started this game originally, I thought it would be best to try out Unreal Engine 4. I'm a fan of C++ as a development language and I don't mind getting into the thick of code to create custom functionality. After a while though, I realized that if I wanted this game to be modded like the Paradox Interactive games, UE4 was probably not the way to go. Their structure and asset files were not the flexibility I was looking for.

I then decided to switch to Unity..., and that was fun. Unity provided me with the flexibility I needed, although the terrain needed a LOT of work and love. I was even able to get a short video of loading in the CK2 Europe map.

However, after a LONG and hard journey of trying to get my scripting engine optimized (and other performance issues), I decided in April 2016 to switch back to C++. Last year I had already begun work on a custom game engine in C++, and now that the CLion IDE seemed to be stable I felt ok about this decision. I did make quite a bit of progress, and it was sad to start all over again, but I couldn't ignore the issues I was facing with Unity. Here's one of the last screenshots done in Unity (I loved that water!)

9rcfwu0


So now my adventures in C++ began again, as it had originally started. I was totally ok with this. C++ is a language I love very much, and while that may be uncommon, it has been a love language of mine since high school (and back then I was coming from a Pascal-based background).

My first mission was to at least look for a framework I can start with. I decided not to use my custom engine because I didn't want to spend the next year implementing features instead of working on the game itself. I was in luck! I found a nice lightweight engine called Urho3d.github.io to begin with. It was bare bones enough to make me not feel like my code was being intruded upon, and it had enough features to make me not feel like I was walking up a mountain to get this game done. It was perfect for my needs!

My next goal was porting all of the C# code to C++. I didn't think this would be a big deal, and while I did run into issues they were mostly trivial. The biggest port was my scripting engine. The scripting engine was built to parse/execute any Paradox Interactive CK2 file. As I mentioned in my first post, it is one of my primary goals to import CK2 mods into this game since I still want to play them (totally selfish reason... I know)! After a good 2 months of tweaking, rework, etc I finally did it!

Strategy game C++ Screenshot

At this point I'm now starting to feel like things are shaping up. While I may not have been able to port the AMAZING ceto water asset from Unity, I do feel like I've made good progress. At this point I'm just working on my UI so I can see the scripting events fire off and not have to use the log files haha.

All in all, this has been a fun experience. I can't wait to start showing off the game in more videos like the one above!

Ok, so one last topic... refactoring (not rewriting)! I recently went through another refactoring of my code. While I don't do this often, I thought a little cleanup was necessary. I feel like you need to use C++ with a lot of care. String corruption should be dealt with immediately, especially in the scripting engine, or it will pop its ugly little head up when you least expect it! A goal of mine is to ensure people can write their scripts without the fear of random retribution from rouge code.

I also believe refactoring can be healthy when done in small spurts. Wait too long and it will seem too daunting of a task. Do it too often and nothing will ever get done. So always be careful when you decide to refactor. It shouldn't take too long either, although "long" is relative in this line of work.

Anyways, I'll stop my rambling. :)

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: