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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : UnRaider, OpenRaider, RaiderUnification 2003
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : System
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments:
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- Test Defines -----------------------------------------------
  17. *
  18. * UNIT_TEST_SYSTEM - Builds System class as a console unit test
  19. *
  20. *-- History ------------------------------------------------
  21. *
  22. * 2002.08.09:
  23. * Mongoose - Created
  24. ================================================================*/
  25. #ifndef GUARD__UNRAIDER_MONGOOSE_SYSTEM_H_
  26. #define GUARD__UNRAIDER_MONGOOSE_SYSTEM_H_
  27. #include "mstl/Map.h"
  28. #include "mstl/Vector.h"
  29. // TODO: Replace with unicode compatible key codes
  30. #define SYS_MOUSE_LEFT 6000
  31. #define SYS_MOUSE_RIGHT 6001
  32. #define SYS_MOUSE_MIDDLE 6002
  33. #define SYS_KEY_ESC 27
  34. #define SYS_KEY_ENTER 13
  35. #define SYS_KEY_UP 5000
  36. #define SYS_KEY_DOWN 5001
  37. #define SYS_KEY_RIGHT 5002
  38. #define SYS_KEY_LEFT 5003
  39. #define SYS_KEY_PAGEDOWN 5004
  40. #define SYS_KEY_PAGEUP 5005
  41. #define SYS_KEY_F1 1000
  42. #define SYS_KEY_F2 1001
  43. #define SYS_KEY_F3 1002
  44. #define SYS_KEY_F4 1003
  45. #define SYS_KEY_F5 1004
  46. #define SYS_KEY_F6 1005
  47. #define SYS_KEY_F7 1006
  48. #define SYS_KEY_F8 1007
  49. #define SYS_KEY_F9 1008
  50. #define SYS_KEY_F10 1009
  51. #define SYS_KEY_F11 1010
  52. #define SYS_KEY_F12 1011
  53. typedef enum
  54. {
  55. SYS_MOD_KEY_LSHIFT = 1,
  56. SYS_MOD_KEY_RSHIFT = 2,
  57. SYS_MOD_KEY_LCTRL = 4,
  58. SYS_MOD_KEY_RCTRL = 8,
  59. SYS_MOD_KEY_LALT = 16,
  60. SYS_MOD_KEY_RALT = 32
  61. } sdl_sys_mod_key_t;
  62. class System
  63. {
  64. public:
  65. ////////////////////////////////////////////////////////////
  66. // Constructors
  67. ////////////////////////////////////////////////////////////
  68. System();
  69. /*------------------------------------------------------
  70. * Pre :
  71. * Post : Constructs an object of System
  72. *
  73. *-- History ------------------------------------------
  74. *
  75. * 2002.08.09:
  76. * Mongoose - Created
  77. ------------------------------------------------------*/
  78. virtual ~System();
  79. /*------------------------------------------------------
  80. * Pre : System object is allocated
  81. * Post : Deconstructs an object of System
  82. *
  83. *-- History ------------------------------------------
  84. *
  85. * 2002.08.09:
  86. * Mongoose - Created
  87. ------------------------------------------------------*/
  88. ////////////////////////////////////////////////////////////
  89. // Public Accessors
  90. ////////////////////////////////////////////////////////////
  91. static char *bufferString(char *string, ...);
  92. /*------------------------------------------------------
  93. * Pre : <String> is a valid string with valid args
  94. *
  95. * Post : Generates a buufered string for the printf
  96. * call
  97. *
  98. *-- History ------------------------------------------
  99. *
  100. * 2003.06.03:
  101. * Mongoose - Made into a printf string caching system
  102. *
  103. * 2001.12.31:
  104. * Mongoose - Created, was GLString::glPrintf
  105. ------------------------------------------------------*/
  106. static char *fullPath(char *path, char end);
  107. /*------------------------------------------------------
  108. * Pre :
  109. * Post : Returns allocated string of path, with
  110. * expansion of unix home enviroment char and
  111. * makes sure string ends in "end" char
  112. *
  113. * end = 0 appends no addional char
  114. *
  115. *-- History ------------------------------------------
  116. *
  117. * 2002.08.17:
  118. * Mongoose - Created
  119. ------------------------------------------------------*/
  120. static char *getFileFromFullPath(char *filename);
  121. /*------------------------------------------------------
  122. * Pre :
  123. * Post :
  124. *
  125. *-- History ------------------------------------------
  126. *
  127. * 2003.07.05:
  128. * Mongoose - Created
  129. ------------------------------------------------------*/
  130. virtual unsigned int getTicks();
  131. /*------------------------------------------------------
  132. * Pre :
  133. * Post : Returns number of milliseconds since start of
  134. * program
  135. *
  136. *-- History ------------------------------------------
  137. *
  138. * 2002.06.06:
  139. * Mongoose - Created
  140. ------------------------------------------------------*/
  141. static int downloadToBuffer(char *urlString,
  142. unsigned char **buffer, unsigned int *size);
  143. /*------------------------------------------------------
  144. * Pre :
  145. * Post : Downloads something into passed buffer,
  146. * Returns < 0 on error, 0 on sucess
  147. *
  148. *-- History ------------------------------------------
  149. *
  150. * 2003.07.12:
  151. * Mongoose - Created
  152. ------------------------------------------------------*/
  153. static int downloadToFile(char *urlString, char *filename);
  154. /*------------------------------------------------------
  155. * Pre :
  156. * Post : Downloads something into a disk file,
  157. * Returns < 0 on error, 0 on sucess
  158. *
  159. *-- History ------------------------------------------
  160. *
  161. * 2003.07.12:
  162. * Mongoose - Created
  163. ------------------------------------------------------*/
  164. static int createDir(char *path);
  165. /*------------------------------------------------------
  166. * Pre : Creates directory
  167. * Post : Returns -1 on error
  168. *
  169. *-- History ------------------------------------------
  170. *
  171. * 2003.07.12:
  172. * Mongoose - Created
  173. ------------------------------------------------------*/
  174. ////////////////////////////////////////////////////////////
  175. // Public Mutators
  176. ////////////////////////////////////////////////////////////
  177. virtual unsigned int addCommandMode(char *command);
  178. /*------------------------------------------------------
  179. * Pre : <Command> is valid command mode for the
  180. * resource file, eg "[Engine.OpenGL.Driver]"
  181. *
  182. * Post : Returns Id given to mode
  183. *
  184. *-- History ------------------------------------------
  185. *
  186. * 2002.03.23:
  187. * Mongoose - Created
  188. ------------------------------------------------------*/
  189. virtual void bindKeyCommand(char *cmd, unsigned int key, int event);
  190. /*------------------------------------------------------
  191. * Pre : <Cmd> is a valid command string
  192. * <Key> is a valid keyboard code
  193. * <Event> is a valid game event Id
  194. *
  195. * Post : Sets <Event> binding <Cmd> to <Key> press
  196. *
  197. *-- History ------------------------------------------
  198. *
  199. * 2003.06.03:
  200. * Mongoose - Created
  201. ------------------------------------------------------*/
  202. virtual void command(char *cmd);
  203. /*------------------------------------------------------
  204. * Pre : cmd is a valid command string
  205. * Post : cmd sets it's var
  206. *
  207. *-- History ------------------------------------------
  208. *
  209. * 2001.05.27:
  210. * Mongoose - Created
  211. ------------------------------------------------------*/
  212. virtual void gameFrame() = 0;
  213. /*------------------------------------------------------
  214. * Pre :
  215. * Post :
  216. *
  217. *-- History ------------------------------------------
  218. *
  219. * 2002.08.09?:
  220. * Mongoose - Created
  221. ------------------------------------------------------*/
  222. virtual void handleMouseMotionEvent(float x, float y) = 0;
  223. /*------------------------------------------------------
  224. * Pre :
  225. * Post :
  226. *
  227. *-- History ------------------------------------------
  228. *
  229. * 2002.08.09?:
  230. * Mongoose - Created
  231. ------------------------------------------------------*/
  232. virtual void handleBoundKeyPressEvent(unsigned int key) = 0;
  233. /*------------------------------------------------------
  234. * Pre : <Key> is a valid keyboard code
  235. *
  236. * Post : Recieves <Event> bound to <Cmd> from <Key> press
  237. *
  238. *-- History ------------------------------------------
  239. *
  240. * 2003.06.03:
  241. * Mongoose - Created
  242. ------------------------------------------------------*/
  243. virtual void handleBoundKeyReleaseEvent(unsigned int key) = 0;
  244. /*------------------------------------------------------
  245. * Pre : <Key> is a valid keyboard code
  246. *
  247. * Post : Recieves <Event> bound to <Cmd> from <Key> release
  248. *
  249. *-- History ------------------------------------------
  250. *
  251. * 2003.06.03:
  252. * Mongoose - Created
  253. ------------------------------------------------------*/
  254. virtual void handleCommand(char *command, unsigned int mode) = 0;
  255. /*------------------------------------------------------
  256. * Pre : <Command> is valid keyword optionally followed
  257. * by ' ' (space) seperated and argument(s)
  258. *
  259. * <Mode> is the current type or resource mode
  260. *
  261. * Post : Executes valid command based on keyword
  262. *
  263. *-- History ------------------------------------------
  264. *
  265. * 2002.03.23:
  266. * Mongoose - Created
  267. ------------------------------------------------------*/
  268. virtual void handleConsoleKeyPressEvent(unsigned int key,
  269. unsigned int mod) = 0;
  270. /*------------------------------------------------------
  271. * Pre : <Key> is a valid keyboard code
  272. *
  273. * Post : Recieves <Key> code from text input in console mode
  274. *
  275. *-- History ------------------------------------------
  276. *
  277. * 2003.06.03:
  278. * Mongoose - Created
  279. ------------------------------------------------------*/
  280. virtual void handleKeyPressEvent(unsigned int key, unsigned int mod) = 0;
  281. /*------------------------------------------------------
  282. * Pre :
  283. * Post :
  284. *
  285. *-- History ------------------------------------------
  286. *
  287. * 2002.08.09?:
  288. * Mongoose - Created
  289. ------------------------------------------------------*/
  290. virtual void handleKeyReleaseEvent(unsigned int key, unsigned int mod) = 0;
  291. /*------------------------------------------------------
  292. * Pre :
  293. * Post :
  294. *
  295. *-- History ------------------------------------------
  296. *
  297. * 2002.08.09?:
  298. * Mongoose - Created
  299. ------------------------------------------------------*/
  300. virtual void initGL();
  301. /*------------------------------------------------------
  302. * Pre :
  303. * Post :
  304. *
  305. *-- History ------------------------------------------
  306. *
  307. * 2002.08.09?:
  308. * Mongoose - Created
  309. ------------------------------------------------------*/
  310. virtual void initVideo(unsigned int width, unsigned int height,
  311. bool fullscreen) = 0;
  312. /*------------------------------------------------------
  313. * Pre :
  314. * Post :
  315. *
  316. *-- History ------------------------------------------
  317. *
  318. * 2002.08.09?:
  319. * Mongoose - Created
  320. ------------------------------------------------------*/
  321. virtual int loadResourceFile(char *filename);
  322. /*------------------------------------------------------
  323. * Pre :
  324. * Post : Init the resource vars
  325. *
  326. * Returns less than zero value on error
  327. *
  328. *-- History ------------------------------------------
  329. *
  330. * 2001.05.27:
  331. * Mongoose - Created
  332. ------------------------------------------------------*/
  333. static void resetTicks();
  334. /*------------------------------------------------------
  335. * Pre :
  336. * Post :
  337. *
  338. *-- History ------------------------------------------
  339. *
  340. * 2002.08.09?:
  341. * Mongoose - Created
  342. ------------------------------------------------------*/
  343. virtual void resizeGL(unsigned int width, unsigned int height);
  344. /*------------------------------------------------------
  345. * Pre :
  346. * Post :
  347. *
  348. *-- History ------------------------------------------
  349. *
  350. * 2002.08.09?:
  351. * Mongoose - Created
  352. ------------------------------------------------------*/
  353. virtual void runGame() = 0;
  354. /*------------------------------------------------------
  355. * Pre :
  356. * Post :
  357. *
  358. *-- History ------------------------------------------
  359. *
  360. * 2002.08.09?:
  361. * Mongoose - Created
  362. ------------------------------------------------------*/
  363. void setConsoleMode(bool on);
  364. /*------------------------------------------------------
  365. * Pre :
  366. * Post : Turns console key events on/off,
  367. * mostly for allowing text entry vs key
  368. * impluse commands
  369. *
  370. *-- History ------------------------------------------
  371. *
  372. * 2003.06.03:
  373. * Mongoose - Created
  374. ------------------------------------------------------*/
  375. void setDriverGL(const char *driver);
  376. /*------------------------------------------------------
  377. * Pre :
  378. * Post :
  379. *
  380. *-- History ------------------------------------------
  381. *
  382. * 2002.08.09?:
  383. * Mongoose - Created
  384. ------------------------------------------------------*/
  385. void setFastCardPerformance(bool isFast);
  386. /*------------------------------------------------------
  387. * Pre :
  388. * Post :
  389. *
  390. *-- History ------------------------------------------
  391. *
  392. * 2002.08.09?:
  393. * Mongoose - Created
  394. ------------------------------------------------------*/
  395. virtual void shutdown(int code) = 0;
  396. /*------------------------------------------------------
  397. * Pre :
  398. * Post :
  399. *
  400. *-- History ------------------------------------------
  401. *
  402. * 2002.08.09?:
  403. * Mongoose - Created
  404. ------------------------------------------------------*/
  405. virtual void swapBuffersGL() = 0;
  406. /*------------------------------------------------------
  407. * Pre :
  408. * Post :
  409. *
  410. *-- History ------------------------------------------
  411. *
  412. * 2002.08.09?:
  413. * Mongoose - Created
  414. ------------------------------------------------------*/
  415. virtual void toggleFullscreen() = 0;
  416. /*------------------------------------------------------
  417. * Pre :
  418. * Post :
  419. *
  420. *-- History ------------------------------------------
  421. *
  422. * 2002.08.09?:
  423. * Mongoose - Created
  424. ------------------------------------------------------*/
  425. protected:
  426. unsigned int m_width; /* Width of the viewport */
  427. unsigned int m_height; /* Height of the viewport */
  428. bool m_fastCard; /* Assume expensive calls are fine if true */
  429. char *m_driver; /* String for dynamic use of GL library */
  430. float m_clipNear; /* Clip near distance */
  431. float m_clipFar; /* Clip far distance */
  432. float m_fovY; /* Field of vision */
  433. Map<unsigned int, int> mKeyEvents; /* Single key press event mappings */
  434. bool mConsoleMode; /* Using text (console) event handler? */
  435. Vector<char *> mCmdModes; /* Dynamic resource command collection */
  436. unsigned int mCommandMode; /* Current resource command mode */
  437. unsigned int mConsoleKey; /* Console toggle event now handled lower */
  438. private:
  439. ////////////////////////////////////////////////////////////
  440. // Private Accessors
  441. ////////////////////////////////////////////////////////////
  442. ////////////////////////////////////////////////////////////
  443. // Private Mutators
  444. ////////////////////////////////////////////////////////////
  445. };
  446. // Could make these static methods later, depends on API evolution
  447. bool rc_command(char *symbol, char *command);
  448. /*------------------------------------------------------
  449. * Pre :
  450. * Post : Returns true if <Command> matches <Symbol>
  451. * command string
  452. *
  453. * Returns the rest of the argument list back in
  454. * <Command> buffer, if any
  455. *
  456. *-- History ------------------------------------------
  457. *
  458. * 2002.03.23:
  459. * Mongoose - Created
  460. ------------------------------------------------------*/
  461. int rc_get_bool(char *buffer, bool *val);
  462. /*------------------------------------------------------
  463. * Pre : Buffer is "true" or "false"
  464. *
  465. * Post : Returns 0 if <Buffer> is "true" or "false"
  466. * and sets <Val> accordingly
  467. *
  468. * Returns -1 for null string
  469. * Returns -2 if string isn't "true" or "false"
  470. *
  471. *-- History ------------------------------------------
  472. *
  473. * 2002.03.23:
  474. * Mongoose - Created
  475. ------------------------------------------------------*/
  476. unsigned int system_timer(int state);
  477. /*------------------------------------------------------
  478. * Pre : 0 - reset, 1 - get number of ticks
  479. * Post : Sets timer state and returns number of ticks
  480. *
  481. *-- History ------------------------------------------
  482. *
  483. * 2002.06.06:
  484. * Mongoose - Created
  485. ------------------------------------------------------*/
  486. #endif