Brass Watch Games

Shipyard Remake: Friendship ended with Java, now C++ is my best friend

by Jonah on June 30, 2018

When I started the original Shipyard, I only knew how to program in Java, a language which makes it very easy to slap together something basically functional but not particularly efficient. This was only exacerbated by my lack of experience. To pick one of many examples, the game’s graphics were done entirely with Java’s built-in graphics and user interface library. This relies entirely on “software rendering,” or performing graphics calculations on the CPU instead of the graphics card, which means the CPU has to do two jobs while the graphics card sits idle, its potential wasted. I didn’t understand this at the time, naively assuming that the computer “just knew” what part of the code did the graphics and assigned it to the graphics card. This poor use of resources limited how many objects could be on screen at once and how complicated they could be. The big-pixel retro style, originally a stylistic choice, increasingly became necessary to cut down on complexity and get a smooth frame rate.

The new game will be written in C++ instead of Java, using a free library called SFML (the same one I used to make that 2D tank game for school back in the day) to handle the graphics. SFML uses the computer’s hardware more efficiently allowing it to draw much more complex graphics and still run more smoothly than the old game. Here’s just one example, using a shader (a small program that runs on the graphics card) to simulate lighting on a shape in real time, regardless of what direction it’s facing:

On the top left is the base color, or what the shape would look like if it was perfectly lit from every angle. Right of that is the “normal map,” which tells the shader what direction each pixel is facing by representing X, Y, and Z coordinates with the red, green, and blue channels of a color. On the bottom is the final product, which as you can see stays lit from the top even as it rotates continuously.

In this picture I’m using a more complicated shader to do several things which had to be done manually in the old Shipyard:

  • Determining the silhouette of the exterior based on the interior plan of the ship
  • Creating the “bevel” effect on the systems that don’t have an exterior design
  • Applying lighting to the ship to make it look three-dimensional
  • Drawing a black outline around the whole thing

What this means for you, the player, is that instead of having to manually place both the interior systems and exterior tiles, all you do is place the systems and the game automatically creates the exterior from that. Of course, this does limit your creative freedom over the style of the exterior, but I have some plans to remedy that which I’ll discuss in future posts.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.