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

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