[6870] Not output error message at loading empty `db_script_string` table.
[getmangos.git] / contrib / vmap_assembler / vmap_assembler.cpp
blob233d4ba3c2875c6d840a2ba489cce3c70bed3a4c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string>
5 #include "TileAssembler.h"
7 //=======================================================
8 // remove last return or LF and tailing SPACE
9 // remove all char after a #
11 void chompAndTrim(std::string& str)
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;
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;
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
36 bool modelNameFilter(char *pName)
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);
47 #endif
48 return true;
51 //=======================================================
52 /**
53 File contains map names that should be split into tiles
54 A '#' at the beginning of a line defines a comment
57 bool readConfigFile(char *pConffile, VMAP::TileAssembler* pTa)
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);
73 fclose(cf);
74 result = true;
76 return(result);
78 //=======================================================
79 int main(int argc, char* argv[])
81 if(argc == 3 || argc == 4)
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];
90 VMAP::TileAssembler* ta = new VMAP::TileAssembler(std::string(src), std::string(dest));
91 ta->setModelNameFilterMethod(modelNameFilter);
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
97 if(conffile != NULL) {
98 ok = readConfigFile(conffile, ta);
99 if(!ok) {
100 printf("Can not open file config file: %s\n", conffile);
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;
110 delete ta;
112 else
114 printf("\nusage: %s <raw data dir> <vmap dest dir> [config file name]\n", argv[0]);
115 return 1;
117 return 0;