bool TeamBox::Update(const Point2i &mousePosition, const Point2i &lastMousePosition) { UpdatePlayerNameColor(); Box::Update(mousePosition, lastMousePosition); if (need_redrawing) { Draw(mousePosition); } if (associated_team) { WidgetList::Update(mousePosition, lastMousePosition); if (previous_player_name != player_name->GetText()) { previous_player_name = player_name->GetText(); if (Network::GetInstance()->IsConnected()) { ValidOptions(); } } } else { RedrawBackground(*this); } //SwapWindowClip(r); need_redrawing = false; return true; }
Widget* TeamBox::ClickUp(const Point2i &mousePosition, uint button) { if (associated_team) { if (!associated_team->IsLocal()) return NULL; // it's not a local team, we can't configure it !! Widget* w = WidgetList::ClickUp(mousePosition, button); if (w == nb_characters) { if (Network::GetInstance()->IsConnected()) { ValidOptions(); } return w; } if (w == player_name) { return w; } if (w == nullw) { if (button == Mouse::BUTTON_LEFT()) { if (group == MAX_TEAM_GROUPS-1) group = 0; else group++; } else { if (group == 0) group = MAX_TEAM_GROUPS-1; else group--; } SetGroup(group); UpdateTeam(associated_team->GetId()); } if (!w) { return w; } if (!custom_team_list.empty()) { if (w == next_custom_team) { player_name->SetText(custom_team_list[custom_team_current_id]->GetName()); if (custom_team_current_id == custom_team_list.size()-1) { custom_team_current_id = 0; } else { custom_team_current_id++; } } if (w == previous_custom_team) { player_name->SetText(custom_team_list[custom_team_current_id]->GetName()); if (custom_team_current_id == 0) { custom_team_current_id = custom_team_list.size()-1; } else { custom_team_current_id--; } } } } return NULL; }
void TeamBox::SwitchPlayerType() { if (!associated_team) return; SetAIName((ai_name == NO_AI_NAME) ? DEFAULT_AI_NAME : NO_AI_NAME); if (Network::GetInstance()->IsConnected()) { ValidOptions(); } }
void TeamBox::SwitchPlayerType() { if (!associated_team) return; ai_level++; if (ai_level > 3) ai_level = 0; UpdatePlayerType(); if (Network::GetInstance()->IsConnected()) { ValidOptions(); } }
void __cdecl main (int argc, char *argv[]) { SYSTEM_INFO systemInfo; WSADATA wsaData; DWORD dwThreadCount = 0; int nRet = 0; g_ThreadHandles[0] = (HANDLE)WSA_INVALID_EVENT; for( int i = 0; i < MAX_WORKER_THREAD; i++ ) { g_ThreadHandles[i] = INVALID_HANDLE_VALUE; } if( !ValidOptions(argc, argv) ) return; if( !SetConsoleCtrlHandler(CtrlHandler, TRUE) ) { myprintf("SetConsoleCtrlHandler() failed to install console handler: %d\n", GetLastError()); return; } GetSystemInfo(&systemInfo); dwThreadCount = systemInfo.dwNumberOfProcessors * 2; if(WSA_INVALID_EVENT == (g_hCleanupEvent[0] = WSACreateEvent())) { myprintf("WSACreateEvent() failed: %d\n", WSAGetLastError()); return; } if( (nRet = WSAStartup(0x202, &wsaData)) != 0 ) { myprintf("WSAStartup() failed: %d\n",nRet); SetConsoleCtrlHandler(CtrlHandler, FALSE); if(g_hCleanupEvent[0] != WSA_INVALID_EVENT) { WSACloseEvent(g_hCleanupEvent[0]); g_hCleanupEvent[0] = WSA_INVALID_EVENT; } return; } __try { InitializeCriticalSection(&g_CriticalSection); } __except(EXCEPTION_EXECUTE_HANDLER) { myprintf("InitializeCriticalSection raised an exception.\n"); SetConsoleCtrlHandler(CtrlHandler, FALSE); if(g_hCleanupEvent[0] != WSA_INVALID_EVENT) { WSACloseEvent(g_hCleanupEvent[0]); g_hCleanupEvent[0] = WSA_INVALID_EVENT; } return; } while( g_bRestart ) { g_bRestart = FALSE; g_bEndServer = FALSE; WSAResetEvent(g_hCleanupEvent[0]); __try { // // notice that we will create more worker threads (dwThreadCount) than // the thread concurrency limit on the IOCP. // g_hIOCP = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); if( g_hIOCP == NULL ) { myprintf("CreateIoCompletionPort() failed to create I/O completion port: %d\n", GetLastError()); __leave; } for( DWORD dwCPU=0; dwCPU<dwThreadCount; dwCPU++ ) { // // Create worker threads to service the overlapped I/O requests. The decision // to create 2 worker threads per CPU in the system is a heuristic. Also, // note that thread handles are closed right away, because we will not need them // and the worker threads will continue to execute. // HANDLE hThread; DWORD dwThreadId; hThread = CreateThread(NULL, 0, WorkerThread, g_hIOCP, 0, &dwThreadId); if( hThread == NULL ) { myprintf("CreateThread() failed to create worker thread: %d\n", GetLastError()); __leave; } g_ThreadHandles[dwCPU] = hThread; hThread = INVALID_HANDLE_VALUE; } if( !CreateListenSocket() ) __leave; if( !CreateAcceptSocket(TRUE) ) __leave; WSAWaitForMultipleEvents(1, g_hCleanupEvent, TRUE, WSA_INFINITE, FALSE); } __finally { g_bEndServer = TRUE; // // Cause worker threads to exit // if( g_hIOCP ) { for( DWORD i = 0; i < dwThreadCount; i++ ) PostQueuedCompletionStatus(g_hIOCP, 0, 0, NULL); } // // Make sure worker threads exits. // if( WAIT_OBJECT_0 != WaitForMultipleObjects(dwThreadCount, g_ThreadHandles, TRUE, 1000) ) myprintf("WaitForMultipleObjects() failed: %d\n", GetLastError()); else for( DWORD i=0; i<dwThreadCount; i++ ) { if( g_ThreadHandles[i] != INVALID_HANDLE_VALUE ) CloseHandle(g_ThreadHandles[i]); g_ThreadHandles[i] = INVALID_HANDLE_VALUE; } if( g_sdListen != INVALID_SOCKET ) { closesocket(g_sdListen); g_sdListen = INVALID_SOCKET; } if( g_pCtxtListenSocket ) { while( !HasOverlappedIoCompleted((LPOVERLAPPED)&g_pCtxtListenSocket->pIOContext->Overlapped) ) Sleep(0); if( g_pCtxtListenSocket->pIOContext->SocketAccept != INVALID_SOCKET ) closesocket(g_pCtxtListenSocket->pIOContext->SocketAccept); g_pCtxtListenSocket->pIOContext->SocketAccept = INVALID_SOCKET; // // We know there is only one overlapped I/O on the listening socket // if( g_pCtxtListenSocket->pIOContext ) xfree(g_pCtxtListenSocket->pIOContext); if( g_pCtxtListenSocket ) xfree(g_pCtxtListenSocket); g_pCtxtListenSocket = NULL; } CtxtListFree(); if( g_hIOCP ) { CloseHandle(g_hIOCP); g_hIOCP = NULL; } } //finally if( g_bRestart ) { myprintf("\niocpserverex is restarting...\n"); } else myprintf("\niocpserverex is exiting...\n"); } //while (g_bRestart) DeleteCriticalSection(&g_CriticalSection); if(g_hCleanupEvent[0] != WSA_INVALID_EVENT) { WSACloseEvent(g_hCleanupEvent[0]); g_hCleanupEvent[0] = WSA_INVALID_EVENT; } WSACleanup(); SetConsoleCtrlHandler(CtrlHandler, FALSE); } //main