Merge pull request #84315 from dsnopek/gdextension-windows-modification-time

GDExtension: Save and compare modification times separately for reload
This commit is contained in:
Yuri Sizov 2023-11-02 20:34:15 +01:00
commit 1b42673b42
2 changed files with 13 additions and 8 deletions

View file

@ -915,9 +915,9 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path,
#ifdef TOOLS_ENABLED
p_extension->set_reloadable(config->get_value("configuration", "reloadable", false) && Engine::get_singleton()->is_extension_reloading_enabled());
p_extension->update_last_modified_time(MAX(
FileAccess::get_modified_time(library_path),
FileAccess::get_modified_time(p_path)));
p_extension->update_last_modified_time(
FileAccess::get_modified_time(p_path),
FileAccess::get_modified_time(library_path));
#endif
err = p_extension->open_library(library_path, entry_symbol);
@ -990,10 +990,13 @@ String GDExtensionResourceLoader::get_resource_type(const String &p_path) const
#ifdef TOOLS_ENABLED
bool GDExtension::has_library_changed() const {
if (FileAccess::get_modified_time(get_path()) > last_modified_time) {
// Check only that the last modified time is different (rather than checking
// that it's newer) since some OS's (namely Windows) will preserve the modified
// time by default when copying files.
if (FileAccess::get_modified_time(get_path()) != resource_last_modified_time) {
return true;
}
if (FileAccess::get_modified_time(library_path) > last_modified_time) {
if (FileAccess::get_modified_time(library_path) != library_last_modified_time) {
return true;
}
return false;

View file

@ -90,7 +90,8 @@ class GDExtension : public Resource {
int32_t level_initialized = -1;
#ifdef TOOLS_ENABLED
uint64_t last_modified_time = 0;
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;
@ -140,8 +141,9 @@ public:
void set_reloadable(bool p_reloadable) { reloadable = p_reloadable; }
bool has_library_changed() const;
void update_last_modified_time(uint64_t p_last_modified_time) {
last_modified_time = MAX(last_modified_time, p_last_modified_time);
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);