From 2141fae61af1fd3f81d792910ffa35d672835523 Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 28 Jan 2009 14:24:22 +0000 Subject: Moved MapContent into header file. --- gameserver.cbp | 4 ++ src/game-server/mapcomposite.cpp | 142 +++++++-------------------------------- src/game-server/mapcomposite.hpp | 97 ++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 118 deletions(-) diff --git a/gameserver.cbp b/gameserver.cbp index 64bfb8a1..a2de9765 100644 --- a/gameserver.cbp +++ b/gameserver.cbp @@ -130,6 +130,10 @@ + + + + diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index 333d5ae7..b9e4b863 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -43,104 +43,6 @@ in dealing with zone changes. */ static int const zoneDiam = 256; -/** - * Part of a map. - */ -struct MapZone -{ - unsigned short nbCharacters, nbMovingObjects; - /** - * Objects present in this zone. - * Characters are stored first, then the remaining MovingObjects, then the - * remaining Objects. - */ - std::vector< Object * > objects; - - /** - * Destinations of the objects that left this zone. - * This is necessary in order to have an accurate iterator around moving - * objects. - */ - MapRegion destinations; - - MapZone(): nbCharacters(0), nbMovingObjects(0) {} - void insert(Object *); - void remove(Object *); -}; - -/** - * Pool of public IDs for MovingObjects on a map. By maintaining public ID - * availability using bits, it can locate an available public ID fast while - * using minimal memory access. - */ -struct ObjectBucket -{ - static int const int_bitsize = sizeof(unsigned) * 8; - unsigned bitmap[256 / int_bitsize]; /**< Bitmap of free locations. */ - short free; /**< Number of empty places. */ - short next_object; /**< Next object to look at. */ - MovingObject *objects[256]; - - ObjectBucket(); - int allocate(); - void deallocate(int); -}; - -/** - * Entities on a map. - */ -struct MapContent -{ - MapContent(Map *); - ~MapContent(); - - /** - * Allocates a unique ID for a moving object on this map. - */ - bool allocate(MovingObject *); - - /** - * Deallocates an ID. - */ - void deallocate(MovingObject *); - - /** - * Fills a region of zones within the range of a point. - */ - void fillRegion(MapRegion &, Point const &, int) const; - - /** - * Fills a region of zones inside a rectangle. - */ - void fillRegion(MapRegion &, Rectangle const &) const; - - /** - * Gets zone at given position. - */ - MapZone &getZone(Point const &pos) const - { return zones[(pos.x / zoneDiam) + (pos.y / zoneDiam) * mapWidth]; } - - /** - * Things (items, characters, monsters, etc) located on the map. - */ - std::vector< Thing * > things; - - /** - * Buckets of MovingObjects located on the map, referenced by ID. - */ - ObjectBucket *buckets[256]; - - int last_bucket; /**< Last bucket acted upon. */ - - /** - * Partition of the Objects, depending on their position on the map. - */ - MapZone *zones; - - unsigned short mapWidth; /**< Width with respect to zones. */ - unsigned short mapHeight; /**< Height with respect to zones. */ -}; - void MapZone::insert(Object *obj) { int type = obj->getType(); @@ -443,26 +345,6 @@ MapContent::~MapContent() delete[] zones; } -void MapComposite::setMap(Map *m) -{ - assert(!mMap && m); - mMap = m; - mContent = new MapContent(m); -} - - -MapComposite::MapComposite(int id, std::string const &name): - mMap(NULL), mContent(NULL), mScript(NULL), mName(name), mID(id) -{ -} - -MapComposite::~MapComposite() -{ - delete mMap; - delete mContent; - delete mScript; -} - bool MapContent::allocate(MovingObject *obj) { // First, try allocating from the last used bucket. @@ -538,6 +420,23 @@ void MapContent::fillRegion(MapRegion &r, Rectangle const &p) const } } +MapZone& MapContent::getZone(Point const &pos) const +{ + return zones[(pos.x / zoneDiam) + (pos.y / zoneDiam) * mapWidth]; +} + +MapComposite::MapComposite(int id, std::string const &name): + mMap(NULL), mContent(NULL), mScript(NULL), mName(name), mID(id) +{ +} + +MapComposite::~MapComposite() +{ + delete mMap; + delete mContent; + delete mScript; +} + ZoneIterator MapComposite::getAroundPointIterator(Point const &p, int radius) const { MapRegion r; @@ -628,6 +527,13 @@ void MapComposite::remove(Thing *ptr) assert(false); } +void MapComposite::setMap(Map *m) +{ + assert(!mMap && m); + mMap = m; + mContent = new MapContent(m); +} + void MapComposite::update() { for (int i = 0; i < mContent->mapHeight * mContent->mapWidth; ++i) diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp index 3f1225f0..078842d6 100644 --- a/src/game-server/mapcomposite.hpp +++ b/src/game-server/mapcomposite.hpp @@ -119,6 +119,103 @@ struct ObjectIterator operator bool() const { return iterator; } }; +/** + * Part of a map. + */ +struct MapZone +{ + unsigned short nbCharacters, nbMovingObjects; + /** + * Objects present in this zone. + * Characters are stored first, then the remaining MovingObjects, then the + * remaining Objects. + */ + std::vector< Object * > objects; + + /** + * Destinations of the objects that left this zone. + * This is necessary in order to have an accurate iterator around moving + * objects. + */ + MapRegion destinations; + + MapZone(): nbCharacters(0), nbMovingObjects(0) {} + void insert(Object *); + void remove(Object *); +}; + +/** + * Pool of public IDs for MovingObjects on a map. By maintaining public ID + * availability using bits, it can locate an available public ID fast while + * using minimal memory access. + */ +struct ObjectBucket +{ + static int const int_bitsize = sizeof(unsigned) * 8; + unsigned bitmap[256 / int_bitsize]; /**< Bitmap of free locations. */ + short free; /**< Number of empty places. */ + short next_object; /**< Next object to look at. */ + MovingObject *objects[256]; + + ObjectBucket(); + int allocate(); + void deallocate(int); +}; + +/** + * Entities on a map. + */ +struct MapContent +{ + MapContent(Map *); + ~MapContent(); + + /** + * Allocates a unique ID for a moving object on this map. + */ + bool allocate(MovingObject *); + + /** + * Deallocates an ID. + */ + void deallocate(MovingObject *); + + /** + * Fills a region of zones within the range of a point. + */ + void fillRegion(MapRegion &, Point const &, int) const; + + /** + * Fills a region of zones inside a rectangle. + */ + void fillRegion(MapRegion &, Rectangle const &) const; + + /** + * Gets zone at given position. + */ + MapZone &getZone(Point const &pos) const; + + /** + * Things (items, characters, monsters, etc) located on the map. + */ + std::vector< Thing * > things; + + /** + * Buckets of MovingObjects located on the map, referenced by ID. + */ + ObjectBucket *buckets[256]; + + int last_bucket; /**< Last bucket acted upon. */ + + /** + * Partition of the Objects, depending on their position on the map. + */ + MapZone *zones; + + unsigned short mapWidth; /**< Width with respect to zones. */ + unsigned short mapHeight; /**< Height with respect to zones. */ +}; + /** * Combined map/entity structure. */ -- cgit v1.2.3-60-g2f50