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