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:
Kawe Mazidjatari 2024-04-20 01:33:34 +02:00
parent 1b6d37725b
commit 101962f5ce
5 changed files with 2 additions and 38 deletions

View File

@ -218,17 +218,6 @@ void CServer::BroadcastMessage(CNetMessage* const msg, const bool onlyActive, co
//---------------------------------------------------------------------------------
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);
LiveAPISystem()->RunFrame();
}
@ -254,6 +243,3 @@ void VServer::Detour(const bool bAttach) const
///////////////////////////////////////////////////////////////////////////////
CServer* g_pServer = nullptr;
CClientExtended CServer::sm_ClientsExtended[MAX_PLAYERS];
std::list<IFrameTask*> g_ServerTaskQueueList;
CFrameTask g_ServerTaskQueue;

View File

@ -112,9 +112,6 @@ static_assert(sizeof(CServer) == 0x25264C0);
extern CServer* g_pServer;
extern std::list<IFrameTask*> g_ServerTaskQueueList;
extern CFrameTask g_ServerTaskQueue;
extern ConVar sv_showconnecting;
extern ConVar sv_pylonVisibility;

View File

@ -117,11 +117,8 @@ bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup)
}
g_TaskQueueList.push_back(&g_TaskQueue);
#ifndef CLIENT_DLL
g_ServerTaskQueueList.push_back(&g_ServerTaskQueue);
#endif // !CLIENT_DLL
g_bAppSystemInit = true;
return CModAppSystemGroup__Create(pModAppSystemGroup);
}

View File

@ -31,18 +31,6 @@ static void SQVM_ServerScript_f(const CCommand& args)
{
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);
}
}

View File

@ -133,11 +133,7 @@ SQBool Script_PrecompileClientScripts(CSquirrelVM* vm)
void Script_Execute(const SQChar* code, const SQCONTEXT context)
{
Assert(context != SQCONTEXT::NONE);
if (context == SQCONTEXT::CLIENT || context == SQCONTEXT::UI)
Assert(ThreadInMainThread());
else if (context == SQCONTEXT::SERVER)
Assert(ThreadInServerFrameThread());
Assert(ThreadInMainOrServerFrameThread());
CSquirrelVM* s = Script_GetScriptHandle(context);
const char* const contextName = s_scriptContextNames[(int)context];