Torque3D Documentation / _generateds / afxEffectWrapper.h

afxEffectWrapper.h

Engine/source/afx/afxEffectWrapper.h

More...

Classes:

Public Typedefs

afxEffectList 

Detailed Description

Public Typedefs

typedef Vector< afxEffectBaseData * > afxEffectList 
  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#ifndef _AFX_EFFECT_WRAPPER_H_
 28#define _AFX_EFFECT_WRAPPER_H_
 29
 30//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 31
 32#include "afx/arcaneFX.h"
 33#include "afxEffectDefs.h"
 34#include "afxConstraint.h"
 35
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37
 38struct afxEffectTimingData
 39{
 40  F32     delay;
 41  F32     lifetime;
 42  F32     fade_in_time;
 43  F32     fade_out_time;
 44  F32     residue_lifetime;   
 45  F32     residue_fadetime;
 46  F32     life_bias;
 47  Point2F fadein_ease;
 48  Point2F fadeout_ease;
 49
 50  afxEffectTimingData()
 51  {
 52    delay = 0.0f;
 53    lifetime = 0.0f;
 54    fade_in_time = 0.0f;
 55    fade_out_time = 0.0f;
 56    residue_lifetime = 0.0f;
 57    residue_fadetime = 0.0f;
 58    life_bias = 1.0f;
 59    fadein_ease.set(0.0f, 1.0f);
 60    fadeout_ease.set(0.0f, 1.0f);
 61  }
 62};
 63
 64//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 65
 66class afxEffectWrapperData;
 67class afxAnimCurve;
 68
 69class afxEffectAdapterDesc
 70{
 71private:
 72  static Vector<afxEffectAdapterDesc*>* adapters;
 73
 74public:
 75  /*C*/         afxEffectAdapterDesc();
 76
 77  virtual bool  testEffectType(const SimDataBlock*) const=0;
 78  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const=0;
 79  virtual bool  runsOnServer(const afxEffectWrapperData*) const=0;
 80  virtual bool  runsOnClient(const afxEffectWrapperData*) const=0;
 81  virtual bool  isPositional(const afxEffectWrapperData*) const { return true; }
 82  virtual void  prepEffect(afxEffectWrapperData*) const { }
 83
 84  virtual afxEffectWrapper* create() const=0;
 85
 86  static bool   identifyEffect(afxEffectWrapperData*);
 87};
 88
 89//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 90
 91class afxXM_BaseData;
 92
 93class afxEffectBaseData : public GameBaseData, public afxEffectDefs
 94{
 95  typedef GameBaseData  Parent;
 96
 97public:
 98  /*C*/           afxEffectBaseData() { }
 99  /*C*/           afxEffectBaseData(const afxEffectBaseData& other, bool temp=false)  : GameBaseData(other, temp){ }
100
101  virtual void    gather_cons_defs(Vector<afxConstraintDef>& defs) { };
102
103  DECLARE_CONOBJECT(afxEffectBaseData);
104  DECLARE_CATEGORY("AFX");
105};
106
107//class afxEffectWrapperData : public GameBaseData, public afxEffectDefs
108class afxEffectWrapperData : public afxEffectBaseData
109{
110  //typedef GameBaseData  Parent;
111  typedef afxEffectBaseData  Parent;
112
113  bool                  do_id_convert;
114
115public:
116  enum  { MAX_CONDITION_STATES = 4 };
117
118public:
119  StringTableEntry      effect_name; 
120  bool                  use_as_cons_obj;    
121  bool                  use_ghost_as_cons_obj;    
122
123  StringTableEntry      cons_spec; 
124  StringTableEntry      pos_cons_spec;
125  StringTableEntry      orient_cons_spec;
126  StringTableEntry      aim_cons_spec;
127  StringTableEntry      life_cons_spec;
128  //
129  afxConstraintDef      cons_def;
130  afxConstraintDef      pos_cons_def;
131  afxConstraintDef      orient_cons_def;
132  afxConstraintDef      aim_cons_def;
133  afxConstraintDef      life_cons_def;
134
135  afxEffectTimingData   ewd_timing;
136  U32                   inherit_timing;
137  
138  F32                   scale_factor;       // scale size if applicable
139  F32                   rate_factor;        // scale rate if applicable
140  F32                   user_fade_out_time;
141
142  bool                  is_looping;
143  U32                   n_loops;
144  F32                   loop_gap_time;
145
146  bool                  ignore_time_factor;
147  bool                  propagate_time_factor;
148
149  ByteRange             ranking_range;
150  ByteRange             lod_range;
151  S32                   life_conds;
152  bool                  effect_enabled;
153  U32                   exec_cond_on_bits[MAX_CONDITION_STATES];
154  U32                   exec_cond_off_bits[MAX_CONDITION_STATES];
155  U32                   exec_cond_bitmasks[MAX_CONDITION_STATES];
156
157  S32                   data_ID;
158
159  afxXM_BaseData*       xfm_modifiers[MAX_XFM_MODIFIERS];
160
161  Box3F                 forced_bbox;
162  bool                  update_forced_bbox;
163
164  S8                    sort_priority;
165  Point3F               direction;
166  F32                   speed;
167  F32                   mass;
168
169  bool                  borrow_altitudes;
170  StringTableEntry      vis_keys_spec;
171  afxAnimCurve*         vis_keys;
172
173  SimDataBlock*         effect_data;
174  afxEffectAdapterDesc* effect_desc;
175
176  S32                   group_index;
177
178  void                  parse_cons_specs();
179  void                  parse_vis_keys();
180  void                  gather_cons_defs(Vector<afxConstraintDef>& defs);
181  void                  pack_mods(BitStream*, afxXM_BaseData* mods[], bool packed);
182  void                  unpack_mods(BitStream*, afxXM_BaseData* mods[]);
183
184public:
185  /*C*/             afxEffectWrapperData();
186  /*C*/             afxEffectWrapperData(const afxEffectWrapperData&, bool = false);
187  /*D*/             ~afxEffectWrapperData();
188
189  virtual bool      onAdd();
190  virtual void      packData(BitStream*);
191  virtual void      unpackData(BitStream*);
192
193  bool              preload(bool server, String &errorStr);
194
195  virtual void      onPerformSubstitutions();
196
197  bool              requiresStop(const afxEffectTimingData& timing) { return effect_desc->requiresStop(this, timing); }
198  bool              runsOnServer() { return effect_desc->runsOnServer(this); }
199  bool              runsOnClient() { return effect_desc->runsOnClient(this); }
200  bool              runsHere(bool server_here) { return (server_here) ? runsOnServer() : runsOnClient(); }
201  bool              isPositional() { return effect_desc->isPositional(this); }
202  bool              testExecConditions(U32 conditions);
203
204  F32               afterStopTime() { return ewd_timing.fade_out_time; }
205
206  virtual bool      allowSubstitutions() const { return true; }
207
208  static void       initPersistFields();
209
210  DECLARE_CONOBJECT(afxEffectWrapperData);
211  DECLARE_CATEGORY("AFX");
212};
213
214inline bool afxEffectWrapperData::testExecConditions(U32 conditions)
215{
216  if (exec_cond_bitmasks[0] == 0)
217    return true;
218
219  if ((exec_cond_bitmasks[0] & conditions) == exec_cond_on_bits[0])
220    return true;
221
222  for (S32 i = 1; i < MAX_CONDITION_STATES; i++)
223  {
224    if (exec_cond_bitmasks[i] == 0)
225      return false;
226    if ((exec_cond_bitmasks[i] & conditions) == exec_cond_on_bits[i])
227      return true;
228  }
229  return false;
230}
231
232typedef Vector<afxEffectBaseData*> afxEffectList;
233
234//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
235// afxEffectWrapper 
236//
237//  NOTE -- this not a subclass of GameBase... it is only meant to exist on
238//    the client-side.
239
240class ShapeBase;
241class GameBase;
242class TSShape;
243class TSShapeInstance;
244class SceneObject;
245class afxConstraint;
246class afxConstraintMgr;
247class afxChoreographer;
248class afxXM_Base;
249
250class afxEffectWrapper : public SimObject,  public afxEffectDefs
251{
252  typedef SimObject Parent;
253  friend class afxEffectVector;
254
255private:
256  bool              test_life_conds();
257
258protected:
259  afxEffectWrapperData* mDatablock;
260
261  afxEffectTimingData   mEW_timing;
262
263  F32               mFade_in_end;
264  F32               mFade_out_start;
265  F32               mFull_lifetime;
266
267  F32               mTime_factor;
268  F32               mProp_time_factor;
269
270  afxChoreographer* mChoreographer;
271  afxConstraintMgr* mCons_mgr;
272
273  afxConstraintID   mPos_cons_id;
274  afxConstraintID   mOrient_cons_id;
275  afxConstraintID   mAim_cons_id;
276  afxConstraintID   mLife_cons_id;
277
278  afxConstraintID   mEffect_cons_id;
279
280  F32               mElapsed;
281  F32               mLife_elapsed;
282  F32               mLife_end;
283  bool              mStopped;
284  bool              mCond_alive;
285
286  U32               mNum_updates;
287
288  MatrixF           mUpdated_xfm;
289  Point3F           mUpdated_pos;
290  Point3F           mUpdated_aim;
291  Point3F           mUpdated_scale;
292  LinearColorF      mUpdated_color;
293
294  F32               mFade_value;
295  F32               mLast_fade_value;
296
297  bool              mDo_fade_inout;
298  bool              mDo_fades;
299  bool              mIn_scope;
300  bool              mIs_aborted;
301
302  afxXM_Base*       mXfm_modifiers[MAX_XFM_MODIFIERS];
303
304  F32               mLive_scale_factor;
305  F32               mLive_fade_factor;
306  F32               mTerrain_altitude;
307  F32               mInterior_altitude;
308
309  S32               mGroup_index;
310
311public:
312  /*C*/             afxEffectWrapper();
313  virtual           ~afxEffectWrapper();
314
315  void              ew_init(afxChoreographer*, afxEffectWrapperData*, afxConstraintMgr*, 
316                            F32 time_factor);
317
318  F32               getFullLifetime() { return mEW_timing.lifetime + mEW_timing.fade_out_time; }
319  F32               getTimeFactor() { return mTime_factor; }
320  afxConstraint*    getPosConstraint() { return mCons_mgr->getConstraint(mPos_cons_id); }
321  afxConstraint*    getOrientConstraint() { return mCons_mgr->getConstraint(mOrient_cons_id); }
322  afxConstraint*    getAimConstraint() { return mCons_mgr->getConstraint(mAim_cons_id); }
323  afxConstraint*    getLifeConstraint() { return mCons_mgr->getConstraint(mLife_cons_id); }
324  afxChoreographer* getChoreographer() { return mChoreographer; }
325
326  virtual bool      isDone();
327  virtual bool      deleteWhenStopped() { return false; }
328  F32               afterStopTime() { return mEW_timing.fade_out_time; }
329  bool              isAborted() const { return mIs_aborted; }
330
331  void              prestart();
332  bool              start(F32 timestamp);
333  bool              update(F32 dt);
334  void              stop();
335  void              cleanup(bool was_stopped=false);
336  void              setScopeStatus(bool flag);
337
338  virtual void      ea_set_datablock(SimDataBlock*) { }
339  virtual bool      ea_start() { return true; }
340  virtual bool      ea_update(F32 dt) { return true; }
341  virtual void      ea_finish(bool was_stopped) { }
342  virtual void      ea_set_scope_status(bool flag) { }
343  virtual bool      ea_is_enabled() { return true; }
344  virtual SceneObject* ea_get_scene_object() const { return 0; }
345  U32               ea_get_triggers() const { return 0; }
346
347  void              getUpdatedPosition(Point3F& pos) { pos = mUpdated_pos;}
348  void              getUpdatedTransform(MatrixF& xfm) { xfm = mUpdated_xfm; }
349  void              getUpdatedScale(Point3F& scale) { scale = mUpdated_scale; }
350  void              getUpdatedColor(LinearColorF& color) { color = mUpdated_color; }
351  virtual void      getUpdatedBoxCenter(Point3F& pos) { pos = mUpdated_pos;}
352
353  virtual void      getUnconstrainedPosition(Point3F& pos) { pos.zero();}
354  virtual void      getUnconstrainedTransform(MatrixF& xfm) { xfm.identity(); }
355  virtual void      getBaseColor(LinearColorF& color) { color.set(1.0f, 1.0f, 1.0f, 1.0f); }
356
357  SceneObject*      getSceneObject() const { return ea_get_scene_object(); }
358  U32               getTriggers() const { return ea_get_triggers(); }
359
360  F32               getMass() { return mDatablock->mass; }
361  Point3F           getDirection() { return mDatablock->direction; }
362  F32               getSpeed() { return mDatablock->speed; }
363
364  virtual TSShape*          getTSShape() { return 0; }
365  virtual TSShapeInstance*  getTSShapeInstance() { return 0; }
366
367  virtual U32       setAnimClip(const char* clip, F32 pos, F32 rate, F32 trans) { return 0; }
368  virtual void      resetAnimation(U32 tag) { }
369  virtual F32       getAnimClipDuration(const char* clip) { return 0.0f; }
370
371  void              setTerrainAltitude(F32 alt) { mTerrain_altitude = alt; }
372  void              setInteriorAltitude(F32 alt) { mInterior_altitude = alt; }
373  void              getAltitudes(F32& terr_alt, F32& inter_alt) const { terr_alt = mTerrain_altitude; inter_alt = mInterior_altitude; }
374
375  void              setGroupIndex(S32 idx) { mGroup_index = idx; }
376  S32               getGroupIndex() const { return mGroup_index; }
377
378  bool              inScope() const { return mIn_scope; }
379
380public:
381  static void       initPersistFields();
382
383  static afxEffectWrapper* ew_create(afxChoreographer*, afxEffectWrapperData*, afxConstraintMgr*, F32 time_factor, S32 group_index=0);
384
385  DECLARE_CONOBJECT(afxEffectWrapper);
386  DECLARE_CATEGORY("AFX");
387};
388
389//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
390
391#endif // _AFX_EFFECT_WRAPPER_H_
392