本文整理汇总了C++中CNetServerSession::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetServerSession::Update方法的具体用法?C++ CNetServerSession::Update怎么用?C++ CNetServerSession::Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNetServerSession
的用法示例。
在下文中一共展示了CNetServerSession::Update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RunStep
bool CNetServerWorker::RunStep()
{
// Check for messages from the game thread.
// (Do as little work as possible while the mutex is held open,
// to avoid performance problems and deadlocks.)
m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(0.5f);
JSContext* cx = m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);
std::vector<std::pair<int, CStr> > newAssignPlayer;
std::vector<bool> newStartGame;
std::vector<std::pair<CStr, int> > newPlayerReady;
std::vector<bool> newPlayerResetReady;
std::vector<std::string> newGameAttributes;
std::vector<u32> newTurnLength;
{
CScopeLock lock(m_WorkerMutex);
if (m_Shutdown)
return false;
newStartGame.swap(m_StartGameQueue);
newPlayerReady.swap(m_PlayerReadyQueue);
newPlayerResetReady.swap(m_PlayerResetReadyQueue);
newAssignPlayer.swap(m_AssignPlayerQueue);
newGameAttributes.swap(m_GameAttributesQueue);
newTurnLength.swap(m_TurnLengthQueue);
}
for (size_t i = 0; i < newAssignPlayer.size(); ++i)
AssignPlayer(newAssignPlayer[i].first, newAssignPlayer[i].second);
for (size_t i = 0; i < newPlayerReady.size(); ++i)
SetPlayerReady(newPlayerReady[i].first, newPlayerReady[i].second);
if (!newPlayerResetReady.empty())
ClearAllPlayerReady();
if (!newGameAttributes.empty())
{
JS::RootedValue gameAttributesVal(cx);
GetScriptInterface().ParseJSON(newGameAttributes.back(), &gameAttributesVal);
UpdateGameAttributes(&gameAttributesVal);
}
if (!newTurnLength.empty())
SetTurnLength(newTurnLength.back());
// Do StartGame last, so we have the most up-to-date game attributes when we start
if (!newStartGame.empty())
StartGame();
// Perform file transfers
for (size_t i = 0; i < m_Sessions.size(); ++i)
m_Sessions[i]->GetFileTransferer().Poll();
// Process network events:
ENetEvent event;
int status = enet_host_service(m_Host, &event, HOST_SERVICE_TIMEOUT);
if (status < 0)
{
LOGERROR("CNetServerWorker: enet_host_service failed (%d)", status);
// TODO: notify game that the server has shut down
return false;
}
if (status == 0)
{
// Reached timeout with no events - try again
return true;
}
// Process the event:
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
{
// Report the client address
char hostname[256] = "(error)";
enet_address_get_host_ip(&event.peer->address, hostname, ARRAY_SIZE(hostname));
LOGMESSAGE("Net server: Received connection from %s:%u", hostname, (unsigned int)event.peer->address.port);
// Set up a session object for this peer
CNetServerSession* session = new CNetServerSession(*this, event.peer);
m_Sessions.push_back(session);
SetupSession(session);
ENSURE(event.peer->data == NULL);
event.peer->data = session;
HandleConnect(session);
//.........这里部分代码省略.........