My Project
Variable.h
1 #pragma once
2 
3 namespace ParaEngine
4 {
5  class IAnimated;
6 
11  {
12  // unknown
13  FieldType_unknown,
14  // get(), set()
15  FieldType_void,
16  // get(int*) set(int)
17  FieldType_Int,
18  // get(bool*) set(bool)
19  FieldType_Bool,
20  // get(float*) set(float)
21  FieldType_Float,
22  // get(float*,float* ) set(float, float)
23  FieldType_Float_Float,
24  // get(float*,float*,float*) set(float, float, float)
25  FieldType_Float_Float_Float,
26  // get(int*) set(int)
27  FieldType_Enum,
28  // get(double*) set(double)
29  FieldType_Double,
30  // get(Vector2*) set(Vector2)
31  FieldType_Vector2,
32  // get(Vector3*) set(Vector3)
33  FieldType_Vector3,
34  // get(Vector4*) set(Vector4)
35  FieldType_Vector4,
36  // get(Quaternion*) set(Quaternion)
37  FieldType_Quaternion,
38  // get(const char**) set(const char*)
39  FieldType_String,
40  // get(DWORD*) set(DWORD)
41  FieldType_DWORD,
42  // get(DVector3*) set(DVector3), double precision vector3
43  FieldType_DVector3,
44  // get(float*,float*,float*,float*) set(float, float, float, float)
45  FieldType_Float_Float_Float_Float,
46  // get(Matrix4*) set(const Matrix4&)
47  FieldType_Matrix4,
48  // get(double*,double* ) set(double, double)
49  FieldType_Double_Double,
50  // get(double*,double*,double*) set(double, double, double)
51  FieldType_Double_Double_Double,
53  // following types are all animated
55  FieldType_Animated,
56  FieldType_AnimatedInt,
57  FieldType_AnimatedFloat,
58  FieldType_AnimatedDouble,
59  FieldType_AnimatedVector2,
60  FieldType_AnimatedVector3,
61  FieldType_AnimatedDVector3,
62  FieldType_AnimatedVector4,
63  FieldType_AnimatedQuaternion,
64 
65  // this is for custom void pointer
66  FieldType_void_pointer,
67  FieldType_Deprecated = 0xffffffff
68  };
69 
70 
71 
75  class CVariable
76  {
77  public:
78  CVariable(DWORD dwType = FieldType_unknown);
79  ~CVariable();
80 
82  void Clone(const CVariable& value);
83 
87  static const char* GetTypeAsString(DWORD dwType);
88  const char* GetTypeName() const;
89  inline ATTRIBUTE_FIELDTYPE GetType() const { return (ATTRIBUTE_FIELDTYPE)m_type; }
90 
91  bool IsNil() const;
92  bool IsStringType() const;
94  bool IsAnimated();
95 
97  void ChangeType(ATTRIBUTE_FIELDTYPE newType);
98 
103  void ToNPLString(std::string& output);
104 
105  void operator = (const CVariable& val);
106 
107  operator double();
108  void operator = (double value);
109 
110  operator float();
111  void operator = (float value);
112 
113  operator int();
114  operator DWORD();
115  void operator = (int value);
116 
117  operator Vector3();
118  void operator = (const Vector3& value);
119 
120  operator Quaternion();
121  void operator = (const Quaternion& value);
122 
123  operator bool();
124  void operator = (bool value);
125 
126  operator const string& ();
127  operator const char* ();
128  bool operator == (const string& value);
129  bool operator == (const char* value);
130  void operator = (const std::string& value);
131  void operator = (const char* value);
132 
133 
135  int GetNumKeys();
137  void SetNumKeys(int nKeyCount);
138 
143  int AddKey(int nTime, bool* isKeyExist = NULL);
144 
149  void SetTime(int nIndex, int nTime);
150  int GetTime(int nIndex);
151 
152  void SetValue(int nIndex, const Quaternion& val);
153  bool GetValue(int nIndex, Quaternion& val);
155  bool GetValueByTime(int nTime, Quaternion& val);
156 
157  void SetValue(int nIndex, const Vector3& val);
158  bool GetValue(int nIndex, Vector3& val);
159  bool GetValueByTime(int nTime, Vector3& val);
160 
161  void SetValue(int nIndex, double val);
162  bool GetValue(int nIndex, double& val);
163  bool GetValueByTime(int nTime, double& val);
164 
165  void SetValue(int nIndex, float val);
166  bool GetValue(int nIndex, float& val);
167  bool GetValueByTime(int nTime, float& val);
168 
169  void SetValue(int nIndex, const std::string& val);
170  bool GetValue(int nIndex, std::string& val);
171  protected:
172 
176  int GetNextKeyIndex(int nTime);
177 
178  protected:
179  DWORD m_type;
180  union{
181  double m_doubleVal;
182  float m_floatVal;
183  int m_intVal;
184  bool m_boolVal;
185  float m_vector3[3];
186  float m_vector4[4];
187  };
188  IAnimated* m_pAnimated;
189  std::string m_strVal;
190  };
191 
192 
193 }
int GetNextKeyIndex(int nTime)
return the index of the first key whose time is larger than or equal to time.
Definition: Variable.cpp:507
int AddKey(int nTime, bool *isKeyExist=NULL)
add a given key with default value at specified time if there is already a key at the index...
Definition: Variable.cpp:407
static const char * GetTypeAsString(DWORD dwType)
Get Type as string.
Definition: Variable.cpp:94
bool GetValueByTime(int nTime, Quaternion &val)
get interpolated value at the given time.
Definition: Variable.cpp:444
different physics engine has different winding order.
Definition: EventBinding.h:32
represent any kind of static or animated variable, such as: string, double, float, int, bool, Vector3, Quaternion, or animated data with multiple time, value keys.
Definition: Variable.h:75
Implementation of a Quaternion, i.e.
Definition: ParaQuaternion.h:10
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
base class for AnimatedVariable.
Definition: IAnimated.h:18
Definition: enum_maker.hpp:46
void Clone(const CVariable &value)
clone from given variable
Definition: Variable.cpp:32
void ChangeType(ATTRIBUTE_FIELDTYPE newType)
change type to given type
Definition: Variable.cpp:59
int GetNumKeys()
get total number of animated keys.
Definition: Variable.cpp:396
bool IsAnimated()
whether the key is animated or not
Definition: Variable.cpp:54
void SetNumKeys(int nKeyCount)
get set the total number of animated keys.
Definition: Variable.cpp:401
ATTRIBUTE_FIELDTYPE
a list of all attribute type this is also used for all variable type supported.
Definition: Variable.h:10
void SetTime(int nIndex, int nTime)
only applied to Animated attribute
Definition: Variable.cpp:412
void ToNPLString(std::string &output)
In case of nil, it is "nil", in case of string, it is in quotation mark.
Definition: Variable.cpp:351