Start work to allow showing worlds without kart, for cutscenes. Does not work yet but getting closer

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11266 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2012-05-31 01:32:27 +00:00
parent 15cd8f4277
commit 553385fe9d
8 changed files with 243 additions and 10 deletions

View File

@ -1443,7 +1443,7 @@ void IrrDriver::update(float dt)
irr_driver->getVideoDriver()->enableMaterial2D();
RaceGUIBase *rg = world->getRaceGUI();
rg->update(dt);
if (rg) rg->update(dt);
for(unsigned int i=0; i<world->getNumKarts(); i++)
{
AbstractKart *kart=world->getKart(i);

View File

@ -1116,9 +1116,14 @@ namespace GUIEngine
else
{
if (ModalDialog::isADialogActive())
{
ModalDialog::getCurrent()->onUpdate(dt);
else
World::getWorld()->getRaceGUI()->renderGlobal(elapsed_time);
}
else
{
RaceGUIBase* rg = World::getWorld()->getRaceGUI();
if (rg != NULL) rg->renderGlobal(elapsed_time);
}
}

View File

@ -0,0 +1,127 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "modes/cutscene_world.hpp"
#include <string>
#include <IMeshSceneNode.h>
#include "audio/music_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
#include "physics/physics.hpp"
#include "states_screens/race_gui_base.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_manager.hpp"
#include "utils/constants.hpp"
//-----------------------------------------------------------------------------
/** Constructor. Sets up the clock mode etc.
*/
CutsceneWorld::CutsceneWorld() : World()
{
WorldStatus::setClockMode(CLOCK_NONE);
m_use_highscores = false;
} // CutsceneWorld
//-----------------------------------------------------------------------------
/** Initialises the three strikes battle. It sets up the data structure
* to keep track of points etc. for each kart.
*/
void CutsceneWorld::init()
{
World::init();
} // CutsceneWorld
//-----------------------------------------------------------------------------
/** Destructor. Clears all internal data structures, and removes the tire mesh
* from the mesh cache.
*/
CutsceneWorld::~CutsceneWorld()
{
} // ~CutsceneWorld
//-----------------------------------------------------------------------------
/** Called when a kart is hit.
* \param kart_id The world kart id of the kart that was hit.
*/
void CutsceneWorld::kartHit(const int kart_id)
{
}
//-----------------------------------------------------------------------------
/** Returns the internal identifier for this race.
*/
const std::string& CutsceneWorld::getIdent() const
{
return IDENT_STRIKES;
} // getIdent
//-----------------------------------------------------------------------------
/** Update the world and the track.
* \param dt Time step size.
*/
void CutsceneWorld::update(float dt)
{
World::update(dt);
World::updateTrack(dt);
} // update
//-----------------------------------------------------------------------------
/** The battle is over if only one kart is left, or no player kart.
*/
bool CutsceneWorld::isRaceOver()
{
return false;
} // isRaceOver
//-----------------------------------------------------------------------------
/** Called when the race finishes, i.e. after playing (if necessary) an
* end of race animation. It updates the time for all karts still racing,
* and then updates the ranks.
*/
void CutsceneWorld::terminateRace()
{
World::terminateRace();
} // terminateRace
//-----------------------------------------------------------------------------
/** Called then a battle is restarted.
*/
void CutsceneWorld::restartRace()
{
World::restartRace();
} // restartRace
//-----------------------------------------------------------------------------
/** Returns the data to display in the race gui.
*/
RaceGUIBase::KartIconDisplayInfo* CutsceneWorld::getKartsDisplayInfo()
{
return NULL;
} // getKartDisplayInfo
//-----------------------------------------------------------------------------
/** Moves a kart to its rescue position.
* \param kart The kart that was rescued.
*/
void CutsceneWorld::moveKartAfterRescue(AbstractKart* kart)
{
} // moveKartAfterRescue

View File

@ -0,0 +1,68 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef CUTSCENE_WORLD_HPP
#define CUTSCENE_WORLD_HPP
#include "modes/world_with_rank.hpp"
#include "states_screens/race_gui_base.hpp"
#include <IMesh.h>
#include <string>
/**
* \brief An implementation of World, to provide animated 3D cutscenes
* \ingroup modes
*/
class CutsceneWorld : public World
{
public:
CutsceneWorld();
virtual ~CutsceneWorld();
virtual void init() OVERRIDE;
// clock events
virtual bool isRaceOver() OVERRIDE;
virtual void terminateRace() OVERRIDE;
// overriding World methods
virtual void restartRace() OVERRIDE;
virtual RaceGUIBase::KartIconDisplayInfo* getKartsDisplayInfo() OVERRIDE;
virtual bool raceHasLaps() OVERRIDE { return false; }
virtual void moveKartAfterRescue(AbstractKart* kart) OVERRIDE;
virtual const std::string& getIdent() const OVERRIDE;
virtual void kartHit(const int kart_id) OVERRIDE;
virtual void update(float dt) OVERRIDE;
virtual void createRaceGUI() OVERRIDE
{
m_race_gui = NULL;
}
}; // CutsceneWorld
#endif

View File

@ -132,7 +132,7 @@ void World::init()
m_physics = new Physics();
unsigned int num_karts = race_manager->getNumberOfKarts();
assert(num_karts > 0);
//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.
@ -169,8 +169,11 @@ void World::init()
powerup_manager->updateWeightsForRace(num_karts);
// erase messages left over
RaceGUIBase* rg = getRaceGUI();
rg->init();
if (rg) rg->clearAllMessages();
if (rg)
{
rg->init();
rg->clearAllMessages();
}
} // init
//-----------------------------------------------------------------------------

View File

@ -543,18 +543,25 @@ void NetworkManager::setupPlayerKartInfo()
for(unsigned int i=0; i<race_manager->getNumLocalPlayers(); i++)
m_kart_info.push_back(race_manager->getLocalKartInfo(i));
printf("[setupPlayerKartInfo] m_num_karts = %i\n", race_manager->getNumberOfKarts());
// Now sort by (hostid, playerid)
std::sort(m_kart_info.begin(), m_kart_info.end());
// Set the player kart information
race_manager->setNumPlayers(m_kart_info.size());
printf("[setupPlayerKartInfo2] m_num_karts = %i\n", race_manager->getNumberOfKarts());
// Set the global player ID for each player
for(unsigned int i=0; i<m_kart_info.size(); i++)
{
m_kart_info[i].setGlobalPlayerId(i);
race_manager->setPlayerKart(i, m_kart_info[i]);
}
printf("[setupPlayerKartInfo3] m_num_karts = %i\n", race_manager->getNumberOfKarts());
// Compute the id of the first kart from each host
m_kart_id_offset.resize(m_num_clients+1);
m_kart_id_offset[0]=0;
@ -562,6 +569,8 @@ void NetworkManager::setupPlayerKartInfo()
m_kart_id_offset[i]=m_kart_id_offset[i-1]+m_num_local_players[i-1];
race_manager->computeRandomKartList();
printf("[setupPlayerKartInfo4] m_num_karts = %i\n", race_manager->getNumberOfKarts());
} // setupPlayerKartInfo
// ----------------------------------------------------------------------------

View File

@ -30,6 +30,7 @@
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/kart_properties_manager.hpp"
#include "modes/cutscene_world.hpp"
#include "modes/demo_world.hpp"
#include "modes/follow_the_leader.hpp"
#include "modes/overworld.hpp"
@ -215,6 +216,8 @@ void RaceManager::setTrack(const std::string& track)
*/
void RaceManager::computeRandomKartList()
{
if (m_num_karts == 0) return;
int n = m_num_karts - m_player_karts.size();
if(UserConfigParams::logMisc())
std::cout << "AI karts count = " << n << " for m_num_karts="
@ -248,6 +251,7 @@ void RaceManager::computeRandomKartList()
void RaceManager::startNew(bool from_overworld)
{
printf("Start New, m_num_karts = %i\n", m_num_karts);
m_started_from_overworld = from_overworld;
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
@ -257,13 +261,15 @@ void RaceManager::startNew(bool from_overworld)
m_num_laps = m_grand_prix.getLaps();
m_reverse_track = m_grand_prix.getReverse();
}
assert(m_player_karts.size() > 0);
//assert(m_player_karts.size() > 0);
// command line parameters: negative numbers=all karts
if(m_num_karts < 0 ) m_num_karts = stk_config->m_max_karts;
if((size_t)m_num_karts < m_player_karts.size())
m_num_karts = (int)m_player_karts.size();
printf("Start New 2, m_num_karts = %i\n", m_num_karts);
// Create the kart status data structure to keep track of scores, times, ...
// ==========================================================================
m_kart_status.clear();
@ -291,6 +297,8 @@ void RaceManager::startNew(bool from_overworld)
}
}
printf("Start New 3, m_num_karts = %i\n", m_num_karts);
// Then the players, which start behind the AI karts
// -------------------------------------------------
for(int i=m_player_karts.size()-1; i>=0; i--)
@ -326,6 +334,8 @@ void RaceManager::startNextRace()
// Uncomment to debug audio leaks
// sfx_manager->dump();
printf("startNextRace, m_num_karts = %i\n", m_num_karts);
stk_config->getAllScores(&m_score_for_position, m_num_karts);
IrrlichtDevice* device = irr_driver->getDevice();
GUIEngine::renderLoading();
@ -365,6 +375,8 @@ void RaceManager::startNextRace()
}
} // not first race
printf("startNextRace 2, m_num_karts = %i\n", m_num_karts);
// the constructor assigns this object to the global
// variable world. Admittedly a bit ugly, but simplifies
// handling of objects which get created in the constructor
@ -382,11 +394,16 @@ void RaceManager::startNextRace()
World::setWorld(new ThreeStrikesBattle());
else if(m_minor_mode==MINOR_MODE_OVERWORLD)
World::setWorld(new OverWorld());
else if(m_minor_mode==MINOR_MODE_CUTSCENE)
World::setWorld(new CutsceneWorld());
else
{
fprintf(stderr,"Could not create given race mode\n");
assert(0);
}
printf("startNextRace 3, m_num_karts = %i\n", m_num_karts);
World::getWorld()->init();
// Save the current score and set last time to zero. This is necessary
// if someone presses esc after finishing a gp, and selects restart:
@ -648,14 +665,17 @@ void RaceManager::startSingleRace(const std::string trackIdent,
{
StateManager::get()->enterGameState();
setTrack(trackIdent.c_str());
if (num_laps != -1) setNumLaps( num_laps );
setMajorMode(RaceManager::MAJOR_MODE_SINGLE);
printf("[startSingleRace3] m_num_karts = %i\n", m_num_karts);
setCoinTarget( 0 ); // Might still be set from a previous challenge
network_manager->setupPlayerKartInfo();
printf("[startSingleRace4] m_num_karts = %i\n", m_num_karts);
startNew(from_overworld);
}

View File

@ -103,7 +103,8 @@ public:
MINOR_MODE_FOLLOW_LEADER = LINEAR_RACE(2, false),
MINOR_MODE_OVERWORLD = LINEAR_RACE(3, false),
MINOR_MODE_3_STRIKES = BATTLE_ARENA(0)
MINOR_MODE_3_STRIKES = BATTLE_ARENA(0),
MINOR_MODE_CUTSCENE = BATTLE_ARENA(1)
};
/** Returns a string identifier for each minor race mode.