-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Based on top of the GDExtensionLoader PR: #91166 * Add a new GodotInstance GDCLASS that provides startup and iteration commands to control a Godot instance. * Adds a libgodot_create_godot_instance entry point that creates a new Godot instance and returns a GodotInstance object. * Adds a libgodot_destroy_godot_instance entry point that destroys the Godot instance. * Allow specifying an external native rendering surface handle to render Godot into the UI of a host application. * It is also possible to embed multiple Godot windows into the UI of a host application. * Currently supported on MacOS and iOS Sample Apps: https://github.com/migeran/libgodot_project Developed by [Migeran](https://migeran.com) Sponsors & Acknowledgements: * Initial development sponsored by [Smirk Software](https://www.smirk.gg/) * Rebasing to Godot 4.3 and further development sponsored by [Xibbon Inc.](https://xibbon.com) * The GDExtension registration of the host process & build system changes were based on @Faolan-Rad's LibGodot PR: #72883 Co-Authored-By: Gabor Koncz <gabor.koncz@migeran.com>
- Loading branch information
Showing
91 changed files
with
2,854 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/**************************************************************************/ | ||
/* gdextension_function_loader.cpp */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#include "gdextension_function_loader.h" | ||
#include "core/config/project_settings.h" | ||
#include "gdextension.h" | ||
|
||
Error GDExtensionFunctionLoader::open_library(const String &p_path) { | ||
ERR_FAIL_COND_V_MSG(!p_path.begins_with("libgodot://"), ERR_FILE_NOT_FOUND, "Function based GDExtensions should have a path starting with libgodot://"); | ||
ERR_FAIL_COND_V_MSG(!initialization_function, ERR_DOES_NOT_EXIST, "Initialization function is required for function based GDExtensions."); | ||
|
||
library_path = p_path; | ||
|
||
return OK; | ||
} | ||
|
||
Error GDExtensionFunctionLoader::initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) { | ||
ERR_FAIL_COND_V_MSG(!initialization_function, ERR_DOES_NOT_EXIST, "Initialization function is required for function based GDExtensions."); | ||
GDExtensionBool ret = initialization_function(p_get_proc_address, p_extension.ptr(), r_initialization); | ||
|
||
if (ret) { | ||
return OK; | ||
} else { | ||
ERR_PRINT("GDExtension initialization function for '" + library_path + "' returned an error."); | ||
return FAILED; | ||
} | ||
} | ||
|
||
void GDExtensionFunctionLoader::close_library() { | ||
initialization_function = nullptr; | ||
library_path.clear(); | ||
} | ||
|
||
bool GDExtensionFunctionLoader::is_library_open() const { | ||
return !library_path.is_empty(); | ||
} | ||
|
||
bool GDExtensionFunctionLoader::has_library_changed() const { | ||
return false; | ||
} | ||
|
||
void GDExtensionFunctionLoader::set_initialization_function(GDExtensionInitializationFunction p_initialization_function) { | ||
initialization_function = p_initialization_function; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/**************************************************************************/ | ||
/* gdextension_function_loader.h */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#ifndef GDEXTENSION_FUNCTION_LOADER_H | ||
#define GDEXTENSION_FUNCTION_LOADER_H | ||
|
||
#include "core/extension/gdextension_loader.h" | ||
#include "core/os/shared_object.h" | ||
#include <functional> | ||
|
||
class GDExtension; | ||
|
||
class GDExtensionFunctionLoader : public GDExtensionLoader { | ||
friend class GDExtensionManager; | ||
friend class GDExtension; | ||
|
||
private: | ||
String library_path; | ||
GDExtensionInitializationFunction initialization_function = nullptr; | ||
|
||
public: | ||
Error open_library(const String &p_path) override; | ||
Error initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) override; | ||
void close_library() override; | ||
bool is_library_open() const override; | ||
bool has_library_changed() const override; | ||
|
||
void set_initialization_function(GDExtensionInitializationFunction initialization_function); | ||
}; | ||
|
||
#endif // GDEXTENSION_FUNCTION_LOADER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/**************************************************************************/ | ||
/* godot_instance.cpp */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#include "godot_instance.h" | ||
#include "core/extension/gdextension_manager.h" | ||
#include "main/main.h" | ||
#include "servers/display_server.h" | ||
|
||
void GodotInstance::_bind_methods() { | ||
ClassDB::bind_method(D_METHOD("start"), &GodotInstance::start); | ||
ClassDB::bind_method(D_METHOD("is_started"), &GodotInstance::is_started); | ||
ClassDB::bind_method(D_METHOD("iteration"), &GodotInstance::iteration); | ||
} | ||
|
||
GodotInstance::GodotInstance() { | ||
} | ||
|
||
GodotInstance::~GodotInstance() { | ||
} | ||
|
||
bool GodotInstance::initialize(GDExtensionInitializationFunction p_init_func) { | ||
GDExtensionManager *gdextension_manager = GDExtensionManager::get_singleton(); | ||
GDExtensionConstPtr<const GDExtensionInitializationFunction> ptr((const GDExtensionInitializationFunction *)&p_init_func); | ||
GDExtensionManager::LoadStatus status = gdextension_manager->load_function_extension("libgodot://main", ptr); | ||
return status == GDExtensionManager::LoadStatus::LOAD_STATUS_OK; | ||
} | ||
|
||
bool GodotInstance::start() { | ||
Error err = Main::setup2(); | ||
if (err != OK) { | ||
return false; | ||
} | ||
started = Main::start() == EXIT_SUCCESS; | ||
if (started) { | ||
OS::get_singleton()->get_main_loop()->initialize(); | ||
} | ||
return started; | ||
} | ||
|
||
bool GodotInstance::is_started() { | ||
return started; | ||
} | ||
|
||
bool GodotInstance::iteration() { | ||
DisplayServer::get_singleton()->process_events(); | ||
return Main::iteration(); | ||
} | ||
|
||
void GodotInstance::stop() { | ||
if (started) { | ||
OS::get_singleton()->get_main_loop()->finalize(); | ||
} | ||
started = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.