2014-02-10 09:10:30 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* variant.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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 07:50:27 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#ifndef VARIANT_H
|
|
|
|
#define VARIANT_H
|
|
|
|
|
2021-08-14 05:31:57 +08:00
|
|
|
#include "core/input/input_enums.h"
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/io/ip_address.h"
|
|
|
|
#include "core/math/aabb.h"
|
2019-02-09 13:24:02 +08:00
|
|
|
#include "core/math/basis.h"
|
2020-11-08 06:33:38 +08:00
|
|
|
#include "core/math/color.h"
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/math/face3.h"
|
|
|
|
#include "core/math/plane.h"
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
#include "core/math/projection.h"
|
2021-01-20 15:02:02 +08:00
|
|
|
#include "core/math/quaternion.h"
|
2022-02-04 20:28:02 +08:00
|
|
|
#include "core/math/rect2.h"
|
|
|
|
#include "core/math/rect2i.h"
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/math/transform_2d.h"
|
2021-02-27 12:26:56 +08:00
|
|
|
#include "core/math/transform_3d.h"
|
2022-02-04 20:28:02 +08:00
|
|
|
#include "core/math/vector2.h"
|
2022-02-04 22:35:14 +08:00
|
|
|
#include "core/math/vector2i.h"
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/math/vector3.h"
|
2020-02-22 11:26:41 +08:00
|
|
|
#include "core/math/vector3i.h"
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
#include "core/math/vector4.h"
|
|
|
|
#include "core/math/vector4i.h"
|
2020-11-08 06:33:38 +08:00
|
|
|
#include "core/object/object_id.h"
|
2021-08-14 05:31:57 +08:00
|
|
|
#include "core/os/keyboard.h"
|
2020-11-08 06:33:38 +08:00
|
|
|
#include "core/string/node_path.h"
|
|
|
|
#include "core/string/ustring.h"
|
2022-05-20 20:28:44 +08:00
|
|
|
#include "core/templates/paged_allocator.h"
|
2020-11-08 06:33:38 +08:00
|
|
|
#include "core/templates/rid.h"
|
|
|
|
#include "core/variant/array.h"
|
|
|
|
#include "core/variant/callable.h"
|
|
|
|
#include "core/variant/dictionary.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class Object;
|
|
|
|
|
|
|
|
struct PropertyInfo;
|
|
|
|
struct MethodInfo;
|
|
|
|
|
2020-02-18 05:06:54 +08: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-25 02:20:53 +08:00
|
|
|
typedef Vector<int32_t> PackedInt32Array;
|
|
|
|
typedef Vector<int64_t> PackedInt64Array;
|
|
|
|
typedef Vector<float> PackedFloat32Array;
|
|
|
|
typedef Vector<double> PackedFloat64Array;
|
2023-12-19 01:37:43 +08:00
|
|
|
typedef Vector<real_t> PackedRealArray;
|
2020-02-18 05:06:54 +08:00
|
|
|
typedef Vector<String> PackedStringArray;
|
|
|
|
typedef Vector<Vector2> PackedVector2Array;
|
|
|
|
typedef Vector<Vector3> PackedVector3Array;
|
|
|
|
typedef Vector<Color> PackedColorArray;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class Variant {
|
|
|
|
public:
|
2017-09-17 08:32:05 +08:00
|
|
|
// If this changes the table in variant_op must be updated
|
2014-02-10 09:10:30 +08:00
|
|
|
enum Type {
|
2016-03-09 07:00:52 +08:00
|
|
|
NIL,
|
|
|
|
|
|
|
|
// atomic types
|
2014-02-10 09:10:30 +08: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-25 02:20:53 +08:00
|
|
|
FLOAT,
|
2014-02-10 09:10:30 +08:00
|
|
|
STRING,
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
// math types
|
2020-02-25 00:00:40 +08:00
|
|
|
VECTOR2,
|
2020-02-22 11:26:41 +08:00
|
|
|
VECTOR2I,
|
2014-02-10 09:10:30 +08:00
|
|
|
RECT2,
|
2020-02-22 11:26:41 +08:00
|
|
|
RECT2I,
|
2014-02-10 09:10:30 +08:00
|
|
|
VECTOR3,
|
2020-02-22 11:26:41 +08:00
|
|
|
VECTOR3I,
|
2017-01-11 11:52:51 +08:00
|
|
|
TRANSFORM2D,
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
VECTOR4,
|
|
|
|
VECTOR4I,
|
2014-02-10 09:10:30 +08:00
|
|
|
PLANE,
|
2021-01-20 15:02:02 +08:00
|
|
|
QUATERNION,
|
2017-11-17 10:09:00 +08:00
|
|
|
AABB,
|
2017-01-11 11:52:51 +08:00
|
|
|
BASIS,
|
2021-04-28 15:36:08 +08:00
|
|
|
TRANSFORM3D,
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
PROJECTION,
|
2016-03-09 07:00:52 +08:00
|
|
|
|
|
|
|
// misc types
|
2014-02-10 09:10:30 +08:00
|
|
|
COLOR,
|
2020-02-21 05:58:05 +08:00
|
|
|
STRING_NAME,
|
2020-02-25 00:00:40 +08:00
|
|
|
NODE_PATH,
|
2020-11-09 21:53:05 +08:00
|
|
|
RID,
|
2016-03-09 07:00:52 +08:00
|
|
|
OBJECT,
|
2020-02-20 03:27:19 +08:00
|
|
|
CALLABLE,
|
|
|
|
SIGNAL,
|
2017-05-17 18:36:47 +08:00
|
|
|
DICTIONARY,
|
2017-10-20 19:13:26 +08:00
|
|
|
ARRAY,
|
2020-02-25 00:00:40 +08: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-25 02:20:53 +08:00
|
|
|
PACKED_INT32_ARRAY,
|
|
|
|
PACKED_INT64_ARRAY,
|
|
|
|
PACKED_FLOAT32_ARRAY,
|
|
|
|
PACKED_FLOAT64_ARRAY,
|
2020-02-18 05:06:54 +08:00
|
|
|
PACKED_STRING_ARRAY,
|
|
|
|
PACKED_VECTOR2_ARRAY,
|
2020-02-25 00:00:40 +08:00
|
|
|
PACKED_VECTOR3_ARRAY,
|
2020-02-18 05:06:54 +08:00
|
|
|
PACKED_COLOR_ARRAY,
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
VARIANT_MAX
|
2016-03-09 07:00:52 +08:00
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2021-07-30 21:43:01 +08:00
|
|
|
enum {
|
|
|
|
// Maximum recursion depth allowed when serializing variants.
|
|
|
|
MAX_RECURSION_DEPTH = 1024,
|
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
private:
|
2022-05-20 20:28:44 +08:00
|
|
|
struct Pools {
|
|
|
|
union BucketSmall {
|
|
|
|
BucketSmall() {}
|
|
|
|
~BucketSmall() {}
|
|
|
|
Transform2D _transform2d;
|
|
|
|
::AABB _aabb;
|
|
|
|
};
|
2022-08-02 23:27:57 +08:00
|
|
|
union BucketMedium {
|
|
|
|
BucketMedium() {}
|
|
|
|
~BucketMedium() {}
|
|
|
|
Basis _basis;
|
|
|
|
Transform3D _transform3d;
|
|
|
|
};
|
2022-05-20 20:28:44 +08:00
|
|
|
union BucketLarge {
|
|
|
|
BucketLarge() {}
|
|
|
|
~BucketLarge() {}
|
2022-08-02 23:27:57 +08:00
|
|
|
Projection _projection;
|
2022-05-20 20:28:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static PagedAllocator<BucketSmall, true> _bucket_small;
|
2022-08-02 23:27:57 +08:00
|
|
|
static PagedAllocator<BucketMedium, true> _bucket_medium;
|
2022-05-20 20:28:44 +08:00
|
|
|
static PagedAllocator<BucketLarge, true> _bucket_large;
|
|
|
|
};
|
|
|
|
|
2018-10-01 22:46:50 +08:00
|
|
|
friend struct _VariantCall;
|
2020-09-03 02:26:28 +08:00
|
|
|
friend class VariantInternal;
|
2014-02-10 09:10:30 +08: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 07:00:52 +08:00
|
|
|
|
2020-05-12 23:01:17 +08:00
|
|
|
Type type = NIL;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
struct ObjData {
|
2020-02-14 03:03:10 +08:00
|
|
|
ObjectID id;
|
2020-11-24 00:38:46 +08:00
|
|
|
Object *obj = nullptr;
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2020-02-24 05:01:26 +08:00
|
|
|
/* array helpers */
|
|
|
|
struct PackedArrayRefBase {
|
|
|
|
SafeRefCount refcount;
|
|
|
|
_FORCE_INLINE_ PackedArrayRefBase *reference() {
|
2024-01-29 04:51:39 +08:00
|
|
|
if (refcount.ref()) {
|
2020-02-24 05:01:26 +08:00
|
|
|
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 <typename 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-14 03:03:10 +08:00
|
|
|
_ALWAYS_INLINE_ ObjData &_get_obj();
|
|
|
|
_ALWAYS_INLINE_ const ObjData &_get_obj() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
union {
|
|
|
|
bool _bool;
|
2017-01-09 07:58:39 +08: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-25 02:20:53 +08:00
|
|
|
double _float;
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D *_transform2d;
|
2017-11-17 10:09:00 +08:00
|
|
|
::AABB *_aabb;
|
2017-01-11 11:52:51 +08:00
|
|
|
Basis *_basis;
|
2021-04-28 15:36:08 +08:00
|
|
|
Transform3D *_transform3d;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
Projection *_projection;
|
2020-02-24 05:01:26 +08:00
|
|
|
PackedArrayRefBase *packed_array;
|
2014-02-10 09:10:30 +08:00
|
|
|
void *_ptr; //generic pointer
|
2021-07-29 21:53:05 +08:00
|
|
|
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)]{ 0 };
|
2020-05-03 06:42:04 +08:00
|
|
|
} _data alignas(8);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void reference(const Variant &p_variant);
|
2022-02-11 19:30:49 +08:00
|
|
|
static bool initialize_ref(Object *p_object);
|
2020-11-09 11:19:09 +08:00
|
|
|
|
|
|
|
void _clear_internal();
|
|
|
|
|
|
|
|
_FORCE_INLINE_ void clear() {
|
|
|
|
static const bool needs_deinit[Variant::VARIANT_MAX] = {
|
|
|
|
false, //NIL,
|
|
|
|
false, //BOOL,
|
|
|
|
false, //INT,
|
|
|
|
false, //FLOAT,
|
|
|
|
true, //STRING,
|
|
|
|
false, //VECTOR2,
|
|
|
|
false, //VECTOR2I,
|
|
|
|
false, //RECT2,
|
|
|
|
false, //RECT2I,
|
|
|
|
false, //VECTOR3,
|
|
|
|
false, //VECTOR3I,
|
|
|
|
true, //TRANSFORM2D,
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
false, //VECTOR4,
|
|
|
|
false, //VECTOR4I,
|
2020-11-09 11:19:09 +08:00
|
|
|
false, //PLANE,
|
2021-01-20 15:02:02 +08:00
|
|
|
false, //QUATERNION,
|
2020-11-09 11:19:09 +08:00
|
|
|
true, //AABB,
|
|
|
|
true, //BASIS,
|
|
|
|
true, //TRANSFORM,
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
true, //PROJECTION,
|
2020-11-09 11:19:09 +08:00
|
|
|
|
|
|
|
// misc types
|
|
|
|
false, //COLOR,
|
|
|
|
true, //STRING_NAME,
|
|
|
|
true, //NODE_PATH,
|
2020-11-09 21:53:05 +08:00
|
|
|
false, //RID,
|
2020-11-09 11:19:09 +08:00
|
|
|
true, //OBJECT,
|
|
|
|
true, //CALLABLE,
|
|
|
|
true, //SIGNAL,
|
|
|
|
true, //DICTIONARY,
|
|
|
|
true, //ARRAY,
|
|
|
|
|
|
|
|
// typed arrays
|
|
|
|
true, //PACKED_BYTE_ARRAY,
|
|
|
|
true, //PACKED_INT32_ARRAY,
|
|
|
|
true, //PACKED_INT64_ARRAY,
|
|
|
|
true, //PACKED_FLOAT32_ARRAY,
|
|
|
|
true, //PACKED_FLOAT64_ARRAY,
|
|
|
|
true, //PACKED_STRING_ARRAY,
|
|
|
|
true, //PACKED_VECTOR2_ARRAY,
|
|
|
|
true, //PACKED_VECTOR3_ARRAY,
|
|
|
|
true, //PACKED_COLOR_ARRAY,
|
|
|
|
};
|
|
|
|
|
Fix various typos with codespell
Found via `codespell -q 3 -S ./thirdparty,*.po,./DONORS.md -L ackward,ang,ans,ba,beng,cas,childs,childrens,dof,doubleclick,fave,findn,hist,inout,leapyear,lod,nd,numer,ois,ony,paket,seeked,sinc,switchs,te,uint`
2021-07-07 23:17:32 +08:00
|
|
|
if (unlikely(needs_deinit[type])) { // Make it fast for types that don't need deinit.
|
2020-11-09 11:19:09 +08:00
|
|
|
_clear_internal();
|
|
|
|
}
|
|
|
|
type = NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _register_variant_operators();
|
|
|
|
static void _unregister_variant_operators();
|
|
|
|
static void _register_variant_methods();
|
|
|
|
static void _unregister_variant_methods();
|
|
|
|
static void _register_variant_setters_getters();
|
|
|
|
static void _unregister_variant_setters_getters();
|
|
|
|
static void _register_variant_constructors();
|
2021-07-29 21:53:05 +08:00
|
|
|
static void _unregister_variant_destructors();
|
|
|
|
static void _register_variant_destructors();
|
2020-11-09 11:19:09 +08:00
|
|
|
static void _unregister_variant_constructors();
|
2020-11-12 00:16:08 +08:00
|
|
|
static void _register_variant_utility_functions();
|
|
|
|
static void _unregister_variant_utility_functions();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2022-03-09 21:58:40 +08:00
|
|
|
void _variant_call_error(const String &p_method, Callable::CallError &error);
|
|
|
|
|
|
|
|
// Avoid accidental conversion. If you reached this point, it's because you most likely forgot to dereference
|
|
|
|
// a Variant pointer (so add * like this: *variant_pointer).
|
|
|
|
|
|
|
|
Variant(const Variant *) {}
|
|
|
|
Variant(const Variant **) {}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
2020-02-24 05:01:26 +08:00
|
|
|
_FORCE_INLINE_ Type get_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
static String get_type_name(Variant::Type p_type);
|
2015-05-05 05:30:57 +08: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);
|
2022-06-27 23:09:51 +08:00
|
|
|
static bool is_type_shared(Variant::Type p_type);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2021-08-27 03:37:17 +08:00
|
|
|
bool is_ref_counted() const;
|
2020-02-24 05:01:26 +08: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-25 02:20:53 +08:00
|
|
|
return type == INT || type == FLOAT;
|
2020-05-19 21:46:49 +08:00
|
|
|
}
|
2023-11-10 20:29:45 +08:00
|
|
|
_FORCE_INLINE_ bool is_string() const {
|
|
|
|
return type == STRING || type == STRING_NAME;
|
|
|
|
}
|
2020-02-24 05:01:26 +08:00
|
|
|
_FORCE_INLINE_ bool is_array() const {
|
|
|
|
return type >= ARRAY;
|
2020-05-19 21:46:49 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
bool is_shared() const;
|
|
|
|
bool is_zero() const;
|
2015-06-29 11:29:49 +08:00
|
|
|
bool is_one() const;
|
2020-02-14 03:03:10 +08:00
|
|
|
bool is_null() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2021-06-10 03:11:06 +08:00
|
|
|
// Make sure Variant is not implicitly cast when accessing it with bracket notation (GH-49469).
|
|
|
|
Variant &operator[](const Variant &p_key) = delete;
|
|
|
|
const Variant &operator[](const Variant &p_key) const = delete;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
operator bool() const;
|
|
|
|
operator int64_t() const;
|
2024-03-28 22:56:02 +08:00
|
|
|
operator int32_t() const;
|
|
|
|
operator int16_t() const;
|
|
|
|
operator int8_t() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
operator uint64_t() const;
|
2024-03-28 22:56:02 +08:00
|
|
|
operator uint32_t() const;
|
|
|
|
operator uint16_t() const;
|
|
|
|
operator uint8_t() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-02-13 01:24:06 +08:00
|
|
|
operator ObjectID() const;
|
|
|
|
|
2020-07-27 18:43:20 +08:00
|
|
|
operator char32_t() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
operator float() const;
|
|
|
|
operator double() const;
|
|
|
|
operator String() const;
|
|
|
|
operator StringName() const;
|
|
|
|
operator Vector2() const;
|
2020-02-22 11:26:41 +08:00
|
|
|
operator Vector2i() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
operator Rect2() const;
|
2020-02-22 11:26:41 +08:00
|
|
|
operator Rect2i() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
operator Vector3() const;
|
2020-02-22 11:26:41 +08:00
|
|
|
operator Vector3i() const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
operator Vector4() const;
|
|
|
|
operator Vector4i() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
operator Plane() const;
|
2017-11-17 10:09:00 +08:00
|
|
|
operator ::AABB() const;
|
2021-01-20 15:02:02 +08:00
|
|
|
operator Quaternion() const;
|
2017-01-11 11:52:51 +08:00
|
|
|
operator Basis() const;
|
|
|
|
operator Transform2D() const;
|
2021-04-28 15:36:08 +08:00
|
|
|
operator Transform3D() const;
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
operator Projection() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
operator Color() const;
|
|
|
|
operator NodePath() const;
|
2020-11-09 21:53:05 +08:00
|
|
|
operator ::RID() const;
|
2017-05-20 23:38:03 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
operator Object *() const;
|
|
|
|
|
2020-02-20 03:27:19 +08:00
|
|
|
operator Callable() const;
|
|
|
|
operator Signal() const;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
operator Dictionary() const;
|
|
|
|
operator Array() const;
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2022-10-11 05:10:59 +08:00
|
|
|
operator PackedByteArray() const;
|
|
|
|
operator PackedInt32Array() const;
|
|
|
|
operator PackedInt64Array() const;
|
|
|
|
operator PackedFloat32Array() const;
|
|
|
|
operator PackedFloat64Array() const;
|
|
|
|
operator PackedStringArray() const;
|
|
|
|
operator PackedVector3Array() const;
|
|
|
|
operator PackedVector2Array() const;
|
|
|
|
operator PackedColorArray() const;
|
|
|
|
|
|
|
|
operator Vector<::RID>() const;
|
2020-02-18 05:06:54 +08:00
|
|
|
operator Vector<Plane>() const;
|
|
|
|
operator Vector<Face3>() const;
|
|
|
|
operator Vector<Variant>() const;
|
|
|
|
operator Vector<StringName>() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
// some core type enums to convert to
|
2020-12-23 00:24:29 +08:00
|
|
|
operator Side() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
operator Orientation() const;
|
|
|
|
|
2021-05-06 08:48:18 +08:00
|
|
|
operator IPAddress() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-02-14 03:03:10 +08:00
|
|
|
Object *get_validated_object() const;
|
|
|
|
Object *get_validated_object_with_check(bool &r_previously_freed) const;
|
|
|
|
|
2017-08-06 08:43:10 +08:00
|
|
|
Variant(bool p_bool);
|
2024-03-28 22:56:02 +08:00
|
|
|
Variant(int64_t p_int64);
|
|
|
|
Variant(int32_t p_int32);
|
|
|
|
Variant(int16_t p_int16);
|
|
|
|
Variant(int8_t p_int8);
|
|
|
|
Variant(uint64_t p_uint64);
|
|
|
|
Variant(uint32_t p_uint32);
|
|
|
|
Variant(uint16_t p_uint16);
|
|
|
|
Variant(uint8_t p_uint8);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(float p_float);
|
|
|
|
Variant(double p_double);
|
2020-02-13 01:24:06 +08:00
|
|
|
Variant(const ObjectID &p_id);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const String &p_string);
|
|
|
|
Variant(const StringName &p_string);
|
|
|
|
Variant(const char *const p_cstring);
|
2020-07-27 18:43:20 +08:00
|
|
|
Variant(const char32_t *p_wstring);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Vector2 &p_vector2);
|
2020-02-22 11:26:41 +08:00
|
|
|
Variant(const Vector2i &p_vector2i);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Rect2 &p_rect2);
|
2020-02-22 11:26:41 +08:00
|
|
|
Variant(const Rect2i &p_rect2i);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Vector3 &p_vector3);
|
2020-02-22 11:26:41 +08:00
|
|
|
Variant(const Vector3i &p_vector3i);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
Variant(const Vector4 &p_vector4);
|
|
|
|
Variant(const Vector4i &p_vector4i);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Plane &p_plane);
|
2017-11-17 10:09:00 +08:00
|
|
|
Variant(const ::AABB &p_aabb);
|
2021-01-20 15:02:02 +08:00
|
|
|
Variant(const Quaternion &p_quat);
|
2019-06-26 21:08:25 +08:00
|
|
|
Variant(const Basis &p_matrix);
|
2017-01-11 11:52:51 +08:00
|
|
|
Variant(const Transform2D &p_transform);
|
2020-10-17 13:08:21 +08:00
|
|
|
Variant(const Transform3D &p_transform);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 07:11:13 +08:00
|
|
|
Variant(const Projection &p_projection);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Color &p_color);
|
2019-06-26 21:08:25 +08:00
|
|
|
Variant(const NodePath &p_node_path);
|
2020-11-09 21:53:05 +08:00
|
|
|
Variant(const ::RID &p_rid);
|
2016-03-09 07:00:52 +08:00
|
|
|
Variant(const Object *p_object);
|
2020-02-20 03:27:19 +08:00
|
|
|
Variant(const Callable &p_callable);
|
|
|
|
Variant(const Signal &p_signal);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Dictionary &p_dictionary);
|
2017-03-05 23:44:50 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Array &p_array);
|
2022-10-11 05:10:59 +08:00
|
|
|
Variant(const PackedByteArray &p_byte_array);
|
|
|
|
Variant(const PackedInt32Array &p_int32_array);
|
|
|
|
Variant(const PackedInt64Array &p_int64_array);
|
|
|
|
Variant(const PackedFloat32Array &p_float32_array);
|
|
|
|
Variant(const PackedFloat64Array &p_float64_array);
|
|
|
|
Variant(const PackedStringArray &p_string_array);
|
|
|
|
Variant(const PackedVector2Array &p_vector2_array);
|
|
|
|
Variant(const PackedVector3Array &p_vector3_array);
|
|
|
|
Variant(const PackedColorArray &p_color_array);
|
|
|
|
|
|
|
|
Variant(const Vector<::RID> &p_array); // helper
|
2020-02-18 05:06:54 +08:00
|
|
|
Variant(const Vector<Plane> &p_array); // helper
|
|
|
|
Variant(const Vector<Face3> &p_face_array);
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Vector<Variant> &p_array);
|
2019-06-26 21:08:25 +08:00
|
|
|
Variant(const Vector<StringName> &p_array);
|
2017-03-05 23:44:50 +08:00
|
|
|
|
2021-05-06 08:48:18 +08:00
|
|
|
Variant(const IPAddress &p_address);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2021-08-14 05:31:57 +08:00
|
|
|
#define VARIANT_ENUM_CLASS_CONSTRUCTOR(m_enum) \
|
2022-10-17 07:52:54 +08:00
|
|
|
Variant(m_enum p_value) { \
|
2021-08-14 05:31:57 +08:00
|
|
|
type = INT; \
|
|
|
|
_data._int = (int64_t)p_value; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only enum classes that need to be bound need this to be defined.
|
2022-10-02 10:53:46 +08:00
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(EulerOrder)
|
2021-08-14 05:31:57 +08:00
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyAxis)
|
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyButton)
|
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(Key)
|
2023-08-03 21:18:26 +08:00
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(KeyLocation)
|
2021-08-14 05:31:57 +08:00
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(MIDIMessage)
|
|
|
|
VARIANT_ENUM_CLASS_CONSTRUCTOR(MouseButton)
|
|
|
|
|
|
|
|
#undef VARIANT_ENUM_CLASS_CONSTRUCTOR
|
|
|
|
|
2017-09-17 08:32:05 +08:00
|
|
|
// If this changes the table in variant_op must be updated
|
2014-02-10 09:10:30 +08:00
|
|
|
enum Operator {
|
2018-02-22 00:30:55 +08:00
|
|
|
//comparison
|
2014-02-10 09:10:30 +08:00
|
|
|
OP_EQUAL,
|
|
|
|
OP_NOT_EQUAL,
|
|
|
|
OP_LESS,
|
|
|
|
OP_LESS_EQUAL,
|
|
|
|
OP_GREATER,
|
|
|
|
OP_GREATER_EQUAL,
|
|
|
|
//mathematic
|
|
|
|
OP_ADD,
|
2017-09-17 08:32:05 +08:00
|
|
|
OP_SUBTRACT,
|
2014-02-10 09:10:30 +08:00
|
|
|
OP_MULTIPLY,
|
|
|
|
OP_DIVIDE,
|
|
|
|
OP_NEGATE,
|
2016-10-13 05:43:59 +08:00
|
|
|
OP_POSITIVE,
|
2014-02-10 09:10:30 +08:00
|
|
|
OP_MODULE,
|
2022-03-08 01:25:21 +08:00
|
|
|
OP_POWER,
|
2014-02-10 09:10:30 +08:00
|
|
|
//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);
|
|
|
|
static void evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b, Variant &r_ret, bool &r_valid);
|
2014-12-09 02:47:45 +08:00
|
|
|
static _FORCE_INLINE_ Variant evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b) {
|
2014-02-10 09:10:30 +08:00
|
|
|
bool valid = true;
|
|
|
|
Variant res;
|
|
|
|
evaluate(p_op, p_a, p_b, res, valid);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-11-10 01:11:15 +08:00
|
|
|
static Variant::Type get_operator_return_type(Operator p_operator, Type p_type_a, Type p_type_b);
|
2020-11-05 10:01:55 +08:00
|
|
|
typedef void (*ValidatedOperatorEvaluator)(const Variant *left, const Variant *right, Variant *r_ret);
|
|
|
|
static ValidatedOperatorEvaluator get_validated_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b);
|
|
|
|
typedef void (*PTROperatorEvaluator)(const void *left, const void *right, void *r_ret);
|
|
|
|
static PTROperatorEvaluator get_ptr_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b);
|
|
|
|
|
2016-02-18 11:34:49 +08:00
|
|
|
void zero();
|
2020-02-01 14:04:14 +08:00
|
|
|
Variant duplicate(bool p_deep = false) const;
|
|
|
|
Variant recursive_duplicate(bool p_deep, int recursion_count) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
/* Built-In Methods */
|
2020-10-14 02:59:37 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
typedef void (*ValidatedBuiltInMethod)(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret);
|
|
|
|
typedef void (*PTRBuiltInMethod)(void *p_base, const void **p_args, void *r_ret, int p_argcount);
|
2020-10-14 02:59:37 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
static bool has_builtin_method(Variant::Type p_type, const StringName &p_method);
|
|
|
|
|
|
|
|
static ValidatedBuiltInMethod get_validated_builtin_method(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static PTRBuiltInMethod get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method);
|
2020-10-14 02:59:37 +08:00
|
|
|
|
2023-09-25 04:33:28 +08:00
|
|
|
static MethodInfo get_builtin_method_info(Variant::Type p_type, const StringName &p_method);
|
2020-11-12 00:16:08 +08:00
|
|
|
static int get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static Variant::Type get_builtin_method_argument_type(Variant::Type p_type, const StringName &p_method, int p_argument);
|
|
|
|
static String get_builtin_method_argument_name(Variant::Type p_type, const StringName &p_method, int p_argument);
|
|
|
|
static Vector<Variant> get_builtin_method_default_arguments(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static bool has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static Variant::Type get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static bool is_builtin_method_const(Variant::Type p_type, const StringName &p_method);
|
2021-02-24 21:56:34 +08:00
|
|
|
static bool is_builtin_method_static(Variant::Type p_type, const StringName &p_method);
|
2020-11-12 00:16:08 +08:00
|
|
|
static bool is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method);
|
|
|
|
static void get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list);
|
2020-12-27 22:09:06 +08:00
|
|
|
static int get_builtin_method_count(Variant::Type p_type);
|
2021-06-19 23:58:49 +08:00
|
|
|
static uint32_t get_builtin_method_hash(Variant::Type p_type, const StringName &p_method);
|
2020-10-14 02:59:37 +08:00
|
|
|
|
2022-03-09 21:58:40 +08:00
|
|
|
void callp(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error);
|
|
|
|
|
|
|
|
template <typename... VarArgs>
|
|
|
|
Variant call(const StringName &p_method, VarArgs... p_args) {
|
|
|
|
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
|
|
|
const Variant *argptrs[sizeof...(p_args) + 1];
|
|
|
|
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
|
|
|
argptrs[i] = &args[i];
|
|
|
|
}
|
|
|
|
Callable::CallError cerr;
|
|
|
|
Variant ret;
|
|
|
|
callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), ret, cerr);
|
|
|
|
if (cerr.error != Callable::CallError::CALL_OK) {
|
|
|
|
_variant_call_error(p_method, cerr);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-04 20:35:21 +08:00
|
|
|
|
2022-06-28 04:10:04 +08:00
|
|
|
void call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error);
|
2021-02-24 21:56:34 +08:00
|
|
|
static void call_static(Variant::Type p_type, const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error);
|
|
|
|
|
2020-11-11 05:31:33 +08:00
|
|
|
static String get_call_error_text(const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce);
|
2020-02-20 03:27:19 +08: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 20:35:21 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
//dynamic (includes Object)
|
|
|
|
void get_method_list(List<MethodInfo> *p_list) const;
|
|
|
|
bool has_method(const StringName &p_method) const;
|
|
|
|
|
|
|
|
/* Constructors */
|
|
|
|
|
2020-12-11 04:12:02 +08:00
|
|
|
typedef void (*ValidatedConstructor)(Variant *r_base, const Variant **p_args);
|
2020-11-09 11:19:09 +08:00
|
|
|
typedef void (*PTRConstructor)(void *base, const void **p_args);
|
|
|
|
|
|
|
|
static int get_constructor_count(Variant::Type p_type);
|
|
|
|
static ValidatedConstructor get_validated_constructor(Variant::Type p_type, int p_constructor);
|
|
|
|
static PTRConstructor get_ptr_constructor(Variant::Type p_type, int p_constructor);
|
|
|
|
static int get_constructor_argument_count(Variant::Type p_type, int p_constructor);
|
|
|
|
static Variant::Type get_constructor_argument_type(Variant::Type p_type, int p_constructor, int p_argument);
|
|
|
|
static String get_constructor_argument_name(Variant::Type p_type, int p_constructor, int p_argument);
|
|
|
|
static void construct(Variant::Type, Variant &base, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
|
|
|
|
|
|
|
|
static void get_constructor_list(Type p_type, List<MethodInfo> *r_list); //convenience
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2021-07-29 21:53:05 +08:00
|
|
|
/* Destructors */
|
|
|
|
|
|
|
|
// Only ptrcall is available.
|
|
|
|
typedef void (*PTRDestructor)(void *base);
|
|
|
|
|
|
|
|
static PTRDestructor get_ptr_destructor(Variant::Type p_type);
|
|
|
|
static bool has_destructor(Variant::Type p_type);
|
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
/* Properties */
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-11-07 09:29:22 +08:00
|
|
|
void set_named(const StringName &p_member, const Variant &p_value, bool &r_valid);
|
|
|
|
Variant get_named(const StringName &p_member, bool &r_valid) const;
|
|
|
|
|
|
|
|
typedef void (*ValidatedSetter)(Variant *base, const Variant *value);
|
|
|
|
typedef void (*ValidatedGetter)(const Variant *base, Variant *value);
|
|
|
|
|
|
|
|
static bool has_member(Variant::Type p_type, const StringName &p_member);
|
|
|
|
static Variant::Type get_member_type(Variant::Type p_type, const StringName &p_member);
|
|
|
|
static void get_member_list(Type p_type, List<StringName> *r_members);
|
2020-12-27 22:09:06 +08:00
|
|
|
static int get_member_count(Type p_type);
|
2020-11-07 09:29:22 +08:00
|
|
|
|
|
|
|
static ValidatedSetter get_member_validated_setter(Variant::Type p_type, const StringName &p_member);
|
|
|
|
static ValidatedGetter get_member_validated_getter(Variant::Type p_type, const StringName &p_member);
|
|
|
|
|
|
|
|
typedef void (*PTRSetter)(void *base, const void *value);
|
|
|
|
typedef void (*PTRGetter)(const void *base, void *value);
|
|
|
|
|
|
|
|
static PTRSetter get_member_ptr_setter(Variant::Type p_type, const StringName &p_member);
|
|
|
|
static PTRGetter get_member_ptr_getter(Variant::Type p_type, const StringName &p_member);
|
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
/* Indexing */
|
|
|
|
|
2020-11-07 09:29:22 +08:00
|
|
|
static bool has_indexing(Variant::Type p_type);
|
|
|
|
static Variant::Type get_indexed_element_type(Variant::Type p_type);
|
2023-01-19 04:57:47 +08:00
|
|
|
static uint32_t get_indexed_element_usage(Variant::Type p_type);
|
2020-11-07 09:29:22 +08:00
|
|
|
|
2020-12-11 04:12:02 +08:00
|
|
|
typedef void (*ValidatedIndexedSetter)(Variant *base, int64_t index, const Variant *value, bool *oob);
|
|
|
|
typedef void (*ValidatedIndexedGetter)(const Variant *base, int64_t index, Variant *value, bool *oob);
|
2020-11-07 09:29:22 +08:00
|
|
|
|
|
|
|
static ValidatedIndexedSetter get_member_validated_indexed_setter(Variant::Type p_type);
|
|
|
|
static ValidatedIndexedGetter get_member_validated_indexed_getter(Variant::Type p_type);
|
|
|
|
|
|
|
|
typedef void (*PTRIndexedSetter)(void *base, int64_t index, const void *value);
|
|
|
|
typedef void (*PTRIndexedGetter)(const void *base, int64_t index, void *value);
|
|
|
|
|
|
|
|
static PTRIndexedSetter get_member_ptr_indexed_setter(Variant::Type p_type);
|
|
|
|
static PTRIndexedGetter get_member_ptr_indexed_getter(Variant::Type p_type);
|
|
|
|
|
|
|
|
void set_indexed(int64_t p_index, const Variant &p_value, bool &r_valid, bool &r_oob);
|
|
|
|
Variant get_indexed(int64_t p_index, bool &r_valid, bool &r_oob) const;
|
|
|
|
|
|
|
|
uint64_t get_indexed_size() const;
|
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
/* Keying */
|
|
|
|
|
2020-11-07 09:29:22 +08:00
|
|
|
static bool is_keyed(Variant::Type p_type);
|
|
|
|
|
2020-12-11 04:12:02 +08:00
|
|
|
typedef void (*ValidatedKeyedSetter)(Variant *base, const Variant *key, const Variant *value, bool *valid);
|
|
|
|
typedef void (*ValidatedKeyedGetter)(const Variant *base, const Variant *key, Variant *value, bool *valid);
|
|
|
|
typedef bool (*ValidatedKeyedChecker)(const Variant *base, const Variant *key, bool *valid);
|
2020-11-07 09:29:22 +08:00
|
|
|
|
|
|
|
static ValidatedKeyedSetter get_member_validated_keyed_setter(Variant::Type p_type);
|
|
|
|
static ValidatedKeyedGetter get_member_validated_keyed_getter(Variant::Type p_type);
|
|
|
|
static ValidatedKeyedChecker get_member_validated_keyed_checker(Variant::Type p_type);
|
|
|
|
|
|
|
|
typedef void (*PTRKeyedSetter)(void *base, const void *key, const void *value);
|
|
|
|
typedef void (*PTRKeyedGetter)(const void *base, const void *key, void *value);
|
2021-06-19 23:58:49 +08:00
|
|
|
typedef uint32_t (*PTRKeyedChecker)(const void *base, const void *key);
|
2020-11-07 09:29:22 +08:00
|
|
|
|
|
|
|
static PTRKeyedSetter get_member_ptr_keyed_setter(Variant::Type p_type);
|
|
|
|
static PTRKeyedGetter get_member_ptr_keyed_getter(Variant::Type p_type);
|
|
|
|
static PTRKeyedChecker get_member_ptr_keyed_checker(Variant::Type p_type);
|
|
|
|
|
|
|
|
void set_keyed(const Variant &p_key, const Variant &p_value, bool &r_valid);
|
|
|
|
Variant get_keyed(const Variant &p_key, bool &r_valid) const;
|
|
|
|
bool has_key(const Variant &p_key, bool &r_valid) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
/* Generic */
|
2022-10-06 02:49:35 +08:00
|
|
|
enum VariantSetError {
|
|
|
|
SET_OK,
|
|
|
|
SET_KEYED_ERR,
|
|
|
|
SET_NAMED_ERR,
|
|
|
|
SET_INDEXED_ERR
|
|
|
|
};
|
|
|
|
enum VariantGetError {
|
|
|
|
GET_OK,
|
|
|
|
GET_KEYED_ERR,
|
|
|
|
GET_NAMED_ERR,
|
|
|
|
GET_INDEXED_ERR
|
|
|
|
};
|
|
|
|
void set(const Variant &p_index, const Variant &p_value, bool *r_valid = nullptr, VariantSetError *err_code = nullptr);
|
|
|
|
Variant get(const Variant &p_index, bool *r_valid = nullptr, VariantGetError *err_code = nullptr) const;
|
2020-04-02 07:20:12 +08:00
|
|
|
bool in(const Variant &p_index, bool *r_valid = nullptr) const;
|
2014-02-10 09:10:30 +08: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;
|
|
|
|
|
|
|
|
void get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
static void call_utility_function(const StringName &p_name, Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
|
|
|
|
static bool has_utility_function(const StringName &p_name);
|
2020-11-11 05:31:33 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
typedef void (*ValidatedUtilityFunction)(Variant *r_ret, const Variant **p_args, int p_argcount);
|
|
|
|
typedef void (*PTRUtilityFunction)(void *r_ret, const void **p_args, int p_argcount);
|
2020-11-11 05:31:33 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
static ValidatedUtilityFunction get_validated_utility_function(const StringName &p_name);
|
|
|
|
static PTRUtilityFunction get_ptr_utility_function(const StringName &p_name);
|
2020-11-11 05:31:33 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
enum UtilityFunctionType {
|
|
|
|
UTILITY_FUNC_TYPE_MATH,
|
|
|
|
UTILITY_FUNC_TYPE_RANDOM,
|
|
|
|
UTILITY_FUNC_TYPE_GENERAL,
|
2020-11-11 05:31:33 +08:00
|
|
|
};
|
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
static UtilityFunctionType get_utility_function_type(const StringName &p_name);
|
2020-11-11 05:31:33 +08:00
|
|
|
|
2021-10-11 03:22:07 +08:00
|
|
|
static MethodInfo get_utility_function_info(const StringName &p_name);
|
2020-11-12 00:16:08 +08:00
|
|
|
static int get_utility_function_argument_count(const StringName &p_name);
|
|
|
|
static Variant::Type get_utility_function_argument_type(const StringName &p_name, int p_arg);
|
|
|
|
static String get_utility_function_argument_name(const StringName &p_name, int p_arg);
|
|
|
|
static bool has_utility_function_return_value(const StringName &p_name);
|
|
|
|
static Variant::Type get_utility_function_return_type(const StringName &p_name);
|
|
|
|
static bool is_utility_function_vararg(const StringName &p_name);
|
2021-06-19 23:58:49 +08:00
|
|
|
static uint32_t get_utility_function_hash(const StringName &p_name);
|
2020-11-11 05:31:33 +08:00
|
|
|
|
2020-11-12 00:16:08 +08:00
|
|
|
static void get_utility_function_list(List<StringName> *r_functions);
|
2020-12-27 22:09:06 +08:00
|
|
|
static int get_utility_function_count();
|
2020-11-11 05:31:33 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
//argsVariant call()
|
|
|
|
|
2015-05-01 08:53:41 +08:00
|
|
|
bool operator==(const Variant &p_variant) const;
|
2016-01-03 07:17:31 +08:00
|
|
|
bool operator!=(const Variant &p_variant) const;
|
2015-05-01 08:53:41 +08:00
|
|
|
bool operator<(const Variant &p_variant) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
uint32_t hash() const;
|
2020-02-01 14:04:14 +08:00
|
|
|
uint32_t recursive_hash(int recursion_count) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2023-03-08 11:13:00 +08:00
|
|
|
// By default, performs a semantic comparison. Otherwise, numeric/binary comparison (if appropriate).
|
|
|
|
bool hash_compare(const Variant &p_variant, int recursion_count = 0, bool semantic_comparison = true) const;
|
2023-01-21 03:36:52 +08:00
|
|
|
bool identity_compare(const Variant &p_variant) const;
|
2017-09-19 02:02:47 +08:00
|
|
|
bool booleanize() const;
|
2020-02-01 14:04:14 +08:00
|
|
|
String stringify(int recursion_count = 0) const;
|
2020-12-30 02:12:33 +08:00
|
|
|
String to_json_string() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void static_assign(const Variant &p_variant);
|
2017-12-15 23:43:27 +08:00
|
|
|
static void get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants);
|
2020-12-27 22:09:06 +08:00
|
|
|
static int get_constants_count_for_type(Variant::Type p_type);
|
2017-12-15 23:43:27 +08:00
|
|
|
static bool has_constant(Variant::Type p_type, const StringName &p_value);
|
2020-04-02 07:20:12 +08:00
|
|
|
static Variant get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid = nullptr);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2022-04-19 02:17:03 +08:00
|
|
|
static void get_enums_for_type(Variant::Type p_type, List<StringName> *p_enums);
|
2021-08-02 03:47:20 +08:00
|
|
|
static void get_enumerations_for_enum(Variant::Type p_type, const StringName &p_enum_name, List<StringName> *p_enumerations);
|
|
|
|
static int get_enum_value(Variant::Type p_type, const StringName &p_enum_name, const StringName &p_enumeration, bool *r_valid = nullptr);
|
2022-04-19 02:17:03 +08:00
|
|
|
|
2015-02-15 12:19:46 +08:00
|
|
|
typedef String (*ObjectDeConstruct)(const Variant &p_object, void *ud);
|
|
|
|
typedef void (*ObjectConstruct)(const String &p_text, void *ud, Variant &r_value);
|
|
|
|
|
2015-12-31 11:54:00 +08:00
|
|
|
String get_construct_string() const;
|
2020-04-02 07:20:12 +08: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 09:10:30 +08:00
|
|
|
|
|
|
|
void operator=(const Variant &p_variant); // only this is enough for all the other types
|
2020-05-12 23:01:17 +08:00
|
|
|
|
2020-11-09 11:19:09 +08:00
|
|
|
static void register_types();
|
|
|
|
static void unregister_types();
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant(const Variant &p_variant);
|
2020-05-12 23:01:17 +08:00
|
|
|
_FORCE_INLINE_ Variant() {}
|
2014-02-10 09:10:30 +08:00
|
|
|
_FORCE_INLINE_ ~Variant() {
|
2020-11-09 11:19:09 +08:00
|
|
|
clear();
|
2017-03-05 23:44:50 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//typedef Dictionary Dictionary; no
|
|
|
|
//typedef Array Array;
|
|
|
|
|
|
|
|
Vector<Variant> varray();
|
|
|
|
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);
|
|
|
|
|
|
|
|
struct VariantHasher {
|
|
|
|
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
|
|
|
|
};
|
|
|
|
|
2017-02-15 21:41:16 +08:00
|
|
|
struct VariantComparator {
|
|
|
|
static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2022-12-06 10:46:47 +08:00
|
|
|
struct StringLikeVariantComparator {
|
|
|
|
static bool compare(const Variant &p_lhs, const Variant &p_rhs);
|
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Variant::ObjData &Variant::_get_obj() {
|
|
|
|
return *reinterpret_cast<ObjData *>(&_data._mem[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Variant::ObjData &Variant::_get_obj() const {
|
|
|
|
return *reinterpret_cast<const ObjData *>(&_data._mem[0]);
|
|
|
|
}
|
|
|
|
|
2022-09-14 04:27:10 +08:00
|
|
|
template <typename... VarArgs>
|
|
|
|
String vformat(const String &p_text, const VarArgs... p_args) {
|
|
|
|
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
|
|
|
Array args_array;
|
|
|
|
args_array.resize(sizeof...(p_args));
|
|
|
|
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
|
|
|
args_array[i] = args[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
String fmt = p_text.sprintf(args_array, &error);
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V_MSG(error, String(), fmt);
|
|
|
|
|
|
|
|
return fmt;
|
|
|
|
}
|
2020-03-25 18:10:34 +08:00
|
|
|
|
2023-07-11 22:18:10 +08:00
|
|
|
template <typename... VarArgs>
|
|
|
|
Variant Callable::call(VarArgs... p_args) const {
|
|
|
|
Variant args[sizeof...(p_args) + 1] = { p_args..., 0 }; // +1 makes sure zero sized arrays are also supported.
|
|
|
|
const Variant *argptrs[sizeof...(p_args) + 1];
|
|
|
|
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
|
|
|
argptrs[i] = &args[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant ret;
|
|
|
|
CallError ce;
|
|
|
|
callp(sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), ret, ce);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-29 04:56:41 +08:00
|
|
|
template <typename... VarArgs>
|
2024-01-31 14:38:11 +08:00
|
|
|
Callable Callable::bind(VarArgs... p_args) const {
|
2022-07-29 04:56:41 +08:00
|
|
|
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
|
|
|
|
const Variant *argptrs[sizeof...(p_args) + 1];
|
|
|
|
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
|
|
|
|
argptrs[i] = &args[i];
|
|
|
|
}
|
|
|
|
return bindp(sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
|
|
|
|
}
|
|
|
|
|
2020-03-25 18:10:34 +08:00
|
|
|
#endif // VARIANT_H
|