/
superwizard
/
openhmm
Обзор
Документация
Войти
/
superwizard
/
openhmm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
game_service.cpp
71 строка
1 KB
Denis Burlaka
Initial project setup
20 июл 2026, 22:19
Верифицирован
20 июл 2026, 22:19
a818c95
Код
Авторство
О чём код?
#include "game_service.hpp" #include "command.hpp" #include "world.hpp" #include <algorithm> GameService::GameService(World &world) : world(world) {} GameService::~GameService() { stop(); if (thread.joinable()) thread.join(); } void GameService::start() { running = true; thread = std::thread(&GameService::run, this); } void GameService::stop() { running = false; } std::unique_lock<std::mutex> GameService::lock() const { return std::unique_lock(mutex); } World &GameService::getWorld() { return world; } const World &GameService::getWorld() const { return world; } void GameService::addCommand(std::unique_ptr<Command> cmd, std::size_t heroIndex) { auto lk = lock(); commands.push_back({std::move(cmd), heroIndex}); } void GameService::run() { using namespace std::chrono_literals; constexpr auto tick = 32ms; auto next = std::chrono::steady_clock::now(); while (running) { { auto lk = lock(); for (auto &entry : commands) entry.cmd->execute(world.hero(entry.heroIndex)); commands.erase( std::remove_if(commands.begin(), commands.end(), [](const auto &e) { return e.cmd->isFinished(); }), commands.end()); } next += tick; std::this_thread::sleep_until(next); } }