Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

World.h 13KB

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