GLS.SmartObjects.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // The multimedia 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 GLScene.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. GLS.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. type
  45. TGLCyborgSmartReference = (csrNone, csrWeak, csrStrong);
  46. TGLCyborgThinkingMode = (ctmSelf, ctmSleep, ctmOutside, ctmZombie, ctmDeath);
  47. TGLCyborgOption = (coCollide, coContact, coJoin);
  48. TGLCyborgSenceOrgans = (csoVision, csoHearing, csoSmell, csoTouch, taste);
  49. TGLCyborgOptions = set of TGLCyborgOption;
  50. TGLCyborgThinks = class(TCollection);
  51. // A list of thinking periods for TGLCyborgThinkingMode
  52. TGLCyborgThinksList = class(TGLPersistentObjectList);
  53. const
  54. cDefaultCyborgOptions = [coCollide];
  55. type
  56. (* The Cyborg class specialized as a smart actor with AI.
  57. The TGLCyborg provides a quick interface to animated actors based on morph
  58. or skeleton frames, it is capable of performing frame interpolation and
  59. thinking blending (via TGLThinkingController components). *)
  60. TGLCyborg = class(TGLActor)
  61. private
  62. FBirthTime, FDeathTime: TDateTime;
  63. FSmartReference: TGLCyborgSmartReference;
  64. FThinkingMode: TGLCyborgThinkingMode;
  65. FControlers: TList;
  66. FInterval: Integer;
  67. FOptions: TGLCyborgOptions;
  68. FThinkings: TGLCyborgThinks;
  69. FReference: TGLCyborgSmartReference;
  70. protected
  71. procedure SetReference(val: TGLCyborgSmartReference);
  72. procedure SetThinking(const val: TGLCyborgThinkingMode);
  73. function StoreThinking: Boolean;
  74. procedure SetOptions(const val: TGLCyborgOptions);
  75. procedure DoThink; virtual;
  76. public
  77. constructor Create(aOwner: TComponent); override;
  78. destructor Destroy; override;
  79. procedure Assign(Source: TPersistent); override;
  80. procedure BuildList(var rci: TGLRenderContextInfo); override;
  81. procedure DoProgress(const progressTime: TGLProgressTimes); override;
  82. procedure LoadFromStream(const Filename: string; aStream: TStream); override;
  83. procedure SwitchToThinking(anThinking: TGLCyborgThinks; smooth: Boolean = False);
  84. function CurrentThinking: string;
  85. // Indicates whether the cyborg is currently thinking
  86. function IsThinking: Boolean;
  87. published
  88. // See TGLCyborgThinkingMode.
  89. property ThinkingMode: TGLCyborgThinkingMode read FThinkingMode
  90. write FThinkingMode default ctmSelf;
  91. // Reference Frame Animation mode. Allows specifying if the model is primarily morph or skeleton based
  92. property SmartReference: TGLCyborgSmartReference read FReference
  93. write FSmartReference default csrNone;
  94. // Interval between thinking frames, in milliseconds.
  95. property Interval: Integer read FInterval write FInterval;
  96. // Cyborg and thinking miscellanious options.
  97. property Options: TGLCyborgOptions read FOptions write SetOptions default cDefaultCyborgOptions;
  98. // Collection of thinking sequences.
  99. ///property Thinkings: TGLCyborgThinks read FThinkings write SetThinking stored StoreThinking;
  100. end;
  101. (* Synchronize self thinking with an other thinkers.
  102. Copies Start/Current/End Frame values, CurrentFrameDelta,
  103. ThinkingMode and FrameInterpolation.
  104. procedure Synchronize(ReferenceCyborg: TGLCyborg);
  105. *)
  106. var
  107. vGLSmartObjectsAllocate: Boolean = True;
  108. vGLSmartObjectsEnableByDefault: Boolean = True;
  109. // ------------------------------------------------------------------
  110. implementation
  111. // ------------------------------------------------------------------
  112. var
  113. vCyborgsFileFormat: TGLCyborgThinksList;
  114. vNextRenderGroupID: Integer = 1;
  115. // ------------------------------------------------------------------
  116. { TGLCyborg }
  117. procedure TGLCyborg.Assign(Source: TPersistent);
  118. begin
  119. inherited;
  120. //
  121. end;
  122. procedure TGLCyborg.BuildList(var rci: TGLRenderContextInfo);
  123. begin
  124. inherited;
  125. //
  126. end;
  127. constructor TGLCyborg.Create(aOwner: TComponent);
  128. begin
  129. inherited;
  130. //
  131. end;
  132. function TGLCyborg.CurrentThinking: string;
  133. begin
  134. //
  135. end;
  136. destructor TGLCyborg.Destroy;
  137. begin
  138. //
  139. inherited;
  140. end;
  141. procedure TGLCyborg.DoProgress(const progressTime: TGLProgressTimes);
  142. begin
  143. inherited;
  144. //
  145. end;
  146. procedure TGLCyborg.DoThink;
  147. begin
  148. //
  149. end;
  150. function TGLCyborg.IsThinking: Boolean;
  151. begin
  152. //
  153. end;
  154. procedure TGLCyborg.LoadFromStream(const Filename: string; aStream: TStream);
  155. begin
  156. inherited;
  157. //
  158. end;
  159. procedure TGLCyborg.SetOptions(const val: TGLCyborgOptions);
  160. begin
  161. //
  162. end;
  163. procedure TGLCyborg.SetReference(val: TGLCyborgSmartReference);
  164. begin
  165. //
  166. end;
  167. procedure TGLCyborg.SetThinking(const val: TGLCyborgThinkingMode);
  168. begin
  169. //
  170. end;
  171. function TGLCyborg.StoreThinking: Boolean;
  172. begin
  173. //
  174. end;
  175. procedure TGLCyborg.SwitchToThinking(anThinking: TGLCyborgThinks; smooth: Boolean);
  176. begin
  177. //
  178. end;
  179. // ------------------------------------------------------------------
  180. initialization
  181. // ------------------------------------------------------------------
  182. RegisterClasses([TGLCyborg{, TGLGerm, TGLCyborgNet, TGLSmartSwarm}]);
  183. finalization
  184. FreeAndNil(vCyborgsFileFormat);
  185. end.