So I thought, this sounds like much of the concept from Godot. Why not have look, but I’m a bit overwhelmed with amount of files and not sure if start in core,main, scene or somewhere else to get practice.
Would appreciate any tips where to start as beginner, or if this even make sense to looking in existing code.
It doesn’t for a beginner. I mean, you always can if you’re up for an adventure, but don’t expect to easily understand it. It’s not just the language, you need to have a decent level of knowledge about general computing and computer graphics concepts and other stuff that typically go into an engine. Those things are not related to any specific language.
In any case, better to gain some more experience with C++ fundamentals first by making your own programs and looking at (or compiling/altering) smaller projects on github, within your area of interest.
Godot is a C++ program like any other. It always runs from the first line in int main(int argc, char **argv). Since it can be conditionally compiled for multiple platforms, there is a platform specific main() for each supported platform.
Linux main is in/platform/linuxbsd/godot_linuxbsd.cpp. For windows it’s in /platform/windows/godot_windows.cpp and so on.
Those do some platform specific setup, then call Main::setup() and Main::start(), and finally call platform specific run() that enters engine’s main loop.
As for Main constructors/destructors, there aren’t any because it’s just a static class. All functions there are static so Main basically serves as a mere namespace.
They are right there in main(), at lines 111 and 121.
After those two, it calls OS_LinuxBSD::run() which runs an endless while loop that is engine’s main loop. In simplified terms, an Iteration of this loop runs once per frame until you quit the program.
At a high level, Godot is C++ built around a few core ideas that make it easier to follow than it first looks:
- The SceneTree drives the main loop, and every node is a C++ object. GDScript, C# and GDExtension are scripting layers on top of that object system, so a call you make in script usually ends up in C++.
- Most subsystems are ‘servers’ with a small API: RenderingServer, PhysicsServer and AudioServer. That keeps the editor, the game logic and the platform drivers decoupled from each other.
- Rendering goes through a driver abstraction (Vulkan in Godot 4). Each frame the rendering server turns the scene into draw calls, rather than nodes drawing themselves directly.
- The editor itself is a Godot project built with the same engine, which is why so much of it can be extended with plugins.
If you want to read the source, the folders are a good map: core/ has the object and Variant system, scene/ has the node tree, and servers/ has the low-level subsystems. main/main.cpp is a good starting point, since that is where setup and the main loop live.