Converter Series: Stealing My Own Code (Logging)

With a Hello World program working correctly, I can start doing slightly more exciting things. I start by creating a changelog, a simple file that documents the changes I’ve made. SourceForge tells this, but it’s not easy to extract the information, and people on the forums like to know what’s changed between releases of the converters.

Once I’ve created it, I start borrowing code from my other projects.

I start with a logger. It allows me to write something like

log(“Put this message in the log filen”);

and have it appear in a log file. This is extremely helpful for debugging, because if someone sees errors, I can get a notion of what the converter was doing. The logger doesn’t have to be complex: this one started as a wrapper around fprintf(). There’s an initial initLog() procedure that opens a file, all the log() calls, then a closeLog() procedure that closes the file. Later on, another programmer added a timestamp to the beginning of all lines output to the log file. It’s just 37 lines of code, but it’s an extremely useful 37 lines.

I use it to print “Hello World!” to the log file.

Surprisingly, it crashes for awhile. I’m extremely puzzled, then I realized I forgot to call initLog() and closeLog(). You only have to do those once each time the program runs, so it’s easy to forget about them in a project that’s existed for over a year. I add them in, and everything works. Hooray!

Converter Series: Initial Decisions and Hello World

Starting a new project is a time where you have to force yourself to be a bit patient. It’s easy to jump in and start coding, but it pays to take the time to think out some important points.

For my first decision, I decided to write this project in C++. It’s a fairly easy decision: I’m familiar with the language, and the EU3 to Vic2 converter is also written in C++, so I can borrow useful bits of code. The disadvantage is that C++ is not particularly good at processing strings. We’ll be doing lots of that, and if not for borrowed code, there would be a nearly impossible start to the project. More on that later.

And instead of starting by coding, I start by setting up a SourceForge project. This allows me to keep all my code in a repository, in case of computer-related disaster, and to make it easy to return to a known good state of code, in case of programmer-related disaster. Believe you me, the latter is a far too common occurrence. Also, this will allow other people to participate, and we can very easily share our code.

Finally, after all of that, I open Visual Studio, and start by writing a Hello World program. A Hello World program simply outputs the text “Hello World!” That’s it. It’s not exciting, but it often proves you’ve got all kinds of things set up correctly. It’s always a good starting place. And oddly, it’s starting to show up as a kind of nerd in-joke now and again.

Converter Series: Introduction

This post will start a series of computer-related blog posts, documenting one of my side projects, hopefully providing some wisdom for less experienced programmers, or enough shame for me to become a better programmer. It’s likely to be irregular, as I will be writing it as I do work on this project. Or long afterwards as I alternately forget and remember to blog about it.

First, some background. This project is intended to convert a save from the end of Crusader Kings 2 into a save near the beginning of Europa Universalis 3 (specifically the Divine Wind expansion, which is the fourth, though I might broaden the scope later on). These games are designed to be highly moddable, and the saves are in an open format that allows this kind of work. There are tons of mods on the forums, the community loves them, and the company that makes these games encourages this kind of stuff.

I’ve done some of these converters before. I updated a converter that took a save from the original Crusader Kings so that it could work with the third expansion to EU3 when that expansion first came out. I’ve been working on (and am coming close to finishing) a converter from EU3 to Victoria 2. And now I’ve just started this converter.