Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 21 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ env.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix

env.__class__.add_shared_library = methods.add_shared_library
env.__class__.add_library = methods.add_library
env.__class__.add_program = methods.add_program
env.__class__.CommandNoCache = methods.CommandNoCache
env.__class__.Run = methods.Run
env.__class__.disable_warnings = methods.disable_warnings
Expand Down Expand Up @@ -204,6 +203,15 @@ opts.Add(("accesskit_sdk_path", "Path to the AccessKit C SDK", ""))
opts.Add(BoolVariable("sdl", "Enable the SDL3 input driver", True))

# Advanced options
opts.Add(
EnumVariable(
"library_type",
"Build library type",
"executable",
("executable", "static_library", "shared_library"),
)
)
opts.Add(BoolVariable("external_target", "Enable external target rendering", False))
opts.Add(
BoolVariable(
"dev_mode", "Alias for dev options: verbose=yes warnings=extra werror=yes tests=yes strict_checks=yes", False
Expand Down Expand Up @@ -330,6 +338,18 @@ if env["import_env_vars"]:

# Platform selection: validate input, and add options.

if env["external_target"]:
env.Append(CPPDEFINES=["EXTERNAL_TARGET_ENABLED"])

if env["library_type"] == "static_library":
env.Append(CPPDEFINES=["LIBGODOT_ENABLED"])
elif env["library_type"] == "shared_library":
env.Append(CPPDEFINES=["LIBGODOT_ENABLED"])
env.Append(CCFLAGS=["-fPIC"])
env.Append(STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME=True)
else:
env.__class__.add_program = methods.add_program

if not env["platform"]:
# Missing `platform` argument, try to detect platform automatically
if (
Expand Down
5 changes: 5 additions & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const PackedStringArray ProjectSettings::get_required_features() {
// Returns the features supported by this build of Godot. Includes all required features.
const PackedStringArray ProjectSettings::_get_supported_features() {
PackedStringArray features = get_required_features();

#ifdef LIBGODOT_ENABLED
features.append("LibGodot");
#endif

#ifdef MODULE_MONO_ENABLED
features.append("C#");
#endif
Expand Down
6 changes: 6 additions & 0 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,8 @@ TypedArray<Dictionary> ClassDB::class_get_method_list(const StringName &p_class,
#else
Dictionary dict;
dict["name"] = E.name;
dict["is_static"] = E.is_static;
dict["hash"] = E.hash;
ret.push_back(dict);
#endif // DEBUG_ENABLED
}
Expand Down Expand Up @@ -2281,6 +2283,10 @@ EngineDebugger::~EngineDebugger() {
::EngineDebugger::unregister_message_capture(E.key);
}
captures.clear();

if (singleton == this) {
singleton = nullptr;
}
}

void EngineDebugger::_bind_methods() {
Expand Down
30 changes: 30 additions & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class ResourceLoader : public Object {
Vector<String> list_directory(const String &p_directory);

ResourceLoader() { singleton = this; }

~ResourceLoader() {
if (singleton == this) {
singleton = nullptr;
}
}
};

class ResourceSaver : public Object {
Expand Down Expand Up @@ -118,6 +124,12 @@ class ResourceSaver : public Object {
ResourceUID::ID get_resource_id_for_path(const String &p_path, bool p_generate = false);

ResourceSaver() { singleton = this; }

~ResourceSaver() {
if (singleton == this) {
singleton = nullptr;
}
}
};

class Logger : public RefCounted {
Expand Down Expand Up @@ -383,6 +395,12 @@ class Geometry2D : public Object {
TypedArray<Point2i> bresenham_line(const Point2i &p_from, const Point2i &p_to);

Geometry2D() { singleton = this; }

~Geometry2D() {
if (singleton == this) {
singleton = nullptr;
}
}
};

class Geometry3D : public Object {
Expand Down Expand Up @@ -414,6 +432,12 @@ class Geometry3D : public Object {
Vector<int32_t> tetrahedralize_delaunay(const Vector<Vector3> &p_points);

Geometry3D() { singleton = this; }

~Geometry3D() {
if (singleton == this) {
singleton = nullptr;
}
}
};

class Marshalls : public Object {
Expand Down Expand Up @@ -640,6 +664,12 @@ class Engine : public Object {
#endif

Engine() { singleton = this; }

~Engine() {
if (singleton == this) {
singleton = nullptr;
}
}
};

class EngineDebugger : public Object {
Expand Down
8 changes: 7 additions & 1 deletion core/core_string_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ class CoreStringNames {
inline static CoreStringNames *singleton = nullptr;

public:
static void create() { singleton = memnew(CoreStringNames); }
static void create() {
if (singleton == nullptr) {
singleton = memnew(CoreStringNames);
}
}
static void free() {
#ifndef LIBGODOT_ENABLED
memdelete(singleton);
singleton = nullptr;
#endif
}

_FORCE_INLINE_ static CoreStringNames *get_singleton() { return singleton; }
Expand Down
75 changes: 75 additions & 0 deletions core/extension/gdextension_function_loader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**************************************************************************/
/* 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;
}

bool GDExtensionFunctionLoader::library_exists() const {
return true;
}

void GDExtensionFunctionLoader::set_initialization_function(GDExtensionInitializationFunction p_initialization_function) {
initialization_function = p_initialization_function;
}
56 changes: 56 additions & 0 deletions core/extension/gdextension_function_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**************************************************************************/
/* 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. */
/**************************************************************************/

#pragma once

#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;
bool library_exists() const override;

void set_initialization_function(GDExtensionInitializationFunction initialization_function);
};
11 changes: 10 additions & 1 deletion core/extension/gdextension_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "gdextension_manager.h"

#include "core/extension/gdextension_function_loader.h"
#include "core/extension/gdextension_library_loader.h"
#include "core/extension/gdextension_special_compat_hashes.h"
#include "core/io/dir_access.h"
Expand Down Expand Up @@ -114,7 +115,14 @@ GDExtensionManager::LoadStatus GDExtensionManager::load_extension(const String &

Ref<GDExtensionLibraryLoader> loader;
loader.instantiate();
return GDExtensionManager::get_singleton()->load_extension_with_loader(p_path, loader);
return load_extension_with_loader(p_path, loader);
}

GDExtensionManager::LoadStatus GDExtensionManager::load_function_extension(const String &p_path, GDExtensionConstPtr<const GDExtensionInitializationFunction> p_init_func) {
Ref<GDExtensionFunctionLoader> func_loader;
func_loader.instantiate();
func_loader->set_initialization_function((GDExtensionInitializationFunction) * (p_init_func.data));
return load_extension_with_loader(p_path, func_loader);
}

GDExtensionManager::LoadStatus GDExtensionManager::load_extension_with_loader(const String &p_path, const Ref<GDExtensionLoader> &p_loader) {
Expand Down Expand Up @@ -454,6 +462,7 @@ GDExtensionManager *GDExtensionManager::get_singleton() {

void GDExtensionManager::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_extension", "path"), &GDExtensionManager::load_extension);
ClassDB::bind_method(D_METHOD("load_function_extension", "path", "init_func"), &GDExtensionManager::load_function_extension);
ClassDB::bind_method(D_METHOD("reload_extension", "path"), &GDExtensionManager::reload_extension);
ClassDB::bind_method(D_METHOD("unload_extension", "path"), &GDExtensionManager::unload_extension);
ClassDB::bind_method(D_METHOD("is_extension_loaded", "path"), &GDExtensionManager::is_extension_loaded);
Expand Down
4 changes: 4 additions & 0 deletions core/extension/gdextension_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#pragma once

#include "core/extension/gdextension.h"
#include "core/variant/native_ptr.h"

GDVIRTUAL_NATIVE_PTR(GDExtensionInitializationFunction)

class GDExtensionManager : public Object {
GDCLASS(GDExtensionManager, Object);
Expand Down Expand Up @@ -66,6 +69,7 @@ class GDExtensionManager : public Object {

public:
LoadStatus load_extension(const String &p_path);
LoadStatus load_function_extension(const String &p_path, GDExtensionConstPtr<const GDExtensionInitializationFunction> p_init_func);
LoadStatus load_extension_with_loader(const String &p_path, const Ref<GDExtensionLoader> &p_loader);
LoadStatus reload_extension(const String &p_path);
LoadStatus unload_extension(const String &p_path);
Expand Down
Loading
Loading