Skip to content

Commit 867efda

Browse files
committed
Sync CowData with upstream Godot. Remove VMap accordingly.
1 parent cb5257a commit 867efda

8 files changed

Lines changed: 583 additions & 690 deletions

File tree

‎include/godot_cpp/core/error_macros.hpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
4848
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool p_editor_notify = false, bool p_fatal = false);
4949
void _err_flush_stdout();
5050

51+
// Normally present in print_string.hpp, added here because our include situation is
52+
// different from upstream godot and some files might otherwise not compile.
53+
bool is_print_verbose_enabled();
54+
5155
} // namespace godot
5256

5357
#ifdef __GNUC__
@@ -708,6 +712,16 @@ void _err_flush_stdout();
708712
} else \
709713
((void)0)
710714

715+
/**
716+
* Warns about `m_msg` only when verbose mode is enabled.
717+
*/
718+
#define WARN_VERBOSE(m_msg) \
719+
{ \
720+
if (is_print_verbose_enabled()) { \
721+
WARN_PRINT(m_msg); \
722+
} \
723+
}
724+
711725
// Print deprecated warning message macros.
712726

713727
/**

‎include/godot_cpp/core/memory.hpp‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,42 @@ T *memnew_arr_template(size_t p_elements) {
199199
return (T *)mem;
200200
}
201201

202+
// Fast alternative to a loop constructor pattern.
203+
template <typename T>
204+
_FORCE_INLINE_ void memnew_arr_placement(T *p_start, size_t p_num) {
205+
if constexpr (is_zero_constructible_v<T>) {
206+
// Can optimize with memset.
207+
memset(static_cast<void *>(p_start), 0, p_num * sizeof(T));
208+
} else {
209+
// Need to use a for loop.
210+
for (size_t i = 0; i < p_num; i++) {
211+
memnew_placement(p_start + i, T());
212+
}
213+
}
214+
}
215+
216+
// Convenient alternative to a loop copy pattern.
217+
template <typename T>
218+
_FORCE_INLINE_ void copy_arr_placement(T *p_dst, const T *p_src, size_t p_num) {
219+
if constexpr (std::is_trivially_copyable_v<T>) {
220+
memcpy((uint8_t *)p_dst, (uint8_t *)p_src, p_num * sizeof(T));
221+
} else {
222+
for (size_t i = 0; i < p_num; i++) {
223+
memnew_placement(p_dst + i, T(p_src[i]));
224+
}
225+
}
226+
}
227+
228+
// Convenient alternative to a loop destructor pattern.
229+
template <typename T>
230+
_FORCE_INLINE_ void destruct_arr_placement(T *p_dst, size_t p_num) {
231+
if constexpr (!std::is_trivially_destructible_v<T>) {
232+
for (size_t i = 0; i < p_num; i++) {
233+
p_dst[i].~T();
234+
}
235+
}
236+
}
237+
202238
template <typename T>
203239
size_t memarr_len(const T *p_class) {
204240
uint8_t *ptr = (uint8_t *)p_class;

0 commit comments

Comments
 (0)