Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

571 lines
30 KiB

  1. #ifndef IHFXPARAM_H_
  2. #define IHFXPARAM_H_
  3. #include ".\\HFXConfig.h"
  4. class IHapticEffect;
  5. typedef IHapticEffect IHFXEffect;
  6. #ifdef HFX_64BIT
  7. #define HFX_NULL_HANDLE ((IHFXEffect*)(unsigned long)0x000000000000001)
  8. #else
  9. #define HFX_NULL_HANDLE ((IHFXEffect*)(unsigned long)0x00000001)
  10. #endif
  11. static IHFXEffect *hfxNoHandle=HFX_NULL_HANDLE;
  12. typedef unsigned __int32 HFXParamID;
  13. typedef unsigned __int32 HFXEffectID;
  14. // if a invalid char is added it will show up as '`'
  15. // if a '?' it will be the same as a '_'
  16. // any upper case chars will be converted to lowercase.
  17. #define HFX_PARAM_ENCODE_CHAR_LOWER(lowercase_alpha_or_underscore) \
  18. (lowercase_alpha_or_underscore ? ( ( lowercase_alpha_or_underscore < ('~'+1) ) ? \
  19. ( (lowercase_alpha_or_underscore)-('^') ) : 2 ) : 0)
  20. #define HFX_PARAM_ENCODE_CHAR_UPPER(upper_alpha) \
  21. (upper_alpha!=0 ? ( (upper_alpha>'>') ? \
  22. ((upper_alpha)-('>')) : ( ((upper_alpha>'/')&&(upper_alpha<':')) ? \
  23. ((upper_alpha + 32)-('>')) : (2) ) \
  24. ) : 0)
  25. #define HFX_PARAM_ENCODE_CHAR(alpha_or_underscore) \
  26. (alpha_or_underscore ?(alpha_or_underscore < '_') ? \
  27. HFX_PARAM_ENCODE_CHAR_UPPER(alpha_or_underscore) : \
  28. HFX_PARAM_ENCODE_CHAR_LOWER(alpha_or_underscore):0 )
  29. #define HFX_PARAM_PACK_CHAR(char, index) \
  30. ( char ? ((char) << (index * 5)) : 0 )
  31. #define HFX_PARAM_ENCODE_STRING_CHAR(char) ( (char < '_') ? (HFX_PARAM_ENCODE_CHAR_UPPER(char)) : (HFX_PARAM_ENCODE_CHAR_LOWER(char)) )
  32. #define HFX_PARAM_ENCODE_AND_PACK_CHAR(char, index) \
  33. HFX_PARAM_PACK_CHAR(HFX_PARAM_ENCODE_CHAR(char), index)
  34. #define TC unsigned int
  35. #define HFX_PARAM_ENCODE_STRING(ConstCharPtr7) \
  36. ( ConstCharPtr7 ? \
  37. (ConstCharPtr7[0]!=0 ? \
  38. ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[0])) << 0) | \
  39. (ConstCharPtr7[1]!=0 ? \
  40. ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[1])) << 5) | \
  41. (ConstCharPtr7[2]!=0 ? \
  42. ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[2])) << 10) | \
  43. (ConstCharPtr7[3]!=0 ? \
  44. ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[3])) << 15) | \
  45. (ConstCharPtr7[4]!=0 ? \
  46. ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[4])) << 20) | \
  47. (ConstCharPtr7[5]!=0 ? \
  48. ((HFX_PARAM_ENCODE_STRING_CHAR((ConstCharPtr7)[5])) << 25) \
  49. : (unsigned)0) \
  50. : (unsigned)0) \
  51. : (unsigned)0) \
  52. : (unsigned)0) \
  53. : (unsigned)0) \
  54. : (unsigned)0) \
  55. : (unsigned)0)
  56. #define HFX_PARAM_ENCODE_6(c1,c2,c3,c4,c5,c6) \
  57. ((HFXParamID)\
  58. ( HFX_PARAM_ENCODE_AND_PACK_CHAR(c1,0) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c2,1) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c3,2) \
  59. | HFX_PARAM_ENCODE_AND_PACK_CHAR(c4,3) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c5,4) | HFX_PARAM_ENCODE_AND_PACK_CHAR(c6,5) ))
  60. #define HFX_PARAM_ENCODE_5(c1,c2,c3,c4,c5) \
  61. HFX_PARAM_ENCODE_6(c1,c2,c3,c4,c5,0)
  62. #define HFX_PARAM_ENCODE_4(c1,c2,c3,c4) \
  63. HFX_PARAM_ENCODE_6(c1,c2,c3,c4,0,0)
  64. #define HFX_PARAM_ENCODE_3(c1,c2,c3) \
  65. HFX_PARAM_ENCODE_6(c1,c2,c3,0,0,0)
  66. #define HFX_PARAM_ENCODE_2(c1,c2) \
  67. HFX_PARAM_ENCODE_6(c1,c2,0,0,0,0)
  68. #define HFX_PARAM_ENCODE_1(c1) \
  69. HFX_PARAM_ENCODE_6(c1,0,0,0,0,0)
  70. #define HFX_PARAM_DECODE_TO(char7, hfxparamid) \
  71. (char7)[0] = HFX_CHAR_ID(hfxparamid, 0); \
  72. (char7)[1] = (char7)[0] ? HFX_CHAR_ID(hfxparamid, 1) : 0; \
  73. (char7)[2] = (char7)[1] ? HFX_CHAR_ID(hfxparamid, 2) : 0; \
  74. (char7)[3] = (char7)[2] ? HFX_CHAR_ID(hfxparamid, 3) : 0; \
  75. (char7)[4] = (char7)[3] ? HFX_CHAR_ID(hfxparamid, 4) : 0; \
  76. (char7)[5] = (char7)[4] ? HFX_CHAR_ID(hfxparamid, 5) : 0; \
  77. (char7)[6] = 0
  78. HFX_INLINE HFXParamID HFX_PARAM_ENCODE_VA(char c1, char c2=0, char c3=0, char c4=0, char c5=0, char c6=0)
  79. {
  80. return HFX_PARAM_ENCODE_6(c1,c2,c3,c4,c5,c6);
  81. }
  82. #if HFX_MSVC > 7
  83. //max of 6!
  84. #define HFX_PARAM_ENCODE(...) HFX_PARAM_ENCODE_VA(__VA_ARGS__)
  85. #else
  86. #define HFX_PARAM_ENCODE HFX_PARAM_ENCODE_VA
  87. #endif
  88. #define HFX_PARAM_ENCODE_4(c1,c2,c3,c4) HFX_PARAM_ENCODE_6(c1,c2,c3,c4,0,0)
  89. #define HFX_5BIT_MASK ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4))
  90. #define HFX_MASK_ID(paramid, index)((paramid>>(index*5)) & (HFX_5BIT_MASK))
  91. #define HFX_CHAR_ID(paramid, index) \
  92. (HFX_MASK_ID(paramid,index)?HFX_MASK_ID(paramid,index)+'^':0)
  93. // usage : char hfxParamText[] = HFX_PARAMETER_DECODE(hfxParamID);
  94. #define HFX_PARAM_DECODE(hfxparam) { \
  95. HFX_CHAR_ID(hfxparam,0), \
  96. HFX_CHAR_ID(hfxparam,1), \
  97. HFX_CHAR_ID(hfxparam,2), \
  98. HFX_CHAR_ID(hfxparam,3), \
  99. HFX_CHAR_ID(hfxparam,4), \
  100. HFX_CHAR_ID(hfxparam,5),0}
  101. enum HFXParamType
  102. {
  103. HFXPARAM_NULL = 0,
  104. HFXPARAM_INT = 'i',
  105. HFXPARAM_FLOAT = 'f',
  106. HFXPARAM_DOUBLE = 'd',
  107. HFXPARAM_BOOL = 'b',
  108. HFXPARAM_INT_ARRAY = 'I',
  109. HFXPARAM_FLOAT_ARRAY = 'F',
  110. HFXPARAM_DOUBLE_ARRAY = 'D',
  111. HFXPARAM_BOOL_ARRAY = 'B',
  112. };
  113. typedef unsigned char HFXPARAM;
  114. enum HFXArray
  115. {
  116. HFXARRAY_NOTARRAY=0,
  117. HFXARRAY_COPY=1,//
  118. HFXARRAY_INDEX=2,
  119. };
  120. typedef unsigned char HFXARRAY;
  121. typedef void *HFXVarValue;
  122. struct HFX_PURE_INTERFACE IHapticEffectParamGroup
  123. {
  124. #ifndef HFX_NO_PARAMETER_CLASS_MACROS
  125. // declare this inside user implementated parametergroup class definitions.
  126. #define HFX_PARAMETER_GROUP(classname, baseclass, defaultEffect) \
  127. typedef classname ParameterGroup; \
  128. typedef baseclass SuperGroup; \
  129. typedef defaultEffect EffectClass; \
  130. using SuperGroup::SetVar; \
  131. using SuperGroup::GetVar; \
  132. using SuperGroup::SetVarFloat; \
  133. using SuperGroup::SetVarInt; \
  134. using SuperGroup::SetVarDouble; \
  135. using SuperGroup::GetVarBool; \
  136. using SuperGroup::GetVarFloat; \
  137. using SuperGroup::GetVarInt; \
  138. using SuperGroup::GetVarDouble;
  139. #define HFX_PARAMETER_ID(name, type) \
  140. static const HFXParamID ID_##name; \
  141. static const char * const ID_##name##_String;
  142. // declare this inside user implementated parametergroup class definitions
  143. // for each variable you want to be accessible through
  144. // parameter filetypes or set/get functions. These macros will make the variable
  145. // you specify.
  146. // specify a seperate membername for readability.
  147. // REMEMBER: name should be no longer than 6 letters, membername can be as long as you want.
  148. #define HFX_PARAMETER_FLOAT(name, membername) \
  149. HFX_PARAMETER_ID(float_##name); \
  150. union{float name; float m_fl##name; float membername;}; \
  151. static const float ID_float_##name##_Default;
  152. #define HFX_PARAMETER_DOUBLE(name, membername) \
  153. HFX_PARAMETER_ID(double_##name); \
  154. union{double name; double m_dbl##name; double membername;}; \
  155. static const bool ID_double_##name##_Default
  156. #define HFX_PARAMETER_BOOL(name, membername) \
  157. HFX_PARAMETER_ID(bool_##name); \
  158. union{bool name:1; bool m_b##name:1; bool membername:1;}; \
  159. static const bool ID_bool_##name##_Default;
  160. #define HFX_PARAMETER_INT(name, membername) \
  161. HFX_PARAMETER_ID(int_##name); \
  162. union{int name; int m_i##name; int membername;}; \
  163. static const int ID_int_##name##_Default;
  164. #define HFX_PARAMETER_FLOAT_ARRAY(size, name, membername) \
  165. HFX_PARAMETER_ID(float##size##_##name); \
  166. union{float name; float m_fl##size##name; float membername;}; \
  167. static const float ID_float##size##_##name##_Default[size];
  168. #define HFX_PARAMETER_DOUBLE_ARRAY(size, name, membername) \
  169. HFX_PARAMETER_ID(double##size##_##name); \
  170. union{double name[size]; double m_dbl##size##name[size]; double membername[size];}; \
  171. static const bool ID_double##size##_##name##_Default[size];
  172. #define HFX_PARAMETER_BOOL_ARRAY(size, name, membername) \
  173. HFX_PARAMETER_ID(bool##size##_##name); \
  174. union{bool name[size]; bool m_b##size##name[size]; bool membername[size];}; \
  175. static const bool ID_bool##size##_##name##_Default[size];
  176. #define HFX_PARAMETER_INT_ARRAY(size, name, membername) \
  177. HFX_PARAMETER_ID(int##size##_##name); \
  178. union{int name[size]; int m_i##name[size]; int membername[size];}; \
  179. static const int ID_int##size##_##name##_Default;
  180. #endif
  181. //virtual bool RunSetCommand( char *cmd ) = 0;
  182. //virtual HFXEffectID StandardEffectName() const = 0;
  183. // ACTUAL OVERRIDES!
  184. virtual bool SetVar(const HFXParamID id, void *value, HFXParamType t,
  185. HFXARRAY settype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0, bool allowMake=false) = 0;
  186. virtual bool GetVar(const HFXParamID id, void *value, HFXParamType t,
  187. HFXARRAY gettype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0 )const = 0;
  188. #ifndef HFX_NO_OVERLOADED_PARAMETER
  189. HFX_INLINE bool SetVarByName(const char *name, HFXVarValue value, HFXParamType t,
  190. bool allowMake )
  191. {return SetVar(HFX_PARAM_ENCODE_STRING(name), value, t, HFXARRAY_NOTARRAY, 0, allowMake);}
  192. HFX_INLINE bool SetVar(const HFXParamID name, HFXVarValue value, HFXParamType t,
  193. bool allowMake )
  194. {return SetVar(name, value, t, HFXARRAY_NOTARRAY, 0, allowMake);}
  195. HFX_INLINE bool SetVarByName(const char *name, HFXVarValue value, HFXParamType t,
  196. HFXARRAY settype, unsigned int indexORcount, bool allowMake )
  197. {return SetVar(HFX_PARAM_ENCODE_STRING(name), value, t, settype, indexORcount, allowMake);}
  198. HFX_INLINE bool SetVarByName(const char *name, const double value, bool allowMake=false)
  199. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE, allowMake);}
  200. HFX_INLINE bool SetVar(const HFXParamID name, const double value, bool allowMake=false)
  201. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE, allowMake);}
  202. HFX_INLINE bool SetVarByName(const char *name, const bool value, bool allowMake=false)
  203. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL, allowMake);}
  204. HFX_INLINE bool SetVar(const HFXParamID name, const bool value, bool allowMake=false)
  205. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL, allowMake);}
  206. HFX_INLINE bool SetVarByName(const char *name, const float value, bool allowMake=false)
  207. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT, allowMake);}
  208. HFX_INLINE bool SetVar(const HFXParamID name, const float value, bool allowMake=false)
  209. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT, allowMake);}
  210. HFX_INLINE bool SetVarByName(const char *name, const int value, bool allowMake=false)
  211. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT, allowMake);}
  212. HFX_INLINE bool SetVar(const HFXParamID name, const int value, bool allowMake=false)
  213. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_INT, allowMake);}
  214. HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const double *value, bool allowMake=false)
  215. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  216. HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const double *value, bool allowMake=false)
  217. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  218. HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const bool *value, bool allowMake=false)
  219. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  220. HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const bool *value, bool allowMake=false)
  221. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  222. HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const float *value, bool allowMake=false)
  223. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  224. HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const float *value, bool allowMake=false)
  225. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  226. HFX_INLINE bool SetVarArrayByName(const char *name, unsigned int arraySize, const int *value, bool allowMake=false)
  227. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  228. HFX_INLINE bool SetVarArray(const HFXParamID name, unsigned int arraySize, const int *value, bool allowMake=false)
  229. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize, allowMake);}
  230. template<typename T, int S>
  231. HFX_INLINE bool SetVarTypeArrayByName(const char *name, const T (value)[S], bool allowMake = false)
  232. {return SetVarArrayByName(name, S, (const T*)value, allowMake);}
  233. template<typename T, int S>
  234. HFX_INLINE bool SetVarTypeArray(const HFXParamID name, const T (value)[S], bool allowMake = false)
  235. {return SetVarArray(name, S, (const T*)value, allowMake);}
  236. HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const double value)
  237. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  238. HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const double value)
  239. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  240. HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const bool value)
  241. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  242. HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const bool value)
  243. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  244. HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const float value)
  245. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  246. HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const float value)
  247. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  248. HFX_INLINE bool SetVarElementByName(const char *name, unsigned int arrayIndex, const int value)
  249. {return SetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  250. HFX_INLINE bool SetVarElement(const HFXParamID name, unsigned int arrayIndex, const int value)
  251. {return SetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex, false);}
  252. HFX_INLINE bool GetVarByName(const char *name, void *value, HFXParamType t,
  253. HFXARRAY gettype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0 )const
  254. {return GetVar(HFX_PARAM_ENCODE_STRING(name), value, t, gettype, indexORcount);}
  255. HFX_INLINE bool GetVarByName(const char *name, float &value )const
  256. {return GetVarByName(name, (void*)&value, HFXPARAM_FLOAT);}
  257. HFX_INLINE bool GetVar( const HFXParamID name, float &value )const
  258. {return GetVar(name, (void*)&value, HFXPARAM_FLOAT);}
  259. HFX_INLINE bool GetVarByName(const char *name, double &value )const
  260. {return GetVarByName(name, (void*)&value, HFXPARAM_DOUBLE);}
  261. HFX_INLINE bool GetVar( const HFXParamID name, double &value )const
  262. {return GetVar(name, (void*)&value, HFXPARAM_DOUBLE);}
  263. HFX_INLINE bool GetVarByName(const char *name, int &value )const
  264. {return GetVarByName(name, (void*)&value, HFXPARAM_INT);}
  265. HFX_INLINE bool GetVar( const HFXParamID name, int &value )const
  266. {return GetVar(name, (void*)&value, HFXPARAM_INT);}
  267. HFX_INLINE bool GetVarByName(const char *name, bool &value )const
  268. {return GetVarByName(name, (void*)&value, HFXPARAM_BOOL);}
  269. HFX_INLINE bool GetVar( const HFXParamID name, bool &value )const
  270. {return GetVar(name, (void*)&value, HFXPARAM_BOOL);}
  271. HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, float &value)const
  272. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  273. HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, float &value)const
  274. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  275. HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, double &value)const
  276. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  277. HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, double &value)const
  278. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  279. HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, bool &value)const
  280. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  281. HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, bool &value)const
  282. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  283. HFX_INLINE bool GetVarElementByName(const char *name, unsigned int arrayIndex, int &value)const
  284. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  285. HFX_INLINE bool GetVarElement(const HFXParamID name, unsigned int arrayIndex, int &value)const
  286. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_INDEX, arrayIndex);}
  287. HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, int *&value)const
  288. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize);}
  289. HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, float *&value)const
  290. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize);}
  291. HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, double *&value)const
  292. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize);}
  293. HFX_INLINE bool GetVarArrayByName(const char *name, unsigned int arraySize, bool *&value)const
  294. {return GetVarByName(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize);}
  295. HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, float *&value)const
  296. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_FLOAT_ARRAY, HFXARRAY_COPY, arraySize);}
  297. HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, double *&value)const
  298. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_DOUBLE_ARRAY, HFXARRAY_COPY, arraySize);}
  299. HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, bool *&value)const
  300. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_BOOL_ARRAY, HFXARRAY_COPY, arraySize);}
  301. HFX_INLINE bool GetVarArray(const HFXParamID name, unsigned int arraySize, int *&value)const
  302. {return GetVar(name, (HFXVarValue)&value, HFXPARAM_INT_ARRAY, HFXARRAY_COPY, arraySize);}
  303. template<typename T, int S>
  304. HFX_INLINE bool GetVarTypeArrayByName(const char *name, T (value)[S])const
  305. {return GetVarArrayByName(name, S, (T*&)value);}
  306. template<typename T, int S>
  307. HFX_INLINE bool GetVarTypeArray(const HFXParamID name, T (value)[S])const
  308. {return GetVarArray(name, S, (T*&)value);}
  309. //strict access start. (ensures type is set) use these for typing or parsing.
  310. HFX_INLINE bool SetVarFloatByName(const char *name, const float value, bool allowMake=false)
  311. { return SetVarByName(name, value, allowMake); }
  312. HFX_INLINE bool SetVarFloat(const HFXParamID name, const float value, bool allowMake=false)
  313. { return SetVar(name, value, allowMake); }
  314. HFX_INLINE bool SetVarDoubleByName(const char *name, const double value, bool allowMake=false)
  315. { return SetVarByName(name, value, allowMake); }
  316. HFX_INLINE bool SetVarDouble(const HFXParamID name, const double value, bool allowMake=false)
  317. { return SetVar(name, value, allowMake); }
  318. HFX_INLINE bool SetVarIntByName(const char *name, const int value, bool allowMake=false)
  319. { return SetVarByName(name, value, allowMake); }
  320. HFX_INLINE bool SetVarInt(const HFXParamID name, const int value, bool allowMake=false)
  321. { return SetVar(name, value, allowMake); }
  322. HFX_INLINE bool SetVarBoolByName(const char *name, const bool value, bool allowMake=false)
  323. { return SetVarByName(name, value, allowMake); }
  324. HFX_INLINE bool SetVarBool(const HFXParamID name, const bool value, bool allowMake=false)
  325. { return SetVar(name, value, allowMake); }
  326. HFX_INLINE bool SetVarDoubleArrayByName(const char * name, unsigned int size, const double *value, bool allowMake=false)
  327. { return SetVarArrayByName(name, size, value, allowMake); }
  328. HFX_INLINE bool SetVarDoubleArray(const HFXParamID name, unsigned int size, const double *value, bool allowMake=false)
  329. { return SetVarArray(name, size, value, allowMake); }
  330. HFX_INLINE bool SetVarFloatArrayByName(const char * name, unsigned int size, const float *value, bool allowMake=false)
  331. { return SetVarArrayByName(name, size, value, allowMake); }
  332. HFX_INLINE bool SetVarFloatArray(const HFXParamID name, unsigned int size, const float *value, bool allowMake=false)
  333. { return SetVarArray(name, size, value, allowMake); }
  334. HFX_INLINE bool SetVarIntArrayByName(const char * name, unsigned int size, const int *value, bool allowMake=false)
  335. { return SetVarArrayByName(name, size, value, allowMake); }
  336. HFX_INLINE bool SetVarIntArray(const HFXParamID name, unsigned int size, const int *value, bool allowMake=false)
  337. { return SetVarArray(name, size, value, allowMake); }
  338. HFX_INLINE bool SetVarBoolArrayByName(const char * name, unsigned int size, const bool *value, bool allowMake=false)
  339. { return SetVarArrayByName(name, size, value, allowMake); }
  340. HFX_INLINE bool SetVarBoolArray(const HFXParamID name, unsigned int size, const bool *value, bool allowMake=false)
  341. { return SetVarArray(name, size, value, allowMake); }
  342. HFX_INLINE bool SetVarFloatElementByName(const char * name, unsigned int index, const float value)
  343. { return SetVarElementByName(name, index, value); }
  344. HFX_INLINE bool SetVarFloatElement(const HFXParamID name, unsigned int index, const float value)
  345. { return SetVarElement(name, index, value); }
  346. HFX_INLINE bool SetVarIntElementByName(const char * name, unsigned int index, const int value)
  347. { return SetVarElementByName(name, index, value); }
  348. HFX_INLINE bool SetVarIntElement(const HFXParamID name, unsigned int index, const int value)
  349. { return SetVarElement(name, index, value); }
  350. HFX_INLINE bool SetVarBoolElementByName(const char * name, unsigned int index, const bool value)
  351. { return SetVarElementByName(name, index, value); }
  352. HFX_INLINE bool SetVarBoolElement(const HFXParamID name, unsigned int index, const bool value)
  353. { return SetVarElement(name, index, value); }
  354. HFX_INLINE bool SetVarDoubleElementByName(const char * name, unsigned int index, const double value)
  355. { return SetVarElementByName(name, index, value); }
  356. HFX_INLINE bool SetVarDoubleElement(const HFXParamID name, unsigned int index, const double value)
  357. { return SetVarElement(name, index, value); }
  358. HFX_INLINE bool SetVarDoubleArrayByFloatArray(const HFXParamID name, unsigned int size, const float *value, bool allowMake=false)
  359. {
  360. double *__d_ = new double[size];
  361. for(unsigned int i=0;i!=size;i++)
  362. __d_[i]=(double)value[i];
  363. bool retval;
  364. retval = SetVarDoubleArray(name, size, __d_, allowMake);
  365. delete [] __d_;
  366. return retval;
  367. }
  368. HFX_INLINE bool SetVarDoubleArrayByFloatArrayByName(const char *name, unsigned int size, const float *value, bool allowMake=false)
  369. { return SetVarDoubleArrayByFloatArray(HFX_PARAM_ENCODE_STRING(name),size,value,allowMake); }
  370. HFX_INLINE bool GetVarFloatByName(const char *name, float &value)const
  371. { return GetVarByName(name, value); }
  372. HFX_INLINE bool GetVarDoubleByName(const char *name, double &value)const
  373. { return GetVarByName(name, value); }
  374. HFX_INLINE bool GetVarIntByName(const char *name, int &value)const
  375. { return GetVarByName(name, value); }
  376. HFX_INLINE bool GetVarBoolByName(const char *name, bool &value)const
  377. { return GetVarByName(name, value); }
  378. HFX_INLINE bool GetVarFloatElementByName(const char *name, unsigned int index, float &value)const
  379. { return GetVarElementByName(name, index, value); }
  380. HFX_INLINE bool GetVarDoubleElementByName(const char *name, unsigned int index, double &value)const
  381. { return GetVarElementByName(name, index, value); }
  382. HFX_INLINE bool GetVarIntElementByName(const char *name, unsigned int index, int &value)const
  383. { return GetVarElementByName(name, index, value); }
  384. HFX_INLINE bool GetVarBoolElementByName(const char *name, unsigned int index, bool &value)const
  385. { return GetVarElementByName(name, index, value); }
  386. HFX_INLINE bool GetVarFloatArrayByName(const char *name, unsigned int size, float *&value)const
  387. { return GetVarArrayByName(name, size, value); }
  388. HFX_INLINE bool GetVarDoubleArrayByName(const char *name, unsigned int size, double *&value)const
  389. { return GetVarArrayByName(name, size, value); }
  390. HFX_INLINE bool GetVarIntArrayByName(const char *name, unsigned int size, int *&value)const
  391. { return GetVarArrayByName(name, size, value); }
  392. HFX_INLINE bool GetVarBoolArrayByName(const char *name, unsigned int size, bool *&value)const
  393. { return GetVarArrayByName(name, size, value); }
  394. HFX_INLINE bool GetVarFloat(const HFXParamID name, float &value)const
  395. { return GetVar(name, value); }
  396. HFX_INLINE bool GetVarDouble(const HFXParamID name, double &value)const
  397. { return GetVar(name, value); }
  398. HFX_INLINE bool GetVarInt(const HFXParamID name, int &value)const
  399. { return GetVar(name, value); }
  400. HFX_INLINE bool GetVarBool(const HFXParamID name, bool &value)const
  401. { return GetVar(name, value); }
  402. HFX_INLINE bool GetVarFloatElement(const HFXParamID name, unsigned int index, float &value)const
  403. { return GetVarElement(name, index, value); }
  404. HFX_INLINE bool GetVarDoubleElement(const HFXParamID name, unsigned int index, double &value)const
  405. { return GetVarElement(name, index, value); }
  406. HFX_INLINE bool GetVarIntElement(const HFXParamID name, unsigned int index, int &value)const
  407. { return GetVarElement(name, index, value); }
  408. HFX_INLINE bool GetVarBoolElement(const HFXParamID name, unsigned int index, bool &value)const
  409. { return GetVarElement(name, index, value); }
  410. HFX_INLINE bool GetVarFloatArray(const HFXParamID name, unsigned int size, float *&value)const
  411. { return GetVarArray(name, size, value); }
  412. HFX_INLINE bool GetVarDoubleArray(const HFXParamID name, unsigned int size, double *&value)const
  413. { return GetVarArray(name, size, value); }
  414. HFX_INLINE bool GetVarIntArray(const HFXParamID name, unsigned int size, int *&value)const
  415. { return GetVarArray(name, size, value); }
  416. HFX_INLINE bool GetVarBoolArray(const HFXParamID name, unsigned int size, bool *&value)const
  417. { return GetVarArray(name, size, value); }
  418. HFX_INLINE bool GetVarDoubleArrayByFloatArray(const HFXParamID name, unsigned int size, float *&value) const
  419. {
  420. double *__d_ = new double[size];
  421. for(unsigned int i=0;i!=size;i++)
  422. __d_[i]=(double)value[i];
  423. bool retval;
  424. if(retval = GetVarDoubleArray(name, size, __d_))
  425. for(unsigned int i = 0;i!=size;i++)
  426. value[i]=(float)__d_[i];
  427. delete [] __d_;
  428. return retval;
  429. }
  430. HFX_INLINE bool GetVarDoubleArrayByFloatArrayByName(const char *name, unsigned int size, float *&value) const
  431. { return GetVarDoubleArrayByFloatArray(HFX_PARAM_ENCODE_STRING(name),size,value); }
  432. // util helpers
  433. // Vec3 and Vec3f
  434. HFX_INLINE bool SetVarVec3ByName(const char *name, const double *hfxVect3, bool bAllowMake=false)
  435. {return SetVarDoubleArrayByName(name, 3, hfxVect3, bAllowMake);}
  436. HFX_INLINE bool SetVarVec3(const HFXParamID name, const double *hfxVect3, bool bAllowMake=false)
  437. {return SetVarDoubleArray(name, 3, hfxVect3, bAllowMake);}
  438. HFX_INLINE bool GetVarVec3ByName(const char *name, double *&hfxVect3) const
  439. {return GetVarDoubleArrayByName(name, 3, hfxVect3);}
  440. HFX_INLINE bool GetVarVec3(const HFXParamID name, double *&hfxVect3) const
  441. {return GetVarDoubleArray(name, 3, hfxVect3);}
  442. HFX_INLINE bool SetVarVec3fByName(const char *name, const float *hfxVect3f, bool bAllowMake=false)
  443. {return SetVarFloatArrayByName(name, 3, hfxVect3f, bAllowMake);}
  444. HFX_INLINE bool SetVarVec3f(const HFXParamID name, const float *hfxVect3f, bool bAllowMake=false)
  445. {return SetVarFloatArray(name, 3, hfxVect3f, bAllowMake);}
  446. HFX_INLINE bool GetVarVec3fByName(const char *name, float *&hfxVect3f) const
  447. {return GetVarFloatArrayByName(name, 3, hfxVect3f);}
  448. HFX_INLINE bool GetVarVec3f(const HFXParamID name, float *&hfxVect3f) const
  449. {return GetVarFloatArray(name, 3, hfxVect3f);}
  450. //strict access end.
  451. #endif
  452. /*
  453. virtual bool SetVar(HFXParamID id, const char *value, HFXParamType t,
  454. HFXARRAY settype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0) = 0;
  455. virtual bool GetVar(HFXParamID id, const char *value, HFXParamType t,
  456. HFXARRAY gettype=HFXARRAY_NOTARRAY, unsigned int indexORcount=0 )const = 0;
  457. */
  458. virtual class IStack *GetDefaultStack() const=0;
  459. virtual void SetDefaultStack(class IStack *stack)=0;
  460. virtual bool Copy(IHapticEffectParamGroup *&group) const=0;
  461. virtual HFXEffectID StandardEffectID() const=0;
  462. virtual void ChangeStandardEffectID(const HFXEffectID type)=0;
  463. // creation
  464. virtual bool CreateStandardEffect( IHFXEffect *&pHandle, class IStack *createOnStack=0, const char *customName=0 )=0;
  465. HFX_INLINE bool CreateStandardEffect( IStack *createOnStack )
  466. {
  467. return CreateStandardEffect(hfxNoHandle, createOnStack, 0);
  468. }
  469. template<typename T>
  470. HFX_INLINE bool CreateStandardEffect( T *&pHandle, class IStack *createOnStack=0, const char *customName=0)
  471. {
  472. return CreateStandardEffect((IHFXEffect *&)pHandle, createOnStack, customName);
  473. }
  474. HFX_INLINE HFXParamType GetVarTypeByName(const char *param, unsigned int *arraysize=0) const{ return GetVarType(HFX_PARAM_ENCODE_STRING(param), arraysize); }
  475. virtual HFXParamType GetVarType(const HFXParamID param, unsigned int *arraysize=0) const=0;
  476. };
  477. typedef IHapticEffectParamGroup IHFXParamGroup;
  478. #define HFX_PARAMETER_INIT(classname, type, name, defaultvalue) \
  479. const char * const classname::ID_##type##name##_String = #name; \
  480. const HFXParamID classname::ID_##type##name = HFX_PARAM_ENCODE_STRING(classname::ID_##type##name##_String); \
  481. const type classname::ID_##type##name##_Default = defaultvalue;
  482. typedef void (*HFXPGCreate_t)(IHFXParamGroup*&ptr);
  483. typedef void (*HFXPGDestroy_t)(IHFXParamGroup*&ptr);
  484. template<typename T>
  485. void HFXDefaultAllocateParameterGroup(IHFXParamGroup *&ptr){ptr = new T;};
  486. template<typename T>
  487. void HFXDefaultDeallocateParameterGroup(IHFXParamGroup *&ptr){if(!ptr)return; delete ((T*)ptr); ptr=0;};
  488. #endif