/** This function is called after instanciating. The code here can't be moved * to the contructor as child classes must be instanciated, otherwise * polymorphism will fail and the results will be incorrect . Also in init() * functions can be called that use World::getWorld(). */ void World::init() { m_faster_music_active = false; m_fastest_kart = 0; m_eliminated_karts = 0; m_eliminated_players = 0; m_num_players = 0; unsigned int gk = 0; if (race_manager->hasGhostKarts()) gk = ReplayPlay::get()->getNumGhostKart(); // Create the race gui before anything else is attached to the scene node // (which happens when the track is loaded). This allows the race gui to // do any rendering on texture. Note that this function can NOT be called // in the World constuctor, since it might be overwritten by a the game // mode class, which would not have been constructed at the time that this // constructor is called, so the wrong race gui would be created. createRaceGUI(); RewindManager::create(); // Grab the track file Track *track = track_manager->getTrack(race_manager->getTrackName()); Scripting::ScriptEngine::getInstance<Scripting::ScriptEngine>(); if(!track) { std::ostringstream msg; msg << "Track '" << race_manager->getTrackName() << "' not found.\n"; throw std::runtime_error(msg.str()); } std::string script_path = track->getTrackFile("scripting.as"); Scripting::ScriptEngine::getInstance()->loadScript(script_path, true); // Create the physics Physics::getInstance<Physics>(); unsigned int num_karts = race_manager->getNumberOfKarts(); //assert(num_karts > 0); // Load the track models - this must be done before the karts so that the // karts can be positioned properly on (and not in) the tracks. // This also defines the static Track::getCurrentTrack function. track->loadTrackModel(race_manager->getReverseTrack()); if (gk > 0) { ReplayPlay::get()->load(); for (unsigned int k = 0; k < gk; k++) m_karts.push_back(ReplayPlay::get()->getGhostKart(k)); } // Assign team of AIs for soccer mode before createKart SoccerWorld* sw = dynamic_cast<SoccerWorld*>(this); if (sw) sw->setAITeam(); for(unsigned int i=0; i<num_karts; i++) { if (race_manager->getKartType(i) == RaceManager::KT_GHOST) continue; std::string kart_ident = history->replayHistory() ? history->getKartIdent(i) : race_manager->getKartIdent(i); int local_player_id = race_manager->getKartLocalPlayerId(i); int global_player_id = race_manager->getKartGlobalPlayerId(i); AbstractKart* newkart = createKart(kart_ident, i, local_player_id, global_player_id, race_manager->getKartType(i), race_manager->getPlayerDifficulty(i)); m_karts.push_back(newkart); track->adjustForFog(newkart->getNode()); } // for i // Load other custom models if needed loadCustomModels(); #ifndef SERVER_ONLY // Now that all models are loaded, apply the overrides irr_driver->applyObjectPassShader(); #endif // Must be called after all karts are created m_race_gui->init(); powerup_manager->updateWeightsForRace(race_manager->getNumberOfKarts()); if (UserConfigParams::m_weather_effects) { Weather::getInstance<Weather>(); // create Weather instance } } // init
/** This function is called after instanciating. The code here can't be moved * to the contructor as child classes must be instanciated, otherwise * polymorphism will fail and the results will be incorrect . Also in init() * functions can be called that use World::getWorld(). */ void World::init() { m_faster_music_active = false; m_fastest_kart = 0; m_eliminated_karts = 0; m_eliminated_players = 0; m_num_players = 0; // Create the race gui before anything else is attached to the scene node // (which happens when the track is loaded). This allows the race gui to // do any rendering on texture. Note that this function can NOT be called // in the World constuctor, since it might be overwritten by a the game // mode class, which would not have been constructed at the time that this // constructor is called, so the wrong race gui would be created. createRaceGUI(); // Grab the track file m_track = track_manager->getTrack(race_manager->getTrackName()); m_script_engine = new Scripting::ScriptEngine(); if(!m_track) { std::ostringstream msg; msg << "Track '" << race_manager->getTrackName() << "' not found.\n"; throw std::runtime_error(msg.str()); } std::string script_path = World::getWorld()->getTrack()->getTrackFile("scripting.as"); m_script_engine->loadScript(script_path, true); // Create the physics m_physics = new Physics(); unsigned int num_karts = race_manager->getNumberOfKarts(); //assert(num_karts > 0); // Load the track models - this must be done before the karts so that the // karts can be positioned properly on (and not in) the tracks. m_track->loadTrackModel(race_manager->getReverseTrack()); for(unsigned int i=0; i<num_karts; i++) { std::string kart_ident = history->replayHistory() ? history->getKartIdent(i) : race_manager->getKartIdent(i); int local_player_id = race_manager->getKartLocalPlayerId(i); int global_player_id = race_manager->getKartGlobalPlayerId(i); const PlayerDifficulty *player_difficulty = stk_config->getPlayerDifficulty(race_manager->getPlayerDifficulty(i)); AbstractKart* newkart = createKart(kart_ident, i, local_player_id, global_player_id, race_manager->getKartType(i), player_difficulty); m_karts.push_back(newkart); m_track->adjustForFog(newkart->getNode()); } // for i // Now that all models are loaded, apply the overrides irr_driver->applyObjectPassShader(); // Must be called after all karts are created m_race_gui->init(); if(ReplayPlay::get()) ReplayPlay::get()->Load(); powerup_manager->updateWeightsForRace(num_karts); if (UserConfigParams::m_weather_effects) { m_weather = new Weather(m_track->getWeatherLightning(), m_track->getWeatherSound()); } m_script_engine->compileLoadedScripts(); } // init
/** This function is called after instanciating. This can't be moved to the * contructor as child classes must be instanciated, otherwise polymorphism * will fail and the results will be incorrect . Also in init() functions * can be called that use World::getWorld(). */ void World::init() { race_state = new RaceState(); m_faster_music_active = false; m_fastest_kart = 0; m_eliminated_karts = 0; m_eliminated_players = 0; m_num_players = 0; // Create the race gui before anything else is attached to the scene node // (which happens when the track is loaded). This allows the race gui to // do any rendering on texture. createRaceGUI(); // Grab the track file m_track = track_manager->getTrack(race_manager->getTrackName()); if(!m_track) { std::ostringstream msg; msg << "Track '" << race_manager->getTrackName() << "' not found.\n"; throw std::runtime_error(msg.str()); } // Create the physics m_physics = new Physics(); unsigned int num_karts = race_manager->getNumberOfKarts(); //assert(num_karts > 0); // Load the track models - this must be done before the karts so that the // karts can be positioned properly on (and not in) the tracks. m_track->loadTrackModel(this, race_manager->getReverseTrack()); for(unsigned int i=0; i<num_karts; i++) { std::string kart_ident = history->replayHistory() ? history->getKartIdent(i) : race_manager->getKartIdent(i); int local_player_id = race_manager->getKartLocalPlayerId(i); int global_player_id = race_manager->getKartGlobalPlayerId(i); AbstractKart* newkart = createKart(kart_ident, i, local_player_id, global_player_id, race_manager->getKartType(i)); m_karts.push_back(newkart); m_track->adjustForFog(newkart->getNode()); } // for i if(ReplayPlay::get()) ReplayPlay::get()->Load(); resetAllKarts(); // Note: track reset must be called after all karts exist, since check // objects need to allocate data structures depending on the number // of karts. m_track->reset(); if(!history->replayHistory()) history->initRecording(); if(ReplayRecorder::get()) ReplayRecorder::get()->init(); network_manager->worldLoaded(); powerup_manager->updateWeightsForRace(num_karts); // erase messages left over RaceGUIBase* rg = getRaceGUI(); if (rg) { rg->init(); rg->clearAllMessages(); } } // init