From cd6185c2ee3e324a06fcbef1517fc8048632bdfa Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 15 Jan 2012 02:46:59 +0000 Subject: [PATCH] Start work on starting challenges from overworld. Note that it does NOT yet fully work. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10668 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/lod_node.cpp | 1 + src/graphics/material_manager.cpp | 1 + src/karts/controller/player_controller.cpp | 4 ++ src/modes/overworld.cpp | 66 ++++++++++++++++++++++ src/modes/overworld.hpp | 4 ++ src/modes/world.hpp | 2 + src/states_screens/race_gui_overworld.cpp | 8 +++ 7 files changed, 86 insertions(+) diff --git a/src/graphics/lod_node.cpp b/src/graphics/lod_node.cpp index 7cacbecd5..81653a70d 100644 --- a/src/graphics/lod_node.cpp +++ b/src/graphics/lod_node.cpp @@ -140,6 +140,7 @@ void LODNode::OnRegisterSceneNode() { scene::IMeshBuffer* mb = mesh->getMeshBuffer(n); video::ITexture* t = mb->getMaterial().getTexture(0); + if (t == NULL) continue; Material* m = material_manager->getMaterialFor(t, mb); if (m != NULL) { diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index 2646ed57a..a7e99faac 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -68,6 +68,7 @@ std::set g_processed; Material* MaterialManager::getMaterialFor(video::ITexture* t, scene::IMeshBuffer *mb) { + assert(t != NULL); const std::string image = StringUtils::getBasename(core::stringc(t->getName()).c_str()); // Search backward so that temporary (track) textures are found first for(int i = (int)m_materials.size()-1; i>=0; i-- ) diff --git a/src/karts/controller/player_controller.cpp b/src/karts/controller/player_controller.cpp index c9689d876..ff7d41721 100644 --- a/src/karts/controller/player_controller.cpp +++ b/src/karts/controller/player_controller.cpp @@ -176,6 +176,10 @@ void PlayerController::action(PlayerAction action, int value) break; case PA_FIRE: m_controls->m_fire = (value!=0); + if (value > 0) + { + World::getWorld()->onFirePressed(this); + } break; case PA_LOOK_BACK: m_controls->m_look_back = (value!=0); diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index 8ee1c4e79..7c6a80a8d 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -15,9 +15,15 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "challenges/unlock_manager.hpp" +#include "input/device_manager.hpp" +#include "input/input.hpp" +#include "input/input_manager.hpp" #include "karts/kart.hpp" #include "modes/overworld.hpp" +#include "network/network_manager.hpp" #include "states_screens/race_gui_overworld.hpp" +#include "tracks/track.hpp" //----------------------------------------------------------------------------- OverWorld::OverWorld() : LinearWorld() @@ -71,3 +77,63 @@ void OverWorld::createRaceGUI() { m_race_gui = new RaceGUIOverworld(); } + +//----------------------------------------------------------------------------- + +void OverWorld::onFirePressed(Controller* who) +{ + const std::vector& challenges = m_track->getChallengeList(); + + Vec3 kart_xyz = getKart(0)->getXYZ(); + for (unsigned int n=0; n pos(15, + 10, + 15 + UserConfigParams::m_width/2, + 10 + GUIEngine::getTitleFontHeight()); + + const ChallengeData* challenge = unlock_manager->getChallenge(challenges[n].m_challenge_id); + + if (challenge == NULL) + { + fprintf(stderr, "[RaceGUIOverworld] ERROR: Cannot find challenge <%s>\n", + challenges[n].m_challenge_id.c_str()); + break; + } + + race_manager->exitRace(); + + // Use latest used device + InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice(); + + int id = StateManager::get()->createActivePlayer( unlock_manager->getCurrentPlayer(), device ); + input_manager->getDeviceList()->setSinglePlayer( StateManager::get()->getActivePlayer(id) ); + + // Set up race manager appropriately + race_manager->setNumLocalPlayers(1); + race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); + + // ASSIGN should make sure that only input from assigned devices is read. + input_manager->getDeviceList()->setAssignMode(ASSIGN); + + // Go straight to the race + StateManager::get()->enterGameState(); + + // Initialise global data - necessary even in local games to avoid + // many if tests in other places (e.g. if network_game call + // network_manager else call race_manager). + network_manager->initCharacterDataStructures(); + + // Launch challenge + challenge->setRace(); + + // Sets up kart info, including random list of kart for AI + network_manager->setupPlayerKartInfo(); + race_manager->startNew(); + return; + } // end if + } // end for +} + diff --git a/src/modes/overworld.hpp b/src/modes/overworld.hpp index c42646529..0da49b11e 100644 --- a/src/modes/overworld.hpp +++ b/src/modes/overworld.hpp @@ -63,6 +63,10 @@ public: // ------------------------------------------------------------------------ /** Override base class method */ virtual bool shouldDrawTimer() const { return false; } + // ------------------------------------------------------------------------ + /** Override base class method */ + virtual void onFirePressed(Controller* who); + }; #endif diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 024f4764d..517bc3365 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -274,6 +274,8 @@ public: void setClearbackBufferColor(irr::video::SColor color) { m_clear_color = color; } // ------------------------------------------------------------------------ + /** Override if you want to know when a kart presses fire */ + virtual void onFirePressed(Controller* who) {} }; // World diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index e579bc796..f827f7831 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -371,6 +371,14 @@ void RaceGUIOverworld::drawGlobalMiniMap() GUIEngine::getFont()->draw(challenge->getChallengeDescription().c_str(), pos, video::SColor(255,255,255,255), false, false /* vcenter */, NULL); + + core::rect pos2(0, + UserConfigParams::m_height - GUIEngine::getFontHeight()*2, + UserConfigParams::m_width, + UserConfigParams::m_height); + GUIEngine::getFont()->draw(_("Press fire to start the challenge"), pos2, + video::SColor(255,255,150,60), + true, true /* vcenter */, NULL); break; } }