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, 32 C4LSectorHgt = 50; 33 34 // one of those object list sectors 35 class C4LSector 36 { 37 public: 38 C4LSector() = default; // constructor ~C4LSector()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 58 class C4LSectors 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: 89 C4LSector *pFirst; 90 int xL, yL, dpitch; // bounds / delta-pitch 91 C4LSector *pOut; // outside? 92 C4LArea()93 C4LArea() { Clear(); } // default constructor C4LArea(C4LSectors * pSectors,int ix,int iy,int iwdt,int ihgt)94 C4LArea(C4LSectors *pSectors, int ix, int iy, int iwdt, int ihgt) // initializing constructor 95 { Set(pSectors, C4Rect(ix, iy, iwdt, ihgt)); } C4LArea(C4LSectors * pSectors,const C4Rect & rect)96 C4LArea(C4LSectors *pSectors, const C4Rect &rect) // initializing constructor 97 { Set(pSectors, rect); } 98 C4LArea(C4LSectors * pSectors,C4Object * pObj)99 C4LArea(C4LSectors *pSectors, C4Object *pObj) // initializing constructor 100 { Set(pSectors, pObj); } 101 Clear()102 inline void Clear() { pFirst=pOut=nullptr; } // zero sector 103 104 bool operator == (const C4LArea &Area) const; 105 IsNull()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 First()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 FirstObjects(C4LSector ** ppSct)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 FirstObjectShapes(C4LSector ** ppSct)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 130