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() {}
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 FireTop = 0;
43  int32_t VtxNum = 0;
44  int32_t VtxX[C4D_MaxVertex] = { 0 };
45  int32_t VtxY[C4D_MaxVertex] = { 0 };
46  int32_t VtxCNAT[C4D_MaxVertex] = { 0 };
47  int32_t VtxFriction[C4D_MaxVertex] = { 0 };
49  int32_t ContactCNAT = 0;
50  int32_t ContactCount = 0;
51  int32_t AttachMat = MNone;
52  int32_t VtxContactCNAT[C4D_MaxVertex] = { 0 };
53  int32_t VtxContactMat[C4D_MaxVertex] = { 0 };
54  int32_t iAttachX = 0, iAttachY = 0, iAttachVtx = 0;
55 public:
56  void Default();
57  void Rotate(C4Real Angle, bool bUpdateVertices);
58  void Stretch(int32_t iCon, bool bUpdateVertices);
59  void Jolt(int32_t iCon, bool bUpdateVertices);
60  void GetVertexOutline(C4Rect &rRect);
61  int32_t GetVertexY(int32_t iVertex);
62  int32_t GetVertexX(int32_t iVertex);
63  int32_t GetX() const { return x; }
64  int32_t GetY() const { return y; }
65  bool AddVertex(int32_t iX, int32_t iY);
66  bool CheckContact(int32_t cx, int32_t cy);
67  bool ContactCheck(int32_t cx, int32_t cy, uint32_t *border_hack_contacts=0, bool collide_halfvehic=false);
68  bool Attach(int32_t &cx, int32_t &cy, BYTE cnat_pos);
69  bool LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld, int32_t oldx, int32_t oldy);
70  bool InsertVertex(int32_t iPos, int32_t tx, int32_t ty);
71  bool RemoveVertex(int32_t iPos);
72  void CopyFrom(C4Shape rFrom, bool bCpyVertices, bool fCopyVerticesFromSelf);
73  int32_t GetBottomVertex();
74  int GetBottom(); // return lowest vertex Y
75  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!
76  bool CheckScaleToWalk(int x, int y);
77  void CreateOwnOriginalCopy(C4Shape &rFrom); // create copy of all vertex members in back area of own buffers
78  void CompileFunc(StdCompiler *pComp, const C4Shape *default_shape);
79 private:
80  bool CheckTouchableMaterial(int32_t x, int32_t y, int32_t vtx_i, int32_t y_dir = 0, const C4DensityProvider &rDensityProvider = DefaultDensityProvider);
81 };
82 
83 #endif // INC_C4Shape
int32_t AttachMat
Definition: C4Shape.h:51
int32_t GetY() const
Definition: C4Shape.h:64
int GetBottom()
Definition: C4Shape.cpp:471
int32_t ContactDensity
Definition: C4Shape.h:48
int32_t FireTop
Definition: C4Shape.h:42
Definition: C4Rect.h:29
uint8_t BYTE
bool AddVertex(int32_t iX, int32_t iY)
Definition: C4Shape.cpp:28
int32_t GetBottomVertex()
Definition: C4Shape.cpp:460
void Default()
Definition: C4Shape.cpp:36
int32_t iAttachY
Definition: C4Shape.h:54
int32_t VtxContactMat[C4D_MaxVertex]
Definition: C4Shape.h:53
int32_t GetVertexX(int32_t iVertex)
Definition: C4Shape.cpp:424
Definition: C4Real.h:58
int32_t ContactCount
Definition: C4Shape.h:50
int32_t VtxFriction[C4D_MaxVertex]
Definition: C4Shape.h:47
const int32_t MNone
Definition: C4Constants.h:178
void CreateOwnOriginalCopy(C4Shape &rFrom)
Definition: C4Shape.cpp:511
int32_t y
Definition: C4Rect.h:32
int32_t VtxContactCNAT[C4D_MaxVertex]
Definition: C4Shape.h:52
int32_t GetVertexContact(int32_t iVtx, DWORD dwCheckMask, int32_t tx, int32_t ty, const C4DensityProvider &rDensityProvider=DefaultDensityProvider)
Definition: C4Shape.cpp:491
int32_t iAttachX
Definition: C4Shape.h:54
int32_t ContactCNAT
Definition: C4Shape.h:49
void CopyFrom(C4Shape rFrom, bool bCpyVertices, bool fCopyVerticesFromSelf)
Definition: C4Shape.cpp:436
int32_t GetX() const
Definition: C4Shape.h:63
int32_t VtxNum
Definition: C4Shape.h:43
int32_t VtxX[C4D_MaxVertex]
Definition: C4Shape.h:44
void Rotate(C4Real Angle, bool bUpdateVertices)
Definition: C4Shape.cpp:41
bool RemoveVertex(int32_t iPos)
Definition: C4Shape.cpp:328
int Angle(int iX1, int iY1, int iX2, int iY2)
Definition: Standard.cpp:35
int32_t iAttachVtx
Definition: C4Shape.h:54
C4DensityProvider DefaultDensityProvider
Definition: C4Shape.cpp:483
const int32_t C4M_Solid
Definition: C4Constants.h:173
const int C4D_MaxVertex
Definition: C4Constants.h:55
int32_t x
Definition: C4Rect.h:32
virtual ~C4DensityProvider()
Definition: C4Shape.h:33
bool InsertVertex(int32_t iPos, int32_t tx, int32_t ty)
Definition: C4Shape.cpp:316
void GetVertexOutline(C4Rect &rRect)
Definition: C4Shape.cpp:146
void Stretch(int32_t iCon, bool bUpdateVertices)
Definition: C4Shape.cpp:119
bool CheckContact(int32_t cx, int32_t cy)
Definition: C4Shape.cpp:337
bool CheckScaleToWalk(int x, int y)
Definition: C4Shape.cpp:400
bool LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld, int32_t oldx, int32_t oldy)
Definition: C4Shape.cpp:255
virtual int32_t GetDensity(int32_t x, int32_t y) const
Definition: C4Shape.cpp:485
int32_t GetVertexY(int32_t iVertex)
Definition: C4Shape.cpp:430
void CompileFunc(StdCompiler *pComp, const C4Shape *default_shape)
Definition: C4Shape.cpp:523
uint32_t DWORD
bool Attach(int32_t &cx, int32_t &cy, BYTE cnat_pos)
Definition: C4Shape.cpp:185
int32_t VtxCNAT[C4D_MaxVertex]
Definition: C4Shape.h:46
int32_t VtxY[C4D_MaxVertex]
Definition: C4Shape.h:45
void Jolt(int32_t iCon, bool bUpdateVertices)
Definition: C4Shape.cpp:135
bool ContactCheck(int32_t cx, int32_t cy, uint32_t *border_hack_contacts=0, bool collide_halfvehic=false)
Definition: C4Shape.cpp:352