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 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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.h>
  13. #include <Vector.h>
  14. //! \todo Replace with unicode compatible key codes
  15. #define SYS_MOUSE_LEFT 6000
  16. #define SYS_MOUSE_RIGHT 6001
  17. #define SYS_MOUSE_MIDDLE 6002
  18. #define SYS_KEY_ESC 27
  19. #define SYS_KEY_ENTER 13
  20. #define SYS_KEY_UP 5000
  21. #define SYS_KEY_DOWN 5001
  22. #define SYS_KEY_RIGHT 5002
  23. #define SYS_KEY_LEFT 5003
  24. #define SYS_KEY_PAGEDOWN 5004
  25. #define SYS_KEY_PAGEUP 5005
  26. #define SYS_KEY_F1 1000
  27. #define SYS_KEY_F2 1001
  28. #define SYS_KEY_F3 1002
  29. #define SYS_KEY_F4 1003
  30. #define SYS_KEY_F5 1004
  31. #define SYS_KEY_F6 1005
  32. #define SYS_KEY_F7 1006
  33. #define SYS_KEY_F8 1007
  34. #define SYS_KEY_F9 1008
  35. #define SYS_KEY_F10 1009
  36. #define SYS_KEY_F11 1010
  37. #define SYS_KEY_F12 1011
  38. typedef enum {
  39. SYS_MOD_KEY_LSHIFT = 1,
  40. SYS_MOD_KEY_RSHIFT = 2,
  41. SYS_MOD_KEY_LCTRL = 4,
  42. SYS_MOD_KEY_RCTRL = 8,
  43. SYS_MOD_KEY_LALT = 16,
  44. SYS_MOD_KEY_RALT = 32,
  45. SYS_MOD_KEY_LMETA = 64,
  46. SYS_MOD_KEY_RMETA = 128
  47. } sdl_sys_mod_key_t;
  48. /*!
  49. * \brief Basic Interface for System implementations (SDLSystem)
  50. */
  51. class System {
  52. public:
  53. /*!
  54. * \brief Constructs an object of System
  55. */
  56. System();
  57. /*!
  58. * \brief Deconstructs an object of System
  59. */
  60. virtual ~System();
  61. /*!
  62. * \brief Generates a buufered string for the printf call
  63. * \param string Format string like for printf
  64. * \returns string in a buffer
  65. */
  66. static char *bufferString(const char *string, ...);
  67. /*!
  68. * \brief Expansion of unix home enviroment char.
  69. * Also makes sure string ends in "end" char.
  70. * \param path path string
  71. * \param end end character. 0 appends no additional char
  72. * \returns allocated string of path with expansions
  73. */
  74. static char *fullPath(const char *path, char end);
  75. /*!
  76. * \brief Only returns last part of a path string.
  77. * \param filename Path to a file
  78. * \returns Name of the file in filename, without path in front
  79. */
  80. static char *getFileFromFullPath(char *filename);
  81. /*!
  82. * \brief Gets the game tick
  83. * \returns number of milliseconds since start of program
  84. */
  85. virtual unsigned int getTicks();
  86. /*!
  87. * \brief Downloads something into passed buffer
  88. * \todo Not yet implemented!
  89. * \param urlString URL of thing to download
  90. * \param buffer array of strings as target
  91. * \param size size of buffer
  92. * \returns < 0 on error, 0 on success
  93. */
  94. static int downloadToBuffer(char *urlString, unsigned char **buffer, unsigned int *size);
  95. /*!
  96. * \brief Downloads something into a disk file.
  97. * Supports HTTP and FTP.
  98. * \param urlString URL of thing to download
  99. * \param filename file that should be created/filled
  100. * \returns < 0 on error, 0 on success. -1000 if libferit not linked
  101. */
  102. static int downloadToFile(char *urlString, char *filename);
  103. /*!
  104. * \brief Created a directory
  105. * \param path Directory to create
  106. * \returns -1 on error
  107. */
  108. static int createDir(char *path);
  109. /*!
  110. * \brief Created a new Command Mode.
  111. * \param command valid command mode for the resource file, eg "[Engine.OpenGL.Driver]"
  112. * \returns id given to mode
  113. */
  114. virtual unsigned int addCommandMode(const char *command);
  115. /*!
  116. * \brief Binds a key to a command
  117. * \param cmd valid command string for event
  118. * \param key valid keyboard code
  119. * \param event valid game event id
  120. */
  121. virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
  122. /*!
  123. * \brief Executes a command string
  124. * \param cmd valid command string, cmd sets its var
  125. */
  126. virtual void command(const char *cmd);
  127. virtual void gameFrame() = 0;
  128. virtual void handleMouseMotionEvent(float x, float y) = 0;
  129. /*!
  130. * \brief Receives the event bound to the command from the key press
  131. * \param key key pressed
  132. */
  133. virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
  134. /*!
  135. * \brief Receives the event bound to the command from the key release
  136. * \param key key released
  137. */
  138. virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
  139. /*!
  140. * \brief Executes valid command based on keyword
  141. * \param command valid keyword, optionally followed by space separated arguments
  142. * \param mode current type or resource mode
  143. */
  144. virtual void handleCommand(char *command, unsigned int mode) = 0;
  145. /*!
  146. * \brief Receives key code from text input in console mode
  147. * \param key is a valid keyboard code
  148. * \param mod modifier key
  149. */
  150. virtual void handleConsoleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  151. virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  152. virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
  153. virtual void initGL();
  154. virtual void initVideo(unsigned int width, unsigned int height, bool fullscreen) = 0;
  155. /*!
  156. * \brief Init the resource vars
  157. * \param filename resource file
  158. * \returns < 0 on error
  159. */
  160. virtual int loadResourceFile(const char *filename);
  161. static void resetTicks();
  162. virtual void resizeGL(unsigned int width, unsigned int height);
  163. virtual void runGame() = 0;
  164. /*!
  165. * \brief Turns console key events on/off
  166. * Mostly for allowing text entry vs key impulse commands
  167. * \param on new state
  168. */
  169. void setConsoleMode(bool on);
  170. void setDriverGL(const char *driver);
  171. void setFastCardPerformance(bool isFast);
  172. virtual void shutdown(int code) = 0;
  173. virtual void swapBuffersGL() = 0;
  174. virtual void toggleFullscreen() = 0;
  175. protected:
  176. unsigned int m_width; //!< Width of the viewport
  177. unsigned int m_height; //!< Height of the viewport
  178. bool m_fastCard; //!< Assume expensive calls are fine if true
  179. char *m_driver; //!< String for dynamic use of GL library
  180. float m_clipNear; //!< Clip near distance
  181. float m_clipFar; //!< Clip far distance
  182. float m_fovY; //!< Field of vision
  183. Map<unsigned int, int> mKeyEvents; //!< Single key press event mappings
  184. bool mConsoleMode; //!< Using text (console) event handler?
  185. Vector<const char *> mCmdModes; //!< Dynamic resource command collection
  186. unsigned int mCommandMode; //!< Current resource command mode
  187. unsigned int mConsoleKey; //!< Console toggle event now handled lower
  188. };
  189. //! \todo Could make these static methods later, depends on API evolution
  190. /*!
  191. * \brief Checks if Command matches Symbol.
  192. * Returns the rest of the argument list back in command buffer, if any
  193. * \param symbol command string
  194. * \param command with arguments
  195. * \returns true if command matches symbol
  196. */
  197. bool rc_command(const char *symbol, char *command);
  198. /*!
  199. * \brief Interpret a string as a bool
  200. * \param buffer "true" or "false"
  201. * \param val is set to boolean interpretation of buffer
  202. * \returns -1 for null string, -2 if string is not "true" or "false"
  203. */
  204. int rc_get_bool(char *buffer, bool *val);
  205. /*!
  206. * \brief Sets timer state and returns number of ticks
  207. * \param state 0 - reset, 1 - get number of ticks
  208. * \returns number of ticks
  209. */
  210. unsigned int system_timer(int state);
  211. #endif