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