Skip to content

Commit

Permalink
GDExtension: Implement GDExtensionLoader concept
Browse files Browse the repository at this point in the history
- Implements the concept of GDExtension loaders that can be used to customize how GDExtensions are loaded and initialized.
- Moves the parsing of `.gdextension` config files to the new `GDExtensionLibraryLoader`.
- `GDExtensionManager` is now meant to be the main way to load/unload extensions and can optionally take a `GDExtensionLoader`.
- `EditorFileSystem` avoids unloading extensions if the file still exists, this should prevent unloading extensions that are outside the user project.
  • Loading branch information
raulsntos committed Aug 17, 2024
1 parent 1bd740d commit 283dcc2
Show file tree
Hide file tree
Showing 9 changed files with 581 additions and 347 deletions.
357 changes: 32 additions & 325 deletions core/extension/gdextension.cpp

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions core/extension/gdextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
#ifndef GDEXTENSION_H
#define GDEXTENSION_H

#include <functional>

#include "core/extension/gdextension_interface.h"
#include "core/extension/gdextension_loader.h"
#include "core/io/config_file.h"
#include "core/io/resource_loader.h"
#include "core/object/ref_counted.h"
#include "core/os/shared_object.h"

class GDExtensionMethodBind;

Expand All @@ -46,8 +44,8 @@ class GDExtension : public Resource {

friend class GDExtensionManager;

void *library = nullptr; // pointer if valid,
String library_path;
Ref<GDExtensionLoader> loader;

bool reloadable = false;

struct Extension {
Expand Down Expand Up @@ -96,8 +94,6 @@ class GDExtension : public Resource {
int32_t level_initialized = -1;

#ifdef TOOLS_ENABLED
uint64_t resource_last_modified_time = 0;
uint64_t library_last_modified_time = 0;
bool is_reloading = false;
Vector<GDExtensionMethodBind *> invalid_methods;
Vector<ObjectID> instance_bindings;
Expand All @@ -124,11 +120,12 @@ class GDExtension : public Resource {
virtual bool editor_can_reload_from_file() override { return false; } // Reloading is handled in a special way.

static String get_extension_list_config_file();
static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);
static Vector<SharedObject> find_extension_dependencies(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature);

Error open_library(const String &p_path, const String &p_entry_symbol, Vector<SharedObject> *p_dependencies = nullptr);
const Ref<GDExtensionLoader> get_loader() const { return loader; }

Error open_library(const String &p_path, const Ref<GDExtensionLoader> &p_loader);
void close_library();
bool is_library_open() const;

enum InitializationLevel {
INITIALIZATION_LEVEL_CORE = GDEXTENSION_INITIALIZATION_CORE,
Expand All @@ -146,17 +143,11 @@ class GDExtension : public Resource {
#endif

public:
bool is_library_open() const;

#ifdef TOOLS_ENABLED
bool is_reloadable() const { return reloadable; }
void set_reloadable(bool p_reloadable) { reloadable = p_reloadable; }

bool has_library_changed() const;
void update_last_modified_time(uint64_t p_resource_last_modified_time, uint64_t p_library_last_modified_time) {
resource_last_modified_time = p_resource_last_modified_time;
library_last_modified_time = p_library_last_modified_time;
}

void track_instance_binding(Object *p_object);
void untrack_instance_binding(Object *p_object);
Expand Down
Loading

0 comments on commit 283dcc2

Please sign in to comment.