Port rewinders to use shared_ptr

This commit is contained in:
Benau 2018-07-24 14:22:20 +08:00
parent bbf5c54f87
commit 60bfc1840b
28 changed files with 154 additions and 151 deletions

View File

@ -47,7 +47,7 @@ std::vector<scene::IMesh *> ItemManager::m_item_mesh;
std::vector<scene::IMesh *> ItemManager::m_item_lowres_mesh;
std::vector<video::SColorf> ItemManager::m_glow_color;
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;
//-----------------------------------------------------------------------------
@ -55,7 +55,8 @@ std::mt19937 ItemManager::m_random_engine;
void ItemManager::create()
{
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
//-----------------------------------------------------------------------------
@ -63,8 +64,7 @@ void ItemManager::create()
void ItemManager::destroy()
{
assert(m_item_manager);
delete m_item_manager;
m_item_manager = NULL;
m_item_manager = nullptr;
} // destroy
//-----------------------------------------------------------------------------

View File

@ -60,7 +60,7 @@ private:
static std::mt19937 m_random_engine;
protected:
/** The instance of ItemManager while a race is on. */
static ItemManager *m_item_manager;
static std::shared_ptr<ItemManager> m_item_manager;
public:
static void loadDefaultItemMeshes();
static void removeTextures();
@ -90,9 +90,10 @@ public:
// ------------------------------------------------------------------------
/** Return an instance of the item manager (it does not automatically
* create one, call create for that). */
static ItemManager *get() {
static ItemManager *get()
{
assert(m_item_manager);
return m_item_manager;
return m_item_manager.get();
} // get
// ========================================================================
@ -119,9 +120,9 @@ protected:
virtual unsigned int insertItem(Item *item);
void setSwitchItems(const std::vector<int> &switch_items);
ItemManager();
public:
virtual ~ItemManager();
public:
virtual Item* placeItem (ItemState::ItemType type, const Vec3& xyz,
const Vec3 &normal);
virtual Item* dropNewItem (ItemState::ItemType type,

View File

@ -31,10 +31,11 @@
void NetworkItemManager::create()
{
assert(!m_item_manager);
m_item_manager = new NetworkItemManager();
auto nim = std::shared_ptr<NetworkItemManager>(new NetworkItemManager());
nim->rewinderAdd();
m_item_manager = nim;
} // create
// ============================================================================
/** Creates a new instance of the item manager. This is done at startup
* of each race. */

View File

@ -61,10 +61,10 @@ private:
void forwardTime(int ticks);
NetworkItemManager();
virtual ~NetworkItemManager();
public:
static void create();
virtual ~NetworkItemManager();
void setSwitchItems(const std::vector<int> &switch_items);
void sendItemUpdate();

View File

@ -298,7 +298,7 @@ void PowerupManager::WeightsData::convertRankToSection(int rank, int *prev,
}
// 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;
*weight = 1.0f;
@ -600,9 +600,11 @@ void PowerupManager::unitTesting()
int num_weights = wd.m_summed_weights_for_rank[0].back();
for(int i=0; i<num_weights; i++)
{
#ifdef DEBUG
unsigned int n;
assert( powerup_manager->getRandomPowerup(1, &n, i)==POWERUP_BOWLING );
assert(n==3);
#endif
}
// Test 2: Test all possible random numbers for 5 karts and rank 5

View File

@ -139,7 +139,6 @@ public:
};
private:
const int RAND_CLASS_RANGE = 1000;
/** The icon for each powerup. */
Material* m_all_icons [POWERUP_MAX];

View File

@ -176,7 +176,7 @@ void LinearWorld::update(int ticks)
for(unsigned int n=0; n<kart_amount; 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
// rescued or eliminated
@ -218,7 +218,7 @@ void LinearWorld::update(int ticks)
// Update the estimated finish time.
// This is used by the AI
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,
// compute the live time difference
@ -328,7 +328,7 @@ void LinearWorld::updateLiveDifference()
void LinearWorld::newLap(unsigned int 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
PlayerProfile *p = PlayerManager::getCurrentPlayer();
@ -556,7 +556,7 @@ void LinearWorld::getKartsDisplayInfo(
for(unsigned int i = 0; i < kart_amount ; i++)
{
RaceGUIBase::KartIconDisplayInfo& rank_info = (*info)[i];
AbstractKart* kart = m_karts[i];
AbstractKart* kart = m_karts[i].get();
// reset color
rank_info.m_color = video::SColor(255, 255, 255, 255);
@ -585,7 +585,7 @@ void LinearWorld::getKartsDisplayInfo(
{
RaceGUIBase::KartIconDisplayInfo& rank_info = (*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();
@ -799,7 +799,7 @@ void LinearWorld::updateRacePosition()
// so that debug output is still correct!!!!!!!!!!!
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
// race already have their (final) position assigned. If
// 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());
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,"
" progress %u, finished %d, eliminated %d, initial position %u.",
kart->getIdent().c_str(),
@ -973,7 +973,7 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
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
// 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.

View File

@ -103,19 +103,18 @@ void ProfileWorld::setProfileModeLaps(int laps)
* this player globally (i.e. including network players).
* \param init_pos The start XYZ coordinates.
*/
AbstractKart *ProfileWorld::createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
RaceManager::KartType type,
std::shared_ptr<AbstractKart> ProfileWorld::createKart
(const std::string &kart_ident, int index, int local_player_id,
int global_player_id, RaceManager::KartType kart_type,
PerPlayerDifficulty difficulty)
{
btTransform init_pos = getStartTransform(index);
Kart *new_kart = new KartWithStats(kart_ident,
/*world kart id*/ index,
/*position*/ index+1,
init_pos, difficulty);
std::shared_ptr<KartWithStats> new_kart =
std::make_shared<KartWithStats>(kart_ident, /*world kart id*/ index,
/*position*/ index + 1, init_pos, difficulty);
new_kart->init(RaceManager::KT_AI);
Controller *controller = loadAIController(new_kart);
Controller *controller = loadAIController(new_kart.get());
new_kart->setController(controller);
// 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)
{
// 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;
} // createKart
@ -197,7 +196,7 @@ void ProfileWorld::enterRaceOverState()
// ---------- update rank ------
if (m_karts[i]->hasFinishedRace() || m_karts[i]->isEliminated())
continue;
m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i]));
m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i].get()));
}
// Print framerate statistics
@ -231,7 +230,7 @@ void ProfileWorld::enterRaceOverState()
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());
min_t = std::min(min_t, kart->getFinishTime());
@ -285,7 +284,7 @@ void ProfileWorld::enterRaceOverState()
float av_time = 0.0f, energy = 0;
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();
if(name!=*it)
continue;

View File

@ -72,9 +72,9 @@ protected:
* used by DemoWorld. */
static int m_num_laps;
virtual AbstractKart *createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
RaceManager::KartType type,
virtual std::shared_ptr<AbstractKart> createKart
(const std::string &kart_ident, int index, int local_player_id,
int global_player_id, RaceManager::KartType type,
PerPlayerDifficulty difficulty);
public:

View File

@ -228,7 +228,7 @@ void SoccerWorld::update(int ticks)
{
for (unsigned int i = 0; i < m_karts.size(); i++)
{
AbstractKart* kart = m_karts[i];
auto& kart = m_karts[i];
if (kart->isEliminated())
continue;
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++)
{
AbstractKart* kart = m_karts[i];
auto& kart = m_karts[i];
if (kart->isEliminated())
continue;
kart->getBody()->setLinearVelocity(Vec3(0.0f));
@ -406,7 +406,7 @@ void SoccerWorld::handlePlayerGoalFromServer(const NetworkString& ns)
m_ball->setEnabled(false);
for (unsigned i = 0; i < m_karts.size(); i++)
{
AbstractKart* kart = m_karts[i];
auto& kart = m_karts[i];
if (kart->isEliminated())
continue;
btTransform transform_now = kart->getBody()->getWorldTransform();
@ -431,7 +431,7 @@ void SoccerWorld::resetKartsToSelfGoals()
setPhase(WorldStatus::RACE_PHASE);
for (unsigned i = 0; i < m_karts.size(); i++)
{
AbstractKart* kart = m_karts[i];
auto& kart = m_karts[i];
if (kart->isEliminated())
continue;
@ -439,7 +439,7 @@ void SoccerWorld::resetKartsToSelfGoals()
kart->getBody()->setAngularVelocity(Vec3(0.0f));
unsigned index = m_kart_position_map.at(kart->getWorldKartId());
btTransform t = Track::getCurrentTrack()->getStartTransform(index);
moveKartTo(kart, t);
moveKartTo(kart.get(), t);
}
} // resetKartsToSelfGoals
@ -532,9 +532,9 @@ bool SoccerWorld::getKartSoccerResult(unsigned int kart_id) const
} // getKartSoccerResult
//-----------------------------------------------------------------------------
AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
RaceManager::KartType kart_type,
std::shared_ptr<AbstractKart> SoccerWorld::createKart
(const std::string &kart_ident, int index, int local_player_id,
int global_player_id, RaceManager::KartType kart_type,
PerPlayerDifficulty difficulty)
{
int cur_red = getTeamNum(SOCCER_TEAM_RED);
@ -590,16 +590,19 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
std::shared_ptr<RenderInfo> ri = std::make_shared<RenderInfo>();
ri = (team == SOCCER_TEAM_BLUE ? std::make_shared<RenderInfo>(0.66f) :
std::make_shared<RenderInfo>(1.0f));
AbstractKart* new_kart;
std::shared_ptr<AbstractKart> new_kart;
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
{
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));
@ -608,18 +611,18 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
switch(kart_type)
{
case RaceManager::KT_PLAYER:
controller = new LocalPlayerController(new_kart, local_player_id,
controller = new LocalPlayerController(new_kart.get(), local_player_id,
difficulty);
m_num_players ++;
break;
case RaceManager::KT_NETWORK_PLAYER:
controller = new NetworkPlayerController(new_kart);
controller = new NetworkPlayerController(new_kart.get());
if (!online_name.empty())
new_kart->setOnScreenText(online_name.c_str());
m_num_players++;
break;
case RaceManager::KT_AI:
controller = loadAIController(new_kart);
controller = loadAIController(new_kart.get());
break;
case RaceManager::KT_GHOST:
break;

View File

@ -51,9 +51,9 @@ public:
}; // ScorerData
protected:
virtual AbstractKart *createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
RaceManager::KartType type,
virtual std::shared_ptr<AbstractKart> createKart
(const std::string &kart_ident, int index, int local_player_id,
int global_player_id, RaceManager::KartType type,
PerPlayerDifficulty difficulty) OVERRIDE;
private:

View File

@ -103,7 +103,7 @@ void StandardRace::endRaceEarly()
for (unsigned int i = 1; i <= kart_amount; i++)
{
int kartid = m_position_index[i-1];
AbstractKart* kart = m_karts[kartid];
AbstractKart* kart = m_karts[kartid].get();
if (kart->hasFinishedRace())
{
@ -140,7 +140,7 @@ void StandardRace::endRaceEarly()
int kartid = active_players[i];
int position = getNumKarts() - (int) active_players.size() + 1 + i;
setKartPosition(kartid, position);
float punished_time = estimateFinishTimeForKart(m_karts[kartid])
float punished_time = estimateFinishTimeForKart(m_karts[kartid].get())
+ worse_finish_time - WorldStatus::getTime();
m_karts[kartid]->finishedRace(punished_time);

View File

@ -722,18 +722,18 @@ void ThreeStrikesBattle::loadCustomModels()
// Now add them
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,
std::make_shared<RenderInfo>(1.0f));
sta->init(RaceManager::KartType::KT_SPARE_TIRE);
sta->setController(new SpareTireAI(sta));
sta->setController(new SpareTireAI(sta.get()));
m_karts.push_back(sta);
race_manager->addSpareTireKart(sta_list[i]);
// Copy STA pointer to m_spare_tire_karts array, allowing them
// 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();
assert(m_spare_tire_karts.size() == sta_num);

View File

@ -212,9 +212,8 @@ void World::init()
: race_manager->getKartIdent(i);
int local_player_id = race_manager->getKartLocalPlayerId(i);
int global_player_id = race_manager->getKartGlobalPlayerId(i);
AbstractKart* newkart = createKart(kart_ident, i, local_player_id,
global_player_id,
race_manager->getKartType(i),
auto newkart = createKart(kart_ident, i, local_player_id,
global_player_id, race_manager->getKartType(i),
race_manager->getPlayerDifficulty(i));
m_karts.push_back(newkart);
@ -334,9 +333,9 @@ void World::createRaceGUI()
* \param global_player_id If the kart is a player kart this is the index of
* this player globally (i.e. including network players).
*/
AbstractKart *World::createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
RaceManager::KartType kart_type,
std::shared_ptr<AbstractKart> World::createKart
(const std::string &kart_ident, int index, int local_player_id,
int global_player_id, RaceManager::KartType kart_type,
PerPlayerDifficulty difficulty)
{
unsigned int gk = 0;
@ -355,13 +354,19 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
int position = index+1;
btTransform init_pos = getStartTransform(index - gk);
AbstractKart *new_kart;
std::shared_ptr<AbstractKart> new_kart;
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
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));
Controller *controller = NULL;
@ -369,7 +374,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
{
case RaceManager::KT_PLAYER:
{
controller = new LocalPlayerController(new_kart, local_player_id,
controller = new LocalPlayerController(new_kart.get(), local_player_id,
difficulty);
const PlayerProfile* p = StateManager::get()
->getActivePlayer(local_player_id)->getConstProfile();
@ -383,7 +388,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
}
case RaceManager::KT_NETWORK_PLAYER:
{
controller = new NetworkPlayerController(new_kart);
controller = new NetworkPlayerController(new_kart.get());
if (!online_name.empty())
new_kart->setOnScreenText(online_name.c_str());
m_num_players++;
@ -391,7 +396,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index,
}
case RaceManager::KT_AI:
{
controller = loadAIController(new_kart);
controller = loadAIController(new_kart.get());
break;
}
case RaceManager::KT_GHOST:
@ -485,13 +490,7 @@ World::~World()
Weather::kill();
for ( unsigned int i = 0 ; i < m_karts.size() ; i++ )
{
// Let ReplayPlay destroy the ghost karts
if (m_karts[i]->isGhostKart()) continue;
delete m_karts[i];
}
m_karts.clear();
if(race_manager->hasGhostKarts() || race_manager->isRecordingRace())
{
// Destroy the old replay object, which also stored the ghost
@ -502,7 +501,6 @@ World::~World()
ReplayPlay::destroy();
ReplayPlay::create();
}
m_karts.clear();
if(race_manager->isRecordingRace())
ReplayRecorder::get()->reset();
race_manager->setRaceGhostKarts(false);
@ -567,7 +565,8 @@ void World::terminateRace()
{
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
@ -699,7 +698,7 @@ void World::resetAllKarts()
btTransform t = getRescueTransform(rescue_pos);
// This will print out warnings if there is no terrain under
// 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
@ -725,7 +724,7 @@ void World::resetAllKarts()
Vec3 up_offset = (*i)->getNormal() * (0.5f * ((*i)->getKartHeight()));
(*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)
{
@ -1165,7 +1164,7 @@ void World::updateHighscores(int* best_highscore_rank)
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
assert(index[pos] < m_karts.size());
Kart *k = (Kart*)m_karts[index[pos]];
Kart *k = (Kart*)m_karts[index[pos]].get();
Highscores* highscores = getHighscores();
@ -1200,10 +1199,13 @@ AbstractKart *World::getPlayerKart(unsigned int n) const
unsigned int count = -1;
for(unsigned int i = 0; i < m_karts.size(); i++)
{
if (m_karts[i]->getController()->isPlayerController())
{
count++;
if(count==n) return m_karts[i];
if (count == n)
return m_karts[i].get();
}
}
return NULL;
} // getPlayerKart
@ -1225,7 +1227,7 @@ AbstractKart *World::getLocalPlayerKart(unsigned int n) const
void World::eliminateKart(int kart_id, bool notify_of_elimination)
{
assert(kart_id < (int)m_karts.size());
AbstractKart *kart = m_karts[kart_id];
AbstractKart *kart = m_karts[kart_id].get();
if (kart->isGhostKart()) return;
// Display a message about the eliminated kart in the race guia

View File

@ -25,6 +25,7 @@
* battle, etc.)
*/
#include <memory>
#include <vector>
#include <stdexcept>
@ -80,7 +81,7 @@ public:
class World : public WorldStatus
{
public:
typedef std::vector<AbstractKart*> KartList;
typedef std::vector<std::shared_ptr<AbstractKart> > KartList;
private:
/** A pointer to the global world object for a race. */
static World *m_world;
@ -117,9 +118,9 @@ protected:
Controller*
loadAIController (AbstractKart *kart);
virtual AbstractKart *createKart(const std::string &kart_ident, int index,
int local_player_id, int global_player_id,
RaceManager::KartType type,
virtual std::shared_ptr<AbstractKart> createKart
(const std::string &kart_ident, int index, int local_player_id,
int global_player_id, RaceManager::KartType type,
PerPlayerDifficulty difficulty);
/** Pointer to the race GUI. The race GUI is handled by world. */
@ -293,7 +294,7 @@ public:
/** Returns the kart with a given world id. */
AbstractKart *getKart(int kartId) const {
assert(kartId >= 0 && kartId < int(m_karts.size()));
return m_karts[kartId]; }
return m_karts[kartId].get(); }
// ------------------------------------------------------------------------
/** Returns all karts. */
const KartList & getKarts() const { return m_karts; }

View File

@ -82,7 +82,7 @@ AbstractKart* WorldWithRank::getKartAtPosition(unsigned int p) const
if(p<1 || p>m_position_index.size())
return NULL;
return m_karts[m_position_index[p-1]];
return m_karts[m_position_index[p-1]].get();
} // getKartAtPosition
//-----------------------------------------------------------------------------

View File

@ -19,8 +19,8 @@
#include "network/rewind_info.hpp"
#include "network/network_config.hpp"
#include "network/rewinder.hpp"
#include "network/rewind_manager.hpp"
#include "physics/physics.hpp"
/** Constructor for a state: it only takes the size, and allocates a buffer
* for all state info.

View File

@ -21,7 +21,6 @@
#include "network/event_rewinder.hpp"
#include "network/network_string.hpp"
#include "network/rewinder.hpp"
#include "utils/cpp2011.hpp"
#include "utils/leak_check.hpp"
#include "utils/ptr_vector.hpp"

View File

@ -24,7 +24,7 @@
/** Add this object to the list of all rewindable
* objects in the rewind manager.
*/
bool Rewinder::add()
bool Rewinder::rewinderAdd()
{
return RewindManager::get()->addRewinder(shared_from_this());
} // add
} // rewinderAdd

View File

@ -91,7 +91,7 @@ public:
return m_unique_identity;
}
// -------------------------------------------------------------------------
bool add();
bool rewinderAdd();
}; // Rewinder
#endif

View File

@ -71,8 +71,6 @@ void* btKartRaycaster::castRay(const btVector3& from, const btVector3& to,
result.m_hitNormalInWorld.normalize();
result.m_distFraction = rayCallback.m_closestHitFraction;
result.m_triangle_index = -1;
const TriangleMesh &tm =
Track::getCurrentTrack()->getTriangleMesh();
// FIXME: this code assumes atm that the object the kart is
// 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

View File

@ -123,12 +123,11 @@ void PhysicalObject::Settings::init()
} // Settings
// ============================================================================
PhysicalObject* PhysicalObject::fromXML(bool is_dynamic,
const XMLNode &xml_node,
TrackObject* object)
std::shared_ptr<PhysicalObject> PhysicalObject::fromXML
(bool is_dynamic, const XMLNode &xml_node, TrackObject* object)
{
PhysicalObject::Settings settings(xml_node);
return new PhysicalObject(is_dynamic, settings, object);
return std::make_shared<PhysicalObject>(is_dynamic, settings, object);
} // fromXML
// ----------------------------------------------------------------------------
@ -792,7 +791,7 @@ void PhysicalObject::addForRewind()
SmoothNetworkBody::setAdjustVerticalOffset(false);
Rewinder::setUniqueIdentity(std::string("P") + StringUtils::toString
(Track::getCurrentTrack()->getPhysicalObjectUID()));
Rewinder::add();
Rewinder::rewinderAdd();
} // addForRewind
// ----------------------------------------------------------------------------

View File

@ -197,8 +197,8 @@ public:
PhysicalObject(bool is_dynamic, const Settings& settings,
TrackObject* object);
static PhysicalObject* fromXML(bool is_dynamic, const XMLNode &node,
TrackObject* object);
static std::shared_ptr<PhysicalObject> fromXML
(bool is_dynamic, const XMLNode &node, TrackObject* object);
virtual ~PhysicalObject ();
virtual void reset ();

View File

@ -296,11 +296,13 @@ void History::Load()
{
fgets(s, 1023, fd);
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,
&ie.m_action, &ie.m_value) != 4 )
&action, &ie.m_value) != 4)
{
Log::warn("History", "Problems reading event: '%s'", s);
}
ie.m_action = (PlayerAction)action;
} // for i
RewindManager::setEnable(rewind_manager_was_enabled);

View File

@ -58,7 +58,7 @@ void ReplayPlay::reset()
{
for(unsigned int i=0; i<(unsigned int)m_ghost_karts.size(); i++)
{
m_ghost_karts[i].reset();
m_ghost_karts[i]->reset();
}
} // reset
@ -297,7 +297,7 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay, int ca
//-----------------------------------------------------------------------------
void ReplayPlay::load()
{
m_ghost_karts.clearAndDeleteAll();
m_ghost_karts.clear();
if (m_second_replay_enabled)
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();
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),
kart_num, kart_num + 1,
m_ghost_karts.push_back(std::make_shared<GhostKart>
(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)));
m_ghost_karts[kart_num].init(RaceManager::KT_GHOST);
Controller* controller = new GhostController(getGhostKart(kart_num),
m_ghost_karts[kart_num]->init(RaceManager::KT_GHOST);
Controller* controller = new GhostController(getGhostKart(kart_num).get(),
rd.m_name_list[kart_num-first_loaded_f_num]);
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_red_skidding = red_skidding!=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);
}
else
@ -472,7 +472,7 @@ void ReplayPlay::readKartData(FILE *fd, char *next_line, bool second_replay)
kre.m_skidding_effect = skidding;
kre.m_red_skidding = red_skidding!=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);
}
else

View File

@ -20,10 +20,10 @@
#define HEADER_REPLAY__PLAY_HPP
#include "replay/replay_base.hpp"
#include "utils/ptr_vector.hpp"
#include "irrString.h"
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
@ -118,7 +118,7 @@ private:
std::vector<ReplayData> m_replay_file_list;
/** All ghost karts. */
PtrVector<GhostKart> m_ghost_karts;
std::vector<std::shared_ptr<GhostKart> > m_ghost_karts;
ReplayPlay();
~ReplayPlay();
@ -162,7 +162,7 @@ public:
const unsigned int getNumReplayFile() const
{ 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
{

View File

@ -74,7 +74,6 @@ TrackObject::TrackObject(const core::vector3df& xyz, const core::vector3df& hpr,
m_enabled = true;
m_presentation = NULL;
m_animator = NULL;
m_physical_object = NULL;
m_parent_library = NULL;
m_interaction = interaction;
m_presentation = presentation;
@ -86,9 +85,8 @@ TrackObject::TrackObject(const core::vector3df& xyz, const core::vector3df& hpr,
if (m_interaction != "ghost" && m_interaction != "none" &&
physics_settings )
{
m_physical_object = new PhysicalObject(is_dynamic,
*physics_settings,
this);
m_physical_object = std::make_shared<PhysicalObject>
(is_dynamic, *physics_settings, this);
}
reset();
@ -112,7 +110,6 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
m_presentation = NULL;
m_animator = NULL;
m_parent_library = parent_library;
m_physical_object = NULL;
xml_node.get("id", &m_id );
xml_node.get("model", &m_name );
@ -455,7 +452,6 @@ TrackObject::~TrackObject()
{
delete m_presentation;
delete m_animator;
delete m_physical_object;
} // ~TrackObject
// ----------------------------------------------------------------------------
@ -482,7 +478,7 @@ void TrackObject::setEnabled(bool enabled)
if (getType() == "mesh")
{
if (m_physical_object != NULL)
if (m_physical_object)
{
if (enabled)
m_physical_object->addBody();
@ -508,7 +504,7 @@ void TrackObject::resetEnabled()
if (getType() == "mesh")
{
if (m_physical_object != NULL)
if (m_physical_object)
{
if (m_initially_visible)
m_physical_object->addBody();
@ -581,7 +577,7 @@ void TrackObject::move(const core::vector3df& xyz, const core::vector3df& hpr,
if (m_presentation != NULL)
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);
}

View File

@ -86,7 +86,7 @@ protected:
/** True if a kart can drive on this object. This will */
bool m_is_driveable;
PhysicalObject* m_physical_object;
std::shared_ptr<PhysicalObject> m_physical_object;
ThreeDAnimation* m_animator;
@ -164,9 +164,10 @@ public:
// ------------------------------------------------------------------------
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; }
// ------------------------------------------------------------------------
@ -214,7 +215,7 @@ public:
/** Get the physics representation of an object.
* 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 */
void setEnabled(bool mode);