277 lines
6.5 KiB
C
277 lines
6.5 KiB
C
/*
|
|
* PVVMUD a 3D MUD
|
|
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
*/
|
|
#include <sys/param.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <iostream.h>
|
|
|
|
#include "pvvmud.H"
|
|
#include "geometry.H"
|
|
#include "namedb.H"
|
|
#include "crossindex.H"
|
|
#include "remapgeometry.H"
|
|
#include "exception.H"
|
|
|
|
void remapGeometry(FILE * goscfgFile,char * gosDBPath, CNameDB * gosbogndb, CNameDB * gosmatndb);
|
|
void remapMaterial(char * gosDBPath, CNameDB * gosmatndb, CNameDB * gostexndb);
|
|
void remapTexture(char * gosDBPath, CNameDB * gostexndb);
|
|
|
|
int main(int argc, char * argv[]){
|
|
char goscfgName[MAXPATHLEN];
|
|
FILE * goscfgFile;
|
|
char gosDBPath[MAXPATHLEN];
|
|
char outName[MAXPATHLEN];
|
|
CNameDB *gosbogndb,*gosmatndb,*gostexndb;
|
|
|
|
// Parse arguments
|
|
|
|
if (argc != 2) {
|
|
cerr << "usage: " << argv[0] << " <gos_cfg>\n";
|
|
exit(1);
|
|
}
|
|
|
|
strcpy(goscfgName,argv[1]);
|
|
goscfgFile = fopen(goscfgName,"r");
|
|
if (goscfgFile == NULL){
|
|
cerr << "Faild to open config file: " << goscfgName << endl;
|
|
exit(1);
|
|
}
|
|
cout << "Config file: " << goscfgName << endl;
|
|
|
|
// Load gos DB path from config file
|
|
|
|
if (fscanf(goscfgFile,"%s\n",gosDBPath)!= 1){
|
|
cerr << "Faild to locate GOS DB path" << endl;
|
|
exit(1);
|
|
}
|
|
cout << "GOS DB path: " << gosDBPath << endl;
|
|
|
|
// Prepare namedbs
|
|
|
|
gosbogndb = new CNameDB();
|
|
gosmatndb = new CNameDB();
|
|
gostexndb = new CNameDB();
|
|
|
|
// Do the stuff
|
|
|
|
cout << "Process geometries" << endl;
|
|
remapGeometry(goscfgFile,gosDBPath,gosbogndb,gosmatndb);
|
|
cout << "Process materials" << endl;
|
|
remapMaterial(gosDBPath,gosmatndb,gostexndb);
|
|
cout << "Process textures" << endl;
|
|
remapTexture(gosDBPath,gostexndb);
|
|
|
|
// Save namedbs
|
|
|
|
sprintf(outName,"%sgosbog.ndb",gosDBPath);
|
|
cout << "Writing: " << outName << endl;
|
|
gosbogndb->save(outName);
|
|
|
|
sprintf(outName,"%sgosmat.ndb",gosDBPath);
|
|
cout << "Writing: " << outName << endl;
|
|
gosmatndb->save(outName);
|
|
|
|
sprintf(outName,"%sgostex.ndb",gosDBPath);
|
|
cout << "Writing: " << outName << endl;
|
|
gostexndb->save(outName);
|
|
|
|
// Clean up files and memory
|
|
|
|
fclose(goscfgFile);
|
|
delete gosbogndb;
|
|
delete gosmatndb;
|
|
|
|
}
|
|
|
|
void remapGeometry(FILE * goscfgFile, char * gosDBPath,
|
|
CNameDB * gosbogndb, CNameDB * gosmatndb){
|
|
CNameDB *ndb;
|
|
char cfgName[MAXPATHLEN];
|
|
char bogName[MAXPATHLEN];
|
|
char ndbName[MAXPATHLEN];
|
|
char outName[MAXPATHLEN];
|
|
|
|
CCrossIndex * crossIndex;
|
|
CRemapGeometry * objgeo;
|
|
int bogid;
|
|
|
|
while (fscanf(goscfgFile,"%s\n",cfgName)==1){
|
|
|
|
bogid = gosbogndb->insert(cfgName);
|
|
|
|
// Create fileNames
|
|
strcpy(bogName,cfgName); strcat(bogName,".bog");
|
|
strcpy(ndbName,cfgName); strcat(ndbName,".ndb");
|
|
|
|
cout << "Loading: " << bogName << flush;
|
|
|
|
// Load data
|
|
try {
|
|
|
|
// Load geometry
|
|
objgeo = new CRemapGeometry(bogid);
|
|
objgeo->load(bogName);
|
|
|
|
// Load name db
|
|
cout << ", reading ndb" << flush;
|
|
ndb = new CNameDB();
|
|
ndb->load(ndbName);
|
|
|
|
} catch (CException *e){
|
|
delete e;
|
|
cout << " FAILED!" << endl;
|
|
continue; // Failed continue with next file
|
|
}
|
|
|
|
crossIndex = gosmatndb->merge(ndb);
|
|
|
|
cout << ", remapping" << flush;
|
|
objgeo->remapMaterialIDs( crossIndex );
|
|
delete crossIndex;
|
|
|
|
// Write geometry
|
|
sprintf(outName,"%s%i.bog",gosDBPath,bogid);
|
|
cout << ", saveing: " << outName << flush ;
|
|
objgeo->save( outName );
|
|
|
|
// Clean up memory
|
|
delete ndb;
|
|
delete objgeo;
|
|
|
|
cout << ", done." << endl ;
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
void remapMaterial(char * gosDBPath, CNameDB * gosmatndb, CNameDB * gostexndb){
|
|
char matName[MAXPATHLEN];
|
|
char matndbName[MAXPATHLEN];
|
|
char outName[MAXPATHLEN];
|
|
CRemapMaterial * mat;
|
|
CNameDB * ndb;
|
|
CNameDBItem * item;
|
|
CCrossIndex * crossIndex;
|
|
|
|
item = gosmatndb->getFirst();
|
|
while (item != NULL){
|
|
|
|
// Create fileNames
|
|
strcpy(matName,item->getName()); strcat(matName,".bmat");
|
|
strcpy(matndbName,item->getName()); strcat(matndbName,".ndb");
|
|
|
|
cout << "Loading: " << matName << flush;
|
|
|
|
try {
|
|
|
|
// Load material
|
|
mat = new CRemapMaterial();
|
|
mat->load(matName);
|
|
|
|
} catch (CException *e){
|
|
delete e;
|
|
cout << " FAILED!" << endl;
|
|
item = item->getNext();
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
|
|
// Load name db
|
|
cout << ", reading ndb" << flush;
|
|
ndb = new CNameDB();
|
|
ndb->load(matndbName);
|
|
|
|
} catch (CException *e){
|
|
delete e;
|
|
cout << " FAILED" << flush;
|
|
ndb = NULL;
|
|
}
|
|
|
|
// Create crossindex and remap
|
|
if (ndb != NULL){
|
|
cout << ", remapping" << flush;
|
|
crossIndex = gostexndb->merge(ndb);
|
|
mat->remapTextureIDs( crossIndex );
|
|
delete crossIndex;
|
|
}
|
|
|
|
sprintf(outName,"%s%i.bmat",gosDBPath,item->getId());
|
|
cout << ", saveing " << outName << flush;
|
|
mat->save( outName );
|
|
|
|
// Clean up memory
|
|
if (ndb != NULL) delete ndb;
|
|
delete mat;
|
|
|
|
cout << ", done" << endl ;
|
|
|
|
item = item->getNext();
|
|
}
|
|
}
|
|
|
|
void remapTexture(char * gosDBPath, CNameDB * gostexndb){
|
|
char texName[MAXPATHLEN];
|
|
char outName[MAXPATHLEN];
|
|
CTexture * tex;
|
|
CNameDBItem * item;
|
|
|
|
item = gostexndb->getFirst();
|
|
while (item != NULL){
|
|
|
|
// Create fileNames
|
|
strcpy(texName,item->getName()); strcat(texName,".tex");
|
|
|
|
cout << "Loading: " << texName << flush;
|
|
|
|
// Load texture
|
|
tex = new CTexture();
|
|
try {
|
|
tex->load(texName);
|
|
} catch (CException *e){
|
|
delete e;
|
|
cout << " FAILED!" << endl;
|
|
item = item->getNext();
|
|
delete tex;
|
|
continue;
|
|
}
|
|
|
|
sprintf(outName,"%s%i.tex",gosDBPath,item->getId());
|
|
cout << ", saveing " << outName << flush;
|
|
|
|
try {
|
|
tex->save( outName );
|
|
} catch (CException *e){
|
|
delete e;
|
|
cout << " FAILED!" << endl;
|
|
item = item->getNext();
|
|
delete tex;
|
|
continue;
|
|
}
|
|
|
|
// Clean up memory
|
|
delete tex;
|
|
|
|
cout << ", done" << endl;
|
|
|
|
item = item->getNext();
|
|
}
|
|
}
|