From efe4f0baddf10124581e4fcb88d55a52838b06a1 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 9 Sep 2012 17:51:10 +0200 Subject: Refactoring in src/common - refactored CInstanceManager and some headers - removed old headers --- src/app/app.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index 7991177..b92c6b6 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -22,8 +22,7 @@ #pragma once - -#include "common/misc.h" +#include "common/global.h" #include "common/singleton.h" #include "graphics/core/device.h" #include "graphics/engine/engine.h" @@ -198,6 +197,12 @@ public: //! Returns the full path to a file in data directory std::string GetDataFilePath(const std::string &dirName, const std::string &fileName); + //! Management of language + //@{ + Language GetLanguage(); + void SetLanguage(Language language); + //@} + protected: //! Creates the window's SDL_Surface bool CreateVideoSurface(); @@ -267,5 +272,8 @@ protected: //! Path to directory with data files std::string m_dataPath; + + //! Application language + Language m_language; }; -- cgit v1.2.3-1-g7c22 From 34d7dcf3be24de04b2b9c64edb2666439b353a5b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 12 Sep 2012 23:43:04 +0200 Subject: Simulation timestamps and input bindings - added new simulation time calculations in CApplication - added simulation frame updates - rewritten old input binding code and input state tracking --- src/app/app.h | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 191 insertions(+), 25 deletions(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index b92c6b6..4d567e0 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -38,8 +38,9 @@ class CRobotMain; class CSound; /** - \struct JoystickDevice - \brief Information about a joystick device */ + * \struct JoystickDevice + * \brief Information about a joystick device + */ struct JoystickDevice { //! Device index (-1 = invalid device) @@ -56,8 +57,9 @@ struct JoystickDevice }; /** - \enum VideoQueryResult - \brief Result of querying for available video resolutions */ + * \enum VideoQueryResult + * \brief Result of querying for available video resolutions + */ enum VideoQueryResult { VIDEO_QUERY_ERROR, @@ -67,6 +69,83 @@ enum VideoQueryResult }; +/** + * \enum TrackedKeys + * \brief Keys (or kmods) whose state (pressed/released) is tracked by CApplication + */ +enum TrackedKey +{ + TRKEY_SHIFT, + TRKEY_CONTROL, + TRKEY_NUM_UP, + TRKEY_NUM_DOWN, + TRKEY_NUM_LEFT, + TRKEY_NUM_RIGHT, + TRKEY_NUM_PLUS, + TRKEY_NUM_MINUS, + TRKEY_PAGE_UP, + TRKEY_PAGE_DOWN, + TRKEY_MAX +}; + +/** + * \enum InputSlot + * \brief Available slots for input bindings + */ +enum InputSlot +{ + INPUT_SLOT_LEFT = 0, + INPUT_SLOT_RIGHT = 1, + INPUT_SLOT_UP = 2, + INPUT_SLOT_DOWN = 3, + INPUT_SLOT_GUP = 4, + INPUT_SLOT_GDOWN = 5, + INPUT_SLOT_CAMERA = 6, + INPUT_SLOT_DESEL = 7, + INPUT_SLOT_ACTION = 8, + INPUT_SLOT_NEAR = 9, + INPUT_SLOT_AWAY = 10, + INPUT_SLOT_NEXT = 11, + INPUT_SLOT_HUMAN = 12, + INPUT_SLOT_QUIT = 13, + INPUT_SLOT_HELP = 14, + INPUT_SLOT_PROG = 15, + INPUT_SLOT_VISIT = 16, + INPUT_SLOT_SPEED10 = 17, + INPUT_SLOT_SPEED15 = 18, + INPUT_SLOT_SPEED20 = 19, + INPUT_SLOT_SPEED30 = 20, + INPUT_SLOT_AIMUP = 21, + INPUT_SLOT_AIMDOWN = 22, + INPUT_SLOT_CBOT = 23, + + INPUT_SLOT_MAX +}; + +/** + * \struct InputBinding + * \brief Settable binding for user input + */ +struct InputBinding +{ + //! Key + int key; + //! Key modifier (e.g. shift, control) + int kmod; + //! Joystick button + int joy; + + inline InputBinding() + { + Reset(); + } + + inline void Reset() + { + key = kmod = joy = -1; + } +}; + struct ApplicationPrivate; /** @@ -146,8 +225,37 @@ public: //! Change the video mode to given mode bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig); + //! Suspends animation (time will not be updated) + void SuspendSimulation(); + //! Resumes animation + void ResumeSimulation(); + //! Returns whether simulation is suspended + bool GetSimulationSuspended(); + //! Updates the simulation state - void StepSimulation(float rTime); + void StepSimulation(); + + //@{ + //! Management of simulation speed + void SetSimulationSpeed(float speed); + float GetSimulationSpeed(); + //@} + + //! Returns the absolute time counter [seconds] + float GetAbsTime(); + //! Returns the exact absolute time counter [nanoseconds] + long long GetExactAbsTime(); + + //! Returns the exact absolute time counter disregarding speed setting [nanoseconds] + long long GetRealAbsTime(); + + //! Returns the relative time since last update [seconds] + float GetRelTime(); + //! Returns the exact realative time since last update [nanoseconds] + long long GetExactRelTime(); + + //! Returns the exact relative time since last update disregarding speed setting [nanoseconds] + long long GetRealRelTime(); //! Returns a list of available joystick devices std::vector GetJoystickList(); @@ -158,10 +266,11 @@ public: //! Change the current joystick device bool ChangeJoystick(const JoystickDevice &newJoystick); - //! Enables/disables joystick + //! Management of joystick enable state + //@{ void SetJoystickEnabled(bool enable); - //! Returns whether joystick is enabled bool GetJoystickEnabled(); + //@} //! Polls the state of joystick axes and buttons void UpdateJoystick(); @@ -169,30 +278,56 @@ public: //! Updates the mouse position explicitly void UpdateMouse(); - void FlushPressKey(); - void ResetKey(); - void SetKey(int keyRank, int option, int key); - int GetKey(int keyRank, int option); + //! Returns the current key modifiers + int GetKmods(); + //! Returns whether the given kmod is active + bool GetKmodState(int kmod); + + //! Returns whether the tracked key is pressed + bool GetTrackedKeyState(TrackedKey key); - //! Sets the grab mode for input (keyboard & mouse) + //! Returns whether the mouse button is pressed + bool GetMouseButtonState(int index); + + //! Resets tracked key states, modifiers and motion vectors + void ResetKeyStates(); + + + // TODO move input binding and motion vectors to CRobotMain + + //! Sets the default input bindings + void SetDefaultInputBindings(); + + //! Management of input bindings + //@{ + void SetInputBinding(InputSlot slot, const InputBinding& binding); + const InputBinding& GetInputBinding(InputSlot slot); + //@} + + + //! Management of the grab mode for input (keyboard & mouse) + //@{ void SetGrabInput(bool grab); - //! Returns the grab mode bool GetGrabInput(); + //@} - //! Sets the visiblity of system mouse cursor + //! Management of the visiblity of system mouse cursor + //@{ void SetSystemMouseVisible(bool visible); - //! Returns the visiblity of system mouse cursor bool GetSystemMouseVisibile(); + //@} - //! Sets the position of system mouse cursor (in interface coords) + //! Management of 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(); + //@} - //! Enables/disables debug mode (prints more info in logger) + //! Management of debug mode (prints more info in logger) + //@{ void SetDebugMode(bool mode); - //! Returns whether debug mode is enabled bool GetDebugMode(); + //@} //! Returns the full path to a file in data directory std::string GetDataFilePath(const std::string &dirName, const std::string &fileName); @@ -253,13 +388,44 @@ protected: //! Text set as window title std::string m_windowTitle; - int m_keyState; - Math::Vector m_axeKey; - Math::Vector m_axeJoy; - Math::Point m_systemMousePos; - long m_mouseWheel; + //! Animation time stamps, etc. + //@{ + SystemTimeStamp* m_baseTimeStamp; + SystemTimeStamp* m_lastTimeStamp; + SystemTimeStamp* m_curTimeStamp; + + long long m_realAbsTimeBase; + long long m_realAbsTime; + long long m_realRelTime; + + long long m_absTimeBase; + long long m_exactAbsTime; + long long m_exactRelTime; - long m_key[50][2]; + float m_absTime; + float m_relTime; + + float m_simulationSpeed; + bool m_simulationSuspended; + //@} + + //! Current state of key modifiers (mask of SDLMod) + unsigned int m_kmodState; + //! Current state of some tracked keys (mask of TrackedKey) + bool m_trackedKeysState[TRKEY_MAX]; + //! Current state of mouse buttons (mask of button indexes) + unsigned int m_mouseButtonsState; + + //! Bindings for user inputs + InputBinding m_inputBindings[INPUT_SLOT_MAX]; + + //! Motion vector set by keyboard + Math::Vector m_keyMotion; + //! Motion vector set by joystick + Math::Vector m_joyMotion; + + //! Current system mouse position + Math::Point m_systemMousePos; //! Info about current joystick device JoystickDevice m_joystick; -- cgit v1.2.3-1-g7c22 From af9af56bb007050c969af310c4e816d260b9ce7f Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 15 Sep 2012 22:19:32 +0200 Subject: Successful compilation & running - temporarily mocked CSoundInterface and CPluginInterface - added CRobotMain to application - successfully compiles & runs, but doesn't display correctly at the moment --- src/app/app.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index 4d567e0..1834a67 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -35,7 +35,7 @@ class CInstanceManager; class CEvent; class CRobotMain; -class CSound; +class CSoundInterface; /** * \struct JoystickDevice @@ -366,7 +366,7 @@ protected: //! Graphics device Gfx::CDevice* m_device; //! Sound subsystem - CSound* m_sound; + CSoundInterface* m_sound; //! Main class of the proper game engine CRobotMain* m_robotMain; -- cgit v1.2.3-1-g7c22 From 4b67386a697c27186b6eb4809bea9547372dacd7 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 17 Sep 2012 23:41:53 +0200 Subject: Change of background image handling - removed old 4 quarter backgrounds - fixes in texture loading - other minor fixes --- src/app/app.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index 1834a67..1275d10 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -146,6 +146,17 @@ struct InputBinding } }; +/** + * \enum ParseArgsStatus + * \brief State of parsing commandline arguments + */ +enum ParseArgsStatus +{ + PARSE_ARGS_OK = 1, //! < all ok + PARSE_ARGS_FAIL = 2, //! < invalid syntax + PARSE_ARGS_HELP = 3 //! < -help requested +}; + struct ApplicationPrivate; /** @@ -201,7 +212,7 @@ public: public: //! Parses commandline arguments - bool ParseArguments(int argc, char *argv[]); + ParseArgsStatus ParseArguments(int argc, char *argv[]); //! Initializes the application bool Create(); //! Main event loop -- cgit v1.2.3-1-g7c22 From a397922e8d53c6f7ff469d38e5139fd003c705b5 Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Tue, 18 Sep 2012 00:01:00 +0200 Subject: warnings fight in progress. --- src/app/app.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index 1834a67..849f441 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -129,11 +129,11 @@ enum InputSlot struct InputBinding { //! Key - int key; + unsigned int key; //! Key modifier (e.g. shift, control) - int kmod; + unsigned int kmod; //! Joystick button - int joy; + unsigned int joy; inline InputBinding() { @@ -142,7 +142,7 @@ struct InputBinding inline void Reset() { - key = kmod = joy = -1; + key = kmod = joy = static_cast(-1); } }; -- cgit v1.2.3-1-g7c22 From 4a639cf543c15d45a37674d7eadaf09c23c2203d Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Wed, 19 Sep 2012 00:04:21 +0200 Subject: Fixed includes in ui. --- src/app/app.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index 8848be1..d3fa647 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -452,5 +452,9 @@ protected: //! Application language Language m_language; + +private: + //! Set locale, needed for putenv/setenv + std::string m_locale; }; -- cgit v1.2.3-1-g7c22 From 51884cef8e015bccbe1fa96dc56dc2f32439ccc5 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 19 Sep 2012 18:32:18 +0200 Subject: Input bindings rewrite - moved input bindings to CRobotMain - added virtual keymod and joystick button key presses - fixed putenv error; other minor fixes --- src/app/app.h | 105 ++++++++-------------------------------------------------- 1 file changed, 14 insertions(+), 91 deletions(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index d3fa647..8429e0e 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -75,75 +75,16 @@ enum VideoQueryResult */ enum TrackedKey { - TRKEY_SHIFT, - TRKEY_CONTROL, - TRKEY_NUM_UP, - TRKEY_NUM_DOWN, - TRKEY_NUM_LEFT, - TRKEY_NUM_RIGHT, - TRKEY_NUM_PLUS, - TRKEY_NUM_MINUS, - TRKEY_PAGE_UP, - TRKEY_PAGE_DOWN, - TRKEY_MAX -}; - -/** - * \enum InputSlot - * \brief Available slots for input bindings - */ -enum InputSlot -{ - INPUT_SLOT_LEFT = 0, - INPUT_SLOT_RIGHT = 1, - INPUT_SLOT_UP = 2, - INPUT_SLOT_DOWN = 3, - INPUT_SLOT_GUP = 4, - INPUT_SLOT_GDOWN = 5, - INPUT_SLOT_CAMERA = 6, - INPUT_SLOT_DESEL = 7, - INPUT_SLOT_ACTION = 8, - INPUT_SLOT_NEAR = 9, - INPUT_SLOT_AWAY = 10, - INPUT_SLOT_NEXT = 11, - INPUT_SLOT_HUMAN = 12, - INPUT_SLOT_QUIT = 13, - INPUT_SLOT_HELP = 14, - INPUT_SLOT_PROG = 15, - INPUT_SLOT_VISIT = 16, - INPUT_SLOT_SPEED10 = 17, - INPUT_SLOT_SPEED15 = 18, - INPUT_SLOT_SPEED20 = 19, - INPUT_SLOT_SPEED30 = 20, - INPUT_SLOT_AIMUP = 21, - INPUT_SLOT_AIMDOWN = 22, - INPUT_SLOT_CBOT = 23, - - INPUT_SLOT_MAX -}; - -/** - * \struct InputBinding - * \brief Settable binding for user input - */ -struct InputBinding -{ - //! Key - unsigned int key; - //! Key modifier (e.g. shift, control) - unsigned int kmod; - //! Joystick button - unsigned int joy; - - inline InputBinding() - { - Reset(); - } - - inline void Reset() - { - key = kmod = joy = static_cast(-1); - } + TRKEY_SHIFT = (1<<0), + TRKEY_CONTROL = (1<<1), + TRKEY_NUM_UP = (1<<2), + TRKEY_NUM_DOWN = (1<<3), + TRKEY_NUM_LEFT = (1<<4), + TRKEY_NUM_RIGHT = (1<<5), + TRKEY_NUM_PLUS = (1<<6), + TRKEY_NUM_MINUS = (1<<7), + TRKEY_PAGE_UP = (1<<8), + TRKEY_PAGE_DOWN = (1<<9) }; /** @@ -303,19 +244,6 @@ public: //! Resets tracked key states, modifiers and motion vectors void ResetKeyStates(); - - // TODO move input binding and motion vectors to CRobotMain - - //! Sets the default input bindings - void SetDefaultInputBindings(); - - //! Management of input bindings - //@{ - void SetInputBinding(InputSlot slot, const InputBinding& binding); - const InputBinding& GetInputBinding(InputSlot slot); - //@} - - //! Management of the grab mode for input (keyboard & mouse) //@{ void SetGrabInput(bool grab); @@ -355,8 +283,10 @@ protected: //! Processes the captured SDL event to Event struct Event ParseEvent(); + //! If applicable, creates a virtual event to match the changed state as of new event + Event CreateVirtualEvent(const Event& sourceEvent); //! Handles some incoming events - bool ProcessEvent(const Event &event); + bool ProcessEvent(Event &event); //! Renders the image in window void Render(); @@ -423,13 +353,10 @@ protected: //! Current state of key modifiers (mask of SDLMod) unsigned int m_kmodState; //! Current state of some tracked keys (mask of TrackedKey) - bool m_trackedKeysState[TRKEY_MAX]; + unsigned int m_trackedKeys; //! Current state of mouse buttons (mask of button indexes) unsigned int m_mouseButtonsState; - //! Bindings for user inputs - InputBinding m_inputBindings[INPUT_SLOT_MAX]; - //! Motion vector set by keyboard Math::Vector m_keyMotion; //! Motion vector set by joystick @@ -452,9 +379,5 @@ protected: //! Application language Language m_language; - -private: - //! Set locale, needed for putenv/setenv - std::string m_locale; }; -- cgit v1.2.3-1-g7c22 From 10c9d92cd2581448d76548efb20957a7a1c24478 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 19 Sep 2012 21:23:42 +0200 Subject: Mouse wheel events, motion vectors - added mouse wheel events - added motion vectors to CRobotMain - other minor changes in event.h --- src/app/app.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/app/app.h') diff --git a/src/app/app.h b/src/app/app.h index 8429e0e..33be5a5 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -112,7 +112,7 @@ struct ApplicationPrivate; * \section Creation Creation of other main objects * * The class creates the only instance of CInstanceManager, CEventQueue, CEngine, - * CRobotMain and CSound classes. + * CRobotMain and CSoundInterface classes. * * \section Window Window management * @@ -241,7 +241,7 @@ public: //! Returns whether the mouse button is pressed bool GetMouseButtonState(int index); - //! Resets tracked key states, modifiers and motion vectors + //! Resets tracked key states and modifiers void ResetKeyStates(); //! Management of the grab mode for input (keyboard & mouse) @@ -307,7 +307,7 @@ protected: //! Graphics device Gfx::CDevice* m_device; //! Sound subsystem - CSoundInterface* m_sound; + CSoundInterface* m_sound; //! Main class of the proper game engine CRobotMain* m_robotMain; @@ -357,11 +357,6 @@ protected: //! Current state of mouse buttons (mask of button indexes) unsigned int m_mouseButtonsState; - //! Motion vector set by keyboard - Math::Vector m_keyMotion; - //! Motion vector set by joystick - Math::Vector m_joyMotion; - //! Current system mouse position Math::Point m_systemMousePos; -- cgit v1.2.3-1-g7c22