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

#include <C4Particles.h>

Collaboration diagram for C4Particle:
[legend]

Classes

struct  DrawingData
 

Public Member Functions

float GetAge () const
 
float GetLifetime () const
 
float GetRelativeAge () const
 
void Init ()
 
 C4Particle ()
 
void SetPosition (float x, float y)
 
bool Exec (C4Object *obj, float timeDelta, C4ParticleDef *sourceDef)
 

Public Attributes

struct C4Particle::DrawingData drawingData
 

Protected Attributes

float currentSpeedX
 
float currentSpeedY
 
float positionX
 
float positionY
 
float lifetime
 
float startingLifetime
 
C4ParticleProperties properties
 

Friends

class C4ParticleProperties
 
class C4ParticleValueProvider
 
class C4ParticleChunk
 
class C4ParticleSystem
 

Detailed Description

Definition at line 235 of file C4Particles.h.

Constructor & Destructor Documentation

C4Particle::C4Particle ( )
inline

Definition at line 322 of file C4Particles.h.

References Init().

Referenced by C4ParticleChunk::AddNewParticle().

322 { Init(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Member Function Documentation

bool C4Particle::Exec ( C4Object obj,
float  timeDelta,
C4ParticleDef sourceDef 
)

Definition at line 891 of file C4Particles.cpp.

References C4ParticleProperties::collisionCallback, C4ParticleProperties::collisionDensity, C4ParticleProperties::collisionVertex, C4ParticleProperties::colorAlpha, C4ParticleProperties::colorB, C4ParticleProperties::colorG, C4ParticleProperties::colorR, currentSpeedX, currentSpeedY, drawingData, C4ParticleProperties::forceX, C4ParticleProperties::forceY, GBackDensity(), C4ParticleValueProvider::GetValue(), C4ParticleProperties::hasCollisionVertex, C4ParticleProperties::hasConstantColor, C4ParticleValueProvider::IsConstant(), lifetime, C4ParticleProperties::phase, C4Particle::DrawingData::phase, positionX, positionY, properties, C4ParticleProperties::rotation, C4Particle::DrawingData::SetColor(), C4Particle::DrawingData::SetPhase(), C4Particle::DrawingData::SetPosition(), C4ParticleProperties::size, C4ParticleProperties::speedDampingX, C4ParticleProperties::speedDampingY, startingLifetime, and C4ParticleProperties::stretch.

Referenced by C4ParticleChunk::Exec().

892 {
893  // die of old age? :<
894  lifetime -= timeDelta;
895  // check only if we had a maximum lifetime to begin with (for permanent particles)
896  if (startingLifetime > 0.f)
897  {
898  if (lifetime <= 0.f) return false;
899  }
900 
901  // movement
902  float currentForceX = properties.forceX.GetValue(this);
903  float currentForceY = properties.forceY.GetValue(this);
904 
905  currentSpeedX += currentForceX;
906  currentSpeedY += currentForceY;
907 
908  if (currentSpeedX != 0.f || currentSpeedY != 0.f)
909  {
910  float currentDampingX = properties.speedDampingX.GetValue(this);
911  float currentDampingY = properties.speedDampingY.GetValue(this);
912  float size = properties.size.GetValue(this);
913 
914  currentSpeedX *= currentDampingX;
915  currentSpeedY *= currentDampingY;
916 
917  // move & collision check
918  // note: accessing Landscape.GetDensity here is not protected by locks
919  // it is assumed that the particle system is cleaned up before, f.e., the landscape memory is freed
920  bool collided = false;
922  {
923  float collisionPoint = properties.collisionVertex.GetValue(this);
924  float size_x = (currentSpeedX > 0.f ? size : -size) * 0.5f * collisionPoint;
925  float size_y = (currentSpeedY > 0.f ? size : -size) * 0.5f * collisionPoint;
926  float density = static_cast<float>(GBackDensity(positionX + size_x + timeDelta * currentSpeedX, positionY + size_y + timeDelta * currentSpeedY));
927 
928  if (density + 0.5f >= properties.collisionDensity.GetValue(this)) // Small offset against floating point insanities.
929  {
930  // exec collision func
931  if (properties.collisionCallback != 0 && !(properties.*properties.collisionCallback)(this)) return false;
932  collided = true;
933  }
934  }
935 
936  if (!collided)
937  {
938  positionX += timeDelta * currentSpeedX;
939  positionY += timeDelta * currentSpeedY;
940  }
942 
943  }
945  {
947  }
948 
949  // adjust color
951  {
953  }
954 
955  int currentPhase = (int)(properties.phase.GetValue(this) + 0.5f);
956  if (currentPhase != drawingData.phase)
957  drawingData.SetPhase(currentPhase, sourceDef);
958 
959  return true;
960 }
C4ParticleProperties properties
Definition: C4Particles.h:314
C4ParticleValueProvider forceY
Definition: C4Particles.h:206
C4ParticleValueProvider phase
Definition: C4Particles.h:210
C4ParticleValueProvider stretch
Definition: C4Particles.h:205
C4ParticleValueProvider forceX
Definition: C4Particles.h:206
C4ParticleValueProvider colorG
Definition: C4Particles.h:208
void SetPhase(int phase, C4ParticleDef *sourceDef)
float positionY
Definition: C4Particles.h:311
float startingLifetime
Definition: C4Particles.h:312
C4ParticleValueProvider colorAlpha
Definition: C4Particles.h:208
bool IsConstant() const
Definition: C4Particles.h:157
float lifetime
Definition: C4Particles.h:312
float currentSpeedX
Definition: C4Particles.h:310
float GetValue(C4Particle *forParticle)
float currentSpeedY
Definition: C4Particles.h:310
C4ParticleValueProvider rotation
Definition: C4Particles.h:209
C4ParticleCollisionCallback collisionCallback
Definition: C4Particles.h:214
void SetColor(float r, float g, float b, float a=1.0f)
Definition: C4Particles.h:290
C4ParticleValueProvider speedDampingX
Definition: C4Particles.h:207
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:227
C4ParticleValueProvider speedDampingY
Definition: C4Particles.h:207
C4ParticleValueProvider collisionVertex
Definition: C4Particles.h:211
C4ParticleValueProvider collisionDensity
Definition: C4Particles.h:211
C4ParticleValueProvider colorB
Definition: C4Particles.h:208
C4ParticleValueProvider colorR
Definition: C4Particles.h:208
struct C4Particle::DrawingData drawingData
void SetPosition(float x, float y, float size, float rotation=0.f, float stretch=1.f)
C4ParticleValueProvider size
Definition: C4Particles.h:205
float positionX
Definition: C4Particles.h:311

Here is the call graph for this function:

Here is the caller graph for this function:

float C4Particle::GetAge ( ) const
inline

Definition at line 317 of file C4Particles.h.

References lifetime.

317 { return startingLifetime - lifetime; }
float startingLifetime
Definition: C4Particles.h:312
float lifetime
Definition: C4Particles.h:312
float C4Particle::GetLifetime ( ) const
inline

Definition at line 318 of file C4Particles.h.

References lifetime.

318 { return lifetime; }
float lifetime
Definition: C4Particles.h:312
float C4Particle::GetRelativeAge ( ) const
inline

Definition at line 319 of file C4Particles.h.

References startingLifetime.

319 { return (startingLifetime != 0.f) ? (1.0f - (lifetime / startingLifetime)) : 0.f; }
float startingLifetime
Definition: C4Particles.h:312
float lifetime
Definition: C4Particles.h:312
void C4Particle::Init ( )

Definition at line 884 of file C4Particles.cpp.

References currentSpeedX, currentSpeedY, lifetime, positionX, positionY, and startingLifetime.

Referenced by C4Particle().

885 {
887  positionX = positionY = 0.f;
888  lifetime = startingLifetime = 5.f * 38.f;
889 }
float positionY
Definition: C4Particles.h:311
float startingLifetime
Definition: C4Particles.h:312
float lifetime
Definition: C4Particles.h:312
float currentSpeedX
Definition: C4Particles.h:310
float currentSpeedY
Definition: C4Particles.h:310
float positionX
Definition: C4Particles.h:311

Here is the caller graph for this function:

void C4Particle::SetPosition ( float  x,
float  y 
)
inline

Definition at line 324 of file C4Particles.h.

References drawingData, C4ParticleValueProvider::GetValue(), C4ParticleProperties::rotation, C4Particle::DrawingData::SetPosition(), and C4ParticleProperties::size.

Referenced by C4ParticleSystem::Create().

325  {
326  positionX = x;
327  positionY = y;
329  }
C4ParticleProperties properties
Definition: C4Particles.h:314
float positionY
Definition: C4Particles.h:311
float GetValue(C4Particle *forParticle)
C4ParticleValueProvider rotation
Definition: C4Particles.h:209
struct C4Particle::DrawingData drawingData
void SetPosition(float x, float y, float size, float rotation=0.f, float stretch=1.f)
C4ParticleValueProvider size
Definition: C4Particles.h:205
float positionX
Definition: C4Particles.h:311

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ParticleChunk
friend

Definition at line 335 of file C4Particles.h.

Referenced by C4ParticleList::GetFittingParticleChunk().

friend class C4ParticleProperties
friend

Definition at line 333 of file C4Particles.h.

friend class C4ParticleSystem
friend

Definition at line 336 of file C4Particles.h.

friend class C4ParticleValueProvider
friend

Definition at line 334 of file C4Particles.h.

Referenced by C4ParticleValueProvider::operator=().

Member Data Documentation

float C4Particle::currentSpeedX
protected
float C4Particle::currentSpeedY
protected
float C4Particle::lifetime
protected

Definition at line 312 of file C4Particles.h.

Referenced by C4ParticleSystem::Create(), Exec(), GetAge(), GetLifetime(), and Init().

float C4Particle::positionX
protected

Definition at line 311 of file C4Particles.h.

Referenced by Exec(), and Init().

float C4Particle::positionY
protected

Definition at line 311 of file C4Particles.h.

Referenced by Exec(), and Init().

C4ParticleProperties C4Particle::properties
protected

Definition at line 314 of file C4Particles.h.

Referenced by C4ParticleSystem::Create(), and Exec().

float C4Particle::startingLifetime
protected

Definition at line 312 of file C4Particles.h.

Referenced by C4ParticleSystem::Create(), Exec(), GetRelativeAge(), and Init().


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