ScummVM API documentation
character.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TETRAEDGE_GAME_CHARACTER_H
23 #define TETRAEDGE_GAME_CHARACTER_H
24 
25 #include "common/array.h"
26 #include "common/str.h"
27 #include "common/types.h"
28 #include "common/ptr.h"
29 #include "tetraedge/te/te_animation.h"
30 #include "tetraedge/te/te_model_animation.h"
31 #include "tetraedge/te/te_vector3f32.h"
32 #include "tetraedge/te/te_matrix4x4.h"
33 #include "tetraedge/te/te_model.h"
34 #include "tetraedge/te/te_bezier_curve.h"
35 #include "tetraedge/te/te_free_move_zone.h"
36 #include "tetraedge/te/te_trs.h"
37 #include "tetraedge/te/te_curve_anim2.h"
38 
39 namespace Tetraedge {
40 
41 class Character : public TeAnimation, public TeObject {
42 public:
43  Character();
44  virtual ~Character();
45 
46  struct AnimSettings {
47  AnimSettings() : _stepLeft(0), _stepRight(0) {};
48  Common::String _file;
49  int _stepLeft;
50  int _stepRight;
51  };
52 
53  struct WalkSettings {
54  AnimSettings _walkParts[4];
55 
56  void clear();
57  };
58 
60  CharacterSettings() : _walkSpeed(0.0f), _invertNormals(false) {}
61 
62  Common::String _name;
63  Common::String _modelFileName;
64  TeVector3f32 _defaultScale;
65  Common::String _idleAnimFileName;
66  Common::HashMap<Common::String, WalkSettings> _walkSettings; // keys are "Walk", "Jog", etc
67  float _walkSpeed;
68 
69  TeVector3f32 _cutSceneCurveDemiPosition;
70  Common::String _defaultEyes; // Note: Engine supports more, but in practice only one ever used.
71  Common::String _defaultMouth; // Note: Engine supports more, but in practice only one ever used.
72  Common::String _defaultBody; // Note: Engine supports more, but in practice only one ever used.
73 
74  bool _invertNormals;
75 
76  void clear();
77  };
78 
81  int _size;
82  };
83 
84  enum WalkPart {
85  WalkPart_Start,
86  WalkPart_Loop,
87  WalkPart_EndD,
88  WalkPart_EndG
89  };
90 
91  struct Callback {
92  Common::String _luaFn;
93  int _triggerFrame;
94  int _lastCheckFrame;
95  int _maxCalls;
96  float _callsMade;
97  };
98 
99  class Water {
100  Water();
104  };
105 
106  void addCallback(const Common::String &s1, const Common::String &s2, float f1, float f2);
107 
108  static void animCacheFreeAll();
109  static void animCacheFreeOldest();
110  static TeIntrusivePtr<TeModelAnimation> animCacheLoad(const Common::Path &path);
111 
112  float animLength(const TeModelAnimation &modelanim, int bone, int lastframe);
113  float animLengthFromFile(const Common::String &animname, uint32 *pframeCount, uint lastframe = 9999);
114  bool blendAnimation(const Common::String &animname, float amount, bool repeat, bool returnToIdle);
115  TeVector3f32 correctPosition(const TeVector3f32 &pos);
116  float curveOffset();
117  void deleteAllCallback();
118  void deleteAnim();
119  void deleteCallback(const Common::String &str1, const Common::String &str2, float f);
120  //static bool deserialize(TiXmlElement *param_1, Walk *param_2);
121  void endMove();
122 
123  const WalkSettings *getCurrentWalkFiles();
124  bool isFramePassed(int frameno);
125  bool isWalkEnd();
126  int leftStepFrame(enum WalkPart walkpart);
127  int rightStepFrame(enum WalkPart walkpart);
128  bool loadModel(const Common::String &name, bool unused);
129  static bool loadSettings(const Common::Path &path);
130 
131  bool onBonesUpdate(const Common::String &boneName, TeMatrix4x4 &boneMatrix);
132  bool onModelAnimationFinished();
133  void permanentUpdate();
134  void placeOnCurve(TeIntrusivePtr<TeBezierCurve> &curve);
135  //void play() // just called TeAnimation::play();
136  void removeAnim();
137  void removeFromCurve();
138  Common::String rootBone() const;
139 
140  bool setAnimation(const Common::String &name, bool repeat, bool returnToIdle = false, bool unused = false, int startFrame = -1, int endFrame = 9999);
141  void setAnimationSound(const Common::String &name, uint offset);
142  void setCurveOffset(float offset);
143  void setFreeMoveZone(TeFreeMoveZone *zone);
144  bool setShadowVisible(bool visible);
145  void setStepSound(const Common::String &stepSound1, const Common::String &stepSound2);
146  float speedFromAnim(double amount);
147  //void stop(); // just maps to TeAnimation::stop();
148  float translationFromAnim(const TeModelAnimation &anim, int bone, int frame);
149  TeVector3f32 translationVectorFromAnim(const TeModelAnimation &anim, int bone, int frame);
150  TeTRS trsFromAnim(const TeModelAnimation &anim, int bone, int frame);
151  void update(double percentval) override;
152  void updateAnimFrame();
153  void updatePosition(float curveOffset);
154  Common::String walkAnim(WalkPart part);
155  void walkMode(const Common::String &mode);
156  void walkTo(float curveEnd, bool walkFlag);
157 
159  TeIntrusivePtr<TeModel> _shadowModel[2];
160  TeSignal1Param<const Common::String &> _characterAnimPlayerFinishedSignal;
161  TeSignal1Param<const Common::String &> _onCharacterAnimFinishedSignal;
162 
163  const CharacterSettings &characterSettings() const { return _characterSettings; }
164  Common::String &walkModeStr() { return _walkModeStr; } // writable for loading games.
165  const Common::String &curAnimName() const { return _curAnimName; }
166  TeFreeMoveZone *freeMoveZone() { return _freeMoveZone; }
167  const Common::String &freeMoveZoneName() const { return _freeMoveZoneName; }
168  void setFreeMoveZoneName(const Common::String &val) { _freeMoveZoneName = val; }
169  bool needsSomeUpdate() const { return _needsSomeUpdate; }
170  void setNeedsSomeUpdate(bool val) { _needsSomeUpdate = val; }
171  void setCharLookingAt(Character *other) { _charLookingAt = other; }
172  void setCharLookingAtOffset(float val) { _charLookingAtOffset = val; }
173  float charLookingAtOffset() const { return _charLookingAtOffset; }
174  const TeVector3f32 &positionCharacter() const { return _positionCharacter; }
175  void setPositionCharacter(const TeVector3f32 &val) { _positionCharacter = val; }
176  bool positionFlag() const { return _positionFlag; }
177  void setPositionFlag(bool val) { _positionFlag = val; }
178  void setCurveStartLocation(const TeVector3f32 &val) { _curveStartLocation = val; }
179  bool hasAnchor() const { return _hasAnchor; }
180  void setHasAnchor(bool val) { _hasAnchor = val; }
181  const TeVector2f32 &headRotation() const { return _headRotation; }
182  void setHeadRotation(const TeVector2f32 &val) { _headRotation = val; }
183  void setLastHeadRotation(const TeVector2f32 &val) { _lastHeadRotation = val; }
184  const TeVector3f32 &lastHeadBoneTrans() const { return _lastHeadBoneTrans; }
185  Character *charLookingAt() { return _charLookingAt; }
186  bool lookingAtTallThing() const { return _lookingAtTallThing; }
187  void setLookingAtTallThing(bool val) { _lookingAtTallThing = val; }
188  TeIntrusivePtr<TeBezierCurve> curve() { return _curve; }
189  void setRecallageY(bool val) { _recallageY = val; }
190 
191  static void cleanup();
192 
193 private:
194  float _walkCurveStart;
195  float _walkCurveLast;
196  float _walkCurveEnd;
197  float _walkCurveLen;
198  float _walkCurveIncrement;
199  float _walkCurveNextLength;
200  float _walkedLength;
201  int _walkTotalFrames;
202  bool _walkToFlag;
203  bool _walkEndAnimG;
205  TeVector3f32 _curveStartLocation;
206 
207  TeFreeMoveZone *_freeMoveZone;
208  Common::String _freeMoveZoneName;
209  Common::String _stepSound1;
210  Common::String _stepSound2;
211  Common::String _walkModeStr; // Walk or Jog
212  Common::String _animSound;
213 
214  Character *_charLookingAt;
215  float _charLookingAtOffset; // Only used in Syberia 2
216 
217  uint _animSoundOffset;
218 
219  TeIntrusivePtr<TeModelAnimation> _curModelAnim;
220 
221  CharacterSettings _characterSettings;
222 
223  float _walkStartAnimLen;
224  float _walkLoopAnimLen;
225  float _walkEndGAnimLen;
226 
227  uint32 _walkStartAnimFrameCount;
228  uint32 _walkLoopAnimFrameCount;
229  uint32 _walkEndGAnimFrameCount;
230 
231  int _lastFrame;
232  int _lastAnimFrame;
233  bool _notWalkAnim;
234  bool _returnToIdleAnim;
235  bool _callbacksChanged;
236  bool _needsSomeUpdate;
237  bool _positionFlag;
238  bool _lookingAtTallThing;
239  bool _hasAnchor;
240  bool _recallageY;
241 
242  TeVector2f32 _headRotation;
243  TeVector2f32 _lastHeadRotation;
244  TeVector3f32 _lastHeadBoneTrans;
245 
246  TeVector3f32 _positionCharacter;
247 
248  // TODO: work out how these are different
249  Common::String _setAnimName;
250  Common::String _curAnimName;
251 
253 
254  // static Common::Array<AnimCacheElement> *_animCache; // Never used?
255  // static uint _animCacheSize; // Never used?
257  static Common::HashMap<Common::String, CharacterSettings> *_globalCharacterSettings;
258 
259 };
260 
261 } // end namespace Tetraedge
262 
263 #endif // TETRAEDGE_GAME_CHARACTER_H
Definition: character.h:41
Definition: str.h:59
Definition: detection.h:27
Definition: path.h:52
Definition: te_free_move_zone.h:57
Definition: te_curve_anim2.h:36
Definition: character.h:79
Definition: te_model_animation.h:40
Definition: te_matrix4x4.h:37
Definition: hashmap.h:85
Definition: te_object.h:29
Definition: character.h:46
Definition: character.h:99
Definition: character.h:91
Definition: character.h:59
Definition: te_trs.h:31
Definition: te_intrusive_ptr.h:31
Definition: te_animation.h:31
Definition: te_vector3f32.h:33
Definition: te_vector2f32.h:32
Definition: te_signal.h:80
Definition: character.h:53