2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 1998 - 2000 , Matthes Bender
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
/* Basic classes for rectangles and vertex outlines */
# ifndef INC_C4Shape
# define INC_C4Shape
2016-04-03 18:07:56 +00:00
# include "config/C4Constants.h"
# include "lib/C4Rect.h"
2009-05-08 13:28:41 +00:00
# define C4D_VertexCpyPos (C4D_MaxVertex / 2)
// a functional class to provide density for coordinates
class C4DensityProvider
2010-03-28 17:58:21 +00:00
{
public :
virtual int32_t GetDensity ( int32_t x , int32_t y ) const ;
2017-05-07 11:50:00 +00:00
virtual ~ C4DensityProvider ( ) = default ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
extern C4DensityProvider DefaultDensityProvider ;
2015-11-14 15:17:00 +00:00
class C4Shape : public C4Rect
2010-03-28 17:58:21 +00:00
{
public :
// remember to adjust C4Shape::CopyFrom and CreateOwnOriginalCopy when adding members here!
2015-11-14 15:17:00 +00:00
int32_t VtxNum = 0 ;
int32_t VtxX [ C4D_MaxVertex ] = { 0 } ;
int32_t VtxY [ C4D_MaxVertex ] = { 0 } ;
int32_t VtxCNAT [ C4D_MaxVertex ] = { 0 } ;
int32_t VtxFriction [ C4D_MaxVertex ] = { 0 } ;
int32_t ContactDensity = C4M_Solid ;
int32_t ContactCNAT = 0 ;
int32_t ContactCount = 0 ;
int32_t AttachMat = MNone ;
int32_t VtxContactCNAT [ C4D_MaxVertex ] = { 0 } ;
int32_t VtxContactMat [ C4D_MaxVertex ] = { 0 } ;
int32_t iAttachX = 0 , iAttachY = 0 , iAttachVtx = 0 ;
2010-03-28 17:58:21 +00:00
public :
void Default ( ) ;
2013-05-25 11:10:54 +00:00
void Rotate ( C4Real Angle , bool bUpdateVertices ) ;
2010-03-28 17:58:21 +00:00
void Stretch ( int32_t iCon , bool bUpdateVertices ) ;
void Jolt ( int32_t iCon , bool bUpdateVertices ) ;
void GetVertexOutline ( C4Rect & rRect ) ;
int32_t GetVertexY ( int32_t iVertex ) ;
int32_t GetVertexX ( int32_t iVertex ) ;
2013-08-31 21:23:35 +00:00
int32_t GetX ( ) const { return x ; }
int32_t GetY ( ) const { return y ; }
2010-03-28 17:58:21 +00:00
bool AddVertex ( int32_t iX , int32_t iY ) ;
bool CheckContact ( int32_t cx , int32_t cy ) ;
2017-05-07 11:50:00 +00:00
bool ContactCheck ( int32_t cx , int32_t cy , uint32_t * border_hack_contacts = nullptr , bool collide_halfvehic = false ) ;
2010-03-28 17:58:21 +00:00
bool Attach ( int32_t & cx , int32_t & cy , BYTE cnat_pos ) ;
bool LineConnect ( int32_t tx , int32_t ty , int32_t cvtx , int32_t ld , int32_t oldx , int32_t oldy ) ;
bool InsertVertex ( int32_t iPos , int32_t tx , int32_t ty ) ;
bool RemoveVertex ( int32_t iPos ) ;
void CopyFrom ( C4Shape rFrom , bool bCpyVertices , bool fCopyVerticesFromSelf ) ;
int32_t GetBottomVertex ( ) ;
2012-07-27 15:44:59 +00:00
int GetBottom ( ) ; // return lowest vertex Y
2010-03-28 17:58:21 +00:00
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!
2012-06-18 23:40:37 +00:00
bool CheckScaleToWalk ( int x , int y ) ;
2010-03-28 17:58:21 +00:00
void CreateOwnOriginalCopy ( C4Shape & rFrom ) ; // create copy of all vertex members in back area of own buffers
2013-03-30 14:59:15 +00:00
void CompileFunc ( StdCompiler * pComp , const C4Shape * default_shape ) ;
2015-08-30 13:19:36 +00:00
private :
bool CheckTouchableMaterial ( int32_t x , int32_t y , int32_t vtx_i , int32_t y_dir = 0 , const C4DensityProvider & rDensityProvider = DefaultDensityProvider ) ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
# endif // INC_C4Shape