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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*!
  2. * \file include/World.h
  3. * \brief The game world (model)
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #ifndef _WORLD_H_
  9. #define _WORLD_H_
  10. #include <list>
  11. #include <vector>
  12. #define BAD_BLOOD //!< \todo For temp rendering use
  13. #ifdef BAD_BLOOD
  14. #include "SkeletalModel.h"
  15. #else
  16. #include "Room.h"
  17. #include "Sprite.h"
  18. #endif
  19. #include "WorldData.h"
  20. /*!
  21. * \brief The game world (model)
  22. */
  23. class World {
  24. public:
  25. /*!
  26. * \brief Deconstructs an object of World
  27. */
  28. ~World();
  29. #ifdef BAD_BLOOD
  30. //! \todo Temp methods for rendering use until more refactoring is done
  31. /*!
  32. * \brief Adds room to world
  33. * \param room room to add
  34. */
  35. void addRoom(room_mesh_t *room);
  36. /*!
  37. * \brief Adds mesh to world
  38. * \param model mesh to add
  39. */
  40. void addMesh(model_mesh_t *model);
  41. /*!
  42. * \brief Adds entity to world
  43. * \param e entity to add
  44. */
  45. void addEntity(entity_t *e);
  46. /*!
  47. * \brief Adds model to world.
  48. * \param model model to add
  49. * \returns next model ID or -1 on error
  50. */
  51. int addModel(skeletal_model_t *model);
  52. /*!
  53. * \brief Adds sprite to world
  54. * \param sprite sprite to add
  55. */
  56. void addSprite(sprite_seq_t *sprite);
  57. /*!
  58. * \brief Move entity in given direction unless collision occurs
  59. * \param e entity to move
  60. * \param movement direction of movement ('f', 'b', 'l' or 'r')
  61. */
  62. void moveEntity(entity_t *e, char movement);
  63. model_mesh_t *getMesh(int index);
  64. skeletal_model_t *getModel(int index);
  65. room_mesh_t *getRoom(int index);
  66. std::vector<entity_t *> *getEntities();
  67. std::vector<sprite_seq_t *> *getSprites();
  68. std::vector<room_mesh_t *> *getRooms();
  69. #else
  70. void addRoom(Room &room);
  71. void addSprite(SpriteSequence &sprite);
  72. #endif
  73. /*!
  74. * \brief Find room a location is in.
  75. *
  76. * If it fails to be in a room it gives closest overlapping room.
  77. * \param index Guessed room index
  78. * \param x X coordinate
  79. * \param y Y coordinate
  80. * \param z Z coordinate
  81. * \returns correct room index or -1 for unknown
  82. */
  83. int getRoomByLocation(int index, float x, float y, float z);
  84. /*!
  85. * \brief Find room a location is in.
  86. *
  87. * If it fails to be in a room it gives closest overlapping room.
  88. * \param x X coordinate
  89. * \param y Y coordinate
  90. * \param z Z coordinate
  91. * \returns correct room index or -1 for unknown
  92. */
  93. int getRoomByLocation(float x, float y, float z);
  94. /*!
  95. * \brief Looks for portal crossings from xyz to xyz2 segment
  96. * from room[index]
  97. * \param index valid room index
  98. * \param x X coordinate of first point
  99. * \param y Y coordinate of first point
  100. * \param z Z coordinate of first point
  101. * \param x2 X coordinate of second point
  102. * \param y2 Y coordinate of second point
  103. * \param z2 Z coordinate of second point
  104. * \returns index of adjoined room or -1
  105. */
  106. int getAdjoiningRoom(int index,
  107. float x, float y, float z,
  108. float x2, float y2, float z2);
  109. /*!
  110. * \brief Gets the sector index of the position in room
  111. * \param room valid room index
  112. * \param x X coordinate in room
  113. * \param z Z coordinate in room
  114. * \returns sector index of position in room
  115. */
  116. int getSector(int room, float x, float z);
  117. int getSector(int room, float x, float z, float *floor, float *ceiling);
  118. unsigned int getRoomInfo(int room);
  119. /*!
  120. * \brief Check if sector is a wall
  121. * \param room valid room index
  122. * \param sector valid sector index
  123. * \returns true if this sector is a wall
  124. */
  125. bool isWall(int room, int sector);
  126. /*!
  127. * \brief Get the world height at a position
  128. * \param index valid room index
  129. * \param x X coordinate
  130. * \param y will be set to world height in that room
  131. * \param z Z coordinate
  132. * \returns true if position is in a room
  133. */
  134. bool getHeightAtPosition(int index, float x, float *y, float z);
  135. /*!
  136. * \brief Clears all data in world
  137. * \todo in future will check if data is in use before clearing
  138. */
  139. void destroy();
  140. private:
  141. #ifdef BAD_BLOOD
  142. // Old World
  143. std::vector<entity_t *> mEntities; //!< World entities
  144. std::vector<room_mesh_t *> mRooms; //!< Map data and meshes
  145. std::vector<model_mesh_t *> mMeshes; //!< Unanimated meshes
  146. std::vector<sprite_seq_t *> mSprites; //!< Sprites
  147. std::vector<skeletal_model_t *> mModels; //!< Skeletal animation models
  148. #else
  149. // New World
  150. std::vector<Room *> mRooms;
  151. std::vector<SpriteSequence *> mSprites;
  152. #endif
  153. };
  154. #endif