mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
make timer cleaner
This commit is contained in:
parent
a2b056f385
commit
bfe09374bb
@ -68,19 +68,17 @@ void OrganizerSceneService::sceneFixedUpdate(Engine&) {
|
|||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
|
|
||||||
auto newNow = clock::now();
|
auto newNow = clock::now();
|
||||||
auto deltaTime = std::chrono::duration_cast<std::chrono::nanoseconds>(newNow - _last_time);
|
std::chrono::duration<double, std::ratio<1, 1>> deltaTime = newNow - _last_time;
|
||||||
_last_time = newNow;
|
_last_time = newNow;
|
||||||
_accumulator += deltaTime.count();
|
_accumulator += deltaTime.count();
|
||||||
const double dt = f_delta * 1'000'000'000.0;
|
|
||||||
|
|
||||||
size_t continuous_counter = 0;
|
size_t continuous_counter = 0;
|
||||||
|
|
||||||
auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, initial_delta_factor);
|
auto& time_ctx = _scene->ctx_or_set<MM::Components::TimeDelta>(f_delta, initial_delta_factor);
|
||||||
time_ctx.tickDelta = f_delta * time_ctx.deltaFactor;
|
time_ctx.tickDelta = f_delta * time_ctx.deltaFactor;
|
||||||
|
|
||||||
// TODO: this while is just cancer
|
while (_accumulator >= f_delta){
|
||||||
while (_accumulator >= static_cast<decltype(_accumulator)>(dt)){
|
_accumulator -= f_delta;
|
||||||
_accumulator -= static_cast<decltype(_accumulator)>(dt);
|
|
||||||
continuous_counter++;
|
continuous_counter++;
|
||||||
|
|
||||||
for (auto&& v : _scene->ctx<std::vector<entt::organizer::vertex>>()) {
|
for (auto&& v : _scene->ctx<std::vector<entt::organizer::vertex>>()) {
|
||||||
@ -133,7 +131,7 @@ void OrganizerSceneService::updateOrganizerVertices(Scene& scene) {
|
|||||||
|
|
||||||
void OrganizerSceneService::resetTime(void) {
|
void OrganizerSceneService::resetTime(void) {
|
||||||
_last_time = clock::now();
|
_last_time = clock::now();
|
||||||
_accumulator = 0;
|
_accumulator = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // MM::Services
|
} // MM::Services
|
||||||
|
@ -14,7 +14,7 @@ namespace MM::Services {
|
|||||||
std::unique_ptr<Scene> _next_scene; // enqueued next scene
|
std::unique_ptr<Scene> _next_scene; // enqueued next scene
|
||||||
|
|
||||||
using clock = std::chrono::high_resolution_clock;
|
using clock = std::chrono::high_resolution_clock;
|
||||||
long long int _accumulator = 0;
|
double _accumulator = 0.0;
|
||||||
std::chrono::time_point<clock> _last_time;
|
std::chrono::time_point<clock> _last_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user