CreateParticleEx: added "amount" parameter

fixed some minor documentation errors (mainly links)
stable-5.4
David Dormagen 2013-10-10 17:19:20 +02:00
parent 7ffa7e2ed9
commit 23a3abe01e
13 changed files with 60 additions and 37 deletions

View File

@ -49,6 +49,14 @@
<h id="properties">Properties</h>
<text>Each particle has different attributes like position, lifetime, size and more. These are set by script when creating the particle.</text>
<text>The following properties can be contained in a proplist passed to <funclink>CreateParticleEx</funclink>. For an example, see <funclink>CreateParticleEx</funclink></text>
<text>You can assign either constants to the properties (f.e. <code>R = 200</code>) or use certain value provider functions (f.e. <code>R = <funclink>PV_Linear</funclink>(200, 0)</code>). Available value provider functions are:
<funclink>PV_Linear</funclink>
<funclink>PV_Direction</funclink>
<funclink>PV_Random</funclink>
<funclink>PV_Step</funclink>
<funclink>PV_Speed</funclink>
<funclink>PV_KeyFrames</funclink>
</text>
<text>
<table>
<caption id="particledef">Particle definition proplist</caption>

View File

@ -28,22 +28,27 @@
<param>
<type>int</type>
<name>speed_x</name>
<desc>Starting speed of the particle in x-direction.</desc>
<desc>Starting speed of the particle in x-direction. Can also be a value provider function.</desc>
</param>
<param>
<type>int</type>
<name>speed_y</name>
<desc>Starting speed of the particle in y-direction.</desc>
<desc>Starting speed of the particle in y-direction. Can also be a value provider function.</desc>
</param>
<param>
<type>int</type>
<name>lifetime</name>
<desc>Time in frames that the particle will be alive before it is removed.</desc>
<desc>Time in frames that the particle will be alive before it is removed. Can also be a value provider function.</desc>
</param>
<param>
<type>proplist</type>
<name>properties</name>
<desc>PropList with the particle attributes (see <emlink href="#attributes">below</emlink>).</desc>
<desc>PropList with the particle attributes (see the <emlink href="particle/index.html#attributes">particle documentation</emlink>).</desc>
</param>
<param>
<type>int</type>
<name>amount</name>
<desc>Amount of particles to create. Defaults to 1.</desc>
</param>
</params>
</syntax>
@ -67,10 +72,9 @@ var particles =
ForceX = <funclink>PV_Random</funclink>(-5, 5, 15),
Phase = <funclink>PV_Step</funclink>(1, 0, 10)
};
for (var i = 0; i &lt; 100; ++i)
<funclink>CreateParticleEx</funclink>("Fire", 0, 0, RandomX(-30, 30), RandomX(-30, 30), RandomX(18, 38 * 5), particles);
<funclink>CreateParticleEx</funclink>("Fire", 0, 0, <funclink>PV_Random(-200, 200)</funclink>, <funclink>PV_Random</funclink>(-200, 200), <funclink>PV_Random</funclink>(18, 38 * 5), particles, 100);
</code>
<text>Casts around 100 particles with a previously defined behavior.</text>
<text>Casts 100 particles with a previously defined behavior.</text>
</example>
</examples>
<related>

View File

@ -18,7 +18,7 @@
</params>
</syntax>
<desc>A particle collision function. The particle will bounce off the ground on collision. If your particles get stuck instead of bouncing, you might need to increase the CollisionVertex value a bit.</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -11,7 +11,7 @@
<rtype>array</rtype>
</syntax>
<desc>A particle collision function. The particle will die on collision.</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -19,7 +19,7 @@
</params>
</syntax>
<desc>The value depends on the current angle of movement of the particle. Usually the factor-parameter can be left out, since the original purpose of this function is to be used for the rotation-property.</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -38,7 +38,7 @@
</params>
</syntax>
<desc>The value returned will be an interpolated value of the (smoothed) curve between the up to 4 key frames. PV_KeyFrames(0, 0, X, 1000, Y) is equivalent to PV_Linear(X, Y).</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -23,7 +23,7 @@
</params>
</syntax>
<desc>The value will go linearly from start_value to end_value over the life of the particle.</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Direction</funclink>

View File

@ -31,7 +31,7 @@
</params>
</syntax>
<desc>The value will be a random number in the interval from start_value to (not including) end_value. The values in between are not whole integers, but are also in fraction of integers. This means that PV_Random(0, 1) can not only return one value (the 0) but a lot of different values in the interval between 0 and 1.</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -23,7 +23,7 @@
</params>
</syntax>
<desc>The value will depend on the speed of the particle.</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -30,7 +30,7 @@
</params>
</syntax>
<desc>PV_Step can be used for values that do not depend on the particle age (unlike f.e. <funclink>PV_Linear</funclink>).</desc>
<remark>See the <emlink href="particles/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<remark>See the <emlink href="particle/index.html">particle documentation</emlink> for further explanations of the particle system.</remark>
<related>
<funclink>CreateParticleEx</funclink>
<funclink>PV_Linear</funclink>

View File

@ -1533,11 +1533,12 @@ static bool FnCreateParticle(C4PropList * _this, C4String *szName, long iX, long
return true;
}
static bool FnCreateParticleEx(C4PropList * _this, C4String *name, long x, long y, C4Value speedX, C4Value speedY, int lifetime, C4PropList *properties, int attachment)
static bool FnCreateParticleEx(C4PropList * _this, C4String *name, long x, long y, C4Value speedX, C4Value speedY, C4Value lifetime, C4PropList *properties, int amount, int attachment)
{
// safety
C4Object *obj = Object(_this);
if (obj && !_this->Status) return false;
if (amount <= 0) amount = 1;
// local offset
if (obj)
@ -1549,11 +1550,12 @@ static bool FnCreateParticleEx(C4PropList * _this, C4String *name, long x, long
C4ParticleDef *pDef=::Particles.GetDef(FnStringPar(name));
if (!pDef) return false;
// construct data
C4DynamicParticleValueProvider valueSpeedX, valueSpeedY;
C4DynamicParticleValueProvider valueSpeedX, valueSpeedY, valueLifetime;
valueSpeedX.Set(speedX);
valueSpeedY.Set(speedY);
valueLifetime.Set(lifetime);
// create
::DynamicParticles.Create(pDef, (float)x, (float)y, valueSpeedX, valueSpeedY, (float)lifetime, properties, obj ? (attachment == 1 ? obj->DynamicBackParticles : obj->DynamicFrontParticles) : NULL, obj);
::DynamicParticles.Create(pDef, (float)x, (float)y, valueSpeedX, valueSpeedY, valueLifetime, properties, amount, obj ? (attachment == 1 ? obj->DynamicBackParticles : obj->DynamicFrontParticles) : NULL, obj);
// success, even if not created
return true;
}

View File

@ -252,9 +252,9 @@ void C4DynamicParticleValueProvider::Floatify(float denominator)
void C4DynamicParticleValueProvider::RollRandom()
{
int range = (int)(100.f * (endValue - startValue));
int randomValue = SafeRandom(range);
currentValue = startValue + (float)randomValue / 100.0f;
float range = endValue - startValue;
float rnd = (float)(rand()) / (float)(RAND_MAX);
currentValue = startValue + rnd * range;
}
float C4DynamicParticleValueProvider::GetValue(C4DynamicParticle *forParticle)
@ -980,7 +980,7 @@ void C4DynamicParticleSystem::ReleaseParticleList(C4DynamicParticleList *first,
particleListAccessMutex.Leave();
}
C4DynamicParticle *C4DynamicParticleSystem::Create(C4ParticleDef *of_def, float x, float y, C4DynamicParticleValueProvider &speedX, C4DynamicParticleValueProvider &speedY, float lifetime, C4PropList *properties, C4DynamicParticleList *pxList, C4Object *object)
void C4DynamicParticleSystem::Create(C4ParticleDef *of_def, float x, float y, C4DynamicParticleValueProvider &speedX, C4DynamicParticleValueProvider &speedY, C4DynamicParticleValueProvider &lifetime, C4PropList *properties, int amount, C4DynamicParticleList *pxList, C4Object *object)
{
// todo: check amount etc
@ -1000,23 +1000,31 @@ C4DynamicParticle *C4DynamicParticleSystem::Create(C4ParticleDef *of_def, float
C4DynamicParticleProperties particleProperties;
particleProperties.Set(properties);
// create a particle in the fitting chunk
C4DynamicParticle *particle = pxList->AddNewParticle(of_def, particleProperties.blitMode);
speedX.Floatify(10.f);
speedY.Floatify(10.f);
// initialize some more properties
particle->properties = particleProperties;
// this will adjust the initial values of the (possibly cached) particle properties
particle->properties.Floatify();
while (amount--)
{
if (speedX.IsRandom()) speedX.RollRandom();
if (speedY.IsRandom()) speedY.RollRandom();
if (lifetime.IsRandom()) lifetime.RollRandom();
// create a particle in the fitting chunk
C4DynamicParticle *particle = pxList->AddNewParticle(of_def, particleProperties.blitMode);
// setup some more non-property attributes of the particle
particle->lifetime = particle->startingLifetime = lifetime;
particle->currentSpeedX = speedX.GetValue(particle);
particle->currentSpeedY = speedY.GetValue(particle);
particle->drawingData.aspect = of_def->Aspect;
particle->SetPosition(x, y);
particle->drawingData.SetColor(particle->properties.colorR.GetValue(particle), particle->properties.colorG.GetValue(particle), particle->properties.colorB.GetValue(particle), particle->properties.colorAlpha.GetValue(particle));
// initialize some more properties
particle->properties = particleProperties;
// this will adjust the initial values of the (possibly cached) particle properties
particle->properties.Floatify();
return particle;
// setup some more non-property attributes of the particle
particle->lifetime = particle->startingLifetime = lifetime.GetValue(particle);
particle->currentSpeedX = speedX.GetValue(particle);
particle->currentSpeedY = speedY.GetValue(particle);
particle->drawingData.aspect = of_def->Aspect;
particle->SetPosition(x, y);
particle->drawingData.SetColor(particle->properties.colorR.GetValue(particle), particle->properties.colorG.GetValue(particle), particle->properties.colorB.GetValue(particle), particle->properties.colorAlpha.GetValue(particle));
}
}
void C4DynamicParticleSystem::PreparePrimitiveRestartIndices(uint32_t forAmount)

View File

@ -98,6 +98,7 @@ public:
void SetParameterValue(int type, const C4Value &value, float C4DynamicParticleValueProvider::*floatVal, int C4DynamicParticleValueProvider::*intVal = 0, size_t keyFrameIndex = 0);
bool IsConstant() const { return isConstant; }
bool IsRandom() const { return valueFunction == &C4DynamicParticleValueProvider::Random; }
C4DynamicParticleValueProvider() : startValue(0.f), endValue(0.f), currentValue(0.f), rerollInterval(0), smoothing(0), valueFunction(0), isConstant(true), floatValueToChange(0), typeOfValueToChange(VAL_TYPE_FLOAT) { }
~C4DynamicParticleValueProvider()
{
@ -354,7 +355,7 @@ public:
void PreparePrimitiveRestartIndices(uint32_t forSize);
void *GetPrimitiveRestartArray() { return (void*)&primitiveRestartIndices[0]; }
C4DynamicParticle *Create(C4ParticleDef *of_def, float x, float y, C4DynamicParticleValueProvider &speedX, C4DynamicParticleValueProvider &speedY, float lifetime, C4PropList *properties, C4DynamicParticleList *pxList=NULL, C4Object *object=NULL);
void Create(C4ParticleDef *of_def, float x, float y, C4DynamicParticleValueProvider &speedX, C4DynamicParticleValueProvider &speedY, C4DynamicParticleValueProvider &lifetime, C4PropList *properties, int amount = 1, C4DynamicParticleList *pxList=NULL, C4Object *object=NULL);
friend class CalculationThread;
};