From f7b50992b58afae563b6364702065fc2ac716ca4 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sat, 9 May 2020 13:42:50 -0400 Subject: Allow using integer vectors for iteration and make range() use them --- core/variant_op.cpp | 120 +++++++++++++++++++++++++---------- modules/gdscript/gdscript_parser.cpp | 14 ++-- 2 files changed, 95 insertions(+), 39 deletions(-) diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 27624b81ee..43f364cc56 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -78,38 +78,38 @@ #define TYPE(PREFIX, OP, TYPE) &&PREFIX##_##OP##_##TYPE /* clang-format off */ -#define TYPES(PREFIX, OP) { \ - TYPE(PREFIX, OP, NIL), \ - TYPE(PREFIX, OP, BOOL), \ - TYPE(PREFIX, OP, INT), \ - TYPE(PREFIX, OP, FLOAT), \ - TYPE(PREFIX, OP, STRING), \ - TYPE(PREFIX, OP, VECTOR2), \ - TYPE(PREFIX, OP, VECTOR2I), \ - TYPE(PREFIX, OP, RECT2), \ - TYPE(PREFIX, OP, RECT2I), \ - TYPE(PREFIX, OP, VECTOR3), \ - TYPE(PREFIX, OP, VECTOR3I), \ - TYPE(PREFIX, OP, TRANSFORM2D), \ - TYPE(PREFIX, OP, PLANE), \ - TYPE(PREFIX, OP, QUAT), \ - TYPE(PREFIX, OP, AABB), \ - TYPE(PREFIX, OP, BASIS), \ - TYPE(PREFIX, OP, TRANSFORM), \ - TYPE(PREFIX, OP, COLOR), \ +#define TYPES(PREFIX, OP) { \ + TYPE(PREFIX, OP, NIL), \ + TYPE(PREFIX, OP, BOOL), \ + TYPE(PREFIX, OP, INT), \ + TYPE(PREFIX, OP, FLOAT), \ + TYPE(PREFIX, OP, STRING), \ + TYPE(PREFIX, OP, VECTOR2), \ + TYPE(PREFIX, OP, VECTOR2I), \ + TYPE(PREFIX, OP, RECT2), \ + TYPE(PREFIX, OP, RECT2I), \ + TYPE(PREFIX, OP, VECTOR3), \ + TYPE(PREFIX, OP, VECTOR3I), \ + TYPE(PREFIX, OP, TRANSFORM2D), \ + TYPE(PREFIX, OP, PLANE), \ + TYPE(PREFIX, OP, QUAT), \ + TYPE(PREFIX, OP, AABB), \ + TYPE(PREFIX, OP, BASIS), \ + TYPE(PREFIX, OP, TRANSFORM), \ + TYPE(PREFIX, OP, COLOR), \ TYPE(PREFIX, OP, STRING_NAME), \ - TYPE(PREFIX, OP, NODE_PATH), \ - TYPE(PREFIX, OP, _RID), \ - TYPE(PREFIX, OP, OBJECT), \ + TYPE(PREFIX, OP, NODE_PATH), \ + TYPE(PREFIX, OP, _RID), \ + TYPE(PREFIX, OP, OBJECT), \ TYPE(PREFIX, OP, CALLABLE), \ - TYPE(PREFIX, OP, SIGNAL), \ - TYPE(PREFIX, OP, DICTIONARY), \ - TYPE(PREFIX, OP, ARRAY), \ + TYPE(PREFIX, OP, SIGNAL), \ + TYPE(PREFIX, OP, DICTIONARY), \ + TYPE(PREFIX, OP, ARRAY), \ TYPE(PREFIX, OP, PACKED_BYTE_ARRAY), \ - TYPE(PREFIX, OP, PACKED_INT32_ARRAY), \ - TYPE(PREFIX, OP, PACKED_INT64_ARRAY), \ - TYPE(PREFIX, OP, PACKED_FLOAT32_ARRAY), \ - TYPE(PREFIX, OP, PACKED_FLOAT64_ARRAY), \ + TYPE(PREFIX, OP, PACKED_INT32_ARRAY), \ + TYPE(PREFIX, OP, PACKED_INT64_ARRAY), \ + TYPE(PREFIX, OP, PACKED_FLOAT32_ARRAY), \ + TYPE(PREFIX, OP, PACKED_FLOAT64_ARRAY), \ TYPE(PREFIX, OP, PACKED_STRING_ARRAY), \ TYPE(PREFIX, OP, PACKED_VECTOR2_ARRAY), \ TYPE(PREFIX, OP, PACKED_VECTOR3_ARRAY), \ @@ -3465,6 +3465,14 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return from < to; } break; + case VECTOR2I: { + int64_t from = reinterpret_cast(_data._mem)->x; + int64_t to = reinterpret_cast(_data._mem)->y; + + r_iter = from; + + return from < to; + } break; case VECTOR3: { int64_t from = reinterpret_cast(_data._mem)->x; int64_t to = reinterpret_cast(_data._mem)->y; @@ -3476,10 +3484,22 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return false; } else if (from < to) { return step > 0; - } else { - return step < 0; } - //return true; + return step < 0; + } break; + case VECTOR3I: { + int64_t from = reinterpret_cast(_data._mem)->x; + int64_t to = reinterpret_cast(_data._mem)->y; + int64_t step = reinterpret_cast(_data._mem)->z; + + r_iter = from; + + if (from == to) { + return false; + } else if (from < to) { + return step > 0; + } + return step < 0; } break; case OBJECT: { @@ -3651,6 +3671,18 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { r_iter = idx; return true; } break; + case VECTOR2I: { + int64_t to = reinterpret_cast(_data._mem)->y; + + int64_t idx = r_iter; + idx++; + + if (idx >= to) + return false; + + r_iter = idx; + return true; + } break; case VECTOR3: { int64_t to = reinterpret_cast(_data._mem)->y; int64_t step = reinterpret_cast(_data._mem)->z; @@ -3667,6 +3699,22 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { r_iter = idx; return true; } break; + case VECTOR3I: { + int64_t to = reinterpret_cast(_data._mem)->y; + int64_t step = reinterpret_cast(_data._mem)->z; + + int64_t idx = r_iter; + idx += step; + + if (step < 0 && idx <= to) + return false; + + if (step > 0 && idx >= to) + return false; + + r_iter = idx; + return true; + } break; case OBJECT: { if (!_get_obj().obj) { @@ -3844,10 +3892,18 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return r_iter; } break; + case VECTOR2I: { + + return r_iter; + } break; case VECTOR3: { return r_iter; } break; + case VECTOR3I: { + + return r_iter; + } break; case OBJECT: { if (!_get_obj().obj) { diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 17077567c7..d6339c03df 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3171,9 +3171,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { ConstantNode *cn = alloc_node(); switch (args.size()) { - case 1: cn->value = (int)constants[0]; break; - case 2: cn->value = Vector2(constants[0], constants[1]); break; - case 3: cn->value = Vector3(constants[0], constants[1], constants[2]); break; + case 1: cn->value = (int64_t)constants[0]; break; + case 2: cn->value = Vector2i(constants[0], constants[1]); break; + case 3: cn->value = Vector3i(constants[0], constants[1], constants[2]); break; } cn->datatype = _type_from_variant(cn->value); container = cn; @@ -3186,8 +3186,8 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { switch (args.size()) { case 1: tn->vtype = Variant::INT; break; - case 2: tn->vtype = Variant::VECTOR2; break; - case 3: tn->vtype = Variant::VECTOR3; break; + case 2: tn->vtype = Variant::VECTOR2I; break; + case 3: tn->vtype = Variant::VECTOR3I; break; } for (int i = 0; i < args.size(); i++) { @@ -7802,7 +7802,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { ConstantNode *tgt_type = alloc_node(); tgt_type->line = v.line; - tgt_type->value = (int)v.data_type.builtin_type; + tgt_type->value = (int64_t)v.data_type.builtin_type; OperatorNode *convert_call = alloc_node(); convert_call->line = v.line; @@ -8179,7 +8179,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) { ConstantNode *tgt_type = alloc_node(); tgt_type->line = lv->line; - tgt_type->value = (int)lv->datatype.builtin_type; + tgt_type->value = (int64_t)lv->datatype.builtin_type; tgt_type->datatype = _type_from_variant(tgt_type->value); OperatorNode *convert_call = alloc_node(); -- cgit v1.2.3 From 38a0ff2249e50ddc1aebb9ec93bc446ab6b3e70b Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 13 Mar 2020 05:03:40 -0400 Subject: Allow Vector2/Vector3 iterators to have non-integer values --- core/variant_op.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 43f364cc56..8f4062cc69 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -3458,8 +3458,8 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return _data._float > 0.0; } break; case VECTOR2: { - int64_t from = reinterpret_cast(_data._mem)->x; - int64_t to = reinterpret_cast(_data._mem)->y; + double from = reinterpret_cast(_data._mem)->x; + double to = reinterpret_cast(_data._mem)->y; r_iter = from; @@ -3474,9 +3474,9 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return from < to; } break; case VECTOR3: { - int64_t from = reinterpret_cast(_data._mem)->x; - int64_t to = reinterpret_cast(_data._mem)->y; - int64_t step = reinterpret_cast(_data._mem)->z; + double from = reinterpret_cast(_data._mem)->x; + double to = reinterpret_cast(_data._mem)->y; + double step = reinterpret_cast(_data._mem)->z; r_iter = from; @@ -3660,9 +3660,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case VECTOR2: { - int64_t to = reinterpret_cast(_data._mem)->y; + double to = reinterpret_cast(_data._mem)->y; - int64_t idx = r_iter; + double idx = r_iter; idx++; if (idx >= to) @@ -3684,10 +3684,10 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case VECTOR3: { - int64_t to = reinterpret_cast(_data._mem)->y; - int64_t step = reinterpret_cast(_data._mem)->z; + double to = reinterpret_cast(_data._mem)->y; + double step = reinterpret_cast(_data._mem)->z; - int64_t idx = r_iter; + double idx = r_iter; idx += step; if (step < 0 && idx <= to) -- cgit v1.2.3 From cf4482e8c415c2193abc7dfedc67f607fe404409 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sat, 9 May 2020 13:45:00 -0400 Subject: Change get_completion_identifier_is_function to return a bool A minor bugfix --- modules/gdscript/gdscript_parser.cpp | 2 +- modules/gdscript/gdscript_parser.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index d6339c03df..c7de45c7fb 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -8784,7 +8784,7 @@ int GDScriptParser::get_completion_argument_index() { return completion_argument; } -int GDScriptParser::get_completion_identifier_is_function() { +bool GDScriptParser::get_completion_identifier_is_function() { return completion_ident_is_call; } diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index f254352423..3b9d772032 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -683,7 +683,7 @@ public: BlockNode *get_completion_block(); FunctionNode *get_completion_function(); int get_completion_argument_index(); - int get_completion_identifier_is_function(); + bool get_completion_identifier_is_function(); const List &get_dependencies() const { return dependencies; } -- cgit v1.2.3