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

#include <C4Particles.h>

Public Member Functions

bool IsConstant () const
 
bool IsRandom () const
 
 C4ParticleValueProvider ()
 
 ~C4ParticleValueProvider ()
 
 C4ParticleValueProvider (const C4ParticleValueProvider &other)
 
C4ParticleValueProvideroperator= (const C4ParticleValueProvider &other)
 
void Floatify (float denominator)
 
void Set (const C4Value &value)
 
void Set (const C4ValueArray &fromArray)
 
void Set (float to)
 
float GetValue (C4Particle *forParticle)
 

Detailed Description

Definition at line 109 of file C4Particles.h.

Constructor & Destructor Documentation

C4ParticleValueProvider::C4ParticleValueProvider ( )
inline

Definition at line 159 of file C4Particles.h.

159  :
160  startValue(0.f), endValue(0.f), currentValue(0.f), rerollInterval(0), smoothing(0), keyFrameCount(0), valueFunction(0), isConstant(true), floatValueToChange(0), typeOfValueToChange(VAL_TYPE_FLOAT)
161  { }
C4ParticleValueProvider::~C4ParticleValueProvider ( )
inline

Definition at line 162 of file C4Particles.h.

163  {
164  for (std::vector<C4ParticleValueProvider*>::iterator iter = childrenValueProviders.begin(); iter != childrenValueProviders.end(); ++iter)
165  delete *iter;
166  }
C4ParticleValueProvider::C4ParticleValueProvider ( const C4ParticleValueProvider other)
inline

Definition at line 167 of file C4Particles.h.

167 { *this = other; }

Member Function Documentation

void C4ParticleValueProvider::Floatify ( float  denominator)

Definition at line 351 of file C4Particles.cpp.

Referenced by C4ParticleSystem::Create().

352 {
353  assert (denominator != 0.f && "Trying to floatify C4ParticleValueProvider with denominator of 0");
354 
355  if (valueFunction == &C4ParticleValueProvider::Direction)
356  {
357  FloatifyParameterValue(&C4ParticleValueProvider::startValue, 1000.f);
358  return;
359  }
360 
361  FloatifyParameterValue(&C4ParticleValueProvider::startValue, denominator);
362  FloatifyParameterValue(&C4ParticleValueProvider::endValue, denominator);
363  FloatifyParameterValue(&C4ParticleValueProvider::currentValue, denominator);
364 
365  // special treatment for keyframes
366  if (valueFunction == &C4ParticleValueProvider::KeyFrames)
367  {
368  for (size_t i = 0; i < keyFrameCount; ++i)
369  {
370  FloatifyParameterValue(0, 1000.f, 2 * i); // even numbers are the time values
371  FloatifyParameterValue(0, denominator, 2 * i + 1); // odd numbers are the actual values
372  }
373  }
374  else if (valueFunction == &C4ParticleValueProvider::Speed || valueFunction == &C4ParticleValueProvider::Wind || valueFunction == &C4ParticleValueProvider::Gravity)
375  {
376  FloatifyParameterValue(&C4ParticleValueProvider::speedFactor, 1000.0f);
377  }
378  else if (valueFunction == &C4ParticleValueProvider::Step)
379  {
380  FloatifyParameterValue(&C4ParticleValueProvider::maxValue, denominator);
381  }
382  else if (valueFunction == &C4ParticleValueProvider::Sin || valueFunction == &C4ParticleValueProvider::Cos)
383  {
384  FloatifyParameterValue(&C4ParticleValueProvider::parameterValue, 1.0f);
385  FloatifyParameterValue(&C4ParticleValueProvider::maxValue, denominator);
386  }
387 }

Here is the caller graph for this function:

float C4ParticleValueProvider::GetValue ( C4Particle forParticle)

Definition at line 389 of file C4Particles.cpp.

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

390 {
391  UpdateChildren(forParticle);
392  return (this->*valueFunction)(forParticle);
393 }

Here is the caller graph for this function:

bool C4ParticleValueProvider::IsConstant ( ) const
inline

Definition at line 157 of file C4Particles.h.

Referenced by C4Particle::Exec().

157 { return isConstant; }

Here is the caller graph for this function:

bool C4ParticleValueProvider::IsRandom ( ) const
inline

Definition at line 158 of file C4Particles.h.

158 { return valueFunction == &C4ParticleValueProvider::Random; }
C4ParticleValueProvider & C4ParticleValueProvider::operator= ( const C4ParticleValueProvider other)

Definition at line 212 of file C4Particles.cpp.

References C4Particle::C4ParticleValueProvider.

213 {
214  startValue = other.startValue;
215  endValue = other.endValue;
216  currentValue = other.currentValue;
217  rerollInterval = other.rerollInterval;
218  smoothing = other.smoothing;
219  valueFunction = other.valueFunction;
220  isConstant = other.isConstant;
221  keyFrameCount = other.keyFrameCount;
222  rng = other.rng;
223 
224  if (keyFrameCount > 0)
225  {
226  keyFrames.reserve(2 * keyFrameCount);
227  keyFrames.assign(other.keyFrames.begin(), other.keyFrames.end());
228  }
229 
230  typeOfValueToChange = other.typeOfValueToChange;
231  switch (typeOfValueToChange)
232  {
233  case VAL_TYPE_FLOAT:
234  floatValueToChange = other.floatValueToChange;
235  break;
236  case VAL_TYPE_INT:
237  intValueToChange = other.intValueToChange;
238  break;
239  case VAL_TYPE_KEYFRAMES:
240  keyFrameIndex = other.keyFrameIndex;
241  break;
242  default:
243  assert (false && "Trying to copy C4ParticleValueProvider with invalid value type");
244  break;
245  }
246 
247  // copy the other's children, too
248  for (std::vector<C4ParticleValueProvider*>::const_iterator iter = other.childrenValueProviders.begin(); iter != other.childrenValueProviders.end(); ++iter)
249  {
250  childrenValueProviders.push_back(new C4ParticleValueProvider(**iter)); // custom copy constructor usage
251  }
252  return (*this);
253 }
void C4ParticleValueProvider::Set ( const C4Value value)

Definition at line 687 of file C4Particles.cpp.

References C4Value::getArray(), and C4Value::getInt().

688 {
689  C4ValueArray *valueArray= value.getArray();
690 
691  if (valueArray != 0)
692  Set(*valueArray);
693  else
694  Set((float)value.getInt());
695 }
C4ValueArray * getArray() const
Definition: C4Value.h:118
int32_t getInt() const
Definition: C4Value.h:112
void Set(const C4Value &value)

Here is the call graph for this function:

void C4ParticleValueProvider::Set ( const C4ValueArray fromArray)

Definition at line 552 of file C4Particles.cpp.

References C4PV_Const, C4PV_Cos, C4PV_Direction, C4PV_Gravity, C4PV_KeyFrames, C4PV_Linear, C4PV_Random, C4PV_Sin, C4PV_Speed, C4PV_Step, C4PV_Wind, C4V_Nil, C4ValueArray::GetSize(), and UnsyncedRandom().

553 {
554  startValue = endValue = 1.0f;
555  valueFunction = &C4ParticleValueProvider::Const;
556 
557  size_t arraySize = (size_t) fromArray.GetSize();
558  if (arraySize < 2) return;
559 
560  int type = fromArray[0].getInt();
561 
562  switch (type)
563  {
564  case C4PV_Const:
565  if (arraySize >= 2)
566  {
567  SetType(C4PV_Const);
568  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::startValue);
569  }
570  break;
571 
572  case C4PV_Linear:
573  if (arraySize >= 3)
574  {
575  SetType(C4PV_Linear);
576  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::startValue);
577  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::endValue);
578  }
579  break;
580  case C4PV_Random:
581  if (arraySize >= 3)
582  {
583  SetType(C4PV_Random);
584  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::startValue);
585  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::endValue);
586  if (arraySize >= 4 && fromArray[3].GetType() != C4V_Type::C4V_Nil)
587  SetParameterValue(VAL_TYPE_INT, fromArray[3], 0, &C4ParticleValueProvider::rerollInterval);
588  if (arraySize >= 5 && fromArray[4].GetType() != C4V_Type::C4V_Nil)
589  {
590  // We don't need the seed later on, but SetParameterValue won't accept local
591  // variables. Use an unrelated member instead which is reset below.
592  SetParameterValue(VAL_TYPE_INT, fromArray[4], 0, &C4ParticleValueProvider::alreadyRolled);
593  rng.seed(alreadyRolled);
594  }
595  else
596  {
597  rng.seed(UnsyncedRandom());
598  }
599  alreadyRolled = 0;
600  }
601  break;
602  case C4PV_Direction:
603  if (arraySize >= 2)
604  {
605  SetType(C4PV_Direction);
606  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::startValue);
607  }
608  break;
609  case C4PV_Step:
610  if (arraySize >= 4)
611  {
612  SetType(C4PV_Step);
613  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::startValue);
614  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::currentValue);
615  SetParameterValue(VAL_TYPE_FLOAT, fromArray[3], &C4ParticleValueProvider::delay);
616  SetParameterValue(VAL_TYPE_FLOAT, fromArray[4], &C4ParticleValueProvider::maxValue);
617  if (delay == 0.f) delay = 1.f;
618  }
619  break;
620  case C4PV_KeyFrames:
621  if (arraySize >= 5)
622  {
623  SetType(C4PV_KeyFrames);
624  SetParameterValue(VAL_TYPE_INT, fromArray[1], 0, &C4ParticleValueProvider::smoothing);
625  keyFrames.resize(arraySize + 4 - 1); // 2*2 additional information floats at the beginning and ending, offset the first array item, though
626 
627  keyFrameCount = 0;
628  const size_t startingOffset = 2;
629  size_t i = startingOffset;
630  for (; i < arraySize; ++i)
631  {
632  SetParameterValue(VAL_TYPE_KEYFRAMES, fromArray[(int32_t)i], 0, 0, 2 + i - startingOffset);
633  }
634  keyFrameCount = (i - startingOffset) / 2 + 2;
635 
636  startValue = keyFrames[2 + 1];
637  endValue = keyFrames[2 * keyFrameCount - 1];
638 
639  // add two points for easier interpolation at beginning and ending
640  keyFrames[0] = -500.f;
641  keyFrames[1] = keyFrames[2 + 1];
642  keyFrames[2 * keyFrameCount - 2] = 1500.f;
643  keyFrames[2 * keyFrameCount - 1] = keyFrames[keyFrameCount - 1 - 2];
644 
645  }
646  break;
647  case C4PV_Sin: // fallthrough
648  case C4PV_Cos:
649  if (arraySize >= 3)
650  {
651  SetType(static_cast<C4ParticleValueProviderID> (type)); // Sin(parameterValue) * maxValue + startValue
652  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::parameterValue);
653  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::maxValue);
654  SetParameterValue(VAL_TYPE_FLOAT, fromArray[3], &C4ParticleValueProvider::startValue);
655  }
656  break;
657  case C4PV_Speed:
658  if (arraySize >= 3)
659  {
660  SetType(C4PV_Speed);
661  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::speedFactor);
662  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::startValue);
663  }
664  break;
665  case C4PV_Wind:
666  if (arraySize >= 3)
667  {
668  SetType(C4PV_Wind);
669  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::speedFactor);
670  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::startValue);
671  }
672  break;
673  case C4PV_Gravity:
674  if (arraySize >= 3)
675  {
676  SetType(C4PV_Gravity);
677  SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4ParticleValueProvider::speedFactor);
678  SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4ParticleValueProvider::startValue);
679  }
680  break;
681  default:
682  throw C4AulExecError("invalid particle value provider supplied");
683  break;
684  }
685 }
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
int32_t GetSize() const
Definition: C4ValueArray.h:36

Here is the call graph for this function:

void C4ParticleValueProvider::Set ( float  to)

Definition at line 697 of file C4Particles.cpp.

References C4PV_Const.

698 {
699  SetType(C4PV_Const);
700  startValue = endValue = to;
701 }

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