OpenClonk
C4LArea Class Reference

#include <C4Sector.h>

Collaboration diagram for C4LArea:
[legend]

Public Member Functions

 C4LArea ()
 
 C4LArea (C4LSectors *pSectors, int ix, int iy, int iwdt, int ihgt)
 
 C4LArea (C4LSectors *pSectors, const C4Rect &rect)
 
 C4LArea (C4LSectors *pSectors, C4Object *pObj)
 
void Clear ()
 
bool operator== (const C4LArea &Area) const
 
bool IsNull () const
 
void Set (C4LSectors *pSectors, const C4Rect &rect)
 
void Set (C4LSectors *pSectors, C4Object *pObj)
 
C4LSectorFirst () const
 
C4LSectorNext (C4LSector *pPrev) const
 
bool Contains (C4LSector *pSct) const
 
C4ObjectListFirstObjects (C4LSector **ppSct)
 
C4ObjectListNextObjects (C4ObjectList *pPrev, C4LSector **ppSct)
 
C4ObjectListFirstObjectShapes (C4LSector **ppSct)
 
C4ObjectListNextObjectShapes (C4ObjectList *pPrev, C4LSector **ppSct)
 
void DebugRec (class C4Object *pObj, char cMarker)
 

Public Attributes

C4LSectorpFirst
 
int xL
 
int yL
 
int dpitch
 
C4LSectorpOut
 

Detailed Description

Definition at line 86 of file C4Sector.h.

Constructor & Destructor Documentation

◆ C4LArea() [1/4]

C4LArea::C4LArea ( )
inline

Definition at line 93 of file C4Sector.h.

93 { Clear(); } // default constructor
void Clear()
Definition: C4Sector.h:102

References Clear().

Here is the call graph for this function:

◆ C4LArea() [2/4]

C4LArea::C4LArea ( C4LSectors pSectors,
int  ix,
int  iy,
int  iwdt,
int  ihgt 
)
inline

Definition at line 94 of file C4Sector.h.

95  { Set(pSectors, C4Rect(ix, iy, iwdt, ihgt)); }
void Set(C4LSectors *pSectors, const C4Rect &rect)
Definition: C4Sector.cpp:244
Definition: C4Rect.h:28

References Set().

Here is the call graph for this function:

◆ C4LArea() [3/4]

C4LArea::C4LArea ( C4LSectors pSectors,
const C4Rect rect 
)
inline

Definition at line 96 of file C4Sector.h.

97  { Set(pSectors, rect); }

References Set().

Here is the call graph for this function:

◆ C4LArea() [4/4]

C4LArea::C4LArea ( C4LSectors pSectors,
C4Object pObj 
)
inline

Definition at line 99 of file C4Sector.h.

100  { Set(pSectors, pObj); }

References Set().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4LArea::Clear ( )
inline

Definition at line 102 of file C4Sector.h.

102 { pFirst=pOut=nullptr; } // zero sector
C4LSector * pOut
Definition: C4Sector.h:91
C4LSector * pFirst
Definition: C4Sector.h:89

References pFirst, and pOut.

Referenced by C4LArea().

Here is the caller graph for this function:

◆ Contains()

bool C4LArea::Contains ( C4LSector pSct) const

Definition at line 291 of file C4Sector.cpp.

292 {
293  assert(pSct);
294  // no area
295  if (!pFirst) return false;
296  // outside?
297  if (pSct == pOut) return true;
298  if (pFirst == pOut) return false;
299  // check bounds
300  return (pSct->x>=pFirst->x && pSct->y>=pFirst->y && pSct->x<=xL && pSct->y<=yL);
301 }
int yL
Definition: C4Sector.h:90
int xL
Definition: C4Sector.h:90
int y
Definition: C4Sector.h:46
int x
Definition: C4Sector.h:46

References pFirst, pOut, C4LSector::x, xL, C4LSector::y, and yL.

Referenced by C4LSectors::Update().

Here is the caller graph for this function:

◆ DebugRec()

void C4LArea::DebugRec ( class C4Object pObj,
char  cMarker 
)

Definition at line 331 of file C4Sector.cpp.

332 {
333  C4RCArea rc;
334  rc.op = cMarker;
335  rc.obj = pObj ? pObj->Number : -1;
336  rc.x1 = pFirst ? pFirst->x : -1;
337  rc.y1 = pFirst ? pFirst->x /* 2do: y */ : -1;
338  rc.xL = xL;
339  rc.yL = yL;
340  rc.dpitch = dpitch;
341  rc.out = !!pOut;
342  AddDbgRec(RCT_Area, &rc, sizeof(C4RCArea));
343 }
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
char op
Definition: C4Record.h:202
@ RCT_Area
Definition: C4Record.h:80
int32_t x1
Definition: C4Record.h:204
int32_t xL
Definition: C4Record.h:204
int32_t y1
Definition: C4Record.h:204
int32_t obj
Definition: C4Record.h:203
int32_t yL
Definition: C4Record.h:204
int32_t dpitch
Definition: C4Record.h:204
bool out
Definition: C4Record.h:205
int dpitch
Definition: C4Sector.h:90

References AddDbgRec(), C4RCArea::dpitch, dpitch, C4PropListNumbered::Number, C4RCArea::obj, C4RCArea::op, C4RCArea::out, pFirst, pOut, RCT_Area, C4LSector::x, C4RCArea::x1, C4RCArea::xL, xL, C4RCArea::y1, C4RCArea::yL, and yL.

Referenced by C4LSectors::Add(), C4LSectors::Remove(), and C4LSectors::Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ First()

C4LSector* C4LArea::First ( ) const
inline

Definition at line 111 of file C4Sector.h.

111 { return pFirst; } // get first sector

References pFirst.

Referenced by C4LSectors::Add(), NextObjects(), NextObjectShapes(), C4LSectors::Remove(), and C4LSectors::Update().

Here is the caller graph for this function:

◆ FirstObjects()

C4ObjectList* C4LArea::FirstObjects ( C4LSector **  ppSct)
inline

Definition at line 118 of file C4Sector.h.

119  { *ppSct=nullptr; return NextObjects(nullptr, ppSct); }
C4ObjectList * NextObjects(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:303

References NextObjects().

Referenced by C4FindObject::Count(), C4GameObjects::CrossCheck(), C4FindObject::Find(), and C4FindObject::FindMany().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FirstObjectShapes()

C4ObjectList* C4LArea::FirstObjectShapes ( C4LSector **  ppSct)
inline

Definition at line 122 of file C4Sector.h.

123  { *ppSct=nullptr; return NextObjectShapes(nullptr, ppSct); }
C4ObjectList * NextObjectShapes(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:317

References NextObjectShapes().

Referenced by C4FindObject::Count(), C4FindObject::Find(), C4Game::FindConstuctionSiteBlock(), C4FindObject::FindMany(), and C4SolidMask::Remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsNull()

bool C4LArea::IsNull ( ) const
inline

Definition at line 106 of file C4Sector.h.

106 { return !pFirst; }

References pFirst.

Referenced by C4LSectors::Update().

Here is the caller graph for this function:

◆ Next()

C4LSector * C4LArea::Next ( C4LSector pPrev) const

Definition at line 276 of file C4Sector.cpp.

277 {
278  // the outside-sector is the last sector that is returned
279  if (pPrev == pOut)
280  return nullptr;
281  // within one line?
282  if (pPrev->x<xL)
283  return pPrev+1;
284  // within the area?
285  if (pPrev->y<yL)
286  return pPrev+dpitch;
287  // end reached - return outside-sector if applicable
288  return pOut;
289 }

References dpitch, pOut, C4LSector::x, xL, C4LSector::y, and yL.

Referenced by C4LSectors::Add(), C4FindObject::Count(), C4FindObject::FindMany(), NextObjects(), NextObjectShapes(), C4LSectors::Remove(), and C4LSectors::Update().

Here is the caller graph for this function:

◆ NextObjects()

C4ObjectList * C4LArea::NextObjects ( C4ObjectList pPrev,
C4LSector **  ppSct 
)

Definition at line 303 of file C4Sector.cpp.

304 {
305  // get next sector
306  if (!*ppSct)
307  *ppSct = First();
308  else
309  *ppSct = Next(*ppSct);
310  // nothing left?
311  if (!*ppSct)
312  return nullptr;
313  // return object list
314  return &(*ppSct)->Objects;
315 }
C4LSector * First() const
Definition: C4Sector.h:111
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:276

References First(), and Next().

Referenced by C4FindObject::Count(), C4GameObjects::CrossCheck(), C4FindObject::Find(), C4FindObject::FindMany(), and FirstObjects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextObjectShapes()

C4ObjectList * C4LArea::NextObjectShapes ( C4ObjectList pPrev,
C4LSector **  ppSct 
)

Definition at line 317 of file C4Sector.cpp.

318 {
319  // get next sector
320  if (!*ppSct)
321  *ppSct = First();
322  else
323  *ppSct = Next(*ppSct);
324  // nothing left?
325  if (!*ppSct)
326  return nullptr;
327  // return object list
328  return &(*ppSct)->ObjectShapes;
329 }

References First(), and Next().

Referenced by C4FindObject::Count(), C4FindObject::Find(), C4Game::FindConstuctionSiteBlock(), C4FindObject::FindMany(), FirstObjectShapes(), and C4SolidMask::Remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==()

bool C4LArea::operator== ( const C4LArea Area) const

Definition at line 236 of file C4Sector.cpp.

237 {
238  return pFirst == Area.pFirst &&
239  xL == Area.xL &&
240  yL == Area.yL &&
241  pOut == Area.pOut;
242 }

References pFirst, pOut, xL, and yL.

◆ Set() [1/2]

void C4LArea::Set ( C4LSectors pSectors,
C4Object pObj 
)

Definition at line 270 of file C4Sector.cpp.

271 {
272  // set to object facet rect
273  Set(pSectors, C4Rect(pObj->Left(), pObj->Top(), pObj->Width(), pObj->Height()));
274 }
int32_t Left() const
Definition: C4Object.h:281
int32_t Height() const
Definition: C4Object.h:284
int32_t Top() const
Definition: C4Object.h:282
int32_t Width() const
Definition: C4Object.h:283

References C4Object::Height(), C4Object::Left(), Set(), C4Object::Top(), and C4Object::Width().

Here is the call graph for this function:

◆ Set() [2/2]

void C4LArea::Set ( C4LSectors pSectors,
const C4Rect rect 
)

Definition at line 244 of file C4Sector.cpp.

245 {
246  // default: no area
247  pFirst=nullptr; pOut=nullptr;
248  // check bounds
249  C4Rect ClippedRect(Rect),
250  Bounds(0, 0, pSectors->PxWdt, pSectors->PxHgt);
251  ClippedRect.Normalize();
252  if (!Bounds.Contains(ClippedRect))
253  {
254  ClippedRect.Intersect(Bounds);
255  pOut = &pSectors->SectorOut;
256  }
257  // calc first sector
258  pFirst = pSectors->SectorAt(ClippedRect.x, ClippedRect.y);
259  // assert the rect isn't degenerated for the following calculations
260  // (note this will associate areas that are above landscape bounds with sectors inside)
261  if (!ClippedRect.Wdt) ClippedRect.Wdt = 1;
262  if (!ClippedRect.Hgt) ClippedRect.Hgt = 1;
263  // calc bounds
264  xL = (ClippedRect.x + ClippedRect.Wdt - 1) / C4LSectorWdt;
265  yL = (ClippedRect.y + ClippedRect.Hgt - 1) / C4LSectorHgt;
266  // calc pitch
267  dpitch = pSectors->Wdt - (ClippedRect.x + ClippedRect.Wdt - 1) / C4LSectorWdt + ClippedRect.x / C4LSectorWdt;
268 }
const int32_t C4LSectorHgt
Definition: C4Sector.h:32
const int32_t C4LSectorWdt
Definition: C4Sector.h:31
int Wdt
Definition: C4Sector.h:63
int PxHgt
Definition: C4Sector.h:62
C4LSector SectorOut
Definition: C4Sector.h:65
int PxWdt
Definition: C4Sector.h:62
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:82

References C4LSectorHgt, C4LSectorWdt, C4Rect::Contains(), dpitch, pFirst, pOut, C4LSectors::PxHgt, C4LSectors::PxWdt, C4LSectors::SectorAt(), C4LSectors::SectorOut, C4LSectors::Wdt, xL, and yL.

Referenced by C4LSectors::Add(), C4LArea(), and Set().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dpitch

int C4LArea::dpitch

Definition at line 90 of file C4Sector.h.

Referenced by DebugRec(), Next(), and Set().

◆ pFirst

C4LSector* C4LArea::pFirst

Definition at line 89 of file C4Sector.h.

Referenced by Clear(), Contains(), DebugRec(), First(), IsNull(), operator==(), and Set().

◆ pOut

C4LSector* C4LArea::pOut

Definition at line 91 of file C4Sector.h.

Referenced by Clear(), Contains(), DebugRec(), Next(), operator==(), and Set().

◆ xL

int C4LArea::xL

Definition at line 90 of file C4Sector.h.

Referenced by Contains(), DebugRec(), Next(), operator==(), and Set().

◆ yL

int C4LArea::yL

Definition at line 90 of file C4Sector.h.

Referenced by Contains(), DebugRec(), Next(), operator==(), and Set().


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