1. Sweet Transit
  2. News

Sweet Transit News

About Sweet Transit #7

Dynamic Sprite Loading

I wanted to write something more technical for this post. We touched on some parts of the gameplay and what you can expect. My inner dev just wants to talk about struggles and solutions. One of these struggles was finding a solution for future expansion. I wanted to solve the ever-increasing VRAM requirement.


Sweet Transit is an isometric 2D game. That means that everything is images or the correct term would be sprites. Sprites are superior to 3D in terms of performance. I can put as many details as I want into a sprite and that will not influence how hard the GPU needs to work. However, with 3D models you are not limited to a single view angle. If you want to rotate a train then it is simple, just rotate it. In 2D I need to make sure that I have those rotations in sprites. This means that every new train is quite expensive to have. But this is a game about trains and players should not be limited by how many different trains they can have.



With my plan 1.0 should be playable with 4GB of VRAM if all settings are ramped up to the full. Of course, to support the wider audience there are plenty of settings to minimize that requirement. For example, you can change sprite resolution to low, that alone will make the VRAM requirement to about 256MB. Furthermore turning off shadows and other effects, turning on compression can make that requirement below 100MB.



The problem is what happens when people start adding mods or I start creating some DLC. Vanilla sprites are optimized. Wagons for example are symmetrical and use only 64 sprites for 128 rotations. I do not want to add extra requirements like these for making mods, just the option to do them. But at some point even most high-end GPUs will struggle when enough sprites are present. The solution is obvious - streaming. In this case sprite streaming. At the surface it sounds easy enough. Just load sprites that are needed and unload that are not. But with game development it is never as easy as it sounds.

I usually start with my requirements when adding something new. In this case those were:
  • All sprites need to be packed to their atlases.
  • Atlas packing or unpacking should minimally influence performance.
  • Loads sprites fast on HDD.
  • Decided what to load or unload should minimally influence performance.
  • Most of the work done should be done in a separate thread.




In 2D games having sprites in atlases is a huge performance boost due to the cost of draw calls. In Sweet Transit it is a requirement. In some cases there can be around 100k sprites on the screen. If you have a 4k screen and are zoomed out there is a chance that even 200k sprites will be visible. Having so many sprites and a stable 60 fps is not possible without atlases. That means the first step for sprite streaming is solving how to efficiently load and unload those sprites to the atlas.

In 3D games Megatextures are quite popular for loading model textures in one big atlas. It is a solid base. It is balanced around loading square textures in sizes of power of 2. Having this constraint searching for a possible position is really fast. Sprites however have many different variations of sizes. Furthermore unloading sprites leaves unusable spaces that can lead to memory fragmentation problems. I opted for a custom Binary Tree algorithm. It offers fast possible position searches with good unloading and merging options.

To solve fragmentation I divided the atlas into separate smaller regions. If I cannot find a new place to put my sprites I just can unload the least used region. With the region unloaded I can then pack all needed sprites tightly again. To avoid invisible sprites while they are loading I preloaded atlases with downscaled sprites.



The next problem to solve was loading fast on HDD. Standard sprite loading opens the whole image and loads all sprites to the atlas. This solution is only good if all sprites are needed, but that was not the case. For example, we have a train going with its wagons and goods loaded to its destination. Sprite streaming looks at the needed sprite requests and loads 64 rotations for the locomotive, 64 rotations for each wagon, wheels, shadows in all 4 directions for all rotations and so on... In most cases it would load around 2k of sprites when only a handful was needed. If you have a slower CPU or HDD then good luck seeing your sprites.



To solve this problem I made custom-formated sprite files. It is not far off of how zip works. Png files are converted to these custom files during game load. Now when the game runs any specific sprite can be loaded if needed. This was enough to make the HDD happy.

Other problems were trivial to solve and it is really not worth mentioning them. Now a player will be able to load all sprites at once or use sprite streaming. This will allow an even wider range of audience who can enjoy those sweet trains. I am happy with the solution even if it is not perfect. But it was really scary to start given the lack of information and solutions for sprite streaming.


I hope you enjoyed reading about the technical parts. Developing games offers a lot of smaller problems. It is a great feeling when you solve them and get closer to the final game bit by bit. Write a comment if you want to hear about something specific!

About Sweet Transit #6

City Building

This week I wanted to dive into the city-building. In Sweet Transit train management and city-building is the core of the gameplay. Half of the time you will be managing your workforce and their needs. I will divide city building into two parts to keep it short.



The first building will be a village hall. Everything in the village will have to be connected to it. This and some other features will make the expansion more organic. The village hall also acts as a storage to store and distribute goods. To get to your first city you will have to reach the minimum required inhabitants who are happy and taken care of.



Next we have residences. These are the most basic to house laborers. Laborers will be your first people type. They have small needs, pay some tax and require a little to be happy. To reach the full capacity of the residence and increase tax per person you will have to provide it with goods. Without any goods or services provided people eventually will move out.



This brings us to the service buildings. This is a market. It is required by laborers and other production buildings. All service buildings have a limited road reach. Good road planning is needed to make sure that your spending on the upkeep is at the minimum.



On top of it laborers need work to move in. If they are unhappy they will stop paying taxes and will take their time resting after work. With these mechanics rapid expansion is possible only with good planning. Just one missing train can halt your progress.

For example, a train that has potatoes got stuck somewhere. Without potatoes delivered to the village inhabitants will start to move out one by one. This might still be unnoticeable, but eventually, there might not be enough people to go to work. That will halt other production and again fewer goods will be delivered to where they are needed.




Next time we will look deeper into the city building. I still haven't talked about attractiveness, traveling, commercial buildings, production, decorations, connecting stations. Finally, I will leave you with this information. In Sweet Transit you will be building a colony, which means a lot of villages and cities to support one another.

About Sweet Transit #5

Modding

It is time to see what kind of modding there will be. In general most things can be changed. That includes trains, structures, people, map generation, production and so on. I will introduce modding in sections to get the overall look.



Sweet Transit consists of many .define files. In these files you can add, remove or edit definitions. For example, you can add a new train, modify the existing one, create a train from existing trains specifications or even remove a vanilla train. This can be done with any entity in the game and non-destructively.



There will be custom tools and blender scenes to help out with the graphics creation. Dynamic sprite streaming should support a big library of graphics for your modding collections.



Other things that can be changed are day and night cycles, localization, biome generation, sounds, technical camera, build and world settings. But probably the more interesting one is game rules. Game rules control what is unlocked when and how. This way player options will not be limited to the original balancing.



Finally, all shaders are exposed. This will make more technical people happy. On top of that there is a filter system. A filter can be applied to the world only or everything. The main reason for this was to support colorblind people. But as shown above cool effects is a nice extra feature.


In conclusion Sweet Transit can be changed to fit the needs of many. Tutorials and information on how to mod will be provided during early access. Write a comment if you want to hear about something specific!

About Sweet Transit #4

The World

Last time we touched on one part of the gameplay. Now I wanted to talk about where that gameplay will be. Sweet Transit's main game mode will be a sandbox. It will be up to you to create and expand your colony. Random map generation will help to make it more interesting and challenging. Let us look at the tile-based world a bit.



This is the map mode. Going in and out of the map is seamless just by zooming in or out. Something like this will be playable in the demo which is coming in the near future. A tiny 256x256 map with one biome. Biomes will be used to limit resources and what you can build there. On top of that, each tile has resources, fertility and height values. This will impact greatly where you will want your villages and cities placed.



The world consists of three layers. Land, water and mountains. The land is where everything is built. It is limited by water, which is used mostly for crossing and some structures. And there are mountains that are meant to block your building and transportation options. Think of it as a puzzle.



Sweet Transit engine can support up to 4096x4096 maps. I doubt that anyone will have the time to play on such a big map. In case people get bored of the default generation then modding should help. Map generation is done using a nodes system. Similar to how photoshop manages layers. For example, creating maps based on real world is quite easy.




Here is a coal mine that was recently made. I feel proud of this shack. Next time I am planning to talk either about trains more or about the modding system. Write a comment if you want to hear about something specific!

About Sweet Transit #3

The Warehouse

This week let's take a look at the gameplay a bit. In Sweet Transit you will be building a colony. That means building villages to attract new people. Building farms and factories to take care of those people. Using trains to transfer and support your infrastructure. And then there is a warehouse in the center of it all. It will be the first structure you will build. Hopefully in a good location also.



Warehouse stores building goods for expansion and upkeep. To build anything you will need goods such as wood. Producing wood in the sawmill is not enough. It needs to be transferred to the warehouse. That means that there is going to be a lot of traffic heading towards it. Good planning will be essential.



The warehouse can be expanded and multiple stations can be connected. But there is a catch! There can only be one. This will be a challenge throughout the whole gameplay. Optimization and refinement will be your closest friend to make sure that goods are being delivered.




This is only one challenge of many that will test your planning skills. Sweet Transit is not intended to be a hardcore game with a strict way to play. But each system will make sure that your gears are turning. Write a comment if you want to hear about something specific!