C++ gdextension code review

Godot Version



Hello guys i wanted tour honest opinion on my spawn ground script how can i optimize, refactor. Im using C++ gdextension. Thanks

Ps: instead of posting the code i made a video, i hope thats not a problem.

1 Like

Neat. Most of my suggestions are related to the style. Classes use PascalCase, so Spawn_ground would be SpawnGround. Functions like getInput in your player.h file use snake_case, so it would be get_input. There’s more, however, it’s better shown. There’s a documentation page on the style. It has a .clang-format file you can use to format your code with.

I learned from reading the official repository. It’s separate from the godot-cpp repository, which mostly contains bindings rather than the full code.

I noticed that your move_and_slide function is in _process, rather than _physics_process. It’s recommended to use functions like these in _physics_process because it’s a physics body movement.

Have you looked into the templates Godot provides? It’s recommended to use those over the data types in STL. Your std::queue may be interchangeable with Godot’s list.

Input is a singleton, so it doesn’t need to have it’s own variable in the Player class. Instead, you can use Input::get_singleton() and it will return the same pointer to Input every time.

1 Like

Thanks, i will try to use some naming convenction for variables, functions etc.
And im going to refactor the queue unto Godot list if possible.

1 Like