Fixed particles for Prey.

This commit is contained in:
Justin Marshall
2026-05-07 14:00:07 -07:00
parent 469be38dbe
commit 13e58aba52
2 changed files with 463 additions and 162 deletions
+307 -31
View File
@@ -171,6 +171,140 @@ void idDeclParticle::ParseParms( idLexer &src, float *parms, int maxParms ) {
} }
} }
/*
================
idDeclParticle::IsParticleStageToken
================
*/
static bool IsParticleStageToken(const idToken& token) {
if (!token.Icmp("}")) {
return true;
}
if (!token.Icmp("{")) {
return true;
}
if (!token.Icmp("material")) {
return true;
}
if (!token.Icmp("count")) {
return true;
}
if (!token.Icmp("time")) {
return true;
}
if (!token.Icmp("cycles")) {
return true;
}
if (!token.Icmp("timeOffset")) {
return true;
}
if (!token.Icmp("deadTime")) {
return true;
}
if (!token.Icmp("randomDistribution")) {
return true;
}
if (!token.Icmp("bunching")) {
return true;
}
if (!token.Icmp("distribution")) {
return true;
}
if (!token.Icmp("direction")) {
return true;
}
if (!token.Icmp("orientation")) {
return true;
}
if (!token.Icmp("customPath")) {
return true;
}
if (!token.Icmp("speed")) {
return true;
}
if (!token.Icmp("rotation")) {
return true;
}
if (!token.Icmp("angle")) {
return true;
}
if (!token.Icmp("entityColor")) {
return true;
}
if (!token.Icmp("size")) {
return true;
}
if (!token.Icmp("aspect")) {
return true;
}
if (!token.Icmp("fadeIn")) {
return true;
}
if (!token.Icmp("fadeOut")) {
return true;
}
if (!token.Icmp("fadeIndex")) {
return true;
}
if (!token.Icmp("color")) {
return true;
}
if (!token.Icmp("fadeColor")) {
return true;
}
if (!token.Icmp("offset")) {
return true;
}
if (!token.Icmp("animationFrames")) {
return true;
}
if (!token.Icmp("animationRate")) {
return true;
}
if (!token.Icmp("boundsExpansion")) {
return true;
}
if (!token.Icmp("gravity")) {
return true;
}
#ifdef PREY
if (!token.Icmp("lowSkippable")) {
return true;
}
#endif
return false;
}
/*
================
idDeclParticle::ReadParticleParmFloat
================
*/
static bool ReadParticleParmFloat(idLexer& src, float& value) {
idToken token;
if (!src.ReadToken(&token)) {
src.Error("missing particle parm value");
return false;
}
if (!token.Cmp("-")) {
idToken token2;
if (!src.ReadToken(&token2)) {
src.Error("no number after minus sign");
return false;
}
token = "-" + token2;
}
token.StripQuotes();
value = atof(token.c_str());
return true;
}
/* /*
================ ================
idDeclParticle::ParseParametric idDeclParticle::ParseParametric
@@ -180,34 +314,91 @@ void idDeclParticle::ParseParametric( idLexer &src, idParticleParm *parm ) {
idToken token; idToken token;
parm->table = NULL; parm->table = NULL;
parm->from = parm->to = 0.0f; parm->from = 0.0f;
parm->to = 0.0f;
#ifdef PREY
parm->randomp = 0.0f;
#endif
//
// First token can be:
// 10
// -10
// table sometable
//
if (!src.ReadToken(&token)) { if (!src.ReadToken(&token)) {
src.Error( "not enough parameters" ); src.Error("missing particle parm");
return; return;
} }
if ( token.IsNumeric() ) { if (!token.Cmp("-")) {
// can have a to + 2nd parm idToken token2;
parm->from = parm->to = atof( token );
if ( src.ReadToken( &token ) ) { if (!src.ReadToken(&token2)) {
if ( !token.Icmp( "to" ) ) { src.Error("no number after minus sign");
if ( !src.ReadToken( &token ) ) {
src.Error( "missing second parameter" );
return; return;
} }
parm->to = atof( token );
} else { token = "-" + token2;
}
token.StripQuotes();
if (!token.Icmp("table")) {
if (!src.ReadToken(&token)) {
src.Error("missing table name");
return;
}
token.StripQuotes();
parm->table = static_cast<const idDeclTable*>(declManager->FindType(DECL_TABLE, token.c_str(), false));
parm->from = 0.0f;
parm->to = 1.0f;
}
else {
parm->from = atof(token.c_str());
parm->to = parm->from;
}
//
// Prey allows:
// size 1.000 to 2.000 with 0.500
// and also broken/exported formatting:
// size 1.000
// with 0.500
//
while (src.ReadToken(&token)) {
if (IsParticleStageToken(token)) {
src.UnreadToken(&token); src.UnreadToken(&token);
} break;
}
} else {
// table
parm->table = static_cast<const idDeclTable *>( declManager->FindType( DECL_TABLE, token, false ) );
} }
if (!token.Icmp("to")) {
if (!ReadParticleParmFloat(src, parm->to)) {
return;
}
continue;
} }
#ifdef PREY
if (!token.Icmp("with")) {
if (!ReadParticleParmFloat(src, parm->randomp)) {
return;
}
continue;
}
#endif
//
// If some other token appears, do not eat the rest of the stage.
// Put it back so the normal stage parser can report it correctly.
//
src.UnreadToken(&token);
break;
}
}
/* /*
================ ================
idDeclParticle::ParseParticleStage idDeclParticle::ParseParticleStage
@@ -267,11 +458,14 @@ idParticleStage *idDeclParticle::ParseParticleStage( idLexer &src ) {
src.ReadToken(&token); src.ReadToken(&token);
if (!token.Icmp("rect")) { if (!token.Icmp("rect")) {
stage->distributionType = PDIST_RECT; stage->distributionType = PDIST_RECT;
} else if ( !token.Icmp( "cylinder" ) ) { }
else if (!token.Icmp("cylinder")) {
stage->distributionType = PDIST_CYLINDER; stage->distributionType = PDIST_CYLINDER;
} else if ( !token.Icmp( "sphere" ) ) { }
else if (!token.Icmp("sphere")) {
stage->distributionType = PDIST_SPHERE; stage->distributionType = PDIST_SPHERE;
} else { }
else {
src.Error("bad distribution type: %s\n", token.c_str()); src.Error("bad distribution type: %s\n", token.c_str());
} }
ParseParms(src, stage->distributionParms, sizeof(stage->distributionParms) / sizeof(stage->distributionParms[0])); ParseParms(src, stage->distributionParms, sizeof(stage->distributionParms) / sizeof(stage->distributionParms[0]));
@@ -282,9 +476,11 @@ idParticleStage *idDeclParticle::ParseParticleStage( idLexer &src ) {
src.ReadToken(&token); src.ReadToken(&token);
if (!token.Icmp("cone")) { if (!token.Icmp("cone")) {
stage->directionType = PDIR_CONE; stage->directionType = PDIR_CONE;
} else if ( !token.Icmp( "outward" ) ) { }
else if (!token.Icmp("outward")) {
stage->directionType = PDIR_OUTWARD; stage->directionType = PDIR_OUTWARD;
} else { }
else {
src.Error("bad direction type: %s\n", token.c_str()); src.Error("bad direction type: %s\n", token.c_str());
} }
ParseParms(src, stage->directionParms, sizeof(stage->directionParms) / sizeof(stage->directionParms[0])); ParseParms(src, stage->directionParms, sizeof(stage->directionParms) / sizeof(stage->directionParms[0]));
@@ -295,15 +491,20 @@ idParticleStage *idDeclParticle::ParseParticleStage( idLexer &src ) {
src.ReadToken(&token); src.ReadToken(&token);
if (!token.Icmp("view")) { if (!token.Icmp("view")) {
stage->orientation = POR_VIEW; stage->orientation = POR_VIEW;
} else if ( !token.Icmp( "aimed" ) ) { }
else if (!token.Icmp("aimed")) {
stage->orientation = POR_AIMED; stage->orientation = POR_AIMED;
} else if ( !token.Icmp( "x" ) ) { }
else if (!token.Icmp("x")) {
stage->orientation = POR_X; stage->orientation = POR_X;
} else if ( !token.Icmp( "y" ) ) { }
else if (!token.Icmp("y")) {
stage->orientation = POR_Y; stage->orientation = POR_Y;
} else if ( !token.Icmp( "z" ) ) { }
else if (!token.Icmp("z")) {
stage->orientation = POR_Z; stage->orientation = POR_Z;
} else { }
else {
src.Error("bad orientation type: %s\n", token.c_str()); src.Error("bad orientation type: %s\n", token.c_str());
} }
ParseParms(src, stage->orientationParms, sizeof(stage->orientationParms) / sizeof(stage->orientationParms[0])); ParseParms(src, stage->orientationParms, sizeof(stage->orientationParms) / sizeof(stage->orientationParms[0]));
@@ -314,13 +515,17 @@ idParticleStage *idDeclParticle::ParseParticleStage( idLexer &src ) {
src.ReadToken(&token); src.ReadToken(&token);
if (!token.Icmp("standard")) { if (!token.Icmp("standard")) {
stage->customPathType = PPATH_STANDARD; stage->customPathType = PPATH_STANDARD;
} else if ( !token.Icmp( "helix" ) ) { }
else if (!token.Icmp("helix")) {
stage->customPathType = PPATH_HELIX; stage->customPathType = PPATH_HELIX;
} else if ( !token.Icmp( "flies" ) ) { }
else if (!token.Icmp("flies")) {
stage->customPathType = PPATH_FLIES; stage->customPathType = PPATH_FLIES;
} else if ( !token.Icmp( "spherical" ) ) { }
else if (!token.Icmp("spherical")) {
stage->customPathType = PPATH_ORBIT; stage->customPathType = PPATH_ORBIT;
} else { }
else {
src.Error("bad path type: %s\n", token.c_str()); src.Error("bad path type: %s\n", token.c_str());
} }
ParseParms(src, stage->customPathParms, sizeof(stage->customPathParms) / sizeof(stage->customPathParms[0])); ParseParms(src, stage->customPathParms, sizeof(stage->customPathParms) / sizeof(stage->customPathParms[0]));
@@ -399,13 +604,21 @@ idParticleStage *idDeclParticle::ParseParticleStage( idLexer &src ) {
src.ReadToken(&token); src.ReadToken(&token);
if (!token.Icmp("world")) { if (!token.Icmp("world")) {
stage->worldGravity = true; stage->worldGravity = true;
} else { }
else {
src.UnreadToken(&token); src.UnreadToken(&token);
} }
stage->gravity = src.ParseFloat(); stage->gravity = src.ParseFloat();
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("lowSkippable")) {
stage->lowSkippable = src.ParseBool();
continue;
}
#endif
src.Error("unknown token %s\n", token.c_str()); src.Error("unknown token %s\n", token.c_str());
} }
@@ -430,6 +643,11 @@ bool idDeclParticle::Parse( const char *text, const int textLength ) {
depthHack = 0.0f; depthHack = 0.0f;
#ifdef PREY
bool boundsSpecified = false;
bounds.Clear();
#endif
while (1) { while (1) {
if (!src.ReadToken(&token)) { if (!src.ReadToken(&token)) {
break; break;
@@ -455,11 +673,37 @@ bool idDeclParticle::Parse( const char *text, const int textLength ) {
continue; continue;
} }
#ifdef PREY
if (!token.Icmp("bounds")) {
bounds[0][0] = src.ParseFloat();
bounds[0][1] = src.ParseFloat();
bounds[0][2] = src.ParseFloat();
bounds[1][0] = src.ParseFloat();
bounds[1][1] = src.ParseFloat();
bounds[1][2] = src.ParseFloat();
boundsSpecified = true;
continue;
}
#endif
src.Warning("bad token %s", token.c_str()); src.Warning("bad token %s", token.c_str());
MakeDefault(); MakeDefault();
return false; return false;
} }
#ifdef PREY
//
// Prey declarations may carry explicit bounds.
// If no bounds were present, or the cvar asks for recalculation,
// recalculate them and rebuild the source text with a bounds line.
//
if (!boundsSpecified || cvarSystem->GetCVarBool("r_recalcParticleBounds")) {
CalcBounds();
RebuildTextSource();
}
#else
// //
// calculate the bounds // calculate the bounds
// //
@@ -472,10 +716,39 @@ bool idDeclParticle::Parse( const char *text, const int textLength ) {
if (bounds.GetVolume() <= 0.1f) { if (bounds.GetVolume() <= 0.1f) {
bounds = idBounds(vec3_origin).Expand(8.0f); bounds = idBounds(vec3_origin).Expand(8.0f);
} }
#endif
return true; return true;
} }
#ifdef PREY
/*
================
idDeclParticle::CalcBounds
HUMANHEAD bjk
================
*/
void idDeclParticle::CalcBounds(void) {
bounds.Clear();
for (int i = 0; i < stages.Num(); i++) {
#ifdef PARTICLE_BOUNDS
idDrawVert particleVerts[MAX_PARTICLES * 4]; // see note below
GetStageBounds(stages[i], particleVerts);
#else
GetStageBounds(stages[i]);
#endif
bounds.AddBounds(stages[i]->bounds);
}
if (bounds.GetVolume() <= 0.1f) {
bounds = idBounds(vec3_origin).Expand(8.0f);
}
}
#endif
/* /*
================ ================
idDeclParticle::FreeData idDeclParticle::FreeData
@@ -744,6 +1017,9 @@ void idParticleStage::Default() {
spawnBunching = 1.0f; spawnBunching = 1.0f;
particleLife = 1.5f; particleLife = 1.5f;
timeOffset = 0.0f; timeOffset = 0.0f;
#ifdef PREY
lowSkippable = false;
#endif
deadTime = 0.0f; deadTime = 0.0f;
distributionType = PDIST_RECT; distributionType = PDIST_RECT;
distributionParms[0] = 8.0f; distributionParms[0] = 8.0f;
+27 -2
View File
@@ -39,11 +39,20 @@ If you have questions concerning this license or the applicable additional terms
class idParticleParm { class idParticleParm {
public: public:
idParticleParm( void ) { table = NULL; from = to = 0.0f; } idParticleParm(void) {
table = NULL;
from = to = 0.0f;
#ifdef PREY
randomp = 0.0f;
#endif
}
const idDeclTable* table; const idDeclTable* table;
float from; float from;
float to; float to;
#ifdef PREY
float randomp; // HUMANHEAD bjk
#endif
float Eval(float frac, idRandom& rand) const; float Eval(float frac, idRandom& rand) const;
float Integrate(float frac, idRandom& rand) const; float Integrate(float frac, idRandom& rand) const;
@@ -91,7 +100,6 @@ typedef struct {
idVec3 origin; // dynamic smoke particles can have individual origins and axis idVec3 origin; // dynamic smoke particles can have individual origins and axis
idMat3 axis; idMat3 axis;
float age; // in seconds, calculated as fraction * stage->particleLife float age; // in seconds, calculated as fraction * stage->particleLife
idRandom originalRandom; // needed so aimed particles can reset the random for another origin calculation idRandom originalRandom; // needed so aimed particles can reset the random for another origin calculation
float animationFrameFrac; // set by ParticleTexCoords, used to make the cross faded version float animationFrameFrac; // set by ParticleTexCoords, used to make the cross faded version
@@ -185,6 +193,10 @@ public:
float boundsExpansion; // user tweak to fix poorly calculated bounds float boundsExpansion; // user tweak to fix poorly calculated bounds
idBounds bounds; // derived idBounds bounds; // derived
#ifdef PREY
bool lowSkippable; // HUMANHEAD bjk
#endif
}; };
@@ -207,7 +219,20 @@ public:
private: private:
bool RebuildTextSource(void); bool RebuildTextSource(void);
#ifdef PREY
void CalcBounds(void); // HUMANHEAD bjk
# ifdef PARTICLE_BOUNDS
void GetStageBounds(idParticleStage* stage, idDrawVert* particleVerts);
# else
void GetStageBounds(idParticleStage* stage); void GetStageBounds(idParticleStage* stage);
# endif
#else
void GetStageBounds(idParticleStage* stage);
#endif
idParticleStage* ParseParticleStage(idLexer& src); idParticleStage* ParseParticleStage(idLexer& src);
void ParseParms(idLexer& src, float* parms, int maxParms); void ParseParms(idLexer& src, float* parms, int maxParms);
void ParseParametric(idLexer& src, idParticleParm* parm); void ParseParametric(idLexer& src, idParticleParm* parm);