Commit 4f28d4ef authored by progs's avatar progs Committed by Romain Bignon

BIG BIG BIG BIG BIG BIG BIG BIG BIG optimization of memory!

parent 9b484069
......@@ -30,20 +30,9 @@
* ECBatiment *
********************************************************************************************/
ECBatiment::ECBatiment(ECSpriteBase* b, ECSpriteBase* explos)
ECBatiment::ECBatiment(ECSpriteBase* explos)
: explosion(explos)
{
img = new ECSpriteBase(b->path.c_str());
if(Owner() && Owner()->Color())
img->ChangeColor(white_color, color_eq[Owner()->Color()]);
SetImage(img);
}
void ECBatiment::RefreshColor(Color last)
{
img->ChangeColor(last, Owner() ? color_eq[Owner()->Color()] : white_color);
}
bool ECBatiment::AfterEvent(const std::vector<ECEntity*>&, ECase* c, EC_Client*)
......@@ -71,17 +60,12 @@ bool ECBatiment::AfterEvent(const std::vector<ECEntity*>&, ECase* c, EC_Client*)
return true;
}
ECBatiment::~ECBatiment()
{
if(img)
delete img;
}
/********************************************************************************************
* ECEiffelTower *
********************************************************************************************/
void ECEiffelTower::Init()
{
ECEntity::Init();
if(Owner() && Owner()->IsMe())
{
Map()->SetBrouillard(false);
......@@ -111,6 +95,7 @@ ECEiffelTower::~ECEiffelTower()
********************************************************************************************/
void ECRadar::Init()
{
ECEntity::Init();
if(Owner() && Owner()->IsMe())
{
std::vector<ECBCase*> cases = Map()->Cases();
......@@ -265,7 +250,7 @@ ECMine::~ECMine()
void ECMine::Init()
{
ECBEntity::Init();
ECEntity::Init();
activeimg = new ECSpriteBase(Resources::Mine_ActFace()->path.c_str());
......@@ -302,6 +287,7 @@ std::string ECMine::SpecialInfo()
void ECNuclearSearch::Init()
{
ECBNuclearSearch::Init();
ECEntity::Init();
Image()->SetAnim(true);
if(Owner() && Channel() && !Owner()->IsMe())
Channel()->Print(StringF(_("WARNING!! %s has got nuclear technologie, with his nuclear search"), Owner()->GetNick()), 0x008);
......
......@@ -39,10 +39,9 @@ class ECBatiment : public ECEntity
/* Constructeur/Destructeur */
public:
ECBatiment() : img(0), explosion(0) {}
ECBatiment() : explosion(0) {}
ECBatiment(ECSpriteBase* b, ECSpriteBase* explosion = 0);
virtual ~ECBatiment();
ECBatiment(ECSpriteBase* explosion);
/* Methodes */
public:
......@@ -53,10 +52,7 @@ public:
virtual bool AfterEvent(const std::vector<ECEntity*>&, ECase* c, EC_Client*);
virtual void RefreshColor(Color last);
private:
ECSpriteBase *img;
ECSpriteBase *explosion;
};
......@@ -71,7 +67,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECBarbedWire) {}
ENTITY_CONSTRUCTOR(ECBarbedWire), ECBatiment(Resources::BarbedWire_Horiz()) {}
ENTITY_CONSTRUCTOR(ECBarbedWire) {}
void UpdateImages() { PutImage(I_Down, (Resources::BarbedWire_Horiz())); }
virtual void Created();
......@@ -103,7 +101,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECRail) {}
ENTITY_CONSTRUCTOR(ECRail), ECBatiment(Resources::Rail_Horiz()) {}
ENTITY_CONSTRUCTOR(ECRail) {}
void UpdateImages() { PutImage(I_Down, (Resources::Rail_Horiz())); }
virtual void Created();
......@@ -135,7 +135,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECTrees) {}
ENTITY_CONSTRUCTOR(ECTrees), ECBatiment(Resources::Trees_Face()) {}
ENTITY_CONSTRUCTOR(ECTrees) {}
void UpdateImages() { PutImage(I_Down, (Resources::Trees_Face())); }
/* Infos */
public:
......@@ -166,7 +168,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECMine) : activeimg(0) {}
ENTITY_CONSTRUCTOR(ECMine), ECBatiment(Resources::Mine_DesactFace(), Resources::Brouillard()), activeimg(0) {}
ENTITY_CONSTRUCTOR(ECMine), ECBatiment(Resources::Brouillard()), activeimg(0) {}
void UpdateImages() { PutImage(I_Down, Resources::Mine_DesactFace()); }
~ECMine();
......@@ -203,7 +207,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECEiffelTower) {}
ENTITY_CONSTRUCTOR(ECEiffelTower), ECBatiment(Resources::EiffelTower_Face()) {}
ENTITY_CONSTRUCTOR(ECEiffelTower) {}
void UpdateImages() { PutImage(I_Down, (Resources::EiffelTower_Face())); }
virtual void Init();
......@@ -233,7 +239,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECRadar) {}
ENTITY_CONSTRUCTOR(ECRadar), ECBatiment(Resources::Radar_Face()) {}
ENTITY_CONSTRUCTOR(ECRadar) {}
void UpdateImages() { PutImage(I_Down, (Resources::Radar_Face())); }
virtual void Init();
......@@ -263,7 +271,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECNuclearSearch) {}
ENTITY_CONSTRUCTOR(ECNuclearSearch), ECBatiment(Resources::NuclearSearch_Face()) {}
ENTITY_CONSTRUCTOR(ECNuclearSearch) {}
void UpdateImages() { PutImage(I_Down, (Resources::NuclearSearch_Face())); }
virtual void Init();
......@@ -298,12 +308,23 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECSilo) : missile(this, SILO_MISSILE_STEP) {}
ENTITY_CONSTRUCTOR(ECSilo), ECBatiment(Resources::Silo_Face()), missile(this, SILO_MISSILE_STEP)
ENTITY_CONSTRUCTOR(ECSilo), ECBatiment(), missile(this, SILO_MISSILE_STEP)
{
missile.SetMissileUp(Resources::Silo_Missile_Up());
missile.SetMissileDown(Resources::Silo_Missile_Down());
}
void UpdateImages()
{
PutImage(I_Down, Resources::Silo_Face());
}
void Init()
{
ECEntity::Init();
ECBSilo::Init();
}
/* Infos */
public:
......@@ -345,7 +366,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECMegalopole) {}
ENTITY_CONSTRUCTOR(ECMegalopole), ECBatiment(Resources::Megalopole_Face()) {}
ENTITY_CONSTRUCTOR(ECMegalopole) {}
void UpdateImages() { PutImage(I_Down, (Resources::Megalopole_Face())); }
virtual void Init()
{
......@@ -380,7 +403,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECapitale) {}
ENTITY_CONSTRUCTOR(ECapitale), ECBatiment(Resources::Capitale_Face()) {}
ENTITY_CONSTRUCTOR(ECapitale) {}
void UpdateImages() { PutImage(I_Down, (Resources::Capitale_Face())); }
/* Infos */
public:
......@@ -408,7 +433,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECity) {}
ENTITY_CONSTRUCTOR(ECity), ECBatiment(Resources::City_Face()) {}
ENTITY_CONSTRUCTOR(ECity) {}
void UpdateImages() { PutImage(I_Down, (Resources::City_Face())); }
/* Infos */
public:
......@@ -436,13 +463,18 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECDefenseTower) : missile(this, DEFENSETOWER_MISSILE_STEP), miss(0), cible(0) {}
ENTITY_CONSTRUCTOR(ECDefenseTower), ECBatiment(Resources::DefenseTower_Face()),
ENTITY_CONSTRUCTOR(ECDefenseTower), ECBatiment(),
missile(this, DEFENSETOWER_MISSILE_STEP), miss(0), cible(0)
{
missile.SetMissileUp(Resources::MissiLauncher_Missile_Up());
missile.SetMissileDown(Resources::MissiLauncher_Missile_Down());
}
void UpdateImages()
{
PutImage(I_Down, Resources::DefenseTower_Face());
}
/* Infos */
public:
......@@ -481,7 +513,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECObelisk) : victim(0) {}
ENTITY_CONSTRUCTOR(ECObelisk), ECBatiment(Resources::Obelisk_Face()), victim(0) {}
ENTITY_CONSTRUCTOR(ECObelisk), victim(0) {}
void UpdateImages() { PutImage(I_Down, (Resources::Obelisk_Face())); }
/* Infos */
public:
......@@ -520,7 +554,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECharFact) {}
ENTITY_CONSTRUCTOR(ECharFact), ECBatiment(Resources::CharFact_Face()) {}
ENTITY_CONSTRUCTOR(ECharFact) {}
void UpdateImages() { PutImage(I_Down, (Resources::CharFact_Face())); }
virtual void Init()
{
......@@ -553,7 +589,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECaserne) {}
ENTITY_CONSTRUCTOR(ECaserne), ECBatiment(Resources::Caserne_Face()) {}
ENTITY_CONSTRUCTOR(ECaserne) {}
void UpdateImages() { PutImage(I_Down, (Resources::Caserne_Face())); }
/* Infos */
public:
......@@ -580,7 +618,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECAirPort) {}
ENTITY_CONSTRUCTOR(ECAirPort), ECBatiment(Resources::AirPort_Face()) {}
ENTITY_CONSTRUCTOR(ECAirPort) {}
void UpdateImages() { PutImage(I_Down, (Resources::AirPort_Face())); }
/* Infos */
public:
......@@ -606,7 +646,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECShipyard) {}
ENTITY_CONSTRUCTOR(ECShipyard), ECBatiment(Resources::Shipyard_Face()) {}
ENTITY_CONSTRUCTOR(ECShipyard) {}
void UpdateImages() { PutImage(I_Down, (Resources::Shipyard_Face())); }
/* Infos */
public:
......
......@@ -49,6 +49,13 @@ ECPlayer::ECPlayer(std::string _nick, EChannel *_chan, bool _owner, bool _op, bo
}
ECPlayer::~ECPlayer()
{
for(SpriteMap::iterator it = sprites.begin(); it != sprites.end(); ++it)
for(std::map<int, ECSpriteBase*>::iterator sb = it->second.begin(); sb != it->second.end(); ++sb)
delete sb->second;
}
void ECPlayer::AddBreakPoint(BreakPoint bp)
{
assert(Channel()->Map()->ShowMap()->Window());
......
......@@ -24,6 +24,7 @@
#include "../lib/Channels.h"
#include "Map.h"
#include <map>
class EChannel;
......@@ -55,6 +56,8 @@ public:
*/
ECPlayer(std::string nick, EChannel* chan, bool owner, bool op, bool IsMe, bool IsIA);
~ECPlayer();
struct BreakPoint
{
BreakPoint(ECase* _c, std::string _message)
......@@ -90,11 +93,18 @@ public:
void AddBreakPoint(BreakPoint bp);
bool RemoveBreakPoint(ECBCase *c);
typedef std::map<ECBEntity::e_type, std::map<int, ECSpriteBase*> > SpriteMap;
SpriteMap Sprites() const { return sprites; }
ECSpriteBase* GetSprite(ECBEntity::e_type e, int id) { return sprites[e][id]; }
bool HasSprite(ECBEntity::e_type e, int id) { return sprites.find(e) != sprites.end() && sprites[e].find(id) != sprites[e].end(); }
void SetSprite(ECBEntity::e_type e, int id, ECSpriteBase* sb) { sprites[e][id] = sb; }
/* Variables privées */
private:
bool isme;
bool is_ia;
uint votes;
SpriteMap sprites;
std::vector<BreakPoint> breakpoints;
};
typedef std::vector<ECPlayer*> PlayerVector;
......
......@@ -152,6 +152,12 @@ ECEntity::~ECEntity()
delete attaq;
}
void ECEntity::Init()
{
ECBEntity::Init();
UpdateImages();
}
ECSpriteBase* ECEntity::DeadCase() const
{
return 0;
......@@ -382,6 +388,35 @@ void ECEntity::SetImage(ECSpriteBase* spr)
Map()->ShowMap()->Y() + (CASE_HEIGHT * Case()->Y()));
}
void ECEntity::SetOwner(ECBPlayer* player)
{
images.clear();
ECBEntity::SetOwner(player);
UpdateImages(); // Call the virtual method to update image list.
}
void ECEntity::PutImage(imgs_t i, ECSpriteBase* b)
{
if (Owner())
{
if(Owner()->HasSprite(Type(), i))
b = Owner()->GetSprite(Type(), i);
else
{
b = new ECSpriteBase(b->path.c_str());
Owner()->SetSprite(Type(), i, b);
}
}
images.insert(ImgList::value_type(i, b));
if(Owner() && Owner()->Color())
images[i]->ChangeColor(white_color, color_eq[Owner()->Color()]);
if(images.size() == 1) SetImage(b);
}
void ECEntity::ChangeCase(ECBCase* newcase)
{
if(newcase == Case()) return;
......
......@@ -95,6 +95,17 @@ class ECEntity : public virtual ECBEntity
/* Constructeur/Destructeur */
public:
enum imgs_t {
I_Up=ECMove::Up,
I_Down=ECMove::Down,
I_Left=ECMove::Left,
I_Right=ECMove::Right,
I_Attaq,
I_Deployed,
I_Reployed
};
typedef std::map<imgs_t, ECSpriteBase*> ImgList;
ECEntity();
ECEntity(const Entity_ID _name, ECBPlayer* _owner, ECBCase* _case);
......@@ -125,8 +136,6 @@ public:
virtual void ChangeCase(ECBCase* new_case);
virtual void RefreshColor(Color) = 0;
virtual void SetShowedCases(bool show, bool forced = false);
virtual void Played();
......@@ -146,6 +155,10 @@ public:
bool CanWalkTo(ECase* c, bool &move, bool &invest);
virtual void UpdateImages() = 0;
virtual void Init();
/* Attributs */
public:
......@@ -172,6 +185,9 @@ public:
ECase* Case() const;
ECPlayer* Owner() const;
virtual void SetOwner(ECBPlayer*);
ECase* AttaquedCase() const { return attaqued_case; }
void SetAttaquedCase(ECase* c);
......@@ -194,6 +210,11 @@ protected:
bool selected;
ECase* attaqued_case;
uint max_nb;
ImgList images;
void PutImage(imgs_t i, ECSpriteBase* b);
ECSpriteBase* GetSprite(imgs_t t) { return images[t]; }
};
/********************************************************************************************
......
......@@ -912,7 +912,6 @@ void TBarreEntity::SetEntity(ECEntity* e)
break;
}
}
entity->RefreshColor(last_color);
dynamic_cast<EMap*>(entity->Case()->Map())->CreatePreview(120,120,P_FRONTMER|P_ENTITIES);
}
}
......
......@@ -278,28 +278,6 @@ bool ECMissiLauncher::AfterEvent(const std::vector<ECEntity*>& entities, ECase*
* ECUnit *
********************************************************************************************/
void ECUnit::PutImage(imgs_t i, ECSpriteBase* b)
{
images.insert(ImgList::value_type(i, new ECSpriteBase(b->path.c_str())));
if(Owner() && Owner()->Color())
images[i]->ChangeColor(white_color, color_eq[Owner()->Color()]);
if(i == I_Down) SetImage(images[i]);
}
void ECUnit::RefreshColor(Color last)
{
for(ImgList::iterator it = images.begin(); it != images.end(); ++it)
it->second->ChangeColor(last, Owner() ? color_eq[Owner()->Color()] : white_color);
}
ECUnit::~ECUnit()
{
for(ImgList::iterator it = images.begin(); it != images.end(); ++it)
delete it->second;
}
bool ECUnit::BeforeEvent(const std::vector<ECEntity*>&, ECase*, EC_Client*)
{
if(EventType() & ARM_MOVE)
......
......@@ -39,23 +39,10 @@ class ECUnit : public ECEntity
/* Constructeur/Destructeur */
public:
enum imgs_t {
I_Up=ECMove::Up,
I_Down=ECMove::Down,
I_Left=ECMove::Left,
I_Right=ECMove::Right,
I_Attaq,
I_Deployed,
I_Reployed
};
typedef std::map<imgs_t, ECSpriteBase*> ImgList;
ECUnit() : visual_step(0) {}
ECUnit(uint vs, bool m = false) : move_anim(m), visual_step(vs) {}
virtual ~ECUnit();
/* Methodes */
public:
......@@ -65,23 +52,17 @@ public:
virtual bool AfterEvent(const std::vector<ECEntity*>&, ECase* c, EC_Client*);
void RefreshColor(Color last);
virtual void SetDeployed(bool d = true);
/* Mathodes prot��s */
/* Mathodes protégées */
protected:
bool MoveEffect(const std::vector<ECEntity*>&);
void PutImage(imgs_t, ECSpriteBase*);
ECSpriteBase* GetSprite(imgs_t t) { return images[t]; }
/* Variables prot��s */
/* Variables protégées */
private:
bool move_anim;
uint visual_step;
ImgList images;
};
/********************************************************************************************
......@@ -98,7 +79,9 @@ public:
: ECUnit(MISSILAUNCHER_VISUAL_STEP), missile(this, MISSILAUNCHER_MISSILE_STEP)
{}
ENTITY_CONSTRUCTOR(ECMissiLauncher), ECUnit(MISSILAUNCHER_VISUAL_STEP), missile(this, MISSILAUNCHER_MISSILE_STEP)
ENTITY_CONSTRUCTOR(ECMissiLauncher), ECUnit(MISSILAUNCHER_VISUAL_STEP), missile(this, MISSILAUNCHER_MISSILE_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::MissiLauncher_Dos());
PutImage(I_Down, Resources::MissiLauncher_Face());
......@@ -152,7 +135,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECTrain) {}
ENTITY_CONSTRUCTOR(ECTrain), ECUnit(TRAIN_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECTrain), ECUnit(TRAIN_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Train_Dos());
PutImage(I_Down, Resources::Train_Face());
......@@ -187,7 +172,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECBoat) {}
ENTITY_CONSTRUCTOR(ECBoat), ECUnit(BOAT_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECBoat), ECUnit(BOAT_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Boat_Dos());
PutImage(I_Down, Resources::Boat_Face());
......@@ -222,7 +209,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECPlane) {}
ENTITY_CONSTRUCTOR(ECPlane), ECUnit(PLANE_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECPlane), ECUnit(PLANE_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Plane_Dos());
PutImage(I_Down, Resources::Plane_Face());
......@@ -234,6 +223,12 @@ public:
SetImage(GetSprite(I_Deployed));
}
void Init()
{
ECEntity::Init();
ECBPlane::Init();
}
public:
virtual const char *Name() const { return _("Freighter"); }
virtual const char* Qual() const { return _("freighter"); }
......@@ -255,7 +250,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(EChar) {}
ENTITY_CONSTRUCTOR(EChar), ECUnit(CHAR_VISUAL_STEP, true)
ENTITY_CONSTRUCTOR(EChar), ECUnit(CHAR_VISUAL_STEP, true) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Char_Dos());
PutImage(I_Down, Resources::Char_Face());
......@@ -289,7 +286,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECJouano) {}
ENTITY_CONSTRUCTOR(ECJouano), ECUnit(JOUANO_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECJouano), ECUnit(JOUANO_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Jouano_Face());
PutImage(I_Down, Resources::Jouano_Face());
......@@ -347,7 +346,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECMcDo) : invested(ECEntity::E_NONE), ex_owner(0) {}
ENTITY_CONSTRUCTOR(ECMcDo), ECUnit(MCDO_VISUAL_STEP), invested(ECEntity::E_NONE), ex_owner(0)
ENTITY_CONSTRUCTOR(ECMcDo), ECUnit(MCDO_VISUAL_STEP), invested(ECEntity::E_NONE), ex_owner(0) {}
void UpdateImages()
{
PutImage(I_Up, Resources::McDo_Dos());
PutImage(I_Down, Resources::McDo_Face());
......@@ -409,7 +410,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECTourist) {}
ENTITY_CONSTRUCTOR(ECTourist), ECUnit(TOURIST_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECTourist), ECUnit(TOURIST_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Tourist_Dos());
PutImage(I_Down, Resources::Tourist_Face());
......@@ -447,7 +450,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECEnginer) {}
ENTITY_CONSTRUCTOR(ECEnginer), ECUnit(ENGINER_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECEnginer), ECUnit(ENGINER_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Enginer_Dos());
PutImage(I_Down, Resources::Enginer_Face());
......@@ -479,7 +484,9 @@ public:
ENTITY_EMPTY_CONSTRUCTOR(ECArmy) {}
ENTITY_CONSTRUCTOR(ECArmy), ECUnit(ARMY_VISUAL_STEP)
ENTITY_CONSTRUCTOR(ECArmy), ECUnit(ARMY_VISUAL_STEP) {}
void UpdateImages()
{
PutImage(I_Up, Resources::Army_Dos());
PutImage(I_Down, Resources::Army_Face());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment