Refactoring

I’ve been without the internet for a little while so I spent a good part of that time refactoring some of the UI code.

I quickly identified a distinction between widgets that hold a single other widget, and widgets that contain many other widgets. These are Containers vs Layouts. Obviously a widget that holds one other widget is a container, something that holds many widgets only does so for the sole purpose of positioning them, therefore it’s a layout.

This brings me a Container class that the Window now inherits from. Containers don’t seem to have a clear way of doing a hierarchy as each positions them differently. The two I have now, a Tetris like stack that I call Box (I might rename it to TetrisLayout) and TableLayout don’t even store their widgets in the same manner.

The UI code is really starting to look slick. It’s actually got more code than the current state of the graphics engine and more than 4x the code of any of the celestial mechanics and AI stuff I’ve already done.

Scrolling Box Complete

I’m pretty sure I’m now 99% complete with the scrolling boxes. There were a couple of bugs; one which was interesting.

Because the  box essentially draws its contents onto a render texture, the render texture created is the size of the screen. Then, as the box is scrolled, basically the region of this texture that’s then drawn to the boxes quad is updated.

What I found was that I was drawing the contents at normal window position on this texture. So a box close to the edge of the screen would result in the contents being partially drawn offscreen. Which is fine. Until you scroll and then the “region” of the texture you’re drawing is actually not on the texture. Graphical glitch.

Easy fix was to just draw to 0,0 on the texture and accommodate this in the region calculation. It also means that I can use a much smaller texture; probably the size of the widget contents. However, there would be a problem if that widget changed it’s size, I would then need to regenerate the texture, or resize it; and I’m concerned about the overhead needed. For now the screen dimensions cover all possible cases, so I’m using it until there’s performance problems.

I’ve also enabled mouse wheel and touch-pad scrolling via SDL2. So that’s pretty handy, makes it much more usable. I’m basically trying to recreate everything that people are used to.

Scrolling boxes

It’s badly coded and needs some fixing up; but it works:

Scrollbars working
Scrollbars working

I’ve also been working on documentation of the UI system and need to complete that. It took far too long to complete the above because I had to keep going back over code to figure out what it was meant for.

Emergent Gameplay

I was reading a very very long AAR that begins with the original Crusader Kings and it got me thinking about emergent gameplay. In short I think of it like things happen in the game that the developer/designer never outright sort to accomplish, but rather it occurred simply because the game is structured in such a way that it can. On it’s own.

For example, in the linked AAR, there’s all sorts of things happening that are sort of emergent. You piss off a vassal and then later he revolts. Now; that may not seem emergent but consider: You grant title to someone else and you piss off a vassal who has a claim there. Then later; when the man you gave the title to begins to dislike you due to the size of your demesne, he concocts a plot with your spiteful wife to kill you; and it only succeeds because they can draw your pissed off vassal into the plot as well.

That’s emergent. Games like Dwarf Fortress definitely show emergent gameplay. These are the sort of games that inspire my own; and so I’m thinking about it’s inclusion.

So obviously, I can just program in emergence. Instead I need to program the game mechanics in such a way that it’s very very hard to predict how all the bits and pieces will affect each other. This allows these bits and pieces to affect each other in a consistent manner, with affects flowing on. And these affects aren’t always known from the outset of a decision by the player.

Nothing that I have planned features this to a large degree. Sure, the economy affects the budget affects the military; but these are known affects to the player. If I increase research budget I get more theoretical knowledge; this helps practical knowledge, this produces new technologies for my military. So I need something more.

When I look at both Dwarf Fortress and Crusader Kings I see the following:

  • The “emergent” behaviour is seen from characters
  • The game is in a large part organised around the characters
  • The “emergent” behaviour comes from interactions between characters

When I then look at something like Hearts of Iron; there is no emergent behaviour and the game is very little reflective of characters. But this also leads me to a revelation; the game must be completely open for emergent behaviour to be seen and for it to make sense. So, in HOI3 for example, the Commanders don’t show any behaviour, just aptitude for warfare, and you put then in a place where their skillset is most useful. But they are unable to defect; ignore orders or anything like that. This is because the game is very narrowly focused, and for good reason, mostly because of the historical accuracy, you can’t have people off doing whatever they want.

The Last Boundary is focused toward a long time span, and a high level. So it’s hard to find somewhere where I can put the ability of having emergence…

Table Layout 99% Complete

It can never truly be 100% complete; but it’s pretty close. Cellpadding and cellspacing are in place as well as options to draw the borders. Elements are also positioned within their cell.

Table Layout 99% complete
Table Layout 99% complete

Now that I’ve got some way to position elements I can start working on text boxes; then the very tricky scrollbars.

I haven’t planned these out; but I think scrollbars need to handle a single…. Box, or Cell element. Every frame, the contents of the box or cell will need to be drawn to a texture, and then only the visible part of the texture is drawn to the destination; the scrollbar would adjust the region drawn. I can’t think of another way to hide the parts that are “offscreen”.