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

Object.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef BZR_OBJECT_H
  19. #define BZR_OBJECT_H
  20. #include "Property.h"
  21. #include "Noncopyable.h"
  22. #include "LandcellId.h"
  23. #include "Location.h"
  24. #include "ObjectId.h"
  25. #include "Resource.h"
  26. #include <unordered_map>
  27. #define DEFINE_HASHER(type) \
  28. template<> \
  29. struct hash<type> \
  30. { \
  31. size_t operator()(type value) const \
  32. { return static_cast<size_t>(value); } \
  33. };
  34. namespace std
  35. {
  36. DEFINE_HASHER(BoolProperty)
  37. DEFINE_HASHER(StringProperty)
  38. DEFINE_HASHER(IntProperty)
  39. DEFINE_HASHER(Int64Property)
  40. DEFINE_HASHER(FloatProperty)
  41. DEFINE_HASHER(PositionProperty)
  42. DEFINE_HASHER(IIDProperty)
  43. DEFINE_HASHER(DIDProperty)
  44. }
  45. #undef DEFINE_HASHER
  46. struct Position
  47. {
  48. LandcellId landcell;
  49. glm::vec3 position;
  50. glm::quat rotation;
  51. };
  52. class Object : Noncopyable
  53. {
  54. public:
  55. Object(ObjectId id);
  56. void setProperty(BoolProperty property, bool value);
  57. void setProperty(StringProperty property, string value);
  58. void setProperty(IntProperty property, uint32_t value);
  59. void setProperty(Int64Property property, uint64_t value);
  60. void setProperty(FloatProperty property, double value);
  61. void setProperty(PositionProperty property, Position value);
  62. void setProperty(IIDProperty property, uint32_t value);
  63. void setProperty(DIDProperty property, uint32_t value);
  64. // Skill
  65. // Attribute
  66. // Attribute2nd
  67. void setModel(ResourcePtr model);
  68. void setLandcellId(const LandcellId& landcellId);
  69. void setLocation(const Location& location);
  70. ObjectId id() const;
  71. const ResourcePtr& model() const;
  72. const LandcellId& landcellId() const;
  73. const Location& location() const;
  74. private:
  75. const ObjectId id_;
  76. unordered_map<BoolProperty, bool> boolProperties_;
  77. unordered_map<StringProperty, string> stringProperties_;
  78. unordered_map<IntProperty, uint32_t> intProperties_;
  79. unordered_map<Int64Property, uint64_t> int64Properties_;
  80. unordered_map<FloatProperty, double> floatProperties_;
  81. unordered_map<PositionProperty, Position> positionProperties_;
  82. unordered_map<IIDProperty, uint32_t> iidProperties_;
  83. unordered_map<DIDProperty, uint32_t> didProperties_;
  84. ResourcePtr model_;
  85. LandcellId landcellId_;
  86. Location location_;
  87. };
  88. #endif