summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub2
-rw-r--r--core/array.cpp2
-rw-r--r--core/bind/core_bind.cpp6
-rw-r--r--core/bind/core_bind.h2
-rw-r--r--core/class_db.cpp19
-rw-r--r--core/class_db.h10
-rw-r--r--core/color.h18
-rw-r--r--core/command_queue_mt.cpp24
-rw-r--r--core/command_queue_mt.h1507
-rw-r--r--core/compressed_translation.cpp2
-rw-r--r--core/core_string_names.cpp28
-rw-r--r--core/dictionary.cpp4
-rw-r--r--core/dvector.h2
-rw-r--r--core/engine.h6
-rw-r--r--core/error_list.h2
-rw-r--r--core/error_macros.cpp2
-rw-r--r--core/global_constants.cpp15
-rw-r--r--core/hash_map.h6
-rw-r--r--core/helper/math_fieldwise.cpp9
-rw-r--r--core/io/file_access_buffered_fa.h4
-rw-r--r--core/io/file_access_compressed.cpp24
-rw-r--r--core/io/file_access_encrypted.cpp12
-rw-r--r--core/io/file_access_network.cpp6
-rw-r--r--core/io/file_access_pack.cpp6
-rw-r--r--core/io/json.cpp53
-rw-r--r--core/io/json.h4
-rw-r--r--core/io/marshalls.cpp24
-rw-r--r--core/io/resource_format_binary.cpp17
-rw-r--r--core/io/resource_format_binary.h1
-rw-r--r--core/io/resource_import.h6
-rw-r--r--core/io/stream_peer.cpp6
-rw-r--r--core/list.h4
-rw-r--r--core/math/a_star.h4
-rw-r--r--core/math/aabb.h6
-rw-r--r--core/math/bsp_tree.cpp10
-rw-r--r--core/math/camera_matrix.cpp1
-rw-r--r--core/math/face3.cpp3
-rw-r--r--core/math/face3.h2
-rw-r--r--core/math/math_2d.cpp29
-rw-r--r--core/math/math_2d.h35
-rw-r--r--core/math/math_funcs.h2
-rw-r--r--core/math/plane.h18
-rw-r--r--core/math/transform.cpp6
-rw-r--r--core/node_path.cpp81
-rw-r--r--core/node_path.h13
-rw-r--r--core/object.cpp302
-rw-r--r--core/object.h44
-rw-r--r--core/ordered_hash_map.h26
-rw-r--r--core/os/dir_access.cpp3
-rw-r--r--core/os/file_access.cpp2
-rw-r--r--core/os/file_access.h2
-rw-r--r--core/os/input_event.cpp32
-rw-r--r--core/os/input_event.h9
-rw-r--r--core/os/keyboard.cpp43
-rw-r--r--core/os/keyboard.h1
-rw-r--r--core/os/os.cpp35
-rw-r--r--core/os/os.h11
-rw-r--r--core/pair.h6
-rw-r--r--core/project_settings.cpp5
-rw-r--r--core/project_settings.h22
-rw-r--r--core/register_core_types.cpp3
-rw-r--r--core/resource.cpp33
-rw-r--r--core/resource.h1
-rw-r--r--core/safe_refcount.cpp8
-rw-r--r--core/script_debugger_local.cpp4
-rw-r--r--core/script_debugger_remote.cpp40
-rw-r--r--core/script_language.cpp8
-rw-r--r--core/string_buffer.cpp2
-rw-r--r--core/string_buffer.h2
-rw-r--r--core/translation.cpp12
-rw-r--r--core/typedefs.h6
-rw-r--r--core/ustring.cpp6
-rw-r--r--core/variant.cpp19
-rw-r--r--core/variant_call.cpp26
-rw-r--r--core/vector.h4
75 files changed, 1075 insertions, 1685 deletions
diff --git a/core/SCsub b/core/SCsub
index e9b21bc71b..1545bc8aeb 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -105,6 +105,6 @@ SConscript('helper/SCsub')
# Build it all as a library
-lib = env.Library("core", env.core_sources)
+lib = env.add_library("core", env.core_sources)
env.Prepend(LIBS=[lib])
Export('env')
diff --git a/core/array.cpp b/core/array.cpp
index b7d4ae413a..1ccbbae147 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -261,7 +261,7 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
SortArray<Variant, _ArrayVariantSortCustom> avs;
avs.compare.obj = p_obj;
avs.compare.func = p_function;
- avs.sort(_p->array.ptr(), _p->array.size());
+ avs.sort(_p->array.ptrw(), _p->array.size());
return *this;
}
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 999befaf67..f6011c3976 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -2694,12 +2694,12 @@ Variant JSONParseResult::get_result() const {
}
void _JSON::_bind_methods() {
- ClassDB::bind_method(D_METHOD("print", "value"), &_JSON::print);
+ ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys"), &_JSON::print, DEFVAL(String()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse);
}
-String _JSON::print(const Variant &p_value) {
- return JSON::print(p_value);
+String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys) {
+ return JSON::print(p_value, p_indent, p_sort_keys);
}
Ref<JSONParseResult> _JSON::parse(const String &p_json) {
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 8163b08d76..b642a907fb 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -719,7 +719,7 @@ protected:
public:
static _JSON *get_singleton() { return singleton; }
- String print(const Variant &p_value);
+ String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
Ref<JSONParseResult> parse(const String &p_json);
_JSON();
diff --git a/core/class_db.cpp b/core/class_db.cpp
index 57e88044b5..edd49fe95f 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -1036,7 +1036,6 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
r_value = *c;
return true;
}
- //if (check->constant_map.fin)
check = check->inherits_ptr;
}
@@ -1163,24 +1162,6 @@ bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inhe
return false;
}
-bool ClassDB::get_setter_and_type_for_property(const StringName &p_class, const StringName &p_prop, StringName &r_class, StringName &r_setter) {
-
- ClassInfo *type = classes.getptr(p_class);
- ClassInfo *check = type;
- while (check) {
-
- if (check->property_setget.has(p_prop)) {
- r_class = check->name;
- r_setter = check->property_setget[p_prop].setter;
- return true;
- }
-
- check = check->inherits_ptr;
- }
-
- return false;
-}
-
#ifdef DEBUG_METHODS_ENABLED
MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
StringName mdname = method_name.name;
diff --git a/core/class_db.h b/core/class_db.h
index 24db4c61bb..55fe01ec6d 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -49,10 +49,10 @@ struct MethodDefinition {
StringName name;
Vector<StringName> args;
MethodDefinition() {}
- MethodDefinition(const char *p_name)
- : name(p_name) {}
- MethodDefinition(const StringName &p_name)
- : name(p_name) {}
+ MethodDefinition(const char *p_name) :
+ name(p_name) {}
+ MethodDefinition(const StringName &p_name) :
+ name(p_name) {}
};
MethodDefinition D_METHOD(const char *p_name);
@@ -349,8 +349,6 @@ public:
static StringName get_category(const StringName &p_node);
- static bool get_setter_and_type_for_property(const StringName &p_class, const StringName &p_prop, StringName &r_class, StringName &r_setter);
-
static void set_class_enabled(StringName p_class, bool p_enable);
static bool is_class_enabled(StringName p_class);
diff --git a/core/color.h b/core/color.h
index 972b6a1b33..da2bfdcd98 100644
--- a/core/color.h
+++ b/core/color.h
@@ -101,6 +101,24 @@ struct Color {
return res;
}
+ _FORCE_INLINE_ Color darkened(float p_amount) const {
+
+ Color res = *this;
+ res.r = CLAMP(res.r * (1.0f - p_amount), 0.0, 1.0);
+ res.g = CLAMP(res.g * (1.0f - p_amount), 0.0, 1.0);
+ res.b = CLAMP(res.b * (1.0f - p_amount), 0.0, 1.0);
+ return res;
+ }
+
+ _FORCE_INLINE_ Color lightened(float p_amount) const {
+
+ Color res = *this;
+ res.r = CLAMP(res.r + (1.0f - res.r) * p_amount, 0.0, 1.0);
+ res.g = CLAMP(res.g + (1.0f - res.g) * p_amount, 0.0, 1.0);
+ res.b = CLAMP(res.b + (1.0f - res.b) * p_amount, 0.0, 1.0);
+ return res;
+ }
+
_FORCE_INLINE_ uint32_t to_rgbe9995() const {
const float pow2to9 = 512.0f;
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index 8e2aa24c22..2028a18a06 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -76,6 +76,30 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() {
return &sync_sems[idx];
}
+bool CommandQueueMT::dealloc_one() {
+tryagain:
+ if (dealloc_ptr == write_ptr) {
+ // The queue is empty
+ return false;
+ }
+
+ uint32_t size = *(uint32_t *)&command_mem[dealloc_ptr];
+
+ if (size == 0) {
+ // End of command buffer wrap down
+ dealloc_ptr = 0;
+ goto tryagain;
+ }
+
+ if (size & 1) {
+ // Still used, nothing can be deallocated
+ return false;
+ }
+
+ dealloc_ptr += (size >> 1) + sizeof(uint32_t);
+ return true;
+}
+
CommandQueueMT::CommandQueueMT(bool p_sync) {
read_ptr = 0;
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index e37d593f9f..af91ee0cd9 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -39,6 +39,230 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
+#define COMMA(N) _COMMA_##N
+#define _COMMA_0
+#define _COMMA_1 ,
+#define _COMMA_2 ,
+#define _COMMA_3 ,
+#define _COMMA_4 ,
+#define _COMMA_5 ,
+#define _COMMA_6 ,
+#define _COMMA_7 ,
+#define _COMMA_8 ,
+#define _COMMA_9 ,
+#define _COMMA_10 ,
+#define _COMMA_11 ,
+#define _COMMA_12 ,
+
+// 1-based comma separed list of ITEMs
+#define COMMA_SEP_LIST(ITEM, LENGTH) _COMMA_SEP_LIST_##LENGTH(ITEM)
+#define _COMMA_SEP_LIST_12(ITEM) \
+ _COMMA_SEP_LIST_11(ITEM) \
+ , ITEM(12)
+#define _COMMA_SEP_LIST_11(ITEM) \
+ _COMMA_SEP_LIST_10(ITEM) \
+ , ITEM(11)
+#define _COMMA_SEP_LIST_10(ITEM) \
+ _COMMA_SEP_LIST_9(ITEM) \
+ , ITEM(10)
+#define _COMMA_SEP_LIST_9(ITEM) \
+ _COMMA_SEP_LIST_8(ITEM) \
+ , ITEM(9)
+#define _COMMA_SEP_LIST_8(ITEM) \
+ _COMMA_SEP_LIST_7(ITEM) \
+ , ITEM(8)
+#define _COMMA_SEP_LIST_7(ITEM) \
+ _COMMA_SEP_LIST_6(ITEM) \
+ , ITEM(7)
+#define _COMMA_SEP_LIST_6(ITEM) \
+ _COMMA_SEP_LIST_5(ITEM) \
+ , ITEM(6)
+#define _COMMA_SEP_LIST_5(ITEM) \
+ _COMMA_SEP_LIST_4(ITEM) \
+ , ITEM(5)
+#define _COMMA_SEP_LIST_4(ITEM) \
+ _COMMA_SEP_LIST_3(ITEM) \
+ , ITEM(4)
+#define _COMMA_SEP_LIST_3(ITEM) \
+ _COMMA_SEP_LIST_2(ITEM) \
+ , ITEM(3)
+#define _COMMA_SEP_LIST_2(ITEM) \
+ _COMMA_SEP_LIST_1(ITEM) \
+ , ITEM(2)
+#define _COMMA_SEP_LIST_1(ITEM) \
+ _COMMA_SEP_LIST_0(ITEM) \
+ ITEM(1)
+#define _COMMA_SEP_LIST_0(ITEM)
+
+// 1-based semicolon separed list of ITEMs
+#define SEMIC_SEP_LIST(ITEM, LENGTH) _SEMIC_SEP_LIST_##LENGTH(ITEM)
+#define _SEMIC_SEP_LIST_12(ITEM) \
+ _SEMIC_SEP_LIST_11(ITEM); \
+ ITEM(12)
+#define _SEMIC_SEP_LIST_11(ITEM) \
+ _SEMIC_SEP_LIST_10(ITEM); \
+ ITEM(11)
+#define _SEMIC_SEP_LIST_10(ITEM) \
+ _SEMIC_SEP_LIST_9(ITEM); \
+ ITEM(10)
+#define _SEMIC_SEP_LIST_9(ITEM) \
+ _SEMIC_SEP_LIST_8(ITEM); \
+ ITEM(9)
+#define _SEMIC_SEP_LIST_8(ITEM) \
+ _SEMIC_SEP_LIST_7(ITEM); \
+ ITEM(8)
+#define _SEMIC_SEP_LIST_7(ITEM) \
+ _SEMIC_SEP_LIST_6(ITEM); \
+ ITEM(7)
+#define _SEMIC_SEP_LIST_6(ITEM) \
+ _SEMIC_SEP_LIST_5(ITEM); \
+ ITEM(6)
+#define _SEMIC_SEP_LIST_5(ITEM) \
+ _SEMIC_SEP_LIST_4(ITEM); \
+ ITEM(5)
+#define _SEMIC_SEP_LIST_4(ITEM) \
+ _SEMIC_SEP_LIST_3(ITEM); \
+ ITEM(4)
+#define _SEMIC_SEP_LIST_3(ITEM) \
+ _SEMIC_SEP_LIST_2(ITEM); \
+ ITEM(3)
+#define _SEMIC_SEP_LIST_2(ITEM) \
+ _SEMIC_SEP_LIST_1(ITEM); \
+ ITEM(2)
+#define _SEMIC_SEP_LIST_1(ITEM) \
+ _SEMIC_SEP_LIST_0(ITEM) \
+ ITEM(1)
+#define _SEMIC_SEP_LIST_0(ITEM)
+
+// 1-based space separed list of ITEMs
+#define SPACE_SEP_LIST(ITEM, LENGTH) _SPACE_SEP_LIST_##LENGTH(ITEM)
+#define _SPACE_SEP_LIST_12(ITEM) \
+ _SPACE_SEP_LIST_11(ITEM) \
+ ITEM(12)
+#define _SPACE_SEP_LIST_11(ITEM) \
+ _SPACE_SEP_LIST_10(ITEM) \
+ ITEM(11)
+#define _SPACE_SEP_LIST_10(ITEM) \
+ _SPACE_SEP_LIST_9(ITEM) \
+ ITEM(10)
+#define _SPACE_SEP_LIST_9(ITEM) \
+ _SPACE_SEP_LIST_8(ITEM) \
+ ITEM(9)
+#define _SPACE_SEP_LIST_8(ITEM) \
+ _SPACE_SEP_LIST_7(ITEM) \
+ ITEM(8)
+#define _SPACE_SEP_LIST_7(ITEM) \
+ _SPACE_SEP_LIST_6(ITEM) \
+ ITEM(7)
+#define _SPACE_SEP_LIST_6(ITEM) \
+ _SPACE_SEP_LIST_5(ITEM) \
+ ITEM(6)
+#define _SPACE_SEP_LIST_5(ITEM) \
+ _SPACE_SEP_LIST_4(ITEM) \
+ ITEM(5)
+#define _SPACE_SEP_LIST_4(ITEM) \
+ _SPACE_SEP_LIST_3(ITEM) \
+ ITEM(4)
+#define _SPACE_SEP_LIST_3(ITEM) \
+ _SPACE_SEP_LIST_2(ITEM) \
+ ITEM(3)
+#define _SPACE_SEP_LIST_2(ITEM) \
+ _SPACE_SEP_LIST_1(ITEM) \
+ ITEM(2)
+#define _SPACE_SEP_LIST_1(ITEM) \
+ _SPACE_SEP_LIST_0(ITEM) \
+ ITEM(1)
+#define _SPACE_SEP_LIST_0(ITEM)
+
+#define ARG(N) p##N
+#define PARAM(N) P##N p##N
+#define TYPE_PARAM(N) class P##N
+#define PARAM_DECL(N) typename GetSimpleTypeT<P##N>::type_t p##N
+
+#define DECL_CMD(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ struct Command##N : public CommandBase { \
+ T *instance; \
+ M method; \
+ SEMIC_SEP_LIST(PARAM_DECL, N); \
+ virtual void call() { \
+ (instance->*method)(COMMA_SEP_LIST(ARG, N)); \
+ } \
+ };
+
+#define DECL_CMD_RET(N) \
+ template <class T, class M, COMMA_SEP_LIST(TYPE_PARAM, N) COMMA(N) class R> \
+ struct CommandRet##N : public SyncCommand { \
+ R *ret; \
+ T *instance; \
+ M method; \
+ SEMIC_SEP_LIST(PARAM_DECL, N); \
+ virtual void call() { \
+ *ret = (instance->*method)(COMMA_SEP_LIST(ARG, N)); \
+ } \
+ };
+
+#define DECL_CMD_SYNC(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ struct CommandSync##N : public SyncCommand { \
+ T *instance; \
+ M method; \
+ SEMIC_SEP_LIST(PARAM_DECL, N); \
+ virtual void call() { \
+ (instance->*method)(COMMA_SEP_LIST(ARG, N)); \
+ } \
+ };
+
+#define TYPE_ARG(N) P##N
+#define CMD_TYPE(N) Command##N<T, M COMMA(N) COMMA_SEP_LIST(TYPE_ARG, N)>
+#define CMD_ASSIGN_PARAM(N) cmd->p##N = p##N
+
+#define DECL_PUSH(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ void push(T *p_instance, M p_method COMMA(N) COMMA_SEP_LIST(PARAM, N)) { \
+ CMD_TYPE(N) *cmd = allocate_and_lock<CMD_TYPE(N)>(); \
+ cmd->instance = p_instance; \
+ cmd->method = p_method; \
+ SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
+ unlock(); \
+ if (sync) sync->post(); \
+ }
+
+#define CMD_RET_TYPE(N) CommandRet##N<T, M, COMMA_SEP_LIST(TYPE_ARG, N) COMMA(N) R>
+
+#define DECL_PUSH_AND_RET(N) \
+ template <class T, class M, COMMA_SEP_LIST(TYPE_PARAM, N) COMMA(N) class R> \
+ void push_and_ret(T *p_instance, M p_method, COMMA_SEP_LIST(PARAM, N) COMMA(N) R *r_ret) { \
+ SyncSemaphore *ss = _alloc_sync_sem(); \
+ CMD_RET_TYPE(N) *cmd = allocate_and_lock<CMD_RET_TYPE(N)>(); \
+ cmd->instance = p_instance; \
+ cmd->method = p_method; \
+ SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
+ cmd->ret = r_ret; \
+ cmd->sync_sem = ss; \
+ unlock(); \
+ if (sync) sync->post(); \
+ ss->sem->wait(); \
+ }
+
+#define CMD_SYNC_TYPE(N) CommandSync##N<T, M COMMA(N) COMMA_SEP_LIST(TYPE_ARG, N)>
+
+#define DECL_PUSH_AND_SYNC(N) \
+ template <class T, class M COMMA(N) COMMA_SEP_LIST(TYPE_PARAM, N)> \
+ void push_and_sync(T *p_instance, M p_method COMMA(N) COMMA_SEP_LIST(PARAM, N)) { \
+ SyncSemaphore *ss = _alloc_sync_sem(); \
+ CMD_SYNC_TYPE(N) *cmd = allocate_and_lock<CMD_SYNC_TYPE(N)>(); \
+ cmd->instance = p_instance; \
+ cmd->method = p_method; \
+ SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
+ cmd->sync_sem = ss; \
+ unlock(); \
+ if (sync) sync->post(); \
+ ss->sem->wait(); \
+ }
+
+#define MAX_CMD_PARAMS 12
+
class CommandQueueMT {
struct SyncSemaphore {
@@ -50,551 +274,30 @@ class CommandQueueMT {
struct CommandBase {
virtual void call() = 0;
+ virtual void post(){};
virtual ~CommandBase(){};
};
- template <class T, class M>
- struct Command0 : public CommandBase {
-
- T *instance;
- M method;
-
- virtual void call() { (instance->*method)(); }
- };
-
- template <class T, class M, class P1>
- struct Command1 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
-
- virtual void call() { (instance->*method)(p1); }
- };
-
- template <class T, class M, class P1, class P2>
- struct Command2 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
-
- virtual void call() { (instance->*method)(p1, p2); }
- };
-
- template <class T, class M, class P1, class P2, class P3>
- struct Command3 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
-
- virtual void call() { (instance->*method)(p1, p2, p3); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- struct Command4 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- struct Command5 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- struct Command6 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- struct Command7 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- struct Command8 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>
- struct Command9 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>
- struct Command10 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
- typename GetSimpleTypeT<P10>::type_t p10;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11>
- struct Command11 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
- typename GetSimpleTypeT<P10>::type_t p10;
- typename GetSimpleTypeT<P11>::type_t p11;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11, class P12>
- struct Command12 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- typename GetSimpleTypeT<P9>::type_t p9;
- typename GetSimpleTypeT<P10>::type_t p10;
- typename GetSimpleTypeT<P11>::type_t p11;
- typename GetSimpleTypeT<P12>::type_t p12;
-
- virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); }
- };
-
- /* comands that return */
-
- template <class T, class M, class R>
- struct CommandRet0 : public CommandBase {
-
- T *instance;
- M method;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)();
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class R>
- struct CommandRet1 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class R>
- struct CommandRet2 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class R>
- struct CommandRet3 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class R>
- struct CommandRet4 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class R>
- struct CommandRet5 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class R>
- struct CommandRet6 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5, p6);
- sync->sem->post();
- sync->in_use = false;
- }
- };
+ struct SyncCommand : public CommandBase {
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class R>
- struct CommandRet7 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5, p6, p7);
- sync->sem->post();
- sync->in_use = false;
- }
- };
+ SyncSemaphore *sync_sem;
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class R>
- struct CommandRet8 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
- R *ret;
- SyncSemaphore *sync;
-
- virtual void call() {
- *ret = (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8);
- sync->sem->post();
- sync->in_use = false;
+ virtual void post() {
+ sync_sem->sem->post();
+ sync_sem->in_use = false;
}
};
- /** commands that don't return but sync */
+ DECL_CMD(0)
+ SPACE_SEP_LIST(DECL_CMD, 12)
/* comands that return */
+ DECL_CMD_RET(0)
+ SPACE_SEP_LIST(DECL_CMD_RET, 12)
- template <class T, class M>
- struct CommandSync0 : public CommandBase {
-
- T *instance;
- M method;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)();
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1>
- struct CommandSync1 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2>
- struct CommandSync2 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3>
- struct CommandSync3 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- struct CommandSync4 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- struct CommandSync5 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- struct CommandSync6 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5, p6);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- struct CommandSync7 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5, p6, p7);
- sync->sem->post();
- sync->in_use = false;
- }
- };
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- struct CommandSync8 : public CommandBase {
-
- T *instance;
- M method;
- typename GetSimpleTypeT<P1>::type_t p1;
- typename GetSimpleTypeT<P2>::type_t p2;
- typename GetSimpleTypeT<P3>::type_t p3;
- typename GetSimpleTypeT<P4>::type_t p4;
- typename GetSimpleTypeT<P5>::type_t p5;
- typename GetSimpleTypeT<P6>::type_t p6;
- typename GetSimpleTypeT<P7>::type_t p7;
- typename GetSimpleTypeT<P8>::type_t p8;
-
- SyncSemaphore *sync;
-
- virtual void call() {
- (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8);
- sync->sem->post();
- sync->in_use = false;
- }
- };
+ /* commands that don't return but sync */
+ DECL_CMD_SYNC(0)
+ SPACE_SEP_LIST(DECL_CMD_SYNC, 12)
/***** BASE *******/
@@ -607,6 +310,7 @@ class CommandQueueMT {
uint8_t command_mem[COMMAND_MEM_SIZE];
uint32_t read_ptr;
uint32_t write_ptr;
+ uint32_t dealloc_ptr;
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex *mutex;
Semaphore *sync;
@@ -619,18 +323,30 @@ class CommandQueueMT {
tryagain:
- if (write_ptr < read_ptr) {
- // behind read_ptr, check that there is room
- if ((read_ptr - write_ptr) <= alloc_size)
+ if (write_ptr < dealloc_ptr) {
+ // behind dealloc_ptr, check that there is room
+ if ((dealloc_ptr - write_ptr) <= alloc_size) {
+
+ // There is no more room, try to deallocate something
+ if (dealloc_one()) {
+ goto tryagain;
+ }
return NULL;
- } else if (write_ptr >= read_ptr) {
- // ahead of read_ptr, check that there is room
+ }
+ } else if (write_ptr >= dealloc_ptr) {
+ // ahead of dealloc_ptr, check that there is room
- if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + 4) {
+ if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + sizeof(uint32_t)) {
// no room at the end, wrap down;
- if (read_ptr == 0) // don't want write_ptr to become read_ptr
+ if (dealloc_ptr == 0) { // don't want write_ptr to become dealloc_ptr
+
+ // There is no more room, try to deallocate something
+ if (dealloc_one()) {
+ goto tryagain;
+ }
return NULL;
+ }
// if this happens, it's a bug
ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < sizeof(uint32_t), NULL);
@@ -642,9 +358,11 @@ class CommandQueueMT {
goto tryagain;
}
}
- // allocate the size
+ // 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 *p = (uint32_t *)&command_mem[write_ptr];
- *p = sizeof(T);
+ *p = (sizeof(T) << 1) | 1;
write_ptr += sizeof(uint32_t);
// allocate the command
T *cmd = memnew_placement(&command_mem[write_ptr], T);
@@ -669,15 +387,16 @@ class CommandQueueMT {
return ret;
}
- bool flush_one() {
-
+ bool flush_one(bool p_lock = true) {
+ if (p_lock) lock();
tryagain:
// tried to read an empty queue
if (read_ptr == write_ptr)
return false;
- uint32_t size = *(uint32_t *)(&command_mem[read_ptr]);
+ uint32_t size_ptr = read_ptr;
+ uint32_t size = *(uint32_t *)&command_mem[read_ptr] >> 1;
if (size == 0) {
//end of ringbuffer, wrap
@@ -689,11 +408,17 @@ class CommandQueueMT {
CommandBase *cmd = reinterpret_cast<CommandBase *>(&command_mem[read_ptr]);
+ read_ptr += size;
+
+ if (p_lock) unlock();
cmd->call();
- cmd->~CommandBase();
+ if (p_lock) lock();
- read_ptr += size;
+ cmd->post();
+ cmd->~CommandBase();
+ *(uint32_t *)&command_mem[size_ptr] &= ~1;
+ if (p_lock) unlock();
return true;
}
@@ -701,681 +426,33 @@ class CommandQueueMT {
void unlock();
void wait_for_flush();
SyncSemaphore *_alloc_sync_sem();
+ bool dealloc_one();
public:
/* NORMAL PUSH COMMANDS */
+ DECL_PUSH(0)
+ SPACE_SEP_LIST(DECL_PUSH, 12)
- template <class T, class M>
- void push(T *p_instance, M p_method) {
-
- Command0<T, M> *cmd = allocate_and_lock<Command0<T, M> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1>
- void push(T *p_instance, M p_method, P1 p1) {
-
- Command1<T, M, P1> *cmd = allocate_and_lock<Command1<T, M, P1> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2>
- void push(T *p_instance, M p_method, P1 p1, P2 p2) {
-
- Command2<T, M, P1, P2> *cmd = allocate_and_lock<Command2<T, M, P1, P2> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3) {
-
- Command3<T, M, P1, P2, P3> *cmd = allocate_and_lock<Command3<T, M, P1, P2, P3> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4) {
-
- Command4<T, M, P1, P2, P3, P4> *cmd = allocate_and_lock<Command4<T, M, P1, P2, P3, P4> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
-
- Command5<T, M, P1, P2, P3, P4, P5> *cmd = allocate_and_lock<Command5<T, M, P1, P2, P3, P4, P5> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
-
- Command6<T, M, P1, P2, P3, P4, P5, P6> *cmd = allocate_and_lock<Command6<T, M, P1, P2, P3, P4, P5, P6> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
-
- Command7<T, M, P1, P2, P3, P4, P5, P6, P7> *cmd = allocate_and_lock<Command7<T, M, P1, P2, P3, P4, P5, P6, P7> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
-
- Command8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> *cmd = allocate_and_lock<Command8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
-
- unlock();
-
- if (sync) sync->post();
- }
+ /* PUSH AND RET COMMANDS */
+ DECL_PUSH_AND_RET(0)
+ SPACE_SEP_LIST(DECL_PUSH_AND_RET, 12)
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {
-
- Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> *cmd = allocate_and_lock<Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {
-
- Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> *cmd = allocate_and_lock<Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
- cmd->p10 = p10;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11) {
-
- Command11<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> *cmd = allocate_and_lock<Command11<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
- cmd->p10 = p10;
- cmd->p11 = p11;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10, class P11, class P12>
- void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, P11 p11, P12 p12) {
-
- Command12<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> *cmd = allocate_and_lock<Command12<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->p9 = p9;
- cmd->p10 = p10;
- cmd->p11 = p11;
- cmd->p12 = p12;
-
- unlock();
-
- if (sync) sync->post();
- }
-
- /*** PUSH AND RET COMMANDS ***/
-
- template <class T, class M, class R>
- void push_and_ret(T *p_instance, M p_method, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet0<T, M, R> *cmd = allocate_and_lock<CommandRet0<T, M, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet1<T, M, P1, R> *cmd = allocate_and_lock<CommandRet1<T, M, P1, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet2<T, M, P1, P2, R> *cmd = allocate_and_lock<CommandRet2<T, M, P1, P2, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet3<T, M, P1, P2, P3, R> *cmd = allocate_and_lock<CommandRet3<T, M, P1, P2, P3, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet4<T, M, P1, P2, P3, P4, R> *cmd = allocate_and_lock<CommandRet4<T, M, P1, P2, P3, P4, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet5<T, M, P1, P2, P3, P4, P5, R> *cmd = allocate_and_lock<CommandRet5<T, M, P1, P2, P3, P4, P5, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet6<T, M, P1, P2, P3, P4, P5, P6, R> *cmd = allocate_and_lock<CommandRet6<T, M, P1, P2, P3, P4, P5, P6, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet7<T, M, P1, P2, P3, P4, P5, P6, P7, R> *cmd = allocate_and_lock<CommandRet7<T, M, P1, P2, P3, P4, P5, P6, P7, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class R>
- void push_and_ret(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, R *r_ret) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandRet8<T, M, P1, P2, P3, P4, P5, P6, P7, P8, R> *cmd = allocate_and_lock<CommandRet8<T, M, P1, P2, P3, P4, P5, P6, P7, P8, R> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
- cmd->ret = r_ret;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M>
- void push_and_sync(T *p_instance, M p_method) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync0<T, M> *cmd = allocate_and_lock<CommandSync0<T, M> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1>
- void push_and_sync(T *p_instance, M p_method, P1 p1) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync1<T, M, P1> *cmd = allocate_and_lock<CommandSync1<T, M, P1> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync2<T, M, P1, P2> *cmd = allocate_and_lock<CommandSync2<T, M, P1, P2> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync3<T, M, P1, P2, P3> *cmd = allocate_and_lock<CommandSync3<T, M, P1, P2, P3> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync4<T, M, P1, P2, P3, P4> *cmd = allocate_and_lock<CommandSync4<T, M, P1, P2, P3, P4> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync5<T, M, P1, P2, P3, P4, P5> *cmd = allocate_and_lock<CommandSync5<T, M, P1, P2, P3, P4, P5> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync6<T, M, P1, P2, P3, P4, P5, P6> *cmd = allocate_and_lock<CommandSync6<T, M, P1, P2, P3, P4, P5, P6> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync7<T, M, P1, P2, P3, P4, P5, P6, P7> *cmd = allocate_and_lock<CommandSync7<T, M, P1, P2, P3, P4, P5, P6, P7> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
-
- template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
- void push_and_sync(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
-
- SyncSemaphore *ss = _alloc_sync_sem();
-
- CommandSync8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> *cmd = allocate_and_lock<CommandSync8<T, M, P1, P2, P3, P4, P5, P6, P7, P8> >();
-
- cmd->instance = p_instance;
- cmd->method = p_method;
- cmd->p1 = p1;
- cmd->p2 = p2;
- cmd->p3 = p3;
- cmd->p4 = p4;
- cmd->p5 = p5;
- cmd->p6 = p6;
- cmd->p7 = p7;
- cmd->p8 = p8;
-
- cmd->sync = ss;
-
- unlock();
-
- if (sync) sync->post();
- ss->sem->wait();
- }
+ /* PUSH AND RET SYNC COMMANDS*/
+ DECL_PUSH_AND_SYNC(0)
+ SPACE_SEP_LIST(DECL_PUSH_AND_SYNC, 12)
void wait_and_flush_one() {
ERR_FAIL_COND(!sync);
sync->wait();
- lock();
flush_one();
- unlock();
}
void flush_all() {
//ERR_FAIL_COND(sync);
lock();
- while (true) {
- bool exit = !flush_one();
- if (exit)
- break;
- }
+ while (flush_one(false))
+ ;
unlock();
}
@@ -1383,4 +460,20 @@ public:
~CommandQueueMT();
};
+#undef ARG
+#undef PARAM
+#undef TYPE_PARAM
+#undef PARAM_DECL
+#undef DECL_CMD
+#undef DECL_CMD_RET
+#undef DECL_CMD_SYNC
+#undef TYPE_ARG
+#undef CMD_TYPE
+#undef CMD_ASSIGN_PARAM
+#undef DECL_PUSH
+#undef CMD_RET_TYPE
+#undef DECL_PUSH_AND_RET
+#undef CMD_SYNC_TYPE
+#undef DECL_CMD_SYNC
+
#endif
diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp
index 74565d2e32..5c7b793590 100644
--- a/core/compressed_translation.cpp
+++ b/core/compressed_translation.cpp
@@ -288,7 +288,7 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
CharString uncomp;
uncomp.resize(bucket.elem[idx].uncomp_size + 1);
- smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptr(), bucket.elem[idx].uncomp_size);
+ smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
String rstr;
rstr.parse_utf8(uncomp.get_data());
//print_line("Compressed, size: "+itos(bucket.elem[idx].comp_size));
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index feee39225f..3091c80607 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -31,22 +31,22 @@
CoreStringNames *CoreStringNames::singleton = NULL;
-CoreStringNames::CoreStringNames()
- : _free(StaticCString::create("free")),
- changed(StaticCString::create("changed")),
- _meta(StaticCString::create("__meta__")),
- _script(StaticCString::create("script")),
- script_changed(StaticCString::create("script_changed")),
- ___pdcdata(StaticCString::create("___pdcdata")),
- __getvar(StaticCString::create("__getvar")),
- _iter_init(StaticCString::create("_iter_init")),
- _iter_next(StaticCString::create("_iter_next")),
- _iter_get(StaticCString::create("_iter_get")),
- get_rid(StaticCString::create("get_rid")),
+CoreStringNames::CoreStringNames() :
+ _free(StaticCString::create("free")),
+ changed(StaticCString::create("changed")),
+ _meta(StaticCString::create("__meta__")),
+ _script(StaticCString::create("script")),
+ script_changed(StaticCString::create("script_changed")),
+ ___pdcdata(StaticCString::create("___pdcdata")),
+ __getvar(StaticCString::create("__getvar")),
+ _iter_init(StaticCString::create("_iter_init")),
+ _iter_next(StaticCString::create("_iter_next")),
+ _iter_get(StaticCString::create("_iter_get")),
+ get_rid(StaticCString::create("get_rid")),
#ifdef TOOLS_ENABLED
- _sections_unfolded(StaticCString::create("_sections_unfolded")),
+ _sections_unfolded(StaticCString::create("_sections_unfolded")),
#endif
- _custom_features(StaticCString::create("_custom_features")) {
+ _custom_features(StaticCString::create("_custom_features")) {
x = StaticCString::create("x");
y = StaticCString::create("y");
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 48e65c734f..44fce2474f 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -204,7 +204,9 @@ const Variant *Dictionary::next(const Variant *p_key) const {
if (p_key == NULL) {
// caller wants to get the first element
- return &_p->variant_map.front().key();
+ if (_p->variant_map.front())
+ return &_p->variant_map.front().key();
+ return NULL;
}
OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.find(*p_key);
diff --git a/core/dvector.h b/core/dvector.h
index 1b81ceec5e..66bf0e7862 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -149,7 +149,7 @@ class PoolVector {
}
if (old_alloc->refcount.unref() == true) {
-//this should never happen but..
+ //this should never happen but..
#ifdef DEBUG_ENABLED
MemoryPool::alloc_mutex->lock();
diff --git a/core/engine.h b/core/engine.h
index 4a573c1539..1becebe34a 100644
--- a/core/engine.h
+++ b/core/engine.h
@@ -41,9 +41,9 @@ public:
struct Singleton {
StringName name;
Object *ptr;
- Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL)
- : name(p_name),
- ptr(p_ptr) {
+ Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) :
+ name(p_name),
+ ptr(p_ptr) {
}
};
diff --git a/core/error_list.h b/core/error_list.h
index 50d248b3d0..9a36b27aab 100644
--- a/core/error_list.h
+++ b/core/error_list.h
@@ -87,8 +87,6 @@ enum Error {
ERR_HELP, ///< user requested help!!
ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
- ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
- ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
};
#endif
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index 7d85aa9001..a942b1dd2d 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -101,6 +101,6 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, bool fatal) {
String fstr(fatal ? "FATAL: " : "");
- String err(fstr + "Index" + p_index_str + "=" + itos(p_index) + " out of size (" + p_size_str + "=" + itos(p_size) + ")");
+ String err(fstr + "Index " + p_index_str + "=" + itos(p_index) + " out of size (" + p_size_str + "=" + itos(p_size) + ")");
_err_print_error(p_function, p_file, p_line, err.utf8().get_data());
}
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 48101c8cf1..a8f6e4da6c 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -45,15 +45,15 @@ struct _GlobalConstant {
_GlobalConstant() {}
#ifdef DEBUG_METHODS_ENABLED
- _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value)
- : enum_name(p_enum_name),
- name(p_name),
- value(p_value) {
+ _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value) :
+ enum_name(p_enum_name),
+ name(p_name),
+ value(p_value) {
}
#else
- _GlobalConstant(const char *p_name, int p_value)
- : name(p_name),
- value(p_value) {
+ _GlobalConstant(const char *p_name, int p_value) :
+ name(p_name),
+ value(p_value) {
}
#endif
};
@@ -491,7 +491,6 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(ERR_BUSY);
BIND_GLOBAL_ENUM_CONSTANT(ERR_HELP); ///< user requested help!!
BIND_GLOBAL_ENUM_CONSTANT(ERR_BUG); ///< a bug in the software certainly happened ), due to a double check failing or unexpected behavior.
- BIND_GLOBAL_ENUM_CONSTANT(ERR_WTF);
BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_NONE);
BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_RANGE);
diff --git a/core/hash_map.h b/core/hash_map.h
index e100d7a904..a53cb53c84 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -63,9 +63,9 @@ public:
TData data;
Pair() {}
- Pair(const TKey &p_key, const TData &p_data)
- : key(p_key),
- data(p_data) {
+ Pair(const TKey &p_key, const TData &p_data) :
+ key(p_key),
+ data(p_data) {
}
};
diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp
index 2cd8a4f392..9e5eab2ee8 100644
--- a/core/helper/math_fieldwise.cpp
+++ b/core/helper/math_fieldwise.cpp
@@ -44,10 +44,10 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
ERR_FAIL_COND_V(p_target.get_type() != p_source.get_type(), p_target);
- switch (p_source.get_type()) {
+ /* clang-format makes a mess of this macro usage */
+ /* clang-format off */
- /* clang-format makes a mess of this macro usage */
- /* clang-format off */
+ switch (p_source.get_type()) {
case Variant::VECTOR2: {
@@ -174,9 +174,8 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
default: {
ERR_FAIL_V(p_target);
}
-
- /* clang-format on */
}
+ /* clang-format on */
}
#endif // TOOLS_ENABLED
diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h
index 309fc16d09..67751e840f 100644
--- a/core/io/file_access_buffered_fa.h
+++ b/core/io/file_access_buffered_fa.h
@@ -55,10 +55,10 @@ class FileAccessBufferedFA : public FileAccessBuffered {
// on dvector
//PoolVector<uint8_t>::Write write = cache.buffer.write();
- //f.get_buffer(write.ptr(), p_size);
+ //f.get_buffer(write.ptrw(), p_size);
// on vector
- f.get_buffer(cache.buffer.ptr(), p_size);
+ f.get_buffer(cache.buffer.ptrw(), p_size);
return p_size;
};
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 514e3c65f0..c6f31dc8f0 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -51,7 +51,7 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_
if (write_max > write_buffer_size) { \
write_buffer_size = next_power_of_2(write_max); \
buffer.resize(write_buffer_size); \
- write_ptr = buffer.ptr(); \
+ write_ptr = buffer.ptrw(); \
} \
}
@@ -76,14 +76,14 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
comp_buffer.resize(max_bs);
buffer.resize(block_size);
- read_ptr = buffer.ptr();
- f->get_buffer(comp_buffer.ptr(), read_blocks[0].csize);
+ read_ptr = buffer.ptrw();
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[0].csize);
at_end = false;
read_eof = false;
read_block_count = bc;
read_block_size = read_blocks.size() == 1 ? read_total : block_size;
- Compression::decompress(buffer.ptr(), read_block_size, comp_buffer.ptr(), read_blocks[0].csize, cmode);
+ Compression::decompress(buffer.ptrw(), read_block_size, comp_buffer.ptr(), read_blocks[0].csize, cmode);
read_block = 0;
read_pos = 0;
@@ -114,7 +114,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
write_buffer_size = 256;
buffer.resize(256);
write_max = 0;
- write_ptr = buffer.ptr();
+ write_ptr = buffer.ptrw();
//don't store anything else unless it's done saving!
} else {
@@ -160,7 +160,7 @@ void FileAccessCompressed::close() {
Vector<uint8_t> cblock;
cblock.resize(Compression::get_max_compressed_buffer_size(bl, cmode));
- int s = Compression::compress(cblock.ptr(), bp, bl, cmode);
+ int s = Compression::compress(cblock.ptrw(), bp, bl, cmode);
f->store_buffer(cblock.ptr(), s);
block_sizes.push_back(s);
@@ -211,8 +211,8 @@ void FileAccessCompressed::seek(size_t p_position) {
read_block = block_idx;
f->seek(read_blocks[read_block].offset);
- f->get_buffer(comp_buffer.ptr(), read_blocks[read_block].csize);
- Compression::decompress(buffer.ptr(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
+ Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
}
@@ -282,8 +282,8 @@ uint8_t FileAccessCompressed::get_8() const {
if (read_block < read_block_count) {
//read another block of compressed data
- f->get_buffer(comp_buffer.ptr(), read_blocks[read_block].csize);
- Compression::decompress(buffer.ptr(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
+ Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
read_pos = 0;
@@ -315,8 +315,8 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
if (read_block < read_block_count) {
//read another block of compressed data
- f->get_buffer(comp_buffer.ptr(), read_blocks[read_block].csize);
- Compression::decompress(buffer.ptr(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
+ f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
+ Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
read_pos = 0;
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index e5da307153..71ebf57508 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -80,11 +80,11 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
data.resize(ds);
- uint32_t blen = p_base->get_buffer(data.ptr(), ds);
+ uint32_t blen = p_base->get_buffer(data.ptrw(), ds);
ERR_FAIL_COND_V(blen != ds, ERR_FILE_CORRUPT);
aes256_context ctx;
- aes256_init(&ctx, key.ptr());
+ aes256_init(&ctx, key.ptrw());
for (size_t i = 0; i < ds; i += 16) {
@@ -97,7 +97,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
MD5_CTX md5;
MD5Init(&md5);
- MD5Update(&md5, data.ptr(), data.size());
+ MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
ERR_FAIL_COND_V(String::md5(md5.digest) != String::md5(md5d), ERR_FILE_CORRUPT);
@@ -141,17 +141,17 @@ void FileAccessEncrypted::close() {
MD5_CTX md5;
MD5Init(&md5);
- MD5Update(&md5, data.ptr(), data.size());
+ MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
compressed.resize(len);
- zeromem(compressed.ptr(), len);
+ zeromem(compressed.ptrw(), len);
for (int i = 0; i < data.size(); i++) {
compressed[i] = data[i];
}
aes256_context ctx;
- aes256_init(&ctx, key.ptr());
+ aes256_init(&ctx, key.ptrw());
for (size_t i = 0; i < len; i += 16) {
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index a224abd9e7..61a0521cae 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -147,7 +147,7 @@ void FileAccessNetworkClient::_thread_func() {
Vector<uint8_t> block;
block.resize(len);
- client->get_data(block.ptr(), len);
+ client->get_data(block.ptrw(), len);
if (fa) //may have been queued
fa->_set_block(offset, block);
@@ -434,12 +434,12 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
_queue_page(page + j);
}
- buff = pages[page].buffer.ptr();
+ buff = pages[page].buffer.ptrw();
//queue pages
buffer_mutex->unlock();
}
- buff = pages[page].buffer.ptr();
+ buff = pages[page].buffer.ptrw();
last_page_buff = buff;
last_page = page;
}
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index a7eb8ce6a9..c46e645ed8 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -313,9 +313,9 @@ bool FileAccessPack::file_exists(const String &p_name) {
return false;
}
-FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file)
- : pf(p_file),
- f(FileAccess::open(pf.pack, FileAccess::READ)) {
+FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) :
+ pf(p_file),
+ f(FileAccess::open(pf.pack, FileAccess::READ)) {
if (!f) {
ERR_EXPLAIN("Can't open pack-referenced file: " + String(pf.pack));
ERR_FAIL_COND(!f);
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 2e9170bc34..82e938d2db 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -43,7 +43,25 @@ const char *JSON::tk_name[TK_MAX] = {
"EOF",
};
-String JSON::_print_var(const Variant &p_var) {
+static String _make_indent(const String &p_indent, int p_size) {
+
+ String indent_text = "";
+ if (!p_indent.empty()) {
+ for (int i = 0; i < p_size; i++)
+ indent_text += p_indent;
+ }
+ return indent_text;
+}
+
+String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) {
+
+ String colon = ":";
+ String end_statement = "";
+
+ if (!p_indent.empty()) {
+ colon += " ";
+ end_statement += "\n";
+ }
switch (p_var.get_type()) {
@@ -57,41 +75,50 @@ String JSON::_print_var(const Variant &p_var) {
case Variant::ARRAY: {
String s = "[";
+ s += end_statement;
Array a = p_var;
for (int i = 0; i < a.size(); i++) {
- if (i > 0)
- s += ", ";
- s += _print_var(a[i]);
+ if (i > 0) {
+ s += ",";
+ s += end_statement;
+ }
+ s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(a[i], p_indent, p_cur_indent + 1, p_sort_keys);
}
- s += "]";
+ s += end_statement + _make_indent(p_indent, p_cur_indent) + "]";
return s;
};
case Variant::DICTIONARY: {
String s = "{";
+ s += end_statement;
Dictionary d = p_var;
List<Variant> keys;
d.get_key_list(&keys);
+ if (p_sort_keys)
+ keys.sort();
+
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
- if (E != keys.front())
- s += ", ";
- s += _print_var(String(E->get()));
- s += ":";
- s += _print_var(d[E->get()]);
+ if (E != keys.front()) {
+ s += ",";
+ s += end_statement;
+ }
+ s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys);
+ s += colon;
+ s += _print_var(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys);
}
- s += "}";
+ s += end_statement + _make_indent(p_indent, p_cur_indent) + "}";
return s;
};
default: return "\"" + String(p_var).json_escape() + "\"";
}
}
-String JSON::print(const Variant &p_var) {
+String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) {
- return _print_var(p_var);
+ return _print_var(p_var, p_indent, 0, p_sort_keys);
}
Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
diff --git a/core/io/json.h b/core/io/json.h
index 893a88e264..fbb7875c7c 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -64,7 +64,7 @@ class JSON {
static const char *tk_name[TK_MAX];
- static String _print_var(const Variant &p_var);
+ static String _print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys);
static Error _get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
static Error _parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str);
@@ -72,7 +72,7 @@ class JSON {
static Error _parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str);
public:
- static String print(const Variant &p_var);
+ static String print(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true);
static Error parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line);
};
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 1d9d2dd959..7dd3468c48 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -159,8 +159,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = str;
} break;
- // math types
+ // math types
case Variant::VECTOR2: {
ERR_FAIL_COND_V(len < (int)4 * 2, ERR_INVALID_DATA);
@@ -324,7 +324,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V(len < 12, ERR_INVALID_DATA);
Vector<StringName> names;
Vector<StringName> subnames;
- StringName prop;
uint32_t namecount = strlen &= 0x7FFFFFFF;
uint32_t subnamecount = decode_uint32(buf + 4);
@@ -333,9 +332,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 12;
buf += 12;
+ if (flags & 2) // Obsolete format with property seperate from subpath
+ subnamecount++;
+
uint32_t total = namecount + subnamecount;
- if (flags & 2)
- total++;
if (r_len)
(*r_len) += 12;
@@ -359,10 +359,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
if (i < namecount)
names.push_back(str);
- else if (i < namecount + subnamecount)
- subnames.push_back(str);
else
- prop = str;
+ subnames.push_back(str);
buf += strlen + pad;
len -= strlen + pad;
@@ -371,7 +369,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 4 + strlen + pad;
}
- r_variant = NodePath(names, subnames, flags & 1, prop);
+ r_variant = NodePath(names, subnames, flags & 1);
} else {
//old format, just a string
@@ -919,8 +917,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
uint32_t flags = 0;
if (np.is_absolute())
flags |= 1;
- if (np.get_property() != StringName())
- flags |= 2;
encode_uint32(flags, buf + 8);
@@ -930,8 +926,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 12;
int total = np.get_name_count() + np.get_subname_count();
- if (np.get_property() != StringName())
- total++;
for (int i = 0; i < total; i++) {
@@ -939,10 +933,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
if (i < np.get_name_count())
str = np.get_name(i);
- else if (i < np.get_name_count() + np.get_subname_count())
- str = np.get_subname(i - np.get_subname_count());
else
- str = np.get_property();
+ str = np.get_subname(i - np.get_name_count());
CharString utf8 = str.utf8();
@@ -967,8 +959,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
_encode_string(p_variant, buf, r_len);
} break;
- // math types
+ // math types
case Variant::VECTOR2: {
if (buf) {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 8dc396c362..df0d41ea9d 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -84,8 +84,10 @@ enum {
OBJECT_INTERNAL_RESOURCE = 2,
OBJECT_EXTERNAL_RESOURCE_INDEX = 3,
//version 2: added 64 bits support for float and int
- FORMAT_VERSION = 2,
- FORMAT_VERSION_CAN_RENAME_DEPS = 1
+ //version 3: changed nodepath encoding
+ FORMAT_VERSION = 3,
+ FORMAT_VERSION_CAN_RENAME_DEPS = 1,
+ FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3,
};
@@ -267,21 +269,22 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
Vector<StringName> names;
Vector<StringName> subnames;
- StringName property;
bool absolute;
int name_count = f->get_16();
uint32_t subname_count = f->get_16();
absolute = subname_count & 0x8000;
subname_count &= 0x7FFF;
+ if (ver_format < FORMAT_VERSION_NO_NODEPATH_PROPERTY) {
+ subname_count += 1; // has a property field, so we should count it as well
+ }
for (int i = 0; i < name_count; i++)
names.push_back(_get_string());
for (uint32_t i = 0; i < subname_count; i++)
subnames.push_back(_get_string());
- property = _get_string();
- NodePath np = NodePath(names, subnames, absolute, property);
+ NodePath np = NodePath(names, subnames, absolute);
r_v = np;
@@ -856,7 +859,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
uint32_t ver_major = f->get_32();
uint32_t ver_minor = f->get_32();
- uint32_t ver_format = f->get_32();
+ ver_format = f->get_32();
print_bl("big endian: " + itos(big_endian));
#ifdef BIG_ENDIAN_ENABLED
@@ -1454,7 +1457,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property,
f->store_32(get_string_index(np.get_name(i)));
for (int i = 0; i < np.get_subname_count(); i++)
f->store_32(get_string_index(np.get_subname(i)));
- f->store_32(get_string_index(np.get_property()));
} break;
case Variant::_RID: {
@@ -1685,7 +1687,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
get_string_index(np.get_name(i));
for (int i = 0; i < np.get_subname_count(); i++)
get_string_index(np.get_subname(i));
- get_string_index(np.get_property());
} break;
default: {}
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 2316f05b3c..687da0a9b4 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -41,6 +41,7 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
String res_path;
String type;
Ref<Resource> resource;
+ uint32_t ver_format;
FileAccess *f;
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
index 28489b5d34..166fff85cf 100644
--- a/core/io/resource_import.h
+++ b/core/io/resource_import.h
@@ -90,9 +90,9 @@ public:
PropertyInfo option;
Variant default_value;
- ImportOption(const PropertyInfo &p_info, const Variant &p_default)
- : option(p_info),
- default_value(p_default) {
+ ImportOption(const PropertyInfo &p_info, const Variant &p_default) :
+ option(p_info),
+ default_value(p_default) {
}
ImportOption() {}
};
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 2583eb369d..42a258a10d 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -220,7 +220,7 @@ void StreamPeer::put_var(const Variant &p_variant) {
encode_variant(p_variant, NULL, len);
buf.resize(len);
put_32(len);
- encode_variant(p_variant, buf.ptr(), len);
+ encode_variant(p_variant, buf.ptrw(), len);
put_data(buf.ptr(), buf.size());
}
@@ -340,7 +340,7 @@ String StreamPeer::get_utf8_string(int p_bytes) {
Vector<uint8_t> buf;
Error err = buf.resize(p_bytes);
ERR_FAIL_COND_V(err != OK, String());
- err = get_data(buf.ptr(), p_bytes);
+ err = get_data(buf.ptrw(), p_bytes);
ERR_FAIL_COND_V(err != OK, String());
String ret;
@@ -353,7 +353,7 @@ Variant StreamPeer::get_var() {
Vector<uint8_t> var;
Error err = var.resize(len);
ERR_FAIL_COND_V(err != OK, Variant());
- err = get_data(var.ptr(), len);
+ err = get_data(var.ptrw(), len);
ERR_FAIL_COND_V(err != OK, Variant());
Variant ret;
diff --git a/core/list.h b/core/list.h
index da201e9868..448be4a5ab 100644
--- a/core/list.h
+++ b/core/list.h
@@ -306,6 +306,8 @@ public:
if (!p_element->next_ptr) {
_data->last = n;
+ } else {
+ p_element->next_ptr->prev_ptr = n;
}
p_element->next_ptr = n;
@@ -330,6 +332,8 @@ public:
if (!p_element->prev_ptr) {
_data->first = n;
+ } else {
+ p_element->prev_ptr->next_ptr = n;
}
p_element->prev_ptr = n;
diff --git a/core/math/a_star.h b/core/math/a_star.h
index b7b7e54125..1f13f4fae8 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -59,8 +59,8 @@ class AStar : public Reference {
Point *prev_point;
real_t distance;
- Point()
- : list(this) {}
+ Point() :
+ list(this) {}
};
Map<int, Point *> points;
diff --git a/core/math/aabb.h b/core/math/aabb.h
index c60213496a..c5ba79e172 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -101,9 +101,9 @@ public:
operator String() const;
_FORCE_INLINE_ AABB() {}
- inline AABB(const Vector3 &p_pos, const Vector3 &p_size)
- : position(p_pos),
- size(p_size) {
+ inline AABB(const Vector3 &p_pos, const Vector3 &p_size) :
+ position(p_pos),
+ size(p_size) {
}
};
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index bdc040160f..ecda777583 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -577,11 +577,11 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3> &p_faces, real_t p_error_radius) {
error_radius = p_error_radius;
}
-BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB &p_aabb, real_t p_error_radius)
- : nodes(p_nodes),
- planes(p_planes),
- aabb(p_aabb),
- error_radius(p_error_radius) {
+BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB &p_aabb, real_t p_error_radius) :
+ nodes(p_nodes),
+ planes(p_planes),
+ aabb(p_aabb),
+ error_radius(p_error_radius) {
}
BSP_Tree::~BSP_Tree() {
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index c5f1d57441..42d2d0373a 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -140,6 +140,7 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_
real_t add = ((f1 + f2) * (p_oversample - 1.0)) / 2.0;
f1 += add;
f2 += add;
+ f3 *= p_oversample;
// always apply KEEP_WIDTH aspect ratio
f3 *= p_aspect;
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index 070ce77db4..7e586a1fd2 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -195,9 +195,8 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const {
if (!p_aabb.intersects_plane(get_plane()))
return false;
- /** TEST FACE AXIS */
-
#define TEST_AXIS(m_ax) \
+ /** TEST FACE AXIS */ \
{ \
real_t aabb_min = p_aabb.position.m_ax; \
real_t aabb_max = p_aabb.position.m_ax + p_aabb.size.m_ax; \
diff --git a/core/math/face3.h b/core/math/face3.h
index 561fa31238..9a1f6b2c2e 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -256,6 +256,4 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
return true;
}
- //this sucks...
-
#endif // FACE3_H
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index c77fe96ff2..11003c1cd5 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -222,35 +222,6 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
(2.0 * p0 - 5.0 * p1 + 4 * p2 - p3) * t2 +
(-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t3);
return out;
-
- /*
- real_t mu = p_t;
- real_t mu2 = mu*mu;
-
- Vector2 a0 = p_post_b - p_b - p_pre_a + *this;
- Vector2 a1 = p_pre_a - *this - a0;
- Vector2 a2 = p_b - p_pre_a;
- Vector2 a3 = *this;
-
- return ( a0*mu*mu2 + a1*mu2 + a2*mu + a3 );
-*/
- /*
- real_t t = p_t;
- real_t t2 = t*t;
- real_t t3 = t2*t;
-
- real_t a = 2.0*t3- 3.0*t2 + 1;
- real_t b = -2.0*t3+ 3.0*t2;
- real_t c = t3- 2.0*t2 + t;
- real_t d = t3- t2;
-
- Vector2 p_a=*this;
-
- return Vector2(
- (a * p_a.x) + (b *p_b.x) + (c * p_pre_a.x) + (d * p_post_b.x),
- (a * p_a.y) + (b *p_b.y) + (c * p_pre_a.y) + (d * p_post_b.y)
- );
-*/
}
// slide returns the component of the vector along the given plane, specified by its normal vector.
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index d215df8a43..60351445c0 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -382,16 +382,21 @@ struct Rect2 {
size = end - begin;
}
+ inline Rect2 abs() const {
+
+ return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs());
+ }
+
operator String() const { return String(position) + ", " + String(size); }
Rect2() {}
- Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height)
- : position(Point2(p_x, p_y)),
- size(Size2(p_width, p_height)) {
+ Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) :
+ position(Point2(p_x, p_y)),
+ size(Size2(p_width, p_height)) {
}
- Rect2(const Point2 &p_pos, const Size2 &p_size)
- : position(p_pos),
- size(p_size) {
+ Rect2(const Point2 &p_pos, const Size2 &p_size) :
+ position(p_pos),
+ size(p_size) {
}
};
@@ -578,18 +583,18 @@ struct Rect2i {
operator String() const { return String(position) + ", " + String(size); }
operator Rect2() const { return Rect2(position, size); }
- Rect2i(const Rect2 &p_r2)
- : position(p_r2.position),
- size(p_r2.size) {
+ Rect2i(const Rect2 &p_r2) :
+ position(p_r2.position),
+ size(p_r2.size) {
}
Rect2i() {}
- Rect2i(int p_x, int p_y, int p_width, int p_height)
- : position(Point2(p_x, p_y)),
- size(Size2(p_width, p_height)) {
+ Rect2i(int p_x, int p_y, int p_width, int p_height) :
+ position(Point2(p_x, p_y)),
+ size(Size2(p_width, p_height)) {
}
- Rect2i(const Point2 &p_pos, const Size2 &p_size)
- : position(p_pos),
- size(p_size) {
+ Rect2i(const Point2 &p_pos, const Size2 &p_size) :
+ position(p_pos),
+ size(p_size) {
}
};
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index bc0b3717ed..80e5805451 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -272,7 +272,7 @@ public:
#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a __asm fistp b
-/*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
+ /*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
// use AT&T inline assembly style, document that
// we use memory as output (=m) and input (m)
__asm__ __volatile__ (
diff --git a/core/math/plane.h b/core/math/plane.h
index 559a735817..1d02b5d523 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -74,9 +74,9 @@ public:
operator String() const;
_FORCE_INLINE_ Plane() { d = 0; }
- _FORCE_INLINE_ Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d)
- : normal(p_a, p_b, p_c),
- d(p_d){};
+ _FORCE_INLINE_ Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) :
+ normal(p_a, p_b, p_c),
+ d(p_d){};
_FORCE_INLINE_ Plane(const Vector3 &p_normal, real_t p_d);
_FORCE_INLINE_ Plane(const Vector3 &p_point, const Vector3 &p_normal);
@@ -100,14 +100,14 @@ bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const {
return (dist <= _epsilon);
}
-Plane::Plane(const Vector3 &p_normal, real_t p_d)
- : normal(p_normal),
- d(p_d) {
+Plane::Plane(const Vector3 &p_normal, real_t p_d) :
+ normal(p_normal),
+ d(p_d) {
}
-Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal)
- : normal(p_normal),
- d(p_normal.dot(p_point)) {
+Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) :
+ normal(p_normal),
+ d(p_normal.dot(p_point)) {
}
Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) {
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 638a39ab73..fb4ca16565 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -208,7 +208,7 @@ Transform::operator String() const {
return basis.operator String() + " - " + origin.operator String();
}
-Transform::Transform(const Basis &p_basis, const Vector3 &p_origin)
- : basis(p_basis),
- origin(p_origin) {
+Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) :
+ basis(p_basis),
+ origin(p_origin) {
}
diff --git a/core/node_path.cpp b/core/node_path.cpp
index 15f950f605..a12152aca6 100644
--- a/core/node_path.cpp
+++ b/core/node_path.cpp
@@ -48,8 +48,6 @@ uint32_t NodePath::hash() const {
h = h ^ ssn[i].hash();
}
- h = h ^ data->property.hash();
-
return h;
}
@@ -81,13 +79,6 @@ StringName NodePath::get_name(int p_idx) const {
return data->path[p_idx];
}
-StringName NodePath::get_property() const {
-
- if (!data)
- return StringName();
- return data->property;
-}
-
int NodePath::get_subname_count() const {
if (!data)
@@ -128,9 +119,6 @@ bool NodePath::operator==(const NodePath &p_path) const {
if (data->subpath.size() != p_path.data->subpath.size())
return false;
- if (data->property != p_path.data->property)
- return false;
-
for (int i = 0; i < data->path.size(); i++) {
if (data->path[i] != p_path.data->path[i])
@@ -184,8 +172,6 @@ NodePath::operator String() const {
ret += ":" + data->subpath[i].operator String();
}
- if (data->property.operator String() != "")
- ret += ":" + String(data->property);
return ret;
}
@@ -205,6 +191,7 @@ Vector<StringName> NodePath::get_names() const {
return data->path;
return Vector<StringName>();
}
+
Vector<StringName> NodePath::get_subnames() const {
if (data)
@@ -212,6 +199,21 @@ Vector<StringName> NodePath::get_subnames() const {
return Vector<StringName>();
}
+StringName NodePath::get_concatenated_subnames() const {
+ ERR_FAIL_COND_V(!data, StringName());
+
+ if (!data->concatenated_subpath) {
+ int spc = data->subpath.size();
+ String concatenated;
+ const StringName *ssn = data->subpath.ptr();
+ for (int i = 0; i < spc; i++) {
+ concatenated += i == 0 ? ssn[i].operator String() : ":" + ssn[i];
+ }
+ data->concatenated_subpath = concatenated;
+ }
+ return data->concatenated_subpath;
+}
+
NodePath NodePath::rel_path_to(const NodePath &p_np) const {
ERR_FAIL_COND_V(!is_absolute(), NodePath());
@@ -250,10 +252,27 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const {
if (relpath.size() == 0)
relpath.push_back(".");
- return NodePath(relpath, p_np.get_subnames(), false, p_np.get_property());
+ return NodePath(relpath, p_np.get_subnames(), false);
}
-NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute, const String &p_property) {
+NodePath NodePath::get_as_property_path() const {
+
+ if (!data->path.size()) {
+ return *this;
+ } else {
+ Vector<StringName> new_path = data->subpath;
+
+ String initial_subname = data->path[0];
+ for (size_t i = 1; i < data->path.size(); i++) {
+ initial_subname += i == 0 ? data->path[i].operator String() : "/" + data->path[i];
+ }
+ new_path.insert(0, initial_subname);
+
+ return NodePath(Vector<StringName>(), new_path, false);
+ }
+}
+
+NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
data = NULL;
@@ -264,14 +283,14 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute, const Stri
data->refcount.init();
data->absolute = p_absolute;
data->path = p_path;
- data->property = p_property;
+ data->has_slashes = true;
}
-NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute, const String &p_property) {
+NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) {
data = NULL;
- if (p_path.size() == 0)
+ if (p_path.size() == 0 && p_subpath.size() == 0)
return;
data = memnew(Data);
@@ -279,7 +298,7 @@ NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p
data->absolute = p_absolute;
data->path = p_path;
data->subpath = p_subpath;
- data->property = p_property;
+ data->has_slashes = true;
}
void NodePath::simplify() {
@@ -320,11 +339,11 @@ NodePath::NodePath(const String &p_path) {
return;
String path = p_path;
- StringName property;
Vector<StringName> subpath;
int absolute = (path[0] == '/') ? 1 : 0;
bool last_is_slash = true;
+ bool has_slashes = false;
int slices = 0;
int subpath_pos = path.find(":");
@@ -337,16 +356,13 @@ NodePath::NodePath(const String &p_path) {
if (path[i] == ':' || path[i] == 0) {
String str = path.substr(from, i - from);
- if (path[i] == ':') {
- if (str == "") {
- ERR_EXPLAIN("Invalid NodePath: " + p_path);
- ERR_FAIL();
- }
- subpath.push_back(str);
- } else {
- //property can be empty
- property = str;
+ if (str == "") {
+ if (path[i] == 0) continue; // Allow end-of-path :
+
+ ERR_EXPLAIN("Invalid NodePath: " + p_path);
+ ERR_FAIL();
}
+ subpath.push_back(str);
from = i + 1;
}
@@ -360,6 +376,7 @@ NodePath::NodePath(const String &p_path) {
if (path[i] == '/') {
last_is_slash = true;
+ has_slashes = true;
} else {
if (last_is_slash)
@@ -369,13 +386,13 @@ NodePath::NodePath(const String &p_path) {
}
}
- if (slices == 0 && !absolute && !property)
+ if (slices == 0 && !absolute && !subpath.size())
return;
data = memnew(Data);
data->refcount.init();
data->absolute = absolute ? true : false;
- data->property = property;
+ data->has_slashes = has_slashes;
data->subpath = subpath;
if (slices == 0)
diff --git a/core/node_path.h b/core/node_path.h
index eb5b9eb6cf..063c4f62db 100644
--- a/core/node_path.h
+++ b/core/node_path.h
@@ -41,10 +41,11 @@ class NodePath {
struct Data {
SafeRefCount refcount;
- StringName property;
Vector<StringName> path;
Vector<StringName> subpath;
+ StringName concatenated_subpath;
bool absolute;
+ bool has_slashes;
};
Data *data;
@@ -53,7 +54,7 @@ class NodePath {
public:
_FORCE_INLINE_ StringName get_sname() const {
- if (data && data->path.size() == 1 && data->subpath.empty() && !data->property) {
+ if (data && data->path.size() == 1 && data->subpath.empty()) {
return data->path[0];
} else {
return operator String();
@@ -67,13 +68,13 @@ public:
StringName get_subname(int p_idx) const;
Vector<StringName> get_names() const;
Vector<StringName> get_subnames() const;
+ StringName get_concatenated_subnames() const;
NodePath rel_path_to(const NodePath &p_np) const;
+ NodePath get_as_property_path() const;
void prepend_period();
- StringName get_property() const;
-
NodePath get_parent() const;
uint32_t hash() const;
@@ -88,8 +89,8 @@ public:
void simplify();
NodePath simplified() const;
- NodePath(const Vector<StringName> &p_path, bool p_absolute, const String &p_property = "");
- NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute, const String &p_property = "");
+ NodePath(const Vector<StringName> &p_path, bool p_absolute);
+ NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute);
NodePath(const NodePath &p_path);
NodePath(const String &p_path);
NodePath();
diff --git a/core/object.cpp b/core/object.cpp
index 823cbe14d4..cf1472243b 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -126,9 +126,9 @@ MethodInfo::operator Dictionary() const {
return d;
}
-MethodInfo::MethodInfo()
- : flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo() :
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
}
MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
@@ -164,48 +164,48 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
return mi;
}
-MethodInfo::MethodInfo(const String &p_name)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const String &p_name) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
}
-MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
}
-MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
}
-MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
}
-MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
arguments.push_back(p_param4);
}
-MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
@@ -213,48 +213,48 @@ MethodInfo::MethodInfo(const String &p_name, const PropertyInfo &p_param1, const
arguments.push_back(p_param5);
}
-MethodInfo::MethodInfo(Variant::Type ret)
- : flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret) :
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
}
-MethodInfo::MethodInfo(Variant::Type ret, const String &p_name)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret, const String &p_name) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
}
-MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
arguments.push_back(p_param1);
}
-MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
arguments.push_back(p_param1);
arguments.push_back(p_param2);
}
-MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
}
-MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
arguments.push_back(p_param1);
arguments.push_back(p_param2);
@@ -262,10 +262,10 @@ MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyIn
arguments.push_back(p_param4);
}
-MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
return_val.type = ret;
arguments.push_back(p_param1);
arguments.push_back(p_param2);
@@ -274,56 +274,56 @@ MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyIn
arguments.push_back(p_param5);
}
-MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name)
- : name(p_name),
- flags(METHOD_FLAG_NORMAL),
- return_val(p_ret),
- id(0) {
+MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name) :
+ name(p_name),
+ flags(METHOD_FLAG_NORMAL),
+ return_val(p_ret),
+ id(0) {
}
-MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1)
- : name(p_name),
- return_val(p_ret),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1) :
+ name(p_name),
+ return_val(p_ret),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
}
-MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2)
- : name(p_name),
- return_val(p_ret),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2) :
+ name(p_name),
+ return_val(p_ret),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
}
-MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3)
- : name(p_name),
- return_val(p_ret),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3) :
+ name(p_name),
+ return_val(p_ret),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
}
-MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4)
- : name(p_name),
- return_val(p_ret),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4) :
+ name(p_name),
+ return_val(p_ret),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
arguments.push_back(p_param4);
}
-MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5)
- : name(p_name),
- return_val(p_ret),
- flags(METHOD_FLAG_NORMAL),
- id(0) {
+MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5) :
+ name(p_name),
+ return_val(p_ret),
+ flags(METHOD_FLAG_NORMAL),
+ id(0) {
arguments.push_back(p_param1);
arguments.push_back(p_param2);
arguments.push_back(p_param3);
@@ -517,6 +517,80 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
}
}
+void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_value, bool *r_valid) {
+ if (p_names.empty()) {
+ if (r_valid)
+ *r_valid = false;
+ return;
+ }
+ if (p_names.size() == 1) {
+ set(p_names[0], p_value, r_valid);
+ return;
+ }
+
+ bool valid = false;
+ if (!r_valid) r_valid = &valid;
+
+ List<Variant> value_stack;
+
+ value_stack.push_back(get(p_names[0], r_valid));
+
+ if (!*r_valid) {
+ value_stack.clear();
+ return;
+ }
+
+ for (int i = 1; i < p_names.size() - 1; i++) {
+ value_stack.push_back(value_stack.back()->get().get_named(p_names[i], r_valid));
+
+ if (!*r_valid) {
+ value_stack.clear();
+ return;
+ }
+ }
+
+ value_stack.push_back(p_value); // p_names[p_names.size() - 1]
+
+ for (int i = p_names.size() - 1; i > 0; i--) {
+
+ value_stack.back()->prev()->get().set_named(p_names[i], value_stack.back()->get(), r_valid);
+ value_stack.pop_back();
+
+ if (!*r_valid) {
+ value_stack.clear();
+ return;
+ }
+ }
+
+ set(p_names[0], value_stack.back()->get(), r_valid);
+ value_stack.pop_back();
+
+ ERR_FAIL_COND(!value_stack.empty());
+}
+
+Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) const {
+ if (p_names.empty()) {
+ if (r_valid)
+ *r_valid = false;
+ return Variant();
+ }
+ bool valid = false;
+
+ Variant current_value = get(p_names[0]);
+ for (int i = 1; i < p_names.size(); i++) {
+ current_value = current_value.get_named(p_names[i], &valid);
+
+ if (!valid) {
+ if (r_valid)
+ *r_valid = false;
+ return Variant();
+ }
+ }
+ if (r_valid)
+ *r_valid = true;
+ return current_value;
+}
+
void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) const {
if (script_instance && p_reversed) {
@@ -744,7 +818,7 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) {
}
Variant::CallError ce;
- return call(p_method, argptrs.ptr(), p_args.size(), ce);
+ return call(p_method, (const Variant **)argptrs.ptr(), p_args.size(), ce);
}
Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
@@ -1109,7 +1183,7 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
bind_mem[p_argcount + j] = &c.binds[j];
}
- args = bind_mem.ptr();
+ args = (const Variant **)bind_mem.ptr();
argc = bind_mem.size();
}
@@ -1416,6 +1490,16 @@ Variant Object::_get_bind(const String &p_name) const {
return get(p_name);
}
+void Object::_set_indexed_bind(const NodePath &p_name, const Variant &p_value) {
+
+ set_indexed(p_name.get_as_property_path().get_subnames(), p_value);
+}
+
+Variant Object::_get_indexed_bind(const NodePath &p_name) const {
+
+ return get_indexed(p_name.get_as_property_path().get_subnames());
+}
+
void Object::initialize_class() {
static bool initialized = false;
@@ -1513,6 +1597,8 @@ void Object::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_class", "type"), &Object::is_class);
ClassDB::bind_method(D_METHOD("set", "property", "value"), &Object::_set_bind);
ClassDB::bind_method(D_METHOD("get", "property"), &Object::_get_bind);
+ ClassDB::bind_method(D_METHOD("set_indexed", "property", "value"), &Object::_set_indexed_bind);
+ ClassDB::bind_method(D_METHOD("get_indexed", "property"), &Object::_get_indexed_bind);
ClassDB::bind_method(D_METHOD("get_property_list"), &Object::_get_property_list_bind);
ClassDB::bind_method(D_METHOD("get_method_list"), &Object::_get_method_list_bind);
ClassDB::bind_method(D_METHOD("notification", "what", "reversed"), &Object::notification, DEFVAL(false));
@@ -1661,6 +1747,50 @@ Variant::Type Object::get_static_property_type(const StringName &p_property, boo
return Variant::NIL;
}
+Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid) const {
+
+ if (p_path.size() == 0) {
+ if (r_valid)
+ *r_valid = false;
+
+ return Variant::NIL;
+ }
+
+ bool valid = false;
+ Variant::Type t = get_static_property_type(p_path[0], &valid);
+ if (!valid) {
+ if (r_valid)
+ *r_valid = false;
+
+ return Variant::NIL;
+ }
+
+ Variant::CallError ce;
+ Variant check = Variant::construct(t, NULL, 0, ce);
+
+ for (int i = 1; i < p_path.size(); i++) {
+ if (check.get_type() == Variant::OBJECT || check.get_type() == Variant::DICTIONARY || check.get_type() == Variant::ARRAY) {
+ // We cannot be sure about the type of properties this types can have
+ if (r_valid)
+ *r_valid = false;
+ return Variant::NIL;
+ }
+
+ check = check.get_named(p_path[i], &valid);
+
+ if (!valid) {
+ if (r_valid)
+ *r_valid = false;
+ return Variant::NIL;
+ }
+ }
+
+ if (r_valid)
+ *r_valid = true;
+
+ return check.get_type();
+}
+
bool Object::is_queued_for_deletion() const {
return _is_queued_for_deletion;
}
diff --git a/core/object.h b/core/object.h
index 7af2c78fc3..3d93953227 100644
--- a/core/object.h
+++ b/core/object.h
@@ -109,10 +109,11 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 17,
PROPERTY_USAGE_CLASS_IS_ENUM = 1 << 18,
PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 19,
+ PROPERTY_USAGE_INTERNAL = 1 << 20,
PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED,
- PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK,
+ PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNAL,
};
#define ADD_SIGNAL(m_signal) ClassDB::add_signal(get_class_static(), m_signal)
@@ -143,18 +144,18 @@ struct PropertyInfo {
static PropertyInfo from_dict(const Dictionary &p_dict);
- PropertyInfo()
- : type(Variant::NIL),
- hint(PROPERTY_HINT_NONE),
- usage(PROPERTY_USAGE_DEFAULT) {
+ PropertyInfo() :
+ type(Variant::NIL),
+ hint(PROPERTY_HINT_NONE),
+ usage(PROPERTY_USAGE_DEFAULT) {
}
- PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName())
- : type(p_type),
- name(p_name),
- hint(p_hint),
- hint_string(p_hint_string),
- usage(p_usage) {
+ PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = StringName()) :
+ type(p_type),
+ name(p_name),
+ hint(p_hint),
+ hint_string(p_hint_string),
+ usage(p_usage) {
if (hint == PROPERTY_HINT_RESOURCE_TYPE) {
class_name = hint_string;
@@ -163,11 +164,11 @@ struct PropertyInfo {
}
}
- PropertyInfo(const StringName &p_class_name)
- : type(Variant::OBJECT),
- class_name(p_class_name),
- hint(PROPERTY_HINT_NONE),
- usage(PROPERTY_USAGE_DEFAULT) {
+ PropertyInfo(const StringName &p_class_name) :
+ type(Variant::OBJECT),
+ class_name(p_class_name),
+ hint(PROPERTY_HINT_NONE),
+ usage(PROPERTY_USAGE_DEFAULT) {
}
bool operator<(const PropertyInfo &p_info) const {
@@ -427,9 +428,9 @@ private:
_FORCE_INLINE_ bool operator<(const Target &p_target) const { return (_id == p_target._id) ? (method < p_target.method) : (_id < p_target._id); }
- Target(const ObjectID &p_id, const StringName &p_method)
- : _id(p_id),
- method(p_method) {
+ Target(const ObjectID &p_id, const StringName &p_method) :
+ _id(p_id),
+ method(p_method) {
}
Target() { _id = 0; }
};
@@ -477,6 +478,8 @@ private:
Array _get_incoming_connections() const;
void _set_bind(const String &p_set, const Variant &p_value);
Variant _get_bind(const String &p_name) const;
+ void _set_indexed_bind(const NodePath &p_name, const Variant &p_value);
+ Variant _get_indexed_bind(const NodePath &p_name) const;
void *_script_instance_bindings[MAX_SCRIPT_INSTANCE_BINDINGS];
@@ -627,6 +630,8 @@ public:
void set(const StringName &p_name, const Variant &p_value, bool *r_valid = NULL);
Variant get(const StringName &p_name, bool *r_valid = NULL) const;
+ void set_indexed(const Vector<StringName> &p_names, const Variant &p_value, bool *r_valid = NULL);
+ Variant get_indexed(const Vector<StringName> &p_names, bool *r_valid = NULL) const;
void get_property_list(List<PropertyInfo> *p_list, bool p_reversed = false) const;
@@ -687,6 +692,7 @@ public:
bool is_blocking_signals() const;
Variant::Type get_static_property_type(const StringName &p_property, bool *r_valid = NULL) const;
+ Variant::Type get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid = NULL) const;
virtual void get_translatable_strings(List<String> *p_strings) const;
diff --git a/core/ordered_hash_map.h b/core/ordered_hash_map.h
index 1ed5a5d369..fed16809e6 100644
--- a/core/ordered_hash_map.h
+++ b/core/ordered_hash_map.h
@@ -68,8 +68,10 @@ public:
}
public:
- _FORCE_INLINE_ Element()
- : list_element(NULL), prev_element(NULL), next_element(NULL) {
+ _FORCE_INLINE_ Element() :
+ list_element(NULL),
+ prev_element(NULL),
+ next_element(NULL) {
}
Element next() const {
@@ -80,10 +82,10 @@ public:
return Element(prev_element);
}
- Element(const Element &other)
- : list_element(other.list_element),
- prev_element(other.prev_element),
- next_element(other.next_element) {
+ Element(const Element &other) :
+ list_element(other.list_element),
+ prev_element(other.prev_element),
+ next_element(other.next_element) {
}
Element &operator=(const Element &other) {
@@ -135,17 +137,17 @@ public:
const typename InternalList::Element *list_element;
- ConstElement(const typename InternalList::Element *p_element)
- : list_element(p_element) {
+ ConstElement(const typename InternalList::Element *p_element) :
+ list_element(p_element) {
}
public:
- _FORCE_INLINE_ ConstElement()
- : list_element(NULL) {
+ _FORCE_INLINE_ ConstElement() :
+ list_element(NULL) {
}
- ConstElement(const ConstElement &other)
- : list_element(other.list_element) {
+ ConstElement(const ConstElement &other) :
+ list_element(other.list_element) {
}
ConstElement &operator=(const ConstElement &other) {
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 6d4b46f4da..e19c8e8ea5 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -333,6 +333,9 @@ Error DirAccess::copy(String p_from, String p_to, int chmod_flags) {
if (err == OK && chmod_flags != -1) {
fdst->close();
err = fdst->_chmod(p_to, chmod_flags);
+ // If running on a platform with no chmod support (i.e., Windows), don't fail
+ if (err == ERR_UNAVAILABLE)
+ err = OK;
}
memdelete(fsrc);
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 5fdd2b9135..7b2062936b 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -481,7 +481,7 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) {
ERR_FAIL_COND_V(!f, Vector<uint8_t>());
Vector<uint8_t> data;
data.resize(f->get_len());
- f->get_buffer(data.ptr(), data.size());
+ f->get_buffer(data.ptrw(), data.size());
memdelete(f);
return data;
}
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 455dd1ea99..6fda3d9668 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -141,7 +141,7 @@ public:
virtual Error reopen(const String &p_path, int p_mode_flags); ///< does not change the AccessType
- virtual Error _chmod(const String &p_path, int p_mod) { return FAILED; }
+ virtual Error _chmod(const String &p_path, int p_mod) { return ERR_UNAVAILABLE; }
static FileAccess *create(AccessType p_access); /// Create a file access (for the current platform) this is the only portable way of accessing files.
static FileAccess *create_for_path(const String &p_path);
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 103a8e82c2..9b2bd30868 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -278,16 +278,16 @@ String InputEventKey::as_text() const {
return kc;
if (get_metakey()) {
- kc = "Meta+" + kc;
+ kc = find_keycode_name(KEY_META) + ("+" + kc);
}
if (get_alt()) {
- kc = "Alt+" + kc;
+ kc = find_keycode_name(KEY_ALT) + ("+" + kc);
}
if (get_shift()) {
- kc = "Shift+" + kc;
+ kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
}
if (get_control()) {
- kc = "Ctrl+" + kc;
+ kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
}
return kc;
}
@@ -939,6 +939,14 @@ void InputEventGesture::set_position(const Vector2 &p_pos) {
pos = p_pos;
}
+void InputEventGesture::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
+ ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
+}
+
Vector2 InputEventGesture::get_position() const {
return pos;
@@ -970,6 +978,14 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform,
return ev;
}
+void InputEventMagnifyGesture::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
+ ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
+
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
+}
+
InputEventMagnifyGesture::InputEventMagnifyGesture() {
factor = 1.0;
@@ -1000,6 +1016,14 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con
return ev;
}
+void InputEventPanGesture::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
+ ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
+}
+
InputEventPanGesture::InputEventPanGesture() {
delta = Vector2(0, 0);
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 2cba60bede..614a3289ba 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -476,6 +476,9 @@ class InputEventGesture : public InputEventWithModifiers {
Vector2 pos;
+protected:
+ static void _bind_methods();
+
public:
void set_position(const Vector2 &p_pos);
Vector2 get_position() const;
@@ -486,6 +489,9 @@ class InputEventMagnifyGesture : public InputEventGesture {
GDCLASS(InputEventMagnifyGesture, InputEventGesture)
real_t factor;
+protected:
+ static void _bind_methods();
+
public:
void set_factor(real_t p_factor);
real_t get_factor() const;
@@ -500,6 +506,9 @@ class InputEventPanGesture : public InputEventGesture {
GDCLASS(InputEventPanGesture, InputEventGesture)
Vector2 delta;
+protected:
+ static void _bind_methods();
+
public:
void set_delta(const Vector2 &p_delta);
Vector2 get_delta() const;
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index edf4f3e2f9..dead3b6ac0 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -60,7 +60,11 @@ static const _KeyCodeText _keycodes[] = {
{KEY_PAGEDOWN ,"PageDown"},
{KEY_SHIFT ,"Shift"},
{KEY_CONTROL ,"Control"},
+#ifdef OSX_ENABLED
+ {KEY_META ,"Command"},
+#else
{KEY_META ,"Meta"},
+#endif
{KEY_ALT ,"Alt"},
{KEY_CAPSLOCK ,"CapsLock"},
{KEY_NUMLOCK ,"NumLock"},
@@ -390,14 +394,22 @@ bool keycode_has_unicode(uint32_t p_keycode) {
String keycode_get_string(uint32_t p_code) {
String codestr;
- if (p_code & KEY_MASK_SHIFT)
- codestr += "Shift+";
- if (p_code & KEY_MASK_ALT)
- codestr += "Alt+";
- if (p_code & KEY_MASK_CTRL)
- codestr += "Ctrl+";
- if (p_code & KEY_MASK_META)
- codestr += "Meta+";
+ if (p_code & KEY_MASK_SHIFT) {
+ codestr += find_keycode_name(KEY_SHIFT);
+ codestr += "+";
+ }
+ if (p_code & KEY_MASK_ALT) {
+ codestr += find_keycode_name(KEY_ALT);
+ codestr += "+";
+ }
+ if (p_code & KEY_MASK_CTRL) {
+ codestr += find_keycode_name(KEY_CONTROL);
+ codestr += "+";
+ }
+ if (p_code & KEY_MASK_META) {
+ codestr += find_keycode_name(KEY_META);
+ codestr += "+";
+ }
p_code &= KEY_CODE_MASK;
@@ -433,6 +445,21 @@ int find_keycode(const String &p_code) {
return 0;
}
+const char *find_keycode_name(int p_keycode) {
+
+ const _KeyCodeText *kct = &_keycodes[0];
+
+ while (kct->text) {
+
+ if (kct->code == p_keycode) {
+ return kct->text;
+ }
+ kct++;
+ }
+
+ return "";
+}
+
struct _KeyCodeReplace {
int from;
int to;
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 509ff23a93..f49cbc6b18 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -326,6 +326,7 @@ enum KeyModifierMask {
String keycode_get_string(uint32_t p_code);
bool keycode_has_unicode(uint32_t p_keycode);
int find_keycode(const String &p_code);
+const char *find_keycode_name(int p_keycode);
int keycode_get_count();
int keycode_get_value_by_index(int p_index);
const char *keycode_get_name_by_index(int p_index);
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 0e7e26df73..8088a6fa74 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -122,6 +122,16 @@ bool OS::is_in_low_processor_usage_mode() const {
return low_processor_usage_mode;
}
+void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
+
+ low_processor_usage_mode_sleep_usec = p_usec;
+}
+
+int OS::get_low_processor_usage_mode_sleep_usec() const {
+
+ return low_processor_usage_mode_sleep_usec;
+}
+
void OS::set_clipboard(const String &p_text) {
_local_clipboard = p_text;
@@ -269,14 +279,22 @@ String OS::get_locale() const {
return "en";
}
-// Helper function used by OS_Unix and OS_Windows
-String OS::get_safe_application_name() const {
- String an = ProjectSettings::get_singleton()->get("application/config/name");
- Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" ");
- for (int i = 0; i < invalid_char.size(); i++) {
- an = an.replace(invalid_char[i], "-");
+// Helper function to ensure that a dir name/path will be valid on the OS
+String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
+
+ Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
+ if (p_allow_dir_separator) {
+ // Dir separators are allowed, but disallow ".." to avoid going up the filesystem
+ invalid_chars.push_back("..");
+ } else {
+ invalid_chars.push_back("/");
+ }
+
+ String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges();
+ for (int i = 0; i < invalid_chars.size(); i++) {
+ safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-");
}
- return an;
+ return safe_dir_name;
}
// Path to data, config, cache, etc. OS-specific folders
@@ -554,7 +572,7 @@ bool OS::has_feature(const String &p_feature) {
if (sizeof(void *) == 4 && p_feature == "32") {
return true;
}
-#if defined(__x86_64) || defined(__x86_64__)
+#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__)
if (p_feature == "x86_64") {
return true;
}
@@ -599,6 +617,7 @@ OS::OS() {
singleton = this;
_keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
low_processor_usage_mode = false;
+ low_processor_usage_mode_sleep_usec = 10000;
_verbose_stdout = false;
_no_window = false;
_exit_code = 0;
diff --git a/core/os/os.h b/core/os/os.h
index fe4ffb2922..979ad7e92a 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -50,6 +50,7 @@ class OS {
List<String> _cmdline;
bool _keep_screen_on;
bool low_processor_usage_mode;
+ int low_processor_usage_mode_sleep_usec;
bool _verbose_stdout;
String _local_clipboard;
uint64_t _msec_splash;
@@ -91,14 +92,16 @@ public:
bool resizable;
bool borderless_window;
bool maximized;
+ bool use_vsync;
float get_aspect() const { return (float)width / (float)height; }
- VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false) {
+ VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_use_vsync = false) {
width = p_width;
height = p_height;
fullscreen = p_fullscreen;
resizable = p_resizable;
borderless_window = p_borderless_window;
maximized = p_maximized;
+ use_vsync = p_use_vsync;
}
};
@@ -194,7 +197,7 @@ public:
virtual void set_ime_position(const Point2 &p_pos) {}
virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {}
- virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; }
+ virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) { return ERR_UNAVAILABLE; }
virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }
virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; }
@@ -202,6 +205,8 @@ public:
virtual bool is_keep_screen_on() const;
virtual void set_low_processor_usage_mode(bool p_enabled);
virtual bool is_in_low_processor_usage_mode() const;
+ virtual void set_low_processor_usage_mode_sleep_usec(int p_usec);
+ virtual int get_low_processor_usage_mode_sleep_usec() const;
virtual String get_executable_path() const;
virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false) = 0;
@@ -335,7 +340,7 @@ public:
virtual String get_locale() const;
- String get_safe_application_name() const;
+ String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
virtual String get_godot_dir_name() const;
virtual String get_data_path() const;
diff --git a/core/pair.h b/core/pair.h
index 535c3355b6..aa51b77a4f 100644
--- a/core/pair.h
+++ b/core/pair.h
@@ -37,9 +37,9 @@ struct Pair {
S second;
Pair() {}
- Pair(F p_first, const S &p_second)
- : first(p_first),
- second(p_second) {
+ Pair(F p_first, const S &p_second) :
+ first(p_first),
+ second(p_second) {
}
};
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 361464ee1f..67b081de34 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -429,7 +429,7 @@ Error ProjectSettings::_load_settings_binary(const String p_path) {
uint32_t vlen = f->get_32();
Vector<uint8_t> d;
d.resize(vlen);
- f->get_buffer(d.ptr(), vlen);
+ f->get_buffer(d.ptrw(), vlen);
Variant value;
Error err = decode_variant(value, d.ptr(), d.size());
ERR_EXPLAIN("Error decoding property: " + key);
@@ -891,7 +891,8 @@ ProjectSettings::ProjectSettings() {
custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "tscn,scn,res");
GLOBAL_DEF("application/run/disable_stdout", false);
GLOBAL_DEF("application/run/disable_stderr", false);
- GLOBAL_DEF("application/config/use_shared_user_dir", true);
+ GLOBAL_DEF("application/config/use_custom_user_dir", false);
+ GLOBAL_DEF("application/config/custom_user_dir_name", "");
key.instance();
key->set_scancode(KEY_ENTER);
diff --git a/core/project_settings.h b/core/project_settings.h
index 1c4078cebb..d8a1ea1f7a 100644
--- a/core/project_settings.h
+++ b/core/project_settings.h
@@ -58,18 +58,18 @@ protected:
Variant initial;
bool hide_from_editor;
bool overrided;
- VariantContainer()
- : order(0),
- persist(false),
- hide_from_editor(false),
- overrided(false) {
+ VariantContainer() :
+ order(0),
+ persist(false),
+ hide_from_editor(false),
+ overrided(false) {
}
- VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false)
- : order(p_order),
- persist(p_persist),
- variant(p_variant),
- hide_from_editor(false),
- overrided(false) {
+ VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) :
+ order(p_order),
+ persist(p_persist),
+ variant(p_variant),
+ hide_from_editor(false),
+ overrided(false) {
}
};
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index baaf738b42..17f951e4f4 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -129,6 +129,9 @@ void register_core_types() {
ClassDB::register_class<InputEventScreenDrag>();
ClassDB::register_class<InputEventScreenTouch>();
ClassDB::register_class<InputEventAction>();
+ ClassDB::register_virtual_class<InputEventGesture>();
+ ClassDB::register_class<InputEventMagnifyGesture>();
+ ClassDB::register_class<InputEventPanGesture>();
ClassDB::register_class<FuncRef>();
ClassDB::register_virtual_class<StreamPeer>();
diff --git a/core/resource.cpp b/core/resource.cpp
index 78e20bada4..be6da792ad 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -184,6 +184,35 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
return Ref<Resource>(r);
}
+void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {
+
+ print_line("configure for local: " + get_class());
+ List<PropertyInfo> plist;
+ get_property_list(&plist);
+
+ local_scene = p_for_scene;
+
+ for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
+
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ continue;
+ Variant p = get(E->get().name);
+ if (p.get_type() == Variant::OBJECT) {
+
+ RES sr = p;
+ if (sr.is_valid()) {
+
+ if (sr->is_local_to_scene()) {
+ if (!remap_cache.has(sr)) {
+ sr->configure_for_local_scene(p_for_scene, remap_cache);
+ remap_cache[sr] = sr;
+ }
+ }
+ }
+ }
+ }
+}
+
Ref<Resource> Resource::duplicate(bool p_subresources) const {
List<PropertyInfo> plist;
@@ -349,8 +378,8 @@ void Resource::_bind_methods() {
BIND_VMETHOD(MethodInfo("_setup_local_to_scene"));
}
-Resource::Resource()
- : remapped_list(this) {
+Resource::Resource() :
+ remapped_list(this) {
#ifdef TOOLS_ENABLED
last_modified_time = 0;
diff --git a/core/resource.h b/core/resource.h
index 7dc3b67291..19714a68d1 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -108,6 +108,7 @@ public:
virtual Ref<Resource> duplicate(bool p_subresources = false) const;
Ref<Resource> duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache);
+ void configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache);
void set_local_to_scene(bool p_enable);
bool is_local_to_scene() const;
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp
index c9acdb7970..908c8a34b5 100644
--- a/core/safe_refcount.cpp
+++ b/core/safe_refcount.cpp
@@ -57,7 +57,7 @@
return m_val; \
}
-_ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(register uint32_t *pw) {
+_ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(register uint32_t *pw){
ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONG, InterlockedCompareExchange, uint32_t)
}
@@ -82,12 +82,12 @@ _ALWAYS_INLINE_ uint32_t _atomic_add_impl(register uint32_t *pw, register uint32
return InterlockedAdd((LONG volatile *)pw, val);
}
-_ALWAYS_INLINE_ uint32_t _atomic_exchange_if_greater_impl(register uint32_t *pw, register uint32_t val) {
+_ALWAYS_INLINE_ uint32_t _atomic_exchange_if_greater_impl(register uint32_t *pw, register uint32_t val){
ATOMIC_EXCHANGE_IF_GREATER_BODY(pw, val, LONG, InterlockedCompareExchange, uint32_t)
}
-_ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(register uint64_t *pw) {
+_ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(register uint64_t *pw){
ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONGLONG, InterlockedCompareExchange64, uint64_t)
}
@@ -112,7 +112,7 @@ _ALWAYS_INLINE_ uint64_t _atomic_add_impl(register uint64_t *pw, register uint64
return InterlockedAdd64((LONGLONG volatile *)pw, val);
}
-_ALWAYS_INLINE_ uint64_t _atomic_exchange_if_greater_impl(register uint64_t *pw, register uint64_t val) {
+_ALWAYS_INLINE_ uint64_t _atomic_exchange_if_greater_impl(register uint64_t *pw, register uint64_t val){
ATOMIC_EXCHANGE_IF_GREATER_BODY(pw, val, LONGLONG, InterlockedCompareExchange64, uint64_t)
}
diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp
index 8d2600e52d..94c48f1c8f 100644
--- a/core/script_debugger_local.cpp
+++ b/core/script_debugger_local.cpp
@@ -212,7 +212,7 @@ void ScriptDebuggerLocal::idle_poll() {
}
SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort;
- sort.sort(pinfo.ptr(), ofs);
+ sort.sort(pinfo.ptrw(), ofs);
//falta el frame time
@@ -264,7 +264,7 @@ void ScriptDebuggerLocal::profiling_end() {
}
SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort;
- sort.sort(pinfo.ptr(), ofs);
+ sort.sort(pinfo.ptrw(), ofs);
uint64_t total_us = 0;
for (int i = 0; i < ofs; i++) {
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index 5e06339b9e..658b72b47a 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -749,7 +749,7 @@ void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
}
SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa;
- sa.sort(profile_info_ptrs.ptr(), ofs);
+ sa.sort(profile_info_ptrs.ptrw(), ofs);
int to_send = MIN(ofs, max_frame_functions);
@@ -989,25 +989,25 @@ void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p
ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL;
-ScriptDebuggerRemote::ScriptDebuggerRemote()
- : profiling(false),
- max_frame_functions(16),
- skip_profile_frame(false),
- reload_all_scripts(false),
- tcp_client(StreamPeerTCP::create_ref()),
- packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
- last_perf_time(0),
- performance(Engine::get_singleton()->get_singleton_object("Performance")),
- requested_quit(false),
- mutex(Mutex::create()),
- max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
- char_count(0),
- last_msec(0),
- msec_count(0),
- locking(false),
- poll_every(0),
- request_scene_tree(NULL),
- live_edit_funcs(NULL) {
+ScriptDebuggerRemote::ScriptDebuggerRemote() :
+ profiling(false),
+ max_frame_functions(16),
+ skip_profile_frame(false),
+ reload_all_scripts(false),
+ tcp_client(StreamPeerTCP::create_ref()),
+ packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
+ last_perf_time(0),
+ performance(Engine::get_singleton()->get_singleton_object("Performance")),
+ requested_quit(false),
+ mutex(Mutex::create()),
+ max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
+ char_count(0),
+ last_msec(0),
+ msec_count(0),
+ locking(false),
+ poll_every(0),
+ request_scene_tree(NULL),
+ live_edit_funcs(NULL) {
packet_peer_stream->set_stream_peer(tcp_client);
packet_peer_stream->set_output_buffer_max_size(1024 * 1024 * 8); //8mb should be way more than enough
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 384e41e4bd..c1e9d55872 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -387,10 +387,10 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
//change notify
}
-PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner)
- : owner(p_owner),
- language(p_language),
- script(p_script) {
+PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner) :
+ owner(p_owner),
+ language(p_language),
+ script(p_script) {
}
PlaceHolderScriptInstance::~PlaceHolderScriptInstance() {
diff --git a/core/string_buffer.cpp b/core/string_buffer.cpp
index 195068f887..8489df2599 100644
--- a/core/string_buffer.cpp
+++ b/core/string_buffer.cpp
@@ -71,7 +71,7 @@ StringBuffer &StringBuffer::reserve(int p_size) {
bool need_copy = string_length > 0 && buffer.empty();
buffer.resize(next_power_of_2(p_size));
if (need_copy) {
- memcpy(buffer.ptr(), short_buffer, string_length * sizeof(CharType));
+ memcpy(buffer.ptrw(), short_buffer, string_length * sizeof(CharType));
}
return *this;
diff --git a/core/string_buffer.h b/core/string_buffer.h
index 3f36249148..b6ccd4af20 100644
--- a/core/string_buffer.h
+++ b/core/string_buffer.h
@@ -40,7 +40,7 @@ class StringBuffer {
int string_length = 0;
_FORCE_INLINE_ CharType *current_buffer_ptr() {
- return static_cast<Vector<CharType> &>(buffer).empty() ? short_buffer : buffer.ptr();
+ return static_cast<Vector<CharType> &>(buffer).empty() ? short_buffer : buffer.ptrw();
}
public:
diff --git a/core/translation.cpp b/core/translation.cpp
index 7e4d4feb89..515b5f1134 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -333,6 +333,7 @@ static const char *locale_list[] = {
"sq_KV", // Albanian (Kosovo)
"sq_MK", // Albanian (Macedonia)
"sr", // Serbian
+ "sr_Cyrl", // Serbian (Cyrillic)
"sr_ME", // Serbian (Montenegro)
"sr_RS", // Serbian (Serbia)
"ss_ZA", // Swati (South Africa)
@@ -693,6 +694,7 @@ static const char *locale_names[] = {
"Albanian (Kosovo)",
"Albanian (Macedonia)",
"Serbian",
+ "Serbian (Cyrillic)",
"Serbian (Montenegro)",
"Serbian (Serbia)",
"Swati (South Africa)",
@@ -874,8 +876,8 @@ void Translation::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale");
}
-Translation::Translation()
- : locale("en") {
+Translation::Translation() :
+ locale("en") {
}
///////////////////////////////////////////////
@@ -1161,9 +1163,9 @@ void TranslationServer::load_translations() {
}
}
-TranslationServer::TranslationServer()
- : locale("en"),
- enabled(true) {
+TranslationServer::TranslationServer() :
+ locale("en"),
+ enabled(true) {
singleton = this;
for (int i = 0; locale_list[i]; ++i) {
diff --git a/core/typedefs.h b/core/typedefs.h
index c509edf9fe..889513ddc9 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -73,7 +73,7 @@ T *_nullptr() {
#define OFFSET_OF(st, m) \
((size_t)((char *)&(_nullptr<st>()->m) - (char *)0))
-/**
+ /**
* Some platforms (devices) not define NULL
*/
@@ -81,7 +81,7 @@ T *_nullptr() {
#define NULL 0
#endif
-/**
+ /**
* Windows defines a lot of badly stuff we'll never ever use. undefine it.
*/
@@ -103,7 +103,7 @@ T *_nullptr() {
#include "error_list.h"
#include "error_macros.h"
-/** Generic ABS function, for math uses please use Math::abs */
+ /** Generic ABS function, for math uses please use Math::abs */
#ifndef ABS
#define ABS(m_v) ((m_v < 0) ? (-(m_v)) : (m_v))
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 8d40f56386..3a0708851e 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -115,7 +115,7 @@ void String::copy_from(const char *p_cstr) {
resize(len + 1); // include 0
- CharType *dst = this->ptr();
+ CharType *dst = this->ptrw();
for (int i = 0; i < len + 1; i++) {
@@ -1119,7 +1119,7 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
chars++;
String s;
s.resize(chars + 1);
- CharType *c = s.ptr();
+ CharType *c = s.ptrw();
c[chars] = 0;
n = num;
do {
@@ -3380,8 +3380,6 @@ bool String::is_valid_float() const {
from++;
}
- //this was pulled out of my ass, i wonder if it's correct...
-
bool exponent_found = false;
bool period_found = false;
bool sign_found = false;
diff --git a/core/variant.cpp b/core/variant.cpp
index d4143b8d84..7f0cabbce4 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -66,8 +66,7 @@ String Variant::get_type_name(Variant::Type p_type) {
return "String";
} break;
- // math types
-
+ // math types
case VECTOR2: {
return "Vector2";
@@ -513,6 +512,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
static const Type valid[] = {
QUAT,
+ VECTOR3,
NIL
};
@@ -723,8 +723,7 @@ bool Variant::is_zero() const {
} break;
- // math types
-
+ // math types
case VECTOR2: {
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2();
@@ -932,8 +931,7 @@ void Variant::reference(const Variant &p_variant) {
memnew_placement(_data._mem, String(*reinterpret_cast<const String *>(p_variant._data._mem)));
} break;
- // math types
-
+ // math types
case VECTOR2: {
memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem)));
@@ -1632,7 +1630,9 @@ Variant::operator Basis() const {
return *_data._basis;
else if (type == QUAT)
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == TRANSFORM)
+ else if (type == VECTOR3) {
+ return Basis(*reinterpret_cast<const Vector3 *>(_data._mem));
+ } else if (type == TRANSFORM) // unexposed in Variant::can_convert?
return _data._transform->basis;
else
return Basis();
@@ -2502,8 +2502,7 @@ void Variant::operator=(const Variant &p_variant) {
*reinterpret_cast<String *>(_data._mem) = *reinterpret_cast<const String *>(p_variant._data._mem);
} break;
- // math types
-
+ // math types
case VECTOR2: {
*reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem);
@@ -2642,8 +2641,8 @@ uint32_t Variant::hash() const {
return reinterpret_cast<const String *>(_data._mem)->hash();
} break;
- // math types
+ // math types
case VECTOR2: {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index da6e602ccb..f66cce85c9 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -130,9 +130,9 @@ struct _VariantCall {
StringName name;
Variant::Type type;
Arg() { type = Variant::NIL; }
- Arg(Variant::Type p_type, const StringName &p_name)
- : name(p_name),
- type(p_type) {
+ Arg(Variant::Type p_type, const StringName &p_name) :
+ name(p_name),
+ type(p_type) {
}
};
@@ -360,6 +360,7 @@ struct _VariantCall {
VCALL_LOCALMEM2R(Rect2, grow_margin);
VCALL_LOCALMEM4R(Rect2, grow_individual);
VCALL_LOCALMEM1R(Rect2, expand);
+ VCALL_LOCALMEM0R(Rect2, abs);
VCALL_LOCALMEM0R(Vector3, min_axis);
VCALL_LOCALMEM0R(Vector3, max_axis);
@@ -437,6 +438,8 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Color, contrasted);
VCALL_LOCALMEM2R(Color, linear_interpolate);
VCALL_LOCALMEM1R(Color, blend);
+ VCALL_LOCALMEM1R(Color, lightened);
+ VCALL_LOCALMEM1R(Color, darkened);
VCALL_LOCALMEM1R(Color, to_html);
VCALL_LOCALMEM0R(RID, get_id);
@@ -446,7 +449,8 @@ struct _VariantCall {
VCALL_LOCALMEM1R(NodePath, get_name);
VCALL_LOCALMEM0R(NodePath, get_subname_count);
VCALL_LOCALMEM1R(NodePath, get_subname);
- VCALL_LOCALMEM0R(NodePath, get_property);
+ VCALL_LOCALMEM0R(NodePath, get_concatenated_subnames);
+ VCALL_LOCALMEM0R(NodePath, get_as_property_path);
VCALL_LOCALMEM0R(NodePath, is_empty);
VCALL_LOCALMEM0R(Dictionary, size);
@@ -496,7 +500,7 @@ struct _VariantCall {
PoolByteArray::Read r = ba->read();
CharString cs;
cs.resize(ba->size() + 1);
- copymem(cs.ptr(), r.ptr(), ba->size());
+ copymem(cs.ptrw(), r.ptr(), ba->size());
cs[ba->size()] = 0;
s = cs.get_data();
@@ -899,11 +903,6 @@ struct _VariantCall {
r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
}
- static void Basis_init3(Variant &r_ret, const Variant **p_args) {
-
- r_ret = Basis(p_args[0]->operator Vector3());
- }
-
static void Transform_init1(Variant &r_ret, const Variant **p_args) {
Transform t;
@@ -1528,6 +1527,7 @@ void register_variant_methods() {
ADDFUNC2R(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray());
ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
ADDFUNC1R(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
+ ADDFUNC0R(RECT2, RECT2, Rect2, abs, varray());
ADDFUNC0R(VECTOR3, INT, Vector3, min_axis, varray());
ADDFUNC0R(VECTOR3, INT, Vector3, max_axis, varray());
@@ -1583,6 +1583,8 @@ void register_variant_methods() {
ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "b", REAL, "t", varray());
ADDFUNC1R(COLOR, COLOR, Color, blend, COLOR, "over", varray());
+ ADDFUNC1R(COLOR, COLOR, Color, lightened, REAL, "amount", varray());
+ ADDFUNC1R(COLOR, COLOR, Color, darkened, REAL, "amount", varray());
ADDFUNC1R(COLOR, STRING, Color, to_html, BOOL, "with_alpha", varray(true));
ADDFUNC0R(_RID, INT, RID, get_id, varray());
@@ -1592,7 +1594,8 @@ void register_variant_methods() {
ADDFUNC1R(NODE_PATH, STRING, NodePath, get_name, INT, "idx", varray());
ADDFUNC0R(NODE_PATH, INT, NodePath, get_subname_count, varray());
ADDFUNC1R(NODE_PATH, STRING, NodePath, get_subname, INT, "idx", varray());
- ADDFUNC0R(NODE_PATH, STRING, NodePath, get_property, varray());
+ ADDFUNC0R(NODE_PATH, STRING, NodePath, get_concatenated_subnames, varray());
+ ADDFUNC0R(NODE_PATH, NODE_PATH, NodePath, get_as_property_path, varray());
ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_empty, varray());
ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray());
@@ -1799,7 +1802,6 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::REAL);
- _VariantCall::add_constructor(_VariantCall::Basis_init3, Variant::BASIS, "euler", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::BASIS, "origin", Variant::VECTOR3);
diff --git a/core/vector.h b/core/vector.h
index 03eaf65099..a5c4b3b155 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -96,7 +96,7 @@ class Vector {
void _copy_on_write();
public:
- _FORCE_INLINE_ T *ptr() {
+ _FORCE_INLINE_ T *ptrw() {
if (!_ptr) return NULL;
_copy_on_write();
return (T *)_get_data();
@@ -361,7 +361,7 @@ template <class T>
void Vector<T>::remove(int p_index) {
ERR_FAIL_INDEX(p_index, size());
- T *p = ptr();
+ T *p = ptrw();
int len = size();
for (int i = p_index; i < len - 1; i++) {