light/modules/app/private/application.cpp

56 lines
1.1 KiB
C++
Raw Permalink Normal View History

#include <app/application.hpp>
#include <app/system.hpp>
#include <memory/reference.hpp>
namespace lt::app {
2025-07-11 01:42:56 +03:30
void Application::game_loop()
2022-03-07 21:57:00 +03:30
{
while (true)
2025-07-11 00:49:04 +03:30
{
for (auto &system : m_systems)
2025-07-06 17:23:28 +03:30
{
const auto &last_tick = system->get_last_tick_result();
const auto now = std::chrono::steady_clock::now();
system->tick(
TickInfo {
.delta_time = now - last_tick.end_time,
.budget = std::chrono::milliseconds { 10 },
.start_time = now,
}
);
2025-07-06 17:23:28 +03:30
}
2021-05-23 18:10:11 +04:30
for (auto &system : m_systems_to_be_registered)
{
m_systems.emplace_back(system)->on_register();
}
for (auto &system : m_systems_to_be_unregistered)
2025-07-06 16:30:38 +03:30
{
m_systems.erase(
std::remove(m_systems.begin(), m_systems.end(), system),
m_systems.end()
);
2025-07-06 16:30:38 +03:30
}
2021-06-15 09:39:11 +04:30
if (m_systems.empty())
2025-07-06 16:30:38 +03:30
{
2022-03-07 21:57:00 +03:30
return;
2025-07-06 16:30:38 +03:30
}
}
2022-03-07 21:57:00 +03:30
}
void Application::register_system(memory::Ref<app::ISystem> system)
2025-07-11 00:24:44 +03:30
{
m_systems.emplace_back(std::move(system));
2025-07-11 00:24:44 +03:30
}
void Application::unregister_system(memory::Ref<app::ISystem> system)
2022-03-07 21:57:00 +03:30
{
m_systems_to_be_unregistered.emplace_back(std::move(system));
2022-03-07 21:57:00 +03:30
}
} // namespace lt::app