scene.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // scene.h
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 01/28/97 JMI Made the m_layers member public.
  23. //
  24. // 02/06/97 JMI Filled out the CSprite3 class.
  25. //
  26. // 02/07/97 JMI Added m_transWorld transform to affect all 3D objects
  27. // rendered via the CScene.
  28. //
  29. // 02/07/97 JMI Added alphable sprite.
  30. //
  31. // 02/07/97 JMI Moved m_sX2 and m_sY2 that all three types of sprites
  32. // contained, to the base class.
  33. //
  34. // 02/07/97 JMI Now the scene has its own pipeline and CSprite3 does not.
  35. // B/c of this we no longer needed the m_transWorld, b/c we
  36. // could incorporate it right into the view.
  37. // Also, removed m_ppipe from CSprite3 and added m_sRadius
  38. // so the X Ray logic could do correct collision between
  39. // the X Rayee and X Rayables.
  40. // Also, added a function to initialize/create the pipeline.
  41. //
  42. // 02/10/97 JMI Added support for child objects of 3D sprites (CSprite3's).
  43. //
  44. // 02/13/97 JMI Changing RForm3d to RSop.
  45. //
  46. // 02/13/97 JMI Render() now uses the hood passed to it to get the lighting
  47. // effects. Render() now takes a CHood* as a parm.
  48. //
  49. // 02/14/97 JMI CSprite3 now contains an m_psphere ptr which must be set
  50. // to the bounding sphere data for the CSprite3 frame (x, y,
  51. // z, w).
  52. // Also, added TransformPts() function which will map an array
  53. // of pts through the optionally provided transform and then
  54. // through the scenes transforms.
  55. //
  56. // 02/14/97 JMI Added m_transNoZ which is a transform that is equivalent
  57. // to the scene's pipeline (m_pipeline), but does not scale
  58. // Z to the maximum value. It instead scales Z the same
  59. // as X and Y.
  60. // Also, added InFlag InHighIntensity indicating that the
  61. // object should be rendered/BLiT'ed with higher intensity
  62. // lighting.
  63. // Also, added m_sBrightness to CSprite3 indicating the
  64. // center point for the fog effect on the 3D object when
  65. // rendered.
  66. // Also, added TransformPtsToRealm() which translate points
  67. // through the specified transform, the scene's pipeline's
  68. // transforms, and finally maps them to Realm 3D coordinates.
  69. //
  70. // 02/17/97 JMI Added CSprite3::m_sCenX and CSprite3::m_sCenY indicating
  71. // center of circle that's radius was indicated by
  72. // CSprite3::m_sRadius.
  73. //
  74. // 02/20/97 JRD Added global lighting control and parameters to scene.
  75. //
  76. // 02/23/97 JMI Now CSprite3 intializes m_psphere to NULL in its
  77. // constructor and m_sBrightness was being set to 128
  78. // which used to be the middle range of light but now,
  79. // as an offset, the middle is 0 (negative is decreased
  80. // brightness and positive is increased brightness).
  81. //
  82. // 02/24/97 JMI Collapsed CAlphaSprite2 into CSprite2 and added
  83. // m_sAlphaLevel so a constant alpha level can be specified.
  84. // Using a constant alpha level is faster than using a mask.
  85. // Also, made it so the m_type field of the various sprites
  86. // are set automatically on construction so YOU SHOULD NO
  87. // LONGER SET THE CSprite*::m_type!
  88. //
  89. // 02/26/97 JMI Added m_pthing to CSprite class for debugging purposes.
  90. //
  91. // 03/05/97 JMI Added Render() function to render a 3D sprite into a
  92. // specified background.
  93. //
  94. // 03/21/97 JMI Added InDeleteOnRender flag and made CSprite base class
  95. // destructor virtual so, when objects are deleted as general
  96. // CSprites, all their destructors will be called (even though
  97. // none do anything yet, they may someday).
  98. // Also, added a CSpriteLine2d.
  99. //
  100. // 04/29/97 JMI Made the child concept part of the base class sprite (was
  101. // part of the 3D sprite (CSprite3)) and added a parent
  102. // pointer.
  103. // Now that we have the parent sprite pointer, I was able to
  104. // make sure the sprites remove themselves from their parents
  105. // and remove their children when they are destroyed.
  106. // Also, added member functions to CScene to handle rendering
  107. // 2D sprites, 3D sprites, and 2D lines.
  108. //
  109. // 04/29/97 JMI Added GetType() to CSprite to allow read-only access to
  110. // its m_type member.
  111. //
  112. // 05/02/97 JMI Added CSpriteCylinder3d, a cylinder primitive.
  113. //
  114. // 05/08/97 JMI If VC < 4.2, we were including <multiset>. Changed <multiset> to
  115. // <multiset.h>
  116. //
  117. // 05/12/97 JMI Added m_sRenderX, m_sRenderY, m_sRenderOffX, m_sRenderOffY
  118. // which is used by Render3D() to store at what offset the 3D
  119. // item was rendered.
  120. //
  121. // 05/15/97 JMI I had thought that the max alpha (i.e., opaque) level was
  122. // 100 and was, therefore, checking to see if the level was
  123. // less than 100 before calling the alpha blit. As it turns
  124. // out, it is 255. Fixed.
  125. //
  126. // 05/17/97 JMI Moved class CLayer out of CScene.
  127. //
  128. // 05/19/97 JMI Added m_pszText to basic CSprite.
  129. // Also, added ms_print to CScene to print m_pszText.
  130. //
  131. // 06/09/97 JMI RemoveChild() was not moving the pointer to the previous
  132. // child's next.
  133. //
  134. // 06/14/97 MJR Added g_bSceneDontBlit to replace the flag in gamesettings
  135. // that was being misused for that purpose.
  136. //
  137. // 06/16/97 JMI Added InBlitOpaque flag for opaque 2D sprites.
  138. //
  139. // 06/25/97 JMI Added SetXRayAll() and m_bXRayAll which enable or disable
  140. // xraying of all 'alpha' _and_ 'opaque' layers.
  141. // Also, changed InXrayable to InAlpha and added InOpaque to
  142. // differentiate between these two types which are now, at
  143. // times, both xrayable.
  144. //
  145. // 06/26/97 JMI Added phood parm to RenderCylinder3D().
  146. //
  147. // 06/27/97 JMI Moved CSprite and derived sprite classes from here to
  148. // sprites.h
  149. //
  150. // 06/29/97 MJR Converted vector of layers into simple array of layers
  151. // (motivated by trying to get it to work on the mac).
  152. //
  153. // 07/01/97 JMI Added m_transScene2Realm which is used in
  154. // TransformPtsToRealm() to convert from the scene to the
  155. // realm. This value is set via the SetupPipeline() call.
  156. //
  157. // 08/07/97 JMI Moved global single instance of gdSCALE3D defined in
  158. // scene.cpp into scene as an instantiable member, m_dScale3d.
  159. //
  160. // 08/18/97 JMI Changed Render() used by dead things to update themselves
  161. // into the background to be called DeadRender3D() to better
  162. // describe what it does and differentiate it from the other
  163. // more generic Render()ers. Also, added two parameters so
  164. // it could call itself with 3D children.
  165. //
  166. // 10/03/99 JMI Changed Render3D() to take a light scheme instead of a hood
  167. // to make it more general.
  168. //
  169. ////////////////////////////////////////////////////////////////////////////////
  170. #ifndef SCENE_H
  171. #define SCENE_H
  172. #if _MSC_VER >= 1020 || __MWERKS__ >= 0x1100 || __GNUC__
  173. #include <set>
  174. #else
  175. #include <multiset.h>
  176. #endif
  177. #include "RSPiX.h"
  178. #include "hood.h"
  179. #include "sprites.h"
  180. ////////////////////////////////////////////////////////////////////////////////
  181. // HERE ARE GLOBAL LIGHTING MACROS FOR YOUR ENJOYMENT!
  182. // They are nolonger constant, as the user may adjust them.
  183. //
  184. // NOTE: ONLY THE MENU MAY ADJUST THESE VALUES
  185. // 3d objects may need to use gsGlobalBrightnessPerLightAttribute for calculation
  186. //
  187. extern short gsGlobalBrightnessPerLightAttribute;
  188. extern short gsGlobalLightingAdjustment;
  189. //
  190. ////////////////////////////////////////////////////////////////////////////////
  191. // Used to control whether or not scene will actually blit. When set to true,
  192. // scene will execute quite a bit faster, except you won't see anything. :)
  193. extern bool g_bSceneDontBlit;
  194. // Define a layer, which is a sorted collection of sprites (this must be
  195. // a class so that the member object's constructor gets called!)
  196. class Layer
  197. {
  198. public:
  199. msetSprites m_sprites; // Sprites in this layer
  200. bool m_bHidden; // Whether this layer is hidden
  201. Layer()
  202. {
  203. m_bHidden = false;
  204. }
  205. ~Layer()
  206. {
  207. }
  208. };
  209. // A CScene object consists of any number of layers, each of which contains any
  210. // number of CSprites. It handles both 2d and 3d sprites, and does everything
  211. // necessary to render a view of the scene.
  212. class CScene
  213. {
  214. //---------------------------------------------------------------------------
  215. // Types, enums, etc.
  216. //---------------------------------------------------------------------------
  217. public:
  218. //---------------------------------------------------------------------------
  219. // Variables
  220. //---------------------------------------------------------------------------
  221. public:
  222. // STATIC! Used to draw within the scene.
  223. static RPrint ms_print;
  224. // Array of layers
  225. Layer* m_pLayers;
  226. short m_sNumLayers;
  227. // The world pipeline. All 3D objects are rendered via this pipeline.
  228. // We might eventually have more than one.
  229. RPipeLine m_pipeline;
  230. // This transform is equivalent to the scene's pipeline (m_pipeline), but
  231. // does not scale Z to the maximum value. It instead scales Z the same
  232. // as X and Y.
  233. RTransform m_transNoZView;
  234. RTransform m_transNoZScreen;
  235. // When true, all 'opaque' layers will be alpha'ed in the way 'alpha' layers
  236. // are. But not when false; duh!
  237. bool m_bXRayAll;
  238. // The transform for converting from the scene to the realm.
  239. // Used in TransformPtsToRealm().
  240. RTransform m_transScene2Realm;
  241. // The global scaling factor. This is used to tune our model ratio so we
  242. // can scale 3D objects differently on a per realm basis.
  243. double m_dScale3d;
  244. //---------------------------------------------------------------------------
  245. // Functions
  246. //---------------------------------------------------------------------------
  247. public:
  248. // Default (and only) constructor
  249. CScene();
  250. // Destructor
  251. ~CScene();
  252. // Clear the scene (clears out all layers and sprites)
  253. void Clear(void);
  254. // Remove all sprites (from all layers)
  255. void RemoveAllSprites(void);
  256. // Remove sprites from specified layer
  257. void RemoveSprites(
  258. short sLayer); // In: Layer number (0 to n-1)
  259. // Set number of layers (destroys any existing layers!)
  260. void SetLayers( // Returns 0 if successfull, non-zero otherwise
  261. short sNumLayers); // In: Number of layers
  262. // Update existing sprite or add new sprite
  263. void UpdateSprite(
  264. CSprite* pSprite); // In: Sprite to add
  265. // Remove sprite (safe to call even if sprite isn't in scene).
  266. void RemoveSprite(
  267. CSprite* pSprite); // In: Sprite to remove
  268. // Render specified area of scene into specified image
  269. void Render(
  270. short sSrcX, // In: Source (scene) x coord
  271. short sSrcY, // In: Source (scene) y coord
  272. short sW, // In: Width
  273. short sH, // In: Height
  274. RImage* pimDst, // In: Destination image
  275. short sDstX, // In: Destination (image) x coord
  276. short sDstY, // In: Destination (image) y coord
  277. CHood* phood); // In: The hood involved.
  278. // Render a single sprite tree.
  279. void Render( // Returns nothing.
  280. RImage* pimDst, // Destination image.
  281. short sDstX, // Destination 2D x coord.
  282. short sDstY, // Destination 2D y coord.
  283. CSprite* pSprite, // Tree of sprites to render.
  284. CHood* phood, // Da hood, homey.
  285. RRect* prcDstClip, // Dst clip rect.
  286. CSprite* psXRayee); // XRayee, if not NULL.
  287. // Render a 2D sprite.
  288. void Render2D( // Returns nothing.
  289. RImage* pimDst, // Destination image.
  290. short sDstX, // Destination 2D x coord.
  291. short sDstY, // Destination 2D y coord.
  292. CSprite2* ps2Cur, // Tree of sprites to render.
  293. CHood* phood, // Da hood, homey.
  294. RRect* prcDstClip, // Dst clip rect.
  295. CSprite* psXRayee); // XRayee, if not NULL.
  296. // Draw a 2D line.
  297. void Line2D( // Returns nothing.
  298. RImage* pimDst, // Destination image.
  299. short sDstX, // Destination 2D x coord.
  300. short sDstY, // Destination 2D y coord.
  301. CSpriteLine2d* psl2, // Tree of sprites to render.
  302. RRect* prcDstClip); // Dst clip rect.
  303. // Draw a 3D (as if there were another kind) cylinder.
  304. void RenderCylinder3D( // Returns nothing.
  305. RImage* pimDst, // Destination image.
  306. short sDstX, // Destination 2D x coord.
  307. short sDstY, // Destination 2D y coord.
  308. CSpriteCylinder3d* psc3, // Cylinder sprite.
  309. CHood* phood, // Da hood, homey.
  310. RRect* prcDstClip); // Dst clip rect.
  311. void // Returns nothing.
  312. Render3D(
  313. RImage* pimDst, // Destination image.
  314. short sDstX, // Destination 2D x coord.
  315. short sDstY, // Destination 2D y coord.
  316. CSprite3* ps3Cur, // 3D sprite to render.
  317. RAlpha* plight, // Light to render with.
  318. RRect* prcDstClip); // Dst clip rect.
  319. inline
  320. void // Returns nothing.
  321. Render3D(
  322. RImage* pimDst, // Destination image.
  323. short sDstX, // Destination 2D x coord.
  324. short sDstY, // Destination 2D y coord.
  325. CSprite3* ps3Cur, // 3D sprite to render.
  326. CHood* phood, // Da hood, homey.
  327. RRect* prcDstClip); // Dst clip rect.
  328. // Setup render pipeline. Use this function to setup or alter the pipeline.
  329. // This function DOES a Make1() and then multiplies by the supplied transform,
  330. // if any. Any transforms that need to be applied after this setup can be
  331. // done following a call to this function.
  332. // The only sux is you cannot insert yourself into the middle of this function.
  333. // If that's what you need, you should probably just do the entire setup for
  334. // the pipe yourself or add a similar function to this one.
  335. void SetupPipeline( // Returns nothing.
  336. RTransform* ptransScene = NULL, // In: Transform to apply before doing defaults.
  337. RTransform* ptransScene2Realm = NULL, // In: Transform to convert from scene to realm.
  338. double dScale3d = 0.0) // In: New scaling to apply to pipeline (see
  339. // m_dScale3d declaration).
  340. ;
  341. // Transform the given points through the CScene's pipeline with the
  342. // supplied transform.
  343. void TransformPts( // Returns nothing.
  344. RTransform* ptrans, // In: Transformation to apply to CScene's before
  345. // transforming pts.
  346. RP3d* p3dPtsSrc, // In: Ptr to group of pts to transform from.
  347. RP3d* p3dPtsDst, // Out: Ptr to group of pts to transform into.
  348. short sNum); // In: The number of pts in p3dPtsSrc to transform.
  349. // Transform the given points through the CScene's pipeline with the
  350. // supplied transform and then map them to Realm 3D coordinates.
  351. void TransformPtsToRealm( // Returns nothing.
  352. RTransform* ptrans, // In: Transformation to apply to CScene's before
  353. // transforming pts.
  354. RP3d* p3dPtsSrc, // In: Ptr to group of pts to transform from.
  355. RP3d* p3dPtsDst, // Out: Ptr to group of pts to transform into.
  356. short sNum); // In: The number of pts in p3dPtsSrc to transform.
  357. // Render a 3D sprite tree into the specified image.
  358. // Ignores non 3D sprites.
  359. void DeadRender3D( // Returns nothing.
  360. RImage* pimDst, // Destination image.
  361. CSprite3* ps3Cur, // Tree of 3D sprites to render.
  362. CHood* phood, // Da hood, homey.
  363. short sDstX = 0, // Destination 2D x coord.
  364. short sDstY = 0, // Destination 2D y coord.
  365. RRect* prcDstClip = NULL); // Dst clip rect.
  366. // Set all 'alpha' _and_ 'opaque' layers to xray.
  367. void SetXRayAll( // You see a door to the north. Returns nothing.
  368. bool bXRayAll); // In: true to X Ray all 'alpha' _and_ 'opaque' layers.
  369. };
  370. #endif //SCENE_H
  371. ////////////////////////////////////////////////////////////////////////////////
  372. // EOF
  373. ////////////////////////////////////////////////////////////////////////////////