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 93 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().

94 {
95  assert(Sectors);
96  // Add to owning sector
97  C4LSector *pSct = SectorAt(pObj->GetX(), pObj->GetY());
98  pSct->Objects.Add(pObj, C4ObjectList::stMain, pMainList);
99  // Save position
100  pObj->old_x = pObj->GetX(); pObj->old_y = pObj->GetY();
101  // Add to all sectors in shape area
102  pObj->Area.Set(this, pObj);
103  for (pSct = pObj->Area.First(); pSct; pSct = pObj->Area.Next(pSct))
104  {
105  pSct->ObjectShapes.Add(pObj, C4ObjectList::stMain, pMainList);
106  }
107  if (Config.General.DebugRec)
108  pObj->Area.DebugRec(pObj, 'A');
109 }
int32_t GetY() const
Definition: C4Object.h:287
C4Config Config
Definition: C4Config.cpp:831
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:252
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:84
int32_t old_y
Definition: C4Object.h:114
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:333
int32_t old_x
Definition: C4Object.h:114
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:278
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:246
int32_t DebugRec
Definition: C4Config.h:61

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LSectors::AssertObjectNotInList ( C4Object pObj)

Definition at line 187 of file C4Sector.cpp.

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

Referenced by C4Object::~C4Object().

188 {
189 #ifndef NDEBUG
190  C4LSector *sct=Sectors;
191  for (int cnt=0; cnt<Size; cnt++, sct++)
192  {
193  assert(!sct->Objects.IsContained(pObj));
194  assert(!sct->ObjectShapes.IsContained(pObj));
195  }
196  assert(!SectorOut.Objects.IsContained(pObj));
197  assert(!SectorOut.ObjectShapes.IsContained(pObj));
198 #endif
199 }
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 218 of file C4Sector.cpp.

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

219 {
220  for (int cnt=0; cnt<Size; cnt++)
221  if (!Sectors[cnt].Objects.CheckSort(&::Objects))
222  return false;
223  if (!SectorOut.Objects.CheckSort(&::Objects)) return false;
224  return true;
225 }
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 76 of file C4Sector.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4LSectors::ClearObjects ( )

Definition at line 227 of file C4Sector.cpp.

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

Referenced by C4GameObjects::DeleteObjects().

228 {
229  if (Sectors)
230  {
231  for (int cnt=0; cnt<Size; cnt++) Sectors[cnt].ClearObjects();
232  }
234 }
C4LSector SectorOut
Definition: C4Sector.h:65
void ClearObjects()
Definition: C4Sector.cpp:51
C4LSector * Sectors
Definition: C4Sector.h:61
void ClearObjects()
Definition: C4Sector.cpp:227
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 209 of file C4Sector.cpp.

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

210 {
211  C4ValueNumbers numbers;
212  LogSilent(DecompileToBuf<StdCompilerINIWrite>(
215  "Sector")).getData());
216 }
bool LogSilent(const char *szMessage, bool fConsole)
Definition: C4Log.cpp:117
StdParameterAdaptMaker< P > mkParAdaptMaker(P &&rPar)
Definition: StdAdaptors.h:469
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
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:311

Here is the call graph for this function:

int C4LSectors::getShapeSum ( ) const

Definition at line 201 of file C4Sector.cpp.

References Sectors, and Size.

Referenced by C4ControlSyncCheck::Set().

202 {
203  int iSum = 0;
204  for (int cnt=0; cnt<Size; cnt++)
205  iSum += Sectors[cnt].ObjectShapes.ObjectCount();
206  return iSum;
207 }
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 60 of file C4Sector.cpp.

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

Referenced by C4GameObjects::Init().

61 {
62  // clear any previous initialization
63  Clear();
64  // store class members, calc size
65  Wdt = ((PxWdt=iWdt)-1)/C4LSectorWdt+1;
66  Hgt = ((PxHgt=iHgt)-1)/C4LSectorHgt+1;
67  // create sectors
68  Sectors = new C4LSector[Size=Wdt*Hgt];
69  // init sectors
70  C4LSector *sct=Sectors;
71  for (int cnt=0; cnt<Size; cnt++, sct++)
72  sct->Init(cnt%Wdt, cnt/Wdt);
73  SectorOut.Init(-1,-1); // outpos at -1,-1 - MUST NOT intersect with an inside sector!
74 }
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:76
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:29
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 153 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().

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

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

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

85 {
86  // check bounds
87  if (ix<0 || iy<0 || ix>=PxWdt || iy>=PxHgt)
88  return &SectorOut;
89  // get sector
90  return Sectors+(iy/C4LSectorHgt)*Wdt+(ix/C4LSectorWdt);
91 }
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 111 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().

112 {
113  assert(Sectors);
114  // Not added yet?
115  if (pObj->Area.IsNull())
116  {
117  Add(pObj, pMainList);
118  return;
119  }
120  C4LSector *pOld, *pNew;
121  if (pObj->old_x != pObj->GetX() || pObj->old_y != pObj->GetY())
122  {
123  // Get involved sectors
124  pOld = SectorAt(pObj->old_x, pObj->old_y);
125  pNew = SectorAt(pObj->GetX(), pObj->GetY());
126  if (pOld != pNew)
127  {
128  pOld->Objects.Remove(pObj);
129  pNew->Objects.Add(pObj, C4ObjectList::stMain, pMainList);
130  }
131  // Save position
132  pObj->old_x = pObj->GetX(); pObj->old_y = pObj->GetY();
133  }
134  // New area
135  C4LArea NewArea(this, pObj);
136  if (pObj->Area == NewArea) return;
137  // Remove from all old sectors in shape area
138  for (pOld = pObj->Area.First(); pOld; pOld = pObj->Area.Next(pOld))
139  if (!NewArea.Contains(pOld))
140  pOld->ObjectShapes.Remove(pObj);
141  // Add to all new sectors in shape area
142  for (pNew = NewArea.First(); pNew; pNew = NewArea.Next(pNew))
143  if (!pObj->Area.Contains(pNew))
144  {
145  pNew->ObjectShapes.Add(pObj, C4ObjectList::stMain, pMainList);
146  }
147  // Update area
148  pObj->Area = NewArea;
149  if (Config.General.DebugRec)
150  pObj->Area.DebugRec(pObj, 'U');
151 }
int32_t GetY() const
Definition: C4Object.h:287
bool Contains(C4LSector *pSct) const
Definition: C4Sector.cpp:293
C4Config Config
Definition: C4Config.cpp:831
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:252
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:93
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:84
int32_t old_y
Definition: C4Object.h:114
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:333
int32_t old_x
Definition: C4Object.h:114
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:278
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:61
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: