interiorSubObject.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "core/stream/stream.h"
  23. #include "interior/interiorInstance.h"
  24. #include "interior/interiorSubObject.h"
  25. #include "interior/mirrorSubObject.h"
  26. InteriorSubObject::InteriorSubObject()
  27. {
  28. mInteriorInstance = NULL;
  29. }
  30. InteriorSubObject::~InteriorSubObject()
  31. {
  32. mInteriorInstance = NULL;
  33. }
  34. InteriorSubObject* InteriorSubObject::readISO(Stream& stream)
  35. {
  36. U32 soKey;
  37. stream.read(&soKey);
  38. InteriorSubObject* pObject = NULL;
  39. switch (soKey) {
  40. case MirrorSubObjectKey:
  41. pObject = new MirrorSubObject;
  42. break;
  43. default:
  44. Con::errorf(ConsoleLogEntry::General, "Bad key in subObject stream!");
  45. return NULL;
  46. };
  47. if (pObject) {
  48. bool readSuccess = pObject->_readISO(stream);
  49. if (readSuccess == false) {
  50. delete pObject;
  51. pObject = NULL;
  52. }
  53. }
  54. return pObject;
  55. }
  56. bool InteriorSubObject::writeISO(Stream& stream) const
  57. {
  58. stream.write(getSubObjectKey());
  59. return _writeISO(stream);
  60. }
  61. bool InteriorSubObject::_readISO(Stream& stream)
  62. {
  63. return (stream.getStatus() == Stream::Ok);
  64. }
  65. bool InteriorSubObject::_writeISO(Stream& stream) const
  66. {
  67. return (stream.getStatus() == Stream::Ok);
  68. }
  69. const MatrixF& InteriorSubObject::getSOTransform() const
  70. {
  71. static const MatrixF csBadMatrix(true);
  72. if (mInteriorInstance != NULL) {
  73. return mInteriorInstance->getTransform();
  74. } else {
  75. AssertWarn(false, "Returning bad transform for subobject");
  76. return csBadMatrix;
  77. }
  78. }
  79. const Point3F& InteriorSubObject::getSOScale() const
  80. {
  81. return mInteriorInstance->getScale();
  82. }
  83. InteriorInstance* InteriorSubObject::getInstance()
  84. {
  85. return mInteriorInstance;
  86. }
  87. void InteriorSubObject::noteTransformChange()
  88. {
  89. //
  90. }