bool stageTwoInitialise(void) { int i; debug(LOG_WZ, "== stageTwoInitalise =="); // make sure we clear on loading; this a bad hack to fix a bug when // loading a savegame where we are building a lassat for (i = 0; i < MAX_PLAYERS; i++) { setLasSatExists(false, i); } if (!dispInitialise()) /* Initialise the display system */ { return false; } if(!initMiscImds()) /* Set up the explosions */ { iV_ShutDown(); debug( LOG_FATAL, "Can't find all the explosions graphics?" ); abort(); return false; } if (!cmdDroidInit()) { return false; } /* Shift the interface initialisation here temporarily so that it can pick up the stats after they have been loaded */ if (!intInitialise()) { return false; } if (!initMessage()) /* Initialise the message heaps */ { return false; } if (!gwInitialise()) { return false; } if (!initScripts()) // Initialise the new javascript system { return false; } // keymappings keyClearMappings(); keyInitMappings(false); // Set the default uncoloured cursor here, since it looks slightly // better for menus and such. wzSetCursor(CURSOR_DEFAULT); SetFormAudioIDs(ID_SOUND_WINDOWOPEN,ID_SOUND_WINDOWCLOSE); // Setup game queues. // Don't ask why this doesn't go in stage three. In fact, don't even ask me what stage one/two/three is supposed to mean, it seems about as descriptive as stage doStuff, stage doMoreStuff and stage doEvenMoreStuff... debug(LOG_MAIN, "Init game queues, I am %d.", selectedPlayer); sendQueuedDroidInfo(); // Discard any pending orders which could later get flushed into the game queue. for (i = 0; i < MAX_PLAYERS; ++i) { NETinitQueue(NETgameQueue(i)); if (!myResponsibility(i)) { NETsetNoSendOverNetwork(NETgameQueue(i)); } } debug(LOG_MAIN, "stageTwoInitialise: done"); return true; }
bool stageOneInitialise(void) { debug(LOG_WZ, "== stageOneInitalise =="); // Initialise all globals and statics everwhere. if(!InitialiseGlobals()) { return false; } iV_Reset(); // Reset the IV library if (!stringsInitialise()) /* Initialise the string system */ { return false; } if (!objInitialise()) /* Initialise the object system */ { return false; } if (!droidInit()) { return false; } if (!initViewData()) { return false; } if (!grpInitialise()) { return false; } if (!aiInitialise()) /* Initialise the AI system */ // pregame { return false; } if (!anim_Init()) { return false; } if ( !animObj_Init( init_ObjectDead ) ) { return false; } if (!allocPlayerPower()) /*set up the PlayerPower for each player - this should only be done ONCE now*/ { return false; } // initialise the visibility stuff if (!visInitialise()) { return false; } /* Initialise the movement system */ if (!moveInitialise()) { return false; } if (!proj_InitSystem()) { return false; } if (!scrTabInitialise()) // Initialise the old wzscript system { return false; } if (!initScripts()) // Initialise the new javascript system { return false; } if (!gridInitialise()) { return false; } initMission(); initTransporters(); scriptInit(); // do this here so that the very first mission has it initialised initRunData(); gameTimeInit(); eventTimeReset(gameTime / SCR_TICKRATE); return true; }
void Engine::exec() { LOGME_CALL("Engine::exec"); LOGME_DEBUG("Initializing window"); if(!initWindow()) { throw std::runtime_error("Window initialization failed"); } LOGME_DEBUG("Initializing engine state stack"); if (!initStateStack()) { throw std::runtime_error("State stack initialization failed"); } LOGME_DEBUG("Initializing resources"); if (!initResources()) { throw std::runtime_error("Resource initialization failed"); } #ifdef MVE_LUA_ENABLED LOGME_DEBUG("Initializing LUA scripts"); if(!initScripts()) { throw std::runtime_error("Script initialization failed"); } #endif if (!initEngine()) { throw std::runtime_error("Engine initialization failed"); } LOGME_DEBUG("Initialization success"); sf::Clock clock; sf::Time timeSinceLastUpdate(sf::Time::Zero); sf::Event event; sf::Text debugFpsText; sf::Time debugUpdateTime(sf::Time::Zero); std::size_t debugFramesCount(0); // TODO: Find nice font on a good licence terms for debug purposes sf::Font font; if (!font.loadFromFile("assets/GRUPO3.ttf")) { throw std::runtime_error("Cannot load font"); } // TODO: Magic numbers debugFpsText.setFont(font); debugFpsText.setCharacterSize(14); debugFpsText.setColor(sf::Color::White); debugFpsText.setPosition(5.f, 5.f); debugFpsText.setString(""); sf::RenderWindow& window = getWindow(); mve::StateStack& stateStack = getStateStack(); // TODO: API to set pixel scale factor // TODO: API to have multiple views managed by Engine or some its component // sf::View scaledView(window.getDefaultView()); sf::View scaledView(sf::Vector2f(160, 120), sf::Vector2f(320, 240)); // Main loop onLoopStarted(); while (window.isOpen()) { window.setView(scaledView); sf::Time dt = clock.restart(); timeSinceLastUpdate += dt; // We need to catch up with logic and input handling first while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; // Process input while (window.pollEvent(event)) { if (!onEventHandle(event)) { continue; } stateStack.handleEvent(event); if (event.type == sf::Event::Closed) { stateStack.clearRequest(); } } // Update logic by the constant time TimePerFrame onLogicUpdate(TimePerFrame); stateStack.update(TimePerFrame); // No state on the stack means no client to handle the logic if (stateStack.isEmpty()) { window.close(); } } const bool displayFps = getDisplayFps(); if (displayFps) { debugUpdateTime += dt; ++debugFramesCount; if (debugUpdateTime >= sf::seconds(1.f)) { onFpsUpdate(debugFramesCount); debugFpsText.setString("FPS: " + utils::toString(debugFramesCount)); debugUpdateTime -= sf::seconds(1.f); debugFramesCount = 0; } } window.clear(mBgColor); onRenderStarted(); stateStack.draw(); window.setView(window.getDefaultView()); if (displayFps) { window.draw(debugFpsText); } onRenderFinished(); window.display(); } onLoopFinished(); }