2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* variant.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01: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-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef VARIANT_H
|
|
|
|
#define VARIANT_H
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/array.h"
|
2020-02-19 20:27:19 +01:00
|
|
|
#include "core/callable.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/color.h"
|
|
|
|
#include "core/dictionary.h"
|
|
|
|
#include "core/io/ip_address.h"
|
|
|
|
#include "core/math/aabb.h"
|
2019-02-09 06:24:02 +01:00
|
|
|
#include "core/math/basis.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/face3.h"
|
|
|
|
#include "core/math/plane.h"
|
|
|
|
#include "core/math/quat.h"
|
|
|
|
#include "core/math/transform.h"
|
|
|
|
#include "core/math/transform_2d.h"
|
|
|
|
#include "core/math/vector3.h"
|
2020-02-22 04:26:41 +01:00
|
|
|
#include "core/math/vector3i.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/node_path.h"
|
2020-02-12 18:24:06 +01:00
|
|
|
#include "core/object_id.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/rid.h"
|
|
|
|
#include "core/ustring.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class Object;
|
|
|
|
class Node; // helper
|
|
|
|
class Control; // helper
|
|
|
|
|
|
|
|
struct PropertyInfo;
|
|
|
|
struct MethodInfo;
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
typedef Vector<uint8_t> PackedByteArray;
|
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 19:20:53 +01:00
|
|
|
typedef Vector<int32_t> PackedInt32Array;
|
|
|
|
typedef Vector<int64_t> PackedInt64Array;
|
|
|
|
typedef Vector<float> PackedFloat32Array;
|
|
|
|
typedef Vector<double> PackedFloat64Array;
|
2020-02-17 22:06:54 +01:00
|
|
|
typedef Vector<String> PackedStringArray;
|
|
|
|
typedef Vector<Vector2> PackedVector2Array;
|
|
|
|
typedef Vector<Vector3> PackedVector3Array;
|
|
|
|
typedef Vector<Color> PackedColorArray;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class Variant {
|
|
|
|
public:
|
2017-09-17 02:32:05 +02:00
|
|
|
// If this changes the table in variant_op must be updated
|
2014-02-10 02:10:30 +01:00
|
|
|
enum Type {
|
2016-03-09 00:00:52 +01:00
|
|
|
NIL,
|
|
|
|
|
|
|
|
// atomic types
|
2014-02-10 02:10:30 +01:00
|
|
|
BOOL,
|
|
|
|
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 19:20:53 +01:00
|
|
|
FLOAT,
|
2014-02-10 02:10:30 +01:00
|
|
|
STRING,
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// math types
|
2020-02-24 17:00:40 +01:00
|
|
|
VECTOR2,
|
2020-02-22 04:26:41 +01:00
|
|
|
VECTOR2I,
|
2014-02-10 02:10:30 +01:00
|
|
|
RECT2,
|
2020-02-22 04:26:41 +01:00
|
|
|
RECT2I,
|
2014-02-10 02:10:30 +01:00
|
|
|
VECTOR3,
|
2020-02-22 04:26:41 +01:00
|
|
|
VECTOR3I,
|
2017-01-11 04:52:51 +01:00
|
|
|
TRANSFORM2D,
|
2014-02-10 02:10:30 +01:00
|
|
|
PLANE,
|
2020-02-24 17:00:40 +01:00
|
|
|
QUAT,
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB,
|
2017-01-11 04:52:51 +01:00
|
|
|
BASIS,
|
2014-02-10 02:10:30 +01:00
|
|
|
TRANSFORM,
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
// misc types
|
2014-02-10 02:10:30 +01:00
|
|
|
COLOR,
|
2020-02-20 22:58:05 +01:00
|
|
|
STRING_NAME,
|
2020-02-24 17:00:40 +01:00
|
|
|
NODE_PATH,
|
2014-02-10 02:10:30 +01:00
|
|
|
_RID,
|
2016-03-09 00:00:52 +01:00
|
|
|
OBJECT,
|
2020-02-19 20:27:19 +01:00
|
|
|
CALLABLE,
|
|
|
|
SIGNAL,
|
2017-05-17 12:36:47 +02:00
|
|
|
DICTIONARY,
|
2017-10-20 13:13:26 +02:00
|
|
|
ARRAY,
|
2020-02-24 17:00:40 +01:00
|
|
|
|
|
|
|
// typed arrays
|
|
|
|
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 19:20:53 +01:00
|
|
|
PACKED_INT32_ARRAY,
|
|
|
|
PACKED_INT64_ARRAY,
|
|
|
|
PACKED_FLOAT32_ARRAY,
|
|
|
|
PACKED_FLOAT64_ARRAY,
|
2020-02-17 22:06:54 +01:00
|
|
|
PACKED_STRING_ARRAY,
|
|
|
|
PACKED_VECTOR2_ARRAY,
|
2020-02-24 17:00:40 +01:00
|
|
|
PACKED_VECTOR3_ARRAY,
|
2020-02-17 22:06:54 +01:00
|
|
|
PACKED_COLOR_ARRAY,
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
VARIANT_MAX
|
2016-03-09 00:00:52 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
private:
|
2018-10-01 16:46:50 +02:00
|
|
|
friend struct _VariantCall;
|
2020-09-02 20:26:28 +02:00
|
|
|
friend class VariantInternal;
|
2014-02-10 02:10:30 +01:00
|
|
|
// Variant takes 20 bytes when real_t is float, and 36 if double
|
|
|
|
// it only allocates extra memory for aabb/matrix.
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
Type type = NIL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct ObjData {
|
2020-02-13 20:03:10 +01:00
|
|
|
ObjectID id;
|
2014-02-10 02:10:30 +01:00
|
|
|
Object *obj;
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-02-23 22:01:26 +01:00
|
|
|
/* array helpers */
|
|
|
|
struct PackedArrayRefBase {
|
|
|
|
SafeRefCount refcount;
|
|
|
|
_FORCE_INLINE_ PackedArrayRefBase *reference() {
|
|
|
|
if (this->refcount.ref()) {
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static _FORCE_INLINE_ PackedArrayRefBase *reference_from(PackedArrayRefBase *p_base, PackedArrayRefBase *p_from) {
|
|
|
|
if (p_base == p_from) {
|
|
|
|
return p_base; //same thing, do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_from->reference()) {
|
|
|
|
if (p_base->refcount.unref()) {
|
|
|
|
memdelete(p_base);
|
|
|
|
}
|
|
|
|
return p_from;
|
|
|
|
} else {
|
|
|
|
return p_base; //keep, could not reference new
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static _FORCE_INLINE_ void destroy(PackedArrayRefBase *p_array) {
|
|
|
|
if (p_array->refcount.unref()) {
|
|
|
|
memdelete(p_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ virtual ~PackedArrayRefBase() {} //needs virtual destructor, but make inline
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct PackedArrayRef : public PackedArrayRefBase {
|
|
|
|
Vector<T> array;
|
|
|
|
static _FORCE_INLINE_ PackedArrayRef<T> *create() {
|
|
|
|
return memnew(PackedArrayRef<T>);
|
|
|
|
}
|
|
|
|
static _FORCE_INLINE_ PackedArrayRef<T> *create(const Vector<T> &p_from) {
|
|
|
|
return memnew(PackedArrayRef<T>(p_from));
|
|
|
|
}
|
|
|
|
|
|
|
|
static _FORCE_INLINE_ const Vector<T> &get_array(PackedArrayRefBase *p_base) {
|
|
|
|
return static_cast<PackedArrayRef<T> *>(p_base)->array;
|
|
|
|
}
|
|
|
|
static _FORCE_INLINE_ Vector<T> *get_array_ptr(const PackedArrayRefBase *p_base) {
|
|
|
|
return &const_cast<PackedArrayRef<T> *>(static_cast<const PackedArrayRef<T> *>(p_base))->array;
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ PackedArrayRef(const Vector<T> &p_from) {
|
|
|
|
array = p_from;
|
|
|
|
refcount.init();
|
|
|
|
}
|
|
|
|
_FORCE_INLINE_ PackedArrayRef() {
|
|
|
|
refcount.init();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* end of array helpers */
|
2020-02-13 20:03:10 +01:00
|
|
|
_ALWAYS_INLINE_ ObjData &_get_obj();
|
|
|
|
_ALWAYS_INLINE_ const ObjData &_get_obj() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
union {
|
|
|
|
bool _bool;
|
2017-01-09 00:58:39 +01:00
|
|
|
int64_t _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 19:20:53 +01:00
|
|
|
double _float;
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D *_transform2d;
|
2017-11-17 03:09:00 +01:00
|
|
|
::AABB *_aabb;
|
2017-01-11 04:52:51 +01:00
|
|
|
Basis *_basis;
|
2016-03-09 00:00:52 +01:00
|
|
|
Transform *_transform;
|
2020-02-23 22:01:26 +01:00
|
|
|
PackedArrayRefBase *packed_array;
|
2014-02-10 02:10:30 +01:00
|
|
|
void *_ptr; //generic pointer
|
2017-03-05 16:44:50 +01:00
|
|
|
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)];
|
2020-05-03 00:42:04 +02:00
|
|
|
} _data alignas(8);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void reference(const Variant &p_variant);
|
2014-02-10 02:10:30 +01:00
|
|
|
void clear();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-02-23 22:01:26 +01:00
|
|
|
_FORCE_INLINE_ Type get_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
static String get_type_name(Variant::Type p_type);
|
2015-05-04 23:30:57 +02:00
|
|
|
static bool can_convert(Type p_type_from, Type p_type_to);
|
|
|
|
static bool can_convert_strict(Type p_type_from, Type p_type_to);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
bool is_ref() const;
|
2020-02-23 22:01:26 +01:00
|
|
|
_FORCE_INLINE_ bool is_num() const {
|
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 19:20:53 +01:00
|
|
|
return type == INT || type == FLOAT;
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2020-02-23 22:01:26 +01:00
|
|
|
_FORCE_INLINE_ bool is_array() const {
|
|
|
|
return type >= ARRAY;
|
2020-05-19 15:46:49 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
bool is_shared() const;
|
|
|
|
bool is_zero() const;
|
2015-06-29 05:29:49 +02:00
|
|
|
bool is_one() const;
|
2020-02-13 20:03:10 +01:00
|
|
|
bool is_null() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
operator bool() const;
|
|
|
|
operator signed int() const;
|
|
|
|
operator unsigned int() const; // this is the real one
|
|
|
|
operator signed short() const;
|
|
|
|
operator unsigned short() const;
|
|
|
|
operator signed char() const;
|
|
|
|
operator unsigned char() const;
|
|
|
|
//operator long unsigned int() const;
|
|
|
|
operator int64_t() const;
|
|
|
|
operator uint64_t() const;
|
|
|
|
#ifdef NEED_LONG_INT
|
|
|
|
operator signed long() const;
|
|
|
|
operator unsigned long() const;
|
|
|
|
#endif
|
|
|
|
|
2020-02-12 18:24:06 +01:00
|
|
|
operator ObjectID() const;
|
|
|
|
|
2020-07-27 12:43:20 +02:00
|
|
|
operator char32_t() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator float() const;
|
|
|
|
operator double() const;
|
|
|
|
operator String() const;
|
|
|
|
operator StringName() const;
|
|
|
|
operator Vector2() const;
|
2020-02-22 04:26:41 +01:00
|
|
|
operator Vector2i() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Rect2() const;
|
2020-02-22 04:26:41 +01:00
|
|
|
operator Rect2i() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Vector3() const;
|
2020-02-22 04:26:41 +01:00
|
|
|
operator Vector3i() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Plane() const;
|
2017-11-17 03:09:00 +01:00
|
|
|
operator ::AABB() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Quat() const;
|
2017-01-11 04:52:51 +01:00
|
|
|
operator Basis() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Transform() const;
|
2017-01-11 04:52:51 +01:00
|
|
|
operator Transform2D() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
operator Color() const;
|
|
|
|
operator NodePath() const;
|
|
|
|
operator RID() const;
|
2017-05-20 17:38:03 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
operator Object *() const;
|
|
|
|
operator Node *() const;
|
|
|
|
operator Control *() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
operator Callable() const;
|
|
|
|
operator Signal() const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Dictionary() const;
|
|
|
|
operator Array() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Vector<uint8_t>() const;
|
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 19:20:53 +01:00
|
|
|
operator Vector<int32_t>() const;
|
|
|
|
operator Vector<int64_t>() const;
|
|
|
|
operator Vector<float>() const;
|
|
|
|
operator Vector<double>() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Vector<String>() const;
|
|
|
|
operator Vector<Vector3>() const;
|
|
|
|
operator Vector<Color>() const;
|
2020-02-17 22:06:54 +01:00
|
|
|
operator Vector<Plane>() const;
|
|
|
|
operator Vector<Face3>() const;
|
|
|
|
|
|
|
|
operator Vector<Variant>() const;
|
|
|
|
operator Vector<StringName>() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
operator Vector<RID>() const;
|
|
|
|
operator Vector<Vector2>() const;
|
|
|
|
|
|
|
|
// some core type enums to convert to
|
|
|
|
operator Margin() const;
|
|
|
|
operator Orientation() const;
|
|
|
|
|
|
|
|
operator IP_Address() const;
|
|
|
|
|
2020-02-13 20:03:10 +01:00
|
|
|
Object *get_validated_object() const;
|
|
|
|
Object *get_validated_object_with_check(bool &r_previously_freed) const;
|
|
|
|
|
2017-08-06 02:43:10 +02:00
|
|
|
Variant(bool p_bool);
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant(signed int p_int); // real one
|
|
|
|
Variant(unsigned int p_int);
|
|
|
|
#ifdef NEED_LONG_INT
|
|
|
|
Variant(signed long p_long); // real one
|
|
|
|
Variant(unsigned long p_long);
|
2017-03-05 16:44:50 +01:00
|
|
|
//Variant(long unsigned int p_long);
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
|
|
|
Variant(signed short p_short); // real one
|
|
|
|
Variant(unsigned short p_short);
|
|
|
|
Variant(signed char p_char); // real one
|
|
|
|
Variant(unsigned char p_char);
|
2019-06-26 15:08:25 +02:00
|
|
|
Variant(int64_t p_int); // real one
|
|
|
|
Variant(uint64_t p_int);
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant(float p_float);
|
|
|
|
Variant(double p_double);
|
2020-02-12 18:24:06 +01:00
|
|
|
Variant(const ObjectID &p_id);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const String &p_string);
|
|
|
|
Variant(const StringName &p_string);
|
|
|
|
Variant(const char *const p_cstring);
|
2020-07-27 12:43:20 +02:00
|
|
|
Variant(const char32_t *p_wstring);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Vector2 &p_vector2);
|
2020-02-22 04:26:41 +01:00
|
|
|
Variant(const Vector2i &p_vector2i);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Rect2 &p_rect2);
|
2020-02-22 04:26:41 +01:00
|
|
|
Variant(const Rect2i &p_rect2i);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Vector3 &p_vector3);
|
2020-02-22 04:26:41 +01:00
|
|
|
Variant(const Vector3i &p_vector3i);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Plane &p_plane);
|
2017-11-17 03:09:00 +01:00
|
|
|
Variant(const ::AABB &p_aabb);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Quat &p_quat);
|
2019-06-26 15:08:25 +02:00
|
|
|
Variant(const Basis &p_matrix);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Transform2D &p_transform);
|
|
|
|
Variant(const Transform &p_transform);
|
|
|
|
Variant(const Color &p_color);
|
2019-06-26 15:08:25 +02:00
|
|
|
Variant(const NodePath &p_node_path);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const RID &p_rid);
|
|
|
|
Variant(const Object *p_object);
|
2020-02-19 20:27:19 +01:00
|
|
|
Variant(const Callable &p_callable);
|
|
|
|
Variant(const Signal &p_signal);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Dictionary &p_dictionary);
|
|
|
|
|
|
|
|
Variant(const Array &p_array);
|
2020-02-17 22:06:54 +01:00
|
|
|
Variant(const Vector<Plane> &p_array); // helper
|
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 19:20:53 +01:00
|
|
|
Variant(const Vector<uint8_t> &p_byte_array);
|
|
|
|
Variant(const Vector<int32_t> &p_int32_array);
|
|
|
|
Variant(const Vector<int64_t> &p_int64_array);
|
|
|
|
Variant(const Vector<float> &p_float32_array);
|
|
|
|
Variant(const Vector<double> &p_float64_array);
|
2020-02-17 22:06:54 +01:00
|
|
|
Variant(const Vector<String> &p_string_array);
|
|
|
|
Variant(const Vector<Vector3> &p_vector3_array);
|
|
|
|
Variant(const Vector<Color> &p_color_array);
|
|
|
|
Variant(const Vector<Face3> &p_face_array);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
Variant(const Vector<Variant> &p_array);
|
2019-06-26 15:08:25 +02:00
|
|
|
Variant(const Vector<StringName> &p_array);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Vector<RID> &p_array); // helper
|
|
|
|
Variant(const Vector<Vector2> &p_array); // helper
|
|
|
|
|
|
|
|
Variant(const IP_Address &p_address);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-17 02:32:05 +02:00
|
|
|
// If this changes the table in variant_op must be updated
|
2014-02-10 02:10:30 +01:00
|
|
|
enum Operator {
|
|
|
|
|
2018-02-21 17:30:55 +01:00
|
|
|
//comparison
|
2014-02-10 02:10:30 +01:00
|
|
|
OP_EQUAL,
|
|
|
|
OP_NOT_EQUAL,
|
|
|
|
OP_LESS,
|
|
|
|
OP_LESS_EQUAL,
|
|
|
|
OP_GREATER,
|
|
|
|
OP_GREATER_EQUAL,
|
|
|
|
//mathematic
|
|
|
|
OP_ADD,
|
2017-09-17 02:32:05 +02:00
|
|
|
OP_SUBTRACT,
|
2014-02-10 02:10:30 +01:00
|
|
|
OP_MULTIPLY,
|
|
|
|
OP_DIVIDE,
|
|
|
|
OP_NEGATE,
|
2016-10-12 23:43:59 +02:00
|
|
|
OP_POSITIVE,
|
2014-02-10 02:10:30 +01:00
|
|
|
OP_MODULE,
|
|
|
|
OP_STRING_CONCAT,
|
|
|
|
//bitwise
|
|
|
|
OP_SHIFT_LEFT,
|
|
|
|
OP_SHIFT_RIGHT,
|
|
|
|
OP_BIT_AND,
|
|
|
|
OP_BIT_OR,
|
|
|
|
OP_BIT_XOR,
|
|
|
|
OP_BIT_NEGATE,
|
|
|
|
//logic
|
|
|
|
OP_AND,
|
|
|
|
OP_OR,
|
|
|
|
OP_XOR,
|
|
|
|
OP_NOT,
|
|
|
|
//containment
|
|
|
|
OP_IN,
|
|
|
|
OP_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static String get_operator_name(Operator p_op);
|
2017-03-05 16:44:50 +01:00
|
|
|
static void evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b, Variant &r_ret, bool &r_valid);
|
|
|
|
static _FORCE_INLINE_ Variant evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b) {
|
|
|
|
bool valid = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant res;
|
2017-03-05 16:44:50 +01:00
|
|
|
evaluate(p_op, p_a, p_b, res, valid);
|
2014-02-10 02:10:30 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-02-18 04:34:49 +01:00
|
|
|
void zero();
|
2018-03-09 20:16:08 +01:00
|
|
|
Variant duplicate(bool deep = false) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst);
|
|
|
|
static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
void call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, Callable::CallError &r_error);
|
|
|
|
Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant());
|
2016-01-04 13:35:21 +01:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
static String get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce);
|
|
|
|
static String get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce);
|
2016-01-04 13:35:21 +01:00
|
|
|
|
2020-02-19 20:27:19 +01:00
|
|
|
static Variant construct(const Variant::Type, const Variant **p_args, int p_argcount, Callable::CallError &r_error, bool p_strict = true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void get_method_list(List<MethodInfo> *p_list) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
bool has_method(const StringName &p_method) const;
|
|
|
|
static Vector<Variant::Type> get_method_argument_types(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static Vector<Variant> get_method_default_arguments(Variant::Type p_type, const StringName &p_method);
|
2020-04-02 01:20:12 +02:00
|
|
|
static Variant::Type get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return = nullptr);
|
2017-03-05 16:44:50 +01:00
|
|
|
static Vector<StringName> get_method_argument_names(Variant::Type p_type, const StringName &p_method);
|
2017-09-25 22:08:48 +02:00
|
|
|
static bool is_method_const(Variant::Type p_type, const StringName &p_method);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
void set_named(const StringName &p_index, const Variant &p_value, bool *r_valid = nullptr);
|
|
|
|
Variant get_named(const StringName &p_index, bool *r_valid = nullptr) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
void set(const Variant &p_index, const Variant &p_value, bool *r_valid = nullptr);
|
|
|
|
Variant get(const Variant &p_index, bool *r_valid = nullptr) const;
|
|
|
|
bool in(const Variant &p_index, bool *r_valid = nullptr) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool iter_init(Variant &r_iter, bool &r_valid) const;
|
|
|
|
bool iter_next(Variant &r_iter, bool &r_valid) const;
|
|
|
|
Variant iter_get(const Variant &r_iter, bool &r_valid) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
|
|
|
|
//argsVariant call()
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator==(const Variant &p_variant) const;
|
|
|
|
bool operator!=(const Variant &p_variant) const;
|
|
|
|
bool operator<(const Variant &p_variant) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
uint32_t hash() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool hash_compare(const Variant &p_variant) const;
|
2017-09-18 20:02:47 +02:00
|
|
|
bool booleanize() const;
|
2019-04-20 01:57:29 +02:00
|
|
|
String stringify(List<const void *> &stack) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void static_assign(const Variant &p_variant);
|
2014-02-10 02:10:30 +01:00
|
|
|
static void get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list);
|
2017-12-15 16:43:27 +01:00
|
|
|
static void get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants);
|
|
|
|
static bool has_constant(Variant::Type p_type, const StringName &p_value);
|
2020-04-02 01:20:12 +02:00
|
|
|
static Variant get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid = nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
typedef String (*ObjectDeConstruct)(const Variant &p_object, void *ud);
|
|
|
|
typedef void (*ObjectConstruct)(const String &p_text, void *ud, Variant &r_value);
|
2015-02-15 05:19:46 +01:00
|
|
|
|
2015-12-31 04:54:00 +01:00
|
|
|
String get_construct_string() const;
|
2020-04-02 01:20:12 +02:00
|
|
|
static void construct_from_string(const String &p_string, Variant &r_value, ObjectConstruct p_obj_construct = nullptr, void *p_construct_ud = nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void operator=(const Variant &p_variant); // only this is enough for all the other types
|
2020-05-12 17:01:17 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant(const Variant &p_variant);
|
2020-05-12 17:01:17 +02:00
|
|
|
_FORCE_INLINE_ Variant() {}
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ ~Variant() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (type != Variant::NIL) {
|
2020-05-10 12:56:01 +02:00
|
|
|
clear();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//typedef Dictionary Dictionary; no
|
|
|
|
//typedef Array Array;
|
|
|
|
|
|
|
|
Vector<Variant> varray();
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<Variant> varray(const Variant &p_arg1);
|
|
|
|
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2);
|
|
|
|
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3);
|
|
|
|
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4);
|
|
|
|
Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct VariantHasher {
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-02-15 14:41:16 +01:00
|
|
|
struct VariantComparator {
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
|
2017-02-15 14:41:16 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::ObjData &Variant::_get_obj() {
|
|
|
|
return *reinterpret_cast<ObjData *>(&_data._mem[0]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Variant::ObjData &Variant::_get_obj() const {
|
|
|
|
return *reinterpret_cast<const ObjData *>(&_data._mem[0]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String vformat(const String &p_text, const Variant &p1 = Variant(), const Variant &p2 = Variant(), const Variant &p3 = Variant(), const Variant &p4 = Variant(), const Variant &p5 = Variant());
|
2020-03-25 11:10:34 +01:00
|
|
|
|
|
|
|
#endif // VARIANT_H
|