dynamic particles: added collision function PC_Stop; added value provider function PV_Gravity

stable-5.4
David Dormagen 2013-10-19 14:50:43 +02:00
parent 0707458264
commit 63009705ed
7 changed files with 155 additions and 4 deletions

View File

@ -56,6 +56,8 @@
<funclink>PV_Step</funclink>
<funclink>PV_Speed</funclink>
<funclink>PV_KeyFrames</funclink>
<funclink>PV_Wind</funclink>
<funclink>PV_Gravity</funclink>
</text>
<text>
<table>
@ -137,7 +139,7 @@
</row>
<row>
<col>OnCollision</col>
<col><funclink>PC_Die</funclink>, <funclink>PC_Bounce</funclink></col>
<col><funclink>PC_Die</funclink>, <funclink>PC_Bounce</funclink>, <funclink>PC_Stop</funclink></col>
<col>Defines what happens when the particle collides with the landscape.</col>
</row>
<row>

View File

@ -84,8 +84,11 @@ var particles =
<funclink>PV_Step</funclink>
<funclink>PV_Speed</funclink>
<funclink>PV_KeyFrames</funclink>
<funclink>PV_Wind</funclink>
<funclink>PV_Gravity</funclink>
<funclink>PC_Die</funclink>
<funclink>PC_Bounce</funclink>
<funclink>PC_Stop</funclink>
</related>
</func>
<author>Zapper</author><date>2013-10</date>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>PC_Stop</title>
<category>Particles</category>
<version>5.3.3 OC</version>
<syntax>
<rtype>array</rtype>
</syntax>
<desc>A particle collision function. The particle will set its velocity to zero on collision.</desc>
<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>
<funclink>PV_Direction</funclink>
<funclink>PV_Random</funclink>
<funclink>PV_KeyFrames</funclink>
<funclink>PV_Step</funclink>
<funclink>PV_Speed</funclink>
<funclink>PV_Wind</funclink>
<funclink>PC_Bounce</funclink>
<funclink>PC_Die</funclink>
</related>
</func>
<author>Zapper</author><date>2013-10</date>
</funcs>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>PV_Wind</title>
<category>Particles</category>
<version>5.3.3 OC</version>
<syntax>
<rtype>array</rtype>
<params>
<param>
<type>int</type>
<name>factor</name>
<desc>Factor for the speed. 1000 is a factor of 1.0.</desc>
</param>
<param>
<type>int</type>
<name>constant_value</name>
<desc>Value that is added to the result.</desc>
</param>
</params>
</syntax>
<desc>The value will depend on the wind at the current position of the particle.</desc>
<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>
<funclink>PV_Random</funclink>
<funclink>PV_Step</funclink>
<funclink>PV_Speed</funclink>
<funclink>PV_KeyFrames</funclink>
<funclink>PC_Die</funclink>
<funclink>PC_Bounce</funclink>
<funclink>PC_Stop</funclink>
</related>
</func>
<author>Zapper</author><date>2013-10</date>
</funcs>

View File

@ -1682,7 +1682,25 @@ static C4ValueArray* FnPV_Speed(C4PropList * _this, C4Value factor, C4Value star
{
C4ValueArray *pArray = new C4ValueArray(3);
pArray->SetItem(0, C4VInt(C4PV_Speed));
pArray->SetItem(1, factor);
pArray->SetItem(1, factor.GetType() == C4V_Nil ? C4VInt(1000) : factor);
pArray->SetItem(2, startValue);
return pArray;
}
static C4ValueArray* FnPV_Wind(C4PropList * _this, C4Value factor, C4Value startValue)
{
C4ValueArray *pArray = new C4ValueArray(3);
pArray->SetItem(0, C4VInt(C4PV_Wind));
pArray->SetItem(1, factor.GetType() == C4V_Nil ? C4VInt(1000) : factor);
pArray->SetItem(2, startValue);
return pArray;
}
static C4ValueArray* FnPV_Gravity(C4PropList * _this, C4Value factor, C4Value startValue)
{
C4ValueArray *pArray = new C4ValueArray(3);
pArray->SetItem(0, C4VInt(C4PV_Gravity));
pArray->SetItem(1, factor.GetType() == C4V_Nil ? C4VInt(1000) : factor);
pArray->SetItem(2, startValue);
return pArray;
}
@ -1702,6 +1720,13 @@ static C4ValueArray* FnPC_Bounce(C4PropList * _this, C4Value bouncyness)
return pArray;
}
static C4ValueArray* FnPC_Stop(C4PropList * _this)
{
C4ValueArray *pArray = new C4ValueArray(1);
pArray->SetItem(0, C4VInt(C4PC_Stop));
return pArray;
}
static bool FnSetSkyParallax(C4PropList * _this, Nillable<long> iMode, Nillable<long> iParX, Nillable<long> iParY, Nillable<long> iXDir, Nillable<long> iYDir, Nillable<long> iX, Nillable<long> iY)
{
// set all parameters that aren't nil
@ -2548,9 +2573,12 @@ void InitGameFunctionMap(C4AulScriptEngine *pEngine)
F(PV_Direction);
F(PV_Step);
F(PV_Speed);
F(PV_Wind);
F(PV_Gravity);
// F(PV_KeyFrames); added below
F(PC_Die);
F(PC_Bounce);
F(PC_Stop);
AddFunc(pEngine, "IncinerateLandscape", FnIncinerateLandscape);
AddFunc(pEngine, "GetGravity", FnGetGravity);

View File

@ -26,6 +26,7 @@
#include <C4DrawGL.h>
#include <C4Random.h>
#include <C4Landscape.h>
#include <C4Weather.h>
#endif
#ifndef USE_CONSOLE
@ -247,7 +248,7 @@ void C4DynamicParticleValueProvider::Floatify(float denominator)
//LogF("KF is %f @ %f", keyFrames[2 * i + 1], keyFrames[2 * i]);
}
}
else if (valueFunction == &C4DynamicParticleValueProvider::Speed)
else if (valueFunction == &C4DynamicParticleValueProvider::Speed || valueFunction == &C4DynamicParticleValueProvider::Wind || valueFunction == &C4DynamicParticleValueProvider::Gravity)
{
FloatifyParameterValue(&C4DynamicParticleValueProvider::speedFactor, 1000.0f);
}
@ -337,6 +338,16 @@ float C4DynamicParticleValueProvider::Speed(C4DynamicParticle *forParticle)
return startValue + speedFactor * speed;
}
float C4DynamicParticleValueProvider::Wind(C4DynamicParticle *forParticle)
{
return startValue + (speedFactor * ::Weather.GetWind((int)forParticle->positionX, (int)forParticle->positionY));
}
float C4DynamicParticleValueProvider::Gravity(C4DynamicParticle *forParticle)
{
return startValue + (speedFactor * ::Landscape.Gravity);
}
void C4DynamicParticleValueProvider::SetType(C4ParticleValueProviderID what)
{
switch (what)
@ -362,6 +373,12 @@ void C4DynamicParticleValueProvider::SetType(C4ParticleValueProviderID what)
case C4PV_Speed:
valueFunction = &C4DynamicParticleValueProvider::Speed;
break;
case C4PV_Wind:
valueFunction = &C4DynamicParticleValueProvider::Wind;
break;
case C4PV_Gravity:
valueFunction = &C4DynamicParticleValueProvider::Gravity;
break;
default:
assert(false && "Invalid C4DynamicParticleValueProvider ID passed");
};
@ -465,6 +482,22 @@ void C4DynamicParticleValueProvider::Set(const C4ValueArray &fromArray)
SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4DynamicParticleValueProvider::startValue);
}
break;
case C4PV_Wind:
if (arraySize >= 3)
{
SetType(C4PV_Wind);
SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4DynamicParticleValueProvider::speedFactor);
SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4DynamicParticleValueProvider::startValue);
}
break;
case C4PV_Gravity:
if (arraySize >= 3)
{
SetType(C4PV_Gravity);
SetParameterValue(VAL_TYPE_FLOAT, fromArray[1], &C4DynamicParticleValueProvider::speedFactor);
SetParameterValue(VAL_TYPE_FLOAT, fromArray[2], &C4DynamicParticleValueProvider::startValue);
}
break;
default:
throw new C4AulExecError("invalid particle value provider supplied");
break;
@ -643,6 +676,9 @@ void C4DynamicParticleProperties::SetCollisionFunc(const C4Value &source)
if (arraySize >= 2)
bouncyness = ((float)(*valueArray)[1].getInt());
break;
case C4PC_Stop:
collisionCallback = &C4DynamicParticleProperties::CollisionStop;
break;
default:
assert(false);
break;
@ -656,6 +692,13 @@ bool C4DynamicParticleProperties::CollisionBounce(C4DynamicParticle *forParticle
return true;
}
bool C4DynamicParticleProperties::CollisionStop(C4DynamicParticle *forParticle)
{
forParticle->currentSpeedX = 0.f;
forParticle->currentSpeedY = 0.f;
return true;
}
void C4DynamicParticle::Init()
{
currentSpeedX = currentSpeedY = 0.f;

View File

@ -31,6 +31,8 @@ enum C4ParticleValueProviderID
C4PV_Direction,
C4PV_Step,
C4PV_Speed,
C4PV_Wind,
C4PV_Gravity,
};
enum C4ParticleAttachmentPropertyID
@ -45,6 +47,7 @@ enum C4ParticleCollisionFuncID
{
C4PC_Die,
C4PC_Bounce,
C4PC_Stop,
};
class C4DynamicParticleList;
@ -70,7 +73,7 @@ protected:
int rerollInterval; // for Random
size_t keyFrameCount; // for KeyFrames
float delay; // for Step
float speedFactor; // for Speed
float speedFactor; // for Speed & Wind & Gravity
};
union
@ -134,6 +137,8 @@ public:
float Direction(C4DynamicParticle *forParticle);
float Step(C4DynamicParticle *forParticle);
float Speed(C4DynamicParticle *forParticle);
float Wind(C4DynamicParticle *forParticle);
float Gravity(C4DynamicParticle *forParticle);
};
class C4DynamicParticleProperties
@ -168,6 +173,7 @@ public:
bool CollisionDie(C4DynamicParticle *forParticle) { return false; }
bool CollisionBounce(C4DynamicParticle *forParticle);
bool CollisionStop(C4DynamicParticle *forParticle);
};
class C4DynamicParticle