Aug, 25
The joy of cleaning up old code

Between adding features and making other changes visible to the players, I spend quite a bit of time working on the code architecture in KeeperRL. It pays off given the long term nature of the project, and also because working with well designed code simply makes me a happier programmer.

There is a particular bastion of bad design that goes back to the days when KeeperRL was a simple ascii roguelike. All non-moving objects in the game are described by one type of entity, called a square (because each one occupies one square on the grid). There may be only one square at a given position, so when, for example, a chest is placed on a floor, it replaces the floor square. A square is also responsible for tracking any creature that enters its grid cell, and any items that are dropped on it.

When I added the dungeon management features, building and digging was as simple as replacing one square with another. Even cutting trees meant replacing a tree with a tree trunk. When I added graphics to the game (about 10 months into development), the squares had to remember what they replaced and draw that as a background, so you could see the grass under a tree (with ascii you don’t have this problem, as each position is always rendered as one character).

As I was adding features to the game, more logic piled up on top of this design, and it stopped being pretty. The right way to do it was to have another type of entity represent all the objects that can be built, replaced, etc. It would also take care of all interactions between the static object and a creature. The change is not simple though, as a lot of things would be influenced: pathfinding, building, lighting, spreading of fire, etc. On the other hand, there was a solid reason against it: the existing code was already well tested and working.

Until a few weeks ago, when I started implementing manual placement of floors. I wanted to allow replacing the floor under an already existing object, like a door, but the existing design couldn’t handle it. This was the straw that broke the camel’s back, and I went and added the new type of entity, temporarily called “furniture”, although it includes other things, like trees, walls, etc. These existing objects and their functionality needed to be translated to “furniture”, which caused a chain reaction of other necessary changes deep in the game’s internals. The resulting design will be much better, but it will need a lot of testing before it’s released to the public.

Anyway, this is what I’ve been doing in the past week. It’s just an example of what I work on, when I’m not adding new features. If some updates seem to take too long, it’s because I have to embark on this kind of adventures. 🙂

COMMENTS

Home Forums The joy of cleaning up old code

  • You must be logged in to reply to this topic.

 LATEST NEWS

Feb, 29

KeeperRL v1.0 is released!

I'm very proud to announce that KeeperRL v1.0 is out! In addition to being the most important milestone for the game, this is also a huge update with major gameplay additions.... more

Feb, 08

More news on the upcoming v1.0 patch

KeeperRL will leave Early Access in exactly three weeks. The last major patch was released one year ago, so you can imagine that this will be a pretty huge update. In the August... more

Feb, 05

KeeperRL 1.0 will be officially released on February 29th 2024

I have important news for you today. KeeperRL version 1.0 will be officially released on February 29th! More details about the patch will follow, and for now let's celebrate this... more

Aug, 24

Upcoming features in KeeperRL 1.0

In the last news update I revealed that KeeperRL will leave Early Access in the next (major) patch, and that it will bring some big gameplay changes. It's finally time to share... more

Jun, 29

KeeperRL will leave Early Access with the next update

When I launched the Indiegogo campaign to fund KeeperRL nine years ago, I promised a 1.0 release by the end of 2014. This kinda didn't happen, but I've always been committed to... more

 

 PLAYERS SAID

There are no other games out there like KeeperRL. The game is a unique mixture of management, levelling, crafting, constructing, exploring, adventure etc. […] The possibility of interacting with other’s players monumental dungeons turn KeeperRL into one of the most promising games I’ve found.

dbvel

This game is amazing! It’s challenging, fun, unique, and exactly what you might expect it to be. For an early access game it’s incredible. And the thought that there’s more to come thrills me! I can’t wait to see how this awesome game will develop even more.

Avarti

Any time I touch another race, I get bent over like a cheap, overworked sex worker. I love sucking at this game so much.

DaavPuke