Torque3D Documentation / _generateds / afxEA_ScriptEvent.cpp

afxEA_ScriptEvent.cpp

Engine/source/afx/ea/afxEA_ScriptEvent.cpp

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#include <typeinfo>
 28#include "afx/arcaneFX.h"
 29#include "afx/afxEffectDefs.h"
 30#include "afx/afxEffectWrapper.h"
 31#include "afx/afxChoreographer.h"
 32#include "afx/ce/afxScriptEvent.h"
 33
 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 35// afxEA_ScriptEvent 
 36
 37class afxEA_ScriptEvent : public afxEffectWrapper
 38{
 39  typedef afxEffectWrapper Parent;
 40
 41  afxScriptEventData* script_data;
 42  bool              ran_script;
 43
 44  void              do_runtime_substitutions();
 45
 46public:
 47  /*C*/             afxEA_ScriptEvent();
 48  /*D*/             ~afxEA_ScriptEvent();
 49
 50  virtual bool      isDone() { return ran_script; }
 51
 52  virtual void      ea_set_datablock(SimDataBlock*);
 53  virtual bool      ea_start();
 54  virtual bool      ea_update(F32 dt);
 55  virtual void      ea_finish(bool was_stopped);
 56};
 57
 58//~~~~~~~~~~~~~~~~~~~~//
 59
 60afxEA_ScriptEvent::afxEA_ScriptEvent()
 61{
 62  script_data = 0;
 63  ran_script = false;
 64}
 65
 66afxEA_ScriptEvent::~afxEA_ScriptEvent()
 67{
 68  if (script_data && script_data->isTempClone())
 69    delete script_data;
 70  script_data = 0;
 71}
 72
 73void afxEA_ScriptEvent::ea_set_datablock(SimDataBlock* db)
 74{
 75  script_data = dynamic_cast<afxScriptEventData*>(db);
 76}
 77
 78bool afxEA_ScriptEvent::ea_start()
 79{
 80  if (!script_data)
 81  {
 82    Con::errorf("afxEA_ScriptEvent::ea_start() -- missing or incompatible datablock.");
 83    return false;
 84  }
 85
 86  do_runtime_substitutions();
 87
 88  ran_script = (script_data->method_name == ST_NULLSTRING);
 89
 90  return true;
 91}
 92
 93bool afxEA_ScriptEvent::ea_update(F32 dt)
 94{
 95  if (!ran_script && mChoreographer != NULL)
 96  {
 97    afxConstraint* pos_constraint = getPosConstraint();
 98   mChoreographer->executeScriptEvent(script_data->method_name, pos_constraint, mUpdated_xfm,
 99                                      script_data->script_data);
100    ran_script = true;
101  }
102
103  return true;
104}
105
106void afxEA_ScriptEvent::ea_finish(bool was_stopped)
107{
108  ran_script = false;
109}
110
111void afxEA_ScriptEvent::do_runtime_substitutions()
112{
113  // only clone the datablock if there are substitutions
114  if (script_data->getSubstitutionCount() > 0)
115  {
116    // clone the datablock and perform substitutions
117    afxScriptEventData* orig_db = script_data;
118    script_data = new afxScriptEventData(*orig_db, true);
119    orig_db->performSubstitutions(script_data, mChoreographer, mGroup_index);
120  }
121}
122
123//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
124
125class afxEA_ScriptEventDesc : public afxEffectAdapterDesc, public afxEffectDefs 
126{
127  static afxEA_ScriptEventDesc desc;
128
129public:
130  virtual bool  testEffectType(const SimDataBlock*) const;
131  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const { return false; }
132  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return true; }
133  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return false; }
134  virtual bool  isPositional(const afxEffectWrapperData*) const { return false; }
135
136  virtual afxEffectWrapper* create() const { return new afxEA_ScriptEvent; }
137};
138
139afxEA_ScriptEventDesc afxEA_ScriptEventDesc::desc;
140
141bool afxEA_ScriptEventDesc::testEffectType(const SimDataBlock* db) const
142{
143  return (typeid(afxScriptEventData) == typeid(*db));
144}
145
146//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
147