37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include "IGameServer.h"
|
|
#include <stdexcept>
|
|
|
|
namespace FRG {
|
|
|
|
// Keeps references held by UI and runtime objects stable while campaigns switch
|
|
// between the local and remote implementations.
|
|
class GameServerRouter final : public IGameServer {
|
|
public:
|
|
explicit GameServerRouter(IGameServer& initial)
|
|
: active_(&initial)
|
|
{
|
|
}
|
|
|
|
void use(IGameServer& server) { active_ = &server; }
|
|
std::shared_ptr<const GameSnapshot> snapshot() const override {
|
|
return active_->snapshot();
|
|
}
|
|
const std::string& localPlayerId() const override {
|
|
return active_->localPlayerId();
|
|
}
|
|
void submit(const GameCommand& command) override { active_->submit(command); }
|
|
std::vector<GameServerEvent> drainEvents() override {
|
|
return active_->drainEvents();
|
|
}
|
|
void update(std::int64_t deltaMs) override { active_->update(deltaMs); }
|
|
void save(nlohmann::json& out) const override { active_->save(out); }
|
|
void load(const nlohmann::json& in) override { active_->load(in); }
|
|
|
|
private:
|
|
IGameServer* active_;
|
|
};
|
|
|
|
} // namespace FRG
|