1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2020, The LegacyClonk 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/* Basic class for vertex outlines */
18
19#pragma once
20
21#include "C4Constants.h"
22#include "C4ForwardDeclarations.h"
23#include "C4Rect.h"
24
25#include <cstdint>
26
27#define C4D_VertexCpyPos (C4D_MaxVertex/2)
28
29// a functional class to provide density for coordinates
30class C4DensityProvider
31{
32public:
33 virtual int32_t GetDensity(int32_t x, int32_t y) const;
34 virtual ~C4DensityProvider() {}
35};
36
37extern C4DensityProvider DefaultDensityProvider;
38
39class C4Shape : public C4Rect
40{
41public:
42 // remember to adjust C4Shape::CopyFrom and CreateOwnOriginalCopy when adding members here!
43 int32_t FireTop{};
44 int32_t VtxNum{};
45 int32_t VtxX[C4D_MaxVertex]{};
46 int32_t VtxY[C4D_MaxVertex]{};
47 int32_t VtxCNAT[C4D_MaxVertex]{};
48 int32_t VtxFriction[C4D_MaxVertex]{};
49 int32_t ContactDensity;
50 int32_t ContactCNAT{};
51 int32_t ContactCount{};
52 int32_t AttachMat;
53 int32_t VtxContactCNAT[C4D_MaxVertex]{};
54 int32_t VtxContactMat[C4D_MaxVertex]{};
55 int32_t iAttachX{}, iAttachY{}, iAttachVtx{};
56
57public:
58 C4Shape();
59 void Default();
60 void Rotate(int32_t iAngle, bool bUpdateVertices);
61 void Stretch(int32_t iPercent, bool bUpdateVertices);
62 void Jolt(int32_t iPercent, bool bUpdateVertices);
63 void GetVertexOutline(C4Rect &rRect);
64 int32_t GetVertexY(int32_t iVertex);
65 int32_t GetVertexX(int32_t iVertex);
66 bool AddVertex(int32_t iX, int32_t iY);
67 bool CheckContact(int32_t cx, int32_t cy);
68 bool ContactCheck(int32_t cx, int32_t cy);
69 bool Attach(int32_t &cx, int32_t &cy, uint8_t cnat_pos);
70 bool LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld, int32_t oldx, int32_t oldy);
71 bool InsertVertex(int32_t iPos, int32_t tx, int32_t ty);
72 bool RemoveVertex(int32_t iPos);
73 void CopyFrom(C4Shape rFrom, bool bCpyVertices, bool fCopyVerticesFromSelf);
74 int32_t GetBottomVertex();
75 int32_t GetVertexContact(int32_t iVtx, uint32_t dwCheckMask, int32_t tx, int32_t ty, const C4DensityProvider &rDensityProvider = DefaultDensityProvider); // get CNAT-mask for given vertex - does not check range for iVtx!
76 void CreateOwnOriginalCopy(C4Shape &rFrom); // create copy of all vertex members in back area of own buffers
77 void CompileFunc(StdCompiler *pComp, bool fRuntime);
78};
79