Torque3D Documentation / _generateds / decalDataFile.h

decalDataFile.h

Engine/source/T3D/decal/decalDataFile.h

More...

Classes:

class

This is the data file for decals.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  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
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _DECALDATAFILE_H_
 25#define _DECALDATAFILE_H_
 26
 27#ifndef _DATACHUNKER_H_
 28#include "core/dataChunker.h"
 29#endif
 30
 31#ifndef _TVECTOR_H_
 32#include "core/util/tVector.h"
 33#endif
 34
 35#ifndef _DECALSPHERE_H_
 36#include "T3D/decal/decalSphere.h"
 37#endif
 38
 39
 40class Stream;
 41class DecalData;
 42
 43
 44
 45/// This is the data file for decals.
 46/// Not intended to be used directly, do your work with decals
 47/// via the DecalManager.
 48class DecalDataFile
 49{
 50   protected:
 51
 52      enum { FILE_VERSION = 5 };
 53
 54      /// Set to true if the file is dirty and
 55      /// needs to be saved before being destroyed.
 56      bool mIsDirty;
 57
 58      /// @name Memory Management
 59      /// @{
 60
 61      /// Allocator for DecalInstances.
 62      FreeListChunker< DecalInstance> mChunker;
 63
 64      /// Allocate a new, uninitialized DecalInstance.
 65      DecalInstance* _allocateInstance() { return mChunker.alloc(); }
 66
 67      /// Free the memory of the given DecalInstance.
 68      void _freeInstance( DecalInstance *decal ) { mChunker.free( decal ); }
 69
 70      /// @}
 71      
 72      /// @name Instance Management
 73      /// @{
 74
 75      /// The decal sphere that we have last insert an item into.  This sphere
 76      /// is most likely to be a good candidate for the next insertion so
 77      /// test this sphere first.
 78      DecalSphere* mSphereWithLastInsertion;
 79
 80      /// List of bounding sphere shapes that contain and organize
 81      /// DecalInstances for optimized culling and lookup.
 82      Vector< DecalSphere*> mSphereList;
 83
 84      /// Add the given decal to the sphere list.
 85      void _addDecalToSpheres( DecalInstance *inst );
 86
 87      /// Remove the decal from the sphere list.
 88      bool _removeDecalFromSpheres( DecalInstance *inst );
 89
 90      /// @}
 91   
 92   public:
 93
 94      DecalDataFile();
 95      virtual ~DecalDataFile();
 96
 97      Vector< DecalSphere*>& getSphereList() { return mSphereList; }
 98      const Vector< DecalSphere*>& getSphereList() const { return mSphereList; }
 99
100      /// Return true if the decal data has been modified since the last save or load.
101      bool isDirty() const { return mIsDirty; }
102
103      /// Deletes all the data and resets the 
104      /// file to an empty state.
105      void clear();
106
107      /// @name I/O
108      /// @{
109
110      /// Write the decal data to the given stream.
111      bool write( Stream& stream );
112
113      /// Read the decal data from the given stream.
114      bool read( Stream& stream );
115
116      /// @}
117
118      /// @name Decal Management
119      /// @{
120
121      /// Create a new decal in this file using the given data.
122      DecalInstance* addDecal( const Point3F& pos, const Point3F& normal, const Point3F& tangent,
123                               DecalData* decalData, F32 decalScale, S32 decalTexIndex, U8 flags );
124
125      /// Remove a decal from the file.
126      void removeDecal( DecalInstance *inst );
127
128      /// Let the file know that the data of the given decal has changed.
129      void notifyDecalModified( DecalInstance *inst );
130
131      /// @}
132};
133
134#endif // _DECALDATAFILE_H_
135