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.

World.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : OpenRaider
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : World
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments: The game world ( model )
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History ------------------------------------------------
  17. *
  18. * 2002.12.16:
  19. * Mongoose - Created
  20. ================================================================*/
  21. #ifndef _WORLD_H_
  22. #define _WORLD_H_
  23. #define BAD_BLOOD // For temp rendering use
  24. #ifdef BAD_BLOOD
  25. #include <SkeletalModel.h>
  26. #endif
  27. #include <List.h>
  28. #include <Vector.h>
  29. #include <MatMath.h>
  30. // Mirrors TombRaider class' room flags really
  31. typedef enum
  32. {
  33. roomFlag_underWater = 0x0001
  34. } room_flags_t;
  35. typedef enum
  36. {
  37. worldMoveType_walkNoSwim = -1,
  38. worldMoveType_walk = 0,
  39. worldMoveType_noClipping = 1,
  40. worldMoveType_fly = 2,
  41. worldMoveType_swim = 3
  42. } worldMoveType;
  43. typedef struct vertex_s
  44. {
  45. vec3_t pos;
  46. } vertex_t;
  47. typedef struct uv_s
  48. {
  49. vec2_t uv;
  50. } uv_t;
  51. typedef struct texel_s
  52. {
  53. vec2_t st;
  54. } texel_t;
  55. typedef struct color_s
  56. {
  57. vec4_t rgba;
  58. } color_t;
  59. typedef struct sprite_s
  60. {
  61. int num_verts; // 4 == Quad, 3 == Triangle, renderered as triangles
  62. vertex_t vertex[4];
  63. texel_t texel[4];
  64. float pos[3];
  65. float radius; // yeah, I know
  66. int texture;
  67. } sprite_t;
  68. typedef struct sprite_seq_s
  69. {
  70. int num_sprites;
  71. sprite_t *sprite;
  72. } sprite_seq_t;
  73. /*! \fixme For now shaders are textures on tex objects
  74. * and materials on color objects. If -1
  75. * then it doesn't have that information yet.
  76. */
  77. typedef struct texture_tri_s
  78. {
  79. int index[3];
  80. vec_t st[6];
  81. int texture;
  82. unsigned short transparency;
  83. } texture_tri_t;
  84. typedef struct model_mesh_s
  85. {
  86. Vector<texture_tri_t *> texturedTriangles;
  87. Vector<texture_tri_t *> coloredTriangles;
  88. Vector<texture_tri_t *> texturedRectangles;
  89. Vector<texture_tri_t *> coloredRectangles;
  90. vec3_t center;
  91. float radius;
  92. unsigned int vertexCount;
  93. vec_t *vertices;
  94. unsigned int colorCount;
  95. vec_t *colors;
  96. unsigned int normalCount;
  97. vec_t *normals;
  98. } model_mesh_t;
  99. ////////////////////////////////////////////////////////////////
  100. typedef struct entity_s
  101. {
  102. int id; // Unique identifier
  103. float pos[3]; // World position
  104. float angles[3]; // Eular angles (pitch, yaw, roll)
  105. int type; // {(0x00, item), (0x01, ai), (0x02, player)}
  106. int room; // Current room entity is in
  107. worldMoveType moveType; // Type of motion/clipping
  108. bool moving; // In motion?
  109. struct entity_s *master; // Part of entity chain?
  110. int state; // State of the Player, AI, or object
  111. int objectId; // What kind of entity?
  112. int modelId; // Animation model
  113. void *tmpHook;
  114. bool animate;
  115. /*
  116. float time, lastTime;
  117. int state, lastState;
  118. int event, lastEvent;
  119. int goal;
  120. */
  121. } entity_t;
  122. typedef struct static_model_s
  123. {
  124. int index; // model_mesh index
  125. float yaw; // angle of rotation on Y
  126. float pos[3]; // position
  127. //vec3_t bboxMax;
  128. //vec3_t bboxMin;
  129. } static_model_t;
  130. typedef struct portal_s
  131. {
  132. float vertices[4][3];
  133. float normal[3];
  134. int adjoining_room;
  135. } portal_t;
  136. typedef struct box_s
  137. {
  138. vertex_t a;
  139. vertex_t b;
  140. vertex_t c;
  141. vertex_t d;
  142. } box_t;
  143. typedef struct sector_s
  144. {
  145. vec_t floor;
  146. vec_t ceiling;
  147. bool wall;
  148. } sector_t;
  149. //! \fixme No room mesh list or sprites and etc
  150. typedef struct room_mesh_s
  151. {
  152. Vector<int> adjacentRooms;
  153. Vector<portal_t *> portals;
  154. Vector<static_model_t *> models;
  155. Vector<sprite_t *> sprites;
  156. Vector<box_t *> boxes;
  157. Vector<sector_t *> sectors;
  158. int id;
  159. unsigned int flags;
  160. unsigned int numXSectors;
  161. unsigned int numZSectors;
  162. float pos[3];
  163. vec3_t bbox_min;
  164. vec3_t bbox_max;
  165. } room_mesh_t;
  166. // Workout generic entity and a client class from these entities
  167. typedef struct world_entity_s
  168. {
  169. vec3_t pos;
  170. vec3_t lastPos;
  171. vec3_t angle;
  172. vec_t ttl;
  173. int type;
  174. int state;
  175. //struct world_entity_s *master;
  176. } world_entity_t;
  177. typedef struct actor_entity_s
  178. {
  179. vec3_t pos;
  180. vec3_t lastPos;
  181. vec3_t angle;
  182. char clipping;
  183. float time, eventTime, eventTimer;
  184. int state, nextState;
  185. float health;
  186. // Client
  187. unsigned int uid;
  188. char name[32];
  189. int actor, enemy;
  190. // Render
  191. unsigned int model;
  192. unsigned int skin;
  193. unsigned int animFrame;
  194. } actor_entity_t;
  195. enum OpenRaiderEvent
  196. {
  197. eNone = 0,
  198. eWeaponDischarge,
  199. eDying,
  200. eDead,
  201. eWounded,
  202. eRunForward,
  203. eRunBackward,
  204. eJump,
  205. eCrouchWalk,
  206. eIdle,
  207. eTaunt,
  208. eTurn,
  209. eRespawn,
  210. eLand
  211. };
  212. class World
  213. {
  214. public:
  215. enum WorldFlag
  216. {
  217. fEnableHopping = 1
  218. };
  219. ////////////////////////////////////////////////////////////
  220. // Constructors
  221. ////////////////////////////////////////////////////////////
  222. World();
  223. /*------------------------------------------------------
  224. * Pre :
  225. * Post : Constructs an object of World
  226. *
  227. *-- History ------------------------------------------
  228. *
  229. * 2002.12.16:
  230. * Mongoose - Created
  231. ------------------------------------------------------*/
  232. ~World();
  233. /*------------------------------------------------------
  234. * Pre : World object is allocated
  235. * Post : Deconstructs an object of World
  236. *
  237. *-- History ------------------------------------------
  238. *
  239. * 2002.12.16:
  240. * Mongoose - Created
  241. ------------------------------------------------------*/
  242. ////////////////////////////////////////////////////////////
  243. // Public Accessors
  244. ////////////////////////////////////////////////////////////
  245. int getRoomByLocation(int index, float x, float y, float z);
  246. /*------------------------------------------------------
  247. * Pre : index - Guessed room index
  248. * Post : Returns correct room index or -1 for unknown
  249. *
  250. * NOTE: If it fails to be in a room it gives
  251. * closest overlapping room
  252. *
  253. *-- History ------------------------------------------
  254. *
  255. * 2002.12.20:
  256. * Mongoose - Created, factored out of Render class
  257. ------------------------------------------------------*/
  258. int getRoomByLocation(float x, float y, float z);
  259. /*------------------------------------------------------
  260. * Pre :
  261. * Post : Returns correct room index or -1 for unknown
  262. *
  263. * NOTE: If it fails to be in a room it gives
  264. * closest overlapping room
  265. *
  266. *-- History ------------------------------------------
  267. *
  268. * 2002.12.20:
  269. * Mongoose - Created, factored out of Render class
  270. ------------------------------------------------------*/
  271. int getAdjoiningRoom(int index,
  272. float x, float y, float z,
  273. float x2, float y2, float z2);
  274. /*------------------------------------------------------
  275. * Pre :
  276. * Post : Looks for portal crossings from xyz to xyz2 segment
  277. * from room[index] returns index of adjoined room or -1
  278. *
  279. *-- History ------------------------------------------
  280. *
  281. * 2003.05.29:
  282. * Mongoose - Created
  283. ------------------------------------------------------*/
  284. int getSector(int room, float x, float z);
  285. int getSector(int room, float x, float z, float *floor, float *ceiling);
  286. /*------------------------------------------------------
  287. * Pre : room - valid room index
  288. * Post : Gets the sector index of the position in room
  289. *
  290. *-- History ------------------------------------------
  291. *
  292. * 2002.12.20:
  293. * Mongoose - Created, factored out of Render class
  294. ------------------------------------------------------*/
  295. unsigned int getRoomInfo(int room);
  296. /*------------------------------------------------------
  297. * Pre :
  298. * Post :
  299. *
  300. *-- History ------------------------------------------
  301. *
  302. * 2003.05.28:
  303. * Mongoose - Created
  304. ------------------------------------------------------*/
  305. bool isWall(int room, int sector);
  306. /*------------------------------------------------------
  307. * Pre : room - valid room index
  308. * sector - valid sector index
  309. * Post : Returns true if this sector is a wall
  310. *
  311. *-- History ------------------------------------------
  312. *
  313. * 2002.12.20:
  314. * Mongoose - Created, factored out of Render class
  315. ------------------------------------------------------*/
  316. bool getHeightAtPosition(int index, float x, float *y, float z);
  317. /*------------------------------------------------------
  318. * Pre : index - valid room index
  319. * Post : Returns true if position is in a room
  320. * and sets y to the world height in that room
  321. *
  322. *-- History ------------------------------------------
  323. *
  324. * 2002.12.20:
  325. * Mongoose - Created, factored out of Render class
  326. ------------------------------------------------------*/
  327. // Temp methods for rendering use until more refactoring is done
  328. #ifdef BAD_BLOOD
  329. model_mesh_t *getMesh(int index);
  330. skeletal_model_t *getModel(int index);
  331. room_mesh_t *getRoom(int index);
  332. Vector<entity_t *> *getEntities();
  333. Vector<sprite_seq_t *> *getSprites();
  334. Vector<room_mesh_t *> *getRooms();
  335. #endif
  336. ////////////////////////////////////////////////////////////
  337. // Public Mutators
  338. ////////////////////////////////////////////////////////////
  339. void setFlag(WorldFlag flag);
  340. /*------------------------------------------------------
  341. * Pre :
  342. * Post : Sets option flag
  343. *
  344. *-- History ------------------------------------------
  345. *
  346. * 2002.12.20:
  347. * Mongoose - Created, factored out of Render class
  348. ------------------------------------------------------*/
  349. void clearFlag(WorldFlag flag);
  350. /*------------------------------------------------------
  351. * Pre :
  352. * Post : Clears option flag
  353. *
  354. *-- History ------------------------------------------
  355. *
  356. * 2002.12.20:
  357. * Mongoose - Created, factored out of Render class
  358. ------------------------------------------------------*/
  359. void destroy();
  360. /*------------------------------------------------------
  361. * Pre :
  362. * Post : Clears all data in world, in future will check
  363. * if data is in use before clearing
  364. *
  365. *-- History ------------------------------------------
  366. *
  367. * 2002.12.20:
  368. * Mongoose - Created
  369. ------------------------------------------------------*/
  370. void addRoom(room_mesh_t *room);
  371. /*------------------------------------------------------
  372. * Pre :
  373. * Post : Adds object to world
  374. *
  375. *-- History ------------------------------------------
  376. *
  377. * 2002.12.20:
  378. * Mongoose - Created, factored out of Render class
  379. ------------------------------------------------------*/
  380. void addMesh(model_mesh_t *model);
  381. /*------------------------------------------------------
  382. * Pre :
  383. * Post : Adds object to world
  384. *
  385. *-- History ------------------------------------------
  386. *
  387. * 2002.12.20:
  388. * Mongoose - Created, factored out of Render class
  389. ------------------------------------------------------*/
  390. void addEntity(entity_t *e);
  391. /*------------------------------------------------------
  392. * Pre :
  393. * Post : Adds object to world
  394. *
  395. *-- History ------------------------------------------
  396. *
  397. * 2002.12.20:
  398. * Mongoose - Created, factored out of Render class
  399. ------------------------------------------------------*/
  400. int addModel(skeletal_model_t *model);
  401. /*------------------------------------------------------
  402. * Pre :
  403. * Post : Adds object to world, returns next model Id
  404. * or -1 if failed to add model to world
  405. *
  406. *-- History ------------------------------------------
  407. *
  408. * 2002.12.20:
  409. * Mongoose - Created, factored out of Render class
  410. ------------------------------------------------------*/
  411. void addSprite(sprite_seq_t *sprite);
  412. /*------------------------------------------------------
  413. * Pre :
  414. * Post : Adds object to world
  415. *
  416. *-- History ------------------------------------------
  417. *
  418. * 2002.12.20:
  419. * Mongoose - Created, factored out of Render class
  420. ------------------------------------------------------*/
  421. void moveEntity(entity_t *e, char movement);
  422. /*------------------------------------------------------
  423. * Pre : movement - 'f' orward
  424. * 'b' ackward
  425. * 'l' eft
  426. * 'r' ight
  427. *
  428. * Post : Move entity e in a given direction, unless
  429. * a collision ocurrs
  430. *
  431. *-- History ------------------------------------------
  432. *
  433. * 2002.12.20:
  434. * Mongoose - Moved to WOrld class
  435. *
  436. * 2002.09.02:
  437. * Mongoose - Created
  438. ------------------------------------------------------*/
  439. private:
  440. ////////////////////////////////////////////////////////////
  441. // Private Accessors
  442. ////////////////////////////////////////////////////////////
  443. ////////////////////////////////////////////////////////////
  444. // Private Mutators
  445. ////////////////////////////////////////////////////////////
  446. void clear();
  447. /*------------------------------------------------------
  448. * Pre :
  449. * Post : Clears all data in world
  450. *
  451. *-- History ------------------------------------------
  452. *
  453. * 2002.12.20:
  454. * Mongoose - Created
  455. ------------------------------------------------------*/
  456. bool mClearLock;
  457. unsigned int mFlags; /* World flags */
  458. Vector<entity_t *> mEntities; /* World entities */
  459. Vector<room_mesh_t *> mRooms; /* Map data and meshes */
  460. Vector<model_mesh_t *> mMeshes; /* Unanimated meshes */
  461. Vector<sprite_seq_t *> mSprites; /* Sprites */
  462. Vector<skeletal_model_t *> mModels; /* Skeletal animation models */
  463. };
  464. #endif