-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callbacks to Main::setup()
/ Main::start()
/ Main::cleanup()
, so to allow much freedom to modules.
#1593
Comments
This is needed because of issues like Zylann/godot_voxel#189. Godot 4.0 adds ability to |
Would this also allow my module to register a "process" callback without needing a node in the tree? I have some sort of server which needs to run an update loop like some other servers do (Physics Server, Visual Server) but I could not find a way to insert this within the main loop. |
Yes, you can obtain the SceneTree singleton (into the setup_done callback) and register the function to the process event. In this way your singleton is naturally called each frame or physics frame without the need to use a node. |
Main::setup()
/ Main::start()
/ Main::cleanup()
, so to allow much freedom to modules.
I've noticed there's I suspect that it might not be always thread-safe, so that's where we'd also like to have ability to register process callbacks as well. Due to this, I think that it may be also required to check whether you're inside physics frame with
@AndreaCatania not sure whether I understand this correctly, do you imply that there's some other/existing mechanism already available for registering process callbacks within the engine (just like |
I've implemented this feature here: godotengine/godot#50179 @Xrayez check it, maybe it's cleaner what I meant by checking the code. |
This feature add a mechanism that emits a notification when a specific app lifecycle phase is executed. It call the callback on: - Setup begins (`Main::setup`) LIFECYCLE_PHASE_SETUP_BEGIN - Setup2 begins (`Main::setup2`) LIFECYCLE_PHASE_SETUP2_BEGIN - Setup2 done (`Main::setup2`) LIFECYCLE_PHASE_SETUP2_DONE - Start begins (`Main::start`) LIFECYCLE_PHASE_START_BEGIN - Start done (`Main::start`) LIFECYCLE_PHASE_START_DONE - Cleanup begins (`Main::cleanup`) LIFECYCLE_PHASE_CLEANUP_BEGIN - Cleanup done (`Main::cleanup`) LIFECYCLE_PHASE_CLEANUP_DONE ---- To use it, it's enough to implement the function `void MODULENAME_lifecycle_callback(int);` to `yourmodule/register_types.h` and define the macro: `#define MODULE_MODULENAME_HAS_LIFECYCLE_CALLBACK` For example, if we need to register a new singleton in the GLTF module, we can write the following: ```c++ // .h void gltf_lifecycle_callback(int p_lifecycle_phase); // .cpp void gltf_lifecycle_callback(int p_lifecycle_phase) { switch (p_lifecycle_phase) { case LIFECYCLE_PHASE_STARTUP_BEGIN: // TODO Init here the singleton. break; case LIFECYCLE_PHASE_CLEANUP_BEGIN: // TODO Clear here the singleton. break; } } ``` Implements the proposal: godotengine/godot-proposals#1593 The proposal code is different than this implementation because this code is using the adviced implementation the core dev adviced.
Describe the project you are working on:
I'm working on a game, and I'm creating various C++ modules. Couple of those modules, need to know when the engine setup is over, and so the
SceneTree
or other singletons are ready to be used.Describe the problem or limitation you are having in your project:
Those modules try to connect to some events like
process
and so on, but since the engine is not ready, there is no way to connects to those events. Right now, from theregister_MODULE_types()
it's not possible to know when the engine starts.Describe the feature / enhancement and how it helps to overcome the problem or limitation:
The idea is to add 3 callbacks to the
Main
class:From the
register_MODULE_types()
will be possible to add callbacks in the following way:All the registered callbacks will be called when the setup/start terminates or the cleanup is started.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Right before the
Main::setup2
is done https://github.com/godotengine/godot/blob/master/main/main.cpp#L1719-L1720 the following code is executed:So the modules, will be able to interact with the engine extensively.
If this enhancement will not be used often, can it be worked around with a few lines of script?:
Low level feature.
Is there a reason why this should be core and not an add-on in the asset library?:
Low level feature.
The text was updated successfully, but these errors were encountered: