OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 "object/C4ObjectList.h"
23 #include "lib/C4Rect.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() { } // 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
C4LArea()
Definition: C4Sector.h:93
bool Contains(C4LSector *pSct) const
Definition: C4Sector.cpp:293
C4LSector SectorOut
Definition: C4Sector.h:65
C4ObjectList Objects
Definition: C4Sector.h:48
C4LSector * First() const
Definition: C4Sector.h:111
int Wdt
Definition: C4Sector.h:63
bool IsNull() const
Definition: C4Sector.h:106
int Hgt
Definition: C4Sector.h:63
bool CheckSort()
Definition: C4Sector.cpp:218
void Add(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:93
C4LSector * SectorAt(int ix, int iy)
Definition: C4Sector.cpp:84
Definition: C4Rect.h:29
void Clear()
Definition: C4Sector.h:102
void DebugRec(class C4Object *pObj, char cMarker)
Definition: C4Sector.cpp:333
C4LArea(C4LSectors *pSectors, const C4Rect &rect)
Definition: C4Sector.h:96
void Dump()
Definition: C4Sector.cpp:209
int PxHgt
Definition: C4Sector.h:62
int y
Definition: C4Sector.h:46
C4ObjectList * NextObjectShapes(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:319
int xL
Definition: C4Sector.h:90
void Clear()
Definition: C4Sector.cpp:76
C4LSector * Next(C4LSector *pPrev) const
Definition: C4Sector.cpp:278
const int32_t C4LSectorWdt
Definition: C4Sector.h:31
void AssertObjectNotInList(C4Object *pObj)
Definition: C4Sector.cpp:187
void Init(int Wdt, int Hgt)
Definition: C4Sector.cpp:60
void ClearObjects()
Definition: C4Sector.cpp:51
int dpitch
Definition: C4Sector.h:90
C4LSector * pOut
Definition: C4Sector.h:91
bool operator==(const C4LArea &Area) const
Definition: C4Sector.cpp:238
void Update(C4Object *pObj, C4ObjectList *pMainList)
Definition: C4Sector.cpp:111
C4ObjectList * FirstObjects(C4LSector **ppSct)
Definition: C4Sector.h:118
const int32_t C4LSectorHgt
Definition: C4Sector.h:32
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *numbers)
Definition: C4Sector.cpp:43
C4ObjectList ObjectShapes
Definition: C4Sector.h:49
C4ObjectList * FirstObjectShapes(C4LSector **ppSct)
Definition: C4Sector.h:122
C4LSector * Sectors
Definition: C4Sector.h:61
~C4LSector()
Definition: C4Sector.h:39
void Init(int ix, int iy)
Definition: C4Sector.cpp:29
void ClearObjects()
Definition: C4Sector.cpp:227
C4LSector * pFirst
Definition: C4Sector.h:89
void Set(C4LSectors *pSectors, const C4Rect &rect)
Definition: C4Sector.cpp:246
C4LSector()
Definition: C4Sector.h:38
C4LArea(C4LSectors *pSectors, C4Object *pObj)
Definition: C4Sector.h:99
C4LArea(C4LSectors *pSectors, int ix, int iy, int iwdt, int ihgt)
Definition: C4Sector.h:94
int yL
Definition: C4Sector.h:90
int Size
Definition: C4Sector.h:63
void Remove(C4Object *pObj)
Definition: C4Sector.cpp:153
int getShapeSum() const
Definition: C4Sector.cpp:201
void Clear()
Definition: C4Sector.cpp:37
int x
Definition: C4Sector.h:46
C4ObjectList * NextObjects(C4ObjectList *pPrev, C4LSector **ppSct)
Definition: C4Sector.cpp:305
int PxWdt
Definition: C4Sector.h:62