Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added model particles, spin
  • Loading branch information
skyjake committed Aug 24, 2003
1 parent 2ad7e19 commit 31e5e49
Showing 1 changed file with 56 additions and 9 deletions.
65 changes: 56 additions & 9 deletions doomsday/Src/p_particle.c
Expand Up @@ -145,9 +145,8 @@ void P_InitParticleGen(ptcgen_t *gen, ded_ptcgen_t *def)
gen->stages[i].resistance = FRACUNIT * (1 - def->stages[i].resistance);
gen->stages[i].radius = FRACUNIT * def->stages[i].radius;
gen->stages[i].gravity = FRACUNIT * def->stages[i].gravity;
// FIXME: What!? Why are you evaluating now?
gen->stages[i].type = Def_EvalFlags(def->stages[i].type);
gen->stages[i].flags = Def_EvalFlags(def->stages[i].flags);
gen->stages[i].type = def->stages[i].type;
gen->stages[i].flags = def->stages[i].flags;
}

// Init some data.
Expand All @@ -160,8 +159,11 @@ void P_InitParticleGen(ptcgen_t *gen, ded_ptcgen_t *def)
// Mark everything unused.
memset(gen->ptcs, -1, sizeof(particle_t) * gen->count);

// Clear the contact pointers.
for(i = 0; i < gen->count; i++) gen->ptcs[i].contact = NULL;
for(i = 0; i < gen->count; i++)
{
// Clear the contact pointers.
gen->ptcs[i].contact = NULL;
}
}

//===========================================================================
Expand Down Expand Up @@ -276,6 +278,17 @@ void P_Uncertain(fixed_t *pos, fixed_t low, fixed_t high)
}
}

//===========================================================================
// P_SetParticleAngles
//===========================================================================
void P_SetParticleAngles(particle_t *pt, int flags)
{
if(flags & PTCF_ZERO_YAW) pt->yaw = 0;
if(flags & PTCF_ZERO_PITCH) pt->pitch = 0;
if(flags & PTCF_RANDOM_YAW) pt->yaw = M_FRandom() * 65536;
if(flags & PTCF_RANDOM_PITCH) pt->pitch = M_FRandom() * 65536;
}

//===========================================================================
// P_NewParticle
// Spawns a new particle.
Expand Down Expand Up @@ -451,6 +464,9 @@ void P_NewParticle(ptcgen_t *gen)
FRACUNIT * def->spawn_radius);
}

// Initial angles for the particle.
P_SetParticleAngles(pt, def->stages[pt->stage].flags);

// The other place where this gets updated is after moving over
// a two-sided line.
pt->sector = gen->sector? gen->sector
Expand Down Expand Up @@ -633,6 +649,30 @@ fixed_t P_GetParticleZ(particle_t *pt)
return pt->pos[VZ];
}

//===========================================================================
// P_SpinParticle
//===========================================================================
void P_SpinParticle(ptcgen_t *gen, particle_t *pt)
{
ded_ptcstage_t *stDef = gen->def->stages + pt->stage;
uint index = pt - gen->ptcs + (int)gen/8;
static int yawSigns[4] = { 1, 1, -1, -1 };
static int pitchSigns[4] = { 1, -1, 1, -1 };
int yawSign, pitchSign;

yawSign = yawSigns[index % 4];
pitchSign = pitchSigns[index % 4];

if(stDef->spin[0] != 0)
{
pt->yaw += 65536 * yawSign * stDef->spin[0] / (360 * TICSPERSEC);
}
if(stDef->spin[1] != 0)
{
pt->pitch += 65536 * pitchSign * stDef->spin[1] / (360 * TICSPERSEC);
}
}

//===========================================================================
// P_MoveParticle
// The movement is done in two steps:
Expand All @@ -644,10 +684,14 @@ void P_MoveParticle(ptcgen_t *gen, particle_t *pt)
{
int x, y, z, xl, xh, yl, yh, bx, by;
ptcstage_t *st = gen->stages + pt->stage;
boolean zbounce = false;

boolean zBounce = false;
boolean hitFloor;
fixed_t hardRadius = st->radius/2;

// Particle rotates according to spin speed.
P_SpinParticle(gen, pt);

// Changes to momentum.
pt->mov[VZ] -= FixedMul(mapgravity, st->gravity);

Expand Down Expand Up @@ -731,7 +775,7 @@ void P_MoveParticle(ptcgen_t *gen, particle_t *pt)
}
if(!P_TouchParticle(pt, st, false)) return;
z = pt->sector->ceilingheight - hardRadius;
zbounce = true;
zBounce = true;
hitFloor = false;
}
// Also check the floor.
Expand All @@ -744,10 +788,10 @@ void P_MoveParticle(ptcgen_t *gen, particle_t *pt)
}
if(!P_TouchParticle(pt, st, false)) return;
z = pt->sector->floorheight + hardRadius;
zbounce = true;
zBounce = true;
hitFloor = true;
}
if(zbounce)
if(zBounce)
{
pt->mov[VZ] = FixedMul(-pt->mov[VZ], st->bounce);
if(!pt->mov[VZ])
Expand Down Expand Up @@ -947,6 +991,9 @@ void P_PtcGenThinker(ptcgen_t *gen)
}
pt->tics = def->stages[pt->stage].tics
* (1 - def->stages[pt->stage].variance * M_FRandom());

// Change in particle angles?
P_SetParticleAngles(pt, def->stages[pt->stage].flags);
}
// Try to move.
P_MoveParticle(gen, pt);
Expand Down

0 comments on commit 31e5e49

Please sign in to comment.