summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2006-02-19 01:48:04 +0000
committerYohann Ferreira <bertram@cegetel.net>2006-02-19 01:48:04 +0000
commit9952ec8092599a5142adae48e050539aaa7c94d9 (patch)
treeffa69458e3dda4a6b5b92e851e326aec9c373137 /src
parenta980a18bee10ca9cd635b404425c66f66bba6edc (diff)
downloadmanaserv-9952ec8092599a5142adae48e050539aaa7c94d9.tar.gz
manaserv-9952ec8092599a5142adae48e050539aaa7c94d9.tar.bz2
manaserv-9952ec8092599a5142adae48e050539aaa7c94d9.tar.xz
manaserv-9952ec8092599a5142adae48e050539aaa7c94d9.zip
Made use of counted pointer for objects, just the way it is for beings.
Diffstat (limited to 'src')
-rw-r--r--src/object.h16
-rw-r--r--src/state.cpp24
-rw-r--r--src/state.h10
3 files changed, 29 insertions, 21 deletions
diff --git a/src/object.h b/src/object.h
index fbc49cd8..b8640285 100644
--- a/src/object.h
+++ b/src/object.h
@@ -24,15 +24,14 @@
#ifndef _TMWSERV_OBJECT_H_
#define _TMWSERV_OBJECT_H_
-
#include <utility>
#include <string>
-
+#include <vector>
+#include "utils/countedptr.h"
namespace tmwserv
{
-
/**
* Structure type for the statistics.
*
@@ -52,7 +51,6 @@ struct Statistics
int speed;
};
-
/**
* Generic in-game object definition.
* Base class for in-game objects.
@@ -179,6 +177,16 @@ class Object
unsigned int mMapId; /**< id of the map being is on */
};
+/**
+ * Type definition for a smart pointer to Object.
+ */
+typedef utils::CountedPtr<Object> ObjectPtr;
+
+
+/**
+ * Type definition for a list of Objects.
+ */
+typedef std::vector<ObjectPtr> Objects;
} // namespace tmwserv
diff --git a/src/state.cpp b/src/state.cpp
index cb9a9e22..75dae62e 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -145,23 +145,23 @@ bool State::loadMap(const unsigned int mapId) {
return true; // We let true for testing on beings
}
-void State::addObject(Object *object, const unsigned int mapId) {
- if (!objectExists(object)) {
+void State::addObject(ObjectPtr objectPtr, const unsigned int mapId) {
+ if (!objectExists(objectPtr)) {
if (!mapExists(mapId))
if (!loadMap(mapId))
return;
- maps[mapId].objects.push_back(object);
+ maps[mapId].objects.push_back(objectPtr);
}
}
-void State::removeObject(Object *object) {
+void State::removeObject(ObjectPtr objectPtr) {
for (std::map<unsigned int, MapComposite>::iterator i = maps.begin();
i != maps.end();
i++) {
- for (std::vector<Object*>::iterator b = i->second.objects.begin();
+ for (Objects::iterator b = i->second.objects.begin();
b != i->second.objects.end();
b++) {
- if (*b == object) {
+ if (b->get() == objectPtr.get()) {
i->second.objects.erase(b);
return;
}
@@ -169,14 +169,14 @@ void State::removeObject(Object *object) {
}
}
-bool State::objectExists(const Object *object) {
+bool State::objectExists(const ObjectPtr objectPtr) {
for (std::map<unsigned int, MapComposite>::iterator i = maps.begin();
i != maps.end();
i++) {
- for (std::vector<Object*>::iterator b = i->second.objects.begin();
+ for (Objects::iterator b = i->second.objects.begin();
b != i->second.objects.end();
b++) {
- if (*b == object)
+ if (b->get() == objectPtr.get())
return true;
}
}
@@ -197,14 +197,14 @@ const unsigned int State::findPlayer(BeingPtr beingPtr) {
return 0;
}
-const unsigned int State::findObject(Object *object) {
+const unsigned int State::findObject(ObjectPtr objectPtr) {
for (std::map<unsigned int, MapComposite>::iterator i = maps.begin();
i != maps.end();
i++) {
- for (std::vector<Object*>::iterator b = i->second.objects.begin();
+ for (Objects::iterator b = i->second.objects.begin();
b != i->second.objects.end();
b++) {
- if (*b == object)
+ if (b->get() == objectPtr.get())
return i->first;
}
}
diff --git a/src/state.h b/src/state.h
index bc6d3331..ba32bdcd 100644
--- a/src/state.h
+++ b/src/state.h
@@ -56,7 +56,7 @@ struct MapComposite {
/**
* Items located on the map
*/
- std::vector<Object*> objects;
+ Objects objects;
};
/**
@@ -110,17 +110,17 @@ class State : public utils::Singleton<State>
/**
* Add object to the map
*/
- void addObject(Object *object, const unsigned int mapId);
+ void addObject(ObjectPtr objectPtr, const unsigned int mapId);
/**
* Remove an object from the map
*/
- void removeObject(Object *object);
+ void removeObject(ObjectPtr objectPtr);
/**
* Find out whether an object exists in the game world or not
*/
- bool objectExists(const Object *object);
+ bool objectExists(const ObjectPtr objectPtr);
/**
* Find map player in world is on
@@ -130,7 +130,7 @@ class State : public utils::Singleton<State>
/**
* Find map object in world is on
*/
- const unsigned int findObject(Object *object);
+ const unsigned int findObject(ObjectPtr objectPtr);
};
} // namespace tmwserv