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 141 of file C4PXS.cpp.

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

Referenced by Execute().

142 {
143 #ifdef DEBUGREC_PXS
144  if (Config.General.DebugRec)
145  {
146  C4RCExecPXS rc;
147  rc.x=x; rc.y=y; rc.iMat=Mat;
148  rc.pos = 2;
149  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
150  }
151 #endif
152  Mat=MNone;
153  ::PXS.Delete(this);
154 }
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:532
int32_t Mat
Definition: C4PXS.h:30
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:492

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, 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 {
36 #ifdef DEBUGREC_PXS
38  {
39  C4RCExecPXS rc;
40  rc.x=x; rc.y=y; rc.iMat=Mat;
41  rc.pos = 0;
42  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
43  }
44 #endif
45  int32_t inmat;
46 
47  // Safety
48  if (!MatValid(Mat))
49  { Deactivate(); return; }
50 
51  // Out of bounds
52  if ((x<0) || (x>=::Landscape.GetWidth()) || (y<-10) || (y>=::Landscape.GetHeight()))
53  { Deactivate(); return; }
54 
55  // Material conversion
56  int32_t iX = fixtoi(x), iY = fixtoi(y);
57  inmat=GBackMat(iX,iY);
59  if (pReact && (*pReact->pFunc)(pReact, iX,iY, iX,iY, xdir,ydir, Mat,inmat, meePXSPos, nullptr))
60  { Deactivate(); return; }
61 
62  // Gravity
63  ydir+=GravAccel;
64 
65  if (GBackDensity(iX, iY + 1) < ::MaterialMap.Map[Mat].Density)
66  {
67  // Air speed: Wind plus some random
68  int32_t iWind = Weather.GetWind(iX, iY);
69  C4Real txdir = itofix(iWind, 15) + C4REAL256(Random(1200) - 600);
70  C4Real tydir = C4REAL256(Random(1200) - 600);
71 
72  // Air friction, based on WindDrift. MaxSpeed is ignored.
73  int32_t iWindDrift = std::max(::MaterialMap.Map[Mat].WindDrift - 20, 0);
74  xdir += ((txdir - xdir) * iWindDrift) * WindDrift_Factor;
75  ydir += ((tydir - ydir) * iWindDrift) * WindDrift_Factor;
76  }
77 
78  C4Real ctcox = x + xdir;
79  C4Real ctcoy = y + ydir;
80 
81  int32_t iToX = fixtoi(ctcox), iToY = fixtoi(ctcoy);
82 
83  // In bounds?
84  if (Inside<int32_t>(iToX, 0, ::Landscape.GetWidth()-1) && Inside<int32_t>(iToY, 0, ::Landscape.GetHeight()-1))
85  // Check path
86  if (::Landscape._PathFree(iX, iY, iToX, iToY))
87  {
88  x=ctcox; y=ctcoy;
89  return;
90  }
91 
92  // Test path to target position
93  int32_t iX0 = iX, iY0 = iY;
94  bool fStopMovement = false;
95  do
96  {
97  // Step
98  int32_t inX = iX + Sign(iToX - iX), inY = iY + Sign(iToY - iY);
99  // Contact?
100  inmat = GBackMat(inX, inY);
102  if (pReact)
103  {
104  if ((*pReact->pFunc)(pReact, iX,iY, inX,inY, xdir,ydir, Mat,inmat, meePXSMove, &fStopMovement))
105  {
106  // destructive contact
107  Deactivate();
108  return;
109  }
110  else
111  {
112  // no destructive contact, but speed or position changed: Stop moving for now
113  if (fStopMovement)
114  {
115  // But keep fractional positions to allow proper movement on moving ground
116  if (iX != iX0) x = itofix(iX);
117  if (iY != iY0) y = itofix(iY);
118  return;
119  }
120  // there was a reaction func, but it didn't do anything - continue movement
121  }
122  }
123  iX = inX; iY = inY;
124  }
125  while (iX != iToX || iY != iToY);
126 
127  // No contact? Free movement
128  x=ctcox; y=ctcoy;
129 #ifdef DEBUGREC_PXS
130  if (Config.General.DebugRec)
131  {
132  C4RCExecPXS rc;
133  rc.x=x; rc.y=y; rc.iMat=Mat;
134  rc.pos = 1;
135  AddDbgRec(RCT_ExecPXS, &rc, sizeof(rc));
136  }
137 #endif
138  return;
139 }
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:141
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
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: