GXS.SmartObjects.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // The graphics engine GXScene
  3. //
  4. unit GXS.SmartObjects;
  5. (*
  6. The objects that have built-in properties and methods to support sound, vision,
  7. physics, and finding shortest paths through mezza obstacles, hightfields or terrains.
  8. They should have AI to conduct dialogues and make independent decisions.
  9. The smart spatial objects are used to interact with other smart objects and cyborgs.
  10. The registered classes:
  11. [TGLSmartGerm, TGLSmartCells, TGLSmartSwarm, TGLSmartNet, TgxCyborg, TgxCyborgs]
  12. *)
  13. interface
  14. {$I Stage.Defines.inc}
  15. uses
  16. Winapi.OpenGL,
  17. Winapi.OpenGLext,
  18. System.Classes,
  19. System.SysUtils,
  20. System.Types,
  21. System.Math,
  22. Stage.OpenGLTokens,
  23. Stage.VectorTypes,
  24. Stage.VectorGeometry,
  25. Stage.VectorTypesExt,
  26. Stage.PipelineTransform,
  27. Stage.Strings,
  28. GXS.BaseClasses,
  29. GXS.PersistentClasses,
  30. GXS.VectorLists,
  31. GXS.Coordinates,
  32. GXS.GeometryBB,
  33. GXS.Color,
  34. GXS.Scene,
  35. GXS.Silhouette,
  36. GXS.Texture,
  37. GXS.Material,
  38. GXS.Mesh,
  39. GXS.Octree,
  40. GXS.Objects,
  41. GXS.GeomObjects,
  42. GXS.ApplicationFileIO,
  43. GXS.Context,
  44. GXS.Selection,
  45. GXS.RenderContextInfo,
  46. GXS.VectorFileObjects,
  47. GXS.SoundManager,
  48. GXS.SoundFileObjects;
  49. type
  50. TgxSmartSwarmMode = (isNone, isRandom, isTetra, isGrid);
  51. TgxCyborgReference = (crNone, crWeak, crStrong);
  52. TgxCyborgThinkMode = (ctmSelf, ctmSleep, ctmOutside, ctmZombie, ctmDeath);
  53. TgxCyborgOption = (coCollide, coContact, coJoin);
  54. TgxCyborgSenceOrgans = (csoVision, csoHearing, csoSmell, csoTouch, taste);
  55. TgxCyborgOptions = set of TgxCyborgOption;
  56. TgxCyborgThinks = class(TCollection);
  57. // A list of thinking periods for TgxCyborgThinkMode
  58. TgxCyborgThinksList = class(TgxPersistentObjectList);
  59. const
  60. cDefaultCyborgOptions = [coCollide];
  61. type
  62. (* The Cyborg class specialized as a smart actor with AI.
  63. The TgxCyborg provides a quick interface to animated actors based on morph
  64. or skeleton frames, it is capable of performing frame interpolation and
  65. thinking blending (via TGLThinkingController components). *)
  66. TgxCyborg = class(TgxActor)
  67. private
  68. FBirthTime, FDeathTime: TDateTime;
  69. FReference: TgxCyborgReference;
  70. FThinkMode: TgxCyborgThinkMode;
  71. FControlers: TList;
  72. FInterval: Integer;
  73. FOptions: TgxCyborgOptions;
  74. FThinkings: TgxCyborgThinks;
  75. protected
  76. procedure SetReference(val: TgxCyborgReference);
  77. procedure SetThinking(const val: TgxCyborgThinkMode);
  78. function StoreThinking: Boolean;
  79. procedure SetOptions(const val: TgxCyborgOptions);
  80. procedure DoThink; virtual;
  81. public
  82. constructor Create(aOwner: TComponent); override;
  83. destructor Destroy; override;
  84. procedure Assign(Source: TPersistent); override;
  85. procedure BuildList(var rci: TgxRenderContextInfo); override;
  86. procedure DoProgress(const progressTime: TgxProgressTimes); override;
  87. procedure LoadFromStream(const Filename: string; aStream: TStream); override;
  88. procedure SwitchToThinking(anThinking: TgxCyborgThinks; smooth: Boolean = False);
  89. function CurrentThinking: string;
  90. // Indicates whether the cyborg is currently thinking
  91. function IsThinking: Boolean;
  92. published
  93. // See TgxCyborgThinkMode.
  94. property ThinkingMode: TgxCyborgThinkMode read FThinkMode
  95. write FThinkMode default ctmSelf;
  96. // Reference Frame Animation mode. Allows specifying if the model is primarily morph or skeleton based
  97. property SmartReference: TgxCyborgReference read FReference
  98. write FReference default crNone;
  99. // Interval between thinking frames, in milliseconds.
  100. property Interval: Integer read FInterval write FInterval;
  101. // Cyborg and thinking miscellanious options.
  102. property Options: TgxCyborgOptions read FOptions write SetOptions default cDefaultCyborgOptions;
  103. // Collection of thinking sequences.
  104. ///property Thinkings: TgxCyborgThinks read FThinkings write SetThinking stored StoreThinking;
  105. end;
  106. (*
  107. Synchronize self thinking with an other thinkers in the swarm
  108. Copies Ai/Current/End values,ThinkingMode and GridInterpolation.
  109. procedure Synchronize(IntelSwarm: TGLIntelSwarm);
  110. *)
  111. TgxSwartSwarm = class(TgxPoints)
  112. private
  113. FBirthTime, FDeathTime: TDateTime;
  114. FReference: TgxCyborgReference;
  115. FThinkMode: TgxSmartSwarmMode;
  116. public
  117. constructor Create(aOwner: TComponent); override;
  118. destructor Destroy; override;
  119. procedure Assign(Source: TPersistent); override;
  120. published
  121. property ThinkingMode: TgxSmartSwarmMode read FThinkMode;
  122. end;
  123. var
  124. vGLSmartObjectsAllocate: Boolean = True;
  125. vGLSmartObjectsEnableByDefault: Boolean = True;
  126. implementation // ----------------------------------------------------------
  127. var
  128. vCyborgsFileFormat: TgxCyborgThinksList;
  129. vNextRenderGroupID: Integer = 1;
  130. // ------------------------------------------------------------------
  131. { TgxCyborg }
  132. procedure TgxCyborg.Assign(Source: TPersistent);
  133. begin
  134. inherited;
  135. //
  136. end;
  137. procedure TgxCyborg.BuildList(var rci: TgxRenderContextInfo);
  138. begin
  139. inherited;
  140. //
  141. end;
  142. constructor TgxCyborg.Create(aOwner: TComponent);
  143. begin
  144. inherited;
  145. //
  146. end;
  147. function TgxCyborg.CurrentThinking: string;
  148. begin
  149. //
  150. end;
  151. destructor TgxCyborg.Destroy;
  152. begin
  153. //
  154. inherited;
  155. end;
  156. procedure TgxCyborg.DoProgress(const progressTime: TgxProgressTimes);
  157. begin
  158. inherited;
  159. //
  160. end;
  161. procedure TgxCyborg.DoThink;
  162. begin
  163. //
  164. end;
  165. function TgxCyborg.IsThinking: Boolean;
  166. begin
  167. //
  168. end;
  169. procedure TgxCyborg.LoadFromStream(const Filename: string; aStream: TStream);
  170. begin
  171. inherited;
  172. //
  173. end;
  174. procedure TgxCyborg.SetOptions(const val: TgxCyborgOptions);
  175. begin
  176. //
  177. end;
  178. procedure TgxCyborg.SetReference(val: TgxCyborgReference);
  179. begin
  180. //
  181. end;
  182. procedure TgxCyborg.SetThinking(const val: TgxCyborgThinkMode);
  183. begin
  184. //
  185. end;
  186. function TgxCyborg.StoreThinking: Boolean;
  187. begin
  188. //
  189. end;
  190. procedure TgxCyborg.SwitchToThinking(anThinking: TgxCyborgThinks; smooth: Boolean);
  191. begin
  192. //
  193. end;
  194. // ------------------------------------------------------------------
  195. { TgxSwartSwarm }
  196. procedure TgxSwartSwarm.Assign(Source: TPersistent);
  197. begin
  198. inherited;
  199. //
  200. end;
  201. constructor TgxSwartSwarm.Create(aOwner: TComponent);
  202. begin
  203. inherited;
  204. //
  205. end;
  206. destructor TgxSwartSwarm.Destroy;
  207. begin
  208. //
  209. inherited;
  210. end;
  211. initialization
  212. // ------------------------------------------------------------------
  213. RegisterClasses([TgxCyborg (*, TGLSmartSwarm*)]);
  214. finalization
  215. FreeAndNil(vCyborgsFileFormat);
  216. end.