Use singleton constructions for check manager.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/reverse_mode@10837 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -28,14 +28,11 @@
|
||||
#include "tracks/track.hpp"
|
||||
|
||||
/** Constructor for a checksphere.
|
||||
* \param check_manager Pointer to the check manager, which is needed when
|
||||
* resetting e.g. new lap counters.
|
||||
* \param node XML node containing the parameters for this checkline.
|
||||
*/
|
||||
AmbientLightSphere::AmbientLightSphere(CheckManager *check_manager,
|
||||
const XMLNode &node,
|
||||
AmbientLightSphere::AmbientLightSphere(const XMLNode &node,
|
||||
unsigned int index)
|
||||
: CheckSphere(check_manager, node, index)
|
||||
: CheckSphere(node, index)
|
||||
{
|
||||
m_ambient_color = video::SColor(255, 0, 255, 0); // green
|
||||
m_inner_radius2 = 1;
|
||||
|
||||
@@ -49,8 +49,7 @@ private:
|
||||
* inner radius. */
|
||||
video::SColor m_ambient_color;
|
||||
public:
|
||||
AmbientLightSphere(CheckManager *check_manager,
|
||||
const XMLNode &node, unsigned int index);
|
||||
AmbientLightSphere(const XMLNode &node, unsigned int index);
|
||||
virtual ~AmbientLightSphere() {};
|
||||
virtual void update(float dt);
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "io/xml_node.hpp"
|
||||
#include "modes/linear_world.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "tracks/check_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
|
||||
/** Constructor for a lap line.
|
||||
@@ -31,9 +30,8 @@
|
||||
* resetting e.g. new lap counters.
|
||||
* \param node XML node containing the parameters for this checkline.
|
||||
*/
|
||||
CheckLap::CheckLap(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index)
|
||||
: CheckStructure(check_manager, node, index)
|
||||
CheckLap::CheckLap(const XMLNode &node, unsigned int index)
|
||||
: CheckStructure(node, index)
|
||||
{
|
||||
// Note that when this is called the karts have not been allocated
|
||||
// in world, so we can't call world->getNumKarts()
|
||||
|
||||
@@ -37,8 +37,7 @@ private:
|
||||
std::vector<float> m_previous_distance;
|
||||
|
||||
public:
|
||||
CheckLap(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index);
|
||||
CheckLap(const XMLNode &node, unsigned int index);
|
||||
virtual ~CheckLap() {};
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
int indx);
|
||||
|
||||
@@ -27,13 +27,11 @@
|
||||
#include "race/race_manager.hpp"
|
||||
|
||||
/** Constructor for a checkline.
|
||||
* \param check_manager Pointer to the check manager, which is needed when
|
||||
* resetting e.g. new lap counters.
|
||||
* \param node XML node containing the parameters for this checkline.
|
||||
* \param index Index of this check structure in the check manager.
|
||||
*/
|
||||
CheckLine::CheckLine(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index)
|
||||
: CheckStructure(check_manager, node, index)
|
||||
CheckLine::CheckLine(const XMLNode &node, unsigned int index)
|
||||
: CheckStructure(node, index)
|
||||
{
|
||||
// Note that when this is called the karts have not been allocated
|
||||
// in world, so we can't call world->getNumKarts()
|
||||
|
||||
@@ -64,8 +64,7 @@ private:
|
||||
* quad and still considered to be able to cross it. */
|
||||
static const int m_over_min_height = 4;
|
||||
public:
|
||||
CheckLine(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index);
|
||||
CheckLine(const XMLNode &node, unsigned int index);
|
||||
virtual ~CheckLine();
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx);
|
||||
virtual void reset(const Track &track);
|
||||
|
||||
@@ -28,7 +28,11 @@
|
||||
#include "tracks/check_structure.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
|
||||
CheckManager::CheckManager(const XMLNode &node, Track *track)
|
||||
CheckManager *CheckManager::m_check_manager = NULL;
|
||||
|
||||
/** Loads all check structure informaiton from the specified xml file.
|
||||
*/
|
||||
void CheckManager::load(const XMLNode &node)
|
||||
{
|
||||
for(unsigned int i=0; i<node.getNumNodes(); i++)
|
||||
{
|
||||
@@ -36,16 +40,16 @@ CheckManager::CheckManager(const XMLNode &node, Track *track)
|
||||
const std::string &type = check_node->getName();
|
||||
if(type=="check-line")
|
||||
{
|
||||
CheckLine *cl = new CheckLine(this, *check_node, i);
|
||||
CheckLine *cl = new CheckLine(*check_node, i);
|
||||
m_all_checks.push_back(cl);
|
||||
} // checkline
|
||||
else if(type=="check-lap")
|
||||
{
|
||||
m_all_checks.push_back(new CheckLap(this, *check_node, i));
|
||||
m_all_checks.push_back(new CheckLap(*check_node, i));
|
||||
}
|
||||
else if(type=="check-sphere")
|
||||
{
|
||||
AmbientLightSphere *cs = new AmbientLightSphere(this, *check_node,
|
||||
AmbientLightSphere *cs = new AmbientLightSphere(*check_node,
|
||||
i);
|
||||
m_all_checks.push_back(cs);
|
||||
} // checksphere
|
||||
@@ -78,15 +82,19 @@ CheckManager::CheckManager(const XMLNode &node, Track *track)
|
||||
}
|
||||
|
||||
}
|
||||
} // CheckManager
|
||||
} // load
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Private destructor (to make sure it is only called using the static
|
||||
* destroy function). Frees all check structures.
|
||||
*/
|
||||
CheckManager::~CheckManager()
|
||||
{
|
||||
for(unsigned int i=0; i<m_all_checks.size(); i++)
|
||||
{
|
||||
delete m_all_checks[i];
|
||||
}
|
||||
m_check_manager = NULL;
|
||||
} // ~CheckManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
#ifndef HEADER_CHECK_MANAGER_HPP
|
||||
#define HEADER_CHECK_MANAGER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class XMLNode;
|
||||
class CheckStructure;
|
||||
@@ -30,22 +33,40 @@ class Track;
|
||||
* \brief Controls all checks structures of a track.
|
||||
* \ingroup tracks
|
||||
*/
|
||||
class CheckManager
|
||||
class CheckManager : public NoCopy
|
||||
{
|
||||
private:
|
||||
std::vector<CheckStructure*> m_all_checks;
|
||||
static CheckManager *m_check_manager;
|
||||
/** Private constructor, to make sure it is only called via
|
||||
* the static create function. */
|
||||
CheckManager() {m_all_checks.clear();};
|
||||
~CheckManager();
|
||||
public:
|
||||
CheckManager(const XMLNode &node, Track *track);
|
||||
~CheckManager();
|
||||
void update(float dt);
|
||||
void reset(const Track &track);
|
||||
|
||||
void load(const XMLNode &node);
|
||||
void update(float dt);
|
||||
void reset(const Track &track);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Creates an instance of the check manager. */
|
||||
static void create()
|
||||
{
|
||||
assert(!m_check_manager);
|
||||
m_check_manager = new CheckManager();
|
||||
} // create
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the instance of the check manager. */
|
||||
static CheckManager* get() { return m_check_manager; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Destroys the check manager. */
|
||||
static void destroy() { delete m_check_manager; m_check_manager = NULL; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of check structures defined. */
|
||||
int getCheckStructureCount() const { return m_all_checks.size(); }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the nth. check structure. */
|
||||
CheckStructure *getCheckStructure(unsigned int n)
|
||||
{
|
||||
if (n >= m_all_checks.size()) return NULL;
|
||||
assert(n < m_all_checks.size());
|
||||
return m_all_checks[n];
|
||||
}
|
||||
}; // CheckManager
|
||||
|
||||
@@ -30,9 +30,8 @@
|
||||
* resetting e.g. new lap counters.
|
||||
* \param node XML node containing the parameters for this checkline.
|
||||
*/
|
||||
CheckSphere::CheckSphere(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index)
|
||||
: CheckStructure(check_manager, node, index)
|
||||
CheckSphere::CheckSphere(const XMLNode &node, unsigned int index)
|
||||
: CheckStructure(node, index)
|
||||
{
|
||||
m_radius2 = 1;
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ private:
|
||||
* This saves some computations. */
|
||||
std::vector<float> m_distance2;
|
||||
public:
|
||||
CheckSphere(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index);
|
||||
CheckSphere(const XMLNode &node, unsigned int index);
|
||||
virtual ~CheckSphere() {};
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
int kart_id);
|
||||
|
||||
@@ -28,11 +28,9 @@
|
||||
#include "tracks/check_manager.hpp"
|
||||
|
||||
|
||||
CheckStructure::CheckStructure(CheckManager *check_manager,
|
||||
const XMLNode &node, unsigned int index)
|
||||
CheckStructure::CheckStructure(const XMLNode &node, unsigned int index)
|
||||
{
|
||||
m_index = index;
|
||||
m_check_manager = check_manager;
|
||||
m_check_type = CT_NEW_LAP;
|
||||
|
||||
// This structure is actually filled by the check manager (necessary
|
||||
@@ -115,7 +113,7 @@ void CheckStructure::update(float dt)
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Changes the status (active/inactive) of all check structures contained
|
||||
* in the index list indices.
|
||||
* \param indices List of index of check structures in check_manager that
|
||||
* \param indices List of index of check structures in the CheckManager that
|
||||
* are to be changed.
|
||||
* \param int kart_index For which the status should be changed.
|
||||
* \param change_state How to change the state (active, deactivate, toggle).
|
||||
@@ -131,7 +129,7 @@ void CheckStructure::changeStatus(const std::vector<int> indices,
|
||||
for(unsigned int i=0; i<indices.size(); i++)
|
||||
{
|
||||
CheckStructure *cs =
|
||||
m_check_manager->getCheckStructure(indices[i]);
|
||||
CheckManager::get()->getCheckStructure(indices[i]);
|
||||
if (cs == NULL) continue;
|
||||
|
||||
switch(change_state)
|
||||
@@ -177,9 +175,9 @@ void CheckStructure::changeStatus(const std::vector<int> indices,
|
||||
|
||||
/*
|
||||
printf("--------\n");
|
||||
for (int n=0; n<m_check_manager->getCheckStructureCount(); n++)
|
||||
for (int n=0; n<CheckManager::get()->getCheckStructureCount(); n++)
|
||||
{
|
||||
CheckStructure *cs = m_check_manager->getCheckStructure(n);
|
||||
CheckStructure *cs = CheckManager::get()->getCheckStructure(n);
|
||||
if (dynamic_cast<CheckLap*>(cs) != NULL)
|
||||
printf("Checkline %i (LAP) : %i\n", n, (int)cs->m_is_active[kart_index]);
|
||||
else
|
||||
|
||||
@@ -73,9 +73,6 @@ protected:
|
||||
bool m_active_at_reset;
|
||||
|
||||
private:
|
||||
/** Stores a pointer to the check manager. */
|
||||
CheckManager *m_check_manager;
|
||||
|
||||
/** The type of this checkline. */
|
||||
CheckType m_check_type;
|
||||
|
||||
@@ -100,8 +97,7 @@ private:
|
||||
ChangeState change_state);
|
||||
|
||||
public:
|
||||
CheckStructure(CheckManager *check_manager, const XMLNode &node,
|
||||
unsigned int index);
|
||||
CheckStructure(const XMLNode &node, unsigned int index);
|
||||
virtual ~CheckStructure() {};
|
||||
virtual void update(float dt);
|
||||
virtual void changeDebugColor(bool is_active) {}
|
||||
|
||||
@@ -211,7 +211,7 @@ void QuadGraph::load(const std::string &filename)
|
||||
void QuadGraph::setChecklineRequirements(GraphNode* node, int latest_checkline)
|
||||
{
|
||||
Track* t = World::getWorld()->getTrack();
|
||||
CheckManager* cm = t->getCheckManager();
|
||||
CheckManager* cm = CheckManager::get();
|
||||
assert(cm != NULL);
|
||||
|
||||
// Find lapline
|
||||
|
||||
@@ -91,7 +91,6 @@ Track::Track(const std::string &filename)
|
||||
m_all_cached_meshes.clear();
|
||||
m_is_arena = false;
|
||||
m_camera_far = 1000.0f;
|
||||
m_check_manager = NULL;
|
||||
m_mini_map = NULL;
|
||||
m_sky_particles = NULL;
|
||||
m_sky_dx = 0.05f;
|
||||
@@ -121,8 +120,7 @@ Track::~Track()
|
||||
void Track::reset()
|
||||
{
|
||||
m_ambient_color = m_default_ambient_color;
|
||||
if(m_check_manager)
|
||||
m_check_manager->reset(*this);
|
||||
CheckManager::get()->reset(*this);
|
||||
item_manager->reset();
|
||||
m_track_object_manager->reset();
|
||||
} // reset
|
||||
@@ -152,11 +150,7 @@ void Track::cleanup()
|
||||
|
||||
m_all_emitters.clearAndDeleteAll();
|
||||
|
||||
if(m_check_manager)
|
||||
{
|
||||
delete m_check_manager;
|
||||
m_check_manager=NULL;
|
||||
}
|
||||
CheckManager::destroy();
|
||||
|
||||
delete m_track_object_manager;
|
||||
m_track_object_manager = NULL;
|
||||
@@ -197,7 +191,7 @@ void Track::cleanup()
|
||||
m_all_cached_meshes.clear();
|
||||
|
||||
QuadGraph::destroy();
|
||||
if(m_check_manager) delete m_check_manager;
|
||||
|
||||
if(m_mini_map)
|
||||
{
|
||||
assert(m_mini_map->getReferenceCount()==1);
|
||||
@@ -1050,8 +1044,7 @@ void Track::update(float dt)
|
||||
{
|
||||
m_animated_textures[i]->update(dt);
|
||||
}
|
||||
if(m_check_manager)
|
||||
m_check_manager->update(dt);
|
||||
CheckManager::get()->update(dt);
|
||||
item_manager->update(dt);
|
||||
|
||||
} // update
|
||||
@@ -1151,6 +1144,7 @@ void Track::loadTrackModel(World* parent, bool reverse_track,
|
||||
{
|
||||
reverse_track = false;
|
||||
}
|
||||
CheckManager::create();
|
||||
assert(m_all_cached_meshes.size()==0);
|
||||
if(UserConfigParams::logMemory())
|
||||
{
|
||||
@@ -1315,7 +1309,7 @@ void Track::loadTrackModel(World* parent, bool reverse_track,
|
||||
}
|
||||
else if(name=="checks")
|
||||
{
|
||||
m_check_manager = new CheckManager(*node, this);
|
||||
CheckManager::get()->load(*node);
|
||||
}
|
||||
else if (name=="particle-emitter")
|
||||
{
|
||||
@@ -1549,7 +1543,8 @@ void Track::loadTrackModel(World* parent, bool reverse_track,
|
||||
|
||||
// Only print warning if not in battle mode, since battle tracks don't have
|
||||
// any quads or check lines.
|
||||
if(!m_check_manager && race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES)
|
||||
if(CheckManager::get()->getCheckStructureCount()==0 &&
|
||||
race_manager->getMinorMode()!=RaceManager::MINOR_MODE_3_STRIKES)
|
||||
{
|
||||
printf("WARNING: no check lines found in track '%s'.\n",
|
||||
m_ident.c_str());
|
||||
@@ -1843,8 +1838,8 @@ std::vector< std::vector<float> > Track::buildHeightMap()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
core::vector3df Track::getSunRotation()
|
||||
/** Returns the rotation of the sun. */
|
||||
const core::vector3df& Track::getSunRotation()
|
||||
{
|
||||
return m_sun->getRotation();
|
||||
}
|
||||
|
||||
@@ -279,9 +279,6 @@ private:
|
||||
/** List of all bezier curves in the track - for e.g. camera, ... */
|
||||
std::vector<BezierCurve*> m_all_curves;
|
||||
|
||||
/** Checkline manager. */
|
||||
CheckManager *m_check_manager;
|
||||
|
||||
void loadTrackInfo();
|
||||
void itemCommand(const Vec3 &xyz, Item::ItemType item_type,
|
||||
bool drop);
|
||||
@@ -312,7 +309,7 @@ public:
|
||||
void reset();
|
||||
void adjustForFog(scene::ISceneNode *node);
|
||||
void adjustForFog(scene::IMesh* mesh, scene::ISceneNode* parent_scene_node);
|
||||
|
||||
const core::vector3df& getSunRotation();
|
||||
/** Sets the current ambient color for a kart with index k. */
|
||||
void setAmbientColor(const video::SColor &color,
|
||||
unsigned int k);
|
||||
@@ -430,17 +427,13 @@ public:
|
||||
ParticleKind* getSkyParticles () { return m_sky_particles; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isFogEnabled() const { return m_use_fog; }
|
||||
|
||||
CheckManager* getCheckManager() { return m_check_manager; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Whether this is an "internal" track. If so it won't be offered
|
||||
* in the track seelction screen
|
||||
*/
|
||||
* in the track seelction screen. */
|
||||
bool isInternal() const { return m_internal; }
|
||||
|
||||
core::vector3df getSunRotation();
|
||||
|
||||
TrackObjectManager* getTrackObjectManager() { return m_track_object_manager; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
TrackObjectManager* getTrackObjectManager() {return m_track_object_manager;}
|
||||
|
||||
/** Get list of challenges placed on that world. Works only for overworld. */
|
||||
const std::vector<OverworldChallenge>& getChallengeList() const
|
||||
|
||||
Reference in New Issue
Block a user