OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4LSectors Class Reference

#include <C4Sector.h>

Collaboration diagram for C4LSectors:
[legend]

Public Member Functions

void Init (int Wdt, int Hgt)
 
void Clear ()
 
C4LSectorSectorAt (int ix, int iy)
 
void Add (C4Object *pObj, C4ObjectList *pMainList)
 
void Update (C4Object *pObj, C4ObjectList *pMainList)
 
void Remove (C4Object *pObj)
 
void ClearObjects ()
 
void AssertObjectNotInList (C4Object *pObj)
 
int getShapeSum () const
 
void Dump ()
 
bool CheckSort ()
 

Public Attributes

C4LSectorSectors
 
int PxWdt
 
int PxHgt
 
int Wdt
 
int Hgt
 
int Size
 
C4LSector SectorOut
 

Detailed Description

Definition at line 58 of file C4Sector.h.

Member Function Documentation

void C4LSectors::Add ( C4Object pObj,
C4ObjectList pMainList 
)

Definition at line 91 of file C4Sector.cpp.

References C4ObjectList::Add(), C4Object::Area, Config, C4ConfigGeneral::DebugRec, C4LArea::DebugRec(), C4LArea::First(), C4Config::General, C4Object::GetX(), C4Object::GetY(), C4LArea::Next(), C4LSector::Objects, C4LSector::ObjectShapes, C4Object::old_x, C4Object::old_y, SectorAt(), Sectors, C4LArea::Set(), and C4ObjectList::stMain.

Referenced by C4GameObjects::Add(), Update(), and C4GameObjects::UpdatePosResort().

92 {
93  assert(Sectors);
94  // Add to owning sector
95  C4LSector *pSct = SectorAt(pObj->GetX(), pObj->GetY());
96  pSct->Objects.Add(pObj, C4ObjectList::stMain, pMainList);
97  // Save position
98  pObj->old_x = pObj->GetX(); pObj->old_y = pObj->GetY();
99  // Add to all sectors in shape area
100  pObj->Area.Set(this, pObj);
101  for (pSct = pObj->Area.First(); pSct; pSct = pObj->Area.Next(pSct))
102  {
103  pSct->ObjectShapes.Add(pObj, C4ObjectList::stMain, pMainList);
104  }
105  if (Config.General.DebugRec)
106  pObj->Area.DebugRec(pObj, 'A');
107 }
int32_t GetY() const
Definition: C4Object.h:287
C4Config Config
Definition: C4Config.cpp:833
C4LArea Area
Definition: C4Object.h:114
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
C4ObjectList Objects
Definition: C4Sector.h:48
C4LSector * First() const
Definition: C4Sector.h:111
C4ConfigGeneral General
Definition: C4Config.h:251
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:82
int32_t old_y
Definition: C4Object.h:114
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:331
int32_t old_x
Definition: C4Object.h:114
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:276
int32_t GetX() const
Definition: C4Object.h:286
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4LSector * Sectors
Definition: C4Sector.h:61
void Set(C4LSectors *pSectors, const C4Rect &rect)
Definition: C4Sector.cpp:244
int32_t DebugRec
Definition: C4Config.h:60

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LSectors::AssertObjectNotInList ( C4Object pObj)

Definition at line 185 of file C4Sector.cpp.

References C4ObjectList::IsContained(), C4LSector::Objects, C4LSector::ObjectShapes, SectorOut, Sectors, and Size.

Referenced by C4Object::~C4Object().

186 {
187 #ifndef NDEBUG
188  C4LSector *sct=Sectors;
189  for (int cnt=0; cnt<Size; cnt++, sct++)
190  {
191  assert(!sct->Objects.IsContained(pObj));
192  assert(!sct->ObjectShapes.IsContained(pObj));
193  }
194  assert(!SectorOut.Objects.IsContained(pObj));
195  assert(!SectorOut.ObjectShapes.IsContained(pObj));
196 #endif
197 }
C4LSector SectorOut
Definition: C4Sector.h:65
C4ObjectList Objects
Definition: C4Sector.h:48
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4LSector * Sectors
Definition: C4Sector.h:61
bool IsContained(const C4Object *pObj) const
int Size
Definition: C4Sector.h:63

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4LSectors::CheckSort ( )

Definition at line 216 of file C4Sector.cpp.

References C4ObjectList::CheckSort(), Objects, C4LSector::Objects, SectorOut, Sectors, and Size.

217 {
218  for (int cnt=0; cnt<Size; cnt++)
219  if (!Sectors[cnt].Objects.CheckSort(&::Objects))
220  return false;
221  if (!SectorOut.Objects.CheckSort(&::Objects)) return false;
222  return true;
223 }
C4LSector SectorOut
Definition: C4Sector.h:65
C4ObjectList Objects
Definition: C4Sector.h:48
C4LSector * Sectors
Definition: C4Sector.h:61
int Size
Definition: C4Sector.h:63
bool CheckSort(C4ObjectList *pList)
C4GameObjects Objects
Definition: C4Globals.cpp:48

Here is the call graph for this function:

void C4LSectors::Clear ( )

Definition at line 74 of file C4Sector.cpp.

References C4LSector::Clear(), SectorOut, and Sectors.

Referenced by C4GameObjects::Default(), Init(), and C4GameObjects::~C4GameObjects().

75 {
76  // clear out-sector
77  SectorOut.Clear();
78  // free sectors
79  delete [] Sectors; Sectors=nullptr;
80 }
C4LSector SectorOut
Definition: C4Sector.h:65
C4LSector * Sectors
Definition: C4Sector.h:61
void Clear()
Definition: C4Sector.cpp:35

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LSectors::ClearObjects ( )

Definition at line 225 of file C4Sector.cpp.

References C4LSector::ClearObjects(), SectorOut, Sectors, and Size.

Referenced by C4GameObjects::DeleteObjects().

226 {
227  if (Sectors)
228  {
229  for (int cnt=0; cnt<Size; cnt++) Sectors[cnt].ClearObjects();
230  }
232 }
C4LSector SectorOut
Definition: C4Sector.h:65
void ClearObjects()
Definition: C4Sector.cpp:49
C4LSector * Sectors
Definition: C4Sector.h:61
void ClearObjects()
Definition: C4Sector.cpp:225
int Size
Definition: C4Sector.h:63

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LSectors::Dump ( )

Definition at line 207 of file C4Sector.cpp.

References LogSilent(), mkArrayAdaptMap(), mkNamingAdapt(), mkParAdaptMaker(), Sectors, and Size.

208 {
209  C4ValueNumbers numbers;
210  LogSilent(DecompileToBuf<StdCompilerINIWrite>(
213  "Sector")).getData());
214 }
bool LogSilent(const char *szMessage, bool fConsole)
Definition: C4Log.cpp:114
StdParameterAdaptMaker< P > mkParAdaptMaker(P &&rPar)
Definition: StdAdaptors.h:471
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4LSector * Sectors
Definition: C4Sector.h:61
int Size
Definition: C4Sector.h:63
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:313

Here is the call graph for this function:

int C4LSectors::getShapeSum ( ) const

Definition at line 199 of file C4Sector.cpp.

References Sectors, and Size.

Referenced by C4ControlSyncCheck::Set().

200 {
201  int iSum = 0;
202  for (int cnt=0; cnt<Size; cnt++)
203  iSum += Sectors[cnt].ObjectShapes.ObjectCount();
204  return iSum;
205 }
C4LSector * Sectors
Definition: C4Sector.h:61
int Size
Definition: C4Sector.h:63

Here is the caller graph for this function:

void C4LSectors::Init ( int  Wdt,
int  Hgt 
)

Definition at line 58 of file C4Sector.cpp.

References C4LSectorHgt, C4LSectorWdt, Clear(), Hgt, C4LSector::Init(), PxHgt, PxWdt, SectorOut, Sectors, Size, and Wdt.

Referenced by C4GameObjects::Init().

59 {
60  // clear any previous initialization
61  Clear();
62  // store class members, calc size
63  Wdt = ((PxWdt=iWdt)-1)/C4LSectorWdt+1;
64  Hgt = ((PxHgt=iHgt)-1)/C4LSectorHgt+1;
65  // create sectors
66  Sectors = new C4LSector[Size=Wdt*Hgt];
67  // init sectors
68  C4LSector *sct=Sectors;
69  for (int cnt=0; cnt<Size; cnt++, sct++)
70  sct->Init(cnt%Wdt, cnt/Wdt);
71  SectorOut.Init(-1,-1); // outpos at -1,-1 - MUST NOT intersect with an inside sector!
72 }
C4LSector SectorOut
Definition: C4Sector.h:65
int Wdt
Definition: C4Sector.h:63
int Hgt
Definition: C4Sector.h:63
int PxHgt
Definition: C4Sector.h:62
void Clear()
Definition: C4Sector.cpp:74
const int32_t C4LSectorWdt
Definition: C4Sector.h:31
const int32_t C4LSectorHgt
Definition: C4Sector.h:32
C4LSector * Sectors
Definition: C4Sector.h:61
void Init(int ix, int iy)
Definition: C4Sector.cpp:27
int Size
Definition: C4Sector.h:63
int PxWdt
Definition: C4Sector.h:62

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LSectors::Remove ( C4Object pObj)

Definition at line 151 of file C4Sector.cpp.

References C4Object::Area, Config, C4ConfigGeneral::DebugRec, C4LArea::DebugRec(), C4LArea::First(), C4Config::General, C4Object::id, LogF(), C4LArea::Next(), C4PropListNumbered::Number, C4LSector::Objects, C4LSector::ObjectShapes, C4Object::old_x, C4Object::old_y, C4ObjectList::Remove(), SectorAt(), SectorOut, Sectors, Size, and C4ID::ToString().

Referenced by C4GameObjects::Remove(), and C4GameObjects::UpdatePosResort().

152 {
153  assert(Sectors); assert(pObj);
154  // Remove from owning sector
155  C4LSector *pSct = SectorAt(pObj->old_x, pObj->old_y);
156  if (!pSct->Objects.Remove(pObj))
157  {
158 #ifdef _DEBUG
159  LogF("WARNING: Object %d of type %s deleted but not found in pos sector list!", pObj->Number, pObj->id.ToString());
160 #endif
161  // if it was not found in owning sector, it must be somewhere else. yeah...
162  bool fFound = false;
163  for (pSct = pObj->Area.First(); pSct; pSct = pObj->Area.Next(pSct))
164  if (pSct->Objects.Remove(pObj)) { fFound=true; break; }
165  // yukh, somewhere else entirely...
166  if (!fFound)
167  {
168  fFound = !!SectorOut.Objects.Remove(pObj);
169  if (!fFound)
170  {
171  pSct = Sectors;
172  for (int cnt=0; cnt<Size; cnt++, pSct++)
173  if (pSct->Objects.Remove(pObj)) { fFound=true; break; }
174  }
175  assert(fFound);
176  }
177  }
178  // Remove from all sectors in shape area
179  for (pSct = pObj->Area.First(); pSct; pSct = pObj->Area.Next(pSct))
180  pSct->ObjectShapes.Remove(pObj);
181  if (Config.General.DebugRec)
182  pObj->Area.DebugRec(pObj, 'R');
183 }
C4LSector SectorOut
Definition: C4Sector.h:65
C4Config Config
Definition: C4Config.cpp:833
C4LArea Area
Definition: C4Object.h:114
C4ID id
Definition: C4Object.h:108
C4ObjectList Objects
Definition: C4Sector.h:48
C4LSector * First() const
Definition: C4Sector.h:111
C4ConfigGeneral General
Definition: C4Config.h:251
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:82
int32_t old_y
Definition: C4Object.h:114
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:331
int32_t old_x
Definition: C4Object.h:114
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:276
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4LSector * Sectors
Definition: C4Sector.h:61
const char * ToString() const
Definition: C4Id.h:59
int32_t DebugRec
Definition: C4Config.h:60
int Size
Definition: C4Sector.h:63
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
virtual bool Remove(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

C4LSector * C4LSectors::SectorAt ( int  ix,
int  iy 
)

Definition at line 82 of file C4Sector.cpp.

References C4LSectorHgt, C4LSectorWdt, PxHgt, PxWdt, SectorOut, Sectors, and Wdt.

Referenced by Add(), C4GameObjects::ObjectsAt(), Remove(), C4LArea::Set(), and Update().

83 {
84  // check bounds
85  if (ix<0 || iy<0 || ix>=PxWdt || iy>=PxHgt)
86  return &SectorOut;
87  // get sector
88  return Sectors+(iy/C4LSectorHgt)*Wdt+(ix/C4LSectorWdt);
89 }
C4LSector SectorOut
Definition: C4Sector.h:65
int Wdt
Definition: C4Sector.h:63
int PxHgt
Definition: C4Sector.h:62
const int32_t C4LSectorWdt
Definition: C4Sector.h:31
const int32_t C4LSectorHgt
Definition: C4Sector.h:32
C4LSector * Sectors
Definition: C4Sector.h:61
int PxWdt
Definition: C4Sector.h:62

Here is the caller graph for this function:

void C4LSectors::Update ( C4Object pObj,
C4ObjectList pMainList 
)

Definition at line 109 of file C4Sector.cpp.

References Add(), C4ObjectList::Add(), C4Object::Area, Config, C4LArea::Contains(), C4ConfigGeneral::DebugRec, C4LArea::DebugRec(), C4LArea::First(), C4Config::General, C4Object::GetX(), C4Object::GetY(), C4LArea::IsNull(), C4LArea::Next(), C4LSector::Objects, C4LSector::ObjectShapes, C4Object::old_x, C4Object::old_y, C4ObjectList::Remove(), SectorAt(), Sectors, and C4ObjectList::stMain.

Referenced by C4GameObjects::UpdatePos().

110 {
111  assert(Sectors);
112  // Not added yet?
113  if (pObj->Area.IsNull())
114  {
115  Add(pObj, pMainList);
116  return;
117  }
118  C4LSector *pOld, *pNew;
119  if (pObj->old_x != pObj->GetX() || pObj->old_y != pObj->GetY())
120  {
121  // Get involved sectors
122  pOld = SectorAt(pObj->old_x, pObj->old_y);
123  pNew = SectorAt(pObj->GetX(), pObj->GetY());
124  if (pOld != pNew)
125  {
126  pOld->Objects.Remove(pObj);
127  pNew->Objects.Add(pObj, C4ObjectList::stMain, pMainList);
128  }
129  // Save position
130  pObj->old_x = pObj->GetX(); pObj->old_y = pObj->GetY();
131  }
132  // New area
133  C4LArea NewArea(this, pObj);
134  if (pObj->Area == NewArea) return;
135  // Remove from all old sectors in shape area
136  for (pOld = pObj->Area.First(); pOld; pOld = pObj->Area.Next(pOld))
137  if (!NewArea.Contains(pOld))
138  pOld->ObjectShapes.Remove(pObj);
139  // Add to all new sectors in shape area
140  for (pNew = NewArea.First(); pNew; pNew = NewArea.Next(pNew))
141  if (!pObj->Area.Contains(pNew))
142  {
143  pNew->ObjectShapes.Add(pObj, C4ObjectList::stMain, pMainList);
144  }
145  // Update area
146  pObj->Area = NewArea;
147  if (Config.General.DebugRec)
148  pObj->Area.DebugRec(pObj, 'U');
149 }
int32_t GetY() const
Definition: C4Object.h:287
bool Contains(C4LSector *pSct) const
Definition: C4Sector.cpp:291
C4Config Config
Definition: C4Config.cpp:833
C4LArea Area
Definition: C4Object.h:114
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
C4ObjectList Objects
Definition: C4Sector.h:48
C4LSector * First() const
Definition: C4Sector.h:111
bool IsNull() const
Definition: C4Sector.h:106
C4ConfigGeneral General
Definition: C4Config.h:251
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:91
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:82
int32_t old_y
Definition: C4Object.h:114
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:331
int32_t old_x
Definition: C4Object.h:114
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:276
int32_t GetX() const
Definition: C4Object.h:286
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4LSector * Sectors
Definition: C4Sector.h:61
int32_t DebugRec
Definition: C4Config.h:60
virtual bool Remove(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int C4LSectors::Hgt

Definition at line 63 of file C4Sector.h.

Referenced by Init().

int C4LSectors::PxHgt

Definition at line 62 of file C4Sector.h.

Referenced by Init(), SectorAt(), and C4LArea::Set().

int C4LSectors::PxWdt

Definition at line 62 of file C4Sector.h.

Referenced by Init(), SectorAt(), and C4LArea::Set().

C4LSector C4LSectors::SectorOut
C4LSector* C4LSectors::Sectors
int C4LSectors::Size

Definition at line 63 of file C4Sector.h.

Referenced by AssertObjectNotInList(), CheckSort(), ClearObjects(), Dump(), getShapeSum(), Init(), and Remove().

int C4LSectors::Wdt

Definition at line 63 of file C4Sector.h.

Referenced by Init(), SectorAt(), and C4LArea::Set().


The documentation for this class was generated from the following files: