Skip to content

Commit

Permalink
Merge pull request #917 from Spartan322/merge/d2ada64
Browse files Browse the repository at this point in the history
  • Loading branch information
Spartan322 authored Jan 8, 2025
2 parents 13428bb + 889d027 commit 9c31ef2
Show file tree
Hide file tree
Showing 306 changed files with 7,389 additions and 2,352 deletions.
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ methods.sort_module_list(env)

if env.editor_build:
# Add editor-specific dependencies to the dependency graph.
env.module_add_dependencies("editor", ["freetype", "svg"])
env.module_add_dependencies("editor", ["freetype", "regex", "svg"])

# And check if they are met.
if not env.module_check_dependencies("editor"):
Expand Down
7 changes: 7 additions & 0 deletions core/config/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Engine {
bool project_manager_hint = false;
bool extension_reloading = false;
bool embedded_in_editor = false;
bool recovery_mode_hint = false;

bool _print_header = true;

Expand Down Expand Up @@ -164,6 +165,9 @@ class Engine {

_FORCE_INLINE_ void set_extension_reloading_enabled(bool p_enabled) { extension_reloading = p_enabled; }
_FORCE_INLINE_ bool is_extension_reloading_enabled() const { return extension_reloading; }

_FORCE_INLINE_ void set_recovery_mode_hint(bool p_enabled) { recovery_mode_hint = p_enabled; }
_FORCE_INLINE_ bool is_recovery_mode_hint() const { return recovery_mode_hint; }
#else
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) {}
_FORCE_INLINE_ bool is_editor_hint() const { return false; }
Expand All @@ -173,6 +177,9 @@ class Engine {

_FORCE_INLINE_ void set_extension_reloading_enabled(bool p_enabled) {}
_FORCE_INLINE_ bool is_extension_reloading_enabled() const { return false; }

_FORCE_INLINE_ void set_recovery_mode_hint(bool p_enabled) {}
_FORCE_INLINE_ bool is_recovery_mode_hint() const { return false; }
#endif

Dictionary get_version_info() const;
Expand Down
27 changes: 27 additions & 0 deletions core/extension/gdextension_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::_unload_extension_internal(co
}

GDExtensionManager::LoadStatus GDExtensionManager::load_extension(const String &p_path) {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return LOAD_STATUS_FAILED;
}

Ref<GDExtensionLibraryLoader> loader;
loader.instantiate();
return GDExtensionManager::get_singleton()->load_extension_with_loader(p_path, loader);
Expand Down Expand Up @@ -121,6 +125,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::reload_extension(const String
#else
ERR_FAIL_COND_V_MSG(!Engine::get_singleton()->is_extension_reloading_enabled(), LOAD_STATUS_FAILED, "GDExtension reloading is disabled.");

if (Engine::get_singleton()->is_recovery_mode_hint()) {
return LOAD_STATUS_FAILED;
}

if (!gdextension_map.has(p_path)) {
return LOAD_STATUS_NOT_LOADED;
}
Expand Down Expand Up @@ -163,6 +171,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::reload_extension(const String
}

GDExtensionManager::LoadStatus GDExtensionManager::unload_extension(const String &p_path) {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return LOAD_STATUS_FAILED;
}

if (!gdextension_map.has(p_path)) {
return LOAD_STATUS_NOT_LOADED;
}
Expand Down Expand Up @@ -209,6 +221,10 @@ String GDExtensionManager::class_get_icon_path(const String &p_class) const {
}

void GDExtensionManager::initialize_extensions(GDExtension::InitializationLevel p_level) {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return;
}

ERR_FAIL_COND(int32_t(p_level) - 1 != level);
for (KeyValue<String, Ref<GDExtension>> &E : gdextension_map) {
E.value->initialize_library(p_level);
Expand All @@ -223,6 +239,10 @@ void GDExtensionManager::initialize_extensions(GDExtension::InitializationLevel
}

void GDExtensionManager::deinitialize_extensions(GDExtension::InitializationLevel p_level) {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return;
}

ERR_FAIL_COND(int32_t(p_level) != level);
for (KeyValue<String, Ref<GDExtension>> &E : gdextension_map) {
E.value->deinitialize_library(p_level);
Expand Down Expand Up @@ -261,6 +281,10 @@ void GDExtensionManager::_reload_all_scripts() {
#endif // TOOLS_ENABLED

void GDExtensionManager::load_extensions() {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return;
}

Ref<FileAccess> f = FileAccess::open(GDExtension::get_extension_list_config_file(), FileAccess::READ);
while (f.is_valid() && !f->eof_reached()) {
String s = f->get_line().strip_edges();
Expand All @@ -275,6 +299,9 @@ void GDExtensionManager::load_extensions() {

void GDExtensionManager::reload_extensions() {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return;
}
bool reloaded = false;
for (const KeyValue<String, Ref<GDExtension>> &E : gdextension_map) {
if (!E.value->is_reloadable()) {
Expand Down
4 changes: 2 additions & 2 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName

int InputMap::event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
int index = -1;
event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
return index;
bool valid = event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
return valid ? index : -1;
}

bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {
Expand Down
19 changes: 10 additions & 9 deletions core/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
String str;
while (true) {
if (p_str[index] == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
} else if (p_str[index] == '"') {
index++;
Expand All @@ -210,7 +210,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
index++;
char32_t next = p_str[index];
if (next == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
}
char32_t res = 0;
Expand All @@ -236,7 +236,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
for (int j = 0; j < 4; j++) {
char32_t c = p_str[index + j + 1];
if (c == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
}
if (!is_hex_digit(c)) {
Expand Down Expand Up @@ -272,7 +272,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
for (int j = 0; j < 4; j++) {
char32_t c = p_str[index + j + 1];
if (c == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
}
if (!is_hex_digit(c)) {
Expand Down Expand Up @@ -315,7 +315,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
res = next;
} break;
default: {
r_err_str = "Invalid escape sequence.";
r_err_str = "Invalid escape sequence";
return ERR_PARSE_ERROR;
}
}
Expand Down Expand Up @@ -363,19 +363,20 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
r_token.value = id;
return OK;
} else {
r_err_str = "Unexpected character.";
r_err_str = "Unexpected character";
return ERR_PARSE_ERROR;
}
}
}
}

r_err_str = "Unknown error getting token";
return ERR_PARSE_ERROR;
}

Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str) {
if (p_depth > Variant::MAX_RECURSION_DEPTH) {
r_err_str = "JSON structure is too deep. Bailing.";
r_err_str = "JSON structure is too deep";
return ERR_OUT_OF_MEMORY;
}

Expand All @@ -402,15 +403,15 @@ Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, in
} else if (id == "null") {
value = Variant();
} else {
r_err_str = "Expected 'true','false' or 'null', got '" + id + "'.";
r_err_str = vformat("Expected 'true', 'false', or 'null', got '%s'", id);
return ERR_PARSE_ERROR;
}
} else if (token.type == TK_NUMBER) {
value = token.value;
} else if (token.type == TK_STRING) {
value = token.value;
} else {
r_err_str = "Expected value, got " + String(tk_name[token.type]) + ".";
r_err_str = vformat("Expected value, got '%s'", String(tk_name[token.type]));
return ERR_PARSE_ERROR;
}

Expand Down
5 changes: 5 additions & 0 deletions core/io/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include "core/os/time.h"

#include "modules/modules_enabled.gen.h" // For regex.
#ifdef MODULE_REGEX_ENABLED
#include "modules/regex/regex.h"
#else
class RegEx : public RefCounted {};
#endif // MODULE_REGEX_ENABLED

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define sprintf sprintf_s
Expand Down
8 changes: 2 additions & 6 deletions core/io/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
#include "core/io/file_access.h"
#include "core/string/ustring.h"
#include "core/templates/vector.h"
#include "modules/modules_enabled.gen.h" // For regex.
#ifdef MODULE_REGEX_ENABLED
#include "modules/regex/regex.h"
#endif // MODULE_REGEX_ENABLED

#include <stdarg.h>

class RegEx;

class Logger {
protected:
bool should_log(bool p_err);
Expand Down Expand Up @@ -92,9 +90,7 @@ class RotatedFileLogger : public Logger {
void clear_old_backups();
void rotate_file();

#ifdef MODULE_REGEX_ENABLED
Ref<RegEx> strip_ansi_regex;
#endif // MODULE_REGEX_ENABLED

public:
explicit RotatedFileLogger(const String &p_base_path, int p_max_files = 10);
Expand Down
5 changes: 3 additions & 2 deletions core/io/pck_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ Error PCKPacker::flush(bool p_verbose) {
}

for (int i = 0; i < files.size(); i++) {
int string_len = files[i].path.utf8().length();
CharString utf8_string = files[i].path.utf8();
int string_len = utf8_string.length();
int pad = _get_pad(4, string_len);

fhead->store_32(uint32_t(string_len + pad));
fhead->store_buffer((const uint8_t *)files[i].path.utf8().get_data(), string_len);
fhead->store_buffer((const uint8_t *)utf8_string.get_data(), string_len);
for (int j = 0; j < pad; j++) {
fhead->store_8(0);
}
Expand Down
6 changes: 3 additions & 3 deletions core/io/resource_uid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ String ResourceUID::get_cache_file() {

static constexpr uint8_t uuid_characters[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', '0', '1', '2', '3', '4', '5', '6', '7', '8' };
static constexpr uint32_t uuid_characters_element_count = (sizeof(uuid_characters) / sizeof(*uuid_characters));
static constexpr uint8_t max_uuid_number_length = 19; // Max 0x7FFFFFFFFFFFFFFF size is 19 digits.
static constexpr uint8_t max_uuid_number_length = 13; // Max 0x7FFFFFFFFFFFFFFF (uid://d4n4ub6itg400) size is 13 characters.

String ResourceUID::id_to_text(ID p_id) const {
if (p_id < 0) {
Expand All @@ -58,12 +58,12 @@ String ResourceUID::id_to_text(ID p_id) const {

char32_t tmp[max_uuid_number_length];
uint32_t tmp_size = 0;
while (p_id) {
do {
uint32_t c = p_id % uuid_characters_element_count;
tmp[tmp_size] = uuid_characters[c];
p_id /= uuid_characters_element_count;
++tmp_size;
}
} while (p_id);

// tmp_size + uid:// (6) + 1 for null.
String txt;
Expand Down
8 changes: 7 additions & 1 deletion core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,13 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
PropertyInfo pi = PropertyInfo(K.value.get_type(), "metadata/" + K.key.operator String());
if (K.value.get_type() == Variant::OBJECT) {
pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
pi.hint_string = "Resource";
Object *obj = K.value;
if (Object::cast_to<Script>(obj)) {
pi.hint_string = "Script";
pi.usage |= PROPERTY_USAGE_NEVER_DUPLICATE;
} else {
pi.hint_string = "Resource";
}
}
p_list->push_back(pi);
}
Expand Down
37 changes: 36 additions & 1 deletion core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,28 @@ String OS::get_bundle_icon_path() const {
}

// OS specific path for user://
String OS::get_user_data_dir() const {
String OS::get_user_data_dir(const String &p_user_dir) const {
return ".";
}

String OS::get_user_data_dir() const {
String appname = get_safe_dir_name(GLOBAL_GET("application/config/name"));
if (!appname.is_empty()) {
bool use_custom_dir = GLOBAL_GET("application/config/use_custom_user_dir");
if (use_custom_dir) {
String custom_dir = get_safe_dir_name(GLOBAL_GET("application/config/custom_user_dir_name"), true);
if (custom_dir.is_empty()) {
custom_dir = appname;
}
return get_user_data_dir(custom_dir);
} else {
return get_user_data_dir(get_godot_dir_name().path_join("app_userdata").path_join(appname));
}
} else {
return get_user_data_dir(get_godot_dir_name().path_join("app_userdata").path_join("[unnamed project]"));
}
}

// Absolute path to res://
String OS::get_resource_dir() const {
return ProjectSettings::get_singleton()->get_resource_path();
Expand All @@ -306,6 +324,23 @@ String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
return ".";
}

void OS::create_lock_file() {
if (Engine::get_singleton()->is_recovery_mode_hint()) {
return;
}

String lock_file_path = get_user_data_dir().path_join(".recovery_mode_lock");
Ref<FileAccess> lock_file = FileAccess::open(lock_file_path, FileAccess::WRITE);
if (lock_file.is_valid()) {
lock_file->close();
}
}

void OS::remove_lock_file() {
String lock_file_path = get_user_data_dir().path_join(".recovery_mode_lock");
DirAccess::remove_absolute(lock_file_path);
}

Error OS::shell_open(const String &p_uri) {
return ERR_UNAVAILABLE;
}
Expand Down
4 changes: 4 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class OS {
virtual String get_bundle_resource_dir() const;
virtual String get_bundle_icon_path() const;

virtual String get_user_data_dir(const String &p_user_dir) const;
virtual String get_user_data_dir() const;
virtual String get_resource_dir() const;

Expand All @@ -305,6 +306,9 @@ class OS {

virtual Error move_to_trash(const String &p_path) { return FAILED; }

void create_lock_file();
void remove_lock_file();

virtual int get_exit_code() const;
// `set_exit_code` should only be used from `SceneTree` (or from a similar
// level, e.g. from the `Main::start` if leaving without creating a `SceneTree`).
Expand Down
2 changes: 1 addition & 1 deletion core/os/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include "core/object/script_language.h"

SafeNumeric<uint64_t> Thread::id_counter(1); // The first value after .increment() is 2, hence by default the main thread ID should be 1.
thread_local Thread::ID Thread::caller_id = Thread::id_counter.increment();

thread_local Thread::ID Thread::caller_id = Thread::UNASSIGNED_ID;
#endif

Thread::PlatformFunctions Thread::platform_functions;
Expand Down
Loading

0 comments on commit 9c31ef2

Please sign in to comment.