1/*
2 * LegacyClonk
3 *
4 * Copyright (c) RedWolf Design
5 * Copyright (c) 2003, Sven2
6 * Copyright (c) 2017-2020, 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/* Solid areas of objects, put into the landscape */
19
20#pragma once
21
22#include <C4ObjectList.h>
23#include <C4Shape.h>
24
25class C4SolidMask
26{
27protected:
28 bool MaskPut; // if set, the mask is currently put into landscape
29 int MaskPutRotation; // rotation in which the mask was put (and resides in the buffers)
30 int MatBuffPitch; // pitch (and width) of mat buffer
31
32 int32_t MaskRemovalX, MaskRemovalY; // last position mask was removed from
33 class C4Object **ppAttachingObjects; // objects to be moved with mask motion
34 int iAttachingObjectsCount, iAttachingObjectsCapacity;
35
36 C4TargetRect MaskPutRect; // absolute bounding screen rect at which the mask is put - tx and ty are offsets within pSolidMask (for rects outside the landscape)
37
38 uint8_t *pSolidMask; // solid mask data: 0x00 if not solid at this position; 0xff if solid
39 uint8_t *pSolidMaskMatBuff; // material replaced by this solidmask. MCVehic if no solid mask data at this position OR another solidmask was already present during put
40
41 C4Object *pForObject;
42
43 // provides density within put SolidMask of an object
44 class DensityProvider : public C4DensityProvider
45 {
46 private:
47 class C4Object *pForObject;
48 C4SolidMask &rSolidMaskData;
49
50 public:
51 DensityProvider(class C4Object *pForObject, C4SolidMask &rSolidMaskData)
52 : pForObject(pForObject), rSolidMaskData(rSolidMaskData) {}
53
54 virtual int32_t GetDensity(int32_t x, int32_t y) const override;
55 };
56
57 // Remove the solidmask temporary
58 void RemoveTemporary(C4Rect where);
59 void PutTemporary(C4Rect where);
60 // Reput and update Matbuf after landscape change underneath
61 void Repair(C4Rect where);
62
63 friend class C4Landscape;
64 friend class DensityProvider;
65
66public:
67 // Linked list of all solidmasks
68 static C4SolidMask *First;
69 static C4SolidMask *Last;
70 C4SolidMask *Prev;
71 C4SolidMask *Next;
72
73 void Put(bool fCauseInstability, C4TargetRect *pClipRect, bool fRestoreAttachment); // put mask to landscape
74 void Remove(bool fCauseInstability, bool fBackupAttachment); // remove mask from landscape
75 void Clear(); // clear any SolidMask-data
76
77 C4SolidMask(C4Object *pForObject);
78 ~C4SolidMask();
79
80#ifdef SOLIDMASK_DEBUG
81 static bool CheckConsistency();
82#else
83 static bool CheckConsistency() { return true; }
84#endif
85};
86