Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / micro_life_manager.h
blob0a6768fb24c88dc5b677547cbca2c254125f9939
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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"
31 class CFloraSheet;
33 namespace NLLIGO
35 class CPrimVector;
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
44 * \date 1/2004
47 class CMicroLifeManager : public NL3D::ULandscapeTileCallback
49 public:
50 // get the unique instance of that class
51 static CMicroLifeManager &getInstance();
52 /** Init the manager
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
61 void release();
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);
66 #ifdef NL_DEBUG
67 // render active tiles
68 void renderActiveTiles();
69 #endif
70 private:
71 // infos for a zone polygon overlapping a given grid cell
72 class CGridOverlapPolyInfo
74 public:
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;
79 uint PrimitiveIndex;
80 public:
81 bool operator < (const CGridOverlapPolyInfo &other) const;
82 bool operator == (const CGridOverlapPolyInfo &other) const;
84 // a vector of CGridOverlapPolyInfo
85 class CGridOverlapPolyInfoVector
87 public:
88 std::vector<CGridOverlapPolyInfo> V;
89 public:
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
112 #ifdef NL_DEBUG
113 CHashMap<uint64, NL3D::CTileAddedInfo> _ActiveTiles;
114 CHashMap<uint64, NL3D::CTileAddedInfo> _ActiveTilesWithFX;
115 #endif
117 private:
118 // prevent construction from outside
119 CMicroLifeManager();
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,
125 uint primitiveIndex,
126 TBuildGrid &buildGrid,
127 const CFloraSheet *sheet,
128 bool isExcludeTri);
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
143 #if !FINAL_VERSION
144 extern bool DisplayMicroLifeZones;
145 #endif
147 #ifdef NL_DEBUG
148 extern bool DisplayMicroLifeActiveTiles;
149 #endif
153 #endif