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 ///
119 bool mRegen;
120
121 enum MaskBits
122 {
123 MediaMask = Parent::NextFreeMask << 1,
124 LodMask = Parent::NextFreeMask << 2,
125 NextFreeMask = Parent::NextFreeMask << 3
126 };
127
128
129 static U32 smTotalCells;
130 static U32 smCellsRendered;
131 static U32 smCellItemsRendered;
132 static U32 smCellsBatched;
133 static U32 smCellItemsBatched;
134 static F32 smAverageItemsPerCell;
135
136 static void _clearStats(bool);
137
138 void _renderCellBounds( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
139
140 void _onZoningChanged( SceneZoneSpaceManager *zoneManager );
141
142 static ForestCreatedSignal smCreatedSignal;
143 static ForestCreatedSignal smDestroyedSignal;
144
145public:
146
147 static ForestCreatedSignal& getCreatedSignal() { return smCreatedSignal; }
148 static ForestCreatedSignal& getDestroyedSignal() { return smDestroyedSignal; }
149
150 Forest();
151 virtual ~Forest();
152
153 DECLARE_CONOBJECT(Forest);
154 static void consoleInit();
155 static void initPersistFields();
156
157 // SimObject
158 bool onAdd();
159 void onRemove();
160
161 /// Overloaded from SceneObject to properly update
162 /// the client side forest when changes occur within
163 /// the mission editor.
164 void inspectPostApply();
165
166 /// Overloaded from SceneObject for updating the
167 /// client side position of the forest.
168 void setTransform( const MatrixF &mat );
169
170 void prepRenderImage( SceneRenderState *state );
171
172 bool isTreeInRange( const Point2F& point, F32 radius ) const;
173
174 // Network
175 U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
176 void unpackUpdate( NetConnection *conn, BitStream *stream );
177
178 //IForestCollision *getCollision() const { return mCollision; }
179
180 // SceneObject - Collision
181 virtual void buildConvex( const Box3F& box, Convex* convex );
182 virtual bool buildPolyList( PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere );
183 virtual bool castRay( const Point3F &start, const Point3F &end, RayInfo *outInfo );
184 virtual bool castRayRendered( const Point3F &start, const Point3F &end, RayInfo *outInfo );
185 virtual bool collideBox( const Point3F &start, const Point3F &end, RayInfo *outInfo );
186
187 // SceneObject - Other
188 virtual void applyRadialImpulse( const Point3F &origin, F32 radius, F32 magnitude );
189
190 bool castRayBase( const Point3F &start, const Point3F &end, RayInfo *outInfo, bool rendered );
191
192 const Resource<ForestData>& getData() const { return mData; }
193
194 Resource<ForestData>& getData() { return mData; }
195
196 //bool buildPolyList(AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere);
197 //void buildConvex(const Box3F& box, Convex* convex);
198
199 void getLocalWindTrees( const Point3F &camPos, F32 radius, Vector<TreePlacementInfo> *placementInfo );
200
201 /// Called to create a new empty planting data file and
202 /// assign it to this forest.
203 void createNewFile();
204
205 ///
206 void saveDataFile( const char *path = NULL );
207
208 ///
209 void clear() { mData->clear(); }
210
211 /// Called to rebuild the collision state.
212 void updateCollision();
213};
214
215#endif // _H_FOREST_
216