afxSelectron.h

Engine/source/afx/afxSelectron.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_SELECTION_EFFECT_H_
 28#define _AFX_SELECTION_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 afxEffectBaseData;
 40
 41class  afxSelectronDefs
 42{
 43public:
 44  enum {
 45    MAIN_PHRASE,
 46    SELECT_PHRASE,
 47    DESELECT_PHRASE,
 48    NUM_PHRASES
 49  };
 50};
 51
 52class afxSelectronData : public afxChoreographerData, public afxSelectronDefs
 53{
 54  typedef afxChoreographerData Parent;
 55
 56  class ewValidator : public TypeValidator
 57  {
 58    U32 id;
 59  public:
 60    ewValidator(U32 id) { this->id = id; }
 61    void validateType(SimObject *object, void *typePtr);
 62  };
 63
 64  bool          do_id_convert;
 65
 66public:
 67  F32           main_dur;
 68  F32           select_dur;
 69  F32           deselect_dur;
 70
 71  S32           n_main_loops;
 72  S32           n_select_loops;
 73  S32           n_deselect_loops;
 74
 75  bool          registered;
 76  U8            obj_type_style;
 77  U32           obj_type_mask;
 78
 79  afxEffectBaseData* dummy_fx_entry;
 80
 81  afxEffectList main_fx_list;
 82  afxEffectList select_fx_list;
 83  afxEffectList deselect_fx_list;
 84  
 85private:
 86  void          pack_fx(BitStream* stream, const afxEffectList& fx, bool packed);
 87  void          unpack_fx(BitStream* stream, afxEffectList& fx);
 88
 89public:
 90  /*C*/         afxSelectronData();
 91  /*C*/         afxSelectronData(const afxSelectronData&, bool = false);
 92  /*D*/         ~afxSelectronData();
 93
 94  virtual void  reloadReset();
 95
 96  virtual bool  onAdd();
 97  virtual void  packData(BitStream*);
 98  virtual void  unpackData(BitStream*);
 99
100  bool          preload(bool server, String &errorStr);
101
102  bool          matches(U32 mask, U8 style);
103  void          gatherConstraintDefs(Vector<afxConstraintDef>&); 
104
105  virtual bool  allowSubstitutions() const { return true; }
106
107  static void   initPersistFields();
108
109  DECLARE_CONOBJECT(afxSelectronData);
110  DECLARE_CATEGORY("AFX");
111};
112
113inline bool afxSelectronData::matches(U32 mask, U8 style)
114{
115  if (obj_type_style != style)
116    return false;
117
118  if (obj_type_mask == 0 && mask == 0)
119    return true;
120
121  return ((obj_type_mask & mask) != 0);
122}
123
124//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
125// afxSelectron
126
127class afxSelectron : public afxChoreographer, public afxSelectronDefs
128{
129  typedef afxChoreographer Parent;
130  friend class arcaneFX;
131
132public:
133  enum MaskBits 
134  {
135    StateEventMask    = Parent::NextFreeMask << 0,
136    SyncEventMask     = Parent::NextFreeMask << 1,
137    NextFreeMask      = Parent::NextFreeMask << 2
138  };
139
140  enum
141  {
142    NULL_EVENT,
143    ACTIVATE_EVENT,
144    SHUTDOWN_EVENT,
145    DEACTIVATE_EVENT,
146    INTERRUPT_EVENT
147  };
148
149  enum
150  {
151    INACTIVE_STATE,
152    ACTIVE_STATE,
153    CLEANUP_STATE,
154    DONE_STATE,
155    LATE_STATE
156  };
157
158  enum {
159    MARK_ACTIVATE   = BIT(0),
160    MARK_SHUTDOWN   = BIT(1),
161    MARK_DEACTIVATE = BIT(2),
162    MARK_INTERRUPT  = BIT(3),
163  };
164
165  class ObjectDeleteEvent : public SimEvent
166  {
167  public:
168    void process(SimObject *obj) { if (obj) obj->deleteObject(); }
169  };
170
171private:
172  static StringTableEntry  CAMERA_CONS;
173  static StringTableEntry  LISTENER_CONS;
174  static StringTableEntry  FREE_TARGET_CONS;
175
176private:
177  afxSelectronData*  datablock;
178  SimObject*         exeblock;
179
180  bool          constraints_initialized;
181  bool          client_only;
182
183  U8            effect_state;
184  F32           effect_elapsed;
185
186  afxConstraintID listener_cons_id;
187  afxConstraintID free_target_cons_id;
188  afxConstraintID camera_cons_id;
189  SceneObject*  camera_cons_obj;
190
191  afxPhrase*    phrases[NUM_PHRASES];
192
193  F32           time_factor;
194  U8            marks_mask;
195
196private:
197  void          init();
198  bool          state_expired();
199  void          init_constraints();
200  void          setup_main_fx();
201  void          setup_select_fx();
202  void          setup_deselect_fx();
203  bool          cleanup_over();
204
205public:
206  /*C*/         afxSelectron();
207  /*C*/         afxSelectron(bool not_default);
208  /*D*/         ~afxSelectron();
209
210    // STANDARD OVERLOADED METHODS //
211  virtual bool  onNewDataBlock(GameBaseData* dptr, bool reload);
212  virtual void  processTick(const Move*);
213  virtual void  advanceTime(F32 dt);
214  virtual bool  onAdd();
215  virtual void  onRemove();
216  virtual U32   packUpdate(NetConnection*, U32, BitStream*);
217  virtual void  unpackUpdate(NetConnection*, BitStream*);
218
219  virtual void  sync_with_clients();
220  void          finish_startup();
221
222  DECLARE_CONOBJECT(afxSelectron);
223  DECLARE_CATEGORY("AFX");
224
225private:
226  void          process_server();
227  //
228  void          change_state_s(U8 pending_state);
229  //
230  void          enter_active_state_s();
231  void          leave_active_state_s();
232  void          enter_cleanup_state_s();
233  void          enter_done_state_s();
234
235private:
236  void          process_client(F32 dt);
237  //
238  void          change_state_c(U8 pending_state);
239  //
240  void          enter_active_state_c(F32 starttime);
241  void          enter_cleanup_state_c();
242  void          enter_done_state_c();
243  void          leave_active_state_c();
244
245  void          sync_client(U16 marks, U8 state, F32 elapsed);
246
247public:
248  void          postEvent(U8 event);
249  void          setTimeFactor(F32 f) { time_factor = (f > 0) ? f : 1.0f; }
250  F32           getTimeFactor() { return time_factor; }
251
252  void          activate();
253
254public:
255  static afxSelectron*  start_selectron(SceneObject* picked, U8 subcode, SimObject* extra);
256};
257
258//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
259#endif // _AFX_SELECTION_EFFECT_H_
260