diff options
85 files changed, 1625 insertions, 1758 deletions
diff --git a/core/array.cpp b/core/array.cpp index 171c11776c..b7d4ae413a 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -265,6 +265,49 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) { return *this; } +template <typename Less> +_FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value, bool p_before, const Less &p_less) { + + int lo = 0; + int hi = p_array.size(); + if (p_before) { + while (lo < hi) { + const int mid = (lo + hi) / 2; + if (p_less(p_array.get(mid), p_value)) { + lo = mid + 1; + } else { + hi = mid; + } + } + } else { + while (lo < hi) { + const int mid = (lo + hi) / 2; + if (p_less(p_value, p_array.get(mid))) { + hi = mid; + } else { + lo = mid + 1; + } + } + } + return lo; +} + +int Array::bsearch(const Variant &p_value, bool p_before) { + + return bisect(_p->array, p_value, p_before, _ArrayVariantSort()); +} + +int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before) { + + ERR_FAIL_NULL_V(p_obj, 0); + + _ArrayVariantSortCustom less; + less.obj = p_obj; + less.func = p_function; + + return bisect(_p->array, p_value, p_before, less); +} + Array &Array::invert() { _p->array.invert(); diff --git a/core/array.h b/core/array.h index 2c29103108..3d70a31d2f 100644 --- a/core/array.h +++ b/core/array.h @@ -70,6 +70,8 @@ public: Array &sort(); Array &sort_custom(Object *p_obj, const StringName &p_function); + int bsearch(const Variant &p_value, bool p_before = true); + int bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before = true); Array &invert(); int find(const Variant &p_value, int p_from = 0) const; 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..697fec3fc4 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,556 +274,35 @@ 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 *******/ enum { - COMMAND_MEM_SIZE_KB = 256, + COMMAND_MEM_SIZE_KB = 256 * 1024, COMMAND_MEM_SIZE = COMMAND_MEM_SIZE_KB * 1024, SYNC_SEMAPHORES = 8 }; @@ -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/io/logger.cpp b/core/io/logger.cpp index ce2ce44b1d..7177359c8a 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "logger.h" + #include "os/dir_access.h" #include "os/os.h" #include "print_string.h" @@ -259,6 +260,10 @@ void CompositeLogger::log_error(const char *p_function, const char *p_file, int } } +void CompositeLogger::add_logger(Logger *p_logger) { + loggers.push_back(p_logger); +} + CompositeLogger::~CompositeLogger() { for (int i = 0; i < loggers.size(); ++i) { memdelete(loggers[i]); diff --git a/core/io/logger.h b/core/io/logger.h index cf0cc7699f..f8a394193f 100644 --- a/core/io/logger.h +++ b/core/io/logger.h @@ -101,6 +101,8 @@ public: virtual void logv(const char *p_format, va_list p_list, bool p_err); virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR); + void add_logger(Logger *p_logger); + virtual ~CompositeLogger(); }; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 1d9d2dd959..37320d7a77 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -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(); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 8dc396c362..aa51b00028 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -267,7 +267,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { Vector<StringName> names; Vector<StringName> subnames; - StringName property; bool absolute; int name_count = f->get_16(); @@ -279,9 +278,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { 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; @@ -1454,7 +1452,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 +1682,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/node_path.cpp b/core/node_path.cpp index 15f950f605..a01bb420a5 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,23 @@ 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::get_as_property_path() const { + + if (data->has_slashes || !data->path.size()) { + return NodePath(Vector<StringName>(), data->subpath, false); + } else { + ERR_FAIL_COND_V(data->path.size() != 1, NodePath()); + + Vector<StringName> new_path = data->subpath; + new_path.insert(0, data->path[0]); + return NodePath(Vector<StringName>(), new_path, false); + } } -NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute, const String &p_property) { +NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) { data = NULL; @@ -264,14 +279,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 +294,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() { @@ -325,6 +340,7 @@ NodePath::NodePath(const String &p_path) { 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 +353,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 +373,7 @@ NodePath::NodePath(const String &p_path) { if (path[i] == '/') { last_is_slash = true; + has_slashes = true; } else { if (last_is_slash) @@ -369,13 +383,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..631676d827 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -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) { @@ -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,43 @@ 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 { + + 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..3ac699f978 100644 --- a/core/object.h +++ b/core/object.h @@ -477,6 +477,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 +629,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 +691,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/os/input_event.cpp b/core/os/input_event.cpp index 6b43f2c63b..3cdd9ae0e0 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -177,6 +177,14 @@ bool InputEventWithModifiers::get_command() const { return command; } +void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) { + + set_alt(event->get_alt()); + set_shift(event->get_shift()); + set_control(event->get_control()); + set_metakey(event->get_metakey()); +} + void InputEventWithModifiers::_bind_methods() { ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt); @@ -270,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; } @@ -436,10 +444,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co mb->set_id(get_id()); mb->set_device(get_device()); - mb->set_alt(get_alt()); - mb->set_shift(get_shift()); - mb->set_control(get_control()); - mb->set_metakey(get_metakey()); + mb->set_modifiers_from_event(this); mb->set_position(l); mb->set_global_position(g); @@ -555,10 +560,7 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co mm->set_id(get_id()); mm->set_device(get_device()); - mm->set_alt(get_alt()); - mm->set_shift(get_shift()); - mm->set_control(get_control()); - mm->set_metakey(get_metakey()); + mm->set_modifiers_from_event(this); mm->set_position(l); mm->set_global_position(g); @@ -930,3 +932,75 @@ void InputEventAction::_bind_methods() { InputEventAction::InputEventAction() { pressed = false; } +///////////////////////////// + +void InputEventGesture::set_position(const Vector2 &p_pos) { + + pos = p_pos; +} + +Vector2 InputEventGesture::get_position() const { + + return pos; +} +///////////////////////////// + +void InputEventMagnifyGesture::set_factor(real_t p_factor) { + + factor = p_factor; +} + +real_t InputEventMagnifyGesture::get_factor() const { + + return factor; +} + +Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { + + Ref<InputEventMagnifyGesture> ev; + ev.instance(); + + ev->set_id(get_id()); + ev->set_device(get_device()); + ev->set_modifiers_from_event(this); + + ev->set_position(p_xform.xform(get_position() + p_local_ofs)); + ev->set_factor(get_factor()); + + return ev; +} + +InputEventMagnifyGesture::InputEventMagnifyGesture() { + + factor = 1.0; +} +///////////////////////////// + +void InputEventPanGesture::set_delta(const Vector2 &p_delta) { + + delta = p_delta; +} + +Vector2 InputEventPanGesture::get_delta() const { + return delta; +} + +Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { + + Ref<InputEventPanGesture> ev; + ev.instance(); + + ev->set_id(get_id()); + ev->set_device(get_device()); + ev->set_modifiers_from_event(this); + + ev->set_position(p_xform.xform(get_position() + p_local_ofs)); + ev->set_delta(get_delta()); + + return ev; +} + +InputEventPanGesture::InputEventPanGesture() { + + delta = Vector2(0, 0); +} diff --git a/core/os/input_event.h b/core/os/input_event.h index de3c0232ff..2cba60bede 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -213,6 +213,8 @@ public: void set_command(bool p_enabled); bool get_command() const; + void set_modifiers_from_event(const InputEventWithModifiers *event); + InputEventWithModifiers(); }; @@ -468,4 +470,42 @@ public: InputEventAction(); }; +class InputEventGesture : public InputEventWithModifiers { + + GDCLASS(InputEventGesture, InputEventWithModifiers) + + Vector2 pos; + +public: + void set_position(const Vector2 &p_pos); + Vector2 get_position() const; +}; + +class InputEventMagnifyGesture : public InputEventGesture { + + GDCLASS(InputEventMagnifyGesture, InputEventGesture) + real_t factor; + +public: + void set_factor(real_t p_factor); + real_t get_factor() const; + + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + + InputEventMagnifyGesture(); +}; + +class InputEventPanGesture : public InputEventGesture { + + GDCLASS(InputEventPanGesture, InputEventGesture) + Vector2 delta; + +public: + void set_delta(const Vector2 &p_delta); + Vector2 get_delta() const; + + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + + InputEventPanGesture(); +}; #endif 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 02f7d01cd3..84937c0e59 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -63,15 +63,21 @@ void OS::debug_break(){ // something }; -void OS::_set_logger(Logger *p_logger) { +void OS::_set_logger(CompositeLogger *p_logger) { if (_logger) { memdelete(_logger); } _logger = p_logger; } -void OS::initialize_logger() { - _set_logger(memnew(StdLogger)); +void OS::add_logger(Logger *p_logger) { + if (!_logger) { + Vector<Logger *> loggers; + loggers.push_back(p_logger); + _logger = memnew(CompositeLogger(loggers)); + } else { + _logger->add_logger(p_logger); + } } void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type) { @@ -604,7 +610,10 @@ OS::OS() { _stack_bottom = (void *)(&stack_bottom); _logger = NULL; - _set_logger(memnew(StdLogger)); + + Vector<Logger *> loggers; + loggers.push_back(memnew(StdLogger)); + _set_logger(memnew(CompositeLogger(loggers))); } OS::~OS() { diff --git a/core/os/os.h b/core/os/os.h index e48e5c6d70..fe4ffb2922 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -62,10 +62,10 @@ class OS { void *_stack_bottom; - Logger *_logger; + CompositeLogger *_logger; protected: - void _set_logger(Logger *p_logger); + void _set_logger(CompositeLogger *p_logger); public: typedef void (*ImeCallback)(void *p_inp, String p_text, Point2 p_selection); @@ -114,7 +114,8 @@ protected: virtual int get_audio_driver_count() const = 0; virtual const char *get_audio_driver_name(int p_driver) const = 0; - virtual void initialize_logger(); + void add_logger(Logger *p_logger); + virtual void initialize_core() = 0; virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 9e6aaeb911..365ed07810 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -446,7 +446,7 @@ 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, is_empty); VCALL_LOCALMEM0R(Dictionary, size); @@ -483,6 +483,8 @@ struct _VariantCall { VCALL_LOCALMEM1(Array, erase); VCALL_LOCALMEM0(Array, sort); VCALL_LOCALMEM2(Array, sort_custom); + VCALL_LOCALMEM2R(Array, bsearch); + VCALL_LOCALMEM4R(Array, bsearch_custom); VCALL_LOCALMEM0R(Array, duplicate); VCALL_LOCALMEM0(Array, invert); @@ -1590,7 +1592,7 @@ 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, BOOL, NodePath, is_empty, varray()); ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray()); @@ -1625,6 +1627,8 @@ void register_variant_methods() { ADDFUNC0RNC(ARRAY, NIL, Array, pop_front, varray()); ADDFUNC0NC(ARRAY, NIL, Array, sort, varray()); ADDFUNC2NC(ARRAY, NIL, Array, sort_custom, OBJECT, "obj", STRING, "func", varray()); + ADDFUNC2R(ARRAY, INT, Array, bsearch, NIL, "value", BOOL, "before", varray(true)); + ADDFUNC4R(ARRAY, INT, Array, bsearch_custom, NIL, "value", OBJECT, "obj", STRING, "func", BOOL, "before", varray(true)); ADDFUNC0NC(ARRAY, NIL, Array, invert, varray()); ADDFUNC0RNC(ARRAY, ARRAY, Array, duplicate, varray()); diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 203c60e644..3bb40755a6 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -260,6 +260,32 @@ Sort the array using a custom method and return reference to the array. The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair of elements from the array) and must return true if the first argument is less than the second, and return false otherwise. Note: you cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior. </description> </method> + <method name="bsearch"> + <return type="int"> + </return> + <argument index="0" name="value" type="var"> + </argument> + <argument index="1" name="before" type="bool" default="true"> + </argument> + <description> + Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search. Optionally, a before specifier can be passed. If false, the returned index comes after all existing entries of the value in the array. Note that calling bsearch on an unsorted array results in unexpected behavior. + </description> + </method> + <method name="bsearch_custom"> + <return type="int"> + </return> + <argument index="0" name="value" type="var"> + </argument> + <argument index="1" name="obj" type="Object"> + </argument> + <argument index="2" name="func" type="String"> + </argument> + <argument index="3" name="before" type="bool" default="true"> + </argument> + <description> + Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search and a custom comparison method. Optionally, a before specifier can be passed. If false, the returned index comes after all existing entries of the value in the array. The custom method receives two arguments (an element from the array and the value searched for) and must return true if the first argument is less than the second, and return false otherwise. Note that calling bsearch on an unsorted array results in unexpected behavior. + </description> + </method> </methods> <constants> </constants> diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index ce0967af2c..0d102902e8 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -133,15 +133,6 @@ void OS_Unix::initialize_core() { } } -void OS_Unix::initialize_logger() { - Vector<Logger *> loggers; - loggers.push_back(memnew(UnixTerminalLogger)); - // FIXME: Reenable once we figure out how to get this properly in user:// - // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277) - //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt"))); - _set_logger(memnew(CompositeLogger(loggers))); -} - void OS_Unix::finalize_core() { } @@ -543,4 +534,10 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i UnixTerminalLogger::~UnixTerminalLogger() {} +OS_Unix::OS_Unix() { + Vector<Logger *> loggers; + loggers.push_back(memnew(UnixTerminalLogger)); + _set_logger(memnew(CompositeLogger(loggers))); +} + #endif diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 432f48408f..5b3fb824f0 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -53,7 +53,6 @@ protected: virtual int get_audio_driver_count() const; virtual const char *get_audio_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual int unix_initialize_audio(int p_audio_driver); //virtual void initialize(int p_video_driver,int p_audio_driver); @@ -63,6 +62,8 @@ protected: String stdin_buf; public: + OS_Unix(); + virtual void alert(const String &p_alert, const String &p_title = "ALERT!"); virtual String get_stdin_string(bool p_block); diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index 7d877bdb8c..1d70f8ba55 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -966,7 +966,9 @@ void AnimationKeyEditor::_cleanup_animation(Ref<Animation> p_animation) { Object *obj = NULL; RES res; - Node *node = root->get_node_and_resource(p_animation->track_get_path(i), res); + Vector<StringName> leftover_path; + + Node *node = root->get_node_and_resource(p_animation->track_get_path(i), res, leftover_path); if (res.is_valid()) { obj = res.ptr(); @@ -975,7 +977,7 @@ void AnimationKeyEditor::_cleanup_animation(Ref<Animation> p_animation) { } if (obj && p_animation->track_get_type(i) == Animation::TYPE_VALUE) { - valid_type = obj->get_static_property_type(p_animation->track_get_path(i).get_property(), &prop_exists); + valid_type = obj->get_static_property_type_indexed(leftover_path, &prop_exists); } if (!obj && cleanup_tracks->is_pressed()) { @@ -1315,7 +1317,9 @@ void AnimationKeyEditor::_track_editor_draw() { Object *obj = NULL; RES res; - Node *node = root ? root->get_node_and_resource(animation->track_get_path(idx), res) : (Node *)NULL; + Vector<StringName> leftover_path; + + Node *node = root ? root->get_node_and_resource(animation->track_get_path(idx), res, leftover_path) : (Node *)NULL; if (res.is_valid()) { obj = res.ptr(); @@ -1324,7 +1328,8 @@ void AnimationKeyEditor::_track_editor_draw() { } if (obj && animation->track_get_type(idx) == Animation::TYPE_VALUE) { - valid_type = obj->get_static_property_type(animation->track_get_path(idx).get_property(), &prop_exists); + // While leftover_path might be still empty, we wouldn't be able to get here anyway + valid_type = obj->get_static_property_type_indexed(leftover_path, &prop_exists); } if (/*mouse_over.over!=MouseOver::OVER_NONE &&*/ idx == mouse_over.track) { @@ -1648,26 +1653,34 @@ PropertyInfo AnimationKeyEditor::_find_hint_for_track(int p_idx, NodePath &r_bas return PropertyInfo(); RES res; - Node *node = root->get_node_and_resource(path, res); + Vector<StringName> leftover_path; + Node *node = root->get_node_and_resource(path, res, leftover_path, true); if (node) { r_base_path = node->get_path(); } - String property = path.get_property(); - if (property == "") + if (leftover_path.empty()) return PropertyInfo(); - List<PropertyInfo> pinfo; + Variant property_info_base; if (res.is_valid()) - res->get_property_list(&pinfo); + property_info_base = res; else if (node) - node->get_property_list(&pinfo); + property_info_base = node; + + for (int i = 0; i < leftover_path.size() - 1; i++) { + property_info_base = property_info_base.get_named(leftover_path[i]); + } + + List<PropertyInfo> pinfo; + property_info_base.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) + if (E->get().name == leftover_path[leftover_path.size() - 1]) { return E->get(); + } } return PropertyInfo(); @@ -2779,7 +2792,8 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) Object *obj = NULL; RES res; - Node *node = root->get_node_and_resource(animation->track_get_path(idx), res); + Vector<StringName> leftover_path; + Node *node = root->get_node_and_resource(animation->track_get_path(idx), res, leftover_path); if (res.is_valid()) { obj = res.ptr(); @@ -2788,7 +2802,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } if (obj) { - valid_type = obj->get_static_property_type(animation->track_get_path(idx).get_property(), &prop_exists); + valid_type = obj->get_static_property_type_indexed(leftover_path, &prop_exists); } text += "type: " + Variant::get_type_name(v.get_type()) + "\n"; @@ -2889,6 +2903,18 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } } } + + Ref<InputEventMagnifyGesture> magnify_gesture = p_input; + if (magnify_gesture.is_valid()) { + zoom->set_value(zoom->get_value() * magnify_gesture->get_factor()); + } + + Ref<InputEventPanGesture> pan_gesture = p_input; + if (pan_gesture.is_valid()) { + + h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * pan_gesture->get_delta().x / 8); + v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * pan_gesture->get_delta().y / 8); + } } void AnimationKeyEditor::_notification(int p_what) { diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index c7012a0c14..216f2027fb 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -979,6 +979,23 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { } } + Ref<InputEventMagnifyGesture> magnify_gesture = p_event; + if (magnify_gesture.is_valid()) { + + Ref<DynamicFont> font = text_editor->get_font("font"); + + if (font.is_valid()) { + if (font->get_size() != (int)font_size) { + font_size = font->get_size(); + } + + font_size *= powf(magnify_gesture->get_factor(), 0.25); + + _add_font_size((int)font_size - font->get_size()); + } + return; + } + Ref<InputEventKey> k = p_event; if (k.is_valid()) { @@ -999,14 +1016,15 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { void CodeTextEditor::_zoom_in() { font_resize_val += EDSCALE; - - if (font_resize_timer->get_time_left() == 0) - font_resize_timer->start(); + _zoom_changed(); } void CodeTextEditor::_zoom_out() { font_resize_val -= EDSCALE; + _zoom_changed(); +} +void CodeTextEditor::_zoom_changed() { if (font_resize_timer->get_time_left() == 0) font_resize_timer->start(); } @@ -1067,16 +1085,25 @@ void CodeTextEditor::_complete_request() { void CodeTextEditor::_font_resize_timeout() { + if (_add_font_size(font_resize_val)) { + font_resize_val = 0; + } +} + +bool CodeTextEditor::_add_font_size(int p_delta) { + Ref<DynamicFont> font = text_editor->get_font("font"); if (font.is_valid()) { - int new_size = CLAMP(font->get_size() + font_resize_val, 8 * EDSCALE, 96 * EDSCALE); + int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE); if (new_size != font->get_size()) { EditorSettings::get_singleton()->set("interface/editor/source_font_size", new_size / EDSCALE); font->set_size(new_size); } - font_resize_val = 0; + return true; + } else { + return false; } } @@ -1285,6 +1312,7 @@ CodeTextEditor::CodeTextEditor() { code_complete_timer->connect("timeout", this, "_code_complete_timer_timeout"); font_resize_val = 0; + font_size = -1; font_resize_timer = memnew(Timer); add_child(font_resize_timer); font_resize_timer->set_one_shot(true); diff --git a/editor/code_editor.h b/editor/code_editor.h index 410dd99878..656ea4b47b 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -204,6 +204,7 @@ class CodeTextEditor : public VBoxContainer { Timer *font_resize_timer; int font_resize_val; + real_t font_size; Label *error; @@ -212,10 +213,12 @@ class CodeTextEditor : public VBoxContainer { void _update_font(); void _complete_request(); void _font_resize_timeout(); + bool _add_font_size(int p_delta); void _text_editor_gui_input(const Ref<InputEvent> &p_event); void _zoom_in(); void _zoom_out(); + void _zoom_changed(); void _reset_zoom(); CodeTextEditorCodeCompleteFunc code_complete_func; diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index a0ca9b88e0..f8b9425a4e 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -541,6 +541,9 @@ void EditorFileDialog::update_file_list() { while ((item = dir_access->get_next(&isdir)) != "") { + if (item == ".") + continue; + ishidden = dir_access->current_is_hidden(); if (show_hidden || !ishidden) { @@ -562,7 +565,7 @@ void EditorFileDialog::update_file_list() { while (!dirs.empty()) { const String &dir_name = dirs.front()->get(); - item_list->add_item(dir_name + "/"); + item_list->add_item(dir_name); if (display_mode == DISPLAY_THUMBNAILS) { diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index cc7f1cac43..4b372e7afd 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -564,18 +564,37 @@ void EditorHelp::_class_desc_select(const String &p_select) { emit_signal("go_to_help", "class_name:" + p_select.substr(1, p_select.length())); return; } else if (p_select.begins_with("@")) { + String tag = p_select.substr(1, 6); + String link = p_select.substr(7, p_select.length()); + + String topic; + Map<String, int> *table = NULL; + + if (tag == "method") { + topic = "class_method"; + table = &this->method_line; + } else if (tag == "member") { + topic = "class_property"; + table = &this->property_line; + } else if (tag == "enum ") { + topic = "class_enum"; + table = &this->enum_line; + } else if (tag == "signal") { + topic = "class_signal"; + table = &this->signal_line; + } else { + return; + } - String m = p_select.substr(1, p_select.length()); - - if (m.find(".") != -1) { + if (link.find(".") != -1) { //must go somewhere else - emit_signal("go_to_help", "class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0)); + emit_signal("go_to_help", topic + ":" + link.get_slice(".", 0) + ":" + link.get_slice(".", 1)); } else { - if (!method_line.has(m)) + if (!table->has(link)) return; - class_desc->scroll_to_line(method_line[m]); + class_desc->scroll_to_line((*table)[link]); } } else if (p_select.begins_with("http")) { OS::get_singleton()->shell_open(p_select); @@ -808,7 +827,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { } class_desc->push_cell(); if (describe) { - class_desc->push_meta("@" + cd.properties[i].name); + class_desc->push_meta("@member" + cd.properties[i].name); } class_desc->push_font(doc_code_font); @@ -881,7 +900,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { if (methods[i].description != "") { method_descr = true; - class_desc->push_meta("@" + methods[i].name); + class_desc->push_meta("@method" + methods[i].name); } class_desc->push_color(headline_color); _add_text(methods[i].name); @@ -1240,7 +1259,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { for (int i = 0; i < cd.properties.size(); i++) { - method_line[cd.properties[i].name] = class_desc->get_line_count() - 2; + property_line[cd.properties[i].name] = class_desc->get_line_count() - 2; class_desc->push_table(2); class_desc->set_table_column_expand(1, 1); @@ -1452,7 +1471,6 @@ void EditorHelp::_help_callback(const String &p_topic) { line = property_line[name]; } else if (what == "class_enum") { - print_line("go to enum:"); if (enum_line.has(name)) line = enum_line[name]; } else if (what == "class_theme_item") { @@ -1535,12 +1553,13 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { p_rt->add_text("["); pos = brk_pos + 1; - } else if (tag.begins_with("method ")) { + } else if (tag.begins_with("method ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ")) { - String m = tag.substr(7, tag.length()); + String link_target = tag.substr(tag.find(" ") + 1, tag.length()); + String link_tag = tag.substr(0, tag.find(" ")).rpad(6); p_rt->push_color(link_color); - p_rt->push_meta("@" + m); - p_rt->add_text(m + "()"); + p_rt->push_meta("@" + link_tag + link_target); + p_rt->add_text(link_target + (tag.begins_with("method ") ? "()" : "")); p_rt->pop(); p_rt->pop(); pos = brk_end + 1; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 109f132d76..a32ade3b71 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -364,7 +364,8 @@ void EditorNode::_notification(int p_what) { dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons")); } - if (p_what = Control::NOTIFICATION_RESIZED) { + + if (p_what == Control::NOTIFICATION_RESIZED) { _update_scene_tabs(); } } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 9c432323f4..2ddfea00e3 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1417,18 +1417,18 @@ void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) { if (all_files_scenes) { file_options->add_item(TTR("Instance"), FILE_INSTANCE); } + file_options->add_separator(); if (filenames.size() == 1) { - file_options->add_separator(); file_options->add_item(TTR("Edit Dependencies.."), FILE_DEPENDENCIES); file_options->add_item(TTR("View Owners.."), FILE_OWNERS); + file_options->add_separator(); } } else if (all_folders && foldernames.size() > 0) { file_options->add_item(TTR("Open"), FILE_OPEN); + file_options->add_separator(); } - file_options->add_separator(); - int num_items = filenames.size() + foldernames.size(); if (num_items >= 1) { if (num_items == 1) { @@ -1448,12 +1448,13 @@ void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) { } void FileSystemDock::_rmb_pressed(const Vector2 &p_pos) { - folder_options->clear(); - folder_options->set_size(Size2(1, 1)); + file_options->clear(); + file_options->set_size(Size2(1, 1)); - folder_options->add_item(TTR("New Folder.."), FOLDER_NEW_FOLDER); - folder_options->set_position(files->get_global_position() + p_pos); - folder_options->popup(); + file_options->add_item(TTR("New Folder.."), FILE_NEW_FOLDER); + file_options->add_item(TTR("Show In File Manager"), FILE_SHOW_IN_EXPLORER); + file_options->set_position(files->get_global_position() + p_pos); + file_options->popup(); } void FileSystemDock::select_file(const String &p_file) { diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 22d23e1c72..8fe6538653 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -1196,14 +1196,14 @@ void AnimationTreeEditor::_edit_filters() { if (base) { NodePath np = E->get(); - if (np.get_property() != StringName()) { + if (np.get_subname_count() == 1) { Node *n = base->get_node(np); Skeleton *s = Object::cast_to<Skeleton>(n); if (s) { String skelbase = E->get().substr(0, E->get().find(":")); - int bidx = s->find_bone(np.get_property()); + int bidx = s->find_bone(np.get_subname(0)); if (bidx != -1) { int bparent = s->get_bone_parent(bidx); @@ -1213,7 +1213,7 @@ void AnimationTreeEditor::_edit_filters() { String bpn = skelbase + ":" + s->get_bone_name(bparent); if (pm.has(bpn)) { parent = pm[bpn]; - descr = np.get_property(); + descr = np.get_subname(0); } } else { diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6cb4171f5a..3940dd9044 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1442,6 +1442,22 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { } } + Ref<InputEventMagnifyGesture> magnify_gesture = p_event; + if (magnify_gesture.is_valid()) { + + _zoom_on_position(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position()); + return; + } + + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + const Vector2 delta = (int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom) * pan_gesture->get_delta(); + h_scroll->set_value(h_scroll->get_value() + delta.x); + v_scroll->set_value(v_scroll->get_value() + delta.y); + return; + } + Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { // Button event diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index a525983c75..ebb5f57e99 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -339,6 +339,19 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { uv_edit_draw->update(); } } + + Ref<InputEventMagnifyGesture> magnify_gesture = p_input; + if (magnify_gesture.is_valid()) { + + uv_zoom->set_value(uv_zoom->get_value() * magnify_gesture->get_factor()); + } + + Ref<InputEventPanGesture> pan_gesture = p_input; + if (pan_gesture.is_valid()) { + + uv_hscroll->set_value(uv_hscroll->get_value() + uv_hscroll->get_page() * pan_gesture->get_delta().x / 8); + uv_vscroll->set_value(uv_vscroll->get_value() + uv_vscroll->get_page() * pan_gesture->get_delta().y / 8); + } } void Polygon2DEditor::_uv_scroll_changed(float) { diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 448daab226..921ba529a2 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1694,92 +1694,78 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { switch (nav_mode) { case NAVIGATION_PAN: { + _nav_pan(m, _get_warped_mouse_motion(m)); - real_t pan_speed = 1 / 150.0; - int pan_speed_modifier = 10; - if (nav_scheme == NAVIGATION_MAYA && m->get_shift()) - pan_speed *= pan_speed_modifier; + } break; - Point2i relative = _get_warped_mouse_motion(m); + case NAVIGATION_ZOOM: { + _nav_zoom(m, m->get_relative()); - Transform camera_transform; + } break; - camera_transform.translate(cursor.pos); - camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot); - camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot); - Vector3 translation(-relative.x * pan_speed, relative.y * pan_speed, 0); - translation *= cursor.distance / DISTANCE_DEFAULT; - camera_transform.translate(translation); - cursor.pos = camera_transform.origin; + case NAVIGATION_ORBIT: { + _nav_orbit(m, _get_warped_mouse_motion(m)); + + } break; + + case NAVIGATION_LOOK: { + _nav_look(m, _get_warped_mouse_motion(m)); + + } break; + + default: {} + } + } + + Ref<InputEventMagnifyGesture> magnify_gesture = p_event; + if (magnify_gesture.is_valid()) { + + if (is_freelook_active()) + scale_freelook_speed(magnify_gesture->get_factor()); + else + scale_cursor_distance(1.0 / magnify_gesture->get_factor()); + } + + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); + NavigationMode nav_mode = NAVIGATION_NONE; + + if (nav_scheme == NAVIGATION_GODOT) { + + int mod = _get_key_modifier(pan_gesture); + + if (mod == _get_key_modifier_setting("editors/3d/navigation/pan_modifier")) + nav_mode = NAVIGATION_PAN; + else if (mod == _get_key_modifier_setting("editors/3d/navigation/zoom_modifier")) + nav_mode = NAVIGATION_ZOOM; + else if (mod == _get_key_modifier_setting("editors/3d/navigation/orbit_modifier")) + nav_mode = NAVIGATION_ORBIT; + + } else if (nav_scheme == NAVIGATION_MAYA) { + if (pan_gesture->get_alt()) + nav_mode = NAVIGATION_PAN; + } + + switch (nav_mode) { + case NAVIGATION_PAN: { + _nav_pan(m, pan_gesture->get_delta()); } break; case NAVIGATION_ZOOM: { - real_t zoom_speed = 1 / 80.0; - int zoom_speed_modifier = 10; - if (nav_scheme == NAVIGATION_MAYA && m->get_shift()) - zoom_speed *= zoom_speed_modifier; - - NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/navigation/zoom_style").operator int(); - if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { - if (m->get_relative().x > 0) - scale_cursor_distance(1 - m->get_relative().x * zoom_speed); - else if (m->get_relative().x < 0) - scale_cursor_distance(1.0 / (1 + m->get_relative().x * zoom_speed)); - } else { - if (m->get_relative().y > 0) - scale_cursor_distance(1 + m->get_relative().y * zoom_speed); - else if (m->get_relative().y < 0) - scale_cursor_distance(1.0 / (1 - m->get_relative().y * zoom_speed)); - } + _nav_zoom(m, pan_gesture->get_delta()); } break; case NAVIGATION_ORBIT: { - Point2i relative = _get_warped_mouse_motion(m); - - real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); - real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); - - cursor.x_rot += relative.y * radians_per_pixel; - cursor.y_rot += relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) - cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) - cursor.x_rot = -Math_PI / 2.0; - name = ""; - _update_name(); + _nav_orbit(m, pan_gesture->get_delta()); + } break; case NAVIGATION_LOOK: { - // Freelook only works properly in perspective. - // It technically works too in ortho, but it's awful for a user due to fov being near zero - if (!orthogonal) { - Point2i relative = _get_warped_mouse_motion(m); - - real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); - real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); - - // Note: do NOT assume the camera has the "current" transform, because it is interpolated and may have "lag". - Transform prev_camera_transform = to_camera_transform(cursor); - - cursor.x_rot += relative.y * radians_per_pixel; - cursor.y_rot += relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) - cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) - cursor.x_rot = -Math_PI / 2.0; - - // Look is like the opposite of Orbit: the focus point rotates around the camera - Transform camera_transform = to_camera_transform(cursor); - Vector3 pos = camera_transform.xform(Vector3(0, 0, 0)); - Vector3 prev_pos = prev_camera_transform.xform(Vector3(0, 0, 0)); - Vector3 diff = prev_pos - pos; - cursor.pos += diff; - - name = ""; - _update_name(); - } + _nav_look(m, pan_gesture->get_delta()); } break; @@ -1885,6 +1871,94 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { accept_event(); } +void SpatialEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { + + const NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); + + real_t pan_speed = 1 / 150.0; + int pan_speed_modifier = 10; + if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) + pan_speed *= pan_speed_modifier; + + Transform camera_transform; + + camera_transform.translate(cursor.pos); + camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot); + camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot); + Vector3 translation(-p_relative.x * pan_speed, p_relative.y * pan_speed, 0); + translation *= cursor.distance / DISTANCE_DEFAULT; + camera_transform.translate(translation); + cursor.pos = camera_transform.origin; +} + +void SpatialEditorViewport::_nav_zoom(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { + + const NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); + + real_t zoom_speed = 1 / 80.0; + int zoom_speed_modifier = 10; + if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) + zoom_speed *= zoom_speed_modifier; + + NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/navigation/zoom_style").operator int(); + if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { + if (p_relative.x > 0) + scale_cursor_distance(1 - p_relative.x * zoom_speed); + else if (p_relative.x < 0) + scale_cursor_distance(1.0 / (1 + p_relative.x * zoom_speed)); + } else { + if (p_relative.y > 0) + scale_cursor_distance(1 + p_relative.y * zoom_speed); + else if (p_relative.y < 0) + scale_cursor_distance(1.0 / (1 - p_relative.y * zoom_speed)); + } +} + +void SpatialEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { + + real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); + real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); + + cursor.x_rot += p_relative.y * radians_per_pixel; + cursor.y_rot += p_relative.x * radians_per_pixel; + if (cursor.x_rot > Math_PI / 2.0) + cursor.x_rot = Math_PI / 2.0; + if (cursor.x_rot < -Math_PI / 2.0) + cursor.x_rot = -Math_PI / 2.0; + name = ""; + _update_name(); +} + +void SpatialEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { + + // Freelook only works properly in perspective. + // It technically works too in ortho, but it's awful for a user due to fov being near zero + if (!orthogonal) { + real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); + real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); + + // Note: do NOT assume the camera has the "current" transform, because it is interpolated and may have "lag". + Transform prev_camera_transform = to_camera_transform(cursor); + + cursor.x_rot += p_relative.y * radians_per_pixel; + cursor.y_rot += p_relative.x * radians_per_pixel; + if (cursor.x_rot > Math_PI / 2.0) + cursor.x_rot = Math_PI / 2.0; + if (cursor.x_rot < -Math_PI / 2.0) + cursor.x_rot = -Math_PI / 2.0; + + // Look is like the opposite of Orbit: the focus point rotates around the camera + Transform camera_transform = to_camera_transform(cursor); + Vector3 pos = camera_transform.xform(Vector3(0, 0, 0)); + Vector3 prev_pos = prev_camera_transform.xform(Vector3(0, 0, 0)); + Vector3 diff = prev_pos - pos; + cursor.pos += diff; + + name = ""; + _update_name(); + } +} + void SpatialEditorViewport::set_freelook_active(bool active_now) { if (!freelook_active && active_now) { diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index ad11ec33df..14558fc878 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -170,6 +170,11 @@ private: void _select_region(); bool _gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false); + void _nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative); + void _nav_zoom(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative); + void _nav_orbit(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative); + void _nav_look(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative); + float get_znear() const; float get_zfar() const; float get_fov() const; diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index b07280a4cd..900f7625bc 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -360,7 +360,7 @@ void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) { last_wait_for_key = p_event; String str = keycode_get_string(k->get_scancode()).capitalize(); if (k->get_metakey()) - str = TTR("Meta+") + str; + str = vformat("%s+", find_keycode_name(KEY_META)) + str; if (k->get_shift()) str = TTR("Shift+") + str; if (k->get_alt()) @@ -642,7 +642,7 @@ void ProjectSettingsEditor::_update_actions() { String str = keycode_get_string(k->get_scancode()).capitalize(); if (k->get_metakey()) - str = TTR("Meta+") + str; + str = vformat("%s+", find_keycode_name(KEY_META)) + str; if (k->get_shift()) str = TTR("Shift+") + str; if (k->get_alt()) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 1d2647badc..a97a5630e6 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -986,7 +986,7 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP //will be renamed NodePath rel_path = new_root_path.rel_path_to(E->get().second); - NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false, track_np.get_property()); + NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false); if (new_path == track_np) continue; //bleh editor_data->get_undo_redo().add_do_method(anim.ptr(), "track_set_path", i, new_path); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index 2a3e47b2a6..ef082f29c3 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -1127,6 +1127,15 @@ void ScriptEditorDebugger::_notification(int p_what) { tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles")); tabs->set_margin(MARGIN_LEFT, -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT)); tabs->set_margin(MARGIN_RIGHT, EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT)); + + bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines"); + Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color"); + + if (enable_rl) { + inspect_scene_tree->add_constant_override("draw_relationship_lines", 1); + inspect_scene_tree->add_color_override("relationship_line_color", rl_color); + } else + inspect_scene_tree->add_constant_override("draw_relationship_lines", 0); } break; } } diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index c052845be9..853761f689 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -291,7 +291,7 @@ void EditorSettingsDialog::_wait_for_key(const Ref<InputEvent> &p_event) { last_wait_for_key = k; String str = keycode_get_string(k->get_scancode()).capitalize(); if (k->get_metakey()) - str = TTR("Meta+") + str; + str = vformat("%s+", find_keycode_name(KEY_META)) + str; if (k->get_shift()) str = TTR("Shift+") + str; if (k->get_alt()) diff --git a/main/input_default.cpp b/main/input_default.cpp index 2940f432d5..7cc7521686 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -319,6 +319,15 @@ void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) { set_joy_axis(jm->get_device(), jm->get_axis(), jm->get_axis_value()); } + Ref<InputEventGesture> ge = p_event; + + if (ge.is_valid()) { + + if (main_loop) { + main_loop->input_event(ge); + } + } + if (!p_event->is_echo()) { for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { diff --git a/main/main.cpp b/main/main.cpp index 5410aae1d2..8b866e160f 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -290,8 +290,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph register_core_settings(); //here globals is present - OS::get_singleton()->initialize_logger(); - translation_server = memnew(TranslationServer); performance = memnew(Performance); ClassDB::register_class<Performance>(); @@ -745,6 +743,15 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph #endif } + GLOBAL_DEF("logging/file_logging/enable_file_logging", true); + GLOBAL_DEF("logging/file_logging/log_path", "user://logs/log.txt"); + GLOBAL_DEF("logging/file_logging/max_log_files", 10); + if (FileAccess::get_create_func(FileAccess::ACCESS_USERDATA) && GLOBAL_GET("logging/file_logging/enable_file_logging")) { + String base_path = GLOBAL_GET("logging/file_logging/log_path"); + int max_files = GLOBAL_GET("logging/file_logging/max_log_files"); + OS::get_singleton()->add_logger(memnew(RotatedFileLogger(base_path, max_files))); + } + if (editor) { Engine::get_singleton()->set_editor_hint(true); main_args.push_back("--editor"); @@ -825,8 +832,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true); if (rtm == -1) { rtm = GLOBAL_DEF("rendering/threads/thread_model", OS::RENDER_THREAD_SAFE); - if (rtm >= 1) //hack for now - rtm = 1; } if (rtm >= 0 && rtm < 3) { diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 98ae82bc5f..f5ab8221e3 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -511,12 +511,14 @@ void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) { mode = PhysicsServer::BODY_MODE_RIGID; set_axis_lock(axis_lock); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); + scratch_space_override_modificator(); break; } case PhysicsServer::BODY_MODE_CHARACTER: { mode = PhysicsServer::BODY_MODE_CHARACTER; set_axis_lock(axis_lock); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); + scratch_space_override_modificator(); break; } } diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 485bf4b9df..54d0672a5b 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -19,19 +19,27 @@ def _spaced(e): return e if e[-1] == '*' else e + ' ' def _build_gdnative_api_struct_header(api): - ext_wrappers = '' + gdnative_api_init_macro = [ + '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;' + ] for name in api['extensions']: - ext_wrappers += ' extern const godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;' + gdnative_api_init_macro.append( + '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name)) - ext_init = 'for (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ' - ext_init += 'switch (_gdnative_wrapper_api_struct->extensions[i]->type) {' + gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;') + gdnative_api_init_macro.append('\tfor (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ') + gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {') for name in api['extensions']: - ext_init += 'case GDNATIVE_EXT_' + api['extensions'][name]['type'] + ': ' - ext_init += '_gdnative_wrapper_' + name + '_api_struct = (' + 'godot_gdnative_ext_' + name + '_api_struct *) _gdnative_wrapper_api_struct->extensions[i]; break;' - - ext_init += '}' + gdnative_api_init_macro.append( + '\t\t\tcase GDNATIVE_EXT_%s:' % api['extensions'][name]['type']) + gdnative_api_init_macro.append( + '\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)' + ' _gdnative_wrapper_api_struct->extensions[i];'.format(name)) + gdnative_api_init_macro.append('\t\t\t\tbreak;') + gdnative_api_init_macro.append('\t\t}') + gdnative_api_init_macro.append('\t}') out = [ '/* THIS FILE IS GENERATED DO NOT EDIT */', @@ -43,7 +51,7 @@ def _build_gdnative_api_struct_header(api): '#include <nativescript/godot_nativescript.h>', '#include <pluginscript/godot_pluginscript.h>', '', - '#define GDNATIVE_API_INIT(options) do { extern const godot_gdnative_api_struct *_gdnative_wrapper_api_struct;' + ext_wrappers + ' _gdnative_wrapper_api_struct = options->api_struct; ' + ext_init + ' } while (0)', + '#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)', '', '#ifdef __cplusplus', 'extern "C" {', @@ -179,7 +187,7 @@ def _build_gdnative_wrapper_code(api): ] for name in api['extensions']: - out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;') + out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;') out += [''] diff --git a/modules/gdnative/gdnative/array.cpp b/modules/gdnative/gdnative/array.cpp index e0d9514985..8351c43574 100644 --- a/modules/gdnative/gdnative/array.cpp +++ b/modules/gdnative/gdnative/array.cpp @@ -302,6 +302,17 @@ void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, con self->sort_custom((Object *)p_obj, *func); } +godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before) { + Array *self = (Array *)p_self; + return self->bsearch((const Variant *)p_value, p_before); +} + +godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before) { + Array *self = (Array *)p_self; + const String *func = (const String *)p_func; + return self->bsearch_custom((const Variant *)p_value, (Object *)p_obj, *func, p_before); +} + void GDAPI godot_array_destroy(godot_array *p_self) { ((Array *)p_self)->~Array(); } diff --git a/modules/gdnative/gdnative/node_path.cpp b/modules/gdnative/gdnative/node_path.cpp index 2bd278e050..8dfe151f91 100644 --- a/modules/gdnative/gdnative/node_path.cpp +++ b/modules/gdnative/gdnative/node_path.cpp @@ -91,10 +91,10 @@ godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, co return dest; } -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self) { +godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self) { godot_string dest; const NodePath *self = (const NodePath *)p_self; - memnew_placement(&dest, String(self->get_property())); + memnew_placement(&dest, String(self->get_concatenated_subnames())); return dest; } diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 007c7955d4..488ed93206 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -2680,6 +2680,26 @@ ] }, { + "name": "godot_array_bsearch", + "return_type": "godot_int", + "arguments": [ + ["godot_array *", "p_self"], + ["const godot_variant *", "p_value"], + ["const godot_bool", "p_before"] + ] + }, + { + "name": "godot_array_bsearch_custom", + "return_type": "godot_int", + "arguments": [ + ["godot_array *", "p_self"], + ["const godot_variant *", "p_value"], + ["godot_object *", "p_obj"], + ["const godot_string *", "p_func"], + ["const godot_bool", "p_before"] + ] + }, + { "name": "godot_array_destroy", "return_type": "void", "arguments": [ @@ -2898,7 +2918,7 @@ ] }, { - "name": "godot_node_path_get_property", + "name": "godot_node_path_get_concatenated_subnames", "return_type": "godot_string", "arguments": [ ["const godot_node_path *", "p_self"] diff --git a/modules/gdnative/include/gdnative/array.h b/modules/gdnative/include/gdnative/array.h index 01ae61e280..484ffd10ba 100644 --- a/modules/gdnative/include/gdnative/array.h +++ b/modules/gdnative/include/gdnative/array.h @@ -124,6 +124,10 @@ void GDAPI godot_array_sort(godot_array *p_self); void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func); +godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before); + +godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before); + void GDAPI godot_array_destroy(godot_array *p_self); #ifdef __cplusplus diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index 0a884e6106..6e69d43469 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -53,7 +53,7 @@ extern "C" { // This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! #ifdef _WIN32 -#define GDN_EXPORT +#define GDN_EXPORT __declspec(dllexport) #else #define GDN_EXPORT #endif diff --git a/modules/gdnative/include/gdnative/node_path.h b/modules/gdnative/include/gdnative/node_path.h index 42446175d8..b5a59fd325 100644 --- a/modules/gdnative/include/gdnative/node_path.h +++ b/modules/gdnative/include/gdnative/node_path.h @@ -73,7 +73,7 @@ godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self) godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx); -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self); +godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self); godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 491adb31ee..3a5d0fd3fc 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -623,6 +623,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu return do_input_action(p_camera, mm->get_position(), false); } + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + if (pan_gesture->get_command() || pan_gesture->get_shift()) { + const real_t delta = pan_gesture->get_delta().y; + floor->set_value(floor->get_value() + SGN(delta)); + return true; + } + } + return false; } diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 83b8d8da2d..2318149ca5 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1389,7 +1389,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "obj_property") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Getter. Hold Shift to drop a generic signature.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature.")); #endif @@ -1398,7 +1398,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "nodes") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a simple reference to the node.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node.")); #endif @@ -1407,7 +1407,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "visual_script_variable_drag") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Variable Setter.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter.")); #endif diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index b2c8799540..b575f15559 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -114,15 +114,6 @@ void OS_Android::initialize_core() { #endif } -void OS_Android::initialize_logger() { - Vector<Logger *> loggers; - loggers.push_back(memnew(AndroidLogger)); - // FIXME: Reenable once we figure out how to get this properly in user:// - // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277) - //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt"))); - _set_logger(memnew(CompositeLogger(loggers))); -} - void OS_Android::set_opengl_extensions(const char *p_gl_extensions) { ERR_FAIL_COND(!p_gl_extensions); @@ -762,7 +753,9 @@ OS_Android::OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURI alert_func = p_alert_func; use_reload_hooks = false; - _set_logger(memnew(AndroidLogger)); + Vector<Logger *> loggers; + loggers.push_back(memnew(AndroidLogger)); + _set_logger(memnew(CompositeLogger(loggers))); } OS_Android::~OS_Android() { diff --git a/platform/android/os_android.h b/platform/android/os_android.h index d25f60d540..3b7f55096e 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -144,7 +144,6 @@ public: virtual int get_audio_driver_count() const; virtual const char *get_audio_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 90cb09b458..fbe3bd310d 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -97,17 +97,6 @@ void OSIPhone::initialize_core() { set_data_dir(data_dir); }; -void OSIPhone::initialize_logger() { - Vector<Logger *> loggers; - loggers.push_back(memnew(SyslogLogger)); -#ifdef DEBUG_ENABLED - // it seems iOS app's stdout/stderr is only obtainable if you launch it from Xcode - loggers.push_back(memnew(StdLogger)); -#endif - loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt"))); - _set_logger(memnew(CompositeLogger(loggers))); -} - void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { supported_orientations = 0; @@ -639,7 +628,13 @@ OSIPhone::OSIPhone(int width, int height, String p_data_dir) { // which is initialized in initialize_core data_dir = p_data_dir; - _set_logger(memnew(SyslogLogger)); + Vector<Logger *> loggers; + loggers.push_back(memnew(SyslogLogger)); +#ifdef DEBUG_ENABLED + // it seems iOS app's stdout/stderr is only obtainable if you launch it from Xcode + loggers.push_back(memnew(StdLogger)); +#endif + _set_logger(memnew(CompositeLogger(loggers))); }; OSIPhone::~OSIPhone() { diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 0790a2a9ea..1ef673765a 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -86,7 +86,6 @@ private: virtual int get_video_driver_count() const; virtual const char *get_video_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 74cfec14a6..d5c675d9e0 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -80,10 +80,6 @@ void OS_JavaScript::initialize_core() { FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix> >(FileAccess::ACCESS_RESOURCES); } -void OS_JavaScript::initialize_logger() { - _set_logger(memnew(StdLogger)); -} - void OS_JavaScript::set_opengl_extensions(const char *p_gl_extensions) { ERR_FAIL_COND(!p_gl_extensions); diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 77eeb02a9f..a95b069d03 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -81,7 +81,6 @@ public: virtual int get_audio_driver_count() const; virtual const char *get_audio_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index aa8ee1fe83..9a740a7bea 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -121,7 +121,6 @@ protected: virtual int get_video_driver_count() const; virtual const char *get_video_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); virtual void finalize(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 110cb776ee..781e8de1ab 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -85,6 +85,15 @@ static int prev_mouse_y = 0; static int button_mask = 0; static bool mouse_down_control = false; +static Vector2 get_mouse_pos(NSEvent *event) { + + const NSRect contentRect = [OS_OSX::singleton->window_view frame]; + const NSPoint p = [event locationInWindow]; + mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + return Vector2(mouse_x, mouse_y); +} + @interface GodotApplication : NSApplication @end @@ -508,12 +517,9 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) { mm->set_button_mask(button_mask); prev_mouse_x = mouse_x; prev_mouse_y = mouse_y; - const NSRect contentRect = [OS_OSX::singleton->window_view frame]; - const NSPoint p = [event locationInWindow]; - mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - mm->set_position(Vector2(mouse_x, mouse_y)); - mm->set_global_position(Vector2(mouse_x, mouse_y)); + const Vector2 pos = get_mouse_pos(event); + mm->set_position(pos); + mm->set_global_position(pos); Vector2 relativeMotion = Vector2(); relativeMotion.x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); relativeMotion.y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); @@ -575,6 +581,15 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) { OS_OSX::singleton->input->set_mouse_in_window(true); } +- (void)magnifyWithEvent:(NSEvent *)event { + Ref<InputEventMagnifyGesture> ev; + ev.instance(); + get_key_modifier_state([event modifierFlags], ev); + ev->set_position(get_mouse_pos(event)); + ev->set_factor([event magnification] + 1.0); + OS_OSX::singleton->push_input(ev); +} + - (void)viewDidChangeBackingProperties { // nothing left to do here } @@ -838,6 +853,18 @@ inline void sendScrollEvent(int button, double factor, int modifierFlags) { OS_OSX::singleton->push_input(sc); } +inline void sendPanEvent(double dx, double dy, int modifierFlags) { + + Ref<InputEventPanGesture> pg; + pg.instance(); + + get_key_modifier_state(modifierFlags, pg); + Vector2 mouse_pos = Vector2(mouse_x, mouse_y); + pg->set_position(mouse_pos); + pg->set_delta(Vector2(-dx, -dy)); + OS_OSX::singleton->push_input(pg); +} + - (void)scrollWheel:(NSEvent *)event { double deltaX, deltaY; @@ -856,11 +883,16 @@ inline void sendScrollEvent(int button, double factor, int modifierFlags) { deltaX = [event deltaX]; deltaY = [event deltaY]; } - if (fabs(deltaX)) { - sendScrollEvent(0 > deltaX ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT, fabs(deltaX * 0.3), [event modifierFlags]); - } - if (fabs(deltaY)) { - sendScrollEvent(0 < deltaY ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN, fabs(deltaY * 0.3), [event modifierFlags]); + + if ([event phase] != NSEventPhaseNone || [event momentumPhase] != NSEventPhaseNone) { + sendPanEvent(deltaX, deltaY, [event modifierFlags]); + } else { + if (fabs(deltaX)) { + sendScrollEvent(0 > deltaX ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT, fabs(deltaX * 0.3), [event modifierFlags]); + } + if (fabs(deltaY)) { + sendScrollEvent(0 < deltaY ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN, fabs(deltaY * 0.3), [event modifierFlags]); + } } } @@ -1185,15 +1217,6 @@ public: typedef UnixTerminalLogger OSXTerminalLogger; #endif -void OS_OSX::initialize_logger() { - Vector<Logger *> loggers; - loggers.push_back(memnew(OSXTerminalLogger)); - // FIXME: Reenable once we figure out how to get this properly in user:// - // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277) - //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt"))); - _set_logger(memnew(CompositeLogger(loggers))); -} - void OS_OSX::alert(const String &p_alert, const String &p_title) { // Set OS X-compliant variables NSAlert *window = [[NSAlert alloc] init]; @@ -2142,7 +2165,9 @@ OS_OSX::OS_OSX() { window_size = Vector2(1024, 600); zoomed = false; - _set_logger(memnew(OSXTerminalLogger)); + Vector<Logger *> loggers; + loggers.push_back(memnew(OSXTerminalLogger)); + _set_logger(memnew(CompositeLogger(loggers))); } bool OS_OSX::_check_internal_feature_support(const String &p_feature) { diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 64e319327f..1655caf04b 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -179,15 +179,6 @@ void OSUWP::initialize_core() { cursor_shape = CURSOR_ARROW; } -void OSUWP::initialize_logger() { - Vector<Logger *> loggers; - loggers.push_back(memnew(WindowsTerminalLogger)); - // FIXME: Reenable once we figure out how to get this properly in user:// - // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277) - //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt"))); - _set_logger(memnew(CompositeLogger(loggers))); -} - bool OSUWP::can_draw() const { return !minimized; @@ -834,7 +825,9 @@ OSUWP::OSUWP() { AudioDriverManager::add_driver(&audio_driver); - _set_logger(memnew(WindowsTerminalLogger)); + Vector<Logger *> loggers; + loggers.push_back(memnew(WindowsTerminalLogger)); + _set_logger(memnew(CompositeLogger(loggers))); } OSUWP::~OSUWP() { diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 3c52fc29a8..8d69cd53fd 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -157,7 +157,6 @@ protected: virtual int get_audio_driver_count() const; virtual const char *get_audio_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 72d51ad62a..c189b3b744 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -201,15 +201,6 @@ void OS_Windows::initialize_core() { cursor_shape = CURSOR_ARROW; } -void OS_Windows::initialize_logger() { - Vector<Logger *> loggers; - loggers.push_back(memnew(WindowsTerminalLogger)); - // FIXME: Reenable once we figure out how to get this properly in user:// - // instead of littering the user's working dirs (res:// + pwd) with log files (GH-12277) - //loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt"))); - _set_logger(memnew(CompositeLogger(loggers))); -} - bool OS_Windows::can_draw() const { return !minimized; @@ -2326,7 +2317,9 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) { AudioDriverManager::add_driver(&driver_xaudio2); #endif - _set_logger(memnew(WindowsTerminalLogger)); + Vector<Logger *> loggers; + loggers.push_back(memnew(WindowsTerminalLogger)); + _set_logger(memnew(CompositeLogger(loggers))); } OS_Windows::~OS_Windows() { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 5e0c240dba..4367297262 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -145,7 +145,6 @@ protected: virtual int get_audio_driver_count() const; virtual const char *get_audio_driver_name(int p_driver) const; - virtual void initialize_logger(); virtual void initialize_core(); virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index b35b2568d1..fbe2593362 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -87,95 +87,90 @@ void AnimationCache::_update_cache() { Ref<Resource> res; - if (np.get_subname_count()) { - - if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) { + if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) { + if (np.get_subname_count() > 1) { path_cache.push_back(Path()); ERR_EXPLAIN("Transform tracks can't have a subpath: " + np); ERR_CONTINUE(animation->track_get_type(i) == Animation::TYPE_TRANSFORM); } - RES res; - - for (int j = 0; j < np.get_subname_count(); j++) { - res = j == 0 ? node->get(np.get_subname(j)) : res->get(np.get_subname(j)); - if (res.is_null()) - break; - } + Spatial *sp = Object::cast_to<Spatial>(node); - if (res.is_null()) { + if (!sp) { path_cache.push_back(Path()); - ERR_EXPLAIN("Invalid Track SubPath in Animation: " + np); - ERR_CONTINUE(res.is_null()); + ERR_EXPLAIN("Transform track not of type Spatial: " + np); + ERR_CONTINUE(!sp); } - path.resource = res; - path.object = res.ptr(); - - } else { - - if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) { - StringName property = np.get_property(); + if (np.get_subname_count() == 1) { + StringName property = np.get_subname(0); String ps = property; - Spatial *sp = Object::cast_to<Spatial>(node); + Skeleton *sk = Object::cast_to<Skeleton>(node); + if (!sk) { - if (!sp) { + path_cache.push_back(Path()); + ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: " + np); + ERR_CONTINUE(!sk); + } + int idx = sk->find_bone(ps); + if (idx == -1) { path_cache.push_back(Path()); - ERR_EXPLAIN("Transform track not of type Spatial: " + np); - ERR_CONTINUE(!sp); + ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: " + np); + ERR_CONTINUE(idx == -1); } - if (ps != "") { + path.bone_idx = idx; + path.skeleton = sk; + } - Skeleton *sk = Object::cast_to<Skeleton>(node); - if (!sk) { + path.spatial = sp; - path_cache.push_back(Path()); - ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: " + np); - ERR_CONTINUE(!sk); - } + } else { + if (np.get_subname_count() > 0) { - int idx = sk->find_bone(ps); - if (idx == -1) { + RES res; + Vector<StringName> leftover_subpath; - path_cache.push_back(Path()); - ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: " + np); - ERR_CONTINUE(idx == -1); - } + // We don't want to cache the last resource unless it is a method call + bool is_method = animation->track_get_type(i) == Animation::TYPE_METHOD; + root->get_node_and_resource(np, res, leftover_subpath, is_method); - path.bone_idx = idx; - path.skeleton = sk; + if (res.is_valid()) { + path.resource = res; + } else { + path.node = node; } + path.object = res.is_valid() ? res.ptr() : (Object *)node; + path.subpath = leftover_subpath; - path.spatial = sp; - } + } else { - path.node = node; - path.object = node; + path.node = node; + path.object = node; + path.subpath = np.get_subnames(); + } } if (animation->track_get_type(i) == Animation::TYPE_VALUE) { - if (np.get_property().operator String() == "") { + if (np.get_subname_count() == 0) { path_cache.push_back(Path()); ERR_EXPLAIN("Value Track lacks property: " + np); - ERR_CONTINUE(np.get_property().operator String() == ""); + ERR_CONTINUE(np.get_subname_count() == 0); } - path.property = np.get_property(); - } else if (animation->track_get_type(i) == Animation::TYPE_METHOD) { - if (np.get_property().operator String() != "") { + if (path.subpath.size() != 0) { // Trying to call a method of a non-resource path_cache.push_back(Path()); ERR_EXPLAIN("Method Track has property: " + np); - ERR_CONTINUE(np.get_property().operator String() != ""); + ERR_CONTINUE(path.subpath.size() != 0); } } @@ -226,7 +221,7 @@ void AnimationCache::set_track_value(int p_idx, const Variant &p_value) { return; ERR_FAIL_COND(!p.object); - p.object->set(p.property, p_value); + p.object->set_indexed(p.subpath, p_value); } void AnimationCache::call_track(int p_idx, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { diff --git a/scene/animation/animation_cache.h b/scene/animation/animation_cache.h index e593668df6..481de59730 100644 --- a/scene/animation/animation_cache.h +++ b/scene/animation/animation_cache.h @@ -46,7 +46,7 @@ class AnimationCache : public Object { Spatial *spatial; int bone_idx; - StringName property; + Vector<StringName> subpath; bool valid; Path() { object = NULL; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 6be3ff88d9..010f5a586f 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -242,7 +242,8 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { p_anim->node_cache[i] = NULL; RES resource; - Node *child = parent->get_node_and_resource(a->track_get_path(i), resource); + Vector<StringName> leftover_path; + Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path); if (!child) { ERR_EXPLAIN("On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'"); } @@ -250,9 +251,9 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id(); int bone_idx = -1; - if (a->track_get_path(i).get_property() && Object::cast_to<Skeleton>(child)) { + if (a->track_get_path(i).get_subname_count() == 1 && Object::cast_to<Skeleton>(child)) { - bone_idx = Object::cast_to<Skeleton>(child)->find_bone(a->track_get_path(i).get_property()); + bone_idx = Object::cast_to<Skeleton>(child)->find_bone(a->track_get_path(i).get_subname(0)); if (bone_idx == -1) { continue; @@ -289,8 +290,8 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton>(child); if (p_anim->node_cache[i]->skeleton) { - StringName bone_name = a->track_get_path(i).get_property(); - if (bone_name.operator String() != "") { + if (a->track_get_path(i).get_subname_count() == 1) { + StringName bone_name = a->track_get_path(i).get_subname(0); p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx < 0) { @@ -311,24 +312,23 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { if (a->track_get_type(i) == Animation::TYPE_VALUE) { - StringName property = a->track_get_path(i).get_property(); - if (!p_anim->node_cache[i]->property_anim.has(property)) { + if (!p_anim->node_cache[i]->property_anim.has(a->track_get_path(i).get_concatenated_subnames())) { TrackNodeCache::PropertyAnim pa; - pa.prop = property; + pa.subpath = leftover_path; pa.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child; pa.special = SP_NONE; pa.owner = p_anim->node_cache[i]; if (false && p_anim->node_cache[i]->node_2d) { - if (pa.prop == SceneStringNames::get_singleton()->transform_pos) + if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos) pa.special = SP_NODE2D_POS; - else if (pa.prop == SceneStringNames::get_singleton()->transform_rot) + else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot) pa.special = SP_NODE2D_ROT; - else if (pa.prop == SceneStringNames::get_singleton()->transform_scale) + else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale) pa.special = SP_NODE2D_SCALE; } - p_anim->node_cache[i]->property_anim[property] = pa; + p_anim->node_cache[i]->property_anim[a->track_get_path(i).get_concatenated_subnames()] = pa; } } } @@ -396,7 +396,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float //StringName property=a->track_get_path(i).get_property(); - Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_property()); + Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_concatenated_subnames()); ERR_CONTINUE(!E); //should it continue, or create a new one? TrackNodeCache::PropertyAnim *pa = &E->get(); @@ -434,7 +434,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float case SP_NONE: { bool valid; - pa->object->set(pa->prop, value, &valid); //you are not speshul + pa->object->set_indexed(pa->subpath, value, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { ERR_PRINTS("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid. Animation '" + a->get_name() + "' at node '" + get_path() + "'."); @@ -622,7 +622,7 @@ void AnimationPlayer::_animation_update_transforms() { case SP_NONE: { bool valid; - pa->object->set(pa->prop, pa->value_accum, &valid); //you are not speshul + pa->object->set_indexed(pa->subpath, pa->value_accum, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { ERR_PRINTS("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property"); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 83da3b2e5c..e4e021c7fe 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -83,7 +83,7 @@ private: TrackNodeCache *owner; SpecialProperty special; //small optimization - StringName prop; + Vector<StringName> subpath; Object *object; Variant value_accum; uint64_t accum_pass; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index ad5329c94b..23eccec82f 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -811,7 +811,7 @@ void AnimationTreePlayer::_process_animation(float p_delta) { t.scale.y = 0; t.scale.z = 0; - t.value = t.object->get(t.property); + t.value = t.object->get_indexed(t.subpath); t.value.zero(); t.skip = false; @@ -890,8 +890,8 @@ void AnimationTreePlayer::_process_animation(float p_delta) { if (t.skip || !t.object) continue; - if (t.property) { // value track - t.object->set(t.property, t.value); + if (t.subpath.size()) { // value track + t.object->set_indexed(t.subpath, t.value); continue; } @@ -1475,7 +1475,8 @@ AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_p ERR_FAIL_COND_V(!parent, NULL); RES resource; - Node *child = parent->get_node_and_resource(p_path, resource); + Vector<StringName> leftover_path; + Node *child = parent->get_node_and_resource(p_path, resource, leftover_path); if (!child) { String err = "Animation track references unknown Node: '" + String(p_path) + "'."; WARN_PRINT(err.ascii().get_data()); @@ -1483,21 +1484,18 @@ AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_p } ObjectID id = child->get_instance_id(); - StringName property; int bone_idx = -1; - if (p_path.get_property()) { + if (p_path.get_subname_count()) { if (Object::cast_to<Skeleton>(child)) - bone_idx = Object::cast_to<Skeleton>(child)->find_bone(p_path.get_property()); - if (bone_idx == -1) - property = p_path.get_property(); + bone_idx = Object::cast_to<Skeleton>(child)->find_bone(p_path.get_subname(0)); } TrackKey key; key.id = id; key.bone_idx = bone_idx; - key.property = property; + key.subpath_concatenated = p_path.get_concatenated_subnames(); if (!track_map.has(key)) { @@ -1507,7 +1505,7 @@ AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_p tr.skeleton = Object::cast_to<Skeleton>(child); tr.spatial = Object::cast_to<Spatial>(child); tr.bone_idx = bone_idx; - tr.property = property; + if (bone_idx == -1) tr.subpath = leftover_path; track_map[key] = tr; } diff --git a/scene/animation/animation_tree_player.h b/scene/animation/animation_tree_player.h index 3e2bb88198..c49b0c4d1b 100644 --- a/scene/animation/animation_tree_player.h +++ b/scene/animation/animation_tree_player.h @@ -78,14 +78,14 @@ private: struct TrackKey { uint32_t id; - StringName property; + StringName subpath_concatenated; int bone_idx; inline bool operator<(const TrackKey &p_right) const { if (id == p_right.id) { if (bone_idx == p_right.bone_idx) { - return property < p_right.property; + return subpath_concatenated < p_right.subpath_concatenated; } else return bone_idx < p_right.bone_idx; } else @@ -99,7 +99,7 @@ private: Spatial *spatial; Skeleton *skeleton; int bone_idx; - StringName property; + Vector<StringName> subpath; Vector3 loc; Quat rot; diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 40d06dc756..151632a0cb 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -264,12 +264,12 @@ Variant &Tween::_get_initial_val(InterpolateData &p_data) { if (p_data.type == TARGETING_PROPERTY) { bool valid = false; - initial_val = object->get(p_data.target_key, &valid); + initial_val = object->get_indexed(p_data.target_key, &valid); ERR_FAIL_COND_V(!valid, p_data.initial_val); } else { Variant::CallError error; - initial_val = object->call(p_data.target_key, NULL, 0, error); + initial_val = object->call(p_data.target_key[0], NULL, 0, error); ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val); } return initial_val; @@ -296,12 +296,12 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) { if (p_data.type == FOLLOW_PROPERTY) { bool valid = false; - final_val = target->get(p_data.target_key, &valid); + final_val = target->get_indexed(p_data.target_key, &valid); ERR_FAIL_COND_V(!valid, p_data.initial_val); } else { Variant::CallError error; - final_val = target->call(p_data.target_key, NULL, 0, error); + final_val = target->call(p_data.target_key[0], NULL, 0, error); ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val); } @@ -462,6 +462,9 @@ Variant Tween::_run_equation(InterpolateData &p_data) { result = r; } break; + default: { + result = initial_val; + } break; }; #undef APPLY_EQUATION @@ -479,7 +482,7 @@ bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { case FOLLOW_PROPERTY: case TARGETING_PROPERTY: { bool valid = false; - object->set(p_data.key, value, &valid); + object->set_indexed(p_data.key, value, &valid); return valid; } @@ -489,9 +492,9 @@ bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { Variant::CallError error; if (value.get_type() != Variant::NIL) { Variant *arg[1] = { &value }; - object->call(p_data.key, (const Variant **)arg, 1, error); + object->call(p_data.key[0], (const Variant **)arg, 1, error); } else { - object->call(p_data.key, NULL, 0, error); + object->call(p_data.key[0], NULL, 0, error); } if (error.error == Variant::CallError::CALL_OK) @@ -548,7 +551,7 @@ void Tween::_tween_process(float p_delta) { continue; else if (prev_delaying) { - emit_signal("tween_started", object, data.key); + emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false)); _apply_tween_value(data, data.initial_val); } @@ -562,7 +565,7 @@ void Tween::_tween_process(float p_delta) { case INTER_PROPERTY: case INTER_METHOD: { Variant result = _run_equation(data); - emit_signal("tween_step", object, data.key, data.elapsed, result); + emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result); _apply_tween_value(data, result); if (data.finish) _apply_tween_value(data, data.final_val); @@ -574,22 +577,22 @@ void Tween::_tween_process(float p_delta) { switch (data.args) { case 0: - object->call_deferred(data.key); + object->call_deferred(data.key[0]); break; case 1: - object->call_deferred(data.key, data.arg[0]); + object->call_deferred(data.key[0], data.arg[0]); break; case 2: - object->call_deferred(data.key, data.arg[0], data.arg[1]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1]); break; case 3: - object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]); break; case 4: - object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]); break; case 5: - object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); break; } } else { @@ -601,17 +604,18 @@ void Tween::_tween_process(float p_delta) { &data.arg[3], &data.arg[4], }; - object->call(data.key, (const Variant **)arg, data.args, error); + object->call(data.key[0], (const Variant **)arg, data.args, error); } } break; + default: {} } if (data.finish) { - emit_signal("tween_completed", object, data.key); + emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false)); // not repeat mode, remove completed action if (!repeat) - call_deferred("_remove", object, data.key, true); + call_deferred("_remove", object, NodePath(Vector<StringName>(), data.key, false), true); } } pending_update--; @@ -690,7 +694,7 @@ bool Tween::start() { return true; } -bool Tween::reset(Object *p_object, String p_key) { +bool Tween::reset(Object *p_object, StringName p_key) { pending_update++; for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { @@ -700,7 +704,7 @@ bool Tween::reset(Object *p_object, String p_key) { if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) { + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { data.elapsed = 0; data.finish = false; @@ -727,7 +731,7 @@ bool Tween::reset_all() { return true; } -bool Tween::stop(Object *p_object, String p_key) { +bool Tween::stop(Object *p_object, StringName p_key) { pending_update++; for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { @@ -736,7 +740,7 @@ bool Tween::stop(Object *p_object, String p_key) { Object *object = ObjectDB::get_instance(data.id); if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) data.active = false; } pending_update--; @@ -758,7 +762,7 @@ bool Tween::stop_all() { return true; } -bool Tween::resume(Object *p_object, String p_key) { +bool Tween::resume(Object *p_object, StringName p_key) { set_active(true); _set_process(true); @@ -770,7 +774,7 @@ bool Tween::resume(Object *p_object, String p_key) { Object *object = ObjectDB::get_instance(data.id); if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) data.active = true; } pending_update--; @@ -792,12 +796,12 @@ bool Tween::resume_all() { return true; } -bool Tween::remove(Object *p_object, String p_key) { +bool Tween::remove(Object *p_object, StringName p_key) { _remove(p_object, p_key, false); return true; } -void Tween::_remove(Object *p_object, String p_key, bool first_only) { +void Tween::_remove(Object *p_object, StringName p_key, bool first_only) { if (pending_update != 0) { call_deferred("_remove", p_object, p_key, first_only); @@ -810,7 +814,7 @@ void Tween::_remove(Object *p_object, String p_key, bool first_only) { Object *object = ObjectDB::get_instance(data.id); if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) { + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { for_removal.push_back(E); if (first_only) { break; @@ -850,8 +854,9 @@ bool Tween::seek(real_t p_time) { data.finish = true; data.elapsed = (data.delay + data.duration); - } else + } else { data.finish = false; + } switch (data.type) { case INTER_PROPERTY: @@ -993,11 +998,15 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final return true; } -bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("interpolate_property", p_object, p_property, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; } + p_property = p_property.get_as_property_path(); + + if (p_initial_val.get_type() == Variant::NIL) p_initial_val = p_object->get_indexed(p_property.get_subnames()); + // convert INT to REAL is better for interpolaters if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); @@ -1011,7 +1020,7 @@ bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_ ERR_FAIL_COND_V(p_delay < 0, false); bool prop_valid = false; - p_object->get(p_property, &prop_valid); + p_object->get_indexed(p_property.get_subnames(), &prop_valid); ERR_FAIL_COND_V(!prop_valid, false); InterpolateData data; @@ -1021,7 +1030,8 @@ bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_ data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_property; + data.key = p_property.get_subnames(); + data.concatenated_key = p_property.get_concatenated_subnames(); data.initial_val = p_initial_val; data.final_val = p_final_val; data.duration = p_duration; @@ -1036,7 +1046,7 @@ bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_ return true; } -bool Tween::interpolate_method(Object *p_object, String p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("interpolate_method", p_object, p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; @@ -1063,7 +1073,8 @@ bool Tween::interpolate_method(Object *p_object, String p_method, Variant p_init data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_method; + data.key.push_back(p_method); + data.concatenated_key = p_method; data.initial_val = p_initial_val; data.final_val = p_final_val; data.duration = p_duration; @@ -1100,7 +1111,8 @@ bool Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_c data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_callback; + data.key.push_back(p_callback); + data.concatenated_key = p_callback; data.duration = p_duration; data.delay = 0; @@ -1152,7 +1164,8 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_callback; + data.key.push_back(p_callback); + data.concatenated_key = p_callback; data.duration = p_duration; data.delay = 0; @@ -1183,11 +1196,16 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S return true; } -bool Tween::follow_property(Object *p_object, String p_property, Variant p_initial_val, Object *p_target, String p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("follow_property", p_object, p_property, p_initial_val, p_target, p_target_property, p_duration, p_trans_type, p_ease_type, p_delay); return true; } + p_property = p_property.get_as_property_path(); + p_target_property = p_target_property.get_as_property_path(); + + if (p_initial_val.get_type() == Variant::NIL) p_initial_val = p_object->get_indexed(p_property.get_subnames()); + // convert INT to REAL is better for interpolaters if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); @@ -1201,11 +1219,11 @@ bool Tween::follow_property(Object *p_object, String p_property, Variant p_initi ERR_FAIL_COND_V(p_delay < 0, false); bool prop_valid = false; - p_object->get(p_property, &prop_valid); + p_object->get_indexed(p_property.get_subnames(), &prop_valid); ERR_FAIL_COND_V(!prop_valid, false); bool target_prop_valid = false; - Variant target_val = p_target->get(p_target_property, &target_prop_valid); + Variant target_val = p_target->get_indexed(p_target_property.get_subnames(), &target_prop_valid); ERR_FAIL_COND_V(!target_prop_valid, false); // convert INT to REAL is better for interpolaters @@ -1219,10 +1237,11 @@ bool Tween::follow_property(Object *p_object, String p_property, Variant p_initi data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_property; + data.key = p_property.get_subnames(); + data.concatenated_key = p_property.get_concatenated_subnames(); data.initial_val = p_initial_val; data.target_id = p_target->get_instance_id(); - data.target_key = p_target_property; + data.target_key = p_target_property.get_subnames(); data.duration = p_duration; data.trans_type = p_trans_type; data.ease_type = p_ease_type; @@ -1232,7 +1251,7 @@ bool Tween::follow_property(Object *p_object, String p_property, Variant p_initi return true; } -bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_val, Object *p_target, String p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("follow_method", p_object, p_method, p_initial_val, p_target, p_target_method, p_duration, p_trans_type, p_ease_type, p_delay); return true; @@ -1269,10 +1288,11 @@ bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_v data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_method; + data.key.push_back(p_method); + data.concatenated_key = p_method; data.initial_val = p_initial_val; data.target_id = p_target->get_instance_id(); - data.target_key = p_target_method; + data.target_key.push_back(p_target_method); data.duration = p_duration; data.trans_type = p_trans_type; data.ease_type = p_ease_type; @@ -1282,11 +1302,15 @@ bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_v return true; } -bool Tween::targeting_property(Object *p_object, String p_property, Object *p_initial, String p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { + if (pending_update != 0) { _add_pending_command("targeting_property", p_object, p_property, p_initial, p_initial_property, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; } + p_property = p_property.get_as_property_path(); + p_initial_property = p_initial_property.get_as_property_path(); + // convert INT to REAL is better for interpolaters if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); @@ -1300,11 +1324,11 @@ bool Tween::targeting_property(Object *p_object, String p_property, Object *p_in ERR_FAIL_COND_V(p_delay < 0, false); bool prop_valid = false; - p_object->get(p_property, &prop_valid); + p_object->get_indexed(p_property.get_subnames(), &prop_valid); ERR_FAIL_COND_V(!prop_valid, false); bool initial_prop_valid = false; - Variant initial_val = p_initial->get(p_initial_property, &initial_prop_valid); + Variant initial_val = p_initial->get_indexed(p_initial_property.get_subnames(), &initial_prop_valid); ERR_FAIL_COND_V(!initial_prop_valid, false); // convert INT to REAL is better for interpolaters @@ -1318,9 +1342,10 @@ bool Tween::targeting_property(Object *p_object, String p_property, Object *p_in data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_property; + data.key = p_property.get_subnames(); + data.concatenated_key = p_property.get_concatenated_subnames(); data.target_id = p_initial->get_instance_id(); - data.target_key = p_initial_property; + data.target_key = p_initial_property.get_subnames(); data.initial_val = initial_val; data.final_val = p_final_val; data.duration = p_duration; @@ -1335,7 +1360,7 @@ bool Tween::targeting_property(Object *p_object, String p_property, Object *p_in return true; } -bool Tween::targeting_method(Object *p_object, String p_method, Object *p_initial, String p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("targeting_method", p_object, p_method, p_initial, p_initial_method, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; @@ -1372,9 +1397,10 @@ bool Tween::targeting_method(Object *p_object, String p_method, Object *p_initia data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_method; + data.key.push_back(p_method); + data.concatenated_key = p_method; data.target_id = p_initial->get_instance_id(); - data.target_key = p_initial_method; + data.target_key.push_back(p_initial_method); data.initial_val = initial_val; data.final_val = p_final_val; data.duration = p_duration; diff --git a/scene/animation/tween.h b/scene/animation/tween.h index fac1d346b4..44710b25f9 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -86,12 +86,13 @@ private: bool call_deferred; real_t elapsed; ObjectID id; - StringName key; + Vector<StringName> key; + StringName concatenated_key; Variant initial_val; Variant delta_val; Variant final_val; ObjectID target_id; - StringName target_key; + Vector<StringName> target_key; real_t duration; TransitionType trans_type; EaseType ease_type; @@ -132,7 +133,7 @@ private: void _tween_process(float p_delta); void _set_process(bool p_process, bool p_force = false); - void _remove(Object *p_object, String p_key, bool first_only); + void _remove(Object *p_object, StringName p_key, bool first_only); protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -156,34 +157,34 @@ public: float get_speed_scale() const; bool start(); - bool reset(Object *p_object, String p_key); + bool reset(Object *p_object, StringName p_key); bool reset_all(); - bool stop(Object *p_object, String p_key); + bool stop(Object *p_object, StringName p_key); bool stop_all(); - bool resume(Object *p_object, String p_key); + bool resume(Object *p_object, StringName p_key); bool resume_all(); - bool remove(Object *p_object, String p_key); + bool remove(Object *p_object, StringName p_key); bool remove_all(); bool seek(real_t p_time); real_t tell() const; real_t get_runtime() const; - bool interpolate_property(Object *p_object, String p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool interpolate_method(Object *p_object, String p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); bool interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE); bool interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE); - bool follow_property(Object *p_object, String p_property, Variant p_initial_val, Object *p_target, String p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool follow_method(Object *p_object, String p_method, Variant p_initial_val, Object *p_target, String p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool targeting_property(Object *p_object, String p_property, Object *p_initial, String p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool targeting_method(Object *p_object, String p_method, Object *p_initial, String p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); Tween(); ~Tween(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 6ade4fcc38..6aba535572 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -323,6 +323,9 @@ void FileDialog::update_file_list() { while ((item = dir_access->get_next(&isdir)) != "") { + if (item == ".") + continue; + ishidden = dir_access->current_is_hidden(); if (show_hidden || !ishidden) { @@ -344,7 +347,7 @@ void FileDialog::update_file_list() { while (!dirs.empty()) { String &dir_name = dirs.front()->get(); TreeItem *ti = tree->create_item(root); - ti->set_text(0, dir_name + "/"); + ti->set_text(0, dir_name); ti->set_icon(0, folder); Dictionary d; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 946a8c47a3..da52fb39e0 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -964,6 +964,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { emit_signal("delete_nodes_request"); accept_event(); } + + Ref<InputEventMagnifyGesture> magnify_gesture = p_ev; + if (magnify_gesture.is_valid()) { + + set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position()); + } + + Ref<InputEventPanGesture> pan_gesture = p_ev; + if (pan_gesture.is_valid()) { + + h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8); + v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8); + } } void GraphEdit::clear_connections() { @@ -975,6 +988,11 @@ void GraphEdit::clear_connections() { void GraphEdit::set_zoom(float p_zoom) { + set_zoom_custom(p_zoom, get_size() / 2); +} + +void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) { + p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM); if (zoom == p_zoom) return; @@ -982,7 +1000,7 @@ void GraphEdit::set_zoom(float p_zoom) { zoom_minus->set_disabled(zoom == MIN_ZOOM); zoom_plus->set_disabled(zoom == MAX_ZOOM); - Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + get_size() / 2) / zoom; + Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + p_center) / zoom; zoom = p_zoom; top_layer->update(); @@ -992,7 +1010,7 @@ void GraphEdit::set_zoom(float p_zoom) { if (is_visible_in_tree()) { - Vector2 ofs = sbofs * zoom - get_size() / 2; + Vector2 ofs = sbofs * zoom - p_center; h_scroll->set_value(ofs.x); v_scroll->set_value(ofs.y); } diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 4656b50133..e8e530848d 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -179,6 +179,7 @@ public: bool is_valid_connection_type(int p_type, int p_with_type) const; void set_zoom(float p_zoom); + void set_zoom_custom(float p_zoom, const Vector2 &p_center); float get_zoom() const; GraphEditFilter *get_top_layer() const { return top_layer; } diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 5e4dedcb48..51ab49e643 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -713,6 +713,12 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { } } } + + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * pan_gesture->get_delta().y / 8); + } } void ItemList::ensure_current_is_visible() { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 71e02cb2f7..124c268c8a 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -817,6 +817,16 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } } + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + if (scroll_active) + + vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8); + + return; + } + Ref<InputEventKey> k = p_event; if (k.is_valid()) { diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 9022d67a4a..a71a1c5f92 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -180,6 +180,17 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) { time_since_motion = 0; } } + + Ref<InputEventPanGesture> pan_gesture = p_gui_input; + if (pan_gesture.is_valid()) { + + if (h_scroll->is_visible_in_tree()) { + h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8); + } + if (v_scroll->is_visible_in_tree()) { + v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8); + } + } } void ScrollContainer::_update_scrollbar_position() { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 21842d4d58..69dc7b21fe 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1777,46 +1777,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mb->is_pressed()) { if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) { - float scroll_factor = 3 * mb->get_factor(); - if (scrolling) { - target_v_scroll = (target_v_scroll - scroll_factor); - } else { - target_v_scroll = (v_scroll->get_value() - scroll_factor); - } - - if (smooth_scroll_enabled) { - if (target_v_scroll <= 0) { - target_v_scroll = 0; - } - scrolling = true; - set_physics_process(true); - } else { - v_scroll->set_value(target_v_scroll); - } + _scroll_up(3 * mb->get_factor()); } if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) { - float scroll_factor = 3 * mb->get_factor(); - if (scrolling) { - target_v_scroll = (target_v_scroll + scroll_factor); - } else { - target_v_scroll = (v_scroll->get_value() + scroll_factor); - } - - if (smooth_scroll_enabled) { - int max_v_scroll = get_total_unhidden_rows(); - if (!scroll_past_end_of_file_enabled) { - max_v_scroll -= get_visible_rows(); - max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); - } - - if (target_v_scroll > max_v_scroll) { - target_v_scroll = max_v_scroll; - } - scrolling = true; - set_physics_process(true); - } else { - v_scroll->set_value(target_v_scroll); - } + _scroll_down(3 * mb->get_factor()); } if (mb->get_button_index() == BUTTON_WHEEL_LEFT) { h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor())); @@ -1973,6 +1937,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } + const Ref<InputEventPanGesture> pan_gesture = p_gui_input; + if (pan_gesture.is_valid()) { + + const real_t delta = pan_gesture->get_delta().y; + if (delta < 0) { + _scroll_up(-delta); + } else { + _scroll_down(delta); + } + h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100); + return; + } + Ref<InputEventMouseMotion> mm = p_gui_input; if (mm.is_valid()) { @@ -3066,6 +3043,50 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } +void TextEdit::_scroll_up(real_t p_delta) { + + if (scrolling) { + target_v_scroll = (target_v_scroll - p_delta); + } else { + target_v_scroll = (v_scroll->get_value() - p_delta); + } + + if (smooth_scroll_enabled) { + if (target_v_scroll <= 0) { + target_v_scroll = 0; + } + scrolling = true; + set_physics_process(true); + } else { + v_scroll->set_value(target_v_scroll); + } +} + +void TextEdit::_scroll_down(real_t p_delta) { + + if (scrolling) { + target_v_scroll = (target_v_scroll + p_delta); + } else { + target_v_scroll = (v_scroll->get_value() + p_delta); + } + + if (smooth_scroll_enabled) { + int max_v_scroll = get_total_unhidden_rows(); + if (!scroll_past_end_of_file_enabled) { + max_v_scroll -= get_visible_rows(); + max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); + } + + if (target_v_scroll > max_v_scroll) { + target_v_scroll = max_v_scroll; + } + scrolling = true; + set_physics_process(true); + } else { + v_scroll->set_value(target_v_scroll); + } +} + void TextEdit::_pre_shift_selection() { if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) { @@ -3467,7 +3488,10 @@ void TextEdit::adjust_viewport_to_cursor() { cursor.x_ofs = cursor_x; update_line_scroll_pos(); - v_scroll->set_value(get_line_scroll_pos() + 1); + if (get_line_scroll_pos() == 0) + v_scroll->set_value(0); + else + v_scroll->set_value(get_line_scroll_pos() + 1); update(); /* get_range()->set_max(text.size()); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index b1c7b14e58..bb9ca87d06 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -328,6 +328,9 @@ class TextEdit : public Control { void _update_selection_mode_word(); void _update_selection_mode_line(); + void _scroll_up(real_t p_delta); + void _scroll_down(real_t p_delta); + void _pre_shift_selection(); void _post_shift_selection(); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 749ff51f57..9213296c55 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2612,6 +2612,12 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } break; } } + + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8); + } } bool Tree::edit_selected() { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 253084dd99..30b831adfc 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2305,7 +2305,7 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { copytarget = target; if (copy && copytarget) { - copy->connect(E->get().signal, copytarget, E->get().method, E->get().binds, CONNECT_PERSIST); + copy->connect(E->get().signal, copytarget, E->get().method, E->get().binds, E->get().flags); } } } @@ -2502,24 +2502,19 @@ bool Node::has_node_and_resource(const NodePath &p_path) const { return false; Node *node = get_node(p_path); - if (p_path.get_subname_count()) { + bool result = false; - RES r; - for (int j = 0; j < p_path.get_subname_count(); j++) { - r = j == 0 ? node->get(p_path.get_subname(j)) : r->get(p_path.get_subname(j)); - if (r.is_null()) - return false; - } - } + node->get_indexed(p_path.get_subnames(), &result); - return true; + return result; } Array Node::_get_node_and_resource(const NodePath &p_path) { Node *node; RES res; - node = get_node_and_resource(p_path, res); + Vector<StringName> leftover_path; + node = get_node_and_resource(p_path, res, leftover_path); Array result; if (node) @@ -2532,21 +2527,35 @@ Array Node::_get_node_and_resource(const NodePath &p_path) { else result.push_back(Variant()); + result.push_back(NodePath(Vector<StringName>(), leftover_path, false)); + return result; } -Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res) const { +Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property) const { Node *node = get_node(p_path); r_res = RES(); + r_leftover_subpath = Vector<StringName>(); if (!node) return NULL; if (p_path.get_subname_count()) { - for (int j = 0; j < p_path.get_subname_count(); j++) { - r_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); - ERR_FAIL_COND_V(r_res.is_null(), node); + int j = 0; + // If not p_last_is_property, we shouldn't consider the last one as part of the resource + for (; j < p_path.get_subname_count() - p_last_is_property; j++) { + RES new_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); + + if (new_res.is_null()) { + break; + } + + r_res = new_res; + } + for (; j < p_path.get_subname_count(); j++) { + // Put the rest of the subpath in the leftover path + r_leftover_subpath.push_back(p_path.get_subname(j)); } } diff --git a/scene/main/node.h b/scene/main/node.h index bd0b18c87a..2b71b71c8d 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -245,7 +245,7 @@ public: Node *get_node(const NodePath &p_path) const; Node *find_node(const String &p_mask, bool p_recursive = true, bool p_owned = true) const; bool has_node_and_resource(const NodePath &p_path) const; - Node *get_node_and_resource(const NodePath &p_path, RES &r_res) const; + Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const; Node *get_parent() const; _FORCE_INLINE_ SceneTree *get_tree() const { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0a02f471c1..1f539041fd 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2013,6 +2013,30 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } } + Ref<InputEventGesture> gesture_event = p_event; + if (gesture_event.is_valid()) { + + Size2 pos = gesture_event->get_position(); + + Control *over = _gui_find_control(pos); + if (over) { + + if (over->can_process()) { + + gesture_event = gesture_event->xformed_by(Transform2D()); //make a copy + if (over == gui.mouse_focus) { + pos = gui.focus_inv_xform.xform(pos); + } else { + pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos); + } + gesture_event->set_position(pos); + _gui_call_input(over, gesture_event); + } + get_tree()->set_input_as_handled(); + return; + } + } + Ref<InputEventScreenDrag> drag_event = p_event; if (drag_event.is_valid()) { diff --git a/servers/server_wrap_mt_common.h b/servers/server_wrap_mt_common.h index 51e7f446ea..0416dc6762 100644 --- a/servers/server_wrap_mt_common.h +++ b/servers/server_wrap_mt_common.h @@ -61,6 +61,7 @@ if (m_type##_id_pool.size() == 0) { \ int ret; \ command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, &ret); \ + SYNC_DEBUG \ } \ rid = m_type##_id_pool.front()->get(); \ m_type##_id_pool.pop_front(); \ @@ -91,6 +92,7 @@ if (m_type##_id_pool.size() == 0) { \ int ret; \ command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, &ret); \ + SYNC_DEBUG \ } \ rid = m_type##_id_pool.front()->get(); \ m_type##_id_pool.pop_front(); \ @@ -121,6 +123,7 @@ if (m_type##_id_pool.size() == 0) { \ int ret; \ command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, &ret); \ + SYNC_DEBUG \ } \ rid = m_type##_id_pool.front()->get(); \ m_type##_id_pool.pop_front(); \ @@ -151,6 +154,7 @@ if (m_type##_id_pool.size() == 0) { \ int ret; \ command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, p3, &ret); \ + SYNC_DEBUG \ } \ rid = m_type##_id_pool.front()->get(); \ m_type##_id_pool.pop_front(); \ @@ -181,6 +185,7 @@ if (m_type##_id_pool.size() == 0) { \ int ret; \ command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, p3, p4, &ret); \ + SYNC_DEBUG \ } \ rid = m_type##_id_pool.front()->get(); \ m_type##_id_pool.pop_front(); \ @@ -211,6 +216,7 @@ if (m_type##_id_pool.size() == 0) { \ int ret; \ command_queue.push_and_ret(this, &ServerNameWrapMT::m_type##allocn, p1, p2, p3, p4, p5, &ret); \ + SYNC_DEBUG \ } \ rid = m_type##_id_pool.front()->get(); \ m_type##_id_pool.pop_front(); \ @@ -255,6 +261,7 @@ virtual void m_type() { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type); \ + SYNC_DEBUG \ } else { \ server_name->m_type(); \ } \ @@ -264,6 +271,7 @@ virtual void m_type() const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type); \ + SYNC_DEBUG \ } else { \ server_name->m_type(); \ } \ @@ -299,6 +307,7 @@ virtual void m_type(m_arg1 p1) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1); \ } \ @@ -308,6 +317,7 @@ virtual void m_type(m_arg1 p1) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1); \ } \ @@ -359,6 +369,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2); \ } \ @@ -368,6 +379,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2); \ } \ @@ -408,6 +420,7 @@ if (Thread::get_caller_id() != server_thread) { \ m_r ret; \ command_queue.push_and_ret(server_name, &ServerName::m_type, p1, p2, p3, &ret); \ + SYNC_DEBUG \ return ret; \ } else { \ return server_name->m_type(p1, p2, p3); \ @@ -418,6 +431,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3); \ } \ @@ -427,6 +441,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3); \ } \ @@ -478,6 +493,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4); \ } \ @@ -487,6 +503,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4); \ } \ @@ -538,6 +555,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5); \ } \ @@ -547,6 +565,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5); \ } \ @@ -587,6 +606,7 @@ if (Thread::get_caller_id() != server_thread) { \ m_r ret; \ command_queue.push_and_ret(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, &ret); \ + SYNC_DEBUG \ return ret; \ } else { \ return server_name->m_type(p1, p2, p3, p4, p5, p6); \ @@ -597,6 +617,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5, p6); \ } \ @@ -606,6 +627,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5, p6); \ } \ @@ -657,6 +679,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5, p6, p7); \ } \ @@ -666,6 +689,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5, p6, p7); \ } \ @@ -717,6 +741,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7, p8); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8); \ } \ @@ -726,6 +751,7 @@ virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8) const { \ if (Thread::get_caller_id() != server_thread) { \ command_queue.push_and_sync(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7, p8); \ + SYNC_DEBUG \ } else { \ server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8); \ } \ diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp index 1a03c72529..a9bfef7ef3 100644 --- a/servers/visual/visual_server_wrap_mt.cpp +++ b/servers/visual/visual_server_wrap_mt.cpp @@ -37,14 +37,7 @@ void VisualServerWrapMT::thread_exit() { void VisualServerWrapMT::thread_draw() { - draw_mutex->lock(); - - draw_pending--; - bool draw = (draw_pending == 0); // only draw when no more flushes are pending - - draw_mutex->unlock(); - - if (draw) { + if (!atomic_decrement(&draw_pending)) { visual_server->draw(); } @@ -52,11 +45,7 @@ void VisualServerWrapMT::thread_draw() { void VisualServerWrapMT::thread_flush() { - draw_mutex->lock(); - - draw_pending--; - - draw_mutex->unlock(); + atomic_decrement(&draw_pending); } void VisualServerWrapMT::_thread_callback(void *_instance) { @@ -92,15 +81,8 @@ void VisualServerWrapMT::sync() { if (create_thread) { - /* TODO: sync with the thread */ - - /* - ERR_FAIL_COND(!draw_mutex); - draw_mutex->lock(); - draw_pending++; //cambiar por un saferefcount - draw_mutex->unlock(); - */ - //command_queue.push( this, &VisualServerWrapMT::thread_flush); + atomic_increment(&draw_pending); + command_queue.push_and_sync(this, &VisualServerWrapMT::thread_flush); } else { command_queue.flush_all(); //flush all pending from other threads @@ -111,14 +93,8 @@ void VisualServerWrapMT::draw() { if (create_thread) { - /* TODO: Make it draw - ERR_FAIL_COND(!draw_mutex); - draw_mutex->lock(); - draw_pending++; //cambiar por un saferefcount - draw_mutex->unlock(); - - command_queue.push( this, &VisualServerWrapMT::thread_draw); - */ + atomic_increment(&draw_pending); + command_queue.push(this, &VisualServerWrapMT::thread_draw); } else { visual_server->draw(); @@ -129,7 +105,6 @@ void VisualServerWrapMT::init() { if (create_thread) { - draw_mutex = Mutex::create(); print_line("CREATING RENDER THREAD"); OS::get_singleton()->release_rendering_thread(); if (create_thread) { @@ -181,9 +156,6 @@ void VisualServerWrapMT::finish() { canvas_item_free_cached_ids(); canvas_light_occluder_free_cached_ids(); canvas_occluder_polygon_free_cached_ids(); - - if (draw_mutex) - memdelete(draw_mutex); } VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread) @@ -192,7 +164,6 @@ VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_ visual_server = p_contained; create_thread = p_create_thread; thread = NULL; - draw_mutex = NULL; draw_pending = 0; draw_thread_up = false; alloc_mutex = Mutex::create(); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index e120eb5ad3..417e8de833 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -52,8 +52,7 @@ class VisualServerWrapMT : public VisualServer { volatile bool draw_thread_up; bool create_thread; - Mutex *draw_mutex; - int draw_pending; + uint64_t draw_pending; void thread_draw(); void thread_flush(); |