1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CL_MICRO_LIFE_MANAGER_H
20 #define CL_MICRO_LIFE_MANAGER_H
22 #include "timed_fx_manager.h"
24 #include "game_share/season.h"
26 #include "nel/3d/u_landscape.h"
27 #include "nel/misc/polygon.h"
28 #include "nel/misc/triangle.h"
38 /** Spawn/despawn microlife fx on the landscape. Those fx are created in the world editor using 'patatoid' primitives.
39 * This manager look in which primitive the player is, and add/remove microlife with the given density as necessary.
40 * Microlife FXs are a special case of timed fx, and this manager relies in fact on CTimedFXManager
41 * \TODO The container used is basically a quadgrid tailored for polygons, so it may be good to put the container part in NL3D for reuse (test for water intersection are similar)
42 * \author Nicolas Vizerie
43 * \author Nevrax France
47 class CMicroLifeManager
: public NL3D::ULandscapeTileCallback
50 // get the unique instance of that class
51 static CMicroLifeManager
&getInstance();
53 * \param minCorner minimum coordinate of continent
54 * \param maxCorner maximum coordinate of continent
55 * \param cellSize size of grid cells used to test if a tile intersect a primitive (also limit precision of tests)
57 void init(const NLMISC::CVector2f
&minCorner
, const NLMISC::CVector2f
&maxCorner
, float cellSize
= 30.f
);
58 // build from a list of primitive names
59 void build(const std::vector
<std::string
> &fileNames
);
60 // release all managed primitive / created fxs
62 // Dump grid as a tga file. For debug
63 void dumpMLGrid(const std::string
&filename
);
64 // render the primitive that contains microlife on screen as boxes (for debug)
65 void renderMLZones(const NLMISC::CVector2f
&camPos
, float maxDist
= 1000.f
);
67 // render active tiles
68 void renderActiveTiles();
71 // infos for a zone polygon overlapping a given grid cell
72 class CGridOverlapPolyInfo
75 NLMISC::CPolygon2D Poly
;
76 bool IsExcludePoly
; // this is an exclusion polygon
77 bool IsFullyCovered
; // the grid cell is fully contained into that polygon so fast test can be performed
78 const CFloraSheet
*Sheet
;
81 bool operator < (const CGridOverlapPolyInfo
&other
) const;
82 bool operator == (const CGridOverlapPolyInfo
&other
) const;
84 // a vector of CGridOverlapPolyInfo
85 class CGridOverlapPolyInfoVector
88 std::vector
<CGridOverlapPolyInfo
> V
;
90 bool operator < (const CGridOverlapPolyInfoVector
&other
) const;
91 bool operator == (const CGridOverlapPolyInfoVector
&other
) const;
93 // temporary grid used for build
94 typedef std::vector
<CGridOverlapPolyInfoVector
> TBuildGrid
;
95 // possible list of polygons that can overlap a grid cells
96 typedef std::vector
<CGridOverlapPolyInfoVector
> TPossibleOverlapingPolyLists
;
97 TPossibleOverlapingPolyLists _PossibleOverlapPolyLists
;
98 /** A grid that cover the continent and that give the list of primitives polygons that cover each cell
99 * List of primitives are shared between each cell.
100 * Each cell contains an index into _PossibleOverlapPolyLists.
102 std::vector
<uint16
> _Grid
;
103 float _CellSize
; // size of a grid cell in meters
104 uint _GridWidth
; // width of the grid (a number of cells)
105 uint _GridHeight
; // height of the grid (a number of cells)
106 NLMISC::CVector2f _MinCorner
;
107 NLMISC::CNoiseValue _Noise
;
109 typedef CHashMap
<uint64
, CTimedFXManager::TFXGroupHandle
> TTileIDToFX
;
110 TTileIDToFX _ActiveFXs
; // active fxs, sorted by tiles ids
113 CHashMap
<uint64
, NL3D::CTileAddedInfo
> _ActiveTiles
;
114 CHashMap
<uint64
, NL3D::CTileAddedInfo
> _ActiveTilesWithFX
;
118 // prevent construction from outside
120 // from NL3D::ULandscapeTileCallback
121 virtual void tileAdded(const NL3D::CTileAddedInfo
&infos
);
122 virtual void tileRemoved(uint64 id
);
123 // add / remove a poly of a zone to a build grid. Poly coordinates are in world.
124 void drawPolyInBuildGrid(const std::vector
<NLLIGO::CPrimVector
> &primPoly
,
126 TBuildGrid
&buildGrid
,
127 const CFloraSheet
*sheet
,
129 // pack the build grid so that each cell only contains index into a small set of poly list, instead of a full poly list
130 // (a lot of cells share the same poly list)
131 void packBuildGrid(TBuildGrid
&buildGrid
,
132 TPossibleOverlapingPolyLists
&possibleLists
134 // add a primitive file in the build grid
135 // the primitive file 'primitiveIndex' is incremented
136 void addPrimitiveToBuildGrid(const std::string
&fileName
, uint
&primitiveIndex
, TBuildGrid
&buildGrid
);
138 friend class CCleanFullyCoveredGridCellPred
;
142 // for debug : boolean which indicates if micro_life zones should
144 extern bool DisplayMicroLifeZones
;
148 extern bool DisplayMicroLifeActiveTiles
;