Add infos into target window
[ryzomcore.git] / ryzom / server / src / ai_data_service / dummy_crunch.cpp
blobe1b0605ff0e822a43d4151c20da201dbce0ba8bb
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/>.
17 #include "nel/misc/command.h"
19 #include "game_share/bmp4image.h"
21 #include <vector>
23 using namespace std;
24 using namespace NLMISC;
28 #include <stack>
30 class CNeighbour
32 uint SurfaceCell;
33 uint CellSurfaceIdx;
35 uint8 Heading[16][16];
38 class CSurface
40 public:
41 CSurface()
43 memset(Points,0,sizeof(Points));
46 void addPoint(uint x,uint y)
48 Points[y]|=(1<<x);
51 void displayPoints()
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))? ' ': '#';
59 nlinfo("- %s",txt);
64 sint16 Points[16]; // boolean map of surface shape
65 uint8 XNeighbours[16][16];
66 uint8 YNeighbours[16][16];
67 std::vector<CNeighbour> Neighbours;
70 class CCell
72 public:
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;
80 uint i,j;
82 // fill the points grid with -1 where accessible and -2 where inaccessible
83 uint goodCount=0, badCount=0;
84 for (j=0;j<16;++j)
85 for (i=0;i<16;++i)
86 if (*(topLeft+i+lineLen*j)==' ')
88 cell.Points[j][i]= -1;
89 ++goodCount;
91 else
93 cell.Points[j][i]= -2;
94 ++badCount;
97 // flood fill to convert -1s to surface ids
98 uint surfaceCount=~0u;
99 for (j=0;j<16;++j)
100 for (i=0;i<16;++i)
101 if (cell.Points[j][i]==-1)
103 CSurface *surface=new CSurface;
104 cell.Surfaces.push_back(surface);
105 ++surfaceCount;
106 cell.Points[j][i]=surfaceCount;
107 stack.push(16*j+i);
108 while (!stack.empty())
110 // pop the coordinate off the stack
111 uint x=stack.top()&0xf;
112 uint y=stack.top()/16;
113 stack.pop();
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);
127 for (j=0;j<16;++j)
129 char txt[17];
130 for (i=0;i<16;++i)
131 txt[i]=(cell.Points[j][i]>=0 && cell.Points[j][i]<=9)? cell.Points[j][i]+'0': '#';
132 txt[16]=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","")
154 if(args.size()!=0)
155 return false;
157 char testMap[]=
158 "0000000000000000111111111111111100000000000000001111111111111111"
159 "0000000000000000111111111111111100000000000000001111111111111111"
160 "0000000000000000111111111111111100000000000000001111111111111111"
161 "000 111000 111"
162 "000 111"
163 "000 111000 111"
164 "000 00000000001111111111 111000 00000000001111111111 111"
165 "000 1 111000 1 111"
166 "000 1 111000 1 111"
167 "000 1 111000 1 111"
168 "000 1 111000 1 111"
169 "000 1 111000 1 111"
170 "000 1 111000 1 111"
171 "000 1 111000 1 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"
176 "222 3 333222 3 333"
177 "222 3 3 333"
178 "222 2222222222223333333333 333222 2222222222223333333333 333"
179 "22222 33322222 333"
180 "222 333222 333"
181 "222 333222 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"
193 "000 11000 111"
194 "000 1000 111"
195 "000 1 000 111"
196 "000 00000000001111111111 11 00 00000000001111111111 111"
197 "000 1 111 0 1 111"
198 "000 1 1110 1 111"
199 "000 1 11100 1 111"
200 "000 1 111000 1 111"
201 "000 1 111000 1 111"
202 "000 1 111000 1 111"
203 "000 1 111000 1 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"
208 "222 3 333222 3 333"
209 "222 3 333222 3 333"
210 "222 2222222222223333333333 333222 2222222222223333333333 333"
211 "22222 33322222 333"
212 "222 333222 333"
213 "222 333222 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";
224 int i,j;
226 // need to create a dummy cell that links into the cell grid in all slots as
227 // default value
228 // *** here ***
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));
234 for (j=0;j<4;++j)
235 for (i=0;i<4;++i)
236 cells[j+1][i+1]=new CCell;
238 // generate surfaces
239 for (j=0;j<4;++j)
240 for (i=0;i<4;++i)
241 generateSurfaces(testMap+i*16+j*64*16,64,*cells[j+1][i+1]);
243 // generate surface neighbourhoods
244 for (j=0;j<4;++j)
245 for (i=0;i<4;++i)
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]
252 return true;