mirror of
https://github.com/glest/glest-source.git
synced 2025-08-15 12:54:01 +02:00
- added new commandline options to tell the game where to look for data, ini's and where to write logs
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "platform_util.h"
|
||||
#include "conversion.h"
|
||||
#include "cache_manager.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
@@ -191,9 +192,24 @@ string formatString(const string &str){
|
||||
return outStr;
|
||||
}
|
||||
|
||||
string getGameReadWritePath() {
|
||||
string getGameReadWritePath(string lookupKey) {
|
||||
string path = "";
|
||||
if(getenv("GLESTHOME") != NULL) {
|
||||
|
||||
if(lookupKey != "") {
|
||||
std::map<string,string> &pathCache = CacheManager::getCachedItem< std::map<string,string> >(GameConstants::pathCacheLookupKey);
|
||||
std::map<string,string>::const_iterator iterFind = pathCache.find(lookupKey);
|
||||
if(iterFind != pathCache.end()) {
|
||||
path = iterFind->second;
|
||||
|
||||
if(path != "" && EndsWith(path, "/") == false && EndsWith(path, "\\") == false) {
|
||||
path += "/";
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path to be used for [%s] files [%s]\n",__FILE__,__FUNCTION__,__LINE__,lookupKey.c_str(),path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if(path == "" && getenv("GLESTHOME") != NULL) {
|
||||
path = getenv("GLESTHOME");
|
||||
if(path != "" && EndsWith(path, "/") == false && EndsWith(path, "\\") == false) {
|
||||
path += "/";
|
||||
|
@@ -41,7 +41,7 @@ string getCompileDateTime();
|
||||
|
||||
string formatString(const string &str);
|
||||
|
||||
string getGameReadWritePath();
|
||||
string getGameReadWritePath(string lookupKey="");
|
||||
|
||||
}}//end namespace
|
||||
|
||||
|
@@ -17,7 +17,8 @@
|
||||
#include "metrics.h"
|
||||
#include "lang.h"
|
||||
#include "graphics_interface.h"
|
||||
|
||||
#include "game_constants.h"
|
||||
#include "game_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -35,7 +36,9 @@ const int Logger::logLineCount= 15;
|
||||
// ===================== PUBLIC ========================
|
||||
|
||||
Logger::Logger(){
|
||||
fileName= "log.txt";
|
||||
string logs_path = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey);
|
||||
|
||||
fileName= logs_path + "log.txt";
|
||||
loadingTexture=NULL;
|
||||
}
|
||||
|
||||
|
@@ -235,7 +235,8 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
|
||||
|
||||
//printf("In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,settings->getFactionTypeName(i).c_str());
|
||||
if(settings->getFactionTypeName(i) == formatString(GameConstants::OBSERVER_SLOTNAME)) {
|
||||
const string factionLogo = "data/core/misc_textures/observer.jpg";
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
const string factionLogo = data_path + "data/core/misc_textures/observer.jpg";
|
||||
//printf("In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
if(fileExists(factionLogo) == true) {
|
||||
@@ -249,7 +250,8 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
|
||||
}
|
||||
}
|
||||
else if(settings->getFactionTypeName(i) == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||
const string factionLogo = "data/core/misc_textures/random.jpg";
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
const string factionLogo = data_path + "data/core/misc_textures/random.jpg";
|
||||
//printf("In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
if(fileExists(factionLogo) == true) {
|
||||
|
@@ -107,6 +107,10 @@ public:
|
||||
static const char *RANDOMFACTION_SLOTNAME;
|
||||
|
||||
static const char *playerTextureCacheLookupKey;
|
||||
static const char *pathCacheLookupKey;
|
||||
static const char *path_data_CacheLookupKey;
|
||||
static const char *path_ini_CacheLookupKey;
|
||||
static const char *path_logs_CacheLookupKey;
|
||||
|
||||
static const char *application_name;
|
||||
};
|
||||
|
@@ -48,6 +48,15 @@ const char *GameConstants::RANDOMFACTION_SLOTNAME = "*Random*";
|
||||
const char *GameConstants::playerTextureCacheLookupKey = "playerTextureCache";
|
||||
const char *GameConstants::application_name = "MegaGlest";
|
||||
|
||||
const char *GameConstants::pathCacheLookupKey = "pathCache_";
|
||||
const char *GameConstants::path_data_CacheLookupKey = "data";
|
||||
const char *GameConstants::path_ini_CacheLookupKey = "ini";
|
||||
const char *GameConstants::path_logs_CacheLookupKey = "logs";
|
||||
|
||||
const char *Config::glest_ini_filename = "glest.ini";
|
||||
const char *Config::glestuser_ini_filename = "glestuser.ini";
|
||||
|
||||
|
||||
// =====================================================
|
||||
// class Config
|
||||
// =====================================================
|
||||
@@ -73,9 +82,9 @@ Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> f
|
||||
cfgType = type;
|
||||
|
||||
fileName = file;
|
||||
if(getGameReadWritePath() != "") {
|
||||
fileName.first = getGameReadWritePath() + fileName.first;
|
||||
fileName.second = getGameReadWritePath() + fileName.second;
|
||||
if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
|
||||
fileName.first = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName.first;
|
||||
fileName.second = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName.second;
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
|
||||
@@ -148,7 +157,7 @@ void Config::reload() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
std::pair<ConfigType,ConfigType> type = std::make_pair(cfgMainGame,cfgUserGame);
|
||||
Config newconfig(type, std::make_pair("glest.ini","glestuser.ini"), std::make_pair(true,false));
|
||||
Config newconfig(type, std::make_pair(glest_ini_filename,glestuser_ini_filename), std::make_pair(true,false));
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
@@ -382,46 +391,51 @@ string Config::toString(){
|
||||
vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
||||
vector<string> pathList;
|
||||
|
||||
//#include "game_constants.h"
|
||||
//#include "game_util.h"
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
|
||||
string userData = getString("UserData_Root","");
|
||||
if(userData != "") {
|
||||
if(userData[userData.size()-1] != '/' && userData[userData.size()-1] != '\\') {
|
||||
userData += '/';
|
||||
}
|
||||
userData=data_path+userData;
|
||||
if(isdir(userData.c_str()) == false) {
|
||||
createDirectoryPaths(userData);
|
||||
}
|
||||
}
|
||||
if(scenarioDir != "") {
|
||||
pathList.push_back(scenarioDir);
|
||||
pathList.push_back(data_path+scenarioDir);
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case ptMaps:
|
||||
pathList.push_back(GameConstants::folder_path_maps);
|
||||
pathList.push_back(data_path+GameConstants::folder_path_maps);
|
||||
if(userData != "") {
|
||||
pathList.push_back(userData + string(GameConstants::folder_path_maps));
|
||||
}
|
||||
break;
|
||||
case ptScenarios:
|
||||
pathList.push_back(GameConstants::folder_path_scenarios);
|
||||
pathList.push_back(data_path+GameConstants::folder_path_scenarios);
|
||||
if(userData != "") {
|
||||
pathList.push_back(userData + string(GameConstants::folder_path_scenarios));
|
||||
}
|
||||
break;
|
||||
case ptTechs:
|
||||
pathList.push_back(GameConstants::folder_path_techs);
|
||||
pathList.push_back(data_path+GameConstants::folder_path_techs);
|
||||
if(userData != "") {
|
||||
pathList.push_back(userData + string(GameConstants::folder_path_techs));
|
||||
}
|
||||
break;
|
||||
case ptTilesets:
|
||||
pathList.push_back(GameConstants::folder_path_tilesets);
|
||||
pathList.push_back(data_path+GameConstants::folder_path_tilesets);
|
||||
if(userData != "") {
|
||||
pathList.push_back(userData + string(GameConstants::folder_path_tilesets));
|
||||
}
|
||||
break;
|
||||
case ptTutorials:
|
||||
pathList.push_back(GameConstants::folder_path_tutorials);
|
||||
pathList.push_back(data_path+GameConstants::folder_path_tutorials);
|
||||
if(userData != "") {
|
||||
pathList.push_back(userData + string(GameConstants::folder_path_tutorials));
|
||||
}
|
||||
|
@@ -34,7 +34,6 @@ enum ConfigType {
|
||||
cfgUserKeys
|
||||
};
|
||||
|
||||
|
||||
class Config {
|
||||
private:
|
||||
std::pair<Properties,Properties> properties;
|
||||
@@ -44,6 +43,9 @@ private:
|
||||
|
||||
static map<ConfigType,Config> configList;
|
||||
|
||||
static const char *glest_ini_filename;
|
||||
static const char *glestuser_ini_filename;
|
||||
|
||||
protected:
|
||||
Config();
|
||||
Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist);
|
||||
@@ -54,7 +56,7 @@ protected:
|
||||
|
||||
public:
|
||||
static Config &getInstance(std::pair<ConfigType,ConfigType> type = std::make_pair(cfgMainGame,cfgUserGame) ,
|
||||
std::pair<string,string> file = std::make_pair("glest.ini","glestuser.ini") ,
|
||||
std::pair<string,string> file = std::make_pair(glest_ini_filename,glestuser_ini_filename) ,
|
||||
std::pair<bool,bool> fileMustExist = std::make_pair(true,false) );
|
||||
void save(const string &path="");
|
||||
void reload();
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "platform_util.h"
|
||||
#include "game_constants.h"
|
||||
#include "game_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Sound;
|
||||
@@ -41,7 +43,9 @@ CoreData::~CoreData(){
|
||||
}
|
||||
|
||||
void CoreData::load() {
|
||||
const string dir="data/core";
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
|
||||
const string dir = data_path + "data/core";
|
||||
Logger::getInstance().add("Core data");
|
||||
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
@@ -63,7 +67,7 @@ void CoreData::load(){
|
||||
snowTexture->getPixmap()->load(dir+"/misc_textures/snow_particle.tga");
|
||||
|
||||
customTexture= renderer.newTexture2D(rsGlobal);
|
||||
customTexture->getPixmap()->load("data/core/menu/textures/custom_texture.tga");
|
||||
customTexture->getPixmap()->load(dir+"/menu/textures/custom_texture.tga");
|
||||
|
||||
logoTexture= renderer.newTexture2D(rsGlobal);
|
||||
logoTexture->setMipmap(false);
|
||||
|
@@ -16,6 +16,8 @@
|
||||
#include "logger.h"
|
||||
#include "util.h"
|
||||
#include "platform_util.h"
|
||||
#include "game_constants.h"
|
||||
#include "game_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -36,7 +38,8 @@ Lang &Lang::getInstance(){
|
||||
void Lang::loadStrings(const string &language){
|
||||
this->language= language;
|
||||
strings.clear();
|
||||
strings.load("data/lang/"+language+".lng");
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
strings.load(data_path + "data/lang/"+language+".lng");
|
||||
}
|
||||
|
||||
void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenarioName){
|
||||
|
@@ -82,7 +82,10 @@ const char *GAME_ARGS[] = {
|
||||
"--sdl-info",
|
||||
"--lua-info",
|
||||
"--validate-techtrees",
|
||||
"--validate-factions"
|
||||
"--validate-factions",
|
||||
"--data-path",
|
||||
"--ini-path",
|
||||
"--log-path"
|
||||
|
||||
};
|
||||
|
||||
@@ -97,7 +100,10 @@ enum GAME_ARG_TYPE {
|
||||
GAME_ARG_SDL_INFO,
|
||||
GAME_ARG_LUA_INFO,
|
||||
GAME_ARG_VALIDATE_TECHTREES,
|
||||
GAME_ARG_VALIDATE_FACTIONS
|
||||
GAME_ARG_VALIDATE_FACTIONS,
|
||||
GAME_ARG_DATA_PATH,
|
||||
GAME_ARG_INI_PATH,
|
||||
GAME_ARG_LOG_PATH
|
||||
};
|
||||
|
||||
string runtimeErrorMsg = "";
|
||||
@@ -603,6 +609,12 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n \t\t*NOTE: leaving the list empty is the same as running");
|
||||
printf("\n \t\t%s",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
|
||||
printf("\n \t\texample: %s %s=tech,egypt",argv0,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]);
|
||||
printf("\n%s=x\t\t\tSets the game data path to x",GAME_ARGS[GAME_ARG_DATA_PATH]);
|
||||
printf("\n \t\texample: %s %s=/usr/local/game_data/",argv0,GAME_ARGS[GAME_ARG_DATA_PATH]);
|
||||
printf("\n%s=x\t\t\tSets the game ini path to x",GAME_ARGS[GAME_ARG_INI_PATH]);
|
||||
printf("\n \t\texample: %s %s=~/game_config/",argv0,GAME_ARGS[GAME_ARG_INI_PATH]);
|
||||
printf("\n%s=x\t\t\tSets the game logs path to x",GAME_ARGS[GAME_ARG_LOG_PATH]);
|
||||
printf("\n \t\texample: %s %s=~/game_logs/",argv0,GAME_ARGS[GAME_ARG_LOG_PATH]);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
@@ -683,6 +695,79 @@ int glestMain(int argc, char** argv) {
|
||||
exceptionHandler.install( getCrashDumpFileName() );
|
||||
|
||||
try {
|
||||
// Setup path cache for files and folders used in the game
|
||||
std::map<string,string> &pathCache = CacheManager::getCachedItem< std::map<string,string> >(GameConstants::pathCacheLookupKey);
|
||||
|
||||
//GAME_ARG_DATA_PATH
|
||||
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_DATA_PATH]) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_DATA_PATH]) + string("="),&foundParamIndIndex);
|
||||
if(foundParamIndIndex < 0) {
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_DATA_PATH]),&foundParamIndIndex);
|
||||
}
|
||||
string customPath = argv[foundParamIndIndex];
|
||||
vector<string> paramPartTokens;
|
||||
Tokenize(customPath,paramPartTokens,"=");
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
string customPathValue = paramPartTokens[1];
|
||||
pathCache[GameConstants::path_data_CacheLookupKey]=customPathValue;
|
||||
printf("Using custom data path [%s]\n",customPathValue.c_str());
|
||||
}
|
||||
else {
|
||||
|
||||
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
|
||||
printParameterHelp(argv[0],foundInvalidArgs);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//GAME_ARG_INI_PATH
|
||||
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_INI_PATH]) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_INI_PATH]) + string("="),&foundParamIndIndex);
|
||||
if(foundParamIndIndex < 0) {
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_INI_PATH]),&foundParamIndIndex);
|
||||
}
|
||||
string customPath = argv[foundParamIndIndex];
|
||||
vector<string> paramPartTokens;
|
||||
Tokenize(customPath,paramPartTokens,"=");
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
string customPathValue = paramPartTokens[1];
|
||||
pathCache[GameConstants::path_ini_CacheLookupKey]=customPathValue;
|
||||
printf("Using custom ini path [%s]\n",customPathValue.c_str());
|
||||
}
|
||||
else {
|
||||
|
||||
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
|
||||
printParameterHelp(argv[0],foundInvalidArgs);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//GAME_ARG_LOG_PATH
|
||||
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LOG_PATH]) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_LOG_PATH]) + string("="),&foundParamIndIndex);
|
||||
if(foundParamIndIndex < 0) {
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_LOG_PATH]),&foundParamIndIndex);
|
||||
}
|
||||
string customPath = argv[foundParamIndIndex];
|
||||
vector<string> paramPartTokens;
|
||||
Tokenize(customPath,paramPartTokens,"=");
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
string customPathValue = paramPartTokens[1];
|
||||
pathCache[GameConstants::path_logs_CacheLookupKey]=customPathValue;
|
||||
printf("Using custom logs path [%s]\n",customPathValue.c_str());
|
||||
}
|
||||
else {
|
||||
|
||||
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
|
||||
printParameterHelp(argv[0],foundInvalidArgs);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::auto_ptr<FileCRCPreCacheThread> preCacheThread;
|
||||
Config &config = Config::getInstance();
|
||||
FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str()));
|
||||
@@ -699,33 +784,57 @@ int glestMain(int argc, char** argv) {
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled = config.getBool("DebugError","true");
|
||||
|
||||
string debugLogFile = config.getString("DebugLogFile","");
|
||||
if(getGameReadWritePath() != "") {
|
||||
debugLogFile = getGameReadWritePath() + debugLogFile;
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
debugLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugLogFile;
|
||||
}
|
||||
string debugWorldSynchLogFile = config.getString("DebugLogFileWorldSynch","");
|
||||
if(debugWorldSynchLogFile == "") {
|
||||
debugWorldSynchLogFile = debugLogFile;
|
||||
}
|
||||
else {
|
||||
debugWorldSynchLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugWorldSynchLogFile;
|
||||
}
|
||||
|
||||
string debugPerformanceLogFile = config.getString("DebugLogFilePerformance","");
|
||||
if(debugPerformanceLogFile == "") {
|
||||
debugPerformanceLogFile = debugLogFile;
|
||||
}
|
||||
else {
|
||||
debugPerformanceLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugPerformanceLogFile;
|
||||
}
|
||||
|
||||
string debugNetworkLogFile = config.getString("DebugLogFileNetwork","");
|
||||
if(debugNetworkLogFile == "") {
|
||||
debugNetworkLogFile = debugLogFile;
|
||||
}
|
||||
else {
|
||||
debugNetworkLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugNetworkLogFile;
|
||||
}
|
||||
|
||||
string debugUnitCommandsLogFile = config.getString("DebugLogFileUnitCommands","");
|
||||
if(debugUnitCommandsLogFile == "") {
|
||||
debugUnitCommandsLogFile = debugLogFile;
|
||||
}
|
||||
else {
|
||||
debugUnitCommandsLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugUnitCommandsLogFile;
|
||||
}
|
||||
|
||||
string debugPathFinderLogFile = config.getString("DebugLogFilePathFinder","");
|
||||
if(debugUnitCommandsLogFile == "") {
|
||||
debugUnitCommandsLogFile = debugLogFile;
|
||||
}
|
||||
else {
|
||||
debugUnitCommandsLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugUnitCommandsLogFile;
|
||||
}
|
||||
|
||||
string debugLUALogFile = config.getString("DebugLogFileLUA","");
|
||||
if(debugLUALogFile == "") {
|
||||
debugLUALogFile = debugLogFile;
|
||||
}
|
||||
else {
|
||||
debugLUALogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugLUALogFile;
|
||||
}
|
||||
|
||||
string debugErrorLogFile = config.getString("DebugLogFileError","");
|
||||
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).debugLogFileName = debugLogFile;
|
||||
@@ -1053,10 +1162,11 @@ int glestMain(int argc, char** argv) {
|
||||
//printf("In [%s::%s Line: %d] screenShotsPath [%s]\n",__FILE__,__FUNCTION__,__LINE__,screenShotsPath.c_str());
|
||||
}
|
||||
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
// Cache Player textures - START
|
||||
std::map<int,Texture2D *> &crcPlayerTextureCache = CacheManager::getCachedItem< std::map<int,Texture2D *> >(GameConstants::playerTextureCacheLookupKey);
|
||||
for(int index = 0; index < GameConstants::maxPlayers; ++index) {
|
||||
string playerTexture = "data/core/faction_textures/faction" + intToStr(index) + ".tga";
|
||||
string playerTexture = data_path + "data/core/faction_textures/faction" + intToStr(index) + ".tga";
|
||||
if(fileExists(playerTexture) == true) {
|
||||
Texture2D *texture = Renderer::getInstance().newTexture2D(rsGlobal);
|
||||
texture->load(playerTexture);
|
||||
|
@@ -495,8 +495,8 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
|
||||
//log start
|
||||
Logger &logger= Logger::getInstance();
|
||||
string logFile = "glest.log";
|
||||
if(getGameReadWritePath() != "") {
|
||||
logFile = getGameReadWritePath() + logFile;
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
logFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + logFile;
|
||||
}
|
||||
logger.setFile(logFile);
|
||||
logger.clear();
|
||||
|
@@ -200,10 +200,11 @@ MenuState::MenuState(Program *program, MainMenu *mainMenu, const string &stateNa
|
||||
float configVolume = (config.getInt("SoundVolumeMusic") / 100.f);
|
||||
CoreData::getInstance().getMenuMusic()->setVolume(configVolume);
|
||||
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
|
||||
//camera
|
||||
XmlTree xmlTree;
|
||||
xmlTree.load("data/core/menu/menu.xml");
|
||||
xmlTree.load(data_path + "data/core/menu/menu.xml");
|
||||
const XmlNode *menuNode= xmlTree.getRootNode();
|
||||
const XmlNode *cameraNode= menuNode->getChild("camera");
|
||||
|
||||
|
182
source/glest_game/menu/menu_background.cpp
Normal file
182
source/glest_game/menu/menu_background.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#include "menu_background.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "renderer.h"
|
||||
#include "core_data.h"
|
||||
#include "config.h"
|
||||
#include "xml_parser.h"
|
||||
#include "util.h"
|
||||
#include "game_constants.h"
|
||||
#include "game_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Xml;
|
||||
using namespace Shared::Graphics;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
// =====================================================
|
||||
// class MenuBackground
|
||||
// =====================================================
|
||||
|
||||
MenuBackground::MenuBackground(){
|
||||
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
|
||||
//load data
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
|
||||
XmlTree xmlTree;
|
||||
xmlTree.load(data_path + "data/core/menu/menu.xml");
|
||||
const XmlNode *menuNode= xmlTree.getRootNode();
|
||||
|
||||
//water
|
||||
const XmlNode *waterNode= menuNode->getChild("water");
|
||||
water= waterNode->getAttribute("value")->getBoolValue();
|
||||
if(water){
|
||||
waterHeight= waterNode->getAttribute("height")->getFloatValue();
|
||||
|
||||
//water texture
|
||||
waterTexture= renderer.newTexture2D(rsMenu);
|
||||
waterTexture->getPixmap()->init(4);
|
||||
waterTexture->getPixmap()->load(data_path + "data/core/menu/textures/water.tga");
|
||||
}
|
||||
|
||||
//fog
|
||||
const XmlNode *fogNode= menuNode->getChild("fog");
|
||||
fog= fogNode->getAttribute("value")->getBoolValue();
|
||||
if(fog){
|
||||
fogDensity= fogNode->getAttribute("density")->getFloatValue();
|
||||
}
|
||||
|
||||
//rain
|
||||
rain= menuNode->getChild("rain")->getAttribute("value")->getBoolValue();
|
||||
if(rain){
|
||||
RainParticleSystem *rps= new RainParticleSystem();
|
||||
rps->setSpeed(12.f/GameConstants::updateFps);
|
||||
rps->setEmissionRate(25);
|
||||
rps->setWind(-90.f, 4.f/GameConstants::updateFps);
|
||||
rps->setPos(Vec3f(0.f, 25.f, 0.f));
|
||||
rps->setColor(Vec4f(1.f, 1.f, 1.f, 0.2f));
|
||||
rps->setRadius(30.f);
|
||||
renderer.manageParticleSystem(rps, rsMenu);
|
||||
|
||||
for(int i=0; i<raindropCount; ++i){
|
||||
raindropStates[i]= random.randRange(0.f, 1.f);
|
||||
raindropPos[i]= computeRaindropPos();
|
||||
}
|
||||
}
|
||||
|
||||
//camera
|
||||
const XmlNode *cameraNode= menuNode->getChild("camera");
|
||||
|
||||
//position
|
||||
const XmlNode *positionNode= cameraNode->getChild("start-position");
|
||||
Vec3f startPosition;
|
||||
startPosition.x= positionNode->getAttribute("x")->getFloatValue();
|
||||
startPosition.y= positionNode->getAttribute("y")->getFloatValue();
|
||||
startPosition.z= positionNode->getAttribute("z")->getFloatValue();
|
||||
camera.setPosition(startPosition);
|
||||
|
||||
//rotation
|
||||
const XmlNode *rotationNode= cameraNode->getChild("start-rotation");
|
||||
Vec3f startRotation;
|
||||
startRotation.x= rotationNode->getAttribute("x")->getFloatValue();
|
||||
startRotation.y= rotationNode->getAttribute("y")->getFloatValue();
|
||||
startRotation.z= rotationNode->getAttribute("z")->getFloatValue();
|
||||
camera.setOrientation(Quaternion(EulerAngles(
|
||||
degToRad(startRotation.x),
|
||||
degToRad(startRotation.y),
|
||||
degToRad(startRotation.z))));
|
||||
|
||||
//load main model
|
||||
mainModel= renderer.newModel(rsMenu);
|
||||
mainModel->load(data_path + "data/core/menu/main_model/menu_main.g3d");
|
||||
|
||||
//models
|
||||
for(int i=0; i<5; ++i){
|
||||
characterModels[i]= renderer.newModel(rsMenu);
|
||||
characterModels[i]->load(data_path + "data/core/menu/about_models/character"+intToStr(i)+".g3d");
|
||||
}
|
||||
|
||||
//about position
|
||||
positionNode= cameraNode->getChild("about-position");
|
||||
aboutPosition.x= positionNode->getAttribute("x")->getFloatValue();
|
||||
aboutPosition.y= positionNode->getAttribute("y")->getFloatValue();
|
||||
aboutPosition.z= positionNode->getAttribute("z")->getFloatValue();
|
||||
rotationNode= cameraNode->getChild("about-rotation");
|
||||
|
||||
targetCamera= NULL;
|
||||
t= 0.f;
|
||||
fade= 0.f;
|
||||
anim= 0.f;
|
||||
}
|
||||
|
||||
void MenuBackground::setTargetCamera(const Camera *targetCamera){
|
||||
this->targetCamera= targetCamera;
|
||||
this->lastCamera= camera;
|
||||
t= 0.f;
|
||||
}
|
||||
|
||||
void MenuBackground::update(){
|
||||
|
||||
//rain drops
|
||||
for(int i=0; i<raindropCount; ++i){
|
||||
raindropStates[i]+= 1.f / GameConstants::updateFps;
|
||||
if(raindropStates[i]>=1.f){
|
||||
raindropStates[i]= 0.f;
|
||||
raindropPos[i]= computeRaindropPos();
|
||||
}
|
||||
}
|
||||
|
||||
if(targetCamera!=NULL){
|
||||
t+= ((0.01f+(1.f-t)/10.f)/20.f)*(60.f/GameConstants::updateFps);
|
||||
|
||||
//interpolate position
|
||||
camera.setPosition(lastCamera.getPosition().lerp(t, targetCamera->getPosition()));
|
||||
|
||||
//interpolate orientation
|
||||
Quaternion q= lastCamera.getOrientation().lerp(t, targetCamera->getOrientation());
|
||||
camera.setOrientation(q);
|
||||
|
||||
if(t>=1.f){
|
||||
targetCamera= NULL;
|
||||
t= 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
//fade
|
||||
if(fade<=1.f){
|
||||
fade+= 0.6f/GameConstants::updateFps;
|
||||
if(fade>1.f){
|
||||
fade= 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
//animation
|
||||
anim+=(0.6f/GameConstants::updateFps)/5+random.randRange(0.f, (0.6f/GameConstants::updateFps)/5.f);
|
||||
if(anim>1.f){
|
||||
anim= 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
Vec2f MenuBackground::computeRaindropPos(){
|
||||
float f= static_cast<float>(meshSize);
|
||||
return Vec2f(random.randRange(-f, f), random.randRange(-f, f));
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
@@ -2116,8 +2116,8 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
||||
void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(getGameReadWritePath() != "") {
|
||||
fileName = getGameReadWritePath() + fileName;
|
||||
if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
|
||||
fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName;
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
|
||||
@@ -2174,8 +2174,8 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
||||
|
||||
GameSettings gameSettings;
|
||||
|
||||
if(getGameReadWritePath() != "") {
|
||||
fileName = getGameReadWritePath() + fileName;
|
||||
if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
|
||||
fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName;
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str());
|
||||
|
@@ -54,8 +54,8 @@ MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool
|
||||
networkManager.init(nrClient);
|
||||
|
||||
serversSavedFile = serverFileName;
|
||||
if(getGameReadWritePath() != "") {
|
||||
serversSavedFile = getGameReadWritePath() + serversSavedFile;
|
||||
if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
|
||||
serversSavedFile = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + serversSavedFile;
|
||||
}
|
||||
|
||||
servers.load(serversSavedFile);
|
||||
|
@@ -123,7 +123,9 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
|
||||
listBoxLang.registerGraphicComponent(containerName,"listBoxLang");
|
||||
listBoxLang.init(leftColumnStart, leftline, 170);
|
||||
vector<string> langResults;
|
||||
findAll("data/lang/*.lng", langResults, true);
|
||||
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
findAll(data_path + "data/lang/*.lng", langResults, true);
|
||||
if(langResults.empty()){
|
||||
throw runtime_error("There is no lang file");
|
||||
}
|
||||
|
@@ -80,7 +80,8 @@ void Faction::init(
|
||||
}
|
||||
|
||||
texture= Renderer::getInstance().newTexture2D(rsGame);
|
||||
texture->load("data/core/faction_textures/faction"+intToStr(startLocationIndex)+".tga");
|
||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||
texture->load(data_path + "data/core/faction_textures/faction"+intToStr(startLocationIndex)+".tga");
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
@@ -1357,8 +1357,8 @@ int World::getNextUnitId(Faction *faction) {
|
||||
std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
|
||||
|
||||
string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log");
|
||||
if(getGameReadWritePath() != "") {
|
||||
debugWorldLogFile = getGameReadWritePath() + debugWorldLogFile;
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
debugWorldLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugWorldLogFile;
|
||||
}
|
||||
|
||||
if(consoleBasicInfoOnly == true) {
|
||||
|
@@ -73,8 +73,8 @@ Profiler::~Profiler(){
|
||||
rootSection->stop();
|
||||
|
||||
string profileLog = "profiler.log";
|
||||
if(getGameReadWritePath() != "") {
|
||||
profileLog = getGameReadWritePath() + profileLog;
|
||||
if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
|
||||
profileLog = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + profileLog;
|
||||
}
|
||||
FILE *f= fopen(profileLog.c_str(), "w");
|
||||
if(f==NULL)
|
||||
|
Reference in New Issue
Block a user