NL3D::CZoneManager Class Reference

#include <zone_manager.h>

Inheritance diagram for NL3D::CZoneManager:

NL3D::CZoneSearch

Detailed Description

CZoneManager is a class that manage zone loading around of player
Author:
Alain Saffray

Nevrax France

Date:
2000 sa See Also, CZoneSearch, CTaskManager

Definition at line 52 of file zone_manager.h.

Public Member Functions

void checkZonesAround (uint x, uint y, uint area)
void clear ()
 Remove all zones.

 CZoneManager ()
 Constructor.

void getListZoneId (uint x, uint y, uint sizeArea, std::vector< uint16 > &l)
void getListZoneName (uint x, uint y, uint sizeArea, std::list< std::pair< std::string, uint32 > > &l)
uint getNumZoneLeftToLoad ()
 Return the count of zone left to load.

uint16 getZoneId (uint x, uint y) const
std::pair< std::string, uint32getZoneName (uint x, uint y, uint cx, uint cy)
std::string getZoneNameFromId (uint16 zoneid)
std::string getZonePath (void)
 getZonePath : Get Path for zone loading

void getZonePos (uint16 zoneId, uint &x, uint &y) const
bool isLoading () const
 Does the manager is loading ?

bool isRemoving () const
 Does the manager is removing ?

bool isWorkComplete (SZoneManagerWork &rWork)
 Is a work has been completed ?

void setZonePath (std::string zonePath)
 setZonePath : Set Path for zone loading

void setZoneTileColor (bool monochrome, float factor)
 set the zone tile color (if false tile are monochromed with the tile color)

 ~CZoneManager ()
 Destructor.


Private Attributes

uint16 _IdZoneToRemove
uint32 _LastX
uint32 _LastY
std::vector< uint16_LoadedZones
std::list< CLoadingZone_LoadingZones
bool _RemovingZone
std::vector< uint16_ZoneList
std::string _zonePath
 Path for zone loading.

float _ZoneTileColorFactor
bool _ZoneTileColorMono


Constructor & Destructor Documentation

NL3D::CZoneManager::CZoneManager  ) 
 

Constructor.

Definition at line 46 of file zone_manager.cpp.

References _RemovingZone, _ZoneTileColorFactor, and _ZoneTileColorMono.

00047 {
00048         _RemovingZone= false;
00049         _ZoneTileColorMono = true;
00050         _ZoneTileColorFactor = 1.0f;
00051 }

NL3D::CZoneManager::~CZoneManager  ) 
 

Destructor.

Definition at line 54 of file zone_manager.cpp.

00055 {
00056 }


Member Function Documentation

void NL3D::CZoneManager::checkZonesAround uint  x,
uint  y,
uint  area
 

checkZonesAround : Add/Remove all zomes around a certain point If a work is currently completed remove it and began another one

Definition at line 80 of file zone_manager.cpp.

References _IdZoneToRemove, _LastY, _LoadedZones, _LoadingZones, _RemovingZone, _ZoneList, _ZoneTileColorFactor, _ZoneTileColorMono, NLMISC::CTaskManager::addTask(), NL3D::CZoneSearch::getListZoneId(), NL3D::CZoneSearch::getZoneNameFromId(), NL3D::CZoneSearch::getZonePos(), uint, uint16, uint32, v, x, y, NL3D::CZoneManager::CLoadingZone::Zone, NL3D::CZoneManager::CLoadingZone::ZoneToAddId, and NL3D::CZoneManager::CLoadingZone::ZoneToAddName.

Referenced by NL3D::CLandscapeUser::loadAllZonesAround(), NL3D::CLandscapeUser::refreshAllZonesAround(), and NL3D::CLandscapeUser::refreshZonesAround().

00081 {
00082         if (_RemovingZone) return;
00083 
00084         // Obtain the new set of zones around
00085         if ((x != _LastX) || (y != _LastY))
00086                 getListZoneId (x, y, area, _ZoneList);
00087         _LastX = x;
00088         _LastY = y;
00089 
00090         // Look if we have zone loaded that is not needed anymore
00091         uint32 i, j;
00092         for (i = 0; i < _LoadedZones.size(); ++i)
00093         {
00094                 // If the loadedzone i do not appear in the zone list so we have to remove it
00095                 bool bFound = false;
00096                 uint16 nLoadedZone = _LoadedZones[i];
00097                 for (j = 0; j < _ZoneList.size(); ++j)
00098                 {
00099                         if (_ZoneList[j] == nLoadedZone)
00100                         {
00101                                 bFound = true;
00102                                 break;
00103                         }
00104                 }
00105 
00106                 if (!bFound)
00107                 {
00108                         // Remove the zone nLoadedZone
00109                         _IdZoneToRemove = nLoadedZone;
00110                         _RemovingZone = true;
00111                         return;
00112                 }
00113         }
00114 
00115         // Look if we have zone not already loaded
00116         for (i = 0; i < _ZoneList.size(); ++i)
00117         {
00118                 // If the zone requested do not appear in the zone loaded list so we have to load it
00119                 bool bFound = false;
00120                 uint16 nZone = _ZoneList[i];
00121                 for (j = 0; j < _LoadedZones.size(); ++j)
00122                 {
00123                         if (_LoadedZones[j] == nZone)
00124                         {
00125                                 bFound = true;
00126                                 break;
00127                         }
00128                 }
00129 
00130                 if (!bFound)
00131                 {
00132                         // Already loading ?
00133                         std::list<CLoadingZone>::iterator ite = _LoadingZones.begin ();
00134                         while (ite != _LoadingZones.end())
00135                         {
00136                                 if (ite->ZoneToAddId == nZone)
00137                                         break;
00138 
00139                                 // Next loading zone
00140                                 ite++;
00141                         }
00142 
00143                         // Not loading ?
00144                         if (ite == _LoadingZones.end())
00145                         {
00146                                 // Add a new zone to load
00147                                 _LoadingZones.push_back(CLoadingZone ());
00148                                 CLoadingZone &newZone = _LoadingZones.back();
00149                                 newZone.ZoneToAddName = getZoneNameFromId(nZone);
00150                                 newZone.ZoneToAddId = nZone;
00151                                 newZone.Zone = NULL;
00152                                 
00153                                 // We have to load this zone ! and return because only one load at a time
00154                                 CAsyncFileManager &rAFM = CAsyncFileManager::getInstance();
00155 
00156                                 // Make a position
00157                                 uint x, y;
00158                                 getZonePos (newZone.ZoneToAddId, x, y);
00159 //                              rAFM.addTask (new CZoneLoadingTask(newZone.ZoneToAddName, &newZone.Zone, CVector ((float)x, -(float)y, 0)));
00160                                 CVector v = CVector ((float)x, -(float)y, 0);
00161                                 rAFM.addTask (new CZoneLoadingTask(newZone.ZoneToAddName, &newZone.Zone, v, _ZoneTileColorMono, _ZoneTileColorFactor));
00162                         }
00163                 }
00164         }
00165 }

void NL3D::CZoneManager::clear  ) 
 

Remove all zones.

Definition at line 220 of file zone_manager.cpp.

References _LoadedZones, _LoadingZones, _RemovingZone, and nlassert.

Referenced by NL3D::CLandscapeUser::removeAllZones().

00221 {
00222         nlassert(_LoadingZones.size() == 0);
00223         _LoadedZones.clear();
00224         _RemovingZone = false;
00225 }

void NL3D::CZoneSearch::getListZoneId uint  x,
uint  y,
uint  sizeArea,
std::vector< uint16 > &  l
[inherited]
 

Definition at line 158 of file zone_search.cpp.

References NL3D::CZoneSearch::_NbZoneX, NL3D::CZoneSearch::_NbZoneY, NL3D::CZoneSearch::_SizeZoneX, NL3D::CZoneSearch::_SizeZoneY, NL3D::CZoneSearch::getZoneId(), sint, uint, x, and y.

Referenced by checkZonesAround().

00159 {
00160         sint startPosX, startPosY;
00161         uint lastPosX, lastPosY, sizeAreaX, sizeAreaY;
00162 
00163         startPosX = x - sizeArea;
00164         startPosY = y - sizeArea;
00165 
00166         sizeArea += sizeArea;
00167         sizeAreaX = sizeAreaY = sizeArea;
00168 
00169         if(startPosX < 0)
00170         {
00171                 sizeAreaX += startPosX;
00172                 startPosX = 0;
00173         }
00174 
00175         lastPosX = startPosX + sizeAreaX;
00176         if(lastPosX >= (_NbZoneX * _SizeZoneX))
00177         {
00178                 sizeAreaX -= _NbZoneX * _SizeZoneX - lastPosX;
00179                 lastPosX = _NbZoneX * _SizeZoneX - 1;
00180         }
00181 
00182         if(startPosY < 0)
00183         {
00184                 sizeAreaY += startPosY;
00185                 startPosY = 0;
00186         }
00187 
00188         lastPosY = startPosY + sizeAreaY;
00189         if(lastPosY >= (_NbZoneY * _SizeZoneY))
00190         {
00191                 sizeAreaY -= _NbZoneY * _SizeZoneY - lastPosY;
00192                 lastPosY = _NbZoneY * _SizeZoneY - 1;
00193         }
00194 
00195         l.clear();
00196 
00197         for(uint i = startPosY; i <= lastPosY; i += _SizeZoneY)
00198         {
00199                 for(uint j = startPosX; j <= lastPosX; j += _SizeZoneX)
00200                 {
00201                         l.push_back(getZoneId(j, i));
00202                 }
00203         }
00204 }

void NL3D::CZoneSearch::getListZoneName uint  x,
uint  y,
uint  sizeArea,
std::list< std::pair< std::string, uint32 > > &  l
[inherited]
 

Definition at line 96 of file zone_search.cpp.

References NL3D::CZoneSearch::_NbZoneX, NL3D::CZoneSearch::_NbZoneY, NL3D::CZoneSearch::_SizeZoneX, NL3D::CZoneSearch::_SizeZoneY, NL3D::CZoneSearch::getZoneName(), sint, uint, x, and y.

00097 {
00098         sint startPosX, startPosY;
00099         uint lastPosX, lastPosY, sizeAreaX, sizeAreaY;
00100 
00101         startPosX = x - sizeArea;
00102         startPosY = y - sizeArea;
00103 
00104         sizeArea += sizeArea;
00105         sizeAreaX = sizeAreaY = sizeArea;
00106 
00107         if(startPosX < 0)
00108         {
00109                 sizeAreaX += startPosX;
00110                 startPosX = 0;
00111         }
00112 
00113         lastPosX = startPosX + sizeAreaX;
00114         if(lastPosX >= (_NbZoneX * _SizeZoneX))
00115         {
00116                 sizeAreaX -= _NbZoneX * _SizeZoneX - lastPosX;
00117                 lastPosX = _NbZoneX * _SizeZoneX - 1;
00118         }
00119 
00120         if(startPosY < 0)
00121         {
00122                 sizeAreaY += startPosY;
00123                 startPosY = 0;
00124         }
00125 
00126         lastPosY = startPosY + sizeAreaY;
00127         if(lastPosY >= (_NbZoneY * _SizeZoneY))
00128         {
00129                 sizeAreaY -= _NbZoneY * _SizeZoneY - lastPosY;
00130                 lastPosY = _NbZoneY * _SizeZoneY - 1;
00131         }
00132 
00133         l.clear();
00134 
00135         for(uint i = startPosY; i <= lastPosY; i += _SizeZoneY)
00136         {
00137                 for(uint j = startPosX; j <= lastPosX; j += _SizeZoneX)
00138                 {
00139                         l.push_back(getZoneName(j, i, x, y));
00140                 }
00141         }
00142 }

uint NL3D::CZoneManager::getNumZoneLeftToLoad  ) 
 

Return the count of zone left to load.

Definition at line 59 of file zone_manager.cpp.

References _LoadedZones, _ZoneList, uint, and uint32.

Referenced by NL3D::CLandscapeUser::refreshAllZonesAround().

00060 {
00061         // Make a set of the loaded zone
00062         set<uint16> zoneLoaded;
00063         uint32 i;
00064         for (i = 0; i < _LoadedZones.size(); ++i)
00065         {
00066                 zoneLoaded.insert (_LoadedZones[i]);
00067         }
00068 
00069         // Check for each zone in the list if they are loaded or not
00070         uint zoneCount = 0;
00071         for (i = 0; i < _ZoneList.size(); ++i)
00072         {
00073                 if (zoneLoaded.find (_ZoneList[i]) == zoneLoaded.end ())
00074                         zoneCount++;
00075         }
00076         return zoneCount;
00077 }

uint16 NL3D::CZoneSearch::getZoneId uint  x,
uint  y
const [inherited]
 

Definition at line 144 of file zone_search.cpp.

References NL3D::CZoneSearch::_SizeZoneX, NL3D::CZoneSearch::_SizeZoneY, uint, uint16, x, and y.

Referenced by NL3D::CZoneSearch::getListZoneId().

00145 {
00146         uint zoneY = y / _SizeZoneY;
00147         uint zoneX = x / _SizeZoneX;
00148         
00149         return (zoneX&255)+(zoneY<<8);
00150 }

pair< string, uint32 > NL3D::CZoneSearch::getZoneName uint  x,
uint  y,
uint  cx,
uint  cy
[inherited]
 

Get the zone name corresponding to coordinate

Parameters:
x is axis X coordinate (in meters)
y is axis Y coordinate (in meters)
cx is axis X coordinate of center area (in meters)
cy is axis Y coordinate of center area (in meters)
Returns:
a pair of the zone name and square distance between zone and center area (in zone unit)

Definition at line 67 of file zone_search.cpp.

References NL3D::CZoneSearch::_SizeZoneX, NL3D::CZoneSearch::_SizeZoneY, uint, uint32, x, and y.

Referenced by NL3D::CZoneSearch::getListZoneName(), and NL3D::CLandscapeUser::getZoneName().

00068 {
00069         char name[13];
00070 
00071         uint zoneY = y / _SizeZoneY + 1;
00072         uint zoneX = x / _SizeZoneX;
00073 
00074         uint zoneCenterY = cy / _SizeZoneY + 1;
00075         uint zoneCenterX = cx / _SizeZoneX;
00076 
00077         uint32 distance = (zoneX - zoneCenterX) * (zoneX - zoneCenterX) + (zoneY - zoneCenterY) * (zoneY - zoneCenterY);
00078 
00079         char firstLetter = zoneX / 26 + 'A';
00080         char secondLetter = zoneX % 26 + 'A';
00081 
00082         sprintf(name, "%d_%c%c.zonel", zoneY, firstLetter, secondLetter);
00083 
00084         return make_pair<string, uint32>(string(name), distance);
00085 }

std::string NL3D::CZoneSearch::getZoneNameFromId uint16  zoneid  )  [inherited]
 

Definition at line 206 of file zone_search.cpp.

References sint, uint16, x, and y.

Referenced by checkZonesAround(), and isWorkComplete().

00207 {
00208         char name[16];
00209 
00210         sint    x = zoneid & 255;
00211         sint    y = zoneid >> 8;
00212         sprintf (name, "%d_%c%c.zonel", y+1, (char)('A'+(x/26)), (char)('A'+(x%26)));
00213         return string(name);
00214 }

std::string NL3D::CZoneManager::getZonePath void   )  [inline]
 

getZonePath : Get Path for zone loading

Definition at line 112 of file zone_manager.h.

References _zonePath.

00112 { return _zonePath; }

void NL3D::CZoneSearch::getZonePos uint16  zoneId,
uint x,
uint y
const [inherited]
 

Definition at line 152 of file zone_search.cpp.

References NL3D::CZoneSearch::_SizeZoneY, uint, uint16, x, and y.

Referenced by checkZonesAround().

00153 {
00154         x = _SizeZoneY*(zoneId&255);
00155         y = _SizeZoneY*(zoneId>>8);     
00156 }

bool NL3D::CZoneManager::isLoading  )  const [inline]
 

Does the manager is loading ?

Definition at line 93 of file zone_manager.h.

References _LoadingZones.

Referenced by NL3D::CLandscapeUser::loadAllZonesAround(), NL3D::CLandscapeUser::refreshAllZonesAround(), and NL3D::CLandscapeUser::removeAllZones().

00093 {return _LoadingZones.size () != 0;}

bool NL3D::CZoneManager::isRemoving  )  const [inline]
 

Does the manager is removing ?

Definition at line 96 of file zone_manager.h.

References _RemovingZone.

Referenced by NL3D::CLandscapeUser::refreshAllZonesAround().

00096 {return _RemovingZone;}

bool NL3D::CZoneManager::isWorkComplete SZoneManagerWork rWork  ) 
 

Is a work has been completed ?

Definition at line 168 of file zone_manager.cpp.

References _IdZoneToRemove, _LoadedZones, _LoadingZones, _RemovingZone, NL3D::CZoneSearch::getZoneNameFromId(), NL3D::CZoneManager::SZoneManagerWork::IdZoneToRemove, NL3D::CZoneManager::SZoneManagerWork::NameZoneAdded, NL3D::CZoneManager::SZoneManagerWork::NameZoneRemoved, uint32, NL3D::CZoneManager::SZoneManagerWork::Zone, NL3D::CZoneManager::SZoneManagerWork::ZoneAdded, and NL3D::CZoneManager::SZoneManagerWork::ZoneRemoved.

Referenced by NL3D::CLandscapeUser::loadAllZonesAround(), NL3D::CLandscapeUser::refreshZonesAround(), and NL3D::CLandscapeUser::removeAllZones().

00169 {
00170         // Check if there is someting to add
00171         std::list<CLoadingZone>::iterator ite = _LoadingZones.begin ();
00172         while (ite != _LoadingZones.end())
00173         {
00174                 // Loaded ?
00175                 if (ite->Zone)
00176                 {
00177                         rWork.ZoneAdded = true;
00178                         rWork.NameZoneAdded = ite->ZoneToAddName;
00179                         rWork.ZoneRemoved = false;
00180                         rWork.IdZoneToRemove = 0;
00181                         rWork.NameZoneRemoved = "";
00182                         rWork.Zone = const_cast<CZone*>(ite->Zone);
00183                         _LoadedZones.push_back (ite->ZoneToAddId);
00184 
00185                         // Remove from loading zone
00186                         _LoadingZones.erase(ite);
00187                         return true;
00188                 }
00189 
00190                 // Next zone
00191                 ite++;
00192         }
00193 
00194         if (_RemovingZone)
00195         {
00196                 _RemovingZone = false;
00197                 rWork.ZoneAdded = false;
00198                 rWork.NameZoneAdded = "";
00199                 rWork.ZoneRemoved = true;
00200                 rWork.IdZoneToRemove = _IdZoneToRemove;
00201                 rWork.NameZoneRemoved = getZoneNameFromId(_IdZoneToRemove);
00202                 uint32 i, j;
00203                 for (i = 0 ; i < _LoadedZones.size(); ++i)
00204                         if (_LoadedZones[i] == _IdZoneToRemove)
00205                                 break;
00206                 if (i < _LoadedZones.size())
00207                 {
00208                         for (j = i; j < _LoadedZones.size()-1; ++j)
00209                                 _LoadedZones[j] = _LoadedZones[j+1];
00210                         _LoadedZones.resize(_LoadedZones.size()-1);
00211                 }
00212                 rWork.Zone = NULL;
00213                 return true;
00214         }
00215 
00216         return false;
00217 }

void NL3D::CZoneManager::setZonePath std::string  zonePath  )  [inline]
 

setZonePath : Set Path for zone loading

Accessors

Definition at line 109 of file zone_manager.h.

References _zonePath.

00109 { _zonePath = zonePath; }

void NL3D::CZoneManager::setZoneTileColor bool  monochrome,
float  factor
[inline]
 

set the zone tile color (if false tile are monochromed with the tile color)

Definition at line 115 of file zone_manager.h.

References _ZoneTileColorFactor, and _ZoneTileColorMono.

Referenced by NL3D::CLandscapeUser::setTileColor().

00115 { _ZoneTileColorMono = monochrome; _ZoneTileColorFactor = factor; }


Field Documentation

uint16 NL3D::CZoneManager::_IdZoneToRemove [private]
 

Definition at line 150 of file zone_manager.h.

Referenced by checkZonesAround(), and isWorkComplete().

uint32 NL3D::CZoneManager::_LastX [private]
 

Definition at line 129 of file zone_manager.h.

uint32 NL3D::CZoneManager::_LastY [private]
 

Definition at line 129 of file zone_manager.h.

Referenced by checkZonesAround().

std::vector<uint16> NL3D::CZoneManager::_LoadedZones [private]
 

Definition at line 126 of file zone_manager.h.

Referenced by checkZonesAround(), clear(), getNumZoneLeftToLoad(), and isWorkComplete().

std::list<CLoadingZone> NL3D::CZoneManager::_LoadingZones [private]
 

Definition at line 146 of file zone_manager.h.

Referenced by checkZonesAround(), clear(), isLoading(), and isWorkComplete().

bool NL3D::CZoneManager::_RemovingZone [private]
 

Definition at line 149 of file zone_manager.h.

Referenced by checkZonesAround(), clear(), CZoneManager(), isRemoving(), and isWorkComplete().

std::vector<uint16> NL3D::CZoneManager::_ZoneList [private]
 

Definition at line 128 of file zone_manager.h.

Referenced by checkZonesAround(), and getNumZoneLeftToLoad().

std::string NL3D::CZoneManager::_zonePath [private]
 

Path for zone loading.

Definition at line 124 of file zone_manager.h.

Referenced by getZonePath(), and setZonePath().

float NL3D::CZoneManager::_ZoneTileColorFactor [private]
 

Definition at line 121 of file zone_manager.h.

Referenced by checkZonesAround(), CZoneManager(), and setZoneTileColor().

bool NL3D::CZoneManager::_ZoneTileColorMono [private]
 

Definition at line 120 of file zone_manager.h.

Referenced by checkZonesAround(), CZoneManager(), and setZoneTileColor().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 08:36:11 2004 for NeL by doxygen 1.3.6