Speed up weapon draw
This commit is contained in:
1 parent
53328484b8
commit
4e40a1825a
3 files changed
+88
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "LocationGameState.h"
|
||||
#include "game_server/InternalGameServer.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -338,6 +339,82 @@ int main()
|
||||
return fail("Enabled player acquired an autonomous attack target");
|
||||
}
|
||||
|
||||
FRG::CharacterState drawAnimation;
|
||||
drawAnimation.configureAsPlayer();
|
||||
drawAnimation.enabled = true;
|
||||
drawAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::STAND_TO_ACTION, 0, 100);
|
||||
drawAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::ACTION_IDLE, 0, 100);
|
||||
FRG::CharacterObservation attackTarget{
|
||||
point(0.f, 0.f, 1.f), 100.f};
|
||||
drawAnimation.update(100, {{"player1", &attackTarget}, nullptr});
|
||||
if (drawAnimation.currentState != FRG::AnimationState::STAND_TO_ACTION ||
|
||||
std::abs(drawAnimation.animationFrame - 8.333333f) > 0.001f ||
|
||||
drawAnimation.showWeapon) {
|
||||
return fail("Weapon draw animation did not advance at 2x speed");
|
||||
}
|
||||
drawAnimation.update(200, {{"player1", &attackTarget}, nullptr});
|
||||
if (!drawAnimation.showWeapon) {
|
||||
return fail("Weapon draw animation did not use its frame visibility threshold");
|
||||
}
|
||||
|
||||
FRG::CharacterState sheathAnimation;
|
||||
sheathAnimation.configureAsPlayer();
|
||||
sheathAnimation.enabled = true;
|
||||
sheathAnimation.currentState = FRG::AnimationState::ACTION_IDLE;
|
||||
sheathAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::ACTION_TO_STAND, 0, 100);
|
||||
sheathAnimation.update(100, {{"player1", nullptr}, nullptr});
|
||||
if (sheathAnimation.currentState != FRG::AnimationState::ACTION_TO_STAND ||
|
||||
std::abs(sheathAnimation.animationFrame - 8.333333f) > 0.001f ||
|
||||
!sheathAnimation.showWeapon) {
|
||||
return fail("Weapon sheath animation did not advance at 2x speed");
|
||||
}
|
||||
sheathAnimation.update(300, {{"player1", nullptr}, nullptr});
|
||||
if (sheathAnimation.showWeapon) {
|
||||
return fail("Weapon sheath animation did not hide at its frame visibility threshold");
|
||||
}
|
||||
|
||||
FRG::CharacterState ordinaryAnimation;
|
||||
ordinaryAnimation.configureAsPlayer();
|
||||
ordinaryAnimation.enabled = true;
|
||||
ordinaryAnimation.currentState = FRG::AnimationState::STAND;
|
||||
ordinaryAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::STAND, 0, 100);
|
||||
ordinaryAnimation.update(100, {{"player1", nullptr}, nullptr});
|
||||
if (std::abs(ordinaryAnimation.animationFrame - 4.1666665f) > 0.001f) {
|
||||
return fail("Ordinary animation playback rate changed unexpectedly");
|
||||
}
|
||||
|
||||
FRG::CharacterState completedDrawAnimation;
|
||||
completedDrawAnimation.configureAsPlayer();
|
||||
completedDrawAnimation.enabled = true;
|
||||
completedDrawAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::STAND_TO_ACTION, 0, 30);
|
||||
completedDrawAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::ACTION_IDLE, 0, 30);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
completedDrawAnimation.update(
|
||||
100, {{"player1", &attackTarget}, nullptr});
|
||||
if (completedDrawAnimation.currentState !=
|
||||
FRG::AnimationState::ACTION_IDLE) {
|
||||
return fail("Accelerated weapon draw animation did not complete");
|
||||
}
|
||||
|
||||
FRG::CharacterState completedSheathAnimation;
|
||||
completedSheathAnimation.configureAsPlayer();
|
||||
completedSheathAnimation.enabled = true;
|
||||
completedSheathAnimation.currentState = FRG::AnimationState::ACTION_IDLE;
|
||||
completedSheathAnimation.setAnimationMetadata(
|
||||
FRG::AnimationState::ACTION_TO_STAND, 0, 30);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
completedSheathAnimation.update(
|
||||
100, {{"player1", nullptr}, nullptr});
|
||||
if (completedSheathAnimation.currentState != FRG::AnimationState::STAND) {
|
||||
return fail("Accelerated weapon sheath animation did not complete");
|
||||
}
|
||||
|
||||
FRG::CharacterState guardedMover;
|
||||
nlohmann::json guardedJson;
|
||||
guardedMover.velocity = {
|
||||
|
||||
@@ -40,6 +40,9 @@ void CharacterState::configureAsPlayer() {
|
||||
Eigen::AngleAxisf(-PI * 0.5f, Eigen::Vector3f::UnitX()));
|
||||
canAttack = true;
|
||||
isPlayer = true;
|
||||
animationPlaybackRates.fill(1.0f);
|
||||
animationPlaybackRates[static_cast<std::size_t>(AnimationState::STAND_TO_ACTION)] = 2.0f;
|
||||
animationPlaybackRates[static_cast<std::size_t>(AnimationState::ACTION_TO_STAND)] = 2.0f;
|
||||
}
|
||||
|
||||
void CharacterState::configureNavigationRetryCooldowns(
|
||||
@@ -452,7 +455,11 @@ CharacterUpdateEvents CharacterState::update(
|
||||
? static_cast<float>(animationStartFrames[index]) : 0.f;
|
||||
}
|
||||
const int previousFrame = static_cast<int>(animationFrame);
|
||||
animationFrame += static_cast<float>(deltaMs) / 24.f;
|
||||
const auto animationIndex = static_cast<std::size_t>(currentState);
|
||||
const float playbackRate =
|
||||
animationIndex < animationPlaybackRates.size()
|
||||
? animationPlaybackRates[animationIndex] : 1.0f;
|
||||
animationFrame += static_cast<float>(deltaMs) / 24.f * playbackRate;
|
||||
|
||||
if (previousFrame < 19 && static_cast<int>(animationFrame) >= 19 &&
|
||||
(currentState == AnimationState::ACTION_ATTACK ||
|
||||
@@ -482,7 +489,6 @@ CharacterUpdateEvents CharacterState::update(
|
||||
currentState == AnimationState::ACTION_ATTACK ||
|
||||
currentState == AnimationState::ACTION_IDLE;
|
||||
|
||||
const auto animationIndex = static_cast<std::size_t>(currentState);
|
||||
const int frameCount = animationIndex < animationFrameCounts.size()
|
||||
? animationFrameCounts[animationIndex] : 1;
|
||||
if (frameCount > 1 && static_cast<int>(animationFrame) >= frameCount - 1) {
|
||||
|
||||
@@ -107,6 +107,9 @@ public:
|
||||
float animationFrame = 0.0f;
|
||||
std::array<int, 9> animationStartFrames = {{0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||||
std::array<int, 9> animationFrameCounts = {{1, 1, 1, 1, 1, 1, 1, 1, 1}};
|
||||
std::array<float, 9> animationPlaybackRates = {{
|
||||
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f, 1.0f}};
|
||||
|
||||
// --- Movement / visual parameters ---
|
||||
fp walkSpeed = static_cast<fp>(3.0f);
|
||||
|
||||
Reference in new issue
Block a user