- added new commandline option to convert folders of g3d models to use specified texture format

- added new utility methods and changed code to use them (like adding trailing slash on paths)
This commit is contained in:
Mark Vejvoda 2011-03-13 08:23:43 +00:00
parent f35e920d47
commit 39bf1b986e
32 changed files with 529 additions and 308 deletions

View File

@ -770,9 +770,7 @@ void MainWindow::saveScreenshot() {
//string screenShotsPath = extractDirectoryPathFromFile(appPath) + string("screens/"); //string screenShotsPath = extractDirectoryPathFromFile(appPath) + string("screens/");
string userData = Config::getInstance().getString("UserData_Root",""); string userData = Config::getInstance().getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
string screenShotsPath = userData + string("screens/"); string screenShotsPath = userData + string("screens/");
printf("screenShotsPath [%s]\n",screenShotsPath.c_str()); printf("screenShotsPath [%s]\n",screenShotsPath.c_str());

View File

@ -43,9 +43,7 @@ Logger::Logger() {
else { else {
string userData = Config::getInstance().getString("UserData_Root",""); string userData = Config::getInstance().getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
fileName= userData + "log.txt"; fileName= userData + "log.txt";
} }

View File

@ -231,7 +231,6 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
vector<string> loadScreenList; vector<string> loadScreenList;
findAll(scenarioDir + factionLogoFilter, loadScreenList, false, false); findAll(scenarioDir + factionLogoFilter, loadScreenList, false, false);
if(loadScreenList.size() > 0) { if(loadScreenList.size() > 0) {
//string senarioLogo = scenarioDir + "/" + "loading_screen.jpg";
string senarioLogo = scenarioDir + loadScreenList[0]; string senarioLogo = scenarioDir + loadScreenList[0];
if(fileExists(senarioLogo) == true) { if(fileExists(senarioLogo) == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found scenario loading screen '%s'\n",__FILE__,__FUNCTION__,senarioLogo.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found scenario loading screen '%s'\n",__FILE__,__FUNCTION__,senarioLogo.c_str());
@ -291,15 +290,17 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
else { else {
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir); vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
const string path = pathList[idx]+ "/" +techName+ "/"+ "factions"+ "/"+ settings->getFactionTypeName(i); string currentPath = pathList[idx];
endPathWithSlash(currentPath);
string path = currentPath + techName + "/" + "factions" + "/" + settings->getFactionTypeName(i);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
vector<string> loadScreenList; endPathWithSlash(path);
findAll(path + "/" + factionLogoFilter, loadScreenList, false, false);
if(loadScreenList.size() > 0) {
//string factionLogo = path + "/" + "loading_screen.jpg";
string factionLogo = path + "/" + loadScreenList[0];
vector<string> loadScreenList;
findAll(path + factionLogoFilter, loadScreenList, false, false);
if(loadScreenList.size() > 0) {
string factionLogo = path + loadScreenList[0];
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
if(fileExists(factionLogo) == true) { if(fileExists(factionLogo) == true) {
@ -330,15 +331,17 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir); vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
const string path = pathList[idx]+ "/" +techName; string currentPath = pathList[idx];
endPathWithSlash(currentPath);
string path = currentPath + techName;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
vector<string> loadScreenList; endPathWithSlash(path);
findAll(path + "/" + factionLogoFilter, loadScreenList, false, false);
if(loadScreenList.size() > 0) {
//string factionLogo = path + "/" + "loading_screen.jpg";
string factionLogo = path + "/" + loadScreenList[0];
vector<string> loadScreenList;
findAll(path + factionLogoFilter, loadScreenList, false, false);
if(loadScreenList.size() > 0) {
string factionLogo = path + loadScreenList[0];
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
if(fileExists(factionLogo) == true) { if(fileExists(factionLogo) == true) {

View File

@ -114,22 +114,37 @@ Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> f
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
string userData = "";
if(cfgType.first == cfgMainGame) { if(cfgType.first == cfgMainGame) {
if( properties.first.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { if( properties.first.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
fileName.second = properties.first.getString("UserData_Root") + fileNameParameter.second; string userData = properties.first.getString("UserData_Root");
if(userData != "") {
endPathWithSlash(userData);
}
fileName.second = userData + fileNameParameter.second;
} }
else if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { else if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
fileName.second = properties.first.getString("UserOverrideFile") + fileNameParameter.second; string userData = properties.first.getString("UserOverrideFile");
if(userData != "") {
endPathWithSlash(userData);
}
fileName.second = userData + fileNameParameter.second;
} }
} }
else if(cfgType.first == cfgMainKeys) { else if(cfgType.first == cfgMainKeys) {
Config &mainCfg = Config::getInstance(); Config &mainCfg = Config::getInstance();
if( mainCfg.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { if( mainCfg.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
fileName.second = mainCfg.getString("UserData_Root") + fileNameParameter.second; string userData = mainCfg.getString("UserData_Root");
if(userData != "") {
endPathWithSlash(userData);
}
fileName.second = userData + fileNameParameter.second;
} }
else if(mainCfg.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { else if(mainCfg.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
fileName.second = mainCfg.getString("UserOverrideFile") + fileNameParameter.second; string userData = mainCfg.getString("UserOverrideFile");
if(userData != "") {
endPathWithSlash(userData);
}
fileName.second = userData + fileNameParameter.second;
} }
} }

View File

@ -45,7 +45,9 @@ void Lang::loadStrings(const string &language){
void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenarioName){ void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenarioName){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scenarioDir = [%s] scenarioName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioDir.c_str(),scenarioName.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scenarioDir = [%s] scenarioName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioDir.c_str(),scenarioName.c_str());
string scenarioFolder = scenarioDir + "/" + scenarioName + "/"; string currentPath = scenarioDir;
endPathWithSlash(currentPath);
string scenarioFolder = currentPath + scenarioName + "/";
string path = scenarioFolder + scenarioName + "_" + language + ".lng"; string path = scenarioFolder + scenarioName + "_" + language + ".lng";
if(EndsWith(scenarioDir, ".xml") == true) { if(EndsWith(scenarioDir, ".xml") == true) {
scenarioFolder = extractDirectoryPathFromFile(scenarioDir); scenarioFolder = extractDirectoryPathFromFile(scenarioDir);

View File

@ -18,11 +18,13 @@
#include "config.h" #include "config.h"
#include "game_constants.h" #include "game_constants.h"
#include "util.h" #include "util.h"
#include "platform_common.h"
#include "leak_dumper.h" #include "leak_dumper.h"
using namespace Shared::Xml; using namespace Shared::Xml;
using namespace Shared::Graphics; using namespace Shared::Graphics;
using namespace Shared::Util; using namespace Shared::Util;
using namespace Shared::PlatformCommon;
namespace Glest{ namespace Game{ namespace Glest{ namespace Game{
@ -51,7 +53,9 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
else{ else{
texture->getPixmap()->init(4); texture->getPixmap()->init(4);
} }
texture->load(dir + "/" + textureNode->getAttribute("path")->getRestrictedValue()); string currentPath = dir;
endPathWithSlash(currentPath);
texture->load(currentPath + textureNode->getAttribute("path")->getRestrictedValue());
} }
else { else {
texture= NULL; texture= NULL;
@ -65,7 +69,10 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
string path= modelNode->getAttribute("path")->getRestrictedValue(); string path= modelNode->getAttribute("path")->getRestrictedValue();
model= renderer->newModel(rsGame); model= renderer->newModel(rsGame);
model->load(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
model->load(currentPath + path);
} }
} }
else{ else{

View File

@ -37,6 +37,7 @@
#include "FileReader.h" #include "FileReader.h"
#include "cache_manager.h" #include "cache_manager.h"
#include <iterator> #include <iterator>
#include "core_data.h"
// For gcc backtrace on crash! // For gcc backtrace on crash!
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD) #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
@ -99,7 +100,8 @@ const char *GAME_ARGS[] = {
"--ini-path", "--ini-path",
"--log-path", "--log-path",
"--show-ini-settings", "--show-ini-settings",
"--convert-model", "--convert-models",
"--convert-textures",
"--disable-backtrace", "--disable-backtrace",
"--disable-vbo", "--disable-vbo",
"--verbose" "--verbose"
@ -123,7 +125,8 @@ enum GAME_ARG_TYPE {
GAME_ARG_INI_PATH, GAME_ARG_INI_PATH,
GAME_ARG_LOG_PATH, GAME_ARG_LOG_PATH,
GAME_ARG_SHOW_INI_SETTINGS, GAME_ARG_SHOW_INI_SETTINGS,
GAME_ARG_CONVERT_MODEL, GAME_ARG_CONVERT_MODELS,
GAME_ARG_CONVERT_TEXTURES,
GAME_ARG_DISABLE_BACKTRACE, GAME_ARG_DISABLE_BACKTRACE,
GAME_ARG_DISABLE_VBO, GAME_ARG_DISABLE_VBO,
GAME_ARG_VERBOSE_MODE GAME_ARG_VERBOSE_MODE
@ -697,9 +700,7 @@ void MainWindow::eventKeyDown(char key){
else if(key == configKeys.getCharKey("Screenshot")) { else if(key == configKeys.getCharKey("Screenshot")) {
string userData = Config::getInstance().getString("UserData_Root",""); string userData = Config::getInstance().getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
string path = userData + GameConstants::folder_path_screenshots; string path = userData + GameConstants::folder_path_screenshots;
@ -862,10 +863,15 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
printf("\n \t\tWhere x is an optional property name to filter (default shows all)."); printf("\n \t\tWhere x is an optional property name to filter (default shows all).");
printf("\n \t\texample: %s %s=DebugMode",argv0,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]); printf("\n \t\texample: %s %s=DebugMode",argv0,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
printf("\n%s=x=format\t\t\tconvert a model to current g3d format.",GAME_ARGS[GAME_ARG_CONVERT_MODEL]); printf("\n%s=x=textureformat\t\t\tconvert a model file or folder to the current g3d version format.",GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
printf("\n \t\tWhere x is the filename for the g3d model."); printf("\n \t\tWhere x is a filename or folder containing the g3d model(s).");
printf("\n \t\tWhere format is the optional texture format to convert to (default is png)."); printf("\n \t\tWhere textureformat is an optional supported texture format to convert to (tga,bmp,png).");
printf("\n \t\texample: %s %s=techs/megapack/factions/tech/units/castle/models/castle.g3d",argv0,GAME_ARGS[GAME_ARG_CONVERT_MODEL]); printf("\n \t\texample: %s %s=techs/megapack/factions/tech/units/castle/models/castle.g3d=png",argv0,GAME_ARGS[GAME_ARG_CONVERT_MODELS]);
printf("\n%s=x=textureformat\t\t\tconvert a texture file or folder to the format textureformat.",GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]);
printf("\n \t\tWhere x is a filename or folder containing the texture(s).");
printf("\n \t\tWhere textureformat is a supported texture format to convert to (tga,bmp,png).");
printf("\n \t\texample: %s %s=data/core/misc_textures/fire_particle.tga=png",argv0,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]);
printf("\n%s\t\tdisables stack backtrace on errors.",GAME_ARGS[GAME_ARG_DISABLE_BACKTRACE]); printf("\n%s\t\tdisables stack backtrace on errors.",GAME_ARGS[GAME_ARG_DISABLE_BACKTRACE]);
printf("\n%s\t\tdisables trying to use Vertex Buffer Objects.",GAME_ARGS[GAME_ARG_DISABLE_VBO]); printf("\n%s\t\tdisables trying to use Vertex Buffer Objects.",GAME_ARGS[GAME_ARG_DISABLE_VBO]);
@ -964,9 +970,7 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) {
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
string debugLogFile = config.getString("DebugLogFile",""); string debugLogFile = config.getString("DebugLogFile","");
@ -1154,6 +1158,8 @@ void runTechValidationReport(int argc, char** argv) {
vector<string> techPaths = config.getPathListForType(ptTechs); vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) { for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx]; string &techPath = techPaths[idx];
endPathWithSlash(techPath);
//printf("techPath [%s]\n",techPath.c_str()); //printf("techPath [%s]\n",techPath.c_str());
for(int idx2 = 0; idx2 < techTreeFiles.size(); idx2++) { for(int idx2 = 0; idx2 < techTreeFiles.size(); idx2++) {
@ -1163,7 +1169,7 @@ void runTechValidationReport(int argc, char** argv) {
std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) { std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) {
vector<string> factionsList; vector<string> factionsList;
findAll(techPath + "/" + techName + "/factions/*.", factionsList, false, false); findAll(techPath + techName + "/factions/*.", factionsList, false, false);
if(factionsList.size() > 0) { if(factionsList.size() > 0) {
Checksum checksum; Checksum checksum;
@ -1419,8 +1425,11 @@ void CheckForDuplicateData() {
if(duplicateMapsToRename.size() > 0) { if(duplicateMapsToRename.size() > 0) {
string errorMsg = "Warning duplicate maps were detected and renamed:\n"; string errorMsg = "Warning duplicate maps were detected and renamed:\n";
for(int i = 0; i < duplicateMapsToRename.size(); ++i) { for(int i = 0; i < duplicateMapsToRename.size(); ++i) {
string oldFile = mapPaths[1] + "/" + duplicateMapsToRename[i]; string currentPath = mapPaths[1];
string newFile = mapPaths[1] + "/" + duplicateMapsToRename[i]; endPathWithSlash(currentPath);
string oldFile = currentPath + duplicateMapsToRename[i];
string newFile = currentPath + duplicateMapsToRename[i];
string ext = extractExtension(newFile); string ext = extractExtension(newFile);
newFile = newFile.substr( 0, newFile.length()-ext.length()-1); newFile = newFile.substr( 0, newFile.length()-ext.length()-1);
newFile = newFile + "_custom." + ext; newFile = newFile + "_custom." + ext;
@ -1608,9 +1617,7 @@ int glestMain(int argc, char** argv) {
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
if(isdir(userData.c_str()) == false) { if(isdir(userData.c_str()) == false) {
createDirectoryPaths(userData); createDirectoryPaths(userData);
@ -1786,6 +1793,108 @@ int glestMain(int argc, char** argv) {
delete mainWindow; delete mainWindow;
return -1; return -1;
} }
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_MODELS]) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONVERT_MODELS]) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONVERT_MODELS]),&foundParamIndIndex);
}
string paramValue = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string modelFile = paramPartTokens[1];
printf("About to convert model(s) [%s]\n",modelFile.c_str());
string textureFormat = "";
if(paramPartTokens.size() >= 3 && paramPartTokens[1].length() > 0) {
textureFormat = paramPartTokens[2];
printf("About to convert using texture format [%s]\n",textureFormat.c_str());
}
showCursor(true);
mainWindow->setUseDefaultCursorOnly(true);
const Metrics &metrics= Metrics::getInstance();
renderer.clearBuffers();
renderer.clearZBuffer();
renderer.reset2d();
renderer.renderText(
"Please wait, converting models...",
CoreData::getInstance().getMenuFontBig(),
Vec3f(1.f, 1.f, 0.f), (metrics.getScreenW() / 2) - 400,
(metrics.getScreenH() / 2), true);
renderer.swapBuffers();
std::vector<string> models;
if(isdir(modelFile.c_str()) == true) {
models = getFolderTreeContentsListRecursively(modelFile, ".g3d");
}
else {
models.push_back(modelFile);
}
sleep(0);
Window::handleEvent();
SDL_PumpEvents();
char szTextBuf[1024]="";
for(unsigned int i =0; i < models.size(); ++i) {
string &file = models[i];
bool modelLoadedOk = false;
renderer.clearBuffers();
renderer.clearZBuffer();
renderer.reset2d();
sprintf(szTextBuf,"Please wait, converting models [%d of %lu] ...",i,(long int)models.size());
renderer.renderText(
szTextBuf,
CoreData::getInstance().getMenuFontBig(),
Vec3f(1.f, 1.f, 0.f), (metrics.getScreenW() / 2) - 400,
(metrics.getScreenH() / 2), true);
renderer.swapBuffers();
sleep(0);
Window::handleEvent();
SDL_PumpEvents();
Model *model = renderer.newModel(rsGlobal);
try {
printf("About to load model [%s]\n",file.c_str());
model->load(file);
modelLoadedOk = true;
}
catch(const exception &ex) {
printf("ERROR loading model [%s] message [%s]\n",file.c_str(),ex.what());
}
if(modelLoadedOk == true) {
printf("About to save converted model [%s]\n",file.c_str());
model->save(file,textureFormat);
}
Renderer::getInstance().endModel(rsGlobal, model);
}
delete mainWindow;
return -1;
}
else {
printf("\nInvalid model specified on commandline [%s] texture [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
return -1;
}
}
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]) == true) {
//!!!
printf("\nComing soon (not yet implemented)\n\n");
delete mainWindow;
return -1;
}
if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true || if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) { hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) {
@ -1795,49 +1904,11 @@ int glestMain(int argc, char** argv) {
return -1; return -1;
} }
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_MODEL]) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONVERT_MODEL]) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CONVERT_MODEL]),&foundParamIndIndex);
}
string paramValue = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string modelFile = paramPartTokens[1];
string textureFormat = "png";
if(paramPartTokens.size() >= 3) {
textureFormat = paramPartTokens[2];
}
printf("About to convert model [%s] using texture format [%s]\n",modelFile.c_str(),textureFormat.c_str());
Model *model = renderer.newModel(rsGlobal);
model->load(modelFile);
model->save(modelFile,textureFormat);
//!!!
delete mainWindow;
return -1;
}
else {
printf("\nInvalid model name specified on commandline [%s] model [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
return -1;
}
}
gameInitialized = true; gameInitialized = true;
// Setup the screenshots folder // Setup the screenshots folder
//string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
string screenShotsPath = userData + GameConstants::folder_path_screenshots; string screenShotsPath = userData + GameConstants::folder_path_screenshots;

View File

@ -495,9 +495,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
else { else {
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
logFile = userData + logFile; logFile = userData + logFile;

View File

@ -1604,8 +1604,8 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool
vector<string> techPaths = config.getPathListForType(ptTechs); vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) { for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx]; string &techPath = techPaths[idx];
endPathWithSlash(techPath);
findAll(techPath + "/" + gameSettings->getTech() + "/factions/*.", results, false, false); findAll(techPath + gameSettings->getTech() + "/factions/*.", results, false, false);
if(results.size() > 0) { if(results.size() > 0) {
break; break;
} }

View File

@ -444,7 +444,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
vector<string> techPaths = config.getPathListForType(ptTechs); vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) { for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx]; string &techPath = techPaths[idx];
findAll(techPath + "/" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false); endPathWithSlash(techPath);
findAll(techPath + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false);
if(results.size() > 0) { if(results.size() > 0) {
break; break;
@ -2238,15 +2239,10 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
//if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
// fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName;
//}
Config &config = Config::getInstance(); Config &config = Config::getInstance();
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
fileName = userData + fileName; fileName = userData + fileName;
@ -2306,15 +2302,10 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
GameSettings gameSettings; GameSettings gameSettings;
//if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
// fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName;
//}
Config &config = Config::getInstance(); Config &config = Config::getInstance();
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
fileName = userData + fileName; fileName = userData + fileName;
@ -2556,16 +2547,14 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa
} }
void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem) { void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem) {
vector<string> results; vector<string> results;
Config &config = Config::getInstance(); Config &config = Config::getInstance();
vector<string> techPaths = config.getPathListForType(ptTechs); vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) { for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx]; string &techPath = techPaths[idx];
endPathWithSlash(techPath);
findAll(techPath + "/" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false); findAll(techPath + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false);
if(results.size() > 0) { if(results.size() > 0) {
break; break;
} }

View File

@ -54,15 +54,9 @@ MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool
networkManager.init(nrClient); networkManager.init(nrClient);
serversSavedFile = serverFileName; serversSavedFile = serverFileName;
//if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
// serversSavedFile = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + serversSavedFile;
//}
//Config &config = Config::getInstance();
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
serversSavedFile = userData + serversSavedFile; serversSavedFile = userData + serversSavedFile;

View File

@ -69,10 +69,11 @@ ServerLine::ServerLine(MasterServerInfo *mServerInfo, int lineIndex, int baseY,
Config &config= Config::getInstance(); Config &config= Config::getInstance();
if(config.getString("CountryTexturePath", "") != ""){ if(config.getString("CountryTexturePath", "") != ""){
countryLogoPath= config.getString("CountryTexturePath", ""); countryLogoPath = config.getString("CountryTexturePath", "");
} }
endPathWithSlash(countryLogoPath);
string logoFile= countryLogoPath + "/" + toLower(masterServerInfo.getCountry()) + ".png"; string logoFile= countryLogoPath + toLower(masterServerInfo.getCountry()) + ".png";
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFile.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFile.c_str());
if(fileExists(logoFile) == true){ if(fileExists(logoFile) == true){

View File

@ -321,7 +321,6 @@ void ClientInterface::updateLobby() {
} }
// check the checksum's // check the checksum's
//int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_tilesets) + "/" + networkMessageSynchNetworkGameData.getTileset() + "/*", ".xml", NULL);
tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTileset() + string("/*"), ".xml", NULL); tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTileset() + string("/*"), ".xml", NULL);
this->setNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC())); this->setNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC()));
@ -330,9 +329,7 @@ void ClientInterface::updateLobby() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTileset() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC(),networkMessageSynchNetworkGameData.getTileset().c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTileset() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC(),networkMessageSynchNetworkGameData.getTileset().c_str());
//} //}
//tech, load before map because of resources //tech, load before map because of resources
//int32 techCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_techs) + "/" + networkMessageSynchNetworkGameData.getTech() + "/*", ".xml", NULL);
techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTech() + string("/*"), ".xml", NULL); techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), string("/") + networkMessageSynchNetworkGameData.getTech() + string("/*"), ".xml", NULL);
this->setNetworkGameDataSynchCheckOkTech((techCRC == networkMessageSynchNetworkGameData.getTechCRC())); this->setNetworkGameDataSynchCheckOkTech((techCRC == networkMessageSynchNetworkGameData.getTechCRC()));

View File

@ -637,21 +637,17 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
if(networkGameDataSynchCheckOkTile == false) { if(networkGameDataSynchCheckOkTile == false) {
if(tilesetCRC == 0) { if(tilesetCRC == 0) {
//vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_tilesets) + "/" + serverInterface->getGameSettings()->getTileset() + "/*", "", &vctFileList);
vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), "", &vctFileList); vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), "", &vctFileList);
} }
else { else {
//vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_tilesets) + "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList);
vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList); vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList);
} }
} }
if(networkGameDataSynchCheckOkTech == false) { if(networkGameDataSynchCheckOkTech == false) {
if(techCRC == 0) { if(techCRC == 0) {
//vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList);
vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList); vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList);
} }
else { else {
//vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList);
vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList); vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList);
} }
@ -670,14 +666,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
} }
else { else {
if(networkGameDataSynchCheckOkTech == false) { if(networkGameDataSynchCheckOkTech == false) {
//if(techCRC == 0) {
//vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList);
//vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList);
//}
//else {
//vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList);
vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", NULL); vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", NULL);
//}
string report = networkMessageSynchNetworkGameDataStatus.getTechCRCFileMismatchReport(serverInterface->getGameSettings()->getTech(),vctFileList); string report = networkMessageSynchNetworkGameDataStatus.getTechCRCFileMismatchReport(serverInterface->getGameSettings()->getTech(),vctFileList);
this->setNetworkGameDataSynchCheckTechMismatchReport(report); this->setNetworkGameDataSynchCheckTechMismatchReport(report);

View File

@ -51,7 +51,10 @@ void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTr
//image //image
const XmlNode *imageNode= n->getChild("image"); const XmlNode *imageNode= n->getChild("image");
image= Renderer::getInstance().newTexture2D(rsGame); image= Renderer::getInstance().newTexture2D(rsGame);
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue());
string currentPath = dir;
endPathWithSlash(currentPath);
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
//unit requirements //unit requirements
const XmlNode *unitRequirementsNode= n->getChild("unit-requirements"); const XmlNode *unitRequirementsNode= n->getChild("unit-requirements");
@ -378,7 +381,10 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T
const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i); const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(dir + "/" + path);
string currentPath = dir;
endPathWithSlash(currentPath);
sound->load(currentPath + path);
startSounds[i]= sound; startSounds[i]= sound;
} }
} }
@ -391,7 +397,10 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T
const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i); const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(dir + "/" + path);
string currentPath = dir;
endPathWithSlash(currentPath);
sound->load(currentPath + path);
builtSounds[i]= sound; builtSounds[i]= sound;
} }
} }

View File

@ -106,7 +106,9 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
} }
//open xml file //open xml file
string path= dir+"/"+name+".xml"; string currentPath = dir;
endPathWithSlash(currentPath);
string path= currentPath + name + ".xml";
checksum->addFile(path); checksum->addFile(path);
techtreeChecksum->addFile(path); techtreeChecksum->addFile(path);
@ -143,7 +145,10 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
bool value= musicNode->getAttribute("value")->getBoolValue(); bool value= musicNode->getAttribute("value")->getBoolValue();
if(value){ if(value){
music= new StrSound(); music= new StrSound();
music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue());
string currentPath = dir;
endPathWithSlash(currentPath);
music->open(currentPath + musicNode->getAttribute("path")->getRestrictedValue());
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -57,7 +57,9 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
name= lastDir(dir); name= lastDir(dir);
Logger::getInstance().add("Resource type: "+ formatString(name), true); Logger::getInstance().add("Resource type: "+ formatString(name), true);
path= dir+"/"+name+".xml"; string currentPath = dir;
endPathWithSlash(currentPath);
path= currentPath + name + ".xml";
checksum->addFile(path); checksum->addFile(path);
techtreeChecksum->addFile(path); techtreeChecksum->addFile(path);
@ -69,7 +71,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
//image //image
const XmlNode *imageNode= resourceNode->getChild("image"); const XmlNode *imageNode= resourceNode->getChild("image");
image= renderer.newTexture2D(rsGame); image= renderer.newTexture2D(rsGame);
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
//type //type
const XmlNode *typeNode= resourceNode->getChild("type"); const XmlNode *typeNode= resourceNode->getChild("type");
@ -81,7 +83,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
{ {
//model //model
const XmlNode *modelNode= typeNode->getChild("model"); const XmlNode *modelNode= typeNode->getChild("model");
string path=dir+"/" + modelNode->getAttribute("path")->getRestrictedValue(); string path= currentPath + modelNode->getAttribute("path")->getRestrictedValue();
model= renderer.newModel(rsGame); model= renderer.newModel(rsGame);
model->load(path); model->load(path);
@ -95,7 +97,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
string path= particleFileNode->getAttribute("path")->getRestrictedValue(); string path= particleFileNode->getAttribute("path")->getRestrictedValue();
ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType();
objectParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); objectParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance());
particleTypes.push_back(objectParticleSystemType); particleTypes.push_back(objectParticleSystemType);
} }
} }

View File

@ -63,7 +63,9 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
//model //model
string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(); string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue();
animation= Renderer::getInstance().newModel(rsGame); animation= Renderer::getInstance().newModel(rsGame);
animation->load(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
animation->load(currentPath + path);
//particles //particles
if(sn->hasChild("particles")){ if(sn->hasChild("particles")){
@ -74,7 +76,7 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
const XmlNode *particleFileNode= particleNode->getChild("particle-file", i); const XmlNode *particleFileNode= particleNode->getChild("particle-file", i);
string path= particleFileNode->getAttribute("path")->getRestrictedValue(); string path= particleFileNode->getAttribute("path")->getRestrictedValue();
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
unitParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance());
unitParticleSystemTypes.push_back(unitParticleSystemType); unitParticleSystemTypes.push_back(unitParticleSystemType);
} }
} }
@ -93,7 +95,7 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(dir + "/" + path); sound->load(currentPath + path);
sounds[i]= sound; sounds[i]= sound;
} }
} }
@ -189,6 +191,9 @@ AttackSkillType::~AttackSkillType() {
void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft) { void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft) {
SkillType::load(sn, dir, tt, ft); SkillType::load(sn, dir, tt, ft);
string currentPath = dir;
endPathWithSlash(currentPath);
//misc //misc
attackStrength= sn->getChild("attack-strenght")->getAttribute("value")->getIntValue(); attackStrength= sn->getChild("attack-strenght")->getAttribute("value")->getIntValue();
attackVar= sn->getChild("attack-var")->getAttribute("value")->getIntValue(); attackVar= sn->getChild("attack-var")->getAttribute("value")->getIntValue();
@ -239,7 +244,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
if(particleEnabled){ if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue(); string path= particleNode->getAttribute("path")->getRestrictedValue();
projectileParticleSystemType= new ParticleSystemTypeProjectile(); projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); projectileParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance());
} }
//proj sounds //proj sounds
@ -251,7 +256,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(dir + "/" + path); sound->load(currentPath + path);
projSounds[i]= sound; projSounds[i]= sound;
} }
} }
@ -270,7 +275,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
if(particleEnabled){ if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue(); string path= particleNode->getAttribute("path")->getRestrictedValue();
splashParticleSystemType= new ParticleSystemTypeSplash(); splashParticleSystemType= new ParticleSystemTypeSplash();
splashParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); splashParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance());
} }
} }
} }

View File

@ -35,7 +35,10 @@ namespace Glest{ namespace Game{
Checksum TechTree::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum) { Checksum TechTree::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum) {
Checksum techtreeChecksum; Checksum techtreeChecksum;
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
string path = pathList[idx] + "/" + techName; string currentPath = pathList[idx];
endPathWithSlash(currentPath);
string path = currentPath + techName;
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
load(path, factions, checksum, &techtreeChecksum); load(path, factions, checksum, &techtreeChecksum);
break; break;
@ -85,7 +88,9 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
//load tech tree xml info //load tech tree xml info
try{ try{
XmlTree xmlTree; XmlTree xmlTree;
string path= dir+"/"+lastDir(dir)+".xml"; string currentPath = dir;
endPathWithSlash(currentPath);
string path = currentPath + lastDir(dir) + ".xml";
checksum->addFile(path); checksum->addFile(path);
checksumValue.addFile(path); checksumValue.addFile(path);

View File

@ -121,7 +121,9 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string path = dir + "/" + name + ".xml"; string currentPath = dir;
endPathWithSlash(currentPath);
string path = currentPath + name + ".xml";
this->id= id; this->id= id;
@ -284,7 +286,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
//Texture2D *newTexture = Renderer::getInstance().newTexture2D(rsGame); //Texture2D *newTexture = Renderer::getInstance().newTexture2D(rsGame);
Texture2D *newTexture = NULL; Texture2D *newTexture = NULL;
unitParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance());
if(unitParticleSystemType->hasTexture() == false) { if(unitParticleSystemType->hasTexture() == false) {
//Renderer::getInstance().endLastTexture(rsGame,true); //Renderer::getInstance().endLastTexture(rsGame,true);
} }
@ -353,19 +355,19 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
//image //image
const XmlNode *imageNode= parametersNode->getChild("image"); const XmlNode *imageNode= parametersNode->getChild("image");
image= Renderer::getInstance().newTexture2D(rsGame); image= Renderer::getInstance().newTexture2D(rsGame);
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
//image cancel //image cancel
const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel"); const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel");
cancelImage= Renderer::getInstance().newTexture2D(rsGame); cancelImage= Renderer::getInstance().newTexture2D(rsGame);
cancelImage->load(dir+"/"+imageCancelNode->getAttribute("path")->getRestrictedValue()); cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue());
//meeting point //meeting point
const XmlNode *meetingPointNode= parametersNode->getChild("meeting-point"); const XmlNode *meetingPointNode= parametersNode->getChild("meeting-point");
meetingPoint= meetingPointNode->getAttribute("value")->getBoolValue(); meetingPoint= meetingPointNode->getAttribute("value")->getBoolValue();
if(meetingPoint){ if(meetingPoint){
meetingPointImage= Renderer::getInstance().newTexture2D(rsGame); meetingPointImage= Renderer::getInstance().newTexture2D(rsGame);
meetingPointImage->load(dir+"/"+meetingPointNode->getAttribute("image-path")->getRestrictedValue()); meetingPointImage->load(currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue());
} }
//selection sounds //selection sounds
@ -376,7 +378,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
const XmlNode *soundNode= selectionSoundNode->getChild("sound", i); const XmlNode *soundNode= selectionSoundNode->getChild("sound", i);
string path= soundNode->getAttribute("path")->getRestrictedValue(); string path= soundNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(dir + "/" + path); sound->load(currentPath + path);
selectionSounds[i]= sound; selectionSounds[i]= sound;
} }
} }
@ -389,7 +391,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
const XmlNode *soundNode= commandSoundNode->getChild("sound", i); const XmlNode *soundNode= commandSoundNode->getChild("sound", i);
string path= soundNode->getAttribute("path")->getRestrictedValue(); string path= soundNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(dir + "/" + path); sound->load(currentPath + path);
commandSounds[i]= sound; commandSounds[i]= sound;
} }
} }

View File

@ -54,7 +54,9 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
Logger::getInstance().add("Upgrade type: "+ formatString(name), true); Logger::getInstance().add("Upgrade type: "+ formatString(name), true);
path = dir + "/" + name + ".xml"; string currentPath = dir;
endPathWithSlash(currentPath);
path = currentPath + name + ".xml";
try{ try{
checksum->addFile(path); checksum->addFile(path);
@ -67,12 +69,12 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
//image //image
const XmlNode *imageNode= upgradeNode->getChild("image"); const XmlNode *imageNode= upgradeNode->getChild("image");
image= Renderer::getInstance().newTexture2D(rsGame); image= Renderer::getInstance().newTexture2D(rsGame);
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
//image cancel //image cancel
const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel"); const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel");
cancelImage= Renderer::getInstance().newTexture2D(rsGame); cancelImage= Renderer::getInstance().newTexture2D(rsGame);
cancelImage->load(dir+"/"+imageCancelNode->getAttribute("path")->getRestrictedValue()); cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue());
//upgrade time //upgrade time
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time"); const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");

View File

@ -1250,9 +1250,11 @@ string Map::getMapPath(const string &mapName, string scenarioDir, bool errorOnNo
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir); vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
const string &map_path = pathList[idx]; string map_path = pathList[idx];
const string mega = map_path + "/" + mapName + ".mgm"; endPathWithSlash(map_path);
const string glest = map_path + "/" + mapName + ".gbm";
const string mega = map_path + mapName + ".mgm";
const string glest = map_path + mapName + ".gbm";
if (fileExists(mega)) { if (fileExists(mega)) {
return mega; return mega;
} }

View File

@ -17,11 +17,13 @@
#include "xml_parser.h" #include "xml_parser.h"
#include "util.h" #include "util.h"
#include "game_util.h" #include "game_util.h"
#include "leak_dumper.h"
#include <stdio.h> #include <stdio.h>
#include "platform_common.h"
#include "leak_dumper.h"
using namespace Shared::Xml; using namespace Shared::Xml;
using namespace Shared::Util; using namespace Shared::Util;
using namespace Shared::PlatformCommon;
using namespace std; using namespace std;
namespace Glest{ namespace Game{ namespace Glest{ namespace Game{
@ -67,7 +69,9 @@ Checksum Scenario::load(const string &path) {
int Scenario::getScenarioPathIndex(const vector<string> dirList, const string &scenarioName) { int Scenario::getScenarioPathIndex(const vector<string> dirList, const string &scenarioName) {
int iIndex = 0; int iIndex = 0;
for(int idx = 0; idx < dirList.size(); idx++) { for(int idx = 0; idx < dirList.size(); idx++) {
string scenarioFile = dirList[idx] + "/" + scenarioName + "/" + scenarioName + ".xml"; string currentPath = dirList[idx];
endPathWithSlash(currentPath);
string scenarioFile = currentPath + scenarioName + "/" + scenarioName + ".xml";
if(fileExists(scenarioFile) == true) { if(fileExists(scenarioFile) == true) {
iIndex = idx; iIndex = idx;
break; break;
@ -80,7 +84,9 @@ int Scenario::getScenarioPathIndex(const vector<string> dirList, const string &s
string Scenario::getScenarioPath(const vector<string> dirList, const string &scenarioName, bool getMatchingRootScenarioPathOnly){ string Scenario::getScenarioPath(const vector<string> dirList, const string &scenarioName, bool getMatchingRootScenarioPathOnly){
string scenarioFile = ""; string scenarioFile = "";
for(int idx = 0; idx < dirList.size(); idx++) { for(int idx = 0; idx < dirList.size(); idx++) {
scenarioFile = dirList[idx] + "/" + scenarioName + "/" + scenarioName + ".xml"; string currentPath = dirList[idx];
endPathWithSlash(currentPath);
scenarioFile = currentPath + scenarioName + "/" + scenarioName + ".xml";
if(fileExists(scenarioFile) == true) { if(fileExists(scenarioFile) == true) {
if(getMatchingRootScenarioPathOnly == true) { if(getMatchingRootScenarioPathOnly == true) {
scenarioFile = dirList[idx]; scenarioFile = dirList[idx];
@ -96,9 +102,9 @@ string Scenario::getScenarioPath(const vector<string> dirList, const string &sce
} }
string Scenario::getScenarioPath(const string &dir, const string &scenarioName){ string Scenario::getScenarioPath(const string &dir, const string &scenarioName){
string scenarioFile = dir + "/" + scenarioName + "/" + scenarioName + ".xml"; string currentPath = dir;
//printf("dir [%s] scenarioName [%s] scenarioFile [%s]\n",dir.c_str(),scenarioName.c_str(),scenarioFile.c_str()); endPathWithSlash(currentPath);
string scenarioFile = currentPath + scenarioName + "/" + scenarioName + ".xml";
return scenarioFile; return scenarioFile;
} }

View File

@ -39,7 +39,9 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
enabledDay= dayNode->getAttribute("enabled")->getBoolValue(); enabledDay= dayNode->getAttribute("enabled")->getBoolValue();
if(enabledDay){ if(enabledDay){
path= dayNode->getAttribute("path")->getRestrictedValue(); path= dayNode->getAttribute("path")->getRestrictedValue();
day.open(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
day.open(currentPath + path);
alwaysPlayDay= dayNode->getAttribute("play-always")->getBoolValue(); alwaysPlayDay= dayNode->getAttribute("play-always")->getBoolValue();
} }
@ -48,7 +50,9 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
enabledNight= nightNode->getAttribute("enabled")->getBoolValue(); enabledNight= nightNode->getAttribute("enabled")->getBoolValue();
if(enabledNight){ if(enabledNight){
path= nightNode->getAttribute("path")->getRestrictedValue(); path= nightNode->getAttribute("path")->getRestrictedValue();
night.open(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
night.open(currentPath + path);
alwaysPlayNight= nightNode->getAttribute("play-always")->getBoolValue(); alwaysPlayNight= nightNode->getAttribute("play-always")->getBoolValue();
} }
@ -57,7 +61,9 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
enabledRain= rainNode->getAttribute("enabled")->getBoolValue(); enabledRain= rainNode->getAttribute("enabled")->getBoolValue();
if(enabledRain){ if(enabledRain){
path= rainNode->getAttribute("path")->getRestrictedValue(); path= rainNode->getAttribute("path")->getRestrictedValue();
rain.open(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
rain.open(currentPath + path);
} }
//snow //snow
@ -65,7 +71,9 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
enabledSnow= snowNode->getAttribute("enabled")->getBoolValue(); enabledSnow= snowNode->getAttribute("enabled")->getBoolValue();
if(enabledSnow){ if(enabledSnow){
path= snowNode->getAttribute("path")->getRestrictedValue(); path= snowNode->getAttribute("path")->getRestrictedValue();
snow.open(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
snow.open(currentPath + path);
} }
//dayStart //dayStart
@ -73,7 +81,9 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
enabledDayStart= dayStartNode->getAttribute("enabled")->getBoolValue(); enabledDayStart= dayStartNode->getAttribute("enabled")->getBoolValue();
if(enabledDayStart){ if(enabledDayStart){
path= dayStartNode->getAttribute("path")->getRestrictedValue(); path= dayStartNode->getAttribute("path")->getRestrictedValue();
dayStart.load(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
dayStart.load(currentPath + path);
} }
//nightStart //nightStart
@ -81,9 +91,10 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
enabledNightStart= nightStartNode->getAttribute("enabled")->getBoolValue(); enabledNightStart= nightStartNode->getAttribute("enabled")->getBoolValue();
if(enabledNightStart){ if(enabledNightStart){
path= nightStartNode->getAttribute("path")->getRestrictedValue(); path= nightStartNode->getAttribute("path")->getRestrictedValue();
nightStart.load(dir + "/" + path); string currentPath = dir;
endPathWithSlash(currentPath);
nightStart.load(currentPath + path);
} }
} }
// ===================================================== // =====================================================
@ -93,7 +104,9 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
Checksum Tileset::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) { Checksum Tileset::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) {
Checksum tilesetChecksum; Checksum tilesetChecksum;
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
const string path = pathList[idx] + "/" + tilesetName; string currentPath = pathList[idx];
endPathWithSlash(currentPath);
string path = currentPath + tilesetName;
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
load(path, checksum, &tilesetChecksum); load(path, checksum, &tilesetChecksum);
break; break;
@ -111,7 +124,9 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string name= lastDir(dir); string name= lastDir(dir);
string path= dir + "/" + name + ".xml"; string currentPath = dir;
endPathWithSlash(currentPath);
string path= currentPath + name + ".xml";
checksum->addFile(path); checksum->addFile(path);
tilesetChecksum->addFile(path); tilesetChecksum->addFile(path);
@ -152,7 +167,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
for(int j=0; j<childCount; ++j){ for(int j=0; j<childCount; ++j){
const XmlNode *textureNode= surfaceNode->getChild("texture", j); const XmlNode *textureNode= surfaceNode->getChild("texture", j);
surfPixmaps[i][j].init(3); surfPixmaps[i][j].init(3);
surfPixmaps[i][j].load(dir +"/"+textureNode->getAttribute("path")->getRestrictedValue()); surfPixmaps[i][j].load(currentPath + textureNode->getAttribute("path")->getRestrictedValue());
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue(); surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
} }
} }
@ -178,7 +193,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
for(int j=0; j<childCount; ++j) { for(int j=0; j<childCount; ++j) {
const XmlNode *modelNode= objectNode->getChild("model", j); const XmlNode *modelNode= objectNode->getChild("model", j);
const XmlAttribute *pathAttribute= modelNode->getAttribute("path"); const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue()); objectTypes[i].loadModel(currentPath + pathAttribute->getRestrictedValue());
if(modelNode->hasChild("particles")){ if(modelNode->hasChild("particles")){
const XmlNode *particleNode= modelNode->getChild("particles"); const XmlNode *particleNode= modelNode->getChild("particles");
@ -188,7 +203,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
const XmlNode *particleFileNode= particleNode->getChild("particle-file", k); const XmlNode *particleFileNode= particleNode->getChild("particle-file", k);
string path= particleFileNode->getAttribute("path")->getRestrictedValue(); string path= particleFileNode->getAttribute("path")->getRestrictedValue();
ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType();
objectParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); objectParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance());
objectTypes[i].addParticleSystem((objectParticleSystemType)); objectTypes[i].addParticleSystem((objectParticleSystemType));
} }
} }
@ -222,7 +237,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
waterTex->getPixmap()->init(waterFrameCount, 4); waterTex->getPixmap()->init(waterFrameCount, 4);
for(int i=0; i<waterFrameCount; ++i){ for(int i=0; i<waterFrameCount; ++i){
const XmlNode *waterFrameNode= waterNode->getChild("texture", i); const XmlNode *waterFrameNode= waterNode->getChild("texture", i);
waterTex->getPixmap()->loadSlice(dir +"/"+ waterFrameNode->getAttribute("path")->getRestrictedValue(), i); waterTex->getPixmap()->loadSlice(currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue(), i);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -1597,9 +1597,7 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
else { else {
string userData = Config::getInstance().getString("UserData_Root",""); string userData = Config::getInstance().getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
debugWorldLogFile = userData + debugWorldLogFile; debugWorldLogFile = userData + debugWorldLogFile;
} }

View File

@ -131,20 +131,21 @@ public:
void updateInterpolationData(float t, bool cycle); void updateInterpolationData(float t, bool cycle);
void updateInterpolationVertices(float t, bool cycle); void updateInterpolationVertices(float t, bool cycle);
Texture2D *loadMeshTexture(TextureManager *textureManager, string textureFile, Texture2D *loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile,
int textureChannelCount, bool &textureOwned, int textureChannelCount, bool &textureOwned,
bool deletePixMapAfterLoad); bool deletePixMapAfterLoad);
//load //load
void loadV2(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
void loadV3(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
void load(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
void save(const string &dir, FILE *f, TextureManager *textureManager, void save(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
string convertTextureToFormat, std::map<string,int> &textureDeleteList); string convertTextureToFormat, std::map<string,int> &textureDeleteList);
void deletePixels(); void deletePixels();
private: private:
string findAlternateTexture(vector<string> conversionList, string textureFile);
void computeTangents(); void computeTangents();
}; };

View File

@ -147,8 +147,11 @@ void restoreVideoMode(bool exitingApp=false);
bool StartsWith(const std::string &str, const std::string &key); bool StartsWith(const std::string &str, const std::string &key);
bool EndsWith(const string &str, const string& key); bool EndsWith(const string &str, const string& key);
void endPathWithSlash(string &path);
string replaceAll(string& context, const string& from, const string& to); string replaceAll(string& context, const string& from, const string& to);
bool removeFile(string file); bool removeFile(string file);
bool renameFile(string oldFile, string newFile);
void removeFolder(const string path); void removeFolder(const string path);
int getScreenW(); int getScreenW();

View File

@ -189,19 +189,41 @@ void Mesh::ReleaseVBOs() {
// ==================== load ==================== // ==================== load ====================
void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) { string Mesh::findAlternateTexture(vector<string> conversionList, string textureFile) {
string result = textureFile;
string fileExt = extractExtension(textureFile);
for(int i = 0; i < conversionList.size(); ++i) {
string convertTo = conversionList[i];
if(fileExt != convertTo) {
string alternateTexture = textureFile;
replaceAll(alternateTexture, "." + fileExt, "." + convertTo);
if(fileExists(alternateTexture) == true) {
result = alternateTexture;
break;
}
}
}
return result;
}
void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
this->textureManager = textureManager; this->textureManager = textureManager;
//read header //read header
MeshHeaderV2 meshHeader; MeshHeaderV2 meshHeader;
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV2), 1, f); size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV2), 1, f);
if(meshHeader.normalFrameCount!=meshHeader.vertexFrameCount){ if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
throw runtime_error("Old model: vertex frame count different from normal frame count"); char szBuf[4096]="";
sprintf(szBuf,"Old v2 model: vertex frame count different from normal frame count [v = %d, n = %d] meshIndex = %d",meshHeader.vertexFrameCount,meshHeader.normalFrameCount,meshIndex);
throw runtime_error(szBuf);
} }
if(meshHeader.texCoordFrameCount!=1){ if(meshHeader.texCoordFrameCount != 1) {
throw runtime_error("Old model: texture coord frame count is not 1"); char szBuf[4096]="";
sprintf(szBuf,"Old v2 model: texture coord frame count is not 1 [t = %d] meshIndex = %d",meshHeader.texCoordFrameCount,meshIndex);
throw runtime_error(szBuf);
} }
//init //init
@ -216,7 +238,7 @@ void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,boo
twoSided= false; twoSided= false;
customColor= false; customColor= false;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v2, this = %p Found meshHeader.hasTexture = %d, texName [%s] mtDiffuse = %d\n",this,meshHeader.hasTexture,toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(),mtDiffuse); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v2, this = %p Found meshHeader.hasTexture = %d, texName [%s] mtDiffuse = %d meshIndex = %d\n",this,meshHeader.hasTexture,toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(),mtDiffuse,meshIndex);
textureFlags= 0; textureFlags= 0;
if(meshHeader.hasTexture == true) { if(meshHeader.hasTexture == true) {
@ -228,19 +250,31 @@ void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,boo
texturePaths[mtDiffuse]= toLower(reinterpret_cast<char*>(meshHeader.texName)); texturePaths[mtDiffuse]= toLower(reinterpret_cast<char*>(meshHeader.texName));
string texPath= dir; string texPath= dir;
if(texPath != "") { if(texPath != "") {
texPath += "/"; endPathWithSlash(texPath);
} }
texPath += texturePaths[mtDiffuse]; texPath += texturePaths[mtDiffuse];
textures[mtDiffuse]= static_cast<Texture2D*>(textureManager->getTexture(texPath)); textures[mtDiffuse]= dynamic_cast<Texture2D*>(textureManager->getTexture(texPath));
if(textures[mtDiffuse]==NULL){ if(textures[mtDiffuse] == NULL) {
textures[mtDiffuse]= textureManager->newTexture2D(); if(fileExists(texPath) == false) {
textures[mtDiffuse]->load(texPath); vector<string> conversionList;
texturesOwned[mtDiffuse]=true; conversionList.push_back("png");
// M.V. Test conversionList.push_back("jpg");
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); conversionList.push_back("tga");
if(deletePixMapAfterLoad == true) { conversionList.push_back("bmp");
textures[mtDiffuse]->deletePixels(); texPath = findAlternateTexture(conversionList, texPath);
}
if(fileExists(texPath) == true) {
textures[mtDiffuse]= textureManager->newTexture2D();
textures[mtDiffuse]->load(texPath);
texturesOwned[mtDiffuse]=true;
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) {
textures[mtDiffuse]->deletePixels();
}
}
else {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error v2 model is missing texture [%s] meshIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,texPath.c_str(),meshIndex);
} }
} }
} }
@ -257,7 +291,7 @@ void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,boo
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f); readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
} }
void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) { void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
this->textureManager = textureManager; this->textureManager = textureManager;
//read header //read header
@ -265,8 +299,10 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,boo
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV3), 1, f); size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV3), 1, f);
if(meshHeader.normalFrameCount!=meshHeader.vertexFrameCount){ if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
throw runtime_error("Old model: vertex frame count different from normal frame count"); char szBuf[4096]="";
sprintf(szBuf,"Old v3 model: vertex frame count different from normal frame count [v = %d, n = %d] meshIndex = %d",meshHeader.vertexFrameCount,meshHeader.normalFrameCount,meshIndex);
throw runtime_error(szBuf);
} }
//init //init
@ -286,7 +322,7 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,boo
textureFlags= 1; textureFlags= 1;
} }
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v3, this = %p Found meshHeader.properties = %d, textureFlags = %d, texName [%s] mtDiffuse = %d\n",this,meshHeader.properties,textureFlags,toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(),mtDiffuse); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v3, this = %p Found meshHeader.properties = %d, textureFlags = %d, texName [%s] mtDiffuse = %d meshIndex = %d\n",this,meshHeader.properties,textureFlags,toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(),mtDiffuse,meshIndex);
//texture //texture
if((meshHeader.properties & mp3NoTexture) != mp3NoTexture && textureManager!=NULL){ if((meshHeader.properties & mp3NoTexture) != mp3NoTexture && textureManager!=NULL){
@ -294,19 +330,32 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,boo
string texPath= dir; string texPath= dir;
if(texPath != "") { if(texPath != "") {
texPath += "/"; endPathWithSlash(texPath);
} }
texPath += texturePaths[mtDiffuse]; texPath += texturePaths[mtDiffuse];
textures[mtDiffuse]= static_cast<Texture2D*>(textureManager->getTexture(texPath)); textures[mtDiffuse]= dynamic_cast<Texture2D*>(textureManager->getTexture(texPath));
if(textures[mtDiffuse]==NULL){ if(textures[mtDiffuse] == NULL) {
textures[mtDiffuse]= textureManager->newTexture2D(); if(fileExists(texPath) == false) {
textures[mtDiffuse]->load(texPath); vector<string> conversionList;
texturesOwned[mtDiffuse]=true; conversionList.push_back("png");
// M.V. Test conversionList.push_back("jpg");
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); conversionList.push_back("tga");
if(deletePixMapAfterLoad == true) { conversionList.push_back("bmp");
textures[mtDiffuse]->deletePixels(); texPath = findAlternateTexture(conversionList, texPath);
}
if(fileExists(texPath) == true) {
textures[mtDiffuse]= textureManager->newTexture2D();
textures[mtDiffuse]->load(texPath);
texturesOwned[mtDiffuse]=true;
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) {
textures[mtDiffuse]->deletePixels();
}
}
else {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error v3 model is missing texture [%s] meshHeader.properties = %d meshIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,texPath.c_str(),meshHeader.properties,meshIndex);
} }
} }
} }
@ -325,26 +374,53 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,boo
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f); readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
} }
Texture2D* Mesh::loadMeshTexture(TextureManager *textureManager, string textureFile, Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile,
int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad) { int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad) {
Texture2D* texture = static_cast<Texture2D*>(textureManager->getTexture(textureFile));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] #1 load texture [%s]\n",__FUNCTION__,textureFile.c_str());
Texture2D* texture = dynamic_cast<Texture2D*>(textureManager->getTexture(textureFile));
if(texture == NULL) { if(texture == NULL) {
texture = textureManager->newTexture2D(); if(fileExists(textureFile) == false) {
if(textureChannelCount != -1) { vector<string> conversionList;
texture->getPixmap()->init(textureChannelCount); conversionList.push_back("png");
conversionList.push_back("jpg");
conversionList.push_back("tga");
conversionList.push_back("bmp");
textureFile = findAlternateTexture(conversionList, textureFile);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] #2 load texture [%s]\n",__FUNCTION__,textureFile.c_str());
} }
texture->load(textureFile);
textureOwned = true; if(fileExists(textureFile) == true) {
texture->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] texture exists loading [%s]\n",__FUNCTION__,textureFile.c_str());
if(deletePixMapAfterLoad == true) {
texture->deletePixels(); texture = textureManager->newTexture2D();
if(textureChannelCount != -1) {
texture->getPixmap()->init(textureChannelCount);
}
texture->load(textureFile);
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] texture loaded [%s]\n",__FUNCTION__,textureFile.c_str());
textureOwned = true;
texture->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) {
texture->deletePixels();
}
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] texture inited [%s]\n",__FUNCTION__,textureFile.c_str());
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] #3 cannot load texture [%s]\n",__FUNCTION__,textureFile.c_str());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error v4 model is missing texture [%s] textureFlags = %d meshIndex = %d textureIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,textureFile.c_str(),textureFlags,meshIndex,textureIndex);
} }
} }
return texture; return texture;
} }
void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager, void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
bool deletePixMapAfterLoad) { bool deletePixMapAfterLoad) {
this->textureManager = textureManager; this->textureManager = textureManager;
@ -375,26 +451,28 @@ void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager,
textureFlags= meshHeader.textures; textureFlags= meshHeader.textures;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v4, this = %p Found meshHeader.textures = %d\n",this,meshHeader.textures); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v4, this = %p Found meshHeader.textures = %d meshIndex = %d\n",this,meshHeader.textures,meshIndex);
//maps //maps
uint32 flag= 1; uint32 flag= 1;
for(int i=0; i<meshTextureCount; ++i){ for(int i = 0; i < meshTextureCount; ++i) {
if((meshHeader.textures & flag) && textureManager!=NULL){ if((meshHeader.textures & flag) && textureManager != NULL) {
uint8 cMapPath[mapPathSize]; uint8 cMapPath[mapPathSize];
readBytes = fread(cMapPath, mapPathSize, 1, f); readBytes = fread(cMapPath, mapPathSize, 1, f);
string mapPath= toLower(reinterpret_cast<char*>(cMapPath)); string mapPath= toLower(reinterpret_cast<char*>(cMapPath));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("mapPath [%s] meshHeader.textures = %d flag = %d (meshHeader.textures & flag) = %d meshIndex = %d i = %d\n",mapPath.c_str(),meshHeader.textures,flag,(meshHeader.textures & flag),meshIndex,i);
string mapFullPath= dir; string mapFullPath= dir;
if(mapFullPath != "") { if(mapFullPath != "") {
mapFullPath += "/"; endPathWithSlash(mapFullPath);
} }
mapFullPath += mapPath; mapFullPath += mapPath;
textures[i] = loadMeshTexture(textureManager, mapFullPath, textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath,
meshTextureChannelCount[i],texturesOwned[i],deletePixMapAfterLoad); meshTextureChannelCount[i],texturesOwned[i],deletePixMapAfterLoad);
} }
flag*= 2; flag *= 2;
} }
//read data //read data
@ -411,7 +489,7 @@ void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager,
} }
} }
void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager, void Mesh::save(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
string convertTextureToFormat, std::map<string,int> &textureDeleteList) { string convertTextureToFormat, std::map<string,int> &textureDeleteList) {
MeshHeader meshHeader; MeshHeader meshHeader;
memset(&meshHeader, 0, sizeof(struct MeshHeader)); memset(&meshHeader, 0, sizeof(struct MeshHeader));
@ -439,7 +517,7 @@ void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager,
meshHeader.textures = textureFlags; meshHeader.textures = textureFlags;
fwrite(&meshHeader, sizeof(MeshHeader), 1, f); fwrite(&meshHeader, sizeof(MeshHeader), 1, f);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Save, this = %p, Found meshTextureCount = %d, meshHeader.textures = %d\n",this,meshTextureCount,meshHeader.textures); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Save, this = %p, Found meshTextureCount = %d, meshHeader.textures = %d meshIndex = %d\n",this,meshTextureCount,meshHeader.textures,meshIndex);
//maps //maps
uint32 flag= 1; uint32 flag= 1;
@ -487,7 +565,9 @@ void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager,
} }
//textureManager->endTexture(texture); //textureManager->endTexture(texture);
texture = loadMeshTexture(textureManager,file,
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Save, load new texture [%s]\n",file.c_str());
texture = loadMeshTexture(meshIndex, i, textureManager,file,
meshTextureChannelCount[i], meshTextureChannelCount[i],
texturesOwned[i], texturesOwned[i],
false); false);
@ -496,8 +576,16 @@ void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager,
file = extractFileFromDirectoryPath(texture->getPath()); file = extractFileFromDirectoryPath(texture->getPath());
if(file.length() > mapPathSize) {
throw runtime_error("file.length() > mapPathSize, file.length() = " + intToStr(file.length()));
}
else if(file.length() == 0) {
throw runtime_error("file.length() == 0");
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Save, new texture file [%s]\n",file.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Save, new texture file [%s]\n",file.c_str());
memset(&cMapPath[0],0,mapPathSize);
memcpy(&cMapPath[0],file.c_str(),file.length()); memcpy(&cMapPath[0],file.c_str(),file.length());
} }
@ -690,32 +778,32 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
//load meshes //load meshes
meshes= new Mesh[meshCount]; meshes= new Mesh[meshCount];
for(uint32 i=0; i<meshCount; ++i){ for(uint32 i = 0; i < meshCount; ++i) {
meshes[i].load(dir, f, textureManager,deletePixMapAfterLoad); meshes[i].load(i, dir, f, textureManager,deletePixMapAfterLoad);
meshes[i].buildInterpolationData(); meshes[i].buildInterpolationData();
} }
} }
//version 3 //version 3
else if(fileHeader.version==3){ else if(fileHeader.version == 3) {
readBytes = fread(&meshCount, sizeof(meshCount), 1, f); readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount);
meshes= new Mesh[meshCount]; meshes= new Mesh[meshCount];
for(uint32 i=0; i<meshCount; ++i){ for(uint32 i = 0; i < meshCount; ++i) {
meshes[i].loadV3(dir, f, textureManager,deletePixMapAfterLoad); meshes[i].loadV3(i, dir, f, textureManager,deletePixMapAfterLoad);
meshes[i].buildInterpolationData(); meshes[i].buildInterpolationData();
} }
} }
//version 2 //version 2
else if(fileHeader.version==2) { else if(fileHeader.version == 2) {
readBytes = fread(&meshCount, sizeof(meshCount), 1, f); readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount);
meshes= new Mesh[meshCount]; meshes= new Mesh[meshCount];
for(uint32 i=0; i<meshCount; ++i){ for(uint32 i = 0; i < meshCount; ++i){
meshes[i].loadV2(dir, f, textureManager,deletePixMapAfterLoad); meshes[i].loadV2(i,dir, f, textureManager,deletePixMapAfterLoad);
meshes[i].buildInterpolationData(); meshes[i].buildInterpolationData();
} }
} }
@ -733,9 +821,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
//save a model to a g3d file //save a model to a g3d file
void Model::saveG3d(const string &path, string convertTextureToFormat) { void Model::saveG3d(const string &path, string convertTextureToFormat) {
FILE *f= fopen(path.c_str(), "wb");
string tempModelFilename = path + "cvt";
FILE *f= fopen(tempModelFilename.c_str(), "wb");
if(f == NULL) { if(f == NULL) {
throw runtime_error("Cant open file for writting: "+path); throw runtime_error("Cant open file for writting: [" + tempModelFilename + "]");
} }
convertTextureToFormat = toLower(convertTextureToFormat); convertTextureToFormat = toLower(convertTextureToFormat);
@ -760,13 +851,17 @@ void Model::saveG3d(const string &path, string convertTextureToFormat) {
std::map<string,int> textureDeleteList; std::map<string,int> textureDeleteList;
for(uint32 i = 0; i < meshCount; ++i) { for(uint32 i = 0; i < meshCount; ++i) {
meshes[i].save(path, f, textureManager,convertTextureToFormat,textureDeleteList); meshes[i].save(i,tempModelFilename, f, textureManager,
convertTextureToFormat,textureDeleteList);
} }
// Now delete old textures since they were converted to a new format removeFile(path);
for(std::map<string,int>::iterator iterMap = textureDeleteList.begin(); if(renameFile(tempModelFilename,path) == true) {
iterMap != textureDeleteList.end(); ++iterMap) { // Now delete old textures since they were converted to a new format
for(std::map<string,int>::iterator iterMap = textureDeleteList.begin();
iterMap != textureDeleteList.end(); ++iterMap) {
removeFile(iterMap->first);
}
} }
} }
else { else {

View File

@ -61,7 +61,7 @@ using namespace Shared::Platform;
using namespace Shared::Util; using namespace Shared::Util;
using namespace std; using namespace std;
#define _DISABLE MEMORY_VAULT_CHECKS 1 #define _DISABLE_MEMORY_VAULT_CHECKS 1
namespace Shared { namespace PlatformCommon { namespace Shared { namespace PlatformCommon {
@ -214,13 +214,15 @@ void findDirs(const vector<string> &paths, vector<string> &results, bool errorOn
results.clear(); results.clear();
size_t pathCount = paths.size(); size_t pathCount = paths.size();
for(unsigned int idx = 0; idx < pathCount; idx++) { for(unsigned int idx = 0; idx < pathCount; idx++) {
string path = paths[idx] + "/*."; string currentPath = paths[idx];
endPathWithSlash(currentPath);
string path = currentPath + "*.";
vector<string> current_results; vector<string> current_results;
findAll(path, current_results, false, errorOnNotFound); findAll(path, current_results, false, errorOnNotFound);
if(current_results.size() > 0) { if(current_results.size() > 0) {
for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) { for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) {
const string current_folder = current_results[folder_index]; const string current_folder = current_results[folder_index];
const string current_folder_path = paths[idx] + "/" + current_folder; const string current_folder_path = currentPath + current_folder;
if(isdir(current_folder_path.c_str()) == true) { if(isdir(current_folder_path.c_str()) == true) {
if(keepDuplicates == true || std::find(results.begin(),results.end(),current_folder) == results.end()) { if(keepDuplicates == true || std::find(results.begin(),results.end(),current_folder) == results.end()) {
@ -238,7 +240,10 @@ void findAll(const vector<string> &paths, const string &fileFilter, vector<strin
results.clear(); results.clear();
size_t pathCount = paths.size(); size_t pathCount = paths.size();
for(unsigned int idx = 0; idx < pathCount; idx++) { for(unsigned int idx = 0; idx < pathCount; idx++) {
string path = paths[idx] + "/" + fileFilter; string currentPath = paths[idx];
endPathWithSlash(currentPath);
string path = currentPath + fileFilter;
vector<string> current_results; vector<string> current_results;
findAll(path, current_results, cutExtension, errorOnNotFound); findAll(path, current_results, cutExtension, errorOnNotFound);
if(current_results.size() > 0) { if(current_results.size() > 0) {
@ -401,6 +406,12 @@ bool EndsWith(const string &str, const string& key)
return result; return result;
} }
void endPathWithSlash(string &path) {
if(EndsWith(path, "/") == false && EndsWith(path, "\\") == false) {
path += "/";
}
}
string getCRCCacheFilePath() { string getCRCCacheFilePath() {
return crcCachePath; return crcCachePath;
} }
@ -656,8 +667,12 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string
if( S_ISDIR(statStruct.st_mode) == 0) if( S_ISDIR(statStruct.st_mode) == 0)
continue; continue;
#endif #endif
const char* p = globbuf.gl_pathv[i]; const char *p = globbuf.gl_pathv[i];
getFolderTreeContentsCheckSumRecursively(string(p) + "/*", filterFileExt, &checksum);
string currentPath = p;
endPathWithSlash(currentPath);
getFolderTreeContentsCheckSumRecursively(currentPath + "*", filterFileExt, &checksum);
} }
globfree(&globbuf); globfree(&globbuf);
@ -829,7 +844,11 @@ vector<string> getFolderTreeContentsListRecursively(const string &path, const st
if(includeFolders == true) { if(includeFolders == true) {
resultFiles.push_back(p); resultFiles.push_back(p);
} }
resultFiles = getFolderTreeContentsListRecursively(string(p) + "/*", filterFileExt, includeFolders,&resultFiles);
string currentPath = p;
endPathWithSlash(currentPath);
resultFiles = getFolderTreeContentsListRecursively(currentPath + "*", filterFileExt, includeFolders,&resultFiles);
} }
globfree(&globbuf); globfree(&globbuf);
@ -953,8 +972,12 @@ vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(co
if( S_ISDIR(statStruct.st_mode) == 0) if( S_ISDIR(statStruct.st_mode) == 0)
continue; continue;
#endif #endif
const char* p = globbuf.gl_pathv[i]; const char *p = globbuf.gl_pathv[i];
checksumFiles = getFolderTreeContentsCheckSumListRecursively(string(p) + "/*", filterFileExt, &checksumFiles);
string currentPath = p;
endPathWithSlash(currentPath);
checksumFiles = getFolderTreeContentsCheckSumListRecursively(currentPath + "*", filterFileExt, &checksumFiles);
} }
globfree(&globbuf); globfree(&globbuf);
@ -972,7 +995,6 @@ vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(co
string extractFileFromDirectoryPath(string filename) { string extractFileFromDirectoryPath(string filename) {
size_t lastDirectory = filename.find_last_of("/\\"); size_t lastDirectory = filename.find_last_of("/\\");
//return filename.substr( 0, filename.rfind("/")+1 );
if (lastDirectory == string::npos) { if (lastDirectory == string::npos) {
return filename; return filename;
} }
@ -982,14 +1004,10 @@ string extractFileFromDirectoryPath(string filename) {
string extractDirectoryPathFromFile(string filename) { string extractDirectoryPathFromFile(string filename) {
size_t lastDirectory = filename.find_last_of("/\\"); size_t lastDirectory = filename.find_last_of("/\\");
//printf("In [%s::%s Line: %d] filename = [%s] lastDirectory= %u\n",__FILE__,__FUNCTION__,__LINE__,filename.c_str(),lastDirectory);
string path = ""; string path = "";
//return filename.substr( 0, filename.rfind("/")+1 );
if (lastDirectory != string::npos) { if (lastDirectory != string::npos) {
path = filename.substr( 0, lastDirectory + 1); path = filename.substr( 0, lastDirectory + 1);
} }
//printf("In [%s::%s Line: %d] filename = [%s] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filename.c_str(),path.c_str());
return path; return path;
} }
@ -1356,6 +1374,16 @@ bool removeFile(string file) {
return (result == 0); return (result == 0);
} }
bool renameFile(string oldFile, string newFile) {
#ifdef WIN32
int result = _rename(oldFile.c_str(),newFile.c_str());
#else
int result = rename(oldFile.c_str(),newFile.c_str());
#endif
return (result == 0);
}
// ===================================== // =====================================
// ModeInfo // ModeInfo
// ===================================== // =====================================
@ -1371,15 +1399,19 @@ string ModeInfo::getString() const{
} }
void ValueCheckerVault::addItemToVault(const void *ptr,int value) { void ValueCheckerVault::addItemToVault(const void *ptr,int value) {
#ifndef _DISABLE MEMORY_VAULT_CHECKS #ifndef _DISABLE_MEMORY_VAULT_CHECKS
Checksum checksum; Checksum checksum;
vaultList[ptr] = checksum.addInt(value); vaultList[ptr] = checksum.addInt(value);
#endif #endif
// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] add vault key [%p] value [%s] [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,intToStr(checksum.getSum()).c_str(),value); // if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] add vault key [%p] value [%s] [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,intToStr(checksum.getSum()).c_str(),value);
} }
void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const { void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const {
#ifndef _DISABLE MEMORY_VAULT_CHECKS #ifndef _DISABLE_MEMORY_VAULT_CHECKS
map<const void *,int32>::const_iterator iterFind = vaultList.find(ptr); map<const void *,int32>::const_iterator iterFind = vaultList.find(ptr);
if(iterFind == vaultList.end()) { if(iterFind == vaultList.end()) {
// if(SystemFlags::VERBOSE_MODE_ENABLED) { // if(SystemFlags::VERBOSE_MODE_ENABLED) {
@ -1402,7 +1434,9 @@ void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const {
// } // }
throw std::runtime_error("memory value has been unexpectedly modified (changed)!"); throw std::runtime_error("memory value has been unexpectedly modified (changed)!");
} }
#endif #endif
} }

View File

@ -240,9 +240,7 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri
string destFileExt = ""; string destFileExt = "";
string destFile = this->mapsPath.second; string destFile = this->mapsPath.second;
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) { endPathWithSlash(destFile);
destFile += "/";
}
destFile += mapFileName; destFile += mapFileName;
if(EndsWith(destFile,".mgm") == false && EndsWith(destFile,".gbm") == false) { if(EndsWith(destFile,".mgm") == false && EndsWith(destFile,".gbm") == false) {
@ -388,34 +386,22 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
string destRootFolder = ""; string destRootFolder = "";
if(tileSetNameSubfolder == "") { if(tileSetNameSubfolder == "") {
destRootFolder = this->tilesetsPath.second; destRootFolder = this->tilesetsPath.second;
if( EndsWith(destRootFolder,"/") == false && endPathWithSlash(destRootFolder);
EndsWith(destRootFolder,"\\") == false) {
destRootFolder += "/";
}
destRootArchiveFolder = destRootFolder; destRootArchiveFolder = destRootFolder;
destRootFolder += tileSetName; destRootFolder += tileSetName;
if( EndsWith(destRootFolder,"/") == false && endPathWithSlash(destRootFolder);
EndsWith(destRootFolder,"\\") == false) {
destRootFolder += "/";
}
createDirectoryPaths(destRootFolder); createDirectoryPaths(destRootFolder);
} }
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) { endPathWithSlash(destFile);
destFile += "/";
}
destFile += tileSetName; destFile += tileSetName;
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) { endPathWithSlash(destFile);
destFile += "/";
}
if(tileSetNameSubfolder != "") { if(tileSetNameSubfolder != "") {
destFile += tileSetNameSubfolder; destFile += tileSetNameSubfolder;
endPathWithSlash(destFile);
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) {
destFile += "/";
}
} }
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s] findArchive = %d\n",destFile.c_str(),findArchive); if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s] findArchive = %d\n",destFile.c_str(),findArchive);
@ -580,26 +566,16 @@ FTP_Client_ResultType FTPClientThread::getTechtreeFromServer(string techtreeName
string destRootArchiveFolder = ""; string destRootArchiveFolder = "";
string destRootFolder = ""; string destRootFolder = "";
destRootFolder = this->techtreesPath.second; destRootFolder = this->techtreesPath.second;
if( EndsWith(destRootFolder,"/") == false && endPathWithSlash(destRootFolder);
EndsWith(destRootFolder,"\\") == false) {
destRootFolder += "/";
}
destRootArchiveFolder = destRootFolder; destRootArchiveFolder = destRootFolder;
destRootFolder += techtreeName; destRootFolder += techtreeName;
if( EndsWith(destRootFolder,"/") == false && endPathWithSlash(destRootFolder);
EndsWith(destRootFolder,"\\") == false) {
destRootFolder += "/";
}
createDirectoryPaths(destRootFolder); createDirectoryPaths(destRootFolder);
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) { endPathWithSlash(destFile);
destFile += "/";
}
destFile += techtreeName; destFile += techtreeName;
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) { endPathWithSlash(destFile);
destFile += "/";
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str());

View File

@ -79,9 +79,7 @@ Profiler::~Profiler(){
else { else {
string userData = config.getString("UserData_Root",""); string userData = config.getString("UserData_Root","");
if(userData != "") { if(userData != "") {
if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { endPathWithSlash(userData);
userData += "/";
}
} }
profileLog = userData + profileLog; profileLog = userData + profileLog;
} }

View File

@ -322,9 +322,10 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
vsnprintf(szBuf,max_debug_buffer_size-1,fmt, argList); vsnprintf(szBuf,max_debug_buffer_size-1,fmt, argList);
va_end(argList); va_end(argList);
if(SystemFlags::ENABLE_THREADED_LOGGING && if( currentDebugLog.debugLogFileName != "" &&
threadLogger != NULL && SystemFlags::ENABLE_THREADED_LOGGING &&
threadLogger->getRunningStatus() == true) { threadLogger != NULL &&
threadLogger->getRunningStatus() == true) {
threadLogger->addLogEntry(type, szBuf); threadLogger->addLogEntry(type, szBuf);
} }
else { else {