Shadowrun: Awakened 29 September 2011 - Build 871
GridSectorizer.h
Go to the documentation of this file.
00001 #ifndef _GRID_SECTORIZER_H
00002 #define _GRID_SECTORIZER_H
00003 
00004 //#define _USE_ORDERED_LIST
00005 
00006 #include "RakMemoryOverride.h"
00007 
00008 #ifdef _USE_ORDERED_LIST
00009 #include "DS_OrderedList.h"
00010 #else
00011 #include "DS_List.h"
00012 #endif
00013 
00014 class GridSectorizer
00015 {
00016 public:
00017     GridSectorizer();
00018     ~GridSectorizer();
00019 
00020     // _cellWidth, _cellHeight is the width and height of each cell in world units
00021     // minX, minY, maxX, maxY are the world dimensions (can be changed to dynamically allocate later if needed)
00022     void Init(const float _maxCellWidth, const float _maxCellHeight, const float minX, const float minY, const float maxX, const float maxY);
00023 
00024     // Adds a pointer to the grid with bounding rectangle dimensions
00025     void AddEntry(void *entry, const float minX, const float minY, const float maxX, const float maxY);
00026 
00027 #ifdef _USE_ORDERED_LIST
00028 
00029     // Removes a pointer, as above
00030     void RemoveEntry(void *entry, const float minX, const float minY, const float maxX, const float maxY);
00031 
00032     // Adds and removes in one pass, more efficient than calling both functions consecutively
00033     void MoveEntry(void *entry, const float sourceMinX, const float sourceMinY, const float sourceMaxX, const float sourceMaxY,
00034         const float destMinX, const float destMinY, const float destMaxX, const float destMaxY);
00035 
00036 #endif
00037 
00038     // Adds to intersectionList all entries in a certain radius
00039     void GetEntries(DataStructures::List<void*>& intersectionList, const float minX, const float minY, const float maxX, const float maxY);
00040 
00041     void Clear(void);
00042 
00043 protected:
00044     int WorldToCellX(const float input) const;
00045     int WorldToCellY(const float input) const;
00046     int WorldToCellXOffsetAndClamped(const float input) const;
00047     int WorldToCellYOffsetAndClamped(const float input) const;
00048 
00049     // Returns true or false if a position crosses cells in the grid.  If false, you don't need to move entries
00050     bool PositionCrossesCells(const float originX, const float originY, const float destinationX, const float destinationY) const;
00051 
00052     float cellOriginX, cellOriginY;
00053     float cellWidth, cellHeight;
00054     float invCellWidth, invCellHeight;
00055     float gridWidth, gridHeight;
00056     int gridCellWidthCount, gridCellHeightCount;
00057 
00058 
00059     // int gridWidth, gridHeight;
00060 
00061 #ifdef _USE_ORDERED_LIST
00062     DataStructures::OrderedList<void*, void*>* grid;
00063 #else
00064     DataStructures::List<void*>* grid;
00065 #endif
00066 };
00067 
00068 #endif

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net