Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions include/godot_cpp/core/error_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
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);
void _err_flush_stdout();

// Normally present in print_string.hpp, added here because our include situation is
// different from upstream godot and some files might otherwise not compile.
bool is_print_verbose_enabled();
Comment thread
dsnopek marked this conversation as resolved.

} // namespace godot

#ifdef __GNUC__
Expand Down Expand Up @@ -708,6 +712,16 @@ void _err_flush_stdout();
} else \
((void)0)

/**
* Warns about `m_msg` only when verbose mode is enabled.
*/
#define WARN_VERBOSE(m_msg) \
{ \
if (is_print_verbose_enabled()) { \
WARN_PRINT(m_msg); \
} \
}

// Print deprecated warning message macros.

/**
Expand Down
36 changes: 36 additions & 0 deletions include/godot_cpp/core/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,42 @@ T *memnew_arr_template(size_t p_elements) {
return (T *)mem;
}

// Fast alternative to a loop constructor pattern.
template <typename T>
_FORCE_INLINE_ void memnew_arr_placement(T *p_start, size_t p_num) {
if constexpr (is_zero_constructible_v<T>) {
// Can optimize with memset.
memset(static_cast<void *>(p_start), 0, p_num * sizeof(T));
} else {
// Need to use a for loop.
for (size_t i = 0; i < p_num; i++) {
memnew_placement(p_start + i, T());
}
}
}

// Convenient alternative to a loop copy pattern.
template <typename T>
_FORCE_INLINE_ void copy_arr_placement(T *p_dst, const T *p_src, size_t p_num) {
if constexpr (std::is_trivially_copyable_v<T>) {
memcpy((uint8_t *)p_dst, (uint8_t *)p_src, p_num * sizeof(T));
} else {
for (size_t i = 0; i < p_num; i++) {
memnew_placement(p_dst + i, T(p_src[i]));
}
}
}

// Convenient alternative to a loop destructor pattern.
template <typename T>
_FORCE_INLINE_ void destruct_arr_placement(T *p_dst, size_t p_num) {
if constexpr (!std::is_trivially_destructible_v<T>) {
for (size_t i = 0; i < p_num; i++) {
p_dst[i].~T();
}
}
}

template <typename T>
size_t memarr_len(const T *p_class) {
uint8_t *ptr = (uint8_t *)p_class;
Expand Down
Loading
Loading