summaryrefslogtreecommitdiffstats
path: root/src/graphics/engine
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-20 20:37:37 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-20 20:37:37 +0200
commitbd36d76b31b27255c73376cda7f844e2eba7af82 (patch)
tree465e4f2c684bdd8bc8a5cbfddb2f2bd326f5bf4b /src/graphics/engine
parent7b6bbf79c4bb73013e2fe01f84f0025e7c06c00e (diff)
downloadcolobot-bd36d76b31b27255c73376cda7f844e2eba7af82.tar.gz
colobot-bd36d76b31b27255c73376cda7f844e2eba7af82.tar.bz2
colobot-bd36d76b31b27255c73376cda7f844e2eba7af82.zip
Mouse pos setting, low cpu mode, stats display
Diffstat (limited to 'src/graphics/engine')
-rw-r--r--src/graphics/engine/engine.cpp129
-rw-r--r--src/graphics/engine/engine.h107
2 files changed, 132 insertions, 104 deletions
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 3b314ec..f88a37b 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -116,6 +116,8 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_sound = nullptr;
m_terrain = nullptr;
+ m_showStats = false;
+
m_focus = 0.75f;
m_rankView = 0;
@@ -137,7 +139,6 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_groundSpotVisible = true;
m_dirty = true;
m_fog = true;
- m_speed = 1.0f;
m_secondTexNum = 0;
m_eyeDirH = 0.0f;
m_eyeDirV = 0.0f;
@@ -171,7 +172,7 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_lensMode = true;
m_waterMode = true;
m_skyMode = true;
- m_backForce = false; // TODO: change to true?
+ m_backForce = true;
m_planetMode = true;
m_lightMode = true;
m_editIndentMode = true;
@@ -203,9 +204,11 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_mice[ENG_MOUSE_SCROLLD] = EngineMouse(30, 31, 46, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 17.0f));
m_mouseSize = Math::Point(0.04f, 0.04f * (800.0f / 600.0f));
- m_mousePos = Math::Point(0.5f, 0.5f);
m_mouseType = ENG_MOUSE_NORM;
- m_mouseVisible = false;
+
+ m_fpsCounter = 0;
+ m_lastFrameTime = CreateTimeStamp();
+ m_currentFrameTime = CreateTimeStamp();
m_texPath = "textures/";
m_defaultTexParams.format = TEX_IMG_AUTO;
@@ -226,6 +229,11 @@ CEngine::~CEngine()
m_device = nullptr;
m_sound = nullptr;
m_terrain = nullptr;
+
+ DestroyTimeStamp(m_lastFrameTime);
+ m_lastFrameTime = nullptr;
+ DestroyTimeStamp(m_currentFrameTime);
+ m_currentFrameTime = nullptr;
}
void CEngine::SetDevice(CDevice *device)
@@ -288,6 +296,9 @@ bool CEngine::Create()
params.mipmap = false;
m_miceTexture = LoadTexture("mouse.png", params);
+ GetCurrentTimeStamp(m_currentFrameTime);
+ GetCurrentTimeStamp(m_lastFrameTime);
+
return true;
}
@@ -326,18 +337,8 @@ bool CEngine::ProcessEvent(const Event &event)
{
if (event.type == EVENT_KEY_DOWN)
{
- // !! Debug, to be removed later !!
-
- if (event.key.key == KEY(F1))
- {
- m_mouseVisible = !m_mouseVisible;
- m_app->SetSystemMouseVisible(! m_app->GetSystemMouseVisibile());
- }
- else if (event.key.key == KEY(F2))
- {
- int index = static_cast<int>(m_mouseType);
- m_mouseType = static_cast<EngineMouseType>( (index + 1) % ENG_MOUSE_COUNT );
- }
+ if (event.key.key == KEY(F12))
+ m_showStats = !m_showStats;
}
// By default, pass on all events
@@ -346,6 +347,27 @@ bool CEngine::ProcessEvent(const Event &event)
void CEngine::FrameUpdate()
{
+ m_fpsCounter++;
+
+ GetCurrentTimeStamp(m_currentFrameTime);
+ float diff = TimeStampDiff(m_lastFrameTime, m_currentFrameTime, STU_SEC);
+ if (diff > 1.0f)
+ {
+ CopyTimeStamp(m_lastFrameTime, m_currentFrameTime);
+
+ m_fps = m_fpsCounter / diff;
+
+ if (m_showStats)
+ {
+ std::stringstream str;
+ str << "FPS: ";
+ str.precision(2);
+ str.setf(std::ios_base::fixed);
+ str << m_fps;
+ m_fpsText = str.str();
+ }
+ }
+
float rTime = m_app->GetRelTime();
m_lightMan->UpdateProgression(rTime);
@@ -2664,26 +2686,6 @@ float CEngine::GetTracePrecision()
return m_tracePrecision;
}
-void CEngine::SetMouseVisible(bool visible)
-{
- m_mouseVisible = visible;
-}
-
-bool CEngine::GetMouseVisible()
-{
- return m_mouseVisible;
-}
-
-void CEngine::SetMousePos(Math::Point pos)
-{
- m_mousePos = pos;
-}
-
-Math::Point CEngine::GetMousePos()
-{
- return m_mousePos;
-}
-
void CEngine::SetMouseType(EngineMouseType type)
{
m_mouseType = type;
@@ -3167,9 +3169,10 @@ void CEngine::DrawInterface()
if (m_overFront)
DrawOverColor();
- // Mouse & highlight at the end
+ // At the end to not overlap
DrawMouse();
DrawHighlight();
+ DrawStats();
}
void CEngine::UpdateGroundSpotTextures()
@@ -3668,10 +3671,8 @@ void CEngine::DrawHighlight()
// Status: TESTED, VERIFIED
void CEngine::DrawMouse()
{
- if (! m_mouseVisible)
- return;
-
- if (m_app->GetSystemMouseVisibile())
+ MouseMode mode = m_app->GetMouseMode();
+ if (mode != MOUSE_ENGINE && mode != MOUSE_BOTH)
return;
Material material;
@@ -3683,9 +3684,9 @@ void CEngine::DrawMouse()
int index = static_cast<int>(m_mouseType);
- Math::Point pos = m_mousePos;
- pos.x = m_mousePos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f;
- pos.y = m_mousePos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f;
+ Math::Point pos = m_app->GetMousePos();
+ pos.x = pos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f;
+ pos.y = pos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f;
Math::Point shadowPos;
shadowPos.x = pos.x + (4.0f/800.0f);
@@ -3731,11 +3732,47 @@ void CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon)
Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v1))
};
- m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
- m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
AddStatisticTriangle(2);
}
+void CEngine::DrawStats()
+{
+ if (!m_showStats)
+ return;
+
+ std::stringstream str;
+ str << "Triangles: ";
+ str << m_statisticTriangle;
+ std::string triangleText = str.str();
+
+ float height = m_text->GetAscent(FONT_COLOBOT, 12.0f);
+ float width = 0.15f;
+
+ Math::Point pos(0.04f, 0.04f + height);
+
+ SetState(ENG_RSTATE_OPAQUE_COLOR);
+
+ Gfx::Color black(0.0f, 0.0f, 0.0f, 0.0f);
+
+ VertexCol vertex[4] =
+ {
+ VertexCol(Math::Vector(pos.x , pos.y - height, 0.0f), black),
+ VertexCol(Math::Vector(pos.x , pos.y + height, 0.0f), black),
+ VertexCol(Math::Vector(pos.x + width, pos.y - height, 0.0f), black),
+ VertexCol(Math::Vector(pos.x + width, pos.y + height, 0.0f), black)
+ };
+
+ m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
+
+ SetState(ENG_RSTATE_TEXT);
+
+ m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0);
+
+ pos.y -= height;
+
+ m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0);
+}
+
} // namespace Gfx
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 059de8d..9d69a28 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -53,6 +53,7 @@ class CSoundInterface;
// Graphics module namespace
namespace Gfx {
+
class CDevice;
class CLightManager;
class CText;
@@ -143,11 +144,11 @@ struct EngineTriangle
//! Material
Material material;
//! Render state
- int state;
+ int state;
//! 1st texture
- std::string tex1Name;
+ std::string tex1Name;
//! 2nd texture
- std::string tex2Name;
+ std::string tex2Name;
EngineTriangle()
{
@@ -245,10 +246,10 @@ struct EngineObjLevel4;
*/
struct EngineObjLevel4
{
- bool used;
+ bool used;
EngineTriangleType type;
Material material;
- int state;
+ int state;
std::vector<VertexTex2> vertices;
EngineObjLevel4(bool used = false,
@@ -263,9 +264,9 @@ struct EngineObjLevel4
*/
struct EngineObjLevel3
{
- bool used;
- float min;
- float max;
+ bool used;
+ float min;
+ float max;
std::vector<EngineObjLevel4> next;
EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f);
@@ -277,8 +278,8 @@ struct EngineObjLevel3
*/
struct EngineObjLevel2
{
- bool used;
- int objRank;
+ bool used;
+ int objRank;
std::vector<EngineObjLevel3> next;
EngineObjLevel2(bool used = false, int objRank = -1);
@@ -290,10 +291,10 @@ struct EngineObjLevel2
*/
struct EngineObjLevel1
{
- bool used;
- std::string tex1Name;
+ bool used;
+ std::string tex1Name;
Texture tex1;
- std::string tex2Name;
+ std::string tex2Name;
Texture tex2;
std::vector<EngineObjLevel2> next;
@@ -1123,20 +1124,8 @@ public:
//@}
//@{
- //! 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(EngineMouseType type);
+ void SetMouseType(EngineMouseType type);
EngineMouseType GetMouseType();
//@}
@@ -1188,6 +1177,8 @@ protected:
void DrawMouse();
//! Draw part of mouse cursor sprite
void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon);
+ //! Draw statistic texts
+ void DrawStats();
//! Creates new tier 1 object
EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name);
@@ -1225,27 +1216,31 @@ protected:
void UpdateGeometry();
protected:
- CInstanceManager* m_iMan;
- CApplication* m_app;
- CSoundInterface* m_sound;
- CDevice* m_device;
- CText* m_text;
- CLightManager* m_lightMan;
- CParticle* m_particle;
- CWater* m_water;
- CCloud* m_cloud;
- CLightning* m_lightning;
- CPlanet* m_planet;
- CTerrain* m_terrain;
+ CInstanceManager* m_iMan;
+ CApplication* m_app;
+ CSoundInterface* m_sound;
+ CDevice* m_device;
+ CText* m_text;
+ CLightManager* m_lightMan;
+ CParticle* m_particle;
+ CWater* m_water;
+ CCloud* m_cloud;
+ CLightning* m_lightning;
+ CPlanet* m_planet;
+ CTerrain* m_terrain;
//! Last encountered error
std::string m_error;
+ SystemTimeStamp* m_lastFrameTime;
+ SystemTimeStamp* m_currentFrameTime;
+ int m_fpsCounter;
+ float m_fps;
+
//! Whether to show stats (FPS, etc)
bool m_showStats;
+ std::string m_fpsText;
- //! Speed of animation
- float m_speed;
//! Pause mode
bool m_pause;
//! Rendering enabled?
@@ -1290,12 +1285,12 @@ protected:
float m_eyeDirH;
float m_eyeDirV;
int m_rankView;
- Color m_ambientColor[2];
- Color m_backColor[2];
- Color m_fogColor[2];
+ Color m_ambientColor[2];
+ Color m_backColor[2];
+ Color m_fogColor[2];
float m_deepView[2];
float m_fogStart[2];
- Color m_waterAddColor;
+ Color m_waterAddColor;
int m_statisticTriangle;
bool m_updateGeometry;
int m_alphaMode;
@@ -1310,16 +1305,16 @@ protected:
bool m_backgroundFull;
Math::Point m_backgroundScale;
std::string m_backgroundName;
- Texture m_backgroundTex;
- Color m_backgroundColorUp;
- Color m_backgroundColorDown;
- Color m_backgroundCloudUp;
- Color m_backgroundCloudDown;
+ Texture m_backgroundTex;
+ Color m_backgroundColorUp;
+ Color m_backgroundColorDown;
+ Color m_backgroundCloudUp;
+ Color m_backgroundCloudDown;
bool m_overFront;
- Color m_overColor;
+ Color m_overColor;
int m_overMode;
std::string m_foregroundName;
- Texture m_foregroundTex;
+ Texture m_foregroundTex;
bool m_drawWorld;
bool m_drawFront;
float m_limitLOD[2];
@@ -1373,22 +1368,18 @@ protected:
//! Texture with mouse cursors
Texture m_miceTexture;
//! Size of mouse cursor
- Math::Point m_mouseSize;
+ Math::Point m_mouseSize;
//! Type of mouse cursor
EngineMouseType m_mouseType;
- //! Position of mouse in interface coords
- Math::Point m_mousePos;
- //! Is mouse visible?
- bool m_mouseVisible;
//! Last engine render state (-1 at the beginning of frame)
int m_lastState;
//! Last color set with render state
- Color m_lastColor;
+ Color m_lastColor;
//! Last texture names for 2 used texture stages
std::string m_lastTexture[2];
//! Last material
- Material m_lastMaterial;
+ Material m_lastMaterial;
};