Fleet Battles User Interface

Progress on Fleet Battles

Fleet Battles is what I’m naming the miniature game that I’m making to realise the fleet warfare aspect of the game. I’m also doing it so that I actually complete something and hopefully gain some learning from it to then proceed with the rest of The Last Boundary.

I’m sort of thinking that I may end up with several games, but that’s far into the future.

Anyway, I decided that the UI I had created looked a little sad; so I’ve been working in GIMP to make a new one. The result required some reworking of my UI code to incorporate the new bits and bobs but I think it looks pretty good so far.

Fleet Battles title and UI
New UI and Title Screen

The title could probably use some work; but I’m far from a designer. So it’ll probably stay like that.

Gameplay The Last Boundary

A Change of Pace

I’ve taken a few nights off coding to start thinking about game design for the fleet battles. I want to just start with probably a fleshed out game revolving around just the fleet battles.

There probably won’t be too much “game” in this game as fleet battles are not determined much by the player, but only influenced. What it will do is let me see how this influences affect the course of a battle.

So I’ve got a big spreadsheet with numbers and formulas to start working it all out. It’s beginning to come together nicely, especially the way a ship is fitted-out.

Graphics The Last Boundary User Interface

More UI work completed

I’ve done a bit of refactoring of my UI code and brought it down a few hundred lines of code.

I’ve also started noting the performance. Right now, a window with a table and a bit of text and another window with just text gets me around 500-550 fps. This is from a base of about 2500 (if nothing is being drawn to the screen).

I have no idea if this is acceptable or not. In contrast, my scene with a sun and an earth runs at about 200-250 fps. The thing is; I’m doing things in the most inefficient way.

So; I put some work into speeding up the code. Everything in the UI uses a single shader for one. Next is to get everything to use a single VBO; it’s not doing that now because my text quads are drawn with position info in the vertices, whereas everything else uses a translation and scale matrix to define the position.

If they both use the translation matrix, I can remove any need to bind different buffers between calls. This should make things faster.

Also, everything at the moment binds it’s texture. However everything uses the same texture (except text); so I may be able to remove the  glBindTexture calls for a lot of the time. Probably via a texture manager or something.

If it’s still not fast enough; I’ve been reading about instance drawing and also about using textures to hold position info (R,G is x,y and B,A is w,h). I think I can combine these so that my gl_InstanceID in the vertex shader is my lookup into the texture of position info. I’d probably also need a second texture to hold UV coords seeing as these don’t change much either (textures rather than providing a lookup array to the shader, only because that would need to be updated and passed each frame anyway).

Here’s a picture:

SpaceEngineUI 2015-01-02 23-16-02-99

The Last Boundary

Gameplay thoughts

I realise that I should have spent a little more time fleshing out the gameplay on paper, maybe even putting numbers into spreadsheets to see how the equations work out. But I didn’t.

I’m currently in a game of Hearts of Iron 3 and I’ve realised a few things.

The Last Boundary User Interface


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.

Graphics The Last Boundary User Interface

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.

The Last Boundary User Interface

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.

The Last Boundary

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…

The Last Boundary User Interface

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”.

The Last Boundary User Interface

Table Layout 80% done

I spent the bulk of my available time this weekend writing the code for the Table Layout. It ended up quite a bit different from the design; chiefly because I found there was no need for an abstract row. The TableLayout class itself handles all the row…ing.

I just need to add some things like cellpadding, cellspacing, rowspan and colspan. Maybe some method to draw borders; though I might use a specialised DataTable class for that.

TableLayout is working
TableLayout is working