mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 03:42:48 +01:00
Extract AnimGroup to own header and cleanup
This commit is contained in:
parent
d8cda62668
commit
a59fb1ae56
@ -29,6 +29,8 @@ set(RWENGINE_SOURCES
|
||||
src/core/Logger.hpp
|
||||
src/core/Profiler.cpp
|
||||
src/core/Profiler.hpp
|
||||
src/data/AnimGroup.cpp
|
||||
src/data/AnimGroup.hpp
|
||||
src/data/Chase.cpp
|
||||
src/data/Chase.hpp
|
||||
src/data/CollisionModel.hpp
|
||||
|
@ -202,14 +202,14 @@ bool Activities::EnterVehicle::update(CharacterObject *character,
|
||||
auto entryPos = vehicle->getSeatEntryPositionWorld(seat);
|
||||
auto entryPosLocal = vehicle->getSeatEntryPosition(seat);
|
||||
|
||||
auto anm_open = character->animations.car_open_lhs;
|
||||
auto anm_enter = character->animations.car_getin_lhs;
|
||||
auto anm_pullout = character->animations.car_pullout_lhs;
|
||||
auto anm_open = character->animations->car_open_lhs;
|
||||
auto anm_enter = character->animations->car_getin_lhs;
|
||||
auto anm_pullout = character->animations->car_pullout_lhs;
|
||||
|
||||
if (entryPosLocal.x > 0.f) {
|
||||
anm_open = character->animations.car_open_rhs;
|
||||
anm_enter = character->animations.car_getin_rhs;
|
||||
anm_pullout = character->animations.car_pullout_rhs;
|
||||
anm_open = character->animations->car_open_rhs;
|
||||
anm_enter = character->animations->car_getin_rhs;
|
||||
anm_pullout = character->animations->car_pullout_rhs;
|
||||
}
|
||||
|
||||
// If there's someone in this seat already, we may have to ask them to
|
||||
@ -298,8 +298,8 @@ bool Activities::ExitVehicle::update(CharacterObject *character,
|
||||
RW_UNUSED(controller);
|
||||
|
||||
if (jacked) {
|
||||
auto anm_jacked_lhs = character->animations.car_jacked_lhs;
|
||||
auto anm_jacked_rhs = character->animations.car_jacked_lhs;
|
||||
auto anm_jacked_lhs = character->animations->car_jacked_lhs;
|
||||
auto anm_jacked_rhs = character->animations->car_jacked_lhs;
|
||||
auto anm_current = character->animator->getAnimation(AnimIndexAction);
|
||||
|
||||
if (anm_current == anm_jacked_lhs || anm_current == anm_jacked_rhs) {
|
||||
@ -339,10 +339,10 @@ bool Activities::ExitVehicle::update(CharacterObject *character,
|
||||
auto exitPos = vehicle->getSeatEntryPositionWorld(seat);
|
||||
auto exitPosLocal = vehicle->getSeatEntryPosition(seat);
|
||||
|
||||
auto anm_exit = character->animations.car_getout_lhs;
|
||||
auto anm_exit = character->animations->car_getout_lhs;
|
||||
|
||||
if (exitPosLocal.x > 0.f) {
|
||||
anm_exit = character->animations.car_getout_rhs;
|
||||
anm_exit = character->animations->car_getout_rhs;
|
||||
}
|
||||
|
||||
if (vehicle->getVehicle()->vehicletype_ == VehicleModelInfo::BOAT) {
|
||||
|
39
rwengine/src/data/AnimGroup.cpp
Normal file
39
rwengine/src/data/AnimGroup.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "AnimGroup.hpp"
|
||||
|
||||
AnimGroup::AnimGroup(AnimationSet &animations, const std::string &name)
|
||||
: idle(find(animations, name, "idle_stance"))
|
||||
, walk(find(animations, name, "walk_player"))
|
||||
, walk_start(find(animations, name, "walk_start"))
|
||||
, run(find(animations, name, "run_player"))
|
||||
, sprint(find(animations, name, "sprint_civi"))
|
||||
, walk_right(find(animations, name, "walk_player_right"))
|
||||
, walk_right_start(find(animations, name, "walk_start_right"))
|
||||
, walk_left(find(animations, name, "walk_player_left"))
|
||||
, walk_left_start(find(animations, name, "walk_start_left"))
|
||||
, walk_back(find(animations, name, "walk_player_back"))
|
||||
, walk_back_start(find(animations, name, "walk_start_back"))
|
||||
, jump_start(find(animations, name, "jump_launch"))
|
||||
, jump_glide(find(animations, name, "jump_glide"))
|
||||
, jump_land(find(animations, name, "jump_land"))
|
||||
, car_sit(find(animations, name, "car_sit"))
|
||||
, car_sit_low(find(animations, name, "car_lsit"))
|
||||
, car_open_lhs(find(animations, name, "car_open_lhs"))
|
||||
, car_getin_lhs(find(animations, name, "car_getin_lhs"))
|
||||
, car_getout_lhs(find(animations, name, "car_getout_lhs"))
|
||||
, car_pullout_lhs(find(animations, name, "car_pullout_lhs"))
|
||||
, car_jacked_lhs(find(animations, name, "car_jackedlhs"))
|
||||
, car_open_rhs(find(animations, name, "car_open_rhs"))
|
||||
, car_getin_rhs(find(animations, name, "car_getin_rhs"))
|
||||
, car_getout_rhs(find(animations, name, "car_getout_rhs"))
|
||||
, car_pullout_rhs(find(animations, name, "car_pullout_rhs"))
|
||||
, car_jacked_rhs(find(animations, name, "car_jackedrhs"))
|
||||
, kd_front(find(animations, name, "kd_front"))
|
||||
, ko_shot_front(find(animations, name, "ko_shot_front")) {
|
||||
}
|
||||
|
||||
Animation *AnimGroup::find(AnimationSet &animations, const std::string &group,
|
||||
const std::string &anim) {
|
||||
// @todo actually find the correct animation
|
||||
RW_UNUSED(group);
|
||||
return animations[anim];
|
||||
}
|
55
rwengine/src/data/AnimGroup.hpp
Normal file
55
rwengine/src/data/AnimGroup.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef RWENGINE_DATA_ANIMGROUP_HPP
|
||||
#define RWENGINE_DATA_ANIMGROUP_HPP
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include "rw/types.hpp"
|
||||
|
||||
struct Animation;
|
||||
|
||||
struct AnimGroup {
|
||||
/* Animations */
|
||||
Animation* idle;
|
||||
Animation* walk;
|
||||
Animation* walk_start;
|
||||
Animation* run;
|
||||
Animation* sprint;
|
||||
|
||||
Animation* walk_right;
|
||||
Animation* walk_right_start;
|
||||
Animation* walk_left;
|
||||
Animation* walk_left_start;
|
||||
|
||||
Animation* walk_back;
|
||||
Animation* walk_back_start;
|
||||
|
||||
Animation* jump_start;
|
||||
Animation* jump_glide;
|
||||
Animation* jump_land;
|
||||
|
||||
Animation* car_sit;
|
||||
Animation* car_sit_low;
|
||||
|
||||
Animation* car_open_lhs;
|
||||
Animation* car_getin_lhs;
|
||||
Animation* car_getout_lhs;
|
||||
Animation* car_pullout_lhs;
|
||||
Animation* car_jacked_lhs;
|
||||
|
||||
Animation* car_open_rhs;
|
||||
Animation* car_getin_rhs;
|
||||
Animation* car_getout_rhs;
|
||||
Animation* car_pullout_rhs;
|
||||
Animation* car_jacked_rhs;
|
||||
|
||||
Animation* kd_front;
|
||||
Animation* ko_shot_front;
|
||||
|
||||
AnimGroup(AnimationSet& animations, const std::string&);
|
||||
|
||||
static Animation* find(AnimationSet&, const std::string& group,
|
||||
const std::string& anim);
|
||||
};
|
||||
|
||||
using AnimGroups = std::unordered_map<std::string, std::unique_ptr<AnimGroup>>;
|
||||
|
||||
#endif
|
@ -58,6 +58,9 @@ void GameData::load() {
|
||||
|
||||
loadIFP("ped.ifp");
|
||||
|
||||
/// @todo load real data
|
||||
pedAnimGroups["player"] = std::make_unique<AnimGroup>(animations, "player");
|
||||
|
||||
// Clear existing zones
|
||||
gamezones = ZoneDataList{
|
||||
{"CITYZON", 0, {-4000.f, -4000.f, -500.f}, {4000.f, 4000.f, 500.f}, 0}};
|
||||
|
@ -7,6 +7,7 @@ class Logger;
|
||||
#include <data/GameTexts.hpp>
|
||||
#include <data/PedData.hpp>
|
||||
#include <data/ZoneData.hpp>
|
||||
#include <data/AnimGroup.hpp>
|
||||
#include <loaders/LoaderDFF.hpp>
|
||||
#include <loaders/LoaderIDE.hpp>
|
||||
#include <loaders/LoaderIFP.hpp>
|
||||
@ -281,6 +282,11 @@ public:
|
||||
*/
|
||||
AnimationSet animations;
|
||||
|
||||
/**
|
||||
* Pedestrian Animation Groups
|
||||
*/
|
||||
AnimGroups pedAnimGroups;
|
||||
|
||||
/**
|
||||
* DynamicObjectData
|
||||
*/
|
||||
|
@ -32,42 +32,7 @@ CharacterObject::CharacterObject(GameWorld* engine, const glm::vec3& pos,
|
||||
, physObject(nullptr)
|
||||
, physShape(nullptr)
|
||||
, controller(nullptr) {
|
||||
// TODO move AnimationGroup creation somewhere else.
|
||||
animations.idle = engine->data->animations["idle_stance"];
|
||||
animations.walk = engine->data->animations["walk_player"];
|
||||
animations.walk_start = engine->data->animations["walk_start"];
|
||||
animations.run = engine->data->animations["run_player"];
|
||||
animations.sprint = engine->data->animations["sprint_civi"];
|
||||
|
||||
animations.walk_right = engine->data->animations["walk_player_right"];
|
||||
animations.walk_right_start = engine->data->animations["walk_start_right"];
|
||||
animations.walk_left = engine->data->animations["walk_player_left"];
|
||||
animations.walk_left_start = engine->data->animations["walk_start_left"];
|
||||
|
||||
animations.walk_back = engine->data->animations["walk_player_back"];
|
||||
animations.walk_back_start = engine->data->animations["walk_start_back"];
|
||||
|
||||
animations.jump_start = engine->data->animations["jump_launch"];
|
||||
animations.jump_glide = engine->data->animations["jump_glide"];
|
||||
animations.jump_land = engine->data->animations["jump_land"];
|
||||
|
||||
animations.car_sit = engine->data->animations["car_sit"];
|
||||
animations.car_sit_low = engine->data->animations["car_lsit"];
|
||||
|
||||
animations.car_open_lhs = engine->data->animations["car_open_lhs"];
|
||||
animations.car_getin_lhs = engine->data->animations["car_getin_lhs"];
|
||||
animations.car_getout_lhs = engine->data->animations["car_getout_lhs"];
|
||||
animations.car_pullout_lhs = engine->data->animations["car_pullout_lhs"];
|
||||
animations.car_jacked_lhs = engine->data->animations["car_jackedlhs"];
|
||||
|
||||
animations.car_open_rhs = engine->data->animations["car_open_rhs"];
|
||||
animations.car_getin_rhs = engine->data->animations["car_getin_rhs"];
|
||||
animations.car_getout_rhs = engine->data->animations["car_getout_rhs"];
|
||||
animations.car_pullout_rhs = engine->data->animations["car_pullout_rhs"];
|
||||
animations.car_jacked_rhs = engine->data->animations["car_jackedrhs"];
|
||||
|
||||
animations.kd_front = engine->data->animations["kd_front"];
|
||||
animations.ko_shot_front = engine->data->animations["ko_shot_front"];
|
||||
animations = engine->data->pedAnimGroups["player"].get();
|
||||
|
||||
auto info = getModelInfo<PedModelInfo>();
|
||||
setClump(ClumpPtr(info->getModel()->clone()));
|
||||
@ -151,11 +116,11 @@ glm::vec3 CharacterObject::updateMovementAnimation(float dt) {
|
||||
|
||||
// Things are simpler if we're in a vehicle
|
||||
if (getCurrentVehicle()) {
|
||||
animator->playAnimation(0, animations.car_sit, 1.f, true);
|
||||
animator->playAnimation(0, animations->car_sit, 1.f, true);
|
||||
return glm::vec3();
|
||||
}
|
||||
|
||||
Animation* movementAnimation = animations.idle;
|
||||
Animation* movementAnimation = animations->idle;
|
||||
Animation* currentAnim = animator->getAnimation(AnimIndexMovement);
|
||||
bool isActionHappening =
|
||||
(animator->getAnimation(AnimIndexAction) != nullptr);
|
||||
@ -165,46 +130,46 @@ glm::vec3 CharacterObject::updateMovementAnimation(float dt) {
|
||||
|
||||
float movementLength = glm::length(movement);
|
||||
if (!isAlive()) {
|
||||
movementAnimation = animations.ko_shot_front;
|
||||
movementAnimation = animations->ko_shot_front;
|
||||
repeat = false;
|
||||
} else if (jumped) {
|
||||
repeat = false;
|
||||
if (currentAnim == animations.jump_start &&
|
||||
if (currentAnim == animations->jump_start &&
|
||||
animator->isCompleted(AnimIndexMovement)) {
|
||||
movementAnimation = animations.jump_start;
|
||||
movementAnimation = animations->jump_start;
|
||||
}
|
||||
if (isOnGround()) {
|
||||
if (currentAnim != animations.jump_land ||
|
||||
if (currentAnim != animations->jump_land ||
|
||||
!animator->isCompleted(AnimIndexMovement)) {
|
||||
movementAnimation = animations.jump_land;
|
||||
movementAnimation = animations->jump_land;
|
||||
} else {
|
||||
// We are done jumping
|
||||
jumped = false;
|
||||
}
|
||||
} else {
|
||||
movementAnimation = animations.jump_glide;
|
||||
movementAnimation = animations->jump_glide;
|
||||
}
|
||||
} else if (movementLength > movementEpsilon) {
|
||||
if (running && !isActionHappening) {
|
||||
if (movementLength > 1.f) {
|
||||
movementAnimation = animations.sprint;
|
||||
movementAnimation = animations->sprint;
|
||||
} else {
|
||||
movementAnimation = animations.run;
|
||||
movementAnimation = animations->run;
|
||||
}
|
||||
animationSpeed = 1.f;
|
||||
} else {
|
||||
animationSpeed = 1.f / movementLength;
|
||||
// Determine if we need to play the walk start animation
|
||||
if (currentAnim != animations.walk) {
|
||||
if (currentAnim != animations.walk_start ||
|
||||
if (currentAnim != animations->walk) {
|
||||
if (currentAnim != animations->walk_start ||
|
||||
!animator->isCompleted(AnimIndexMovement)) {
|
||||
movementAnimation = animations.walk_start;
|
||||
movementAnimation = animations->walk_start;
|
||||
} else {
|
||||
movementAnimation = animations.walk;
|
||||
movementAnimation = animations->walk;
|
||||
}
|
||||
} else {
|
||||
// Keep walkin
|
||||
movementAnimation = animations.walk;
|
||||
movementAnimation = animations->walk;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -219,7 +184,7 @@ glm::vec3 CharacterObject::updateMovementAnimation(float dt) {
|
||||
|
||||
// If we have to, interrogate the movement animation
|
||||
const auto& modelroot = getClump()->getFrame();
|
||||
if (movementAnimation != animations.idle &&
|
||||
if (movementAnimation != animations->idle &&
|
||||
!modelroot->getChildren().empty()) {
|
||||
const auto& root = modelroot->getChildren()[0];
|
||||
auto it = movementAnimation->bones.find(root->getName());
|
||||
@ -439,8 +404,8 @@ bool CharacterObject::enterVehicle(VehicleObject* vehicle, size_t seat) {
|
||||
|
||||
bool CharacterObject::isEnteringOrExitingVehicle() const {
|
||||
auto a = animator->getAnimation(AnimIndexAction);
|
||||
return a == animations.car_getout_lhs || a == animations.car_getin_lhs ||
|
||||
a == animations.car_getout_rhs || a == animations.car_getin_rhs;
|
||||
return a == animations->car_getout_lhs || a == animations->car_getin_lhs ||
|
||||
a == animations->car_getout_rhs || a == animations->car_getin_rhs;
|
||||
}
|
||||
|
||||
bool CharacterObject::isStopped() const {
|
||||
@ -487,7 +452,7 @@ void CharacterObject::jump() {
|
||||
if (physCharacter) {
|
||||
physCharacter->jump();
|
||||
jumped = true;
|
||||
animator->playAnimation(AnimIndexMovement, animations.jump_start, 1.f,
|
||||
animator->playAnimation(AnimIndexMovement, animations->jump_start, 1.f,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <data/AnimGroup.hpp>
|
||||
|
||||
constexpr int kMaxInventorySlots = 13;
|
||||
|
||||
@ -36,64 +37,6 @@ struct CharacterState {
|
||||
class VehicleObject;
|
||||
class GameWorld;
|
||||
|
||||
struct AnimationGroup {
|
||||
Animation* idle;
|
||||
Animation* walk;
|
||||
Animation* walk_start;
|
||||
Animation* run;
|
||||
Animation* sprint;
|
||||
|
||||
Animation* walk_right;
|
||||
Animation* walk_right_start;
|
||||
Animation* walk_left;
|
||||
Animation* walk_left_start;
|
||||
|
||||
Animation* walk_back;
|
||||
Animation* walk_back_start;
|
||||
|
||||
Animation* jump_start;
|
||||
Animation* jump_glide;
|
||||
Animation* jump_land;
|
||||
|
||||
Animation* car_sit;
|
||||
Animation* car_sit_low;
|
||||
|
||||
Animation* car_open_lhs;
|
||||
Animation* car_getin_lhs;
|
||||
Animation* car_getout_lhs;
|
||||
Animation* car_jacked_lhs;
|
||||
Animation* car_pullout_lhs;
|
||||
|
||||
Animation* car_open_rhs;
|
||||
Animation* car_getin_rhs;
|
||||
Animation* car_getout_rhs;
|
||||
Animation* car_jacked_rhs;
|
||||
Animation* car_pullout_rhs;
|
||||
|
||||
Animation* kd_front;
|
||||
Animation* ko_shot_front;
|
||||
|
||||
AnimationGroup()
|
||||
: idle(nullptr)
|
||||
, walk(nullptr)
|
||||
, walk_start(nullptr)
|
||||
, run(nullptr)
|
||||
, jump_start(nullptr)
|
||||
, jump_glide(nullptr)
|
||||
, jump_land(nullptr)
|
||||
, car_sit(nullptr)
|
||||
, car_sit_low(nullptr)
|
||||
, car_open_lhs(nullptr)
|
||||
, car_getin_lhs(nullptr)
|
||||
, car_getout_lhs(nullptr)
|
||||
, car_open_rhs(nullptr)
|
||||
, car_getin_rhs(nullptr)
|
||||
, car_getout_rhs(nullptr)
|
||||
, kd_front(nullptr)
|
||||
, ko_shot_front(nullptr) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The CharacterObject struct
|
||||
* Implements Character object behaviours.
|
||||
@ -128,7 +71,7 @@ public:
|
||||
|
||||
CharacterController* controller;
|
||||
|
||||
AnimationGroup animations;
|
||||
AnimGroup* animations;
|
||||
|
||||
/**
|
||||
* @param pos
|
||||
|
@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_death) {
|
||||
character->tick(0.16f);
|
||||
|
||||
BOOST_CHECK_EQUAL(character->animator->getAnimation(0),
|
||||
character->animations.ko_shot_front);
|
||||
character->animations->ko_shot_front);
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
|
Loading…
Reference in New Issue
Block a user