Advertisement
here2share

c3D.Engine.4.Python ZZZ

Mar 30th, 2021
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 51.67 KB | None | 0 0
  1. /**
  2.  * \file graphics/engine/engine.h
  3.  * \brief Main graphics engine - CEngine class
  4.  */
  5.  
  6. #pragma once
  7.  
  8. #include "common/singleton.h"
  9.  
  10. #include "graphics/core/color.h"
  11. #include "graphics/core/material.h"
  12. #include "graphics/core/texture.h"
  13. #include "graphics/core/vertex.h"
  14.  
  15. #include "math/intpoint.h"
  16. #include "math/matrix.h"
  17. #include "math/point.h"
  18. #include "math/sphere.h"
  19. #include "math/vector.h"
  20.  
  21.  
  22. #include <string>
  23. #include <vector>
  24. #include <map>
  25. #include <set>
  26. #include <memory>
  27. #include <unordered_map>
  28.  
  29.  
  30. class CApplication;
  31. class CSoundInterface;
  32. class CImage;
  33. class CSystemUtils;
  34. struct SystemTimeStamp;
  35. struct Event;
  36.  
  37.  
  38. // Graphics module namespace
  39. namespace Gfx
  40. {
  41.  
  42.  
  43. class CDevice;
  44. class COldModelManager;
  45. class CLightManager;
  46. class CText;
  47. class CParticle;
  48. class CWater;
  49. class CCloud;
  50. class CLightning;
  51. class CPlanet;
  52. class CTerrain;
  53. class CPyroManager;
  54. class CModelMesh;
  55. struct ModelShadowSpot;
  56. struct ModelTriangle;
  57.  
  58.  
  59. /**
  60.  * \enum EngineRenderState
  61.  * \brief Render state of graphics engine
  62.  *
  63.  * States are used for settings certain modes, for instance texturing and blending.
  64.  * The enum is a bitmask and some of the states can be OR'd together.
  65. */
  66. enum EngineRenderState
  67. {
  68.    //! Normal opaque materials
  69.    ENG_RSTATE_NORMAL           = 0,
  70.    //! The transparent texture (black = no)
  71.    ENG_RSTATE_TTEXTURE_BLACK   = (1<<0),
  72.    //! The transparent texture (white = no)
  73.    ENG_RSTATE_TTEXTURE_WHITE   = (1<<1),
  74.    //! The transparent diffuse color
  75.    ENG_RSTATE_TDIFFUSE         = (1<<2),
  76.    //! Texture wrap
  77.    ENG_RSTATE_WRAP             = (1<<3),
  78.    //! Texture borders with solid color
  79.    ENG_RSTATE_CLAMP            = (1<<4),
  80.    //! Light texture (ambient max)
  81.    ENG_RSTATE_LIGHT            = (1<<5),
  82.    //! Double black texturing
  83.    ENG_RSTATE_DUAL_BLACK       = (1<<6),
  84.    //! Double white texturing
  85.    ENG_RSTATE_DUAL_WHITE       = (1<<7),
  86.    //! Part 1 (no change in. MOD!)
  87.    ENG_RSTATE_PART1            = (1<<8),
  88.    //! Part 2
  89.    ENG_RSTATE_PART2            = (1<<9),
  90.    //! Part 3
  91.    ENG_RSTATE_PART3            = (1<<10),
  92.    //! Part 4
  93.    ENG_RSTATE_PART4            = (1<<11),
  94.    //! Double-sided face
  95.    ENG_RSTATE_2FACE            = (1<<12),
  96.    //! Image using alpha channel
  97.    ENG_RSTATE_ALPHA            = (1<<13),
  98.    //! Always use 2nd floor texturing
  99.    ENG_RSTATE_SECOND           = (1<<14),
  100.    //! Causes the fog
  101.    ENG_RSTATE_FOG              = (1<<15),
  102.    //! The transparent color (black = no)
  103.    ENG_RSTATE_TCOLOR_BLACK     = (1<<16),
  104.    //! The transparent color (white = no)
  105.    ENG_RSTATE_TCOLOR_WHITE     = (1<<17),
  106.    //! Mode for rendering text
  107.    ENG_RSTATE_TEXT             = (1<<18),
  108.    //! Only opaque texture, no blending, etc.
  109.    ENG_RSTATE_OPAQUE_TEXTURE   = (1<<19),
  110.    //! Only opaque color, no texture, blending, etc.
  111.    ENG_RSTATE_OPAQUE_COLOR     = (1<<20),
  112.    //! Texture using alpha channel
  113.    ENG_RSTATE_TTEXTURE_ALPHA   = (1<<21),
  114.    //! Color with transparency
  115.    ENG_RSTATE_TCOLOR_ALPHA     = (1<<22)
  116. };
  117.  
  118.  
  119. /**
  120. * \enum EngineTriangleType
  121. * \brief Type of triangles drawn for engine objects
  122. */
  123. enum EngineTriangleType
  124. {
  125.    //! Triangles
  126.    ENG_TRIANGLE_TYPE_TRIANGLES = 1,
  127.    //! Surfaces
  128.    ENG_TRIANGLE_TYPE_SURFACE   = 2
  129. };
  130.  
  131. /**
  132. * \struct EngineTriangle
  133. * \brief A triangle drawn by the graphics engine
  134. */
  135. struct EngineTriangle
  136. {
  137.    //! Triangle vertices
  138.    VertexTex2     triangle[3];
  139.    //! Material
  140.    Material       material;
  141.    //! Render state
  142.    int            state = ENG_RSTATE_NORMAL;
  143.    //! 1st texture
  144.    std::string    tex1Name;
  145.    //! 2nd texture
  146.    std::string    tex2Name;
  147. };
  148.  
  149. /**
  150.  \enum EngineObjectType
  151.  \brief Class of graphics engine object */
  152. enum EngineObjectType
  153. {
  154.    //! Object doesn't exist
  155.     ENG_OBJTYPE_NULL        = 0,
  156.     //! Terrain
  157.     ENG_OBJTYPE_TERRAIN     = 1,
  158.     //! Fixed object
  159.     ENG_OBJTYPE_FIX         = 2,
  160.     //! Moving object
  161.     ENG_OBJTYPE_VEHICLE    = 3,
  162.     //! Part of a moving object
  163.     ENG_OBJTYPE_DESCENDANT  = 4,
  164.     //! Fixed object type quartz
  165.     ENG_OBJTYPE_QUARTZ      = 5,
  166.     //! Fixed object type metal
  167.     ENG_OBJTYPE_METAL       = 6
  168. };
  169.  
  170.  
  171. /**
  172.  * \struct EngineBaseObjDataTier
  173.  * \brief Tier 3 of object tree (data)
  174.  */
  175. struct EngineBaseObjDataTier
  176. {
  177.     EngineTriangleType      type;
  178.     Material                material;
  179.     int                     state;
  180.     std::vector<VertexTex2> vertices;
  181.     unsigned int            staticBufferId;
  182.     bool                    updateStaticBuffer;
  183.  
  184.     inline EngineBaseObjDataTier(EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES,
  185.                                  const Material& material = Material(),
  186.                                  int state = ENG_RSTATE_NORMAL)
  187.      : type(type)
  188.      , material(material)
  189.      , state(state)
  190.      , staticBufferId(0)
  191.      , updateStaticBuffer(false)
  192.     {}
  193. };
  194.  
  195. /**
  196.  * \struct EngineBaseObjTexTier
  197.  * \brief Tier 2 of base object tree (textures)
  198.  */
  199. struct EngineBaseObjTexTier
  200. {
  201.     std::string                        tex1Name;
  202.     Texture                            tex1;
  203.     std::string                        tex2Name;
  204.     Texture                            tex2;
  205.     std::vector<EngineBaseObjDataTier>  next;
  206.  
  207.     inline EngineBaseObjTexTier(const std::string& tex1Name = "",
  208.                                 const std::string& tex2Name = "")
  209.      : tex1Name(tex1Name)
  210.      , tex2Name(tex2Name)
  211.     {}
  212. };
  213.  
  214. /**
  215.  * \struct BaseEngineObject
  216.  * \brief Base (template) object - geometry for engine objects
  217.  *
  218.  * This is also the tier 1 of base object tree.
  219.  */
  220. struct EngineBaseObject
  221. {
  222.     //! If true, base object is valid in objects vector
  223.     bool used = false;
  224.     //! Number of triangles
  225.     int                    totalTriangles = 0;
  226.     //! Bounding box min (origin 0,0,0 always included)
  227.     Math::Vector           bboxMin;
  228.     //! bounding box max (origin 0,0,0 always included)
  229.     Math::Vector           bboxMax;
  230.     //! A bounding sphere that contains all the vertices in this EngineBaseObject
  231.     Math::Sphere           boundingSphere;
  232.     //! Next tier (Tex)
  233.     std::vector<EngineBaseObjTexTier> next;
  234.  
  235.     inline void LoadDefault()
  236.     {
  237.         *this = EngineBaseObject();
  238.     }
  239. };
  240.  
  241. /**
  242.  * \struct EngineObject
  243.  * \brief Object drawn by the graphics engine
  244.  */
  245. struct EngineObject
  246. {
  247.     //! If true, object is valid in objects vector
  248.     bool                   used = false;
  249.     //! Rank of associated base engine object
  250.     int                    baseObjRank = -1;
  251.     //! If true, the object is drawn
  252.     bool                   visible = false;
  253.     //! If true, object is behind the 2D interface
  254.     bool                   drawWorld = false;
  255.     //! If true, the shape is before the 2D interface
  256.     bool                   drawFront = false;
  257.     //! Type of object
  258.     EngineObjectType       type = ENG_OBJTYPE_NULL;
  259.     //! Transformation matrix
  260.     Math::Matrix           transform;
  261.     //! Distance to object from eye point
  262.     float                  distance = 0.0f;
  263.     //! Rank of the associated shadow
  264.     int                    shadowRank = -1;
  265.     //! Transparency of the object [0, 1]
  266.     float                  transparency = 0.0f;
  267.  
  268.     //! Loads default values
  269.     inline void LoadDefault()
  270.     {
  271.         *this = EngineObject();
  272.     }
  273. };
  274.  
  275. /**
  276.  * \struct EngineShadowType
  277.  * \brief Type of shadow drawn by the graphics engine
  278.  */
  279. enum EngineShadowType
  280. {
  281.     //! Normal shadow
  282.     ENG_SHADOW_NORM = 0,
  283.     //! TODO: ?
  284.     ENG_SHADOW_WORM = 1
  285. };
  286.  
  287. /**
  288.  * \struct EngineShadow
  289.  * \brief Shadow drawn by the graphics engine
  290.  */
  291. struct EngineShadow
  292. {
  293.     //! If true, shadow is valid
  294.     bool                used = false;
  295.     //! If true, shadow is invisible (object being carried for example)
  296.     bool                hide = false;
  297.     //! Rank of the associated object
  298.     int                 objRank = -1;
  299.     //! Type of shadow
  300.     EngineShadowType type = ENG_SHADOW_NORM;
  301.     //! Position of the shadow
  302.     Math::Vector        pos;
  303.     //! Normal to the terrain
  304.     Math::Vector        normal;
  305.     //! Angle of the shadow
  306.     float               angle = 0.0f;
  307.     //! Radius of the shadow
  308.     float               radius = 0.0f;
  309.     //! Intensity of the shadow
  310.     float               intensity = 0.0f;
  311.     //! Height from the ground
  312.     float               height = 0.0f;
  313.  
  314.     void LoadDefault()
  315.     {
  316.         *this = EngineShadow();
  317.     }
  318. };
  319.  
  320. /**
  321.  * \struct EngineGroundSpot
  322.  * \brief A spot (large shadow) drawn on the ground by the graphics engine
  323.  */
  324. struct EngineGroundSpot
  325. {
  326.     //! If true, ground spot is valid
  327.     bool            used = false;
  328.     //! Color of the shadow
  329.     Color      color;
  330.     //! Min altitude
  331.     float           min = 0.0f;
  332.     //! Max altitude
  333.     float           max = 0.0f;
  334.     //! Transition area
  335.     float           smooth = 0.0f;
  336.     //! Position for the shadow
  337.     Math::Vector    pos;
  338.     //! Radius of the shadow
  339.     float           radius = 0.0f;
  340.     //! Position of the shadow drawn
  341.     Math::Vector    drawPos;
  342.     //! Radius of the shadow drawn
  343.     float           drawRadius = 0.0f;
  344.  
  345.     void LoadDefault()
  346.     {
  347.         *this = EngineGroundSpot();
  348.     }
  349. };
  350.  
  351. /**
  352.  * \enum EngineGroundMarkPhase
  353.  * \brief Phase of life of an EngineGroundMark
  354.  */
  355. enum EngineGroundMarkPhase
  356. {
  357.     //! Null phase
  358.     ENG_GR_MARK_PHASE_NULL = 0,
  359.     //! Increase
  360.     ENG_GR_MARK_PHASE_INC = 1,
  361.     //! Fixed
  362.     ENG_GR_MARK_PHASE_FIX = 2,
  363.     //! Decrease
  364.     ENG_GR_MARK_PHASE_DEC = 3
  365. };
  366.  
  367. /**
  368.  * \struct EngineGroundMark
  369.  * \brief A mark on ground drawn by the graphics engine
  370.  */
  371. struct EngineGroundMark
  372. {
  373.     //! If true, draw mark
  374.     bool                        draw = false;
  375.     //! Phase of life
  376.     EngineGroundMarkPhase  phase = ENG_GR_MARK_PHASE_NULL;
  377.     //! Times for 3 life phases
  378.     float                       delay[3] = {};
  379.     //! Fixed time
  380.     float                       fix = 0.0f;
  381.     //! Position for marks
  382.     Math::Vector                pos;
  383.     //! Radius of marks
  384.     float                       radius = 0.0f;
  385.     //! Color intensity
  386.     float                       intensity = 0.0f;
  387.     //! Draw position for marks
  388.     Math::Vector                drawPos;
  389.     //! Radius for  marks
  390.     float                       drawRadius = 0.0f;
  391.     //! Draw intensity for marks
  392.     float                       drawIntensity = 0.0f;
  393.     //! X dimension of table
  394.     int                         dx = 0;
  395.     //! Y dimension of table
  396.     int                         dy = 0;
  397.     //! Pointer to the table
  398.     char*                       table = nullptr;
  399.  
  400.     void LoadDefault()
  401.     {
  402.         *this = EngineGroundMark();
  403.     }
  404. };
  405.  
  406. /**
  407.  * \enum EngineTextureMapping
  408.  * \brief Type of texture mapping
  409.  */
  410. enum EngineTextureMapping
  411. {
  412.     ENG_TEX_MAPPING_X       = 1,
  413.     ENG_TEX_MAPPING_Y       = 2,
  414.     ENG_TEX_MAPPING_Z       = 3,
  415.     ENG_TEX_MAPPING_1X      = 4,
  416.     ENG_TEX_MAPPING_1Y      = 5,
  417.     ENG_TEX_MAPPING_1Z      = 6
  418. };
  419.  
  420.  
  421. /**
  422.  * \enum EngineMouseType
  423.  * \brief Type of mouse cursor displayed in-game
  424.  */
  425. enum EngineMouseType
  426. {
  427.     //! Normal cursor (arrow)
  428.     ENG_MOUSE_NORM      = 0,
  429.     //! Busy
  430.     ENG_MOUSE_WAIT      = 1,
  431.     //! Edit (I-beam)
  432.     ENG_MOUSE_EDIT      = 2,
  433.     //! Hand
  434.     ENG_MOUSE_HAND      = 3,
  435.     //! Small cross
  436.     ENG_MOUSE_CROSS     = 4,
  437.     //! TODO: ?
  438.     ENG_MOUSE_SHOW      = 5,
  439.     //! Crossed out sign
  440.     ENG_MOUSE_NO        = 6,
  441.     //! Resize
  442.     ENG_MOUSE_MOVE      = 7,
  443.     //! Resize horizontally
  444.     ENG_MOUSE_MOVEH     = 8,
  445.     //! Resize vertically
  446.     ENG_MOUSE_MOVEV     = 9,
  447.     //! Resize diagonally bottom-left to top-right
  448.     ENG_MOUSE_MOVED     = 10,
  449.     //! Resize diagonally top-left to bottom-right
  450.     ENG_MOUSE_MOVEI     = 11,
  451.     //! Scroll to the left
  452.     ENG_MOUSE_SCROLLL   = 12,
  453.     //! Scroll to the right
  454.     ENG_MOUSE_SCROLLR   = 13,
  455.     //! Scroll up
  456.     ENG_MOUSE_SCROLLU   = 14,
  457.     //! Scroll down
  458.     ENG_MOUSE_SCROLLD   = 15,
  459.     //! Larger crosshair
  460.     ENG_MOUSE_TARGET    = 16,
  461.  
  462.     //! Number of items in enum
  463.     ENG_MOUSE_COUNT
  464. };
  465.  
  466.  
  467. /**
  468.  * \class CEngine
  469.  * \brief The graphics engine
  470.  *
  471.  * This is the main class for graphics engine. It is responsible for drawing the 3D scene,
  472.  * setting various render states, and facilitating the drawing of 2D interface.
  473.  *
  474.  * It uses a lower-level CDevice object which is implementation-independent core engine.
  475.  *
  476.  * \section Scene 3D Scene
  477.  *
  478.  * The 3D scene is drawn with view coordinates set from camera position in 3D space and
  479.  * a perspective projection matrix. The world matrix depends on the object drawn.
  480.  * The coordinate system is left-handed: X axis is to the right, Y axis to the top and Z axis
  481.  * is into the screen (Z = 0 is the sceen surface).
  482.  *
  483.  * In general, the 3D scene is composed of the following things:
  484.  *  - sky background (gradient or texture image)
  485.  *  - planets orbiting in the sky (drawn by CPlanet)
  486.  *  - terrain - ground of the game level (part of engine objects)
  487.  *  - main scene objects - robots, buildings, etc. (engine objects)
  488.  *  - water/lava (drawn by CWater)
  489.  *  - cloud layer (drawn by CCloud)
  490.  *  - fire, lightning and particle effects (CPyro, CLightning and CParticle)
  491.  *  - foreground image overlaid onto the scene at the end - for example, aiming crosshairs
  492.  *  - 2D interface controls available in-game
  493.  *  - mouse cursor
  494.  *  - animated highlight box of the selected object(s)
  495.  *
  496.  * \section Interface 2D Interface
  497.  *
  498.  * The 2D interface is drawn in fixed XY coordinates, independent from window size.
  499.  * Lower-left corner of the screen is (0,0) and upper-right corner is (1,1).
  500.  * Matrices for world, view and projection are therefore fixed and never change.
  501.  *
  502.  * The class tracks the change of window coordinates and conversion functions
  503.  * between the window and interface coordinates are provided.
  504.  *
  505.  * Interface drawing is delegated to CInterface class and particular controls
  506.  * are instances of CControl class. The source code for these classes is in
  507.  * src/ui directory.
  508.  *
  509.  * \section Objects Engine Objects
  510.  *
  511.  * The 3D scene is composed of objects which are basically collections of triangles forming
  512.  * a surface or simply independent triangles in space.
  513.  *
  514.  * Objects are uniquely identified by object rank obtained at object creation. Creating an
  515.  * object equals to allocating space for EngineObject structure which holds object parameters.
  516.  *
  517.  * Object's geometric data is stored as a separate object -- base engine object. Each object
  518. * must reference a valid base engine object or an empty base engine object (with rank = -1).
  519. * This many-to-one association allows to share same geometric data (e.g. from same model)
  520. * across objects.
  521. *
  522. * Base engine object data is stored in a 4-tier tree which splits the data describing triangles.
  523. *
  524. * The 4 tiers contain the following information:
  525. *  - level 1 (EngineBaseObject) - geometric statistics
  526. *  - level 2 (EngineBaseObjTexTier) - two textures (names and structs) applied to triangles,
  527. *  - level 3 (EngineBaseObjDataTier) - type of object*, material, render state and the actual vertex data
  528. *
  529. *  *NOTE: type of object in this context means only the internal type in 3D engine. It is not related
  530. *  to CObject types.
  531. *
  532. * Last tier containing vertex data contains also an ID of static buffer holding the data.
  533. * The static buffer is created and updated with new data as needed.
  534. *
  535. * Such tiered structure complicates loops over all object data, but saves a lot of memory and
  536. * optimizes the rendering process.
  537. *
  538. * \section Shadows Shadows
  539. *
  540. * Each engine object can be associated with a shadow (EngineShadow). Like objects, shadows are
  541. * identified by their rank obtained upon creation.
  542. *
  543. * Shadows are drawn as circular spots on the ground, except for shadows for worms, which have
  544. * special mode for them.
  545. *
  546. * \section RenderStates Render States
  547. *
  548. * Almost every primitive drawn on screen is drawn in state set through EngineRenderState enum.
  549. * In some functions, custom modes are still set, using CDevice's SetRenderState. However, it
  550.  * will be subject to removal in the future. Generally, setting render states should be minimized
  551.  * to avoid unnecessary overhead.
  552.  *
  553.  * Some states are clearly the result of legacy drawing and texturing methods. For example, TTEXTURE
  554.  * states should really be removed and the textures changed to ones with alpha channel. In the future,
  555.  * the whole modesetting code will probably be refactored to something more maintainable.
  556.  *
  557.  * \section Textures Textures
  558.  *
  559.  * Textures are loaded from a texture subdir in data directory. In the old code, textures were identified
  560.  * by file name and loaded using some D3D util code. With new code and OpenGL backend, this approach is not
  561.  * efficient - name comparison, etc. takes a lot of time. In the future, textures should be loaded once
  562.  * at object creation time, and then referenced to as Texture structs, or even as unsigned int ID's
  563. * which is what OpenGL actually wants. The old method is kept for now, with mapping between texture names
  564. * and texture structs but it will also be subject to refactoring in the future.
  565. */
  566. class CEngine : public CSingleton<CEngine>
  567. {
  568. public:
  569.    CEngine(CApplication* app, CSystemUtils* systemUtils);
  570.    ~CEngine();
  571.  
  572.    //! Sets the device to be used
  573.    void            SetDevice(CDevice* device);
  574.    //! Returns the current device
  575.    CDevice*        GetDevice();
  576.  
  577.    //! Returns the text rendering engine
  578.    CText*          GetText();
  579.    COldModelManager* GetModelManager();
  580.    CPyroManager*   GetPyroManager();
  581.    //! Returns the light manager
  582.    CLightManager*  GetLightManager();
  583.    //! Returns the particle manager
  584.    CParticle*      GetParticle();
  585.    //! Returns the terrain manager
  586.    CTerrain*       GetTerrain();
  587.    //! Returns the water manager
  588.    CWater*         GetWater();
  589.    //! Returns the lighting manager
  590.    CLightning*     GetLightning();
  591.    //! Returns the planet manager
  592.    CPlanet*        GetPlanet();
  593.    //! Returns the fog manager
  594.    CCloud*         GetCloud();
  595.  
  596.    //! Sets the terrain object
  597.    void            SetTerrain(CTerrain* terrain);
  598.  
  599.  
  600.    //! Performs the initialization; must be called after device was set
  601.    bool            Create();
  602.    //! Frees all resources before exit
  603.    void            Destroy();
  604.  
  605.  
  606.    //! Called once per frame, the call is the entry point for rendering
  607.    void            Render();
  608.  
  609.  
  610.    //! Processes incoming event
  611.    bool            ProcessEvent(const Event& event);
  612.  
  613.    //! Called once per frame, the call is the entry point for animating the scene
  614.    void            FrameUpdate();
  615.  
  616.  
  617.    //! Writes a screenshot containing the current frame
  618.    void            WriteScreenShot(const std::string& fileName);
  619.  
  620.  
  621.    //@{
  622.    //! Management of animation pause mode
  623.    void            SetPause(bool pause);
  624.    bool            GetPause();
  625.    //@}
  626.  
  627.    //@{
  628.    //! Management of displaying statistic information
  629.    void            SetShowStats(bool show);
  630.    bool            GetShowStats();
  631.    //@}
  632.  
  633.    //! Enables/disables rendering
  634.    void            SetRenderEnable(bool enable);
  635.  
  636.    void            SetRenderInterface(bool enable);
  637.    bool            GetRenderInterface();
  638.  
  639.    //! Management of "screenshot mode" (disables interface particle rendering)
  640.    //@{
  641.    void            SetScreenshotMode(bool screenshotMode);
  642.    bool            GetScreenshotMode();
  643.    //@}
  644.  
  645.    //! Returns current size of viewport window
  646.    Math::IntPoint   GetWindowSize();
  647.  
  648.    //@{
  649.    //! Conversion functions between window and interface coordinates
  650.    /** Window coordinates are from top-left (0,0) to bottom-right (w,h) - size of window
  651.        Interface cords are from bottom-left (0,0) to top-right (1,1) - and do not depend on window size */
  652.    Math::Point     WindowToInterfaceCoords(Math::IntPoint pos);
  653.    Math::IntPoint  InterfaceToWindowCoords(Math::Point pos);
  654.    //@}
  655.  
  656.    //@{
  657.    //! Conversion functions between window and interface sizes
  658.    /** Unlike coordinate conversions, this is only scale conversion, not translation and scale. */
  659.    Math::Point      WindowToInterfaceSize(Math::IntPoint size);
  660.    Math::IntPoint   InterfaceToWindowSize(Math::Point size);
  661.    //@}
  662.  
  663.    //! Increments the triangle counter for the current frame
  664.    void            AddStatisticTriangle(int count);
  665.    //! Returns the number of triangles in current frame
  666.    int             GetStatisticTriangle();
  667.  
  668.    //! Sets the coordinates to display in stats window
  669.    void            SetStatisticPos(Math::Vector pos);
  670.  
  671.    //! Sets text to display as mission timer
  672.    void            SetTimerDisplay(const std::string& text);
  673.  
  674.  
  675.    /* *************** New mesh interface *************** */
  676.    //! Add new instance of static mesh
  677.    /**
  678.     * Static meshes never change their geometry or texture mapping,
  679.     * so specific instances can share mesh data.
  680.     *
  681.     * @param mesh mesh data
  682.     * @param key key unique per object class
  683.     * @return mesh instance handle
  684.     */
  685.    int AddStaticMesh(const std::string& key, const Gfx::CModelMesh* mesh, const Math::Matrix& worldMatrix);
  686.  
  687.    //! Removes given static mesh
  688.    void DeleteStaticMesh(int meshHandle);
  689.  
  690.    //! Adds a shadow spot to mesh
  691.    void AddStaticMeshShadowSpot(int meshHandle, const Gfx::ModelShadowSpot& shadowSpot);
  692.  
  693.    //! Returns static mesh world matrix
  694.    const Math::Matrix& GetStaticMeshWorldMatrix(int meshHandle);
  695.  
  696.    //! Sets transparency for static mesh
  697.    void SetStaticMeshTransparency(int meshHandle, float value);
  698.  
  699.  
  700.    /* *************** Object management *************** */
  701.  
  702.    // Base objects
  703.  
  704.    //! Creates a base object and returns its rank
  705.    int             CreateBaseObject();
  706.    //! Deletes a base object
  707.    void            DeleteBaseObject(int baseObjRank);
  708.    //! Deletes all base objects
  709.    void            DeleteAllBaseObjects();
  710.  
  711.    //! Copies geometry between two base objects
  712.    void            CopyBaseObject(int sourceBaseObjRank, int destBaseObjRank);
  713.  
  714.    //! Adds triangles to given object with the specified params
  715.    void AddBaseObjTriangles(int baseObjRank, const std::vector<Gfx::ModelTriangle>& triangles);
  716.  
  717.    //! Adds a tier 4 engine object directly
  718.    void            AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer,
  719.                                    std::string tex1Name, std::string tex2Name,
  720.                                    bool globalUpdate);
  721.  
  722.    // Objects
  723.  
  724.    //! Print debug info about an object
  725.    void            DebugObject(int objRank);
  726.  
  727.    //! Creates a new object and returns its rank
  728.    int             CreateObject();
  729.    //! Deletes all objects, shadows and ground spots
  730.    void            DeleteAllObjects();
  731.    //! Deletes the given object
  732.    void            DeleteObject(int objRank);
  733.  
  734.    //@{
  735.    //! Management of the base object rank for engine object
  736.    void            SetObjectBaseRank(int objRank, int baseObjRank);
  737.    int             GetObjectBaseRank(int objRank);
  738.    //@}
  739.  
  740.    //@{
  741.    //! Management of engine object type
  742.    void            SetObjectType(int objRank, EngineObjectType type);
  743.    EngineObjectType GetObjectType(int objRank);
  744.    //@}
  745.  
  746.    //@{
  747.    //! Management of object transform
  748.    void            SetObjectTransform(int objRank, const Math::Matrix& transform);
  749.    void            GetObjectTransform(int objRank, Math::Matrix& transform);
  750.    //@}
  751.  
  752.    //! Sets drawWorld for given object
  753.    void            SetObjectDrawWorld(int objRank, bool draw);
  754.    //! Sets drawFront for given object
  755.    void            SetObjectDrawFront(int objRank, bool draw);
  756.  
  757.    //! Sets the transparency level for given object
  758.    void            SetObjectTransparency(int objRank, float value);
  759.  
  760.    //! Returns the bounding box for an object
  761.    void            GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max);
  762.  
  763.    //! Returns the total number of triangles of given object
  764.    int             GetObjectTotalTriangles(int objRank);
  765.  
  766.    //! Returns the first found tier 4 engine object for the given params or nullptr if not found
  767.    EngineBaseObjDataTier* FindTriangles(int objRank, const Material& material,
  768.                                         int state, std::string tex1Name, std::string tex2Name);
  769.  
  770.    //! Returns a partial list of triangles for given object
  771.    int             GetPartialTriangles(int objRank, float percent, int maxCount,
  772.                                        std::vector<EngineTriangle>& triangles);
  773.  
  774.    //! Changes the 2nd texure for given object
  775.    void            ChangeSecondTexture(int objRank, const std::string& tex2Name);
  776.  
  777.    //! Changes (recalculates) texture mapping for given object
  778.    void            ChangeTextureMapping(int objRank, const Material& mat, int state,
  779.                                         const std::string& tex1Name, const std::string& tex2Name,
  780.                                         EngineTextureMapping mode,
  781.                                         float au, float bu, float av, float bv);
  782.  
  783.    //! Changes texture mapping for robot tracks
  784.    void            TrackTextureMapping(int objRank, const Material& mat, int state,
  785.                                        const std::string& tex1Name, const std::string& tex2Name,
  786.                                        EngineTextureMapping mode,
  787.                                        float pos, float factor, float tl, float ts, float tt);
  788.  
  789.    //! Detects the target object that is selected with the mouse
  790.    /** Returns the rank of the object or -1. */
  791.    int             DetectObject(Math::Point mouse, Math::Vector& targetPos, bool terrain = false);
  792.  
  793.    //! Creates a shadow for the given object
  794.    void            CreateShadowSpot(int objRank);
  795.    //! Deletes the shadow for given object
  796.    void            DeleteShadowSpot(int objRank);
  797.  
  798.    //@{
  799.    //! Management of different shadow params
  800.    void            SetObjectShadowSpotHide(int objRank, bool hide);
  801.    void            SetObjectShadowSpotType(int objRank, EngineShadowType type);
  802.    void            SetObjectShadowSpotPos(int objRank, const Math::Vector& pos);
  803.    void            SetObjectShadowSpotAngle(int objRank, float angle);
  804.    void            SetObjectShadowSpotRadius(int objRank, float radius);
  805.    void            SetObjectShadowSpotIntensity(int objRank, float intensity);
  806.    void            SetObjectShadowSpotHeight(int objRank, float height);
  807.    void            UpdateObjectShadowSpotNormal(int objRank);
  808.    //@}
  809.  
  810.    //! Lists the ranks of objects and subobjects selected
  811.    void            SetHighlightRank(int* rankList);
  812.    //! Returns the highlighted rectangle
  813.    bool            GetHighlight(Math::Point& p1, Math::Point& p2);
  814.  
  815.    //! Deletes all ground spots
  816.    void            DeleteAllGroundSpots();
  817.    //! Creates a new ground spot and returns its rank
  818.    int             CreateGroundSpot();
  819.    //! Deletes the given ground spot
  820.    void            DeleteGroundSpot(int rank);
  821.  
  822.    //@{
  823.    //! Management of different ground spot params
  824.    void            SetObjectGroundSpotPos(int rank, const Math::Vector& pos);
  825.    void            SetObjectGroundSpotRadius(int rank, float radius);
  826.    void            SetObjectGroundSpotColor(int rank, const Color& color);
  827.    void            SetObjectGroundSpotMinMax(int rank, float min, float max);
  828.    void            SetObjectGroundSpotSmooth(int rank, float smooth);
  829.    //@}
  830.  
  831.    //! Creates the ground mark with the given params
  832.    void            CreateGroundMark(Math::Vector pos, float radius,
  833.                                     float delay1, float delay2, float delay3,
  834.                                     int dx, int dy, char* table);
  835.    //! Deletes the ground mark
  836.    void            DeleteGroundMark(int rank);
  837.  
  838.    //! Updates the state after creating objects
  839.    void            Update();
  840.  
  841.  
  842.    /* *************** Mode setting *************** */
  843.  
  844.    //! Sets the current rendering state
  845.    void            SetState(int state, const Color& color = Color(1.0f, 1.0f, 1.0f, 1.0f));
  846.  
  847.    //! Sets the current material
  848.    void            SetMaterial(const Material& mat);
  849.  
  850.    //! Specifies the location and direction of view
  851.    void SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec);
  852.  
  853.    //! Updates the textures used for drawing ground spot
  854.    void        UpdateGroundSpotTextures();
  855.  
  856.    //! Loads texture, creating it if not already present
  857.    Texture         LoadTexture(const std::string& name);
  858.    //! Loads texture from existing image
  859.    Texture         LoadTexture(const std::string& name, CImage* image);
  860.    //! Loads texture, creating it with given params if not already present
  861.    Texture         LoadTexture(const std::string& name, const TextureCreateParams& params);
  862.    //! Loads all necessary textures
  863.    bool            LoadAllTextures();
  864.  
  865.    //! Changes colors in a texture
  866.    //@{
  867.    bool            ChangeTextureColor(const std::string& texName,
  868.                                       const std::string& srcName,
  869.                                       Color colorRef1, Color colorNew1,
  870.                                       Color colorRef2, Color colorNew2,
  871.                                       float tolerance1, float tolerance2,
  872.                                       Math::Point ts, Math::Point ti,
  873.                                       Math::Point *exclude = nullptr,
  874.                                       float shift = 0.0f, bool hsv = false);
  875.    bool            ChangeTextureColor(const std::string& texName,
  876.                                       Color colorRef1, Color colorNew1,
  877.                                       Color colorRef2, Color colorNew2,
  878.                                       float tolerance1, float tolerance2,
  879.                                       Math::Point ts, Math::Point ti,
  880.                                       Math::Point *exclude = nullptr,
  881.                                       float shift = 0.0f, bool hsv = false);
  882.    //@}
  883.  
  884.    //! Sets texture for given stage; if not present in cache, the texture is loaded
  885.    /** If loading fails, returns false. */
  886.    bool            SetTexture(const std::string& name, int stage = 0);
  887.    //! Sets texture for given stage
  888.    void            SetTexture(const Texture& tex, int stage = 0);
  889.  
  890.    //! Deletes the given texture, unloading it and removing from cache
  891.    void            DeleteTexture(const std::string& texName);
  892.    //! Deletes the given texture, unloading it and removing from cache
  893.    void            DeleteTexture(const Texture& tex);
  894.  
  895.    //! Creates or updates the given texture with given image data
  896.    void            CreateOrUpdateTexture(const std::string& texName, CImage* img);
  897.  
  898.    //! Empties the texture cache
  899.    void            FlushTextureCache();
  900.  
  901.    //! Defines of the distance field of vision
  902.    void            SetTerrainVision(float vision);
  903.  
  904.    //@{
  905.    //! Management of camera vertical field-of-view angle.
  906.    /** This is specified in radians.
  907.    Horizontal FoV is calculated based on vertical FoV and aspect ratio.
  908.    0.75 = normal
  909.    1.50 = wide-angle */
  910.    void            SetFocus(float focus);
  911.    //! Deprecated alias for GetVFovAngle
  912.    float           GetFocus();
  913.    float           GetVFovAngle();
  914.    float           GetHFovAngle();
  915.    //@}
  916.  
  917.    //@{
  918.    //! Management of the global mode of contamination
  919.    // NOTE: This is an user configuration setting
  920.    void            SetDirty(bool mode);
  921.    bool            GetDirty();
  922.    //@}
  923.  
  924.    //@{
  925.    //! Management of the global mode of horizontal fog patches
  926.    // NOTE: This is an user configuration setting
  927.    void            SetFog(bool mode);
  928.    bool            GetFog();
  929.    //@}
  930.  
  931.    //@{
  932.    //! Management of the global mode of secondary texturing
  933.    void            SetSecondTexture(const std::string& texNum);
  934.    const std::string& GetSecondTexture();
  935.    //@}
  936.  
  937.    //@{
  938.    //! Management of view mode
  939.    void            SetRankView(int rank);
  940.    int             GetRankView();
  941.    //@}
  942.  
  943.    //! Whether to draw the world
  944.    void            SetDrawWorld(bool draw);
  945.  
  946.    //! Whether to draw the world on the interface
  947.    void            SetDrawFront(bool draw);
  948.  
  949.    //@{
  950.    //! Ambient color management
  951.    void            SetAmbientColor(const Color& color, int rank = 0);
  952.    Color           GetAmbientColor(int rank = 0);
  953.    //@}
  954.  
  955.    //@{
  956.    //! Color management under water
  957.    void            SetWaterAddColor(const Color& color);
  958.    Color           GetWaterAddColor();
  959.    //@}
  960.  
  961.    //@{
  962.    //! Management of the fog color
  963.    void            SetFogColor(const Color& color, int rank = 0);
  964.    Color           GetFogColor(int rank = 0);
  965.    //@}
  966.  
  967.    //@{
  968.    //! Management of the depth of field.
  969.    /** Beyond this distance, nothing is visible.
  970.        Shortly (according SetFogStart), one enters the fog. */
  971.    void            SetDeepView(float length, int rank = 0, bool ref=false);
  972.    float           GetDeepView(int rank = 0);
  973.    //@}
  974.  
  975.  
  976.    //@{
  977.    //! Management the start of fog.
  978.    /** With 0.0, the fog from the point of view (fog max).
  979.        With 1.0, the fog from the depth of field (no fog). */
  980.    void            SetFogStart(float start, int rank = 0);
  981.    float           GetFogStart(int rank = 0);
  982.    //@}
  983.  
  984.    //@{
  985.    //! Management of the background image to use
  986.    void            SetBackground(const std::string& name, Color up = Color(), Color down = Color(),
  987.                                  Color cloudUp = Color(), Color cloudDown = Color(),
  988.                                  bool full = false, bool scale = false);
  989.    void            GetBackground(std::string& name, Color& up, Color& down,
  990.                                  Color& cloudUp, Color& cloudDown,
  991.                                  bool& full, bool& scale);
  992.    //@}
  993.  
  994.    //! Specifies the name of foreground texture
  995.    void            SetForegroundName(const std::string& name);
  996.    //! Specifies whether to draw the foreground
  997.    void            SetOverFront(bool front);
  998.    //! Sets the foreground overlay color
  999.    void            SetOverColor(const Color& color = Color(), int mode = ENG_RSTATE_TCOLOR_BLACK);
  1000.  
  1001.    //@{
  1002.    //! Management of the particle density
  1003.    // NOTE: This is an user configuration setting
  1004.    void            SetParticleDensity(float value);
  1005.    float           GetParticleDensity();
  1006.    //@}
  1007.  
  1008.    //! Adapts particle factor according to particle density
  1009.    float           ParticleAdapt(float factor);
  1010.  
  1011.    //@{
  1012.    //! Management of the distance of clipping.
  1013.    // NOTE: This is an user configuration setting
  1014.    void            SetClippingDistance(float value);
  1015.    float           GetClippingDistance();
  1016.    //@}
  1017.  
  1018.    //@{
  1019.    //! Management the texture filter mode
  1020.    // NOTE: This is an user configuration setting
  1021.    void            SetTextureFilterMode(TexFilter value);
  1022.    TexFilter       GetTextureFilterMode();
  1023.    //@}
  1024.  
  1025.    //@{
  1026.    //! Management the mipmap level for textures
  1027.    // NOTE: This is an user configuration setting
  1028.    void            SetTextureMipmapLevel(int value);
  1029.    int             GetTextureMipmapLevel();
  1030.    //@}
  1031.  
  1032.    //@{
  1033.    //! Management the anisotropy level for textures
  1034.    // NOTE: This is an user configuration setting
  1035.    void            SetTextureAnisotropyLevel(int value);
  1036.    int             GetTextureAnisotropyLevel();
  1037.    //@}
  1038.  
  1039.    //@{
  1040.    //! Management of shadow mapping
  1041.    // NOTE: These are user configuration settings
  1042.    bool            IsShadowMappingSupported();
  1043.    void            SetShadowMapping(bool value);
  1044.    bool            GetShadowMapping();
  1045.    void            SetShadowMappingOffscreen(bool value);
  1046.    bool            GetShadowMappingOffscreen();
  1047.    void            SetShadowMappingOffscreenResolution(int resolution);
  1048.    int             GetShadowMappingOffscreenResolution();
  1049.    bool            IsShadowMappingQualitySupported();
  1050.    void            SetShadowMappingQuality(bool value);
  1051.    bool            GetShadowMappingQuality();
  1052.    void            SetTerrainShadows(bool value);
  1053.    bool            GetTerrainShadows();
  1054.    //@}
  1055.  
  1056.    //@{
  1057.    //! Management of vertical synchronization
  1058.    // NOTE: This is an user configuration setting
  1059.    void            SetVSync(int value);
  1060.    int             GetVSync();
  1061.    //@}
  1062.  
  1063.    //@{
  1064.    //! Management of shadow color
  1065.    // NOTE: This is a setting configurable only in INI file
  1066.    void            SetShadowColor(float value);
  1067.    float           GetShadowColor();
  1068.    //@}
  1069.  
  1070.    //@{
  1071.    //! Management of shadow range
  1072.    // NOTE: This is a setting configurable only in INI file
  1073.    void            SetShadowRange(float value);
  1074.    float           GetShadowRange();
  1075.    //@}
  1076.  
  1077.    //@{
  1078.    //! Management of shadow range
  1079.    // NOTE: This is an user configuration setting
  1080.    void            SetMultiSample(int value);
  1081.    int             GetMultiSample();
  1082.    //@}
  1083.  
  1084.    //@{
  1085.    //! Management the mode of background
  1086.    void            SetBackForce(bool present);
  1087.    bool            GetBackForce();
  1088.    //@}
  1089.  
  1090.    //@{
  1091.    //! Managing the mode of dynamic lights.
  1092.    // NOTE: This is an user configuration setting
  1093.    void            SetLightMode(bool present);
  1094.    bool            GetLightMode();
  1095.    //@}
  1096.  
  1097.    //@{
  1098.    //! Management of the indentation mode while editing (CEdit)
  1099.    // NOTE: This is an user configuration setting
  1100.    // TODO: Move to CSettings
  1101.    void            SetEditIndentMode(bool autoIndent);
  1102.    bool            GetEditIndentMode();
  1103.    //@}
  1104.  
  1105.    //@{
  1106.    //! Management of tab indent when editing (CEdit)
  1107.    // NOTE: This is an user configuration setting
  1108.    // TODO: Move to CSettings
  1109.    void            SetEditIndentValue(int value);
  1110.    int             GetEditIndentValue();
  1111.    //@}
  1112.  
  1113.    //@{
  1114.    //! Management of precision of robot tracks
  1115.    void            SetTracePrecision(float factor);
  1116.    float           GetTracePrecision();
  1117.    //@}
  1118.  
  1119.    //@{
  1120.    //! Management of mouse cursor type
  1121.    void            SetMouseType(EngineMouseType type);
  1122.    EngineMouseType GetMouseType();
  1123.    //@}
  1124.  
  1125.    //@{
  1126.    //! Management of pause blur
  1127.    void            SetPauseBlurEnabled(bool enable);
  1128.    bool            GetPauseBlurEnabled();
  1129.    //@}
  1130.  
  1131.    //! Returns the view matrix
  1132.    const Math::Matrix& GetMatView();
  1133.    //! Returns the projection matrix
  1134.    const Math::Matrix& GetMatProj();
  1135.    //! Returns the camera center point
  1136.    TEST_VIRTUAL Math::Vector GetEyePt();
  1137.    //! Returns the camera target point
  1138.    TEST_VIRTUAL Math::Vector GetLookatPt();
  1139.    //! Returns the horizontal direction angle of view
  1140.    float           GetEyeDirH();
  1141.    //! Returns the vertical direction angle of view
  1142.    float           GetEyeDirV();
  1143.    //! Indicates whether a point is visible
  1144.    bool            IsVisiblePoint(const Math::Vector& pos);
  1145.  
  1146.    //! Resets the projection matrix after changes
  1147.    void            UpdateMatProj();
  1148.  
  1149.    //! Updates the scene after a change of parameters
  1150.    void            ApplyChange();
  1151.  
  1152.    void            RenderDebugSphere(const Math::Sphere&, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f});
  1153.    void            RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f});
  1154.  
  1155.    void            SetDebugLights(bool debugLights);
  1156.    bool            GetDebugLights();
  1157.    void            DebugDumpLights();
  1158.  
  1159.    void            SetDebugResources(bool debugResources);
  1160.    bool            GetDebugResources();
  1161.  
  1162.    void            SetDebugGoto(bool debugGoto);
  1163.    bool            GetDebugGoto();
  1164.    void            AddDebugGotoLine(std::vector<Gfx::VertexCol> line);
  1165.    void            SetDebugGotoBitmap(std::unique_ptr<CImage> debugImage);
  1166.  
  1167.    void            SetWindowCoordinates();
  1168.    void            SetInterfaceCoordinates();
  1169.  
  1170.    void            EnablePauseBlur();
  1171.    void            DisablePauseBlur();
  1172.  
  1173. protected:
  1174.    //! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
  1175.    /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/
  1176.    void            ResetAfterVideoConfigChanged();
  1177.  
  1178.    //! Prepares the interface for 3D scene
  1179.    void        Draw3DScene();
  1180.    //! Capture the 3D scene for pause blur
  1181.    void        Capture3DScene();
  1182.    //! Draw the 3D scene capured for pause blur
  1183.    void        DrawCaptured3DScene();
  1184.    //! Renders shadow map
  1185.    void        RenderShadowMap();
  1186.    //! Enables or disables shadow mapping
  1187.    void        UseShadowMapping(bool enable);
  1188.    //! Enables or disables MSAA
  1189.    void        UseMSAA(bool enable);
  1190.    //! Draw 3D object
  1191.    void        DrawObject(const EngineBaseObjDataTier& p4);
  1192.    //! Draws the user interface over the scene
  1193.    void        DrawInterface();
  1194.  
  1195.    //! Draws old-style shadow spots
  1196.    void        DrawShadowSpots();
  1197.    //! Draws the gradient background
  1198.    void        DrawBackground();
  1199.    //! Draws the gradient background
  1200.    void        DrawBackgroundGradient(const Color& up, const Color& down);
  1201.    //! Draws the image background
  1202.    void        DrawBackgroundImage();
  1203.    //! Draws all the planets
  1204.    void        DrawPlanet();
  1205.    //! Draws the image foreground
  1206.    void        DrawForegroundImage();
  1207.    //! Draws the foreground color
  1208.    void        DrawOverColor();
  1209.    //! Draws the rectangle of the object highlighted
  1210.    void        DrawHighlight();
  1211.    //! Draws the mouse cursor
  1212.    void        DrawMouse();
  1213.    //! Draw part of mouse cursor sprite
  1214.    void        DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon);
  1215.    //! Draw statistic texts
  1216.    void        DrawStats();
  1217.    //! Draw mission timer
  1218.    void        DrawTimer();
  1219.    void        RenderPendingDebugDraws();
  1220.  
  1221.    //! Creates a new tier 2 object (texture)
  1222.    EngineBaseObjTexTier&  AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name);
  1223.    //! Creates a new tier 3 object (data)
  1224.    EngineBaseObjDataTier& AddLevel3(EngineBaseObjTexTier &p3, EngineTriangleType type,
  1225.                                     const Material& material, int state);
  1226.  
  1227.    //! Create texture and add it to cache
  1228.    Texture CreateTexture(const std::string &texName, const TextureCreateParams &params, CImage* image = nullptr);
  1229.  
  1230.    //! Tests whether the given object is visible
  1231.    bool        IsVisible(int objRank);
  1232.  
  1233.    //! Detects whether an object is affected by the mouse
  1234.    bool        DetectBBox(int objRank, Math::Point mouse);
  1235.  
  1236.    //! Compute and return the 2D box on screen of any object
  1237.    bool        GetBBox2D(int objRank, Math::Point& min, Math::Point& max);
  1238.  
  1239.    //! Detects whether the mouse is in a triangle.
  1240.    bool        DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist, Math::Vector& pos);
  1241.  
  1242.    //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window
  1243.    /** The coordinated p2D.z gives the distance. */
  1244.    bool        TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D);
  1245.  
  1246.    //! Calculates the distances between the viewpoint and the origin of different objects
  1247.    void        ComputeDistance();
  1248.  
  1249.    //! Updates geometric parameters of objects (bounding box and radius)
  1250.    void        UpdateGeometry();
  1251.  
  1252.    //! Updates a given static buffer
  1253.    void        UpdateStaticBuffer(EngineBaseObjDataTier& p4);
  1254.  
  1255.    //! Updates static buffers of changed objects
  1256.    void        UpdateStaticBuffers();
  1257.  
  1258.    void            AddBaseObjTriangles(int baseObjRank, const std::vector<VertexTex2>& vertices,
  1259.                                        const Material& material, int state,
  1260.                                        std::string tex1Name, std::string tex2Name);
  1261.  
  1262.    int GetEngineState(const ModelTriangle& triangle);
  1263.  
  1264.    struct WriteScreenShotData
  1265.    {
  1266.        std::unique_ptr<CImage> img;
  1267.        std::string fileName;
  1268.    };
  1269.    static void WriteScreenShotThread(std::unique_ptr<WriteScreenShotData> data);
  1270.  
  1271.    //! Reloads all textures
  1272.    /** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/
  1273.    void ReloadAllTextures();
  1274.  
  1275. protected:
  1276.    CApplication*     m_app;
  1277.    CSystemUtils*     m_systemUtils;
  1278.    CSoundInterface*  m_sound;
  1279.    CDevice*          m_device;
  1280.    CTerrain*         m_terrain;
  1281.    std::unique_ptr<COldModelManager> m_modelManager;
  1282.    std::unique_ptr<CText>            m_text;
  1283.    std::unique_ptr<CLightManager>    m_lightMan;
  1284.    std::unique_ptr<CParticle>        m_particle;
  1285.    std::unique_ptr<CWater>           m_water;
  1286.    std::unique_ptr<CCloud>           m_cloud;
  1287.    std::unique_ptr<CLightning>       m_lightning;
  1288.    std::unique_ptr<CPlanet>          m_planet;
  1289.    std::unique_ptr<CPyroManager> m_pyroManager;
  1290.  
  1291.    //! Last encountered error
  1292.    std::string     m_error;
  1293.  
  1294.    SystemTimeStamp* m_lastFrameTime;
  1295.    SystemTimeStamp* m_currentFrameTime;
  1296.    int             m_fpsCounter;
  1297.    float           m_fps;
  1298.  
  1299.    //! Whether to show stats (FPS, etc)
  1300.    bool            m_showStats;
  1301.    //! Rendering enabled?
  1302.    bool            m_render;
  1303.    //! Render / hide the UI?
  1304.    bool            m_renderInterface;
  1305.  
  1306.    //! Screenshot mode?
  1307.    bool            m_screenshotMode;
  1308.  
  1309.    //! Projection matrix for 3D scene
  1310.    Math::Matrix    m_matProj;
  1311.    //! View matrix for 3D scene
  1312.    Math::Matrix    m_matView;
  1313.    //! Camera vertical field-of-view angle for 3D scene. A.k.a. m_vfov
  1314.    float           m_focus;
  1315.    //! Horizontal field-of-view angle, calculated from vertical FOV and aspect ratio
  1316.    float           m_hfov;
  1317.  
  1318.    //! Projection matrix for rendering shadow maps
  1319.    Math::Matrix    m_shadowProjMat;
  1320.    //! View matrix for rendering shadow maps
  1321.    Math::Matrix    m_shadowViewMat;
  1322.    //! Texture matrix for rendering shadow maps
  1323.    Math::Matrix    m_shadowTextureMat;
  1324.    //! Texture bias for sampling shadow maps
  1325.    Math::Matrix    m_shadowBias;
  1326.  
  1327.    //! Vertical synchronization controll
  1328.    int m_vsync;
  1329.  
  1330.    //! World matrix for 2D interface
  1331.    Math::Matrix    m_matWorldInterface;
  1332.    //! Projection matrix for 2D interface
  1333.    Math::Matrix    m_matProjInterface;
  1334.    //! View matrix for 2D interface
  1335.    Math::Matrix    m_matViewInterface;
  1336.  
  1337.    //! Current size of viewport window
  1338.    Math::IntPoint   m_size;
  1339.  
  1340.    //! Base objects (also level 1 tier list)
  1341.    std::vector<EngineBaseObject> m_baseObjects;
  1342.    //! Object parameters
  1343.    std::vector<EngineObject>     m_objects;
  1344.    //! Shadow list
  1345.    std::vector<EngineShadow>     m_shadowSpots;
  1346.    //! Ground spot list
  1347.    std::vector<EngineGroundSpot> m_groundSpots;
  1348.    //! Ground mark
  1349.    EngineGroundMark              m_groundMark;
  1350.  
  1351.    //! Location of camera
  1352.    Math::Vector    m_eyePt;
  1353.    //! Camera target
  1354.    Math::Vector    m_lookatPt;
  1355.    float           m_eyeDirH;
  1356.    float           m_eyeDirV;
  1357.    int             m_rankView;
  1358.    Color           m_ambientColor[2];
  1359.    Color           m_backColor[2];
  1360.    Color           m_fogColor[2];
  1361.    float           m_deepView[2];
  1362.    float           m_fogStart[2];
  1363.    Color           m_waterAddColor;
  1364.    int             m_statisticTriangle;
  1365.    Math::Vector    m_statisticPos;
  1366.    bool            m_updateGeometry;
  1367.    bool            m_updateStaticBuffers;
  1368.    bool            m_firstGroundSpot;
  1369.    std::string     m_secondTex;
  1370.    bool            m_backgroundFull;
  1371.    bool            m_backgroundScale;
  1372.    std::string     m_backgroundName;
  1373.    Texture         m_backgroundTex;
  1374.    Color           m_backgroundColorUp;
  1375.    Color           m_backgroundColorDown;
  1376.    Color           m_backgroundCloudUp;
  1377.    Color           m_backgroundCloudDown;
  1378.    bool            m_overFront;
  1379.    Color           m_overColor;
  1380.    int             m_overMode;
  1381.    std::string     m_foregroundName;
  1382.    Texture         m_foregroundTex;
  1383.    bool            m_drawWorld;
  1384.    bool            m_drawFront;
  1385.    float           m_terrainVision;
  1386.    bool            m_backForce;
  1387.    float           m_tracePrecision;
  1388.    bool            m_pauseBlurEnabled;
  1389.  
  1390.    bool            m_dirty;
  1391.    bool            m_fog;
  1392.    float           m_particleDensity;
  1393.    float           m_clippingDistance;
  1394.    bool            m_lightMode;
  1395.    bool            m_editIndentMode;
  1396.    int             m_editIndentValue;
  1397.  
  1398.    Texture         m_shadowMap;
  1399.  
  1400.    struct PendingDebugDraw
  1401.    {
  1402.        std::vector<VertexCol> vertices;
  1403.        std::vector<int> firsts;
  1404.        std::vector<int> counts;
  1405.    }
  1406.    m_pendingDebugDraws;
  1407.  
  1408.    //! Ranks of highlighted objects
  1409.    int             m_highlightRank[100];
  1410.    //! Highlight visible?
  1411.    bool            m_highlight;
  1412.    //! Time counter for highlight animation
  1413.    float           m_highlightTime;
  1414.    //@{
  1415.    //! Highlight rectangle points
  1416.    Math::Point     m_highlightP1;
  1417.    Math::Point     m_highlightP2;
  1418.    //@}
  1419.  
  1420.    //! Default texture create params
  1421.    TextureCreateParams m_defaultTexParams;
  1422.    //! Create params for terrain textures
  1423.    TextureCreateParams m_terrainTexParams;
  1424.    //! Requested texture mipmap level
  1425.    int m_textureMipmapLevel;
  1426.    //! Requested texture anisotropy level
  1427.    int m_textureAnisotropy;
  1428.    //! true if shadow mapping enabled
  1429.    bool m_shadowMapping;
  1430.    //! true enables offscreen shadow rendering
  1431.    bool m_offscreenShadowRendering;
  1432.    //! Offscreen shadow rendering resolution
  1433.    int m_offscreenShadowRenderingResolution;
  1434.    //! true enables higher quality shadows
  1435.    bool m_qualityShadows;
  1436.    //! true enables casting shadows by terrain
  1437.    bool m_terrainShadows;
  1438.    //! Shadow color
  1439.    float m_shadowColor;
  1440.    //! Shadow range
  1441.    float m_shadowRange;
  1442.    //! Number of samples for multisample rendering
  1443.    int m_multisample;
  1444.  
  1445.    //! Map of loaded textures (by name)
  1446.    std::map<std::string, Texture> m_texNameMap;
  1447.    //! Reverse map of loaded textures (by texture)
  1448.    std::map<Texture, std::string> m_revTexNameMap;
  1449.    //! Blacklist map of textures
  1450.    /** Textures on this list were not successful in first loading,
  1451.     *  so are disabled for subsequent load calls. */
  1452.    std::set<std::string> m_texBlacklist;
  1453.  
  1454.    //! Texture with mouse cursors
  1455.    Texture         m_miceTexture;
  1456.    //! Type of mouse cursor
  1457.    EngineMouseType m_mouseType;
  1458.  
  1459.    //! Last engine render state (-1 at the beginning of frame)
  1460.    int             m_lastState;
  1461.    //! Last color set with render state
  1462.    Color           m_lastColor;
  1463.    //! Last texture names for 2 used texture stages
  1464.    std::string     m_lastTexture[2];
  1465.    //! Last material
  1466.    Material        m_lastMaterial;
  1467.  
  1468.    //! True when drawing 2D UI
  1469.    bool            m_interfaceMode;
  1470.  
  1471.    bool            m_debugLights;
  1472.    bool            m_debugDumpLights;
  1473.    bool            m_debugCrashSpheres = false;
  1474.    bool            m_debugResources = false;
  1475.    bool            m_debugGoto = false;
  1476.  
  1477.    std::string     m_timerText;
  1478.  
  1479.    std::unordered_map<std::string, int> m_staticMeshBaseObjects;
  1480.  
  1481.    std::vector<std::vector<VertexCol>> m_displayGoto;
  1482.    std::unique_ptr<CImage> m_displayGotoImage;
  1483.  
  1484.    //! Pause the animation updates
  1485.    bool            m_pause = false;
  1486.  
  1487.    //! true means that current 3D scene was captured and is not to be rendered again
  1488.    bool            m_worldCaptured = false;
  1489.    //! true means that currently rendered world is to be captured
  1490.    bool            m_captureWorld = false;
  1491.    //! Texture with captured 3D world
  1492.    Texture         m_capturedWorldTexture;
  1493. };
  1494.  
  1495.  
  1496. } // namespace Gfx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement