Added portable turret anim blends + fixed anim blends

This commit is contained in:
smallmodel 2023-11-16 23:03:04 +01:00
parent 5105dcce04
commit ce0e9fe77e
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "player.h"
#include "g_phys.h"
#include "portableturret.h"
extern Event EV_Player_AnimLoop_Torso;
extern Event EV_Player_AnimLoop_Legs;
@ -32,7 +33,7 @@ extern Event EV_Player_AnimLoop_Legs;
void Player::EndAnim_Legs(Event *ev)
{
animdone_Legs = true;
if (IsRepeatType(m_iPartSlot[legs])) {
SetAnimDoneEvent(EV_Player_AnimLoop_Legs, m_iPartSlot[legs]);
}
@ -51,7 +52,7 @@ void Player::EndAnim_Torso(Event *ev)
EvaluateState();
}
void Player::EndAnim_Pain(Event* ev)
void Player::EndAnim_Pain(Event *ev)
{
animdone_Pain = true;
}
@ -166,15 +167,173 @@ int Player::CurrentPartAnim(bodypart_t part) const
void Player::AdjustAnimBlends(void)
{
int iPartSlot;
int iOldPartSlot;
float fWeightTotal;
int iPartSlot;
int iOldPartSlot;
float fWeightTotal;
qboolean playTurretAnim = false;
if (movetype == MOVETYPE_PORTABLE_TURRET) {
PortableTurret *turret = static_cast<PortableTurret *>(m_pTurret.Pointer());
if (turret->IsReloading()) {
if (partAnim[legs] != "mg42tripod_reload") {
SetPartAnim("mg42tripod_reload", legs);
StopAnimating(m_iPartSlot[torso]);
StopAnimating(m_iPartSlot[torso] ^ 1);
partAnim[torso] = "";
}
} else if (turret->IsSettingUp()) {
if (partAnim[legs] != "mg42tripod_setup") {
SetPartAnim("mg42tripod_setup", legs);
StopAnimating(m_iPartSlot[torso]);
StopAnimating(m_iPartSlot[torso] ^ 1);
partAnim[torso] = "";
}
} else if (turret->IsPackingUp()) {
if (partAnim[legs] != "mg42tripod_packup") {
SetPartAnim("mg42tripod_packup", legs);
StopAnimating(m_iPartSlot[torso]);
StopAnimating(m_iPartSlot[torso] ^ 1);
partAnim[torso] = "";
}
} else {
playTurretAnim = true;
}
}
if (playTurretAnim) {
PortableTurret *turret = static_cast<PortableTurret *>(m_pTurret.Pointer());
if (partAnim[legs] != "mg42tripod_aim") {
StopPartAnimating(legs);
}
if (partAnim[torso] != "mg42tripod_aim") {
StopPartAnimating(torso);
}
partAnim[legs] = "mg42tripod_aim";
partAnim[torso] = "mg42tripod_aim";
float pitch, yaw;
float legsPitchAngle, torsoPitchAngle;
float pitchAlpha, yawAlpha;
float legsYawAngle, torsoYawAngle;
float weight;
int animNum;
str vertLegsStr, vertTorsoStr;
str horzLegsStr, horzTorsoStr;
str anim;
pitch = AngleSubtract(turret->GetGroundPitch(), turret->angles[0]);
yaw = AngleSubtract(turret->GetStartYaw(), turret->angles[1]);
if (pitch >= 0) {
legsPitchAngle = 0.0;
torsoPitchAngle = 15.0;
vertLegsStr = "_straight";
vertTorsoStr = "_up15";
} else {
legsPitchAngle = -15.0;
torsoPitchAngle = 0.0;
vertLegsStr = "_down15";
vertTorsoStr = "_straight";
}
pitchAlpha = (pitch - legsPitchAngle) / (torsoPitchAngle - legsPitchAngle);
pitchAlpha = Q_clamp_float(pitchAlpha, 0, 1);
if (yaw < -20) {
legsYawAngle = -40.0;
torsoYawAngle = -20.0;
horzLegsStr = "_left40";
horzTorsoStr = "_left20";
} else if (yaw < 0) {
legsYawAngle = -20.0;
torsoYawAngle = 0.0;
horzLegsStr = "_left20";
horzTorsoStr = "_straight";
} else if (yaw <= 20) {
legsYawAngle = 0.0;
torsoYawAngle = 20.0;
horzLegsStr = "_straight";
horzTorsoStr = "_right20";
} else {
legsYawAngle = 20.0;
torsoYawAngle = 40.0;
horzLegsStr = "_right20";
horzTorsoStr = "_right40";
}
yawAlpha = (yaw - legsYawAngle) / (torsoYawAngle - legsYawAngle);
yawAlpha = Q_clamp_float(yawAlpha, 0, 1);
anim = "mg42tripod_aim" + horzLegsStr + vertLegsStr;
weight = (1 - pitchAlpha) * (1 - yawAlpha);
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
if (animNum == -1) {
gi.DPrintf("^~^~^ Warning: Can't find player animation '%s'.\n", anim.c_str());
anim = "mg42tripod_aim_straight_straight";
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
}
if (animNum == CurrentAnim(0)) {
SetWeight(0, weight);
} else {
NewAnim(animNum, 0, weight);
}
anim = "mg42tripod_aim" + horzLegsStr + vertTorsoStr;
weight = (1.0 - yawAlpha) * pitchAlpha;
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
if (animNum == -1) {
gi.DPrintf("^~^~^ Warning: Can't find player animation '%s'.\n", anim.c_str());
anim = "mg42tripod_aim_straight_straight";
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
}
if (animNum == CurrentAnim(1)) {
SetWeight(1, weight);
} else {
NewAnim(animNum, 1, weight);
}
anim = "mg42tripod_aim" + horzTorsoStr + vertTorsoStr;
weight = pitchAlpha * yawAlpha;
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
if (animNum == -1) {
gi.DPrintf("^~^~^ Warning: Can't find player animation '%s'.\n", anim.c_str());
anim = "mg42tripod_aim_straight_straight";
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
}
if (animNum == CurrentAnim(2)) {
SetWeight(2, weight);
} else {
NewAnim(animNum, 2, weight);
}
anim = "mg42tripod_aim" + horzTorsoStr + vertTorsoStr;
weight = (1.0 - pitchAlpha) * yawAlpha;
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
if (animNum == -1) {
gi.DPrintf("^~^~^ Warning: Can't find player animation '%s'.\n", anim.c_str());
anim = "mg42tripod_aim_straight_straight";
animNum = gi.Anim_NumForName(edict->tiki, anim.c_str());
}
if (animNum == CurrentAnim(3)) {
SetWeight(3, weight);
} else {
NewAnim(animNum, 3, weight);
}
}
if (deadflag == DEAD_DEAD) {
if (m_fPainBlend) {
StopAnimating(ANIMSLOT_PAIN);
edict->s.frameInfo[ANIMSLOT_PAIN].weight = 0;
m_fPainBlend = 0;
SetWeight(ANIMSLOT_PAIN, 0);
m_fPainBlend = 0;
animdone_Pain = false;
}
return;
@ -184,44 +343,56 @@ void Player::AdjustAnimBlends(void)
iOldPartSlot = m_iPartSlot[legs] ^ 1;
if (m_fPartBlends[legs] <= 0.0f) {
if (partOldAnim[legs] == "") {
goto __blend_torso;
}
if (partOldAnim[legs] != "") {
StopAnimating(iOldPartSlot);
StopAnimating(iOldPartSlot);
if (partAnim[legs] == "") {
SetWeight(iPartSlot, 0.0);
} else {
SetWeight(iPartSlot, 1.0);
}
} else {
if (partAnim[legs] == "") {
SetWeight(iPartSlot, 0.0);
} else {
SetWeight(iPartSlot, 1.0);
}
}
} else {
m_fPartBlends[legs] = m_fPartBlends[legs] - level.frametime * partBlendMult[legs];
m_fPartBlends[legs] -= level.frametime * partBlendMult[legs];
if (m_fPartBlends[legs] >= 0.01f) {
if (partOldAnim[legs] != "") {
edict->s.frameInfo[iOldPartSlot].weight = m_fPartBlends[legs];
SetWeight(iOldPartSlot, m_fPartBlends[legs]);
}
if (partAnim[legs] != "") {
edict->s.frameInfo[iPartSlot].weight = 1.0f - m_fPartBlends[legs];
SetWeight(iPartSlot, 1.0f - m_fPartBlends[legs]);
}
} else {
m_fPartBlends[legs] = 0.0f;
StopAnimating(iOldPartSlot);
partOldAnim[legs] = "";
goto __blend_torso;
if (partAnim[legs] == "") {
SetWeight(iPartSlot, 0.0);
} else {
SetWeight(iPartSlot, 1.0);
}
}
m_fPartBlends[legs] = 0.0f;
StopAnimating(iOldPartSlot);
partOldAnim[legs] = "";
}
if (partAnim[legs] != "") {
edict->s.frameInfo[iPartSlot].weight = 1.0f;
} else {
edict->s.frameInfo[iPartSlot].weight = 0.0f;
}
__blend_torso:
iPartSlot = m_iPartSlot[torso];
iOldPartSlot = m_iPartSlot[torso] ^ 1;
if (m_fPartBlends[torso] <= 0.0f) {
if (partOldAnim[torso] != "") {
StopAnimating(iOldPartSlot);
partOldAnim[torso] = "";
if (partAnim[torso] == "") {
SetWeight(iPartSlot, 0.0);
} else {
SetWeight(iPartSlot, 1.0);
}
}
} else {
m_fPartBlends[torso] = m_fPartBlends[torso] - level.frametime * partBlendMult[torso];
@ -229,11 +400,11 @@ __blend_torso:
fWeightTotal = 0.0f;
if (partOldAnim[torso] != "") {
edict->s.frameInfo[iOldPartSlot].weight = m_fPartBlends[torso];
SetWeight(iOldPartSlot, m_fPartBlends[torso]);
fWeightTotal += m_fPartBlends[torso];
}
if (partAnim[torso] != "") {
edict->s.frameInfo[iPartSlot].weight = 1.0f - m_fPartBlends[torso];
SetWeight(iPartSlot, m_fPartBlends[torso]);
fWeightTotal += 1.0f - m_fPartBlends[torso];
}
@ -241,9 +412,15 @@ __blend_torso:
} else {
m_fPartBlends[torso] = 0.0f;
StopAnimating(iOldPartSlot);
partOldAnim[torso] = "";
edict->s.frameInfo[iPartSlot].weight = partAnim[torso] != "" ? 1.0f : 0.0f;
edict->s.actionWeight = partAnim[torso] != "" ? 1.0f : 0.0f;
partOldAnim[torso] = "";
if (partAnim[torso] == "") {
SetWeight(iPartSlot, 0.0);
edict->s.actionWeight = 0.0;
} else {
SetWeight(iPartSlot, 1.0);
edict->s.actionWeight = 1.0;
}
}
}
@ -251,24 +428,24 @@ __blend_torso:
if (m_sPainAnim == "") {
StopAnimating(ANIMSLOT_PAIN);
edict->s.frameInfo[ANIMSLOT_PAIN].weight = 0;
m_fPainBlend = 0;
animdone_Pain = false;
m_fPainBlend = 0;
animdone_Pain = false;
} else if (animdone_Pain) {
m_fPainBlend -= level.frametime * (10.0 / 3.0);
if (m_fPainBlend < 0.01f) {
StopAnimating(ANIMSLOT_PAIN);
edict->s.frameInfo[ANIMSLOT_PAIN].weight = 0;
m_fPainBlend = 0;
animdone_Pain = false;
m_fPainBlend = 0;
animdone_Pain = false;
}
}
if (m_fPainBlend) {
int i;
int i;
float w;
edict->s.frameInfo[ANIMSLOT_PAIN].weight = m_fPainBlend;
w = 1.0 - m_fPainBlend * 0.5;
w = 1.0 - m_fPainBlend * 0.5;
for (i = 0; i < ANIMSLOT_PAIN; i++) {
if (edict->s.frameInfo[i].weight) {
@ -336,7 +513,7 @@ void Player::PlayerAnimDelta(float *vDelta)
}
}
void Player::EventTestAnim(Event* ev)
void Player::EventTestAnim(Event *ev)
{
// FIXME: unimplemented
}