Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

Scene.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/Scene.h"
  19. #include "BinReader.h"
  20. #include "Land.h"
  21. #include "util.h"
  22. static void read(BinReader& reader, Scene::ObjectDesc& objectDesc)
  23. {
  24. objectDesc.resourceId = reader.readInt();
  25. assert(objectDesc.resourceId == 0 ||
  26. (objectDesc.resourceId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kModel) ||
  27. (objectDesc.resourceId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kSetup));
  28. read(reader, objectDesc.position);
  29. assert(objectDesc.position.x >= -Land::kCellSize && objectDesc.position.x <= Land::kCellSize);
  30. assert(objectDesc.position.y >= -Land::kCellSize && objectDesc.position.y <= Land::kCellSize);
  31. read(reader, objectDesc.rotation);
  32. objectDesc.frequency = reader.readFloat();
  33. assert(objectDesc.frequency >= 0.0 && objectDesc.frequency <= 1.0);
  34. objectDesc.displace.x = reader.readFloat();
  35. assert(objectDesc.displace.x >= -Land::kCellSize && objectDesc.displace.x <= Land::kCellSize);
  36. objectDesc.displace.y = reader.readFloat();
  37. assert(objectDesc.displace.y >= -Land::kCellSize && objectDesc.displace.y <= Land::kCellSize);
  38. objectDesc.minScale = reader.readFloat();
  39. assert(objectDesc.minScale >= 0.0f);
  40. objectDesc.maxScale = reader.readFloat();
  41. assert(objectDesc.maxScale >= 0.0f);
  42. assert(objectDesc.minScale <= objectDesc.maxScale);
  43. objectDesc.maxRotation = reader.readFloat();
  44. assert(objectDesc.maxRotation >= 0.0 && objectDesc.maxRotation <= 360.0);
  45. objectDesc.minSlope = reader.readFloat();
  46. objectDesc.maxSlope = reader.readFloat();
  47. uint32_t intAlign = reader.readInt();
  48. assert(intAlign == 0 || intAlign == 1);
  49. objectDesc.align = (intAlign != 0);
  50. uint32_t intOrient = reader.readInt();
  51. assert(intOrient == 0 || intOrient == 1);
  52. objectDesc.orient = (intOrient != 0);
  53. uint32_t intIsWeenieObj = reader.readInt();
  54. assert(intIsWeenieObj == 0 || intIsWeenieObj == 1);
  55. objectDesc.isWeenieObj = (intIsWeenieObj != 0);
  56. }
  57. Scene::Scene(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  58. {
  59. BinReader reader(data, size);
  60. uint32_t resourceId = reader.readInt();
  61. assert(resourceId == id);
  62. UNUSED(resourceId);
  63. uint32_t numObjects = reader.readInt();
  64. objects.resize(numObjects);
  65. for(ObjectDesc& objectDesc : objects)
  66. {
  67. read(reader, objectDesc);
  68. }
  69. }