OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Shape.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk 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 /* Basic classes for rectangles and vertex outlines */
19 
20 #ifndef INC_C4Shape
21 #define INC_C4Shape
22 
23 #include "config/C4Constants.h"
24 #include "lib/C4Rect.h"
25 
26 #define C4D_VertexCpyPos (C4D_MaxVertex/2)
27 
28 // a functional class to provide density for coordinates
30 {
31 public:
32  virtual int32_t GetDensity(int32_t x, int32_t y) const;
33  virtual ~C4DensityProvider() = default;
34 };
35 
37 
38 class C4Shape : public C4Rect
39 {
40 public:
41  // remember to adjust C4Shape::CopyFrom and CreateOwnOriginalCopy when adding members here!
42  int32_t VtxNum = 0;
43  int32_t VtxX[C4D_MaxVertex] = { 0 };
44  int32_t VtxY[C4D_MaxVertex] = { 0 };
45  int32_t VtxCNAT[C4D_MaxVertex] = { 0 };
46  int32_t VtxFriction[C4D_MaxVertex] = { 0 };
48  int32_t ContactCNAT = 0;
49  int32_t ContactCount = 0;
50  int32_t AttachMat = MNone;
51  int32_t VtxContactCNAT[C4D_MaxVertex] = { 0 };
52  int32_t VtxContactMat[C4D_MaxVertex] = { 0 };
53  int32_t iAttachX = 0, iAttachY = 0, iAttachVtx = 0;
54 public:
55  void Default();
56  void Rotate(C4Real Angle, bool bUpdateVertices);
57  void Stretch(int32_t iCon, bool bUpdateVertices);
58  void Jolt(int32_t iCon, bool bUpdateVertices);
59  void GetVertexOutline(C4Rect &rRect);
60  int32_t GetVertexY(int32_t iVertex);
61  int32_t GetVertexX(int32_t iVertex);
62  int32_t GetX() const { return x; }
63  int32_t GetY() const { return y; }
64  bool AddVertex(int32_t iX, int32_t iY);
65  bool CheckContact(int32_t cx, int32_t cy);
66  bool ContactCheck(int32_t cx, int32_t cy, uint32_t *border_hack_contacts=nullptr, bool collide_halfvehic=false);
67  bool Attach(int32_t &cx, int32_t &cy, BYTE cnat_pos);
68  bool LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld, int32_t oldx, int32_t oldy);
69  bool InsertVertex(int32_t iPos, int32_t tx, int32_t ty);
70  bool RemoveVertex(int32_t iPos);
71  void CopyFrom(C4Shape rFrom, bool bCpyVertices, bool fCopyVerticesFromSelf);
72  int32_t GetBottomVertex();
73  int GetBottom(); // return lowest vertex Y
74  int32_t GetVertexContact(int32_t iVtx, DWORD dwCheckMask, int32_t tx, int32_t ty, const C4DensityProvider &rDensityProvider = DefaultDensityProvider); // get CNAT-mask for given vertex - does not check range for iVtx!
75  bool CheckScaleToWalk(int x, int y);
76  void CreateOwnOriginalCopy(C4Shape &rFrom); // create copy of all vertex members in back area of own buffers
77  void CompileFunc(StdCompiler *pComp, const C4Shape *default_shape);
78 private:
79  bool CheckTouchableMaterial(int32_t x, int32_t y, int32_t vtx_i, int32_t y_dir = 0, const C4DensityProvider &rDensityProvider = DefaultDensityProvider);
80 };
81 
82 #endif // INC_C4Shape
int32_t AttachMat
Definition: C4Shape.h:50
int32_t GetY() const
Definition: C4Shape.h:63
int GetBottom()
Definition: C4Shape.cpp:468
int32_t ContactDensity
Definition: C4Shape.h:47
Definition: C4Rect.h:27
uint8_t BYTE
bool AddVertex(int32_t iX, int32_t iY)
Definition: C4Shape.cpp:28
int32_t GetBottomVertex()
Definition: C4Shape.cpp:457
void Default()
Definition: C4Shape.cpp:36
int32_t iAttachY
Definition: C4Shape.h:53
int32_t Angle(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iPrec)
Definition: Standard.cpp:37
int32_t VtxContactMat[C4D_MaxVertex]
Definition: C4Shape.h:52
int32_t GetVertexX(int32_t iVertex)
Definition: C4Shape.cpp:422
Definition: C4Real.h:58
int32_t ContactCount
Definition: C4Shape.h:49
int32_t VtxFriction[C4D_MaxVertex]
Definition: C4Shape.h:46
const int32_t MNone
Definition: C4Constants.h:177
void CreateOwnOriginalCopy(C4Shape &rFrom)
Definition: C4Shape.cpp:508
int32_t y
Definition: C4Rect.h:30
bool ContactCheck(int32_t cx, int32_t cy, uint32_t *border_hack_contacts=nullptr, bool collide_halfvehic=false)
Definition: C4Shape.cpp:350
int32_t VtxContactCNAT[C4D_MaxVertex]
Definition: C4Shape.h:51
int32_t GetVertexContact(int32_t iVtx, DWORD dwCheckMask, int32_t tx, int32_t ty, const C4DensityProvider &rDensityProvider=DefaultDensityProvider)
Definition: C4Shape.cpp:488
int32_t iAttachX
Definition: C4Shape.h:53
int32_t ContactCNAT
Definition: C4Shape.h:48
void CopyFrom(C4Shape rFrom, bool bCpyVertices, bool fCopyVerticesFromSelf)
Definition: C4Shape.cpp:434
int32_t GetX() const
Definition: C4Shape.h:62
int32_t VtxNum
Definition: C4Shape.h:42
int32_t VtxX[C4D_MaxVertex]
Definition: C4Shape.h:43
void Rotate(C4Real Angle, bool bUpdateVertices)
Definition: C4Shape.cpp:41
bool RemoveVertex(int32_t iPos)
Definition: C4Shape.cpp:326
int32_t iAttachVtx
Definition: C4Shape.h:53
C4DensityProvider DefaultDensityProvider
Definition: C4Shape.cpp:480
const int32_t C4M_Solid
Definition: C4Constants.h:172
const int C4D_MaxVertex
Definition: C4Constants.h:55
int32_t x
Definition: C4Rect.h:30
bool InsertVertex(int32_t iPos, int32_t tx, int32_t ty)
Definition: C4Shape.cpp:314
void GetVertexOutline(C4Rect &rRect)
Definition: C4Shape.cpp:144
void Stretch(int32_t iCon, bool bUpdateVertices)
Definition: C4Shape.cpp:119
bool CheckContact(int32_t cx, int32_t cy)
Definition: C4Shape.cpp:335
bool CheckScaleToWalk(int x, int y)
Definition: C4Shape.cpp:398
virtual ~C4DensityProvider()=default
bool LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld, int32_t oldx, int32_t oldy)
Definition: C4Shape.cpp:253
virtual int32_t GetDensity(int32_t x, int32_t y) const
Definition: C4Shape.cpp:482
int32_t GetVertexY(int32_t iVertex)
Definition: C4Shape.cpp:428
void CompileFunc(StdCompiler *pComp, const C4Shape *default_shape)
Definition: C4Shape.cpp:520
uint32_t DWORD
bool Attach(int32_t &cx, int32_t &cy, BYTE cnat_pos)
Definition: C4Shape.cpp:183
int32_t VtxCNAT[C4D_MaxVertex]
Definition: C4Shape.h:45
int32_t VtxY[C4D_MaxVertex]
Definition: C4Shape.h:44
void Jolt(int32_t iCon, bool bUpdateVertices)
Definition: C4Shape.cpp:134