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.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*!
  2. * \file src/World.cpp
  3. * \brief The game world (model)
  4. *
  5. * \author Mongoose
  6. */
  7. #include <cstdio>
  8. #include <math.h>
  9. #include "global.h"
  10. #include "World.h"
  11. World &getWorld() {
  12. static World gWorld;
  13. return gWorld;
  14. }
  15. World::~World() {
  16. destroy();
  17. }
  18. void World::addRoom(Room &room) {
  19. mRooms.push_back(&room);
  20. }
  21. unsigned long World::sizeRoom() {
  22. return mRooms.size();
  23. }
  24. Room &World::getRoom(unsigned long index) {
  25. assert(index < mRooms.size());
  26. return *mRooms.at(index);
  27. }
  28. void World::addSprite(SpriteSequence &sprite) {
  29. mSprites.push_back(&sprite);
  30. }
  31. unsigned long World::sizeSprite() {
  32. return mSprites.size();
  33. }
  34. SpriteSequence &World::getSprite(unsigned long index) {
  35. assert(index < mSprites.size());
  36. return *mSprites.at(index);
  37. }
  38. void World::addEntity(Entity &entity) {
  39. mEntities.push_back(&entity);
  40. }
  41. unsigned long World::sizeEntity() {
  42. return mEntities.size();
  43. }
  44. Entity &World::getEntity(unsigned long index) {
  45. assert(index < mEntities.size());
  46. return *mEntities.at(index);
  47. }
  48. void World::addSkeletalModel(SkeletalModel &model) {
  49. mModels.push_back(&model);
  50. }
  51. unsigned long World::sizeSkeletalModel() {
  52. return mModels.size();
  53. }
  54. SkeletalModel &World::getSkeletalModel(unsigned long index) {
  55. assert(index < mModels.size());
  56. return *mModels.at(index);
  57. }
  58. void World::addStaticMesh(StaticMesh &model) {
  59. mMeshes.push_back(&model);
  60. }
  61. unsigned long World::sizeStaticMesh() {
  62. return mMeshes.size();
  63. }
  64. StaticMesh &World::getStaticMesh(unsigned long index) {
  65. assert(index < mMeshes.size());
  66. return *mMeshes.at(index);
  67. }
  68. long World::getRoomByLocation(long index, float x, float y, float z)
  69. {
  70. assert(index >= 0);
  71. assert(index < (long)mRooms.size());
  72. Room &room = *mRooms.at(index);
  73. if (room.getBoundingBox().inBox(x, y, z))
  74. return index;
  75. else
  76. return getRoomByLocation(x, y, z);
  77. }
  78. long World::getRoomByLocation(float x, float y, float z) {
  79. long hop = -1;
  80. for (unsigned long i = 0; i < mRooms.size(); i++) {
  81. if (mRooms.at(i)->getBoundingBox().inBoxPlane(x, z)) {
  82. if (mRooms.at(i)->getBoundingBox().inBox(x, y, z))
  83. return i;
  84. else
  85. hop = i; // This room is above or below current position
  86. }
  87. }
  88. return hop;
  89. }
  90. void World::destroy() {
  91. for (unsigned long i = 0; i < mRooms.size(); i++)
  92. delete mRooms[i];
  93. mRooms.clear();
  94. for (unsigned long i = 0; i < mSprites.size(); i++)
  95. delete mSprites[i];
  96. mSprites.clear();
  97. for (unsigned long i = 0; i < mEntities.size(); i++)
  98. delete mEntities[i];
  99. mEntities.clear();
  100. for (unsigned long i = 0; i < mModels.size(); i++)
  101. delete mModels[i];
  102. mModels.clear();
  103. for (unsigned long i = 0; i < mMeshes.size(); i++)
  104. delete mMeshes[i];
  105. mMeshes.clear();
  106. }