OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
animate.h
1/*
2===========================================================================
3Copyright (C) 2023 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22// animate.h -- Animate class
23
24#pragma once
25
26#if defined(GAME_DLL)
27# include "entity.h"
28#elif defined(CGAME_DLL)
29# include "script/canimate.h"
30#endif
31
32#include "archive.h"
33
34extern Event EV_SetAnim;
35extern Event EV_SetSyncTime;
36
37#define ANIM_PAUSED 1
38#define ANIM_SYNC 2
39#define ANIM_FINISHED 4
40#define ANIM_NOEXIT 8
41#define ANIM_NODELTA 16
42#define ANIM_LOOP 32
43#define ANIM_NOACTION 64
44
45#define MINIMUM_DELTA_MOVEMENT 8
46#define MINIMUM_DELTA_MOVEMENT_PER_FRAME (MINIMUM_DELTA_MOVEMENT / 20.0f)
47
48#define FLAGGED_ANIMATE_SLOT 20
49
50class Animate;
51
52typedef SafePtr<Animate> AnimatePtr;
53
54class Animate : public Entity
55{
56protected:
57 int animFlags[MAX_FRAMEINFOS];
58
59 float syncTime;
60 float syncRate;
61 int pauseSyncTime;
62 bool is_paused;
63
64 Event *doneEvents[MAX_FRAMEINFOS];
65
66 float animtimes[MAX_FRAMEINFOS];
67 float frametimes[MAX_FRAMEINFOS];
68
69public:
70 Vector frame_delta;
71 float angular_delta;
72
73public:
74 CLASS_PROTOTYPE(Animate);
75
76 Animate();
77 ~Animate();
78
79 void NewAnim(int animnum, int slot = 0, float weight = 1.0f);
80 void NewAnim(int animnum, Event *endevent, int slot = 0, float weight = 1.0f);
81 void NewAnim(int animnum, Event &endevent, int slot = 0, float weight = 1.0f);
82 void NewAnim(const char *animname, int slot = 0, float weight = 1.0f);
83 void NewAnim(const char *animname, Event *endevent, int slot = 0, float weight = 1.0f);
84 void NewAnim(const char *animname, Event &endevent, int slot = 0, float weight = 1.0f);
85 void SetFrame(void);
86 qboolean HasAnim(const char *animname);
87 Event *AnimDoneEvent(int slot = 0);
88 void SetAnimDoneEvent(Event &event, int slot = 0);
89 void SetAnimDoneEvent(Event *event, int slot = 0);
90 int NumAnims(void);
91 const char *AnimName(int slot = 0);
92 float AnimTime(int slot = 0);
93
94 int CurrentAnim(int slot = 0) const override;
95 float CurrentTime(int slot = 0) const override;
96
97 void Archive(Archiver &arc) override;
98 virtual void AnimFinished(int slot = 0);
99
100 void PreAnimate(void) override;
101 void PostAnimate(void) override;
102 void SetTime(int slot = 0, float time = 0.0f);
103 void SetNormalTime(int slot = 0, float normal = 1.0f);
104 float GetTime(int slot = 0);
105 float GetNormalTime(int slot = 0);
106 void SetWeight(int slot = 0, float weight = 1.0f);
107 float GetWeight(int slot = 0);
108 void SetRepeatType(int slot = 0);
109 void SetOnceType(int slot = 0);
110 bool IsRepeatType(int slot);
111 void Pause(int slot = 0, int pause = 1);
112 void StopAnimating(int slot = 0);
113 void UseSyncTime(int slot, int sync);
114 void SetSyncTime(float s);
115 float GetSyncTime();
116 void SetSyncRate(float rate);
117
118 float GetSyncRate();
119 void PauseSyncTime(int pause);
120 float GetYawOffset();
121 float GetCrossTime(int slot);
122
123 void DoExitCommands(int slot = 0);
124 void ForwardExec(Event *ev);
125 void EventSetSyncTime(Event *ev);
126 void EventIsLoopingAnim(Event *ev);
127 void EventSetYawFromBone(Event *ev);
128 void EventPlayerSpawn(Event *ev);
129 void EventPlayerSpawnUtility(Event *ev);
130 void EventPauseAnim(Event *ev);
131 virtual void DumpAnimInfo();
132 void SlotChanged(int slot);
133
134 void ClientSound(Event *ev);
135
136 // FIXME: delete this, fakk2 remnant
137 int NumFrames(int slot = 0);
138};
139
140inline void Animate::SetWeight(int slot, float weight)
141{
142 edict->s.frameInfo[slot].weight = weight;
143}
144
145inline float Animate::GetWeight(int slot)
146{
147 return edict->s.frameInfo[slot].weight;
148}
149
150inline bool Animate::IsRepeatType(int slot)
151{
152 return (animFlags[slot] & ANIM_LOOP) != 0;
153}
154
155inline float Animate::GetSyncTime()
156{
157 return syncTime;
158}
159
160inline float Animate::GetSyncRate()
161{
162 return syncRate;
163}
164
165inline void Animate::PauseSyncTime(int pause)
166{
167 pauseSyncTime = pause;
168}
169
170inline void Animate::Archive(Archiver& arc)
171{
172 int i;
173
174 Entity::Archive(arc);
175
176 for (i = 0; i < MAX_FRAMEINFOS; i++) {
177 arc.ArchiveInteger(&animFlags[i]);
178 }
179 arc.ArchiveFloat(&syncTime);
180 arc.ArchiveFloat(&syncRate);
181 arc.ArchiveInteger(&pauseSyncTime);
182 arc.ArchiveBool(&is_paused);
183 for (i = 0; i < MAX_FRAMEINFOS; i++) {
184 arc.ArchiveEventPointer(&doneEvents[i]);
185 }
186 for (i = 0; i < MAX_FRAMEINFOS; i++) {
187 arc.ArchiveFloat(&animtimes[i]);
188 }
189 for (i = 0; i < MAX_FRAMEINFOS; i++) {
190 arc.ArchiveFloat(&frametimes[i]);
191 }
192 arc.ArchiveVector(&frame_delta);
193 arc.ArchiveFloat(&angular_delta);
194}
195
196inline void Animate::SlotChanged(int slot)
197{
198 animFlags[slot] = (animFlags[slot] | ANIM_NODELTA) & ~ANIM_FINISHED;
199}
200
201inline float Animate::CurrentTime(int slot) const
202{
203 return edict->s.frameInfo[slot].time;
204}
205
206inline Event *Animate::AnimDoneEvent(int slot)
207{
208 return doneEvents[slot];
209}
210
211inline int Animate::NumFrames(int slot)
212{
213 return gi.Anim_NumFrames(edict->tiki, edict->s.frameInfo[slot].index);
214}
Definition animate.h:55
Definition archive.h:86
Definition listener.h:246
Definition safeptr.h:160
Definition vector.h:61