1) Only Track is now using the ItemManager.
2) Fixed several memory leaks in animation code. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3849 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
756335fc8b
commit
1033bfdf59
@ -34,6 +34,17 @@ AnimationBase::AnimationBase(const XMLNode &node, float fps)
|
||||
m_playing = true;
|
||||
|
||||
} // AnimationBase
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Removes all IPOs.
|
||||
*/
|
||||
AnimationBase::~AnimationBase()
|
||||
{
|
||||
std::vector<Ipo*>::iterator i;
|
||||
for(i=m_all_ipos.begin(); i<m_all_ipos.end(); i++)
|
||||
delete *i;
|
||||
m_all_ipos.clear();
|
||||
} // ~AnimationBase
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Stores the initial transform (in the IPOs actually). This is necessary
|
||||
* for relative IPOs.
|
||||
|
@ -59,7 +59,7 @@ protected:
|
||||
|
||||
public:
|
||||
AnimationBase(const XMLNode &node, float fps);
|
||||
virtual ~AnimationBase() {}
|
||||
virtual ~AnimationBase();
|
||||
virtual void update(float dt, core::vector3df *xyz, core::vector3df *hpr);
|
||||
/** This needs to be implemented by the inheriting classes. It is called
|
||||
* once per frame from the track. */
|
||||
|
@ -43,6 +43,18 @@ AnimationManager::AnimationManager(const std::string &track_name, const XMLNode
|
||||
} // for i<node.getNumNodes
|
||||
} // AnimationManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Removes all animations from the scene node and memory. Called from
|
||||
* Track::cleanup().
|
||||
*/
|
||||
AnimationManager::~AnimationManager()
|
||||
{
|
||||
std::vector<AnimationBase*>::iterator i;
|
||||
for(i=m_all_animations.begin(); i!=m_all_animations.end(); i++)
|
||||
delete *i;
|
||||
m_all_animations.clear();
|
||||
} // ~AnimationManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Resets all animations.
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ private:
|
||||
|
||||
public:
|
||||
AnimationManager(const std::string &track_name, const XMLNode &node);
|
||||
~AnimationManager();
|
||||
void update(float dt);
|
||||
void reset();
|
||||
}; // AnimationManager
|
||||
|
@ -126,6 +126,12 @@ void ThreeDAnimation::createPhysicsBody(const std::string &shape)
|
||||
/** Destructor. */
|
||||
ThreeDAnimation::~ThreeDAnimation()
|
||||
{
|
||||
RaceManager::getWorld()->getPhysics()->removeBody(m_body);
|
||||
delete m_body;
|
||||
delete m_motion_state;
|
||||
delete m_collision_shape;
|
||||
irr_driver->removeNode(m_animated_node);
|
||||
irr_driver->removeMesh(m_mesh);
|
||||
} // ~ThreeDAnimation
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -43,8 +43,7 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
|
||||
so the player doesn't catch up with the ball
|
||||
and explode by touching it */
|
||||
m_speed = kart->getSpeed() + m_speed;
|
||||
if(m_speed < min_speed) m_speed
|
||||
= min_speed;
|
||||
if(m_speed < min_speed) m_speed = min_speed;
|
||||
}
|
||||
|
||||
createPhysics(y_offset, btVector3(0.0f, m_speed*2, 0.0f),
|
||||
@ -52,7 +51,7 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */)
|
||||
-70.0f /*gravity*/,
|
||||
true /*rotates*/);
|
||||
// Even if the ball is fired backwards, m_speed must be positive,
|
||||
// otherwise the ball can start to vibrate when enery is added.
|
||||
// otherwise the ball can start to vibrate when energy is added.
|
||||
m_speed = fabsf(m_speed);
|
||||
// Do not adjust the z velociy depending on height above terrain, since
|
||||
// this would disable gravity.
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "items/bubblegumitem.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
ItemManager* item_manager;
|
||||
@ -235,8 +236,8 @@ void ItemManager::cleanup()
|
||||
} // cleanup
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Remove all item instances, and the track specific models. This is used
|
||||
* just before a new track is loaded and a race is started
|
||||
/** Resets all items and removes bubble gum that is stuck on the track.
|
||||
* This is necessary in case that a race is restarted.
|
||||
*/
|
||||
void ItemManager::reset()
|
||||
{
|
||||
@ -259,6 +260,44 @@ void ItemManager::reset()
|
||||
} // for i
|
||||
} // reset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the selected item style to be used in the track. The style depends on
|
||||
* either the GP or the track selected.
|
||||
*/
|
||||
void ItemManager::setStyle()
|
||||
{
|
||||
if(race_manager->getMajorMode()== RaceManager::MAJOR_MODE_GRAND_PRIX)
|
||||
{
|
||||
try
|
||||
{
|
||||
item_manager->loadItemStyle(race_manager->getItemStyle());
|
||||
}
|
||||
catch(std::runtime_error)
|
||||
{
|
||||
fprintf(stderr, "The grand prix '%s' contains an invalid item style '%s'.\n",
|
||||
race_manager->getGrandPrix()->getName().c_str(),
|
||||
race_manager->getItemStyle().c_str());
|
||||
fprintf(stderr, "Please fix the file '%s'.\n",
|
||||
race_manager->getGrandPrix()->getFilename().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
item_manager->loadItemStyle(RaceManager::getTrack()->getItemStyle());
|
||||
}
|
||||
catch(std::runtime_error)
|
||||
{
|
||||
fprintf(stderr, "The track '%s' contains an invalid item style '%s'.\n",
|
||||
RaceManager::getTrack()->getName().c_str(),
|
||||
RaceManager::getTrack()->getItemStyle().c_str());
|
||||
fprintf(stderr, "Please fix the file '%s'.\n",
|
||||
RaceManager::getTrack()->getFilename().c_str());
|
||||
}
|
||||
}
|
||||
} // setStyle
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ItemManager::update(float delta)
|
||||
{
|
||||
|
@ -32,36 +32,39 @@ class ItemManager
|
||||
{
|
||||
|
||||
private:
|
||||
// The vector of all items of the current track
|
||||
/** The vector of all items of the current track. */
|
||||
typedef std::vector<Item*> AllItemTypes;
|
||||
AllItemTypes m_all_items;
|
||||
|
||||
// This stores all item models
|
||||
/** This stores all item models. */
|
||||
scene::IMesh *m_item_mesh[Item::ITEM_LAST-Item::ITEM_FIRST+1];
|
||||
|
||||
/** Stores all meshes for all items. */
|
||||
std::map<std::string,scene::IMesh*> m_all_meshes;
|
||||
|
||||
std::string m_user_filename;
|
||||
void setDefaultItemStyle();
|
||||
void setItem(const lisp::Lisp *item_node, const char *colour,
|
||||
Item::ItemType type);
|
||||
void loadItemStyle (const std::string filename);
|
||||
|
||||
public:
|
||||
ItemManager();
|
||||
~ItemManager();
|
||||
void loadDefaultItems();
|
||||
void loadItemStyle (const std::string filename);
|
||||
Item* newItem (Item::ItemType type, const Vec3& xyz,
|
||||
const Vec3 &normal, Kart* parent=NULL);
|
||||
void update (float delta);
|
||||
void hitItem (Kart* kart);
|
||||
void cleanup ();
|
||||
void reset ();
|
||||
void removeTextures ();
|
||||
void setUserFilename (char *s) {m_user_filename=s;}
|
||||
void collectedItem (int item_id, Kart *kart,
|
||||
int add_info=-1);
|
||||
scene::IMesh* getItemModel (Item::ItemType type)
|
||||
{return m_item_mesh[type];}
|
||||
ItemManager();
|
||||
~ItemManager();
|
||||
void loadDefaultItems();
|
||||
Item* newItem (Item::ItemType type, const Vec3& xyz,
|
||||
const Vec3 &normal, Kart* parent=NULL);
|
||||
void update (float delta);
|
||||
void hitItem (Kart* kart);
|
||||
void cleanup ();
|
||||
void reset ();
|
||||
void removeTextures ();
|
||||
void setUserFilename (char *s) {m_user_filename=s;}
|
||||
void collectedItem (int item_id, Kart *kart,
|
||||
int add_info=-1);
|
||||
void setStyle ();
|
||||
scene::IMesh* getItemModel (Item::ItemType type)
|
||||
{return m_item_mesh[type];}
|
||||
};
|
||||
|
||||
extern ItemManager* item_manager;
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/race_gui.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "items/item_manager.hpp"
|
||||
#include "items/projectile_manager.hpp"
|
||||
#include "karts/auto_kart.hpp"
|
||||
#include "karts/player_kart.hpp"
|
||||
@ -98,7 +97,7 @@ void World::init()
|
||||
|
||||
// Load the track models - this must be done before the karts so that the
|
||||
// karts can be positioned properly on (and not in) the tracks.
|
||||
loadTrack() ;
|
||||
m_track->loadTrackModel();
|
||||
|
||||
m_player_karts.resize(race_manager->getNumPlayers());
|
||||
m_network_karts.resize(race_manager->getNumPlayers());
|
||||
@ -289,7 +288,6 @@ void World::update(float dt)
|
||||
}
|
||||
|
||||
projectile_manager->update(dt);
|
||||
item_manager->update(dt);
|
||||
m_race_gui->update(dt);
|
||||
} // update
|
||||
|
||||
@ -435,44 +433,6 @@ void World::removeKart(int kart_number)
|
||||
m_eliminated_karts++;
|
||||
|
||||
} // removeKart
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Cleans up old items (from a previous race), removes old track specific
|
||||
* item models, and loads the actual track.
|
||||
*/
|
||||
void World::loadTrack()
|
||||
{
|
||||
if(race_manager->getMajorMode()== RaceManager::MAJOR_MODE_GRAND_PRIX)
|
||||
{
|
||||
try
|
||||
{
|
||||
item_manager->loadItemStyle(race_manager->getItemStyle());
|
||||
}
|
||||
catch(std::runtime_error)
|
||||
{
|
||||
fprintf(stderr, "The grand prix '%s' contains an invalid item style '%s'.\n",
|
||||
race_manager->getGrandPrix()->getName().c_str(),
|
||||
race_manager->getItemStyle().c_str());
|
||||
fprintf(stderr, "Please fix the file '%s'.\n",
|
||||
race_manager->getGrandPrix()->getFilename().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
item_manager->loadItemStyle(m_track->getItemStyle());
|
||||
}
|
||||
catch(std::runtime_error)
|
||||
{
|
||||
fprintf(stderr, "The track '%s' contains an invalid item style '%s'.\n",
|
||||
m_track->getName().c_str(), m_track->getItemStyle().c_str());
|
||||
fprintf(stderr, "Please fix the file '%s'.\n",
|
||||
m_track->getFilename().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
m_track->loadTrackModel();
|
||||
} // loadTrack
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void World::getDefaultCollectibles(int& collectible_type, int& amount )
|
||||
@ -503,7 +463,6 @@ void World::restartRace()
|
||||
// Enable SFX again
|
||||
sfx_manager->resumeAll();
|
||||
|
||||
item_manager->reset();
|
||||
projectile_manager->cleanup();
|
||||
race_manager->reset();
|
||||
|
||||
|
@ -103,7 +103,6 @@ protected:
|
||||
bool m_use_highscores;
|
||||
|
||||
void updateHighscores ();
|
||||
void loadTrack ();
|
||||
void resetAllKarts ();
|
||||
void removeKart (int kart_number);
|
||||
Kart* loadRobot (const std::string& kart_name, int position,
|
||||
|
@ -80,7 +80,6 @@ Track::Track( std::string filename)
|
||||
Track::~Track()
|
||||
{
|
||||
if(m_quad_graph) delete m_quad_graph;
|
||||
if(m_animation_manager) delete m_animation_manager;
|
||||
if(m_check_manager) delete m_check_manager;
|
||||
if(m_mini_map) irr_driver->removeTexture(m_mini_map);
|
||||
} // ~Track
|
||||
@ -96,6 +95,8 @@ void Track::reset()
|
||||
m_animation_manager->reset();
|
||||
if(m_check_manager)
|
||||
m_check_manager->reset(*this);
|
||||
item_manager->reset();
|
||||
|
||||
} // reset
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -125,7 +126,12 @@ void Track::cleanup()
|
||||
irr_driver->removeMesh(m_all_meshes[i]);
|
||||
}
|
||||
m_all_meshes.clear();
|
||||
|
||||
|
||||
if(m_animation_manager)
|
||||
{
|
||||
delete m_animation_manager;
|
||||
m_animation_manager = NULL;
|
||||
}
|
||||
|
||||
delete m_non_collision_mesh;
|
||||
m_non_collision_mesh = new TriangleMesh();
|
||||
@ -523,6 +529,8 @@ void Track::update(float dt)
|
||||
m_animation_manager->update(dt);
|
||||
if(m_check_manager)
|
||||
m_check_manager->update(dt);
|
||||
item_manager->update(dt);
|
||||
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -599,6 +607,8 @@ void Track::createWater(const XMLNode &node)
|
||||
*/
|
||||
void Track::loadTrackModel()
|
||||
{
|
||||
item_manager->setStyle();
|
||||
|
||||
// Load the graph only now: this function is called from world, after
|
||||
// the race gui was created. The race gui is needed since it stores
|
||||
// the information about the size of the texture to render the mini
|
||||
|
Loading…
x
Reference in New Issue
Block a user