static void Sys_Android_SignalHandler( int sig ) { signal( SIGTERM, SIG_DFL ); signal( SIGINT, SIG_DFL ); Com_Printf( "Received signal %d, exiting...\n", sig ); Com_Quit(); }
static void signal_handler( int sig ) { static int try = 0; switch( try++ ) { case 0: if( sig == SIGINT || sig == SIGTERM ) { Com_Printf( "Received signal %d, exiting...\n", sig ); Com_Quit(); } else { Com_Error( ERR_FATAL, "Received signal %d\n", sig ); } break; case 1: #ifndef DEDICATED_ONLY printf( "Received signal %d, exiting...\n", sig ); SV_Shutdown( "Received signal, exiting...\n" ); CL_Shutdown(); _exit( 1 ); break; case 2: #endif printf( "Received signal %d, exiting...\n", sig ); _exit( 1 ); break; default: _exit( 1 ); break; } }
static int Sys_Main(int argc, char **argv) { // fix current directory to point to the basedir if (!fix_current_directory()) { return 1; } #if (_MSC_VER >= 1400) // work around strftime given invalid format string // killing the whole f*****g process :(( _set_invalid_parameter_handler(msvcrt_sucks); #endif Qcommon_Init(argc, argv); // main program loop while (1) { Qcommon_Frame(); if (shouldExit) { #if USE_WINSVC if (shouldExit == SE_FULL) #endif Com_Quit(NULL, ERR_DISCONNECT); break; } } // may get here when our service stops return 0; }
/* ================= main ================= */ int main(int argc, char **argv) { if (argc > 1) { if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) { fprintf(stderr, "%s\n", com_version_string); return EXIT_SUCCESS; } if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { fprintf(stderr, "Usage: %s [+command arguments] [...]\n", argv[0]); return EXIT_SUCCESS; } } if (!getuid() || !geteuid()) { fprintf(stderr, "You can not run " PRODUCT " as superuser " "for security reasons!\n"); return EXIT_FAILURE; } Qcommon_Init(argc, argv); while (!terminate) { Qcommon_Frame(); } Com_Quit(NULL, ERR_DISCONNECT); return EXIT_FAILURE; // never gets here }
/* ============ VID_PumpEvents ============ */ void VID_PumpEvents( void ) { MSG msg; while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if( msg.message == WM_QUIT ) { Com_Quit( NULL, ERR_DISCONNECT ); break; } win.lastMsgTime = msg.time; TranslateMessage( &msg ); DispatchMessage( &msg ); } if( win.mode_changed ) { if( win.mode_changed & (MODE_SIZE|MODE_POS) ) { VID_SetGeometry( &win.rc ); if( win.mouse.grabbed == IN_GRAB ) { Win_ClipCursor(); } } if( win.mode_changed & MODE_STYLE ) { Win_SetPosition(); } if( win.mode_changed & MODE_SIZE ) { Win_ModeChanged(); } win.mode_changed = 0; } }
/** * @brief Catch kernel interrupts and dispatch the appropriate exit routine. */ static void Sys_Signal (int s) { switch (s) { case SIGHUP: case SIGTERM: case SIGQUIT: #ifndef COMPILE_UFO case SIGINT: #endif Com_Printf("Received signal %d, quitting..\n", s); Sys_Quit(); break; #ifdef COMPILE_UFO case SIGINT: Com_Printf("Received signal %d, quitting..\n", s); Com_Quit(); break; #endif default: Sys_Error("Received signal %d.\n", s); break; } }
/* * Updates the input queue state. Called every * frame by the client and does nearly all the * input magic. */ void IN_Update(void) { qboolean want_grab; SDL_Event event; unsigned int key; /* Get and process an event */ while (SDL_PollEvent(&event)) { switch (event.type) { #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_MOUSEWHEEL: Key_Event((event.wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN), true, true); Key_Event((event.wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN), false, true); break; #endif case SDL_MOUSEBUTTONDOWN: #if !SDL_VERSION_ATLEAST(2, 0, 0) if (event.button.button == 4) { Key_Event(K_MWHEELUP, true, true); Key_Event(K_MWHEELUP, false, true); break; } else if (event.button.button == 5) { Key_Event(K_MWHEELDOWN, true, true); Key_Event(K_MWHEELDOWN, false, true); break; } #endif /* fall-through */ case SDL_MOUSEBUTTONUP: switch (event.button.button) { case SDL_BUTTON_LEFT: key = K_MOUSE1; break; case SDL_BUTTON_MIDDLE: key = K_MOUSE3; break; case SDL_BUTTON_RIGHT: key = K_MOUSE2; break; case SDL_BUTTON_X1: key = K_MOUSE4; break; case SDL_BUTTON_X2: key = K_MOUSE5; break; default: return; } Key_Event(key, (event.type == SDL_MOUSEBUTTONDOWN), true); break; case SDL_MOUSEMOTION: if (cls.key_dest == key_game && (int) cl_paused->value == 0) { mouse_x += event.motion.xrel; mouse_y += event.motion.yrel; } break; #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_TEXTINPUT: if ((event.text.text[0] >= ' ') && (event.text.text[0] <= '~')) { Char_Event(event.text.text[0]); } break; #endif case SDL_KEYDOWN: #if !SDL_VERSION_ATLEAST(2, 0, 0) if ((event.key.keysym.unicode >= SDLK_SPACE) && (event.key.keysym.unicode < SDLK_DELETE)) { Char_Event(event.key.keysym.unicode); } #endif /* fall-through */ case SDL_KEYUP: { qboolean down = (event.type == SDL_KEYDOWN); #if SDL_VERSION_ATLEAST(2, 0, 0) /* workaround for AZERTY-keyboards, which don't have 1, 2, ..., 9, 0 in first row: * always map those physical keys (scancodes) to those keycodes anyway * see also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 */ SDL_Scancode sc = event.key.keysym.scancode; if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_0) { /* Note that the SDL_SCANCODEs are SDL_SCANCODE_1, _2, ..., _9, SDL_SCANCODE_0 * while in ASCII it's '0', '1', ..., '9' => handle 0 and 1-9 separately * (quake2 uses the ASCII values for those keys) */ int key = '0'; /* implicitly handles SDL_SCANCODE_0 */ if (sc <= SDL_SCANCODE_9) { key = '1' + (sc - SDL_SCANCODE_1); } Key_Event(key, down, false); } else #endif /* SDL2; (SDL1.2 doesn't have scancodes so nothing we can do there) */ if ((event.key.keysym.sym >= SDLK_SPACE) && (event.key.keysym.sym < SDLK_DELETE)) { Key_Event(event.key.keysym.sym, down, false); } else { Key_Event(IN_TranslateSDLtoQ2Key(event.key.keysym.sym), down, true); } } break; #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST || event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { Key_MarkAllUp(); } else if (event.window.event == SDL_WINDOWEVENT_MOVED) { // make sure GLimp_GetRefreshRate() will query from SDL again - the window might // be on another display now! glimp_refreshRate = -1; } #else /* SDL1.2 */ case SDL_ACTIVEEVENT: if(event.active.gain == 0 && (event.active.state & SDL_APPINPUTFOCUS)) { Key_MarkAllUp(); } #endif break; #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONDOWN: /* Handle Controller Back button */ { qboolean down = (event.type == SDL_CONTROLLERBUTTONDOWN); if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { Key_Event(K_JOY_BACK, down, true); } } break; case SDL_CONTROLLERAXISMOTION: /* Handle Controller Motion */ { char *direction_type; float threshold = 0; float fix_value = 0; int axis_value = event.caxis.value; switch (event.caxis.axis) { /* left/right */ case SDL_CONTROLLER_AXIS_LEFTX: direction_type = joy_axis_leftx->string; threshold = joy_axis_leftx_threshold->value; break; /* top/bottom */ case SDL_CONTROLLER_AXIS_LEFTY: direction_type = joy_axis_lefty->string; threshold = joy_axis_lefty_threshold->value; break; /* second left/right */ case SDL_CONTROLLER_AXIS_RIGHTX: direction_type = joy_axis_rightx->string; threshold = joy_axis_rightx_threshold->value; break; /* second top/bottom */ case SDL_CONTROLLER_AXIS_RIGHTY: direction_type = joy_axis_righty->string; threshold = joy_axis_righty_threshold->value; break; case SDL_CONTROLLER_AXIS_TRIGGERLEFT: direction_type = joy_axis_triggerleft->string; threshold = joy_axis_triggerleft_threshold->value; break; case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: direction_type = joy_axis_triggerright->string; threshold = joy_axis_triggerright_threshold->value; break; default: direction_type = "none"; } if (threshold > 0.9) threshold = 0.9; if (axis_value < 0 && (axis_value > (32768 * threshold))) axis_value = 0; else if (axis_value > 0 && (axis_value < (32768 * threshold))) axis_value = 0; // Smoothly ramp from dead zone to maximum value (from ioquake) // https://github.com/ioquake/ioq3/blob/master/code/sdl/sdl_input.c fix_value = ((float) abs(axis_value) / 32767.0f - threshold) / (1.0f - threshold); if (fix_value < 0.0f) fix_value = 0.0f; axis_value = (int) (32767 * ((axis_value < 0) ? -fix_value : fix_value)); if (cls.key_dest == key_game && (int) cl_paused->value == 0) { if (strcmp(direction_type, "sidemove") == 0) { joystick_sidemove = axis_value * joy_sidesensitivity->value; // We need to be twice faster because with joystic we run... joystick_sidemove *= cl_sidespeed->value * 2.0f; } else if (strcmp(direction_type, "forwardmove") == 0) { joystick_forwardmove = axis_value * joy_forwardsensitivity->value; // We need to be twice faster because with joystic we run... joystick_forwardmove *= cl_forwardspeed->value * 2.0f; } else if (strcmp(direction_type, "yaw") == 0) { joystick_yaw = axis_value * joy_yawsensitivity->value; joystick_yaw *= cl_yawspeed->value; } else if (strcmp(direction_type, "pitch") == 0) { joystick_pitch = axis_value * joy_pitchsensitivity->value; joystick_pitch *= cl_pitchspeed->value; } else if (strcmp(direction_type, "updown") == 0) { joystick_up = axis_value * joy_upsensitivity->value; joystick_up *= cl_upspeed->value; } } if (strcmp(direction_type, "triggerleft") == 0) { qboolean new_left_trigger = abs(axis_value) > (32767 / 4); if (new_left_trigger != left_trigger) { left_trigger = new_left_trigger; Key_Event(K_TRIG_LEFT, left_trigger, true); } } else if (strcmp(direction_type, "triggerright") == 0) { qboolean new_right_trigger = abs(axis_value) > (32767 / 4); if (new_right_trigger != right_trigger) { right_trigger = new_right_trigger; Key_Event(K_TRIG_RIGHT, right_trigger, true); } } } break; /* Joystick can have more buttons than on general game controller * so try to map not free buttons */ case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: { qboolean down = (event.type == SDL_JOYBUTTONDOWN); /* Ignore back button, we dont need event for such button */ if (back_button_id == event.jbutton.button) return; if (event.jbutton.button <= (K_JOY32 - K_JOY1)) { Key_Event(event.jbutton.button + K_JOY1, down, true); } } break; case SDL_JOYHATMOTION: { if (last_hat != event.jhat.value) { char diff = last_hat ^event.jhat.value; int i; for (i = 0; i < 4; i++) { if (diff & (1 << i)) { /* check that we have button up for some bit */ if (last_hat & (1 << i)) Key_Event(i + K_HAT_UP, false, true); /* check that we have button down for some bit */ if (event.jhat.value & (1 << i)) Key_Event(i + K_HAT_UP, true, true); } } last_hat = event.jhat.value; } } break; #endif case SDL_QUIT: Com_Quit(); break; } } /* Grab and ungrab the mouse if the console or the menu is opened */ if (in_grab->value == 3) { want_grab = windowed_mouse->value; } else { want_grab = (vid_fullscreen->value || in_grab->value == 1 || (in_grab->value == 2 && windowed_mouse->value)); } /* calling GLimp_GrabInput() each is a bit ugly but simple and should work. * + the called SDL functions return after a cheap check, if there's * nothing to do, anyway. */ GLimp_GrabInput(want_grab); /* We need to save the frame time so other subsystems know the * exact time of the last input events. */ sys_frame_time = Sys_Milliseconds(); }
/* ================== CL_Quit_f ================== */ void CL_Quit_f (void) { CL_Disconnect (); Com_Quit (); }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; double time, oldtime, newtime; char *cddir; /* previous instances do not exist in Win32 */ if (hPrevInstance) return 0; global_hInstance = hInstance; ParseCommandLine (lpCmdLine); // if we find the CD, add a +set cddir xxx command line cddir = Sys_ScanForCD (); if (cddir && argc < MAX_NUM_ARGVS - 3) { int i; // don't override a cddir on the command line for (i=0 ; i<argc ; i++) if (!strcmp(argv[i], "cddir")) break; if (i == argc) { argv[argc++] = "+set"; argv[argc++] = "cddir"; argv[argc++] = cddir; } } Detect_WinNT(); Qcommon_Init (argc, argv); oldtime = Sys_Milliseconds (); /* main window message loop */ while (1) { // if at a full screen console, don't update unless needed if (Minimized || (dedicated && dedicated->value) ) { Sleep (1); } while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage (&msg, NULL, 0, 0)) Com_Quit (); sys_msg_time = (double)msg.time; TranslateMessage (&msg); DispatchMessage (&msg); } do { newtime = Sys_Milliseconds (); time = newtime - oldtime; } while (time < 1); // Con_Printf ("time:%5.2f - %5.2f = %5.2f\n", newtime, oldtime, time); // _controlfp( ~( _EM_ZERODIVIDE /*| _EM_INVALID*/ ), _MCW_EM ); _controlfp( _PC_24, _MCW_PC ); Qcommon_Frame (time); oldtime = newtime; } // never gets here return TRUE; }
LONG WINAPI MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG lRet = 0; static qboolean newwindow = true; static qboolean minimized = false; if (uMsg == MSH_MOUSEWHEEL) { if (((int)wParam) > 0) { Key_Event(K_MWHEELUP, true, sys_msg_time); Key_Event(K_MWHEELUP, false, sys_msg_time); } else { Key_Event(K_MWHEELDOWN, true, sys_msg_time); Key_Event(K_MWHEELDOWN, false, sys_msg_time); } return DefWindowProc(hWnd, uMsg, wParam, lParam); } //Com_Printf("%x\n", uMsg); switch (uMsg) { case WM_MOUSEWHEEL: /* ** this chunk of code theoretically only works under NT4 and Win98 ** since this message doesn't exist under Win95 */ if ((short)HIWORD(wParam) > 0) { Key_Event(K_MWHEELUP, true, sys_msg_time); Key_Event(K_MWHEELUP, false, sys_msg_time); } else { Key_Event(K_MWHEELDOWN, true, sys_msg_time); Key_Event(K_MWHEELDOWN, false, sys_msg_time); } break; case WM_HOTKEY: return 0; case WM_CREATE: cl_hwnd = hWnd; newwindow = true; MSH_MOUSEWHEEL = RegisterWindowMessage("MSWHEEL_ROLLMSG"); return DefWindowProc (hWnd, uMsg, wParam, lParam); case WM_PAINT: SCR_DirtyScreen(); // force entire screen to update next frame return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_DESTROY: // let sound and input know about this? cl_hwnd = NULL; return DefWindowProc(hWnd, uMsg, wParam, lParam); /* case WM_KILLFOCUS: // jit - make sure mouse is deactivated if another window takes focus AppActivate(false, minimized, newwindow); if (reflib_active) re.AppActivate(false); return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_NCACTIVATE: AppActivate(wParam, minimized, newwindow); if (reflib_active) re.AppActivate(wParam); return DefWindowProc(hWnd, uMsg, wParam, lParam); */ /*case WM_ACTIVATEAPP: AppActivate(wParam, minimized, newwindow); if (reflib_active) re.AppActivate(wParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);*/ /* jit - disabled this because we run CheckActive() every frame because we aren't getting appropriate events when the game loses focus/foreground, sometimes. case WM_ACTIVATE: { int fActive; qboolean active; HWND foregroundWindow = GetForegroundWindow(); // KJB: Watch this for problems in fullscreen modes with Alt-tabbing. fActive = LOWORD(wParam); minimized = (BOOL)HIWORD(wParam); active = (fActive != WA_INACTIVE); //if (foregroundWindow != hWnd) // active = false; Com_Printf("\nForeground: %d hWnd: %d\n\n", foregroundWindow, hWnd); AppActivate(active, minimized, newwindow); if (reflib_active) re.AppActivate(active); newwindow = false; return DefWindowProc(hWnd, uMsg, wParam, lParam); } /* case WM_WINDOWPOSCHANGED: // jit - handle another case of losing app focus { LPWINDOWPOS windowpos = (LPWINDOWPOS)lParam; if (windowpos->flags & 0x800) // SWP_STATECHANGED { HWND foregroundWindow = GetForegroundWindow(); qboolean active = (foregroundWindow == hWnd); AppActivate(active, minimized, newwindow); if (reflib_active) re.AppActivate(active); } Com_Printf("\nWindowposchanged flags %x\n", windowpos->flags); return DefWindowProc(hWnd, uMsg, wParam, lParam); } */ case WM_MOVE: { int xPos, yPos; RECT r; int style; if (!vid_fullscreen->value) { xPos = (short)LOWORD(lParam); // horizontal position yPos = (short)HIWORD(lParam); // vertical position r.left = 0; r.top = 0; r.right = 1; r.bottom = 1; style = GetWindowLong(hWnd, GWL_STYLE); AdjustWindowRect(&r, style, FALSE); Cvar_SetValue("vid_xpos", xPos + r.left); Cvar_SetValue("vid_ypos", yPos + r.top); vid_xpos->modified = false; vid_ypos->modified = false; } // jitmouse - force mouse to recenter properly if (ActiveApp) IN_Activate(true); } return DefWindowProc(hWnd, uMsg, wParam, lParam); // this is complicated because Win32 seems to pack multiple mouse events into // one update sometimes, so we always check all states and look for events case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MOUSEMOVE: case WM_XBUTTONDOWN: // jitmouse case WM_XBUTTONUP: // jitmouse { int temp = 0; if (wParam & MK_LBUTTON) temp |= 1; if (wParam & MK_RBUTTON) temp |= 2; if (wParam & MK_MBUTTON) temp |= 4; // === jitmouse if (wParam & MK_XBUTTON1) temp |= 8; if (wParam & MK_XBUTTON2) temp |= 16; // === IN_MouseEvent(temp); // ++ ARTHUR [9/04/03] - Mouse movement emulates keystroke Key_Event(K_MOUSEMOVE, true, sys_msg_time); // -- ARTHUR } break; case WM_INPUT: // jitmouse if (m_rawinput->value && !(cls.key_dest == key_console || g_windowed && M_MenuActive())) // Don't accumulate in-game mouse input when at the console or menu { UINT dwSize = 40; static BYTE lpb[40]; RAWINPUT *raw; GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)); raw = (RAWINPUT*)lpb; if (raw->header.dwType == RIM_TYPEMOUSE) { extern int g_raw_mouse_x, g_raw_mouse_y; g_raw_mouse_x += raw->data.mouse.lLastX; g_raw_mouse_y += raw->data.mouse.lLastY; } } break; case WM_SYSCOMMAND: if (wParam == SC_SCREENSAVE) return 0; return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_SYSKEYDOWN: if (wParam == 13) // alt-enter toggles fullscreen { if (!win_noaltenter || !win_noaltenter->value) // jitkeyboard { if (vid_fullscreen) Cvar_SetValue("vid_fullscreen", !vid_fullscreen->value); return 0; } } // fall through case WM_KEYDOWN: Key_Event(Sys_MapKeyModified(wParam, lParam), true, sys_msg_time); break; case WM_SYSKEYUP: case WM_KEYUP: Key_Event(Sys_MapKeyModified(wParam, lParam), false, sys_msg_time); break; case WM_SIZE: if (lParam) // This is 0 when minimized? { M_RefreshMenu(); // jitmenu re.DrawResizeWindow(LOWORD(lParam), HIWORD(lParam)); VID_NewWindow(LOWORD(lParam), HIWORD(lParam)); } if (wParam == SIZE_MINIMIZED) // jit minimized = true; else minimized = false; break; case WM_CLOSE: case WM_QUIT: Com_Quit(); break; case WM_APPCOMMAND: #ifdef OGG_SUPPORT if(ogg_started) switch(GET_APPCOMMAND_LPARAM(lParam)) { case APPCOMMAND_MEDIA_PLAY_PAUSE: Cbuf_AddText("ogg_playpause\n"); return 1; case APPCOMMAND_MEDIA_NEXTTRACK: Cbuf_AddText("ogg_play >\n"); return 1; case APPCOMMAND_MEDIA_PREVIOUSTRACK: Cbuf_AddText("ogg_play <\n"); return 1; case APPCOMMAND_MEDIA_STOP: Cbuf_AddText("ogg_stop\n"); return 1; } break; #endif case MM_MCINOTIFY: { LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); lRet = CDAudio_MessageHandler(hWnd, uMsg, wParam, lParam); } break; default: // pass all unhandled messages to DefWindowProc return DefWindowProc(hWnd, uMsg, wParam, lParam); } //CheckActive(hWnd); // return 0 if handled message, 1 if not return DefWindowProc(hWnd, uMsg, wParam, lParam); }
static void Com_Recycle_f(void) { Com_Quit(Cmd_Args(), ERR_RECONNECT); }
static void Com_Quit_f(void) { Com_Quit(Cmd_Args(), ERR_DISCONNECT); }
/* * Windows main function. Containts the * initialization code and the main loop */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; long long oldtime, newtime; /* Previous instances do not exist in Win32 */ if (hPrevInstance) { return 0; } /* Make the current instance global */ global_hInstance = hInstance; /* Setup FPU if necessary */ Sys_SetupFPU(); /* Force DPI awareness */ Sys_SetHighDPIMode(); /* Parse the command line arguments */ ParseCommandLine(lpCmdLine); /* Are we portable? */ for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "-portable") == 0) { is_portable = true; } } /* Need to redirect stdout before anything happens. */ #ifndef DEDICATED_ONLY Sys_RedirectStdout(); #endif /* Seed PRNG */ randk_seed(); /* Call the initialization code */ Qcommon_Init(argc, argv); /* Save our time */ oldtime = Sys_Microseconds(); /* The legendary main loop */ while (1) { /* If at a full screen console, don't update unless needed */ if (Minimized || (dedicated && dedicated->value)) { Sleep(1); } while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) { Com_Quit(); } sys_msg_time = msg.time; TranslateMessage(&msg); DispatchMessage(&msg); } // Throttle the game a little bit Sys_Nanosleep(5000); newtime = Sys_Microseconds(); Qcommon_Frame(newtime - oldtime); oldtime = newtime; } /* never gets here */ return TRUE; }
/* * Windows main function. Containts the * initialization code and the main loop */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; long long oldtime, newtime; /* Previous instances do not exist in Win32 */ if (hPrevInstance) { return 0; } /* Make the current instance global */ global_hInstance = hInstance; /* Setup FPU if necessary */ Sys_SetupFPU(); /* Force DPI awareness */ Sys_SetHighDPIMode(); /* Parse the command line arguments */ ParseCommandLine(lpCmdLine); /* Are we portable? */ for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "-portable") == 0) { is_portable = true; } } /* Need to redirect stdout before anything happens. */ #ifndef DEDICATED_ONLY Sys_RedirectStdout(); #endif printf("Yamagi Quake II v%s\n", YQ2VERSION); printf("=====================\n\n"); #ifndef DEDICATED_ONLY printf("Client build options:\n"); #ifdef SDL2 printf(" + SDL2\n"); #else printf(" - SDL2 (using 1.2)\n"); #endif #ifdef CDA printf(" + CD audio\n"); #else printf(" - CD audio\n"); #endif #ifdef OGG printf(" + OGG/Vorbis\n"); #else printf(" - OGG/Vorbis\n"); #endif #ifdef USE_OPENAL printf(" + OpenAL audio\n"); #else printf(" - OpenAL audio\n"); #endif #ifdef ZIP printf(" + Zip file support\n"); #else printf(" - Zip file support\n"); #endif #endif printf("Platform: %s\n", YQ2OSTYPE); printf("Architecture: %s\n", YQ2ARCH); /* Seed PRNG */ randk_seed(); /* Call the initialization code */ Qcommon_Init(argc, argv); /* Save our time */ oldtime = Sys_Microseconds(); /* The legendary main loop */ while (1) { /* If at a full screen console, don't update unless needed */ if (Minimized || (dedicated && dedicated->value)) { Sleep(1); } while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) { Com_Quit(); } sys_msg_time = msg.time; TranslateMessage(&msg); DispatchMessage(&msg); } // Throttle the game a little bit Sys_Nanosleep(5000); newtime = Sys_Microseconds(); Qcommon_Frame(newtime - oldtime); oldtime = newtime; } /* never gets here */ return TRUE; }
void printUsage() { Com_Printf("usage: ZoneBuilder.exe zone name [-b] [-v] [-sSourceZone] [-dBuildFolder]\n"); Com_Printf("Or run with no arguments for console.\n"); Com_Quit(); }