From 7d8141782963d1e677e00aa6137b3c2ed9c3688e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Tue, 1 Nov 2022 18:09:33 -0300 Subject: [PATCH] Particle Rolling --- src/playsim/p_actionfunctions.cpp | 6 +++++- src/playsim/p_effect.cpp | 14 +++++++++++++- src/playsim/p_effect.h | 6 +++++- src/rendering/hwrenderer/scene/hw_sprites.cpp | 12 ++++++++++-- wadsrc/static/zscript/actors/actor.zs | 2 +- wadsrc/static/zscript/constants.zs | 1 + 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index c1a891a0d..f24c7c1d0 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -1619,6 +1619,7 @@ enum SPFflag SPF_RELACCEL = 1 << 3, SPF_RELANG = 1 << 4, SPF_NOTIMEFREEZE = 1 << 5, + SPF_ROLL = 1 << 6, }; DEFINE_ACTION_FUNCTION(AActor, A_SpawnParticle) @@ -1698,6 +1699,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_SpawnParticleEx) PARAM_FLOAT (startalpha) PARAM_FLOAT (fadestep) PARAM_FLOAT (sizestep) + PARAM_FLOAT (startroll) + PARAM_FLOAT (rollvel) + PARAM_FLOAT (rollacc) startalpha = clamp(startalpha, 0., 1.); if (fadestep > 0) fadestep = clamp(fadestep, 0., 1.); @@ -1737,7 +1741,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_SpawnParticleEx) style = STYLE_None; } - P_SpawnParticle(self->Level, self->Vec3Offset(pos), vel, acc, color, startalpha, lifetime, size, fadestep, sizestep, flags, texid, ERenderStyle(style)); + P_SpawnParticle(self->Level, self->Vec3Offset(pos), vel, acc, color, startalpha, lifetime, size, fadestep, sizestep, flags, texid, ERenderStyle(style), startroll, rollvel, rollacc); } return 0; } diff --git a/src/playsim/p_effect.cpp b/src/playsim/p_effect.cpp index ee8abf7aa..64564e9ac 100644 --- a/src/playsim/p_effect.cpp +++ b/src/playsim/p_effect.cpp @@ -248,6 +248,13 @@ void P_ThinkParticles (FLevelLocals *Level) particle->Pos.Y = newxy.Y; particle->Pos.Z += particle->Vel.Z; particle->Vel += particle->Acc; + + if(particle->doRoll) + { + particle->Roll += particle->RollVel; + particle->RollVel += particle->RollAcc; + } + particle->subsector = Level->PointInRenderSubsector(particle->Pos); sector_t *s = particle->subsector->sector; // Handle crossing a sector portal. @@ -275,10 +282,11 @@ enum PSFlag { PS_FULLBRIGHT = 1, PS_NOTIMEFREEZE = 1 << 5, + PS_ROLL = 1 << 6, }; void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &vel, const DVector3 &accel, PalEntry color, double startalpha, int lifetime, double size, - double fadestep, double sizestep, int flags, FTextureID texture, ERenderStyle style) + double fadestep, double sizestep, int flags, FTextureID texture, ERenderStyle style, double startroll, double rollvel, double rollacc) { particle_t *particle = NewParticle(Level); @@ -298,6 +306,10 @@ void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &v particle->notimefreeze = !!(flags & PS_NOTIMEFREEZE); particle->texture = texture; particle->style = style; + particle->Roll = startroll; + particle->RollVel = rollvel; + particle->RollAcc = rollacc; + particle->doRoll = !!(flags & PS_ROLL); } } diff --git a/src/playsim/p_effect.h b/src/playsim/p_effect.h index 92176541a..233d2f095 100644 --- a/src/playsim/p_effect.h +++ b/src/playsim/p_effect.h @@ -68,6 +68,10 @@ struct particle_t uint16_t snext; FTextureID texture; ERenderStyle style; + double Roll; + double RollVel; + double RollAcc; + bool doRoll; }; const uint16_t NO_PARTICLE = 0xffff; @@ -83,7 +87,7 @@ particle_t *JitterParticle (FLevelLocals *Level, int ttl); particle_t *JitterParticle (FLevelLocals *Level, int ttl, double drift); void P_ThinkParticles (FLevelLocals *Level); -void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &vel, const DVector3 &accel, PalEntry color, double startalpha, int lifetime, double size, double fadestep, double sizestep, int flags = 0, FTextureID texture = FNullTextureID(), ERenderStyle style = STYLE_None); +void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &vel, const DVector3 &accel, PalEntry color, double startalpha, int lifetime, double size, double fadestep, double sizestep, int flags = 0, FTextureID texture = FNullTextureID(), ERenderStyle style = STYLE_None, double startroll = 0, double rollvel = 0, double rollacc = 0); void P_InitEffects (void); void P_RunEffect (AActor *actor, int effects); diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 480b31c84..906e93229 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -390,6 +390,8 @@ bool HWSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp) // [Nash] has +ROLLSPRITE const bool drawRollSpriteActor = (actor != nullptr && actor->renderflags & RF_ROLLSPRITE); + const bool drawRollParticle = (particle != nullptr && particle->doRoll); + // [fgsfds] check sprite type mask uint32_t spritetype = (uint32_t)-1; @@ -430,7 +432,7 @@ bool HWSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp) // [fgsfds] calculate yaw vectors float yawvecX = 0, yawvecY = 0, rollDegrees = 0; float angleRad = (FAngle::fromDeg(270.) - HWAngles.Yaw).Radians(); - if (actor) rollDegrees = Angles.Roll.Degrees(); + if (actor || drawRollParticle) rollDegrees = Angles.Roll.Degrees(); if (isFlatSprite) { yawvecX = Angles.Yaw.Cos(); @@ -448,7 +450,7 @@ bool HWSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp) if (useOffsets) mat.Translate(-xx, -zz, -yy); } } - else if (drawRollSpriteActor) + else if (drawRollSpriteActor || drawRollParticle) { if (useOffsets) mat.Translate(xx, zz, yy); if (drawWithXYBillboard) @@ -1340,6 +1342,12 @@ void HWSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * x = float(particle->Pos.X) + xvf; y = float(particle->Pos.Y) + yvf; z = float(particle->Pos.Z) + zvf; + + if(particle->doRoll) + { + float rvf = (particle->RollVel) * timefrac; + Angles.Roll = TAngle::fromDeg(particle->Roll + rvf); + } float factor; if (particle_style == 1) factor = 1.3f / 7.f; diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 903cc880d..0552d1bb9 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1128,7 +1128,7 @@ class Actor : Thinker native native void A_FadeTo(double target, double amount = 0.1, int flags = 0); native void A_SpawnDebris(class spawntype, bool transfer_translation = false, double mult_h = 1, double mult_v = 1); native void A_SpawnParticle(color color1, int flags = 0, int lifetime = TICRATE, double size = 1, double angle = 0, double xoff = 0, double yoff = 0, double zoff = 0, double velx = 0, double vely = 0, double velz = 0, double accelx = 0, double accely = 0, double accelz = 0, double startalphaf = 1, double fadestepf = -1, double sizestep = 0); - native void A_SpawnParticleEx(color color1, TextureID texture, int style = STYLE_None, int flags = 0, int lifetime = TICRATE, double size = 1, double angle = 0, double xoff = 0, double yoff = 0, double zoff = 0, double velx = 0, double vely = 0, double velz = 0, double accelx = 0, double accely = 0, double accelz = 0, double startalphaf = 1, double fadestepf = -1, double sizestep = 0); + native void A_SpawnParticleEx(color color1, TextureID texture, int style = STYLE_None, int flags = 0, int lifetime = TICRATE, double size = 1, double angle = 0, double xoff = 0, double yoff = 0, double zoff = 0, double velx = 0, double vely = 0, double velz = 0, double accelx = 0, double accely = 0, double accelz = 0, double startalphaf = 1, double fadestepf = -1, double sizestep = 0, double startroll = 0, double rollvel = 0, double rollacc = 0); native void A_ExtChase(bool usemelee, bool usemissile, bool playactive = true, bool nightmarefast = false); native void A_DropInventory(class itemtype, int amount = -1); native void A_SetBlend(color color1, double alpha, int tics, color color2 = 0, double alpha2 = 0.); diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index 9a32392f9..fcb1b6220 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -689,6 +689,7 @@ enum EParticleFlags SPF_RELACCEL = 1 << 3, SPF_RELANG = 1 << 4, SPF_NOTIMEFREEZE = 1 << 5, + SPF_ROLL = 1 << 6, SPF_RELATIVE = SPF_RELPOS|SPF_RELVEL|SPF_RELACCEL|SPF_RELANG };