forest.h

Engine/source/forest/forest.h

More...

Classes:

class

Public Typedefs

Signal< void(Forest *forest)>
ForestCreatedSignal 

Detailed Description

Public Typedefs

typedef Signal< void(Forest *forest)> ForestCreatedSignal 
  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 _H_FOREST_
 25#define _H_FOREST_
 26
 27#ifndef _FORESTITEM_H_
 28   #include "forest/forestItem.h"
 29#endif
 30#ifndef _FORESTDATAFILE_H_
 31   #include "forest/forestDataFile.h"
 32#endif
 33#ifndef _MATHUTIL_FRUSTUM_H_  
 34   #include "math/util/frustum.h"
 35#endif
 36#ifndef _GFXTEXTUREHANDLE_H_
 37   #include "gfx/gfxTextureHandle.h"
 38#endif
 39#ifndef _COLLISION_H_
 40   #include "collision/collision.h"
 41#endif
 42#ifndef _SCENEOBJECT_H_
 43   #include "scene/sceneObject.h"
 44#endif
 45#ifndef _SIGNAL_H_
 46   #include "core/util/tSignal.h"
 47#endif
 48#ifndef __RESOURCE_H__
 49   #include "core/resource.h"
 50#endif
 51#ifndef _CONVEX_H_
 52   #include "collision/convex.h"
 53#endif
 54
 55
 56class TSShapeInstance;
 57class Forest;
 58class ForestItemData;
 59class ForestData;
 60class GBitmap;
 61class IForestCollision;
 62class IForestMask;
 63class PhysicsBody;
 64struct ObjectRenderInst;
 65struct TreePlacementInfo;
 66class ForestRayInfo;
 67class SceneZoneSpaceManager;
 68
 69
 70struct TreeInfo
 71{
 72   U32                     treeId;   
 73   SimObjectId             treeTypeId;
 74   F32                     distance;
 75   SimObjectId             forestId;
 76   Point3F                 position;
 77};
 78
 79typedef Signal<void( Forest *forest )> ForestCreatedSignal;
 80
 81
 82/// 
 83class Forest : public SceneObject
 84{
 85   friend class CreateForestEvent;
 86   friend class ForestConvex;
 87
 88protected:
 89
 90   typedef SceneObject Parent;
 91   
 92   /// Collision and Physics
 93   /// @{
 94
 95   Convex* mConvexList;   
 96   
 97   /// @}
 98
 99   /// The name of the planting data file.
100   StringTableEntry mDataFileName;
101
102   /// The forest data file which defines planting.
103   Resource<ForestData> mData;
104
105   /// Used to scale the tree LODs when rendering into 
106   /// reflections.  It should be greater or equal to 1.
107   F32 mReflectionLodScalar;
108
109   /// Set when rezoning of forest cells is required.
110   bool mZoningDirty;
111
112   /// Debug helpers.
113   static bool smForceImposters;
114   static bool smDisableImposters;
115   static bool smDrawCells;
116   static bool smDrawBounds;
117
118   enum MaskBits
119   {
120      MediaMask         = Parent::NextFreeMask << 1,
121      LodMask           = Parent::NextFreeMask << 2,
122      NextFreeMask      = Parent::NextFreeMask << 3
123   };
124
125
126   static U32  smTotalCells;
127   static U32  smCellsRendered;
128   static U32  smCellItemsRendered;
129   static U32  smCellsBatched;
130   static U32  smCellItemsBatched;
131   static F32  smAverageItemsPerCell;
132
133   static void _clearStats(bool);
134
135   void _renderCellBounds( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
136
137   void _onZoningChanged( SceneZoneSpaceManager *zoneManager );
138
139   static ForestCreatedSignal smCreatedSignal;
140   static ForestCreatedSignal smDestroyedSignal;
141
142public:
143   
144   static ForestCreatedSignal& getCreatedSignal() { return smCreatedSignal; }
145   static ForestCreatedSignal& getDestroyedSignal() { return smDestroyedSignal; }
146
147   Forest();
148   virtual ~Forest();
149
150   DECLARE_CONOBJECT(Forest);
151   static void consoleInit();
152   static void initPersistFields();   
153
154   // SimObject
155   bool onAdd();
156   void onRemove();
157
158   /// Overloaded from SceneObject to properly update
159   /// the client side forest when changes occur within
160   /// the mission editor.
161   void inspectPostApply();
162
163   /// Overloaded from SceneObject for updating the 
164   /// client side position of the forest.
165   void setTransform( const MatrixF &mat );
166
167   void prepRenderImage( SceneRenderState *state );
168
169   bool isTreeInRange( const Point2F& point, F32 radius ) const;
170
171   // Network
172   U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
173   void unpackUpdate( NetConnection *conn, BitStream *stream );
174
175   //IForestCollision *getCollision() const { return mCollision; }
176
177   // SceneObject - Collision
178   virtual void buildConvex( const Box3F& box, Convex* convex );
179   virtual bool buildPolyList( PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere );
180   virtual bool castRay( const Point3F &start, const Point3F &end, RayInfo *outInfo );
181   virtual bool castRayRendered( const Point3F &start, const Point3F &end, RayInfo *outInfo );
182   virtual bool collideBox( const Point3F &start, const Point3F &end, RayInfo *outInfo );
183
184   // SceneObject - Other
185   virtual void applyRadialImpulse( const Point3F &origin, F32 radius, F32 magnitude );
186
187   bool castRayBase( const Point3F &start, const Point3F &end, RayInfo *outInfo, bool rendered );
188     
189   const Resource<ForestData>& getData() const { return mData; }
190
191   Resource<ForestData>& getData() { return mData; }
192
193   //bool  buildPolyList(AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere);
194   //void  buildConvex(const Box3F& box, Convex* convex);
195
196   void getLocalWindTrees( const Point3F &camPos, F32 radius, Vector<TreePlacementInfo> *placementInfo );
197
198   /// Called to create a new empty planting data file and
199   /// assign it to this forest.
200   void createNewFile();
201
202   ///
203   void saveDataFile( const char *path = NULL );
204
205   ///
206   void clear() { mData->clear(); }
207
208   /// Called to rebuild the collision state.
209   void updateCollision();
210};
211
212#endif // _H_FOREST_
213