2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* method_ptrcall.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +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). */
|
2017-03-05 15:47:28 +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
|
|
|
|
2016-06-23 04:12:20 +02:00
|
|
|
#ifndef METHOD_PTRCALL_H
|
|
|
|
#define METHOD_PTRCALL_H
|
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/object/object_id.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/typedefs.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/variant/variant.h"
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
2020-11-25 14:08:17 +01:00
|
|
|
struct PtrToArg {};
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define MAKE_PTRARG(m_type) \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<m_type> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
return *reinterpret_cast<const m_type *>(p_ptr); \
|
|
|
|
} \
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef m_type EncodeT; \
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
|
|
|
*((m_type *)p_ptr) = p_val; \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const m_type &> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
return *reinterpret_cast<const m_type *>(p_ptr); \
|
|
|
|
} \
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef m_type EncodeT; \
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
|
|
|
*((m_type *)p_ptr) = p_val; \
|
|
|
|
} \
|
|
|
|
}
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2017-07-19 13:37:05 +02:00
|
|
|
#define MAKE_PTRARGCONV(m_type, m_conv) \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<m_type> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
return static_cast<m_type>(*reinterpret_cast<const m_conv *>(p_ptr)); \
|
|
|
|
} \
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef m_conv EncodeT; \
|
2017-07-19 13:37:05 +02:00
|
|
|
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
|
|
|
*((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const m_type &> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
return static_cast<m_type>(*reinterpret_cast<const m_conv *>(p_ptr)); \
|
|
|
|
} \
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef m_conv EncodeT; \
|
2017-07-19 13:37:05 +02:00
|
|
|
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
|
|
|
*((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \
|
|
|
|
} \
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2017-08-12 13:04:30 +02:00
|
|
|
#define MAKE_PTRARG_BY_REFERENCE(m_type) \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<m_type> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
return *reinterpret_cast<const m_type *>(p_ptr); \
|
|
|
|
} \
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef m_type EncodeT; \
|
2017-08-12 13:04:30 +02:00
|
|
|
_FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \
|
|
|
|
*((m_type *)p_ptr) = p_val; \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const m_type &> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
return *reinterpret_cast<const m_type *>(p_ptr); \
|
|
|
|
} \
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef m_type EncodeT; \
|
2017-08-12 13:04:30 +02:00
|
|
|
_FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \
|
|
|
|
*((m_type *)p_ptr) = p_val; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:00:56 +02:00
|
|
|
MAKE_PTRARGCONV(bool, uint8_t);
|
2020-12-15 21:02:50 +01:00
|
|
|
// Integer types.
|
2017-07-19 13:37:05 +02:00
|
|
|
MAKE_PTRARGCONV(uint8_t, int64_t);
|
|
|
|
MAKE_PTRARGCONV(int8_t, int64_t);
|
|
|
|
MAKE_PTRARGCONV(uint16_t, int64_t);
|
|
|
|
MAKE_PTRARGCONV(int16_t, int64_t);
|
|
|
|
MAKE_PTRARGCONV(uint32_t, int64_t);
|
|
|
|
MAKE_PTRARGCONV(int32_t, int64_t);
|
|
|
|
MAKE_PTRARG(int64_t);
|
|
|
|
MAKE_PTRARG(uint64_t);
|
2020-12-15 21:02:50 +01:00
|
|
|
// Float types
|
2017-07-19 13:37:05 +02:00
|
|
|
MAKE_PTRARGCONV(float, double);
|
|
|
|
MAKE_PTRARG(double);
|
2016-06-23 04:12:20 +02:00
|
|
|
|
|
|
|
MAKE_PTRARG(String);
|
|
|
|
MAKE_PTRARG(Vector2);
|
2020-03-01 23:14:37 +01:00
|
|
|
MAKE_PTRARG(Vector2i);
|
2020-12-15 21:02:50 +01:00
|
|
|
MAKE_PTRARG(Rect2);
|
2020-03-01 23:14:37 +01:00
|
|
|
MAKE_PTRARG(Rect2i);
|
2020-12-15 21:02:50 +01:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(Vector3);
|
2020-03-01 23:14:37 +01:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(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
|
|
|
MAKE_PTRARG_BY_REFERENCE(Vector4);
|
|
|
|
MAKE_PTRARG_BY_REFERENCE(Vector4i);
|
2017-01-11 04:52:51 +01:00
|
|
|
MAKE_PTRARG(Transform2D);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
|
|
|
MAKE_PTRARG(Projection);
|
2017-08-12 13:04:30 +02:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(Plane);
|
2021-01-20 08:02:02 +01:00
|
|
|
MAKE_PTRARG(Quaternion);
|
2017-11-17 03:09:00 +01:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(AABB);
|
2017-08-12 13:04:30 +02:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(Basis);
|
2020-10-17 07:08:21 +02:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(Transform3D);
|
2017-08-12 13:04:30 +02:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(Color);
|
2020-02-20 22:58:05 +01:00
|
|
|
MAKE_PTRARG(StringName);
|
2016-06-23 04:12:20 +02:00
|
|
|
MAKE_PTRARG(NodePath);
|
|
|
|
MAKE_PTRARG(RID);
|
2020-12-15 21:02:50 +01:00
|
|
|
// Object doesn't need this.
|
2020-02-19 20:27:19 +01:00
|
|
|
MAKE_PTRARG(Callable);
|
|
|
|
MAKE_PTRARG(Signal);
|
2020-12-15 21:02:50 +01:00
|
|
|
MAKE_PTRARG(Dictionary);
|
2016-06-23 04:12:20 +02:00
|
|
|
MAKE_PTRARG(Array);
|
2020-02-17 22:06:54 +01:00
|
|
|
MAKE_PTRARG(PackedByteArray);
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
|
|
|
MAKE_PTRARG(PackedInt32Array);
|
|
|
|
MAKE_PTRARG(PackedInt64Array);
|
|
|
|
MAKE_PTRARG(PackedFloat32Array);
|
|
|
|
MAKE_PTRARG(PackedFloat64Array);
|
2020-02-17 22:06:54 +01:00
|
|
|
MAKE_PTRARG(PackedStringArray);
|
|
|
|
MAKE_PTRARG(PackedVector2Array);
|
|
|
|
MAKE_PTRARG(PackedVector3Array);
|
|
|
|
MAKE_PTRARG(PackedColorArray);
|
2017-08-12 13:04:30 +02:00
|
|
|
MAKE_PTRARG_BY_REFERENCE(Variant);
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2020-11-25 14:08:17 +01:00
|
|
|
// This is for Object.
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
|
|
|
struct PtrToArg<T *> {
|
|
|
|
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
|
|
|
|
return const_cast<T *>(reinterpret_cast<const T *>(p_ptr));
|
2016-06-23 04:12:20 +02:00
|
|
|
}
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef Object *EncodeT;
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
|
|
|
|
*((T **)p_ptr) = p_var;
|
2016-06-23 04:12:20 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <class T>
|
|
|
|
struct PtrToArg<const T *> {
|
|
|
|
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
|
|
|
|
return reinterpret_cast<const T *>(p_ptr);
|
2016-06-23 04:12:20 +02:00
|
|
|
}
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef const Object *EncodeT;
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
|
|
|
|
*((T **)p_ptr) = p_var;
|
2016-06-23 04:12:20 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-25 14:08:17 +01:00
|
|
|
// This is for ObjectID.
|
2020-02-12 18:24:06 +01:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct PtrToArg<ObjectID> {
|
|
|
|
_FORCE_INLINE_ static const ObjectID convert(const void *p_ptr) {
|
|
|
|
return ObjectID(*reinterpret_cast<const uint64_t *>(p_ptr));
|
|
|
|
}
|
2021-06-19 17:58:49 +02:00
|
|
|
typedef uint64_t EncodeT;
|
2020-02-12 18:24:06 +01:00
|
|
|
_FORCE_INLINE_ static void encode(const ObjectID &p_val, void *p_ptr) {
|
|
|
|
*((uint64_t *)p_ptr) = p_val;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-25 14:08:17 +01:00
|
|
|
// This is for the special cases used by Variant.
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2020-02-17 22:06:54 +01:00
|
|
|
#define MAKE_VECARG(m_type) \
|
|
|
|
template <> \
|
2020-03-17 07:33:00 +01:00
|
|
|
struct PtrToArg<Vector<m_type>> { \
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
|
|
|
const Vector<m_type> *dvs = reinterpret_cast<const Vector<m_type> *>(p_ptr); \
|
|
|
|
Vector<m_type> ret; \
|
|
|
|
int len = dvs->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
{ \
|
|
|
|
const m_type *r = dvs->ptr(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
ret.write[i] = r[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
_FORCE_INLINE_ static void encode(Vector<m_type> p_vec, void *p_ptr) { \
|
|
|
|
Vector<m_type> *dv = reinterpret_cast<Vector<m_type> *>(p_ptr); \
|
|
|
|
int len = p_vec.size(); \
|
|
|
|
dv->resize(len); \
|
|
|
|
{ \
|
|
|
|
m_type *w = dv->ptrw(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
w[i] = p_vec[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const Vector<m_type> &> { \
|
|
|
|
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
|
|
|
const Vector<m_type> *dvs = reinterpret_cast<const Vector<m_type> *>(p_ptr); \
|
|
|
|
Vector<m_type> ret; \
|
|
|
|
int len = dvs->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
{ \
|
|
|
|
const m_type *r = dvs->ptr(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
ret.write[i] = r[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2020-02-17 22:06:54 +01:00
|
|
|
#define MAKE_VECARG_ALT(m_type, m_type_alt) \
|
|
|
|
template <> \
|
2020-03-17 07:33:00 +01:00
|
|
|
struct PtrToArg<Vector<m_type_alt>> { \
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ static Vector<m_type_alt> convert(const void *p_ptr) { \
|
|
|
|
const Vector<m_type> *dvs = reinterpret_cast<const Vector<m_type> *>(p_ptr); \
|
|
|
|
Vector<m_type_alt> ret; \
|
|
|
|
int len = dvs->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
{ \
|
|
|
|
const m_type *r = dvs->ptr(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
ret.write[i] = r[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
_FORCE_INLINE_ static void encode(Vector<m_type_alt> p_vec, void *p_ptr) { \
|
|
|
|
Vector<m_type> *dv = reinterpret_cast<Vector<m_type> *>(p_ptr); \
|
|
|
|
int len = p_vec.size(); \
|
|
|
|
dv->resize(len); \
|
|
|
|
{ \
|
|
|
|
m_type *w = dv->ptrw(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
w[i] = p_vec[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const Vector<m_type_alt> &> { \
|
|
|
|
_FORCE_INLINE_ static Vector<m_type_alt> convert(const void *p_ptr) { \
|
|
|
|
const Vector<m_type> *dvs = reinterpret_cast<const Vector<m_type> *>(p_ptr); \
|
|
|
|
Vector<m_type_alt> ret; \
|
|
|
|
int len = dvs->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
{ \
|
|
|
|
const m_type *r = dvs->ptr(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
ret.write[i] = r[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
2018-06-25 21:21:57 +02:00
|
|
|
}
|
2020-11-25 14:08:17 +01:00
|
|
|
|
2018-06-25 21:21:57 +02:00
|
|
|
MAKE_VECARG_ALT(String, StringName);
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2020-11-25 14:08:17 +01:00
|
|
|
// For stuff that gets converted to Array vectors.
|
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2017-03-05 16:44:50 +01:00
|
|
|
#define MAKE_VECARR(m_type) \
|
|
|
|
template <> \
|
2020-03-17 07:33:00 +01:00
|
|
|
struct PtrToArg<Vector<m_type>> { \
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
|
|
|
const Array *arr = reinterpret_cast<const Array *>(p_ptr); \
|
|
|
|
Vector<m_type> ret; \
|
|
|
|
int len = arr->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
2018-07-25 03:11:03 +02:00
|
|
|
ret.write[i] = (*arr)[i]; \
|
2017-03-05 16:44:50 +01:00
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
_FORCE_INLINE_ static void encode(Vector<m_type> p_vec, void *p_ptr) { \
|
|
|
|
Array *arr = reinterpret_cast<Array *>(p_ptr); \
|
|
|
|
int len = p_vec.size(); \
|
|
|
|
arr->resize(len); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
(*arr)[i] = p_vec[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const Vector<m_type> &> { \
|
|
|
|
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
|
|
|
const Array *arr = reinterpret_cast<const Array *>(p_ptr); \
|
|
|
|
Vector<m_type> ret; \
|
|
|
|
int len = arr->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
2018-07-25 03:11:03 +02:00
|
|
|
ret.write[i] = (*arr)[i]; \
|
2017-03-05 16:44:50 +01:00
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
}
|
2016-06-23 04:12:20 +02:00
|
|
|
|
|
|
|
MAKE_VECARR(Variant);
|
|
|
|
MAKE_VECARR(RID);
|
|
|
|
MAKE_VECARR(Plane);
|
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2020-02-17 22:06:54 +01:00
|
|
|
#define MAKE_DVECARR(m_type) \
|
|
|
|
template <> \
|
2020-03-17 07:33:00 +01:00
|
|
|
struct PtrToArg<Vector<m_type>> { \
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
|
|
|
const Array *arr = reinterpret_cast<const Array *>(p_ptr); \
|
|
|
|
Vector<m_type> ret; \
|
|
|
|
int len = arr->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
{ \
|
|
|
|
m_type *w = ret.ptrw(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
w[i] = (*arr)[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
_FORCE_INLINE_ static void encode(Vector<m_type> p_vec, void *p_ptr) { \
|
|
|
|
Array *arr = reinterpret_cast<Array *>(p_ptr); \
|
|
|
|
int len = p_vec.size(); \
|
|
|
|
arr->resize(len); \
|
|
|
|
{ \
|
|
|
|
const m_type *r = p_vec.ptr(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
(*arr)[i] = r[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const Vector<m_type> &> { \
|
|
|
|
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
|
|
|
const Array *arr = reinterpret_cast<const Array *>(p_ptr); \
|
|
|
|
Vector<m_type> ret; \
|
|
|
|
int len = arr->size(); \
|
|
|
|
ret.resize(len); \
|
|
|
|
{ \
|
|
|
|
m_type *w = ret.ptrw(); \
|
|
|
|
for (int i = 0; i < len; i++) { \
|
|
|
|
w[i] = (*arr)[i]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return ret; \
|
|
|
|
} \
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2021-05-06 02:48:18 +02:00
|
|
|
// Special case for IPAddress.
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2017-08-12 13:04:30 +02:00
|
|
|
#define MAKE_STRINGCONV_BY_REFERENCE(m_type) \
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<m_type> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
m_type s = *reinterpret_cast<const String *>(p_ptr); \
|
|
|
|
return s; \
|
|
|
|
} \
|
|
|
|
_FORCE_INLINE_ static void encode(const m_type &p_vec, void *p_ptr) { \
|
|
|
|
String *arr = reinterpret_cast<String *>(p_ptr); \
|
|
|
|
*arr = p_vec; \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
template <> \
|
|
|
|
struct PtrToArg<const m_type &> { \
|
|
|
|
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
|
|
|
m_type s = *reinterpret_cast<const String *>(p_ptr); \
|
|
|
|
return s; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2021-05-06 02:48:18 +02:00
|
|
|
MAKE_STRINGCONV_BY_REFERENCE(IPAddress);
|
2016-06-23 04:12:20 +02:00
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2017-03-05 16:44:50 +01:00
|
|
|
template <>
|
2020-03-17 07:33:00 +01:00
|
|
|
struct PtrToArg<Vector<Face3>> {
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ static Vector<Face3> convert(const void *p_ptr) {
|
|
|
|
const Vector<Vector3> *dvs = reinterpret_cast<const Vector<Vector3> *>(p_ptr);
|
|
|
|
Vector<Face3> ret;
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = dvs->size() / 3;
|
2016-06-23 04:12:20 +02:00
|
|
|
ret.resize(len);
|
|
|
|
{
|
2020-02-17 22:06:54 +01:00
|
|
|
const Vector3 *r = dvs->ptr();
|
|
|
|
Face3 *w = ret.ptrw();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
w[i].vertex[0] = r[i * 3 + 0];
|
|
|
|
w[i].vertex[1] = r[i * 3 + 1];
|
|
|
|
w[i].vertex[2] = r[i * 3 + 2];
|
2016-06-23 04:12:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ static void encode(Vector<Face3> p_vec, void *p_ptr) {
|
|
|
|
Vector<Vector3> *arr = reinterpret_cast<Vector<Vector3> *>(p_ptr);
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = p_vec.size();
|
|
|
|
arr->resize(len * 3);
|
|
|
|
{
|
2020-02-17 22:06:54 +01:00
|
|
|
const Face3 *r = p_vec.ptr();
|
|
|
|
Vector3 *w = arr->ptrw();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
w[i * 3 + 0] = r[i].vertex[0];
|
|
|
|
w[i * 3 + 1] = r[i].vertex[1];
|
|
|
|
w[i * 3 + 2] = r[i].vertex[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-23 04:12:20 +02:00
|
|
|
};
|
2020-11-25 14:08:17 +01:00
|
|
|
|
2021-08-23 19:53:27 +02:00
|
|
|
// No EncodeT because direct pointer conversion not possible.
|
2017-03-05 16:44:50 +01:00
|
|
|
template <>
|
2020-02-17 22:06:54 +01:00
|
|
|
struct PtrToArg<const Vector<Face3> &> {
|
|
|
|
_FORCE_INLINE_ static Vector<Face3> convert(const void *p_ptr) {
|
|
|
|
const Vector<Vector3> *dvs = reinterpret_cast<const Vector<Vector3> *>(p_ptr);
|
|
|
|
Vector<Face3> ret;
|
2017-03-05 16:44:50 +01:00
|
|
|
int len = dvs->size() / 3;
|
2016-06-23 04:12:20 +02:00
|
|
|
ret.resize(len);
|
|
|
|
{
|
2020-02-17 22:06:54 +01:00
|
|
|
const Vector3 *r = dvs->ptr();
|
|
|
|
Face3 *w = ret.ptrw();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
w[i].vertex[0] = r[i * 3 + 0];
|
|
|
|
w[i].vertex[1] = r[i * 3 + 1];
|
|
|
|
w[i].vertex[2] = r[i * 3 + 2];
|
2016-06-23 04:12:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // METHOD_PTRCALL_H
|