afxEffectron.h

Engine/source/afx/afxEffectron.h

More...

Classes:

Detailed Description

  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_COMPOSITE_EFFECT_H_
 28#define _AFX_COMPOSITE_EFFECT_H_
 29
 30//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 31
 32#include "console/typeValidators.h"
 33
 34#include "afxChoreographer.h"
 35#include "afxEffectWrapper.h"
 36#include "afxPhrase.h"
 37
 38class afxChoreographerData;
 39class afxEffectWrapperData;
 40
 41class afxEffectronData : public afxChoreographerData
 42{
 43  typedef afxChoreographerData Parent;
 44
 45  class ewValidator : public TypeValidator
 46  {
 47    U32 id;
 48  public:
 49    ewValidator(U32 id) { this->id = id; }
 50    void validateType(SimObject *object, void *typePtr);
 51  };
 52
 53  bool          do_id_convert;
 54
 55public:
 56  F32           duration;
 57  S32           n_loops;
 58
 59  afxEffectBaseData* dummy_fx_entry;
 60
 61  afxEffectList fx_list;
 62  
 63private:
 64  void          pack_fx(BitStream* stream, const afxEffectList& fx, bool packed);
 65  void          unpack_fx(BitStream* stream, afxEffectList& fx);
 66
 67public:
 68  /*C*/         afxEffectronData();
 69  /*C*/         afxEffectronData(const afxEffectronData&, bool = false);
 70
 71  virtual void  reloadReset();
 72
 73  virtual bool  onAdd();
 74  virtual void  packData(BitStream*);
 75  virtual void  unpackData(BitStream*);
 76
 77  bool          preload(bool server, String &errorStr);
 78
 79  void          gatherConstraintDefs(Vector<afxConstraintDef>&); 
 80
 81  virtual bool  allowSubstitutions() const { return true; }
 82
 83  static void   initPersistFields();
 84
 85  DECLARE_CONOBJECT(afxEffectronData);
 86  DECLARE_CATEGORY("AFX");
 87};
 88
 89//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 90// afxEffectron
 91
 92class afxEffectron : public afxChoreographer
 93{
 94  typedef afxChoreographer Parent;
 95
 96public:
 97  enum MaskBits 
 98  {
 99    StateEventMask    = Parent::NextFreeMask << 0,
100    SyncEventMask     = Parent::NextFreeMask << 1,
101    NextFreeMask      = Parent::NextFreeMask << 2
102  };
103
104  enum
105  {
106    NULL_EVENT,
107    ACTIVATE_EVENT,
108    SHUTDOWN_EVENT,
109    DEACTIVATE_EVENT,
110    INTERRUPT_EVENT
111  };
112
113  enum
114  {
115    INACTIVE_STATE,
116    ACTIVE_STATE,
117    CLEANUP_STATE,
118    DONE_STATE,
119    LATE_STATE
120  };
121
122  enum {
123    MARK_ACTIVATE   = BIT(0),
124    MARK_SHUTDOWN   = BIT(1),
125    MARK_DEACTIVATE = BIT(2),
126    MARK_INTERRUPT  = BIT(3),
127  };
128
129  class ObjectDeleteEvent : public SimEvent
130  {
131  public:
132    void process(SimObject *obj) { if (obj) obj->deleteObject(); }
133  };
134
135private:
136  static StringTableEntry  CAMERA_CONS;
137  static StringTableEntry  LISTENER_CONS;
138
139private:
140  afxEffectronData*  datablock;
141  SimObject*         exeblock;
142
143  bool          constraints_initialized;
144  bool          scoping_initialized;
145
146  U8            effect_state;
147  F32           effect_elapsed;
148  U8            marks_mask;
149  afxConstraintID listener_cons_id;
150  afxConstraintID camera_cons_id;
151  SceneObject*  camera_cons_obj;
152  afxPhrase*    active_phrase;
153  F32           time_factor;
154
155private:
156  void          init();
157  bool          state_expired();
158  void          init_constraints();
159  void          init_scoping();
160  void          setup_active_fx();
161  bool          cleanup_over();
162
163public:
164  /*C*/         afxEffectron();
165  /*C*/         afxEffectron(bool not_default);
166  /*D*/         ~afxEffectron();
167
168    // STANDARD OVERLOADED METHODS //
169  virtual bool  onNewDataBlock(GameBaseData* dptr, bool reload);
170  virtual void  processTick(const Move*);
171  virtual void  advanceTime(F32 dt);
172  virtual bool  onAdd();
173  virtual U32   packUpdate(NetConnection*, U32, BitStream*);
174  virtual void  unpackUpdate(NetConnection*, BitStream*);
175
176  virtual void  inflictDamage(const char * label, const char* flavor, SimObjectId target,
177                              F32 amt, U8 count, F32 ad_amt, F32 rad, Point3F pos, F32 imp);
178  virtual void  sync_with_clients();
179  void          finish_startup();
180
181  DECLARE_CONOBJECT(afxEffectron);
182  DECLARE_CATEGORY("AFX");
183
184private:
185  void          process_server();
186  //
187  void          change_state_s(U8 pending_state);
188  //
189  void          enter_active_state_s();
190  void          leave_active_state_s();
191  void          enter_cleanup_state_s();
192  void          enter_done_state_s();
193
194private:
195  void          process_client(F32 dt);
196  //
197  void          change_state_c(U8 pending_state);
198  //
199  void          enter_active_state_c(F32 starttime);
200  void          leave_active_state_c();
201
202  void          sync_client(U16 marks, U8 state, F32 elapsed);
203
204public:
205  void          postEvent(U8 event);
206  void          setTimeFactor(F32 f) { time_factor = (f > 0) ? f : 1.0f; }
207  F32           getTimeFactor() { return time_factor; }
208
209  bool          activationCallInit(bool postponed=false);
210  void          activate();
211
212public:
213  static afxEffectron*  start_effect(afxEffectronData*, SimObject* extra);
214};
215
216//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
217#endif // _AFX_EFFECTRON_H_
218