Refactoring and future plans

When you play the game, nothing is obvious about how it works in the back, and it never will be. Even for someone with 8 years of experience of making games it’s quite hard to precisely understand every bit of code that’s working.
This is like trying to know how an engine works just by driving a car, won’t happen. You need to open the hood and see for yourself, as well as learn about it by reading or watching material, or having someone teach you.
However, when i opened the hood, the game looked… off. I can navigate through it fine because there aren’t that many files, but some parts of the “engine” are just dirty. So i started cleaning all the obvious bits and pieces. Now there are still some easy places to clean, but they are definitely much harder to find, so i have to come up with new cleaning strategies.
Refactoring
To do it, i first need to understand what’s going on.
What is under the hood?
Let me make a quick drawing:
That big monolith in the middle is the car script. It has absorbed way too much code and is more than 1000 lines long. The whole game is about 4000 lines. That script holds about 25% of the whole game. I have reduced the size of this script by roughly 10% without changing functionality.
The wheel script is another 537 lines as of writing this and it was 616 lines before. Another huge portion of the game.
“The best part is no part.”
The green stuff is what i added to come help with the situation. Especially that Helper script which is part of my work in progress addon.
This isn’t enough, but it’s a good start.
Dependent design
The drawing shows many connections that should not exist or should be in one direction. This means that if i change some code, other code may suddenly break for no reason. Thankfully the game has so far been very nice to me, but i still had some… moments:
The Helper is part of an addon i’m developing separately over here: https://github.com/tomsterBG/short
Having code that connects to my Helper is fine because the Helper is designed for it. Having code that connects left and right is… not fine. Also some places like tire smoke try to go up to its parent tire, then higher to the car and access something from the car. If the smoke is placed somewhere else, that means the code will break. This is one reason why they say “call down, signal up” which basically means a node should only care about itself and its children. This is why if you go to my Short addon, i have put a comment on one function to say “Bad code practice. Nodes should be unaware of their parents.”
Coupling can be fixed in various different ways. Because i’m using Godot, there can be a global autoload for references, however this will only work for specific references that don’t change.
Another way is to use groups, this is way more powerful and well integrated with the game engine.
Groups basically means that i can find any object of any group from wherever i want. If there’s one car in the “car” group, i will find that one car. Easy! If there are more cars, i could add a variable to each car to say if it’s the player car. Oh wait, that already exists, another easy solution!
Future plans
I think everyone can relate if i say that, i’m just a human when it comes to planning. I make things up as i go and it usually doesn’t go as planned, even if it may go close enough sometimes.
However, looking at past experiences i can at least give myself some limits.
6 months
I have never spent more than 6 months on a larger project and given that i recently, less than a year ago, switched from Roblox to Godot, i don’t want to change that limit just now. Spending more on a project will just burn me out and slow the progress of all the good stuff Godot provides for extendable design, given that i am expanding my own addon with each project that i create. Sticking with a project simply slows down the progress of that addon, while making new projects makes it go faster. It is the core foundation of transitive code that i can use between projects, so effectively that means, permanent-ish game dev progress with each project.
Overwhelming
In Roblox, my 6-month projects were done over many years and went from 1000 to 3000 to 10000 lines of code max, which is my record so far. Picking up VitaVehicle and making a line of code counter, i realized that it is already above 4000 lines, which is very overwhelming.
Full output
This is what my code that counts the lines of source code has to say about the size of the project.
Lines of code when i first forked the project:
res://MAIN/car.gd has 1133 lines
res://MAIN/ground_surface_variables.gd has 17 lines
res://MAIN/vitavehicle.gd has 178 lines
res://MAIN/wheel.gd has 617 lines
res://MAIN/misc/camera.gd has 97 lines
res://MAIN/misc/engine sound/crossfade.gd has 95 lines
res://MAIN/misc/forces debug/forces.gd has 24 lines
res://MAIN/misc/mechanical sounds/other_sounds.gd has 192 lines
res://MAIN/misc/tyre marks/trail_clean.gd has 4 lines
res://MAIN/misc/tyre marks/trail_sm.gd has 123 lines
res://MAIN/misc/tyre smoke/tyre_smoke.gd has 95 lines
res://MAIN/misc/tyre sounds/tyres.gd has 108 lines
res://MAIN/misc/tyre sounds/vars.gd has 6 lines
res://MISC/autoload/graphics.gd has 42 lines
res://MISC/car swapper/car swapper.gd has 127 lines
res://MISC/controls config/check_variables.gd has 4 lines
res://MISC/controls config/run.gd has 51 lines
res://MISC/controls config/slider_variables.gd has 4 lines
res://MISC/graph/draw.gd has 95 lines
res://MISC/graphics_config/graphics config.gd has 39 lines
res://MISC/misc scripts/debug.gd has 108 lines
res://MISC/misc scripts/interior_feedback_camera.gd has 23 lines
res://MISC/misc scripts/show_info.gd has 16 lines
res://MISC/misc scripts/sky_setting.gd has 12 lines
res://MISC/mobile controls/mobile_ctrls.gd has 5 lines
res://MISC/mobile controls/positioning.gd has 19 lines
res://MISC/scene swapper/scene swapper.gd has 87 lines
res://MISC/tachometre/tacho.gd has 79 lines
res://MISC/vertical progress bar/bar.gd has 9 lines
res://MISC/visual gravity system/vgs.gd has 72 lines
res://MISC/visual gravity system/wheel_variables.gd has 6 lines
res://addons/vitavehicle_ui/api_references.gd has 283 lines
res://addons/vitavehicle_ui/folds.gd has 30 lines
res://addons/vitavehicle_ui/graph.gd has 94 lines
res://addons/vitavehicle_ui/handler.gd has 209 lines
res://addons/vitavehicle_ui/script.gd has 50 lines
res://addons/vitavehicle_ui/tune_vars.gd has 4 lines
res://disposable/lines of code.gd has 19 lines
38 scripts
4176 lines
Lines of code today:
res://MAIN/car.gd has 1022 lines
res://MAIN/constants.gd has 48 lines
res://MAIN/ground_surface_variables.gd has 16 lines
res://MAIN/vitavehicle.gd has 151 lines
res://MAIN/wheel.gd has 537 lines
res://MAIN/misc/camera.gd has 81 lines
res://MAIN/misc/engine sound/crossfade.gd has 72 lines
res://MAIN/misc/forces debug/forces.gd has 24 lines
res://MAIN/misc/mechanical sounds/other_sounds.gd has 163 lines
res://MAIN/misc/tyre marks/trail_clean.gd has 4 lines
res://MAIN/misc/tyre marks/trail_sm.gd has 117 lines
res://MAIN/misc/tyre smoke/tyre_smoke.gd has 90 lines
res://MAIN/misc/tyre sounds/tyres.gd has 98 lines
res://MAIN/misc/tyre sounds/vars.gd has 6 lines
res://MISC/autoload/graphics.gd has 42 lines
res://MISC/car swapper/car swapper.gd has 108 lines
res://MISC/controls config/check_variables.gd has 4 lines
res://MISC/controls config/run.gd has 56 lines
res://MISC/controls config/slider_variables.gd has 4 lines
res://MISC/graph/draw.gd has 95 lines
res://MISC/graphics_config/graphics config.gd has 39 lines
res://MISC/misc scripts/debug.gd has 104 lines
res://MISC/misc scripts/interior_feedback_camera.gd has 25 lines
res://MISC/misc scripts/show_info.gd has 16 lines
res://MISC/misc scripts/sky_setting.gd has 12 lines
res://MISC/mobile controls/mobile_ctrls.gd has 5 lines
res://MISC/mobile controls/positioning.gd has 19 lines
res://MISC/scene swapper/scene swapper.gd has 86 lines
res://MISC/tachometre/tacho.gd has 78 lines
res://MISC/vertical progress bar/bar.gd has 9 lines
res://MISC/visual gravity system/vgs.gd has 72 lines
res://MISC/visual gravity system/wheel_variables.gd has 6 lines
res://addons/vitavehicle_ui/api_references.gd has 283 lines
res://addons/vitavehicle_ui/folds.gd has 32 lines
res://addons/vitavehicle_ui/graph.gd has 94 lines
res://addons/vitavehicle_ui/handler.gd has 210 lines
res://addons/vitavehicle_ui/script.gd has 49 lines
res://addons/vitavehicle_ui/tune_vars.gd has 4 lines
res://disposable/lines of code.gd has 19 lines
39 scripts
3900 lines
I think this difference is small (6.6%), but also very effective. Especially considering that i learned a lot about the project in the process and improved my addon.
Also i’m not counting any addon code because those are separately developed, except the vitavehicle_ui
addon which came with the game originally. My goal is to move this addon to not be an addon anymore, but for now i have no clear idea on how to do it.
Uni
It may greatly slow my progress down at some point, so if anything happens, it’s most likely either motivation or uni.
Have fun
This game is just open source. I want to learn, you want to play and maybe learn with me, so yeah, do that!
Get Balkan roads
Balkan roads
Realistic car physics for potato computers
Status | In development |
Author | tomsterBG |
Genre | Racing, Simulation |
Tags | Driving |
More posts
- Continue Your Game Jam postmortem2 days ago
- Optimization, motivation and reevaluation29 days ago
- Game jam beginning34 days ago
Leave a comment
Log in with itch.io to leave a comment.