Skip to content

Commit

Permalink
Fixed Timestep Interpolation (3D)
Browse files Browse the repository at this point in the history
Adds 3D fixed timestep interpolation to the rendering server.
This does not yet include support for multimeshes or particles.

Co-authored-by: lawnjelly <[email protected]>
  • Loading branch information
rburing and lawnjelly committed Jul 7, 2024
1 parent 42e5b3a commit 2f8ab4a
Show file tree
Hide file tree
Showing 31 changed files with 1,470 additions and 69 deletions.
51 changes: 51 additions & 0 deletions core/error/error_macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include "core/os/os.h"
#include "core/string/ustring.h"

// Optional physics interpolation warnings try to include the path to the relevant node.
#if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
#include "core/config/project_settings.h"
#include "scene/main/node.h"
#endif

static ErrorHandlerList *error_handler_list = nullptr;

void add_error_handler(ErrorHandlerList *p_handler) {
Expand Down Expand Up @@ -128,3 +134,48 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
void _err_flush_stdout() {
fflush(stdout);
}

// Prevent error spam by limiting the warnings to a certain frequency.
void _physics_interpolation_warning(const char *p_function, const char *p_file, int p_line, ObjectID p_id, const char *p_warn_string) {
#if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
const uint32_t warn_max = 2048;
const uint32_t warn_timeout_seconds = 15;

static uint32_t warn_count = warn_max;
static uint32_t warn_timeout = warn_timeout_seconds;

uint32_t time_now = UINT32_MAX;

if (warn_count) {
warn_count--;
}

if (!warn_count) {
time_now = OS::get_singleton()->get_ticks_msec() / 1000;
}

if ((warn_count == 0) && (time_now >= warn_timeout)) {
warn_count = warn_max;
warn_timeout = time_now + warn_timeout_seconds;

if (GLOBAL_GET("debug/settings/physics_interpolation/enable_warnings")) {
// UINT64_MAX means unused.
if (p_id.operator uint64_t() == UINT64_MAX) {
_err_print_error(p_function, p_file, p_line, "[Physics interpolation] " + String(p_warn_string) + " (possibly benign).", false, ERR_HANDLER_WARNING);
} else {
String node_name;
if (p_id.is_valid()) {
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(p_id));
if (node && node->is_inside_tree()) {
node_name = "\"" + String(node->get_path()) + "\"";
} else {
node_name = "\"unknown\"";
}
}

_err_print_error(p_function, p_file, p_line, "[Physics interpolation] " + String(p_warn_string) + ": " + node_name + " (possibly benign).", false, ERR_HANDLER_WARNING);
}
}
}
#endif
}
13 changes: 13 additions & 0 deletions core/error/error_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef ERROR_MACROS_H
#define ERROR_MACROS_H

#include "core/object/object_id.h"
#include "core/typedefs.h"

#include <atomic> // We'd normally use safe_refcount.h, but that would cause circular includes.
Expand Down Expand Up @@ -71,6 +72,8 @@ 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 fatal = false);
void _err_flush_stdout();

void _physics_interpolation_warning(const char *p_function, const char *p_file, int p_line, ObjectID p_id, const char *p_warn_string);

#ifdef __GNUC__
//#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
#define FUNCTION_STR __FUNCTION__
Expand Down Expand Up @@ -832,4 +835,14 @@ void _err_flush_stdout();
#define DEV_CHECK_ONCE(m_cond)
#endif

/**
* Physics Interpolation warnings.
* These are spam protection warnings.
*/
#define PHYSICS_INTERPOLATION_NODE_WARNING(m_object_id, m_string) \
_physics_interpolation_warning(FUNCTION_STR, __FILE__, __LINE__, m_object_id, m_string)

#define PHYSICS_INTERPOLATION_WARNING(m_string) \
_physics_interpolation_warning(FUNCTION_STR, __FILE__, __LINE__, UINT64_MAX, m_string)

#endif // ERROR_MACROS_H
Loading

0 comments on commit 2f8ab4a

Please sign in to comment.