2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* variant_op.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "variant.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/core_string_names.h"
|
2020-02-27 02:30:20 +00:00
|
|
|
#include "core/debugger/engine_debugger.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/object.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define CASE_TYPE_ALL(PREFIX, OP) \
|
|
|
|
CASE_TYPE(PREFIX, OP, INT) \
|
|
|
|
CASE_TYPE_ALL_BUT_INT(PREFIX, OP)
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
#define CASE_TYPE_ALL_BUT_INT(PREFIX, OP) \
|
|
|
|
CASE_TYPE(PREFIX, OP, NIL) \
|
|
|
|
CASE_TYPE(PREFIX, OP, BOOL) \
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, FLOAT) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, STRING) \
|
|
|
|
CASE_TYPE(PREFIX, OP, VECTOR2) \
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, VECTOR2I) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, RECT2) \
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, RECT2I) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, VECTOR3) \
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, VECTOR3I) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, TRANSFORM2D) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PLANE) \
|
|
|
|
CASE_TYPE(PREFIX, OP, QUAT) \
|
|
|
|
CASE_TYPE(PREFIX, OP, AABB) \
|
|
|
|
CASE_TYPE(PREFIX, OP, BASIS) \
|
|
|
|
CASE_TYPE(PREFIX, OP, TRANSFORM) \
|
|
|
|
CASE_TYPE(PREFIX, OP, COLOR) \
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, STRING_NAME) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, NODE_PATH) \
|
|
|
|
CASE_TYPE(PREFIX, OP, _RID) \
|
|
|
|
CASE_TYPE(PREFIX, OP, OBJECT) \
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, CALLABLE) \
|
|
|
|
CASE_TYPE(PREFIX, OP, SIGNAL) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, DICTIONARY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_BYTE_ARRAY) \
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_INT32_ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_INT64_ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_FLOAT32_ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_FLOAT64_ARRAY) \
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_STRING_ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_VECTOR2_ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_VECTOR3_ARRAY) \
|
|
|
|
CASE_TYPE(PREFIX, OP, PACKED_COLOR_ARRAY)
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define TYPE(PREFIX, OP, TYPE) &&PREFIX##_##OP##_##TYPE
|
|
|
|
|
|
|
|
/* clang-format off */
|
2020-05-09 17:42:50 +00:00
|
|
|
#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), \
|
2020-02-20 21:58:05 +00:00
|
|
|
TYPE(PREFIX, OP, STRING_NAME), \
|
2020-05-09 17:42:50 +00:00
|
|
|
TYPE(PREFIX, OP, NODE_PATH), \
|
|
|
|
TYPE(PREFIX, OP, _RID), \
|
|
|
|
TYPE(PREFIX, OP, OBJECT), \
|
2020-02-19 19:27:19 +00:00
|
|
|
TYPE(PREFIX, OP, CALLABLE), \
|
2020-05-09 17:42:50 +00:00
|
|
|
TYPE(PREFIX, OP, SIGNAL), \
|
|
|
|
TYPE(PREFIX, OP, DICTIONARY), \
|
|
|
|
TYPE(PREFIX, OP, ARRAY), \
|
2020-02-17 21:06:54 +00:00
|
|
|
TYPE(PREFIX, OP, PACKED_BYTE_ARRAY), \
|
2020-05-09 17:42:50 +00:00
|
|
|
TYPE(PREFIX, OP, PACKED_INT32_ARRAY), \
|
|
|
|
TYPE(PREFIX, OP, PACKED_INT64_ARRAY), \
|
|
|
|
TYPE(PREFIX, OP, PACKED_FLOAT32_ARRAY), \
|
|
|
|
TYPE(PREFIX, OP, PACKED_FLOAT64_ARRAY), \
|
2020-02-17 21:06:54 +00:00
|
|
|
TYPE(PREFIX, OP, PACKED_STRING_ARRAY), \
|
|
|
|
TYPE(PREFIX, OP, PACKED_VECTOR2_ARRAY), \
|
|
|
|
TYPE(PREFIX, OP, PACKED_VECTOR3_ARRAY), \
|
|
|
|
TYPE(PREFIX, OP, PACKED_COLOR_ARRAY), \
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
/* clang-format on */
|
|
|
|
|
2020-09-01 06:59:14 +00:00
|
|
|
#define CASES(PREFIX) static const void *switch_table_##PREFIX[Variant::OP_MAX][Variant::VARIANT_MAX] = { \
|
|
|
|
TYPES(PREFIX, OP_EQUAL), \
|
|
|
|
TYPES(PREFIX, OP_NOT_EQUAL), \
|
|
|
|
TYPES(PREFIX, OP_LESS), \
|
|
|
|
TYPES(PREFIX, OP_LESS_EQUAL), \
|
|
|
|
TYPES(PREFIX, OP_GREATER), \
|
|
|
|
TYPES(PREFIX, OP_GREATER_EQUAL), \
|
|
|
|
TYPES(PREFIX, OP_ADD), \
|
|
|
|
TYPES(PREFIX, OP_SUBTRACT), \
|
|
|
|
TYPES(PREFIX, OP_MULTIPLY), \
|
|
|
|
TYPES(PREFIX, OP_DIVIDE), \
|
|
|
|
TYPES(PREFIX, OP_NEGATE), \
|
|
|
|
TYPES(PREFIX, OP_POSITIVE), \
|
|
|
|
TYPES(PREFIX, OP_MODULE), \
|
|
|
|
TYPES(PREFIX, OP_STRING_CONCAT), \
|
|
|
|
TYPES(PREFIX, OP_SHIFT_LEFT), \
|
|
|
|
TYPES(PREFIX, OP_SHIFT_RIGHT), \
|
|
|
|
TYPES(PREFIX, OP_BIT_AND), \
|
|
|
|
TYPES(PREFIX, OP_BIT_OR), \
|
|
|
|
TYPES(PREFIX, OP_BIT_XOR), \
|
|
|
|
TYPES(PREFIX, OP_BIT_NEGATE), \
|
|
|
|
TYPES(PREFIX, OP_AND), \
|
|
|
|
TYPES(PREFIX, OP_OR), \
|
|
|
|
TYPES(PREFIX, OP_XOR), \
|
|
|
|
TYPES(PREFIX, OP_NOT), \
|
|
|
|
TYPES(PREFIX, OP_IN), \
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SWITCH(PREFIX, op, val) goto *switch_table_##PREFIX[op][val];
|
|
|
|
#define SWITCH_OP(PREFIX, OP, val)
|
|
|
|
#define CASE_TYPE(PREFIX, OP, TYPE) PREFIX##_##OP##_##TYPE:
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define CASES(PREFIX)
|
|
|
|
#define SWITCH(PREFIX, op, val) switch (op)
|
|
|
|
#define SWITCH_OP(PREFIX, OP, val) \
|
|
|
|
case OP: \
|
|
|
|
switch (val)
|
|
|
|
#define CASE_TYPE(PREFIX, OP, TYPE) case TYPE:
|
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant::operator bool() const {
|
2017-09-18 18:02:47 +00:00
|
|
|
return booleanize();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-21 16:30:55 +00:00
|
|
|
// We consider all uninitialized or empty types to be false based on the type's
|
2017-09-18 18:02:47 +00:00
|
|
|
// zeroiness.
|
|
|
|
bool Variant::booleanize() const {
|
|
|
|
return !is_zero();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#define _RETURN(m_what) \
|
|
|
|
{ \
|
|
|
|
r_ret = m_what; \
|
|
|
|
return; \
|
|
|
|
}
|
2017-02-14 20:05:16 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define _RETURN_FAIL \
|
|
|
|
{ \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == INT) \
|
|
|
|
_RETURN(p_a._data.m_type m_op p_b._data._int); \
|
|
|
|
if (p_b.type == FLOAT) \
|
|
|
|
_RETURN(p_a._data.m_type m_op p_b._data._float); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-20 09:32:47 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_NUM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == INT) \
|
|
|
|
_RETURN(p_a._data.m_type m_op p_b._data._int); \
|
|
|
|
if (p_b.type == FLOAT) \
|
|
|
|
_RETURN(p_a._data.m_type m_op p_b._data._float); \
|
|
|
|
if (p_b.type == NIL) \
|
|
|
|
_RETURN(!(p_b.type m_op NIL)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type == INT) { \
|
|
|
|
if (p_b._data._int == 0) { \
|
|
|
|
r_valid = false; \
|
|
|
|
_RETURN("Division By Zero"); \
|
2017-09-17 00:32:05 +00:00
|
|
|
} \
|
2017-09-20 09:32:47 +00:00
|
|
|
_RETURN(p_a._data.m_type / p_b._data._int); \
|
|
|
|
} \
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_b.type == FLOAT) { \
|
|
|
|
if (p_b._data._float == 0) { \
|
2017-09-20 09:32:47 +00:00
|
|
|
r_valid = false; \
|
|
|
|
_RETURN("Division By Zero"); \
|
2017-09-17 00:32:05 +00:00
|
|
|
} \
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
_RETURN(p_a._data.m_type / p_b._data._float); \
|
2017-09-17 00:32:05 +00:00
|
|
|
} \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
#else
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == INT) \
|
|
|
|
_RETURN(p_a._data.m_type / p_b._data._int); \
|
|
|
|
if (p_b.type == FLOAT) \
|
|
|
|
_RETURN(p_a._data.m_type / p_b._data._float); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DEFAULT_OP_NUM_NEG(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
_RETURN(-p_a._data.m_type); \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define DEFAULT_OP_NUM_POS(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
_RETURN(p_a._data.m_type); \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-09-12 20:16:25 +00:00
|
|
|
#define DEFAULT_OP_NUM_VEC(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == INT) \
|
|
|
|
_RETURN(p_a._data.m_type m_op p_b._data._int); \
|
|
|
|
if (p_b.type == FLOAT) \
|
|
|
|
_RETURN(p_a._data.m_type m_op p_b._data._float); \
|
|
|
|
if (p_b.type == VECTOR2) \
|
|
|
|
_RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == VECTOR3) \
|
|
|
|
_RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == VECTOR2I) \
|
|
|
|
_RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2i *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == VECTOR3I) \
|
|
|
|
_RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3i *>(p_b._data._mem)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-20 09:32:47 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_STR_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == STRING) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const String *>(p_a._data._mem)); \
|
|
|
|
if (p_b.type == STRING_NAME) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const StringName *>(p_a._data._mem)); \
|
|
|
|
if (p_b.type == NODE_PATH) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const NodePath *>(p_a._data._mem)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_STR(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == STRING) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == STRING_NAME) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const StringName *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NODE_PATH) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2020-02-20 21:58:05 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_STR_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == STRING) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == STRING_NAME) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const StringName *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NODE_PATH) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NIL) \
|
|
|
|
_RETURN(!(p_b.type m_op NIL)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_STR_NULL_NP(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == STRING) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NODE_PATH) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NIL) \
|
|
|
|
_RETURN(!(p_b.type m_op NIL)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_STR_NULL_SN(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == STRING) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == STRING_NAME) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const StringName *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NIL) \
|
|
|
|
_RETURN(!(p_b.type m_op NIL)); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2020-02-20 21:58:05 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define DEFAULT_OP_LOCALMEM_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const m_type *>(p_a._data._mem)); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define DEFAULT_OP_LOCALMEM(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-20 09:32:47 +00:00
|
|
|
|
|
|
|
#define DEFAULT_OP_LOCALMEM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == NIL) \
|
2018-03-09 19:19:25 +00:00
|
|
|
_RETURN(!(p_b.type m_op NIL)); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2020-05-19 13:46:49 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
#define DEFAULT_OP_LOCALMEM_NEG(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(-*reinterpret_cast<const m_type *>(p_a._data._mem)); \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define DEFAULT_OP_LOCALMEM_POS(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem)); \
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-10 10:56:01 +00:00
|
|
|
#define DEFAULT_OP_LOCALMEM_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
|
|
|
|
if (p_b.type == INT) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._int); \
|
|
|
|
if (p_b.type == FLOAT) \
|
|
|
|
_RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._float); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-20 09:32:47 +00:00
|
|
|
#define DEFAULT_OP_PTR(m_op, m_name, m_sub) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(p_a._data.m_sub m_op p_b._data.m_sub); \
|
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define DEFAULT_OP_PTRREF(m_prefix, m_op_name, m_name, m_op, m_sub) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-20 09:32:47 +00:00
|
|
|
#define DEFAULT_OP_PTRREF_NULL(m_prefix, m_op_name, m_name, m_op, m_sub) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == m_name) \
|
|
|
|
_RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
|
|
|
|
if (p_b.type == NIL) \
|
2018-03-09 19:19:25 +00:00
|
|
|
_RETURN(!(p_b.type m_op NIL)); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
_RETURN_FAIL \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFAULT_OP_ARRAY_EQ(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == NIL) \
|
|
|
|
_RETURN(false) \
|
|
|
|
DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, !=, !=, true, false, false) \
|
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
|
2017-09-21 20:07:31 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_NEQ(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_b.type == NIL) \
|
|
|
|
_RETURN(true) \
|
2018-01-06 02:58:04 +00:00
|
|
|
DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, !=, !=, false, true, true) \
|
2017-09-21 20:07:31 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_LT(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, <, !=, false, a_len < array_b.size(), true)
|
|
|
|
|
|
|
|
#define DEFAULT_OP_ARRAY_GT(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, >, !=, false, a_len < array_b.size(), true)
|
|
|
|
|
2017-09-20 09:32:47 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
|
|
|
|
if (p_a.type != p_b.type) \
|
|
|
|
_RETURN_FAIL \
|
|
|
|
\
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<m_type> &array_a = PackedArrayRef<m_type>::get_array(p_a._data.packed_array); \
|
|
|
|
const Vector<m_type> &array_b = PackedArrayRef<m_type>::get_array(p_b._data.packed_array); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
int a_len = array_a.size(); \
|
|
|
|
if (a_len m_opa array_b.size()) { \
|
|
|
|
_RETURN(m_ret_s); \
|
|
|
|
} else { \
|
2020-02-17 21:06:54 +00:00
|
|
|
const m_type *ra = array_a.ptr(); \
|
|
|
|
const m_type *rb = array_b.ptr(); \
|
2017-09-20 09:32:47 +00:00
|
|
|
\
|
|
|
|
for (int i = 0; i < a_len; i++) { \
|
|
|
|
if (ra[i] m_opb rb[i]) \
|
|
|
|
_RETURN(m_ret_f); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
_RETURN(m_ret_def); \
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_ADD(m_prefix, m_op_name, m_name, m_type) \
|
|
|
|
CASE_TYPE(m_prefix, m_op_name, m_name) { \
|
|
|
|
if (p_a.type != p_b.type) \
|
|
|
|
_RETURN_FAIL; \
|
|
|
|
\
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<m_type> &array_a = PackedArrayRef<m_type>::get_array(p_a._data.packed_array); \
|
|
|
|
const Vector<m_type> &array_b = PackedArrayRef<m_type>::get_array(p_b._data.packed_array); \
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<m_type> sum = array_a; \
|
|
|
|
sum.append_array(array_b); \
|
|
|
|
_RETURN(sum); \
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
void Variant::evaluate(const Operator &p_op, const Variant &p_a,
|
|
|
|
const Variant &p_b, Variant &r_ret, bool &r_valid) {
|
|
|
|
CASES(math);
|
2017-03-05 15:44:50 +00:00
|
|
|
r_valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH(math, p_op, p_a.type) {
|
|
|
|
SWITCH_OP(math, OP_EQUAL, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_EQUAL, NIL) {
|
2020-05-10 10:56:01 +00:00
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(true);
|
2017-09-17 00:32:05 +00:00
|
|
|
if (p_b.type == OBJECT)
|
2020-04-01 23:20:12 +00:00
|
|
|
_RETURN(p_b._get_obj().obj == nullptr);
|
2017-09-20 09:32:47 +00:00
|
|
|
|
|
|
|
_RETURN(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_EQUAL, BOOL) {
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type != BOOL) {
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(false);
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-20 09:32:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(p_a._data._bool == p_b._data._bool);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_EQUAL, OBJECT) {
|
|
|
|
if (p_b.type == OBJECT)
|
|
|
|
_RETURN((p_a._get_obj().obj == p_b._get_obj().obj));
|
|
|
|
if (p_b.type == NIL)
|
2020-04-01 23:20:12 +00:00
|
|
|
_RETURN(p_a._get_obj().obj == nullptr);
|
2017-09-20 09:32:47 +00:00
|
|
|
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, CALLABLE, ==, Callable);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, SIGNAL, ==, Signal);
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_EQUAL, DICTIONARY) {
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type != DICTIONARY) {
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(false);
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-20 09:32:47 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
|
|
|
|
const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(*arr_a == *arr_b);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_EQUAL, ARRAY) {
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type != ARRAY) {
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(false);
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-20 09:32:47 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
int l = arr_a->size();
|
|
|
|
if (arr_b->size() != l)
|
|
|
|
_RETURN(false);
|
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (!((*arr_a)[i] == (*arr_b)[i])) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(false);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(true);
|
|
|
|
}
|
|
|
|
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_NUM_NULL(math, OP_EQUAL, INT, ==, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM_NULL(math, OP_EQUAL, FLOAT, ==, _float);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_STR_NULL(math, OP_EQUAL, STRING, ==, String);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR2, ==, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR2I, ==, Vector2i);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, RECT2, ==, Rect2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, RECT2I, ==, Rect2i);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM2D, ==, _transform2d);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR3, ==, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR3I, ==, Vector3i);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, PLANE, ==, Plane);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, QUAT, ==, Quat);
|
2017-11-17 02:09:00 +00:00
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, AABB, ==, _aabb);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, BASIS, ==, _basis);
|
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM, ==, _transform);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, COLOR, ==, Color);
|
2020-02-20 21:58:05 +00:00
|
|
|
DEFAULT_OP_STR_NULL_SN(math, OP_EQUAL, STRING_NAME, ==, StringName);
|
|
|
|
DEFAULT_OP_STR_NULL_NP(math, OP_EQUAL, NODE_PATH, ==, NodePath);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, _RID, ==, RID);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_BYTE_ARRAY, uint8_t);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_INT32_ARRAY, int32_t);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_INT64_ARRAY, int64_t);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_FLOAT32_ARRAY, float);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_FLOAT64_ARRAY, double);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_VECTOR2_ARRAY, Vector2);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_COLOR_ARRAY, Color);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_NOT_EQUAL, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_NOT_EQUAL, NIL) {
|
2020-05-10 10:56:01 +00:00
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(false);
|
2017-09-17 00:32:05 +00:00
|
|
|
if (p_b.type == OBJECT)
|
2020-04-01 23:20:12 +00:00
|
|
|
_RETURN(p_b._get_obj().obj != nullptr);
|
2017-09-20 09:32:47 +00:00
|
|
|
|
|
|
|
_RETURN(true);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NOT_EQUAL, BOOL) {
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type != BOOL) {
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(true);
|
|
|
|
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-20 09:32:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(p_a._data._bool != p_b._data._bool);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NOT_EQUAL, OBJECT) {
|
|
|
|
if (p_b.type == OBJECT)
|
|
|
|
_RETURN((p_a._get_obj().obj != p_b._get_obj().obj));
|
|
|
|
if (p_b.type == NIL)
|
2020-04-01 23:20:12 +00:00
|
|
|
_RETURN(p_a._get_obj().obj != nullptr);
|
2017-09-20 09:32:47 +00:00
|
|
|
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, CALLABLE, !=, Callable);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, SIGNAL, !=, Signal);
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NOT_EQUAL, DICTIONARY) {
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type != DICTIONARY) {
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(true);
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-20 09:32:47 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
|
|
|
|
const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
|
|
|
|
|
2018-10-06 20:20:41 +00:00
|
|
|
_RETURN(*arr_a != *arr_b);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_NOT_EQUAL, ARRAY) {
|
2017-09-20 09:32:47 +00:00
|
|
|
if (p_b.type != ARRAY) {
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(true);
|
|
|
|
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-20 09:32:47 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
int l = arr_a->size();
|
|
|
|
if (arr_b->size() != l)
|
|
|
|
_RETURN(true);
|
|
|
|
for (int i = 0; i < l; i++) {
|
2018-01-06 02:58:04 +00:00
|
|
|
if (((*arr_a)[i] != (*arr_b)[i])) {
|
|
|
|
_RETURN(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-01-06 02:58:04 +00:00
|
|
|
_RETURN(false);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, INT, !=, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, FLOAT, !=, _float);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, STRING, !=, String);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR2, !=, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR2I, !=, Vector2i);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, RECT2, !=, Rect2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, RECT2I, !=, Rect2i);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM2D, !=, _transform2d);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR3, !=, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR3I, !=, Vector3i);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, PLANE, !=, Plane);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, QUAT, !=, Quat);
|
2017-11-17 02:09:00 +00:00
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, AABB, !=, _aabb);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, BASIS, !=, _basis);
|
|
|
|
DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM, !=, _transform);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, COLOR, !=, Color);
|
2020-02-20 21:58:05 +00:00
|
|
|
DEFAULT_OP_STR_NULL_SN(math, OP_NOT_EQUAL, STRING_NAME, !=, StringName);
|
|
|
|
DEFAULT_OP_STR_NULL_NP(math, OP_NOT_EQUAL, NODE_PATH, !=, NodePath);
|
2017-09-20 09:32:47 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, _RID, !=, RID);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_BYTE_ARRAY, uint8_t);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_INT32_ARRAY, int32_t);
|
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_INT64_ARRAY, int64_t);
|
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_FLOAT32_ARRAY, float);
|
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_FLOAT64_ARRAY, double);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_VECTOR2_ARRAY, Vector2);
|
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_COLOR_ARRAY, Color);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_LESS, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_LESS, BOOL) {
|
|
|
|
if (p_b.type != BOOL)
|
|
|
|
_RETURN_FAIL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
if (p_a._data._bool == p_b._data._bool)
|
|
|
|
_RETURN(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
if (p_a._data._bool && !p_b._data._bool)
|
|
|
|
_RETURN(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-05-01 00:53:41 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, OBJECT) {
|
2017-09-18 11:09:06 +00:00
|
|
|
if (p_b.type != OBJECT)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
_RETURN((p_a._get_obj().obj < p_b._get_obj().obj));
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2015-05-01 00:53:41 +00:00
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_LESS, CALLABLE, <, Callable);
|
|
|
|
DEFAULT_OP_LOCALMEM_NULL(math, OP_LESS, SIGNAL, <, Signal);
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, ARRAY) {
|
|
|
|
if (p_b.type != ARRAY)
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
|
2015-05-01 00:53:41 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
int l = arr_a->size();
|
|
|
|
if (arr_b->size() < l)
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(false);
|
2017-09-17 00:32:05 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (!((*arr_a)[i] < (*arr_b)[i])) {
|
|
|
|
_RETURN(true);
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 00:53:41 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(false);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_LESS, INT, <, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_LESS, FLOAT, <, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_STR(math, OP_LESS, STRING, <, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR2, <, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR2I, <, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR3, <, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR3I, <, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS, _RID, <, RID);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_BYTE_ARRAY, uint8_t);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_INT32_ARRAY, int32_t);
|
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_INT64_ARRAY, int64_t);
|
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_FLOAT32_ARRAY, float);
|
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_FLOAT64_ARRAY, double);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_VECTOR2_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_COLOR_ARRAY, Color);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
CASE_TYPE(math, OP_LESS, NIL)
|
|
|
|
CASE_TYPE(math, OP_LESS, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_LESS, PLANE)
|
|
|
|
CASE_TYPE(math, OP_LESS, QUAT)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, BASIS)
|
|
|
|
CASE_TYPE(math, OP_LESS, TRANSFORM)
|
|
|
|
CASE_TYPE(math, OP_LESS, COLOR)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_LESS, DICTIONARY)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_OP(math, OP_LESS_EQUAL, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, OBJECT) {
|
2017-09-18 11:09:06 +00:00
|
|
|
if (p_b.type != OBJECT)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
_RETURN((p_a._get_obj().obj <= p_b._get_obj().obj));
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_OP_NUM(math, OP_LESS_EQUAL, INT, <=, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_LESS_EQUAL, FLOAT, <=, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_STR(math, OP_LESS_EQUAL, STRING, <=, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR2, <=, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR2I, <=, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR3, <=, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR3I, <=, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, _RID, <=, RID);
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, NIL)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, BOOL)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PLANE)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, QUAT)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, BASIS)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, TRANSFORM)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, COLOR)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, NODE_PATH)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_BYTE_ARRAY);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_INT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_INT64_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_FLOAT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_FLOAT64_ARRAY);
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_STRING_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_VECTOR2_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_VECTOR3_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_LESS_EQUAL, PACKED_COLOR_ARRAY);
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_GREATER, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_GREATER, BOOL) {
|
|
|
|
if (p_b.type != BOOL)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
|
|
|
|
if (p_a._data._bool == p_b._data._bool)
|
|
|
|
_RETURN(false);
|
|
|
|
|
|
|
|
if (!p_a._data._bool && p_b._data._bool)
|
|
|
|
_RETURN(false);
|
|
|
|
|
|
|
|
_RETURN(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, OBJECT) {
|
2017-09-18 11:09:06 +00:00
|
|
|
if (p_b.type != OBJECT)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
_RETURN((p_a._get_obj().obj > p_b._get_obj().obj));
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, ARRAY) {
|
|
|
|
if (p_b.type != ARRAY)
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
int l = arr_a->size();
|
|
|
|
if (arr_b->size() > l)
|
|
|
|
_RETURN(false);
|
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (((*arr_a)[i] < (*arr_b)[i])) {
|
|
|
|
_RETURN(false);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_OP_NUM(math, OP_GREATER, INT, >, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_GREATER, FLOAT, >, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_STR_REV(math, OP_GREATER, STRING, <, String);
|
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR2, <, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR2I, <, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR3, <, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR3I, <, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, _RID, <, RID);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_BYTE_ARRAY, uint8_t);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_INT32_ARRAY, int32_t);
|
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_INT64_ARRAY, int64_t);
|
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_FLOAT32_ARRAY, float);
|
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_FLOAT64_ARRAY, double);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_VECTOR2_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_COLOR_ARRAY, Color);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
CASE_TYPE(math, OP_GREATER, NIL)
|
|
|
|
CASE_TYPE(math, OP_GREATER, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_GREATER, PLANE)
|
|
|
|
CASE_TYPE(math, OP_GREATER, QUAT)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, BASIS)
|
|
|
|
CASE_TYPE(math, OP_GREATER, TRANSFORM)
|
|
|
|
CASE_TYPE(math, OP_GREATER, COLOR)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_GREATER, DICTIONARY)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_GREATER, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_GREATER_EQUAL, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, OBJECT) {
|
2017-09-18 11:09:06 +00:00
|
|
|
if (p_b.type != OBJECT)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
_RETURN((p_a._get_obj().obj >= p_b._get_obj().obj));
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, INT, >=, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, FLOAT, >=, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_STR_REV(math, OP_GREATER_EQUAL, STRING, <=, String);
|
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR2, <=, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR2I, <=, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR3, <=, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR3I, <=, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, _RID, <=, RID);
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, NIL)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, BOOL)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PLANE)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, QUAT)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, BASIS)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, TRANSFORM)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, COLOR)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, NODE_PATH)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_BYTE_ARRAY);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_INT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_INT64_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_FLOAT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_FLOAT64_ARRAY);
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_STRING_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_VECTOR2_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_VECTOR3_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_COLOR_ARRAY);
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-21 02:01:44 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_ADD, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_ADD, ARRAY) {
|
2017-09-18 11:09:06 +00:00
|
|
|
if (p_a.type != p_b.type)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
const Array &array_a = *reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array &array_b = *reinterpret_cast<const Array *>(p_b._data._mem);
|
|
|
|
Array sum;
|
|
|
|
int asize = array_a.size();
|
|
|
|
int bsize = array_b.size();
|
|
|
|
sum.resize(asize + bsize);
|
2020-05-14 14:41:43 +00:00
|
|
|
for (int i = 0; i < asize; i++) {
|
2017-09-17 00:32:05 +00:00
|
|
|
sum[i] = array_a[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < bsize; i++) {
|
2017-09-17 00:32:05 +00:00
|
|
|
sum[i + asize] = array_b[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_OP_NUM(math, OP_ADD, INT, +, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_ADD, FLOAT, +, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_STR(math, OP_ADD, STRING, +, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR2, +, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR2I, +, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR3, +, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR3I, +, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_ADD, QUAT, +, Quat);
|
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_ADD, COLOR, +, Color);
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_BYTE_ARRAY, uint8_t);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_INT32_ARRAY, int32_t);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_INT64_ARRAY, int64_t);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_FLOAT32_ARRAY, float);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_FLOAT64_ARRAY, double);
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_VECTOR2_ARRAY, Vector2);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_COLOR_ARRAY, Color);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
CASE_TYPE(math, OP_ADD, NIL)
|
|
|
|
CASE_TYPE(math, OP_ADD, BOOL)
|
|
|
|
CASE_TYPE(math, OP_ADD, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_ADD, PLANE)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, BASIS)
|
|
|
|
CASE_TYPE(math, OP_ADD, TRANSFORM)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_ADD, _RID)
|
|
|
|
CASE_TYPE(math, OP_ADD, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_ADD, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_ADD, DICTIONARY)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_SUBTRACT, p_a.type) {
|
|
|
|
DEFAULT_OP_NUM(math, OP_SUBTRACT, INT, -, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM(math, OP_SUBTRACT, FLOAT, -, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR2, -, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR2I, -, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR3, -, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR3I, -, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, QUAT, -, Quat);
|
|
|
|
DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, COLOR, -, Color);
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, NIL)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, BOOL)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, STRING)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PLANE)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, BASIS)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, TRANSFORM)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, _RID)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_BYTE_ARRAY);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_INT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_INT64_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_FLOAT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_FLOAT64_ARRAY);
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_STRING_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_VECTOR2_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_VECTOR3_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_SUBTRACT, PACKED_COLOR_ARRAY);
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_MULTIPLY, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, TRANSFORM2D) {
|
2017-09-18 11:09:06 +00:00
|
|
|
switch (p_b.type) {
|
|
|
|
case TRANSFORM2D: {
|
|
|
|
_RETURN(*p_a._data._transform2d * *p_b._data._transform2d);
|
|
|
|
}
|
|
|
|
case VECTOR2: {
|
|
|
|
_RETURN(p_a._data._transform2d->xform(*(const Vector2 *)p_b._data._mem));
|
|
|
|
}
|
2020-05-10 11:00:47 +00:00
|
|
|
default:
|
|
|
|
_RETURN_FAIL;
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, QUAT) {
|
|
|
|
switch (p_b.type) {
|
|
|
|
case VECTOR3: {
|
|
|
|
_RETURN(reinterpret_cast<const Quat *>(p_a._data._mem)->xform(*(const Vector3 *)p_b._data._mem));
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
case QUAT: {
|
|
|
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * *reinterpret_cast<const Quat *>(p_b._data._mem));
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
|
|
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._float);
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2020-05-10 11:00:47 +00:00
|
|
|
default:
|
|
|
|
_RETURN_FAIL;
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, BASIS) {
|
|
|
|
switch (p_b.type) {
|
|
|
|
case VECTOR3: {
|
|
|
|
_RETURN(p_a._data._basis->xform(*(const Vector3 *)p_b._data._mem));
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
case BASIS: {
|
|
|
|
_RETURN(*p_a._data._basis * *p_b._data._basis);
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2020-05-10 11:00:47 +00:00
|
|
|
default:
|
|
|
|
_RETURN_FAIL;
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, TRANSFORM) {
|
|
|
|
switch (p_b.type) {
|
|
|
|
case VECTOR3: {
|
|
|
|
_RETURN(p_a._data._transform->xform(*(const Vector3 *)p_b._data._mem));
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
case TRANSFORM: {
|
|
|
|
_RETURN(*p_a._data._transform * *p_b._data._transform);
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2020-05-10 11:00:47 +00:00
|
|
|
default:
|
|
|
|
_RETURN_FAIL;
|
2017-09-18 11:09:06 +00:00
|
|
|
}
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, FLOAT, *, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2I, *, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3I, *, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, COLOR, *, Color);
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, NIL)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, BOOL)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, STRING)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PLANE)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, AABB)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, _RID)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_BYTE_ARRAY);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_INT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_INT64_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_FLOAT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_FLOAT64_ARRAY);
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_STRING_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_VECTOR2_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_VECTOR3_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_MULTIPLY, PACKED_COLOR_ARRAY);
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_DIVIDE, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, QUAT) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_b.type != FLOAT)
|
2017-09-18 11:09:06 +00:00
|
|
|
_RETURN_FAIL;
|
2017-09-17 00:32:05 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_b._data._float == 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_valid = false;
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN("Division By Zero");
|
|
|
|
}
|
|
|
|
#endif
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._float);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, INT, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, FLOAT, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR2, /, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR2I, /, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR3, /, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR3I, /, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, COLOR, /, Color);
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, NIL)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, BOOL)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, STRING)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PLANE)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, BASIS)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, TRANSFORM)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, _RID)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_BYTE_ARRAY);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_INT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_INT64_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_FLOAT32_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_FLOAT64_ARRAY);
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_STRING_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_VECTOR2_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_VECTOR3_ARRAY);
|
|
|
|
CASE_TYPE(math, OP_DIVIDE, PACKED_COLOR_ARRAY);
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_POSITIVE, p_a.type) {
|
|
|
|
DEFAULT_OP_NUM_POS(math, OP_POSITIVE, INT, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM_POS(math, OP_POSITIVE, FLOAT, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR3, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR3I, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, PLANE, Plane);
|
|
|
|
DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, QUAT, Quat);
|
|
|
|
DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR2, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR2I, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, NIL)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, BOOL)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, STRING)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, TRANSFORM2D)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, BASIS)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, TRANSFORM)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, COLOR)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, _RID)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_BYTE_ARRAY)
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_INT32_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_INT64_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_FLOAT32_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_FLOAT64_ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_STRING_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_VECTOR2_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_VECTOR3_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_POSITIVE, PACKED_COLOR_ARRAY)
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_NEGATE, p_a.type) {
|
|
|
|
DEFAULT_OP_NUM_NEG(math, OP_NEGATE, INT, _int);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_NUM_NEG(math, OP_NEGATE, FLOAT, _float);
|
2017-09-17 00:32:05 +00:00
|
|
|
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR2, Vector2);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR2I, Vector2i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR3, Vector3);
|
2020-02-22 03:26:41 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR3I, Vector3i);
|
2017-09-17 00:32:05 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, PLANE, Plane);
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, QUAT, Quat);
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, COLOR, Color);
|
|
|
|
|
|
|
|
CASE_TYPE(math, OP_NEGATE, NIL)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, BOOL)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, STRING)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, TRANSFORM2D)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, BASIS)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, TRANSFORM)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, _RID)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_BYTE_ARRAY)
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_INT32_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_INT64_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_FLOAT32_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_FLOAT64_ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_STRING_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_VECTOR2_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_VECTOR3_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_NEGATE, PACKED_COLOR_ARRAY)
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_MODULE, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_MODULE, INT) {
|
2017-09-18 11:09:06 +00:00
|
|
|
if (p_b.type != INT)
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_b._data._int == 0) {
|
|
|
|
r_valid = false;
|
|
|
|
_RETURN("Division By Zero");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_a._data._int % p_b._data._int);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, STRING) {
|
2017-09-18 11:09:06 +00:00
|
|
|
const String *format = reinterpret_cast<const String *>(p_a._data._mem);
|
2015-01-10 20:44:20 +00:00
|
|
|
|
2015-02-19 15:45:49 +00:00
|
|
|
String result;
|
|
|
|
bool error;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_b.type == ARRAY) {
|
2015-01-10 20:44:20 +00:00
|
|
|
// e.g. "frog %s %d" % ["fish", 12]
|
2017-09-18 11:09:06 +00:00
|
|
|
const Array *args = reinterpret_cast<const Array *>(p_b._data._mem);
|
2017-03-05 15:44:50 +00:00
|
|
|
result = format->sprintf(*args, &error);
|
2015-01-10 20:44:20 +00:00
|
|
|
} else {
|
|
|
|
// e.g. "frog %d" % 12
|
2015-02-19 15:45:49 +00:00
|
|
|
Array args;
|
|
|
|
args.push_back(p_b);
|
2017-03-05 15:44:50 +00:00
|
|
|
result = format->sprintf(args, &error);
|
2015-01-10 20:44:20 +00:00
|
|
|
}
|
2015-02-19 15:45:49 +00:00
|
|
|
r_valid = !error;
|
|
|
|
_RETURN(result);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, NIL)
|
|
|
|
CASE_TYPE(math, OP_MODULE, BOOL)
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, FLOAT)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, VECTOR2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, VECTOR2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, RECT2)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, RECT2I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, VECTOR3)
|
2020-02-22 03:26:41 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, VECTOR3I)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, TRANSFORM2D)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PLANE)
|
|
|
|
CASE_TYPE(math, OP_MODULE, QUAT)
|
2017-11-17 02:09:00 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, AABB)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, BASIS)
|
|
|
|
CASE_TYPE(math, OP_MODULE, TRANSFORM)
|
|
|
|
CASE_TYPE(math, OP_MODULE, COLOR)
|
2020-02-20 21:58:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, STRING_NAME)
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, NODE_PATH)
|
|
|
|
CASE_TYPE(math, OP_MODULE, _RID)
|
|
|
|
CASE_TYPE(math, OP_MODULE, OBJECT)
|
2020-02-19 19:27:19 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, CALLABLE)
|
|
|
|
CASE_TYPE(math, OP_MODULE, SIGNAL)
|
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, DICTIONARY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_BYTE_ARRAY)
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_INT32_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_INT64_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_FLOAT32_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_FLOAT64_ARRAY)
|
2020-02-17 21:06:54 +00:00
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_STRING_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_VECTOR2_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_VECTOR3_ARRAY)
|
|
|
|
CASE_TYPE(math, OP_MODULE, PACKED_COLOR_ARRAY)
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_STRING_CONCAT, p_a.type) {
|
|
|
|
CASE_TYPE_ALL(math, OP_STRING_CONCAT)
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_a.operator String() + p_b.operator String());
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_SHIFT_LEFT, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_SHIFT_LEFT, INT) {
|
|
|
|
if (p_b.type != INT)
|
|
|
|
_RETURN_FAIL;
|
2019-12-12 19:00:26 +00:00
|
|
|
if (p_b._data._int < 0 || p_b._data._int >= 64)
|
|
|
|
_RETURN_FAIL;
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(p_a._data._int << p_b._data._int);
|
|
|
|
}
|
2017-09-18 11:09:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE_ALL_BUT_INT(math, OP_SHIFT_LEFT)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_SHIFT_RIGHT, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_SHIFT_RIGHT, INT) {
|
|
|
|
if (p_b.type != INT)
|
|
|
|
_RETURN_FAIL;
|
2019-12-12 19:00:26 +00:00
|
|
|
if (p_b._data._int < 0 || p_b._data._int >= 64)
|
|
|
|
_RETURN_FAIL;
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_a._data._int >> p_b._data._int);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2017-09-18 11:09:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE_ALL_BUT_INT(math, OP_SHIFT_RIGHT)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_BIT_AND, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_BIT_AND, INT) {
|
|
|
|
if (p_b.type != INT)
|
|
|
|
_RETURN_FAIL;
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_a._data._int & p_b._data._int);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2017-09-18 11:09:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_AND)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_BIT_OR, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_BIT_OR, INT) {
|
|
|
|
if (p_b.type != INT)
|
|
|
|
_RETURN_FAIL;
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_a._data._int | p_b._data._int);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2017-09-18 11:09:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_OR)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_BIT_XOR, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_BIT_XOR, INT) {
|
|
|
|
if (p_b.type != INT)
|
|
|
|
_RETURN_FAIL;
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_a._data._int ^ p_b._data._int);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2017-09-18 11:09:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_XOR)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_BIT_NEGATE, p_a.type) {
|
|
|
|
CASE_TYPE(math, OP_BIT_NEGATE, INT) {
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(~p_a._data._int);
|
2017-09-17 00:32:05 +00:00
|
|
|
}
|
2017-09-18 11:09:06 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
CASE_TYPE_ALL_BUT_INT(math, OP_BIT_NEGATE)
|
|
|
|
_RETURN_FAIL;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_AND, p_a.type) {
|
|
|
|
CASE_TYPE_ALL(math, OP_AND) {
|
2017-09-18 18:02:47 +00:00
|
|
|
bool l = p_a.booleanize();
|
|
|
|
bool r = p_b.booleanize();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(l && r);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_OR, p_a.type) {
|
|
|
|
CASE_TYPE_ALL(math, OP_OR) {
|
2017-09-18 18:02:47 +00:00
|
|
|
bool l = p_a.booleanize();
|
|
|
|
bool r = p_b.booleanize();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(l || r);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_XOR, p_a.type) {
|
|
|
|
CASE_TYPE_ALL(math, OP_XOR) {
|
2017-09-18 18:02:47 +00:00
|
|
|
bool l = p_a.booleanize();
|
|
|
|
bool r = p_b.booleanize();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN((l || r) && !(l && r));
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_NOT, p_a.type) {
|
|
|
|
CASE_TYPE_ALL(math, OP_NOT) {
|
2017-09-18 18:02:47 +00:00
|
|
|
bool l = p_a.booleanize();
|
2017-09-17 00:32:05 +00:00
|
|
|
_RETURN(!l);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-17 00:32:05 +00:00
|
|
|
SWITCH_OP(math, OP_IN, p_a.type) {
|
|
|
|
CASE_TYPE_ALL(math, OP_IN)
|
2017-03-05 15:44:50 +00:00
|
|
|
_RETURN(p_b.in(p_a, &r_valid));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Variant::set_named(const StringName &p_index, const Variant &p_value, bool *r_valid) {
|
2017-09-24 00:05:35 +00:00
|
|
|
bool valid = false;
|
|
|
|
switch (type) {
|
|
|
|
case VECTOR2: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->x = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->y = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2017-09-24 00:05:35 +00:00
|
|
|
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->x = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->y = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR2I: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->x = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->y = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->x = p_value._data._float;
|
2020-02-22 03:26:41 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->y = p_value._data._float;
|
2020-02-22 03:26:41 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
} break;
|
|
|
|
case RECT2: {
|
|
|
|
if (p_value.type == Variant::VECTOR2) {
|
|
|
|
Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
|
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->position) {
|
|
|
|
v->position = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->size) {
|
|
|
|
v->size = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->end) {
|
|
|
|
v->size = *reinterpret_cast<const Vector2 *>(p_value._data._mem) - v->position;
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case RECT2I: {
|
|
|
|
if (p_value.type == Variant::VECTOR2I) {
|
|
|
|
Rect2i *v = reinterpret_cast<Rect2i *>(_data._mem);
|
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->position) {
|
|
|
|
v->position = *reinterpret_cast<const Vector2i *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->size) {
|
|
|
|
v->size = *reinterpret_cast<const Vector2i *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->end) {
|
|
|
|
v->size = *reinterpret_cast<const Vector2i *>(p_value._data._mem) - v->position;
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2017-09-24 00:05:35 +00:00
|
|
|
case TRANSFORM2D: {
|
|
|
|
if (p_value.type == Variant::VECTOR2) {
|
|
|
|
Transform2D *v = _data._transform2d;
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->elements[0] = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->elements[1] = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->origin) {
|
|
|
|
v->elements[2] = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->x = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->y = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
v->z = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2017-09-24 00:05:35 +00:00
|
|
|
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->x = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->y = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->z = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3I: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->x = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->y = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
v->z = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->x = p_value._data._float;
|
2020-02-22 03:26:41 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->y = p_value._data._float;
|
2020-02-22 03:26:41 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->z = p_value._data._float;
|
2020-02-22 03:26:41 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
} break;
|
|
|
|
case PLANE: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Plane *v = reinterpret_cast<Plane *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->normal.x = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->normal.y = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
v->normal.z = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->d) {
|
2020-05-10 14:47:11 +00:00
|
|
|
v->d = p_value._data._int;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2017-09-24 00:05:35 +00:00
|
|
|
Plane *v = reinterpret_cast<Plane *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->normal.x = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->normal.y = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->normal.z = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->d) {
|
2020-05-10 14:47:11 +00:00
|
|
|
v->d = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (p_value.type == Variant::VECTOR3) {
|
|
|
|
Plane *v = reinterpret_cast<Plane *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->normal) {
|
|
|
|
v->normal = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Quat *v = reinterpret_cast<Quat *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->x = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->y = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
v->z = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->w) {
|
|
|
|
v->w = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2017-09-24 00:05:35 +00:00
|
|
|
Quat *v = reinterpret_cast<Quat *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->x = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->y = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->z = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->w) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->w = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
2017-09-24 00:05:35 +00:00
|
|
|
if (p_value.type == Variant::VECTOR3) {
|
2017-11-17 02:09:00 +00:00
|
|
|
::AABB *v = _data._aabb;
|
2017-09-24 00:05:35 +00:00
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->position) {
|
|
|
|
v->position = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->size) {
|
|
|
|
v->size = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->end) {
|
|
|
|
v->size = *reinterpret_cast<const Vector3 *>(p_value._data._mem) - v->position;
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case BASIS: {
|
|
|
|
if (p_value.type == Variant::VECTOR3) {
|
|
|
|
Basis *v = _data._basis;
|
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
v->set_axis(0, *reinterpret_cast<const Vector3 *>(p_value._data._mem));
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
v->set_axis(1, *reinterpret_cast<const Vector3 *>(p_value._data._mem));
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
v->set_axis(2, *reinterpret_cast<const Vector3 *>(p_value._data._mem));
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
|
|
|
if (p_value.type == Variant::BASIS && p_index == CoreStringNames::singleton->basis) {
|
|
|
|
_data._transform->basis = *p_value._data._basis;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_value.type == Variant::VECTOR3 && p_index == CoreStringNames::singleton->origin) {
|
|
|
|
_data._transform->origin = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
|
|
|
if (p_value.type == Variant::INT) {
|
|
|
|
Color *v = reinterpret_cast<Color *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->r) {
|
|
|
|
v->r = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->g) {
|
|
|
|
v->g = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->b) {
|
|
|
|
v->b = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->a) {
|
|
|
|
v->a = p_value._data._int;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->r8) {
|
|
|
|
v->r = p_value._data._int / 255.0;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->g8) {
|
|
|
|
v->g = p_value._data._int / 255.0;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->b8) {
|
|
|
|
v->b = p_value._data._int / 255.0;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->a8) {
|
|
|
|
v->a = p_value._data._int / 255.0;
|
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->h) {
|
2018-04-22 15:00:45 +00:00
|
|
|
v->set_hsv(p_value._data._int, v->get_s(), v->get_v(), v->a);
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->s) {
|
2018-04-22 15:00:45 +00:00
|
|
|
v->set_hsv(v->get_h(), p_value._data._int, v->get_v(), v->a);
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->v) {
|
2018-04-22 15:00:45 +00:00
|
|
|
v->set_hsv(v->get_h(), v->get_v(), p_value._data._int, v->a);
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
} else if (p_value.type == Variant::FLOAT) {
|
2017-09-24 00:05:35 +00:00
|
|
|
Color *v = reinterpret_cast<Color *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->r) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->r = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->g) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->g = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->b) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->b = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->a) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->a = p_value._data._float;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->r8) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->r = p_value._data._float / 255.0;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->g8) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->g = p_value._data._float / 255.0;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->b8) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->b = p_value._data._float / 255.0;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->a8) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->a = p_value._data._float / 255.0;
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->h) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->set_hsv(p_value._data._float, v->get_s(), v->get_v(), v->a);
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->s) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->set_hsv(v->get_h(), p_value._data._float, v->get_v(), v->a);
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->v) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
v->set_hsv(v->get_h(), v->get_s(), p_value._data._float, v->a);
|
2017-09-24 00:05:35 +00:00
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OBJECT: {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
|
|
|
break;
|
2020-02-27 02:30:20 +00:00
|
|
|
} else if (EngineDebugger::is_active() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2017-09-24 00:05:35 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-09-24 00:05:35 +00:00
|
|
|
_get_obj().obj->set(p_index, p_value, &valid);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {
|
2017-09-24 17:44:49 +00:00
|
|
|
set(p_index.operator String(), p_value, &valid);
|
2017-09-24 00:05:35 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = valid;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
|
2017-09-24 00:05:35 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = true;
|
|
|
|
}
|
2020-06-25 13:33:28 +00:00
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
switch (type) {
|
|
|
|
case VECTOR2: {
|
|
|
|
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->x;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->y;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR2I: {
|
|
|
|
const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->x;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->y;
|
|
|
|
}
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
} break;
|
|
|
|
case RECT2: {
|
|
|
|
const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
|
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->position) {
|
|
|
|
return v->position;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->size) {
|
|
|
|
return v->size;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->end) {
|
|
|
|
return v->size + v->position;
|
|
|
|
}
|
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case RECT2I: {
|
|
|
|
const Rect2i *v = reinterpret_cast<const Rect2i *>(_data._mem);
|
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->position) {
|
|
|
|
return v->position;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->size) {
|
|
|
|
return v->size;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->end) {
|
|
|
|
return v->size + v->position;
|
|
|
|
}
|
|
|
|
} break;
|
2017-09-24 00:05:35 +00:00
|
|
|
case TRANSFORM2D: {
|
|
|
|
const Transform2D *v = _data._transform2d;
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->elements[0];
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->elements[1];
|
|
|
|
} else if (p_index == CoreStringNames::singleton->origin) {
|
|
|
|
return v->elements[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
|
|
|
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->x;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->y;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
return v->z;
|
|
|
|
}
|
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3I: {
|
|
|
|
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->x;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->y;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
return v->z;
|
|
|
|
}
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
} break;
|
|
|
|
case PLANE: {
|
|
|
|
const Plane *v = reinterpret_cast<const Plane *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->normal.x;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->normal.y;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
return v->normal.z;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->d) {
|
2020-05-10 14:47:11 +00:00
|
|
|
return v->d;
|
2017-09-24 00:05:35 +00:00
|
|
|
} else if (p_index == CoreStringNames::singleton->normal) {
|
|
|
|
return v->normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
|
|
|
const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->x;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->y;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
return v->z;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->w) {
|
|
|
|
return v->w;
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
|
|
|
const ::AABB *v = _data._aabb;
|
2017-09-24 00:05:35 +00:00
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->position) {
|
|
|
|
return v->position;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->size) {
|
|
|
|
return v->size;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->end) {
|
|
|
|
return v->size + v->position;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case BASIS: {
|
|
|
|
const Basis *v = _data._basis;
|
|
|
|
//scalar name
|
|
|
|
if (p_index == CoreStringNames::singleton->x) {
|
|
|
|
return v->get_axis(0);
|
|
|
|
} else if (p_index == CoreStringNames::singleton->y) {
|
|
|
|
return v->get_axis(1);
|
|
|
|
} else if (p_index == CoreStringNames::singleton->z) {
|
|
|
|
return v->get_axis(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
|
|
|
if (p_index == CoreStringNames::singleton->basis) {
|
|
|
|
return _data._transform->basis;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->origin) {
|
|
|
|
return _data._transform->origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
|
|
|
const Color *v = reinterpret_cast<const Color *>(_data._mem);
|
|
|
|
if (p_index == CoreStringNames::singleton->r) {
|
|
|
|
return v->r;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->g) {
|
|
|
|
return v->g;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->b) {
|
|
|
|
return v->b;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->a) {
|
|
|
|
return v->a;
|
|
|
|
} else if (p_index == CoreStringNames::singleton->r8) {
|
2018-09-18 15:11:15 +00:00
|
|
|
return int(Math::round(v->r * 255.0));
|
2017-09-24 00:05:35 +00:00
|
|
|
} else if (p_index == CoreStringNames::singleton->g8) {
|
2018-09-18 15:11:15 +00:00
|
|
|
return int(Math::round(v->g * 255.0));
|
2017-09-24 00:05:35 +00:00
|
|
|
} else if (p_index == CoreStringNames::singleton->b8) {
|
2018-09-18 15:11:15 +00:00
|
|
|
return int(Math::round(v->b * 255.0));
|
2017-09-24 00:05:35 +00:00
|
|
|
} else if (p_index == CoreStringNames::singleton->a8) {
|
2018-09-18 15:11:15 +00:00
|
|
|
return int(Math::round(v->a * 255.0));
|
2017-09-24 00:05:35 +00:00
|
|
|
} else if (p_index == CoreStringNames::singleton->h) {
|
|
|
|
return v->get_h();
|
|
|
|
} else if (p_index == CoreStringNames::singleton->s) {
|
|
|
|
return v->get_s();
|
|
|
|
} else if (p_index == CoreStringNames::singleton->v) {
|
|
|
|
return v->get_v();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OBJECT: {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_valid = false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-24 00:05:35 +00:00
|
|
|
return "Instance base is null.";
|
|
|
|
} else {
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r_valid) {
|
2017-09-24 00:05:35 +00:00
|
|
|
*r_valid = false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-24 00:05:35 +00:00
|
|
|
return "Attempted use of stray pointer object.";
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
return _get_obj().obj->get(p_index, r_valid);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
return get(p_index.operator String(), r_valid);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 00:05:35 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = false;
|
|
|
|
}
|
2017-09-24 17:50:51 +00:00
|
|
|
return Variant();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_CMD(m_name, m_type, skip_test, cmd) \
|
|
|
|
case m_name: { \
|
|
|
|
skip_test; \
|
|
|
|
\
|
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \
|
|
|
|
int index = p_index; \
|
|
|
|
m_type *arr = reinterpret_cast<m_type *>(_data._mem); \
|
|
|
|
\
|
|
|
|
if (index < 0) \
|
|
|
|
index += arr->size(); \
|
|
|
|
if (index >= 0 && index < arr->size()) { \
|
|
|
|
valid = true; \
|
|
|
|
cmd; \
|
|
|
|
} \
|
|
|
|
} \
|
2016-05-26 21:35:33 +00:00
|
|
|
} break;
|
|
|
|
|
2020-02-23 21:01:26 +00:00
|
|
|
#define DEFAULT_OP_DVECTOR_SET(m_name, m_type, skip_cond) \
|
|
|
|
case m_name: { \
|
2020-05-10 10:56:01 +00:00
|
|
|
if (skip_cond) \
|
|
|
|
return; \
|
2020-02-23 21:01:26 +00:00
|
|
|
\
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \
|
2020-02-23 21:01:26 +00:00
|
|
|
int index = p_index; \
|
|
|
|
Vector<m_type> *arr = PackedArrayRef<m_type>::get_array_ptr(_data.packed_array); \
|
|
|
|
\
|
|
|
|
if (index < 0) \
|
|
|
|
index += arr->size(); \
|
|
|
|
if (index >= 0 && index < arr->size()) { \
|
|
|
|
valid = true; \
|
|
|
|
arr->set(index, p_value); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} break;
|
2016-05-26 21:35:33 +00:00
|
|
|
|
2020-02-23 21:01:26 +00:00
|
|
|
#define DEFAULT_OP_DVECTOR_GET(m_name, m_type) \
|
|
|
|
case m_name: { \
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \
|
2020-02-23 21:01:26 +00:00
|
|
|
int index = p_index; \
|
|
|
|
const Vector<m_type> *arr = &PackedArrayRef<m_type>::get_array(_data.packed_array); \
|
|
|
|
\
|
|
|
|
if (index < 0) \
|
|
|
|
index += arr->size(); \
|
|
|
|
if (index >= 0 && index < arr->size()) { \
|
|
|
|
valid = true; \
|
|
|
|
return arr->get(index); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} break;
|
2016-05-26 21:35:33 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) {
|
|
|
|
static bool _dummy = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool &valid = r_valid ? *r_valid : _dummy;
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
|
|
|
case NIL: {
|
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case BOOL: {
|
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case INT: {
|
|
|
|
return;
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
return;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case STRING: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = p_index;
|
|
|
|
String *str = reinterpret_cast<String *>(_data._mem);
|
2016-05-28 14:12:10 +00:00
|
|
|
int len = str->length();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += len;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
|
|
|
if (idx < 0 || idx >= len) {
|
2015-01-02 16:17:46 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2015-01-02 16:17:46 +00:00
|
|
|
|
|
|
|
String chr;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_value.type == Variant::INT || p_value.type == Variant::FLOAT) {
|
2015-01-02 16:17:46 +00:00
|
|
|
chr = String::chr(p_value);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_value.type == Variant::STRING) {
|
2015-01-02 16:17:46 +00:00
|
|
|
chr = p_value;
|
|
|
|
} else {
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
*str = str->substr(0, idx) + chr + str->substr(idx + 1, len);
|
|
|
|
valid = true;
|
2015-01-02 16:17:46 +00:00
|
|
|
return;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// scalar index
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = p_index;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 2;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx >= 0 && idx < 2) {
|
|
|
|
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
(*v)[idx] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
|
2017-07-01 00:30:17 +00:00
|
|
|
if (*str == "x") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-07-01 00:30:17 +00:00
|
|
|
} else if (*str == "y") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR2I: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
// scalar index
|
|
|
|
int idx = p_index;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2020-02-22 03:26:41 +00:00
|
|
|
idx += 2;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
if (idx >= 0 && idx < 2) {
|
|
|
|
Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
(*v)[idx] = p_value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
//scalar name
|
|
|
|
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
|
|
|
return;
|
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case RECT2: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
|
2017-06-03 22:25:13 +00:00
|
|
|
if (*str == "position") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2017-06-03 22:25:13 +00:00
|
|
|
v->position = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
|
|
|
v->size = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
2017-06-03 22:25:13 +00:00
|
|
|
v->size = Vector2(p_value) - v->position;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case RECT2I: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR2I) {
|
2020-02-22 03:26:41 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
|
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
|
|
|
//scalar name
|
|
|
|
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Rect2i *v = reinterpret_cast<Rect2i *>(_data._mem);
|
|
|
|
if (*str == "position") {
|
|
|
|
valid = true;
|
|
|
|
v->position = p_value;
|
|
|
|
return;
|
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
|
|
|
v->size = p_value;
|
|
|
|
return;
|
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
|
|
|
v->size = Vector2i(p_value) - v->position;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case TRANSFORM2D: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int index = p_index;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
Transform2D *v = _data._transform2d;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->elements[index] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING && p_value.get_type() == Variant::VECTOR2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Transform2D *v = _data._transform2d;
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->elements[0] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->elements[1] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-07-01 00:30:17 +00:00
|
|
|
} else if (*str == "origin") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->elements[2] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar index
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx >= 0 && idx < 3) {
|
|
|
|
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
(*v)[idx] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->z = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3I: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
//scalar index
|
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2020-02-22 03:26:41 +00:00
|
|
|
idx += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
if (idx >= 0 && idx < 3) {
|
|
|
|
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
(*v)[idx] = p_value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
//scalar name
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
|
|
|
return;
|
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
|
|
|
return;
|
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->z = p_value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case PLANE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Plane *v = reinterpret_cast<Plane *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal.x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal.y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal.z = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "normal") {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "d") {
|
|
|
|
valid = true;
|
2020-05-10 14:47:11 +00:00
|
|
|
v->d = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Quat *v = reinterpret_cast<Quat *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->z = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "w") {
|
|
|
|
valid = true;
|
|
|
|
v->w = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
2017-11-17 02:09:00 +00:00
|
|
|
::AABB *v = _data._aabb;
|
2017-06-06 18:33:51 +00:00
|
|
|
if (*str == "position") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2017-06-06 18:33:51 +00:00
|
|
|
v->position = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
|
|
|
v->size = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
2017-06-06 18:33:51 +00:00
|
|
|
v->size = Vector3(p_value) - v->position;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 16:45:56 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case BASIS: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int index = p_index;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
Basis *v = _data._basis;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->set_axis(index, p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Basis *v = _data._basis;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->set_axis(0, p_value);
|
2014-09-03 02:13:40 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->set_axis(1, p_value);
|
2014-09-03 02:13:40 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->set_axis(2, p_value);
|
2014-09-03 02:13:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 4;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index >= 0 && index < 4) {
|
|
|
|
Transform *v = _data._transform;
|
|
|
|
valid = true;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index == 3) {
|
2017-03-05 15:44:50 +00:00
|
|
|
v->origin = p_value;
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
v->basis.set_axis(index, p_value);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
Transform *v = _data._transform;
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (*str == "basis") {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::BASIS) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->basis = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
if (*str == "origin") {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
|
|
|
v->origin = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Color *v = reinterpret_cast<Color *>(_data._mem);
|
|
|
|
if (*str == "r") {
|
|
|
|
valid = true;
|
|
|
|
v->r = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "g") {
|
|
|
|
valid = true;
|
|
|
|
v->g = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "b") {
|
|
|
|
valid = true;
|
|
|
|
v->b = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "a") {
|
|
|
|
valid = true;
|
|
|
|
v->a = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "h") {
|
|
|
|
valid = true;
|
2018-04-22 15:00:45 +00:00
|
|
|
v->set_hsv(p_value, v->get_s(), v->get_v(), v->a);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "s") {
|
|
|
|
valid = true;
|
2018-04-22 15:00:45 +00:00
|
|
|
v->set_hsv(v->get_h(), p_value, v->get_v(), v->a);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "v") {
|
|
|
|
valid = true;
|
2018-04-22 15:00:45 +00:00
|
|
|
v->set_hsv(v->get_h(), v->get_s(), p_value, v->a);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "r8") {
|
|
|
|
valid = true;
|
|
|
|
v->r = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "g8") {
|
|
|
|
valid = true;
|
|
|
|
v->g = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "b8") {
|
|
|
|
valid = true;
|
|
|
|
v->b = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "a8") {
|
|
|
|
valid = true;
|
|
|
|
v->a = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::INT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 4;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Fix many errors found by PVS-Studio
Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15.
2018-11-28 02:58:00 +00:00
|
|
|
if (idx >= 0 && idx < 4) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Color *v = reinterpret_cast<Color *>(_data._mem);
|
|
|
|
(*v)[idx] = p_value;
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
2020-02-20 21:58:05 +00:00
|
|
|
case STRING_NAME: {
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case NODE_PATH: {
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case _RID: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Object *obj = _get_obj().obj;
|
|
|
|
//only if debugging!
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (obj) {
|
|
|
|
#ifdef DEBUG_ENABLED
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2020-02-13 19:03:10 +00:00
|
|
|
WARN_PRINT("Attempted use of previously freed pointer object.");
|
|
|
|
valid = false;
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-20 21:58:05 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING_NAME && p_index.get_type() != Variant::STRING) {
|
2017-03-05 15:44:50 +00:00
|
|
|
obj->setvar(p_index, p_value, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-01 10:59:42 +00:00
|
|
|
obj->set(p_index, p_value, r_valid);
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem);
|
|
|
|
dic->operator[](p_index) = p_value;
|
|
|
|
valid = true; //always valid, i guess? should this really be ok?
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-05-17 16:45:56 +00:00
|
|
|
} break;
|
2020-02-24 16:00:40 +00:00
|
|
|
DEFAULT_OP_ARRAY_CMD(ARRAY, Array, ;, (*arr)[index] = p_value; return )
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_BYTE_ARRAY, uint8_t, p_value.type != Variant::FLOAT && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_INT32_ARRAY, int32_t, p_value.type != Variant::FLOAT && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_INT64_ARRAY, int64_t, p_value.type != Variant::FLOAT && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_FLOAT32_ARRAY, float, p_value.type != Variant::FLOAT && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_FLOAT64_ARRAY, double, p_value.type != Variant::FLOAT && p_value.type != Variant::INT)
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_STRING_ARRAY, String, p_value.type != Variant::STRING)
|
2020-02-24 16:00:40 +00:00
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2)
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_VECTOR3_ARRAY, Vector3, p_value.type != Variant::VECTOR3)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(PACKED_COLOR_ARRAY, Color, p_value.type != Variant::COLOR)
|
2017-09-17 00:32:05 +00:00
|
|
|
default:
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant Variant::get(const Variant &p_index, bool *r_valid) const {
|
|
|
|
static bool _dummy = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool &valid = r_valid ? *r_valid : _dummy;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
|
|
|
case NIL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case BOOL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case INT: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
return Variant();
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case STRING: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//string index
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = p_index;
|
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += str->length();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx >= 0 && idx < str->length()) {
|
|
|
|
valid = true;
|
|
|
|
return str->substr(idx, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// scalar index
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 2;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx >= 0 && idx < 2) {
|
|
|
|
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return (*v)[idx];
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
|
2017-07-01 00:30:17 +00:00
|
|
|
if (*str == "x") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->x;
|
2017-07-01 00:30:17 +00:00
|
|
|
} else if (*str == "y") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR2I: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
// scalar index
|
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2020-02-22 03:26:41 +00:00
|
|
|
idx += 2;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
if (idx >= 0 && idx < 2) {
|
|
|
|
const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
return (*v)[idx];
|
|
|
|
}
|
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
//scalar name
|
|
|
|
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
return v->x;
|
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
return v->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case RECT2: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
|
2017-06-03 22:25:13 +00:00
|
|
|
if (*str == "position") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2017-06-03 22:25:13 +00:00
|
|
|
return v->position;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->size;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
2017-06-03 22:25:13 +00:00
|
|
|
return v->size + v->position;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case RECT2I: {
|
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
|
|
|
//scalar name
|
|
|
|
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Rect2i *v = reinterpret_cast<const Rect2i *>(_data._mem);
|
|
|
|
if (*str == "position") {
|
|
|
|
valid = true;
|
|
|
|
return v->position;
|
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
|
|
|
return v->size;
|
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
|
|
|
return v->size + v->position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR3: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar index
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx >= 0 && idx < 3) {
|
|
|
|
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return (*v)[idx];
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->x;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->y;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3I: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2020-02-22 03:26:41 +00:00
|
|
|
//scalar index
|
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2020-02-22 03:26:41 +00:00
|
|
|
idx += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2020-02-22 03:26:41 +00:00
|
|
|
if (idx >= 0 && idx < 3) {
|
|
|
|
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
return (*v)[idx];
|
|
|
|
}
|
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
//scalar name
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
return v->x;
|
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
return v->y;
|
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
return v->z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case TRANSFORM2D: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int index = p_index;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
const Transform2D *v = _data._transform2d;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[index];
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Transform2D *v = _data._transform2d;
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[0];
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[1];
|
2017-07-01 00:30:17 +00:00
|
|
|
} else if (*str == "origin") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PLANE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Plane *v = reinterpret_cast<const Plane *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal.x;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal.y;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal.z;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "normal") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "d") {
|
|
|
|
valid = true;
|
2020-05-10 14:47:11 +00:00
|
|
|
return v->d;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->x;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->y;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->z;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "w") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
2017-11-17 02:09:00 +00:00
|
|
|
const ::AABB *v = _data._aabb;
|
2017-06-06 18:33:51 +00:00
|
|
|
if (*str == "position") {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2017-06-06 18:33:51 +00:00
|
|
|
return v->position;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->size;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
2017-06-06 18:33:51 +00:00
|
|
|
return v->size + v->position;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 16:45:56 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case BASIS: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int index = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
const Basis *v = _data._basis;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_axis(index);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Basis *v = _data._basis;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-09-03 02:13:40 +00:00
|
|
|
return v->get_axis(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-09-03 02:13:40 +00:00
|
|
|
return v->get_axis(1);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-09-03 02:13:40 +00:00
|
|
|
return v->get_axis(2);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int index = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (index < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 4;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (index >= 0 && index < 4) {
|
|
|
|
const Transform *v = _data._transform;
|
|
|
|
valid = true;
|
|
|
|
return index == 3 ? v->origin : v->basis.get_axis(index);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const Transform *v = _data._transform;
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (*str == "basis") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->basis;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
if (*str == "origin") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->origin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Color *v = reinterpret_cast<const Color *>(_data._mem);
|
|
|
|
if (*str == "r") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->r;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "g") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->g;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "b") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->b;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "a") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->a;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "h") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_h();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "s") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_s();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "v") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_v();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (*str == "r8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->r * 255.0);
|
|
|
|
} else if (*str == "g8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->g * 255.0);
|
|
|
|
} else if (*str == "b8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->b * 255.0);
|
|
|
|
} else if (*str == "a8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->a * 255.0);
|
|
|
|
}
|
|
|
|
} else if (p_index.get_type() == Variant::INT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int idx = p_index;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx < 0) {
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 4;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Fix many errors found by PVS-Studio
Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15.
2018-11-28 02:58:00 +00:00
|
|
|
if (idx >= 0 && idx < 4) {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Color *v = reinterpret_cast<const Color *>(_data._mem);
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return (*v)[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
2020-02-20 21:58:05 +00:00
|
|
|
case STRING_NAME: {
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case NODE_PATH: {
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case _RID: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
Object *obj = _get_obj().obj;
|
|
|
|
if (obj) {
|
|
|
|
#ifdef DEBUG_ENABLED
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2020-02-13 19:03:10 +00:00
|
|
|
valid = false;
|
|
|
|
return "Attempted get on previously freed instance.";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING) {
|
|
|
|
return obj->getvar(p_index, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return obj->get(p_index, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
|
|
|
const Variant *res = dic->getptr(p_index);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (res) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return *res;
|
|
|
|
}
|
2017-05-17 16:45:56 +00:00
|
|
|
} break;
|
2020-02-24 16:00:40 +00:00
|
|
|
DEFAULT_OP_ARRAY_CMD(ARRAY, const Array, ;, return (*arr)[index])
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_BYTE_ARRAY, uint8_t)
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_INT32_ARRAY, int32_t)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_INT64_ARRAY, int64_t)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_FLOAT32_ARRAY, float)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_FLOAT64_ARRAY, double)
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_STRING_ARRAY, String)
|
2020-02-24 16:00:40 +00:00
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_VECTOR2_ARRAY, Vector2)
|
2020-02-17 21:06:54 +00:00
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_VECTOR3_ARRAY, Vector3)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(PACKED_COLOR_ARRAY, Color)
|
2017-09-17 00:32:05 +00:00
|
|
|
default:
|
|
|
|
return Variant();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Variant::in(const Variant &p_index, bool *r_valid) const {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_valid = true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//string index
|
2017-03-05 15:44:50 +00:00
|
|
|
String idx = p_index;
|
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return str->find(idx) != -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OBJECT: {
|
|
|
|
Object *obj = _get_obj().obj;
|
|
|
|
if (obj) {
|
2017-03-05 15:44:50 +00:00
|
|
|
bool valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2020-02-13 19:03:10 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
return true; // Attempted get on stray pointer.
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING) {
|
|
|
|
obj->getvar(p_index, &valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
obj->get(p_index, &valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
} else {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_valid = false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
return dic->has(p_index);
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
int l = arr->size();
|
|
|
|
if (l) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (evaluate(OP_EQUAL, (*arr)[i], p_index)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_BYTE_ARRAY: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int index = p_index;
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
2020-02-17 21:06:54 +00:00
|
|
|
const uint8_t *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT32_ARRAY: {
|
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
|
|
|
int32_t index = p_index;
|
|
|
|
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
|
|
|
|
int32_t l = arr->size();
|
|
|
|
if (l) {
|
|
|
|
const int32_t *r = arr->ptr();
|
|
|
|
for (int32_t i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PACKED_INT64_ARRAY: {
|
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
|
|
|
int64_t index = p_index;
|
|
|
|
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
|
|
|
|
int64_t l = arr->size();
|
|
|
|
if (l) {
|
|
|
|
const int64_t *r = arr->ptr();
|
|
|
|
for (int64_t i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case PACKED_FLOAT32_ARRAY: {
|
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
|
|
|
real_t index = p_index;
|
|
|
|
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
const float *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_FLOAT64_ARRAY: {
|
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
real_t index = p_index;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
const double *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_STRING_ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
String index = p_index;
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
2020-02-17 21:06:54 +00:00
|
|
|
const String *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} break; //25
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR2_ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::VECTOR2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 index = p_index;
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
2020-02-17 21:06:54 +00:00
|
|
|
const Vector2 *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR3_ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 index = p_index;
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
2020-02-17 21:06:54 +00:00
|
|
|
const Vector3 *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_COLOR_ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_index.get_type() == Variant::COLOR) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Color index = p_index;
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
2020-02-17 21:06:54 +00:00
|
|
|
const Color *r = arr->ptr();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r[i] == index) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (r_valid) {
|
2017-03-05 15:44:50 +00:00
|
|
|
*r_valid = false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Variant::get_property_list(List<PropertyInfo> *p_list) const {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR2: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR2I: {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "y"));
|
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case RECT2: {
|
2017-06-03 22:25:13 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "position"));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "size"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "end"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case RECT2I: {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "position"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "size"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "end"));
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "z"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-22 03:26:41 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR3I: {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "z"));
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case TRANSFORM2D: {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "y"));
|
2017-07-01 00:30:17 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "origin"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case PLANE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "normal"));
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "z"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "d"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "z"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "w"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
2017-06-28 20:00:18 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "position"));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "size"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "end"));
|
2017-05-17 16:45:56 +00:00
|
|
|
} break;
|
2017-01-11 03:52:51 +00:00
|
|
|
case BASIS: {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "z"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BASIS, "basis"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "origin"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "r"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "g"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "b"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "a"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "h"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "s"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::FLOAT, "v"));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "r8"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "g8"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "b8"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "a8"));
|
|
|
|
|
|
|
|
} break;
|
2020-02-20 21:58:05 +00:00
|
|
|
case STRING_NAME: {
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case NODE_PATH: {
|
2020-02-24 16:00:40 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case _RID: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
Object *obj = _get_obj().obj;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (obj) {
|
|
|
|
#ifdef DEBUG_ENABLED
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2020-02-13 19:03:10 +00:00
|
|
|
WARN_PRINT("Attempted get_property list on previously freed instance.");
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
obj->get_property_list(p_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<Variant> keys;
|
|
|
|
dic->get_key_list(&keys);
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
|
|
|
if (E->get().get_type() == Variant::STRING) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, E->get()));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 16:45:56 +00:00
|
|
|
} break;
|
2020-02-24 16:00:40 +00:00
|
|
|
case ARRAY:
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_BYTE_ARRAY:
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT32_ARRAY:
|
|
|
|
case PACKED_INT64_ARRAY:
|
|
|
|
case PACKED_FLOAT32_ARRAY:
|
|
|
|
case PACKED_FLOAT64_ARRAY:
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_STRING_ARRAY:
|
2020-02-24 16:00:40 +00:00
|
|
|
case PACKED_VECTOR2_ARRAY:
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR3_ARRAY:
|
|
|
|
case PACKED_COLOR_ARRAY: {
|
2014-02-10 01:10:30 +00:00
|
|
|
//nothing
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Variant::iter_init(Variant &r_iter, bool &valid) const {
|
|
|
|
valid = true;
|
|
|
|
switch (type) {
|
2017-01-11 23:09:45 +00:00
|
|
|
case INT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
|
|
|
return _data._int > 0;
|
2017-01-11 23:09:45 +00:00
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
2017-05-16 10:56:49 +00:00
|
|
|
r_iter = 0;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return _data._float > 0.0;
|
2017-01-11 23:09:45 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
2020-03-13 09:03:40 +00:00
|
|
|
double from = reinterpret_cast<const Vector2 *>(_data._mem)->x;
|
|
|
|
double to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = from;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
|
|
|
return from < to;
|
|
|
|
} break;
|
2020-05-09 17:42:50 +00:00
|
|
|
case VECTOR2I: {
|
|
|
|
int64_t from = reinterpret_cast<const Vector2i *>(_data._mem)->x;
|
|
|
|
int64_t to = reinterpret_cast<const Vector2i *>(_data._mem)->y;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = from;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
|
|
|
return from < to;
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
2020-03-13 09:03:40 +00:00
|
|
|
double from = reinterpret_cast<const Vector3 *>(_data._mem)->x;
|
|
|
|
double to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
|
|
|
|
double step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = from;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (from == to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
|
|
|
} else if (from < to) {
|
2017-05-16 10:56:49 +00:00
|
|
|
return step > 0;
|
2017-01-11 23:09:45 +00:00
|
|
|
}
|
2020-05-09 17:42:50 +00:00
|
|
|
return step < 0;
|
|
|
|
} break;
|
|
|
|
case VECTOR3I: {
|
|
|
|
int64_t from = reinterpret_cast<const Vector3i *>(_data._mem)->x;
|
|
|
|
int64_t to = reinterpret_cast<const Vector3i *>(_data._mem)->y;
|
|
|
|
int64_t step = reinterpret_cast<const Vector3i *>(_data._mem)->z;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = from;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (from == to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
|
|
|
} else if (from < to) {
|
2017-05-16 10:56:49 +00:00
|
|
|
return step > 0;
|
2017-01-11 23:09:45 +00:00
|
|
|
}
|
2020-05-09 17:42:50 +00:00
|
|
|
return step < 0;
|
2017-01-11 23:09:45 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
if (!_get_obj().obj) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:03:10 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
|
|
|
ce.error = Callable::CallError::CALL_OK;
|
2017-01-11 11:53:31 +00:00
|
|
|
Array ref;
|
2014-02-10 01:10:30 +00:00
|
|
|
ref.push_back(r_iter);
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant vref = ref;
|
|
|
|
const Variant *refp[] = { &vref };
|
|
|
|
Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->_iter_init, refp, 1, ce);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
if (ref.size() != 1 || ce.error != Callable::CallError::CALL_OK) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = ref[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
return ret;
|
|
|
|
} break;
|
|
|
|
|
2016-06-26 20:03:42 +00:00
|
|
|
case STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (str->empty()) {
|
2016-06-26 20:03:42 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-06-26 20:03:42 +00:00
|
|
|
r_iter = 0;
|
|
|
|
return true;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case DICTIONARY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (dic->empty()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
const Variant *next = dic->next(nullptr);
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = *next;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->empty()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_BYTE_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT32_ARRAY: {
|
|
|
|
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT64_ARRAY: {
|
|
|
|
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
r_iter = 0;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PACKED_FLOAT32_ARRAY: {
|
|
|
|
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
r_iter = 0;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PACKED_FLOAT64_ARRAY: {
|
|
|
|
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_STRING_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR2_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR3_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_COLOR_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (arr->size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
2017-09-17 00:32:05 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Variant::iter_next(Variant &r_iter, bool &valid) const {
|
|
|
|
valid = true;
|
|
|
|
switch (type) {
|
2017-01-11 23:09:45 +00:00
|
|
|
case INT: {
|
|
|
|
int64_t idx = r_iter;
|
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= _data._int) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-11 23:09:45 +00:00
|
|
|
r_iter = idx;
|
|
|
|
return true;
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
2017-05-16 10:56:49 +00:00
|
|
|
int64_t idx = r_iter;
|
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= _data._float) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-11 23:09:45 +00:00
|
|
|
r_iter = idx;
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
2020-03-13 09:03:40 +00:00
|
|
|
double to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
|
2017-05-16 10:56:49 +00:00
|
|
|
|
2020-03-13 09:03:40 +00:00
|
|
|
double idx = r_iter;
|
2017-05-16 10:56:49 +00:00
|
|
|
idx++;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-05-16 10:56:49 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2017-01-11 23:09:45 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-05-09 17:42:50 +00:00
|
|
|
case VECTOR2I: {
|
|
|
|
int64_t to = reinterpret_cast<const Vector2i *>(_data._mem)->y;
|
2017-05-16 10:56:49 +00:00
|
|
|
|
|
|
|
int64_t idx = r_iter;
|
|
|
|
idx++;
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-05-16 10:56:49 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2017-01-11 23:09:45 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
2020-03-13 09:03:40 +00:00
|
|
|
double to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
|
|
|
|
double step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2020-03-13 09:03:40 +00:00
|
|
|
double idx = r_iter;
|
2017-03-05 15:44:50 +00:00
|
|
|
idx += step;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (step < 0 && idx <= to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (step > 0 && idx >= to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2017-01-11 23:09:45 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-05-09 17:42:50 +00:00
|
|
|
case VECTOR3I: {
|
|
|
|
int64_t to = reinterpret_cast<const Vector3i *>(_data._mem)->y;
|
|
|
|
int64_t step = reinterpret_cast<const Vector3i *>(_data._mem)->z;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-05-16 10:56:49 +00:00
|
|
|
int64_t idx = r_iter;
|
2017-03-05 15:44:50 +00:00
|
|
|
idx += step;
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (step < 0 && idx <= to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (step > 0 && idx >= to) {
|
2017-01-11 23:09:45 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-01-11 23:09:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2017-01-11 23:09:45 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
if (!_get_obj().obj) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:03:10 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
|
|
|
ce.error = Callable::CallError::CALL_OK;
|
2017-01-11 11:53:31 +00:00
|
|
|
Array ref;
|
2014-02-10 01:10:30 +00:00
|
|
|
ref.push_back(r_iter);
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant vref = ref;
|
|
|
|
const Variant *refp[] = { &vref };
|
|
|
|
Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->_iter_next, refp, 1, ce);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
if (ref.size() != 1 || ce.error != Callable::CallError::CALL_OK) {
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = ref[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
} break;
|
2016-06-26 20:03:42 +00:00
|
|
|
|
|
|
|
case STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2016-06-26 20:03:42 +00:00
|
|
|
int idx = r_iter;
|
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= str->length()) {
|
2016-06-26 20:03:42 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-06-26 20:03:42 +00:00
|
|
|
r_iter = idx;
|
|
|
|
return true;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case DICTIONARY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
|
|
|
const Variant *next = dic->next(&r_iter);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!next) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = *next;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_BYTE_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT32_ARRAY: {
|
|
|
|
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
|
|
|
|
int32_t idx = r_iter;
|
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
r_iter = idx;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PACKED_INT64_ARRAY: {
|
|
|
|
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
|
|
|
|
int64_t idx = r_iter;
|
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
r_iter = idx;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PACKED_FLOAT32_ARRAY: {
|
|
|
|
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_FLOAT64_ARRAY: {
|
|
|
|
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_STRING_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR2_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR3_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_COLOR_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2020-05-14 14:41:43 +00:00
|
|
|
if (idx >= arr->size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
|
|
|
|
r_valid = true;
|
|
|
|
switch (type) {
|
2017-01-11 23:09:45 +00:00
|
|
|
case INT: {
|
|
|
|
return r_iter;
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
2017-01-11 23:09:45 +00:00
|
|
|
return r_iter;
|
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
|
|
|
return r_iter;
|
|
|
|
} break;
|
2020-05-09 17:42:50 +00:00
|
|
|
case VECTOR2I: {
|
|
|
|
return r_iter;
|
|
|
|
} break;
|
2017-01-11 23:09:45 +00:00
|
|
|
case VECTOR3: {
|
|
|
|
return r_iter;
|
|
|
|
} break;
|
2020-05-09 17:42:50 +00:00
|
|
|
case VECTOR3I: {
|
|
|
|
return r_iter;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
if (!_get_obj().obj) {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2020-02-27 02:30:20 +00:00
|
|
|
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
2020-02-13 19:03:10 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
|
|
|
ce.error = Callable::CallError::CALL_OK;
|
2017-03-05 15:44:50 +00:00
|
|
|
const Variant *refp[] = { &r_iter };
|
|
|
|
Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->_iter_get, refp, 1, ce);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
if (ce.error != Callable::CallError::CALL_OK) {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
//r_iter=ref[0];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
} break;
|
|
|
|
|
2016-06-26 20:03:42 +00:00
|
|
|
case STRING: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
|
|
|
return str->substr(r_iter, 1);
|
2016-06-26 20:03:42 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case DICTIONARY: {
|
|
|
|
return r_iter; //iterator is the same as the key
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_BYTE_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT32_ARRAY: {
|
|
|
|
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
|
|
|
|
int32_t idx = r_iter;
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case PACKED_INT64_ARRAY: {
|
|
|
|
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
|
|
|
|
int64_t idx = r_iter;
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case PACKED_FLOAT32_ARRAY: {
|
|
|
|
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_FLOAT64_ARRAY: {
|
|
|
|
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_STRING_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR2_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR3_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_COLOR_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2018-03-09 19:16:08 +00:00
|
|
|
Variant Variant::duplicate(bool deep) const {
|
|
|
|
switch (type) {
|
2018-07-02 18:08:35 +00:00
|
|
|
case OBJECT: {
|
2018-07-03 11:34:06 +00:00
|
|
|
/* breaks stuff :(
|
2018-07-02 18:08:35 +00:00
|
|
|
if (deep && !_get_obj().ref.is_null()) {
|
|
|
|
Ref<Resource> resource = _get_obj().ref;
|
|
|
|
if (resource.is_valid()) {
|
|
|
|
return resource->duplicate(true);
|
|
|
|
}
|
|
|
|
}
|
2018-07-03 11:34:06 +00:00
|
|
|
*/
|
2018-07-02 18:08:35 +00:00
|
|
|
return *this;
|
|
|
|
} break;
|
2018-03-09 19:16:08 +00:00
|
|
|
case DICTIONARY:
|
|
|
|
return operator Dictionary().duplicate(deep);
|
|
|
|
case ARRAY:
|
|
|
|
return operator Array().duplicate(deep);
|
|
|
|
default:
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) {
|
|
|
|
if (a.type != b.type) {
|
|
|
|
if (a.is_num() && b.is_num()) {
|
|
|
|
real_t va = a;
|
|
|
|
real_t vb = b;
|
|
|
|
r_dst = va + vb * c;
|
2016-02-18 03:34:49 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = a;
|
2016-02-18 03:34:49 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (a.type) {
|
|
|
|
case NIL: {
|
|
|
|
r_dst = Variant();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case INT: {
|
|
|
|
int64_t va = a._data._int;
|
|
|
|
int64_t vb = b._data._int;
|
|
|
|
r_dst = int(va + vb * c + 0.5);
|
|
|
|
}
|
|
|
|
return;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
|
|
|
double ra = a._data._float;
|
|
|
|
double rb = b._data._float;
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = ra + rb * c;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR2: {
|
|
|
|
r_dst = *reinterpret_cast<const Vector2 *>(a._data._mem) + *reinterpret_cast<const Vector2 *>(b._data._mem) * c;
|
|
|
|
}
|
|
|
|
return;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR2I: {
|
|
|
|
int32_t vax = reinterpret_cast<const Vector2i *>(a._data._mem)->x;
|
|
|
|
int32_t vbx = reinterpret_cast<const Vector2i *>(b._data._mem)->x;
|
|
|
|
int32_t vay = reinterpret_cast<const Vector2i *>(a._data._mem)->y;
|
|
|
|
int32_t vby = reinterpret_cast<const Vector2i *>(b._data._mem)->y;
|
|
|
|
r_dst = Vector2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5));
|
|
|
|
}
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
case RECT2: {
|
|
|
|
const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem);
|
|
|
|
const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem);
|
2017-06-03 22:25:13 +00:00
|
|
|
r_dst = Rect2(ra->position + rb->position * c, ra->size + rb->size * c);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-22 03:26:41 +00:00
|
|
|
case RECT2I: {
|
|
|
|
const Rect2i *ra = reinterpret_cast<const Rect2i *>(a._data._mem);
|
|
|
|
const Rect2i *rb = reinterpret_cast<const Rect2i *>(b._data._mem);
|
|
|
|
|
|
|
|
int32_t vax = ra->position.x;
|
|
|
|
int32_t vay = ra->position.y;
|
|
|
|
int32_t vbx = ra->size.x;
|
|
|
|
int32_t vby = ra->size.y;
|
|
|
|
int32_t vcx = rb->position.x;
|
|
|
|
int32_t vcy = rb->position.y;
|
|
|
|
int32_t vdx = rb->size.x;
|
|
|
|
int32_t vdy = rb->size.y;
|
|
|
|
|
|
|
|
r_dst = Rect2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vcx + vdx * c + 0.5), int32_t(vcy + vdy * c + 0.5));
|
|
|
|
}
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
case VECTOR3: {
|
|
|
|
r_dst = *reinterpret_cast<const Vector3 *>(a._data._mem) + *reinterpret_cast<const Vector3 *>(b._data._mem) * c;
|
|
|
|
}
|
|
|
|
return;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR3I: {
|
|
|
|
int32_t vax = reinterpret_cast<const Vector3i *>(a._data._mem)->x;
|
|
|
|
int32_t vbx = reinterpret_cast<const Vector3i *>(b._data._mem)->x;
|
|
|
|
int32_t vay = reinterpret_cast<const Vector3i *>(a._data._mem)->y;
|
|
|
|
int32_t vby = reinterpret_cast<const Vector3i *>(b._data._mem)->y;
|
|
|
|
int32_t vaz = reinterpret_cast<const Vector3i *>(a._data._mem)->z;
|
|
|
|
int32_t vbz = reinterpret_cast<const Vector3i *>(b._data._mem)->z;
|
|
|
|
r_dst = Vector3i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vaz + vbz * c + 0.5));
|
|
|
|
}
|
|
|
|
return;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
|
|
|
const ::AABB *ra = reinterpret_cast<const ::AABB *>(a._data._mem);
|
|
|
|
const ::AABB *rb = reinterpret_cast<const ::AABB *>(b._data._mem);
|
|
|
|
r_dst = ::AABB(ra->position + rb->position * c, ra->size + rb->size * c);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case QUAT: {
|
|
|
|
Quat empty_rot;
|
|
|
|
const Quat *qa = reinterpret_cast<const Quat *>(a._data._mem);
|
|
|
|
const Quat *qb = reinterpret_cast<const Quat *>(b._data._mem);
|
|
|
|
r_dst = *qa * empty_rot.slerp(*qb, c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case COLOR: {
|
|
|
|
const Color *ca = reinterpret_cast<const Color *>(a._data._mem);
|
|
|
|
const Color *cb = reinterpret_cast<const Color *>(b._data._mem);
|
2019-02-12 20:10:08 +00:00
|
|
|
float new_r = ca->r + cb->r * c;
|
|
|
|
float new_g = ca->g + cb->g * c;
|
|
|
|
float new_b = ca->b + cb->b * c;
|
|
|
|
float new_a = ca->a + cb->a * c;
|
|
|
|
new_r = new_r > 1.0 ? 1.0 : new_r;
|
|
|
|
new_g = new_g > 1.0 ? 1.0 : new_g;
|
|
|
|
new_b = new_b > 1.0 ? 1.0 : new_b;
|
|
|
|
new_a = new_a > 1.0 ? 1.0 : new_a;
|
|
|
|
r_dst = Color(new_r, new_g, new_b, new_a);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2017-09-17 00:32:05 +00:00
|
|
|
default: {
|
|
|
|
r_dst = c < 0.5 ? a : b;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
return;
|
2016-02-18 03:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) {
|
|
|
|
if (a.type != b.type) {
|
2015-05-16 21:16:11 +00:00
|
|
|
if (a.is_num() && b.is_num()) {
|
|
|
|
//not as efficient but..
|
2017-03-05 15:44:50 +00:00
|
|
|
real_t va = a;
|
|
|
|
real_t vb = b;
|
2018-10-07 13:40:50 +00:00
|
|
|
r_dst = va + (vb - va) * c;
|
2015-05-16 21:16:11 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = a;
|
2015-05-16 21:16:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (a.type) {
|
|
|
|
case NIL: {
|
|
|
|
r_dst = Variant();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case BOOL: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case INT: {
|
|
|
|
int64_t va = a._data._int;
|
|
|
|
int64_t vb = b._data._int;
|
2018-10-07 13:40:50 +00:00
|
|
|
r_dst = int(va + (vb - va) * c);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case FLOAT: {
|
|
|
|
real_t va = a._data._float;
|
|
|
|
real_t vb = b._data._float;
|
2018-10-07 13:40:50 +00:00
|
|
|
r_dst = va + (vb - va) * c;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case STRING: {
|
2014-02-10 01:10:30 +00:00
|
|
|
//this is pretty funny and bizarre, but artists like to use it for typewritter effects
|
2017-03-05 15:44:50 +00:00
|
|
|
String sa = *reinterpret_cast<const String *>(a._data._mem);
|
|
|
|
String sb = *reinterpret_cast<const String *>(b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
String dst;
|
2018-10-07 13:40:50 +00:00
|
|
|
int sa_len = sa.length();
|
|
|
|
int sb_len = sb.length();
|
|
|
|
int csize = sa_len + (sb_len - sa_len) * c;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (csize == 0) {
|
|
|
|
r_dst = "";
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
dst.resize(csize + 1);
|
|
|
|
dst[csize] = 0;
|
|
|
|
int split = csize / 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < csize; i++) {
|
2020-07-27 10:43:20 +00:00
|
|
|
char32_t chr = ' ';
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i < split) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (i < sa.length()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
chr = sa[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (i < sb.length()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
chr = sb[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (i < sb.length()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
chr = sb[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (i < sa.length()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
chr = sa[i];
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dst[i] = chr;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_dst = dst;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR2: {
|
2020-03-16 09:07:33 +00:00
|
|
|
r_dst = reinterpret_cast<const Vector2 *>(a._data._mem)->lerp(*reinterpret_cast<const Vector2 *>(b._data._mem), c);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR2I: {
|
|
|
|
int32_t vax = reinterpret_cast<const Vector2i *>(a._data._mem)->x;
|
|
|
|
int32_t vbx = reinterpret_cast<const Vector2i *>(b._data._mem)->x;
|
|
|
|
int32_t vay = reinterpret_cast<const Vector2i *>(a._data._mem)->y;
|
|
|
|
int32_t vby = reinterpret_cast<const Vector2i *>(b._data._mem)->y;
|
|
|
|
r_dst = Vector2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case RECT2: {
|
2020-03-16 09:07:33 +00:00
|
|
|
r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.lerp(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.lerp(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-22 03:26:41 +00:00
|
|
|
case RECT2I: {
|
|
|
|
const Rect2i *ra = reinterpret_cast<const Rect2i *>(a._data._mem);
|
|
|
|
const Rect2i *rb = reinterpret_cast<const Rect2i *>(b._data._mem);
|
|
|
|
|
|
|
|
int32_t vax = ra->position.x;
|
|
|
|
int32_t vay = ra->position.y;
|
|
|
|
int32_t vbx = ra->size.x;
|
|
|
|
int32_t vby = ra->size.y;
|
|
|
|
int32_t vcx = rb->position.x;
|
|
|
|
int32_t vcy = rb->position.y;
|
|
|
|
int32_t vdx = rb->size.x;
|
|
|
|
int32_t vdy = rb->size.y;
|
|
|
|
|
|
|
|
r_dst = Rect2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vcx + vdx * c + 0.5), int32_t(vcy + vdy * c + 0.5));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case VECTOR3: {
|
2020-03-16 09:07:33 +00:00
|
|
|
r_dst = reinterpret_cast<const Vector3 *>(a._data._mem)->lerp(*reinterpret_cast<const Vector3 *>(b._data._mem), c);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-22 03:26:41 +00:00
|
|
|
case VECTOR3I: {
|
|
|
|
int32_t vax = reinterpret_cast<const Vector3i *>(a._data._mem)->x;
|
|
|
|
int32_t vbx = reinterpret_cast<const Vector3i *>(b._data._mem)->x;
|
|
|
|
int32_t vay = reinterpret_cast<const Vector3i *>(a._data._mem)->y;
|
|
|
|
int32_t vby = reinterpret_cast<const Vector3i *>(b._data._mem)->y;
|
|
|
|
int32_t vaz = reinterpret_cast<const Vector3i *>(a._data._mem)->z;
|
|
|
|
int32_t vbz = reinterpret_cast<const Vector3i *>(b._data._mem)->z;
|
|
|
|
r_dst = Vector3i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vaz + vbz * c + 0.5));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case TRANSFORM2D: {
|
|
|
|
r_dst = a._data._transform2d->interpolate_with(*b._data._transform2d, c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PLANE: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case QUAT: {
|
|
|
|
r_dst = reinterpret_cast<const Quat *>(a._data._mem)->slerp(*reinterpret_cast<const Quat *>(b._data._mem), c);
|
|
|
|
}
|
|
|
|
return;
|
2017-11-17 02:09:00 +00:00
|
|
|
case AABB: {
|
2020-03-16 09:07:33 +00:00
|
|
|
r_dst = ::AABB(a._data._aabb->position.lerp(b._data._aabb->position, c), a._data._aabb->size.lerp(b._data._aabb->size, c));
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case BASIS: {
|
|
|
|
r_dst = Transform(*a._data._basis).interpolate_with(Transform(*b._data._basis), c).basis;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case TRANSFORM: {
|
|
|
|
r_dst = a._data._transform->interpolate_with(*b._data._transform, c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case COLOR: {
|
2020-03-16 09:07:33 +00:00
|
|
|
r_dst = reinterpret_cast<const Color *>(a._data._mem)->lerp(*reinterpret_cast<const Color *>(b._data._mem), c);
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-20 21:58:05 +00:00
|
|
|
case STRING_NAME: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
case NODE_PATH: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case _RID: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case OBJECT: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case DICTIONARY: {
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_BYTE_ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_INT32_ARRAY: {
|
|
|
|
const Vector<int32_t> *arr_a = &PackedArrayRef<int32_t>::get_array(a._data.packed_array);
|
|
|
|
const Vector<int32_t> *arr_b = &PackedArrayRef<int32_t>::get_array(b._data.packed_array);
|
|
|
|
int32_t sz = arr_a->size();
|
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
|
|
|
} else {
|
|
|
|
Vector<int32_t> v;
|
|
|
|
v.resize(sz);
|
|
|
|
{
|
|
|
|
int32_t *vw = v.ptrw();
|
|
|
|
const int32_t *ar = arr_a->ptr();
|
|
|
|
const int32_t *br = arr_b->ptr();
|
|
|
|
|
|
|
|
Variant va;
|
|
|
|
for (int32_t i = 0; i < sz; i++) {
|
|
|
|
Variant::interpolate(ar[i], br[i], c, va);
|
|
|
|
vw[i] = va;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_dst = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PACKED_INT64_ARRAY: {
|
|
|
|
const Vector<int64_t> *arr_a = &PackedArrayRef<int64_t>::get_array(a._data.packed_array);
|
|
|
|
const Vector<int64_t> *arr_b = &PackedArrayRef<int64_t>::get_array(b._data.packed_array);
|
|
|
|
int64_t sz = arr_a->size();
|
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
|
|
|
} else {
|
|
|
|
Vector<int64_t> v;
|
|
|
|
v.resize(sz);
|
|
|
|
{
|
|
|
|
int64_t *vw = v.ptrw();
|
|
|
|
const int64_t *ar = arr_a->ptr();
|
|
|
|
const int64_t *br = arr_b->ptr();
|
|
|
|
|
|
|
|
Variant va;
|
|
|
|
for (int64_t i = 0; i < sz; i++) {
|
|
|
|
Variant::interpolate(ar[i], br[i], c, va);
|
|
|
|
vw[i] = va;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_dst = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PACKED_FLOAT32_ARRAY: {
|
|
|
|
const Vector<float> *arr_a = &PackedArrayRef<float>::get_array(a._data.packed_array);
|
|
|
|
const Vector<float> *arr_b = &PackedArrayRef<float>::get_array(b._data.packed_array);
|
2019-02-16 11:20:01 +00:00
|
|
|
int sz = arr_a->size();
|
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
|
|
|
} else {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
Vector<float> v;
|
2019-02-16 11:20:01 +00:00
|
|
|
v.resize(sz);
|
|
|
|
{
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
float *vw = v.ptrw();
|
|
|
|
const float *ar = arr_a->ptr();
|
|
|
|
const float *br = arr_b->ptr();
|
2019-02-16 11:20:01 +00:00
|
|
|
|
|
|
|
Variant va;
|
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
Variant::interpolate(ar[i], br[i], c, va);
|
|
|
|
vw[i] = va;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_dst = v;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
case PACKED_FLOAT64_ARRAY: {
|
|
|
|
const Vector<double> *arr_a = &PackedArrayRef<double>::get_array(a._data.packed_array);
|
|
|
|
const Vector<double> *arr_b = &PackedArrayRef<double>::get_array(b._data.packed_array);
|
2019-02-16 11:20:01 +00:00
|
|
|
int sz = arr_a->size();
|
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
|
|
|
} else {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
Vector<double> v;
|
2019-02-16 11:20:01 +00:00
|
|
|
v.resize(sz);
|
|
|
|
{
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
double *vw = v.ptrw();
|
|
|
|
const double *ar = arr_a->ptr();
|
|
|
|
const double *br = arr_b->ptr();
|
2019-02-16 11:20:01 +00:00
|
|
|
|
|
|
|
Variant va;
|
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
Variant::interpolate(ar[i], br[i], c, va);
|
|
|
|
vw[i] = va;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_dst = v;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_STRING_ARRAY: {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR2_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector2> *arr_a = &PackedArrayRef<Vector2>::get_array(a._data.packed_array);
|
|
|
|
const Vector<Vector2> *arr_b = &PackedArrayRef<Vector2>::get_array(b._data.packed_array);
|
2014-07-07 20:44:21 +00:00
|
|
|
int sz = arr_a->size();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
2014-07-07 20:44:21 +00:00
|
|
|
} else {
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<Vector2> v;
|
2014-07-07 20:44:21 +00:00
|
|
|
v.resize(sz);
|
|
|
|
{
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector2 *vw = v.ptrw();
|
|
|
|
const Vector2 *ar = arr_a->ptr();
|
|
|
|
const Vector2 *br = arr_b->ptr();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < sz; i++) {
|
2020-03-16 09:07:33 +00:00
|
|
|
vw[i] = ar[i].lerp(br[i], c);
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = v;
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_VECTOR3_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Vector3> *arr_a = &PackedArrayRef<Vector3>::get_array(a._data.packed_array);
|
|
|
|
const Vector<Vector3> *arr_b = &PackedArrayRef<Vector3>::get_array(b._data.packed_array);
|
2014-07-07 20:44:21 +00:00
|
|
|
int sz = arr_a->size();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
2014-07-07 20:44:21 +00:00
|
|
|
} else {
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<Vector3> v;
|
2014-07-07 20:44:21 +00:00
|
|
|
v.resize(sz);
|
|
|
|
{
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector3 *vw = v.ptrw();
|
|
|
|
const Vector3 *ar = arr_a->ptr();
|
|
|
|
const Vector3 *br = arr_b->ptr();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < sz; i++) {
|
2020-03-16 09:07:33 +00:00
|
|
|
vw[i] = ar[i].lerp(br[i], c);
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = v;
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2020-02-17 21:06:54 +00:00
|
|
|
case PACKED_COLOR_ARRAY: {
|
2020-02-23 21:01:26 +00:00
|
|
|
const Vector<Color> *arr_a = &PackedArrayRef<Color>::get_array(a._data.packed_array);
|
|
|
|
const Vector<Color> *arr_b = &PackedArrayRef<Color>::get_array(b._data.packed_array);
|
2019-02-16 11:20:01 +00:00
|
|
|
int sz = arr_a->size();
|
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
|
|
|
r_dst = a;
|
|
|
|
} else {
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<Color> v;
|
2019-02-16 11:20:01 +00:00
|
|
|
v.resize(sz);
|
|
|
|
{
|
2020-02-17 21:06:54 +00:00
|
|
|
Color *vw = v.ptrw();
|
|
|
|
const Color *ar = arr_a->ptr();
|
|
|
|
const Color *br = arr_b->ptr();
|
2019-02-16 11:20:01 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < sz; i++) {
|
2020-03-16 09:07:33 +00:00
|
|
|
vw[i] = ar[i].lerp(br[i], c);
|
2019-02-16 11:20:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r_dst = v;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_dst = a;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *_op_names[Variant::OP_MAX] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"==",
|
|
|
|
"!=",
|
|
|
|
"<",
|
|
|
|
"<=",
|
|
|
|
">",
|
|
|
|
">=",
|
|
|
|
"+",
|
|
|
|
"-",
|
|
|
|
"*",
|
|
|
|
"/",
|
|
|
|
"- (negation)",
|
2018-04-16 17:54:49 +00:00
|
|
|
"+ (positive)",
|
2014-02-10 01:10:30 +00:00
|
|
|
"%",
|
2018-04-16 17:54:49 +00:00
|
|
|
"+ (concatenation)",
|
2014-02-10 01:10:30 +00:00
|
|
|
"<<",
|
|
|
|
">>",
|
|
|
|
"&",
|
|
|
|
"|",
|
|
|
|
"^",
|
|
|
|
"~",
|
|
|
|
"and",
|
|
|
|
"or",
|
|
|
|
"xor",
|
|
|
|
"not",
|
|
|
|
"in"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
String Variant::get_operator_name(Operator p_op) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_op, OP_MAX, "");
|
2014-02-10 01:10:30 +00:00
|
|
|
return _op_names[p_op];
|
|
|
|
}
|