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/>.
17 #include "nel/misc/command.h"
19 #include "game_share/bmp4image.h"
24 using namespace NLMISC
;
35 uint8 Heading
[16][16];
43 memset(Points
,0,sizeof(Points
));
46 void addPoint(uint x
,uint y
)
53 char txt
[]="0123456789abcdef";
54 nlinfo("Surface Points: ",txt
);
55 for (uint j
=0;j
<16;++j
)
57 for (uint i
=0;i
<16;++i
)
58 txt
[i
]=(Points
[j
]&(1<<i
))? ' ': '#';
64 sint16 Points
[16]; // boolean map of surface shape
65 uint8 XNeighbours
[16][16];
66 uint8 YNeighbours
[16][16];
67 std::vector
<CNeighbour
> Neighbours
;
73 sint8 Points
[16][16]; // ends up with set of surface ids
74 std::vector
<CSurface
*> Surfaces
;
77 void generateSurfaces(char *topLeft
,uint lineLen
,CCell
&cell
)
79 std::stack
<uint
> stack
;
82 // fill the points grid with -1 where accessible and -2 where inaccessible
83 uint goodCount
=0, badCount
=0;
86 if (*(topLeft
+i
+lineLen
*j
)==' ')
88 cell
.Points
[j
][i
]= -1;
93 cell
.Points
[j
][i
]= -2;
97 // flood fill to convert -1s to surface ids
98 uint surfaceCount
=~0u;
101 if (cell
.Points
[j
][i
]==-1)
103 CSurface
*surface
=new CSurface
;
104 cell
.Surfaces
.push_back(surface
);
106 cell
.Points
[j
][i
]=surfaceCount
;
108 while (!stack
.empty())
110 // pop the coordinate off the stack
111 uint x
=stack
.top()&0xf;
112 uint y
=stack
.top()/16;
115 // add the point to the surface
116 surface
->addPoint(x
,y
);
118 // look for neighbouring points to add to the same surface
119 if (x
<15 && cell
.Points
[y
][x
+1]==-1) { cell
.Points
[y
][x
+1]=surfaceCount
; stack
.push(16*y
+ x
+1); }
120 if (x
>0 && cell
.Points
[y
][x
-1]==-1) { cell
.Points
[y
][x
-1]=surfaceCount
; stack
.push(16*y
+ x
-1); }
121 if (y
<15 && cell
.Points
[y
+1][x
]==-1) { cell
.Points
[y
+1][x
]=surfaceCount
; stack
.push(16*y
+16+ x
); }
122 if (y
>0 && cell
.Points
[y
-1][x
]==-1) { cell
.Points
[y
-1][x
]=surfaceCount
; stack
.push(16*y
-16+ x
); }
124 surface
->displayPoints();
126 nlinfo("Generated %i surfaces, %i accessible cell.Points, %i inaccessible cell.Points",surfaceCount
+1,goodCount
,badCount
);
131 txt
[i
]=(cell
.Points
[j
][i
]>=0 && cell
.Points
[j
][i
]<=9)? cell
.Points
[j
][i
]+'0': '#';
133 nlinfo("- surfaces: %s", txt
);
137 static void generateSurfaceNeighbourhoods(
138 CCell
*tl
, CCell
*tm
, CCell
*tr
,
139 CCell
*ml
, CCell
*mm
, CCell
*mr
,
140 CCell
*bl
, CCell
*bm
, CCell
*br
)
142 // todo here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
144 // generate horizontal neighbours
146 // generate vertical neighbours
148 // * add propagation maps to the surfaces
149 // for each surface propagate out following neighbour map
152 NLMISC_COMMAND(dummyCrunch
,"Run a test of pacs crunch","")
158 "0000000000000000111111111111111100000000000000001111111111111111"
159 "0000000000000000111111111111111100000000000000001111111111111111"
160 "0000000000000000111111111111111100000000000000001111111111111111"
164 "000 00000000001111111111 111000 00000000001111111111 111"
172 "000 000000000011111 1 111000 000000000011111 1 111"
173 "000 000000011111 1 111000 000000011111 1 111"
174 "222 222222233333 3 333222 222222233333 3 333"
175 "222222222222222233333 3 333222222222222222233333 3 333"
178 "222 2222222222223333333333 333222 2222222222223333333333 333"
182 "222222222222222233333333333333332222222222 22223333333333333333"
183 "22222222222222223 32222222222 22223333333333333333"
184 "22222222222222223 333333333333 32222222222 22223333333333333333"
185 "22222222222222223 33 33 32222222222 22223333333333333333"
186 "22222222222222223 33 32222222222 22223333333333333333"
187 "22222222222222223333 33 32222222222 22223333333333333333"
188 "222222222222222233333 333 2222 22223333333333333333"
189 "222222222222222233333333 33333322222 2222 22223333333333333333"
190 "0000000000000000111111111 1111100000 0000 00001111111111111111"
191 "00000000000000001111111111 111100000 0000 00001111111111111111"
192 "000000000000000011111111111 11100000 0000 00001111111111111111"
196 "000 00000000001111111111 11 00 00000000001111111111 111"
204 "000 000000000011111 1 111000 000000000011111 1 111"
205 "000 000000011111 1 111000 000000011111 1 111"
206 "222 222222233333 3 333222 222222233333 3 333"
207 "222222222222222233333 3 333222222222222222233333 3 333"
210 "222 2222222222223333333333 333222 2222222222223333333333 333"
214 "2222222222222222333333333333333322222222222222223333333333333333"
215 "2222 222222222333 333333322 2222233 333"
216 "22222 22222222223333 33 33333333222 22 22 222222333 3 33333 3333"
217 "22222 22222222223333 33 33333333222 22 22 222222333 33 333 33333"
218 "22222 22222222223333 33 33333333222 22 22 222222333 333 3 333333"
219 "22222 22222222223333 33 33333333222 22 22 222222333 3333 3333333"
220 "2222 222222222333 333333322 2222233 333"
221 "2222222222222222333333333333333322222222222222223333333333333333";
226 // need to create a dummy cell that links into the cell grid in all slots as
230 // setup a 4x4 cell grid in a 6x6 grid surrounded by NULLs
231 typedef CCell
*TCellRef
;
232 TCellRef cells
[6][6];
233 memset (cells
,0,sizeof(cells
));
236 cells
[j
+1][i
+1]=new CCell
;
241 generateSurfaces(testMap
+i
*16+j
*64*16,64,*cells
[j
+1][i
+1]);
243 // generate surface neighbourhoods
246 generateSurfaceNeighbourhoods(
247 cells
[1+j
-1][1+i
-1], cells
[1+j
-1][1+i
+0], cells
[1+j
-1][1+i
+1],
248 cells
[1+j
+0][1+i
-1], cells
[1+j
+0][1+i
+0], cells
[1+j
+0][1+i
+1],
249 cells
[1+j
+1][1+i
-1], cells
[1+j
+1][1+i
+0], cells
[1+j
+1][1+i
+1]