#pragma once #include "IGameServer.h" class AudioPlayerAsync; namespace FRG { class Game; class Character; class Location; struct LocationConfig; struct LocationSetup; // In-process implementation used by single-player. GameState exists exactly // once, here; clients see immutable snapshots and mutate it with typed commands. class InternalGameServer final : public IGameServer { public: InternalGameServer(); std::shared_ptr snapshot() const override; const std::string& localPlayerId() const override { return localPlayerId_; } void submit(const GameCommand& command) override; std::vector drainEvents() override; void update(std::int64_t deltaMs) override; void save(nlohmann::json& out) const override; void load(const nlohmann::json& in) override; private: friend class Game; // Host-only lifecycle operations. They never expose authoritative state and // are intentionally absent from IGameServer. void initializeCampaign( const std::string& campaignId, const std::string& questsPath, const std::string& zipFile); void clearCampaign(); void resetCampaign(const std::string& questsPath, const std::string& zipFile); bool prepareLocation(const LocationConfig& config); void setupRuntimeLocation( const std::string& id, const std::shared_ptr& location, LocationSetup params, AudioPlayerAsync* audioPlayer); Location* runtimeLocation(const std::string& id) const; bool hasRuntimeLocation(const std::string& id) const; std::vector loadedRuntimeLocationIds() const; void clearRuntimeLocations(bool retainState); void bindRuntimeLocation(const std::string& id, std::shared_ptr location); void synchronizeRuntimeAuxiliaryState(); void applyStateToRuntime(); void publishMutation(); void ensureBattleZoneTestBot(); void updateBattleZoneTestBot(std::int64_t deltaMs); GameSnapshot buildSnapshot() const; GameState state_; std::string localPlayerId_ = "player"; std::int64_t battleZoneTestBotElapsedMs_ = 0; std::unordered_map> runtimeLocations_; std::uint64_t revision_ = 1; mutable std::uint64_t cachedRevision_ = 0; mutable std::shared_ptr cachedSnapshot_; std::vector pendingEvents_; }; } // namespace FRG