Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

System.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*!
  2. * \file include/System.h
  3. * \brief Mostly defines the interface of System implementations.
  4. *
  5. * Currently only SDL is used, but there was a GLUT implementation.
  6. *
  7. * \author Mongoose
  8. * \author xythobuz
  9. */
  10. #ifndef _SYSTEM_H_
  11. #define _SYSTEM_H_
  12. #include <map>
  13. #include "templates/Vector.h"
  14. #include "utils/strings.h"
  15. //! \todo Replace with unicode compatible key codes
  16. #define SYS_MOUSE_LEFT 6000
  17. #define SYS_MOUSE_RIGHT 6001
  18. #define SYS_MOUSE_MIDDLE 6002
  19. #define SYS_KEY_ESC 27
  20. #define SYS_KEY_ENTER 13
  21. #define SYS_KEY_UP 5000
  22. #define SYS_KEY_DOWN 5001
  23. #define SYS_KEY_RIGHT 5002
  24. #define SYS_KEY_LEFT 5003
  25. #define SYS_KEY_PAGEDOWN 5004
  26. #define SYS_KEY_PAGEUP 5005
  27. #define SYS_KEY_F1 1000
  28. #define SYS_KEY_F2 1001
  29. #define SYS_KEY_F3 1002
  30. #define SYS_KEY_F4 1003
  31. #define SYS_KEY_F5 1004
  32. #define SYS_KEY_F6 1005
  33. #define SYS_KEY_F7 1006
  34. #define SYS_KEY_F8 1007
  35. #define SYS_KEY_F9 1008
  36. #define SYS_KEY_F10 1009
  37. #define SYS_KEY_F11 1010
  38. #define SYS_KEY_F12 1011
  39. typedef enum {
  40. SYS_MOD_KEY_LSHIFT = 1,
  41. SYS_MOD_KEY_RSHIFT = 2,
  42. SYS_MOD_KEY_LCTRL = 4,
  43. SYS_MOD_KEY_RCTRL = 8,
  44. SYS_MOD_KEY_LALT = 16,
  45. SYS_MOD_KEY_RALT = 32,
  46. SYS_MOD_KEY_LMETA = 64,
  47. SYS_MOD_KEY_RMETA = 128
  48. } sdl_sys_mod_key_t;
  49. /*!
  50. * \brief Basic Interface for System implementations (SDLSystem)
  51. */
  52. class System {
  53. public:
  54. /*!
  55. * \brief Constructs an object of System
  56. */
  57. System();
  58. /*!
  59. * \brief Deconstructs an object of System
  60. */
  61. virtual ~System();
  62. /*!
  63. * \brief Created a directory
  64. * \param path Directory to create
  65. * \returns -1 on error
  66. */
  67. static int createDir(char *path);
  68. /*!
  69. * \brief Created a new Command Mode.
  70. * \param command valid command mode for the resource file, eg "[Engine.OpenGL.Driver]"
  71. * \returns id given to mode
  72. */
  73. virtual unsigned int addCommandMode(const char *command);
  74. /*!
  75. * \brief Binds a key to a command
  76. * \param cmd valid command string for event
  77. * \param key valid keyboard code
  78. * \param event valid game event id
  79. */
  80. virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
  81. /*!
  82. * \brief Executes a command string
  83. * \param cmd valid command string, cmd sets its var
  84. */
  85. virtual void command(const char *cmd);
  86. virtual void gameFrame() = 0;
  87. virtual void handleMouseMotionEvent(float x, float y) = 0;
  88. /*!
  89. * \brief Receives the event bound to the command from the key press
  90. * \param key key pressed
  91. */
  92. virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
  93. /*!
  94. * \brief Receives the event bound to the command from the key release
  95. * \param key key released
  96. */
  97. virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
  98. /*!
  99. * \brief Executes valid command based on keyword
  100. * \param command valid keyword, optionally followed by space separated arguments
  101. * \param mode current type or resource mode
  102. */
  103. virtual void handleCommand(char *command, unsigned int mode) = 0;
  104. /*!
  105. * \brief Receives key code from text input in console mode
  106. * \param key is a valid keyboard code
  107. * \param mod modifier key
  108. */
  109. virtual void handleConsoleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  110. virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  111. virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
  112. virtual void initVideo(unsigned int width, unsigned int height, bool fullscreen) = 0;
  113. /*!
  114. * \brief Init the resource vars
  115. * \param filename resource file
  116. * \returns < 0 on error
  117. */
  118. virtual int loadResourceFile(const char *filename);
  119. virtual void resizeGL(unsigned int width, unsigned int height);
  120. virtual void runGame() = 0;
  121. /*!
  122. * \brief Turns console key events on/off
  123. * Mostly for allowing text entry vs key impulse commands
  124. * \param on new state
  125. */
  126. void setConsoleMode(bool on);
  127. void setDriverGL(const char *driver);
  128. virtual void shutdown(int code) = 0;
  129. virtual void swapBuffersGL() = 0;
  130. virtual void toggleFullscreen() = 0;
  131. protected:
  132. unsigned int m_width; //!< Width of the viewport
  133. unsigned int m_height; //!< Height of the viewport
  134. char *m_driver; //!< String for dynamic use of GL library
  135. float m_clipNear; //!< Clip near distance
  136. float m_clipFar; //!< Clip far distance
  137. float m_fovY; //!< Field of vision
  138. std::map<unsigned int, int> mKeyEvents; //!< Single key press event mappings
  139. bool mConsoleMode; //!< Using text (console) event handler?
  140. Vector<const char *> mCmdModes; //!< Dynamic resource command collection
  141. unsigned int mCommandMode; //!< Current resource command mode
  142. unsigned int mConsoleKey; //!< Console toggle event now handled lower
  143. };
  144. #endif