TUXDB - LINUX GAMING AGGREGATE
by NuSuey
NEWSFEED
▪️ GAMES
▪️ STEAM DECK ▪️ DEALS ▪️ CROWDFUNDING ▪️ COMMUNITY
tuxdb.com logo
Support tuxDB on Patreon
Currently supported by 9 awesome people!

🌟 Special thanks to our amazing supporters:


✨ $10 Tier: [Geeks Love Detail]
🌈 $5 Tier: [Arch Toasty][Benedikt][David Martínez Martí]

Steam ImageSteam ImageSteam ImageSteam ImageSteam ImageSteam Image
Optimization: what I did to make the game 300 times faster

The first major update for The Sapling, the flower update, was released in September. It adds pollination, flowers (obviously), a new scenario, a complete overhaul of the sandbox level, bioluminescence and much more. This is the trailer: [previewyoutube=_aglK-7GFCI;full][/previewyoutube] Importantly, it addresses a major point of feedback that kept coming back: players wanted more space for their creations to grow and evolve. I couldn't easily make the levels larger, however, because the game already had performance problems in the smaller levels and with each new spot where organisms could live this would get worse exponentially. The hard part is that there are not one, but two computationally heavy things going on at the same time: simulating an ecosystem where hundreds of organisms are all doing their own things (moving, eating, reproducing, mutating) AND visualizing these hundreds of objects. With larger levels, this would be thousands, essentially bringing the game to a halt with 1 frame per 5 seconds (FPS) instead of the regular 60 per 1 second. Besides my obvious desire to please the players, having larger levels was also crucial for my own ambitions with the game, because a number of the simulation mechanics didn't really work with the smaller maps; for example, why evolve an instinct to run away from a predator if you have nowhere to go? Or for plants, why evolve things like bark or high leaves if the biggest reason that your offspring is dying is because all seeds are landing on spots that are already taken? In nearly 100% of the cases, all plants evolved to do was getting as much offspring as possible, in the hopes that at least one of them by accident landed in a spot that was free. In other words, if there was going to be one major feature in the first big update, it should be larger maps. To make this possible, I spent 3 months in the beginning of 2020 with that one focus: optimize, optimize, optimize the game's code, so I could get that FPS up and shave off more of the milliseconds it takes to render a scene. It was frustrating at times, but the main feeling I remember was actually excitement, as this really forced me to investigate the major bottlenecks (when I close my eyes, I can still see the Unity profiler), and come up with several new creative solutions for them. During this period I was reading a book about how John Carmack, the brilliant programmer behind the first Doom engine, was doing endless optimizations to make first person shooters a reality in the 90s, which was a great help in keeping me motivated. While I implemented all kinds of larger and smaller ideas that made significant positive contributions to the performance of the game, there is one insight that had the biggest impact for the visualization part of the problem (how do you show thousands of unique organisms on screen?), which is to **fake it before you make it**. Let's go through my thought process step by step to see what I mean by that in this context. For every step, there is an interactive simulation you can run in your browser, so you can play with the idea yourself.

Step 1: the raw, unoptimized goal


This is the basic idea, without any optimization: players can add their self created species somewhere in the world, and see whether it is strong enough to survive. In the interactive example below, you can add two species, 1 and 2, and then run the simulation.
The simulation and subsequent visualization should be instant in your browser, but this is of course a 2D table with precreated images. When we have to create fully animated 3D models in a 3D world instead, it quickly becomes too much. The main problem is that **building/visualizing an organism in 3D is expensive**. While I have done major rewrites of the code that builds plants and animals, mostly focusing on not doing things twice and skipping parts of the procedure that are not 100% necessary (like building the roots of plants that are underground anyway), creating new organisms from scratch remained, and still is, expensive.

Step 2: object pooling


The textbook solution when a lot of objects need to be created and removed in a game is to use object pooling. The idea is that when an object dies (in The Sapling, quite literally), the game object is not destroyed but reincarnates as the next object that is created, instantly moving to the position of the newborn organism and resetting any animations it was showing. That is, you think you are looking at a large amount of objects being created and destroyed again, but in reality you are looking at a smaller amount of objects that are just changing locations quickly. In the interactive example below, I have added a pool to the right. When plants die, their models are either immediately reused or are stored in the pool until they are needed again, so a lot less 3D models need to be created. Comparing this simulation to the one above, the difference becomes clear when you skip 10 days a few times; in the first simulation, the model identifier (the part below each plant were it says 'model 10', for example) gets higher and higher, while here it stays low, reflecting the small number of 3D models that needed to be created.
Object pooling greatly improves the FPS in a stable ecosystem, as you can simply reuse what you already have and there is no need to create new objects on the fly. Unfortunately, in practice ecosystems in the game are very frequently unstable, most notably in the beginning of every new scenario when there is empty land to colonize. In other words, an object pool is not going to help if that pool is empty... so we'll also need a faster way to fill it.

Step 3: prebuilt organism library


So far, when a plant was not available in the pool, we built it from scratch. If we are building a 3D model that we have built before, however, this is not necessary: why not store an example somewhere and just copy it? This is more expensive than taking an object from the pool, but way cheaper than building it from scratch. In the current example, there is a limited number of species (species 1 and species 2), so that would mean we only have to build a 3D model two times, and then be done with it.
At this point, we will get an acceptable FPS in an ecosystem with a small number of species, and no variation within a species... which is actually the case during the scenarios! In the sandbox mode, however, there is a *random mutations mode* that has a 30% chance of introducing a random change to a newborn plant or animal; that is, for 1 out of 3 newborn plants we won't have anything in the object pool AND the prebuilt organism library, so we're back to building from scratch.

Step 4: faking it and showing ancestors instead


I came up with this final step when actually playing around with the (then still sluggish) random mutations mode in larger levels. The main insight is that in random mutations mode the player has no idea of what something is supposed to look like. For example, if a new plant is a little taller than its ancestors, but this is not shown to the player, will the player ever know? Almost certainly not, in particular if you take into account that the player is often looking at hundreds of plants and animals simultaneously. On the other hand, will the player notice performance problems? Yes, for sure... so a 100% smooth experience should get a higher priority than a 100% accurate visualization. In practice, this means that if random mutation leads to a completely new organism, the game will not automatically build it from scratch, even though it is not in the pool or the library. Instead, it will look at what was shown for the parent and show this as a substitute. Later, when the game has time to breathe, the missing model might be added to the library. The game keeps track which organisms have a 'fake' appearance, and I can vary in how fast gaps in the library should be closed. Right now, I have settled on building a maximum of 1 organism per second. In the simulation below, random mutations are turned on for the first time. This means that after some time you will not only see plants like the ones you added yourself (species 1 and species 2); instead, the number will go up each time a newborn plants changes a little bit from its parent, so after some time you will see species 3, species 4, species 5, etc. The accompanying model, however, will NOT change, meaning that the real plant and its 3D model go out of sync; the name will turn orange if this is the case. So you might see the model of a plant 1, while the text in orange tells you it is actually a plant 3. To catch up, you have to click the 'Add 1 model to library' button.
And this way, we have scaled back from building hundreds of 3D models per second to just one! Of course, there are a number of details, quirks and edge cases that I have left out of the explanation above to keep things simple. Two of them I want to mention to give you a more complete idea of the problem:
  • In the simulation above, whenever you create a new 3D model, it's just the next one in line. In the real game, I'm trying to do this smarter by looking at which organisms are visually the most different from the 3D model they are using. That is, an animal that evolved an extra pair of feet is way more likely to get its model updated than a plant that evolved deeper underground roots.
  • When you leave the simulation running for a longer period of time, hundreds of plant species emerge and go extinct again. This means the pool and library will endlessly grow... until you run out of RAM! To fix this, there is a mechanism that keeps track of which models are no longer used, and destroys them after some time to free up memory.
So, now the game is running at >60 FPS all the time, right? Well... it depends. The performance of the game depends on lots of factors: of course, the hardware plays a huge role, as do the quality settings, and any other things the computer might be doing at the same time. On top of that, it really matters what you are doing in the game: how large is the level, is the simulation sped up or not, how fast do the organisms reproduce, is the game camera close to the ground or not (close means more detail needs to be shown), and do you have random mutations turned on? While on the one hand there are numerous use cases where the game went from 0.5 FPS to 60 FPS, on the other it will definitely still drop below 30 if you are playing the sandbox mode (the largest level) with random mutations on, at the highest time speed, with the camera close to the action, shown on max quality settings, on a laptop. Overall, though, the goal was that most players will have a smooth experience with larger levels, and with the optimizations described above I believe this was well achieved. This is why, after three months, I moved on to creating mechanics that were made possible because of these larger levels, which in turn led to the flower update. The things added in the flower update, in turn, open up a whole world of new possibilities, and I can't wait to share them with you. The next devlog will announce a series of short videos; it will be published around a month from now. Follow The Sapling on Twitter or subscribe to the newsletter if you are interested!


[ 2020-11-03 07:07:56 CET ] [ Original post ]

The Sapling
Wessel Stoop Developer
Wessel Stoop Publisher
2019-12-12 Release
Game News Posts: 69
🎹🖱️Keyboard + Mouse
Very Positive (1251 reviews)
Public Linux Depots:
  • The Sapling Linux [149.82 M]
The Sapling is a short simulation game where you design your own plants and animals, and put them in a world together. Or you turn on random mutations, and see what evolution does to your ecosystem!

Features


  • Design plants and animals.
  • Fast-forward time to and watch the ecosystem work like a charm or slowly fall apart (probably the latter :) ).
  • A sandbox mode where you can skip time and turn on random mutation, allowing true evolution.
  • An instinct system where you can specify what an animal should do when it hears or sees something.
  • A procedural animation system so any animal can perform any animation.
  • Procedural music mixed on the fly.
  • Everything set up to be easily extended by players.

This looks just like Spore!


Wessel Stoop has wanted to play a simulation game where you can build your own plants and animals, put them in a world, and see what happens since 2002. You can imagine his excitement when Will Wright, the father of simulation games, demoed his latest game Spore to an enthusiastic crowd. When Spore turned out to be all game genres except simulation, Wessel decided he wanted to try to make the game by himself. The Sapling is the result of that attempt.

MINIMAL SETUP
  • OS: Ubuntu 16 or newer
  • Processor: A processor with SSE2 instruction set supportMemory: 4 GB RAM
  • Memory: 4 GB RAM
  • Graphics: Graphics card with DX10 (shader model 4.0) capabilities.
  • Storage: 150 MB available space
RECOMMENDED SETUP
  • Memory: 16 GB RAM
GAMEBILLET

[ 6138 ]

4.54$ (35%)
2.00$ (80%)
8.19$ (18%)
3.40$ (83%)
8.66$ (57%)
7.50$ (75%)
8.25$ (17%)
1.24$ (79%)
8.87$ (82%)
5.31$ (73%)
6.75$ (83%)
8.49$ (15%)
3.50$ (65%)
20.99$ (16%)
13.04$ (13%)
8.39$ (16%)
21.24$ (15%)
6.80$ (66%)
12.44$ (17%)
16.00$ (60%)
24.59$ (18%)
9.95$ (75%)
14.95$ (25%)
15.29$ (15%)
4.19$ (16%)
6.00$ (70%)
18.69$ (25%)
0.89$ (70%)
21.24$ (29%)
8.59$ (14%)
GAMERSGATE

[ 3464 ]

3.0$ (85%)
1.2$ (85%)
9.9$ (67%)
10.79$ (28%)
9.0$ (70%)
5.22$ (74%)
3.75$ (85%)
9.59$ (36%)
7.5$ (50%)
5.0$ (75%)
39.99$ (20%)
12.0$ (60%)
1.0$ (80%)
24.0$ (60%)
7.5$ (50%)
0.77$ (74%)
4.37$ (78%)
12.0$ (60%)
0.6$ (85%)
4.0$ (50%)
0.45$ (85%)
17.99$ (28%)
2.5$ (75%)
1.5$ (90%)
0.56$ (81%)
1.94$ (84%)
18.74$ (25%)
5.4$ (64%)
2.2$ (91%)
0.88$ (91%)

FANATICAL BUNDLES

Time left:

5 days, 7 hours, 33 minutes


Time left:

11 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

8 days, 7 hours, 33 minutes


Time left:

33 days, 7 hours, 33 minutes


Time left:

13 days, 7 hours, 33 minutes


Time left:

5 days, 7 hours, 33 minutes


Time left:

40 days, 7 hours, 33 minutes


Time left:

29 days, 7 hours, 33 minutes


Time left:

26 days, 7 hours, 33 minutes


Time left:

34 days, 7 hours, 33 minutes


Time left:

36 days, 7 hours, 33 minutes


HUMBLE BUNDLES

Time left:

0 days, 1 hours, 33 minutes


Time left:

14 days, 1 hours, 33 minutes

by buying games/dlcs from affiliate links you are supporting tuxDB
🔴 LIVE