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

890 {
891  // die of old age? :<
892  lifetime -= timeDelta;
893  // check only if we had a maximum lifetime to begin with (for permanent particles)
894  if (startingLifetime > 0.f)
895  {
896  if (lifetime <= 0.f) return false;
897  }
898 
899  // movement
900  float currentForceX = properties.forceX.GetValue(this);
901  float currentForceY = properties.forceY.GetValue(this);
902 
903  currentSpeedX += currentForceX;
904  currentSpeedY += currentForceY;
905 
906  if (currentSpeedX != 0.f || currentSpeedY != 0.f)
907  {
908  float currentDampingX = properties.speedDampingX.GetValue(this);
909  float currentDampingY = properties.speedDampingY.GetValue(this);
910  float size = properties.size.GetValue(this);
911 
912  currentSpeedX *= currentDampingX;
913  currentSpeedY *= currentDampingY;
914 
915  // move & collision check
916  // note: accessing Landscape.GetDensity here is not protected by locks
917  // it is assumed that the particle system is cleaned up before, f.e., the landscape memory is freed
918  bool collided = false;
920  {
921  float collisionPoint = properties.collisionVertex.GetValue(this);
922  float size_x = (currentSpeedX > 0.f ? size : -size) * 0.5f * collisionPoint;
923  float size_y = (currentSpeedY > 0.f ? size : -size) * 0.5f * collisionPoint;
924  float density = static_cast<float>(GBackDensity(positionX + size_x + timeDelta * currentSpeedX, positionY + size_y + timeDelta * currentSpeedY));
925 
926  if (density + 0.5f >= properties.collisionDensity.GetValue(this)) // Small offset against floating point insanities.
927  {
928  // exec collision func
929  if (properties.collisionCallback != 0 && !(properties.*properties.collisionCallback)(this)) return false;
930  collided = true;
931  }
932  }
933 
934  if (!collided)
935  {
936  positionX += timeDelta * currentSpeedX;
937  positionY += timeDelta * currentSpeedY;
938  }
940 
941  }
943  {
945  }
946 
947  // adjust color
949  {
951  }
952 
953  int currentPhase = (int)(properties.phase.GetValue(this) + 0.5f);
954  if (currentPhase != drawingData.phase)
955  drawingData.SetPhase(currentPhase, sourceDef);
956 
957  return true;
958 }
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:226
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 882 of file C4Particles.cpp.

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

Referenced by C4Particle().

883 {
885  positionX = positionY = 0.f;
886  lifetime = startingLifetime = 5.f * 38.f;
887 }
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: