summaryrefslogtreecommitdiffstats
path: root/src/app
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/app
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/app')
-rw-r--r--src/app/app.cpp70
-rw-r--r--src/app/app.h46
2 files changed, 78 insertions, 38 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 23e6d9f..1da237e 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -15,16 +15,18 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
-// app.cpp
#include "app/app.h"
#include "app/system.h"
+
#include "common/logger.h"
#include "common/iman.h"
#include "common/image.h"
#include "common/key.h"
+
#include "graphics/opengl/gldevice.h"
+
#include "object/robotmain.h"
@@ -35,6 +37,7 @@
#include <stdlib.h>
#include <libintl.h>
+#include <unistd.h>
template<> CApplication* CSingleton<CApplication>::mInstance = nullptr;
@@ -116,6 +119,8 @@ CApplication::CApplication()
m_joystickEnabled = false;
+ m_mouseMode = MOUSE_SYSTEM;
+
m_kmodState = 0;
m_mouseButtonsState = 0;
m_trackedKeys = 0;
@@ -123,6 +128,8 @@ CApplication::CApplication()
m_dataPath = "./data";
m_language = LANG_ENGLISH;
+
+ m_lowCPU = true;
}
CApplication::~CApplication()
@@ -649,8 +656,7 @@ void CApplication::UpdateMouse()
{
Math::IntPoint pos;
SDL_GetMouseState(&pos.x, &pos.y);
- m_systemMousePos = m_engine->WindowToInterfaceCoords(pos);
- m_engine->SetMousePos(m_systemMousePos);
+ m_mousePos = m_engine->WindowToInterfaceCoords(pos);
}
int CApplication::Run()
@@ -661,6 +667,8 @@ int CApplication::Run()
GetCurrentTimeStamp(m_lastTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
+ MoveMouse(Math::Point(0.5f, 0.5f)); // center mouse on start
+
while (true)
{
// To be sure no old event remains
@@ -752,6 +760,11 @@ int CApplication::Run()
// Update simulation state
StepSimulation();
+
+ if (m_lowCPU)
+ {
+ usleep(20000); // should still give plenty of fps
+ }
}
}
@@ -889,25 +902,12 @@ bool CApplication::ProcessEvent(Event &event)
CLogger *l = GetLogger();
event.trackedKeys = m_trackedKeys;
- if (GetSystemMouseVisibile())
- event.mousePos = m_systemMousePos;
- else
- event.mousePos = m_engine->GetMousePos();
+ event.mousePos = m_mousePos;
if (event.type == EVENT_ACTIVE)
{
if (m_debugMode)
l->Info("Focus change: active = %s\n", event.active.gain ? "true" : "false");
-
- /*if (m_active != event.active.gain)
- {
- m_active = event.active.gain;
-
- if (m_active)
- ResumeSimulation();
- else
- SuspendSimulation();
- }*/
}
else if (event.type == EVENT_KEY_DOWN)
{
@@ -1268,27 +1268,31 @@ bool CApplication::GetGrabInput()
return result == SDL_GRAB_ON;
}
-void CApplication::SetSystemMouseVisible(bool visible)
+void CApplication::SetMouseMode(MouseMode mode)
{
- SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
+ m_mouseMode = mode;
+ if ((m_mouseMode == MOUSE_SYSTEM) || (m_mouseMode == MOUSE_BOTH))
+ SDL_ShowCursor(SDL_ENABLE);
+ else
+ SDL_ShowCursor(SDL_DISABLE);
}
-bool CApplication::GetSystemMouseVisibile()
+MouseMode CApplication::GetMouseMode()
{
- int result = SDL_ShowCursor(SDL_QUERY);
- return result == SDL_ENABLE;
+ return m_mouseMode;
}
-void CApplication::SetSystemMousePos(Math::Point pos)
+Math::Point CApplication::GetMousePos()
{
- Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
- SDL_WarpMouse(windowPos.x, windowPos.y);
- m_systemMousePos = pos;
+ return m_mousePos;
}
-Math::Point CApplication::GetSystemMousePos()
+void CApplication::MoveMouse(Math::Point pos)
{
- return m_systemMousePos;
+ m_mousePos = pos;
+
+ Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
+ SDL_WarpMouse(windowPos.x, windowPos.y);
}
std::vector<JoystickDevice> CApplication::GetJoystickList()
@@ -1349,3 +1353,13 @@ void CApplication::SetLanguage(Language language)
{
m_language = language;
}
+
+void CApplication::SetLowCPU(bool low)
+{
+ m_lowCPU = low;
+}
+
+bool CApplication::GetLowCPU()
+{
+ return m_lowCPU;
+}
diff --git a/src/app/app.h b/src/app/app.h
index 33be5a5..03199aa 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -22,12 +22,15 @@
#pragma once
+
#include "common/global.h"
#include "common/singleton.h"
+
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "graphics/opengl/gldevice.h"
+
#include <string>
#include <vector>
@@ -98,6 +101,18 @@ enum ParseArgsStatus
PARSE_ARGS_HELP = 3 //! < -help requested
};
+/**
+ * \enum MouseMode
+ * \brief Mode of mouse cursor
+ */
+enum MouseMode
+{
+ MOUSE_SYSTEM, //! < system cursor visible; in-game cursor hidden
+ MOUSE_ENGINE, //! < in-game cursor visible; system cursor hidden
+ MOUSE_BOTH, //! < both cursors visible (only for debug)
+ MOUSE_NONE, //! < no cursor visible
+};
+
struct ApplicationPrivate;
/**
@@ -250,17 +265,17 @@ public:
bool GetGrabInput();
//@}
- //! Management of the visiblity of system mouse cursor
+ //! Management of mouse mode
//@{
- void SetSystemMouseVisible(bool visible);
- bool GetSystemMouseVisibile();
+ void SetMouseMode(MouseMode mode);
+ MouseMode GetMouseMode();
//@}
- //! Management of the position of system mouse cursor (in interface coords)
- //@{
- void SetSystemMousePos(Math::Point pos);
- Math::Point GetSystemMousePos();
- //@}
+ //! Returns the position of mouse cursor (in interface coords)
+ Math::Point GetMousePos();
+
+ //! Moves (warps) the mouse cursor to the specified position (in interface coords)
+ void MoveMouse(Math::Point pos);
//! Management of debug mode (prints more info in logger)
//@{
@@ -277,6 +292,12 @@ public:
void SetLanguage(Language language);
//@}
+ //! Management of sleep in main loop (lowers CPU usage)
+ //@{
+ void SetLowCPU(bool low);
+ bool GetLowCPU();
+ //@}
+
protected:
//! Creates the window's SDL_Surface
bool CreateVideoSurface();
@@ -357,8 +378,10 @@ protected:
//! Current state of mouse buttons (mask of button indexes)
unsigned int m_mouseButtonsState;
- //! Current system mouse position
- Math::Point m_systemMousePos;
+ //! Current mode of mouse
+ MouseMode m_mouseMode;
+ //! Current position of mouse cursor
+ Math::Point m_mousePos;
//! Info about current joystick device
JoystickDevice m_joystick;
@@ -374,5 +397,8 @@ protected:
//! Application language
Language m_language;
+
+ //! Low cpu mode
+ bool m_lowCPU;
};