Singleton.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #include "gosFXHeaders.hpp"
  2. //==========================================================================//
  3. // File: gosFX_Singleton.cpp //
  4. // Contents: Base gosFX::Singleton Component //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. //
  9. //############################################################################
  10. //######################## gosFX::Singleton__Specification #############################
  11. //############################################################################
  12. //------------------------------------------------------------------------------
  13. //
  14. gosFX::Singleton__Specification::Singleton__Specification(
  15. Stuff::RegisteredClass::ClassID class_id,
  16. Stuff::MemoryStream *stream,
  17. int gfx_version
  18. ):
  19. Effect__Specification(class_id, stream, gfx_version)
  20. {
  21. Check_Pointer(this);
  22. Check_Object(stream);
  23. Verify(gos_GetCurrentHeap() == Heap);
  24. //
  25. //-------------------
  26. // Load in the curves
  27. //-------------------
  28. //
  29. m_red.Load(stream, gfx_version);
  30. m_green.Load(stream, gfx_version);
  31. m_blue.Load(stream, gfx_version);
  32. m_alpha.Load(stream, gfx_version);
  33. m_scale.Load(stream, gfx_version);
  34. *stream >> m_alignZUsingX >> m_alignZUsingY;
  35. }
  36. //------------------------------------------------------------------------------
  37. //
  38. gosFX::Singleton__Specification::Singleton__Specification(
  39. Stuff::RegisteredClass::ClassID class_id
  40. ):
  41. Effect__Specification(class_id)
  42. {
  43. Check_Pointer(this);
  44. Verify(gos_GetCurrentHeap() == Heap);
  45. }
  46. //------------------------------------------------------------------------------
  47. //
  48. void
  49. gosFX::Singleton__Specification::Save(Stuff::MemoryStream *stream)
  50. {
  51. Check_Object(this);
  52. Check_Object(stream);
  53. Effect__Specification::Save(stream);
  54. //
  55. //----------------
  56. // Save our curves
  57. //----------------
  58. //
  59. m_red.Save(stream);
  60. m_green.Save(stream);
  61. m_blue.Save(stream);
  62. m_alpha.Save(stream);
  63. m_scale.Save(stream);
  64. *stream << m_alignZUsingX << m_alignZUsingY;
  65. }
  66. //------------------------------------------------------------------------------
  67. //
  68. void
  69. gosFX::Singleton__Specification::BuildDefaults()
  70. {
  71. Check_Object(this);
  72. Effect__Specification::BuildDefaults();
  73. m_red.m_ageCurve.SetCurve(1.0f);
  74. m_red.m_seeded = false;
  75. m_red.m_seedCurve.SetCurve(1.0f);
  76. m_green.m_ageCurve.SetCurve(1.0f);
  77. m_green.m_seeded = false;
  78. m_green.m_seedCurve.SetCurve(1.0f);
  79. m_blue.m_ageCurve.SetCurve(1.0f);
  80. m_blue.m_seeded = false;
  81. m_blue.m_seedCurve.SetCurve(1.0f);
  82. m_alpha.m_ageCurve.SetCurve(1.0f);
  83. m_alpha.m_seeded = false;
  84. m_alpha.m_seedCurve.SetCurve(1.0f);
  85. m_scale.m_ageCurve.SetCurve(1.0f);
  86. m_scale.m_seeded = false;
  87. m_scale.m_seedCurve.SetCurve(1.0f);
  88. }
  89. //------------------------------------------------------------------------------
  90. //
  91. bool
  92. gosFX::Singleton__Specification::IsDataValid(bool fix_data)
  93. {
  94. Check_Object(this);
  95. Stuff::Scalar min,max;
  96. m_scale.ExpensiveComputeRange(&min,&max);
  97. if( min<0.0f)
  98. if(fix_data)
  99. {
  100. m_scale.m_ageCurve.SetCurve(1.0f);
  101. m_scale.m_seeded = false;
  102. m_scale.m_seedCurve.SetCurve(1.0f);
  103. PAUSE(("Warning: Curve \"scale\" in Effect \"%s\" Is Out of Range and has been Reset",(char *)m_name));
  104. }
  105. else
  106. return false;
  107. return Effect__Specification::IsDataValid(fix_data);
  108. }
  109. //------------------------------------------------------------------------------
  110. //
  111. void
  112. gosFX::Singleton__Specification::Copy(Singleton__Specification *spec)
  113. {
  114. Check_Object(this);
  115. Check_Object(spec);
  116. Effect__Specification::Copy(spec);
  117. //
  118. //----------------
  119. // Copy the curves
  120. //----------------
  121. //
  122. gos_PushCurrentHeap(Heap);
  123. m_red = spec->m_red;
  124. m_green = spec->m_green;
  125. m_blue = spec->m_blue;
  126. m_alpha = spec->m_alpha;
  127. m_scale = spec->m_scale;
  128. m_alignZUsingX = spec->m_alignZUsingX;
  129. m_alignZUsingY = spec->m_alignZUsingY;
  130. gos_PopCurrentHeap();
  131. }
  132. //############################################################################
  133. //############################ gosFX::Singleton ###############################
  134. //############################################################################
  135. gosFX::Singleton::ClassData*
  136. gosFX::Singleton::DefaultData = NULL;
  137. //------------------------------------------------------------------------------
  138. //
  139. void
  140. gosFX::Singleton::InitializeClass()
  141. {
  142. Verify(!DefaultData);
  143. Verify(gos_GetCurrentHeap() == Heap);
  144. DefaultData =
  145. new ClassData(
  146. SingletonClassID,
  147. "gosFX::Singleton",
  148. Effect::DefaultData,
  149. NULL,
  150. NULL
  151. );
  152. Register_Object(DefaultData);
  153. }
  154. //------------------------------------------------------------------------------
  155. //
  156. void
  157. gosFX::Singleton::TerminateClass()
  158. {
  159. Unregister_Object(DefaultData);
  160. delete DefaultData;
  161. DefaultData = NULL;
  162. }
  163. //------------------------------------------------------------------------------
  164. //
  165. gosFX::Singleton::Singleton(
  166. ClassData *class_data,
  167. Specification *spec,
  168. unsigned flags
  169. ):
  170. Effect(class_data, spec, flags)
  171. {
  172. Check_Pointer(this);
  173. Check_Object(spec);
  174. Verify(gos_GetCurrentHeap() == Heap);
  175. }
  176. //------------------------------------------------------------------------------
  177. //
  178. void
  179. gosFX::Singleton::TestInstance() const
  180. {
  181. Verify(IsDerivedFrom(DefaultData));
  182. }
  183. //------------------------------------------------------------------------------
  184. //
  185. bool
  186. gosFX::Singleton::Execute(ExecuteInfo *info)
  187. {
  188. Check_Object(this);
  189. Check_Object(info);
  190. if (!IsExecuted())
  191. return false;
  192. //
  193. //------------------------
  194. // Do the effect animation
  195. //------------------------
  196. //
  197. if (!Effect::Execute(info))
  198. return false;
  199. //
  200. //-----------------------------------------
  201. // Animate the parent then get our pointers
  202. //-----------------------------------------
  203. //
  204. Specification *spec = GetSpecification();
  205. Check_Object(spec);
  206. //
  207. //------------------
  208. // Animate the color
  209. //------------------
  210. //
  211. m_color.red = spec->m_red.ComputeValue(m_age, m_seed);
  212. m_color.green = spec->m_green.ComputeValue(m_age, m_seed);
  213. m_color.blue = spec->m_blue.ComputeValue(m_age, m_seed);
  214. m_color.alpha = spec->m_alpha.ComputeValue(m_age, m_seed);
  215. m_scale = spec->m_scale.ComputeValue(m_age, m_seed);
  216. //
  217. //------------------------------
  218. // Calculate the bounding volume
  219. //------------------------------
  220. //
  221. Stuff::OBB bounds;
  222. bounds.sphereRadius = m_radius*m_scale;
  223. if (bounds.sphereRadius < Stuff::SMALL)
  224. bounds.sphereRadius = 0.01f;
  225. bounds.localToParent = m_localToParent;
  226. bounds.axisExtents = Stuff::Vector3D::Identity;
  227. info->m_bounds->Union(*info->m_bounds, bounds);
  228. return true;
  229. }