- moved map path into config class

- proper render performance calc compare
This commit is contained in:
SoftCoder 2013-12-16 23:54:33 -08:00
parent ca12b7912a
commit a56eb83c91
14 changed files with 82 additions and 80 deletions

View File

@ -1145,7 +1145,7 @@ void Game::load(int loadTypes) {
//map
if((loadTypes & lgt_Map) == lgt_Map) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum);
world.loadMap(Config::getMapPath(mapName,scenarioDir), &checksum);
}
if(showPerfStats) {
@ -2763,9 +2763,12 @@ string Game::getGamePerformanceCounts(bool displayWarnings) const {
for(std::map<string,int64>::const_iterator iterMap = gamePerformanceCounts.begin();
iterMap != gamePerformanceCounts.end(); ++iterMap) {
if(iterMap->first == ProgramState::MAIN_PROGRAM_RENDER_KEY) {
if(iterMap->second > WARNING_RENDER_MILLIS) {
if(iterMap->second < WARNING_RENDER_MILLIS) {
continue;
}
//else {
// printf("iterMap->second: " MG_I64_SPECIFIER " WARNING_RENDER_MILLIS = %d\n",iterMap->second,WARNING_RENDER_MILLIS);
//}
}
else if(iterMap->second < WARNING_MILLIS) {
continue;

View File

@ -860,4 +860,32 @@ string Config::findValidLocalFileFromPath(string fileName) {
}
// static
string Config::getMapPath(const string &mapName, string scenarioDir, bool errorOnNotFound) {
Config &config = Config::getInstance();
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
for(int idx = 0; idx < (int)pathList.size(); idx++) {
string map_path = pathList[idx];
endPathWithSlash(map_path);
const string mega = map_path + mapName + ".mgm";
const string glest = map_path + mapName + ".gbm";
if (fileExists(mega)) {
return mega;
}
else if (fileExists(glest)) {
return glest;
}
}
if(errorOnNotFound == true) {
//abort();
throw megaglest_runtime_error("Map not found [" + mapName + "]\nScenario [" + scenarioDir + "]");
}
return "";
}
}}// end namespace

View File

@ -121,6 +121,8 @@ public:
static void setCustomRuntimeProperty(string key, string value) { customRuntimeProperties[key] = value; }
static string findValidLocalFileFromPath(string fileName);
static string getMapPath(const string &mapName, string scenarioDir="", bool errorOnNotFound=true);
};
}}//end namespace

View File

@ -3461,7 +3461,7 @@ int handleShowCRCValuesCommand(int argc, char** argv) {
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string itemName = paramPartTokens[1];
string file = Map::getMapPath(itemName,"",false);
string file = Config::getMapPath(itemName,"",false);
if(file != "") {
Checksum checksum;
checksum.addFile(file);

View File

@ -1692,7 +1692,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
if(loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true) == true) {
if(loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true) == true) {
labelMapInfo.setText(mapInfo.desc);
}
else {
@ -2217,7 +2217,7 @@ void MenuStateConnectedGame::loadGameSettings(GameSettings *gameSettings) {
if(gameSettings->getMap() != "") {
if(lastCheckedCRCMapName != gameSettings->getMap()) {
Checksum checksum;
string file = Map::getMapPath(gameSettings->getMap(),"",false);
string file = Config::getMapPath(gameSettings->getMap(),"",false);
//console.addLine("Checking map CRC [" + file + "]");
checksum.addFile(file);
lastCheckedCRCMapValue = checksum.getSum();
@ -2852,7 +2852,7 @@ void MenuStateConnectedGame::update() {
if(lastCheckedCRCMapName != gameSettings->getMap() &&
gameSettings->getMap() != "") {
Checksum checksum;
string file = Map::getMapPath(gameSettings->getMap(),"",false);
string file = Config::getMapPath(gameSettings->getMap(),"",false);
//console.addLine("Checking map CRC [" + file + "]");
checksum.addFile(file);
mapCRC = checksum.getSum();
@ -3889,7 +3889,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
if(result.first == ftp_crt_SUCCESS) {
// Clear the CRC file Cache
string file = Map::getMapPath(itemName,"",false);
string file = Config::getMapPath(itemName,"",false);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got map itemName [%s] file [%s] lastCheckedCRCMapName [%s] gameSettings->getMap() [%s]\n",
itemName.c_str(),file.c_str(),lastCheckedCRCMapName.c_str(),gameSettings->getMap().c_str());
@ -4451,7 +4451,7 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
if(currentMap != gameSettings->getMap()) {// load the setup again
currentMap = gameSettings->getMap();
}
bool mapLoaded = loadMapInfo(Map::getMapPath(currentMap,scenarioDir,false), &mapInfo, true);
bool mapLoaded = loadMapInfo(Config::getMapPath(currentMap,scenarioDir,false), &mapInfo, true);
if(mapLoaded == true) {
if(find(maps.begin(),maps.end(),formatString(gameSettings->getMap())) == maps.end()) {
maps.push_back(formatString(gameSettings->getMap()));
@ -4809,11 +4809,11 @@ int MenuStateConnectedGame::setupMapList(string scenario) {
formattedMapFiles.clear();
for(int i= 0; i < (int)mapFiles.size(); i++){// fetch info and put map in right list
loadMapInfo(Map::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false);
loadMapInfo(Config::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false);
if(GameConstants::maxPlayers+1 <= mapInfo.players) {
char szBuf[8096]="";
snprintf(szBuf,8096,"Sorted map list [%d] does not match\ncurrent map playercount [%d]\nfor file [%s]\nmap [%s]",GameConstants::maxPlayers+1,mapInfo.players,Map::getMapPath(mapFiles.at(i), "", false).c_str(),mapInfo.desc.c_str());
snprintf(szBuf,8096,"Sorted map list [%d] does not match\ncurrent map playercount [%d]\nfor file [%s]\nmap [%s]",GameConstants::maxPlayers+1,mapInfo.players,Config::getMapPath(mapFiles.at(i), "", false).c_str(),mapInfo.desc.c_str());
throw megaglest_runtime_error(szBuf);
}
playerSortedMaps[mapInfo.players].push_back(mapFiles.at(i));
@ -4828,7 +4828,7 @@ int MenuStateConnectedGame::setupMapList(string scenario) {
string file = Scenario::getScenarioPath(dirList, scenario);
loadScenarioInfo(file, &scenarioInfo);
loadMapInfo(Map::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
loadMapInfo(Config::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = " MG_SIZE_T_SPECIFIER ", mapInfo.players = %d, formattedPlayerSortedMaps[mapInfo.players].size() = " MG_SIZE_T_SPECIFIER ", scenarioInfo.mapName [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxMap.getSelectedItemIndex(),mapFiles.size(),mapInfo.players,formattedPlayerSortedMaps[mapInfo.players].size(),scenarioInfo.mapName.c_str());
listBoxMap.setItems(formattedPlayerSortedMaps[mapInfo.players]);

View File

@ -609,7 +609,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
labelNetStatus[i].setText("");
}
loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true);
loadMapInfo(Config::getMapPath(getCurrentMapFile()), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -1081,7 +1081,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
updateControlers();
updateNetworkSlots();
@ -1224,7 +1224,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true);
loadMapInfo(Config::getMapPath(getCurrentMapFile()), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
updateControlers();
updateNetworkSlots();
@ -3672,7 +3672,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
if(lastCheckedCRCMapName != gameSettings->getMap()) {
Checksum checksum;
string file = Map::getMapPath(gameSettings->getMap(),"",false);
string file = Config::getMapPath(gameSettings->getMap(),"",false);
//console.addLine("Checking map CRC [" + file + "]");
checksum.addFile(file);
lastCheckedCRCMapValue = checksum.getSum();
@ -3821,7 +3821,7 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
//loadScenarioInfo(file, &scenarioInfo);
//printf("#6.1 about to load map [%s]\n",scenarioInfo.mapName.c_str());
//loadMapInfo(Map::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
//loadMapInfo(Config::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
//printf("#6.2\n");
listBoxMapFilter.setSelectedItemIndex(0);
@ -3845,7 +3845,7 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
mapFile = formatString(mapFile);
listBoxMap.setSelectedItem(mapFile);
loadMapInfo(Map::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true);
loadMapInfo(Config::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
}
@ -4509,7 +4509,7 @@ void MenuStateCustomGame::processScenario() {
setupMapList(scenarioInfo.name);
listBoxMap.setSelectedItem(formatString(scenarioInfo.mapName));
loadMapInfo(Map::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true);
loadMapInfo(Config::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
//printf("scenarioInfo.name [%s] [%s]\n",scenarioInfo.name.c_str(),listBoxMap.getSelectedItem().c_str());
@ -4638,7 +4638,7 @@ void MenuStateCustomGame::processScenario() {
else {
setupMapList("");
listBoxMap.setSelectedItem(formatString(formattedPlayerSortedMaps[0][0]));
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",true), &mapInfo, true);
loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",true), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
setupTechList("", false);
@ -4746,11 +4746,11 @@ int MenuStateCustomGame::setupMapList(string scenario) {
//printf("#5\n");
for(int i= 0; i < (int)mapFiles.size(); i++){// fetch info and put map in right list
loadMapInfo(Map::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false);
loadMapInfo(Config::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false);
if(GameConstants::maxPlayers+1 <= mapInfo.players) {
char szBuf[8096]="";
snprintf(szBuf,8096,"Sorted map list [%d] does not match\ncurrent map playercount [%d]\nfor file [%s]\nmap [%s]",GameConstants::maxPlayers+1,mapInfo.players,Map::getMapPath(mapFiles.at(i), "", false).c_str(),mapInfo.desc.c_str());
snprintf(szBuf,8096,"Sorted map list [%d] does not match\ncurrent map playercount [%d]\nfor file [%s]\nmap [%s]",GameConstants::maxPlayers+1,mapInfo.players,Config::getMapPath(mapFiles.at(i), "", false).c_str(),mapInfo.desc.c_str());
throw megaglest_runtime_error(szBuf);
}
playerSortedMaps[mapInfo.players].push_back(mapFiles.at(i));
@ -4766,7 +4766,7 @@ int MenuStateCustomGame::setupMapList(string scenario) {
loadScenarioInfo(file, &scenarioInfo);
//printf("#6.1 about to load map [%s]\n",scenarioInfo.mapName.c_str());
loadMapInfo(Map::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
loadMapInfo(Config::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
//printf("#6.2\n");
listBoxMapFilter.setSelectedItem(intToStr(mapInfo.players));
listBoxMap.setItems(formattedPlayerSortedMaps[mapInfo.players]);

View File

@ -11,18 +11,18 @@
#include "client_interface.h"
#include <stdexcept>
#include <cassert>
#include "logger.h"
#include "window.h"
#include "platform_util.h"
#include "game_util.h"
#include "conversion.h"
#include "config.h"
#include "lang.h"
#include "map.h"
#include "config.h"
#include "logger.h"
#include "window.h"
#include <stdexcept>
#include <cassert>
#include "leak_dumper.h"
using namespace std;
@ -741,7 +741,7 @@ void ClientInterface::updateLobby() {
//map
Checksum checksum;
string file = Map::getMapPath(networkMessageSynchNetworkGameData.getMap(),scenarioDir, false);
string file = Config::getMapPath(networkMessageSynchNetworkGameData.getMap(),scenarioDir, false);
if(file != "") {
checksum.addFile(file);
mapCRC = checksum.getSum();

View File

@ -11,17 +11,15 @@
#include "connection_slot.h"
#include <stdexcept>
#include "conversion.h"
#include "game_util.h"
#include "config.h"
#include "server_interface.h"
#include "network_message.h"
#include "leak_dumper.h"
#include "platform_util.h"
#include "map.h"
#include <stdexcept>
#include "leak_dumper.h"
using namespace std;
using namespace Shared::Util;
@ -1190,7 +1188,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
uint32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), ".xml", NULL);
uint32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", NULL);
Checksum checksum;
string file = Map::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir,false);
string file = Config::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir,false);
checksum.addFile(file);
uint32 mapCRC = checksum.getSum();
@ -1247,7 +1245,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
this->setNetworkGameDataSynchCheckTechMismatchReport(report);
}
if(networkGameDataSynchCheckOkMap == false) {
vctFileList.push_back(std::pair<string,uint32>(Map::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir,false),mapCRC));
vctFileList.push_back(std::pair<string,uint32>(Config::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir,false),mapCRC));
}
//for(int i = 0; i < vctFileList.size(); i++)

View File

@ -12,11 +12,12 @@
#ifndef _GLEST_GAME_CONNECTIONSLOT_H_
#define _GLEST_GAME_CONNECTIONSLOT_H_
#include <vector>
#include "socket.h"
#include "network_interface.h"
#include <time.h>
#include "base_thread.h"
#include <time.h>
#include <vector>
#include "leak_dumper.h"
using Shared::Platform::ServerSocket;

View File

@ -11,19 +11,16 @@
#include "network_message.h"
#include <cassert>
#include <stdexcept>
#include "data_types.h"
#include "util.h"
#include "game_settings.h"
#include "checksum.h"
#include "map.h"
#include "platform_util.h"
#include "config.h"
#include <algorithm>
#include "network_protocol.h"
#include <algorithm>
#include <cassert>
#include <stdexcept>
#include "leak_dumper.h"
@ -1887,7 +1884,7 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam
//map
Checksum checksum;
string file = Map::getMapPath(gameSettings->getMap(),scenarioDir,false);
string file = Config::getMapPath(gameSettings->getMap(),scenarioDir,false);
checksum.addFile(file);
data.header.mapCRC = checksum.getSum();

View File

@ -16,6 +16,7 @@
#include "game_constants.h"
#include "network_types.h"
#include "byte_order.h"
#include "leak_dumper.h"
using Shared::Platform::Socket;

View File

@ -13,22 +13,23 @@
#include <stdexcept>
#include "window.h"
#include "logger.h"
#include "platform_util.h"
#include "conversion.h"
#include "config.h"
#include "lang.h"
#include "logger.h"
#include <time.h>
#include "util.h"
#include "game_util.h"
#include "map.h"
#include "miniftpserver.h"
#include "window.h"
#include "map_preview.h"
#include "stats.h"
#include <time.h>
#include <set>
#include <iostream>
#include "map_preview.h"
#include <iterator>
#include "stats.h"
#include "leak_dumper.h"
using namespace std;
@ -2606,7 +2607,7 @@ void ServerInterface::validateGameSettings(GameSettings *serverGameSettings) {
serverGameSettings->setMapFilterIndex(gameSettings.getMapFilterIndex());
Checksum checksum;
string file = Map::getMapPath(serverGameSettings->getMap(),"",false);
string file = Config::getMapPath(serverGameSettings->getMap(),"",false);
checksum.addFile(file);
serverGameSettings->setMapCRC(checksum.getSum());
}

View File

@ -1704,34 +1704,6 @@ void Map::computeCellColors(){
}
}
// static
string Map::getMapPath(const string &mapName, string scenarioDir, bool errorOnNotFound) {
Config &config = Config::getInstance();
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
for(int idx = 0; idx < (int)pathList.size(); idx++) {
string map_path = pathList[idx];
endPathWithSlash(map_path);
const string mega = map_path + mapName + ".mgm";
const string glest = map_path + mapName + ".gbm";
if (fileExists(mega)) {
return mega;
}
else if (fileExists(glest)) {
return glest;
}
}
if(errorOnNotFound == true) {
//abort();
throw megaglest_runtime_error("Map not found [" + mapName + "]\nScenario [" + scenarioDir + "]");
}
return "";
}
void Map::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *mapNode = rootNode->addChild("Map");

View File

@ -362,7 +362,6 @@ public:
//static
inline static Vec2i toSurfCoords(const Vec2i &unitPos) {return unitPos / cellScale;}
inline static Vec2i toUnitCoords(const Vec2i &surfPos) {return surfPos * cellScale;}
static string getMapPath(const string &mapName, string scenarioDir="", bool errorOnNotFound=true);
inline bool isFreeCellOrMightBeFreeSoon(Vec2i originPos, const Vec2i &pos, Field field) const {
return