QGearsBackground2DFile.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-26 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #include "map/QGearsBackground2DFile.h"
  23. #include <OgreLogManager.h>
  24. #include <OgreResourceGroupManager.h>
  25. #include "map/QGearsBackground2DFileXMLSerializer.h"
  26. namespace QGears
  27. {
  28. //---------------------------------------------------------------------
  29. const String Background2DFile::RESOURCE_TYPE( "QGearsBackground2DFile" );
  30. //---------------------------------------------------------------------
  31. Background2DFile::Background2DFile( Ogre::ResourceManager *creator
  32. ,const String &name, Ogre::ResourceHandle handle
  33. ,const String &group, bool isManual
  34. ,Ogre::ManualResourceLoader *loader ) :
  35. Resource( creator, name, handle, group, isManual, loader )
  36. {
  37. }
  38. //---------------------------------------------------------------------
  39. Background2DFile::~Background2DFile()
  40. {
  41. unload();
  42. }
  43. //---------------------------------------------------------------------
  44. void
  45. Background2DFile::loadImpl()
  46. {
  47. Background2DFileXMLSerializer serializer;
  48. Ogre::DataStreamPtr stream( openResource() );
  49. serializer.importBackground2DFile( stream, this );
  50. }
  51. //---------------------------------------------------------------------
  52. void
  53. Background2DFile::unloadImpl()
  54. {
  55. m_texture_name.clear();
  56. m_range = 0;
  57. m_position = Ogre::Vector3::ZERO;
  58. m_orientation = Ogre::Quaternion::IDENTITY;
  59. m_fov = 0;
  60. m_tiles.clear();
  61. }
  62. //---------------------------------------------------------------------
  63. size_t
  64. Background2DFile::calculateSize() const
  65. {
  66. return 0;
  67. }
  68. //---------------------------------------------------------------------
  69. void
  70. Background2DFile::setTextureName( const String &texture_name )
  71. {
  72. m_texture_name = texture_name;
  73. }
  74. //---------------------------------------------------------------------
  75. String
  76. Background2DFile::getTextureName() const
  77. {
  78. return m_texture_name;
  79. }
  80. //---------------------------------------------------------------------
  81. void
  82. Background2DFile::setClip( const Ogre::Vector2 &clip )
  83. {
  84. m_clip = clip;
  85. }
  86. //---------------------------------------------------------------------
  87. Ogre::Vector2
  88. Background2DFile::getClip() const
  89. {
  90. return m_clip;
  91. }
  92. //---------------------------------------------------------------------
  93. void
  94. Background2DFile::setRange( const Ogre::Vector4 &range )
  95. {
  96. m_range = range;
  97. }
  98. //---------------------------------------------------------------------
  99. Ogre::Vector4
  100. Background2DFile::getRange() const
  101. {
  102. return m_range;
  103. }
  104. //---------------------------------------------------------------------
  105. void
  106. Background2DFile::setPosition( const Ogre::Vector3 &position )
  107. {
  108. m_position = position;
  109. }
  110. //---------------------------------------------------------------------
  111. Ogre::Vector3
  112. Background2DFile::getPosition() const
  113. {
  114. return m_position;
  115. }
  116. //---------------------------------------------------------------------
  117. void
  118. Background2DFile::setOrientation( const Ogre::Quaternion &orientation )
  119. {
  120. m_orientation = orientation;
  121. }
  122. //---------------------------------------------------------------------
  123. Ogre::Quaternion
  124. Background2DFile::getOrientation() const
  125. {
  126. return m_orientation;
  127. }
  128. //---------------------------------------------------------------------
  129. void
  130. Background2DFile::setFov( const Ogre::Radian &fov )
  131. {
  132. m_fov = fov;
  133. }
  134. //---------------------------------------------------------------------
  135. Ogre::Radian
  136. Background2DFile::getFov() const
  137. {
  138. return m_fov;
  139. }
  140. //---------------------------------------------------------------------
  141. Background2DFile::TileList&
  142. Background2DFile::getTiles( void )
  143. {
  144. return m_tiles;
  145. }
  146. //---------------------------------------------------------------------
  147. }