enworld.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /** /**
  2. * \defgroup World World
  3. * @{
  4. */
  5. //----------------------------------------------
  6. /**
  7. * \defgroup WorldCommon World
  8. * @{
  9. */
  10. typedef int[] WorldHandle;
  11. proto native float GetWorldTime();
  12. /*! Sets current world. It allows to work with entities outside world processing
  13. // return previous world
  14. */
  15. proto native WorldHandle SetCurrentWorld(WorldHandle world);
  16. //proto native void SchedulePreload(vector pos, float radius);
  17. proto native IEntity FindEntityByName(IEntity worldEnt, string name);
  18. proto native IEntity FindEntityByID(IEntity worldEnt, int ID);
  19. //!returns number of active (simulated) Entities in the world
  20. proto native int GetNumActiveEntities(IEntity worldEntity);
  21. //!returns active entity
  22. proto native IEntity GetActiveEntity(IEntity worldEntity, int index);
  23. //@}
  24. //----------------------------------------------
  25. /**
  26. * \defgroup Camera Camera
  27. * @{
  28. */
  29. enum CameraType
  30. {
  31. PERSPECTIVE,
  32. ORTHOGRAPHIC
  33. };
  34. //! sets which camera will be a listener (for sound engine)
  35. proto native void SetListenerCamera(int camera);
  36. /*!
  37. Changes camera position
  38. \param cam Index of camera
  39. \param origin position
  40. \param angle orientation
  41. */
  42. proto native void SetCamera(int cam, vector origin, vector angle);
  43. //! Changes camera matrix
  44. proto native void SetCameraEx(int cam, const vector mat[4]);
  45. //!Returns current camera transformation
  46. proto native void GetCamera(int cam, out vector mat[4]);
  47. proto native void SetCameraVerticalFOV(int cam, float fovy);
  48. proto native void SetCameraFarPlane(int cam, float farplane); //default 160000 units
  49. proto native void SetCameraNearPlane(int cam, float nearplane); //default 5 units
  50. proto native void SetCameraType(int cam, CameraType type);
  51. /*!
  52. \brief Post-process effect type.
  53. \attention Keep enum names in synch with post-process effect material class names. Postfix "Effect" is appended automatically.
  54. */
  55. enum PostProcessEffectType
  56. {
  57. None,
  58. UnderWater,
  59. SSAO,
  60. DepthOfField,
  61. HBAO,
  62. RotBlur,
  63. GodRays,
  64. Rain,
  65. Snowfall,
  66. FilmGrain,
  67. RadialBlur,
  68. ChromAber,
  69. WetDistort,
  70. DynamicBlur,
  71. ColorGrading,
  72. Colors,
  73. Glow,
  74. SMAA,
  75. FXAA,
  76. Median,//unused?
  77. SunMask,
  78. GaussFilter,
  79. SSR, //not available
  80. Distort,
  81. Ghost
  82. };
  83. /*!
  84. set postprocess effect to camera
  85. To disable effect in some prioroty ppEffect, just set effectName or name to NULL
  86. \param cam number of camera
  87. \param priority priority of effect
  88. \param type type of effect
  89. \param materialPath material
  90. */
  91. proto native void SetCameraPostProcessEffect(int cam, int priority, PostProcessEffectType type, string materialPath);
  92. //ent can be NULL for world-space coords
  93. proto vector ProjectVector(int cam, IEntity ent, vector vec);
  94. proto vector UnprojectVector(int cam, float x, float y, vector dir);
  95. //@}
  96. //----------------------------------------------
  97. /**
  98. * \defgroup Light Light API
  99. * @{
  100. */
  101. //!Light handle
  102. typedef int[] HLIGHT;
  103. enum LightType
  104. {
  105. POINT, //< point light, all directional light
  106. SPOT, //< spot light, direction is determined by owner (entity)
  107. DIRECTIONAL,
  108. AMBIENT
  109. };
  110. enum LightFlags
  111. {
  112. /*!
  113. Dynamic light. There is limit 512 dynamic lights per world and
  114. 32 per camera view. They are faster when moving and changing shape.
  115. Also they are always attached to owner entity
  116. */
  117. DYNAMIC,
  118. CASTSHADOW,
  119. //! for cheaper dynamic lights, like muzzle flashes (might use cheaper rendering method)
  120. CHEAP
  121. };
  122. /*!
  123. creates light
  124. */
  125. proto HLIGHT AddLight(IEntity owner, LightType type, LightFlags flags, float radius, vector color);
  126. //!removes light
  127. proto native bool RemoveLight(HLIGHT light);
  128. proto native bool SetLightEx(HLIGHT light, float radius, vector color);
  129. //!sets lookup texture for projection lights
  130. proto native bool SetLightTexture(HLIGHT light, string cubemap);
  131. proto native int SetLightFlags(HLIGHT light, LightFlags flags);
  132. proto native int ClearLightFlags(HLIGHT light, LightFlags flags);
  133. //!Sets light cone in degrees (for LightType.SPOT).
  134. proto native bool SetLightCone(HLIGHT light, float cone);
  135. /*!
  136. scene multiplicator of light (based on measured scene light levels) - preexposure of light
  137. */
  138. proto native float GetSceneHDRMul(int camera);
  139. //@}
  140. //----------------------------------------------
  141. /**
  142. * \defgroup WorldTrace Trace&Visibility API
  143. * @{
  144. */
  145. enum TraceFlags
  146. {
  147. BONES, //< tests collision geometries around bones of animated objects
  148. ENTS, //< tests entities
  149. WORLD, //< tests world bounding box
  150. ONLY_PHYSICS,
  151. WATER, //< tests collision with water surface
  152. PASSTRANSLUCENT,//< Do not intersects with entities with EntityFlags.TRANSLUCENT set
  153. RAGDOLLS, //< tests ragdolls
  154. VISTEST, //< performs visibility test first. Not necessary for entities receiving EntityEvent.VISIBLE, because there is a certainty that a camera will see them
  155. NOTRACE,
  156. TRANSPARENT_OCCLUDERS
  157. };
  158. enum TraceShape
  159. {
  160. LINE,
  161. BOX,
  162. OBB,
  163. SPHERE
  164. };
  165. //! collision and tracing
  166. //! WARNING: Non-managed, needs manual delete call, should not be ref'd
  167. class TraceContact
  168. {
  169. float Fraction;
  170. int Content;
  171. int Surfparm;
  172. int MaterialFlags;
  173. int Triangle;
  174. int SurfaceID;
  175. owned string MaterialName;
  176. owned string OriginalMaterialName;
  177. float Plane[4];
  178. vector Point;
  179. }
  180. proto native bool TraceLineToEntity(IEntity ent, vector start, vector end, out TraceContact contact);
  181. //bool FilterCallback(Class target [, vector rayorigin, vector raydirection])
  182. class TraceParam: Managed
  183. {
  184. vector Start;
  185. vector End;
  186. int LayerMask = 0xffffffff;
  187. TraceFlags Flags;
  188. IEntity Exclude;
  189. };
  190. class TraceSphere: TraceParam
  191. {
  192. float Radius;
  193. };
  194. class TraceBox: TraceParam
  195. {
  196. vector Mins;
  197. vector Maxs;
  198. };
  199. class TraceOBB: TraceBox
  200. {
  201. vector Mat[3];
  202. };
  203. /*!
  204. traces line start->end, return 0..1 if trace was sucessfull.
  205. // It take bboux from ent
  206. // flag like in P2PVisibilityEx will be added
  207. //OUTPUT:
  208. \param cent [out] traced entity
  209. \param plane [out] traced polygon plane (X,Y,Z,D)
  210. \param surfparm [out] traced surface parameters
  211. \returns value 0...1, percentage of a path traveled
  212. */
  213. proto volatile float TraceMove(TraceParam param, out IEntity cent, out float plane[4], out int surfparm, func filtercallback);
  214. /*!
  215. tests visibility
  216. \param from
  217. \param to
  218. \param flags
  219. //TraceFlags.VISTEST -
  220. //TraceFlags.DETAIL - test agains detail brushes
  221. //TraceFlags.ENT - test against brush entities
  222. //TraceFlags.NOTRACE - doesn't test geometry (has meaning in conjuction with s TraceFlags.VISTEST)
  223. \returns true is visible/false not visibel
  224. */
  225. proto native int P2PVisibilityEx(vector from, vector to,int flags);
  226. //! finds all entities in a radius
  227. proto int SphereQuery(vector origin, float radius, out IEntity visents[], int ents, int fmask);
  228. /*!tests if bbox is visible according to view-frustum and PVS
  229. \param flags & 1 - test also PVS
  230. \returns true/false is/isn't visible
  231. */
  232. proto native bool IsBoxVisible(vector mins, vector maxs, int flags);
  233. /*!finds all visible entities (rought, according to a visibility. It is convinient for entitie selection where we want to do more precise visibility test)
  234. \param origin - position it is looked from
  235. \param look - look direction
  236. \param angle - view angle (usuably 90). -1 if we do not care about the view angle
  237. \param ents - array to which entities will be stored
  238. \param maxents - length of the array (prevents overflowing the array)
  239. \param fmask - flag mask (SetFlags()). Entity must have all flags set.
  240. it is possible to use reserved flags like EntityFlags.USER1, EntityFlags.USER2, EntityFlags.USER6 for fast finding of entities in custom categories
  241. */
  242. proto int VisEntities(vector origin, vector look, float angle, float radius, out IEntity ents[2], int maxents, int fmask);
  243. /*!
  244. Object that handles visibility on GPU. Used for coronas etc.
  245. */
  246. class OcclusionQuery
  247. {
  248. proto private void ~OcclusionQuery();
  249. /*!
  250. return Query result
  251. \returns -1 result is not ready yet, try it later.
  252. >0 point is visible
  253. ==0 point is not visible
  254. */
  255. proto native int GetResult();
  256. //!Sets world position
  257. proto native void SetPosition(vector pos);
  258. //!Destroys the object
  259. proto native void Destroy();
  260. };
  261. //@}
  262. //----------------------------------------------
  263. /**
  264. * \defgroup Decals Decals API
  265. * @{
  266. */
  267. typedef int[] hDecal;
  268. /*!
  269. Creates single visual mark, e.g. from shots
  270. //when lifetime=0, pointer to decal is returned, that can be removed by RemoveDecal then
  271. \param entity entity where the landmark should be created
  272. \param origin first point of the decal, nothing is done now
  273. \param project projection direction (length is far clipping distance)
  274. \param nearclip near clipping distance
  275. \param materialName Material used for decal
  276. \param lifetime Lifetime in seconds
  277. \param flags Not used ATM
  278. \return Decal pointer or null
  279. */
  280. proto native hDecal CreateDecal(IEntity entity, vector origin, vector project, float nearclip, float angle, float size, string materialName, float lifetime, int flags);
  281. proto native void RemoveDecal(hDecal decal);
  282. /*!
  283. Creates continous visual mark, e.g. from wheel when a car is moving on the ground
  284. \param entity entity where the landmark should be created (only terrain is supported ATM)
  285. \param origin first point of the decal, nothing is done now
  286. \param normal normal of surface
  287. \param edgesize Edge size of decal
  288. \param lifetime Lifetime in seconds
  289. \param materialName Material used for decal
  290. \param prev Previous decal, we are connecting to
  291. \param alpha translucency of point
  292. \return Decal pointer or null
  293. */
  294. proto native hDecal CreateLandMarkDecal(IEntity entity, vector origin, vector normal, float edgeSize, float lifeTime, string materialName, hDecal prevDecal, float alpha);
  295. /*!
  296. is it possible to add new point to landmark decal?
  297. \param lmDecal entity to add new landmark point
  298. \param entity entity to add new landmark point
  299. \param mat material of decal
  300. \param newpoint new point to add
  301. \return
  302. LMD_ERROR = error when adding new point (invalid decal)
  303. LMD_VALID = can add new point
  304. LMD_DIFF_ENT = new point is on different entity
  305. LMD_TOO_FAR = new point is too far from previous point
  306. */
  307. proto native int CanAddToLandMarkDecal(hDecal lmDecal, IEntity entity, string mat, vector newPoint);
  308. /*!
  309. add new point to decal, internally, new point is added when previous point is in some
  310. distance or the angle is more than some threshold
  311. \param lmDecal entity to add new landmark point
  312. \param point contact point
  313. \param normal normal of contact
  314. \param alpha translucency in point
  315. \return true if everything was OK, false if not. In this case, the application MUST not used later the pointer to decal, it's finalized internally !
  316. */
  317. proto native bool AddPointToLandMarkDecal(hDecal lmDecal, vector point, vector normal, float alpha);
  318. /*!
  319. finalize landmark adding, e.g. when entity lose contact with ground -> the pointer to decal
  320. should have only world and entity if it has something to render, otherwise it's destroyed here
  321. \param lmDecal entity to add new landmark point
  322. \param addAlpha if to add last point with transition to zero alpha
  323. \param alphaDist distance to add last point
  324. */
  325. proto native void FinalizeLandMarkDecal(hDecal lmDecal, bool addAlpha, float alphaDist);
  326. /*!
  327. return if landmark was finalized
  328. \param lmDecal decal to test
  329. */
  330. proto native bool IsLandMarkFinalized(hDecal lmDecal);
  331. /*!
  332. return last landmark point or -65535.0 in all components
  333. \param lmDecal decal to test
  334. */
  335. proto native vector GetLastLandMarkPoint(hDecal lmDecal);
  336. /*!
  337. set global parameters for landmark generation
  338. \param minSegmentLength minimum length segment, when new point is added (4 default), when is less, just the end position is on the fly updated
  339. \param maxSegmentLength maximum segment length, when length is bigger, the path is finished
  340. \param degAngle angle in degrees, when is more, the path is finished
  341. */
  342. proto native void SetGlobalLandMarkParams(float minSegmentLength, float maxSegmentLength, float degAngle);
  343. //@}
  344. //----------------------------------------------
  345. /**
  346. * \defgroup Ocean Ocean API
  347. * @{
  348. */
  349. /*!
  350. Is ocean availabled
  351. */
  352. proto native bool IsOcean();
  353. /*!
  354. Get water ocean height at given point
  355. \param worldX world x position
  356. \param worldZ world z position
  357. */
  358. proto native float GetOceanHeight(float worldX, float worldZ);
  359. /*!
  360. Get water ocean height and displacement at given point, returns vector(displaceX, height, displaceZ)
  361. \param worldX world x position
  362. \param worldZ world z position
  363. */
  364. proto native vector GetOceanHeightAndDisplace(float worldX, float worldZ);
  365. //@}
  366. //@}