Hi. Today's devlog will be about optimization.
As you know, optimization is a strange word that everyone talks about as if they know how it works. If the game lags, it means that it is poorly optimized and it means that the developer did a bad job.
But do you know what exactly needs to be done for optimization? Do not load textures that are not currently displayed? Do not insert code into the Update/Process functions that are called every frame? Does this really perform the desired task?
You can and should optimize the game, but even an optimized game will lag and not start on your device if it is new. Why is that? Why does my pixel game, which should not load the system at all, lag or run poorly on old devices?
Now I will show you something that I realized when I started digging into how Godot works and what is really happening.
Life with the Tribe is a pixel game and it is itself quite highly optimized. Here's what happens if I run a scene from the game:
The total load on VRAM is only 226 MB, RAM is occupied by 133 MB. This is actually very little and almost nothing. Your browser loads the system many times more. But for some reason, a lot of people wrote to me that they could not run the game.
The whole problem was that Godot from new versions (4.0+) started using Vulkan, and many old devices (and not the oldest Intel processors with integrated graphics) simply cannot work with it. Old devices do not support this and even a game like mine will not work with them.
Of course, there is a workaround and this is the command that fits into the game shortcut to run it using OpenGL "--rendering-driver opengl3".
It's easy to do, add a command and the game will work without problems, but unfortunately people are now used to the most comfortable conditions and if the game doesn't run on their grandmother's laptop, then the game is not optimized and generally crap.
Honestly, it pisses me off a little, that's why I didn't make updates with a different renderer for my game. Sorry, but to enter one command that was mentioned more than 100 times in the comments and even the error that pops up says what to do! Do you know how to read?! Phew... but I still put up with it. And now I'm doing it so that even the oldest hardware can run my game.
But this doesn't look like optimization, it's just debugging an error! Yes, you're right, but at the same time optimization is about making your game playable on all possible devices and characteristics. As strange as it may be, most of you think that games nowadays can safely use up to 4-8 gigs of VRAM (voting from Discord)
But as you saw earlier, my game doesn't consume nearly that much. And the most interesting thing is that I didn't even think about optimizing the load on VRAM back then. After all, the game is pixel-based and shouldn't load VRAM like that at all? Haha... Unfortunately, no.
The most interesting thing is that the load on VRAM is a rather specific thing. I thought that if a file with textures size about 20-40 KB, then how much VRAM will it consume, but in reality it is not. Here is an example of the main character's sprite sheet:
As you can see, the difference is huge! But anyway, 1MB doesn't seem like such a problem. But let's look at Demonetta and her sprite sheet for just one animation:
There is already a 10-fold increase. But still 10 MB is not such a big problem. And if there are 10 such scenes at the same time? Then 100 MB goes to VRAM. Not counting their rendering which also clogs VRAM, we will rise to the level of the game Life with a Tribe. But this is only animation, you also need to load other textures, shaders and the like.
But still this maximum will be somewhere up to 1 Gig of VRAM if I load all the scenes at the same time. And yes, it is not optimized at all, but a pixel game can eat up quite a lot even like that if it is not controlled.
What about optimization then? Well, I honestly did not think that it was needed. 1 Gigabyte of VRAM is not so much if you take even old video cards. But I decided to make the game possible for playing on phones ... and this requires the most correct use of resources.
The VRAM optimization itself seems quite simple. Just do not load everything at the same time. And in fact, this will be enough to reduce the load several times. But if you want REAL optimization, you will have to manage how exactly the textures are removed, how they are loaded, etc. In fact, I have been a little busy with this and optimized my customization system.
I managed to reduce the load from it from 10 MB in one scene to 3 MB, since all the customization textures were previously loaded at the same time when the scene was created, and now only references to the textures are stored and loading occurs only when needed.
And this approach actually applies to everything that can be optimized. Don't load everything at once, don't load the system when it is not necessary, look for workarounds. Code, texture loading, rendering, etc. If you follow the principle of "don't run everything at the same time" in game development, you can easily have an optimized product. Although there will always be people who will have specific conditions from which your product will lag.