Hello my MODDERS, MODIFIERS and MODULATORS!!
Last week, after releasing the Android test version, I began working on what was by far the hardest coding problem I've ever tackled for MODIFICATION APP.
In this post, I'll go over the entire ordeal, explaining the problem and the struggle to solve it.
Since this is mostly a coding post - and I'd guess most people don't care about that - here's a quicker TLDR.
Over the past few days, I created a new "Low-Resolution" mode for the game.
This reduces texture sizes in the game, making it run much faster and making it compatible with older/weaker devices.
Other than that, I'm still working on the artwork for the new BE repeatable scenes.
Okay, with the TLDR out of the way, let's start with
The Issue
It all started when I got 3 comments over the span of a few months, claiming that sometimes textures didn't render.
As I usually do, I tried to get more information. While I couldn't determine the cause before, on this last one I identified what these reports had in common.Pretty bad laptops/phones.
But even then, while I understand the game lagging, missing textures was a bit strange.
So I found my very old Android tablet and tried to replicate the issue.
And indeed, I also found missing textures.
However, there was no error.The logs showed nothing.Everything was perfect.Except, you know, Mia's lack of breasts.
After a long investigation, I figured out the issue was most likely somewhere in the GPU.GPUs are little bastards that don't like to send messages, so when a texture fails to render, they don't say anything and hope no one notices.
And so, my theory for why this happened was that the GPU's VRAM (which stores the textures) was hitting a size limit on how many textures it can hold.And while most devices don't go anywhere near this limit, old devices with very limited storage might.And when the VRAM couldn't fit the texture onto it, they would just not render anything.
So, since the issue is: textures too big -> can't fit into VRAM,the solution seemed simple: create a low-resolution mode of the game with smaller textures.
If you've played Mario 64, it's basically the same idea where Mario becomes (even more) low-poly when far away from the camera. But in this case, for textures rather than 3d models.
I mean, surely this isn't a new idea, so someone has probably done something like this before.I mean, how hard could it be...
The hardest thing I've done for MODIFICATION APP.
The first idea to tackle this could be to simply reduce the window size/resolution.But that actually doesn't fix the VRAM issue.
While that makes rendering frames faster, the images still need to be fully loaded into the VRAM to be displayed, so we'd still get the size limit issue.We need to have smaller images.
But there's another issue.Let's say I want to have 2 of the same texture, except one is half the size.
So we have the normal sprite, and if we toggle the low-quality mode, it switches the texture from the normal one to the small one.
If it's half the size, it's gonna look half as big when it's on the game.
So, we could just change the scale of the sprite to 2 instead of 1, right?Well, not easily, because I use scaling for animations, so those would all break.And that wouldn't even work on skeleton animations; everything would be out of place.
And here I was stumped for a long time.I tried many ways to make this work, or to at least find an alternative solution.Time after time, nothing worked.It seemed like there was no way to actually do this.
I just had to accept that this was something the game engine was NOT designed to do....
Funny thing about Godot
Godot is an open-source game engine.This means that anyone can see the source code.
It also means someone could modify the engine code, compile it, and use a modified version of the engine.You'd just have to be a little insane to do that, since it would just be an extremely long and painful process...
...
Horrible Decision
So, being stubborn enough to want to make this work, I went ahead and tried to customize the engine to do what I wanted.
Godot uses C++, a programming language I really don't like, but we gotta work with what we have.
And after a couple of days with very little sleep, I had created an entire custom image importing system for Godot.This allowed me to take pngs, and set a size modifier - meaning that while the png is still half size, in the engine renders it at any size I want.
What's happening behind the scenes is, I'm giving a small image to the GPU, so it takes up less VRAM - and at the same time, when Godot asks me "What was the size of the image you gave to the GPU just now?", I just flat-out lie and say I gave it a much bigger one.
So now I could create a very low-resolution version of all images in the game, set their size modifier so they match the original images, and replace them!!
Here are the results!!(The low-resolution image was taken from my tablet, which was missing the textures in the image above!)
Besides fixing the missing textures, since we're now using much smaller textures, the video memory usage also drops a lot.
To be clear, I don't recommend using this mode, since it naturally makes everything look worse.
But, if you really can't play the game, either because textures don't load or the lag is unbearable, it works well as a last-case option, since having it look very crunchy is better than not running at all.
This option will be available from the settings on the main menu in the next update.
Just to be clear and set future expectations: this is probably the only time I'll be doing a big optimization change like this.The game is not particularly resource-intensive, and with this setting, it should already cover most devices.
And I don't have the time (or will) to try and make the game run on even worse devices.There needs to be a cutoff point.I want to be making sexy drawings and silly minigames, not trying to untangle a bunch of very annoying engine code to try and run this on a toaster.I did this one just because I can now reuse this system for all future projects!!... And because my stubbornness of not wanting to have the game engine tell me that I couldn't do something got the better of me.
Either way, if you stuck around for this whole post, I hope it was clear and an interesting look into the gamedev struggles.This was an incredible pain in the ass to do, and I didn't even talk about switching the actual textures, because that was another can of worms.
The moral of this post: making games is very hard.To no one's surprise.
Either way, I'll go back to the dungeon to continue working on the sexy scenes.I need a break from looking at this ugly ass C++ code.
Ⓣ