1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TWINE_SCENE_ANIMATIONS_H
24 #define TWINE_SCENE_ANIMATIONS_H
25 
26 #include "common/scummsys.h"
27 #include "twine/parser/anim.h"
28 
29 namespace TwinE {
30 
31 struct AnimTimerDataStruct;
32 class BodyData;
33 class TwinEEngine;
34 
35 class Animations {
36 private:
37 	TwinEEngine *_engine;
38 	int16 applyAnimStepRotation(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const;
39 	int16 applyAnimStepTranslation(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const;
40 
41 	/**
42 	 * Verify animation at keyframe
43 	 * @param keyframeIdx Animation key frame index
44 	 * @param animData Animation data
45 	 * @param animTimerDataPtr Animation time data
46 	 */
47 	bool verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, AnimTimerDataStruct *animTimerDataPtr);
48 
49 	void copyKeyFrameToState(const KeyFrame *keyframe, BodyData &bodyData, int32 numBones) const;
50 	void copyStateToKeyFrame(KeyFrame *keyframe, const BodyData &bodyData) const;
51 
52 	int _animKeyframeBufIdx = 0;
53 	KeyFrame _animKeyframeBuf[32];
54 
55 	/** Rotation by anim and not by engine */
56 	int16 _processRotationByAnim = 0; // processActorVar5
57 	/** Last rotation angle */
58 	int16 _processLastRotationAngle = ANGLE_0; // processActorVar6
59 
60 	/** Current step coordinates */
61 	IVec3 _currentStep;
62 
63 public:
64 	Animations(TwinEEngine *engine);
65 
66 	/** Current process actor index */
67 	int16 _currentlyProcessedActorIdx = 0;
68 	/** Current actor anim extra pointer */
69 	AnimationTypes _currentActorAnimExtraPtr = AnimationTypes::kAnimNone;
70 
71 	/**
72 	 * Set animation keyframe
73 	 * @param keyframIdx Animation keyframe index
74 	 * @param animData Animation data
75 	 * @param bodyData Body model data
76 	 * @param animTimerDataPtr Animation time data
77 	 */
78 	void setAnimAtKeyframe(int32 keyframeIdx, const AnimData &animData, BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr);
79 
80 	/**
81 	 * Set new body animation
82 	 * @param keyframeIdx Animation key frame index
83 	 * @param animData Animation data
84 	 * @param bodyData Body model data
85 	 * @param animTimerDataPtr Animation time data
86 	 */
87 	bool setModelAnimation(int32 keyframeIdx, const AnimData &animData, BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr);
88 
89 	/**
90 	 * Get entity anim index (This is taken from File3D entities)
91 	 * @param animIdx Entity animation index
92 	 * @param actorIdx Actor index
93 	 */
94 	int32 getBodyAnimIndex(AnimationTypes animIdx, int32 actorIdx = OWN_ACTOR_SCENE_INDEX);
95 
96 	/**
97 	 * Stock animation - copy the next keyFrame from a different buffer
98 	 * @param bodyData Body model data
99 	 * @param animTimerDataPtr Animation time data
100 	 */
101 	void stockAnimation(const BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr);
102 
103 	/**
104 	 * Initialize animation
105 	 * @param newAnim animation to init
106 	 * @param animType animation type
107 	 * @param animExtra animation actions extra data
108 	 * @param actorIdx actor index
109 	 */
110 	bool initAnim(AnimationTypes newAnim, AnimType animType, AnimationTypes animExtra, int32 actorIdx);
111 
112 	/**
113 	 * Process acotr animation actions
114 	 * @param actorIdx Actor index
115 	 */
116 	void processAnimActions(int32 actorIdx);
117 
118 	/**
119 	 * Process main loop actor animations
120 	 * @param actorIdx Actor index
121 	 */
122 	void processActorAnimations(int32 actorIdx);
123 };
124 
125 } // namespace TwinE
126 #endif
127