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