Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

System.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 Gets the game tick
  64. * \returns number of milliseconds since start of program
  65. */
  66. virtual unsigned int getTicks();
  67. /*!
  68. * \brief Created a directory
  69. * \param path Directory to create
  70. * \returns -1 on error
  71. */
  72. static int createDir(char *path);
  73. /*!
  74. * \brief Created a new Command Mode.
  75. * \param command valid command mode for the resource file, eg "[Engine.OpenGL.Driver]"
  76. * \returns id given to mode
  77. */
  78. virtual unsigned int addCommandMode(const char *command);
  79. /*!
  80. * \brief Binds a key to a command
  81. * \param cmd valid command string for event
  82. * \param key valid keyboard code
  83. * \param event valid game event id
  84. */
  85. virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
  86. /*!
  87. * \brief Executes a command string
  88. * \param cmd valid command string, cmd sets its var
  89. */
  90. virtual void command(const char *cmd);
  91. virtual void gameFrame() = 0;
  92. virtual void handleMouseMotionEvent(float x, float y) = 0;
  93. /*!
  94. * \brief Receives the event bound to the command from the key press
  95. * \param key key pressed
  96. */
  97. virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
  98. /*!
  99. * \brief Receives the event bound to the command from the key release
  100. * \param key key released
  101. */
  102. virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
  103. /*!
  104. * \brief Executes valid command based on keyword
  105. * \param command valid keyword, optionally followed by space separated arguments
  106. * \param mode current type or resource mode
  107. */
  108. virtual void handleCommand(char *command, unsigned int mode) = 0;
  109. /*!
  110. * \brief Receives key code from text input in console mode
  111. * \param key is a valid keyboard code
  112. * \param mod modifier key
  113. */
  114. virtual void handleConsoleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  115. virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  116. virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
  117. virtual void initGL();
  118. virtual void initVideo(unsigned int width, unsigned int height, bool fullscreen) = 0;
  119. /*!
  120. * \brief Init the resource vars
  121. * \param filename resource file
  122. * \returns < 0 on error
  123. */
  124. virtual int loadResourceFile(const char *filename);
  125. static void resetTicks();
  126. virtual void resizeGL(unsigned int width, unsigned int height);
  127. virtual void runGame() = 0;
  128. /*!
  129. * \brief Turns console key events on/off
  130. * Mostly for allowing text entry vs key impulse commands
  131. * \param on new state
  132. */
  133. void setConsoleMode(bool on);
  134. void setDriverGL(const char *driver);
  135. virtual void shutdown(int code) = 0;
  136. virtual void swapBuffersGL() = 0;
  137. virtual void toggleFullscreen() = 0;
  138. protected:
  139. unsigned int m_width; //!< Width of the viewport
  140. unsigned int m_height; //!< Height of the viewport
  141. char *m_driver; //!< String for dynamic use of GL library
  142. float m_clipNear; //!< Clip near distance
  143. float m_clipFar; //!< Clip far distance
  144. float m_fovY; //!< Field of vision
  145. std::map<unsigned int, int> mKeyEvents; //!< Single key press event mappings
  146. bool mConsoleMode; //!< Using text (console) event handler?
  147. Vector<const char *> mCmdModes; //!< Dynamic resource command collection
  148. unsigned int mCommandMode; //!< Current resource command mode
  149. unsigned int mConsoleKey; //!< Console toggle event now handled lower
  150. };
  151. //! \todo Could make these static methods later, depends on API evolution
  152. /*!
  153. * \brief Sets timer state and returns number of ticks
  154. * \param state 0 - reset, 1 - get number of ticks
  155. * \returns number of ticks
  156. */
  157. unsigned int system_timer(int state);
  158. #endif