summaryrefslogtreecommitdiffstats
path: root/src/app/app.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/app.h')
-rw-r--r--src/app/app.h153
1 files changed, 103 insertions, 50 deletions
diff --git a/src/app/app.h b/src/app/app.h
index f776b10..956eab8 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -21,10 +21,12 @@
#include "common/misc.h"
-#include "graphics/common/device.h"
-#include "graphics/common/engine.h"
+#include "common/singleton.h"
+#include "graphics/core/device.h"
+#include "graphics/engine/engine.h"
#include <string>
+#include <vector>
class CInstanceManager;
@@ -32,19 +34,41 @@ class CEvent;
class CRobotMain;
class CSound;
-struct ApplicationPrivate;
+struct ApplicationPrivate;
/**
* \class CApplication
* \brief Main application
*
- * This class is responsible for creating and handling main application window,
- * receiving events, etc.
+ * This class is responsible for main application execution, including creating
+ * and handling main application window, receiving events, etc.
+ *
+ * It is a singleton class with only one instance that can be created.
+ *
+ * Creation of other main objects
+ *
+ * The class creates the only instance of CInstanceManager, CEventQueue, CEngine,
+ * CRobotMain and CSound classes.
+ *
+ * Window management
+ *
+ * The class is responsible for creating app window, setting and changing the video mode,
+ * setting the position of mouse and changing the cursor, grabbing and writing screenshots.
+ *
+ * Events
+ *
+ * Events are taken from SDL event queue and either handled by CApplication or translated
+ * to common events from src/common.h and pushed to global event queue CEventQueue.
+ * Joystick events are generated somewhat differently, by running a separate timer,
+ * polling the device for changes and synthesising events on change. It avoids flooding
+ * the event queue with too many joystick events and the granularity of the timer can be
+ * adjusted.
+ *
+ * The events are further handled in CRobotMain class.
*
- * ...
*/
-class CApplication
+class CApplication : public CSingleton<CApplication>
{
public:
//! Constructor (can only be called once!)
@@ -54,61 +78,79 @@ public:
public:
//! Parses commandline arguments
- Error ParseArguments(int argc, char *argv[]);
+ bool ParseArguments(int argc, char *argv[]);
//! Initializes the application
bool Create();
//! Main event loop
int Run();
-
//! Returns the code to be returned at main() exit
int GetExitCode();
-protected:
//! Cleans up before exit
void Destroy();
- //! Processes an SDL event to Event struct
- void ParseEvent();
- //! Handles some incoming events
- void ProcessEvent(Event event);
- //! Renders the image in window
- bool Render();
-public:
+ //! Enters the pause mode
void Pause(bool pause);
+
+ //! Updates the simulation state
void StepSimulation(float rTime);
- void SetMousePos(Math::Point pos);
+ //! Polls the state of joystick axes and buttons
+ void UpdateJoystick();
void SetShowStat(bool show);
- bool RetShowStat();
+ bool GetShowStat();
+
void SetDebugMode(bool mode);
- bool RetDebugMode();
- bool RetSetupMode();
+ bool GetDebugMode();
+
+ bool GetSetupMode();
+
+ void SetJoystickEnabled(bool enable);
+ bool GetJoystickEnabled();
void FlushPressKey();
void ResetKey();
void SetKey(int keyRank, int option, int key);
- int RetKey(int keyRank, int option);
+ int GetKey(int keyRank, int option);
+
+ //! Sets the grab mode for input (keyboard & mouse)
+ void SetGrabInput(bool grab);
+ //! Returns the grab mode
+ bool GetGrabInput();
- void SetJoystick(bool enable);
- bool RetJoystick();
+ //! Sets the visiblity of system mouse cursor
+ void SetSystemMouseVisible(bool visible);
+ //! Returns the visiblity of system mouse cursor
+ bool GetSystemMouseVisibile();
- void SetMouseType(Gfx::MouseType type);
- void SetNiceMouse(bool nice);
- bool RetNiceMouse();
- bool RetNiceMouseCap();
+ //! Sets the position of system mouse cursor (in interface coords)
+ void SetSystemMousePos(Math::Point pos);
+ //! Returns the position of system mouse cursor (in interface coords)
+ Math::Point GetSystemMousePos();
bool WriteScreenShot(char *filename, int width, int height);
+ //! Returns the full path to a file in data directory
+ std::string GetDataFilePath(const std::string &dirName, const std::string &fileName);
+
protected:
- //HRESULT ConfirmDevice( DDCAPS* pddDriverCaps, D3DDEVICEDESC7* pd3dDeviceDesc );
- //HRESULT Initialize3DEnvironment();
- //HRESULT Change3DEnvironment();
- //HRESULT CreateZBuffer(GUID* pDeviceGUID);
- //HRESULT Render3DEnvironment();
- //VOID Cleanup3DEnvironment();
- //VOID DeleteDeviceObjects();
- //VOID DisplayFrameworkError( HRESULT, DWORD );
+ //! Processes the captured SDL event to Event struct
+ Event ParseEvent();
+ //! Handles some incoming events
+ bool ProcessEvent(const Event &event);
+ //! Renders the image in window
+ bool Render();
+
+ //! Opens the joystick device
+ bool OpenJoystick();
+ //! Closes the joystick device
+ void CloseJoystick();
+
+ //! Converts window coords to interface coords
+ Math::Point WindowToInterfaceCoords(Math::IntPoint pos);
+ //! Converts the interface coords to window coords
+ Math::IntPoint InterfaceToWindowCoords(Math::Point pos);
void InitText();
void DrawSuppl();
@@ -116,14 +158,20 @@ protected:
void OutputText(long x, long y, char* str);
protected:
+ //! Instance manager
+ CInstanceManager* m_iMan;
//! Private (SDL-dependent data)
ApplicationPrivate* m_private;
- CInstanceManager* m_iMan;
- Gfx::DeviceConfig m_deviceConfig;
+ //! Global event queue
+ CEventQueue* m_eventQueue;
+ //! Graphics engine
Gfx::CEngine* m_engine;
- CEvent* m_event;
- CRobotMain* m_robotMain;
+ //! Graphics device
+ Gfx::CDevice* m_device;
+ //! Sound subsystem
CSound* m_sound;
+ //! Main class of the proper game engine
+ CRobotMain* m_robotMain;
//! Code to return at exit
int m_exitCode;
@@ -131,27 +179,32 @@ protected:
bool m_active;
bool m_activateApp;
bool m_ready;
- bool m_joystick;
- std::string m_windowTitle;
- long m_vidMemTotal;
- bool m_appUseZBuffer;
- bool m_appUseStereo;
bool m_showStats;
bool m_debugMode;
- bool m_audioState;
- bool m_audioTrack;
- bool m_niceMouse;
bool m_setupMode;
+ //! Whether joystick is enabled
+ bool m_joystickEnabled;
+
+ //! Text set as window title
+ std::string m_windowTitle;
+
int m_keyState;
Math::Vector m_axeKey;
Math::Vector m_axeJoy;
- bool m_joyButton[32];
- Math::Point m_mousePos;
+ Math::Point m_systemMousePos;
long m_mouseWheel;
+ //! Current state of joystick axes; may be updated from another thread
+ std::vector<int> m_joyAxeState;
+ //! Current state of joystick buttons; may be updated from another thread
+ std::vector<bool> m_joyButtonState;
+
float m_time;
long m_key[50][2];
+
+ //! Path to directory with data files
+ std::string m_dataPath;
};