2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* variant.cpp */
/*************************************************************************/
/* 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
/*************************************************************************/
2022-01-03 21:27:34 +01:00
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 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
# include "variant.h"
2017-01-16 08:04:19 +01:00
2018-09-11 18:13:45 +02:00
# include "core/core_string_names.h"
2020-02-27 03:30:20 +01:00
# include "core/debugger/engine_debugger.h"
2020-12-29 19:12:33 +01:00
# include "core/io/json.h"
2018-09-11 18:13:45 +02:00
# include "core/io/marshalls.h"
2020-11-07 23:33:38 +01:00
# include "core/io/resource.h"
2018-09-11 18:13:45 +02:00
# include "core/math/math_funcs.h"
2020-11-07 23:33:38 +01:00
# include "core/string/print_string.h"
# include "core/variant/variant_parser.h"
2014-02-10 02:10:30 +01:00
2022-05-20 14:28:44 +02:00
PagedAllocator < Variant : : Pools : : BucketSmall , true > Variant : : Pools : : _bucket_small ;
2022-08-02 17:27:57 +02:00
PagedAllocator < Variant : : Pools : : BucketMedium , true > Variant : : Pools : : _bucket_medium ;
2022-05-20 14:28:44 +02:00
PagedAllocator < Variant : : Pools : : BucketLarge , true > Variant : : Pools : : _bucket_large ;
2014-02-10 02:10:30 +01:00
String Variant : : get_type_name ( Variant : : Type p_type ) {
switch ( p_type ) {
case NIL : {
return " Nil " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
2022-10-09 13:29:38 +02:00
// Atomic types.
2014-02-10 02:10:30 +01:00
case BOOL : {
return " bool " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case INT : {
return " int " ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
2014-04-05 23:50:09 +02:00
return " float " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case STRING : {
return " String " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
2022-10-09 13:29:38 +02:00
// Math types.
2014-02-10 02:10:30 +01:00
case VECTOR2 : {
return " Vector2 " ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
return " Vector2i " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case RECT2 : {
return " Rect2 " ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case RECT2I : {
return " Rect2i " ;
2022-10-09 13:29:38 +02:00
}
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
return " Transform2D " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case VECTOR3 : {
return " Vector3 " ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
return " Vector3i " ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case VECTOR4 : {
return " Vector4 " ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case VECTOR4I : {
return " Vector4i " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case PLANE : {
return " Plane " ;
2022-10-09 13:29:38 +02:00
}
2017-11-17 03:09:00 +01:00
case AABB : {
return " AABB " ;
2022-10-09 13:29:38 +02:00
}
2021-01-20 08:02:02 +01:00
case QUATERNION : {
return " Quaternion " ;
2022-10-09 13:29:38 +02:00
}
2017-01-11 04:52:51 +01:00
case BASIS : {
return " Basis " ;
2022-10-09 13:29:38 +02:00
}
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
2020-10-17 07:08:21 +02:00
return " Transform3D " ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case PROJECTION : {
return " Projection " ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
2022-10-09 13:29:38 +02:00
// Miscellaneous types.
2014-02-10 02:10:30 +01:00
case COLOR : {
return " Color " ;
2022-10-09 13:29:38 +02:00
}
2020-11-09 14:53:05 +01:00
case RID : {
2014-02-10 02:10:30 +01:00
return " RID " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case OBJECT : {
return " Object " ;
2022-10-09 13:29:38 +02:00
}
2020-02-19 20:27:19 +01:00
case CALLABLE : {
return " Callable " ;
2022-10-09 13:29:38 +02:00
}
2020-02-19 20:27:19 +01:00
case SIGNAL : {
return " Signal " ;
2022-10-09 13:29:38 +02:00
}
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
return " StringName " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case NODE_PATH : {
return " NodePath " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case DICTIONARY : {
return " Dictionary " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case ARRAY : {
return " Array " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
2022-10-09 13:29:38 +02:00
// Arrays.
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
return " PackedByteArray " ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
return " PackedInt32Array " ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
return " PackedInt64Array " ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT32_ARRAY : {
return " PackedFloat32Array " ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT64_ARRAY : {
return " PackedFloat64Array " ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
return " PackedStringArray " ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
return " PackedVector2Array " ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
return " PackedVector3Array " ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
return " PackedColorArray " ;
2022-10-09 13:29:38 +02:00
}
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
return " " ;
}
bool Variant : : can_convert ( Variant : : Type p_type_from , Variant : : Type p_type_to ) {
2020-05-14 16:41:43 +02:00
if ( p_type_from = = p_type_to ) {
2014-02-10 02:10:30 +01:00
return true ;
2020-05-14 16:41:43 +02:00
}
2022-04-07 12:23:40 +02:00
if ( p_type_to = = NIL ) { //nil can convert to anything
2014-02-10 02:10:30 +01:00
return true ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
if ( p_type_from = = NIL ) {
return ( p_type_to = = OBJECT ) ;
2020-05-19 15:46:49 +02:00
}
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
const Type * valid_types = nullptr ;
const Type * invalid_types = nullptr ;
2014-02-10 02:10:30 +01:00
switch ( p_type_to ) {
case BOOL : {
static const Type valid [ ] = {
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 ,
2015-05-04 23:30:57 +02:00
STRING ,
2014-02-10 02:10:30 +01:00
NIL ,
} ;
valid_types = valid ;
} break ;
case INT : {
static const Type valid [ ] = {
BOOL ,
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
FLOAT ,
2015-05-04 23:30:57 +02:00
STRING ,
2014-02-10 02:10:30 +01:00
NIL ,
} ;
valid_types = valid ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
BOOL ,
INT ,
2015-05-04 23:30:57 +02:00
STRING ,
2014-02-10 02:10:30 +01:00
NIL ,
} ;
valid_types = valid ;
} break ;
case STRING : {
static const Type invalid [ ] = {
OBJECT ,
NIL
} ;
invalid_types = invalid ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR2 : {
static const Type valid [ ] = {
VECTOR2I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case VECTOR2I : {
static const Type valid [ ] = {
VECTOR2 ,
NIL ,
} ;
valid_types = valid ;
} break ;
case RECT2 : {
static const Type valid [ ] = {
RECT2I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case RECT2I : {
static const Type valid [ ] = {
RECT2 ,
NIL ,
} ;
valid_types = valid ;
} break ;
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
2021-04-28 09:36:08 +02:00
TRANSFORM3D ,
2014-02-10 02:10:30 +01:00
NIL
} ;
2015-05-04 23:30:57 +02:00
valid_types = valid ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR3 : {
static const Type valid [ ] = {
VECTOR3I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case VECTOR3I : {
static const Type valid [ ] = {
VECTOR3 ,
NIL ,
} ;
valid_types = valid ;
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 01:11:13 +02:00
} break ;
case VECTOR4 : {
static const Type valid [ ] = {
VECTOR4I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case VECTOR4I : {
static const Type valid [ ] = {
VECTOR4 ,
NIL ,
} ;
valid_types = valid ;
2020-02-22 04:26:41 +01:00
} break ;
2021-01-20 08:02:02 +01:00
case QUATERNION : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
2017-01-11 04:52:51 +01:00
BASIS ,
2014-02-10 02:10:30 +01:00
NIL
} ;
valid_types = valid ;
} break ;
2017-01-11 04:52:51 +01:00
case BASIS : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
2021-01-20 08:02:02 +01:00
QUATERNION ,
2014-02-10 02:10:30 +01:00
NIL
} ;
valid_types = valid ;
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
2017-01-11 04:52:51 +01:00
TRANSFORM2D ,
2021-01-20 08:02:02 +01:00
QUATERNION ,
2017-01-11 04:52:51 +01:00
BASIS ,
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 01:11:13 +02:00
PROJECTION ,
NIL
} ;
valid_types = valid ;
} break ;
case PROJECTION : {
static const Type valid [ ] = {
TRANSFORM3D ,
2014-02-10 02:10:30 +01:00
NIL
} ;
valid_types = valid ;
2016-03-09 00:00:52 +01:00
} break ;
2014-04-10 05:18:27 +02:00
2015-05-04 23:30:57 +02:00
case COLOR : {
static const Type valid [ ] = {
2015-05-27 15:56:57 +02:00
STRING ,
INT ,
2015-05-04 23:30:57 +02:00
NIL ,
} ;
valid_types = valid ;
} break ;
2020-11-09 14:53:05 +01:00
case RID : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
OBJECT ,
NIL
} ;
valid_types = valid ;
} break ;
case OBJECT : {
static const Type valid [ ] = {
NIL
} ;
valid_types = valid ;
} break ;
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
static const Type valid [ ] = {
STRING ,
NIL
} ;
valid_types = valid ;
} break ;
2015-05-04 23:30:57 +02:00
case NODE_PATH : {
static const Type valid [ ] = {
STRING ,
NIL
} ;
valid_types = valid ;
} break ;
case ARRAY : {
static const Type valid [ ] = {
2020-02-17 22:06:54 +01:00
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_COLOR_ARRAY ,
PACKED_VECTOR2_ARRAY ,
PACKED_VECTOR3_ARRAY ,
2015-05-04 23:30:57 +02:00
NIL
} ;
valid_types = valid ;
} break ;
// arrays
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
case PACKED_INT64_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT32_ARRAY : {
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
case PACKED_FLOAT64_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2015-05-04 23:30:57 +02:00
}
if ( valid_types ) {
int i = 0 ;
while ( valid_types [ i ] ! = NIL ) {
2020-05-14 16:41:43 +02:00
if ( p_type_from = = valid_types [ i ] ) {
2015-05-04 23:30:57 +02:00
return true ;
2020-05-14 16:41:43 +02:00
}
2015-05-04 23:30:57 +02:00
i + + ;
}
2016-10-04 12:36:31 +02:00
2015-05-04 23:30:57 +02:00
} else if ( invalid_types ) {
2017-02-15 14:41:16 +01:00
int i = 0 ;
2015-05-04 23:30:57 +02:00
while ( invalid_types [ i ] ! = NIL ) {
2020-05-14 16:41:43 +02:00
if ( p_type_from = = invalid_types [ i ] ) {
2015-05-04 23:30:57 +02:00
return false ;
2020-05-14 16:41:43 +02:00
}
2015-05-04 23:30:57 +02:00
i + + ;
}
2016-10-04 12:36:31 +02:00
return true ;
2015-05-04 23:30:57 +02:00
}
return false ;
}
bool Variant : : can_convert_strict ( Variant : : Type p_type_from , Variant : : Type p_type_to ) {
2020-05-14 16:41:43 +02:00
if ( p_type_from = = p_type_to ) {
2015-05-04 23:30:57 +02:00
return true ;
2020-05-14 16:41:43 +02:00
}
2022-04-07 12:23:40 +02:00
if ( p_type_to = = NIL ) { //nil can convert to anything
2015-05-04 23:30:57 +02:00
return true ;
2020-05-14 16:41:43 +02:00
}
2015-05-04 23:30:57 +02:00
if ( p_type_from = = NIL ) {
return ( p_type_to = = OBJECT ) ;
2020-05-19 15:46:49 +02:00
}
2015-05-04 23:30:57 +02:00
2020-04-02 01:20:12 +02:00
const Type * valid_types = nullptr ;
2015-05-04 23:30:57 +02:00
switch ( p_type_to ) {
case BOOL : {
static const Type valid [ ] = {
2015-05-05 14:53:37 +02:00
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 ,
2015-05-04 23:30:57 +02:00
//STRING,
NIL ,
} ;
valid_types = valid ;
} break ;
case INT : {
static const Type valid [ ] = {
2015-05-05 14:53:37 +02:00
BOOL ,
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
FLOAT ,
2015-05-04 23:30:57 +02:00
//STRING,
NIL ,
} ;
valid_types = valid ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
2015-05-05 14:53:37 +02:00
BOOL ,
2015-05-04 23:30:57 +02:00
INT ,
//STRING,
NIL ,
} ;
valid_types = valid ;
} break ;
case STRING : {
static const Type valid [ ] = {
NODE_PATH ,
2020-02-20 22:58:05 +01:00
STRING_NAME ,
2015-05-04 23:30:57 +02:00
NIL
} ;
valid_types = valid ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR2 : {
static const Type valid [ ] = {
VECTOR2I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case VECTOR2I : {
static const Type valid [ ] = {
VECTOR2 ,
NIL ,
} ;
valid_types = valid ;
} break ;
case RECT2 : {
static const Type valid [ ] = {
RECT2I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case RECT2I : {
static const Type valid [ ] = {
RECT2 ,
NIL ,
} ;
valid_types = valid ;
} break ;
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
2021-04-28 09:36:08 +02:00
TRANSFORM3D ,
2015-05-04 23:30:57 +02:00
NIL
} ;
valid_types = valid ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR3 : {
static const Type valid [ ] = {
VECTOR3I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case VECTOR3I : {
static const Type valid [ ] = {
VECTOR3 ,
NIL ,
} ;
valid_types = valid ;
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 01:11:13 +02:00
} break ;
case VECTOR4 : {
static const Type valid [ ] = {
VECTOR4I ,
NIL ,
} ;
valid_types = valid ;
} break ;
case VECTOR4I : {
static const Type valid [ ] = {
VECTOR4 ,
NIL ,
} ;
valid_types = valid ;
2020-02-22 04:26:41 +01:00
} break ;
2021-01-20 08:02:02 +01:00
case QUATERNION : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
2017-01-11 04:52:51 +01:00
BASIS ,
2015-05-04 23:30:57 +02:00
NIL
} ;
valid_types = valid ;
} break ;
2017-01-11 04:52:51 +01:00
case BASIS : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
2021-01-20 08:02:02 +01:00
QUATERNION ,
2015-05-04 23:30:57 +02:00
NIL
} ;
valid_types = valid ;
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
2015-05-04 23:30:57 +02:00
static const Type valid [ ] = {
2017-01-11 04:52:51 +01:00
TRANSFORM2D ,
2021-01-20 08:02:02 +01:00
QUATERNION ,
2017-01-11 04:52:51 +01:00
BASIS ,
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 01:11:13 +02:00
PROJECTION ,
NIL
} ;
valid_types = valid ;
} break ;
case PROJECTION : {
static const Type valid [ ] = {
TRANSFORM3D ,
2015-05-04 23:30:57 +02:00
NIL
} ;
valid_types = valid ;
} break ;
2014-04-10 05:18:27 +02:00
case COLOR : {
static const Type valid [ ] = {
STRING ,
INT ,
NIL ,
} ;
valid_types = valid ;
} break ;
2020-11-09 14:53:05 +01:00
case RID : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
OBJECT ,
NIL
} ;
valid_types = valid ;
} break ;
case OBJECT : {
static const Type valid [ ] = {
NIL
} ;
valid_types = valid ;
} break ;
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
static const Type valid [ ] = {
STRING ,
NIL
} ;
valid_types = valid ;
} break ;
2014-02-10 02:10:30 +01:00
case NODE_PATH : {
static const Type valid [ ] = {
STRING ,
NIL
} ;
valid_types = valid ;
} break ;
case ARRAY : {
static const Type valid [ ] = {
2020-02-17 22:06:54 +01:00
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_COLOR_ARRAY ,
PACKED_VECTOR2_ARRAY ,
PACKED_VECTOR3_ARRAY ,
2014-02-10 02:10:30 +01:00
NIL
} ;
valid_types = valid ;
} break ;
// arrays
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
case PACKED_FLOAT32_ARRAY : {
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
case PACKED_FLOAT64_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2014-02-10 02:10:30 +01:00
static const Type valid [ ] = {
ARRAY ,
NIL
} ;
valid_types = valid ;
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
if ( valid_types ) {
int i = 0 ;
while ( valid_types [ i ] ! = NIL ) {
2020-05-14 16:41:43 +02:00
if ( p_type_from = = valid_types [ i ] ) {
2014-02-10 02:10:30 +01:00
return true ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
i + + ;
}
}
return false ;
}
bool Variant : : operator = = ( const Variant & p_variant ) const {
2020-02-01 07:04:14 +01:00
return hash_compare ( p_variant ) ;
2014-02-10 02:10:30 +01:00
}
2016-01-03 00:17:31 +01:00
bool Variant : : operator ! = ( const Variant & p_variant ) const {
2020-02-01 07:04:14 +01:00
// Don't use `!hash_compare(p_variant)` given it makes use of OP_EQUAL
2020-05-14 16:41:43 +02:00
if ( type ! = p_variant . type ) { //evaluation of operator== needs to be more strict
2016-01-03 00:17:31 +01:00
return true ;
2020-05-14 16:41:43 +02:00
}
2016-01-03 00:17:31 +01:00
bool v ;
Variant r ;
evaluate ( OP_NOT_EQUAL , * this , p_variant , r , v ) ;
return r ;
}
2015-05-01 02:53:41 +02:00
bool Variant : : operator < ( const Variant & p_variant ) const {
2020-05-14 16:41:43 +02:00
if ( type ! = p_variant . type ) { //if types differ, then order by type first
2015-05-01 02:53:41 +02:00
return type < p_variant . type ;
2020-05-14 16:41:43 +02:00
}
2015-05-01 02:53:41 +02:00
bool v ;
Variant r ;
evaluate ( OP_LESS , * this , p_variant , r , v ) ;
return r ;
}
2014-02-10 02:10:30 +01:00
bool Variant : : is_zero ( ) const {
switch ( type ) {
case NIL : {
return true ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
2022-10-09 13:29:38 +02:00
// Atomic types.
2014-02-10 02:10:30 +01:00
case BOOL : {
2019-06-26 15:08:25 +02:00
return ! ( _data . _bool ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case INT : {
return _data . _int = = 0 ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
return _data . _float = = 0 ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case STRING : {
return * reinterpret_cast < const String * > ( _data . _mem ) = = String ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
2022-10-09 13:29:38 +02:00
// Math types.
2014-02-10 02:10:30 +01:00
case VECTOR2 : {
return * reinterpret_cast < const Vector2 * > ( _data . _mem ) = = Vector2 ( ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
return * reinterpret_cast < const Vector2i * > ( _data . _mem ) = = Vector2i ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case RECT2 : {
return * reinterpret_cast < const Rect2 * > ( _data . _mem ) = = Rect2 ( ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case RECT2I : {
return * reinterpret_cast < const Rect2i * > ( _data . _mem ) = = Rect2i ( ) ;
2022-10-09 13:29:38 +02:00
}
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
return * _data . _transform2d = = Transform2D ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case VECTOR3 : {
return * reinterpret_cast < const Vector3 * > ( _data . _mem ) = = Vector3 ( ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
return * reinterpret_cast < const Vector3i * > ( _data . _mem ) = = Vector3i ( ) ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case VECTOR4 : {
return * reinterpret_cast < const Vector4 * > ( _data . _mem ) = = Vector4 ( ) ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case VECTOR4I : {
return * reinterpret_cast < const Vector4i * > ( _data . _mem ) = = Vector4i ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case PLANE : {
return * reinterpret_cast < const Plane * > ( _data . _mem ) = = Plane ( ) ;
2022-10-09 13:29:38 +02:00
}
2017-11-17 03:09:00 +01:00
case AABB : {
return * _data . _aabb = = : : AABB ( ) ;
2022-10-09 13:29:38 +02:00
}
2021-01-20 08:02:02 +01:00
case QUATERNION : {
return * reinterpret_cast < const Quaternion * > ( _data . _mem ) = = Quaternion ( ) ;
2022-10-09 13:29:38 +02:00
}
2017-01-11 04:52:51 +01:00
case BASIS : {
return * _data . _basis = = Basis ( ) ;
2022-10-09 13:29:38 +02:00
}
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
return * _data . _transform3d = = Transform3D ( ) ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case PROJECTION : {
return * _data . _projection = = Projection ( ) ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
2022-10-09 13:29:38 +02:00
// Miscellaneous types.
2014-02-10 02:10:30 +01:00
case COLOR : {
return * reinterpret_cast < const Color * > ( _data . _mem ) = = Color ( ) ;
2022-10-09 13:29:38 +02:00
}
2020-11-09 14:53:05 +01:00
case RID : {
return * reinterpret_cast < const : : RID * > ( _data . _mem ) = = : : RID ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case OBJECT : {
2020-04-02 01:20:12 +02:00
return _get_obj ( ) . obj = = nullptr ;
2022-10-09 13:29:38 +02:00
}
2020-02-19 20:27:19 +01:00
case CALLABLE : {
return reinterpret_cast < const Callable * > ( _data . _mem ) - > is_null ( ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-19 20:27:19 +01:00
case SIGNAL : {
return reinterpret_cast < const Signal * > ( _data . _mem ) - > is_null ( ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
2022-12-07 04:48:58 +01:00
return * reinterpret_cast < const StringName * > ( _data . _mem ) = = StringName ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case NODE_PATH : {
return reinterpret_cast < const NodePath * > ( _data . _mem ) - > is_empty ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case DICTIONARY : {
2020-12-15 13:04:21 +01:00
return reinterpret_cast < const Dictionary * > ( _data . _mem ) - > is_empty ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case ARRAY : {
2020-12-15 13:04:21 +01:00
return reinterpret_cast < const Array * > ( _data . _mem ) - > is_empty ( ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
2022-10-09 13:29:38 +02:00
// Arrays.
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2020-02-23 22:01:26 +01:00
return PackedArrayRef < uint8_t > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2020-02-23 22:01:26 +01:00
return PackedArrayRef < int32_t > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
return PackedArrayRef < int64_t > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT32_ARRAY : {
return PackedArrayRef < float > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT64_ARRAY : {
return PackedArrayRef < double > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2020-02-23 22:01:26 +01:00
return PackedArrayRef < String > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2020-02-23 22:01:26 +01:00
return PackedArrayRef < Vector2 > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2020-02-23 22:01:26 +01:00
return PackedArrayRef < Vector3 > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2020-02-23 22:01:26 +01:00
return PackedArrayRef < Color > : : get_array ( _data . packed_array ) . size ( ) = = 0 ;
2022-10-09 13:29:38 +02:00
}
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
return false ;
}
2015-06-29 05:29:49 +02:00
bool Variant : : is_one ( ) const {
switch ( type ) {
case NIL : {
return true ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case BOOL : {
2018-10-03 19:40:37 +02:00
return _data . _bool ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case INT : {
return _data . _int = = 1 ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
return _data . _float = = 1 ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case VECTOR2 : {
return * reinterpret_cast < const Vector2 * > ( _data . _mem ) = = Vector2 ( 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
return * reinterpret_cast < const Vector2i * > ( _data . _mem ) = = Vector2i ( 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case RECT2 : {
return * reinterpret_cast < const Rect2 * > ( _data . _mem ) = = Rect2 ( 1 , 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case RECT2I : {
return * reinterpret_cast < const Rect2i * > ( _data . _mem ) = = Rect2i ( 1 , 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case VECTOR3 : {
return * reinterpret_cast < const Vector3 * > ( _data . _mem ) = = Vector3 ( 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
return * reinterpret_cast < const Vector3i * > ( _data . _mem ) = = Vector3i ( 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case VECTOR4 : {
return * reinterpret_cast < const Vector4 * > ( _data . _mem ) = = Vector4 ( 1 , 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
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 01:11:13 +02:00
case VECTOR4I : {
return * reinterpret_cast < const Vector4i * > ( _data . _mem ) = = Vector4i ( 1 , 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case PLANE : {
return * reinterpret_cast < const Plane * > ( _data . _mem ) = = Plane ( 1 , 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
case COLOR : {
return * reinterpret_cast < const Color * > ( _data . _mem ) = = Color ( 1 , 1 , 1 , 1 ) ;
2022-10-09 13:29:38 +02:00
}
2015-06-29 05:29:49 +02:00
2019-04-09 17:08:36 +02:00
default : {
return ! is_zero ( ) ;
}
2015-06-29 05:29:49 +02:00
}
}
2020-02-13 20:03:10 +01:00
bool Variant : : is_null ( ) const {
if ( type = = OBJECT & & _get_obj ( ) . obj ) {
return false ;
} else {
return true ;
}
}
2022-02-11 12:30:49 +01:00
bool Variant : : initialize_ref ( Object * p_object ) {
RefCounted * ref_counted = const_cast < RefCounted * > ( static_cast < const RefCounted * > ( p_object ) ) ;
if ( ! ref_counted - > init_ref ( ) ) {
return false ;
}
return true ;
}
2014-02-10 02:10:30 +01:00
void Variant : : reference ( const Variant & p_variant ) {
2019-09-09 11:39:40 +02:00
switch ( type ) {
case NIL :
case BOOL :
case 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
case FLOAT :
2019-09-09 11:39:40 +02:00
break ;
default :
clear ( ) ;
}
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
type = p_variant . type ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
switch ( p_variant . type ) {
case NIL : {
2022-10-09 13:29:38 +02:00
// None.
2014-02-10 02:10:30 +01:00
} break ;
2016-03-09 00:00:52 +01:00
2022-10-09 13:29:38 +02:00
// Atomic types.
2014-02-10 02:10:30 +01:00
case BOOL : {
_data . _bool = p_variant . _data . _bool ;
} break ;
case INT : {
_data . _int = p_variant . _data . _int ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
_data . _float = p_variant . _data . _float ;
2014-02-10 02:10:30 +01:00
} break ;
case STRING : {
memnew_placement ( _data . _mem , String ( * reinterpret_cast < const String * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2016-03-09 00:00:52 +01:00
2022-10-09 13:29:38 +02:00
// Math types.
2014-02-10 02:10:30 +01:00
case VECTOR2 : {
memnew_placement ( _data . _mem , Vector2 ( * reinterpret_cast < const Vector2 * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
memnew_placement ( _data . _mem , Vector2i ( * reinterpret_cast < const Vector2i * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2014-02-10 02:10:30 +01:00
case RECT2 : {
memnew_placement ( _data . _mem , Rect2 ( * reinterpret_cast < const Rect2 * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2020-02-22 04:26:41 +01:00
case RECT2I : {
memnew_placement ( _data . _mem , Rect2i ( * reinterpret_cast < const Rect2i * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
2022-05-20 14:28:44 +02:00
_data . _transform2d = ( Transform2D * ) Pools : : _bucket_small . alloc ( ) ;
memnew_placement ( _data . _transform2d , Transform2D ( * p_variant . _data . _transform2d ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case VECTOR3 : {
memnew_placement ( _data . _mem , Vector3 ( * reinterpret_cast < const Vector3 * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
memnew_placement ( _data . _mem , Vector3i ( * reinterpret_cast < const Vector3i * > ( p_variant . _data . _mem ) ) ) ;
} break ;
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 01:11:13 +02:00
case VECTOR4 : {
memnew_placement ( _data . _mem , Vector4 ( * reinterpret_cast < const Vector4 * > ( p_variant . _data . _mem ) ) ) ;
} break ;
case VECTOR4I : {
memnew_placement ( _data . _mem , Vector4i ( * reinterpret_cast < const Vector4i * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2014-02-10 02:10:30 +01:00
case PLANE : {
memnew_placement ( _data . _mem , Plane ( * reinterpret_cast < const Plane * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2017-11-17 03:09:00 +01:00
case AABB : {
2022-05-20 14:28:44 +02:00
_data . _aabb = ( : : AABB * ) Pools : : _bucket_small . alloc ( ) ;
memnew_placement ( _data . _aabb , : : AABB ( * p_variant . _data . _aabb ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2021-01-20 08:02:02 +01:00
case QUATERNION : {
memnew_placement ( _data . _mem , Quaternion ( * reinterpret_cast < const Quaternion * > ( p_variant . _data . _mem ) ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2017-01-11 04:52:51 +01:00
case BASIS : {
2022-08-02 17:27:57 +02:00
_data . _basis = ( Basis * ) Pools : : _bucket_medium . alloc ( ) ;
2022-05-20 14:28:44 +02:00
memnew_placement ( _data . _basis , Basis ( * p_variant . _data . _basis ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
2022-08-02 17:27:57 +02:00
_data . _transform3d = ( Transform3D * ) Pools : : _bucket_medium . alloc ( ) ;
2022-05-20 14:28:44 +02:00
memnew_placement ( _data . _transform3d , Transform3D ( * p_variant . _data . _transform3d ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
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 01:11:13 +02:00
case PROJECTION : {
2022-08-02 17:27:57 +02:00
_data . _projection = ( Projection * ) Pools : : _bucket_large . alloc ( ) ;
memnew_placement ( _data . _projection , Projection ( * p_variant . _data . _projection ) ) ;
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 01:11:13 +02:00
} break ;
2016-03-09 00:00:52 +01:00
2022-10-09 13:29:38 +02:00
// Miscellaneous types.
2014-02-10 02:10:30 +01:00
case COLOR : {
memnew_placement ( _data . _mem , Color ( * reinterpret_cast < const Color * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2020-11-09 14:53:05 +01:00
case RID : {
memnew_placement ( _data . _mem , : : RID ( * reinterpret_cast < const : : RID * > ( p_variant . _data . _mem ) ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case OBJECT : {
2020-02-13 20:03:10 +01:00
memnew_placement ( _data . _mem , ObjData ) ;
2021-06-04 18:03:15 +02:00
if ( p_variant . _get_obj ( ) . obj & & p_variant . _get_obj ( ) . id . is_ref_counted ( ) ) {
RefCounted * ref_counted = static_cast < RefCounted * > ( p_variant . _get_obj ( ) . obj ) ;
if ( ! ref_counted - > reference ( ) ) {
2020-02-13 20:03:10 +01:00
_get_obj ( ) . obj = nullptr ;
_get_obj ( ) . id = ObjectID ( ) ;
break ;
}
}
_get_obj ( ) . obj = const_cast < Object * > ( p_variant . _get_obj ( ) . obj ) ;
_get_obj ( ) . id = p_variant . _get_obj ( ) . id ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-19 20:27:19 +01:00
case CALLABLE : {
memnew_placement ( _data . _mem , Callable ( * reinterpret_cast < const Callable * > ( p_variant . _data . _mem ) ) ) ;
} break ;
case SIGNAL : {
memnew_placement ( _data . _mem , Signal ( * reinterpret_cast < const Signal * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
memnew_placement ( _data . _mem , StringName ( * reinterpret_cast < const StringName * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2014-02-10 02:10:30 +01:00
case NODE_PATH : {
memnew_placement ( _data . _mem , NodePath ( * reinterpret_cast < const NodePath * > ( p_variant . _data . _mem ) ) ) ;
} break ;
case DICTIONARY : {
memnew_placement ( _data . _mem , Dictionary ( * reinterpret_cast < const Dictionary * > ( p_variant . _data . _mem ) ) ) ;
} break ;
case ARRAY : {
memnew_placement ( _data . _mem , Array ( * reinterpret_cast < const Array * > ( p_variant . _data . _mem ) ) ) ;
} break ;
2016-03-09 00:00:52 +01:00
2022-10-09 13:29:38 +02:00
// Arrays.
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = static_cast < PackedArrayRef < uint8_t > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < uint8_t > : : create ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = static_cast < PackedArrayRef < int32_t > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < int32_t > : : create ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
_data . packed_array = static_cast < PackedArrayRef < int64_t > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < int64_t > : : create ( ) ;
}
} break ;
case PACKED_FLOAT32_ARRAY : {
_data . packed_array = static_cast < PackedArrayRef < float > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < float > : : create ( ) ;
}
} break ;
case PACKED_FLOAT64_ARRAY : {
_data . packed_array = static_cast < PackedArrayRef < double > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
2020-02-23 22:01:26 +01:00
if ( ! _data . packed_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
_data . packed_array = PackedArrayRef < double > : : create ( ) ;
2020-02-23 22:01:26 +01:00
}
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = static_cast < PackedArrayRef < String > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < String > : : create ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = static_cast < PackedArrayRef < Vector2 > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < Vector2 > : : create ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = static_cast < PackedArrayRef < Vector3 > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < Vector3 > : : create ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = static_cast < PackedArrayRef < Color > * > ( p_variant . _data . packed_array ) - > reference ( ) ;
if ( ! _data . packed_array ) {
_data . packed_array = PackedArrayRef < Color > : : create ( ) ;
}
2014-02-10 02:10:30 +01:00
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
2017-09-19 01:46:48 +02:00
2016-02-18 04:34:49 +01:00
void Variant : : zero ( ) {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
break ;
case BOOL :
this - > _data . _bool = false ;
break ;
case INT :
this - > _data . _int = 0 ;
break ;
case FLOAT :
this - > _data . _float = 0 ;
break ;
2022-10-09 13:29:38 +02:00
2020-05-10 13:00:47 +02:00
case VECTOR2 :
* reinterpret_cast < Vector2 * > ( this - > _data . _mem ) = Vector2 ( ) ;
break ;
case VECTOR2I :
* reinterpret_cast < Vector2i * > ( this - > _data . _mem ) = Vector2i ( ) ;
break ;
case RECT2 :
* reinterpret_cast < Rect2 * > ( this - > _data . _mem ) = Rect2 ( ) ;
break ;
case RECT2I :
* reinterpret_cast < Rect2i * > ( this - > _data . _mem ) = Rect2i ( ) ;
break ;
case VECTOR3 :
* reinterpret_cast < Vector3 * > ( this - > _data . _mem ) = Vector3 ( ) ;
break ;
case VECTOR3I :
* reinterpret_cast < Vector3i * > ( this - > _data . _mem ) = Vector3i ( ) ;
break ;
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 01:11:13 +02:00
case VECTOR4 :
* reinterpret_cast < Vector4 * > ( this - > _data . _mem ) = Vector4 ( ) ;
break ;
case VECTOR4I :
* reinterpret_cast < Vector4i * > ( this - > _data . _mem ) = Vector4i ( ) ;
break ;
2020-05-10 13:00:47 +02:00
case PLANE :
* reinterpret_cast < Plane * > ( this - > _data . _mem ) = Plane ( ) ;
break ;
2021-01-20 08:02:02 +01:00
case QUATERNION :
* reinterpret_cast < Quaternion * > ( this - > _data . _mem ) = Quaternion ( ) ;
2020-05-10 13:00:47 +02:00
break ;
2022-10-09 13:29:38 +02:00
2020-05-10 13:00:47 +02:00
case COLOR :
* reinterpret_cast < Color * > ( this - > _data . _mem ) = Color ( ) ;
break ;
2022-10-09 13:29:38 +02:00
2020-05-10 13:00:47 +02:00
default :
this - > clear ( ) ;
break ;
2016-02-18 04:34:49 +01:00
}
}
2017-09-19 01:46:48 +02:00
2020-11-09 04:19:09 +01:00
void Variant : : _clear_internal ( ) {
2014-02-10 02:10:30 +01:00
switch ( type ) {
case STRING : {
reinterpret_cast < String * > ( _data . _mem ) - > ~ String ( ) ;
} break ;
2022-10-09 13:29:38 +02:00
// Math types.
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
2022-05-20 14:28:44 +02:00
if ( _data . _transform2d ) {
_data . _transform2d - > ~ Transform2D ( ) ;
Pools : : _bucket_small . free ( ( Pools : : BucketSmall * ) _data . _transform2d ) ;
_data . _transform2d = nullptr ;
}
2014-02-10 02:10:30 +01:00
} break ;
2017-11-17 03:09:00 +01:00
case AABB : {
2022-05-20 14:28:44 +02:00
if ( _data . _aabb ) {
_data . _aabb - > ~ AABB ( ) ;
Pools : : _bucket_small . free ( ( Pools : : BucketSmall * ) _data . _aabb ) ;
_data . _aabb = nullptr ;
}
2014-02-10 02:10:30 +01:00
} break ;
2017-01-11 04:52:51 +01:00
case BASIS : {
2022-05-20 14:28:44 +02:00
if ( _data . _basis ) {
_data . _basis - > ~ Basis ( ) ;
2022-08-02 17:27:57 +02:00
Pools : : _bucket_medium . free ( ( Pools : : BucketMedium * ) _data . _basis ) ;
2022-05-20 14:28:44 +02:00
_data . _basis = nullptr ;
}
2014-02-10 02:10:30 +01:00
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
2022-05-20 14:28:44 +02:00
if ( _data . _transform3d ) {
_data . _transform3d - > ~ Transform3D ( ) ;
2022-08-02 17:27:57 +02:00
Pools : : _bucket_medium . free ( ( Pools : : BucketMedium * ) _data . _transform3d ) ;
2022-05-20 14:28:44 +02:00
_data . _transform3d = nullptr ;
}
2014-02-10 02:10:30 +01:00
} break ;
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 01:11:13 +02:00
case PROJECTION : {
2022-08-02 17:27:57 +02:00
if ( _data . _projection ) {
_data . _projection - > ~ Projection ( ) ;
Pools : : _bucket_large . free ( ( Pools : : BucketLarge * ) _data . _projection ) ;
_data . _projection = nullptr ;
}
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 01:11:13 +02:00
} break ;
2022-10-09 13:29:38 +02:00
// Miscellaneous types.
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
reinterpret_cast < StringName * > ( _data . _mem ) - > ~ StringName ( ) ;
} break ;
2014-02-10 02:10:30 +01:00
case NODE_PATH : {
reinterpret_cast < NodePath * > ( _data . _mem ) - > ~ NodePath ( ) ;
} break ;
case OBJECT : {
2021-06-04 18:03:15 +02:00
if ( _get_obj ( ) . id . is_ref_counted ( ) ) {
2022-10-09 13:29:38 +02:00
// We are safe that there is a reference here.
2021-06-04 18:03:15 +02:00
RefCounted * ref_counted = static_cast < RefCounted * > ( _get_obj ( ) . obj ) ;
if ( ref_counted - > unreference ( ) ) {
memdelete ( ref_counted ) ;
2020-02-13 20:03:10 +01:00
}
}
2020-04-02 01:20:12 +02:00
_get_obj ( ) . obj = nullptr ;
2020-02-13 20:03:10 +01:00
_get_obj ( ) . id = ObjectID ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-11-09 14:53:05 +01:00
case RID : {
2022-10-09 13:29:38 +02:00
// Not much need probably.
// HACK: Can't seem to use destructor + scoping operator, so hack.
2020-11-09 14:53:05 +01:00
typedef : : RID RID_Class ;
reinterpret_cast < RID_Class * > ( _data . _mem ) - > ~ RID_Class ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-19 20:27:19 +01:00
case CALLABLE : {
reinterpret_cast < Callable * > ( _data . _mem ) - > ~ Callable ( ) ;
} break ;
case SIGNAL : {
reinterpret_cast < Signal * > ( _data . _mem ) - > ~ Signal ( ) ;
} break ;
2014-02-10 02:10:30 +01:00
case DICTIONARY : {
reinterpret_cast < Dictionary * > ( _data . _mem ) - > ~ Dictionary ( ) ;
} break ;
case ARRAY : {
reinterpret_cast < Array * > ( _data . _mem ) - > ~ Array ( ) ;
} break ;
2022-10-09 13:29:38 +02:00
// Arrays.
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
} break ;
case PACKED_FLOAT32_ARRAY : {
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
} break ;
case PACKED_FLOAT64_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2020-02-23 22:01:26 +01:00
PackedArrayRefBase : : destroy ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
} break ;
2019-04-09 17:08:36 +02:00
default : {
2022-10-09 13:29:38 +02:00
// Not needed, there is no point. The following do not allocate memory:
// VECTOR2, VECTOR3, RECT2, PLANE, QUATERNION, COLOR.
}
2014-02-10 02:10:30 +01:00
}
}
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
Variant : : operator signed int ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator unsigned int ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
Variant : : operator int64_t ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
2020-05-13 11:31:51 +02:00
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
}
}
}
Variant : : operator uint64_t ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
}
}
}
2020-02-12 18:24:06 +01:00
Variant : : operator ObjectID ( ) const {
if ( type = = INT ) {
return ObjectID ( _data . _int ) ;
2020-02-23 10:06:13 +01:00
} else if ( type = = OBJECT ) {
return _get_obj ( ) . id ;
2020-02-12 18:24:06 +01:00
} else {
return ObjectID ( ) ;
}
}
2014-02-10 02:10:30 +01:00
# ifdef NEED_LONG_INT
Variant : : operator signed long ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
2020-07-15 20:30:59 +02:00
return _data . _float ;
2020-05-10 13:00:47 +02:00
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
}
}
return 0 ;
2020-05-19 15:46:49 +02:00
}
2014-02-10 02:10:30 +01:00
Variant : : operator unsigned long ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
2020-07-15 20:30:59 +02:00
return _data . _float ;
2020-05-10 13:00:47 +02:00
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
}
}
return 0 ;
2020-05-19 15:46:49 +02:00
}
2014-02-10 02:10:30 +01:00
# endif
Variant : : operator signed short ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator unsigned short ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator signed char ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator unsigned char ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1 : 0 ;
case INT :
return _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
return operator String ( ) . to_int ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2016-06-19 00:05:23 +02:00
2020-07-27 12:43:20 +02:00
Variant : : operator char32_t ( ) const {
2014-02-10 02:10:30 +01:00
return operator unsigned int ( ) ;
}
2016-06-19 00:05:23 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator float ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1.0 : 0.0 ;
case INT :
return ( float ) _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
2020-07-24 20:07:57 +02:00
return operator String ( ) . to_float ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator double ( ) const {
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
return 0 ;
case BOOL :
return _data . _bool ? 1.0 : 0.0 ;
case INT :
return ( double ) _data . _int ;
case FLOAT :
return _data . _float ;
case STRING :
2020-07-24 20:07:57 +02:00
return operator String ( ) . to_float ( ) ;
2014-02-10 02:10:30 +01:00
default : {
return 0 ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
Variant : : operator StringName ( ) const {
2020-02-20 22:58:05 +01:00
if ( type = = STRING_NAME ) {
return * reinterpret_cast < const StringName * > ( _data . _mem ) ;
} else if ( type = = STRING ) {
return * reinterpret_cast < const String * > ( _data . _mem ) ;
2014-02-10 02:10:30 +01:00
}
2020-02-20 22:58:05 +01:00
return StringName ( ) ;
2014-02-10 02:10:30 +01:00
}
struct _VariantStrPair {
String key ;
String value ;
bool operator < ( const _VariantStrPair & p ) const {
return key < p . key ;
}
} ;
Variant : : operator String ( ) const {
2020-02-01 07:04:14 +01:00
return stringify ( 0 ) ;
2019-04-20 01:57:29 +02:00
}
2022-04-29 04:14:20 +02:00
String stringify_variant_clean ( const Variant p_variant , int recursion_count ) {
String s = p_variant . stringify ( recursion_count ) ;
// Wrap strings in quotes to avoid ambiguity.
switch ( p_variant . get_type ( ) ) {
case Variant : : STRING : {
s = s . c_escape ( ) . quote ( ) ;
} break ;
case Variant : : STRING_NAME : {
s = " & " + s . c_escape ( ) . quote ( ) ;
} break ;
case Variant : : NODE_PATH : {
s = " ^ " + s . c_escape ( ) . quote ( ) ;
} break ;
default : {
} break ;
}
return s ;
}
2021-10-09 05:47:18 +02:00
template < class T >
2020-02-01 07:04:14 +01:00
String stringify_vector ( const T & vec , int recursion_count ) {
2021-10-09 05:47:18 +02:00
String str ( " [ " ) ;
for ( int i = 0 ; i < vec . size ( ) ; i + + ) {
if ( i > 0 ) {
str + = " , " ;
}
2022-04-29 04:14:20 +02:00
str + = stringify_variant_clean ( vec [ i ] , recursion_count ) ;
2021-10-09 05:47:18 +02:00
}
str + = " ] " ;
return str ;
}
2020-02-01 07:04:14 +01:00
String Variant : : stringify ( int recursion_count ) const {
2014-02-10 02:10:30 +01:00
switch ( type ) {
2020-05-10 13:00:47 +02:00
case NIL :
2022-07-25 00:15:20 +02:00
return " <null> " ;
2020-05-10 13:00:47 +02:00
case BOOL :
2021-08-25 08:37:40 +02:00
return _data . _bool ? " true " : " false " ;
2020-05-10 13:00:47 +02:00
case INT :
return itos ( _data . _int ) ;
case FLOAT :
return rtos ( _data . _float ) ;
case STRING :
return * reinterpret_cast < const String * > ( _data . _mem ) ;
case VECTOR2 :
2021-02-25 15:54:50 +01:00
return operator Vector2 ( ) ;
2020-05-10 13:00:47 +02:00
case VECTOR2I :
2021-02-25 15:54:50 +01:00
return operator Vector2i ( ) ;
2020-05-10 13:00:47 +02:00
case RECT2 :
2021-02-25 15:54:50 +01:00
return operator Rect2 ( ) ;
2020-05-10 13:00:47 +02:00
case RECT2I :
2021-02-25 15:54:50 +01:00
return operator Rect2i ( ) ;
case TRANSFORM2D :
return operator Transform2D ( ) ;
2020-05-10 13:00:47 +02:00
case VECTOR3 :
2021-02-25 15:54:50 +01:00
return operator Vector3 ( ) ;
2020-05-10 13:00:47 +02:00
case VECTOR3I :
2021-02-25 15:54:50 +01:00
return operator 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 01:11:13 +02:00
case VECTOR4 :
return operator Vector4 ( ) ;
case VECTOR4I :
return operator Vector4i ( ) ;
2014-02-10 02:10:30 +01:00
case PLANE :
return operator Plane ( ) ;
2020-05-10 13:00:47 +02:00
case AABB :
return operator : : AABB ( ) ;
2021-01-20 08:02:02 +01:00
case QUATERNION :
2021-02-25 15:54:50 +01:00
return operator Quaternion ( ) ;
case BASIS :
return operator Basis ( ) ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D :
2020-10-17 07:08:21 +02:00
return operator 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 01:11:13 +02:00
case PROJECTION :
return operator Projection ( ) ;
2020-05-10 13:00:47 +02:00
case STRING_NAME :
return operator StringName ( ) ;
case NODE_PATH :
return operator NodePath ( ) ;
case COLOR :
2021-02-25 15:54:50 +01:00
return operator Color ( ) ;
2014-02-10 02:10:30 +01:00
case DICTIONARY : {
const Dictionary & d = * reinterpret_cast < const Dictionary * > ( _data . _mem ) ;
2020-02-01 07:04:14 +01:00
if ( recursion_count > MAX_RECURSION ) {
2022-08-18 17:20:55 +02:00
ERR_PRINT ( " Maximum dictionary recursion reached! " ) ;
return " { ... } " ;
2019-04-20 01:57:29 +02:00
}
2022-08-18 17:20:55 +02:00
// Add leading and trailing space to Dictionary printing. This distinguishes it
// from array printing on fonts that have similar-looking {} and [] characters.
String str ( " { " ) ;
2014-02-10 02:10:30 +01:00
List < Variant > keys ;
d . get_key_list ( & keys ) ;
Vector < _VariantStrPair > pairs ;
2020-02-01 07:04:14 +01:00
recursion_count + + ;
for ( List < Variant > : : Element * E = keys . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 02:10:30 +01:00
_VariantStrPair sp ;
2022-04-29 04:14:20 +02:00
sp . key = stringify_variant_clean ( E - > get ( ) , recursion_count ) ;
sp . value = stringify_variant_clean ( d [ E - > get ( ) ] , recursion_count ) ;
2019-04-20 01:57:29 +02:00
2014-02-10 02:10:30 +01:00
pairs . push_back ( sp ) ;
}
for ( int i = 0 ; i < pairs . size ( ) ; i + + ) {
2020-05-14 16:41:43 +02:00
if ( i > 0 ) {
2014-02-10 02:10:30 +01:00
str + = " , " ;
2020-05-14 16:41:43 +02:00
}
2022-08-18 17:20:55 +02:00
str + = pairs [ i ] . key + " : " + pairs [ i ] . value ;
2014-02-10 02:10:30 +01:00
}
2022-08-18 17:20:55 +02:00
str + = " } " ;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
return str ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < Vector2 > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < Vector3 > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
2021-10-09 05:47:18 +02:00
case PACKED_COLOR_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < Color > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < String > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
2021-10-09 05:47:18 +02:00
case PACKED_BYTE_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < uint8_t > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < int32_t > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < int64_t > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT32_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < float > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT64_ARRAY : {
2020-02-01 07:04:14 +01:00
return stringify_vector ( operator Vector < double > ( ) , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case ARRAY : {
Array arr = operator Array ( ) ;
2020-02-01 07:04:14 +01:00
if ( recursion_count > MAX_RECURSION ) {
2022-08-18 17:20:55 +02:00
ERR_PRINT ( " Maximum array recursion reached! " ) ;
2019-04-20 01:57:29 +02:00
return " [...] " ;
}
2022-04-29 04:14:20 +02:00
return stringify_vector ( arr , recursion_count ) ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
case OBJECT : {
2015-09-04 04:24:55 +02:00
if ( _get_obj ( ) . obj ) {
2021-06-04 18:03:15 +02:00
if ( ! _get_obj ( ) . id . is_ref_counted ( ) & & ObjectDB : : get_instance ( _get_obj ( ) . id ) = = nullptr ) {
2022-07-25 00:15:20 +02:00
return " <Freed Object> " ;
2020-05-19 15:46:49 +02:00
}
2020-02-13 20:03:10 +01:00
2019-04-10 07:07:40 +02:00
return _get_obj ( ) . obj - > to_string ( ) ;
2020-05-14 16:41:43 +02:00
} else {
2022-07-25 00:15:20 +02:00
return " <Object#null> " ;
2020-05-14 16:41:43 +02:00
}
2022-10-09 13:29:38 +02:00
}
2020-02-19 20:27:19 +01:00
case CALLABLE : {
const Callable & c = * reinterpret_cast < const Callable * > ( _data . _mem ) ;
return c ;
2022-10-09 13:29:38 +02:00
}
2020-02-19 20:27:19 +01:00
case SIGNAL : {
const Signal & s = * reinterpret_cast < const Signal * > ( _data . _mem ) ;
return s ;
2022-10-09 13:29:38 +02:00
}
2020-11-09 14:53:05 +01:00
case RID : {
const : : RID & s = * reinterpret_cast < const : : RID * > ( _data . _mem ) ;
2020-02-19 20:27:19 +01:00
return " RID( " + itos ( s . get_id ( ) ) + " ) " ;
2022-10-09 13:29:38 +02:00
}
2014-02-10 02:10:30 +01:00
default : {
2022-07-25 00:15:20 +02:00
return " < " + get_type_name ( type ) + " > " ;
2016-03-09 00:00:52 +01:00
}
2014-02-10 02:10:30 +01:00
}
}
2020-12-29 19:12:33 +01:00
String Variant : : to_json_string ( ) const {
2022-10-11 00:27:23 +02:00
return JSON : : stringify ( * this ) ;
2020-12-29 19:12:33 +01:00
}
2014-02-10 02:10:30 +01:00
Variant : : operator Vector2 ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = VECTOR2 ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Vector2 * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR2I ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Vector2i * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR3 ) {
2014-02-10 02:10:30 +01:00
return Vector2 ( reinterpret_cast < const Vector3 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3 * > ( _data . _mem ) - > y ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR3I ) {
2020-02-22 04:26:41 +01:00
return Vector2 ( reinterpret_cast < const Vector3i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3i * > ( _data . _mem ) - > y ) ;
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 01:11:13 +02:00
} else if ( type = = VECTOR4 ) {
return Vector2 ( reinterpret_cast < const Vector4 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4 * > ( _data . _mem ) - > y ) ;
} else if ( type = = VECTOR4I ) {
return Vector2 ( reinterpret_cast < const Vector4i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4i * > ( _data . _mem ) - > y ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return Vector2 ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-22 04:26:41 +01:00
Variant : : operator Vector2i ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = VECTOR2I ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Vector2i * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR2 ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Vector2 * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR3 ) {
2020-02-22 04:26:41 +01:00
return Vector2 ( reinterpret_cast < const Vector3 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3 * > ( _data . _mem ) - > y ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR3I ) {
2020-02-22 04:26:41 +01:00
return Vector2 ( reinterpret_cast < const Vector3i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3i * > ( _data . _mem ) - > y ) ;
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 01:11:13 +02:00
} else if ( type = = VECTOR4 ) {
return Vector2 ( reinterpret_cast < const Vector4 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4 * > ( _data . _mem ) - > y ) ;
} else if ( type = = VECTOR4I ) {
return Vector2 ( reinterpret_cast < const Vector4i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4i * > ( _data . _mem ) - > y ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-02-22 04:26:41 +01:00
return Vector2i ( ) ;
2020-05-14 16:41:43 +02:00
}
2020-02-22 04:26:41 +01:00
}
2014-02-10 02:10:30 +01:00
Variant : : operator Rect2 ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = RECT2 ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Rect2 * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = RECT2I ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Rect2i * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return Rect2 ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-22 04:26:41 +01:00
Variant : : operator Rect2i ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = RECT2I ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Rect2i * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = RECT2 ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Rect2 * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-02-22 04:26:41 +01:00
return Rect2i ( ) ;
2020-05-14 16:41:43 +02:00
}
2020-02-22 04:26:41 +01:00
}
2014-02-10 02:10:30 +01:00
Variant : : operator Vector3 ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = VECTOR3 ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Vector3 * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR3I ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Vector3i * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR2 ) {
2018-02-21 13:38:21 +01:00
return Vector3 ( reinterpret_cast < const Vector2 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2 * > ( _data . _mem ) - > y , 0.0 ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR2I ) {
2020-02-22 04:26:41 +01:00
return Vector3 ( reinterpret_cast < const Vector2i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2i * > ( _data . _mem ) - > y , 0.0 ) ;
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 01:11:13 +02:00
} else if ( type = = VECTOR4 ) {
return Vector3 ( reinterpret_cast < const Vector4 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4 * > ( _data . _mem ) - > y , reinterpret_cast < const Vector4 * > ( _data . _mem ) - > z ) ;
} else if ( type = = VECTOR4I ) {
return Vector3 ( reinterpret_cast < const Vector4i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4i * > ( _data . _mem ) - > y , reinterpret_cast < const Vector4i * > ( _data . _mem ) - > z ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return Vector3 ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-22 04:26:41 +01:00
Variant : : operator Vector3i ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = VECTOR3I ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Vector3i * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR3 ) {
2020-02-22 04:26:41 +01:00
return * reinterpret_cast < const Vector3 * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR2 ) {
2020-02-22 04:26:41 +01:00
return Vector3i ( reinterpret_cast < const Vector2 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2 * > ( _data . _mem ) - > y , 0.0 ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = VECTOR2I ) {
2020-02-22 04:26:41 +01:00
return Vector3i ( reinterpret_cast < const Vector2i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2i * > ( _data . _mem ) - > y , 0.0 ) ;
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 01:11:13 +02:00
} else if ( type = = VECTOR4 ) {
return Vector3i ( reinterpret_cast < const Vector4 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4 * > ( _data . _mem ) - > y , reinterpret_cast < const Vector4 * > ( _data . _mem ) - > z ) ;
} else if ( type = = VECTOR4I ) {
return Vector3i ( reinterpret_cast < const Vector4i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector4i * > ( _data . _mem ) - > y , reinterpret_cast < const Vector4i * > ( _data . _mem ) - > z ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-02-22 04:26:41 +01:00
return Vector3i ( ) ;
2020-05-14 16:41:43 +02:00
}
2020-02-22 04:26:41 +01:00
}
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 01:11:13 +02:00
Variant : : operator Vector4 ( ) const {
if ( type = = VECTOR4 ) {
return * reinterpret_cast < const Vector4 * > ( _data . _mem ) ;
} else if ( type = = VECTOR4I ) {
return * reinterpret_cast < const Vector4i * > ( _data . _mem ) ;
} else if ( type = = VECTOR2 ) {
return Vector4 ( reinterpret_cast < const Vector2 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2 * > ( _data . _mem ) - > y , 0.0 , 0.0 ) ;
} else if ( type = = VECTOR2I ) {
return Vector4 ( reinterpret_cast < const Vector2i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2i * > ( _data . _mem ) - > y , 0.0 , 0.0 ) ;
} else if ( type = = VECTOR3 ) {
return Vector4 ( reinterpret_cast < const Vector3 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3 * > ( _data . _mem ) - > y , reinterpret_cast < const Vector3 * > ( _data . _mem ) - > z , 0.0 ) ;
} else if ( type = = VECTOR3I ) {
return Vector4 ( reinterpret_cast < const Vector3i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3i * > ( _data . _mem ) - > y , reinterpret_cast < const Vector3i * > ( _data . _mem ) - > z , 0.0 ) ;
} else {
return Vector4 ( ) ;
}
}
Variant : : operator Vector4i ( ) const {
if ( type = = VECTOR4I ) {
return * reinterpret_cast < const Vector4i * > ( _data . _mem ) ;
} else if ( type = = VECTOR4 ) {
const Vector4 & v4 = * reinterpret_cast < const Vector4 * > ( _data . _mem ) ;
return Vector4i ( v4 . x , v4 . y , v4 . z , v4 . w ) ;
} else if ( type = = VECTOR2 ) {
return Vector4i ( reinterpret_cast < const Vector2 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2 * > ( _data . _mem ) - > y , 0.0 , 0.0 ) ;
} else if ( type = = VECTOR2I ) {
return Vector4i ( reinterpret_cast < const Vector2i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector2i * > ( _data . _mem ) - > y , 0.0 , 0.0 ) ;
} else if ( type = = VECTOR3 ) {
return Vector4i ( reinterpret_cast < const Vector3 * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3 * > ( _data . _mem ) - > y , reinterpret_cast < const Vector3 * > ( _data . _mem ) - > z , 0.0 ) ;
} else if ( type = = VECTOR3I ) {
return Vector4i ( reinterpret_cast < const Vector3i * > ( _data . _mem ) - > x , reinterpret_cast < const Vector3i * > ( _data . _mem ) - > y , reinterpret_cast < const Vector3i * > ( _data . _mem ) - > z , 0.0 ) ;
} else {
return Vector4i ( ) ;
}
}
2014-02-10 02:10:30 +01:00
Variant : : operator Plane ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PLANE ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Plane * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return Plane ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2017-11-17 03:09:00 +01:00
Variant : : operator : : AABB ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = AABB ) {
2017-11-17 03:09:00 +01:00
return * _data . _aabb ;
2020-05-14 16:41:43 +02:00
} else {
2017-11-17 03:09:00 +01:00
return : : AABB ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2017-01-11 04:52:51 +01:00
Variant : : operator Basis ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = BASIS ) {
2017-01-11 04:52:51 +01:00
return * _data . _basis ;
2021-01-20 08:02:02 +01:00
} else if ( type = = QUATERNION ) {
return * reinterpret_cast < const Quaternion * > ( _data . _mem ) ;
2021-04-28 09:36:08 +02:00
} else if ( type = = TRANSFORM3D ) { // unexposed in Variant::can_convert?
return _data . _transform3d - > basis ;
2020-05-14 16:41:43 +02:00
} else {
2017-01-11 04:52:51 +01:00
return Basis ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2021-01-20 08:02:02 +01:00
Variant : : operator Quaternion ( ) const {
if ( type = = QUATERNION ) {
return * reinterpret_cast < const Quaternion * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = BASIS ) {
2017-01-11 04:52:51 +01:00
return * _data . _basis ;
2021-04-28 09:36:08 +02:00
} else if ( type = = TRANSFORM3D ) {
return _data . _transform3d - > basis ;
2020-05-14 16:41:43 +02:00
} else {
2021-01-20 08:02:02 +01:00
return Quaternion ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-10-17 07:08:21 +02:00
Variant : : operator Transform3D ( ) const {
2021-04-28 09:36:08 +02:00
if ( type = = TRANSFORM3D ) {
return * _data . _transform3d ;
2020-05-14 16:41:43 +02:00
} else if ( type = = BASIS ) {
2020-10-17 07:08:21 +02:00
return Transform3D ( * _data . _basis , Vector3 ( ) ) ;
2021-01-20 08:02:02 +01:00
} else if ( type = = QUATERNION ) {
return Transform3D ( Basis ( * reinterpret_cast < const Quaternion * > ( _data . _mem ) ) , Vector3 ( ) ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = TRANSFORM2D ) {
2018-11-26 05:57:40 +01:00
const Transform2D & t = * _data . _transform2d ;
2020-10-17 07:08:21 +02:00
Transform3D m ;
2022-04-25 00:07:35 +02:00
m . basis . rows [ 0 ] [ 0 ] = t . columns [ 0 ] [ 0 ] ;
m . basis . rows [ 1 ] [ 0 ] = t . columns [ 0 ] [ 1 ] ;
m . basis . rows [ 0 ] [ 1 ] = t . columns [ 1 ] [ 0 ] ;
m . basis . rows [ 1 ] [ 1 ] = t . columns [ 1 ] [ 1 ] ;
2022-04-24 23:59:24 +02:00
m . origin [ 0 ] = t . columns [ 2 ] [ 0 ] ;
m . origin [ 1 ] = t . columns [ 2 ] [ 1 ] ;
2018-11-26 05:57:40 +01:00
return m ;
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 01:11:13 +02:00
} else if ( type = = PROJECTION ) {
return * _data . _projection ;
2020-05-14 16:41:43 +02:00
} else {
2020-10-17 07:08:21 +02:00
return Transform3D ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
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 01:11:13 +02:00
Variant : : operator Projection ( ) const {
if ( type = = TRANSFORM3D ) {
return * _data . _transform3d ;
} else if ( type = = BASIS ) {
return Transform3D ( * _data . _basis , Vector3 ( ) ) ;
} else if ( type = = QUATERNION ) {
return Transform3D ( Basis ( * reinterpret_cast < const Quaternion * > ( _data . _mem ) ) , Vector3 ( ) ) ;
} else if ( type = = TRANSFORM2D ) {
const Transform2D & t = * _data . _transform2d ;
Transform3D m ;
m . basis . rows [ 0 ] [ 0 ] = t . columns [ 0 ] [ 0 ] ;
m . basis . rows [ 1 ] [ 0 ] = t . columns [ 0 ] [ 1 ] ;
m . basis . rows [ 0 ] [ 1 ] = t . columns [ 1 ] [ 0 ] ;
m . basis . rows [ 1 ] [ 1 ] = t . columns [ 1 ] [ 1 ] ;
m . origin [ 0 ] = t . columns [ 2 ] [ 0 ] ;
m . origin [ 1 ] = t . columns [ 2 ] [ 1 ] ;
return m ;
} else if ( type = = PROJECTION ) {
return * _data . _projection ;
} else {
return Projection ( ) ;
}
}
2017-01-11 04:52:51 +01:00
Variant : : operator Transform2D ( ) const {
if ( type = = TRANSFORM2D ) {
return * _data . _transform2d ;
2021-04-28 09:36:08 +02:00
} else if ( type = = TRANSFORM3D ) {
const Transform3D & t = * _data . _transform3d ;
2017-01-11 04:52:51 +01:00
Transform2D m ;
2022-04-25 00:07:35 +02:00
m . columns [ 0 ] [ 0 ] = t . basis . rows [ 0 ] [ 0 ] ;
m . columns [ 0 ] [ 1 ] = t . basis . rows [ 1 ] [ 0 ] ;
m . columns [ 1 ] [ 0 ] = t . basis . rows [ 0 ] [ 1 ] ;
m . columns [ 1 ] [ 1 ] = t . basis . rows [ 1 ] [ 1 ] ;
2022-04-24 23:59:24 +02:00
m . columns [ 2 ] [ 0 ] = t . origin [ 0 ] ;
m . columns [ 2 ] [ 1 ] = t . origin [ 1 ] ;
2014-02-10 02:10:30 +01:00
return m ;
2020-05-14 16:41:43 +02:00
} else {
2017-01-11 04:52:51 +01:00
return Transform2D ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
Variant : : operator Color ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = COLOR ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Color * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = STRING ) {
2020-12-06 23:37:34 +01:00
return Color ( operator String ( ) ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = INT ) {
2015-05-27 15:56:57 +02:00
return Color : : hex ( operator int ( ) ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return Color ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
Variant : : operator NodePath ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = NODE_PATH ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const NodePath * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = STRING ) {
2014-02-10 02:10:30 +01:00
return NodePath ( operator String ( ) ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return NodePath ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-11-09 14:53:05 +01:00
Variant : : operator : : RID ( ) const {
if ( type = = RID ) {
return * reinterpret_cast < const : : RID * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else if ( type = = OBJECT & & _get_obj ( ) . obj = = nullptr ) {
2020-11-09 14:53:05 +01:00
return : : RID ( ) ;
2015-04-25 01:45:07 +02:00
} else if ( type = = OBJECT & & _get_obj ( ) . obj ) {
2019-01-26 19:41:26 +01:00
# ifdef DEBUG_ENABLED
2020-02-27 03:30:20 +01:00
if ( EngineDebugger : : is_active ( ) ) {
2020-11-09 14:53:05 +01:00
ERR_FAIL_COND_V_MSG ( ObjectDB : : get_instance ( _get_obj ( ) . id ) = = nullptr , : : RID ( ) , " Invalid pointer (object was freed). " ) ;
2020-05-19 15:46:49 +02:00
}
2019-01-26 19:41:26 +01:00
# endif
2020-02-19 20:27:19 +01:00
Callable : : CallError ce ;
2022-03-09 14:58:40 +01:00
Variant ret = _get_obj ( ) . obj - > callp ( CoreStringNames : : get_singleton ( ) - > get_rid , nullptr , 0 , ce ) ;
2020-11-09 14:53:05 +01:00
if ( ce . error = = Callable : : CallError : : CALL_OK & & ret . get_type ( ) = = Variant : : RID ) {
2015-04-25 01:45:07 +02:00
return ret ;
}
2020-11-09 14:53:05 +01:00
return : : RID ( ) ;
2015-04-25 01:45:07 +02:00
} else {
2020-11-09 14:53:05 +01:00
return : : RID ( ) ;
2015-04-25 01:45:07 +02:00
}
2014-02-10 02:10:30 +01:00
}
Variant : : operator Object * ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = OBJECT ) {
2014-02-10 02:10:30 +01:00
return _get_obj ( ) . obj ;
2020-05-14 16:41:43 +02:00
} else {
2020-04-02 01:20:12 +02:00
return nullptr ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-13 20:03:10 +01:00
Object * Variant : : get_validated_object_with_check ( bool & r_previously_freed ) const {
if ( type = = OBJECT ) {
Object * instance = ObjectDB : : get_instance ( _get_obj ( ) . id ) ;
r_previously_freed = ! instance & & _get_obj ( ) . id ! = ObjectID ( ) ;
return instance ;
} else {
r_previously_freed = false ;
2020-04-02 01:20:12 +02:00
return nullptr ;
2020-02-13 20:03:10 +01:00
}
}
Object * Variant : : get_validated_object ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = OBJECT ) {
2020-02-13 20:03:10 +01:00
return ObjectDB : : get_instance ( _get_obj ( ) . id ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-04-02 01:20:12 +02:00
return nullptr ;
2020-05-14 16:41:43 +02:00
}
2020-02-13 20:03:10 +01:00
}
2014-02-10 02:10:30 +01:00
Variant : : operator Dictionary ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = DICTIONARY ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Dictionary * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return Dictionary ( ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-19 20:27:19 +01:00
Variant : : operator Callable ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = CALLABLE ) {
2020-02-19 20:27:19 +01:00
return * reinterpret_cast < const Callable * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-02-19 20:27:19 +01:00
return Callable ( ) ;
2020-05-14 16:41:43 +02:00
}
2020-02-19 20:27:19 +01:00
}
Variant : : operator Signal ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = SIGNAL ) {
2020-02-19 20:27:19 +01:00
return * reinterpret_cast < const Signal * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2020-02-19 20:27:19 +01:00
return Signal ( ) ;
2020-05-14 16:41:43 +02:00
}
2020-02-19 20:27:19 +01:00
}
2014-02-10 02:10:30 +01:00
template < class DA , class SA >
inline DA _convert_array ( const SA & p_array ) {
DA da ;
da . resize ( p_array . size ( ) ) ;
for ( int i = 0 ; i < p_array . size ( ) ; i + + ) {
da . set ( i , Variant ( p_array . get ( i ) ) ) ;
}
return da ;
}
template < class DA >
inline DA _convert_array_from_variant ( const Variant & p_variant ) {
switch ( p_variant . get_type ( ) ) {
case Variant : : ARRAY : {
return _convert_array < DA , Array > ( p_variant . operator Array ( ) ) ;
}
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_BYTE_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < uint8_t > > ( p_variant . operator Vector < uint8_t > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case Variant : : PACKED_INT32_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < int32_t > > ( p_variant . operator Vector < int32_t > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case Variant : : PACKED_INT64_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < int64_t > > ( p_variant . operator Vector < int64_t > ( ) ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
}
case Variant : : PACKED_FLOAT32_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < float > > ( p_variant . operator Vector < float > ( ) ) ;
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
}
case Variant : : PACKED_FLOAT64_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < double > > ( p_variant . operator Vector < double > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_STRING_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < String > > ( p_variant . operator Vector < String > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_VECTOR2_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < Vector2 > > ( p_variant . operator Vector < Vector2 > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_VECTOR3_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < Vector3 > > ( p_variant . operator Vector < Vector3 > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
2020-02-17 22:06:54 +01:00
case Variant : : PACKED_COLOR_ARRAY : {
2020-03-17 07:33:00 +01:00
return _convert_array < DA , Vector < Color > > ( p_variant . operator Vector < Color > ( ) ) ;
2017-01-11 04:52:51 +01:00
}
2019-04-09 17:08:36 +02:00
default : {
return DA ( ) ;
}
2014-02-10 02:10:30 +01:00
}
}
Variant : : operator Array ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = ARRAY ) {
2014-02-10 02:10:30 +01:00
return * reinterpret_cast < const Array * > ( _data . _mem ) ;
2020-05-14 16:41:43 +02:00
} else {
2014-02-10 02:10:30 +01:00
return _convert_array_from_variant < Array > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < uint8_t > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_BYTE_ARRAY ) {
2020-02-23 22:01:26 +01:00
return static_cast < PackedArrayRef < uint8_t > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < uint8_t > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
Variant : : operator Vector < int32_t > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_INT32_ARRAY ) {
2020-02-23 22:01:26 +01:00
return static_cast < PackedArrayRef < int32_t > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < int > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
Variant : : operator Vector < int64_t > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_INT64_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
return static_cast < PackedArrayRef < int64_t > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < int64_t > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
}
Variant : : operator Vector < float > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_FLOAT32_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
return static_cast < PackedArrayRef < float > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < float > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
}
Variant : : operator Vector < double > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_FLOAT64_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
return static_cast < PackedArrayRef < double > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < double > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < String > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_STRING_ARRAY ) {
2020-02-23 22:01:26 +01:00
return static_cast < PackedArrayRef < String > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < String > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < Vector3 > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_VECTOR3_ARRAY ) {
2020-02-23 22:01:26 +01:00
return static_cast < PackedArrayRef < Vector3 > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < Vector3 > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < Vector2 > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_VECTOR2_ARRAY ) {
2020-02-23 22:01:26 +01:00
return static_cast < PackedArrayRef < Vector2 > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < Vector2 > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < Color > ( ) const {
2020-05-14 16:41:43 +02:00
if ( type = = PACKED_COLOR_ARRAY ) {
2020-02-23 22:01:26 +01:00
return static_cast < PackedArrayRef < Color > * > ( _data . packed_array ) - > array ;
2020-05-14 16:41:43 +02:00
} else {
2020-03-17 07:33:00 +01:00
return _convert_array_from_variant < Vector < Color > > ( * this ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
/* helpers */
2020-11-09 14:53:05 +01:00
Variant : : operator Vector < : : RID > ( ) const {
2014-02-10 02:10:30 +01:00
Array va = operator Array ( ) ;
2020-11-09 14:53:05 +01:00
Vector < : : RID > rids ;
2014-02-10 02:10:30 +01:00
rids . resize ( va . size ( ) ) ;
2020-05-14 16:41:43 +02:00
for ( int i = 0 ; i < rids . size ( ) ; i + + ) {
2018-07-25 03:11:03 +02:00
rids . write [ i ] = va [ i ] ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
return rids ;
}
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < Plane > ( ) const {
2014-02-10 02:10:30 +01:00
Array va = operator Array ( ) ;
2020-02-17 22:06:54 +01:00
Vector < Plane > planes ;
2014-02-10 02:10:30 +01:00
int va_size = va . size ( ) ;
2020-05-14 16:41:43 +02:00
if ( va_size = = 0 ) {
2014-02-10 02:10:30 +01:00
return planes ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
planes . resize ( va_size ) ;
2020-02-17 22:06:54 +01:00
Plane * w = planes . ptrw ( ) ;
2014-02-10 02:10:30 +01:00
2020-05-14 16:41:43 +02:00
for ( int i = 0 ; i < va_size ; i + + ) {
2014-02-10 02:10:30 +01:00
w [ i ] = va [ i ] ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
return planes ;
}
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < Face3 > ( ) const {
Vector < Vector3 > va = operator Vector < Vector3 > ( ) ;
Vector < Face3 > faces ;
2014-02-10 02:10:30 +01:00
int va_size = va . size ( ) ;
2020-05-14 16:41:43 +02:00
if ( va_size = = 0 ) {
2014-02-10 02:10:30 +01:00
return faces ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
faces . resize ( va_size / 3 ) ;
2020-02-17 22:06:54 +01:00
Face3 * w = faces . ptrw ( ) ;
const Vector3 * r = va . ptr ( ) ;
2014-02-10 02:10:30 +01:00
2020-05-14 16:41:43 +02:00
for ( int i = 0 ; i < va_size ; i + + ) {
2014-02-10 02:10:30 +01:00
w [ i / 3 ] . vertex [ i % 3 ] = r [ i ] ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
return faces ;
}
2020-02-17 22:06:54 +01:00
Variant : : operator Vector < Variant > ( ) const {
2014-02-10 02:10:30 +01:00
Array va = operator Array ( ) ;
2020-02-17 22:06:54 +01:00
Vector < Variant > variants ;
2014-02-10 02:10:30 +01:00
int va_size = va . size ( ) ;
2020-05-14 16:41:43 +02:00
if ( va_size = = 0 ) {
2020-02-17 22:06:54 +01:00
return variants ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
2020-02-17 22:06:54 +01:00
variants . resize ( va_size ) ;
Variant * w = variants . ptrw ( ) ;
2020-05-14 16:41:43 +02:00
for ( int i = 0 ; i < va_size ; i + + ) {
2020-02-21 00:35:28 +01:00
w [ i ] = va [ i ] ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
2020-02-17 22:06:54 +01:00
return variants ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2018-06-25 21:21:57 +02:00
Variant : : operator Vector < StringName > ( ) const {
2020-02-17 22:06:54 +01:00
Vector < String > from = operator Vector < String > ( ) ;
2018-06-25 21:21:57 +02:00
Vector < StringName > to ;
int len = from . size ( ) ;
to . resize ( len ) ;
for ( int i = 0 ; i < len ; i + + ) {
2018-07-25 03:11:03 +02:00
to . write [ i ] = from [ i ] ;
2018-06-25 21:21:57 +02:00
}
return to ;
}
2020-12-22 17:24:29 +01:00
Variant : : operator Side ( ) const {
return ( Side ) operator int ( ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : operator Orientation ( ) const {
return ( Orientation ) operator int ( ) ;
}
2021-05-06 02:48:18 +02:00
Variant : : operator IPAddress ( ) 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
if ( type = = PACKED_FLOAT32_ARRAY | | type = = PACKED_INT32_ARRAY | | type = = PACKED_FLOAT64_ARRAY | | type = = PACKED_INT64_ARRAY | | type = = PACKED_BYTE_ARRAY ) {
2020-02-17 22:06:54 +01:00
Vector < int > addr = operator Vector < int > ( ) ;
2014-02-10 02:10:30 +01:00
if ( addr . size ( ) = = 4 ) {
2021-05-06 02:48:18 +02:00
return IPAddress ( addr . get ( 0 ) , addr . get ( 1 ) , addr . get ( 2 ) , addr . get ( 3 ) ) ;
2014-02-10 02:10:30 +01:00
}
}
2021-05-06 02:48:18 +02:00
return IPAddress ( operator String ( ) ) ;
2014-02-10 02:10:30 +01:00
}
Variant : : Variant ( bool p_bool ) {
type = BOOL ;
_data . _bool = p_bool ;
}
Variant : : Variant ( signed int p_int ) {
type = INT ;
_data . _int = p_int ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( unsigned int p_int ) {
type = INT ;
_data . _int = p_int ;
}
# ifdef NEED_LONG_INT
Variant : : Variant ( signed long p_int ) {
type = INT ;
_data . _int = p_int ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( unsigned long p_int ) {
type = INT ;
_data . _int = p_int ;
}
# endif
Variant : : Variant ( int64_t p_int ) {
type = INT ;
_data . _int = p_int ;
}
Variant : : Variant ( uint64_t p_int ) {
type = INT ;
_data . _int = p_int ;
}
Variant : : Variant ( signed short p_short ) {
type = INT ;
_data . _int = p_short ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( unsigned short p_short ) {
type = INT ;
_data . _int = p_short ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( signed char p_char ) {
type = INT ;
_data . _int = p_char ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( unsigned char p_char ) {
type = INT ;
_data . _int = p_char ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( float p_float ) {
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
type = FLOAT ;
_data . _float = p_float ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( double p_double ) {
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
type = FLOAT ;
_data . _float = p_double ;
2014-02-10 02:10:30 +01:00
}
2020-02-12 18:24:06 +01:00
Variant : : Variant ( const ObjectID & p_id ) {
type = INT ;
_data . _int = p_id ;
}
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const StringName & p_string ) {
2020-02-20 22:58:05 +01:00
type = STRING_NAME ;
memnew_placement ( _data . _mem , StringName ( p_string ) ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const String & p_string ) {
type = STRING ;
memnew_placement ( _data . _mem , String ( p_string ) ) ;
}
Variant : : Variant ( const char * const p_cstring ) {
type = STRING ;
memnew_placement ( _data . _mem , String ( ( const char * ) p_cstring ) ) ;
}
2020-07-27 12:43:20 +02:00
Variant : : Variant ( const char32_t * p_wstring ) {
2014-02-10 02:10:30 +01:00
type = STRING ;
memnew_placement ( _data . _mem , String ( p_wstring ) ) ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const Vector3 & p_vector3 ) {
type = VECTOR3 ;
memnew_placement ( _data . _mem , Vector3 ( p_vector3 ) ) ;
}
2020-05-14 14:29:06 +02:00
2020-02-22 04:26:41 +01:00
Variant : : Variant ( const Vector3i & p_vector3i ) {
type = VECTOR3I ;
memnew_placement ( _data . _mem , 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 01:11:13 +02:00
Variant : : Variant ( const Vector4 & p_vector4 ) {
type = VECTOR4 ;
memnew_placement ( _data . _mem , Vector4 ( p_vector4 ) ) ;
}
Variant : : Variant ( const Vector4i & p_vector4i ) {
type = VECTOR4I ;
memnew_placement ( _data . _mem , Vector4i ( p_vector4i ) ) ;
}
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const Vector2 & p_vector2 ) {
type = VECTOR2 ;
memnew_placement ( _data . _mem , Vector2 ( p_vector2 ) ) ;
}
2020-02-22 04:26:41 +01:00
Variant : : Variant ( const Vector2i & p_vector2i ) {
type = VECTOR2I ;
memnew_placement ( _data . _mem , Vector2i ( p_vector2i ) ) ;
}
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const Rect2 & p_rect2 ) {
type = RECT2 ;
memnew_placement ( _data . _mem , Rect2 ( p_rect2 ) ) ;
}
2020-02-22 04:26:41 +01:00
Variant : : Variant ( const Rect2i & p_rect2i ) {
type = RECT2I ;
memnew_placement ( _data . _mem , Rect2i ( p_rect2i ) ) ;
}
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const Plane & p_plane ) {
type = PLANE ;
memnew_placement ( _data . _mem , Plane ( p_plane ) ) ;
}
2020-05-14 14:29:06 +02:00
2017-11-17 03:09:00 +01:00
Variant : : Variant ( const : : AABB & p_aabb ) {
type = AABB ;
2022-05-20 14:28:44 +02:00
_data . _aabb = ( : : AABB * ) Pools : : _bucket_small . alloc ( ) ;
memnew_placement ( _data . _aabb , : : AABB ( p_aabb ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-01-11 04:52:51 +01:00
Variant : : Variant ( const Basis & p_matrix ) {
type = BASIS ;
2022-08-02 17:27:57 +02:00
_data . _basis = ( Basis * ) Pools : : _bucket_medium . alloc ( ) ;
2022-05-20 14:28:44 +02:00
memnew_placement ( _data . _basis , Basis ( p_matrix ) ) ;
2014-02-10 02:10:30 +01:00
}
2021-01-20 08:02:02 +01:00
Variant : : Variant ( const Quaternion & p_quaternion ) {
type = QUATERNION ;
memnew_placement ( _data . _mem , Quaternion ( p_quaternion ) ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-10-17 07:08:21 +02:00
Variant : : Variant ( const Transform3D & p_transform ) {
2021-04-28 09:36:08 +02:00
type = TRANSFORM3D ;
2022-08-02 17:27:57 +02:00
_data . _transform3d = ( Transform3D * ) Pools : : _bucket_medium . alloc ( ) ;
2022-05-20 14:28:44 +02:00
memnew_placement ( _data . _transform3d , Transform3D ( p_transform ) ) ;
2014-02-10 02:10:30 +01:00
}
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 01:11:13 +02:00
Variant : : Variant ( const Projection & pp_projection ) {
type = PROJECTION ;
2022-08-02 17:27:57 +02:00
_data . _projection = ( Projection * ) Pools : : _bucket_large . alloc ( ) ;
memnew_placement ( _data . _projection , Projection ( pp_projection ) ) ;
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 01:11:13 +02:00
}
2017-01-11 04:52:51 +01:00
Variant : : Variant ( const Transform2D & p_transform ) {
type = TRANSFORM2D ;
2022-05-20 14:28:44 +02:00
_data . _transform2d = ( Transform2D * ) Pools : : _bucket_small . alloc ( ) ;
memnew_placement ( _data . _transform2d , Transform2D ( p_transform ) ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const Color & p_color ) {
type = COLOR ;
memnew_placement ( _data . _mem , Color ( p_color ) ) ;
}
Variant : : Variant ( const NodePath & p_node_path ) {
type = NODE_PATH ;
memnew_placement ( _data . _mem , NodePath ( p_node_path ) ) ;
}
2020-11-09 14:53:05 +01:00
Variant : : Variant ( const : : RID & p_rid ) {
type = RID ;
memnew_placement ( _data . _mem , : : RID ( p_rid ) ) ;
2014-02-10 02:10:30 +01:00
}
Variant : : Variant ( const Object * p_object ) {
type = OBJECT ;
memnew_placement ( _data . _mem , ObjData ) ;
2020-02-13 20:03:10 +01:00
if ( p_object ) {
2021-06-04 18:03:15 +02:00
if ( p_object - > is_ref_counted ( ) ) {
RefCounted * ref_counted = const_cast < RefCounted * > ( static_cast < const RefCounted * > ( p_object ) ) ;
if ( ! ref_counted - > init_ref ( ) ) {
2020-02-13 20:03:10 +01:00
_get_obj ( ) . obj = nullptr ;
_get_obj ( ) . id = ObjectID ( ) ;
return ;
}
}
_get_obj ( ) . obj = const_cast < Object * > ( p_object ) ;
_get_obj ( ) . id = p_object - > get_instance_id ( ) ;
} else {
_get_obj ( ) . obj = nullptr ;
_get_obj ( ) . id = ObjectID ( ) ;
}
2014-02-10 02:10:30 +01:00
}
2020-02-19 20:27:19 +01:00
Variant : : Variant ( const Callable & p_callable ) {
type = CALLABLE ;
memnew_placement ( _data . _mem , Callable ( p_callable ) ) ;
}
2020-05-14 14:29:06 +02:00
2020-02-19 20:27:19 +01:00
Variant : : Variant ( const Signal & p_callable ) {
type = SIGNAL ;
memnew_placement ( _data . _mem , Signal ( p_callable ) ) ;
}
2014-02-10 02:10:30 +01:00
Variant : : Variant ( const Dictionary & p_dictionary ) {
type = DICTIONARY ;
2019-07-20 08:09:57 +02:00
memnew_placement ( _data . _mem , Dictionary ( p_dictionary ) ) ;
2014-02-10 02:10:30 +01:00
}
Variant : : Variant ( const Array & p_array ) {
type = ARRAY ;
memnew_placement ( _data . _mem , Array ( p_array ) ) ;
}
Variant : : Variant ( const Vector < Plane > & p_array ) {
type = ARRAY ;
Array * plane_array = memnew_placement ( _data . _mem , Array ) ;
plane_array - > resize ( p_array . size ( ) ) ;
for ( int i = 0 ; i < p_array . size ( ) ; i + + ) {
plane_array - > operator [ ] ( i ) = Variant ( p_array [ i ] ) ;
}
}
2020-11-09 14:53:05 +01:00
Variant : : Variant ( const Vector < : : RID > & p_array ) {
2014-02-10 02:10:30 +01:00
type = ARRAY ;
Array * rid_array = memnew_placement ( _data . _mem , Array ) ;
rid_array - > resize ( p_array . size ( ) ) ;
for ( int i = 0 ; i < p_array . size ( ) ; i + + ) {
rid_array - > set ( i , Variant ( p_array [ i ] ) ) ;
}
}
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 : : Variant ( const Vector < uint8_t > & p_byte_array ) {
2020-02-17 22:06:54 +01:00
type = PACKED_BYTE_ARRAY ;
2020-02-23 22:01:26 +01:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
_data . packed_array = PackedArrayRef < uint8_t > : : create ( p_byte_array ) ;
}
2020-05-14 14:29:06 +02:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
Variant : : Variant ( const Vector < int32_t > & p_int32_array ) {
type = PACKED_INT32_ARRAY ;
_data . packed_array = PackedArrayRef < int32_t > : : create ( p_int32_array ) ;
}
Variant : : Variant ( const Vector < int64_t > & p_int64_array ) {
type = PACKED_INT64_ARRAY ;
_data . packed_array = PackedArrayRef < int64_t > : : create ( p_int64_array ) ;
2014-02-10 02:10:30 +01:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
Variant : : Variant ( const Vector < float > & p_float32_array ) {
type = PACKED_FLOAT32_ARRAY ;
_data . packed_array = PackedArrayRef < float > : : create ( p_float32_array ) ;
2014-02-10 02:10:30 +01:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
Variant : : Variant ( const Vector < double > & p_float64_array ) {
type = PACKED_FLOAT64_ARRAY ;
_data . packed_array = PackedArrayRef < double > : : create ( p_float64_array ) ;
2014-02-10 02:10:30 +01:00
}
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
2020-02-17 22:06:54 +01:00
Variant : : Variant ( const Vector < String > & p_string_array ) {
type = PACKED_STRING_ARRAY ;
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < String > : : create ( p_string_array ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-02-17 22:06:54 +01:00
Variant : : Variant ( const Vector < Vector3 > & p_vector3_array ) {
type = PACKED_VECTOR3_ARRAY ;
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < Vector3 > : : create ( p_vector3_array ) ;
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
Variant : : Variant ( const Vector < Vector2 > & p_vector2_array ) {
type = PACKED_VECTOR2_ARRAY ;
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < Vector2 > : : create ( p_vector2_array ) ;
2014-02-10 02:10:30 +01:00
}
2020-05-14 14:29:06 +02:00
2020-02-17 22:06:54 +01:00
Variant : : Variant ( const Vector < Color > & p_color_array ) {
type = PACKED_COLOR_ARRAY ;
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < Color > : : create ( p_color_array ) ;
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
Variant : : Variant ( const Vector < Face3 > & p_face_array ) {
Vector < Vector3 > vertices ;
2014-02-10 02:10:30 +01:00
int face_count = p_face_array . size ( ) ;
vertices . resize ( face_count * 3 ) ;
if ( face_count ) {
2020-02-17 22:06:54 +01:00
const Face3 * r = p_face_array . ptr ( ) ;
Vector3 * w = vertices . ptrw ( ) ;
2014-02-10 02:10:30 +01:00
for ( int i = 0 ; i < face_count ; i + + ) {
2020-05-14 16:41:43 +02:00
for ( int j = 0 ; j < 3 ; j + + ) {
2014-02-10 02:10:30 +01:00
w [ i * 3 + j ] = r [ i ] . vertex [ j ] ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
}
}
type = NIL ;
* this = vertices ;
}
/* helpers */
Variant : : Variant ( const Vector < Variant > & p_array ) {
type = NIL ;
2020-02-17 22:06:54 +01:00
Array arr ;
arr . resize ( p_array . size ( ) ) ;
for ( int i = 0 ; i < p_array . size ( ) ; i + + ) {
arr [ i ] = p_array [ i ] ;
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
* this = arr ;
2014-02-10 02:10:30 +01:00
}
2020-02-17 22:06:54 +01:00
Variant : : Variant ( const Vector < StringName > & p_array ) {
2014-02-10 02:10:30 +01:00
type = NIL ;
2020-02-17 22:06:54 +01:00
Vector < String > v ;
2014-02-10 02:10:30 +01:00
int len = p_array . size ( ) ;
v . resize ( len ) ;
2020-05-14 16:41:43 +02:00
for ( int i = 0 ; i < len ; i + + ) {
2014-02-10 02:10:30 +01:00
v . set ( i , p_array [ i ] ) ;
2020-05-14 16:41:43 +02:00
}
2014-02-10 02:10:30 +01:00
* this = v ;
}
void Variant : : operator = ( const Variant & p_variant ) {
2020-05-14 16:41:43 +02:00
if ( unlikely ( this = = & p_variant ) ) {
2017-09-19 01:46:48 +02:00
return ;
2020-05-14 16:41:43 +02:00
}
2017-09-19 01:46:48 +02:00
2017-09-20 11:04:50 +02:00
if ( unlikely ( type ! = p_variant . type ) ) {
2017-09-19 01:46:48 +02:00
reference ( p_variant ) ;
return ;
}
switch ( p_variant . type ) {
case NIL : {
// none
} break ;
// atomic types
case BOOL : {
_data . _bool = p_variant . _data . _bool ;
} break ;
case INT : {
_data . _int = p_variant . _data . _int ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
_data . _float = p_variant . _data . _float ;
2017-09-19 01:46:48 +02:00
} break ;
case STRING : {
* reinterpret_cast < String * > ( _data . _mem ) = * reinterpret_cast < const String * > ( p_variant . _data . _mem ) ;
} break ;
2017-11-20 22:41:22 +01:00
// math types
2017-09-19 01:46:48 +02:00
case VECTOR2 : {
* reinterpret_cast < Vector2 * > ( _data . _mem ) = * reinterpret_cast < const Vector2 * > ( p_variant . _data . _mem ) ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
* reinterpret_cast < Vector2i * > ( _data . _mem ) = * reinterpret_cast < const Vector2i * > ( p_variant . _data . _mem ) ;
} break ;
2017-09-19 01:46:48 +02:00
case RECT2 : {
* reinterpret_cast < Rect2 * > ( _data . _mem ) = * reinterpret_cast < const Rect2 * > ( p_variant . _data . _mem ) ;
} break ;
2020-02-22 04:26:41 +01:00
case RECT2I : {
* reinterpret_cast < Rect2i * > ( _data . _mem ) = * reinterpret_cast < const Rect2i * > ( p_variant . _data . _mem ) ;
} break ;
2017-09-19 01:46:48 +02:00
case TRANSFORM2D : {
* _data . _transform2d = * ( p_variant . _data . _transform2d ) ;
} break ;
case VECTOR3 : {
* reinterpret_cast < Vector3 * > ( _data . _mem ) = * reinterpret_cast < const Vector3 * > ( p_variant . _data . _mem ) ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
* reinterpret_cast < Vector3i * > ( _data . _mem ) = * reinterpret_cast < const Vector3i * > ( p_variant . _data . _mem ) ;
} break ;
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 01:11:13 +02:00
case VECTOR4 : {
* reinterpret_cast < Vector4 * > ( _data . _mem ) = * reinterpret_cast < const Vector4 * > ( p_variant . _data . _mem ) ;
} break ;
case VECTOR4I : {
* reinterpret_cast < Vector4i * > ( _data . _mem ) = * reinterpret_cast < const Vector4i * > ( p_variant . _data . _mem ) ;
} break ;
2017-09-19 01:46:48 +02:00
case PLANE : {
* reinterpret_cast < Plane * > ( _data . _mem ) = * reinterpret_cast < const Plane * > ( p_variant . _data . _mem ) ;
} break ;
2017-11-17 03:09:00 +01:00
case AABB : {
* _data . _aabb = * ( p_variant . _data . _aabb ) ;
2017-09-19 01:46:48 +02:00
} break ;
2021-01-20 08:02:02 +01:00
case QUATERNION : {
* reinterpret_cast < Quaternion * > ( _data . _mem ) = * reinterpret_cast < const Quaternion * > ( p_variant . _data . _mem ) ;
2017-09-19 01:46:48 +02:00
} break ;
case BASIS : {
* _data . _basis = * ( p_variant . _data . _basis ) ;
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
* _data . _transform3d = * ( p_variant . _data . _transform3d ) ;
2017-09-19 01:46:48 +02:00
} break ;
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 01:11:13 +02:00
case PROJECTION : {
* _data . _projection = * ( p_variant . _data . _projection ) ;
} break ;
2017-09-19 01:46:48 +02:00
// misc types
case COLOR : {
* reinterpret_cast < Color * > ( _data . _mem ) = * reinterpret_cast < const Color * > ( p_variant . _data . _mem ) ;
} break ;
2020-11-09 14:53:05 +01:00
case RID : {
* reinterpret_cast < : : RID * > ( _data . _mem ) = * reinterpret_cast < const : : RID * > ( p_variant . _data . _mem ) ;
2017-09-19 01:46:48 +02:00
} break ;
case OBJECT : {
2021-06-04 18:03:15 +02:00
if ( _get_obj ( ) . id . is_ref_counted ( ) ) {
2020-02-13 20:03:10 +01:00
//we are safe that there is a reference here
2021-06-04 18:03:15 +02:00
RefCounted * ref_counted = static_cast < RefCounted * > ( _get_obj ( ) . obj ) ;
if ( ref_counted - > unreference ( ) ) {
memdelete ( ref_counted ) ;
2020-02-13 20:03:10 +01:00
}
}
2021-06-04 18:03:15 +02:00
if ( p_variant . _get_obj ( ) . obj & & p_variant . _get_obj ( ) . id . is_ref_counted ( ) ) {
RefCounted * ref_counted = static_cast < RefCounted * > ( p_variant . _get_obj ( ) . obj ) ;
if ( ! ref_counted - > reference ( ) ) {
2020-02-13 20:03:10 +01:00
_get_obj ( ) . obj = nullptr ;
_get_obj ( ) . id = ObjectID ( ) ;
break ;
}
}
_get_obj ( ) . obj = const_cast < Object * > ( p_variant . _get_obj ( ) . obj ) ;
_get_obj ( ) . id = p_variant . _get_obj ( ) . id ;
2017-09-19 01:46:48 +02:00
} break ;
2020-02-19 20:27:19 +01:00
case CALLABLE : {
* reinterpret_cast < Callable * > ( _data . _mem ) = * reinterpret_cast < const Callable * > ( p_variant . _data . _mem ) ;
} break ;
case SIGNAL : {
* reinterpret_cast < Signal * > ( _data . _mem ) = * reinterpret_cast < const Signal * > ( p_variant . _data . _mem ) ;
} break ;
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
* reinterpret_cast < StringName * > ( _data . _mem ) = * reinterpret_cast < const StringName * > ( p_variant . _data . _mem ) ;
} break ;
2017-09-19 01:46:48 +02:00
case NODE_PATH : {
* reinterpret_cast < NodePath * > ( _data . _mem ) = * reinterpret_cast < const NodePath * > ( p_variant . _data . _mem ) ;
} break ;
case DICTIONARY : {
* reinterpret_cast < Dictionary * > ( _data . _mem ) = * reinterpret_cast < const Dictionary * > ( p_variant . _data . _mem ) ;
} break ;
case ARRAY : {
* reinterpret_cast < Array * > ( _data . _mem ) = * reinterpret_cast < const Array * > ( p_variant . _data . _mem ) ;
} break ;
// arrays
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < uint8_t > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < int32_t > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT64_ARRAY : {
_data . packed_array = PackedArrayRef < int64_t > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
} break ;
case PACKED_FLOAT32_ARRAY : {
_data . packed_array = PackedArrayRef < float > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
} break ;
case PACKED_FLOAT64_ARRAY : {
_data . packed_array = PackedArrayRef < double > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < String > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < Vector2 > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < Vector3 > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2020-02-23 22:01:26 +01:00
_data . packed_array = PackedArrayRef < Color > : : reference_from ( _data . packed_array , p_variant . _data . packed_array ) ;
2017-09-19 01:46:48 +02:00
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2017-09-19 01:46:48 +02:00
}
2014-02-10 02:10:30 +01:00
}
2021-05-06 02:48:18 +02:00
Variant : : Variant ( const IPAddress & p_address ) {
2014-02-10 02:10:30 +01:00
type = STRING ;
memnew_placement ( _data . _mem , String ( p_address ) ) ;
}
Variant : : Variant ( const Variant & p_variant ) {
reference ( p_variant ) ;
}
uint32_t Variant : : hash ( ) const {
2020-02-01 07:04:14 +01:00
return recursive_hash ( 0 ) ;
}
uint32_t Variant : : recursive_hash ( int recursion_count ) const {
2014-02-10 02:10:30 +01:00
switch ( type ) {
case NIL : {
return 0 ;
} break ;
case BOOL : {
return _data . _bool ? 1 : 0 ;
} break ;
case INT : {
2021-09-10 16:37:34 +02:00
return hash_one_uint64 ( ( uint64_t ) _data . _int ) ;
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_float ( _data . _float ) ;
2014-02-10 02:10:30 +01:00
} break ;
case STRING : {
return reinterpret_cast < const String * > ( _data . _mem ) - > hash ( ) ;
} break ;
2017-12-06 21:36:34 +01:00
// math types
2014-02-10 02:10:30 +01:00
case VECTOR2 : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Vector2 * > ( _data . _mem ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Vector2i * > ( _data . _mem ) ) ;
2020-02-22 04:26:41 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case RECT2 : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Rect2 * > ( _data . _mem ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-22 04:26:41 +01:00
case RECT2I : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Rect2i * > ( _data . _mem ) ) ;
2020-02-22 04:26:41 +01:00
} break ;
2017-01-11 04:52:51 +01:00
case TRANSFORM2D : {
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
const Transform2D & t = * _data . _transform2d ;
h = hash_murmur3_one_real ( t [ 0 ] . x , h ) ;
h = hash_murmur3_one_real ( t [ 0 ] . y , h ) ;
h = hash_murmur3_one_real ( t [ 1 ] . x , h ) ;
h = hash_murmur3_one_real ( t [ 1 ] . y , h ) ;
h = hash_murmur3_one_real ( t [ 2 ] . x , h ) ;
h = hash_murmur3_one_real ( t [ 2 ] . y , h ) ;
return hash_fmix32 ( h ) ;
2014-02-10 02:10:30 +01:00
} break ;
case VECTOR3 : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Vector3 * > ( _data . _mem ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Vector3i * > ( _data . _mem ) ) ;
2020-02-22 04:26:41 +01:00
} break ;
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 01:11:13 +02:00
case VECTOR4 : {
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Vector4 * > ( _data . _mem ) ) ;
} break ;
case VECTOR4I : {
return HashMapHasherDefault : : hash ( * reinterpret_cast < const Vector4i * > ( _data . _mem ) ) ;
} break ;
2014-02-10 02:10:30 +01:00
case PLANE : {
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
const Plane & p = * reinterpret_cast < const Plane * > ( _data . _mem ) ;
h = hash_murmur3_one_real ( p . normal . x , h ) ;
h = hash_murmur3_one_real ( p . normal . y , h ) ;
h = hash_murmur3_one_real ( p . normal . z , h ) ;
h = hash_murmur3_one_real ( p . d , h ) ;
return hash_fmix32 ( h ) ;
2014-02-10 02:10:30 +01:00
} break ;
2017-11-17 03:09:00 +01:00
case AABB : {
2022-06-18 16:20:55 +02:00
return HashMapHasherDefault : : hash ( * _data . _aabb ) ;
2014-02-10 02:10:30 +01:00
} break ;
2021-01-20 08:02:02 +01:00
case QUATERNION : {
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
const Quaternion & q = * reinterpret_cast < const Quaternion * > ( _data . _mem ) ;
h = hash_murmur3_one_real ( q . x , h ) ;
h = hash_murmur3_one_real ( q . y , h ) ;
h = hash_murmur3_one_real ( q . z , h ) ;
h = hash_murmur3_one_real ( q . w , h ) ;
return hash_fmix32 ( h ) ;
2014-02-10 02:10:30 +01:00
} break ;
2017-01-11 04:52:51 +01:00
case BASIS : {
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
const Basis & b = * _data . _basis ;
h = hash_murmur3_one_real ( b [ 0 ] . x , h ) ;
h = hash_murmur3_one_real ( b [ 0 ] . y , h ) ;
h = hash_murmur3_one_real ( b [ 0 ] . z , h ) ;
h = hash_murmur3_one_real ( b [ 1 ] . x , h ) ;
h = hash_murmur3_one_real ( b [ 1 ] . y , h ) ;
h = hash_murmur3_one_real ( b [ 1 ] . z , h ) ;
h = hash_murmur3_one_real ( b [ 2 ] . x , h ) ;
h = hash_murmur3_one_real ( b [ 2 ] . y , h ) ;
h = hash_murmur3_one_real ( b [ 2 ] . z , h ) ;
return hash_fmix32 ( h ) ;
2014-02-10 02:10:30 +01:00
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
const Transform3D & t = * _data . _transform3d ;
h = hash_murmur3_one_real ( t . basis [ 0 ] . x , h ) ;
h = hash_murmur3_one_real ( t . basis [ 0 ] . y , h ) ;
h = hash_murmur3_one_real ( t . basis [ 0 ] . z , h ) ;
h = hash_murmur3_one_real ( t . basis [ 1 ] . x , h ) ;
h = hash_murmur3_one_real ( t . basis [ 1 ] . y , h ) ;
h = hash_murmur3_one_real ( t . basis [ 1 ] . z , h ) ;
h = hash_murmur3_one_real ( t . basis [ 2 ] . x , h ) ;
h = hash_murmur3_one_real ( t . basis [ 2 ] . y , h ) ;
h = hash_murmur3_one_real ( t . basis [ 2 ] . z , h ) ;
h = hash_murmur3_one_real ( t . origin . x , h ) ;
h = hash_murmur3_one_real ( t . origin . y , h ) ;
h = hash_murmur3_one_real ( t . origin . z , h ) ;
return hash_fmix32 ( h ) ;
2014-02-10 02:10:30 +01:00
} break ;
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 01:11:13 +02:00
case PROJECTION : {
uint32_t h = HASH_MURMUR3_SEED ;
const Projection & t = * _data . _projection ;
2022-10-04 18:44:48 +02:00
h = hash_murmur3_one_real ( t . columns [ 0 ] . x , h ) ;
h = hash_murmur3_one_real ( t . columns [ 0 ] . y , h ) ;
h = hash_murmur3_one_real ( t . columns [ 0 ] . z , h ) ;
h = hash_murmur3_one_real ( t . columns [ 0 ] . w , h ) ;
h = hash_murmur3_one_real ( t . columns [ 1 ] . x , h ) ;
h = hash_murmur3_one_real ( t . columns [ 1 ] . y , h ) ;
h = hash_murmur3_one_real ( t . columns [ 1 ] . z , h ) ;
h = hash_murmur3_one_real ( t . columns [ 1 ] . w , h ) ;
h = hash_murmur3_one_real ( t . columns [ 2 ] . x , h ) ;
h = hash_murmur3_one_real ( t . columns [ 2 ] . y , h ) ;
h = hash_murmur3_one_real ( t . columns [ 2 ] . z , h ) ;
h = hash_murmur3_one_real ( t . columns [ 2 ] . w , h ) ;
h = hash_murmur3_one_real ( t . columns [ 3 ] . x , h ) ;
h = hash_murmur3_one_real ( t . columns [ 3 ] . y , h ) ;
h = hash_murmur3_one_real ( t . columns [ 3 ] . z , h ) ;
h = hash_murmur3_one_real ( t . columns [ 3 ] . w , 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 01:11:13 +02:00
return hash_fmix32 ( h ) ;
} break ;
2014-02-10 02:10:30 +01:00
// misc types
case COLOR : {
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
const Color & c = * reinterpret_cast < const Color * > ( _data . _mem ) ;
h = hash_murmur3_one_float ( c . r , h ) ;
h = hash_murmur3_one_float ( c . g , h ) ;
h = hash_murmur3_one_float ( c . b , h ) ;
h = hash_murmur3_one_float ( c . a , h ) ;
return hash_fmix32 ( h ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-11-09 14:53:05 +01:00
case RID : {
2022-06-15 00:32:10 +02:00
return hash_one_uint64 ( reinterpret_cast < const : : RID * > ( _data . _mem ) - > get_id ( ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
case OBJECT : {
2022-06-18 16:20:55 +02:00
return hash_one_uint64 ( hash_make_uint64_t ( _get_obj ( ) . obj ) ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-20 22:58:05 +01:00
case STRING_NAME : {
return reinterpret_cast < const StringName * > ( _data . _mem ) - > hash ( ) ;
} break ;
2014-02-10 02:10:30 +01:00
case NODE_PATH : {
return reinterpret_cast < const NodePath * > ( _data . _mem ) - > hash ( ) ;
} break ;
case DICTIONARY : {
2020-02-01 07:04:14 +01:00
return reinterpret_cast < const Dictionary * > ( _data . _mem ) - > recursive_hash ( recursion_count ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-19 20:27:19 +01:00
case CALLABLE : {
return reinterpret_cast < const Callable * > ( _data . _mem ) - > hash ( ) ;
} break ;
case SIGNAL : {
const Signal & s = * reinterpret_cast < const Signal * > ( _data . _mem ) ;
uint32_t hash = s . get_name ( ) . hash ( ) ;
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_64 ( s . get_object_id ( ) , hash ) ;
2020-02-19 20:27:19 +01:00
} break ;
2014-02-10 02:10:30 +01:00
case ARRAY : {
const Array & arr = * reinterpret_cast < const Array * > ( _data . _mem ) ;
2020-02-01 07:04:14 +01:00
return arr . recursive_hash ( recursion_count ) ;
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_BYTE_ARRAY : {
2020-02-23 22:01:26 +01:00
const Vector < uint8_t > & arr = PackedArrayRef < uint8_t > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
2020-02-17 22:06:54 +01:00
const uint8_t * r = arr . ptr ( ) ;
2022-06-18 16:20:55 +02:00
return hash_murmur3_buffer ( ( uint8_t * ) & r [ 0 ] , len ) ;
2019-01-30 02:12:41 +01:00
} else {
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_64 ( 0 ) ;
2019-01-30 02:12:41 +01:00
}
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_INT32_ARRAY : {
2020-02-23 22:01:26 +01:00
const Vector < int32_t > & arr = PackedArrayRef < int32_t > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
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
const int32_t * r = arr . ptr ( ) ;
2022-06-18 16:20:55 +02:00
return hash_murmur3_buffer ( ( uint8_t * ) & r [ 0 ] , len * sizeof ( int32_t ) ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
} else {
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_64 ( 0 ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
}
} break ;
case PACKED_INT64_ARRAY : {
const Vector < int64_t > & arr = PackedArrayRef < int64_t > : : get_array ( _data . packed_array ) ;
int len = arr . size ( ) ;
if ( likely ( len ) ) {
const int64_t * r = arr . ptr ( ) ;
2022-06-18 16:20:55 +02:00
return hash_murmur3_buffer ( ( uint8_t * ) & r [ 0 ] , len * sizeof ( int64_t ) ) ;
2019-01-30 02:12:41 +01:00
} else {
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_64 ( 0 ) ;
2019-01-30 02:12:41 +01:00
}
2014-02-10 02:10:30 +01:00
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case PACKED_FLOAT32_ARRAY : {
const Vector < float > & arr = PackedArrayRef < float > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
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
const float * r = arr . ptr ( ) ;
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
for ( int32_t i = 0 ; i < len ; i + + ) {
h = hash_murmur3_one_float ( r [ i ] , h ) ;
}
return hash_fmix32 ( h ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
} else {
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_float ( 0.0 ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
}
} break ;
case PACKED_FLOAT64_ARRAY : {
const Vector < double > & arr = PackedArrayRef < double > : : get_array ( _data . packed_array ) ;
int len = arr . size ( ) ;
if ( likely ( len ) ) {
const double * r = arr . ptr ( ) ;
2022-06-18 16:20:55 +02:00
uint32_t h = HASH_MURMUR3_SEED ;
for ( int32_t i = 0 ; i < len ; i + + ) {
h = hash_murmur3_one_double ( r [ i ] , h ) ;
}
return hash_fmix32 ( h ) ;
2019-01-30 02:12:41 +01:00
} else {
2022-06-18 16:20:55 +02:00
return hash_murmur3_one_float ( 0.0 ) ;
2019-01-30 02:12:41 +01:00
}
2014-02-10 02:10:30 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_STRING_ARRAY : {
2022-06-18 16:20:55 +02:00
uint32_t hash = HASH_MURMUR3_SEED ;
2020-02-23 22:01:26 +01:00
const Vector < String > & arr = PackedArrayRef < String > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
2020-02-17 22:06:54 +01:00
const String * r = arr . ptr ( ) ;
2019-01-30 02:12:41 +01:00
for ( int i = 0 ; i < len ; i + + ) {
2022-06-18 16:20:55 +02:00
hash = hash_murmur3_one_32 ( r [ i ] . hash ( ) , hash ) ;
2019-01-30 02:12:41 +01:00
}
2022-06-18 16:20:55 +02:00
hash = hash_fmix32 ( hash ) ;
2014-02-10 02:10:30 +01:00
}
return hash ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_ARRAY : {
2022-06-18 16:20:55 +02:00
uint32_t hash = HASH_MURMUR3_SEED ;
2020-02-23 22:01:26 +01:00
const Vector < Vector2 > & arr = PackedArrayRef < Vector2 > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
2020-02-17 22:06:54 +01:00
const Vector2 * r = arr . ptr ( ) ;
2019-01-30 02:12:41 +01:00
for ( int i = 0 ; i < len ; i + + ) {
2022-06-18 16:20:55 +02:00
hash = hash_murmur3_one_real ( r [ i ] . x , hash ) ;
hash = hash_murmur3_one_real ( r [ i ] . y , hash ) ;
2019-01-30 02:12:41 +01:00
}
2022-06-18 16:20:55 +02:00
hash = hash_fmix32 ( hash ) ;
2014-02-10 02:10:30 +01:00
}
return hash ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_ARRAY : {
2022-06-18 16:20:55 +02:00
uint32_t hash = HASH_MURMUR3_SEED ;
2020-02-23 22:01:26 +01:00
const Vector < Vector3 > & arr = PackedArrayRef < Vector3 > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
2020-02-17 22:06:54 +01:00
const Vector3 * r = arr . ptr ( ) ;
2019-01-30 02:12:41 +01:00
for ( int i = 0 ; i < len ; i + + ) {
2022-06-18 16:20:55 +02:00
hash = hash_murmur3_one_real ( r [ i ] . x , hash ) ;
hash = hash_murmur3_one_real ( r [ i ] . y , hash ) ;
hash = hash_murmur3_one_real ( r [ i ] . z , hash ) ;
2019-01-30 02:12:41 +01:00
}
2022-06-18 16:20:55 +02:00
hash = hash_fmix32 ( hash ) ;
2014-02-10 02:10:30 +01:00
}
return hash ;
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_ARRAY : {
2022-06-18 16:20:55 +02:00
uint32_t hash = HASH_MURMUR3_SEED ;
2020-02-23 22:01:26 +01:00
const Vector < Color > & arr = PackedArrayRef < Color > : : get_array ( _data . packed_array ) ;
2014-02-10 02:10:30 +01:00
int len = arr . size ( ) ;
2019-01-30 02:12:41 +01:00
if ( likely ( len ) ) {
2020-02-17 22:06:54 +01:00
const Color * r = arr . ptr ( ) ;
2019-01-30 02:12:41 +01:00
for ( int i = 0 ; i < len ; i + + ) {
2022-06-18 16:20:55 +02:00
hash = hash_murmur3_one_float ( r [ i ] . r , hash ) ;
hash = hash_murmur3_one_float ( r [ i ] . g , hash ) ;
hash = hash_murmur3_one_float ( r [ i ] . b , hash ) ;
hash = hash_murmur3_one_float ( r [ i ] . a , hash ) ;
2019-01-30 02:12:41 +01:00
}
2022-06-18 16:20:55 +02:00
hash = hash_fmix32 ( hash ) ;
2014-02-10 02:10:30 +01:00
}
return hash ;
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
return 0 ;
}
2017-02-15 14:41:16 +01:00
# define hash_compare_scalar(p_lhs, p_rhs) \
2017-04-14 11:28:51 +02:00
( ( p_lhs ) = = ( p_rhs ) ) | | ( Math : : is_nan ( p_lhs ) & & Math : : is_nan ( p_rhs ) )
2017-02-15 14:41:16 +01:00
# define hash_compare_vector2(p_lhs, p_rhs) \
( hash_compare_scalar ( ( p_lhs ) . x , ( p_rhs ) . x ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . y , ( p_rhs ) . y ) )
2017-03-05 16:44:50 +01:00
2017-02-15 14:41:16 +01:00
# define hash_compare_vector3(p_lhs, p_rhs) \
( hash_compare_scalar ( ( p_lhs ) . x , ( p_rhs ) . x ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . y , ( p_rhs ) . y ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . z , ( p_rhs ) . z ) )
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 01:11:13 +02:00
# define hash_compare_vector4(p_lhs, p_rhs) \
( hash_compare_scalar ( ( p_lhs ) . x , ( p_rhs ) . x ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . y , ( p_rhs ) . y ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . z , ( p_rhs ) . z ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . w , ( p_rhs ) . w ) )
2017-03-05 16:44:50 +01:00
2021-01-20 08:02:02 +01:00
# define hash_compare_quaternion(p_lhs, p_rhs) \
2017-02-15 14:41:16 +01:00
( hash_compare_scalar ( ( p_lhs ) . x , ( p_rhs ) . x ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . y , ( p_rhs ) . y ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . z , ( p_rhs ) . z ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . w , ( p_rhs ) . w ) )
2017-03-05 16:44:50 +01:00
2017-02-15 14:41:16 +01:00
# define hash_compare_color(p_lhs, p_rhs) \
( hash_compare_scalar ( ( p_lhs ) . r , ( p_rhs ) . r ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . g , ( p_rhs ) . g ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . b , ( p_rhs ) . b ) ) & & \
( hash_compare_scalar ( ( p_lhs ) . a , ( p_rhs ) . a ) )
2017-03-05 16:44:50 +01:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
# define hash_compare_packed_array(p_lhs, p_rhs, p_type, p_compare_func) \
const Vector < p_type > & l = PackedArrayRef < p_type > : : get_array ( p_lhs ) ; \
const Vector < p_type > & r = PackedArrayRef < p_type > : : get_array ( p_rhs ) ; \
\
if ( l . size ( ) ! = r . size ( ) ) \
return false ; \
\
const p_type * lr = l . ptr ( ) ; \
const p_type * rr = r . ptr ( ) ; \
\
for ( int i = 0 ; i < l . size ( ) ; + + i ) { \
if ( ! p_compare_func ( ( lr [ i ] ) , ( rr [ i ] ) ) ) \
return false ; \
} \
\
2017-02-15 14:41:16 +01:00
return true
2017-03-05 16:44:50 +01:00
2020-02-01 07:04:14 +01:00
bool Variant : : hash_compare ( const Variant & p_variant , int recursion_count ) const {
2020-05-14 16:41:43 +02:00
if ( type ! = p_variant . type ) {
2017-02-15 14:41:16 +01:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-02-15 14:41:16 +01:00
switch ( type ) {
2021-10-08 09:36:48 +02:00
case INT : {
return _data . _int = = p_variant . _data . _int ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
case FLOAT : {
return hash_compare_scalar ( _data . _float , p_variant . _data . _float ) ;
2017-02-15 14:41:16 +01:00
} break ;
2021-10-08 09:36:48 +02:00
case STRING : {
return * reinterpret_cast < const String * > ( _data . _mem ) = = * reinterpret_cast < const String * > ( p_variant . _data . _mem ) ;
} break ;
2022-06-03 11:51:46 +02:00
case STRING_NAME : {
return * reinterpret_cast < const StringName * > ( _data . _mem ) = = * reinterpret_cast < const StringName * > ( p_variant . _data . _mem ) ;
} break ;
2017-02-15 14:41:16 +01:00
case VECTOR2 : {
const Vector2 * l = reinterpret_cast < const Vector2 * > ( _data . _mem ) ;
const Vector2 * r = reinterpret_cast < const Vector2 * > ( p_variant . _data . _mem ) ;
return hash_compare_vector2 ( * l , * r ) ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR2I : {
const Vector2i * l = reinterpret_cast < const Vector2i * > ( _data . _mem ) ;
const Vector2i * r = reinterpret_cast < const Vector2i * > ( p_variant . _data . _mem ) ;
return * l = = * r ;
} break ;
2017-02-15 14:41:16 +01:00
case RECT2 : {
const Rect2 * l = reinterpret_cast < const Rect2 * > ( _data . _mem ) ;
const Rect2 * r = reinterpret_cast < const Rect2 * > ( p_variant . _data . _mem ) ;
2017-06-04 00:25:13 +02:00
return ( hash_compare_vector2 ( l - > position , r - > position ) ) & &
2021-10-28 15:19:35 +02:00
( hash_compare_vector2 ( l - > size , r - > size ) ) ;
2017-02-15 14:41:16 +01:00
} break ;
2020-02-22 04:26:41 +01:00
case RECT2I : {
const Rect2i * l = reinterpret_cast < const Rect2i * > ( _data . _mem ) ;
const Rect2i * r = reinterpret_cast < const Rect2i * > ( p_variant . _data . _mem ) ;
return * l = = * r ;
} break ;
2017-02-15 14:41:16 +01:00
case TRANSFORM2D : {
Transform2D * l = _data . _transform2d ;
Transform2D * r = p_variant . _data . _transform2d ;
for ( int i = 0 ; i < 3 ; i + + ) {
2022-04-24 23:59:24 +02:00
if ( ! ( hash_compare_vector2 ( l - > columns [ i ] , r - > columns [ i ] ) ) ) {
2017-02-15 14:41:16 +01:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-02-15 14:41:16 +01:00
}
return true ;
} break ;
case VECTOR3 : {
const Vector3 * l = reinterpret_cast < const Vector3 * > ( _data . _mem ) ;
const Vector3 * r = reinterpret_cast < const Vector3 * > ( p_variant . _data . _mem ) ;
return hash_compare_vector3 ( * l , * r ) ;
} break ;
2020-02-22 04:26:41 +01:00
case VECTOR3I : {
const Vector3i * l = reinterpret_cast < const Vector3i * > ( _data . _mem ) ;
const Vector3i * r = reinterpret_cast < const Vector3i * > ( p_variant . _data . _mem ) ;
return * l = = * r ;
} break ;
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 01:11:13 +02:00
case VECTOR4 : {
const Vector4 * l = reinterpret_cast < const Vector4 * > ( _data . _mem ) ;
const Vector4 * r = reinterpret_cast < const Vector4 * > ( p_variant . _data . _mem ) ;
return hash_compare_vector4 ( * l , * r ) ;
} break ;
case VECTOR4I : {
const Vector4i * l = reinterpret_cast < const Vector4i * > ( _data . _mem ) ;
const Vector4i * r = reinterpret_cast < const Vector4i * > ( p_variant . _data . _mem ) ;
return * l = = * r ;
} break ;
2017-02-15 14:41:16 +01:00
case PLANE : {
const Plane * l = reinterpret_cast < const Plane * > ( _data . _mem ) ;
const Plane * r = reinterpret_cast < const Plane * > ( p_variant . _data . _mem ) ;
return ( hash_compare_vector3 ( l - > normal , r - > normal ) ) & &
2021-10-28 15:19:35 +02:00
( hash_compare_scalar ( l - > d , r - > d ) ) ;
2017-02-15 14:41:16 +01:00
} break ;
2017-11-17 03:09:00 +01:00
case AABB : {
const : : AABB * l = _data . _aabb ;
const : : AABB * r = p_variant . _data . _aabb ;
2017-02-15 14:41:16 +01:00
2017-06-06 20:33:51 +02:00
return ( hash_compare_vector3 ( l - > position , r - > position ) & &
2017-02-15 14:41:16 +01:00
( hash_compare_vector3 ( l - > size , r - > size ) ) ) ;
} break ;
2021-01-20 08:02:02 +01:00
case QUATERNION : {
const Quaternion * l = reinterpret_cast < const Quaternion * > ( _data . _mem ) ;
const Quaternion * r = reinterpret_cast < const Quaternion * > ( p_variant . _data . _mem ) ;
2017-02-15 14:41:16 +01:00
2021-01-20 08:02:02 +01:00
return hash_compare_quaternion ( * l , * r ) ;
2017-02-15 14:41:16 +01:00
} break ;
case BASIS : {
const Basis * l = _data . _basis ;
const Basis * r = p_variant . _data . _basis ;
for ( int i = 0 ; i < 3 ; i + + ) {
2022-04-25 00:07:35 +02:00
if ( ! ( hash_compare_vector3 ( l - > rows [ i ] , r - > rows [ i ] ) ) ) {
2017-02-15 14:41:16 +01:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-02-15 14:41:16 +01:00
}
return true ;
} break ;
2021-04-28 09:36:08 +02:00
case TRANSFORM3D : {
const Transform3D * l = _data . _transform3d ;
const Transform3D * r = p_variant . _data . _transform3d ;
2017-02-15 14:41:16 +01:00
for ( int i = 0 ; i < 3 ; i + + ) {
2022-04-25 00:07:35 +02:00
if ( ! ( hash_compare_vector3 ( l - > basis . rows [ i ] , r - > basis . rows [ i ] ) ) ) {
2017-02-15 14:41:16 +01:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-02-15 14:41:16 +01:00
}
return hash_compare_vector3 ( l - > origin , r - > origin ) ;
} break ;
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 01:11:13 +02:00
case PROJECTION : {
const Projection * l = _data . _projection ;
const Projection * r = p_variant . _data . _projection ;
for ( int i = 0 ; i < 4 ; i + + ) {
2022-10-04 18:44:48 +02:00
if ( ! ( hash_compare_vector4 ( l - > columns [ i ] , r - > columns [ i ] ) ) ) {
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 01:11:13 +02:00
return false ;
}
}
return true ;
} break ;
2017-02-15 14:41:16 +01:00
case COLOR : {
const Color * l = reinterpret_cast < const Color * > ( _data . _mem ) ;
const Color * r = reinterpret_cast < const Color * > ( p_variant . _data . _mem ) ;
return hash_compare_color ( * l , * r ) ;
} break ;
case ARRAY : {
const Array & l = * ( reinterpret_cast < const Array * > ( _data . _mem ) ) ;
const Array & r = * ( reinterpret_cast < const Array * > ( p_variant . _data . _mem ) ) ;
2020-02-01 07:04:14 +01:00
if ( ! l . recursive_equal ( r , recursion_count + 1 ) ) {
2017-02-15 14:41:16 +01:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-02-15 14:41:16 +01:00
2020-02-01 07:04:14 +01:00
return true ;
} break ;
case DICTIONARY : {
const Dictionary & l = * ( reinterpret_cast < const Dictionary * > ( _data . _mem ) ) ;
const Dictionary & r = * ( reinterpret_cast < const Dictionary * > ( p_variant . _data . _mem ) ) ;
if ( ! l . recursive_equal ( r , recursion_count + 1 ) ) {
return false ;
2017-02-15 14:41:16 +01:00
}
return true ;
} break ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
// This is for floating point comparisons only.
case PACKED_FLOAT32_ARRAY : {
hash_compare_packed_array ( _data . packed_array , p_variant . _data . packed_array , float , hash_compare_scalar ) ;
} break ;
case PACKED_FLOAT64_ARRAY : {
hash_compare_packed_array ( _data . packed_array , p_variant . _data . packed_array , double , hash_compare_scalar ) ;
2017-02-15 14:41:16 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR2_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
hash_compare_packed_array ( _data . packed_array , p_variant . _data . packed_array , Vector2 , hash_compare_vector2 ) ;
2017-02-15 14:41:16 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_VECTOR3_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
hash_compare_packed_array ( _data . packed_array , p_variant . _data . packed_array , Vector3 , hash_compare_vector3 ) ;
2017-02-15 14:41:16 +01:00
} break ;
2020-02-17 22:06:54 +01:00
case PACKED_COLOR_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
hash_compare_packed_array ( _data . packed_array , p_variant . _data . packed_array , Color , hash_compare_color ) ;
2017-02-15 14:41:16 +01:00
} break ;
default :
bool v ;
Variant r ;
evaluate ( OP_EQUAL , * this , p_variant , r , v ) ;
return r ;
}
}
2021-08-26 21:37:17 +02:00
bool Variant : : is_ref_counted ( ) const {
2021-06-04 18:03:15 +02:00
return type = = OBJECT & & _get_obj ( ) . id . is_ref_counted ( ) ;
2014-02-10 02:10:30 +01:00
}
Vector < Variant > varray ( ) {
return Vector < Variant > ( ) ;
}
Vector < Variant > varray ( const Variant & p_arg1 ) {
Vector < Variant > v ;
v . push_back ( p_arg1 ) ;
return v ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Vector < Variant > varray ( const Variant & p_arg1 , const Variant & p_arg2 ) {
Vector < Variant > v ;
v . push_back ( p_arg1 ) ;
v . push_back ( p_arg2 ) ;
return v ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Vector < Variant > varray ( const Variant & p_arg1 , const Variant & p_arg2 , const Variant & p_arg3 ) {
Vector < Variant > v ;
v . push_back ( p_arg1 ) ;
v . push_back ( p_arg2 ) ;
v . push_back ( p_arg3 ) ;
return v ;
}
2020-05-14 14:29:06 +02:00
2014-02-10 02:10:30 +01:00
Vector < Variant > varray ( const Variant & p_arg1 , const Variant & p_arg2 , const Variant & p_arg3 , const Variant & p_arg4 ) {
Vector < Variant > v ;
v . push_back ( p_arg1 ) ;
v . push_back ( p_arg2 ) ;
v . push_back ( p_arg3 ) ;
v . push_back ( p_arg4 ) ;
return v ;
}
Vector < Variant > varray ( const Variant & p_arg1 , const Variant & p_arg2 , const Variant & p_arg3 , const Variant & p_arg4 , const Variant & p_arg5 ) {
Vector < Variant > v ;
v . push_back ( p_arg1 ) ;
v . push_back ( p_arg2 ) ;
v . push_back ( p_arg3 ) ;
v . push_back ( p_arg4 ) ;
v . push_back ( p_arg5 ) ;
return v ;
}
void Variant : : static_assign ( const Variant & p_variant ) {
}
2022-06-27 17:09:51 +02:00
bool Variant : : is_type_shared ( Variant : : Type p_type ) {
switch ( p_type ) {
2020-05-10 13:00:47 +02:00
case OBJECT :
case ARRAY :
case DICTIONARY :
2022-06-27 17:09:51 +02:00
case PACKED_BYTE_ARRAY :
case PACKED_INT32_ARRAY :
case PACKED_INT64_ARRAY :
case PACKED_FLOAT32_ARRAY :
case PACKED_FLOAT64_ARRAY :
case PACKED_STRING_ARRAY :
case PACKED_VECTOR2_ARRAY :
case PACKED_VECTOR3_ARRAY :
case PACKED_COLOR_ARRAY :
2020-05-10 13:00:47 +02:00
return true ;
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
return false ;
}
2022-06-27 17:09:51 +02:00
bool Variant : : is_shared ( ) const {
return is_type_shared ( type ) ;
}
2022-03-09 14:58:40 +01:00
void Variant : : _variant_call_error ( const String & p_method , Callable : : CallError & error ) {
2014-02-10 02:10:30 +01:00
switch ( error . error ) {
2020-02-19 20:27:19 +01:00
case Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT : {
String err = " Invalid type for argument # " + itos ( error . argument ) + " , expected ' " + Variant : : get_type_name ( Variant : : Type ( error . expected ) ) + " '. " ;
2014-02-10 02:10:30 +01:00
ERR_PRINT ( err . utf8 ( ) . get_data ( ) ) ;
} break ;
2020-02-19 20:27:19 +01:00
case Callable : : CallError : : CALL_ERROR_INVALID_METHOD : {
2014-02-10 02:10:30 +01:00
String err = " Invalid method ' " + p_method + " ' for type ' " + Variant : : get_type_name ( type ) + " '. " ;
ERR_PRINT ( err . utf8 ( ) . get_data ( ) ) ;
} break ;
2020-02-19 20:27:19 +01:00
case Callable : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS : {
2014-02-10 02:10:30 +01:00
String err = " Too many arguments for method ' " + p_method + " ' " ;
ERR_PRINT ( err . utf8 ( ) . get_data ( ) ) ;
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
}
2015-02-15 05:19:46 +01:00
void Variant : : construct_from_string ( const String & p_string , Variant & r_value , ObjectConstruct p_obj_construct , void * p_construct_ud ) {
r_value = Variant ( ) ;
}
2014-12-17 02:31:57 +01:00
2015-12-31 04:54:00 +01:00
String Variant : : get_construct_string ( ) const {
String vars ;
VariantWriter : : write_to_string ( * this , vars ) ;
2014-12-17 02:31:57 +01:00
2015-12-31 04:54:00 +01:00
return vars ;
2014-12-17 02:31:57 +01:00
}
2016-01-04 13:35:21 +01:00
2020-11-10 22:31:33 +01:00
String Variant : : get_call_error_text ( const StringName & p_method , const Variant * * p_argptrs , int p_argcount , const Callable : : CallError & ce ) {
2022-04-30 13:30:05 +02:00
return get_call_error_text ( nullptr , p_method , p_argptrs , p_argcount , ce ) ;
2020-11-10 22:31:33 +01:00
}
2020-02-19 20:27:19 +01:00
String Variant : : get_call_error_text ( Object * p_base , const StringName & p_method , const Variant * * p_argptrs , int p_argcount , const Callable : : CallError & ce ) {
2016-01-04 13:35:21 +01:00
String err_text ;
2020-02-19 20:27:19 +01:00
if ( ce . error = = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ) {
2016-01-04 13:35:21 +01:00
int errorarg = ce . argument ;
2018-04-30 21:04:30 +02:00
if ( p_argptrs ) {
2022-11-14 18:29:54 +01:00
err_text = " Cannot convert argument " + itos ( errorarg + 1 ) + " from " + Variant : : get_type_name ( p_argptrs [ errorarg ] - > get_type ( ) ) + " to " + Variant : : get_type_name ( Variant : : Type ( ce . expected ) ) ;
2018-04-30 21:04:30 +02:00
} else {
2022-11-14 18:29:54 +01:00
err_text = " Cannot convert argument " + itos ( errorarg + 1 ) + " from [missing argptr, type unknown] to " + Variant : : get_type_name ( Variant : : Type ( ce . expected ) ) ;
2018-04-30 21:04:30 +02:00
}
2020-02-19 20:27:19 +01:00
} else if ( ce . error = = Callable : : CallError : : CALL_ERROR_TOO_MANY_ARGUMENTS ) {
2022-11-14 18:29:54 +01:00
err_text = " Method expected " + itos ( ce . argument ) + " arguments, but called with " + itos ( p_argcount ) ;
2020-02-19 20:27:19 +01:00
} else if ( ce . error = = Callable : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ) {
2022-11-14 18:29:54 +01:00
err_text = " Method expected " + itos ( ce . argument ) + " arguments, but called with " + itos ( p_argcount ) ;
2020-02-19 20:27:19 +01:00
} else if ( ce . error = = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ) {
2022-11-14 18:29:54 +01:00
err_text = " Method not found " ;
2020-02-19 20:27:19 +01:00
} else if ( ce . error = = Callable : : CallError : : CALL_ERROR_INSTANCE_IS_NULL ) {
2016-01-04 13:35:21 +01:00
err_text = " Instance is null " ;
2022-06-27 22:10:04 +02:00
} else if ( ce . error = = Callable : : CallError : : CALL_ERROR_METHOD_NOT_CONST ) {
err_text = " Method not const in const instance " ;
2020-02-19 20:27:19 +01:00
} else if ( ce . error = = Callable : : CallError : : CALL_OK ) {
2016-01-04 13:35:21 +01:00
return " Call OK " ;
}
2022-04-30 13:30:05 +02:00
String base_text ;
if ( p_base ) {
base_text = p_base - > get_class ( ) ;
Ref < Resource > script = p_base - > get_script ( ) ;
if ( script . is_valid ( ) & & script - > get_path ( ) . is_resource_file ( ) ) {
base_text + = " ( " + script - > get_path ( ) . get_file ( ) + " ) " ;
}
base_text + = " :: " ;
2016-01-04 13:35:21 +01:00
}
2022-04-30 13:30:05 +02:00
return " ' " + base_text + String ( p_method ) + " ': " + err_text ;
2016-01-04 13:35:21 +01:00
}
2016-05-17 23:27:15 +02:00
2020-02-19 20:27:19 +01:00
String Variant : : get_callable_error_text ( const Callable & p_callable , const Variant * * p_argptrs , int p_argcount , const Callable : : CallError & ce ) {
2022-04-30 13:30:05 +02:00
return get_call_error_text ( p_callable . get_object ( ) , p_callable . get_method ( ) , p_argptrs , p_argcount , ce ) ;
2020-02-19 20:27:19 +01:00
}
2020-11-09 04:19:09 +01:00
void Variant : : register_types ( ) {
_register_variant_operators ( ) ;
_register_variant_methods ( ) ;
_register_variant_setters_getters ( ) ;
_register_variant_constructors ( ) ;
2021-07-29 15:53:05 +02:00
_register_variant_destructors ( ) ;
2020-11-11 17:16:08 +01:00
_register_variant_utility_functions ( ) ;
2020-11-09 04:19:09 +01:00
}
void Variant : : unregister_types ( ) {
_unregister_variant_operators ( ) ;
_unregister_variant_methods ( ) ;
_unregister_variant_setters_getters ( ) ;
2021-07-29 15:53:05 +02:00
_unregister_variant_destructors ( ) ;
2020-11-11 17:16:08 +01:00
_unregister_variant_utility_functions ( ) ;
2020-11-09 04:19:09 +01:00
}