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