Sunday 26 June 2016

Level class inheritance

The Level class in Teemu is probably the last class that doesn't use inheritance (from those that needs it), but it's about to change. I've already started to break it apart. Level class shares almost every feature between different level themes, but the obvious difference is the generation process.

I was thinking before that generation part wasn't "good enough" reason for inheritance, but I think I was wrong. If nothing else it's easier to maintain source code one theme at a time compared to huge combined Level class. But it's possible to start think about more advanced inheritance schemes with intermediate classes between the base class and actual themes. Longer inheritance chains are better, because they emphasize the benefits of inheritance, but as always you have to be careful not to create wrong kind of inheritance.

This is an important change, because Kaduria has also one large Level class and even from this brief experience I can tell inheriting is much better than one class. It took me a long time to realize this, but things sometimes are set a certain way and can stay that way, because it feels like a big task to change it.

Friday 17 June 2016

Cleaning up Teemu

It's surprising that I'm now a better programmer than I was couple of years ago, because I was really great then. When I'm looking at the source code of Teemu I can now see some issues clearly. The main problem is the way classes have functions (and functionality) that belongs to somewhere else. This is often easy to fix and I've been doing some of that already.

Sometimes functions could use another class using two or more classes to modularize classes to do only what they are supposed to do. But in some cases it's probably not that bad, especially in smaller projects like Teemu. Some classes could be broken into smaller ones, but it's not worth the trouble, because often some functionality is used in limited number of places. I've learned to avoid refactoring when weighing the benefits of better source code vs. time spent to fix some minor issue. Everything can be fixed later.

It's also useful to arrange files into small logical groups in the IDE using virtual folders (or filters as Visual Studio is calling them). This is more important in large projects, but it also keeps files in control in small-ish projects like Teemu.

Tuesday 14 June 2016

Teemu news for 2016

After changing Teemu from SDL1.2 to 2.0 I've kind of abandoned it. The main reason is Kaduria, but somehow I also managed to mess up the source code of Teemu too much so now it's in state of minor chaos.

The problem areas in Teemu are message system and Level class. For some reason those two are difficult to get right for me. It's possible to copy some code from Kaduria's message system, but it's much bigger than Teemu's system and not that easy to use. I think it is also a bit different so it's not even possible to use it without changing messages calls.

The least I can do is go through Teemu's source code again and check out the problem areas, then try to figure out what to do with them. In game design I was first planning to change Teemu to become more a sandbox game without "story", but now I'm not so sure about it. I kind of like the adventure game style where you need to find key items to solve other things.

I would hate to leave Teemu in the current release state, because the new stuff I've made (and planning to do) is quite cool.