int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils systemUtils->Init(); PREV_TIME = GetSystemUtils()->CreateTimeStamp(); CURR_TIME = GetSystemUtils()->CreateTimeStamp(); GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME); GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); // Without any error checking, for simplicity SDL_Init(SDL_INIT_VIDEO); IMG_Init(IMG_INIT_PNG); const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; if (videoInfo->hw_available) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; if (videoInfo->blit_hw) videoFlags |= SDL_HWACCEL; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); SDL_WM_SetCaption("Light Test", "Light Test"); //SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(SDL_DISABLE); Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); device->Create(); Init(device); bool done = false; while (! done) { Render(device); Update(); SDL_GL_SwapBuffers(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { break; done = true; } else if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_q) { done = true; break; } else KeyboardDown(event.key.keysym.sym); } else if (event.type == SDL_KEYUP) KeyboardUp(event.key.keysym.sym); else if (event.type == SDL_MOUSEMOTION) MouseMove(event.motion.x, event.motion.y); } usleep(FRAME_DELAY); } //SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); device->Destroy(); delete device; SDL_FreeSurface(surface); IMG_Quit(); SDL_Quit(); GetSystemUtils()->DestroyTimeStamp(PREV_TIME); GetSystemUtils()->DestroyTimeStamp(CURR_TIME); return 0; }
int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils systemUtils->Init(); PREV_TIME = GetSystemUtils()->CreateTimeStamp(); CURR_TIME = GetSystemUtils()->CreateTimeStamp(); GetSystemUtils()->GetCurrentTimeStamp(PREV_TIME); GetSystemUtils()->GetCurrentTimeStamp(CURR_TIME); if (argc != 3) { std::cerr << "Usage: " << argv[0] << " {old|new_txt|new_bin} model_file" << std::endl; return 1; } Gfx::CModelFile *modelFile = new Gfx::CModelFile(); if (std::string(argv[1]) == "old") { if (! modelFile->ReadModel(argv[2])) { std::cerr << "Error reading model file" << std::endl; return 1; } } else if (std::string(argv[1]) == "new_txt") { if (! modelFile->ReadTextModel(argv[2])) { std::cerr << "Error reading model file" << std::endl; return 1; } } else if (std::string(argv[1]) == "new_bin") { if (! modelFile->ReadBinaryModel(argv[2])) { std::cerr << "Error reading model file" << std::endl; return 1; } } else { std::cerr << "Usage: " << argv[0] << "{old|new_txt|new_bin} model_file" << std::endl; return 1; } // Without any error checking, for simplicity SDL_Init(SDL_INIT_VIDEO); IMG_Init(IMG_INIT_PNG); const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; if (videoInfo->hw_available) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; if (videoInfo->blit_hw) videoFlags |= SDL_HWACCEL; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_Surface *surface = SDL_SetVideoMode(800, 600, 32, videoFlags); SDL_WM_SetCaption("Model Test", "Model Test"); Gfx::CGLDevice *device = new Gfx::CGLDevice(Gfx::GLDeviceConfig()); device->Create(); Init(device, modelFile); bool done = false; while (! done) { Render(device, modelFile); Update(); SDL_GL_SwapBuffers(); SDL_Event event; SDL_PollEvent(&event); if (event.type == SDL_QUIT) done = true; else if (event.type == SDL_KEYDOWN) KeyboardDown(event.key.keysym.sym); else if (event.type == SDL_KEYUP) KeyboardUp(event.key.keysym.sym); usleep(FRAME_DELAY); } delete modelFile; device->Destroy(); delete device; SDL_FreeSurface(surface); IMG_Quit(); SDL_Quit(); GetSystemUtils()->DestroyTimeStamp(PREV_TIME); GetSystemUtils()->DestroyTimeStamp(CURR_TIME); return 0; }
int SDL_MAIN_FUNC(int argc, char *argv[]) { CLogger logger; // single istance of logger // Workaround for character encoding in argv on Windows #if PLATFORM_WINDOWS int wargc; wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &wargc); if(wargv == nullptr) { logger.Error("CommandLineToArgvW failed\n"); return 1; } argv = new char*[wargc]; for(int i = 0; i < wargc; i++) { std::wstring warg = wargv[i]; std::string arg = CSystemUtilsWindows::UTF8_Encode(warg); argv[i] = new char[arg.length()+1]; strcpy(argv[i], arg.c_str()); } LocalFree(wargv); #endif CResourceManager manager(argv[0]); // Initialize static string arrays InitializeRestext(); InitializeEventTypeTexts(); logger.Info("%s starting\n", COLOBOT_FULLNAME); int code = 0; while(true) { CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils systemUtils->Init(); CApplication* app = new CApplication(); // single instance of the application ParseArgsStatus status = app->ParseArguments(argc, argv); if (status == PARSE_ARGS_FAIL) { systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n"); return app->GetExitCode(); } else if (status == PARSE_ARGS_HELP) { return app->GetExitCode(); } if (! app->Create()) { app->Destroy(); // ensure a clean exit code = app->GetExitCode(); if ( code != 0 && !app->GetErrorMessage().empty() ) { systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app->GetErrorMessage()); } logger.Info("Didn't run main loop. Exiting with code %d\n", code); return code; } code = app->Run(); bool restarting = app->IsRestarting(); delete app; delete systemUtils; if(!restarting) break; } logger.Info("Exiting with code %d\n", code); #if PLATFORM_WINDOWS // See the workaround above delete[] argv; #endif return code; }