Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

World.h 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*!
  2. * \file include/World.h
  3. * \brief The game world (model)
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _WORLD_H_
  8. #define _WORLD_H_
  9. #define BAD_BLOOD //!< \todo For temp rendering use
  10. #ifdef BAD_BLOOD
  11. #include "SkeletalModel.h"
  12. #endif
  13. #include "List.h"
  14. #include "Vector.h"
  15. #include "MatMath.h"
  16. // Mirrors TombRaider class' room flags really
  17. typedef enum {
  18. roomFlag_underWater = 0x0001
  19. } room_flags_t;
  20. typedef enum {
  21. worldMoveType_walkNoSwim = -1,
  22. worldMoveType_walk = 0,
  23. worldMoveType_noClipping = 1,
  24. worldMoveType_fly = 2,
  25. worldMoveType_swim = 3
  26. } worldMoveType;
  27. typedef struct {
  28. vec3_t pos;
  29. } vertex_t;
  30. /*
  31. typedef struct {
  32. vec2_t uv;
  33. } uv_t;
  34. typedef struct {
  35. vec4_t rgba;
  36. } color_t;
  37. */
  38. typedef struct {
  39. vec2_t st;
  40. } texel_t;
  41. typedef struct {
  42. int num_verts; //!< 4 == Quad, 3 == Triangle, rendered as triangles
  43. vertex_t vertex[4];
  44. texel_t texel[4];
  45. float pos[3];
  46. float radius; //!< \fixme yeah, I know
  47. int texture;
  48. } sprite_t;
  49. typedef struct {
  50. int num_sprites;
  51. sprite_t *sprite;
  52. } sprite_seq_t;
  53. /*! \fixme For now shaders are textures on tex objects
  54. * and materials on color objects. If -1
  55. * then it doesn't have that information yet.
  56. */
  57. typedef struct {
  58. int index[3];
  59. vec_t st[6];
  60. int texture;
  61. unsigned short transparency;
  62. } texture_tri_t;
  63. typedef struct {
  64. Vector<texture_tri_t *> texturedTriangles;
  65. Vector<texture_tri_t *> coloredTriangles;
  66. Vector<texture_tri_t *> texturedRectangles;
  67. Vector<texture_tri_t *> coloredRectangles;
  68. vec3_t center;
  69. float radius;
  70. unsigned int vertexCount;
  71. vec_t *vertices;
  72. unsigned int colorCount;
  73. vec_t *colors;
  74. unsigned int normalCount;
  75. vec_t *normals;
  76. } model_mesh_t;
  77. typedef struct entity_s {
  78. int id; //!< Unique identifier
  79. float pos[3]; //!< World position
  80. float angles[3]; //!< Euler angles (pitch, yaw, roll)
  81. int type; //!< {(0x00, item), (0x01, ai), (0x02, player)}
  82. int room; //!< Current room entity is in
  83. worldMoveType moveType; //!< Type of motion/clipping
  84. bool moving; //!< In motion?
  85. struct entity_s *master; //!< Part of entity chain?
  86. int state; //!< State of the Player, AI, or object
  87. int objectId; //!< What kind of entity?
  88. int modelId; //!< Animation model
  89. void *tmpHook;
  90. bool animate;
  91. /*
  92. float time, lastTime;
  93. int state, lastState;
  94. int event, lastEvent;
  95. int goal;
  96. */
  97. } entity_t;
  98. typedef struct {
  99. int index; //!< model_mesh index
  100. float yaw; //!< angle of rotation on Y
  101. float pos[3]; //!< position
  102. //vec3_t bboxMax;
  103. //vec3_t bboxMin;
  104. } static_model_t;
  105. typedef struct {
  106. float vertices[4][3];
  107. float normal[3];
  108. int adjoining_room;
  109. } portal_t;
  110. typedef struct {
  111. vertex_t a;
  112. vertex_t b;
  113. vertex_t c;
  114. vertex_t d;
  115. } box_t;
  116. typedef struct {
  117. vec_t floor;
  118. vec_t ceiling;
  119. bool wall;
  120. } sector_t;
  121. //! \fixme No room mesh list or sprites and etc
  122. typedef struct {
  123. Vector<int> adjacentRooms;
  124. Vector<portal_t *> portals;
  125. Vector<static_model_t *> models;
  126. Vector<sprite_t *> sprites;
  127. Vector<box_t *> boxes;
  128. Vector<sector_t *> sectors;
  129. int id;
  130. unsigned int flags;
  131. unsigned int numXSectors;
  132. unsigned int numZSectors;
  133. float pos[3];
  134. vec3_t bbox_min;
  135. vec3_t bbox_max;
  136. } room_mesh_t;
  137. // Workout generic entity and a client class from these entities
  138. typedef struct world_entity_s {
  139. vec3_t pos;
  140. vec3_t lastPos;
  141. vec3_t angle;
  142. vec_t ttl;
  143. int type;
  144. int state;
  145. //struct world_entity_s *master;
  146. } world_entity_t;
  147. typedef struct {
  148. vec3_t pos;
  149. vec3_t lastPos;
  150. vec3_t angle;
  151. char clipping;
  152. float time, eventTime, eventTimer;
  153. int state, nextState;
  154. float health;
  155. // Client
  156. unsigned int uid;
  157. char name[32];
  158. int actor, enemy;
  159. // Render
  160. unsigned int model;
  161. unsigned int skin;
  162. unsigned int animFrame;
  163. } actor_entity_t;
  164. enum OpenRaiderEvent {
  165. eNone = 0,
  166. eWeaponDischarge,
  167. eDying,
  168. eDead,
  169. eWounded,
  170. eRunForward,
  171. eRunBackward,
  172. eJump,
  173. eCrouchWalk,
  174. eIdle,
  175. eTaunt,
  176. eTurn,
  177. eRespawn,
  178. eLand
  179. };
  180. /*!
  181. * \brief The game world (model)
  182. */
  183. class World {
  184. public:
  185. enum WorldFlag {
  186. fEnableHopping = 1
  187. };
  188. /*!
  189. * \brief Constructs an object of World
  190. */
  191. World();
  192. /*!
  193. * \brief Deconstructs an object of World
  194. */
  195. ~World();
  196. /*!
  197. * \brief Find room a location is in.
  198. *
  199. * If it fails to be in a room it gives closest overlapping room.
  200. * \param index Guessed room index
  201. * \param x X coordinate
  202. * \param y Y coordinate
  203. * \param z Z coordinate
  204. * \returns correct room index or -1 for unknown
  205. */
  206. int getRoomByLocation(int index, float x, float y, float z);
  207. /*!
  208. * \brief Find room a location is in.
  209. *
  210. * If it fails to be in a room it gives closest overlapping room.
  211. * \param x X coordinate
  212. * \param y Y coordinate
  213. * \param z Z coordinate
  214. * \returns correct room index or -1 for unknown
  215. */
  216. int getRoomByLocation(float x, float y, float z);
  217. /*!
  218. * \brief Looks for portal crossings from xyz to xyz2 segment
  219. * from room[index]
  220. * \param index valid room index
  221. * \param x X coordinate of first point
  222. * \param y Y coordinate of first point
  223. * \param z Z coordinate of first point
  224. * \param x2 X coordinate of second point
  225. * \param y2 Y coordinate of second point
  226. * \param z2 Z coordinate of second point
  227. * \returns index of adjoined room or -1
  228. */
  229. int getAdjoiningRoom(int index,
  230. float x, float y, float z,
  231. float x2, float y2, float z2);
  232. /*!
  233. * \brief Gets the sector index of the position in room
  234. * \param room valid room index
  235. * \param x X coordinate in room
  236. * \param z Z coordinate in room
  237. * \returns sector index of position in room
  238. */
  239. int getSector(int room, float x, float z);
  240. int getSector(int room, float x, float z, float *floor, float *ceiling);
  241. unsigned int getRoomInfo(int room);
  242. /*!
  243. * \brief Check if sector is a wall
  244. * \param room valid room index
  245. * \param sector valid sector index
  246. * \returns true if this sector is a wall
  247. */
  248. bool isWall(int room, int sector);
  249. /*!
  250. * \brief Get the world height at a position
  251. * \param index valid room index
  252. * \param x X coordinate
  253. * \param y will be set to world height in that room
  254. * \param z Z coordinate
  255. * \returns true if position is in a room
  256. */
  257. bool getHeightAtPosition(int index, float x, float *y, float z);
  258. #ifdef BAD_BLOOD
  259. //! \todo Temp methods for rendering use until more refactoring is done
  260. model_mesh_t *getMesh(int index);
  261. skeletal_model_t *getModel(int index);
  262. room_mesh_t *getRoom(int index);
  263. Vector<entity_t *> *getEntities();
  264. Vector<sprite_seq_t *> *getSprites();
  265. Vector<room_mesh_t *> *getRooms();
  266. #endif
  267. /*!
  268. * \brief Set an option flag
  269. * \param flag flag to set
  270. */
  271. void setFlag(WorldFlag flag);
  272. /*!
  273. * \brief Clear an option flag
  274. * \param flag flag to clear
  275. */
  276. void clearFlag(WorldFlag flag);
  277. /*!
  278. * \brief Clears all data in world
  279. * \todo in future will check if data is in use before clearing
  280. */
  281. void destroy();
  282. /*!
  283. * \brief Adds room to world
  284. * \param room room to add
  285. */
  286. void addRoom(room_mesh_t *room);
  287. /*!
  288. * \brief ADds mesh to world
  289. * \param model mesh to add
  290. */
  291. void addMesh(model_mesh_t *model);
  292. /*!
  293. * \brief Adds entity to world
  294. * \param e entity to add
  295. */
  296. void addEntity(entity_t *e);
  297. /*!
  298. * \brief Adds model to world.
  299. * \param model model to add
  300. * \returns next model ID or -1 on error
  301. */
  302. int addModel(skeletal_model_t *model);
  303. /*!
  304. * \brief Adds sprite to world
  305. * \param sprite sprite to add
  306. */
  307. void addSprite(sprite_seq_t *sprite);
  308. /*!
  309. * \brief Move entity in given direction unless collision occurs
  310. * \param e entity to move
  311. * \param movement direction of movement ('f', 'b', 'l' or 'r')
  312. */
  313. void moveEntity(entity_t *e, char movement);
  314. private:
  315. /*!
  316. * \brief Clears all data in world
  317. */
  318. void clear();
  319. bool mClearLock;
  320. unsigned int mFlags; //!< World flags
  321. Vector<entity_t *> mEntities; //!< World entities
  322. Vector<room_mesh_t *> mRooms; //!< Map data and meshes
  323. Vector<model_mesh_t *> mMeshes; //!< Unanimated meshes
  324. Vector<sprite_seq_t *> mSprites; //!< Sprites
  325. Vector<skeletal_model_t *> mModels; //!< Skeletal animation models
  326. };
  327. #endif