ScummVM API documentation
xmodel.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 /*
23  * This file is based on WME.
24  * http://dead-code.org/redir.php?target=wme
25  * Copyright (c) 2003-2013 Jan Nedoma and contributors
26  */
27 
28 #ifndef WINTERMUTE_XMODEL_H
29 #define WINTERMUTE_XMODEL_H
30 
31 #include "engines/wintermute/base/base_object.h"
32 #include "engines/wintermute/base/base_sprite.h"
33 #include "engines/wintermute/base/gfx/xmath.h"
34 #include "engines/wintermute/base/gfx/3deffect.h"
35 #include "engines/wintermute/base/gfx/3deffect_params.h"
36 #include "engines/wintermute/coll_templ.h"
37 #include "engines/wintermute/video/video_theora_player.h"
38 #include "engines/wintermute/utils/utils.h"
39 
40 namespace Wintermute {
41 
42 class AnimationChannel;
43 class AnimationSet;
44 class FrameNode;
45 class Material;
46 class ShadowVolume;
47 class XFileData;
48 class Effect3D;
49 class Effect3DParams;
50 
51 #define X_NUM_ANIMATION_CHANNELS 10
52 
53 class XModel : public BaseObject {
54 private:
55  class XModelMatSprite {
56  public:
57  char *_matName;
58  char *_effectFile;
59  BaseSprite *_sprite;
60  VideoTheoraPlayer *_theora;
61  Effect3D *_effect;
62  Effect3DParams *_effectParams;
63 
64  XModelMatSprite() {
65  _matName = nullptr;
66  _sprite = nullptr;
67  _theora = nullptr;
68  _effect = nullptr;
69  _effectFile = nullptr;
70  _effectParams = nullptr;
71  }
72 
73  XModelMatSprite(const char *matName, BaseSprite *sprite) {
74  _theora = nullptr;
75  _matName = nullptr;
76  _effect = nullptr;
77  BaseUtils::setString(&_matName, matName);
78  _sprite = sprite;
79  _effectFile = nullptr;
80  _effectParams = nullptr;
81  }
82 
83  XModelMatSprite(const char *matName, VideoTheoraPlayer *theora) {
84  _sprite = nullptr;
85  _matName = nullptr;
86  _effect = nullptr;
87  BaseUtils::setString(&_matName, matName);
88  _theora = theora;
89  _effectFile = nullptr;
90  _effectParams = nullptr;
91  }
92 
93  XModelMatSprite(const char *matName, Effect3D *effect) {
94  _sprite = nullptr;
95  _matName = nullptr;
96  _theora = nullptr;
97  BaseUtils::setString(&_matName, matName);
98  _effect = effect;
99  _effectFile = nullptr;
100  _effectParams = new Effect3DParams();
101  }
102 
103  ~XModelMatSprite() {
104  delete[] _matName;
105  _matName = nullptr;
106  delete _effectFile;
107  _effectFile = nullptr;
108  delete _sprite;
109  _sprite = nullptr;
110  delete _theora;
111  _theora = nullptr;
112  delete _effect;
113  _effect = nullptr;
114  delete _effectParams;
115  _effectParams = nullptr;
116  }
117 
118  bool setSprite(BaseSprite *sprite) {
119  delete _theora;
120  _theora = nullptr;
121  delete _sprite;
122  _sprite = sprite;
123 
124  return true;
125  }
126 
127  bool setTheora(VideoTheoraPlayer *theora) {
128  delete _theora;
129  _theora = nullptr;
130  delete _sprite;
131  _sprite = nullptr;
132  _theora = theora;
133 
134  return true;
135  }
136 
137  bool setEffect(Effect3D *effect) {
138  delete _effect;
139  _effect = effect;
140 
141  if (!_effectParams)
142  _effectParams = new Effect3DParams();
143  else
144  _effectParams->clear();
145 
146  return true;
147  }
148 
149  bool persist(BasePersistenceManager *persistMgr) {
150  persistMgr->transferCharPtr(TMEMBER(_matName));
151  persistMgr->transferPtr(TMEMBER(_sprite));
152 
153  persistMgr->transferPtr(TMEMBER(_theora));
154 
155  if (persistMgr->getIsSaving()) {
156  char *effectFileName = nullptr;
157  if (_effect)
158  BaseUtils::setString(&effectFileName, _effect->getFileName());
159  else
160  effectFileName = nullptr;
161 
162  persistMgr->transferCharPtr(TMEMBER(effectFileName));
163  delete[] effectFileName;
164  } else {
165  persistMgr->transferCharPtr(TMEMBER(_effectFile));
166  }
167 
168  if (persistMgr->getIsSaving()) {
169  bool hasParams = _effectParams != nullptr;
170  persistMgr->transferBool(TMEMBER(hasParams));
171 
172  if (hasParams)
173  _effectParams->persist(persistMgr);
174  } else {
175  bool hasParams;
176  persistMgr->transferBool(TMEMBER(hasParams));
177 
178  if (hasParams) {
179  _effectParams = new Effect3DParams();
180  _effectParams->persist(persistMgr);
181  } else
182  _effectParams = nullptr;
183  }
184 
185  return true;
186  }
187  };
188 
189 public:
190 
191  const static int kDefaultTicksPerSecond = 4800;
192 
193  DECLARE_PERSISTENT(XModel, BaseObject)
194 
195  XModel(BaseGame *inGame, BaseObject *owner);
196  virtual ~XModel();
197 
198  XModel *_parentModel{};
199 
200  bool loadFromFile(const Common::String &filename, XModel *parentModel = nullptr);
201  bool mergeFromFile(const Common::String &filename);
202 
203  bool loadAnimationSet(const Common::String &filename, XFileData *xobj);
204  bool loadAnimation(const Common::String &filename, XFileData *xobj, AnimationSet *parentAnimSet = nullptr);
205 
206  bool update() override;
207  bool render();
208  bool renderFlatShadowModel(uint32 shadowColor);
209  bool reset();
210 
211  bool updateShadowVol(ShadowVolume *shadow, DXMatrix *modelMat, DXVector3 *light, float extrusionDepth);
212 
213  bool playAnim(int channel, const Common::String &anim, uint32 transitionTime = 0, bool forceReset = false, uint32 stopTransitionTime = 0);
214  bool isAnimPending(char *animName = nullptr);
215  bool isAnimPending(int channel, const char *animName = nullptr);
216 
217  bool isTransparentAt(int x, int y);
218 
219  static bool loadName(BaseNamedObject *obj, XFileData *data);
220  static bool loadName(Common::String &targetStr, XFileData *data);
221 
222  Common::Rect32 _boundingRect;
223  BaseObject *_owner{};
224 
225  bool parseAnim(char *buffer);
226  bool parseEvent(AnimationSet *anim, char *buffer);
227  AnimationSet *getAnimationSetByName(const Common::String &name);
228 
229  bool stopAnim(int channel, uint32 transitionTime);
230  bool stopAnim(uint32 transitionTime);
231 
232  DXMatrix *getBoneMatrix(const char *boneName);
233  FrameNode *getRootFrame();
234 
235  bool setMaterialSprite(const char *materialName, const char *spriteFilename);
236  bool setMaterialTheora(const char *materialName, const char *theoraFilename);
237  bool setMaterialEffect(const char *materialName, const char *effectFilename);
238  bool removeMaterialEffect(const char *materialName);
239  bool setMaterialEffectParam(const char *materialName, const char *paramName, ScValue *val);
240  bool setMaterialEffectParam(const char *materialName, const char *paramName, DXVector4 val);
241  bool initializeSimple();
242 
243  bool invalidateDeviceObjects() override;
244  bool restoreDeviceObjects() override;
245 
246  bool unloadAnimation(const char *animName);
247 
248  uint32 _ticksPerSecond{};
249 
250  BaseArray<AnimationSet *> _animationSets;
251 
252 private:
253  void cleanup(bool complete = true);
254  bool findBones(bool animOnly = false, XModel *parentModel = nullptr);
255 
256  void updateBoundingRect();
257  void static inline updateRect(Common::Rect32 *rc, DXVector3 *vec);
258  DXViewport _drawingViewport{};
259  DXMatrix _lastWorldMat;
260  DXMatrix _lastViewMat;
261  DXMatrix _lastProjMat;
262  int32 _lastOffsetX{};
263  int32 _lastOffsetY{};
264 
265  DXVector3 _BBoxStart;
266  DXVector3 _BBoxEnd;
267 
268 protected:
269  BaseArray<const char*> _mergedModels;
270  AnimationChannel *_channels[X_NUM_ANIMATION_CHANNELS]{};
271 
272  FrameNode *_rootFrame{};
273 
274  BaseArray<XModelMatSprite *> _matSprites;
275 };
276 
277 } // namespace Wintermute
278 
279 #endif
Definition: base_game.h:75
Definition: rect.h:526
Definition: script_value.h:42
Definition: str.h:59
Definition: base_persistence_manager.h:55
Definition: xmath.h:50
Definition: coll_templ.h:399
Definition: xanimation_set.h:42
Definition: video_theora_player.h:41
Definition: xmath.h:140
Definition: xmodel.h:53
Definition: 3dshadow_volume.h:49
Definition: xanimation_channel.h:37
Definition: coll_templ.h:347
Definition: 3deffect_params.h:36
Definition: base_named_object.h:36
Definition: xframe_node.h:44
Definition: xmath.h:117
Definition: base_sprite.h:40
Definition: xmath.h:79
Definition: 3deffect.h:36
Definition: xfile_loader.h:459
Definition: base_object.h:49
Definition: achievements_tables.h:27