mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Remove g_GUI usage in simulation2/*
This is the last remaining inclusion of a gui file in simulation2/.
This commit is contained in:
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
|
||||
|
|
@ -387,21 +387,19 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
|
|||
return IN_PASS;
|
||||
}
|
||||
|
||||
void CGUIManager::SendEventToAll(const CStr& eventName) const
|
||||
|
||||
void CGUIManager::SendEventToAll(const CStr& eventName,
|
||||
std::optional<JS::HandleValueArray> paramData) const
|
||||
{
|
||||
const auto pageStack = GetCopyOfFrozenStack();
|
||||
|
||||
for (const SGUIPage& p : pageStack)
|
||||
p.gui->SendEventToAll(eventName);
|
||||
|
||||
}
|
||||
|
||||
void CGUIManager::SendEventToAll(const CStr& eventName, JS::HandleValueArray paramData) const
|
||||
{
|
||||
const auto pageStack = GetCopyOfFrozenStack();
|
||||
|
||||
for (const SGUIPage& p : pageStack)
|
||||
p.gui->SendEventToAll(eventName, paramData);
|
||||
{
|
||||
if (paramData.has_value())
|
||||
p.gui->SendEventToAll(eventName, paramData.value());
|
||||
else
|
||||
p.gui->SendEventToAll(eventName);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<bool> CGUIManager::TickObjects()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -103,8 +103,8 @@ public:
|
|||
/**
|
||||
* See CGUI::SendEventToAll; applies to the currently active page.
|
||||
*/
|
||||
void SendEventToAll(const CStr& eventName) const;
|
||||
void SendEventToAll(const CStr& eventName, JS::HandleValueArray paramData) const;
|
||||
void SendEventToAll(const CStr& eventName,
|
||||
std::optional<JS::HandleValueArray> paramData = std::nullopt) const;
|
||||
|
||||
/**
|
||||
* See CGUI::TickObjects; applies to @em all loaded pages.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -501,8 +501,13 @@ static void NonVisualFrame()
|
|||
|
||||
static u32 turn = 0;
|
||||
if (g_Game && g_Game->IsGameStarted() && g_Game->GetTurnManager())
|
||||
if (g_Game->GetTurnManager()->Update(DEFAULT_TURN_LENGTH, 1))
|
||||
{
|
||||
if (g_Game->GetTurnManager()->Update(DEFAULT_TURN_LENGTH, 1,
|
||||
std::bind_front(&CGUIManager::SendEventToAll, g_GUI)))
|
||||
{
|
||||
debug_printf("Turn %u (%u)...\n", turn++, DEFAULT_TURN_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
g_Profiler.Frame();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -79,7 +79,7 @@ void CNetClientTurnManager::NotifyFinishedOwnCommands(u32 turn)
|
|||
m_NetClient.SendMessage(&msg);
|
||||
}
|
||||
|
||||
void CNetClientTurnManager::NotifyFinishedUpdate(u32 turn)
|
||||
void CNetClientTurnManager::NotifyFinishedUpdate(u32 turn, const UpdateCallback&)
|
||||
{
|
||||
bool quick = !TurnNeedsFullHash(turn);
|
||||
std::string hash;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -54,7 +54,7 @@ public:
|
|||
private:
|
||||
void NotifyFinishedOwnCommands(u32 turn) override;
|
||||
|
||||
void NotifyFinishedUpdate(u32 turn) override;
|
||||
void NotifyFinishedUpdate(u32 turn, const UpdateCallback& sendEventToAll) override;
|
||||
|
||||
CNetClient& m_NetClient;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "lib/self_test.h"
|
||||
|
||||
#include "gui/GUIManager.h"
|
||||
#include "lib/debug.h"
|
||||
#include "lib/external_libraries/enet.h"
|
||||
#include "lib/file/file_system.h"
|
||||
|
|
@ -46,6 +47,14 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
void UpdateGame(CGame& game)
|
||||
{
|
||||
game.GetTurnManager()->Update(1.0f, 1, std::bind_front(&CGUIManager::SendEventToAll, g_GUI));
|
||||
}
|
||||
}
|
||||
|
||||
class TestNetComms : public CxxTest::TestSuite
|
||||
{
|
||||
std::optional<CXeromycesEngine> xeromycesEngine;
|
||||
|
|
@ -216,13 +225,13 @@ public:
|
|||
}
|
||||
|
||||
wait(clients, 100);
|
||||
client1Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client2Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client3Game.GetTurnManager()->Update(1.0f, 1);
|
||||
UpdateGame(client1Game);
|
||||
UpdateGame(client2Game);
|
||||
UpdateGame(client3Game);
|
||||
wait(clients, 100);
|
||||
client1Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client2Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client3Game.GetTurnManager()->Update(1.0f, 1);
|
||||
UpdateGame(client1Game);
|
||||
UpdateGame(client2Game);
|
||||
UpdateGame(client3Game);
|
||||
wait(clients, 100);
|
||||
}
|
||||
|
||||
|
|
@ -286,9 +295,9 @@ public:
|
|||
}
|
||||
|
||||
wait(clients, 100);
|
||||
client1Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client2Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client3Game.GetTurnManager()->Update(1.0f, 1);
|
||||
UpdateGame(client1Game);
|
||||
UpdateGame(client2Game);
|
||||
UpdateGame(client3Game);
|
||||
wait(clients, 100);
|
||||
|
||||
{
|
||||
|
|
@ -339,12 +348,12 @@ public:
|
|||
|
||||
wait(clients, 100);
|
||||
|
||||
client1Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client3Game.GetTurnManager()->Update(1.0f, 1);
|
||||
UpdateGame(client1Game);
|
||||
UpdateGame(client3Game);
|
||||
wait(clients, 100);
|
||||
server.SetTurnLength(100);
|
||||
client1Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client3Game.GetTurnManager()->Update(1.0f, 1);
|
||||
UpdateGame(client1Game);
|
||||
UpdateGame(client3Game);
|
||||
wait(clients, 100);
|
||||
|
||||
// (This SetTurnLength thing doesn't actually detect errors unless you change
|
||||
|
|
@ -380,9 +389,9 @@ public:
|
|||
|
||||
for (size_t i = 0; i < 3; ++i)
|
||||
{
|
||||
client1Game.GetTurnManager()->Update(1.0f, 1);
|
||||
client2BGame.GetTurnManager()->Update(1.0f, 1);
|
||||
client3Game.GetTurnManager()->Update(1.0f, 1);
|
||||
UpdateGame(client1Game);
|
||||
UpdateGame(client2BGame);
|
||||
UpdateGame(client3Game);
|
||||
wait(clients, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -431,7 +431,8 @@ void CGame::Update(const double deltaRealTime, bool doInterpolate)
|
|||
// so just use the sim rate itself as the number of turns per frame.
|
||||
size_t maxTurns = (size_t)m_SimRate;
|
||||
|
||||
if (m_TurnManager->Update(deltaSimTime, maxTurns))
|
||||
if (m_TurnManager->Update(deltaSimTime, maxTurns,
|
||||
std::bind_front(&CGUIManager::SendEventToAll, g_GUI)))
|
||||
{
|
||||
{
|
||||
PROFILE3("gui sim update");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -407,7 +407,8 @@ void Interface::ApplyMessage(const GameMessage& msg)
|
|||
{
|
||||
const double deltaSimTime = deltaRealTime * g_Game->GetSimRate();
|
||||
const size_t maxTurns = static_cast<size_t>(g_Game->GetSimRate());
|
||||
g_Game->GetTurnManager()->Update(deltaSimTime, maxTurns);
|
||||
g_Game->GetTurnManager()->Update(deltaSimTime, maxTurns,
|
||||
std::bind_front(&CGUIManager::SendEventToAll, g_GUI));
|
||||
}
|
||||
else
|
||||
g_Game->Update(deltaRealTime);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue