Merge branch 'master' into skybox_refactoring

This commit is contained in:
Elderme 2015-08-02 00:09:10 +02:00
commit 2817fda910
27 changed files with 168 additions and 194 deletions

2
data/supertuxkart.git Normal file
View File

@ -0,0 +1,2 @@
This file is only here to help STK finding the right directory,
and to avoid problems with other directories called 'data'.

View File

@ -182,7 +182,7 @@ void IconButtonWidget::add()
x1 += diff;
x2 += diff;
}
else if (x2 > irr_driver->getActualScreenSize().Width)
else if (x2 > (int)irr_driver->getActualScreenSize().Width)
{
int diff = x2 - irr_driver->getActualScreenSize().Width;
x2 -= diff;

View File

@ -142,7 +142,7 @@ FileManager::FileManager()
m_file_system = irr::io::createFileSystem();
irr::io::path exe_path;
std::string exe_path;
// Search for the root directory
// =============================
@ -151,8 +151,11 @@ FileManager::FileManager()
// This is esp. useful for Visual Studio, since it's not necessary
// to define the working directory when debugging, it works automatically.
std::string root_dir;
if(m_file_system->existFile(CommandLine::getExecName().c_str()))
exe_path = m_file_system->getFileDir(CommandLine::getExecName().c_str());
const std::string version = std::string("supertuxkart.") + STK_VERSION;
if (fileExists(CommandLine::getExecName()))
{
exe_path = StringUtils::getPath(CommandLine::getExecName());
}
if(exe_path.size()==0 || exe_path[exe_path.size()-1]!='/')
exe_path += "/";
if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL )
@ -160,19 +163,19 @@ FileManager::FileManager()
#ifdef __APPLE__
else if( macSetBundlePathIfRelevant( root_dir ) ) { root_dir = root_dir + "data/"; }
#endif
else if(m_file_system->existFile("data/stk_config.xml"))
else if(fileExists("data/", version))
root_dir = "data/" ;
else if(m_file_system->existFile("../data/stk_config.xml"))
else if(fileExists("../data/", version))
root_dir = "../data/" ;
else if(m_file_system->existFile("../../data/stk_config.xml"))
else if(fileExists("../../data/", version))
root_dir = "../../data/" ;
// Test for old style build environment, with executable in root of stk
else if(m_file_system->existFile(exe_path+"data/stk_config.xml"))
else if(fileExists(exe_path+"data/"+version))
root_dir = (exe_path+"data/").c_str();
// Check for windows cmake style: bld/Debug/bin/supertuxkart.exe
else if (m_file_system->existFile(exe_path + "../../../data/stk_config.xml"))
root_dir = (exe_path + "../../../data/").c_str();
else if (m_file_system->existFile(exe_path + "../data/stk_config.xml"))
else if (fileExists(exe_path + "../../../data/"+version))
root_dir = exe_path + "../../../data/";
else if (fileExists(exe_path + "../data/"+version))
{
root_dir = exe_path.c_str();
root_dir += "../data/";
@ -181,14 +184,22 @@ FileManager::FileManager()
{
#ifdef SUPERTUXKART_DATADIR
root_dir = SUPERTUXKART_DATADIR"/data/";
if(root_dir.size()==0 || root_dir[root_dir.size()-1]!='/')
root_dir+='/';
#else
root_dir = "/usr/local/share/games/supertuxkart/";
#endif
}
if (!m_file_system->existFile((root_dir + version).c_str()))
{
Log::error("FileManager", "Could not file '%s'in any "
"standard location (esp. ../data).", version.c_str());
Log::error("FileManager",
"Last location checked '%s'.", root_dir.c_str());
Log::fatal("FileManager",
"Set $SUPERTUXKART_DATADIR to point to the data directory.");
// fatal will exit the application
}
addRootDirs(root_dir);
if( fileExists(root_dir+"../../stk-assets"))
addRootDirs(root_dir+"../../stk-assets");

View File

@ -134,6 +134,14 @@ public:
std::string searchTexture(const std::string& fname) const;
std::string getUserConfigFile(const std::string& fname) const;
bool fileExists(const std::string& path) const;
// ------------------------------------------------------------------------
/** Convenience function to save some typing in the
* file manager constructor. */
bool fileExists(const char *prefix, const std::string& path) const
{
return fileExists(std::string(prefix) + path);
}
// ------------------------------------------------------------------------
void listFiles (std::set<std::string>& result,
const std::string& dir,
bool make_full_path=false) const;

View File

@ -77,13 +77,8 @@ void CutsceneWorld::init()
m_duration = -1.0f;
//const btTransform &s = getTrack()->getStartTransform(0);
//const Vec3 &v = s.getOrigin();
Camera* stk_cam = Camera::createCamera(NULL);
m_camera = stk_cam->getCameraSceneNode();
//m_camera = irr_driver->getSceneManager()
// ->addCameraSceneNode(NULL, core::vector3df(0.0f, 0.0f, 0.0f),
// core::vector3df(0.0f, 0.0f, 0.0f));
m_camera->setFOV(0.61f);
m_camera->bindTargetAndRotation(true); // no "look-at"

View File

@ -101,11 +101,23 @@ int FollowTheLeaderRace::getScoreForPosition(int p)
return m_score_for_position[p - 2];
} // getScoreForPosition
//-----------------------------------------------------------------------------
const btTransform &FollowTheLeaderRace::getStartTransform(int index)
{
if (index == 0) // Leader start position
return m_track->getStartTransform(index);
// Otherwise the karts will start at the rear starting positions
int start_index = stk_config->m_max_karts
- race_manager->getNumberOfKarts() + index;
return m_track->getStartTransform(start_index);
} // getStartTransform
//-----------------------------------------------------------------------------
/** Returns the original time at which the countdown timer started. This is
* used by the race_gui to display the music credits in FTL mode correctly.
*/
float FollowTheLeaderRace::getClockStartTime()
float FollowTheLeaderRace::getClockStartTime() const
{
return m_leader_intervals[0];
} // getClockStartTime

View File

@ -48,14 +48,19 @@ public:
// overriding World methods
virtual void reset() OVERRIDE;
virtual const std::string& getIdent() const OVERRIDE;
virtual float getClockStartTime();
virtual bool useFastMusicNearEnd() const OVERRIDE { return false; }
virtual const btTransform &getStartTransform(int index);
virtual float getClockStartTime() const;
virtual void getKartsDisplayInfo(
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
virtual void init() OVERRIDE;
virtual void terminateRace() OVERRIDE;
virtual bool isRaceOver() OVERRIDE;
// ------------------------------------------------------------------------
/** Returns if this type of race has laps. */
virtual bool raceHasLaps() OVERRIDE { return false; }
// ------------------------------------------------------------------------
/** Returns if faster music should be used at the end. */
virtual bool useFastMusicNearEnd() const OVERRIDE { return false; }
}; // FollowTheLeader

View File

@ -160,6 +160,37 @@ void OverWorld::update(float dt)
}
} // update
// ----------------------------------------------------------------------------
/** Finds the starting position which is closest to the kart.
* \param kart The kart for which a rescue position needs to be determined.
*/
unsigned int OverWorld::getRescuePositionIndex(AbstractKart *kart)
{
// find closest point to drop kart on
const int start_spots_amount = getNumberOfRescuePositions();
assert(start_spots_amount > 0);
int closest_id = -1;
float closest_distance = 999999999.0f;
for (int n=0; n<start_spots_amount; n++)
{
const btTransform &s = getStartTransform(n);
const Vec3 &v = s.getOrigin();
float abs_distance = (v - kart->getXYZ()).length();
if (abs_distance < closest_distance)
{
closest_distance = abs_distance;
closest_id = n;
}
}
assert(closest_id != -1);
return closest_id;
} // getRescuePositionIndex
//-----------------------------------------------------------------------------
/** This function is not used in the overworld race gui.
*/

View File

@ -48,6 +48,7 @@ public:
static void enterOverWorld();
virtual void update(float delta) OVERRIDE;
unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
virtual void getKartsDisplayInfo(
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) OVERRIDE;
// ------------------------------------------------------------------------

View File

@ -108,7 +108,7 @@ AbstractKart *ProfileWorld::createKart(const std::string &kart_ident, int index,
RaceManager::KartType type,
const PlayerDifficulty *difficulty)
{
btTransform init_pos = m_track->getStartTransform(index);
btTransform init_pos = getStartTransform(index);
Kart *new_kart = new KartWithStats(kart_ident,
/*world kart id*/ index,

View File

@ -315,88 +315,6 @@ void SoccerWorld::getKartsDisplayInfo(
*/
} // getKartsDisplayInfo
//-----------------------------------------------------------------------------
/** Moves a kart to its rescue position.
* \param kart The kart that was rescued.
*/
void SoccerWorld::moveKartAfterRescue(AbstractKart* kart)
{
// find closest point to drop kart on
World *world = World::getWorld();
const int start_spots_amount = world->getTrack()->getNumberOfStartPositions();
assert(start_spots_amount > 0);
float largest_accumulated_distance_found = -1;
int furthest_id_found = -1;
const float kart_x = kart->getXYZ().getX();
const float kart_z = kart->getXYZ().getZ();
for(int n=0; n<start_spots_amount; n++)
{
// no need for the overhead to compute exact distance with sqrt(),
// so using the 'manhattan' heuristic which will do fine enough.
const btTransform &s = world->getTrack()->getStartTransform(n);
const Vec3 &v=s.getOrigin();
float accumulatedDistance = .0f;
bool spawnPointClear = true;
for(unsigned int k=0; k<getCurrentNumKarts(); k++)
{
const AbstractKart *currentKart = World::getWorld()->getKart(k);
const float currentKart_x = currentKart->getXYZ().getX();
const float currentKartk_z = currentKart->getXYZ().getZ();
if(kart_x!=currentKart_x && kart_z !=currentKartk_z)
{
float absDistance = fabs(currentKart_x - v.getX()) +
fabs(currentKartk_z - v.getZ());
if(absDistance < CLEAR_SPAWN_RANGE)
{
spawnPointClear = false;
break;
}
accumulatedDistance += absDistance;
}
}
if(largest_accumulated_distance_found < accumulatedDistance && spawnPointClear)
{
furthest_id_found = n;
largest_accumulated_distance_found = accumulatedDistance;
}
}
assert(furthest_id_found != -1);
const btTransform &s = world->getTrack()->getStartTransform(furthest_id_found);
const Vec3 &xyz = s.getOrigin();
kart->setXYZ(xyz);
kart->setRotation(s.getRotation());
//position kart from same height as in World::resetAllKarts
btTransform pos;
pos.setOrigin(kart->getXYZ()+btVector3(0, 0.5f*kart->getKartHeight(), 0.0f));
pos.setRotation( btQuaternion(btVector3(0.0f, 1.0f, 0.0f), 0 /* angle */) );
kart->getBody()->setCenterOfMassTransform(pos);
//project kart to surface of track
bool kart_over_ground = m_track->findGround(kart);
if (kart_over_ground)
{
//add vertical offset so that the kart starts off above the track
float vertical_offset = kart->getKartProperties()->getVertRescueOffset() *
kart->getKartHeight();
kart->getBody()->translate(btVector3(0, vertical_offset, 0));
}
else
{
Log::warn("[SoccerWorld]", " Invalid position after rescue for kart %s on track %s.",
kart->getIdent().c_str(), m_track->getIdent().c_str());
}
} // moveKartAfterRescue
//-----------------------------------------------------------------------------
/** Set position and team for the karts */
void SoccerWorld::initKartList()
@ -481,7 +399,7 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
if(index % 2 != 0) posIndex += 1;
}
btTransform init_pos = m_track->getStartTransform(posIndex);
btTransform init_pos = getStartTransform(posIndex);
AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos,
difficulty);

View File

@ -77,7 +77,6 @@ public:
std::vector<RaceGUIBase::KartIconDisplayInfo> *info);
int getScore(unsigned int i);
virtual bool raceHasLaps() { return false; }
virtual void moveKartAfterRescue(AbstractKart* kart);
virtual const std::string& getIdent() const;

View File

@ -477,53 +477,3 @@ void ThreeStrikesBattle::getKartsDisplayInfo(
}
} // getKartsDisplayInfo
//-----------------------------------------------------------------------------
/** Determines the rescue position for a kart. The rescue position is the
* start position which is has the biggest accumulated distance to all other
* karts, and which has no other kart very close. The latter avoids dropping
* a kart on top of another kart.
* \param kart The kart that is going to be rescued.
* \returns The index of the start position to which the rescued kart
* should be moved to.
*/
unsigned int ThreeStrikesBattle::getRescuePositionIndex(AbstractKart *kart)
{
const int start_spots_amount = getTrack()->getNumberOfStartPositions();
assert(start_spots_amount > 0);
float largest_accumulated_distance_found = -1;
int furthest_id_found = -1;
for(int n=0; n<start_spots_amount; n++)
{
const btTransform &s = getTrack()->getStartTransform(n);
const Vec3 &v=s.getOrigin();
float accumulated_distance = .0f;
bool spawn_point_clear = true;
for(unsigned int k=0; k<getCurrentNumKarts(); k++)
{
if(kart->getWorldKartId()==k) continue;
float abs_distance2 = (getKart(k)->getXYZ()-v).length2_2d();
const float CLEAR_SPAWN_RANGE2 = 5*5;
if( abs_distance2 < CLEAR_SPAWN_RANGE2)
{
spawn_point_clear = false;
break;
}
accumulated_distance += sqrt(abs_distance2);
}
if(accumulated_distance > largest_accumulated_distance_found &&
spawn_point_clear)
{
furthest_id_found = n;
largest_accumulated_distance_found = accumulated_distance;
}
}
assert(furthest_id_found != -1);
return furthest_id_found;
} // getRescuePositionIndex

View File

@ -97,7 +97,6 @@ public:
virtual void getKartsDisplayInfo(
std::vector<RaceGUIBase::KartIconDisplayInfo> *info);
virtual bool raceHasLaps(){ return false; }
virtual unsigned int getRescuePositionIndex(AbstractKart *kart);
virtual const std::string& getIdent() const;

View File

@ -305,7 +305,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
const PlayerDifficulty *difficulty)
{
int position = index+1;
btTransform init_pos = m_track->getStartTransform(index);
btTransform init_pos = getStartTransform(index);
AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos,
difficulty);
new_kart->init(race_manager->getKartType(index));
@ -337,6 +337,14 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
return new_kart;
} // createKart
//-----------------------------------------------------------------------------
/** Returns the start coordinates for a kart with a given index.
* \param index Index of kart ranging from 0 to kart_num-1. */
const btTransform &World::getStartTransform(int index)
{
return m_track->getStartTransform(index);
} // getStartTransform
//-----------------------------------------------------------------------------
/** Creates an AI controller for the kart.
* \param kart The kart to be controlled by an AI.

View File

@ -231,7 +231,7 @@ public:
/** Returns the bullet transformation for the specified rescue index. */
virtual btTransform getRescueTransform(unsigned int index) const = 0;
// ------------------------------------------------------------------------
void moveKartAfterRescue(AbstractKart* kart);
virtual void moveKartAfterRescue(AbstractKart* kart);
// ------------------------------------------------------------------------
/** Called when it is needed to know whether this kind of race involves
* counting laps. */
@ -294,6 +294,7 @@ public:
PhysicalObject *object);
AbstractKart* getPlayerKart(unsigned int player) const;
AbstractKart* getLocalPlayerKart(unsigned int n) const;
virtual const btTransform &getStartTransform(int index);
// ------------------------------------------------------------------------
/** Returns a pointer to the race gui. */
RaceGUIBase *getRaceGUI() const { return m_race_gui;}

View File

@ -134,35 +134,54 @@ unsigned int WorldWithRank::getNumberOfRescuePositions() const
return getTrack()->getNumberOfStartPositions();
} // getNumberOfRescuePositions
// ----------------------------------------------------------------------------
/** Finds the starting position which is closest to the kart.
* \param kart The kart for which a rescue position needs to be determined.
//-----------------------------------------------------------------------------
/** Determines the rescue position for a kart. The rescue position is the
* start position which is has the biggest accumulated distance to all other
* karts, and which has no other kart very close. The latter avoids dropping
* a kart on top of another kart. This is the method used
* \param kart The kart that is going to be rescued.
* \returns The index of the start position to which the rescued kart
* should be moved to.
*/
unsigned int WorldWithRank::getRescuePositionIndex(AbstractKart *kart)
{
// find closest point to drop kart on
const int start_spots_amount = getNumberOfRescuePositions();
const int start_spots_amount = getTrack()->getNumberOfStartPositions();
assert(start_spots_amount > 0);
int closest_id = -1;
float closest_distance = 999999999.0f;
float largest_accumulated_distance_found = -1;
int furthest_id_found = -1;
for(int n=0; n<start_spots_amount; n++)
{
const btTransform &s = getTrack()->getStartTransform(n);
const btTransform &s = getStartTransform(n);
const Vec3 &v=s.getOrigin();
float accumulated_distance = .0f;
bool spawn_point_clear = true;
float abs_distance = (v - kart->getXYZ()).length();
if (abs_distance < closest_distance)
for(unsigned int k=0; k<getCurrentNumKarts(); k++)
{
closest_distance = abs_distance;
closest_id = n;
if(kart->getWorldKartId()==k) continue;
float abs_distance2 = (getKart(k)->getXYZ()-v).length2_2d();
const float CLEAR_SPAWN_RANGE2 = 5*5;
if( abs_distance2 < CLEAR_SPAWN_RANGE2)
{
spawn_point_clear = false;
break;
}
accumulated_distance += sqrt(abs_distance2);
}
if(accumulated_distance > largest_accumulated_distance_found &&
spawn_point_clear)
{
furthest_id_found = n;
largest_accumulated_distance_found = accumulated_distance;
}
}
assert(closest_id != -1);
return closest_id;
assert(furthest_id_found != -1);
return furthest_id_found;
} // getRescuePositionIndex
// ----------------------------------------------------------------------------

View File

@ -331,12 +331,15 @@ void AddonsLoading::stopDownload()
// (and not uninstalling an installed one):
if(m_download_request)
{
// In case of a cancel we can't free the memory, since
// network_http will potentially update the request. So in
// order to avoid a memory leak, we let network_http free
// the request.
//m_download_request->setManageMemory(true);
// In case of a cancel we can't free the memory, since the
// request manager thread is potentially working on this request. So
// in order to avoid a memory leak, we let the request manager
// free the data. This is thread safe since freeing the data is done
// when the request manager handles the result queue - and this is
// done by the main thread (i.e. this thread).
m_download_request->setManageMemory(true);
m_download_request->cancel();
m_download_request = NULL;
};
} // startDownload

View File

@ -59,7 +59,8 @@ void OptionsScreenAudio::init()
{
Screen::init();
RibbonWidget* ribbon = this->getWidget<RibbonWidget>("options_choice");
if (ribbon != NULL) ribbon->select( "tab_audio", PLAYER_ID_GAME_MASTER );
assert(ribbon != NULL);
ribbon->select( "tab_audio", PLAYER_ID_GAME_MASTER );
ribbon->getRibbonChildren()[0].setTooltip( _("Graphics") );
ribbon->getRibbonChildren()[2].setTooltip( _("User Interface") );

View File

@ -133,7 +133,8 @@ void OptionsScreenInput::init()
{
Screen::init();
RibbonWidget* tabBar = this->getWidget<RibbonWidget>("options_choice");
if (tabBar != NULL) tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER );
assert(tabBar != NULL);
tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER );
tabBar->getRibbonChildren()[0].setTooltip( _("Graphics") );
tabBar->getRibbonChildren()[1].setTooltip( _("Audio") );

View File

@ -79,8 +79,8 @@ void OptionsScreenInput2::init()
{
Screen::init();
RibbonWidget* tabBar = getWidget<RibbonWidget>("options_choice");
if (tabBar != NULL) tabBar->select( "tab_controls",
PLAYER_ID_GAME_MASTER );
assert(tabBar != NULL);
tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER );
tabBar->getRibbonChildren()[0].setTooltip( _("Graphics") );
tabBar->getRibbonChildren()[1].setTooltip( _("Audio") );

View File

@ -112,7 +112,8 @@ void OptionsScreenUI::init()
{
Screen::init();
RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice");
if (ribbon != NULL) ribbon->select( "tab_ui", PLAYER_ID_GAME_MASTER );
assert(ribbon != NULL);
ribbon->select( "tab_ui", PLAYER_ID_GAME_MASTER );
ribbon->getRibbonChildren()[0].setTooltip( _("Graphics") );
ribbon->getRibbonChildren()[1].setTooltip( _("Audio") );

View File

@ -159,7 +159,8 @@ void OptionsScreenVideo::init()
{
Screen::init();
RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice");
if (ribbon != NULL) ribbon->select( "tab_video", PLAYER_ID_GAME_MASTER );
assert(ribbon != NULL);
ribbon->select( "tab_video", PLAYER_ID_GAME_MASTER );
ribbon->getRibbonChildren()[1].setTooltip( _("Audio") );
ribbon->getRibbonChildren()[2].setTooltip( _("User Interface") );

View File

@ -631,7 +631,8 @@ void BaseUserScreen::unloaded()
void TabbedUserScreen::init()
{
RibbonWidget* tab_bar = getWidget<RibbonWidget>("options_choice");
if (tab_bar) tab_bar->select("tab_players", PLAYER_ID_GAME_MASTER);
assert(tab_bar != NULL);
tab_bar->select("tab_players", PLAYER_ID_GAME_MASTER);
tab_bar->getRibbonChildren()[0].setTooltip( _("Graphics") );
tab_bar->getRibbonChildren()[1].setTooltip( _("Audio") );
tab_bar->getRibbonChildren()[2].setTooltip( _("User Interface") );

View File

@ -1736,6 +1736,13 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
if (!m_is_arena && !m_is_soccer && !m_is_cutscene)
{
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_FOLLOW_LEADER)
{
// In a FTL race the non-leader karts are placed at the end of the
// field, so we need all start positions.
m_start_transforms.resize(stk_config->m_max_karts);
}
else
m_start_transforms.resize(race_manager->getNumberOfKarts());
QuadGraph::get()->setDefaultStartPositions(&m_start_transforms,
karts_per_row,

View File

@ -523,7 +523,7 @@ public:
// ------------------------------------------------------------------------
/** Returns the start coordinates for a kart with a given index.
* \param index Index of kart ranging from 0 to kart_num-1. */
btTransform getStartTransform (unsigned int index) const
const btTransform& getStartTransform (unsigned int index) const
{
if (index >= m_start_transforms.size())
Log::fatal("Track", "No start position for kart %i.", index);