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 136 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().

137 {
139  {
140  C4RCExecPXS rc;
141  rc.x=x; rc.y=y; rc.iMat=Mat;
142  rc.pos = 2;
143  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
144  }
145  Mat=MNone;
146  ::PXS.Delete(this);
147 }
C4Real y
Definition: C4Record.h:171
C4Config Config
Definition: C4Config.cpp:833
int32_t iMat
Definition: C4Record.h:173
C4ConfigGeneral General
Definition: C4Config.h:251
C4Real y
Definition: C4PXS.h:31
const int32_t MNone
Definition: C4Constants.h:177
C4Real x
Definition: C4Record.h:171
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
C4PXSSystem PXS
Definition: C4PXS.cpp:525
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:60
void Delete(C4PXS *pPXS)
Definition: C4PXS.cpp:485

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PXS::Execute ( )
protected

Definition at line 33 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().

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

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: