OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
animation.h
Go to the documentation of this file.
1#pragma once
2
3#include <zenkit/ModelScript.hh>
4#include <zenkit/ModelAnimation.hh>
5
6#include <Tempest/Vec>
7#include <memory>
8
9class Npc;
10class MdlVisual;
11class Interactive;
12class World;
13
14class Animation final {
15 public:
16 enum AnimClass : uint8_t {
19 Loop
20 };
21
22 struct EvTimed final {
23 zenkit::MdsEventType def = zenkit::MdsEventType::UNKNOWN;
24 std::string_view item;
25 std::string_view slot[2] = {};
26 uint64_t time = 0;
27 };
28
29 struct EvMorph final {
30 std::string_view node;
31 std::string_view anim;
32 };
33
34 struct EvCount final {
35 uint8_t def_opt_frame = 0;
36 uint8_t groundSounds = 0;
37 zenkit::MdsFightMode weaponCh = zenkit::MdsFightMode::INVALID;
38 std::vector<EvTimed> timed;
39 std::vector<EvMorph> morph;
40 };
41
42 struct MdsParticleEffect : zenkit::MdsParticleEffect {
43 bool pfxStop = false;
44 };
45
46 struct AnimData final {
47 Tempest::Vec3 translate={};
48 Tempest::Vec3 moveTr={};
49
50 std::vector<zenkit::AnimationSample> samples;
51 std::vector<uint32_t> nodeIndex;
52 std::vector<Tempest::Vec3> tr;
53 bool hasMoveTr=false;
54
55 uint32_t firstFrame=0;
56 uint32_t lastFrame =0;
57 float fpsRate =60.f;
58 uint32_t numFrames =0;
59
60 std::vector<zenkit::MdsSoundEffectGround> gfx;
61 std::vector<zenkit::MdsSoundEffect> sfx;
62 std::vector<MdsParticleEffect> pfx;
63 std::vector<zenkit::MdsModelTag> tag;
64 std::vector<zenkit::MdsEventTag> events;
65
66 std::vector<zenkit::MdsMorphAnimation> mmStartAni;
67
68 std::vector<uint64_t> defHitEnd; // hit-end time
69 std::vector<uint64_t> defParFrame;
70 std::vector<uint64_t> defWindow;
71
72 void setupMoveTr();
73 void setupEvents(float fpsRate);
74 };
75
76 struct Sequence final {
77 Sequence()=default;
78 Sequence(const zenkit::MdsAnimation& hdr, std::string_view name);
79
80 bool isRotate() const { return bool(flags & zenkit::AnimationFlags::ROTATE); }
81 bool isMove() const { return bool(flags & zenkit::AnimationFlags::MOVE); }
82 bool isFly() const { return bool(flags & zenkit::AnimationFlags::FLY); }
83 bool isIdle() const { return bool(flags & zenkit::AnimationFlags::IDLE); }
84 bool isFinished(uint64_t now, uint64_t sTime, uint16_t comboLen) const;
85 float atkTotalTime(uint16_t comboLen) const;
86 bool canInterrupt(uint64_t now, uint64_t sTime, uint16_t comboLen) const;
87 bool isInComboWindow(uint64_t t, uint16_t comboLen) const;
88 bool isDefParWindow(uint64_t t) const;
89 bool isDefWindow(uint64_t t) const;
90 float totalTime() const;
91
92 bool isAttackAnim() const;
93 bool isPrehit(uint64_t sTime, uint64_t now) const;
94 void processEvents(uint64_t barrier, uint64_t sTime, uint64_t now, EvCount& ev) const;
95 void processSfx (uint64_t barrier, uint64_t sTime, uint64_t now, Npc* npc, Interactive* mob) const;
96 void processPfx (uint64_t barrier, uint64_t sTime, uint64_t now, MdlVisual& visual, World& world) const;
97 void processPfx (const MdsParticleEffect& p, MdlVisual& visual, World& world) const;
98
99 Tempest::Vec3 speed(uint64_t at, uint64_t dt) const;
100 Tempest::Vec3 translateXZ(uint64_t at) const;
101 void schemeName(char buf[64]) const;
102
103 std::string name, askName;
104 const char* shortName = nullptr;
105 uint32_t layer = 0;
106 zenkit::AnimationFlags flags = zenkit::AnimationFlags::NONE;
107 uint64_t blendIn = 0;
108 uint64_t blendOut = 0;
110 bool reverse = false;
111
112 std::string next;
113 const Sequence* nextPtr = nullptr;
114 const Animation* owner = nullptr;
115
116 std::vector<const Sequence*> comb;
117 std::shared_ptr<AnimData> data;
118
119 private:
120 void setupMoveTr();
121 static void processEvent(const zenkit::MdsEventTag& e, EvCount& ev, uint64_t time);
122 bool extractFrames(uint64_t &frameA, uint64_t &frameB, bool &invert, uint64_t barrier, uint64_t sTime, uint64_t now) const;
123 };
124
125
126 Animation(zenkit::ModelScript &p, std::string_view name, bool ignoreErrChunks);
127
128 const Sequence* sequence(std::string_view name) const;
129 const Sequence* sequenceAsc(std::string_view name) const;
130 void debug() const;
131 std::string_view defaultMesh() const;
132
133 private:
134 Sequence& loadMAN(const zenkit::MdsAnimation& hdr, std::string_view name);
135 void setupIndex();
136
137 mutable const Sequence* sqHot = nullptr;
138 std::vector<Sequence> sequences;
139 std::vector<zenkit::MdsAnimationAlias> ref;
140 std::vector<std::string> mesh;
141 zenkit::MdsSkeleton meshDef;
142 };
const Sequence * sequenceAsc(std::string_view name) const
@ UnknownAnim
Definition animation.h:17
void debug() const
const Sequence * sequence(std::string_view name) const
Definition animation.cpp:93
std::string_view defaultMesh() const
Definition npc.h:25
Definition world.h:31
Tempest::Vec3 translate
Definition animation.h:47
std::vector< Tempest::Vec3 > tr
Definition animation.h:52
std::vector< zenkit::MdsSoundEffect > sfx
Definition animation.h:61
std::vector< zenkit::AnimationSample > samples
Definition animation.h:50
void setupEvents(float fpsRate)
std::vector< uint64_t > defParFrame
Definition animation.h:69
std::vector< MdsParticleEffect > pfx
Definition animation.h:62
std::vector< uint64_t > defWindow
Definition animation.h:70
std::vector< uint32_t > nodeIndex
Definition animation.h:51
std::vector< zenkit::MdsMorphAnimation > mmStartAni
Definition animation.h:66
Tempest::Vec3 moveTr
Definition animation.h:48
std::vector< zenkit::MdsModelTag > tag
Definition animation.h:63
std::vector< uint64_t > defHitEnd
Definition animation.h:68
std::vector< zenkit::MdsSoundEffectGround > gfx
Definition animation.h:60
std::vector< zenkit::MdsEventTag > events
Definition animation.h:64
uint32_t firstFrame
Definition animation.h:55
zenkit::MdsFightMode weaponCh
Definition animation.h:37
uint8_t groundSounds
Definition animation.h:36
std::vector< EvMorph > morph
Definition animation.h:39
std::vector< EvTimed > timed
Definition animation.h:38
uint8_t def_opt_frame
Definition animation.h:35
std::string_view node
Definition animation.h:30
std::string_view anim
Definition animation.h:31
std::string_view slot[2]
Definition animation.h:25
std::string_view item
Definition animation.h:24
zenkit::MdsEventType def
Definition animation.h:23
float atkTotalTime(uint16_t comboLen) const
std::string next
Definition animation.h:112
float totalTime() const
bool canInterrupt(uint64_t now, uint64_t sTime, uint16_t comboLen) const
bool isAttackAnim() const
void processPfx(uint64_t barrier, uint64_t sTime, uint64_t now, MdlVisual &visual, World &world) const
const char * shortName
Definition animation.h:104
const Sequence * nextPtr
Definition animation.h:113
bool isDefParWindow(uint64_t t) const
Tempest::Vec3 speed(uint64_t at, uint64_t dt) const
bool isFinished(uint64_t now, uint64_t sTime, uint16_t comboLen) const
Tempest::Vec3 translateXZ(uint64_t at) const
bool isPrehit(uint64_t sTime, uint64_t now) const
void schemeName(char buf[64]) const
zenkit::AnimationFlags flags
Definition animation.h:106
bool isRotate() const
Definition animation.h:80
bool isMove() const
Definition animation.h:81
bool isFly() const
Definition animation.h:82
const Animation * owner
Definition animation.h:114
std::string name
Definition animation.h:103
bool isIdle() const
Definition animation.h:83
void processEvents(uint64_t barrier, uint64_t sTime, uint64_t now, EvCount &ev) const
bool isInComboWindow(uint64_t t, uint16_t comboLen) const
void processSfx(uint64_t barrier, uint64_t sTime, uint64_t now, Npc *npc, Interactive *mob) const
std::vector< const Sequence * > comb
Definition animation.h:116
bool isDefWindow(uint64_t t) const
std::string askName
Definition animation.h:103
std::shared_ptr< AnimData > data
Definition animation.h:117