1 | #include <stdlib.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include <string> |
---|
4 | |
---|
5 | #include "TileAssembler.h" |
---|
6 | |
---|
7 | //======================================================= |
---|
8 | // remove last return or LF and tailing SPACE |
---|
9 | // remove all char after a # |
---|
10 | |
---|
11 | void chompAndTrim(std::string& str) |
---|
12 | { |
---|
13 | for(unsigned int i=0;i<str.length(); ++i) { |
---|
14 | char lc = str[i]; |
---|
15 | if(lc == '#') { |
---|
16 | str = str.substr(0,i); |
---|
17 | break; |
---|
18 | } |
---|
19 | } |
---|
20 | |
---|
21 | while(str.length() >0) { |
---|
22 | char lc = str[str.length()-1]; |
---|
23 | if(lc == '\r' || lc == '\n' || lc == ' ') { |
---|
24 | str = str.substr(0,str.length()-1); |
---|
25 | } else { |
---|
26 | break; |
---|
27 | } |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | //======================================================= |
---|
32 | /** |
---|
33 | This callback method is called for each model found in the dir file. |
---|
34 | return true if it should be included in the vmap |
---|
35 | */ |
---|
36 | bool modelNameFilter(char *pName) |
---|
37 | { |
---|
38 | #if 0 |
---|
39 | bool result; |
---|
40 | result = !Wildcard::wildcardfit("*bush[0-9]*", pName); |
---|
41 | if(result) result = !Wildcard::wildcardfit("*shrub[0-9]*", pName); |
---|
42 | if(result) result = !Wildcard::wildcardfit("*_Bushes_*", pName); |
---|
43 | if(result) result = !Wildcard::wildcardfit("*_Bush_*", pName); |
---|
44 | if(!result) { |
---|
45 | printf("%s",pName); |
---|
46 | } |
---|
47 | #endif |
---|
48 | return true; |
---|
49 | } |
---|
50 | |
---|
51 | //======================================================= |
---|
52 | /** |
---|
53 | File contains map names that should be split into tiles |
---|
54 | A '#' at the beginning of a line defines a comment |
---|
55 | */ |
---|
56 | |
---|
57 | bool readConfigFile(char *pConffile, VMAP::TileAssembler* pTa) |
---|
58 | { |
---|
59 | bool result = false; |
---|
60 | char buffer[501]; |
---|
61 | FILE *cf = fopen(pConffile, "rb"); |
---|
62 | if(cf) { |
---|
63 | while(fgets(buffer, 500, cf)) { |
---|
64 | std::string name = std::string(buffer); |
---|
65 | size_t pos = name.find_first_not_of(' '); |
---|
66 | name = name.substr(pos); |
---|
67 | chompAndTrim(name); // just to be sure |
---|
68 | if(name[0] != '#' && name.size() >0) { // comment? |
---|
69 | unsigned int mapId = atoi(name.c_str()); |
---|
70 | pTa->addWorldAreaMapId(mapId); |
---|
71 | } |
---|
72 | } |
---|
73 | fclose(cf); |
---|
74 | result = true; |
---|
75 | } |
---|
76 | return(result); |
---|
77 | } |
---|
78 | //======================================================= |
---|
79 | int main(int argc, char* argv[]) |
---|
80 | { |
---|
81 | if(argc == 3 || argc == 4) |
---|
82 | { |
---|
83 | bool ok = true; |
---|
84 | char *src = argv[1]; |
---|
85 | char *dest = argv[2]; |
---|
86 | char *conffile = NULL; |
---|
87 | if(argc >= 4) { |
---|
88 | conffile = argv[3]; |
---|
89 | } |
---|
90 | VMAP::TileAssembler* ta = new VMAP::TileAssembler(std::string(src), std::string(dest)); |
---|
91 | ta->setModelNameFilterMethod(modelNameFilter); |
---|
92 | |
---|
93 | /* |
---|
94 | All the names in the list are considered to be world maps or huge instances. |
---|
95 | These maps will be spilt into tiles in the vmap assemble process |
---|
96 | */ |
---|
97 | if(conffile != NULL) { |
---|
98 | ok = readConfigFile(conffile, ta); |
---|
99 | if(!ok) { |
---|
100 | printf("Can not open file config file: %s\n", conffile); |
---|
101 | } |
---|
102 | } |
---|
103 | if(ok) { ok = ta->convertWorld(); } |
---|
104 | if(ok) { |
---|
105 | printf("Ok, all done\n"); |
---|
106 | } else { |
---|
107 | printf("exit with errors\n"); |
---|
108 | return 1; |
---|
109 | } |
---|
110 | delete ta; |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | printf("\nusage: %s <raw data dir> <vmap dest dir> [config file name]\n", argv[0]); |
---|
115 | return 1; |
---|
116 | } |
---|
117 | return 0; |
---|
118 | } |
---|