summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine/engine.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/engine/engine.h')
-rw-r--r--src/graphics/engine/engine.h917
1 files changed, 615 insertions, 302 deletions
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 25c5e5d..3f21e0d 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1,5 +1,5 @@
// * This file is part of the COLOBOT source code
-// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// * Copyright (C) 2001-2008, Daniel ROUX& EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * This program is free software: you can redistribute it and/or modify
@@ -15,18 +15,20 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// engine.h
+/**
+ * \file graphics/engine/engine.h
+ * \brief Main graphics engine - Gfx::CEngine class
+ */
#pragma once
-
+#include "app/system.h"
#include "common/event.h"
#include "graphics/core/color.h"
#include "graphics/core/material.h"
#include "graphics/core/texture.h"
#include "graphics/core/vertex.h"
#include "math/intpoint.h"
-#include "math/intsize.h"
#include "math/matrix.h"
#include "math/point.h"
#include "math/vector.h"
@@ -35,12 +37,13 @@
#include <string>
#include <vector>
#include <map>
+#include <set>
class CApplication;
class CInstanceManager;
class CObject;
-class CSound;
+class CSoundInterface;
namespace Gfx {
@@ -57,14 +60,69 @@ class CTerrain;
/**
+ \enum EngineRenderState
+ \brief Render state of graphics engine
+
+ States are used for settings certain modes, for instance texturing and blending.
+ The enum is a bitmask and some of the states can be OR'd together. */
+enum EngineRenderState
+{
+ //! Normal opaque materials
+ ENG_RSTATE_NORMAL = 0,
+ //! The transparent texture (black = no)
+ ENG_RSTATE_TTEXTURE_BLACK = (1<<0),
+ //! The transparent texture (white = no)
+ ENG_RSTATE_TTEXTURE_WHITE = (1<<1),
+ //! The transparent diffuse color
+ ENG_RSTATE_TDIFFUSE = (1<<2),
+ //! Texture wrap
+ ENG_RSTATE_WRAP = (1<<3),
+ //! Texture borders with solid color
+ ENG_RSTATE_CLAMP = (1<<4),
+ //! Light texture (ambient max)
+ ENG_RSTATE_LIGHT = (1<<5),
+ //! Double black texturing
+ ENG_RSTATE_DUAL_BLACK = (1<<6),
+ //! Double white texturing
+ ENG_RSTATE_DUAL_WHITE = (1<<7),
+ //! Part 1 (no change in. MOD!)
+ ENG_RSTATE_PART1 = (1<<8),
+ //! Part 2
+ ENG_RSTATE_PART2 = (1<<9),
+ //! Part 3
+ ENG_RSTATE_PART3 = (1<<10),
+ //! Part 4
+ ENG_RSTATE_PART4 = (1<<11),
+ //! Double-sided face
+ ENG_RSTATE_2FACE = (1<<12),
+ //! Image using alpha channel
+ ENG_RSTATE_ALPHA = (1<<13),
+ //! Always use 2nd floor texturing
+ ENG_RSTATE_SECOND = (1<<14),
+ //! Causes the fog
+ ENG_RSTATE_FOG = (1<<15),
+ //! The transparent color (black = no)
+ ENG_RSTATE_TCOLOR_BLACK = (1<<16),
+ //! The transparent color (white = no)
+ ENG_RSTATE_TCOLOR_WHITE = (1<<17),
+ //! Mode for rendering text
+ ENG_RSTATE_TEXT = (1<<18),
+ //! Only opaque texture, no blending, etc.
+ ENG_RSTATE_OPAQUE_TEXTURE = (1<<19),
+ //! Only opaque color, no texture, blending, etc.
+ ENG_RSTATE_OPAQUE_COLOR = (1<<20)
+};
+
+
+/**
\enum EngineTriangleType
\brief Type of triangles drawn for engine objects */
enum EngineTriangleType
{
//! Triangles
- ENG_TRIANGLE_TYPE_6T = 1,
+ ENG_TRIANGLE_TYPE_TRIANGLES = 1,
//! Surfaces
- ENG_TRIANGLE_TYPE_6S = 2
+ ENG_TRIANGLE_TYPE_SURFACE = 2
};
/**
@@ -76,16 +134,16 @@ struct EngineTriangle
Gfx::VertexTex2 triangle[3];
//! Material
Gfx::Material material;
- //! Render state (TODO: ?)
+ //! Render state
int state;
//! 1st texture
- Gfx::Texture tex1;
+ std::string tex1Name;
//! 2nd texture
- Gfx::Texture tex2;
+ std::string tex2Name;
EngineTriangle()
{
- state = 0;
+ state = Gfx::ENG_RSTATE_NORMAL;
}
};
@@ -115,6 +173,8 @@ enum EngineObjectType
\brief Object drawn by the graphics engine */
struct EngineObject
{
+ //! If true, object is valid in objects vector
+ bool used;
//! If true, the object is drawn
bool visible;
//! If true, object is behind the 2D interface
@@ -127,7 +187,7 @@ struct EngineObject
Gfx::EngineObjectType type;
//! Transformation matrix
Math::Matrix transform;
- //! Distance view - origin (TODO: ?)
+ //! Distance to object from eye point
float distance;
//! Bounding box min (origin 0,0,0 always included)
Math::Vector bboxMin;
@@ -140,15 +200,27 @@ struct EngineObject
//! Transparency of the object [0, 1]
float transparency;
+ //! Calls LoadDefault()
EngineObject()
{
+ LoadDefault();
+ }
+
+ //! Loads default values
+ inline void LoadDefault()
+ {
+ used = false;
visible = false;
drawWorld = false;
drawFront = false;
totalTriangles = 0;
+ type = Gfx::ENG_OBJTYPE_NULL;
+ transform.LoadIdentity();
+ bboxMax.LoadZero();
+ bboxMin.LoadZero();
distance = 0.0f;
radius = 0.0f;
- shadowRank = 0;
+ shadowRank = -1;
transparency = 0.0f;
}
};
@@ -157,31 +229,22 @@ struct EngineObjLevel1;
struct EngineObjLevel2;
struct EngineObjLevel3;
struct EngineObjLevel4;
-struct EngineObjLevel5;
-
-/**
- \struct EngineObjLevel5
- \brief Tier 5 of object tree */
-struct EngineObjLevel5
-{
- Gfx::Material material;
- int state;
- Gfx::EngineTriangleType type;
- std::vector<Gfx::VertexTex2> vertices;
-
- EngineObjLevel5();
-};
/**
\struct EngineObjLevel4
\brief Tier 4 of object tree */
struct EngineObjLevel4
{
- int reserved;
- std::vector<Gfx::EngineObjLevel5> up;
- Gfx::EngineObjLevel3* down;
+ bool used;
+ Gfx::EngineTriangleType type;
+ Gfx::Material material;
+ int state;
+ std::vector<Gfx::VertexTex2> vertices;
- EngineObjLevel4();
+ EngineObjLevel4(bool used = false,
+ Gfx::EngineTriangleType type = Gfx::ENG_TRIANGLE_TYPE_TRIANGLES,
+ const Gfx::Material& material = Gfx::Material(),
+ int state = Gfx::ENG_RSTATE_NORMAL);
};
/**
@@ -189,12 +252,12 @@ struct EngineObjLevel4
\brief Tier 3 of object tree */
struct EngineObjLevel3
{
+ bool used;
float min;
float max;
- std::vector<Gfx::EngineObjLevel4> up;
- Gfx::EngineObjLevel2* down;
+ std::vector<Gfx::EngineObjLevel4> next;
- EngineObjLevel3();
+ EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f);
};
/**
@@ -202,11 +265,11 @@ struct EngineObjLevel3
\brief Tier 2 of object tree */
struct EngineObjLevel2
{
+ bool used;
int objRank;
- std::vector<Gfx::EngineObjLevel3> up;
- Gfx::EngineObjLevel1* down;
+ std::vector<Gfx::EngineObjLevel3> next;
- EngineObjLevel2();
+ EngineObjLevel2(bool used = false, int objRank = -1);
};
/**
@@ -214,11 +277,15 @@ struct EngineObjLevel2
\brief Tier 1 of object tree */
struct EngineObjLevel1
{
+ bool used;
+ std::string tex1Name;
Gfx::Texture tex1;
+ std::string tex2Name;
Gfx::Texture tex2;
- std::vector<Gfx::EngineObjLevel2> up;
+ std::vector<Gfx::EngineObjLevel2> next;
- EngineObjLevel1();
+ EngineObjLevel1(bool used = false, const std::string& tex1Name = "",
+ const std::string& tex2Name = "");
};
/**
@@ -237,6 +304,8 @@ enum EngineShadowType
\brief Shadow drawn by the graphics engine */
struct EngineShadow
{
+ //! If true, shadow is valid
+ bool used;
//! If true, shadow is invisible (object being carried for example)
bool hide;
//! Rank of the associated object
@@ -258,8 +327,17 @@ struct EngineShadow
EngineShadow()
{
+ LoadDefault();
+ }
+
+ void LoadDefault()
+ {
+ used = false;
hide = false;
objRank = 0;
+ type = Gfx::ENG_SHADOW_NORM;
+ pos.LoadZero();
+ normal.LoadZero();
angle = radius = intensity = height = 0.0f;
}
};
@@ -269,6 +347,8 @@ struct EngineShadow
\brief A spot (large shadow) drawn on the ground by the graphics engine */
struct EngineGroundSpot
{
+ //! If true, ground spot is valid
+ bool used;
//! Color of the shadow
Gfx::Color color;
//! Min altitude
@@ -288,6 +368,15 @@ struct EngineGroundSpot
EngineGroundSpot()
{
+ LoadDefault();
+ }
+
+ void LoadDefault()
+ {
+ used = false;
+ color = Gfx::Color();
+ pos.LoadZero();
+ drawPos.LoadZero();
min = max = smooth = radius = drawRadius = 0.0f;
}
};
@@ -297,12 +386,14 @@ struct EngineGroundSpot
\brief Phase of life of an EngineGroundMark */
enum EngineGroundMarkPhase
{
+ //! Null phase
+ ENG_GR_MARK_PHASE_NULL = 0,
//! Increase
ENG_GR_MARK_PHASE_INC = 1,
//! Fixed
ENG_GR_MARK_PHASE_FIX = 2,
//! Decrease
- ENG_GR_MARK_PHASE_DEC = 2
+ ENG_GR_MARK_PHASE_DEC = 3
};
/**
@@ -339,11 +430,19 @@ struct EngineGroundMark
EngineGroundMark()
{
+ LoadDefault();
+ }
+
+ void LoadDefault()
+ {
draw = false;
+ phase = ENG_GR_MARK_PHASE_NULL;
+ pos = Math::Vector();
+ drawPos = Math::Vector();
delay[0] = delay[1] = delay[2] = 0.0f;
fix = radius = intensity = drawRadius = drawIntensity = 0.0f;
dx = dy = 0;
- table = NULL;
+ table = nullptr;
}
};
@@ -363,55 +462,6 @@ enum EngineTextureMapping
/**
- \enum EngineRenderState
- \brief Render state of graphics engine
-
- States are used for settings certain modes, for instance texturing and blending.
- The enum is a bitmask and some of the states can be OR'd together. */
-enum EngineRenderState
-{
- //! Normal opaque materials
- ENG_RSTATE_NORMAL = 0,
- //! The transparent texture (black = no)
- ENG_RSTATE_TTEXTURE_BLACK = (1<<0),
- //! The transparent texture (white = no)
- ENG_RSTATE_TTEXTURE_WHITE = (1<<1),
- //! The transparent diffuse color
- ENG_RSTATE_TDIFFUSE = (1<<2),
- //! Texture wrap
- ENG_RSTATE_WRAP = (1<<3),
- //! Texture borders with solid color
- ENG_RSTATE_CLAMP = (1<<4),
- //! Light texture (ambient max)
- ENG_RSTATE_LIGHT = (1<<5),
- //! Double black texturing
- ENG_RSTATE_DUAL_BLACK = (1<<6),
- //! Double white texturing
- ENG_RSTATE_DUAL_WHITE = (1<<7),
- //! Part 1 (no change in. MOD!)
- ENG_RSTATE_PART1 = (1<<8),
- //! Part 2
- ENG_RSTATE_PART2 = (1<<9),
- //! Part 3
- ENG_RSTATE_PART3 = (1<<10),
- //! Part 4
- ENG_RSTATE_PART4 = (1<<11),
- //! Double-sided face
- ENG_RSTATE_2FACE = (1<<12),
- //! Image using alpha channel
- ENG_RSTATE_ALPHA = (1<<13),
- //! Always use 2nd floor texturing
- ENG_RSTATE_SECOND = (1<<14),
- //! Causes the fog
- ENG_RSTATE_FOG = (1<<15),
- //! The transparent color (black = no)
- ENG_RSTATE_TCOLOR_BLACK = (1<<16),
- //! The transparent color (white = no)
- ENG_RSTATE_TCOLOR_WHITE = (1<<17)
-};
-
-
-/**
\enum EngineMouseType
\brief Type of mouse cursor displayed in-game */
enum EngineMouseType
@@ -501,7 +551,7 @@ struct EngineMouse
The 3D scene is composed of objects which are basically collections of triangles forming
a surface or simply independent triangles in space. Objects are stored in the engine
- as a tree structure which is composed of 5 tiers (EngineObjLevel1, EngineObjLevel2 and so on).
+ as a tree structure which is composed of 4 tiers (EngineObjLevel1, EngineObjLevel2 and so on).
Each tier stores some data about object triangle, like textures or materials used.
Additional information on objects stored are in EngineObject structure.
Each object is uniquely identified by its rank.
@@ -511,354 +561,592 @@ struct EngineMouse
class CEngine
{
public:
- CEngine(CInstanceManager *iMan, CApplication *app);
+ CEngine(CInstanceManager* iMan, CApplication* app);
~CEngine();
- //! Returns whether the device was initialized
- bool GetWasInit();
- //! Returns the last error encountered
- std::string GetError();
-
- //! Performs the first initialization, before a device was set
- bool Create();
- //! Frees all resources before exit
- void Destroy();
-
//! Sets the device to be used
- void SetDevice(Gfx::CDevice *device);
+ void SetDevice(Gfx::CDevice* device);
//! Returns the current device
Gfx::CDevice* GetDevice();
- //! Performs initialization after a device was created and set
- bool AfterDeviceSetInit();
+ //! Sets the terrain object
+ void SetTerrain(Gfx::CTerrain* terrain);
+
+ //! Returns the text rendering engine
+ CText* GetText();
+
+
+ //! Performs the initialization; must be called after device was set
+ bool Create();
+ //! Frees all resources before exit
+ void Destroy();
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
void ResetAfterDeviceChanged();
- void SetTerrain(Gfx::CTerrain* terrain);
+
+ //! Called once per frame, the call is the entry point for rendering
+ void Render();
+
//! Processes incoming event
- bool ProcessEvent(const Event &event);
+ bool ProcessEvent(const Event& event);
+
+ //! Called once per frame, the call is the entry point for animating the scene
+ void FrameMove(float rTime);
+ //! Evolved throughout the game
+ void StepSimulation(float rTime);
- //! Renders a single frame
- bool Render();
+ //! Writes a screenshot containing the current frame
+ bool WriteScreenShot(const std::string& fileName, int width, int height);
- bool WriteProfile();
+ //! Reads settings from INI
+ bool ReadSettings();
+ //! Writes settings to INI
+ bool WriteSettings();
+
+ //@{
+ //! Management of game pause mode
void SetPause(bool pause);
bool GetPause();
+ //@}
+ //@{
+ //! Management of lock for the duration of movie sequence
void SetMovieLock(bool lock);
bool GetMovieLock();
+ //@}
- void SetShowStat(bool show);
- bool GetShowStat();
+ //@{
+ //! Management of displaying statistic information
+ void SetShowStats(bool show);
+ bool GetShowStats();
+ //@}
+ //! Enables/disables rendering
void SetRenderEnable(bool enable);
- int OneTimeSceneInit();
- int InitDeviceObjects();
- int DeleteDeviceObjects();
- int RestoreSurfaces();
- int FrameMove(float rTime);
- void StepSimulation(float rTime);
- int FinalCleanup();
+ //! Returns current size of viewport window
+ Math::IntPoint GetWindowSize();
+ //! Returns the last size of viewport window
+ Math::IntPoint GetLastWindowSize();
+
+ //@{
+ //! Conversion functions between window and interface coordinates
+ /** Window coordinates are from top-left (0,0) to bottom-right (w,h) - size of window
+ Interface cords are from bottom-left (0,0) to top-right (1,1) - and do not depend on window size */
+ Math::Point WindowToInterfaceCoords(Math::IntPoint pos);
+ Math::IntPoint InterfaceToWindowCoords(Math::Point pos);
+ //@}
+
+ //@{
+ //! Conversion functions between window and interface sizes
+ /** Unlike coordinate conversions, this is only scale conversion, not translation and scale. */
+ Math::Point WindowToInterfaceSize(Math::IntPoint size);
+ Math::IntPoint InterfaceToWindowSize(Math::Point size);
+ //@}
+
+ //! Returns the name of directory with textures
+ std::string GetTextureDir();
+
+ //! Increments the triangle counter for the current frame
void AddStatisticTriangle(int nb);
+ //! Returns the number of triangles in current frame
int GetStatisticTriangle();
- void SetHiliteRank(int *rankList);
- bool GetHilite(Math::Point &p1, Math::Point &p2);
- bool GetSpriteCoord(int &x, int &y);
- void SetInfoText(int line, char* text);
- char* GetInfoText(int line);
- void FirstExecuteAdapt(bool first);
- bool GetFullScreen();
- Math::Matrix* GetMatView();
- Math::Matrix* GetMatLeftView();
- Math::Matrix* GetMatRightView();
+ /* *************** Object management *************** */
- void TimeInit();
- void TimeEnterGel();
- void TimeExitGel();
- float TimeGet();
-
- int GetRestCreate();
+ //! Creates a new object and returns its rank
int CreateObject();
+ //! Deletes all objects, shadows and ground spots
void FlushObject();
+ //! Deletes the given object
bool DeleteObject(int objRank);
- bool SetDrawWorld(int objRank, bool draw);
- bool SetDrawFront(int objRank, bool draw);
-
- bool AddTriangle(int objRank, Gfx::VertexTex2* vertex, int nb, const Gfx::Material &mat,
- int state, std::string texName1, std::string texName2,
- float min, float max, bool globalUpdate);
- bool AddSurface(int objRank, Gfx::VertexTex2* vertex, int nb, const Gfx::Material &mat,
- int state, std::string texName1, std::string texName2,
+
+ //@{
+ //! Management of engine object type
+ bool SetObjectType(int objRank, Gfx::EngineObjectType type);
+ Gfx::EngineObjectType GetObjectType(int objRank);
+ //@}
+
+ //@{
+ //! Management of object transform
+ bool SetObjectTransform(int objRank, const Math::Matrix& transform);
+ bool GetObjectTransform(int objRank, Math::Matrix& transform);
+ //@}
+
+ //! Sets drawWorld for given object
+ bool SetObjectDrawWorld(int objRank, bool draw);
+ //! Sets drawFront for given object
+ bool SetObjectDrawFront(int objRank, bool draw);
+
+ //! Sets the transparency level for given object
+ bool SetObjectTransparency(int objRank, float value);
+
+ //! Returns the bounding box for an object
+ bool GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max);
+
+ //! Returns the total number of triangles of given object
+ int GetObjectTotalTriangles(int objRank);
+
+ //! Adds triangles to given object with the specified params
+ bool AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& vertices,
+ const Gfx::Material& material, int state,
+ std::string tex1Name, std::string tex2Name,
+ float min, float max, bool globalUpdate);
+
+ //! Adds a surface to given object with the specified params
+ bool AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& vertices,
+ const Gfx::Material& material, int state,
+ std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate);
- bool AddQuick(int objRank, Gfx::EngineObjLevel5* buffer,
- std::string texName1, std::string texName2,
+
+ //! Adds a tier 4 engine object directly
+ bool AddQuick(int objRank, const Gfx::EngineObjLevel4& buffer,
+ std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate);
- Gfx::EngineObjLevel5* SearchTriangle(int objRank, const Gfx::Material &mat,
- int state, std::string texName1, std::string texName2,
- float min, float max);
+ //! Returns the first found tier 4 engine object for the given params or nullptr if not found
+ Gfx::EngineObjLevel4* FindTriangles(int objRank, const Gfx::Material& material,
+ int state, std::string tex1Name, std::string tex2Name,
+ float min, float max);
+
+ //! Returns a partial list of triangles for given object
+ int GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount,
+ std::vector<Gfx::EngineTriangle>& triangles);
+
+ //! Updates LOD after parameter or resolution change
void ChangeLOD();
- bool ChangeSecondTexture(int objRank, char* texName2);
- int GetTotalTriangles(int objRank);
- int GetTriangles(int objRank, float min, float max, Gfx::EngineTriangle* buffer, int size, float percent);
- bool GetBBox(int objRank, Math::Vector &min, Math::Vector &max);
- bool ChangeTextureMapping(int objRank, const Gfx::Material &mat, int state,
- const std::string &texName1, const std::string &texName2,
+
+ //! Changes the 2nd texure for given object
+ bool ChangeSecondTexture(int objRank, const std::string& tex2Name);
+
+ //! Changes (recalculates) texture mapping for given object
+ bool ChangeTextureMapping(int objRank, const Gfx::Material& mat, int state,
+ const std::string& tex1Name, const std::string& tex2Name,
float min, float max, Gfx::EngineTextureMapping mode,
float au, float bu, float av, float bv);
- bool TrackTextureMapping(int objRank, const Gfx::Material &mat, int state,
- const std::string &texName1, const std::string &texName2,
+
+ //! Changes texture mapping for robot tracks
+ bool TrackTextureMapping(int objRank, const Gfx::Material& mat, int state,
+ const std::string& tex1Name, const std::string& tex2Name,
float min, float max, Gfx::EngineTextureMapping mode,
float pos, float factor, float tl, float ts, float tt);
- bool SetObjectTransform(int objRank, const Math::Matrix &transform);
- bool GetObjectTransform(int objRank, Math::Matrix &transform);
- bool SetObjectType(int objRank, Gfx::EngineObjectType type);
- Gfx::EngineObjectType GetObjectType(int objRank);
- bool SetObjectTransparency(int objRank, float value);
- bool ShadowCreate(int objRank);
- void ShadowDelete(int objRank);
+
+ //! Creates a shadow for the given object
+ bool CreateShadow(int objRank);
+ //! Deletes the shadow for given object
+ void DeleteShadow(int objRank);
+
+ //@{
+ //! Management of different shadow params
bool SetObjectShadowHide(int objRank, bool hide);
bool SetObjectShadowType(int objRank, Gfx::EngineShadowType type);
- bool SetObjectShadowPos(int objRank, const Math::Vector &pos);
- bool SetObjectShadowNormal(int objRank, const Math::Vector &n);
+ bool SetObjectShadowPos(int objRank, const Math::Vector& pos);
+ bool SetObjectShadowNormal(int objRank, const Math::Vector& normal);
bool SetObjectShadowAngle(int objRank, float angle);
bool SetObjectShadowRadius(int objRank, float radius);
bool SetObjectShadowIntensity(int objRank, float intensity);
- bool SetObjectShadowHeight(int objRank, float h);
+ bool SetObjectShadowHeight(int objRank, float height);
float GetObjectShadowRadius(int objRank);
-
- void GroundSpotFlush();
- int GroundSpotCreate();
- void GroundSpotDelete(int rank);
- bool SetObjectGroundSpotPos(int rank, const Math::Vector &pos);
+ //@}
+
+ //! Lists the ranks of objects and subobjects selected
+ void SetHighlightRank(int* rankList);
+ //! Returns the highlighted rectangle
+ bool GetHighlight(Math::Point& p1, Math::Point& p2);
+
+ //! Deletes all ground spots
+ void FlushGroundSpot();
+ //! Creates a new ground spot and returns its rank
+ int CreateGroundSpot();
+ //! Deletes the given ground spot
+ void DeleteGroundSpot(int rank);
+
+ //@{
+ //! Management of different ground spot params
+ bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos);
bool SetObjectGroundSpotRadius(int rank, float radius);
- bool SetObjectGroundSpotColor(int rank, const Gfx::Color &color);
+ bool SetObjectGroundSpotColor(int rank, const Gfx::Color& color);
bool SetObjectGroundSpotMinMax(int rank, float min, float max);
bool SetObjectGroundSpotSmooth(int rank, float smooth);
+ //@}
- int GroundMarkCreate(Math::Vector pos, float radius,
+ //! Creates the ground mark with the given params
+ void CreateGroundMark(Math::Vector pos, float radius,
float delay1, float delay2, float delay3,
int dx, int dy, char* table);
- bool GroundMarkDelete(int rank);
+ //! Deletes the ground mark
+ void DeleteGroundMark(int rank);
+ //! Updates the state after creating objects
void Update();
- void SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt,
- const Math::Vector &upVec, float eyeDistance);
- Gfx::Texture CreateTexture(const std::string &texName,
- const Gfx::TextureCreateParams &params);
- Gfx::Texture CreateTexture(const std::string &texName);
- void DestroyTexture(const std::string &texName);
+ /* *************** Mode setting *************** */
- bool LoadTexture(const std::string &name, int stage = 0);
+ //! Sets the current rendering state
+ void SetState(int state, const Gfx::Color& color = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ //! Sets the current material
+ void SetMaterial(const Gfx::Material& mat);
+
+ //! Specifies the location and direction of view
+ void SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt,
+ const Math::Vector& upVec, float eyeDistance);
+
+ //! Loads texture, creating it if not already present
+ Gfx::Texture LoadTexture(const std::string& name);
+ //! Loads texture, creating it with given params if not already present
+ Gfx::Texture LoadTexture(const std::string& name, const Gfx::TextureCreateParams& params);
+ //! Loads all necessary textures
bool LoadAllTextures();
+ //! Sets texture for given stage; if not present in cache, the texture is loaded
+ /** If loading fails, returns false. */
+ bool SetTexture(const std::string& name, int stage = 0);
+ //! Sets texture for given stage
+ void SetTexture(const Gfx::Texture& tex, int stage = 0);
+
+ //! Deletes the given texture, unloading it and removing from cache
+ void DeleteTexture(const std::string& name);
+ //! Deletes the given texture, unloading it and removing from cache
+ void DeleteTexture(const Gfx::Texture& tex);
+
+ //@{
+ //! Border management (distance limits) depends of the resolution (LOD = level-of-detail)
void SetLimitLOD(int rank, float limit);
float GetLimitLOD(int rank, bool last=false);
+ //@}
+ //! Defines of the distance field of vision
void SetTerrainVision(float vision);
+ //@{
+ //! Management of camera angle
+ /**
+ 0.75 = normal
+ 1.50 = wide-angle */
+ void SetFocus(float focus);
+ float GetFocus();
+ //@}
+
+ //@{
+ //! Management of the global mode of marking
void SetGroundSpot(bool mode);
bool GetGroundSpot();
+ //@}
+
+ //@{
+ //! Management of the global mode of shading
void SetShadow(bool mode);
bool GetShadow();
+ //@}
+
+ //@{
+ //! Management of the global mode of contamination
void SetDirty(bool mode);
bool GetDirty();
+ //@}
+
+ //@{
+ //! Management of the global mode of horizontal fog patches
void SetFog(bool mode);
bool GetFog();
+ //@}
+
+ //! Indicates whether it is possible to give a color SetState
bool GetStateColor();
+ //@{
+ //! Management of the global mode of secondary texturing
void SetSecondTexture(int texNum);
int GetSecondTexture();
+ //@}
+ //@{
+ //! Management of view mode
void SetRankView(int rank);
int GetRankView();
+ //@}
+ //! Whether to draw the world
void SetDrawWorld(bool draw);
+
+ //! Whether to draw the world on the interface
void SetDrawFront(bool draw);
- void SetAmbientColor(const Gfx::Color &color, int rank = 0);
+ //@{
+ //! Ambient color management
+ void SetAmbientColor(const Gfx::Color& color, int rank = 0);
Gfx::Color GetAmbientColor(int rank = 0);
+ //@}
- void SetWaterAddColor(const Gfx::Color &color);
+ //@{
+ //! Color management under water
+ void SetWaterAddColor(const Gfx::Color& color);
Gfx::Color GetWaterAddColor();
+ //@}
- void SetFogColor(const Gfx::Color &color, int rank = 0);
+ //@{
+ //! Management of the fog color
+ void SetFogColor(const Gfx::Color& color, int rank = 0);
Gfx::Color GetFogColor(int rank = 0);
+ //@}
+ //@{
+ //! Management of the depth of field.
+ /** Beyond this distance, nothing is visible.
+ Shortly (according SetFogStart), one enters the fog. */
void SetDeepView(float length, int rank = 0, bool ref=false);
float GetDeepView(int rank = 0);
+ //@}
+
+ //@{
+ //! Management the start of fog.
+ /** With 0.0, the fog from the point of view (fog max).
+ With 1.0, the fog from the depth of field (no fog). */
void SetFogStart(float start, int rank = 0);
float GetFogStart(int rank = 0);
+ //@}
- void SetBackground(const std::string &name, Gfx::Color up = Gfx::Color(), Gfx::Color down = Gfx::Color(),
+ //@{
+ //! Management of the background image to use
+ void SetBackground(const std::string& name, Gfx::Color up = Gfx::Color(), Gfx::Color down = Gfx::Color(),
Gfx::Color cloudUp = Gfx::Color(), Gfx::Color cloudDown = Gfx::Color(),
bool full = false, bool quarter = false);
- void GetBackground(const std::string &name, Gfx::Color &up, Gfx::Color &down,
- Gfx::Color &cloudUp, Gfx::Color &cloudDown,
- bool &full, bool &quarter);
- void SetFrontsizeName(char *name);
+ void GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down,
+ Gfx::Color& cloudUp, Gfx::Color& cloudDown,
+ bool& full, bool& quarter);
+ //@}
+
+ //! Specifies the name of foreground texture
+ void SetForegroundName(const std::string& name);
+ //! Specifies whether to draw the foreground
void SetOverFront(bool front);
- void SetOverColor(const Gfx::Color &color = Gfx::Color(), int mode = ENG_RSTATE_TCOLOR_BLACK);
+ //! Sets the foreground overlay color
+ void SetOverColor(const Gfx::Color& color = Gfx::Color(), int mode = ENG_RSTATE_TCOLOR_BLACK);
+ //@{
+ //! Management of the particle density
void SetParticleDensity(float value);
float GetParticleDensity();
+ //@}
+
+ //! Adapts particle factor according to particle density
float ParticleAdapt(float factor);
+ //@{
+ //! Management of the distance of clipping.
void SetClippingDistance(float value);
float GetClippingDistance();
+ //@}
+ //@{
+ //! Management of objects detals.
void SetObjectDetail(float value);
float GetObjectDetail();
+ //@}
+ //@{
+ //! The amount of management objects gadgets
void SetGadgetQuantity(float value);
float GetGadgetQuantity();
+ //@}
+ //@{
+ //! Management the quality of textures
void SetTextureQuality(int value);
int GetTextureQuality();
+ //@}
+ //@{
+ //! Management mode of toto
void SetTotoMode(bool present);
bool GetTotoMode();
+ //@}
+ //@{
+ //! Management the mode of foreground
void SetLensMode(bool present);
bool GetLensMode();
+ //@}
+ //@{
+ //! Management the mode of water
void SetWaterMode(bool present);
bool GetWaterMode();
+ //@}
void SetLightingMode(bool present);
bool GetLightingMode();
+ //@{
+ //! Management the mode of sky
void SetSkyMode(bool present);
bool GetSkyMode();
+ //@}
+ //@{
+ //! Management the mode of background
void SetBackForce(bool present);
bool GetBackForce();
+ //@}
+ //@{
+ //! Management the mode of planets
void SetPlanetMode(bool present);
bool GetPlanetMode();
+ //@}
+ //@{
+ //! Managing the mode of dynamic lights.
void SetLightMode(bool present);
bool GetLightMode();
+ //@}
+ //@{
+ // TODO: move to more appropriate class ?
+ //! Management of the indentation mode while editing (CEdit)
void SetEditIndentMode(bool autoIndent);
bool GetEditIndentMode();
+ //@}
+ //@{
+ // TODO: move to more appropriate class ?
+ //! Management of tab indent when editing (CEdit)
void SetEditIndentValue(int value);
int GetEditIndentValue();
+ //@}
+ //@{
+ //! Management of game speed
void SetSpeed(float speed);
float GetSpeed();
+ //@{
+ //! Management of precision of robot tracks
void SetTracePrecision(float factor);
float GetTracePrecision();
+ //@}
- void SetFocus(float focus);
- float GetFocus();
- Math::Vector GetEyePt();
- Math::Vector GetLookatPt();
- float GetEyeDirH();
- float GetEyeDirV();
- Math::Point GetDim();
- void UpdateMatProj();
-
- void ApplyChange();
-
- void FlushPressKey();
- void ResetKey();
- void SetKey(int keyRank, int option, int key);
- int GetKey(int keyRank, int option);
-
- void SetJoystick(bool enable);
- bool GetJoystick();
-
- void SetDebugMode(bool mode);
- bool GetDebugMode();
- bool GetSetupMode();
-
- bool IsVisiblePoint(const Math::Vector &pos);
-
- int DetectObject(Math::Point mouse);
- void SetState(int state, Gfx::Color color = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f));
- void SetTexture(const std::string &name, int stage = 0);
- void SetMaterial(const Gfx::Material &mat);
-
+ //@{
+ //! Management of mouse cursor visibility
void SetMouseVisible(bool show);
bool GetMouseVisible();
+ //@}
+
+ //@{
+ //! Management of mouse cursor position
void SetMousePos(Math::Point pos);
Math::Point GetMousePos();
+ //@}
+
+ //@{
+ //! Management of mouse cursor type
void SetMouseType(Gfx::EngineMouseType type);
Gfx::EngineMouseType GetMouseType();
+ //@}
- CText* GetText();
+ //! Returns the view matrix
+ const Math::Matrix& GetMatView();
+ //! Returns the camera center point
+ Math::Vector GetEyePt();
+ //! Returns the camera target point
+ Math::Vector GetLookatPt();
+ //! Returns the horizontal direction angle of view
+ float GetEyeDirH();
+ //! Returns the vertical direction angle of view
+ float GetEyeDirV();
+ //! Indicates whether a point is visible
+ bool IsVisiblePoint(const Math::Vector& pos);
- bool ChangeColor(char *name, Gfx::Color colorRef1, Gfx::Color colorNew1,
- Gfx::Color colorRef2, Gfx::Color colorNew2,
- float tolerance1, float tolerance2,
- Math::Point ts, Math::Point ti,
- Math::Point *pExclu=0, float shift=0.0f, bool hSV=false);
- bool OpenImage(char *name);
- bool CopyImage();
- bool LoadImage();
- bool ScrollImage(int dx, int dy);
- bool SetDot(int x, int y, Gfx::Color color);
- bool CloseImage();
- bool WriteScreenShot(char *filename, int width, int height);
- //bool GetRenderDC(HDC &hDC);
- //bool ReleaseRenderDC(HDC &hDC);
- //PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp);
- //bool CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC);
+ //! Resets the projection matrix after changes
+ void UpdateMatProj();
-protected:
+ //! Updates the scene after a change of parameters
+ void ApplyChange();
- void SetUp3DView();
- bool Draw3DScene();
+protected:
+ //! Prepares the interface for 3D scene
+ void Draw3DScene();
+ //! Draws the user interface over the scene
+ void DrawInterface();
- void SetUpInterfaceView();
- bool DrawInterface();
+ //! Updates the textures used for drawing ground spot
+ void UpdateGroundSpotTextures();
- void DrawGroundSpot();
+ //! Draws shadows
void DrawShadow();
+ //! Draws the gradient background
void DrawBackground();
- void DrawBackgroundGradient(Gfx::Color up, Gfx::Color down);
- void DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, char *name);
+ //! Draws the gradient background
+ void DrawBackgroundGradient(const Gfx::Color& up, const Gfx::Color& down);
+ //! Draws a portion of the image background
+ void DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, const Gfx::Texture &tex);
+ //! Draws the image background
void DrawBackgroundImage();
+ //! Draws all the planets
void DrawPlanet();
- void DrawFrontsize();
+ //! Draws the image foreground
+ void DrawForegroundImage();
+ //! Draws the foreground color
void DrawOverColor();
- void DrawHilite();
+ //! Draws the rectangle of the object highlighted
+ void DrawHighlight();
+ //! Draws the mouse cursor
void DrawMouse();
+ //! Draw part of mouse cursor sprite
void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon);
- /*
- Gfx::ObjLevel2* AddLevel1(Gfx::ObjLevel1 *&p1, char* texName1, char* texName2);
- Gfx::ObjLevel3* AddLevel2(Gfx::ObjLevel2 *&p2, int objRank);
- Gfx::ObjLevel4* AddLevel3(Gfx::ObjLevel3 *&p3, float min, float max);
- Gfx::ObjLevel5* AddLevel4(Gfx::ObjLevel4 *&p4, int reserve);
- Gfx::ObjLevel6* AddLevel5(Gfx::ObjLevel5 *&p5, Gfx::TriangleType type, const Gfx::Material &mat, int state, int nb);*/
+ //! Creates new tier 1 object
+ Gfx::EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name);
+ //! Creates a new tier 2 object
+ Gfx::EngineObjLevel2& AddLevel2(Gfx::EngineObjLevel1 &p1, int objRank);
+ //! Creates a new tier 3 object
+ Gfx::EngineObjLevel3& AddLevel3(Gfx::EngineObjLevel2 &p2, float min, float max);
+ //! Creates a new tier 4 object
+ Gfx::EngineObjLevel4& AddLevel4(Gfx::EngineObjLevel3 &p3, Gfx::EngineTriangleType type,
+ const Gfx::Material& mat, int state);
+ //! Create texture and add it to cache
+ Gfx::Texture CreateTexture(const std::string &texName, const Gfx::TextureCreateParams &params);
+
+ //! Tests whether the given object is visible
bool IsVisible(int objRank);
+
+ //! Detects whether an object is affected by the mouse
bool DetectBBox(int objRank, Math::Point mouse);
- bool GetBBox2D(int objRank, Math::Point &min, Math::Point &max);
- bool DetectTriangle(Math::Point mouse, Gfx::VertexTex2 *triangle, int objRank, float &dist);
- bool TransformPoint(Math::Vector &p2D, int objRank, Math::Vector p3D);
+
+ //! Compute and return the 2D box on screen of any object
+ bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max);
+
+ //! Detects the target object that is selected with the mouse
+ /** Returns the rank of the object or -1. */
+ int DetectObject(Math::Point mouse);
+
+ //! Detects whether the mouse is in a triangle.
+ bool DetectTriangle(Math::Point mouse, Gfx::VertexTex2* triangle, int objRank, float& dist);
+
+ //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window
+ /** The coordinated p2D.z gives the distance. */
+ bool TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D);
+
+ //! Calculates the distances between the viewpoint and the origin of different objects
void ComputeDistance();
+
+ //! Updates geometric parameters of objects (bounding box and radius)
void UpdateGeometry();
protected:
CInstanceManager* m_iMan;
CApplication* m_app;
- CSound* m_sound;
+ CSoundInterface* m_sound;
Gfx::CDevice* m_device;
Gfx::CText* m_text;
Gfx::CLightManager* m_lightMan;
@@ -869,51 +1157,54 @@ protected:
Gfx::CPlanet* m_planet;
Gfx::CTerrain* m_terrain;
- bool m_wasInit;
+ //! Last encountered error
std::string m_error;
//! Whether to show stats (FPS, etc)
bool m_showStats;
- int m_blackSrcBlend[2];
- int m_blackDestBlend[2];
- int m_whiteSrcBlend[2];
- int m_whiteDestBlend[2];
- int m_diffuseSrcBlend[2];
- int m_diffuseDestBlend[2];
- int m_alphaSrcBlend[2];
- int m_alphaDestBlend[2];
+ //! Speed of animation
+ float m_speed;
+ //! Pause mode
+ bool m_pause;
+ //! Rendering enabled?
+ bool m_render;
+ //! Lock for duration of movie?
+ bool m_movieLock;
+ //! Projection matrix for 3D scene
Math::Matrix m_matProj;
- Math::Matrix m_matLeftView;
- Math::Matrix m_matRightView;
+ //! View matrix for 3D scene
Math::Matrix m_matView;
+ //! Camera angle for 3D scene
float m_focus;
+ //! World matrix for 2D interface
Math::Matrix m_matWorldInterface;
+ //! Projection matrix for 2D interface
Math::Matrix m_matProjInterface;
+ //! View matrix for 2D interface
Math::Matrix m_matViewInterface;
- long m_baseTime;
- long m_stopTime;
- float m_absTime;
- float m_lastTime;
- float m_speed;
- bool m_pause;
- bool m_render;
- bool m_movieLock;
-
- //! Current size of window
- Math::IntSize m_size;
- Math::IntSize m_lastSize;
+ //! Current size of viewport window
+ Math::IntPoint m_size;
+ //! Previous size of viewport window
+ Math::IntPoint m_lastSize;
+ //! Root of tree object structure (level 1 list)
std::vector<Gfx::EngineObjLevel1> m_objectTree;
+ //! Object parameters
std::vector<Gfx::EngineObject> m_objects;
- std::vector<Gfx::EngineShadow> m_shadow;
- std::vector<Gfx::EngineGroundSpot> m_groundSpot;
+ //! Shadow list
+ std::vector<Gfx::EngineShadow> m_shadows;
+ //! Ground spot list
+ std::vector<Gfx::EngineGroundSpot> m_groundSpots;
+ //! Ground mark
Gfx::EngineGroundMark m_groundMark;
+ //! Location of camera
Math::Vector m_eyePt;
+ //! Camera target
Math::Vector m_lookatPt;
float m_eyeDirH;
float m_eyeDirV;
@@ -926,7 +1217,6 @@ protected:
Gfx::Color m_waterAddColor;
int m_statisticTriangle;
bool m_updateGeometry;
- //char m_infoText[10][200];
int m_alphaMode;
bool m_stateColor;
bool m_forceStateColor;
@@ -936,21 +1226,25 @@ protected:
bool m_fog;
bool m_firstGroundSpot;
int m_secondTexNum;
+ bool m_backgroundFull;
+ bool m_backgroundQuarter;
std::string m_backgroundName;
+ std::string m_backgroundQuarterNames[4];
+ Gfx::Texture m_backgroundFullTex;
+ Gfx::Texture m_backgroundQuarterTexs[4];
Gfx::Color m_backgroundColorUp;
Gfx::Color m_backgroundColorDown;
Gfx::Color m_backgroundCloudUp;
Gfx::Color m_backgroundCloudDown;
- bool m_backgroundFull;
- bool m_backgroundQuarter;
bool m_overFront;
Gfx::Color m_overColor;
int m_overMode;
- std::string m_frontsizeName;
+ std::string m_foregroundName;
+ Gfx::Texture m_foregroundTex;
bool m_drawWorld;
bool m_drawFront;
float m_limitLOD[2];
- float m_particuleDensity;
+ float m_particleDensity;
float m_clippingDistance;
float m_lastClippingDistance;
float m_objectDetail;
@@ -969,34 +1263,53 @@ protected:
int m_editIndentValue;
float m_tracePrecision;
- int m_hiliteRank[100];
- bool m_hilite;
- Math::Point m_hiliteP1;
- Math::Point m_hiliteP2;
-
- int m_lastState;
- Gfx::Color m_lastColor;
- char m_lastTexture[2][50];
- Gfx::Material m_lastMaterial;
-
+ //! Ranks of highlighted objects
+ int m_highlightRank[100];
+ //! Highlight visible?
+ bool m_highlight;
+ //! Time counter for highlight animation
+ float m_highlightTime;
+ //@{
+ //! Highlight rectangle points
+ Math::Point m_highlightP1;
+ Math::Point m_highlightP2;
+ //@}
+
+ //! Texture directory name
std::string m_texPath;
+ //! Default texture create params
Gfx::TextureCreateParams m_defaultTexParams;
+ //! Map of loaded textures (by name)
std::map<std::string, Gfx::Texture> m_texNameMap;
+ //! Reverse map of loaded textures (by texture)
std::map<Gfx::Texture, std::string> m_revTexNameMap;
+ //! Blacklist map of textures
+ /** Textures on this list were not successful in first loading,
+ * so are disabled for subsequent load calls. */
+ std::set<std::string> m_texBlacklist;
+ //! Mouse cursor definitions
Gfx::EngineMouse m_mice[Gfx::ENG_MOUSE_COUNT];
+ //! Texture with mouse cursors
Gfx::Texture m_miceTexture;
+ //! Size of mouse cursor
Math::Point m_mouseSize;
+ //! Type of mouse cursor
Gfx::EngineMouseType m_mouseType;
+ //! Position of mouse in interface coords
Math::Point m_mousePos;
+ //! Is mouse visible?
bool m_mouseVisible;
- //LPDIRECTDRAWSURFACE7 m_imageSurface;
- //DDSURFACEDESC2 m_imageDDSD;
- //WORD* m_imageCopy;
- //int m_imageDX;
- //int m_imageDY;
+ //! Last engine render state (-1 at the beginning of frame)
+ int m_lastState;
+ //! Last color set with render state
+ Gfx::Color m_lastColor;
+ //! Last texture names for 2 used texture stages
+ std::string m_lastTexture[2];
+ //! Last material
+ Gfx::Material m_lastMaterial;
};
}; // namespace Gfx