HRESULT WINAPI DotNetPlugin::Initialize(AIMP36SDK::IAIMPCore* core) { System::Diagnostics::Debug::WriteLine("BEGIN: Initialize DotNet plugin"); _managedCore = gcnew AIMP::SDK360::ManagedAimpCore(core); _managedExtension = gcnew ManagedFunctionality(_managedCore); _configurationManager = gcnew AIMP::ConfigurationManager(_managedCore); LoadExtensions(core); if (_configurationManager->GetValueAsInt32("AimpDotNet\\Settings\\DebugMode") == 1) { AIMP::SDK::InternalLogger::Instance->Initialize(_managedCore->GetPath(AIMP::SDK::AimpMessages::AimpCorePathType::AIMP_CORE_PATH_PROFILE), "aimp_dotnet.log"); } _pluginState = gcnew AIMP::SDK::PluginStateSaver(_configurationManager); _pluginSettings = GetPluginSettings(); _pluginSettings->PluginsCollection->PluginLoadEvent += gcnew AIMP::SDK::PluginLoadUnloadEvent(_managedExtension, &ManagedFunctionality::PluginLoadEventReaction); _pluginSettings->PluginsCollection->PluginUnloadEvent += gcnew AIMP::SDK::PluginLoadUnloadEvent(_managedExtension, &ManagedFunctionality::PluginUnloadEventReaction); _pluginState->Load(_pluginSettings); AIMP::SDK::InternalLogger::Instance->Write("Initialized"); System::Diagnostics::Debug::WriteLine("END: Initialize DotNet plugin"); return S_OK; }
BOOL CMissedCallsDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_list.Init(); m_cboShow.AddString(_("Missed Calls")); m_cboShow.AddString(_("Received Calls")); m_cboShow.AddString(_("Placed Calls")); m_cboShow.SetCurSel(0); m_cboPhone.AddString(_("Show all")); LoadExtensions(); m_cboPhone.SetCurSel(0); m_cboDate.AddString(_("Show all")); m_cboDate.AddString(_("Today")); m_cboDate.SetCurSel(1); SetWindowPos(&this->wndNoTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); UpdateList(); InitLocaleGUI(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize () { if (!ParseCmdLine ()) return false; #ifdef WIN32 // Initialize crash reporting Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "TA Spring Crashreport"); #endif // Initialize class system creg::ClassBinder::InitializeClasses (); #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 InitVFS (); if (!InitWindow ("RtsSpring")) { SDL_Quit (); return false; } // Global structures ENTER_SYNCED; gs=new CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=new CGlobalUnsyncedStuff(); InitOpenGL(); palette.Init(); // Initialize keyboard SDL_EnableUNICODE(1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetModState (KMOD_NONE); keys = new Uint8[SDLK_LAST]; memset (keys,0,sizeof(Uint8)*SDLK_LAST); // Initialize font font = new CglFont(32,223); LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); CreateGameSetup (); return true; }
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; }
extern "C" __declspec(dllexport) int libyabause_init ( CDInterface *_CD, const char *biosfn, int usegl, int carttype, int quickload, int clocksync, int clockbase ) { usinggl = usegl; if (usegl) { //headless cores should not create GL contexts, but use the one from the invoking frontend #ifndef HEADLESS if(!StartGLContext()) return 0; #endif if(!LoadExtensions()) return 0; } FECD.DeInit = _CD->DeInit; FECD.GetStatus = _CD->GetStatus; FECD.Init = _CD->Init; FECD.ReadAheadFAD = _CD->ReadAheadFAD; FECD.ReadSectorFAD = _CD->ReadSectorFAD; FECD.ReadTOC = _CD->ReadTOC; // only overwrite a few SNDDummy functions memcpy(&FESND, &SNDDummy, sizeof(FESND)); FESND.id = 2; FESND.Name = "FESND"; FESND.GetAudioSpace = FESNDGetAudioSpace; FESND.UpdateAudio = FESNDUpdateAudio; yabauseinit_struct yinit; memset(&yinit, 0, sizeof(yabauseinit_struct)); yinit.percoretype = PERCORE_DUMMY; yinit.sh2coretype = SH2CORE_INTERPRETER; if (usegl) yinit.vidcoretype = VIDCORE_OGL; else yinit.vidcoretype = VIDCORE_SOFT; yinit.sndcoretype = 2; //SNDCORE_DUMMY; yinit.cdcoretype = 2; // CDCORE_ISO; //CDCORE_DUMMY; yinit.m68kcoretype = M68KCORE_C68K; yinit.cartpath = CART_NONE; yinit.regionid = REGION_AUTODETECT; yinit.biospath = biosfn; yinit.cdpath = "Saturnus"; //NULL; yinit.buppath = NULL; yinit.mpegpath = NULL; yinit.carttype = carttype; yinit.netlinksetting = NULL; yinit.videoformattype = VIDEOFORMATTYPE_NTSC; yabsys.usequickload = quickload; yinit.usethreads = 0; yinit.frameskip = 0; yinit.clocksync = clocksync; yinit.basetime = clockbase; // same format as return from time(); 0 to use time() if (usegl && !vdp2hookfcn) { // hook vdp2setresolution vdp2hookfcn = VIDOGL.Vdp2SetResolution; VIDOGL.Vdp2SetResolution = vdp2newhook; } if (YabauseInit(&yinit) != 0) return 0; SpeedThrottleDisable(); DisableAutoFrameSkip(); ScspSetFrameAccurate(1); OSDChangeCore(OSDCORE_DUMMY); ctrl1 = PerPadAdd(&PORTDATA1); ctrl2 = PerPadAdd(&PORTDATA2); return 1; }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize () { logOutput.SetMirrorToStdout(!!configHandler.GetInt("StdoutDebug",0)); // Initialize class system creg::ClassBinder::InitializeClasses (); // Initialize crash reporting #ifdef _MSC_VER Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "TA Spring Crashreport"); if (!GetInstance()) { ErrorMessageBox("Error installing crash reporter", "CrashReport error:", MBF_OK); return false; } #endif // _MSC_VER #ifdef __MINGW32__ CrashHandler::Install(); #endif // __MINGW32__ FileSystemHandler::Initialize(true); if (!ParseCmdLine ()) return false; if (!InitWindow ("RtsSpring")) { SDL_Quit (); return false; } mouseInput = IMouseInput::Get (); // Global structures ENTER_SYNCED; gs=SAFE_NEW CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=SAFE_NEW CGlobalUnsyncedStuff(); if (cmdline->result("minimise")) { gu->active = false; SDL_WM_IconifyWindow(); } // Enable auto quit? int quit_time; if (cmdline->result("quit", quit_time)) { gu->autoQuit = true; gu->quitTime = quit_time; } InitOpenGL(); palette.Init(); // Initialize keyboard SDL_EnableUNICODE(1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetModState (KMOD_NONE); keys = SAFE_NEW Uint8[SDLK_LAST]; memset (keys,0,sizeof(Uint8)*SDLK_LAST); // Initialize font font = SAFE_NEW CglFont(configHandler.GetInt("FontCharFirst", 32), configHandler.GetInt("FontCharLast", 223), configHandler.GetString("FontFile", "Luxi.ttf").c_str()); // Initialize GLEW LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); // Initialize ScriptHandler / LUA CScriptHandler::Instance().StartLua(); // Create CGameSetup and CPreGame objects CreateGameSetup (); return true; }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize () { logOutput.SetMirrorToStdout(!!configHandler.GetInt("StdoutDebug",0)); // Initialize class system creg::System::InitializeClasses (); // Initialize crash reporting #ifdef _WIN32 #if defined(_CRASHRPT_H_) Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "Spring Crashreport"); if (!GetInstance()) { ErrorMessageBox("Error installing crash reporter", "CrashReport error:", MBF_OK); return false; } #elif defined(CRASHHANDLER_H) CrashHandler::Install(); #endif InitializeSEH(); #endif ParseCmdLine(); FileSystemHandler::Initialize(true); if (!InitWindow ("RtsSpring")) { SDL_Quit (); return false; } mouseInput = IMouseInput::Get (); // Global structures ENTER_SYNCED; gs=SAFE_NEW CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=SAFE_NEW CGlobalUnsyncedStuff(); if (cmdline->result("minimise")) { gu->active = false; SDL_WM_IconifyWindow(); } // Enable auto quit? int quit_time; if (cmdline->result("quit", quit_time)) { gu->autoQuit = true; gu->quitTime = quit_time; } InitOpenGL(); palette.Init(); // Initialize keyboard SDL_EnableUNICODE(1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetModState (KMOD_NONE); keys = SAFE_NEW Uint8[SDLK_LAST]; memset (keys,0,sizeof(Uint8)*SDLK_LAST); // Initialize font const int charFirst = configHandler.GetInt("FontCharFirst", 32); const int charLast = configHandler.GetInt("FontCharLast", 255); std::string fontFile = configHandler.GetString("FontFile", "fonts/Luxi.ttf"); try { font = SAFE_NEW CglFont(charFirst, charLast, fontFile.c_str()); } catch(content_error&) { // If the standard location fails, retry in fonts directory or vice versa. if (fontFile.substr(0, 6) == "fonts/") fontFile = fontFile.substr(6); else fontFile = "fonts/" + fontFile; font = SAFE_NEW CglFont(charFirst, charLast, fontFile.c_str()); } // Initialize GLEW LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); // Initialize named texture handler CNamedTextures::Init(); // Initialize Lua GL LuaOpenGL::Init(); // Initialize ScriptHandler / LUA CScriptHandler::Instance().StartLua(); // Create CGameSetup and CPreGame objects CreateGameSetup (); return true; }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize() { #if !(defined(WIN32) || defined(__APPLE__) || defined(HEADLESS)) //! this MUST run before any other X11 call (esp. those by SDL!) //! we need it to make calls to X11 threadsafe if (!XInitThreads()) { LOG_L(L_FATAL, "Xlib is not thread safe"); return false; } #endif #if defined(_WIN32) && defined(__GNUC__) // load QTCreator's gdb helper dll; a variant of this should also work on other OSes { // don't display a dialog box if gdb helpers aren't found UINT olderrors = SetErrorMode(SEM_FAILCRITICALERRORS); if (LoadLibrary("gdbmacros.dll")) { LOG("QT Creator's gdbmacros.dll loaded"); } SetErrorMode(olderrors); } #endif // Initialize class system creg::System::InitializeClasses(); // Initialize crash reporting CrashHandler::Install(); globalRendering = new CGlobalRendering(); ParseCmdLine(); CMyMath::Init(); good_fpu_control_registers("::Run"); Watchdog::Install(); //! register (this) mainthread Watchdog::RegisterThread(WDT_MAIN, true); // log OS version LOG("OS: %s", Platform::GetOS().c_str()); if (Platform::Is64Bit()) LOG("OS: 64bit native mode"); else if (Platform::Is32BitEmulation()) LOG("OS: emulated 32bit mode"); else LOG("OS: 32bit native mode"); FileSystemInitializer::Initialize(); UpdateOldConfigs(); if (!InitWindow(("Spring " + SpringVersion::GetSync()).c_str())) { SDL_Quit(); return false; } mouseInput = IMouseInput::GetInstance(); keyInput = KeyInput::GetInstance(); input.AddHandler(boost::bind(&SpringApp::MainEventHandler, this, _1)); // Global structures gs = new CGlobalSynced(); gu = new CGlobalUnsynced(); // Initialize GLEW LoadExtensions(); //! check if FSAA init worked fine if (globalRendering->FSAA && !MultisampleVerify()) globalRendering->FSAA = 0; InitOpenGL(); agui::InitGui(); LoadFonts(); globalRendering->PostInit(); // Initialize named texture handler CNamedTextures::Init(); // Initialize Lua GL LuaOpenGL::Init(); // Sound ISound::Initialize(); InitJoystick(); SetProcessAffinity(configHandler->GetInt("SetCoreAffinity")); // Create CGameSetup and CPreGame objects Startup(); return true; }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize() { assert(cmdline != NULL); assert(configHandler != NULL); // list user's config LOG("============== <User Config> =============="); const std::map<std::string, std::string> settings = configHandler->GetDataWithoutDefaults(); for (auto& it: settings) { // exclude non-engine configtags if (ConfigVariable::GetMetaData(it.first) == nullptr) continue; LOG("%s = %s", it.first.c_str(), it.second.c_str()); } LOG("============== </User Config> =============="); FileSystemInitializer::InitializeLogOutput(); CLogOutput::LogSystemInfo(); LOG(" CPU Clock: %s", spring_clock::GetName()); LOG("Physical CPU Cores: %d", Threading::GetPhysicalCpuCores()); LOG(" Logical CPU Cores: %d", Threading::GetLogicalCpuCores()); CMyMath::Init(); globalRendering = new CGlobalRendering(); globalRendering->SetFullScreen(configHandler->GetBool("Fullscreen"), cmdline->IsSet("window"), cmdline->IsSet("fullscreen")); #if !(defined(WIN32) || defined(__APPLE__) || defined(HEADLESS)) // this MUST run before any other X11 call (esp. those by SDL!) // we need it to make calls to X11 threadsafe if (!XInitThreads()) { LOG_L(L_FATAL, "Xlib is not thread safe"); return false; } #endif #if defined(WIN32) && defined(__GNUC__) // load QTCreator's gdb helper dll; a variant of this should also work on other OSes { // don't display a dialog box if gdb helpers aren't found UINT olderrors = SetErrorMode(SEM_FAILCRITICALERRORS); if (LoadLibrary("gdbmacros.dll")) { LOG_L(L_DEBUG, "QT Creator's gdbmacros.dll loaded"); } SetErrorMode(olderrors); } #endif // Initialize crash reporting CrashHandler::Install(); good_fpu_control_registers(__FUNCTION__); // CREG & GlobalConfig creg::System::InitializeClasses(); GlobalConfig::Instantiate(); // Create Window if (!InitWindow(("Spring " + SpringVersion::GetSync()).c_str())) { SDL_Quit(); return false; } // Init OpenGL LoadExtensions(); // Initialize GLEW globalRendering->PostInit(); InitOpenGL(); // Install Watchdog (must happen after time epoch is set) Watchdog::Install(); Watchdog::RegisterThread(WDT_MAIN, true); // ArchiveScanner uses for_mt --> needs thread-count set // (use all threads available, later switch to less) ThreadPool::SetThreadCount(ThreadPool::GetMaxThreads()); FileSystemInitializer::Initialize(); mouseInput = IMouseInput::GetInstance(); input.AddHandler(boost::bind(&SpringApp::MainEventHandler, this, _1)); // Global structures gs = new CGlobalSynced(); gu = new CGlobalUnsynced(); // GUIs agui::InitGui(); LoadFonts(); CNamedTextures::Init(); LuaOpenGL::Init(); ISound::Initialize(); InitJoystick(); // Lua socket restrictions luaSocketRestrictions = new CLuaSocketRestrictions(); // Multithreading & Affinity Threading::SetThreadName("unknown"); // set default threadname Threading::InitThreadPool(); Threading::SetThreadScheduler(); battery = new CBattery(); // Create CGameSetup and CPreGame objects Startup(); return true; }
int WINAPI WinMain( HINSTANCE hInstanceIn, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { INIT_SYNCIFY; MSG msg; // Windows Message Structure BOOL done=FALSE; // Bool Variable To Exit Loop hInstance=hInstanceIn; for(int b=0;b<256;b++) keys[b]=false; // Initialize crash reporting Install(crashCallback, "*****@*****.**", "TA Spring Crashreport"); ENTER_SYNCED; gs=new CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=new CGlobalUnsyncedStuff(); // Initialize lua bindings CLuaBinder lua; if (!lua.LoadScript("testscript.lua")) MessageBox(NULL, lua.lastError.c_str(), "lua",MB_YESNO|MB_ICONQUESTION); // Check if the commandline parameter is specifying a demo file bool playDemo = false; string cmdline(lpCmdLine); for (string::size_type pos = cmdline.find("\""); pos != string::npos; pos = cmdline.find("\"")) cmdline.erase(pos, 1); string cmdext = cmdline.substr(cmdline.find_last_of('.') + 1); transform(cmdext.begin(), cmdext.end(), cmdext.begin(), (int (*)(int))tolower); if (cmdext == "sdf") { playDemo = true; // Launching a demo through a file association will not start spring with a correct working directory // So we need to determine this from the commandline and change manually // It should look like "x:\path\path\spring.exe" demo.sdf string fullcmd(GetCommandLine()); string executable; if (fullcmd[0] == '"') executable = fullcmd.substr(1, fullcmd.find('"', 1)); else executable = fullcmd.substr(0, fullcmd.find(' ')); string path = executable.substr(0, executable.find_last_of('\\')); if (path != "") _chdir(path.c_str()); //MessageBox(NULL,path.c_str(), "Path",MB_YESNO|MB_ICONQUESTION); } // 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(); ENTER_SYNCED; if (!playDemo) { gameSetup=new CGameSetup(); if(!gameSetup->Init(cmdline)){ delete gameSetup; gameSetup=0; } } ENTER_MIXED; bool server; if (playDemo) server = false; else if(gameSetup) server=gameSetup->myPlayer-gameSetup->numDemoPlayers == 0; else server=MessageBox(NULL,"Do you want to be server?", "Be server?",MB_YESNO|MB_ICONQUESTION)==IDYES; /* // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; // Windowed Mode }*/ fullscreen=regHandler.GetInt("Fullscreen",1)!=0; #ifdef _DEBUG fullscreen=false; #endif; int xres=1024; int yres=768; xres=regHandler.GetInt("XResolution",xres); yres=regHandler.GetInt("YResolution",yres); int frequency=regHandler.GetInt("DisplayFrequency",0); // Create Our OpenGL Window if (!CreateGLWindow("RtsSpring",xres,yres,32,fullscreen,frequency)) { return 0; // Quit If Window Was Not Created } font=new CglFont(hDC,32,223); LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer SwapBuffers(hDC); // Swap Buffers (Double Buffering) if (playDemo) pregame = new CPreGame(false, cmdline); else pregame=new CPreGame(server, ""); #ifdef NEW_GUI guicontroller = new GUIcontroller(); #endif lua.CreateLateBindings(); while(!done) // Loop That Runs While done=FALSE { ENTER_UNSYNCED; if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=TRUE; // If So done=TRUE } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if ((active && !DrawGLScene()) || globalQuit) // Active? Was There A Quit Received? { done=TRUE; // ESC or DrawGLScene Signalled A Quit } else // Not Time To Quit, Update Screen { SwapBuffers(hDC); // Swap Buffers (Double Buffering) SleepEx(0,true); } } } ENTER_MIXED; // Shutdown delete gameSetup; delete pregame; //in case we exit during init delete game; delete font; RegHandler::Deallocate(); UnloadExtensions(); KillGLWindow(); // Kill The Window delete gs; delete gu; END_SYNCIFY; //m_dumpMemoryReport(); return (msg.wParam); // Exit The Program }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize() { #if !(defined(WIN32) || defined(__APPLE__) || defined(HEADLESS)) //! this MUST run before any other X11 call (esp. those by SDL!) //! we need it to make calls to X11 threadsafe if (!XInitThreads()) { LOG_L(L_FATAL, "Xlib is not thread safe"); return false; } #endif #if defined(_WIN32) && defined(__GNUC__) // load QTCreator's gdb helper dll; a variant of this should also work on other OSes { // don't display a dialog box if gdb helpers aren't found UINT olderrors = SetErrorMode(SEM_FAILCRITICALERRORS); if (LoadLibrary("gdbmacros.dll")) { LOG("QT Creator's gdbmacros.dll loaded"); } SetErrorMode(olderrors); } #endif // Initialize class system creg::System::InitializeClasses(); // Initialize crash reporting CrashHandler::Install(); globalRendering = new CGlobalRendering(); ParseCmdLine(); CMyMath::Init(); good_fpu_control_registers("::Run"); // log OS version LOG("OS: %s", Platform::GetOS().c_str()); if (Platform::Is64Bit()) LOG("OS: 64bit native mode"); else if (Platform::Is32BitEmulation()) LOG("OS: emulated 32bit mode"); else LOG("OS: 32bit native mode"); // Rename Threads // We give the process itself the name `unknown`, htop & co. will still show the binary's name. // But all child threads copy by default the name of their parent, so all threads that don't set // their name themselves will show up as 'unknown'. Threading::SetThreadName("unknown"); #ifdef _OPENMP #pragma omp parallel { int i = omp_get_thread_num(); if (i != 0) { // 0 is the source thread std::ostringstream buf; buf << "omp" << i; Threading::SetThreadName(buf.str().c_str()); } } #endif // Install Watchdog Watchdog::Install(); Watchdog::RegisterThread(WDT_MAIN, true); FileSystemInitializer::Initialize(); // Create Window if (!InitWindow(("Spring " + SpringVersion::GetSync()).c_str())) { SDL_Quit(); return false; } mouseInput = IMouseInput::GetInstance(); keyInput = KeyInput::GetInstance(); input.AddHandler(boost::bind(&SpringApp::MainEventHandler, this, _1)); // Global structures gs = new CGlobalSynced(); gu = new CGlobalUnsynced(); // Initialize GLEW LoadExtensions(); //! check if FSAA init worked fine if (globalRendering->FSAA && !MultisampleVerify()) globalRendering->FSAA = 0; InitOpenGL(); agui::InitGui(); LoadFonts(); globalRendering->PostInit(); // Initialize named texture handler CNamedTextures::Init(); // Initialize Lua GL LuaOpenGL::Init(); // Sound & Input ISound::Initialize(); InitJoystick(); // Multithreading & Affinity LOG("CPU Cores: %d", Threading::GetAvailableCores()); const uint32_t affinity = configHandler->GetUnsigned("SetCoreAffinity"); const uint32_t cpuMask = Threading::SetAffinity(affinity); if (cpuMask == 0xFFFFFF) { LOG("CPU affinity not set"); } else if (cpuMask != affinity) { LOG("CPU affinity mask set: %d (config is %d)", cpuMask, affinity); } else if (cpuMask == 0) { LOG_L(L_ERROR, "Failed to CPU affinity mask <%d>", affinity); } else { LOG("CPU affinity mask set: %d", cpuMask); } // Create CGameSetup and CPreGame objects Startup(); return true; }