GLS.SmartObjects.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // The graphics platform GLScene https://github.com/glscene
  3. //
  4. unit GLS.SmartObjects;
  5. (*
  6. The smart spatial objects that have sences and artifitial intelligence
  7. to interact with player, base geometric and other smart objects of GLScene:
  8. TGLGerm, TGLSmartCells, TGLSmartSwarm, TGLCyborg, TGLCyborgNet
  9. *)
  10. interface
  11. {$I Scenario.inc}
  12. uses
  13. Winapi.OpenGL,
  14. Winapi.OpenGLext,
  15. System.Classes,
  16. System.SysUtils,
  17. System.Types,
  18. System.Math,
  19. VCL.Consts,
  20. GLS.OpenGLTokens,
  21. GLS.Scene,
  22. GLS.VectorGeometry,
  23. GLS.VectorTypes,
  24. GLS.VectorTypesExt,
  25. GLS.VectorLists,
  26. GLS.PersistentClasses,
  27. GLS.Silhouette,
  28. Scenario.Strings,
  29. GLS.Texture,
  30. GLS.Material,
  31. GLS.Mesh,
  32. GLS.Logger,
  33. GLS.Octree,
  34. GLS.GeometryBB,
  35. GLS.ApplicationFileIO,
  36. GLS.Context,
  37. GLS.Color,
  38. GLS.PipelineTransformation,
  39. GLS.Selection,
  40. GLS.RenderContextInfo,
  41. GLS.Coordinates,
  42. GLS.BaseClasses,
  43. GLS.VectorFileObjects,
  44. GLS.SoundManager,
  45. GLS.SoundFileObjects;
  46. type
  47. TGLCyborgSmartReference = (csrNone, csrWeak, csrStrong);
  48. TGLCyborgThinkingMode = (ctmSelf, ctmSleep, ctmOutside, ctmZombie, ctmDeath);
  49. TGLCyborgOption = (coCollide, coContact, coJoin);
  50. TGLCyborgSenceOrgans = (csoVision, csoHearing, csoSmell, csoTouch, taste);
  51. TGLCyborgOptions = set of TGLCyborgOption;
  52. TGLCyborgThinks = class(TCollection);
  53. // A list of thinking periods for TGLCyborgThinkingMode
  54. TGLCyborgThinksList = class(TGLPersistentObjectList);
  55. const
  56. cDefaultCyborgOptions = [coCollide];
  57. type
  58. (* The Cyborg class specialized as a smart actor with AI.
  59. The TGLCyborg provides a quick interface to animated actors based on morph
  60. or skeleton frames, it is capable of performing frame interpolation and
  61. thinking blending (via TGLThinkingController components). *)
  62. TGLCyborg = class(TGLActor)
  63. private
  64. FBirthTime, FDeathTime: TDateTime;
  65. FSmartReference: TGLCyborgSmartReference;
  66. FThinkingMode: TGLCyborgThinkingMode;
  67. FControlers: TList;
  68. FInterval: Integer;
  69. FOptions: TGLCyborgOptions;
  70. FThinkings: TGLCyborgThinks;
  71. FReference: TGLCyborgSmartReference;
  72. protected
  73. procedure SetReference(val: TGLCyborgSmartReference);
  74. procedure SetThinking(const val: TGLCyborgThinkingMode);
  75. function StoreThinking: Boolean;
  76. procedure SetOptions(const val: TGLCyborgOptions);
  77. procedure DoThink; virtual;
  78. public
  79. constructor Create(aOwner: TComponent); override;
  80. destructor Destroy; override;
  81. procedure Assign(Source: TPersistent); override;
  82. procedure BuildList(var rci: TGLRenderContextInfo); override;
  83. procedure DoProgress(const progressTime: TGLProgressTimes); override;
  84. procedure LoadFromStream(const Filename: string; aStream: TStream); override;
  85. procedure SwitchToThinking(anThinking: TGLCyborgThinks; smooth: Boolean = False);
  86. function CurrentThinking: string;
  87. // Indicates whether the cyborg is currently thinking
  88. function IsThinking: Boolean;
  89. published
  90. // See TGLCyborgThinkingMode.
  91. property ThinkingMode: TGLCyborgThinkingMode read FThinkingMode
  92. write FThinkingMode default ctmSelf;
  93. // Reference Frame Animation mode. Allows specifying if the model is primarily morph or skeleton based
  94. property SmartReference: TGLCyborgSmartReference read FReference
  95. write FSmartReference default csrNone;
  96. // Interval between thinking frames, in milliseconds.
  97. property Interval: Integer read FInterval write FInterval;
  98. // Cyborg and thinking miscellanious options.
  99. property Options: TGLCyborgOptions read FOptions write SetOptions default cDefaultCyborgOptions;
  100. // Collection of thinking sequences.
  101. ///property Thinkings: TGLCyborgThinks read FThinkings write SetThinking stored StoreThinking;
  102. end;
  103. (* Synchronize self thinking with an other thinkers.
  104. Copies Start/Current/End Frame values, CurrentFrameDelta,
  105. ThinkingMode and FrameInterpolation.
  106. procedure Synchronize(ReferenceCyborg: TGLCyborg);
  107. *)
  108. var
  109. vGLSmartObjectsAllocate: Boolean = True;
  110. vGLSmartObjectsEnableByDefault: Boolean = True;
  111. // ------------------------------------------------------------------
  112. implementation
  113. // ------------------------------------------------------------------
  114. var
  115. vCyborgsFileFormat: TGLCyborgThinksList;
  116. vNextRenderGroupID: Integer = 1;
  117. // ------------------------------------------------------------------
  118. { TGLCyborg }
  119. procedure TGLCyborg.Assign(Source: TPersistent);
  120. begin
  121. inherited;
  122. //
  123. end;
  124. procedure TGLCyborg.BuildList(var rci: TGLRenderContextInfo);
  125. begin
  126. inherited;
  127. //
  128. end;
  129. constructor TGLCyborg.Create(aOwner: TComponent);
  130. begin
  131. inherited;
  132. //
  133. end;
  134. function TGLCyborg.CurrentThinking: string;
  135. begin
  136. //
  137. end;
  138. destructor TGLCyborg.Destroy;
  139. begin
  140. //
  141. inherited;
  142. end;
  143. procedure TGLCyborg.DoProgress(const progressTime: TGLProgressTimes);
  144. begin
  145. inherited;
  146. //
  147. end;
  148. procedure TGLCyborg.DoThink;
  149. begin
  150. //
  151. end;
  152. function TGLCyborg.IsThinking: Boolean;
  153. begin
  154. //
  155. end;
  156. procedure TGLCyborg.LoadFromStream(const Filename: string; aStream: TStream);
  157. begin
  158. inherited;
  159. //
  160. end;
  161. procedure TGLCyborg.SetOptions(const val: TGLCyborgOptions);
  162. begin
  163. //
  164. end;
  165. procedure TGLCyborg.SetReference(val: TGLCyborgSmartReference);
  166. begin
  167. //
  168. end;
  169. procedure TGLCyborg.SetThinking(const val: TGLCyborgThinkingMode);
  170. begin
  171. //
  172. end;
  173. function TGLCyborg.StoreThinking: Boolean;
  174. begin
  175. //
  176. end;
  177. procedure TGLCyborg.SwitchToThinking(anThinking: TGLCyborgThinks; smooth: Boolean);
  178. begin
  179. //
  180. end;
  181. // ------------------------------------------------------------------
  182. initialization
  183. // ------------------------------------------------------------------
  184. RegisterClasses([TGLCyborg{, TGLGerm, TGLCyborgNet, TGLSmartSwarm}]);
  185. finalization
  186. FreeAndNil(vCyborgsFileFormat);
  187. end.