/** * Deallocates and shuts down game */ void SpringApp::Shutdown() { if (gu) gu->globalQuit = true; #define DeleteAndNull(x) delete x; x = NULL; GML::Exit(); DeleteAndNull(pregame); DeleteAndNull(game); DeleteAndNull(gameServer); DeleteAndNull(gameSetup); CLoadScreen::DeleteInstance(); ISound::Shutdown(); DeleteAndNull(font); DeleteAndNull(smallFont); CNamedTextures::Kill(); GLContext::Free(); GlobalConfig::Deallocate(); ConfigHandler::Deallocate(); UnloadExtensions(); IMouseInput::FreeInstance(mouseInput); KeyInput::FreeInstance(keyInput); SDL_WM_GrabInput(SDL_GRAB_OFF); #if !defined(HEADLESS) SDL_QuitSubSystem(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK); #endif SDL_Quit(); DeleteAndNull(gs); DeleteAndNull(gu); DeleteAndNull(globalRendering); DeleteAndNull(startsetup); FileSystemInitializer::Cleanup(); Watchdog::Uninstall(); #ifdef USE_MMGR m_dumpMemoryReport(); #endif }
/** * Deallocates and shuts down game */ void SpringApp::Shutdown() { if (pregame) delete pregame; //in case we exit during init if (game) delete game; if (gameSetup) delete gameSetup; delete font; ConfigHandler::Deallocate(); UnloadExtensions(); SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_Quit(); delete gs; delete gu; END_SYNCIFY; #ifdef USE_MMGR m_dumpMemoryReport(); #endif }
void NGE_Quit() { if(initFlags){ #ifndef NGE_IPHONE FiniInput(); if(initFlags&INIT_VIDEO) FiniGraphics(); if(initFlags&INIT_AUDIO) CoolAudioDefaultFini(); #endif initFlags = 0; #ifdef MMGR m_dumpMemoryReport(); #endif } _notifyCallback = NULL; _notifyCookie = NULL; }
int main( int argc, char *argv[ ], char *envp[ ] ) #endif { #ifndef _WIN32 chdir(SPRING_DATADIR); #endif INIT_SYNCIFY; bool done=false; BaseCmd *cmdline = BaseCmd::initialize(argc,argv); cmdline->addoption('f',"fullscreen",OPTPARM_NONE,"","Run in fullscreen mode"); cmdline->addoption('w',"window",OPTPARM_NONE,"","Run in windowed mode"); cmdline->addoption('s',"server",OPTPARM_NONE,"","Run as a server"); cmdline->addoption('c',"client",OPTPARM_NONE,"","Run as a client"); // cmdline->addoption('g',"runscript",OPTPARM_STRING,"script.txt", "Run with a game setup script"); cmdline->parse(); #ifdef _DEBUG fullscreen = false; #else fullscreen = configHandler.GetInt("Fullscreen",1)!=0; #endif Uint8 scrollWheelSpeed = configHandler.GetInt("ScrollWheelSpeed",25); if (cmdline->result("help")) { cmdline->usage("TA:Spring",VERSION_STRING); delete cmdline; return 0; } else if (cmdline->result("version")) { std::cout << "TA:Spring " << VERSION_STRING << std::endl; delete cmdline; return 0; } else if (cmdline->result("window")) fullscreen = false; else if (cmdline->result("fullscreen")) fullscreen = true; #ifdef _WIN32 // Initialize crash reporting Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "TA Spring Crashreport"); #endif // Initialize class system creg::ClassBinder::InitializeClasses (); // Global structures ENTER_SYNCED; gs=new CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=new CGlobalUnsyncedStuff(); #ifndef NO_LUA // Initialize lua bindings CLuaBinder lua; if (!lua.LoadScript("testscript.lua")) handleerror(NULL, lua.lastError.c_str(), "lua",MBF_OK|MBF_EXCL); #endif // Check if the commandline parameter is specifying a demo file bool playDemo = false; string demofile, startscript; #ifdef _WIN32 string command(argv[0]); int idx = command.rfind("spring"); string path = command.substr(0,idx); if (path.at(0) == '"') path.append(1,'"'); if (path != "") _chdir(path.c_str()); #endif for (int i = 1; i < argc; i++) { if (argv[i][0] != '-') { string command(argv[i]); int idx = command.rfind("sdf"); if (idx == command.size()-3) { playDemo = true; demofile = command; } else { playDemo = false; startscript = command; } } } // Create the archive scanner and vfs handler archiveScanner = new CArchiveScanner(); archiveScanner->ReadCacheData(); archiveScanner->Scan("./maps"); archiveScanner->Scan("./base"); archiveScanner->Scan("./mods"); archiveScanner->WriteCacheData(); hpiHandler = new CVFSHandler(); palette.Init(); ENTER_SYNCED; if (!playDemo) { gameSetup=new CGameSetup(); if(!gameSetup->Init(startscript)){ delete gameSetup; gameSetup=0; } } ENTER_MIXED; bool server = true; if (playDemo) server = false; else if(gameSetup) server=gameSetup->myPlayer-gameSetup->numDemoPlayers == 0; else server=!cmdline->result("client") || cmdline->result("server"); if ( !glwindow ( "RtsSpring", configHandler.GetInt("XResolution",XRES_DEFAULT), configHandler.GetInt("YResolution",YRES_DEFAULT), 0, fullscreen, configHandler.GetInt("DisplayFrequency",0) ) ) { SDL_Quit(); return 0; } SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); font = new CglFont(32,223); LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); if (playDemo) pregame = new CPreGame(false, demofile); else pregame = new CPreGame(server, ""); #ifdef NEW_GUI guicontroller = new GUIcontroller(); #endif #ifndef NO_LUA lua.CreateLateBindings(); #endif keys = new Uint8[SDLK_LAST]; SDL_Event event; while (!done) { ENTER_UNSYNCED; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_VIDEORESIZE: screen = SDL_SetVideoMode(event.resize.w,event.resize.h,0,SDL_OPENGL|SDL_RESIZABLE|SDL_HWSURFACE|SDL_DOUBLEBUF); if (screen) resizescene(screen->w,screen->h); break; case SDL_QUIT: done = true; break; case SDL_MOUSEMOTION: if(mouse) mouse->MouseMove(event.motion.x,event.motion.y); break; case SDL_MOUSEBUTTONDOWN: if (mouse) { if (event.button.button == SDL_BUTTON_WHEELUP) mouse->currentCamController->MouseWheelMove(scrollWheelSpeed); else if (event.button.button == SDL_BUTTON_WHEELDOWN) mouse->currentCamController->MouseWheelMove(-scrollWheelSpeed); mouse->MousePress(event.button.x,event.button.y,event.button.button); } break; case SDL_MOUSEBUTTONUP: if (mouse) mouse->MouseRelease(event.button.x,event.button.y,event.button.button); break; case SDL_KEYDOWN: { int i = event.key.keysym.sym; update_sdlkeys(keys); update_sdlmods(keys); if (i == SDLK_RETURN) keys[i] = 1; if(activeController) { activeController->KeyPressed(i,1); #ifndef NEW_GUI if(activeController->userWriting){ i = event.key.keysym.unicode; if (i >= SDLK_SPACE && i <= SDLK_DELETE) if(activeController->ignoreNextChar || activeController->ignoreChar==char(i)) activeController->ignoreNextChar=false; else activeController->userInput+=char(i); } #endif } #ifdef NEW_GUI i = event.key.keysym.unicode; if (i > SDLK_FIRST && i <= SDLK_DELETE) /* HACK */ GUIcontroller::Character(char(i)); #endif break; } case SDL_KEYUP: { int i = event.key.keysym.sym; update_sdlkeys(keys); update_sdlmods(keys); if (i == SDLK_RETURN) keys[i] = 0; if (activeController) activeController->KeyReleased(i); break; } } } if (FSAA) glEnable(GL_MULTISAMPLE_ARB); int ret = drawscene(); SDL_GL_SwapBuffers(); if (FSAA) glDisable(GL_MULTISAMPLE_ARB); if (globalQuit || (active && !ret)) done=true; } ENTER_MIXED; delete[] keys; // Shutdown if (pregame) delete pregame; //in case we exit during init if (game) delete game; if (gameSetup) delete gameSetup; delete font; ConfigHandler::Deallocate(); UnloadExtensions(); #ifndef DEBUG SDL_WM_GrabInput(SDL_GRAB_OFF); #endif SDL_Quit(); delete gs; delete gu; END_SYNCIFY; #ifdef USE_MMGR m_dumpMemoryReport(); #endif delete cmdline; return 0; }
void nge_mem_log() { #ifdef MMGR m_dumpMemoryReport(); #endif }