1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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 #include "nel/3d/tile_vegetable_desc.h"
20 #include "nel/misc/common.h"
21 #include "nel/3d/vegetable_manager.h"
24 using namespace NLMISC
;
36 // ***************************************************************************
37 CTileVegetableDesc::CTileVegetableDesc()
42 // ***************************************************************************
43 void CTileVegetableDesc::clear()
45 for(sint i
=0; i
<NL3D_VEGETABLE_BLOCK_NUMDIST
; i
++)
47 _VegetableList
[i
].clear();
52 // ***************************************************************************
53 void CTileVegetableDesc::build(const std::vector
<CVegetable
> &vegetables
)
60 // Parse all landscape vegetables, and store them in appropriate distance Type.
61 for(i
=0;i
<vegetables
.size();i
++)
63 uint distType
= vegetables
[i
].DistType
;
64 distType
= min(distType
, (uint
)(NL3D_VEGETABLE_BLOCK_NUMDIST
-1));
65 _VegetableList
[distType
].push_back(vegetables
[i
]);
68 // Compute Seed such that creation of one vegetable for a tile will never receive same seed.
70 for(i
=0; i
<NL3D_VEGETABLE_BLOCK_NUMDIST
; i
++)
72 _VegetableSeed
[i
]= sumVeget
;
73 // add number of vegetable for next seed.
74 sumVeget
+= (uint
)_VegetableList
[i
].size();
81 // ***************************************************************************
82 void CTileVegetableDesc::registerToManager(CVegetableManager
*vegetableManager
)
84 // Pasre all distanceType.
85 for(uint i
=0; i
<NL3D_VEGETABLE_BLOCK_NUMDIST
; i
++)
87 // Parse all vegetables of the list.
88 for(uint j
=0; j
<_VegetableList
[i
].size(); j
++)
90 // register the vegetable to the manager
91 _VegetableList
[i
][j
].registerToManager(vegetableManager
);
96 // ***************************************************************************
97 void CTileVegetableDesc::serial(NLMISC::IStream
&f
)
99 (void)f
.serialVersion(0);
101 nlassert(NL3D_VEGETABLE_BLOCK_NUMDIST
==5);
102 for(uint i
=0; i
<NL3D_VEGETABLE_BLOCK_NUMDIST
; i
++)
104 f
.serialCont(_VegetableList
[i
]);
105 f
.serial(_VegetableSeed
[i
]);
113 // ***************************************************************************
114 const std::vector
<CVegetable
> &CTileVegetableDesc::getVegetableList(uint distType
) const
116 nlassert(distType
< NL3D_VEGETABLE_BLOCK_NUMDIST
);
118 return _VegetableList
[distType
];
121 // ***************************************************************************
122 uint
CTileVegetableDesc::getVegetableSeed(uint distType
) const
124 nlassert(distType
< NL3D_VEGETABLE_BLOCK_NUMDIST
);
126 return _VegetableSeed
[distType
];
129 // ***************************************************************************
130 void CTileVegetableDesc::compileRunTime()
132 // Compute _Empty flag
134 for(uint i
=0; i
<NL3D_VEGETABLE_BLOCK_NUMDIST
; i
++)
136 if(!_VegetableList
[i
].empty())