/* ============== Sys_ShowConsole ============== */ void Sys_ShowConsole(int visLevel, qboolean quitOnClose) { if (quitOnClose) { timeEndPeriod(1); } s_wcd.quitOnClose = quitOnClose; if (visLevel == s_wcd.visLevel) { return; } s_wcd.visLevel = visLevel; if (!s_wcd.hWnd) { return; } ShowWindow(s_wcd.hWnd, SW_SHOWNORMAL); SendMessage(s_wcd.hwndBuffer, EM_LINESCROLL, 0, 0xffff); if (visLevel > 0) { Sys_Splash(qfalse); } switch (visLevel) { case 0: ShowWindow(s_wcd.hWnd, SW_HIDE); break; case 1: ShowWindow(s_wcd.hWnd, SW_SHOWNORMAL); UpdateWindow(s_wcd.hWnd); SetForegroundWindow(s_wcd.hWnd); SetFocus(s_wcd.hwndInputLine); SendMessage(s_wcd.hwndBuffer, EM_LINESCROLL, 0, 0xffff); break; case 2: ShowWindow(s_wcd.hWnd, SW_MINIMIZE); break; default: Sys_Error("Invalid visLevel %d sent to Sys_ShowConsole\n", visLevel); break; } }
/* ================= Sys_Error ================= */ void Sys_Error(const char *error, ...) { va_list argptr; char string[1024]; #ifdef USE_WINDOWS_CONSOLE MSG msg; #endif va_start(argptr, error); Q_vsnprintf(string, sizeof(string), error, argptr); va_end(argptr); #ifdef _WIN32 Sys_Splash(qfalse); #endif #ifdef USE_WINDOWS_CONSOLE Conbuf_AppendText(string); Conbuf_AppendText("\n"); Sys_SetErrorText(string); Sys_ShowConsoleWindow(1, qtrue); IN_Shutdown(); // wait for the user to quit while (1) { if (!GetMessage(&msg, NULL, 0, 0)) { Com_Quit_f(); } TranslateMessage(&msg); DispatchMessage(&msg); } Sys_DestroyConsole(); #endif Sys_ErrorDialog(string); Sys_Exit(3); }
/** * @brief Windows specific initialization */ void Sys_PlatformInit(void) { g_wv.hInstance = GetModuleHandle(NULL); #ifdef EXCEPTION_HANDLER WinSetExceptionVersion(Q3_VERSION); #endif #ifndef DEDICATED Sys_SetProcessProperties(); //show the splash screen Sys_Splash(qtrue); #endif #ifdef USE_WINDOWS_CONSOLE // done before Com/Sys_Init since we need this for error output Sys_CreateConsole(); #endif #ifdef DEDICATED Sys_ShowConsoleWindow(1, qtrue); #endif // no abort/retry/fail errors SetErrorMode(SEM_FAILCRITICALERRORS); #ifndef DEDICATED const char *SDL_VIDEODRIVER = getenv("SDL_VIDEODRIVER"); if (SDL_VIDEODRIVER) { Com_Printf("SDL_VIDEODRIVER is externally set to \"%s\", " "in_mouse -1 will have no effect\n", SDL_VIDEODRIVER); SDL_VIDEODRIVER_externallySet = qtrue; } else { SDL_VIDEODRIVER_externallySet = qfalse; } #endif }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char commandLine[MAX_STRING_CHARS] = { 0 }; char cwd[MAX_OSPATH]; // should never get a previous instance in Win32 if (hPrevInstance) { return EXIT_FAILURE; } #ifdef EXCEPTION_HANDLER WinSetExceptionVersion(Q3_VERSION); #endif g_wv.hInstance = hInstance; #if 1 commandLine[0] = '\0'; Sys_ParseArgs(__argc, __argv); Sys_BuildCommandLine(__argc, __argv, commandLine, sizeof(commandLine)); #else Q_strncpyz(commandLine, lpCmdLine, sizeof(commandLine)); #endif #ifndef DEDICATED Sys_SetProcessProperties(); //show the splash screen Sys_Splash(qtrue); #endif #ifdef USE_WINDOWS_CONSOLE // done before Com/Sys_Init since we need this for error output Sys_CreateConsole(); #endif #ifdef DEDICATED Sys_ShowConsoleWindow(1, qtrue); #endif // no abort/retry/fail errors SetErrorMode(SEM_FAILCRITICALERRORS); // get the initial time base Sys_Milliseconds(); Com_Init(commandLine); NET_Init(); Sys_Splash(qfalse); _getcwd(cwd, sizeof(cwd)); Com_Printf("Working directory: %s\n", cwd); // hide the early console since we've reached the point where we // have a working graphics subsystems #ifndef LEGACY_DEBUG if (!com_dedicated->integer && !com_viewlog->integer) { Sys_ShowConsoleWindow(0, qfalse); } #endif // main game loop Sys_GameLoop(); // never gets here return EXIT_SUCCESS; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char cwd[MAX_OSPATH]; int startTime, endTime; // should never get a previous instance in Win32 if (hPrevInstance) { return 0; } #ifdef EXCEPTION_HANDLER WinSetExceptionVersion(Q3_VERSION); #endif g_wv.hInstance = hInstance; Q_strncpyz(sys_cmdline, lpCmdLine, sizeof(sys_cmdline)); #ifndef DEDICATED Sys_SetProcessProperties(); //show the splash screen Sys_Splash(qtrue); #endif // done before Com/Sys_Init since we need this for error output Sys_CreateConsole(); #ifdef DEDICATED Sys_ShowConsole(1, qtrue); #endif // no abort/retry/fail errors SetErrorMode(SEM_FAILCRITICALERRORS); // get the initial time base Sys_Milliseconds(); Com_Init(sys_cmdline); NET_Init(); Sys_Splash(qfalse); _getcwd(cwd, sizeof(cwd)); Com_Printf("Working directory: %s\n", cwd); // hide the early console since we've reached the point where we // have a working graphics subsystems #if defined (_WIN32) && !defined (_DEBUG) if (!com_dedicated->integer && !com_viewlog->integer) { Sys_ShowConsole(0, qfalse); } #endif //Jacker: We should not set the focus here as the focus gets lost to the console window //SetFocus(g_wv.hWnd); // main game loop while (1) { // if not running as a game client, sleep a bit if (g_wv.isMinimized || (com_dedicated && com_dedicated->integer)) { Sleep(5); } Sleep(0); // set low precision every frame, because some system calls // reset it arbitrarily //_controlfp( _PC_24, _MCW_PC ); //_controlfp( -1, _MCW_EM ); // no exceptions, even if some crappy // syscall turns them back on! startTime = Sys_Milliseconds(); // make sure mouse and joystick are only called once a frame IN_Frame(); // run the game //Com_FrameExt(); Com_Frame(); endTime = Sys_Milliseconds(); totalMsec += endTime - startTime; countMsec++; } // never gets here }
/** * @brief SDL_main * @param[in] argc * @param[in] argv * @return */ int main(int argc, char **argv) { char commandLine[MAX_STRING_CHARS] = { 0 }; Sys_PlatformInit(); // Set the initial time base Sys_Milliseconds(); #ifdef __APPLE__ // This is passed if we are launched by double-clicking if (argc >= 2 && Q_strncmp(argv[1], "-psn", 4) == 0) { argc = 1; } #endif Sys_ParseArgs(argc, argv); #if defined(__APPLE__) && !defined(DEDICATED) // argv[0] would be /Users/seth/etlegacy/etl.app/Contents/MacOS // But on OS X we want to pretend the binary path is the .app's parent // So that way the base folder is right next to the .app allowing { char parentdir[1024]; CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); if (!url) { Sys_Dialog(DT_ERROR, "A CFURL for the app bundle could not be found.", "Can't set Sys_SetBinaryPath"); Sys_Exit(EXIT_FAILURE); } CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); if (!url2 || !CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, 1024)) { Sys_Dialog(DT_ERROR, "CFURLGetFileSystemRepresentation returned an error when finding the app bundle's parent directory.", "Can't set Sys_SetBinaryPath"); Sys_Exit(EXIT_FAILURE); } Sys_SetBinaryPath(parentdir); CFRelease(url); CFRelease(url2); } #else Sys_SetBinaryPath(Sys_Dirname(argv[0])); #endif Sys_SetDefaultInstallPath(DEFAULT_BASEDIR); // Sys_BinaryPath() by default // Concatenate the command line for passing to Com_Init Sys_BuildCommandLine(argc, argv, commandLine, sizeof(commandLine)); Com_Init(commandLine); NET_Init(); Sys_SetUpConsoleAndSignals(); #ifdef _WIN32 #ifndef DEDICATED if (com_viewlog->integer) { Sys_ShowConsoleWindow(1, qfalse); } #endif Sys_Splash(qfalse); { char cwd[MAX_OSPATH]; _getcwd(cwd, sizeof(cwd)); Com_Printf("Working directory: %s\n", cwd); } // hide the early console since we've reached the point where we // have a working graphics subsystems #ifndef LEGACY_DEBUG if (!com_dedicated->integer && !com_viewlog->integer) { Sys_ShowConsoleWindow(0, qfalse); } #endif #endif Sys_GameLoop(); return EXIT_SUCCESS; }