67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
#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<const GameSnapshot> snapshot() const override;
|
|
const std::string& localPlayerId() const override { return localPlayerId_; }
|
|
void submit(const GameCommand& command) override;
|
|
std::vector<GameServerEvent> 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>& location,
|
|
LocationSetup params, AudioPlayerAsync* audioPlayer);
|
|
Location* runtimeLocation(const std::string& id) const;
|
|
bool hasRuntimeLocation(const std::string& id) const;
|
|
std::vector<std::string> loadedRuntimeLocationIds() const;
|
|
void clearRuntimeLocations(bool retainState);
|
|
void bindRuntimeLocation(const std::string& id, std::shared_ptr<Location> 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<std::string, std::shared_ptr<Location>> runtimeLocations_;
|
|
std::uint64_t revision_ = 1;
|
|
mutable std::uint64_t cachedRevision_ = 0;
|
|
mutable std::shared_ptr<const GameSnapshot> cachedSnapshot_;
|
|
std::vector<GameServerEvent> pendingEvents_;
|
|
};
|
|
|
|
} // namespace FRG
|