Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetServer.cpp
Show All 26 Lines | |||||
#include "lib/external_libraries/enet.h" | #include "lib/external_libraries/enet.h" | ||||
#include "lib/types.h" | #include "lib/types.h" | ||||
#include "network/StunClient.h" | #include "network/StunClient.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/GUID.h" | #include "ps/GUID.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "scriptinterface/ScriptContext.h" | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptRuntime.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/system/TurnManager.h" | #include "simulation2/system/TurnManager.h" | ||||
#if CONFIG2_MINIUPNPC | #if CONFIG2_MINIUPNPC | ||||
#include <miniupnpc/miniwget.h> | #include <miniupnpc/miniwget.h> | ||||
#include <miniupnpc/miniupnpc.h> | #include <miniupnpc/miniupnpc.h> | ||||
#include <miniupnpc/upnpcommands.h> | #include <miniupnpc/upnpcommands.h> | ||||
#include <miniupnpc/upnperrors.h> | #include <miniupnpc/upnperrors.h> | ||||
▲ Show 20 Lines • Show All 333 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
debug_SetThreadName("NetServer"); | debug_SetThreadName("NetServer"); | ||||
data->Run(); | data->Run(); | ||||
} | } | ||||
void CNetServerWorker::Run() | void CNetServerWorker::Run() | ||||
{ | { | ||||
// The script runtime uses the profiler and therefore the thread must be registered before the runtime is created | // The script context uses the profiler and therefore the thread must be registered before the context is created | ||||
g_Profiler2.RegisterCurrentThread("Net server"); | g_Profiler2.RegisterCurrentThread("Net server"); | ||||
// To avoid the need for JS_SetContextThread, we create and use and destroy | // We create a new ScriptContext for this network thread, with a single ScriptInterface. | ||||
// the script interface entirely within this network thread | shared_ptr<ScriptContext> netServerContext = ScriptContext::CreateContext(); | ||||
shared_ptr<ScriptRuntime> netServerRuntime = ScriptRuntime::CreateRuntime(); | m_ScriptInterface = new ScriptInterface("Engine", "Net server", netServerContext); | ||||
m_ScriptInterface = new ScriptInterface("Engine", "Net server", netServerRuntime); | |||||
m_GameAttributes.init(m_ScriptInterface->GetJSRuntime(), JS::UndefinedValue()); | m_GameAttributes.init(m_ScriptInterface->GetJSRuntime(), JS::UndefinedValue()); | ||||
while (true) | while (true) | ||||
{ | { | ||||
if (!RunStep()) | if (!RunStep()) | ||||
break; | break; | ||||
// Implement autostart mode | // Implement autostart mode | ||||
Show All 11 Lines | |||||
} | } | ||||
bool CNetServerWorker::RunStep() | bool CNetServerWorker::RunStep() | ||||
{ | { | ||||
// Check for messages from the game thread. | // Check for messages from the game thread. | ||||
// (Do as little work as possible while the mutex is held open, | // (Do as little work as possible while the mutex is held open, | ||||
// to avoid performance problems and deadlocks.) | // to avoid performance problems and deadlocks.) | ||||
m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(0.5f); | m_ScriptInterface->GetContext()->MaybeIncrementalGC(0.5f); | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptInterface::Request rq(m_ScriptInterface); | ||||
std::vector<bool> newStartGame; | std::vector<bool> newStartGame; | ||||
std::vector<std::string> newGameAttributes; | std::vector<std::string> newGameAttributes; | ||||
std::vector<std::pair<CStr, CStr>> newLobbyAuths; | std::vector<std::pair<CStr, CStr>> newLobbyAuths; | ||||
std::vector<u32> newTurnLength; | std::vector<u32> newTurnLength; | ||||
▲ Show 20 Lines • Show All 1,209 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator