GLS.SmartObjects.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // The graphics engine GLScene
  3. //
  4. unit GLS.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, TGLCyborg, TGLCyborgs]
  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. VCL.Consts,
  23. Stage.OpenGLTokens,
  24. Stage.VectorGeometry,
  25. Stage.VectorTypes,
  26. Stage.VectorTypesExt,
  27. Stage.Strings,
  28. Stage.PipelineTransform,
  29. GLS.Scene,
  30. GLS.VectorLists,
  31. GLS.PersistentClasses,
  32. GLS.Silhouette,
  33. GLS.Texture,
  34. GLS.Material,
  35. GLS.Mesh,
  36. GLS.Octree,
  37. GLS.GeometryBB,
  38. GLS.Objects,
  39. GLS.GeomObjects,
  40. GLS.ApplicationFileIO,
  41. GLS.Context,
  42. GLS.Color,
  43. GLS.Selection,
  44. GLS.RenderContextInfo,
  45. GLS.Coordinates,
  46. GLS.BaseClasses,
  47. GLS.VectorFileObjects,
  48. GLS.SoundManager,
  49. GLS.SoundFileObjects;
  50. type
  51. TGLSmartSwarmMode = (isNone, isRandom, isTetra, isGrid);
  52. TGLCyborgReference = (crNone, crWeak, crStrong);
  53. TGLCyborgThinkMode = (ctmSelf, ctmSleep, ctmOutside, ctmZombie, ctmDeath);
  54. TGLCyborgOption = (coCollide, coContact, coJoin);
  55. TGLCyborgSenceOrgans = (csoVision, csoHearing, csoSmell, csoTouch, taste);
  56. TGLCyborgOptions = set of TGLCyborgOption;
  57. TGLCyborgThinks = class(TCollection);
  58. // A list of thinking periods for TGLCyborgThinkMode
  59. TGLCyborgThinksList = class(TGLPersistentObjectList);
  60. const
  61. cDefaultCyborgOptions = [coCollide];
  62. type
  63. (* The Cyborg class specialized as a smart actor with AI.
  64. The TGLCyborg provides a quick interface to animated actors based on morph
  65. or skeleton frames, it is capable of performing frame interpolation and
  66. thinking blending (via TGLThinkingController components). *)
  67. TGLCyborg = class(TGLActor)
  68. private
  69. FBirthTime, FDeathTime: TDateTime;
  70. FReference: TGLCyborgReference;
  71. FThinkMode: TGLCyborgThinkMode;
  72. FControlers: TList;
  73. FInterval: Integer;
  74. FOptions: TGLCyborgOptions;
  75. FThinkings: TGLCyborgThinks;
  76. protected
  77. procedure SetReference(val: TGLCyborgReference);
  78. procedure SetThinking(const val: TGLCyborgThinkMode);
  79. function StoreThinking: Boolean;
  80. procedure SetOptions(const val: TGLCyborgOptions);
  81. procedure DoThink; virtual;
  82. public
  83. constructor Create(aOwner: TComponent); override;
  84. destructor Destroy; override;
  85. procedure Assign(Source: TPersistent); override;
  86. procedure BuildList(var rci: TGLRenderContextInfo); override;
  87. procedure DoProgress(const progressTime: TGLProgressTimes); override;
  88. procedure LoadFromStream(const Filename: string; aStream: TStream); override;
  89. procedure SwitchToThinking(anThinking: TGLCyborgThinks; smooth: Boolean = False);
  90. function CurrentThinking: string;
  91. // Indicates whether the cyborg is currently thinking
  92. function IsThinking: Boolean;
  93. published
  94. // See TGLCyborgThinkMode.
  95. property ThinkingMode: TGLCyborgThinkMode read FThinkMode
  96. write FThinkMode default ctmSelf;
  97. // Reference Frame Animation mode. Allows specifying if the model is primarily morph or skeleton based
  98. property SmartReference: TGLCyborgReference read FReference
  99. write FReference default crNone;
  100. // Interval between thinking frames, in milliseconds.
  101. property Interval: Integer read FInterval write FInterval;
  102. // Cyborg and thinking miscellanious options.
  103. property Options: TGLCyborgOptions read FOptions write SetOptions default cDefaultCyborgOptions;
  104. // Collection of thinking sequences.
  105. ///property Thinkings: TGLCyborgThinks read FThinkings write SetThinking stored StoreThinking;
  106. end;
  107. (*
  108. Synchronize self thinking with an other thinkers in the swarm
  109. Copies Ai/Current/End values,ThinkingMode and GridInterpolation.
  110. procedure Synchronize(IntelSwarm: TGLIntelSwarm);
  111. *)
  112. TGLSwartSwarm = class(TGLPoints)
  113. private
  114. FBirthTime, FDeathTime: TDateTime;
  115. FReference: TGLCyborgReference;
  116. FThinkMode: TGLSmartSwarmMode;
  117. public
  118. constructor Create(aOwner: TComponent); override;
  119. destructor Destroy; override;
  120. procedure Assign(Source: TPersistent); override;
  121. published
  122. property ThinkingMode: TGLSmartSwarmMode read FThinkMode;
  123. end;
  124. var
  125. vGLSmartObjectsAllocate: Boolean = True;
  126. vGLSmartObjectsEnableByDefault: Boolean = True;
  127. // ------------------------------------------------------------------
  128. implementation
  129. // ------------------------------------------------------------------
  130. var
  131. vCyborgsFileFormat: TGLCyborgThinksList;
  132. vNextRenderGroupID: Integer = 1;
  133. // ------------------------------------------------------------------
  134. { TGLCyborg }
  135. procedure TGLCyborg.Assign(Source: TPersistent);
  136. begin
  137. inherited;
  138. //
  139. end;
  140. procedure TGLCyborg.BuildList(var rci: TGLRenderContextInfo);
  141. begin
  142. inherited;
  143. //
  144. end;
  145. constructor TGLCyborg.Create(aOwner: TComponent);
  146. begin
  147. inherited;
  148. //
  149. end;
  150. function TGLCyborg.CurrentThinking: string;
  151. begin
  152. //
  153. end;
  154. destructor TGLCyborg.Destroy;
  155. begin
  156. //
  157. inherited;
  158. end;
  159. procedure TGLCyborg.DoProgress(const progressTime: TGLProgressTimes);
  160. begin
  161. inherited;
  162. //
  163. end;
  164. procedure TGLCyborg.DoThink;
  165. begin
  166. //
  167. end;
  168. function TGLCyborg.IsThinking: Boolean;
  169. begin
  170. //
  171. end;
  172. procedure TGLCyborg.LoadFromStream(const Filename: string; aStream: TStream);
  173. begin
  174. inherited;
  175. //
  176. end;
  177. procedure TGLCyborg.SetOptions(const val: TGLCyborgOptions);
  178. begin
  179. //
  180. end;
  181. procedure TGLCyborg.SetReference(val: TGLCyborgReference);
  182. begin
  183. //
  184. end;
  185. procedure TGLCyborg.SetThinking(const val: TGLCyborgThinkMode);
  186. begin
  187. //
  188. end;
  189. function TGLCyborg.StoreThinking: Boolean;
  190. begin
  191. //
  192. end;
  193. procedure TGLCyborg.SwitchToThinking(anThinking: TGLCyborgThinks; smooth: Boolean);
  194. begin
  195. //
  196. end;
  197. // ------------------------------------------------------------------
  198. { TGLSwartSwarm }
  199. procedure TGLSwartSwarm.Assign(Source: TPersistent);
  200. begin
  201. inherited;
  202. //
  203. end;
  204. constructor TGLSwartSwarm.Create(aOwner: TComponent);
  205. begin
  206. inherited;
  207. //
  208. end;
  209. destructor TGLSwartSwarm.Destroy;
  210. begin
  211. //
  212. inherited;
  213. end;
  214. initialization
  215. // ------------------------------------------------------------------
  216. RegisterClasses([TGLCyborg (*, TGLSmartSwarm*)]);
  217. finalization
  218. FreeAndNil(vCyborgsFileFormat);
  219. end.