1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-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 /* Solid areas of objects, put into the landscape */
18 
19 #ifndef INC_C4SolidMask
20 #define INC_C4SolidMask
21 
22 #include "object/C4ObjectList.h"
23 #include "object/C4Shape.h"
24 
25 class C4SolidMask
26 {
27 protected:
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 	// last position mask was removed from
33 	// A rounded position is used for y, even though that causes movement to be less smooth, because gravity will counter sub-pixel movement and cause all non-attached objects to fall through the mask eventually
34 	C4Real MaskRemovalX;
35 	int32_t MaskRemovalY;
36 
37 	class C4Object **ppAttachingObjects; // objects to be moved with mask motion
38 	int iAttachingObjectsCount, iAttachingObjectsCapacity;
39 
40 	C4TargetRect MaskPutRect; // absolute bounding screen rect at which the mask is put - tx and ty are offsets within pSolidMask (for rects outside the landscape)
41 
42 	BYTE *pSolidMaskMatBuff; // material replaced by this solidmask. MCVehic if no solid mask data at this position OR another solidmask was already present during put (independent of MaskMaterial)
43 
44 	BYTE MaskMaterial; // Either MCVehicle or MCHalfVehicle
45 
46 	C4Object *pForObject;
47 
48 	// provides density within put SolidMask of an object
49 	class DensityProvider : public C4DensityProvider
50 	{
51 	private:
52 		class C4Object *pForObject;
53 		C4SolidMask &rSolidMaskData;
54 
55 	public:
DensityProvider(class C4Object * pForObject,C4SolidMask & rSolidMaskData)56 		DensityProvider(class C4Object *pForObject, C4SolidMask &rSolidMaskData)
57 				: pForObject(pForObject), rSolidMaskData(rSolidMaskData) {}
58 
59 		int32_t GetDensity(int32_t x, int32_t y) const override;
60 	};
61 	// Remove the solidmask temporarily
62 	void RemoveTemporary(C4Rect where);
63 	void PutTemporary(C4Rect where);
64 	// Reput and update Matbuf after landscape change underneath
65 	void Repair(C4Rect where);
66 
67 	friend class C4Landscape;
68 	friend class DensityProvider;
69 
70 public:
71 	// Linked list of all solidmasks
72 	static C4SolidMask * First;
73 	static C4SolidMask * Last;
74 	C4SolidMask * Prev;
75 	C4SolidMask * Next;
76 
77 	void Put(bool fCauseInstability, C4TargetRect *pClipRect, bool fRestoreAttachment);    // put mask to landscape
78 	void Remove(bool fBackupAttachment); // remove mask from landscape
79 	void Draw(C4TargetFacet &cgo);           // draw the solidmask (dbg display)
80 
IsPut()81 	bool IsPut() { return MaskPut; }
82 	C4SolidMask(C4Object *pForObject);  // ctor
83 	~C4SolidMask(); // dtor
84 
85 	static bool CheckConsistency();
86 	static void RemoveSolidMasks();
87 	static void PutSolidMasks();
88 
89 	static CSurface8 *LoadMaskFromFile(class C4Group &hGroup, const char *szFilename);
90 
91 	void SetHalfVehicle(bool set);
92 };
93 
94 #endif
95