OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4PXS Class Reference

#include <C4PXS.h>

Collaboration diagram for C4PXS:
[legend]

Protected Member Functions

void Execute ()
 
void Deactivate ()
 

Protected Attributes

int32_t Mat
 
C4Real x
 
C4Real y
 
C4Real xdir
 
C4Real ydir
 

Friends

class C4PXSSystem
 

Detailed Description

Definition at line 25 of file C4PXS.h.

Member Function Documentation

void C4PXS::Deactivate ( )
protected

Definition at line 137 of file C4PXS.cpp.

References AddDbgRec(), Config, C4ConfigGeneral::DebugRec, DEBUGREC_PXS, C4PXSSystem::Delete(), C4Config::General, C4RCExecPXS::iMat, Mat, MNone, C4RCExecPXS::pos, PXS, RCT_ExecPXS, x, C4RCExecPXS::x, y, and C4RCExecPXS::y.

Referenced by Execute().

138 {
140  {
141  C4RCExecPXS rc;
142  rc.x=x; rc.y=y; rc.iMat=Mat;
143  rc.pos = 2;
144  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
145  }
146  Mat=MNone;
147  ::PXS.Delete(this);
148 }
C4Real y
Definition: C4Record.h:171
C4Config Config
Definition: C4Config.cpp:837
int32_t iMat
Definition: C4Record.h:173
C4ConfigGeneral General
Definition: C4Config.h:252
C4Real y
Definition: C4PXS.h:31
const int32_t MNone
Definition: C4Constants.h:178
C4Real x
Definition: C4Record.h:171
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:36
C4PXSSystem PXS
Definition: C4PXS.cpp:526
int32_t Mat
Definition: C4PXS.h:30
constexpr bool DEBUGREC_PXS
Definition: C4Include.h:32
int32_t pos
Definition: C4Record.h:175
C4Real x
Definition: C4PXS.h:31
int32_t DebugRec
Definition: C4Config.h:61
void Delete(C4PXS *pPXS)
Definition: C4PXS.cpp:486

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PXS::Execute ( )
protected

Definition at line 34 of file C4PXS.cpp.

References C4Landscape::_PathFree(), AddDbgRec(), C4REAL256(), Config, Deactivate(), C4ConfigGeneral::DebugRec, DEBUGREC_PXS, C4MaterialCore::Density, fixtoi(), GBackDensity(), GBackMat(), C4Config::General, C4Landscape::GetHeight(), C4MaterialMap::GetReactionUnsafe(), C4Landscape::GetWidth(), C4Weather::GetWind(), GravAccel, C4RCExecPXS::iMat, itofix(), Landscape, C4MaterialMap::Map, Mat, MaterialMap, MatValid(), meePXSMove, meePXSPos, C4MaterialReaction::pFunc, C4RCExecPXS::pos, Random(), RCT_ExecPXS, Sign(), Weather, C4MaterialCore::WindDrift, x, C4RCExecPXS::x, xdir, y, C4RCExecPXS::y, and ydir.

Referenced by C4PXSSystem::Execute().

35 {
37  {
38  C4RCExecPXS rc;
39  rc.x=x; rc.y=y; rc.iMat=Mat;
40  rc.pos = 0;
41  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
42  }
43  int32_t inmat;
44 
45  // Safety
46  if (!MatValid(Mat))
47  { Deactivate(); return; }
48 
49  // Out of bounds
50  if ((x<0) || (x>=::Landscape.GetWidth()) || (y<-10) || (y>=::Landscape.GetHeight()))
51  { Deactivate(); return; }
52 
53  // Material conversion
54  int32_t iX = fixtoi(x), iY = fixtoi(y);
55  inmat=GBackMat(iX,iY);
57  if (pReact && (*pReact->pFunc)(pReact, iX,iY, iX,iY, xdir,ydir, Mat,inmat, meePXSPos, nullptr))
58  { Deactivate(); return; }
59 
60  // Gravity
61  ydir+=GravAccel;
62 
63  if (GBackDensity(iX, iY + 1) < ::MaterialMap.Map[Mat].Density)
64  {
65  // Air speed: Wind plus some random
66  int32_t iWind = Weather.GetWind(iX, iY);
67  C4Real txdir = itofix(iWind, 15) + C4REAL256(Random(1200) - 600);
68  C4Real tydir = C4REAL256(Random(1200) - 600);
69 
70  // Air friction, based on WindDrift. MaxSpeed is ignored.
71  int32_t iWindDrift = std::max(::MaterialMap.Map[Mat].WindDrift - 20, 0);
72  xdir += ((txdir - xdir) * iWindDrift) * WindDrift_Factor;
73  ydir += ((tydir - ydir) * iWindDrift) * WindDrift_Factor;
74  }
75 
76  C4Real ctcox = x + xdir;
77  C4Real ctcoy = y + ydir;
78 
79  int32_t iToX = fixtoi(ctcox), iToY = fixtoi(ctcoy);
80 
81  // In bounds?
82  if (Inside<int32_t>(iToX, 0, ::Landscape.GetWidth()-1) && Inside<int32_t>(iToY, 0, ::Landscape.GetHeight()-1))
83  // Check path
84  if (::Landscape._PathFree(iX, iY, iToX, iToY))
85  {
86  x=ctcox; y=ctcoy;
87  return;
88  }
89 
90  // Test path to target position
91  int32_t iX0 = iX, iY0 = iY;
92  bool fStopMovement = false;
93  do
94  {
95  // Step
96  int32_t inX = iX + Sign(iToX - iX), inY = iY + Sign(iToY - iY);
97  // Contact?
98  inmat = GBackMat(inX, inY);
100  if (pReact)
101  {
102  if ((*pReact->pFunc)(pReact, iX,iY, inX,inY, xdir,ydir, Mat,inmat, meePXSMove, &fStopMovement))
103  {
104  // destructive contact
105  Deactivate();
106  return;
107  }
108  else
109  {
110  // no destructive contact, but speed or position changed: Stop moving for now
111  if (fStopMovement)
112  {
113  // But keep fractional positions to allow proper movement on moving ground
114  if (iX != iX0) x = itofix(iX);
115  if (iY != iY0) y = itofix(iY);
116  return;
117  }
118  // there was a reaction func, but it didn't do anything - continue movement
119  }
120  }
121  iX = inX; iY = inY;
122  }
123  while (iX != iToX || iY != iToY);
124 
125  // No contact? Free movement
126  x=ctcox; y=ctcoy;
128  {
129  C4RCExecPXS rc;
130  rc.x=x; rc.y=y; rc.iMat=Mat;
131  rc.pos = 1;
132  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
133  }
134  return;
135 }
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:193
C4Real y
Definition: C4Record.h:171
C4Config Config
Definition: C4Config.cpp:837
int32_t iMat
Definition: C4Record.h:173
uint32_t Random()
Definition: C4Random.cpp:43
C4ConfigGeneral General
Definition: C4Config.h:252
C4Material * Map
Definition: C4Material.h:171
#define GravAccel
Definition: C4Physics.h:29
bool _PathFree(int32_t x, int32_t y, int32_t x2, int32_t y2) const
int Sign(T val)
Definition: Standard.h:47
C4Real y
Definition: C4PXS.h:31
Definition: C4Real.h:58
C4MaterialReactionFunc pFunc
Definition: C4Material.h:49
C4Real ydir
Definition: C4PXS.h:31
void Deactivate()
Definition: C4PXS.cpp:137
C4Real x
Definition: C4Record.h:171
C4Landscape Landscape
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:36
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4Weather Weather
Definition: C4Weather.cpp:207
int32_t Mat
Definition: C4PXS.h:30
int32_t Density
Definition: C4Material.h:94
int32_t GetHeight() const
constexpr bool DEBUGREC_PXS
Definition: C4Include.h:32
int32_t WindDrift
Definition: C4Material.h:107
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:227
int32_t pos
Definition: C4Record.h:175
C4Real xdir
Definition: C4PXS.h:31
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
C4Real x
Definition: C4PXS.h:31
int32_t DebugRec
Definition: C4Config.h:61
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool MatValid(int32_t mat)
Definition: C4Material.h:212
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:222
int32_t GetWidth() const
C4Real C4REAL256(int x)
Definition: C4Real.h:268
int32_t GetWind(int32_t x, int32_t y)
Definition: C4Weather.cpp:95

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4PXSSystem
friend

Definition at line 28 of file C4PXS.h.

Member Data Documentation

C4Real C4PXS::x
protected
C4Real C4PXS::xdir
protected

Definition at line 31 of file C4PXS.h.

Referenced by C4PXSSystem::Create(), C4PXSSystem::Draw(), Execute(), and C4PXSSystem::Load().

C4Real C4PXS::y
protected
C4Real C4PXS::ydir
protected

Definition at line 31 of file C4PXS.h.

Referenced by C4PXSSystem::Create(), C4PXSSystem::Draw(), Execute(), and C4PXSSystem::Load().


The documentation for this class was generated from the following files: