Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

World.h 13KB

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