Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add godot-sandbox as a module.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Nov 3, 2024
1 parent 44dd36d commit 5153d35
Show file tree
Hide file tree
Showing 36 changed files with 155 additions and 0 deletions.
39 changes: 39 additions & 0 deletions godot/modules/sandbox/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

Import("env")
Import("env_modules")

def get_sufix():
suffix = ".{}.{}".format(env["platform"], env["target"])
if env.dev_build:
suffix += ".dev"
if env["precision"] == "double":
suffix += ".double"
suffix += "." + env["arch"]
if not env["threads"]:
suffix += ".nothreads"
return suffix.replace("editor", "template_release")

# Libraries
if env["platform"] == "macos" or env["platform"] == "ios":
base_path = "#modules/sandbox/bin/addons/godot_sandbox/bin/libgodot_riscv{}.framework".format(get_sufix())
base_file = "libgodot_riscv{}".format(get_sufix())
else:
base_path = "#modules/sandbox/bin/addons/godot_sandbox/bin"
base_file = "libgodot_riscv{}".format(get_sufix())

env.Append(LIBS=[base_file])
env.Append(LIBPATH=[base_path])

# Godot-cpp
base_path = "#modules/sandbox/ext/godot-cpp/bin"
base_file = "libgodot-cpp{}".format(get_sufix())

env.Append(LIBS=[base_file])
env.Append(LIBPATH=[base_path])

# Sources
env_gdextension = env_modules.Clone()

env_gdextension.add_source_files(env.modules_sources, "*.cpp")
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions godot/modules/sandbox/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def can_build(env, platform):
return True


def configure(env):
pass
41 changes: 41 additions & 0 deletions godot/modules/sandbox/gdextension_static_library_loader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "gdextension_static_library_loader.h"

#include "core/config/project_settings.h"
#include "core/io/dir_access.h"
#include "core/version.h"
#include "core/extension/gdextension.h"

Error GDExtensionStaticLibraryLoader::open_library(const String &p_path) {
library_path = p_path;
return OK;
}

Error GDExtensionStaticLibraryLoader::initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) {

GDExtensionInitializationFunction initialization_function = (GDExtensionInitializationFunction)entry_funcptr;
if (initialization_function == nullptr) {
}
GDExtensionBool ret = initialization_function(p_get_proc_address, p_extension.ptr(), r_initialization);

if (ret) {
return OK;
} else {
ERR_PRINT("GDExtension initialization function '" + library_path + "' returned an error.");
return FAILED;
}
}

void GDExtensionStaticLibraryLoader::close_library() {
}

bool GDExtensionStaticLibraryLoader::is_library_open() const {
return true;
}

bool GDExtensionStaticLibraryLoader::has_library_changed() const {
return false;
}

bool GDExtensionStaticLibraryLoader::library_exists() const {
return true;
}
32 changes: 32 additions & 0 deletions godot/modules/sandbox/gdextension_static_library_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef GDEXTENSION_STATIC_LIBRARY_LOADER_H
#define GDEXTENSION_STATIC_LIBRARY_LOADER_H

#include <functional>

#include "core/extension/gdextension_loader.h"
#include "core/io/config_file.h"
#include "core/os/shared_object.h"

class GDExtensionStaticLibraryLoader : public GDExtensionLoader {
friend class GDExtensionManager;
friend class GDExtension;

private:
String resource_path;
void *entry_funcptr = nullptr;
String library_path;
Vector<SharedObject> library_dependencies;

HashMap<String, String> class_icon_paths;

public:
void set_entry_funcptr(void *p_entry_funcptr) { entry_funcptr = p_entry_funcptr; }
virtual Error open_library(const String &p_path) override;
virtual Error initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) override;
virtual void close_library() override;
virtual bool is_library_open() const override;
virtual bool has_library_changed() const override;
virtual bool library_exists() const override;
};

#endif // GDEXTENSION_STATIC_LIBRARY_LOADER_H
28 changes: 28 additions & 0 deletions godot/modules/sandbox/register_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "register_types.h"
#include "core/object/object.h"
#include "core/extension/gdextension_interface.h"
#include "core/extension/gdextension_manager.h"
#include "./gdextension_static_library_loader.h"
#include "core/object/ref_counted.h"

extern "C" {
GDExtensionBool riscv_library_init(
GDExtensionInterfaceGetProcAddress p_get_proc_address,
GDExtensionClassLibraryPtr p_library,
GDExtensionInitialization *r_initialization
);
}

void initialize_sandbox_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
return;
}

Ref<GDExtensionStaticLibraryLoader> loader;
loader.instantiate();
loader->set_entry_funcptr((void*)&riscv_library_init);
GDExtensionManager::get_singleton()->load_extension_with_loader("sandbox", loader);
}

void uninitialize_sandbox_module(ModuleInitializationLevel p_level) {
}
9 changes: 9 additions & 0 deletions godot/modules/sandbox/register_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SANDBOX_REGISTER_TYPES_H
#define SANDBOX_REGISTER_TYPES_H

#include "modules/register_module_types.h"

void initialize_sandbox_module(ModuleInitializationLevel p_level);
void uninitialize_sandbox_module(ModuleInitializationLevel p_level);

#endif // SANDBOX_REGISTER_TYPES_H

0 comments on commit 5153d35

Please sign in to comment.