diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 13 | ||||
-rw-r--r-- | core/bind/core_bind.h | 9 | ||||
-rw-r--r-- | core/command_queue_mt.cpp | 4 | ||||
-rw-r--r-- | core/command_queue_mt.h | 19 | ||||
-rw-r--r-- | core/engine.cpp | 1 | ||||
-rw-r--r-- | core/io/http_client.cpp | 13 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 40 | ||||
-rw-r--r-- | core/io/resource_loader.h | 20 | ||||
-rw-r--r-- | core/math/math_funcs.h | 4 | ||||
-rw-r--r-- | core/math/random_pcg.h | 5 | ||||
-rw-r--r-- | core/object.cpp | 30 | ||||
-rw-r--r-- | core/os/input_event.cpp | 14 | ||||
-rw-r--r-- | core/os/input_event.h | 1 | ||||
-rw-r--r-- | core/undo_redo.cpp | 11 | ||||
-rw-r--r-- | core/version.h | 5 |
15 files changed, 133 insertions, 56 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index f17d7372e2..f6828ea76a 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -225,8 +225,12 @@ int _OS::get_video_driver_count() const { return OS::get_singleton()->get_video_driver_count(); } -String _OS::get_video_driver_name(int p_driver) const { - return OS::get_singleton()->get_video_driver_name(p_driver); +String _OS::get_video_driver_name(VideoDriver p_driver) const { + return OS::get_singleton()->get_video_driver_name((int)p_driver); +} + +_OS::VideoDriver _OS::get_current_video_driver() const { + return (VideoDriver)OS::get_singleton()->get_current_video_driver(); } int _OS::get_audio_driver_count() const { @@ -1108,6 +1112,8 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_video_driver_count"), &_OS::get_video_driver_count); ClassDB::bind_method(D_METHOD("get_video_driver_name", "driver"), &_OS::get_video_driver_name); + ClassDB::bind_method(D_METHOD("get_current_video_driver"), &_OS::get_current_video_driver); + ClassDB::bind_method(D_METHOD("get_audio_driver_count"), &_OS::get_audio_driver_count); ClassDB::bind_method(D_METHOD("get_audio_driver_name", "driver"), &_OS::get_audio_driver_name); ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs); @@ -1276,6 +1282,9 @@ void _OS::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_position"), "set_window_position", "get_window_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_size"), "set_window_size", "get_window_size"); + BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2); + BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES3); + BIND_ENUM_CONSTANT(DAY_SUNDAY); BIND_ENUM_CONSTANT(DAY_MONDAY); BIND_ENUM_CONSTANT(DAY_TUESDAY); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 1c8b985d73..f3bc4644d8 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -103,6 +103,11 @@ protected: static _OS *singleton; public: + enum VideoDriver { + VIDEO_DRIVER_GLES3, + VIDEO_DRIVER_GLES2, + }; + enum PowerState { POWERSTATE_UNKNOWN, /**< cannot determine power status */ POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ @@ -152,7 +157,8 @@ public: Array get_fullscreen_mode_list(int p_screen = 0) const; virtual int get_video_driver_count() const; - virtual String get_video_driver_name(int p_driver) const; + virtual String get_video_driver_name(VideoDriver p_driver) const; + virtual VideoDriver get_current_video_driver() const; virtual int get_audio_driver_count() const; virtual String get_audio_driver_name(int p_driver) const; @@ -355,6 +361,7 @@ public: _OS(); }; +VARIANT_ENUM_CAST(_OS::VideoDriver); VARIANT_ENUM_CAST(_OS::PowerState); VARIANT_ENUM_CAST(_OS::Weekday); VARIANT_ENUM_CAST(_OS::Month); diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 36d4b0a32f..2bdf02295c 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -97,7 +97,7 @@ tryagain: return false; } - dealloc_ptr += (size >> 1) + sizeof(uint32_t); + dealloc_ptr += (size >> 1) + 8; return true; } @@ -107,6 +107,7 @@ CommandQueueMT::CommandQueueMT(bool p_sync) { write_ptr = 0; dealloc_ptr = 0; mutex = Mutex::create(); + command_mem = (uint8_t *)memalloc(COMMAND_MEM_SIZE); for (int i = 0; i < SYNC_SEMAPHORES; i++) { @@ -128,4 +129,5 @@ CommandQueueMT::~CommandQueueMT() { memdelete(sync_sems[i].sem); } + memfree(command_mem); } diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 3fd660a3db..59eabd8786 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -36,6 +36,7 @@ #include "core/os/semaphore.h" #include "core/simple_type.h" #include "core/typedefs.h" + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -254,6 +255,7 @@ unlock(); \ if (sync) sync->post(); \ ss->sem->wait(); \ + ss->in_use = false; \ } #define CMD_SYNC_TYPE(N) CommandSync##N<T, M COMMA(N) COMMA_SEP_LIST(TYPE_ARG, N)> @@ -270,6 +272,7 @@ unlock(); \ if (sync) sync->post(); \ ss->sem->wait(); \ + ss->in_use = false; \ } #define MAX_CMD_PARAMS 13 @@ -295,7 +298,6 @@ class CommandQueueMT { virtual void post() { sync_sem->sem->post(); - sync_sem->in_use = false; } }; @@ -318,7 +320,7 @@ class CommandQueueMT { SYNC_SEMAPHORES = 8 }; - uint8_t command_mem[COMMAND_MEM_SIZE]; + uint8_t *command_mem; uint32_t read_ptr; uint32_t write_ptr; uint32_t dealloc_ptr; @@ -330,7 +332,7 @@ class CommandQueueMT { T *allocate() { // alloc size is size+T+safeguard - uint32_t alloc_size = sizeof(T) + sizeof(uint32_t); + uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8; tryagain: @@ -360,7 +362,7 @@ class CommandQueueMT { } // if this happens, it's a bug - ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < sizeof(uint32_t), NULL); + ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < 8, NULL); // zero means, wrap to beginning uint32_t *p = (uint32_t *)&command_mem[write_ptr]; @@ -372,12 +374,13 @@ class CommandQueueMT { // Allocate the size and the 'in use' bit. // First bit used to mark if command is still in use (1) // or if it has been destroyed and can be deallocated (0). + uint32_t size = (sizeof(T) + 8 - 1) & ~(8 - 1); uint32_t *p = (uint32_t *)&command_mem[write_ptr]; - *p = (sizeof(T) << 1) | 1; - write_ptr += sizeof(uint32_t); + *p = (size << 1) | 1; + write_ptr += 8; // allocate the command T *cmd = memnew_placement(&command_mem[write_ptr], T); - write_ptr += sizeof(T); + write_ptr += size; return cmd; } @@ -415,7 +418,7 @@ class CommandQueueMT { goto tryagain; } - read_ptr += sizeof(uint32_t); + read_ptr += 8; CommandBase *cmd = reinterpret_cast<CommandBase *>(&command_mem[read_ptr]); diff --git a/core/engine.cpp b/core/engine.cpp index 4dba41853d..9607dedb3c 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -98,6 +98,7 @@ Dictionary Engine::get_version_info() const { #else dict["patch"] = 0; #endif + dict["hex"] = VERSION_HEX; dict["status"] = VERSION_STATUS; dict["build"] = VERSION_BUILD; dict["year"] = VERSION_YEAR; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index b3fd814870..b25b1934ff 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -426,11 +426,10 @@ Error HTTPClient::poll() { response_headers.clear(); response_num = RESPONSE_OK; - // Per the HTTP 1.1 spec, keep-alive is the default, but in practice - // it's safe to assume it only if the explicit header is found, allowing - // to handle body-up-to-EOF responses on naive servers; that's what Curl - // and browsers do - bool keep_alive = false; + // Per the HTTP 1.1 spec, keep-alive is the default. + // Not following that specification breaks standard implemetations. + // Broken web servers should be fixed. + bool keep_alive = true; for (int i = 0; i < responses.size(); i++) { @@ -447,8 +446,8 @@ Error HTTPClient::poll() { if (encoding == "chunked") { chunked = true; } - } else if (s.begins_with("connection: keep-alive")) { - keep_alive = true; + } else if (s.begins_with("connection: close")) { + keep_alive = false; } if (i == 0 && responses[i].begins_with("HTTP")) { diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 4aa002e9a2..10a32bae41 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -55,7 +55,7 @@ Error ResourceInteractiveLoader::wait() { ResourceInteractiveLoader::~ResourceInteractiveLoader() { if (path_loading != String()) { - ResourceLoader::_remove_from_loading_map(path_loading); + ResourceLoader::_remove_from_loading_map_and_thread(path_loading, path_loading_thread); } } @@ -293,10 +293,14 @@ bool ResourceLoader::_add_to_loading_map(const String &p_path) { loading_map_mutex->lock(); } - if (loading_map.has(p_path)) { + LoadingMapKey key; + key.path = p_path; + key.thread = Thread::get_caller_id(); + + if (loading_map.has(key)) { success = false; } else { - loading_map[p_path] = true; + loading_map[key] = true; success = true; } @@ -312,7 +316,27 @@ void ResourceLoader::_remove_from_loading_map(const String &p_path) { loading_map_mutex->lock(); } - loading_map.erase(p_path); + LoadingMapKey key; + key.path = p_path; + key.thread = Thread::get_caller_id(); + + loading_map.erase(key); + + if (loading_map_mutex) { + loading_map_mutex->unlock(); + } +} + +void ResourceLoader::_remove_from_loading_map_and_thread(const String &p_path, Thread::ID p_thread) { + if (loading_map_mutex) { + loading_map_mutex->lock(); + } + + LoadingMapKey key; + key.path = p_path; + key.thread = p_thread; + + loading_map.erase(key); if (loading_map_mutex) { loading_map_mutex->unlock(); @@ -471,6 +495,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ ril->resource = res_cached; ril->path_loading = local_path; + ril->path_loading_thread = Thread::get_caller_id(); return ril; } } @@ -499,6 +524,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ if (!p_no_cache) { ril->set_local_path(local_path); ril->path_loading = local_path; + ril->path_loading_thread = Thread::get_caller_id(); } if (xl_remapped) @@ -919,7 +945,7 @@ void ResourceLoader::remove_custom_loaders() { } Mutex *ResourceLoader::loading_map_mutex = NULL; -HashMap<String, int> ResourceLoader::loading_map; +HashMap<ResourceLoader::LoadingMapKey, int, ResourceLoader::LoadingMapKeyHasher> ResourceLoader::loading_map; void ResourceLoader::initialize() { #ifndef NO_THREADS @@ -929,9 +955,9 @@ void ResourceLoader::initialize() { void ResourceLoader::finalize() { #ifndef NO_THREADS - const String *K = NULL; + const LoadingMapKey *K = NULL; while ((K = loading_map.next(K))) { - ERR_PRINTS("Exited while resource is being loaded: " + *K); + ERR_PRINTS("Exited while resource is being loaded: " + K->path); } loading_map.clear(); memdelete(loading_map_mutex); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 622b74a998..70eb1a3de0 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -31,8 +31,8 @@ #ifndef RESOURCE_LOADER_H #define RESOURCE_LOADER_H +#include "core/os/thread.h" #include "core/resource.h" - /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -42,6 +42,7 @@ class ResourceInteractiveLoader : public Reference { GDCLASS(ResourceInteractiveLoader, Reference); friend class ResourceLoader; String path_loading; + Thread::ID path_loading_thread; protected: static void _bind_methods(); @@ -121,10 +122,25 @@ class ResourceLoader { static Ref<ResourceFormatLoader> _find_custom_resource_format_loader(String path); static Mutex *loading_map_mutex; - static HashMap<String, int> loading_map; + + //used to track paths being loaded in a thread, avoids cyclic recursion + struct LoadingMapKey { + String path; + Thread::ID thread; + bool operator==(const LoadingMapKey &p_key) const { + return (thread == p_key.thread && path == p_key.path); + } + }; + struct LoadingMapKeyHasher { + + static _FORCE_INLINE_ uint32_t hash(const LoadingMapKey &p_key) { return p_key.path.hash() + HashMapHasherDefault::hash(p_key.thread); } + }; + + static HashMap<LoadingMapKey, int, LoadingMapKeyHasher> loading_map; static bool _add_to_loading_map(const String &p_path); static void _remove_from_loading_map(const String &p_path); + static void _remove_from_loading_map_and_thread(const String &p_path, Thread::ID p_thread); public: static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index ea0bfd88cc..629002ced6 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -242,8 +242,8 @@ public: static void randomize(); static uint32_t rand_from_seed(uint64_t *seed); static uint32_t rand(); - static _ALWAYS_INLINE_ double randf() { return (double)rand() / (double)Math::RANDOM_MAX; } - static _ALWAYS_INLINE_ float randd() { return (float)rand() / (float)Math::RANDOM_MAX; } + static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)Math::RANDOM_MAX; } + static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)Math::RANDOM_MAX; } static double random(double from, double to); static float random(float from, float to); diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index ef69bf7120..2a69d43904 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -45,7 +45,10 @@ public: RandomPCG(uint64_t seed = DEFAULT_SEED, uint64_t inc = PCG_DEFAULT_INC_64); - _FORCE_INLINE_ void seed(uint64_t seed) { pcg.state = seed; } + _FORCE_INLINE_ void seed(uint64_t seed) { + pcg.state = seed; + pcg32_random_r(&pcg); // Force changing internal state to avoid initial 0 + } _FORCE_INLINE_ uint64_t get_seed() { return pcg.state; } void randomize(); diff --git a/core/object.cpp b/core/object.cpp index 54a9bb0d7c..4e0416ccb0 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -703,40 +703,38 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Vari } #ifdef DEBUG_ENABLED -static bool _test_call_error(const StringName &p_func, const Variant::CallError &error) { +static void _test_call_error(const StringName &p_func, const Variant::CallError &error) { switch (error.error) { case Variant::CallError::CALL_OK: - return true; case Variant::CallError::CALL_ERROR_INVALID_METHOD: - return false; + break; case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: { ERR_EXPLAIN("Error Calling Function: " + String(p_func) + " - Invalid type for argument " + itos(error.argument) + ", expected " + Variant::get_type_name(error.expected)); - ERR_FAIL_V(true); - } break; + ERR_FAIL(); + break; + } case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { ERR_EXPLAIN("Error Calling Function: " + String(p_func) + " - Too many arguments, expected " + itos(error.argument)); - ERR_FAIL_V(true); - - } break; + ERR_FAIL(); + break; + } case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: { ERR_EXPLAIN("Error Calling Function: " + String(p_func) + " - Too few arguments, expected " + itos(error.argument)); - ERR_FAIL_V(true); - - } break; - case Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL: { - } //? + ERR_FAIL(); + break; + } + case Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL: + break; } - - return true; } #else -#define _test_call_error(m_str, m_err) ((m_err.error == Variant::CallError::CALL_ERROR_INVALID_METHOD) ? false : true) +#define _test_call_error(m_str, m_err) #endif diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 1e0e83c8d2..24ec8a1963 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -749,6 +749,15 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * return match; } +bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const { + + Ref<InputEventJoypadButton> button = p_event; + if (button.is_null()) + return false; + + return button_index == button->button_index; +} + String InputEventJoypadButton::as_text() const { return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure)); @@ -950,11 +959,10 @@ bool InputEventAction::is_pressed() const { } bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const { - Ref<InputEventKey> event = p_event; - if (event.is_null()) + if (p_event.is_null()) return false; - return event->is_action(action); + return p_event->is_action(action); } bool InputEventAction::is_action(const StringName &p_action) const { diff --git a/core/os/input_event.h b/core/os/input_event.h index db31055b5f..a6a7012298 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -400,6 +400,7 @@ public: float get_pressure() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; + virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } virtual String as_text() const; diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 6bc882eaec..00894b41d8 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -234,7 +234,9 @@ void UndoRedo::_pop_history_tail() { } actions.remove(0); - current_action--; + if (current_action >= 0) { + current_action--; + } } void UndoRedo::commit_action() { @@ -258,11 +260,8 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { Operation &op = E->get(); Object *obj = ObjectDB::get_instance(op.object); - if (!obj) { - //corruption - clear_history(); - ERR_FAIL_COND(!obj); - } + if (!obj) //may have been deleted and this is fine + continue; switch (op.type) { diff --git a/core/version.h b/core/version.h index 46eecf6125..05fec9d0a6 100644 --- a/core/version.h +++ b/core/version.h @@ -41,9 +41,14 @@ #ifdef VERSION_PATCH // Example: "3.1.4" #define VERSION_NUMBER "" VERSION_BRANCH "." _MKSTR(VERSION_PATCH) +// Version number encoded as hexadecimal int with one byte for each number, +// for easy comparison from code. +// Example: 3.1.4 will be 0x030104, making comparison easy from script. +#define VERSION_HEX 0x10000 * VERSION_MAJOR + 0x100 * VERSION_MINOR + VERSION_PATCH #else // Example: "3.1" #define VERSION_NUMBER "" VERSION_BRANCH +#define VERSION_HEX 0x10000 * VERSION_MAJOR + 0x100 * VERSION_MINOR #endif // VERSION_PATCH // Describes the full configuration of that Godot version, including the version number, |