Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
PathGenerator.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include <iostream>
7
#include <thread>
8
9
#ifdef _WIN32
10
#include "direct.h"
11
#else
12
#include <sys/stat.h>
13
#endif
14
15
#include "
PathCommon.h
"
16
#include "
MapBuilder.h
"
17
18
using namespace
MMAP
;
19
20
void
CreateDir
(std::string
const
& path)
21
{
22
#ifdef _WIN32
23
_mkdir(path.c_str());
24
#else
25
mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
// 0777
26
#endif
27
}
28
29
bool
checkDirectories
(
bool
debugOutput)
30
{
31
std::vector<std::string> dirFiles;
32
33
if
(
getDirContents
(dirFiles,
"maps"
) ==
LISTFILE_DIRECTORY_NOT_FOUND
|| dirFiles.empty())
34
{
35
printf(
"'maps' directory is empty or does not exist\n"
);
36
return
false
;
37
}
38
39
dirFiles.clear();
40
if
(
getDirContents
(dirFiles,
"vmaps"
,
"*.vmtree"
) ==
LISTFILE_DIRECTORY_NOT_FOUND
|| dirFiles.empty())
41
{
42
printf(
"'vmaps' directory is empty or does not exist\n"
);
43
return
false
;
44
}
45
46
dirFiles.clear();
47
if
(
getDirContents
(dirFiles,
"mmaps"
) ==
LISTFILE_DIRECTORY_NOT_FOUND
)
48
{
49
CreateDir
(
"./mmaps/"
);
50
51
dirFiles.clear();
52
if
(
getDirContents
(dirFiles,
"mmaps"
) ==
LISTFILE_DIRECTORY_NOT_FOUND
)
53
{
54
printf(
"'mmaps' directory does not exist and could not be created\n"
);
55
return
false
;
56
}
57
}
58
59
dirFiles.clear();
60
if
(debugOutput)
61
{
62
if
(
getDirContents
(dirFiles,
"meshes"
) ==
LISTFILE_DIRECTORY_NOT_FOUND
)
63
{
64
printf(
"'meshes' directory does not exist (no place to put debugOutput files)\n"
);
65
return
false
;
66
}
67
}
68
69
return
true
;
70
}
71
72
bool
handleArgs
(
int
argc,
char
** argv,
73
int
&mapnum,
74
int
&tileX,
75
int
&tileY,
76
float
&maxAngle,
77
bool
&skipLiquid,
78
bool
&skipContinents,
79
bool
&skipJunkMaps,
80
bool
&skipBattlegrounds,
81
bool
&debugOutput,
82
bool
&silent,
83
bool
&bigBaseUnit,
84
char
* &offMeshInputPath,
85
char
* &file,
86
unsigned
int
& threads)
87
{
88
char
* param = NULL;
89
for
(
int
i = 1; i < argc; ++i)
90
{
91
if
(strcmp(argv[i],
"--maxAngle"
) == 0)
92
{
93
param = argv[++i];
94
if
(!param)
95
return
false
;
96
97
float
maxangle = atof(param);
98
if
(maxangle <= 90.f && maxangle >= 45.f)
99
maxAngle = maxangle;
100
else
101
printf(
"invalid option for '--maxAngle', using default\n"
);
102
}
103
else
if
(strcmp(argv[i],
"--threads"
) == 0)
104
{
105
param = argv[++i];
106
if
(!param)
107
return
false
;
108
threads =
static_cast<
unsigned
int
>
(std::max(0, atoi(param)));
109
}
110
else
if
(strcmp(argv[i],
"--file"
) == 0)
111
{
112
param = argv[++i];
113
if
(!param)
114
return
false
;
115
file = param;
116
}
117
else
if
(strcmp(argv[i],
"--tile"
) == 0)
118
{
119
param = argv[++i];
120
if
(!param)
121
return
false
;
122
123
char
* stileX = strtok(param,
","
);
124
char
* stileY = strtok(NULL,
","
);
125
int
tilex = atoi(stileX);
126
int
tiley = atoi(stileY);
127
128
if
((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX,
"0"
) == 0))
129
tileX = tilex;
130
if
((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY,
"0"
) == 0))
131
tileY = tiley;
132
133
if
(tileX < 0 || tileY < 0)
134
{
135
printf(
"invalid tile coords.\n"
);
136
return
false
;
137
}
138
}
139
else
if
(strcmp(argv[i],
"--skipLiquid"
) == 0)
140
{
141
param = argv[++i];
142
if
(!param)
143
return
false
;
144
145
if
(strcmp(param,
"true"
) == 0)
146
skipLiquid =
true
;
147
else
if
(strcmp(param,
"false"
) == 0)
148
skipLiquid =
false
;
149
else
150
printf(
"invalid option for '--skipLiquid', using default\n"
);
151
}
152
else
if
(strcmp(argv[i],
"--skipContinents"
) == 0)
153
{
154
param = argv[++i];
155
if
(!param)
156
return
false
;
157
158
if
(strcmp(param,
"true"
) == 0)
159
skipContinents =
true
;
160
else
if
(strcmp(param,
"false"
) == 0)
161
skipContinents =
false
;
162
else
163
printf(
"invalid option for '--skipContinents', using default\n"
);
164
}
165
else
if
(strcmp(argv[i],
"--skipJunkMaps"
) == 0)
166
{
167
param = argv[++i];
168
if
(!param)
169
return
false
;
170
171
if
(strcmp(param,
"true"
) == 0)
172
skipJunkMaps =
true
;
173
else
if
(strcmp(param,
"false"
) == 0)
174
skipJunkMaps =
false
;
175
else
176
printf(
"invalid option for '--skipJunkMaps', using default\n"
);
177
}
178
else
if
(strcmp(argv[i],
"--skipBattlegrounds"
) == 0)
179
{
180
param = argv[++i];
181
if
(!param)
182
return
false
;
183
184
if
(strcmp(param,
"true"
) == 0)
185
skipBattlegrounds =
true
;
186
else
if
(strcmp(param,
"false"
) == 0)
187
skipBattlegrounds =
false
;
188
else
189
printf(
"invalid option for '--skipBattlegrounds', using default\n"
);
190
}
191
else
if
(strcmp(argv[i],
"--debugOutput"
) == 0)
192
{
193
param = argv[++i];
194
if
(!param)
195
return
false
;
196
197
if
(strcmp(param,
"true"
) == 0)
198
debugOutput =
true
;
199
else
if
(strcmp(param,
"false"
) == 0)
200
debugOutput =
false
;
201
else
202
printf(
"invalid option for '--debugOutput', using default true\n"
);
203
}
204
else
if
(strcmp(argv[i],
"--silent"
) == 0)
205
{
206
silent =
true
;
207
}
208
else
if
(strcmp(argv[i],
"--bigBaseUnit"
) == 0)
209
{
210
param = argv[++i];
211
if
(!param)
212
return
false
;
213
214
if
(strcmp(param,
"true"
) == 0)
215
bigBaseUnit =
true
;
216
else
if
(strcmp(param,
"false"
) == 0)
217
bigBaseUnit =
false
;
218
else
219
printf(
"invalid option for '--bigBaseUnit', using default false\n"
);
220
}
221
else
if
(strcmp(argv[i],
"--offMeshInput"
) == 0)
222
{
223
param = argv[++i];
224
if
(!param)
225
return
false
;
226
227
offMeshInputPath = param;
228
}
229
else
230
{
231
int
map = atoi(argv[i]);
232
if
(map > 0 || (map == 0 && (strcmp(argv[i],
"0"
) == 0)))
233
mapnum = map;
234
else
235
{
236
printf(
"invalid map id\n"
);
237
return
false
;
238
}
239
}
240
}
241
242
return
true
;
243
}
244
245
int
finish
(
const
char
* message,
int
returnValue)
246
{
247
printf(
"%s"
, message);
248
getchar();
249
return
returnValue;
250
}
251
252
int
main
(
int
argc,
char
** argv)
253
{
254
unsigned
int
threads = std::thread::hardware_concurrency();
255
int
mapnum = -1;
256
float
maxAngle = 55.0f;
257
int
tileX = -1, tileY = -1;
258
bool
skipLiquid =
false
,
259
skipContinents =
false
,
260
skipJunkMaps =
true
,
261
skipBattlegrounds =
false
,
262
debugOutput =
false
,
263
silent =
false
,
264
bigBaseUnit =
false
;
265
char
* offMeshInputPath = NULL;
266
char
* file = NULL;
267
268
bool
validParam =
handleArgs
(argc, argv, mapnum,
269
tileX, tileY, maxAngle,
270
skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
271
debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
272
273
if
(!validParam)
274
return
silent ? -1 :
finish
(
"You have specified invalid parameters"
, -1);
275
276
if
(mapnum == -1 && debugOutput)
277
{
278
if
(silent)
279
return
-2;
280
281
printf(
"You have specifed debug output, but didn't specify a map to generate.\n"
);
282
printf(
"This will generate debug output for ALL maps.\n"
);
283
printf(
"Are you sure you want to continue? (y/n) "
);
284
if
(getchar() !=
'y'
)
285
return
0;
286
}
287
288
if
(!
checkDirectories
(debugOutput))
289
return
silent ? -3 :
finish
(
"Press ENTER to close..."
, -3);
290
291
MapBuilder
builder(maxAngle, skipLiquid, skipContinents, skipJunkMaps,
292
skipBattlegrounds, debugOutput, bigBaseUnit, offMeshInputPath);
293
294
uint32
start =
getMSTime
();
295
if
(file)
296
builder.
buildMeshFromFile
(file);
297
else
if
(tileX > -1 && tileY > -1 && mapnum >= 0)
298
builder.
buildSingleTile
(mapnum, tileX, tileY);
299
else
if
(mapnum >= 0)
300
builder.
buildMap
(
uint32
(mapnum));
301
else
302
builder.
buildAllMaps
(threads);
303
304
if
(!silent)
305
printf(
"Finished. MMAPS were built in %u ms!\n"
,
GetMSTimeDiffToNow
(start));
306
return
0;
307
}
uint32
std::uint32_t uint32
Definition
Define.h:77
MapBuilder.h
PathCommon.h
MMAP::MapBuilder
Definition
MapBuilder.h:44
MMAP::MapBuilder::buildMeshFromFile
void buildMeshFromFile(char *name)
Definition
MapBuilder.cpp:235
MMAP::MapBuilder::buildMap
void buildMap(uint32 mapID)
Definition
MapBuilder.cpp:309
MMAP::MapBuilder::buildAllMaps
void buildAllMaps(unsigned int threads)
Definition
MapBuilder.cpp:159
MMAP::MapBuilder::buildSingleTile
void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY)
Definition
MapBuilder.cpp:294
MMAP
Definition
MMapFactory.cpp:12
MMAP::LISTFILE_DIRECTORY_NOT_FOUND
@ LISTFILE_DIRECTORY_NOT_FOUND
Definition
PathCommon.h:79
MMAP::getDirContents
ListFilesResult getDirContents(std::vector< std::string > &fileList, std::string dirpath=".", std::string filter="*")
Definition
PathCommon.h:83
MMAP::getMSTime
uint32 getMSTime()
Definition
PathCommon.h:132
MMAP::GetMSTimeDiffToNow
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition
PathCommon.h:148
finish
int finish(const char *message, int returnValue)
Definition
PathGenerator.cpp:245
main
int main(int argc, char **argv)
Definition
PathGenerator.cpp:252
CreateDir
void CreateDir(std::string const &path)
Definition
PathGenerator.cpp:20
handleArgs
bool handleArgs(int argc, char **argv, int &mapnum, int &tileX, int &tileY, float &maxAngle, bool &skipLiquid, bool &skipContinents, bool &skipJunkMaps, bool &skipBattlegrounds, bool &debugOutput, bool &silent, bool &bigBaseUnit, char *&offMeshInputPath, char *&file, unsigned int &threads)
Definition
PathGenerator.cpp:72
checkDirectories
bool checkDirectories(bool debugOutput)
Definition
PathGenerator.cpp:29
src
tools
mmaps_generator
PathGenerator.cpp
Generated on
for Project SkyFire Core by
1.17.0