mirror of
https://github.com/rwengine/openrw.git
synced 2024-07-19 02:54:44 +02:00
Convert AnimationBone and Animatior to unique ptr
This commit is contained in:
parent
4b1e4d3aa6
commit
a813837040
@ -676,7 +676,7 @@ bool Activities::UseItem::update(CharacterObject *character,
|
||||
auto world = character->engine;
|
||||
const auto &weapon = world->data->weaponData.at(itemslot);
|
||||
auto &state = character->getCurrentState().weapons[itemslot];
|
||||
auto animator = character->animator;
|
||||
auto &animator = character->animator;
|
||||
auto shootcycle = find_cycle(weapon->animation1);
|
||||
auto throwcycle = find_cycle(weapon->animation2);
|
||||
|
||||
|
@ -38,7 +38,7 @@ void Animator::tick(float dt) {
|
||||
if (!frame) {
|
||||
continue;
|
||||
}
|
||||
state.boneInstances.insert({bone.second, frame});
|
||||
state.boneInstances.emplace(bone.second.get(), frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ bool LoaderIFP::loadFromMemory(char* data) {
|
||||
CPAN* cpan = read<CPAN>(data, dataI);
|
||||
ANIM* frames = read<ANIM>(data, dataI);
|
||||
|
||||
auto bonedata = new AnimationBone;
|
||||
auto bonedata = std::make_unique<AnimationBone>();
|
||||
bonedata->name = frames->name;
|
||||
bonedata->frames.reserve(frames->frames);
|
||||
|
||||
@ -131,14 +131,14 @@ bool LoaderIFP::loadFromMemory(char* data) {
|
||||
std::transform(framename.begin(), framename.end(),
|
||||
framename.begin(), ::tolower);
|
||||
|
||||
animation->bones.insert({framename, bonedata});
|
||||
animation->bones.emplace(framename, std::move(bonedata));
|
||||
}
|
||||
|
||||
data_offs = animstart + animroot->base.size;
|
||||
|
||||
std::transform(animname.begin(), animname.end(), animname.begin(),
|
||||
::tolower);
|
||||
animations.insert({animname, animation});
|
||||
animations.emplace(animname, animation);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -41,6 +41,21 @@ struct AnimationBone {
|
||||
Data type;
|
||||
std::vector<AnimationKeyframe> frames;
|
||||
|
||||
AnimationBone() = default;
|
||||
|
||||
AnimationBone(const std::string& p_name, int32_t p_previous, int32_t p_next,
|
||||
float p_duration, Data p_type,
|
||||
const std::vector<AnimationKeyframe>& p_frames)
|
||||
: name(p_name)
|
||||
, previous(p_previous)
|
||||
, next(p_next)
|
||||
, duration(p_duration)
|
||||
, type(p_type)
|
||||
, frames(p_frames) {
|
||||
}
|
||||
|
||||
~AnimationBone() = default;
|
||||
|
||||
AnimationKeyframe getInterpolatedKeyframe(float time);
|
||||
AnimationKeyframe getKeyframe(float time);
|
||||
};
|
||||
@ -52,13 +67,9 @@ struct AnimationBone {
|
||||
*/
|
||||
struct Animation {
|
||||
std::string name;
|
||||
std::map<std::string, AnimationBone*> bones;
|
||||
std::map<std::string, std::unique_ptr<AnimationBone>> bones;
|
||||
|
||||
~Animation() {
|
||||
for (auto &bone_pair : bones) {
|
||||
delete bone_pair.second;
|
||||
}
|
||||
}
|
||||
~Animation() = default;
|
||||
|
||||
float duration;
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ CharacterObject::CharacterObject(GameWorld* engine, const glm::vec3& pos,
|
||||
setClump(info->getModel()->clone());
|
||||
if (info->getModel()) {
|
||||
setModel(info->getModel());
|
||||
animator = new Animator(getClump());
|
||||
animator = std::make_unique<Animator>(getClump());
|
||||
|
||||
createActor();
|
||||
}
|
||||
@ -240,7 +240,7 @@ glm::vec3 CharacterObject::updateMovementAnimation(float dt) {
|
||||
const auto& root = modelroot->getChildren()[0];
|
||||
auto it = movementAnimation->bones.find(root->getName());
|
||||
if (it != movementAnimation->bones.end()) {
|
||||
auto rootBone = it->second;
|
||||
auto& rootBone = it->second;
|
||||
float step = dt;
|
||||
RW_CHECK(
|
||||
animator->getAnimation(AnimIndexMovement),
|
||||
@ -321,13 +321,9 @@ void CharacterObject::changeCharacterModel(const std::string& name) {
|
||||
engine->data->loadTXD(modelName + ".txd");
|
||||
auto newmodel = engine->data->loadClump(modelName + ".dff");
|
||||
|
||||
if (animator) {
|
||||
delete animator;
|
||||
}
|
||||
|
||||
setModel(newmodel);
|
||||
|
||||
animator = new Animator(getClump());
|
||||
animator = std::make_unique<Animator>(getClump());
|
||||
}
|
||||
|
||||
void CharacterObject::updateCharacter(float dt) {
|
||||
|
@ -16,7 +16,7 @@ CutsceneObject::CutsceneObject(GameWorld *engine, const glm::vec3 &pos,
|
||||
setModel(getModelInfo<ClumpModelInfo>()->getModel());
|
||||
}
|
||||
setClump(getModel()->clone());
|
||||
animator = new Animator(getClump());
|
||||
animator = std::make_unique<Animator>(getClump());
|
||||
}
|
||||
|
||||
void CutsceneObject::tick(float dt) {
|
||||
|
@ -5,10 +5,6 @@
|
||||
#include "engine/Animator.hpp"
|
||||
|
||||
GameObject::~GameObject() {
|
||||
if (animator) {
|
||||
delete animator;
|
||||
}
|
||||
|
||||
if (modelinfo_) {
|
||||
modelinfo_->removeReference();
|
||||
}
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <rw/forward.hpp>
|
||||
|
||||
#include <data/ModelData.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <objects/ObjectTypes.hpp>
|
||||
|
||||
class Animator;
|
||||
class GameWorld;
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
GameWorld* engine = nullptr;
|
||||
|
||||
Animator* animator = nullptr; /// Object's animator.
|
||||
std::unique_ptr<Animator> animator; /// Object's animator.
|
||||
|
||||
bool inWater = false;
|
||||
|
||||
|
@ -19,17 +19,15 @@ BOOST_AUTO_TEST_CASE(test_matrix) {
|
||||
Animator animator(test_model);
|
||||
|
||||
animation->duration = 1.f;
|
||||
animation->bones["player"] = new AnimationBone{
|
||||
"player",
|
||||
0,
|
||||
0,
|
||||
1.0f,
|
||||
AnimationBone::RT0,
|
||||
{
|
||||
{glm::quat{1.0f,0.0f,0.0f,0.0f}, glm::vec3(0.f, 0.f, 0.f), glm::vec3(), 0.f, 0},
|
||||
{glm::quat{1.0f,0.0f,0.0f,0.0f}, glm::vec3(0.f, 1.f, 0.f), glm::vec3(), 1.0f, 1},
|
||||
}
|
||||
};
|
||||
animation->bones.emplace(
|
||||
"player", std::make_unique<AnimationBone>(
|
||||
"player", 0, 0, 1.0f, AnimationBone::RT0,
|
||||
std::vector<AnimationKeyframe>{
|
||||
{glm::quat{1.0f, 0.0f, 0.0f, 0.0f},
|
||||
glm::vec3(0.f, 0.f, 0.f), glm::vec3(), 0.f, 0},
|
||||
{glm::quat{1.0f, 0.0f, 0.0f, 0.0f},
|
||||
glm::vec3(0.f, 1.f, 0.f), glm::vec3(), 1.0f, 1},
|
||||
}));
|
||||
|
||||
animator.playAnimation(0, animation, 1.f, false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user