OpenClonk
C4Sector.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 // object list sectors
18 
19 #ifndef INC_C4Sector
20 #define INC_C4Sector
21 
22 #include "lib/C4Rect.h"
23 #include "object/C4ObjectList.h"
24 
25 // class predefs
26 class C4LSector;
27 class C4LSectors;
28 class C4LArea;
29 
30 // constants
31 const int32_t C4LSectorWdt = 50,
33 
34 // one of those object list sectors
35 class C4LSector
36 {
37 public:
38  C4LSector() = default; // constructor
39  ~C4LSector() { Clear(); } // destructor
40 
41 protected:
42  void Init(int ix, int iy);
43  void Clear();
44 
45 public:
46  int x, y; // pos
47 
48  C4ObjectList Objects; // objects within this sector
49  C4ObjectList ObjectShapes; // objects with shapes that overlap this sector
50 
51  void CompileFunc(StdCompiler *pComp, C4ValueNumbers * numbers);
52  void ClearObjects(); // remove all objects from object lists
53 
54  friend class C4LSectors;
55 };
56 
57 // the whole map
59 {
60 public:
61  C4LSector *Sectors; // mem holding the sector array
62  int PxWdt, PxHgt; // size in px
63  int Wdt, Hgt, Size; // sector count
64 
65  C4LSector SectorOut; // the sector "outside"
66 
67 public:
68  void Init(int Wdt, int Hgt); // init map sectors
69  void Clear(); // free map sectors
70  C4LSector *SectorAt(int ix, int iy); // get sector at pos
71 
72  void Add(C4Object *pObj, C4ObjectList *pMainList);
73  void Update(C4Object *pObj, C4ObjectList *pMainList); // does not update object order!
74  void Remove(C4Object *pObj);
75  void ClearObjects(); // remove all objects from object lists
76 
77  void AssertObjectNotInList(C4Object *pObj); // searches all sector lists for object, and assert if it's inside a list
78 
79  int getShapeSum() const;
80 
81  void Dump();
82  bool CheckSort();
83 };
84 
85 // a defined sector-area within the map
86 class C4LArea
87 {
88 public:
90  int xL, yL, dpitch; // bounds / delta-pitch
91  C4LSector *pOut; // outside?
92 
93  C4LArea() { Clear(); } // default constructor
94  C4LArea(C4LSectors *pSectors, int ix, int iy, int iwdt, int ihgt) // initializing constructor
95  { Set(pSectors, C4Rect(ix, iy, iwdt, ihgt)); }
96  C4LArea(C4LSectors *pSectors, const C4Rect &rect) // initializing constructor
97  { Set(pSectors, rect); }
98 
99  C4LArea(C4LSectors *pSectors, C4Object *pObj) // initializing constructor
100  { Set(pSectors, pObj); }
101 
102  inline void Clear() { pFirst=pOut=nullptr; } // zero sector
103 
104  bool operator == (const C4LArea &Area) const;
105 
106  bool IsNull() const { return !pFirst; }
107 
108  void Set(C4LSectors *pSectors, const C4Rect &rect); // set rect, calc bounds and get pitch
109  void Set(C4LSectors *pSectors, C4Object *pObj); // set to object facet rect
110 
111  C4LSector *First() const { return pFirst; } // get first sector
112  C4LSector *Next(C4LSector *pPrev) const; // get next sector within area
113 
114  // void MoveObject(C4Object *pObj, const C4LArea &toArea); // store object into new area
115 
116  bool Contains(C4LSector *pSct) const; // return whether sector is contained in area
117 
118  inline C4ObjectList *FirstObjects(C4LSector **ppSct) // get first object list of this area
119  { *ppSct=nullptr; return NextObjects(nullptr, ppSct); }
120  C4ObjectList *NextObjects(C4ObjectList *pPrev, C4LSector **ppSct); // get next object list of this area
121 
122  inline C4ObjectList *FirstObjectShapes(C4LSector **ppSct) // get first object shapes list of this area
123  { *ppSct=nullptr; return NextObjectShapes(nullptr, ppSct); }
124  C4ObjectList *NextObjectShapes(C4ObjectList *pPrev, C4LSector **ppSct); // get next object shapes list of this area
125 
126  void DebugRec(class C4Object *pObj, char cMarker);
127 };
128 
129 #endif
const int32_t C4LSectorHgt
Definition: C4Sector.h:32
const int32_t C4LSectorWdt
Definition: C4Sector.h:31
C4ObjectList * NextObjectShapes(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:317
C4LArea()
Definition: C4Sector.h:93
C4ObjectList * NextObjects(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:303
C4LSector * pOut
Definition: C4Sector.h:91
C4LArea(C4LSectors *pSectors, C4Object *pObj)
Definition: C4Sector.h:99
C4ObjectList * FirstObjectShapes(C4LSector **ppSct)
Definition: C4Sector.h:122
bool Contains(C4LSector *pSct) const
Definition: C4Sector.cpp:291
int yL
Definition: C4Sector.h:90
bool IsNull() const
Definition: C4Sector.h:106
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:331
C4LSector * First() const
Definition: C4Sector.h:111
int xL
Definition: C4Sector.h:90
C4LArea(C4LSectors *pSectors, int ix, int iy, int iwdt, int ihgt)
Definition: C4Sector.h:94
C4LArea(C4LSectors *pSectors, const C4Rect &rect)
Definition: C4Sector.h:96
void Set(C4LSectors *pSectors, const C4Rect &rect)
Definition: C4Sector.cpp:244
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:276
C4LSector * pFirst
Definition: C4Sector.h:89
void Clear()
Definition: C4Sector.h:102
C4ObjectList * FirstObjects(C4LSector **ppSct)
Definition: C4Sector.h:118
bool operator==(const C4LArea &Area) const
Definition: C4Sector.cpp:236
int dpitch
Definition: C4Sector.h:90
C4LSector()=default
void Init(int ix, int iy)
Definition: C4Sector.cpp:27
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4ObjectList Objects
Definition: C4Sector.h:48
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *numbers)
Definition: C4Sector.cpp:41
void ClearObjects()
Definition: C4Sector.cpp:49
int y
Definition: C4Sector.h:46
void Clear()
Definition: C4Sector.cpp:35
~C4LSector()
Definition: C4Sector.h:39
int x
Definition: C4Sector.h:46
int Wdt
Definition: C4Sector.h:63
void Update(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:109
void Clear()
Definition: C4Sector.cpp:74
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:91
int PxHgt
Definition: C4Sector.h:62
void AssertObjectNotInList(C4Object *pObj)
Definition: C4Sector.cpp:185
C4LSector SectorOut
Definition: C4Sector.h:65
int Size
Definition: C4Sector.h:63
int getShapeSum() const
Definition: C4Sector.cpp:199
int PxWdt
Definition: C4Sector.h:62
void Init(int Wdt, int Hgt)
Definition: C4Sector.cpp:58
C4LSector * Sectors
Definition: C4Sector.h:61
void Dump()
Definition: C4Sector.cpp:207
int Hgt
Definition: C4Sector.h:63
void Remove(C4Object *pObj)
Definition: C4Sector.cpp:151
void ClearObjects()
Definition: C4Sector.cpp:225
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:82
bool CheckSort()
Definition: C4Sector.cpp:216
Definition: C4Rect.h:28