diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 4 | ||||
-rw-r--r-- | core/bind/core_bind.h | 11 | ||||
-rw-r--r-- | core/event_queue.cpp | 157 | ||||
-rw-r--r-- | core/event_queue.h | 64 | ||||
-rw-r--r-- | core/os/file_access.h | 1 | ||||
-rw-r--r-- | core/os/os.cpp | 2 | ||||
-rw-r--r-- | core/os/os.h | 16 | ||||
-rw-r--r-- | core/os/power.h | 42 | ||||
-rw-r--r-- | core/project_settings.cpp | 58 | ||||
-rw-r--r-- | core/reference.cpp | 13 | ||||
-rw-r--r-- | core/reference.h | 2 | ||||
-rw-r--r-- | core/undo_redo.cpp | 4 | ||||
-rw-r--r-- | core/variant.cpp | 4 | ||||
-rw-r--r-- | core/variant.h | 1 |
14 files changed, 98 insertions, 281 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 0f217c8235..ab9c107d7a 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -440,8 +440,8 @@ bool _OS::is_vsync_enabled() const { return OS::get_singleton()->is_vsync_enabled(); } -PowerState _OS::get_power_state() { - return OS::get_singleton()->get_power_state(); +_OS::PowerState _OS::get_power_state() { + return _OS::PowerState(OS::get_singleton()->get_power_state()); } int _OS::get_power_seconds_left() { diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 1a3782c471..fc28ada0f8 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -36,7 +36,7 @@ #include "io/resource_saver.h" #include "os/dir_access.h" #include "os/file_access.h" -#include "os/power.h" +#include "os/os.h" #include "os/semaphore.h" #include "os/thread.h" @@ -97,6 +97,14 @@ protected: static _OS *singleton; public: + enum PowerState { + POWERSTATE_UNKNOWN, /**< cannot determine power status */ + POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ + POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ + POWERSTATE_CHARGING, /**< Plugged in, charging battery */ + POWERSTATE_CHARGED /**< Plugged in, battery charged */ + }; + enum Weekday { DAY_SUNDAY, DAY_MONDAY, @@ -312,6 +320,7 @@ public: _OS(); }; +VARIANT_ENUM_CAST(_OS::PowerState); VARIANT_ENUM_CAST(_OS::Weekday); VARIANT_ENUM_CAST(_OS::Month); VARIANT_ENUM_CAST(_OS::SystemDir); diff --git a/core/event_queue.cpp b/core/event_queue.cpp deleted file mode 100644 index 12f9942a07..0000000000 --- a/core/event_queue.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************/ -/* event_queue.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "event_queue.h" - -Error EventQueue::push_call(uint32_t p_instance_ID, const StringName &p_method, VARIANT_ARG_DECLARE) { - - uint8_t room_needed = sizeof(Event); - int args = 0; - if (p_arg5.get_type() != Variant::NIL) - args = 5; - else if (p_arg4.get_type() != Variant::NIL) - args = 4; - else if (p_arg3.get_type() != Variant::NIL) - args = 3; - else if (p_arg2.get_type() != Variant::NIL) - args = 2; - else if (p_arg1.get_type() != Variant::NIL) - args = 1; - else - args = 0; - - room_needed += sizeof(Variant) * args; - - ERR_FAIL_COND_V((buffer_end + room_needed) >= buffer_size, ERR_OUT_OF_MEMORY); - Event *ev = memnew_placement(&event_buffer[buffer_end], Event); - ev->args = args; - ev->instance_ID = p_instance_ID; - ev->method = p_method; - - buffer_end += sizeof(Event); - - if (args >= 1) { - - Variant *v = memnew_placement(&event_buffer[buffer_end], Variant); - buffer_end += sizeof(Variant); - *v = p_arg1; - } - - if (args >= 2) { - - Variant *v = memnew_placement(&event_buffer[buffer_end], Variant); - buffer_end += sizeof(Variant); - *v = p_arg2; - } - - if (args >= 3) { - - Variant *v = memnew_placement(&event_buffer[buffer_end], Variant); - buffer_end += sizeof(Variant); - *v = p_arg3; - } - - if (args >= 4) { - - Variant *v = memnew_placement(&event_buffer[buffer_end], Variant); - buffer_end += sizeof(Variant); - *v = p_arg4; - } - - if (args >= 5) { - - Variant *v = memnew_placement(&event_buffer[buffer_end], Variant); - buffer_end += sizeof(Variant); - *v = p_arg5; - } - - if (buffer_end > buffer_max_used) - buffer_max_used = buffer_end; - - return OK; -} - -void EventQueue::flush_events() { - - uint32_t read_pos = 0; - - while (read_pos < buffer_end) { - - Event *event = (Event *)&event_buffer[read_pos]; - Variant *args = (Variant *)(event + 1); - Object *obj = ObjectDB::get_instance(event->instance_ID); - - if (obj) { - // events don't expect a return value - obj->call(event->method, - (event->args >= 1) ? args[0] : Variant(), - (event->args >= 2) ? args[1] : Variant(), - (event->args >= 3) ? args[2] : Variant(), - (event->args >= 4) ? args[3] : Variant(), - (event->args >= 5) ? args[4] : Variant()); - } - - if (event->args >= 1) args[0].~Variant(); - if (event->args >= 2) args[1].~Variant(); - if (event->args >= 3) args[2].~Variant(); - if (event->args >= 4) args[3].~Variant(); - if (event->args >= 5) args[4].~Variant(); - event->~Event(); - - read_pos += sizeof(Event) + sizeof(Variant) * event->args; - } - - buffer_end = 0; // reset buffer -} - -EventQueue::EventQueue(uint32_t p_buffer_size) { - - buffer_end = 0; - buffer_max_used = 0; - buffer_size = p_buffer_size; - event_buffer = memnew_arr(uint8_t, buffer_size); -} -EventQueue::~EventQueue() { - - uint32_t read_pos = 0; - - while (read_pos < buffer_end) { - - Event *event = (Event *)&event_buffer[read_pos]; - Variant *args = (Variant *)(event + 1); - for (int i = 0; i < event->args; i++) - args[i].~Variant(); - event->~Event(); - - read_pos += sizeof(Event) + sizeof(Variant) * event->args; - } - - memdelete_arr(event_buffer); - event_buffer = NULL; -} diff --git a/core/event_queue.h b/core/event_queue.h deleted file mode 100644 index af1a760945..0000000000 --- a/core/event_queue.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************/ -/* event_queue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef EVENT_QUEUE_H -#define EVENT_QUEUE_H - -#include "object.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ -class EventQueue { - - enum { - - DEFAULT_EVENT_QUEUE_SIZE_KB = 256 - }; - - struct Event { - - uint32_t instance_ID; - StringName method; - int args; - }; - - uint8_t *event_buffer; - uint32_t buffer_end; - uint32_t buffer_max_used; - uint32_t buffer_size; - -public: - Error push_call(uint32_t p_instance_ID, const StringName &p_method, VARIANT_ARG_LIST); - void flush_events(); - - EventQueue(uint32_t p_buffer_size = DEFAULT_EVENT_QUEUE_SIZE_KB * 1024); - ~EventQueue(); -}; - -#endif diff --git a/core/os/file_access.h b/core/os/file_access.h index 8393f0530b..8e5728f525 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -174,6 +174,7 @@ struct FileAccessRef { operator bool() const { return f != NULL; } FileAccess *f; + operator FileAccess *() { return f; } FileAccessRef(FileAccess *fa) { f = fa; } ~FileAccessRef() { if (f) memdelete(f); diff --git a/core/os/os.cpp b/core/os/os.cpp index 764f7fe6e6..437ce01a5e 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -485,7 +485,7 @@ bool OS::is_vsync_enabled() const { return true; } -PowerState OS::get_power_state() { +OS::PowerState OS::get_power_state() { return POWERSTATE_UNKNOWN; } int OS::get_power_seconds_left() { diff --git a/core/os/os.h b/core/os/os.h index 258708eea2..2fc87e44a0 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -34,7 +34,6 @@ #include "image.h" #include "list.h" #include "os/main_loop.h" -#include "power.h" #include "ustring.h" #include "vector.h" #include <stdarg.h> @@ -65,6 +64,14 @@ class OS { public: typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection); + enum PowerState { + POWERSTATE_UNKNOWN, /**< cannot determine power status */ + POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ + POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ + POWERSTATE_CHARGING, /**< Plugged in, charging battery */ + POWERSTATE_CHARGED /**< Plugged in, battery charged */ + }; + enum RenderThreadMode { RENDER_THREAD_UNSAFE, @@ -279,6 +286,9 @@ public: bool is_stdout_verbose() const; + virtual void disable_crash_handler() {} + virtual bool is_disable_crash_handler() const { return false; } + enum CursorShape { CURSOR_ARROW, CURSOR_IBEAM, @@ -410,7 +420,7 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; - virtual PowerState get_power_state(); + virtual OS::PowerState get_power_state(); virtual int get_power_seconds_left(); virtual int get_power_percent_left(); @@ -428,6 +438,6 @@ public: virtual ~OS(); }; -VARIANT_ENUM_CAST(PowerState); +VARIANT_ENUM_CAST(OS::PowerState); #endif diff --git a/core/os/power.h b/core/os/power.h deleted file mode 100644 index 59a091012e..0000000000 --- a/core/os/power.h +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************/ -/* power.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CORE_OS_POWER_H_ -#define CORE_OS_POWER_H_ - -typedef enum { - POWERSTATE_UNKNOWN, /**< cannot determine power status */ - POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ - POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ - POWERSTATE_CHARGING, /**< Plugged in, charging battery */ - POWERSTATE_CHARGED /**< Plugged in, battery charged */ -} PowerState; - -#endif /* CORE_OS_POWER_H_ */ diff --git a/core/project_settings.cpp b/core/project_settings.cpp index 23e4961138..72d40b42c3 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -270,6 +270,11 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) { if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { _load_settings("res://override.cfg"); +#ifdef DEBUG_ENABLED + } else { + // when debug version of godot is used, provide some feedback to the developer + print_line("Couldn't open project over network"); +#endif } return OK; @@ -287,6 +292,12 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) { if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { //load override from location of the main pack _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg")); +#ifdef DEBUG_ENABLED + // when debug version of godot is used, provide some feedback to the developer + print_line("Successfully loaded " + p_main_pack + "/project.godot or project.binary"); + } else { + print_line("Couldn't load/find " + p_main_pack + "/project.godot or project.binary"); +#endif } return OK; @@ -294,12 +305,43 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) { //Attempt with execname.pck if (exec_path != "") { + bool found = false; + + // get our filename without our path (note, not using exec_path.get_basename anymore because not all file systems have dots in their file names!) + String filebase_name = exec_path.get_file(); - if (_load_resource_pack(exec_path.get_basename() + ".pck")) { + // try to open at the location of executable + String datapack_name = exec_path.get_base_dir().plus_file(filebase_name) + ".pck"; + if (_load_resource_pack(datapack_name)) { + found = true; + } else { +#ifdef DEBUG_ENABLED + // when debug version of godot is used, provide some feedback to the developer + print_line("Couldn't open " + datapack_name); +#endif + datapack_name = filebase_name + ".pck"; + if (_load_resource_pack(datapack_name)) { + found = true; +#ifdef DEBUG_ENABLED + } else { + // when debug version of godot is used, provide some feedback to the developer + print_line("Couldn't open " + datapack_name); +#endif + } + } + // if we opened our package, try and load our project... + if (found) { if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { - //load override from location of executable + // load override from location of executable _load_settings(exec_path.get_base_dir().plus_file("override.cfg")); + +#ifdef DEBUG_ENABLED + // when debug version of godot is used, provide some feedback to the developer + print_line("Successfully loaded " + datapack_name + "/project.godot or project.binary"); + } else { + print_line("Couldn't load/find " + datapack_name + "/project.godot or project.binary"); +#endif } return OK; @@ -320,6 +362,12 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) { if (_load_settings("res://project.godot") == OK || _load_settings_binary("res://project.binary") == OK) { _load_settings("res://override.cfg"); +#ifdef DEBUG_ENABLED + // when debug version of godot is used, provide some feedback to the developer + print_line("Successfully loaded " + resource_path + "/project.godot or project.binary"); + } else { + print_line("Couldn't load/find " + resource_path + "/project.godot or project.binary"); +#endif } return OK; @@ -345,6 +393,12 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) { candidate = current_dir; found = true; break; +#ifdef DEBUG_ENABLED + // when debug version of godot is used, provide some feedback to the developer + print_line("Successfully loaded " + current_dir + "/project.godot or project.binary"); + } else { + print_line("Couldn't load/find " + current_dir + "/project.godot or project.binary"); +#endif } d->change_dir(".."); diff --git a/core/reference.cpp b/core/reference.cpp index bb70628cbe..7f93922d22 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -33,7 +33,7 @@ bool Reference::init_ref() { - if (refcount.ref()) { + if (reference()) { // this may fail in the scenario of two threads assigning the pointer for the FIRST TIME // at the same time, which is never likely to happen (would be crazy to do) @@ -41,7 +41,7 @@ bool Reference::init_ref() { if (refcount_init.get() > 0) { refcount_init.unref(); - refcount.unref(); // first referencing is already 1, so compensate for the ref above + unreference(); // first referencing is already 1, so compensate for the ref above } return true; @@ -62,13 +62,16 @@ int Reference::reference_get_count() const { return refcount.get(); } -void Reference::reference() { +bool Reference::reference() { + bool success = refcount.ref(); - refcount.ref(); - if (get_script_instance()) { + if (success && get_script_instance()) { get_script_instance()->refcount_incremented(); } + + return success; } + bool Reference::unreference() { bool die = refcount.unref(); diff --git a/core/reference.h b/core/reference.h index ca3ae60418..bafc164276 100644 --- a/core/reference.h +++ b/core/reference.h @@ -51,7 +51,7 @@ protected: public: _FORCE_INLINE_ bool is_referenced() const { return refcount_init.get() < 1; } bool init_ref(); - void reference(); + bool reference(); // returns false if refcount is at zero and didn't get increased bool unreference(); int reference_get_count() const; diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 4760047959..27fc73ec63 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -503,6 +503,10 @@ void UndoRedo::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_history"), &UndoRedo::clear_history); ClassDB::bind_method(D_METHOD("get_current_action_name"), &UndoRedo::get_current_action_name); ClassDB::bind_method(D_METHOD("get_version"), &UndoRedo::get_version); + ClassDB::bind_method(D_METHOD("set_max_steps", "max_steps"), &UndoRedo::set_max_steps); + ClassDB::bind_method(D_METHOD("get_max_steps"), &UndoRedo::get_max_steps); + ClassDB::bind_method(D_METHOD("redo"), &UndoRedo::redo); + ClassDB::bind_method(D_METHOD("undo"), &UndoRedo::undo); BIND_ENUM_CONSTANT(MERGE_DISABLE); BIND_ENUM_CONSTANT(MERGE_ENDS); diff --git a/core/variant.cpp b/core/variant.cpp index 74f6b6a711..10d86152ee 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2259,8 +2259,8 @@ Variant::Variant(const RefPtr &p_resource) { type = OBJECT; memnew_placement(_data._mem, ObjData); - REF ref = p_resource; - _get_obj().obj = ref.ptr(); + REF *ref = reinterpret_cast<REF *>(p_resource.get_data()); + _get_obj().obj = ref->ptr(); _get_obj().ref = p_resource; } diff --git a/core/variant.h b/core/variant.h index c44608ebfa..e77e2e93c4 100644 --- a/core/variant.h +++ b/core/variant.h @@ -43,7 +43,6 @@ #include "math_2d.h" #include "matrix3.h" #include "node_path.h" -#include "os/power.h" #include "plane.h" #include "quat.h" #include "rect3.h" |