r135 - trunk/src
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Sep 1 14:57:06 EDT 2005
Author: jonas
Date: 2005-09-01 14:57:06 -0400 (Thu, 01 Sep 2005)
New Revision: 135
Modified:
trunk/src/objectpools.cpp
trunk/src/objectpools.h
trunk/src/objects_common.cpp
trunk/src/objects_common.h
trunk/src/scenario.cpp
trunk/src/scenario.h
Log:
added a comparsion function to put a proper ordering on the pools: the numbers of created objects so far. This can be used as an id as well.
Modified: trunk/src/objectpools.cpp
===================================================================
--- trunk/src/objectpools.cpp 2005-09-01 18:33:45 UTC (rev 134)
+++ trunk/src/objectpools.cpp 2005-09-01 18:57:06 UTC (rev 135)
@@ -30,6 +30,11 @@
#include "objects/zombie.h"
+bool Compare::operator()(const Object* obj1, const Object* obj2) {
+ if (obj1->onum<obj2->onum) return true;
+ else return false;
+}
+
ObjectsPool::ObjectsPool():
currentplayer(playerspool.begin()),
au_switch(sndcache->loadWAV("newchar.wav")) { }
Modified: trunk/src/objectpools.h
===================================================================
--- trunk/src/objectpools.h 2005-09-01 18:33:45 UTC (rev 134)
+++ trunk/src/objectpools.h 2005-09-01 18:57:06 UTC (rev 135)
@@ -1,6 +1,10 @@
#ifndef DEF_OBJECTPOOLS_H
#define DEF_OBJECTPOOLS_H 1
+struct Compare {
+ bool operator()(const Object*, const Object*);
+};
+
/** \brief Container for objects.
Contains a pool for each important derived object class,
@@ -69,19 +73,19 @@
///\brief Object pool
///
/// Contains all objects managed by the ObjectsPool
- std::set<Object *> objectspool;
+ std::set<Object *,Compare> objectspool;
///\brief Character pool
///
/// Contains all characters managed by the ObjectsPool
- std::set<Character *> characterspool;
+ std::set<Character *,Compare> characterspool;
///\brief Player pool
///
/// Contains all players managed by the ObjectsPool
- std::set<Player *> playerspool;
+ std::set<Player *,Compare> playerspool;
///\brief Monster pool
///
/// Contains all monsters managed by the ObjectsPool
- std::set<Monster *> monsterspool;
+ std::set<Monster *,Compare> monsterspool;
//@}
private:
//player number of the currently selected player
Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp 2005-09-01 18:33:45 UTC (rev 134)
+++ trunk/src/objects_common.cpp 2005-09-01 18:57:06 UTC (rev 135)
@@ -8,7 +8,6 @@
Object::Object(string imagename, Sint16 xcord, Sint16 ycord, string oname):
- tbirth(SDL_GetTicks()),
state(NOTHING),
event(NULL),
im_orig(new Animation(scenario->imgcache->loadImage(imagename))),
@@ -24,6 +23,7 @@
curpos.h=pos.h;
curpos.x=0;
curpos.y=0;
+ onum=++scenario->max_obj_num;
}
Object::~Object() {
@@ -31,6 +31,11 @@
if (!(otype&OTYPE_CHARACTER)) delete animation;
}
+bool Object::operator<(const Object& obj) const {
+ if (onum<obj.onum) return true;
+ else return false;
+}
+
bool Object::isIn(const SDL_Rect& rect, bool touch) {
if (touch) {
if ((pos.x+pos.w) > rect.x && pos.x < (rect.x+rect.w) && (pos.y+pos.h) > rect.y && pos.y < (rect.y+rect.h)) return true;
Modified: trunk/src/objects_common.h
===================================================================
--- trunk/src/objects_common.h 2005-09-01 18:33:45 UTC (rev 134)
+++ trunk/src/objects_common.h 2005-09-01 18:57:06 UTC (rev 135)
@@ -163,8 +163,9 @@
/// \remark This should be called downwards by all derived classes
virtual void idle(Uint16) { }
//@}
+ bool operator<(const Object& obj) const;
+ Uint32 onum;
protected:
- Uint16 tbirth;
Uint32 state;
Event* event;
Animation* im_orig;
Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp 2005-09-01 18:33:45 UTC (rev 134)
+++ trunk/src/scenario.cpp 2005-09-01 18:57:06 UTC (rev 135)
@@ -23,6 +23,7 @@
physic=new PhysicHandler();
cout << "Map: ObjectsPool...\n";
pool=new ObjectsPool();
+ max_obj_num=0;
}
Scenario::~Scenario() {
@@ -50,6 +51,7 @@
background=NULL;
area=NULL;
player=NULL;
+ max_obj_num=0;
}
void Scenario::newMap(string bgimage) {
Modified: trunk/src/scenario.h
===================================================================
--- trunk/src/scenario.h 2005-09-01 18:33:45 UTC (rev 134)
+++ trunk/src/scenario.h 2005-09-01 18:57:06 UTC (rev 135)
@@ -80,6 +80,8 @@
/// Name of the map background image
string bgimage;
std::vector<string> mapbuf;
+ /// The number of created objects
+ Uint32 max_obj_num;
private:
inline void reinitMap();
};
More information about the lostpenguins-commits
mailing list