1
0
forked from mirrors/0ad

Remove g_GUI usage in simulation2/*

This is the last remaining inclusion of a gui file in simulation2/.
This commit is contained in:
phosit
2025-11-04 09:14:18 +01:00
parent 153dfe7ef1
commit 03a5198ed3
14 changed files with 78 additions and 60 deletions
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -47,7 +47,7 @@ void CLocalTurnManager::NotifyFinishedOwnCommands(u32 turn)
FinishedAllCommands(turn, m_TurnLength);
}
void CLocalTurnManager::NotifyFinishedUpdate(u32 /*turn*/)
void CLocalTurnManager::NotifyFinishedUpdate(u32 /*turn*/, const UpdateCallback&)
{
#if 0 // this hurts performance and is only useful for verifying log replays
std::string hash;
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -43,7 +43,7 @@ public:
protected:
void NotifyFinishedOwnCommands(u32 turn) override;
virtual void NotifyFinishedUpdate(u32 turn) override;
virtual void NotifyFinishedUpdate(u32 turn, const UpdateCallback& sendEventToAll) override;
};
#endif // INCLUDED_LOCALTURNMANAGER
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -19,7 +19,6 @@
#include "ReplayTurnManager.h"
#include "gui/GUIManager.h"
#include "lib/debug.h"
#include "ps/CLogger.h"
#include "ps/Util.h"
@@ -73,15 +72,15 @@ void CReplayTurnManager::StoreFinalReplayTurn(u32 turn)
m_FinalTurn = turn;
}
void CReplayTurnManager::NotifyFinishedUpdate(u32 turn)
void CReplayTurnManager::NotifyFinishedUpdate(u32 turn, const UpdateCallback& sendEventToAll)
{
if (turn == 1 && m_FinalTurn == 0)
g_GUI->SendEventToAll(EventNameReplayFinished);
sendEventToAll(EventNameReplayFinished, std::nullopt);
if (turn > m_FinalTurn)
return;
DoTurn(turn);
DoTurn(turn, sendEventToAll);
// Compare hash if it exists in the replay and if we didn't have an OOS already
std::map<u32, std::pair<std::string, bool>>::iterator turnHashIt = m_ReplayHash.find(turn);
@@ -117,10 +116,10 @@ void CReplayTurnManager::NotifyFinishedUpdate(u32 turn)
Script::ToJSVal(rq, &expectedHashVal, expectedHash);
std::ignore = paramData.append(expectedHashVal);
g_GUI->SendEventToAll(EventNameReplayOutOfSync, paramData);
sendEventToAll(EventNameReplayOutOfSync, paramData);
}
void CReplayTurnManager::DoTurn(u32 turn)
void CReplayTurnManager::DoTurn(u32 turn, const UpdateCallback& sendEventToAll)
{
debug_printf("Executing turn %u of %u\n", turn, m_FinalTurn);
@@ -137,5 +136,5 @@ void CReplayTurnManager::DoTurn(u32 turn)
}
if (turn == m_FinalTurn)
g_GUI->SendEventToAll(EventNameReplayFinished);
sendEventToAll(EventNameReplayFinished, std::nullopt);
}
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -23,6 +23,7 @@
#include "simulation2/helpers/Player.h"
#include "simulation2/system/LocalTurnManager.h"
#include <js/ValueArray.h>
#include <map>
#include <string>
#include <utility>
@@ -48,9 +49,9 @@ public:
void StoreFinalReplayTurn(u32 turn);
private:
void NotifyFinishedUpdate(u32 turn) override;
void NotifyFinishedUpdate(u32 turn, const UpdateCallback& sendEventToAll) override;
void DoTurn(u32 turn);
void DoTurn(u32 turn, const UpdateCallback& sendEventToAll);
static const CStr EventNameReplayFinished;
static const CStr EventNameReplayOutOfSync;
+2 -2
View File
@@ -70,7 +70,7 @@ void CTurnManager::SetPlayerID(int playerId)
m_PlayerId = playerId;
}
bool CTurnManager::Update(float simFrameLength, size_t maxTurns)
bool CTurnManager::Update(float simFrameLength, size_t maxTurns, const UpdateCallback& sendEventToAll)
{
if (m_CurrentTurn > m_FinalTurn)
return false;
@@ -153,7 +153,7 @@ bool CTurnManager::Update(float simFrameLength, size_t maxTurns)
m_Simulation2.Update(m_TurnLength, commands);
NotifyFinishedUpdate(m_CurrentTurn);
NotifyFinishedUpdate(m_CurrentTurn, sendEventToAll);
// Set the time for the next turn update
m_DeltaSimTime -= m_TurnLength / 1000.f;
+6 -2
View File
@@ -28,6 +28,7 @@
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <js/Value.h>
#include <js/ValueArray.h>
#include <list>
#include <map>
#include <optional>
@@ -88,6 +89,9 @@ class CTurnManager
{
NONCOPYABLE(CTurnManager);
public:
using UpdateCallback =
std::function<void(const std::string&, const std::optional<JS::HandleValueArray>)>;
static const CStr EventNameSavegameLoaded;
/**
@@ -112,7 +116,7 @@ public:
* @param simFrameLength Length of the previous frame, in simulation seconds
* @param maxTurns Maximum number of turns to simulate at once
*/
bool Update(float simFrameLength, size_t maxTurns);
bool Update(float simFrameLength, size_t maxTurns, const UpdateCallback& sendEventToAll);
/**
* Advance the simulation by as much as possible. Intended for catching up
@@ -181,7 +185,7 @@ protected:
/**
* Called when this client has finished a simulation update.
*/
virtual void NotifyFinishedUpdate(u32 turn) = 0;
virtual void NotifyFinishedUpdate(u32 turn, const UpdateCallback& sendEventToAll) = 0;
/**
* Returns whether we should compute a complete state hash for the given turn,