mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Replay refactor whit namespace
This commit is contained in:
parent
fcb1a4c121
commit
c6c0314759
7 changed files with 57 additions and 42 deletions
|
|
@ -69,6 +69,7 @@ namespace Script { class Interface; }
|
|||
namespace Script { class Request; }
|
||||
struct SDL_Event_;
|
||||
struct SGUIImageEffects;
|
||||
union SDL_Event;
|
||||
|
||||
extern const double SELECT_DBLCLICK_RATE;
|
||||
|
||||
|
|
@ -132,11 +133,11 @@ public:
|
|||
void DrawSprite(const CGUISpriteInstance& Sprite, CCanvas2D& canvas, const CRect& Rect, const CRect& Clipping = CRect());
|
||||
|
||||
/**
|
||||
* The replacement of Process(), handles an SDL_Event_
|
||||
* The replacement of Process(), handles an SDL_Event
|
||||
*
|
||||
* @param ev SDL Event, like mouse/keyboard input
|
||||
*/
|
||||
InReaction HandleEvent(const SDL_Event_* ev);
|
||||
InReaction HandleEvent(const SDL_Event& ev);
|
||||
|
||||
/**
|
||||
* Load a GUI XML file into the GUI.
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ template<> void Script::ToJSVal<SDL_Event_>(const Script::Request& rq, JS::Mutab
|
|||
{
|
||||
const char* typeName;
|
||||
|
||||
switch (val.ev.type)
|
||||
switch (ev.type)
|
||||
{
|
||||
case SDL_WINDOWEVENT: typeName = "windowevent"; break;
|
||||
case SDL_KEYDOWN: typeName = "keydown"; break;
|
||||
|
|
@ -85,13 +85,13 @@ template<> void Script::ToJSVal<SDL_Event_>(const Script::Request& rq, JS::Mutab
|
|||
|
||||
SET(obj, "type", typeName);
|
||||
|
||||
switch (val.ev.type)
|
||||
switch (ev.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
// SET(obj, "which", (int)val.ev.key.which); // (not in wsdl.h)
|
||||
// SET(obj, "state", (int)val.ev.key.state); // (not in wsdl.h)
|
||||
// SET(obj, "which", static_cast<int>(ev.key.which)); // (not in wsdl.h)
|
||||
// SET(obj, "state", static_cast<int>(ev.key.state)); // (not in wsdl.h)
|
||||
|
||||
JS::RootedObject keysym(rq.cx, JS_NewPlainObject(rq.cx));
|
||||
if (!keysym)
|
||||
|
|
@ -102,9 +102,9 @@ template<> void Script::ToJSVal<SDL_Event_>(const Script::Request& rq, JS::Mutab
|
|||
JS::RootedValue keysymVal(rq.cx, JS::ObjectValue(*keysym));
|
||||
JS_SetProperty(rq.cx, obj, "keysym", keysymVal);
|
||||
|
||||
// SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h)
|
||||
SET(keysym, "sym", (int)val.ev.key.keysym.sym);
|
||||
// SET(keysym, "mod", (int)val.ev.key.keysym.mod); // (not in wsdl.h)
|
||||
// SET(keysym, "scancode", static_cast<int>(ev.key.keysym.scancode)); // (not in wsdl.h)
|
||||
SET(keysym, "sym", static_cast<int>(ev.key.keysym.sym));
|
||||
// SET(keysym, "mod", static_cast<int>(ev.key.keysym.mod)); // (not in wsdl.h)
|
||||
{
|
||||
SET(keysym, "unicode", JS::UndefinedHandleValue);
|
||||
}
|
||||
|
|
@ -115,23 +115,23 @@ template<> void Script::ToJSVal<SDL_Event_>(const Script::Request& rq, JS::Mutab
|
|||
}
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
// SET(obj, "which", (int)val.ev.motion.which); // (not in wsdl.h)
|
||||
// SET(obj, "state", (int)val.ev.motion.state); // (not in wsdl.h)
|
||||
SET(obj, "x", (int)val.ev.motion.x);
|
||||
SET(obj, "y", (int)val.ev.motion.y);
|
||||
// SET(obj, "xrel", (int)val.ev.motion.xrel); // (not in wsdl.h)
|
||||
// SET(obj, "yrel", (int)val.ev.motion.yrel); // (not in wsdl.h)
|
||||
// SET(obj, "which", static_cast<int>(ev.motion.which)); // (not in wsdl.h)
|
||||
// SET(obj, "state", static_cast<int>(ev.motion.state)); // (not in wsdl.h)
|
||||
SET(obj, "x", static_cast<int>(ev.motion.x));
|
||||
SET(obj, "y", static_cast<int>(ev.motion.y));
|
||||
// SET(obj, "xrel", static_cast<int>(ev.motion.xrel)); // (not in wsdl.h)
|
||||
// SET(obj, "yrel", static_cast<int>(ev.motion.yrel)); // (not in wsdl.h)
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
// SET(obj, "which", (int)val.ev.button.which); // (not in wsdl.h)
|
||||
SET(obj, "button", (int)val.ev.button.button);
|
||||
SET(obj, "state", (int)val.ev.button.state);
|
||||
SET(obj, "x", (int)val.ev.button.x);
|
||||
SET(obj, "y", (int)val.ev.button.y);
|
||||
SET(obj, "clicks", (int)val.ev.button.clicks);
|
||||
// SET(obj, "which", static_cast<int>(ev.button.which)); // (not in wsdl.h)
|
||||
SET(obj, "button", static_cast<int>(ev.button.button));
|
||||
SET(obj, "state", static_cast<int>(ev.button.state));
|
||||
SET(obj, "x", static_cast<int>(ev.button.x));
|
||||
SET(obj, "y", static_cast<int>(ev.button.y));
|
||||
SET(obj, "clicks", static_cast<int>(ev.button.clicks));
|
||||
break;
|
||||
}
|
||||
case SDL_HOTKEYPRESS:
|
||||
|
|
@ -140,7 +140,7 @@ template<> void Script::ToJSVal<SDL_Event_>(const Script::Request& rq, JS::Mutab
|
|||
case SDL_HOTKEYPRESS_SILENT:
|
||||
case SDL_HOTKEYUP_SILENT:
|
||||
{
|
||||
SET(obj, "hotkey", static_cast<const char*>(val.ev.user.data1));
|
||||
SET(obj, "hotkey", static_cast<const char*>(ev.user.data1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,6 +159,8 @@ CNetClient::CNetClient(CGame* game, const CStrW& username, const CStr& hostJID,
|
|||
|
||||
CNetClient::~CNetClient()
|
||||
{
|
||||
Unregister(nullptr);
|
||||
|
||||
// Try to flush messages before dying (probably fails).
|
||||
if (m_ClientTurnManager)
|
||||
m_ClientTurnManager->OnDestroyConnection();
|
||||
|
|
@ -364,17 +366,25 @@ void CNetClient::CheckServerConnection()
|
|||
|
||||
JSObject* CNetClient::GetNextGUIMessage(const Script::Interface& guiInterface)
|
||||
{
|
||||
const Script::Request rq{guiInterface};
|
||||
Unregister(nullptr);
|
||||
const ScriptRequest rq{guiInterface};
|
||||
m_GuiMessagePoll.emplace(GuiPollData{guiInterface, {rq.cx, JS::NewPromiseObject(rq.cx, nullptr)}});
|
||||
|
||||
FetchMessage();
|
||||
return m_GuiMessagePoll.value().promise;
|
||||
}
|
||||
|
||||
void CNetClient::Unregister(const Script::Interface& guiInterface)
|
||||
void CNetClient::Unregister(const Script::Interface* guiInterface)
|
||||
{
|
||||
if (m_GuiMessagePoll.has_value() && &m_GuiMessagePoll.value().interface == &guiInterface)
|
||||
m_GuiMessagePoll.reset();
|
||||
if (!m_GuiMessagePoll.has_value() ||
|
||||
(guiInterface && &m_GuiMessagePoll.value().interface != guiInterface))
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto& [interface, promise] = m_GuiMessagePoll.value();
|
||||
const ScriptRequest oldRq{interface};
|
||||
JS::ResolvePromise(oldRq.cx, promise, JS::UndefinedHandleValue);
|
||||
m_GuiMessagePoll.reset();
|
||||
}
|
||||
|
||||
void CNetClient::FetchMessage()
|
||||
|
|
|
|||
|
|
@ -541,7 +541,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
|||
new CProfileViewer;
|
||||
new CProfileManager; // before any script code
|
||||
|
||||
g_ScriptStatsTable = new CScriptStatsTable;
|
||||
g_ScriptStatsTable = new Script::CScriptStatsTable;
|
||||
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
|
||||
|
||||
// Set up the console early, so that debugging
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
|
|||
|
||||
new CProfileViewer;
|
||||
new CProfileManager;
|
||||
g_ScriptStatsTable = new CScriptStatsTable;
|
||||
g_ScriptStatsTable = new Script::CScriptStatsTable;
|
||||
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
|
||||
|
||||
const int contextSize = 384 * 1024 * 1024;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <cstdint>
|
||||
#include <js/GCAPI.h>
|
||||
|
||||
CScriptStatsTable* g_ScriptStatsTable;
|
||||
Script::CScriptStatsTable* g_ScriptStatsTable;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -34,16 +34,16 @@ enum
|
|||
NumberRows
|
||||
};
|
||||
|
||||
CScriptStatsTable::CScriptStatsTable()
|
||||
Script::CScriptStatsTable::CScriptStatsTable()
|
||||
{
|
||||
}
|
||||
|
||||
void CScriptStatsTable::Add(const Script::Interface* scriptInterface, const std::string& title)
|
||||
void Script::CScriptStatsTable::Add(const Script::Interface* scriptInterface, const std::string& title)
|
||||
{
|
||||
m_ScriptInterfaces.emplace_back(scriptInterface, title);
|
||||
}
|
||||
|
||||
void CScriptStatsTable::Remove(const Script::Interface* scriptInterface)
|
||||
void Script::CScriptStatsTable::Remove(const Script::Interface* scriptInterface)
|
||||
{
|
||||
for (size_t i = 0; i < m_ScriptInterfaces.size(); )
|
||||
{
|
||||
|
|
@ -54,22 +54,22 @@ void CScriptStatsTable::Remove(const Script::Interface* scriptInterface)
|
|||
}
|
||||
}
|
||||
|
||||
CStr CScriptStatsTable::GetName()
|
||||
CStr Script::CScriptStatsTable::GetName()
|
||||
{
|
||||
return "script";
|
||||
}
|
||||
|
||||
CStr CScriptStatsTable::GetTitle()
|
||||
CStr Script::CScriptStatsTable::GetTitle()
|
||||
{
|
||||
return "Script statistics";
|
||||
}
|
||||
|
||||
size_t CScriptStatsTable::GetNumberRows()
|
||||
size_t Script::CScriptStatsTable::GetNumberRows()
|
||||
{
|
||||
return NumberRows;
|
||||
}
|
||||
|
||||
const std::vector<ProfileColumn>& CScriptStatsTable::GetColumns()
|
||||
const std::vector<ProfileColumn>& Script::CScriptStatsTable::GetColumns()
|
||||
{
|
||||
m_ColumnDescriptions.clear();
|
||||
m_ColumnDescriptions.push_back(ProfileColumn("Name", 200));
|
||||
|
|
@ -78,7 +78,7 @@ const std::vector<ProfileColumn>& CScriptStatsTable::GetColumns()
|
|||
return m_ColumnDescriptions;
|
||||
}
|
||||
|
||||
CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
|
||||
CStr Script::CScriptStatsTable::GetCellText(size_t row, size_t col)
|
||||
{
|
||||
switch(row)
|
||||
{
|
||||
|
|
@ -108,7 +108,7 @@ CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
|
|||
}
|
||||
}
|
||||
|
||||
AbstractProfileTable* CScriptStatsTable::GetChild(size_t /*row*/)
|
||||
AbstractProfileTable* Script::CScriptStatsTable::GetChild(size_t /*row*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SCRIPTSTATS
|
||||
#define INCLUDED_SCRIPTSTATS
|
||||
#ifndef INCLUDED_SCRIPT_STATS
|
||||
#define INCLUDED_SCRIPT_STATS
|
||||
|
||||
#include "lib/code_annotation.h"
|
||||
#include "ps/CStr.h"
|
||||
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
namespace Script { class Interface; }
|
||||
|
||||
namespace Script {
|
||||
|
||||
class CScriptStatsTable : public AbstractProfileTable
|
||||
{
|
||||
NONCOPYABLE(CScriptStatsTable);
|
||||
|
|
@ -50,8 +52,10 @@ private:
|
|||
std::vector<ProfileColumn> m_ColumnDescriptions;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// To simplify the UI we want to use a single table for all script interfaces,
|
||||
// so just make it a global that they can all add themselves to
|
||||
extern CScriptStatsTable* g_ScriptStatsTable;
|
||||
extern Script::CScriptStatsTable* g_ScriptStatsTable;
|
||||
|
||||
#endif // INCLUDED_SCRIPTSTATS
|
||||
#endif // INCLUDED_SCRIPT_STATS
|
||||
|
|
|
|||
Loading…
Reference in a new issue