GLS.SmartObjects.pas 6.4 KB

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