Skip to content

Commit

Permalink
Returned godot::Timer instead of std::chrono in the web build.
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Nov 5, 2024
1 parent d180911 commit 5f00e28
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/3d/debug_draw_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,6 @@ void DebugDraw3D::draw_square(const Vector3 &position, const real_t &size, const
ZoneScoped;
CHECK_BEFORE_CALL();

Transform3D t(Basis().scaled(VEC3_ONE(size)), position);

LOCK_GUARD(datalock);
GET_SCOPED_CFG_AND_DGC();

Expand All @@ -1179,7 +1177,7 @@ void DebugDraw3D::draw_square(const Vector3 &position, const real_t &size, const
InstanceType::BILLBOARD_SQUARE,
duration,
GET_PROC_TYPE(),
FIX_PRECISION_TRANSFORM(t),
Transform3D(Basis().scaled(VEC3_ONE(size)), FIX_PRECISION_POSITION(position)),
IS_DEFAULT_COLOR(color) ? Colors::red : color,
SphereBounds(position, MathUtils::CubeRadiusForSphere * size),
&Colors::empty_color);
Expand Down
2 changes: 0 additions & 2 deletions src/resources/billboard_unshaded.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ render_mode cull_back, shadows_disabled, unshaded
;
#endif

uniform sampler2D depth_value : hint_depth_texture;

void vertex()
{
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
Expand Down
36 changes: 32 additions & 4 deletions src/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class Utils {
};

#ifndef DISABLE_DEBUG_RENDERING
#ifndef WEB_ENABLED
#include <chrono>

class GodotScopedStopwatch {
Expand All @@ -338,13 +339,40 @@ class GodotScopedStopwatch {
}

~GodotScopedStopwatch() {
using namespace std::chrono;
if (m_add)
*m_time_val += static_cast<int64_t>(duration_cast<microseconds>(high_resolution_clock::now() - start_time).count());
*m_time_val += static_cast<int64_t>(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start_time).count());
else
*m_time_val = static_cast<int64_t>(duration_cast<microseconds>(high_resolution_clock::now() - start_time).count());
*m_time_val = static_cast<int64_t>(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start_time).count());
}
};
#else
// TODO delete when the minimum version is upgraded.
// cannot be deleted due to a mismatch in the Emscripten version.
// 4.2.3 or 4.3
GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/time.hpp>
GODOT_WARNING_RESTORE()

class GodotScopedStopwatch {
uint64_t start_time;
int64_t *m_time_val;
bool m_add;

public:
GodotScopedStopwatch(int64_t *p_time_val, bool p_add) {
m_time_val = p_time_val;
m_add = p_add;
start_time = godot::Time::get_singleton()->get_ticks_usec();
}

~GodotScopedStopwatch() {
if (m_add)
*m_time_val += godot::Time::get_singleton()->get_ticks_usec() - start_time;
else
*m_time_val = godot::Time::get_singleton()->get_ticks_usec() - start_time;
}
};
#endif

#define _GODOT_STOPWATCH_CONCAT_IMPL(name1, name2) name1##name2
#define _GODOT_STOPWATCH_CONCAT(name1, name2) _GODOT_STOPWATCH_CONCAT_IMPL(name1, name2)
Expand All @@ -353,4 +381,4 @@ class GodotScopedStopwatch {
#else
#define GODOT_STOPWATCH(time_val)
#define GODOT_STOPWATCH_ADD(time_val)
#endif
#endif

0 comments on commit 5f00e28

Please sign in to comment.