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 #include "engines/wintermute/dcgf.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  SAFE_DELETE_ARRAY(_matName);
106  SAFE_DELETE_ARRAY(_effectFile);
107  SAFE_DELETE(_sprite);
108  SAFE_DELETE(_theora);
109  SAFE_DELETE(_effect);
110  SAFE_DELETE(_effectParams);
111  }
112 
113  bool setSprite(BaseSprite *sprite) {
114  SAFE_DELETE(_theora);
115  SAFE_DELETE(_sprite);
116  _sprite = sprite;
117 
118  return true;
119  }
120 
121  bool setTheora(VideoTheoraPlayer *theora) {
122  SAFE_DELETE(_theora);
123  SAFE_DELETE(_sprite);
124  _theora = theora;
125 
126  return true;
127  }
128 
129  bool setEffect(Effect3D *effect) {
130  SAFE_DELETE(_effect);
131  _effect = effect;
132 
133  if (!_effectParams)
134  _effectParams = new Effect3DParams();
135  else
136  _effectParams->clear();
137 
138  return true;
139  }
140 
141  bool persist(BasePersistenceManager *persistMgr) {
142  persistMgr->transferCharPtr(TMEMBER(_matName));
143  persistMgr->transferPtr(TMEMBER(_sprite));
144 
145  persistMgr->transferPtr(TMEMBER(_theora));
146 
147  if (persistMgr->getIsSaving()) {
148  char *effectFileName = nullptr;
149  if (_effect)
150  BaseUtils::setString(&effectFileName, _effect->getFileName());
151  else
152  effectFileName = nullptr;
153 
154  persistMgr->transferCharPtr(TMEMBER(effectFileName));
155  SAFE_DELETE_ARRAY(effectFileName);
156  } else {
157  persistMgr->transferCharPtr(TMEMBER(_effectFile));
158  }
159 
160  if (persistMgr->getIsSaving()) {
161  bool hasParams = _effectParams != nullptr;
162  persistMgr->transferBool(TMEMBER(hasParams));
163 
164  if (hasParams)
165  _effectParams->persist(persistMgr);
166  } else {
167  bool hasParams;
168  persistMgr->transferBool(TMEMBER(hasParams));
169 
170  if (hasParams) {
171  _effectParams = new Effect3DParams();
172  _effectParams->persist(persistMgr);
173  } else
174  _effectParams = nullptr;
175  }
176 
177  return true;
178  }
179  };
180 
181 public:
182 
183  const static int kDefaultTicksPerSecond = 4800;
184 
185  DECLARE_PERSISTENT(XModel, BaseObject)
186 
187  XModel(BaseGame *inGame, BaseObject *owner);
188  virtual ~XModel();
189 
190  XModel *_parentModel{};
191 
192  bool loadFromFile(const char *filename, XModel *parentModel = nullptr);
193  bool mergeFromFile(const char *filename);
194 
195  bool loadAnimationSet(const char *filename, XFileData *xobj);
196  bool loadAnimation(const char *filename, XFileData *xobj, AnimationSet *parentAnimSet = nullptr);
197 
198  bool update() override;
199  bool render();
200  bool renderFlatShadowModel(uint32 shadowColor);
201  bool reset();
202 
203  bool updateShadowVol(ShadowVolume *shadow, DXMatrix *modelMat, DXVector3 *light, float extrusionDepth);
204 
205  bool playAnim(int channel, const char *anim, uint32 transitionTime = 0, bool forceReset = false, uint32 stopTransitionTime = 0);
206  bool isAnimPending(char *animName = nullptr);
207  bool isAnimPending(int channel, const char *animName = nullptr);
208 
209  bool isTransparentAt(int x, int y);
210 
211  static bool loadName(BaseNamedObject *obj, XFileData *data);
212  static bool loadName(Common::String &targetStr, XFileData *data);
213 
214  Common::Rect32 _boundingRect;
215  BaseObject *_owner{};
216 
217  bool parseAnim(char *buffer);
218  bool parseEvent(AnimationSet *anim, char *buffer);
219  AnimationSet *getAnimationSetByName(const char *name);
220 
221  bool stopAnim(int channel, uint32 transitionTime);
222  bool stopAnim(uint32 transitionTime);
223 
224  DXMatrix *getBoneMatrix(const char *boneName);
225  FrameNode *getRootFrame();
226 
227  bool setMaterialSprite(const char *materialName, const char *spriteFilename);
228  bool setMaterialTheora(const char *materialName, const char *theoraFilename);
229  bool setMaterialEffect(const char *materialName, const char *effectFilename);
230  bool removeMaterialEffect(const char *materialName);
231  bool setMaterialEffectParam(const char *materialName, const char *paramName, ScValue *val);
232  bool setMaterialEffectParam(const char *materialName, const char *paramName, DXVector4 val);
233  bool initializeSimple();
234 
235  bool invalidateDeviceObjects() override;
236  bool restoreDeviceObjects() override;
237 
238  bool unloadAnimation(const char *animName);
239 
240  uint32 _ticksPerSecond{};
241 
242  BaseArray<AnimationSet *> _animationSets;
243 
244 private:
245  void cleanup(bool complete = true);
246  bool findBones(bool animOnly = false, XModel *parentModel = nullptr);
247 
248  void updateBoundingRect();
249  void static inline updateRect(Common::Rect32 *rc, DXVector3 *vec);
250  DXViewport _drawingViewport{};
251  DXMatrix _lastWorldMat;
252  DXMatrix _lastViewMat;
253  DXMatrix _lastProjMat;
254  int32 _lastOffsetX{};
255  int32 _lastOffsetY{};
256 
257  DXVector3 _BBoxStart;
258  DXVector3 _BBoxEnd;
259 
260 protected:
261  BaseArray<const char*> _mergedModels;
262  AnimationChannel *_channels[X_NUM_ANIMATION_CHANNELS]{};
263 
264  FrameNode *_rootFrame{};
265 
266  BaseArray<XModelMatSprite *> _matSprites;
267 };
268 
269 } // namespace Wintermute
270 
271 #endif
Definition: base_game.h:79
Definition: rect.h:526
Definition: script_value.h:42
Definition: str.h:59
Definition: base_persistence_manager.h:43
Definition: xmath.h:72
Definition: coll_templ.h:399
Definition: xanimation_set.h:42
Definition: video_theora_player.h:41
Definition: xmath.h:162
Definition: xmodel.h:54
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:139
Definition: base_sprite.h:40
Definition: xmath.h:101
Definition: 3deffect.h:36
Definition: xfile_loader.h:459
Definition: base_object.h:49
Definition: achievements_tables.h:27