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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. {
  53. public:
  54. ////////////////////////////////////////////////////////////
  55. // Constructors
  56. ////////////////////////////////////////////////////////////
  57. /*!
  58. * \brief Constructs an object of System
  59. */
  60. System();
  61. /*!
  62. * \brief Deconstructs an object of System
  63. */
  64. virtual ~System();
  65. ////////////////////////////////////////////////////////////
  66. // Public Accessors
  67. ////////////////////////////////////////////////////////////
  68. /*!
  69. * \brief Generates a buufered string for the printf call
  70. * \param string Format string like for printf
  71. * \returns string in a buffer
  72. */
  73. static char *bufferString(const char *string, ...);
  74. /*!
  75. * \brief Expansion of unix home enviroment char.
  76. * Also makes sure string ends in "end" char.
  77. * \param path path string
  78. * \param end end character. 0 appends no additional char
  79. * \returns allocated string of path with expansions
  80. */
  81. static char *fullPath(const char *path, char end);
  82. /*!
  83. * \brief Only returns last part of a path string.
  84. * \param filename Path to a file
  85. * \returns Name of the file in filename, without path in front
  86. */
  87. static char *getFileFromFullPath(char *filename);
  88. /*!
  89. * \brief Gets the game tick
  90. * \returns number of milliseconds since start of program
  91. */
  92. virtual unsigned int getTicks();
  93. /*!
  94. * \brief Downloads something into passed buffer
  95. * \todo Not yet implemented!
  96. * \param urlString URL of thing to download
  97. * \param buffer array of strings as target
  98. * \param size size of buffer
  99. * \returns < 0 on error, 0 on success
  100. */
  101. static int downloadToBuffer(char *urlString,
  102. unsigned char **buffer, unsigned int *size);
  103. /*!
  104. * \brief Downloads something into a disk file.
  105. * Supports HTTP and FTP.
  106. * \param urlString URL of thing to download
  107. * \param filename file that should be created/filled
  108. * \returns < 0 on error, 0 on success. -1000 if libferit not linked
  109. */
  110. static int downloadToFile(char *urlString, char *filename);
  111. /*!
  112. * \brief Created a directory
  113. * \param path Directory to create
  114. * \returns -1 on error
  115. */
  116. static int createDir(char *path);
  117. ////////////////////////////////////////////////////////////
  118. // Public Mutators
  119. ////////////////////////////////////////////////////////////
  120. /*!
  121. * \brief Created a new Command Mode.
  122. * \param command valid command mode for the resource file, eg "[Engine.OpenGL.Driver]"
  123. * \returns id given to mode
  124. */
  125. virtual unsigned int addCommandMode(const char *command);
  126. /*!
  127. * \brief Binds a key to a command
  128. * \param cmd valid command string for event
  129. * \param key valid keyboard code
  130. * \param event valid game event id
  131. */
  132. virtual void bindKeyCommand(const char *cmd, unsigned int key, int event);
  133. /*!
  134. * \brief Executes a command string
  135. * \param cmd valid command string, cmd sets its var
  136. */
  137. virtual void command(const char *cmd);
  138. virtual void gameFrame() = 0;
  139. virtual void handleMouseMotionEvent(float x, float y) = 0;
  140. /*!
  141. * \brief Receives the event bound to the command from the key press
  142. * \param key key pressed
  143. */
  144. virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
  145. /*!
  146. * \brief Receives the event bound to the command from the key release
  147. * \param key key released
  148. */
  149. virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
  150. /*!
  151. * \brief Executes valid command based on keyword
  152. * \param command valid keyword, optionally followed by space separated arguments
  153. * \param mode current type or resource mode
  154. */
  155. virtual void handleCommand(char *command, unsigned int mode) = 0;
  156. /*!
  157. * \brief Receives key code from text input in console mode
  158. * \param key is a valid keyboard code
  159. * \param mod modifier key
  160. */
  161. virtual void handleConsoleKeyPressEvent(unsigned int key,
  162. unsigned int mod) = 0;
  163. virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  164. virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
  165. virtual void initGL();
  166. virtual void initVideo(unsigned int width, unsigned int height,
  167. bool fullscreen) = 0;
  168. /*!
  169. * \brief Init the resource vars
  170. * \param filename resource file
  171. * \returns < 0 on error
  172. */
  173. virtual int loadResourceFile(const char *filename);
  174. static void resetTicks();
  175. virtual void resizeGL(unsigned int width, unsigned int height);
  176. virtual void runGame() = 0;
  177. /*!
  178. * \brief Turns console key events on/off
  179. * Mostly for allowing text entry vs key impulse commands
  180. * \param on new state
  181. */
  182. void setConsoleMode(bool on);
  183. void setDriverGL(const char *driver);
  184. void setFastCardPerformance(bool isFast);
  185. virtual void shutdown(int code) = 0;
  186. virtual void swapBuffersGL() = 0;
  187. virtual void toggleFullscreen() = 0;
  188. protected:
  189. unsigned int m_width; //!< Width of the viewport
  190. unsigned int m_height; //!< Height of the viewport
  191. bool m_fastCard; //!< Assume expensive calls are fine if true
  192. char *m_driver; //!< String for dynamic use of GL library
  193. float m_clipNear; //!< Clip near distance
  194. float m_clipFar; //!< Clip far distance
  195. float m_fovY; //!< Field of vision
  196. Map<unsigned int, int> mKeyEvents; //!< Single key press event mappings
  197. bool mConsoleMode; //!< Using text (console) event handler?
  198. Vector<const char *> mCmdModes; //!< Dynamic resource command collection
  199. unsigned int mCommandMode; //!< Current resource command mode
  200. unsigned int mConsoleKey; //!< Console toggle event now handled lower
  201. private:
  202. ////////////////////////////////////////////////////////////
  203. // Private Accessors
  204. ////////////////////////////////////////////////////////////
  205. ////////////////////////////////////////////////////////////
  206. // Private Mutators
  207. ////////////////////////////////////////////////////////////
  208. };
  209. //! \todo Could make these static methods later, depends on API evolution
  210. /*!
  211. * \brief Checks if Command matches Symbol.
  212. * Returns the rest of the argument list back in command buffer, if any
  213. * \param symbol command string
  214. * \param command with arguments
  215. * \returns true if command matches symbol
  216. */
  217. bool rc_command(const char *symbol, char *command);
  218. /*!
  219. * \brief Interpret a string as a bool
  220. * \param buffer "true" or "false"
  221. * \param val is set to boolean interpretation of buffer
  222. * \returns -1 for null string, -2 if string is not "true" or "false"
  223. */
  224. int rc_get_bool(char *buffer, bool *val);
  225. /*!
  226. * \brief Sets timer state and returns number of ticks
  227. * \param state 0 - reset, 1 - get number of ticks
  228. * \returns number of ticks
  229. */
  230. unsigned int system_timer(int state);
  231. #endif