Port rewinders to use shared_ptr
This commit is contained in:
parent
bbf5c54f87
commit
60bfc1840b
@ -43,19 +43,20 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
std::vector<scene::IMesh *> ItemManager::m_item_mesh;
|
std::vector<scene::IMesh *> ItemManager::m_item_mesh;
|
||||||
std::vector<scene::IMesh *> ItemManager::m_item_lowres_mesh;
|
std::vector<scene::IMesh *> ItemManager::m_item_lowres_mesh;
|
||||||
std::vector<video::SColorf> ItemManager::m_glow_color;
|
std::vector<video::SColorf> ItemManager::m_glow_color;
|
||||||
bool ItemManager::m_disable_item_collection = false;
|
bool ItemManager::m_disable_item_collection = false;
|
||||||
ItemManager * ItemManager::m_item_manager = NULL;
|
std::shared_ptr<ItemManager> ItemManager::m_item_manager;
|
||||||
std::mt19937 ItemManager::m_random_engine;
|
std::mt19937 ItemManager::m_random_engine;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Creates one instance of the item manager. */
|
/** Creates one instance of the item manager. */
|
||||||
void ItemManager::create()
|
void ItemManager::create()
|
||||||
{
|
{
|
||||||
assert(!m_item_manager);
|
assert(!m_item_manager);
|
||||||
m_item_manager = new ItemManager();
|
// Due to protected constructor use new instead of make_shared
|
||||||
|
m_item_manager = std::shared_ptr<ItemManager>(new ItemManager());
|
||||||
} // create
|
} // create
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -63,8 +64,7 @@ void ItemManager::create()
|
|||||||
void ItemManager::destroy()
|
void ItemManager::destroy()
|
||||||
{
|
{
|
||||||
assert(m_item_manager);
|
assert(m_item_manager);
|
||||||
delete m_item_manager;
|
m_item_manager = nullptr;
|
||||||
m_item_manager = NULL;
|
|
||||||
} // destroy
|
} // destroy
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -60,7 +60,7 @@ private:
|
|||||||
static std::mt19937 m_random_engine;
|
static std::mt19937 m_random_engine;
|
||||||
protected:
|
protected:
|
||||||
/** The instance of ItemManager while a race is on. */
|
/** The instance of ItemManager while a race is on. */
|
||||||
static ItemManager *m_item_manager;
|
static std::shared_ptr<ItemManager> m_item_manager;
|
||||||
public:
|
public:
|
||||||
static void loadDefaultItemMeshes();
|
static void loadDefaultItemMeshes();
|
||||||
static void removeTextures();
|
static void removeTextures();
|
||||||
@ -90,9 +90,10 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Return an instance of the item manager (it does not automatically
|
/** Return an instance of the item manager (it does not automatically
|
||||||
* create one, call create for that). */
|
* create one, call create for that). */
|
||||||
static ItemManager *get() {
|
static ItemManager *get()
|
||||||
|
{
|
||||||
assert(m_item_manager);
|
assert(m_item_manager);
|
||||||
return m_item_manager;
|
return m_item_manager.get();
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
@ -119,9 +120,9 @@ protected:
|
|||||||
virtual unsigned int insertItem(Item *item);
|
virtual unsigned int insertItem(Item *item);
|
||||||
void setSwitchItems(const std::vector<int> &switch_items);
|
void setSwitchItems(const std::vector<int> &switch_items);
|
||||||
ItemManager();
|
ItemManager();
|
||||||
|
public:
|
||||||
virtual ~ItemManager();
|
virtual ~ItemManager();
|
||||||
|
|
||||||
public:
|
|
||||||
virtual Item* placeItem (ItemState::ItemType type, const Vec3& xyz,
|
virtual Item* placeItem (ItemState::ItemType type, const Vec3& xyz,
|
||||||
const Vec3 &normal);
|
const Vec3 &normal);
|
||||||
virtual Item* dropNewItem (ItemState::ItemType type,
|
virtual Item* dropNewItem (ItemState::ItemType type,
|
||||||
|
@ -31,10 +31,11 @@
|
|||||||
void NetworkItemManager::create()
|
void NetworkItemManager::create()
|
||||||
{
|
{
|
||||||
assert(!m_item_manager);
|
assert(!m_item_manager);
|
||||||
m_item_manager = new NetworkItemManager();
|
auto nim = std::shared_ptr<NetworkItemManager>(new NetworkItemManager());
|
||||||
|
nim->rewinderAdd();
|
||||||
|
m_item_manager = nim;
|
||||||
} // create
|
} // create
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
/** Creates a new instance of the item manager. This is done at startup
|
/** Creates a new instance of the item manager. This is done at startup
|
||||||
* of each race. */
|
* of each race. */
|
||||||
|
@ -61,10 +61,10 @@ private:
|
|||||||
void forwardTime(int ticks);
|
void forwardTime(int ticks);
|
||||||
|
|
||||||
NetworkItemManager();
|
NetworkItemManager();
|
||||||
virtual ~NetworkItemManager();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void create();
|
static void create();
|
||||||
|
virtual ~NetworkItemManager();
|
||||||
|
|
||||||
void setSwitchItems(const std::vector<int> &switch_items);
|
void setSwitchItems(const std::vector<int> &switch_items);
|
||||||
void sendItemUpdate();
|
void sendItemUpdate();
|
||||||
|
@ -298,7 +298,7 @@ void PowerupManager::WeightsData::convertRankToSection(int rank, int *prev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The last kart always uses the data for the last section
|
// The last kart always uses the data for the last section
|
||||||
if (rank == m_num_karts)
|
if (rank == (int)m_num_karts)
|
||||||
{
|
{
|
||||||
*prev = *next = m_weights_for_section.size() - 1;
|
*prev = *next = m_weights_for_section.size() - 1;
|
||||||
*weight = 1.0f;
|
*weight = 1.0f;
|
||||||
@ -600,9 +600,11 @@ void PowerupManager::unitTesting()
|
|||||||
int num_weights = wd.m_summed_weights_for_rank[0].back();
|
int num_weights = wd.m_summed_weights_for_rank[0].back();
|
||||||
for(int i=0; i<num_weights; i++)
|
for(int i=0; i<num_weights; i++)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
assert( powerup_manager->getRandomPowerup(1, &n, i)==POWERUP_BOWLING );
|
assert( powerup_manager->getRandomPowerup(1, &n, i)==POWERUP_BOWLING );
|
||||||
assert(n==3);
|
assert(n==3);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test 2: Test all possible random numbers for 5 karts and rank 5
|
// Test 2: Test all possible random numbers for 5 karts and rank 5
|
||||||
|
@ -139,7 +139,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int RAND_CLASS_RANGE = 1000;
|
|
||||||
|
|
||||||
/** The icon for each powerup. */
|
/** The icon for each powerup. */
|
||||||
Material* m_all_icons [POWERUP_MAX];
|
Material* m_all_icons [POWERUP_MAX];
|
||||||
|
@ -176,7 +176,7 @@ void LinearWorld::update(int ticks)
|
|||||||
for(unsigned int n=0; n<kart_amount; n++)
|
for(unsigned int n=0; n<kart_amount; n++)
|
||||||
{
|
{
|
||||||
KartInfo& kart_info = m_kart_info[n];
|
KartInfo& kart_info = m_kart_info[n];
|
||||||
AbstractKart* kart = m_karts[n];
|
AbstractKart* kart = m_karts[n].get();
|
||||||
|
|
||||||
// Nothing to do for karts that are currently being
|
// Nothing to do for karts that are currently being
|
||||||
// rescued or eliminated
|
// rescued or eliminated
|
||||||
@ -218,7 +218,7 @@ void LinearWorld::update(int ticks)
|
|||||||
// Update the estimated finish time.
|
// Update the estimated finish time.
|
||||||
// This is used by the AI
|
// This is used by the AI
|
||||||
m_kart_info[i].m_estimated_finish =
|
m_kart_info[i].m_estimated_finish =
|
||||||
estimateFinishTimeForKart(m_karts[i]);
|
estimateFinishTimeForKart(m_karts[i].get());
|
||||||
}
|
}
|
||||||
// If one player and a ghost, or two compared ghosts,
|
// If one player and a ghost, or two compared ghosts,
|
||||||
// compute the live time difference
|
// compute the live time difference
|
||||||
@ -328,7 +328,7 @@ void LinearWorld::updateLiveDifference()
|
|||||||
void LinearWorld::newLap(unsigned int kart_index)
|
void LinearWorld::newLap(unsigned int kart_index)
|
||||||
{
|
{
|
||||||
KartInfo &kart_info = m_kart_info[kart_index];
|
KartInfo &kart_info = m_kart_info[kart_index];
|
||||||
AbstractKart *kart = m_karts[kart_index];
|
AbstractKart *kart = m_karts[kart_index].get();
|
||||||
|
|
||||||
// Reset reset-after-lap achievements
|
// Reset reset-after-lap achievements
|
||||||
PlayerProfile *p = PlayerManager::getCurrentPlayer();
|
PlayerProfile *p = PlayerManager::getCurrentPlayer();
|
||||||
@ -556,7 +556,7 @@ void LinearWorld::getKartsDisplayInfo(
|
|||||||
for(unsigned int i = 0; i < kart_amount ; i++)
|
for(unsigned int i = 0; i < kart_amount ; i++)
|
||||||
{
|
{
|
||||||
RaceGUIBase::KartIconDisplayInfo& rank_info = (*info)[i];
|
RaceGUIBase::KartIconDisplayInfo& rank_info = (*info)[i];
|
||||||
AbstractKart* kart = m_karts[i];
|
AbstractKart* kart = m_karts[i].get();
|
||||||
|
|
||||||
// reset color
|
// reset color
|
||||||
rank_info.m_color = video::SColor(255, 255, 255, 255);
|
rank_info.m_color = video::SColor(255, 255, 255, 255);
|
||||||
@ -585,7 +585,7 @@ void LinearWorld::getKartsDisplayInfo(
|
|||||||
{
|
{
|
||||||
RaceGUIBase::KartIconDisplayInfo& rank_info = (*info)[i];
|
RaceGUIBase::KartIconDisplayInfo& rank_info = (*info)[i];
|
||||||
KartInfo& kart_info = m_kart_info[i];
|
KartInfo& kart_info = m_kart_info[i];
|
||||||
AbstractKart* kart = m_karts[i];
|
AbstractKart* kart = m_karts[i].get();
|
||||||
|
|
||||||
const int position = kart->getPosition();
|
const int position = kart->getPosition();
|
||||||
|
|
||||||
@ -799,7 +799,7 @@ void LinearWorld::updateRacePosition()
|
|||||||
// so that debug output is still correct!!!!!!!!!!!
|
// so that debug output is still correct!!!!!!!!!!!
|
||||||
for (unsigned int i=0; i<kart_amount; i++)
|
for (unsigned int i=0; i<kart_amount; i++)
|
||||||
{
|
{
|
||||||
AbstractKart* kart = m_karts[i];
|
AbstractKart* kart = m_karts[i].get();
|
||||||
// Karts that are either eliminated or have finished the
|
// Karts that are either eliminated or have finished the
|
||||||
// race already have their (final) position assigned. If
|
// race already have their (final) position assigned. If
|
||||||
// these karts would get their rank updated, it could happen
|
// these karts would get their rank updated, it could happen
|
||||||
@ -898,7 +898,7 @@ void LinearWorld::updateRacePosition()
|
|||||||
Log::debug("[LinearWorld]", "Counting laps at %u seconds.", getTime());
|
Log::debug("[LinearWorld]", "Counting laps at %u seconds.", getTime());
|
||||||
for (unsigned int i=0; i<kart_amount; i++)
|
for (unsigned int i=0; i<kart_amount; i++)
|
||||||
{
|
{
|
||||||
AbstractKart* kart = m_karts[i];
|
AbstractKart* kart = m_karts[i].get();
|
||||||
Log::debug("[LinearWorld]", "counting karts ahead of %s (laps %u,"
|
Log::debug("[LinearWorld]", "counting karts ahead of %s (laps %u,"
|
||||||
" progress %u, finished %d, eliminated %d, initial position %u.",
|
" progress %u, finished %d, eliminated %d, initial position %u.",
|
||||||
kart->getIdent().c_str(),
|
kart->getIdent().c_str(),
|
||||||
@ -973,7 +973,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
|
|||||||
|
|
||||||
KartInfo &ki = m_kart_info[i];
|
KartInfo &ki = m_kart_info[i];
|
||||||
|
|
||||||
const AbstractKart *kart=m_karts[i];
|
const AbstractKart *kart=m_karts[i].get();
|
||||||
// If the kart can go in more than one directions from the current track
|
// If the kart can go in more than one directions from the current track
|
||||||
// don't do any reverse message handling, since it is likely that there
|
// don't do any reverse message handling, since it is likely that there
|
||||||
// will be one direction in which it isn't going backwards anyway.
|
// will be one direction in which it isn't going backwards anyway.
|
||||||
|
@ -103,19 +103,18 @@ void ProfileWorld::setProfileModeLaps(int laps)
|
|||||||
* this player globally (i.e. including network players).
|
* this player globally (i.e. including network players).
|
||||||
* \param init_pos The start XYZ coordinates.
|
* \param init_pos The start XYZ coordinates.
|
||||||
*/
|
*/
|
||||||
AbstractKart *ProfileWorld::createKart(const std::string &kart_ident, int index,
|
std::shared_ptr<AbstractKart> ProfileWorld::createKart
|
||||||
int local_player_id, int global_player_id,
|
(const std::string &kart_ident, int index, int local_player_id,
|
||||||
RaceManager::KartType type,
|
int global_player_id, RaceManager::KartType kart_type,
|
||||||
PerPlayerDifficulty difficulty)
|
PerPlayerDifficulty difficulty)
|
||||||
{
|
{
|
||||||
btTransform init_pos = getStartTransform(index);
|
btTransform init_pos = getStartTransform(index);
|
||||||
|
|
||||||
Kart *new_kart = new KartWithStats(kart_ident,
|
std::shared_ptr<KartWithStats> new_kart =
|
||||||
/*world kart id*/ index,
|
std::make_shared<KartWithStats>(kart_ident, /*world kart id*/ index,
|
||||||
/*position*/ index+1,
|
/*position*/ index + 1, init_pos, difficulty);
|
||||||
init_pos, difficulty);
|
|
||||||
new_kart->init(RaceManager::KT_AI);
|
new_kart->init(RaceManager::KT_AI);
|
||||||
Controller *controller = loadAIController(new_kart);
|
Controller *controller = loadAIController(new_kart.get());
|
||||||
new_kart->setController(controller);
|
new_kart->setController(controller);
|
||||||
|
|
||||||
// Create a camera for the last kart (since this way more of the
|
// Create a camera for the last kart (since this way more of the
|
||||||
@ -123,7 +122,7 @@ AbstractKart *ProfileWorld::createKart(const std::string &kart_ident, int index,
|
|||||||
if (index == (int)race_manager->getNumberOfKarts()-1)
|
if (index == (int)race_manager->getNumberOfKarts()-1)
|
||||||
{
|
{
|
||||||
// The camera keeps track of all cameras and will free them
|
// The camera keeps track of all cameras and will free them
|
||||||
Camera::createCamera(new_kart, local_player_id);
|
Camera::createCamera(new_kart.get(), local_player_id);
|
||||||
}
|
}
|
||||||
return new_kart;
|
return new_kart;
|
||||||
} // createKart
|
} // createKart
|
||||||
@ -197,7 +196,7 @@ void ProfileWorld::enterRaceOverState()
|
|||||||
// ---------- update rank ------
|
// ---------- update rank ------
|
||||||
if (m_karts[i]->hasFinishedRace() || m_karts[i]->isEliminated())
|
if (m_karts[i]->hasFinishedRace() || m_karts[i]->isEliminated())
|
||||||
continue;
|
continue;
|
||||||
m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i]));
|
m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i].get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print framerate statistics
|
// Print framerate statistics
|
||||||
@ -229,9 +228,9 @@ void ProfileWorld::enterRaceOverState()
|
|||||||
|
|
||||||
std::set<std::string> all_groups;
|
std::set<std::string> all_groups;
|
||||||
|
|
||||||
for ( KartList::size_type i = 0; i < m_karts.size(); ++i)
|
for (KartList::size_type i = 0; i < m_karts.size(); ++i)
|
||||||
{
|
{
|
||||||
KartWithStats* kart = dynamic_cast<KartWithStats*>(m_karts[i]);
|
auto kart = std::dynamic_pointer_cast<KartWithStats>(m_karts[i]);
|
||||||
|
|
||||||
max_t = std::max(max_t, kart->getFinishTime());
|
max_t = std::max(max_t, kart->getFinishTime());
|
||||||
min_t = std::min(min_t, kart->getFinishTime());
|
min_t = std::min(min_t, kart->getFinishTime());
|
||||||
@ -285,7 +284,7 @@ void ProfileWorld::enterRaceOverState()
|
|||||||
float av_time = 0.0f, energy = 0;
|
float av_time = 0.0f, energy = 0;
|
||||||
for ( unsigned int i = 0; i < (unsigned int)m_karts.size(); ++i)
|
for ( unsigned int i = 0; i < (unsigned int)m_karts.size(); ++i)
|
||||||
{
|
{
|
||||||
KartWithStats* kart = dynamic_cast<KartWithStats*>(m_karts[i]);
|
auto kart = std::dynamic_pointer_cast<KartWithStats>(m_karts[i]);
|
||||||
const std::string &name=kart->getController()->getControllerName();
|
const std::string &name=kart->getController()->getControllerName();
|
||||||
if(name!=*it)
|
if(name!=*it)
|
||||||
continue;
|
continue;
|
||||||
|
@ -72,10 +72,10 @@ protected:
|
|||||||
* used by DemoWorld. */
|
* used by DemoWorld. */
|
||||||
static int m_num_laps;
|
static int m_num_laps;
|
||||||
|
|
||||||
virtual AbstractKart *createKart(const std::string &kart_ident, int index,
|
virtual std::shared_ptr<AbstractKart> createKart
|
||||||
int local_player_id, int global_player_id,
|
(const std::string &kart_ident, int index, int local_player_id,
|
||||||
RaceManager::KartType type,
|
int global_player_id, RaceManager::KartType type,
|
||||||
PerPlayerDifficulty difficulty);
|
PerPlayerDifficulty difficulty);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProfileWorld();
|
ProfileWorld();
|
||||||
|
@ -228,7 +228,7 @@ void SoccerWorld::update(int ticks)
|
|||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < m_karts.size(); i++)
|
for (unsigned int i = 0; i < m_karts.size(); i++)
|
||||||
{
|
{
|
||||||
AbstractKart* kart = m_karts[i];
|
auto& kart = m_karts[i];
|
||||||
if (kart->isEliminated())
|
if (kart->isEliminated())
|
||||||
continue;
|
continue;
|
||||||
kart->getBody()->setLinearVelocity(Vec3(0.0f));
|
kart->getBody()->setLinearVelocity(Vec3(0.0f));
|
||||||
@ -335,7 +335,7 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal)
|
|||||||
}
|
}
|
||||||
for (unsigned i = 0; i < m_karts.size(); i++)
|
for (unsigned i = 0; i < m_karts.size(); i++)
|
||||||
{
|
{
|
||||||
AbstractKart* kart = m_karts[i];
|
auto& kart = m_karts[i];
|
||||||
if (kart->isEliminated())
|
if (kart->isEliminated())
|
||||||
continue;
|
continue;
|
||||||
kart->getBody()->setLinearVelocity(Vec3(0.0f));
|
kart->getBody()->setLinearVelocity(Vec3(0.0f));
|
||||||
@ -406,7 +406,7 @@ void SoccerWorld::handlePlayerGoalFromServer(const NetworkString& ns)
|
|||||||
m_ball->setEnabled(false);
|
m_ball->setEnabled(false);
|
||||||
for (unsigned i = 0; i < m_karts.size(); i++)
|
for (unsigned i = 0; i < m_karts.size(); i++)
|
||||||
{
|
{
|
||||||
AbstractKart* kart = m_karts[i];
|
auto& kart = m_karts[i];
|
||||||
if (kart->isEliminated())
|
if (kart->isEliminated())
|
||||||
continue;
|
continue;
|
||||||
btTransform transform_now = kart->getBody()->getWorldTransform();
|
btTransform transform_now = kart->getBody()->getWorldTransform();
|
||||||
@ -431,7 +431,7 @@ void SoccerWorld::resetKartsToSelfGoals()
|
|||||||
setPhase(WorldStatus::RACE_PHASE);
|
setPhase(WorldStatus::RACE_PHASE);
|
||||||
for (unsigned i = 0; i < m_karts.size(); i++)
|
for (unsigned i = 0; i < m_karts.size(); i++)
|
||||||
{
|
{
|
||||||
AbstractKart* kart = m_karts[i];
|
auto& kart = m_karts[i];
|
||||||
if (kart->isEliminated())
|
if (kart->isEliminated())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ void SoccerWorld::resetKartsToSelfGoals()
|
|||||||
kart->getBody()->setAngularVelocity(Vec3(0.0f));
|
kart->getBody()->setAngularVelocity(Vec3(0.0f));
|
||||||
unsigned index = m_kart_position_map.at(kart->getWorldKartId());
|
unsigned index = m_kart_position_map.at(kart->getWorldKartId());
|
||||||
btTransform t = Track::getCurrentTrack()->getStartTransform(index);
|
btTransform t = Track::getCurrentTrack()->getStartTransform(index);
|
||||||
moveKartTo(kart, t);
|
moveKartTo(kart.get(), t);
|
||||||
}
|
}
|
||||||
} // resetKartsToSelfGoals
|
} // resetKartsToSelfGoals
|
||||||
|
|
||||||
@ -532,10 +532,10 @@ bool SoccerWorld::getKartSoccerResult(unsigned int kart_id) const
|
|||||||
} // getKartSoccerResult
|
} // getKartSoccerResult
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
|
std::shared_ptr<AbstractKart> SoccerWorld::createKart
|
||||||
int local_player_id, int global_player_id,
|
(const std::string &kart_ident, int index, int local_player_id,
|
||||||
RaceManager::KartType kart_type,
|
int global_player_id, RaceManager::KartType kart_type,
|
||||||
PerPlayerDifficulty difficulty)
|
PerPlayerDifficulty difficulty)
|
||||||
{
|
{
|
||||||
int cur_red = getTeamNum(SOCCER_TEAM_RED);
|
int cur_red = getTeamNum(SOCCER_TEAM_RED);
|
||||||
int cur_blue = getTeamNum(SOCCER_TEAM_BLUE);
|
int cur_blue = getTeamNum(SOCCER_TEAM_BLUE);
|
||||||
@ -590,16 +590,19 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
|
|||||||
std::shared_ptr<RenderInfo> ri = std::make_shared<RenderInfo>();
|
std::shared_ptr<RenderInfo> ri = std::make_shared<RenderInfo>();
|
||||||
ri = (team == SOCCER_TEAM_BLUE ? std::make_shared<RenderInfo>(0.66f) :
|
ri = (team == SOCCER_TEAM_BLUE ? std::make_shared<RenderInfo>(0.66f) :
|
||||||
std::make_shared<RenderInfo>(1.0f));
|
std::make_shared<RenderInfo>(1.0f));
|
||||||
AbstractKart* new_kart;
|
|
||||||
|
std::shared_ptr<AbstractKart> new_kart;
|
||||||
if (RewindManager::get()->isEnabled())
|
if (RewindManager::get()->isEnabled())
|
||||||
{
|
{
|
||||||
new_kart = new KartRewinder(kart_ident, index, position, init_pos,
|
auto kr = std::make_shared<KartRewinder>(kart_ident, index, position,
|
||||||
difficulty, ri);
|
init_pos, difficulty, ri);
|
||||||
|
kr->rewinderAdd();
|
||||||
|
new_kart = kr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new_kart = new Kart(kart_ident, index, position, init_pos, difficulty,
|
new_kart = std::make_shared<Kart>(kart_ident, index, position,
|
||||||
ri);
|
init_pos, difficulty, ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_kart->init(race_manager->getKartType(index));
|
new_kart->init(race_manager->getKartType(index));
|
||||||
@ -608,18 +611,18 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
|
|||||||
switch(kart_type)
|
switch(kart_type)
|
||||||
{
|
{
|
||||||
case RaceManager::KT_PLAYER:
|
case RaceManager::KT_PLAYER:
|
||||||
controller = new LocalPlayerController(new_kart, local_player_id,
|
controller = new LocalPlayerController(new_kart.get(), local_player_id,
|
||||||
difficulty);
|
difficulty);
|
||||||
m_num_players ++;
|
m_num_players ++;
|
||||||
break;
|
break;
|
||||||
case RaceManager::KT_NETWORK_PLAYER:
|
case RaceManager::KT_NETWORK_PLAYER:
|
||||||
controller = new NetworkPlayerController(new_kart);
|
controller = new NetworkPlayerController(new_kart.get());
|
||||||
if (!online_name.empty())
|
if (!online_name.empty())
|
||||||
new_kart->setOnScreenText(online_name.c_str());
|
new_kart->setOnScreenText(online_name.c_str());
|
||||||
m_num_players++;
|
m_num_players++;
|
||||||
break;
|
break;
|
||||||
case RaceManager::KT_AI:
|
case RaceManager::KT_AI:
|
||||||
controller = loadAIController(new_kart);
|
controller = loadAIController(new_kart.get());
|
||||||
break;
|
break;
|
||||||
case RaceManager::KT_GHOST:
|
case RaceManager::KT_GHOST:
|
||||||
break;
|
break;
|
||||||
|
@ -51,10 +51,10 @@ public:
|
|||||||
}; // ScorerData
|
}; // ScorerData
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual AbstractKart *createKart(const std::string &kart_ident, int index,
|
virtual std::shared_ptr<AbstractKart> createKart
|
||||||
int local_player_id, int global_player_id,
|
(const std::string &kart_ident, int index, int local_player_id,
|
||||||
RaceManager::KartType type,
|
int global_player_id, RaceManager::KartType type,
|
||||||
PerPlayerDifficulty difficulty) OVERRIDE;
|
PerPlayerDifficulty difficulty) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class KartDistanceMap
|
class KartDistanceMap
|
||||||
|
@ -103,7 +103,7 @@ void StandardRace::endRaceEarly()
|
|||||||
for (unsigned int i = 1; i <= kart_amount; i++)
|
for (unsigned int i = 1; i <= kart_amount; i++)
|
||||||
{
|
{
|
||||||
int kartid = m_position_index[i-1];
|
int kartid = m_position_index[i-1];
|
||||||
AbstractKart* kart = m_karts[kartid];
|
AbstractKart* kart = m_karts[kartid].get();
|
||||||
|
|
||||||
if (kart->hasFinishedRace())
|
if (kart->hasFinishedRace())
|
||||||
{
|
{
|
||||||
@ -140,7 +140,7 @@ void StandardRace::endRaceEarly()
|
|||||||
int kartid = active_players[i];
|
int kartid = active_players[i];
|
||||||
int position = getNumKarts() - (int) active_players.size() + 1 + i;
|
int position = getNumKarts() - (int) active_players.size() + 1 + i;
|
||||||
setKartPosition(kartid, position);
|
setKartPosition(kartid, position);
|
||||||
float punished_time = estimateFinishTimeForKart(m_karts[kartid])
|
float punished_time = estimateFinishTimeForKart(m_karts[kartid].get())
|
||||||
+ worse_finish_time - WorldStatus::getTime();
|
+ worse_finish_time - WorldStatus::getTime();
|
||||||
m_karts[kartid]->finishedRace(punished_time);
|
m_karts[kartid]->finishedRace(punished_time);
|
||||||
|
|
||||||
|
@ -722,18 +722,18 @@ void ThreeStrikesBattle::loadCustomModels()
|
|||||||
// Now add them
|
// Now add them
|
||||||
for (unsigned int i = 0; i < pos.size(); i++)
|
for (unsigned int i = 0; i < pos.size(); i++)
|
||||||
{
|
{
|
||||||
AbstractKart* sta = new Kart(sta_list[i], (int)m_karts.size(),
|
auto sta = std::make_shared<Kart>(sta_list[i], (int)m_karts.size(),
|
||||||
(int)m_karts.size() + 1, pos[i], PLAYER_DIFFICULTY_NORMAL,
|
(int)m_karts.size() + 1, pos[i], PLAYER_DIFFICULTY_NORMAL,
|
||||||
std::make_shared<RenderInfo>(1.0f));
|
std::make_shared<RenderInfo>(1.0f));
|
||||||
sta->init(RaceManager::KartType::KT_SPARE_TIRE);
|
sta->init(RaceManager::KartType::KT_SPARE_TIRE);
|
||||||
sta->setController(new SpareTireAI(sta));
|
sta->setController(new SpareTireAI(sta.get()));
|
||||||
|
|
||||||
m_karts.push_back(sta);
|
m_karts.push_back(sta);
|
||||||
race_manager->addSpareTireKart(sta_list[i]);
|
race_manager->addSpareTireKart(sta_list[i]);
|
||||||
|
|
||||||
// Copy STA pointer to m_spare_tire_karts array, allowing them
|
// Copy STA pointer to m_spare_tire_karts array, allowing them
|
||||||
// to respawn easily
|
// to respawn easily
|
||||||
m_spare_tire_karts.push_back(sta);
|
m_spare_tire_karts.push_back(sta.get());
|
||||||
}
|
}
|
||||||
unsigned int sta_num = race_manager->getNumSpareTireKarts();
|
unsigned int sta_num = race_manager->getNumSpareTireKarts();
|
||||||
assert(m_spare_tire_karts.size() == sta_num);
|
assert(m_spare_tire_karts.size() == sta_num);
|
||||||
|
@ -212,10 +212,9 @@ void World::init()
|
|||||||
: race_manager->getKartIdent(i);
|
: race_manager->getKartIdent(i);
|
||||||
int local_player_id = race_manager->getKartLocalPlayerId(i);
|
int local_player_id = race_manager->getKartLocalPlayerId(i);
|
||||||
int global_player_id = race_manager->getKartGlobalPlayerId(i);
|
int global_player_id = race_manager->getKartGlobalPlayerId(i);
|
||||||
AbstractKart* newkart = createKart(kart_ident, i, local_player_id,
|
auto newkart = createKart(kart_ident, i, local_player_id,
|
||||||
global_player_id,
|
global_player_id, race_manager->getKartType(i),
|
||||||
race_manager->getKartType(i),
|
race_manager->getPlayerDifficulty(i));
|
||||||
race_manager->getPlayerDifficulty(i));
|
|
||||||
m_karts.push_back(newkart);
|
m_karts.push_back(newkart);
|
||||||
|
|
||||||
} // for i
|
} // for i
|
||||||
@ -334,10 +333,10 @@ void World::createRaceGUI()
|
|||||||
* \param global_player_id If the kart is a player kart this is the index of
|
* \param global_player_id If the kart is a player kart this is the index of
|
||||||
* this player globally (i.e. including network players).
|
* this player globally (i.e. including network players).
|
||||||
*/
|
*/
|
||||||
AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
std::shared_ptr<AbstractKart> World::createKart
|
||||||
int local_player_id, int global_player_id,
|
(const std::string &kart_ident, int index, int local_player_id,
|
||||||
RaceManager::KartType kart_type,
|
int global_player_id, RaceManager::KartType kart_type,
|
||||||
PerPlayerDifficulty difficulty)
|
PerPlayerDifficulty difficulty)
|
||||||
{
|
{
|
||||||
unsigned int gk = 0;
|
unsigned int gk = 0;
|
||||||
if (race_manager->hasGhostKarts())
|
if (race_manager->hasGhostKarts())
|
||||||
@ -355,13 +354,19 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
|||||||
|
|
||||||
int position = index+1;
|
int position = index+1;
|
||||||
btTransform init_pos = getStartTransform(index - gk);
|
btTransform init_pos = getStartTransform(index - gk);
|
||||||
AbstractKart *new_kart;
|
std::shared_ptr<AbstractKart> new_kart;
|
||||||
if (RewindManager::get()->isEnabled())
|
if (RewindManager::get()->isEnabled())
|
||||||
new_kart = new KartRewinder(kart_ident, index, position, init_pos,
|
{
|
||||||
difficulty, ri);
|
auto kr = std::make_shared<KartRewinder>(kart_ident, index, position,
|
||||||
|
init_pos, difficulty, ri);
|
||||||
|
kr->rewinderAdd();
|
||||||
|
new_kart = kr;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
new_kart = new Kart(kart_ident, index, position, init_pos, difficulty,
|
{
|
||||||
ri);
|
new_kart = std::make_shared<Kart>(kart_ident, index, position,
|
||||||
|
init_pos, difficulty, ri);
|
||||||
|
}
|
||||||
|
|
||||||
new_kart->init(race_manager->getKartType(index));
|
new_kart->init(race_manager->getKartType(index));
|
||||||
Controller *controller = NULL;
|
Controller *controller = NULL;
|
||||||
@ -369,7 +374,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
|||||||
{
|
{
|
||||||
case RaceManager::KT_PLAYER:
|
case RaceManager::KT_PLAYER:
|
||||||
{
|
{
|
||||||
controller = new LocalPlayerController(new_kart, local_player_id,
|
controller = new LocalPlayerController(new_kart.get(), local_player_id,
|
||||||
difficulty);
|
difficulty);
|
||||||
const PlayerProfile* p = StateManager::get()
|
const PlayerProfile* p = StateManager::get()
|
||||||
->getActivePlayer(local_player_id)->getConstProfile();
|
->getActivePlayer(local_player_id)->getConstProfile();
|
||||||
@ -383,7 +388,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
|||||||
}
|
}
|
||||||
case RaceManager::KT_NETWORK_PLAYER:
|
case RaceManager::KT_NETWORK_PLAYER:
|
||||||
{
|
{
|
||||||
controller = new NetworkPlayerController(new_kart);
|
controller = new NetworkPlayerController(new_kart.get());
|
||||||
if (!online_name.empty())
|
if (!online_name.empty())
|
||||||
new_kart->setOnScreenText(online_name.c_str());
|
new_kart->setOnScreenText(online_name.c_str());
|
||||||
m_num_players++;
|
m_num_players++;
|
||||||
@ -391,7 +396,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
|||||||
}
|
}
|
||||||
case RaceManager::KT_AI:
|
case RaceManager::KT_AI:
|
||||||
{
|
{
|
||||||
controller = loadAIController(new_kart);
|
controller = loadAIController(new_kart.get());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RaceManager::KT_GHOST:
|
case RaceManager::KT_GHOST:
|
||||||
@ -417,7 +422,7 @@ const btTransform &World::getStartTransform(int index)
|
|||||||
/** Creates an AI controller for the kart.
|
/** Creates an AI controller for the kart.
|
||||||
* \param kart The kart to be controlled by an AI.
|
* \param kart The kart to be controlled by an AI.
|
||||||
*/
|
*/
|
||||||
Controller* World::loadAIController(AbstractKart *kart)
|
Controller* World::loadAIController(AbstractKart* kart)
|
||||||
{
|
{
|
||||||
Controller *controller;
|
Controller *controller;
|
||||||
int turn=0;
|
int turn=0;
|
||||||
@ -485,13 +490,7 @@ World::~World()
|
|||||||
|
|
||||||
Weather::kill();
|
Weather::kill();
|
||||||
|
|
||||||
for ( unsigned int i = 0 ; i < m_karts.size() ; i++ )
|
m_karts.clear();
|
||||||
{
|
|
||||||
// Let ReplayPlay destroy the ghost karts
|
|
||||||
if (m_karts[i]->isGhostKart()) continue;
|
|
||||||
delete m_karts[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(race_manager->hasGhostKarts() || race_manager->isRecordingRace())
|
if(race_manager->hasGhostKarts() || race_manager->isRecordingRace())
|
||||||
{
|
{
|
||||||
// Destroy the old replay object, which also stored the ghost
|
// Destroy the old replay object, which also stored the ghost
|
||||||
@ -502,7 +501,6 @@ World::~World()
|
|||||||
ReplayPlay::destroy();
|
ReplayPlay::destroy();
|
||||||
ReplayPlay::create();
|
ReplayPlay::create();
|
||||||
}
|
}
|
||||||
m_karts.clear();
|
|
||||||
if(race_manager->isRecordingRace())
|
if(race_manager->isRecordingRace())
|
||||||
ReplayRecorder::get()->reset();
|
ReplayRecorder::get()->reset();
|
||||||
race_manager->setRaceGhostKarts(false);
|
race_manager->setRaceGhostKarts(false);
|
||||||
@ -567,7 +565,8 @@ void World::terminateRace()
|
|||||||
{
|
{
|
||||||
if(!m_karts[i]->hasFinishedRace() && !m_karts[i]->isEliminated())
|
if(!m_karts[i]->hasFinishedRace() && !m_karts[i]->isEliminated())
|
||||||
{
|
{
|
||||||
m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i]));
|
m_karts[i]->finishedRace(
|
||||||
|
estimateFinishTimeForKart(m_karts[i].get()));
|
||||||
|
|
||||||
}
|
}
|
||||||
} // i<kart_amount
|
} // i<kart_amount
|
||||||
@ -699,7 +698,7 @@ void World::resetAllKarts()
|
|||||||
btTransform t = getRescueTransform(rescue_pos);
|
btTransform t = getRescueTransform(rescue_pos);
|
||||||
// This will print out warnings if there is no terrain under
|
// This will print out warnings if there is no terrain under
|
||||||
// the kart, or the kart is being dropped on a reset texture
|
// the kart, or the kart is being dropped on a reset texture
|
||||||
moveKartTo(m_karts[kart_id], t);
|
moveKartTo(m_karts[kart_id].get(), t);
|
||||||
|
|
||||||
} // rescue_pos<getNumberOfRescuePositions
|
} // rescue_pos<getNumberOfRescuePositions
|
||||||
|
|
||||||
@ -725,7 +724,7 @@ void World::resetAllKarts()
|
|||||||
Vec3 up_offset = (*i)->getNormal() * (0.5f * ((*i)->getKartHeight()));
|
Vec3 up_offset = (*i)->getNormal() * (0.5f * ((*i)->getKartHeight()));
|
||||||
(*i)->setXYZ(xyz+up_offset);
|
(*i)->setXYZ(xyz+up_offset);
|
||||||
|
|
||||||
bool kart_over_ground = Track::getCurrentTrack()->findGround(*i);
|
bool kart_over_ground = Track::getCurrentTrack()->findGround(i->get());
|
||||||
|
|
||||||
if (!kart_over_ground)
|
if (!kart_over_ground)
|
||||||
{
|
{
|
||||||
@ -1165,7 +1164,7 @@ void World::updateHighscores(int* best_highscore_rank)
|
|||||||
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
|
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
|
||||||
|
|
||||||
assert(index[pos] < m_karts.size());
|
assert(index[pos] < m_karts.size());
|
||||||
Kart *k = (Kart*)m_karts[index[pos]];
|
Kart *k = (Kart*)m_karts[index[pos]].get();
|
||||||
|
|
||||||
Highscores* highscores = getHighscores();
|
Highscores* highscores = getHighscores();
|
||||||
|
|
||||||
@ -1197,14 +1196,17 @@ void World::updateHighscores(int* best_highscore_rank)
|
|||||||
*/
|
*/
|
||||||
AbstractKart *World::getPlayerKart(unsigned int n) const
|
AbstractKart *World::getPlayerKart(unsigned int n) const
|
||||||
{
|
{
|
||||||
unsigned int count=-1;
|
unsigned int count = -1;
|
||||||
|
|
||||||
for(unsigned int i=0; i<m_karts.size(); i++)
|
for(unsigned int i = 0; i < m_karts.size(); i++)
|
||||||
if(m_karts[i]->getController()->isPlayerController())
|
{
|
||||||
|
if (m_karts[i]->getController()->isPlayerController())
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
if(count==n) return m_karts[i];
|
if (count == n)
|
||||||
|
return m_karts[i].get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
} // getPlayerKart
|
} // getPlayerKart
|
||||||
|
|
||||||
@ -1225,7 +1227,7 @@ AbstractKart *World::getLocalPlayerKart(unsigned int n) const
|
|||||||
void World::eliminateKart(int kart_id, bool notify_of_elimination)
|
void World::eliminateKart(int kart_id, bool notify_of_elimination)
|
||||||
{
|
{
|
||||||
assert(kart_id < (int)m_karts.size());
|
assert(kart_id < (int)m_karts.size());
|
||||||
AbstractKart *kart = m_karts[kart_id];
|
AbstractKart *kart = m_karts[kart_id].get();
|
||||||
if (kart->isGhostKart()) return;
|
if (kart->isGhostKart()) return;
|
||||||
|
|
||||||
// Display a message about the eliminated kart in the race guia
|
// Display a message about the eliminated kart in the race guia
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
* battle, etc.)
|
* battle, etc.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ public:
|
|||||||
class World : public WorldStatus
|
class World : public WorldStatus
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::vector<AbstractKart*> KartList;
|
typedef std::vector<std::shared_ptr<AbstractKart> > KartList;
|
||||||
private:
|
private:
|
||||||
/** A pointer to the global world object for a race. */
|
/** A pointer to the global world object for a race. */
|
||||||
static World *m_world;
|
static World *m_world;
|
||||||
@ -117,10 +118,10 @@ protected:
|
|||||||
Controller*
|
Controller*
|
||||||
loadAIController (AbstractKart *kart);
|
loadAIController (AbstractKart *kart);
|
||||||
|
|
||||||
virtual AbstractKart *createKart(const std::string &kart_ident, int index,
|
virtual std::shared_ptr<AbstractKart> createKart
|
||||||
int local_player_id, int global_player_id,
|
(const std::string &kart_ident, int index, int local_player_id,
|
||||||
RaceManager::KartType type,
|
int global_player_id, RaceManager::KartType type,
|
||||||
PerPlayerDifficulty difficulty);
|
PerPlayerDifficulty difficulty);
|
||||||
|
|
||||||
/** Pointer to the race GUI. The race GUI is handled by world. */
|
/** Pointer to the race GUI. The race GUI is handled by world. */
|
||||||
RaceGUIBase *m_race_gui;
|
RaceGUIBase *m_race_gui;
|
||||||
@ -293,7 +294,7 @@ public:
|
|||||||
/** Returns the kart with a given world id. */
|
/** Returns the kart with a given world id. */
|
||||||
AbstractKart *getKart(int kartId) const {
|
AbstractKart *getKart(int kartId) const {
|
||||||
assert(kartId >= 0 && kartId < int(m_karts.size()));
|
assert(kartId >= 0 && kartId < int(m_karts.size()));
|
||||||
return m_karts[kartId]; }
|
return m_karts[kartId].get(); }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns all karts. */
|
/** Returns all karts. */
|
||||||
const KartList & getKarts() const { return m_karts; }
|
const KartList & getKarts() const { return m_karts; }
|
||||||
|
@ -82,7 +82,7 @@ AbstractKart* WorldWithRank::getKartAtPosition(unsigned int p) const
|
|||||||
if(p<1 || p>m_position_index.size())
|
if(p<1 || p>m_position_index.size())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return m_karts[m_position_index[p-1]];
|
return m_karts[m_position_index[p-1]].get();
|
||||||
} // getKartAtPosition
|
} // getKartAtPosition
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#include "network/rewind_info.hpp"
|
#include "network/rewind_info.hpp"
|
||||||
|
|
||||||
#include "network/network_config.hpp"
|
#include "network/network_config.hpp"
|
||||||
|
#include "network/rewinder.hpp"
|
||||||
#include "network/rewind_manager.hpp"
|
#include "network/rewind_manager.hpp"
|
||||||
#include "physics/physics.hpp"
|
|
||||||
|
|
||||||
/** Constructor for a state: it only takes the size, and allocates a buffer
|
/** Constructor for a state: it only takes the size, and allocates a buffer
|
||||||
* for all state info.
|
* for all state info.
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include "network/event_rewinder.hpp"
|
#include "network/event_rewinder.hpp"
|
||||||
#include "network/network_string.hpp"
|
#include "network/network_string.hpp"
|
||||||
#include "network/rewinder.hpp"
|
|
||||||
#include "utils/cpp2011.hpp"
|
#include "utils/cpp2011.hpp"
|
||||||
#include "utils/leak_check.hpp"
|
#include "utils/leak_check.hpp"
|
||||||
#include "utils/ptr_vector.hpp"
|
#include "utils/ptr_vector.hpp"
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
/** Add this object to the list of all rewindable
|
/** Add this object to the list of all rewindable
|
||||||
* objects in the rewind manager.
|
* objects in the rewind manager.
|
||||||
*/
|
*/
|
||||||
bool Rewinder::add()
|
bool Rewinder::rewinderAdd()
|
||||||
{
|
{
|
||||||
return RewindManager::get()->addRewinder(shared_from_this());
|
return RewindManager::get()->addRewinder(shared_from_this());
|
||||||
} // add
|
} // rewinderAdd
|
||||||
|
@ -91,7 +91,7 @@ public:
|
|||||||
return m_unique_identity;
|
return m_unique_identity;
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
bool add();
|
bool rewinderAdd();
|
||||||
|
|
||||||
}; // Rewinder
|
}; // Rewinder
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,8 +71,6 @@ void* btKartRaycaster::castRay(const btVector3& from, const btVector3& to,
|
|||||||
result.m_hitNormalInWorld.normalize();
|
result.m_hitNormalInWorld.normalize();
|
||||||
result.m_distFraction = rayCallback.m_closestHitFraction;
|
result.m_distFraction = rayCallback.m_closestHitFraction;
|
||||||
result.m_triangle_index = -1;
|
result.m_triangle_index = -1;
|
||||||
const TriangleMesh &tm =
|
|
||||||
Track::getCurrentTrack()->getTriangleMesh();
|
|
||||||
// FIXME: this code assumes atm that the object the kart is
|
// FIXME: this code assumes atm that the object the kart is
|
||||||
// driving on is the main track (and not e.g. a physical object).
|
// driving on is the main track (and not e.g. a physical object).
|
||||||
// If this should not be the case (i.e. the object hit by the
|
// If this should not be the case (i.e. the object hit by the
|
||||||
|
@ -123,12 +123,11 @@ void PhysicalObject::Settings::init()
|
|||||||
} // Settings
|
} // Settings
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
PhysicalObject* PhysicalObject::fromXML(bool is_dynamic,
|
std::shared_ptr<PhysicalObject> PhysicalObject::fromXML
|
||||||
const XMLNode &xml_node,
|
(bool is_dynamic, const XMLNode &xml_node, TrackObject* object)
|
||||||
TrackObject* object)
|
|
||||||
{
|
{
|
||||||
PhysicalObject::Settings settings(xml_node);
|
PhysicalObject::Settings settings(xml_node);
|
||||||
return new PhysicalObject(is_dynamic, settings, object);
|
return std::make_shared<PhysicalObject>(is_dynamic, settings, object);
|
||||||
} // fromXML
|
} // fromXML
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -792,7 +791,7 @@ void PhysicalObject::addForRewind()
|
|||||||
SmoothNetworkBody::setAdjustVerticalOffset(false);
|
SmoothNetworkBody::setAdjustVerticalOffset(false);
|
||||||
Rewinder::setUniqueIdentity(std::string("P") + StringUtils::toString
|
Rewinder::setUniqueIdentity(std::string("P") + StringUtils::toString
|
||||||
(Track::getCurrentTrack()->getPhysicalObjectUID()));
|
(Track::getCurrentTrack()->getPhysicalObjectUID()));
|
||||||
Rewinder::add();
|
Rewinder::rewinderAdd();
|
||||||
} // addForRewind
|
} // addForRewind
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -197,8 +197,8 @@ public:
|
|||||||
PhysicalObject(bool is_dynamic, const Settings& settings,
|
PhysicalObject(bool is_dynamic, const Settings& settings,
|
||||||
TrackObject* object);
|
TrackObject* object);
|
||||||
|
|
||||||
static PhysicalObject* fromXML(bool is_dynamic, const XMLNode &node,
|
static std::shared_ptr<PhysicalObject> fromXML
|
||||||
TrackObject* object);
|
(bool is_dynamic, const XMLNode &node, TrackObject* object);
|
||||||
|
|
||||||
virtual ~PhysicalObject ();
|
virtual ~PhysicalObject ();
|
||||||
virtual void reset ();
|
virtual void reset ();
|
||||||
|
@ -296,11 +296,13 @@ void History::Load()
|
|||||||
{
|
{
|
||||||
fgets(s, 1023, fd);
|
fgets(s, 1023, fd);
|
||||||
InputEvent &ie = m_all_input_events[i];
|
InputEvent &ie = m_all_input_events[i];
|
||||||
|
int action = 0;
|
||||||
if (sscanf(s, "%d %d %d %d\n", &ie.m_world_ticks, &ie.m_kart_index,
|
if (sscanf(s, "%d %d %d %d\n", &ie.m_world_ticks, &ie.m_kart_index,
|
||||||
&ie.m_action, &ie.m_value) != 4 )
|
&action, &ie.m_value) != 4)
|
||||||
{
|
{
|
||||||
Log::warn("History", "Problems reading event: '%s'", s);
|
Log::warn("History", "Problems reading event: '%s'", s);
|
||||||
}
|
}
|
||||||
|
ie.m_action = (PlayerAction)action;
|
||||||
} // for i
|
} // for i
|
||||||
RewindManager::setEnable(rewind_manager_was_enabled);
|
RewindManager::setEnable(rewind_manager_was_enabled);
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ void ReplayPlay::reset()
|
|||||||
{
|
{
|
||||||
for(unsigned int i=0; i<(unsigned int)m_ghost_karts.size(); i++)
|
for(unsigned int i=0; i<(unsigned int)m_ghost_karts.size(); i++)
|
||||||
{
|
{
|
||||||
m_ghost_karts[i].reset();
|
m_ghost_karts[i]->reset();
|
||||||
}
|
}
|
||||||
} // reset
|
} // reset
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay, int ca
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ReplayPlay::load()
|
void ReplayPlay::load()
|
||||||
{
|
{
|
||||||
m_ghost_karts.clearAndDeleteAll();
|
m_ghost_karts.clear();
|
||||||
|
|
||||||
if (m_second_replay_enabled)
|
if (m_second_replay_enabled)
|
||||||
loadFile(/* second replay */ true);
|
loadFile(/* second replay */ true);
|
||||||
@ -365,11 +365,11 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line, bool second_replay)
|
|||||||
first_loaded_f_num = m_replay_file_list.at(m_second_replay_file).m_kart_list.size();
|
first_loaded_f_num = m_replay_file_list.at(m_second_replay_file).m_kart_list.size();
|
||||||
|
|
||||||
ReplayData &rd = m_replay_file_list[replay_index];
|
ReplayData &rd = m_replay_file_list[replay_index];
|
||||||
m_ghost_karts.push_back(new GhostKart(rd.m_kart_list.at(kart_num-first_loaded_f_num),
|
m_ghost_karts.push_back(std::make_shared<GhostKart>
|
||||||
kart_num, kart_num + 1,
|
(rd.m_kart_list.at(kart_num-first_loaded_f_num), kart_num, kart_num + 1,
|
||||||
rd.m_kart_color.at(kart_num-first_loaded_f_num)));
|
rd.m_kart_color.at(kart_num-first_loaded_f_num)));
|
||||||
m_ghost_karts[kart_num].init(RaceManager::KT_GHOST);
|
m_ghost_karts[kart_num]->init(RaceManager::KT_GHOST);
|
||||||
Controller* controller = new GhostController(getGhostKart(kart_num),
|
Controller* controller = new GhostController(getGhostKart(kart_num).get(),
|
||||||
rd.m_name_list[kart_num-first_loaded_f_num]);
|
rd.m_name_list[kart_num-first_loaded_f_num]);
|
||||||
getGhostKart(kart_num)->setController(controller);
|
getGhostKart(kart_num)->setController(controller);
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line, bool second_replay)
|
|||||||
kre.m_skidding_effect = skidding;
|
kre.m_skidding_effect = skidding;
|
||||||
kre.m_red_skidding = red_skidding!=0;
|
kre.m_red_skidding = red_skidding!=0;
|
||||||
kre.m_jumping = jumping != 0;
|
kre.m_jumping = jumping != 0;
|
||||||
m_ghost_karts[kart_num].addReplayEvent(time,
|
m_ghost_karts[kart_num]->addReplayEvent(time,
|
||||||
btTransform(q, xyz), pi, bi, kre);
|
btTransform(q, xyz), pi, bi, kre);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -472,7 +472,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line, bool second_replay)
|
|||||||
kre.m_skidding_effect = skidding;
|
kre.m_skidding_effect = skidding;
|
||||||
kre.m_red_skidding = red_skidding!=0;
|
kre.m_red_skidding = red_skidding!=0;
|
||||||
kre.m_jumping = jumping != 0;
|
kre.m_jumping = jumping != 0;
|
||||||
m_ghost_karts[kart_num].addReplayEvent(time,
|
m_ghost_karts[kart_num]->addReplayEvent(time,
|
||||||
btTransform(q, xyz), pi, bi, kre);
|
btTransform(q, xyz), pi, bi, kre);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -20,10 +20,10 @@
|
|||||||
#define HEADER_REPLAY__PLAY_HPP
|
#define HEADER_REPLAY__PLAY_HPP
|
||||||
|
|
||||||
#include "replay/replay_base.hpp"
|
#include "replay/replay_base.hpp"
|
||||||
#include "utils/ptr_vector.hpp"
|
|
||||||
|
|
||||||
#include "irrString.h"
|
#include "irrString.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ private:
|
|||||||
std::vector<ReplayData> m_replay_file_list;
|
std::vector<ReplayData> m_replay_file_list;
|
||||||
|
|
||||||
/** All ghost karts. */
|
/** All ghost karts. */
|
||||||
PtrVector<GhostKart> m_ghost_karts;
|
std::vector<std::shared_ptr<GhostKart> > m_ghost_karts;
|
||||||
|
|
||||||
ReplayPlay();
|
ReplayPlay();
|
||||||
~ReplayPlay();
|
~ReplayPlay();
|
||||||
@ -162,7 +162,7 @@ public:
|
|||||||
const unsigned int getNumReplayFile() const
|
const unsigned int getNumReplayFile() const
|
||||||
{ return (unsigned int)m_replay_file_list.size(); }
|
{ return (unsigned int)m_replay_file_list.size(); }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
GhostKart* getGhostKart(int n) { return m_ghost_karts.get(n); }
|
std::shared_ptr<GhostKart> getGhostKart(int n) { return m_ghost_karts[n]; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
const unsigned int getNumGhostKart() const
|
const unsigned int getNumGhostKart() const
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,6 @@ TrackObject::TrackObject(const core::vector3df& xyz, const core::vector3df& hpr,
|
|||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
m_presentation = NULL;
|
m_presentation = NULL;
|
||||||
m_animator = NULL;
|
m_animator = NULL;
|
||||||
m_physical_object = NULL;
|
|
||||||
m_parent_library = NULL;
|
m_parent_library = NULL;
|
||||||
m_interaction = interaction;
|
m_interaction = interaction;
|
||||||
m_presentation = presentation;
|
m_presentation = presentation;
|
||||||
@ -86,9 +85,8 @@ TrackObject::TrackObject(const core::vector3df& xyz, const core::vector3df& hpr,
|
|||||||
if (m_interaction != "ghost" && m_interaction != "none" &&
|
if (m_interaction != "ghost" && m_interaction != "none" &&
|
||||||
physics_settings )
|
physics_settings )
|
||||||
{
|
{
|
||||||
m_physical_object = new PhysicalObject(is_dynamic,
|
m_physical_object = std::make_shared<PhysicalObject>
|
||||||
*physics_settings,
|
(is_dynamic, *physics_settings, this);
|
||||||
this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
@ -112,7 +110,6 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
|
|||||||
m_presentation = NULL;
|
m_presentation = NULL;
|
||||||
m_animator = NULL;
|
m_animator = NULL;
|
||||||
m_parent_library = parent_library;
|
m_parent_library = parent_library;
|
||||||
m_physical_object = NULL;
|
|
||||||
|
|
||||||
xml_node.get("id", &m_id );
|
xml_node.get("id", &m_id );
|
||||||
xml_node.get("model", &m_name );
|
xml_node.get("model", &m_name );
|
||||||
@ -455,7 +452,6 @@ TrackObject::~TrackObject()
|
|||||||
{
|
{
|
||||||
delete m_presentation;
|
delete m_presentation;
|
||||||
delete m_animator;
|
delete m_animator;
|
||||||
delete m_physical_object;
|
|
||||||
} // ~TrackObject
|
} // ~TrackObject
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -482,7 +478,7 @@ void TrackObject::setEnabled(bool enabled)
|
|||||||
|
|
||||||
if (getType() == "mesh")
|
if (getType() == "mesh")
|
||||||
{
|
{
|
||||||
if (m_physical_object != NULL)
|
if (m_physical_object)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
m_physical_object->addBody();
|
m_physical_object->addBody();
|
||||||
@ -508,7 +504,7 @@ void TrackObject::resetEnabled()
|
|||||||
|
|
||||||
if (getType() == "mesh")
|
if (getType() == "mesh")
|
||||||
{
|
{
|
||||||
if (m_physical_object != NULL)
|
if (m_physical_object)
|
||||||
{
|
{
|
||||||
if (m_initially_visible)
|
if (m_initially_visible)
|
||||||
m_physical_object->addBody();
|
m_physical_object->addBody();
|
||||||
@ -581,7 +577,7 @@ void TrackObject::move(const core::vector3df& xyz, const core::vector3df& hpr,
|
|||||||
if (m_presentation != NULL)
|
if (m_presentation != NULL)
|
||||||
m_presentation->move(xyz, hpr, scale, isAbsoluteCoord);
|
m_presentation->move(xyz, hpr, scale, isAbsoluteCoord);
|
||||||
|
|
||||||
if (update_rigid_body && m_physical_object != NULL)
|
if (update_rigid_body && m_physical_object)
|
||||||
{
|
{
|
||||||
movePhysicalBodyToGraphicalNode(xyz, hpr);
|
movePhysicalBodyToGraphicalNode(xyz, hpr);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ protected:
|
|||||||
/** True if a kart can drive on this object. This will */
|
/** True if a kart can drive on this object. This will */
|
||||||
bool m_is_driveable;
|
bool m_is_driveable;
|
||||||
|
|
||||||
PhysicalObject* m_physical_object;
|
std::shared_ptr<PhysicalObject> m_physical_object;
|
||||||
|
|
||||||
ThreeDAnimation* m_animator;
|
ThreeDAnimation* m_animator;
|
||||||
|
|
||||||
@ -164,9 +164,10 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool isSoccerBall() const { return m_soccer_ball; }
|
bool isSoccerBall() const { return m_soccer_ball; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
const PhysicalObject* getPhysicalObject() const { return m_physical_object; }
|
const PhysicalObject* getPhysicalObject() const
|
||||||
|
{ return m_physical_object.get(); }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
PhysicalObject* getPhysicalObject() { return m_physical_object; }
|
PhysicalObject* getPhysicalObject() { return m_physical_object.get(); }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
const core::vector3df getInitXYZ() const { return m_init_xyz; }
|
const core::vector3df getInitXYZ() const { return m_init_xyz; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -214,7 +215,7 @@ public:
|
|||||||
/** Get the physics representation of an object.
|
/** Get the physics representation of an object.
|
||||||
* On the script side, the returned object is of type : @ref Scripting_PhysicalObject
|
* On the script side, the returned object is of type : @ref Scripting_PhysicalObject
|
||||||
*/
|
*/
|
||||||
PhysicalObject* getPhysics() { return m_physical_object; }
|
PhysicalObject* getPhysics() { return m_physical_object.get(); }
|
||||||
/** Hide or show the object */
|
/** Hide or show the object */
|
||||||
void setEnabled(bool mode);
|
void setEnabled(bool mode);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user