1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-21 18:02:43 +01:00

Use static instance of AnimationBone

This commit is contained in:
Filip Gawin 2018-11-23 21:38:00 +01:00
parent fe3d085de2
commit 835c0147fe
5 changed files with 20 additions and 20 deletions

View File

@ -28,12 +28,12 @@ void Animator::tick(float dt) {
if (state.animation == nullptr) continue;
if (state.boneInstances.empty()) {
for (const auto& [name, bonePtr] : state.animation->bones) {
for (auto& [name, bone] : state.animation->bones) {
auto frame = model->findFrame(name);
if (!frame) {
continue;
}
state.boneInstances.emplace(bonePtr.get(), frame);
state.boneInstances.emplace(&bone, frame);
}
}

View File

@ -81,9 +81,9 @@ bool LoaderIFP::loadFromMemory(char* data) {
CPAN* cpan = read<CPAN>(data, dataI);
ANIM* frames = read<ANIM>(data, dataI);
auto bonedata = std::make_unique<AnimationBone>();
bonedata->name = frames->name;
bonedata->frames.reserve(frames->frames);
AnimationBone boneData{};
boneData.name = frames->name;
boneData.frames.reserve(frames->frames);
data_offs += ((8 + frames->base.size) - sizeof(ANIM));
@ -93,37 +93,37 @@ bool LoaderIFP::loadFromMemory(char* data) {
float time = 0.f;
if (type == "KR00") {
bonedata->type = AnimationBone::R00;
boneData.type = AnimationBone::R00;
for (int d = 0; d < frames->frames; ++d) {
glm::quat q = glm::conjugate(*read<glm::quat>(data, dataI));
time = *read<float>(data, dataI);
bonedata->frames.emplace_back(q, glm::vec3(0.f, 0.f, 0.f),
boneData.frames.emplace_back(q, glm::vec3(0.f, 0.f, 0.f),
glm::vec3(1.f, 1.f, 1.f), time,
d);
}
} else if (type == "KRT0") {
bonedata->type = AnimationBone::RT0;
boneData.type = AnimationBone::RT0;
for (int d = 0; d < frames->frames; ++d) {
glm::quat q = glm::conjugate(*read<glm::quat>(data, dataI));
glm::vec3 p = *read<glm::vec3>(data, dataI);
time = *read<float>(data, dataI);
bonedata->frames.emplace_back(
boneData.frames.emplace_back(
q, p, glm::vec3(1.f, 1.f, 1.f), time, d);
}
} else if (type == "KRTS") {
bonedata->type = AnimationBone::RTS;
boneData.type = AnimationBone::RTS;
for (int d = 0; d < frames->frames; ++d) {
glm::quat q = glm::conjugate(*read<glm::quat>(data, dataI));
glm::vec3 p = *read<glm::vec3>(data, dataI);
glm::vec3 s = *read<glm::vec3>(data, dataI);
time = *read<float>(data, dataI);
bonedata->frames.emplace_back(q, p, s, time, d);
boneData.frames.emplace_back(q, p, s, time, d);
}
}
bonedata->duration = time;
boneData.duration = time;
animation->duration =
std::max(bonedata->duration, animation->duration);
std::max(boneData.duration, animation->duration);
data_offs = start + sizeof(CPAN) + cpan->base.size;
@ -131,7 +131,7 @@ bool LoaderIFP::loadFromMemory(char* data) {
std::transform(framename.begin(), framename.end(),
framename.begin(), ::tolower);
animation->bones.emplace(framename, std::move(bonedata));
animation->bones.emplace(framename, std::move(boneData));
}
data_offs = animstart + animroot->base.size;

View File

@ -67,7 +67,7 @@ struct AnimationBone {
*/
struct Animation {
std::string name;
std::map<std::string, std::unique_ptr<AnimationBone>> bones;
std::map<std::string, AnimationBone> bones;
~Animation() = default;

View File

@ -254,18 +254,18 @@ glm::vec3 CharacterObject::updateMovementAnimation(float dt) {
// keyframes
if ((animTime + step) > duration) {
glm::vec3 a =
rootBone->getInterpolatedKeyframe(animTime).position;
rootBone.getInterpolatedKeyframe(animTime).position;
glm::vec3 b =
rootBone->getInterpolatedKeyframe(duration).position;
rootBone.getInterpolatedKeyframe(duration).position;
glm::vec3 d = (b - a);
animTranslate.y += d.y;
step -= (duration - animTime);
animTime = 0.f;
}
glm::vec3 a = rootBone->getInterpolatedKeyframe(animTime).position;
glm::vec3 a = rootBone.getInterpolatedKeyframe(animTime).position;
glm::vec3 b =
rootBone->getInterpolatedKeyframe(animTime + step).position;
rootBone.getInterpolatedKeyframe(animTime + step).position;
glm::vec3 d = (b - a);
animTranslate.y += d.y;

View File

@ -20,7 +20,7 @@ BOOST_AUTO_TEST_CASE(test_matrix) {
animation->duration = 1.f;
animation->bones.emplace(
"player", std::make_unique<AnimationBone>(
"player", AnimationBone(
"player", 0, 0, 1.0f, AnimationBone::RT0,
std::vector<AnimationKeyframe>{
{glm::quat{1.0f, 0.0f, 0.0f, 0.0f},