Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

System.h 4.9KB

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