Skip to content

Commit acbafba

Browse files
committed
Sync CowData with upstream Godot. Remove VMap accordingly.
1 parent c9b0f3e commit acbafba

8 files changed

Lines changed: 580 additions & 689 deletions

File tree

include/godot_cpp/core/error_macros.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ 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+
bool is_print_verbose_enabled();
52+
5153
} // namespace godot
5254

5355
#ifdef __GNUC__
@@ -708,6 +710,16 @@ void _err_flush_stdout();
708710
} else \
709711
((void)0)
710712

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

713725
/**

include/godot_cpp/core/memory.hpp

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

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

0 commit comments

Comments
 (0)