Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions include/godot_cpp/core/method_ptrcall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,47 @@ struct PtrToArg<const T *> {
}
};

// Pointers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that this should be kept in sync with https://github.com/godotengine/godot/blob/master/core/variant/native_ptr.h (especially the GDVIRTUAL_NATIVE_PTR calls).

#define GDVIRTUAL_NATIVE_PTR(m_type) \
template <> \
struct PtrToArg<m_type *> { \
_FORCE_INLINE_ static m_type *convert(const void *p_ptr) { \
return (m_type *)(*(void **)p_ptr); \
} \
typedef m_type *EncodeT; \
_FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \
*((void **)p_ptr) = p_var; \
} \
}; \
\
template <> \
struct PtrToArg<const m_type *> { \
_FORCE_INLINE_ static const m_type *convert(const void *p_ptr) { \
return (const m_type *)(*(const void **)p_ptr); \
} \
typedef const m_type *EncodeT; \
_FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \
*((void **)p_ptr) = p_var; \
} \
}

GDVIRTUAL_NATIVE_PTR(bool);
GDVIRTUAL_NATIVE_PTR(char);
GDVIRTUAL_NATIVE_PTR(char16_t);
GDVIRTUAL_NATIVE_PTR(char32_t);
GDVIRTUAL_NATIVE_PTR(wchar_t);
GDVIRTUAL_NATIVE_PTR(uint8_t);
GDVIRTUAL_NATIVE_PTR(uint8_t *);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing with https://github.com/godotengine/godot/blob/master/core/variant/native_ptr.h, this one seems unique here. Is that expected?

Also AudioFrame missing but I guess that's what you meant with "Custom structs are not yet supported."

Copy link
Contributor Author

@Faless Faless Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing with https://github.com/godotengine/godot/blob/master/core/variant/native_ptr.h, this one seems unique here. Is that expected?

Oh I haven't yet merged godotengine/godot#52481 , that's the PacketPeer uint8_t **, hence the GDVIRTUAL_NATIVE_PTR(uint8_t *);

Also AudioFrame missing but I guess that's what you meant with "Custom structs are not yet supported."

Yes, those should be auto-generated

GDVIRTUAL_NATIVE_PTR(int8_t);
GDVIRTUAL_NATIVE_PTR(uint16_t);
GDVIRTUAL_NATIVE_PTR(int16_t);
GDVIRTUAL_NATIVE_PTR(uint32_t);
GDVIRTUAL_NATIVE_PTR(int32_t);
GDVIRTUAL_NATIVE_PTR(int64_t);
GDVIRTUAL_NATIVE_PTR(uint64_t);
GDVIRTUAL_NATIVE_PTR(float);
GDVIRTUAL_NATIVE_PTR(double);

} // namespace godot

#endif // ! GODOT_CPP_METHOD_PTRCALL_HPP