decalDataFile.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef _DECALDATAFILE_H_
  23. #define _DECALDATAFILE_H_
  24. #ifndef _DATACHUNKER_H_
  25. #include "core/dataChunker.h"
  26. #endif
  27. #ifndef _TVECTOR_H_
  28. #include "core/util/tVector.h"
  29. #endif
  30. #ifndef _DECALSPHERE_H_
  31. #include "T3D/decal/decalSphere.h"
  32. #endif
  33. class Stream;
  34. class DecalData;
  35. /// This is the data file for decals.
  36. /// Not intended to be used directly, do your work with decals
  37. /// via the DecalManager.
  38. class DecalDataFile
  39. {
  40. protected:
  41. enum { FILE_VERSION = 5 };
  42. /// Set to true if the file is dirty and
  43. /// needs to be saved before being destroyed.
  44. bool mIsDirty;
  45. /// @name Memory Management
  46. /// @{
  47. /// Allocator for DecalInstances.
  48. FreeListChunker< DecalInstance > mChunker;
  49. /// Allocate a new, uninitialized DecalInstance.
  50. DecalInstance* _allocateInstance() { return mChunker.alloc(); }
  51. /// Free the memory of the given DecalInstance.
  52. void _freeInstance( DecalInstance *decal ) { mChunker.free( decal ); }
  53. /// @}
  54. /// @name Instance Management
  55. /// @{
  56. /// The decal sphere that we have last insert an item into. This sphere
  57. /// is most likely to be a good candidate for the next insertion so
  58. /// test this sphere first.
  59. DecalSphere* mSphereWithLastInsertion;
  60. /// List of bounding sphere shapes that contain and organize
  61. /// DecalInstances for optimized culling and lookup.
  62. Vector< DecalSphere* > mSphereList;
  63. /// Add the given decal to the sphere list.
  64. void _addDecalToSpheres( DecalInstance *inst );
  65. /// Remove the decal from the sphere list.
  66. bool _removeDecalFromSpheres( DecalInstance *inst );
  67. /// @}
  68. public:
  69. DecalDataFile();
  70. virtual ~DecalDataFile();
  71. Vector< DecalSphere* >& getSphereList() { return mSphereList; }
  72. const Vector< DecalSphere* >& getSphereList() const { return mSphereList; }
  73. /// Return true if the decal data has been modified since the last save or load.
  74. bool isDirty() const { return mIsDirty; }
  75. /// Deletes all the data and resets the
  76. /// file to an empty state.
  77. void clear();
  78. /// @name I/O
  79. /// @{
  80. /// Write the decal data to the given stream.
  81. bool write( Stream& stream );
  82. /// Read the decal data from the given stream.
  83. bool read( Stream& stream );
  84. /// @}
  85. /// @name Decal Management
  86. /// @{
  87. /// Create a new decal in this file using the given data.
  88. DecalInstance* addDecal( const Point3F& pos, const Point3F& normal, const Point3F& tangent,
  89. DecalData* decalData, F32 decalScale, S32 decalTexIndex, U8 flags );
  90. /// Remove a decal from the file.
  91. void removeDecal( DecalInstance *inst );
  92. /// Let the file know that the data of the given decal has changed.
  93. void notifyDecalModified( DecalInstance *inst );
  94. /// @}
  95. };
  96. #endif // _DECALDATAFILE_H_