Enhance animation and control tests; improve rendering and shape loading validation
- Added tests for player animations in animation_archive_tests to ensure all animations are loaded correctly. - Updated entity_dispatch_entry_tests to validate animation direction updates and added tests for sixteen-direction animations. - Expanded isometric_controls_tests with comprehensive key event handling and action requests for various controller states. - Improved map_renderer_tests by adding viewport rendering tests to compare unbounded and bounded views. - Enhanced shape_archive_tests to validate shape frame loading and decoding consistency.
This commit is contained in:
parent
e00f9f3186
commit
a76b071049
28 changed files with 1608 additions and 154 deletions
|
|
@ -145,6 +145,8 @@ public:
|
|||
EntityVmContextProcessEntry* createUsecodeProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
bool startAnimPrimitiveProcess(u16 processId, LiveFixedMapItems& items,
|
||||
const AnimationClip& clip, u8 frameSkip = 0);
|
||||
std::optional<u8> updateAnimPrimitiveDirection(u16 processId, LiveFixedMapItems& items,
|
||||
u8 direction);
|
||||
std::optional<bool> advanceGroundedAnimPrimitive(u16 processId, LiveFixedMapItems& items,
|
||||
const AnimationClip& clip, const std::vector<ShapeTypeInfo>& shapes,
|
||||
const FastAreaRange& fastArea);
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ struct NpcAnimationState {
|
|||
u16 lastAnimation = 0xffff;
|
||||
u8 frame = 0;
|
||||
u8 moreFlags = 0;
|
||||
u8 direction = 0;
|
||||
};
|
||||
|
||||
class LiveFixedMapItems {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,15 @@
|
|||
#include "remorse/compat.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace remorse {
|
||||
|
||||
inline constexpr std::array<u8, 25> controllerAnimationIndices{
|
||||
0, 1, 2, 3, 4, 0x0b, 0x10, 0x17, 0x18, 0x1c, 0x1d, 0x20, 0x22,
|
||||
0x24, 0x26, 0x28, 0x29, 0x2e, 0x30, 0x37, 0x38, 0x3a, 0x3b, 0x3d, 0x3e};
|
||||
|
||||
struct WorldPositionD {
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
|
|
@ -20,6 +25,48 @@ inline bool controllerWalkRequested(u16 modifiers)
|
|||
return shiftDown == capsLockOn;
|
||||
}
|
||||
|
||||
inline bool controllerAllowsInPlaceDirectionUpdate(u8 animation)
|
||||
{
|
||||
switch (animation) {
|
||||
case 1: case 3: case 4: case 7: case 8: case 10: case 12: case 13: case 15:
|
||||
case 25: case 34: case 35: case 36: case 37: case 38: case 39: case 42: case 43:
|
||||
case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 54:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool controllerLastAnimationIsRunning(u8 animation)
|
||||
{
|
||||
switch (animation) {
|
||||
case 1: case 3: case 34: case 35: case 38: case 48: case 49: case 56:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool controllerLastAnimationIsRunningJumping(u8 animation)
|
||||
{
|
||||
switch (animation) {
|
||||
case 3: case 48: case 49: case 56:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool controllerLastAnimationIsNotCombat(u8 animation)
|
||||
{
|
||||
switch (animation) {
|
||||
case 0: case 1: case 11: case 16: case 32: case 55: case 58: case 59:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::optional<u8> controllerDirectionFromScan(u8 scanCode)
|
||||
{
|
||||
// Controller_PickNextAnimByKeyevent (1130:12d6), directional keys with Num Lock off.
|
||||
|
|
@ -39,41 +86,324 @@ inline std::optional<u8> controllerDirectionFromScan(u8 scanCode)
|
|||
struct ControllerMovementRequest {
|
||||
u8 animation = 0;
|
||||
u8 direction = 14;
|
||||
bool oneShot = false;
|
||||
bool updateDirectionInPlace = false;
|
||||
};
|
||||
|
||||
enum class ControllerCommand : u8 {
|
||||
FireWeapon,
|
||||
SelectNextItem,
|
||||
CycleWeaponForward,
|
||||
OpenInventory
|
||||
};
|
||||
|
||||
struct ControllerCommandRequest {
|
||||
ControllerCommand command = ControllerCommand::FireWeapon;
|
||||
};
|
||||
|
||||
struct ControllerActorState {
|
||||
u16 npcNumber = 1;
|
||||
u16 mapNumber = 1;
|
||||
u8 direction = 14;
|
||||
u8 lastAnimation = 0;
|
||||
bool controllerEnabled = true;
|
||||
bool dead = false;
|
||||
bool avatarInStasis = false;
|
||||
bool kneeling = false;
|
||||
bool activeWeapon = false;
|
||||
bool busy = false;
|
||||
bool lastAnimationNotCombat = true;
|
||||
bool avatarSomethingCombatty = false;
|
||||
};
|
||||
|
||||
class ControllerMovementState {
|
||||
public:
|
||||
void setActorState(const ControllerActorState& state)
|
||||
{
|
||||
if (state.direction != actor_.direction) {
|
||||
lastDirection_ = state.direction;
|
||||
}
|
||||
actor_ = state;
|
||||
setFacingDirection(state.direction);
|
||||
crouched_ = state.kneeling;
|
||||
}
|
||||
|
||||
void handleDirectionalKey(u8 scanCode, u16 modifiers, bool pressed)
|
||||
{
|
||||
modifiers_ = modifiers;
|
||||
const auto direction = controllerDirectionFromScan(scanCode);
|
||||
if (!direction) {
|
||||
handleKeyEvent(scanCode, modifiers, 1, pressed ? 1 : 0, pressed ? 1 : 0);
|
||||
}
|
||||
|
||||
void handleKeyEvent(u8 scanCode, u16 modifiers, u8 eventMode, u8 keyState,
|
||||
u16 keyAction = 1, u16 eventFlags = 0)
|
||||
{
|
||||
if (!actor_.controllerEnabled || actor_.npcNumber == 0 || actor_.dead ||
|
||||
(actor_.npcNumber == 1 && actor_.avatarInStasis)) {
|
||||
return;
|
||||
}
|
||||
modifiers_ = modifiers;
|
||||
if (eventMode == 0) {
|
||||
return;
|
||||
}
|
||||
if (keyState != 0 && keyAction == 1 && actor_.npcNumber == 1 &&
|
||||
(scanCode == 0x0f || scanCode == 0x24)) {
|
||||
if (!actor_.busy || (actor_.lastAnimation != 56 &&
|
||||
controllerLastAnimationIsRunningJumping(actor_.lastAnimation))) {
|
||||
pendingAction_ = ControllerMovementRequest{56, actor_.direction, true};
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keyState != 0 && keyAction == 1 && actor_.npcNumber == 1) {
|
||||
if ((scanCode == 0x39 || scanCode == 0x52) && actor_.mapNumber != 0x40 &&
|
||||
!actor_.busy && (scanCode != 0x52 || eventFlags == 0)) {
|
||||
pendingCommand_ = ControllerCommandRequest{ControllerCommand::FireWeapon};
|
||||
return;
|
||||
}
|
||||
if (scanCode == 0x4a) {
|
||||
pendingCommand_ = ControllerCommandRequest{ControllerCommand::SelectNextItem};
|
||||
return;
|
||||
}
|
||||
if (scanCode == 0x37 && eventFlags == 0) {
|
||||
pendingCommand_ = ControllerCommandRequest{ControllerCommand::CycleWeaponForward};
|
||||
return;
|
||||
}
|
||||
if (scanCode == 0x4e || (scanCode == 0x53 && eventFlags == 0)) {
|
||||
pendingCommand_ = ControllerCommandRequest{ControllerCommand::OpenInventory};
|
||||
return;
|
||||
}
|
||||
}
|
||||
const auto held = std::find(heldScans_.begin(), heldScans_.end(), scanCode);
|
||||
if (held != heldScans_.end()) {
|
||||
heldScans_.erase(held);
|
||||
}
|
||||
if (pressed && (modifiers & 0x20) == 0) {
|
||||
constexpr u16 actionModifierMask = 0x0f00;
|
||||
if ((modifiers & actionModifierMask) != 0) {
|
||||
if (keyState != 0) {
|
||||
queueModifiedAction(scanCode, modifiers, keyAction);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const bool numLockOn = (modifiers & 0x20) != 0;
|
||||
if (keyState != 0 && !numLockOn && actor_.mapNumber != 0x40 && !actor_.busy &&
|
||||
actor_.avatarSomethingCombatty && (scanCode == 0x4b || scanCode == 0x4d)) {
|
||||
const int turn = scanCode == 0x4b ? -1 : 1;
|
||||
lastDirection_ = static_cast<u8>((actor_.direction + turn + 16) & 0x0f);
|
||||
pendingAction_ = ControllerMovementRequest{
|
||||
static_cast<u8>(actor_.kneeling ? 0x2e : 4), lastDirection_, true};
|
||||
return;
|
||||
}
|
||||
if (numLockOn && (scanCode == 0x4b || scanCode == 0x4d)) {
|
||||
if (keyState != 0) {
|
||||
if (actor_.busy) {
|
||||
if (controllerAllowsInPlaceDirectionUpdate(actor_.lastAnimation)) {
|
||||
pendingInPlaceDirection_ = static_cast<u8>(scanCode == 0x4b ? 0x12 : 0x11);
|
||||
}
|
||||
} else {
|
||||
const int turn = scanCode == 0x4b ? -turnStep_ : turnStep_;
|
||||
lastDirection_ = static_cast<u8>((facingDirection_ + turn + 16) & 0x0f);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (numLockOn && scanCode != 0x48 && scanCode != 0x50) {
|
||||
return;
|
||||
}
|
||||
const auto direction = controllerDirectionFromScan(scanCode);
|
||||
if (!direction) {
|
||||
if (keyState != 0) {
|
||||
queueModifiedAction(scanCode, modifiers, keyAction);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keyState != 0) {
|
||||
heldScans_.push_back(scanCode);
|
||||
}
|
||||
if (keyState != 0) {
|
||||
queueModifiedAction(scanCode, modifiers, keyAction);
|
||||
}
|
||||
}
|
||||
|
||||
ControllerMovementRequest request() const
|
||||
{
|
||||
if (!actor_.controllerEnabled || actor_.npcNumber == 0 || actor_.dead ||
|
||||
(actor_.npcNumber == 1 && actor_.avatarInStasis)) {
|
||||
return {0, actor_.direction};
|
||||
}
|
||||
if (pendingInPlaceDirection_) {
|
||||
return {actor_.lastAnimation, *pendingInPlaceDirection_, false, true};
|
||||
}
|
||||
if (heldScans_.empty()) {
|
||||
return {0, lastDirection_};
|
||||
}
|
||||
lastDirection_ = *controllerDirectionFromScan(heldScans_.back());
|
||||
return {static_cast<u8>(controllerWalkRequested(modifiers_) ? 1 : 3), lastDirection_};
|
||||
const u8 runAnimation = actor_.activeWeapon ? 0x30 : 3;
|
||||
const u8 scanCode = heldScans_.back();
|
||||
const bool numLockOn = (modifiers_ & 0x20) != 0;
|
||||
const u8 requestedDirection = numLockOn && (scanCode == 0x48 || scanCode == 0x50)
|
||||
? facingDirection_ : *controllerDirectionFromScan(scanCode);
|
||||
lastDirection_ = requestedDirection;
|
||||
const bool walkRequested = controllerWalkRequested(modifiers_);
|
||||
if (actor_.mapNumber == 0x40) {
|
||||
if (controllerLastAnimationIsRunning(actor_.lastAnimation)) {
|
||||
return {static_cast<u8>(walkRequested ? 1 : runAnimation), requestedDirection};
|
||||
}
|
||||
if (requestedDirection == actor_.direction) {
|
||||
return {static_cast<u8>(walkRequested ? 1 : 0x26), requestedDirection};
|
||||
}
|
||||
return {0, requestedDirection};
|
||||
}
|
||||
if (!walkRequested && requestedDirection == actor_.direction &&
|
||||
!controllerLastAnimationIsRunning(actor_.lastAnimation)) {
|
||||
return {0x22, requestedDirection};
|
||||
}
|
||||
if ((modifiers_ & 0x20) != 0) {
|
||||
if (scanCode == 0x48) {
|
||||
return {static_cast<u8>(walkRequested ? 1 : runAnimation), requestedDirection};
|
||||
}
|
||||
if (scanCode == 0x50) {
|
||||
return {2, requestedDirection};
|
||||
}
|
||||
}
|
||||
return {static_cast<u8>(walkRequested ? 1 : runAnimation), requestedDirection};
|
||||
}
|
||||
|
||||
void clear() { heldScans_.clear(); }
|
||||
std::optional<u8> takeInPlaceDirectionUpdate()
|
||||
{
|
||||
auto direction = pendingInPlaceDirection_;
|
||||
pendingInPlaceDirection_.reset();
|
||||
return direction;
|
||||
}
|
||||
|
||||
void setFacingDirection(u8 direction)
|
||||
{
|
||||
if (direction <= 15) {
|
||||
facingDirection_ = direction;
|
||||
}
|
||||
}
|
||||
|
||||
void setTurnStep(u8 step)
|
||||
{
|
||||
turnStep_ = step == 1 ? 1 : 2;
|
||||
}
|
||||
|
||||
std::optional<ControllerMovementRequest> takeActionRequest()
|
||||
{
|
||||
auto action = pendingAction_;
|
||||
pendingAction_.reset();
|
||||
return action;
|
||||
}
|
||||
|
||||
std::optional<ControllerCommandRequest> takeCommandRequest()
|
||||
{
|
||||
auto command = pendingCommand_;
|
||||
pendingCommand_.reset();
|
||||
return command;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
heldScans_.clear();
|
||||
pendingAction_.reset();
|
||||
pendingCommand_.reset();
|
||||
pendingInPlaceDirection_.reset();
|
||||
modifiers_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
void queueModifiedAction(u8 scanCode, u16 modifiers, u16 keyAction)
|
||||
{
|
||||
constexpr u16 altMask = 0x0a00;
|
||||
constexpr u16 ctrlMask = 0x0500;
|
||||
constexpr u8 animationNone = 0x40;
|
||||
u8 animation = animationNone;
|
||||
u8 actionDirection = lastDirection_;
|
||||
if (scanCode == 0x4c) {
|
||||
if (keyAction == 1) {
|
||||
animation = crouched_ ? 0x29 : 0x28;
|
||||
}
|
||||
} else if ((modifiers & (altMask | ctrlMask)) == 0 && scanCode == 0x35) {
|
||||
if (actor_.mapNumber != 0x40 && !controllerLastAnimationIsRunning(actor_.lastAnimation)) {
|
||||
animation = 0x24;
|
||||
}
|
||||
} else if ((modifiers & altMask) != 0) {
|
||||
const bool numLockOn = (modifiers & 0x20) != 0;
|
||||
const auto scanDirection = controllerDirectionFromScan(scanCode);
|
||||
if (numLockOn && scanDirection) {
|
||||
int newDirection = *scanDirection;
|
||||
if (scanCode == 0x4b) {
|
||||
newDirection = 0x12;
|
||||
} else if (scanCode == 0x4d) {
|
||||
newDirection = 0x11;
|
||||
}
|
||||
const int direction = actor_.direction;
|
||||
const int directionDelta = newDirection < direction
|
||||
? direction - newDirection : direction + 0x10 - newDirection;
|
||||
if (0x10 - directionDelta < directionDelta) {
|
||||
animation = 0x1d;
|
||||
actionDirection = static_cast<u8>((newDirection - 4) & 0x0f);
|
||||
} else {
|
||||
animation = 0x1c;
|
||||
actionDirection = static_cast<u8>((newDirection + 4) & 0x0f);
|
||||
}
|
||||
} else {
|
||||
switch (scanCode) {
|
||||
case 0x48: animation = 0x24; break;
|
||||
case 0x4b: animation = 0x1c; break;
|
||||
case 0x4d: animation = 0x1d; break;
|
||||
case 0x50: animation = 2; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
} else if ((modifiers & ctrlMask) != 0) {
|
||||
const auto requestedDirection = controllerDirectionFromScan(scanCode);
|
||||
if ((modifiers & 0x20) == 0 && requestedDirection &&
|
||||
(scanCode == 0x47 || scanCode == 0x49 || scanCode == 0x4f || scanCode == 0x51)) {
|
||||
const int direction = actor_.direction;
|
||||
const int directionDelta = *requestedDirection < direction
|
||||
? direction - *requestedDirection : direction + 0x10 - *requestedDirection;
|
||||
if (0x10 - directionDelta < directionDelta) {
|
||||
animation = 0x18;
|
||||
actionDirection = static_cast<u8>((*requestedDirection - 4) & 0x0f);
|
||||
} else {
|
||||
animation = 0x17;
|
||||
actionDirection = static_cast<u8>((*requestedDirection + 4) & 0x0f);
|
||||
}
|
||||
} else switch (scanCode) {
|
||||
case 0x48:
|
||||
if (crouched_) {
|
||||
animation = 0x29;
|
||||
} else if (!actor_.lastAnimationNotCombat) {
|
||||
animation = 0x0b;
|
||||
} else if (actor_.npcNumber == 1) {
|
||||
animation = 0x3a;
|
||||
}
|
||||
break;
|
||||
case 0x4b: animation = crouched_ ? 0x17 : 0x3d; break;
|
||||
case 0x4d: animation = crouched_ ? 0x18 : 0x3e; break;
|
||||
case 0x50:
|
||||
if (keyAction == 1) {
|
||||
animation = crouched_ ? 0x29 : 0x28;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (animation != animationNone) {
|
||||
pendingAction_ = ControllerMovementRequest{animation, actionDirection, true};
|
||||
if (animation == 0x28 || animation == 0x29) {
|
||||
crouched_ = !crouched_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<u8> heldScans_;
|
||||
std::optional<ControllerMovementRequest> pendingAction_;
|
||||
std::optional<ControllerCommandRequest> pendingCommand_;
|
||||
std::optional<u8> pendingInPlaceDirection_;
|
||||
u16 modifiers_ = 0;
|
||||
mutable u8 lastDirection_ = 14;
|
||||
u8 facingDirection_ = 14;
|
||||
u8 turnStep_ = 2;
|
||||
bool crouched_ = false;
|
||||
ControllerActorState actor_{};
|
||||
};
|
||||
|
||||
inline std::optional<AnimationDisplacement> hostMovementStep(
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ struct ShapeArchive {
|
|||
|
||||
std::optional<ShapeArchive> loadShapeArchive(const std::filesystem::path& path);
|
||||
std::optional<std::vector<ShapeFrame>> loadShapeFrames(const ShapeArchive& archive, u32 shapeIndex);
|
||||
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeFrame& frame);
|
||||
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeArchive& archive, u32 shapeIndex, u32 frameIndex);
|
||||
|
||||
} // namespace remorse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue