afxForce.cpp

Engine/source/afx/forces/afxForce.cpp

More...

Public Defines

define
myOffset(field) (field, )

Detailed Description

Public Defines

myOffset(field) (field, )
  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 "afx/arcaneFX.h"
 28
 29#include "console/consoleTypes.h"
 30#include "core/stream/bitStream.h"
 31#include "scene/sceneRenderState.h"
 32#include "math/mathIO.h"
 33
 34#include "afx/afxChoreographer.h"
 35#include "afx/forces/afxForce.h"
 36
 37//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 38// afxForceData
 39
 40afxForceData::afxForceData()
 41{
 42  force_set_name = ST_NULLSTRING;
 43  force_desc = 0;
 44}
 45
 46afxForceData::afxForceData(const afxForceData& other, bool temp_clone) : GameBaseData(other, temp_clone)
 47{
 48  force_set_name = other.force_set_name;
 49  force_desc = other.force_desc;
 50}
 51
 52#define myOffset(field) Offset(field, afxForceData)
 53
 54void afxForceData::initPersistFields()
 55{
 56  addField("forceSetName",    TypeString,   myOffset(force_set_name),
 57    "...");
 58
 59  Parent::initPersistFields();
 60}
 61
 62bool afxForceData::onAdd()
 63{
 64  if (Parent::onAdd() == false)
 65    return false;
 66
 67  return true;
 68}
 69
 70void afxForceData::packData(BitStream* stream)
 71{
 72   Parent::packData(stream);
 73  stream->writeString(force_set_name);
 74}
 75
 76void afxForceData::unpackData(BitStream* stream)
 77{
 78  Parent::unpackData(stream);
 79  force_set_name = stream->readSTString();
 80}
 81
 82//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 83//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 84// afxForce
 85
 86afxForce::afxForce()
 87{
 88  datablock = 0;
 89  fade_amt = 1.0f;
 90}
 91
 92afxForce::~afxForce()
 93{
 94}
 95
 96bool afxForce::onNewDataBlock(afxForceData* dptr, bool reload)
 97{
 98  datablock = dptr;
 99  return true;
100}
101
102//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
103
104Vector<afxForceDesc*>* afxForceDesc::forces = 0;
105
106afxForceDesc::afxForceDesc() 
107{ 
108  if (!forces)
109    forces = new Vector<afxForceDesc*>;
110
111  forces->push_back(this);
112}
113
114bool afxForceDesc::identifyForce(afxForceData* force_data)
115{
116  if (!force_data)
117  {
118    Con::errorf("afxForceDesc::identifyForce() -- force datablock was not specified.");
119    return false;
120  }
121
122  if (!forces)
123  {
124    Con::errorf("afxForceDesc::identifyForce() -- force registration list has not been allocated.");
125    return false;
126  }
127
128  if (forces->size() == 0)
129  {
130    Con::errorf("afxForceDesc::identifyForce() -- no forces have been registered.");
131    return false;
132  }
133
134  for (S32 i = 0; i < forces->size(); i++)
135  {
136    if ((*forces)[i]->testForceType(force_data))
137    {
138      force_data->force_desc = (*forces)[i];
139      return true;
140    }
141  }
142
143  Con::errorf("afxForceDesc::identifyForce() -- force %s has an undefined type. -- %d", 
144    force_data, forces->size());
145  return false;
146}
147
148
149//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
150