mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Engine: simplify "script" command callback for server
Code actually doesn't need to be ran in the server frame thread. All the code really does is preparation work. Run it in the main thread but do join the server frame thread (FCVAR_SERVER_FRAME_THREAD) as we can't do concurrent work on the server VM.
This commit is contained in:
parent
1b6d37725b
commit
101962f5ce
@ -218,17 +218,6 @@ void CServer::BroadcastMessage(CNetMessage* const msg, const bool onlyActive, co
|
|||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
void CServer::FrameJob(double flFrameTime, bool bRunOverlays, bool bUpdateFrame)
|
void CServer::FrameJob(double flFrameTime, bool bRunOverlays, bool bUpdateFrame)
|
||||||
{
|
{
|
||||||
for (IFrameTask* const& task : g_ServerTaskQueueList)
|
|
||||||
{
|
|
||||||
task->RunFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ServerTaskQueueList.erase(std::remove_if(g_ServerTaskQueueList.begin(),
|
|
||||||
g_ServerTaskQueueList.end(), [](const IFrameTask* task)
|
|
||||||
{
|
|
||||||
return task->IsFinished();
|
|
||||||
}), g_ServerTaskQueueList.end());
|
|
||||||
|
|
||||||
CServer__FrameJob(flFrameTime, bRunOverlays, bUpdateFrame);
|
CServer__FrameJob(flFrameTime, bRunOverlays, bUpdateFrame);
|
||||||
LiveAPISystem()->RunFrame();
|
LiveAPISystem()->RunFrame();
|
||||||
}
|
}
|
||||||
@ -254,6 +243,3 @@ void VServer::Detour(const bool bAttach) const
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
CServer* g_pServer = nullptr;
|
CServer* g_pServer = nullptr;
|
||||||
CClientExtended CServer::sm_ClientsExtended[MAX_PLAYERS];
|
CClientExtended CServer::sm_ClientsExtended[MAX_PLAYERS];
|
||||||
|
|
||||||
std::list<IFrameTask*> g_ServerTaskQueueList;
|
|
||||||
CFrameTask g_ServerTaskQueue;
|
|
||||||
|
@ -112,9 +112,6 @@ static_assert(sizeof(CServer) == 0x25264C0);
|
|||||||
|
|
||||||
extern CServer* g_pServer;
|
extern CServer* g_pServer;
|
||||||
|
|
||||||
extern std::list<IFrameTask*> g_ServerTaskQueueList;
|
|
||||||
extern CFrameTask g_ServerTaskQueue;
|
|
||||||
|
|
||||||
extern ConVar sv_showconnecting;
|
extern ConVar sv_showconnecting;
|
||||||
|
|
||||||
extern ConVar sv_pylonVisibility;
|
extern ConVar sv_pylonVisibility;
|
||||||
|
@ -117,11 +117,8 @@ bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_TaskQueueList.push_back(&g_TaskQueue);
|
g_TaskQueueList.push_back(&g_TaskQueue);
|
||||||
#ifndef CLIENT_DLL
|
|
||||||
g_ServerTaskQueueList.push_back(&g_ServerTaskQueue);
|
|
||||||
#endif // !CLIENT_DLL
|
|
||||||
|
|
||||||
g_bAppSystemInit = true;
|
g_bAppSystemInit = true;
|
||||||
|
|
||||||
return CModAppSystemGroup__Create(pModAppSystemGroup);
|
return CModAppSystemGroup__Create(pModAppSystemGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,18 +31,6 @@ static void SQVM_ServerScript_f(const CCommand& args)
|
|||||||
{
|
{
|
||||||
if (args.ArgC() >= 2)
|
if (args.ArgC() >= 2)
|
||||||
{
|
{
|
||||||
const char* code = args.ArgS();
|
|
||||||
|
|
||||||
if (!ThreadInServerFrameThread())
|
|
||||||
{
|
|
||||||
const string scode(code);
|
|
||||||
g_ServerTaskQueue.Dispatch([scode]()
|
|
||||||
{
|
|
||||||
Script_Execute(scode.c_str(), SQCONTEXT::SERVER);
|
|
||||||
}, 0);
|
|
||||||
return; // Only run in server frame thread.
|
|
||||||
}
|
|
||||||
|
|
||||||
Script_Execute(args.ArgS(), SQCONTEXT::SERVER);
|
Script_Execute(args.ArgS(), SQCONTEXT::SERVER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,11 +133,7 @@ SQBool Script_PrecompileClientScripts(CSquirrelVM* vm)
|
|||||||
void Script_Execute(const SQChar* code, const SQCONTEXT context)
|
void Script_Execute(const SQChar* code, const SQCONTEXT context)
|
||||||
{
|
{
|
||||||
Assert(context != SQCONTEXT::NONE);
|
Assert(context != SQCONTEXT::NONE);
|
||||||
|
Assert(ThreadInMainOrServerFrameThread());
|
||||||
if (context == SQCONTEXT::CLIENT || context == SQCONTEXT::UI)
|
|
||||||
Assert(ThreadInMainThread());
|
|
||||||
else if (context == SQCONTEXT::SERVER)
|
|
||||||
Assert(ThreadInServerFrameThread());
|
|
||||||
|
|
||||||
CSquirrelVM* s = Script_GetScriptHandle(context);
|
CSquirrelVM* s = Script_GetScriptHandle(context);
|
||||||
const char* const contextName = s_scriptContextNames[(int)context];
|
const char* const contextName = s_scriptContextNames[(int)context];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user