mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- did some code refactoring, wanted to load some textures threaded but bailed out due to opengl's hideous problems related to multi-threads
This commit is contained in:
parent
cb96d86a62
commit
f7fdafbff4
@ -42,6 +42,11 @@ Game *thisGamePtr = NULL;
|
||||
|
||||
const float PHOTO_MODE_MAXHEIGHT = 500.0;
|
||||
|
||||
Game::Game() : ProgramState(NULL) {
|
||||
originalDisplayMsgCallback = NULL;
|
||||
aiInterfaces.clear();
|
||||
}
|
||||
|
||||
Game::Game(Program *program, const GameSettings *gameSettings):
|
||||
ProgramState(program), lastMousePos(0), isFirstRender(true)
|
||||
{
|
||||
@ -191,43 +196,15 @@ Texture2D * Game::findFactionLogoTexture(const GameSettings *settings, Logger *l
|
||||
return result;
|
||||
}
|
||||
|
||||
string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,string factionLogoFilter) {
|
||||
string result = "";
|
||||
if(settings == NULL) {
|
||||
result = "";
|
||||
}
|
||||
//Logger &logger= Logger::getInstance();
|
||||
string mapName= settings->getMap();
|
||||
string tilesetName= settings->getTileset();
|
||||
string techName= settings->getTech();
|
||||
string scenarioName= settings->getScenario();
|
||||
bool loadingImageUsed=false;
|
||||
|
||||
if(logger != NULL) {
|
||||
logger->setState(Lang::getInstance().get("Loading"));
|
||||
|
||||
if(scenarioName.empty()){
|
||||
logger->setSubtitle(formatString(mapName)+" - "+formatString(tilesetName)+" - "+formatString(techName));
|
||||
}
|
||||
else{
|
||||
logger->setSubtitle(formatString(scenarioName));
|
||||
}
|
||||
}
|
||||
|
||||
Config &config = Config::getInstance();
|
||||
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//bool skipCustomLoadScreen = true;
|
||||
bool skipCustomLoadScreen = false;
|
||||
|
||||
string scenarioDir = "";
|
||||
if(skipCustomLoadScreen == false && settings->getScenarioDir() != "") {
|
||||
string Game::extractScenarioLogoFile(const GameSettings *settings, string factionLogoFilter,
|
||||
string &result, Logger *logger, bool & loadingImageUsed) {
|
||||
string scenarioDir = "";
|
||||
if(settings->getScenarioDir() != "") {
|
||||
scenarioDir = settings->getScenarioDir();
|
||||
if(EndsWith(scenarioDir, ".xml") == true) {
|
||||
scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4);
|
||||
scenarioDir = scenarioDir.erase(scenarioDir.size() - settings->getScenario().size(), settings->getScenario().size() + 1);
|
||||
}
|
||||
// use a scenario based loading screen
|
||||
vector<string> loadScreenList;
|
||||
findAll(scenarioDir + factionLogoFilter, loadScreenList, false, false);
|
||||
if(loadScreenList.size() > 0) {
|
||||
@ -244,96 +221,58 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,settings->getScenarioDir().c_str(),settings->getScenario().c_str(),scenarioDir.c_str());
|
||||
}
|
||||
return scenarioDir;
|
||||
}
|
||||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
//sleep(0);
|
||||
//SDL_PumpEvents();
|
||||
string Game::extractFactionLogoFile(bool &loadingImageUsed, string factionName, Logger *logger,
|
||||
string scenarioDir, string techName, string factionLogoFilter) {
|
||||
string result = "";
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Searching for faction loading screen\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//for ( int i=0; i < settings->getFactionCount(); ++i ) {
|
||||
// if( settings->getFactionControl(i) == ctHuman ||
|
||||
// (settings->getFactionControl(i) == ctNetwork && settings->getThisFactionIndex() == i)) {
|
||||
|
||||
if(skipCustomLoadScreen == false && loadingImageUsed == false){
|
||||
// try to use a faction related loading screen
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Searching for faction loading screen\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for ( int i=0; i < settings->getFactionCount(); ++i ) {
|
||||
if( settings->getFactionControl(i) == ctHuman ||
|
||||
(settings->getFactionControl(i) == ctNetwork && settings->getThisFactionIndex() == i)) {
|
||||
//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)) {
|
||||
if(factionName == formatString(GameConstants::OBSERVER_SLOTNAME)) {
|
||||
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());
|
||||
|
||||
//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)) {
|
||||
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) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
if(fileExists(factionLogo) == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
result = factionLogo;
|
||||
if(logger != NULL) {
|
||||
logger->loadLoadingScreen(result);
|
||||
}
|
||||
loadingImageUsed = true;
|
||||
}
|
||||
}
|
||||
else if(settings->getFactionTypeName(i) == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||
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) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
result = factionLogo;
|
||||
if(logger != NULL) {
|
||||
logger->loadLoadingScreen(result);
|
||||
}
|
||||
loadingImageUsed = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
|
||||
for(int idx = 0; idx < pathList.size(); idx++) {
|
||||
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());
|
||||
if(isdir(path.c_str()) == true) {
|
||||
endPathWithSlash(path);
|
||||
|
||||
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());
|
||||
|
||||
if(fileExists(factionLogo) == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
result = factionLogo;
|
||||
if(logger != NULL) {
|
||||
logger->loadLoadingScreen(result);
|
||||
}
|
||||
loadingImageUsed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(loadingImageUsed == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
result = factionLogo;
|
||||
if(logger != NULL) {
|
||||
logger->loadLoadingScreen(result);
|
||||
}
|
||||
loadingImageUsed = true;
|
||||
}
|
||||
}
|
||||
if(skipCustomLoadScreen == false && loadingImageUsed == false){
|
||||
// try to use a tech related loading screen
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Searching for tech loading screen\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//else if(settings->getFactionTypeName(i) == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||
else if(factionName == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||
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) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
result = factionLogo;
|
||||
if(logger != NULL) {
|
||||
logger->loadLoadingScreen(result);
|
||||
}
|
||||
loadingImageUsed = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Config &config = Config::getInstance();
|
||||
vector<string> pathList=config.getPathListForType(ptTechs,scenarioDir);
|
||||
for(int idx = 0; idx < pathList.size(); idx++) {
|
||||
string currentPath = pathList[idx];
|
||||
endPathWithSlash(currentPath);
|
||||
string path = currentPath + techName;
|
||||
//string path = currentPath + techName + "/" + "factions" + "/" + settings->getFactionTypeName(i);
|
||||
string path = currentPath + techName + "/" + "factions" + "/" + factionName;
|
||||
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) {
|
||||
endPathWithSlash(path);
|
||||
@ -356,15 +295,157 @@ string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,st
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(loadingImageUsed == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//break;
|
||||
//}
|
||||
//}
|
||||
return result;
|
||||
}
|
||||
|
||||
string Game::extractTechLogoFile(string scenarioDir, string techName,
|
||||
string factionLogoFilter, Logger *logger, bool &loadingImageUsed) {
|
||||
string result = "";
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Searching for tech loading screen\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
Config &config = Config::getInstance();
|
||||
vector<string> pathList = config.getPathListForType(ptTechs, scenarioDir);
|
||||
for(int idx = 0; idx < pathList.size(); idx++) {
|
||||
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());
|
||||
if(isdir(path.c_str()) == true) {
|
||||
endPathWithSlash(path);
|
||||
|
||||
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());
|
||||
|
||||
if(fileExists(factionLogo) == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
|
||||
|
||||
result = factionLogo;
|
||||
if(logger != NULL) {
|
||||
logger->loadLoadingScreen(result);
|
||||
}
|
||||
loadingImageUsed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(loadingImageUsed == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,string factionLogoFilter) {
|
||||
string result = "";
|
||||
if(settings == NULL) {
|
||||
result = "";
|
||||
}
|
||||
string mapName= settings->getMap();
|
||||
string tilesetName= settings->getTileset();
|
||||
string techName= settings->getTech();
|
||||
string scenarioName= settings->getScenario();
|
||||
bool loadingImageUsed=false;
|
||||
|
||||
if(logger != NULL) {
|
||||
logger->setState(Lang::getInstance().get("Loading"));
|
||||
|
||||
if(scenarioName.empty()) {
|
||||
logger->setSubtitle(formatString(mapName) + " - " +
|
||||
formatString(tilesetName) + " - " + formatString(techName));
|
||||
}
|
||||
else {
|
||||
logger->setSubtitle(formatString(scenarioName));
|
||||
}
|
||||
}
|
||||
|
||||
string scenarioDir = "";
|
||||
bool skipCustomLoadScreen = false;
|
||||
if(skipCustomLoadScreen == false) {
|
||||
scenarioDir = extractScenarioLogoFile(settings,
|
||||
factionLogoFilter, result, logger, loadingImageUsed);
|
||||
}
|
||||
// try to use a faction related loading screen
|
||||
if(skipCustomLoadScreen == false && loadingImageUsed == false) {
|
||||
for(int i=0; i < settings->getFactionCount(); ++i ) {
|
||||
if( settings->getFactionControl(i) == ctHuman ||
|
||||
(settings->getFactionControl(i) == ctNetwork && settings->getThisFactionIndex() == i)) {
|
||||
result = extractFactionLogoFile(loadingImageUsed, settings->getFactionTypeName(i),
|
||||
logger,scenarioDir, techName, factionLogoFilter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// try to use a tech related loading screen
|
||||
if(skipCustomLoadScreen == false && loadingImageUsed == false){
|
||||
result = extractTechLogoFile(scenarioDir, techName,
|
||||
factionLogoFilter, logger, loadingImageUsed);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vector<Texture2D *> Game::processTech(string techName) {
|
||||
vector<Texture2D *> logoFiles;
|
||||
bool enableFactionTexturePreview = Config::getInstance().getBool("FactionPreview","true");
|
||||
if(enableFactionTexturePreview) {
|
||||
string currentTechName_factionPreview = techName;
|
||||
|
||||
vector<string> factions;
|
||||
vector<string> techPaths = Config::getInstance().getPathListForType(ptTechs);
|
||||
for(int idx = 0; idx < techPaths.size(); idx++) {
|
||||
string &techPath = techPaths[idx];
|
||||
endPathWithSlash(techPath);
|
||||
findAll(techPath + techName + "/factions/*.", factions, false, false);
|
||||
|
||||
if(factions.size() > 0) {
|
||||
for(unsigned int factionIdx = 0; factionIdx < factions.size(); ++factionIdx) {
|
||||
bool loadingImageUsed = false;
|
||||
string factionLogo = "";
|
||||
string currentFactionName_factionPreview = factions[factionIdx];
|
||||
|
||||
factionLogo = Game::extractFactionLogoFile(
|
||||
loadingImageUsed,
|
||||
currentFactionName_factionPreview,
|
||||
NULL,
|
||||
"",
|
||||
techName,
|
||||
"preview_screen.*");
|
||||
|
||||
if(factionLogo == "") {
|
||||
factionLogo = Game::extractFactionLogoFile(
|
||||
loadingImageUsed,
|
||||
currentFactionName_factionPreview,
|
||||
NULL,
|
||||
"",
|
||||
techName,
|
||||
"loading_screen.*");
|
||||
}
|
||||
if(factionLogo != "") {
|
||||
Texture2D *texture = Renderer::preloadTexture(factionLogo);
|
||||
logoFiles.push_back(texture);
|
||||
// Renderer::findFactionLogoTexture(factionLogo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return logoFiles;
|
||||
}
|
||||
|
||||
void Game::load() {
|
||||
load(lgt_All);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ enum LoadGameItem {
|
||||
// =====================================================
|
||||
|
||||
//class Game: public ProgramState, public SimpleTaskCallbackInterface {
|
||||
class Game: public ProgramState {
|
||||
class Game: public ProgramState, public FileCRCPreCacheThreadCallbackInterface {
|
||||
public:
|
||||
enum Speed{
|
||||
sFast,
|
||||
@ -115,6 +115,7 @@ private:
|
||||
bool gameStarted;
|
||||
|
||||
public:
|
||||
Game();
|
||||
Game(Program *program, const GameSettings *gameSettings);
|
||||
~Game();
|
||||
|
||||
@ -171,9 +172,14 @@ public:
|
||||
|
||||
static Texture2D * findFactionLogoTexture(const GameSettings *settings, Logger *logger,string factionLogoFilter="loading_screen.*", bool useTechDefaultIfFilterNotFound=true);
|
||||
static string findFactionLogoFile(const GameSettings *settings, Logger *logger, string factionLogoFilter="loading_screen.*");
|
||||
static string extractScenarioLogoFile(const GameSettings *settings, string factionLogoFilter,string &result, Logger *logger, bool &loadingImageUsed);
|
||||
static string extractFactionLogoFile(bool &loadingImageUsed, string factionName, Logger *logger,string scenarioDir, string techName, string factionLogoFilter);
|
||||
static string extractTechLogoFile(string scenarioDir, string techName,string factionLogoFilter, Logger *logger, bool &loadingImageUsed);
|
||||
|
||||
|
||||
bool getGameOver() { return gameOver; }
|
||||
bool hasGameStarted() { return gameStarted;}
|
||||
virtual vector<Texture2D *> processTech(string techName);
|
||||
|
||||
private:
|
||||
//render
|
||||
|
@ -5165,7 +5165,7 @@ uint64 Renderer::getCurrentPixelByteCount(ResourceScope rs) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Texture2D * Renderer::findFactionLogoTexture(string logoFilename) {
|
||||
Texture2D * Renderer::preloadTexture(string logoFilename) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFilename [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFilename.c_str());
|
||||
|
||||
Texture2D *result = NULL;
|
||||
@ -5184,7 +5184,7 @@ Texture2D * Renderer::findFactionLogoTexture(string logoFilename) {
|
||||
result = renderer.newTexture2D(rsGlobal);
|
||||
result->setMipmap(true);
|
||||
result->load(logoFilename);
|
||||
renderer.initTexture(rsGlobal,result);
|
||||
//renderer.initTexture(rsGlobal,result);
|
||||
crcFactionPreviewTextureCache[logoFilename] = result;
|
||||
}
|
||||
}
|
||||
@ -5192,6 +5192,18 @@ Texture2D * Renderer::findFactionLogoTexture(string logoFilename) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Texture2D * Renderer::findFactionLogoTexture(string logoFilename) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFilename [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFilename.c_str());
|
||||
|
||||
Texture2D *result = preloadTexture(logoFilename);
|
||||
if(result != NULL && result->getInited() == false) {
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
renderer.initTexture(rsGlobal,result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Renderer::cycleShowDebugUILevel() {
|
||||
if((showDebugUILevel & debugui_fps) != debugui_fps ||
|
||||
(showDebugUILevel & debugui_unit_titles) != debugui_unit_titles) {
|
||||
|
@ -434,6 +434,7 @@ public:
|
||||
void renderProgressBar(int size, int x, int y, Font2D *font,int customWidth=-1, string prefixLabel="");
|
||||
|
||||
static Texture2D * findFactionLogoTexture(string logoFilename);
|
||||
static Texture2D * preloadTexture(string logoFilename);
|
||||
int getCachedSurfaceDataSize() const { return mapSurfaceData.size(); }
|
||||
|
||||
private:
|
||||
|
@ -685,7 +685,8 @@ void MainWindow::eventKeyDown(char key){
|
||||
if(key == configKeys.getCharKey("HotKeyShowDebug")) {
|
||||
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
if(keystate.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
|
||||
//if(keystate.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
|
||||
if(keystate.mod & (KMOD_LALT | KMOD_RALT)) {
|
||||
renderer.cycleShowDebugUILevel();
|
||||
}
|
||||
else {
|
||||
@ -1821,6 +1822,7 @@ int glestMain(int argc, char** argv) {
|
||||
|
||||
// Setup the file crc thread
|
||||
std::auto_ptr<FileCRCPreCacheThread> preCacheThread;
|
||||
Game preCacheThreadGame;
|
||||
|
||||
//float pingTime = Socket::getAveragePingMS("soft-haus.com");
|
||||
//printf("Ping time = %f\n",pingTime);
|
||||
@ -2083,6 +2085,7 @@ int glestMain(int argc, char** argv) {
|
||||
preCacheThread.reset(new FileCRCPreCacheThread());
|
||||
preCacheThread->setUniqueID(__FILE__);
|
||||
preCacheThread->setTechDataPaths(techDataPaths);
|
||||
preCacheThread->setFileCRCPreCacheThreadCallbackInterface(&preCacheThreadGame);
|
||||
preCacheThread->start();
|
||||
}
|
||||
|
||||
@ -2095,9 +2098,23 @@ int glestMain(int argc, char** argv) {
|
||||
//string test = lang.get("ExitGameServer?");
|
||||
//printf("[%s]",test.c_str());
|
||||
|
||||
//time_t lastTextureLoadEvent = time(NULL);
|
||||
//main loop
|
||||
while(Window::handleEvent()) {
|
||||
program->loop();
|
||||
// Because OpenGL really doesn't do multi-threading well
|
||||
// if(difftime(time(NULL),lastTextureLoadEvent) >= 3) {
|
||||
// lastTextureLoadEvent = time(NULL);
|
||||
// vector<Texture2D *> textureList = preCacheThread->getPendingTextureList(1);
|
||||
// for(unsigned int i = 0; i < textureList.size(); ++i) {
|
||||
// Texture2D * factionLogo = textureList[i];
|
||||
// if(factionLogo != NULL) {
|
||||
// printf("\n\n\n\n|||||||||||||||||||||||||| Load texture [%s]\n",factionLogo->getPath().c_str());
|
||||
// //Renderer::findFactionLogoTexture(factionLogo);
|
||||
// renderer.initTexture(rsGlobal,factionLogo);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
if(preCacheThread.get() != NULL) {
|
||||
|
@ -2224,53 +2224,54 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
||||
gameSettings->setNetworkFramePeriod(config.getInt("NetworkSendFrameCount","20"));
|
||||
gameSettings->setNetworkPauseGameForLaggedClients(((listBoxNetworkPauseGameForLaggedClients.getSelectedItemIndex() != 0)));
|
||||
|
||||
if( gameSettings->getTileset() != "") {
|
||||
if(lastCheckedCRCTilesetName != gameSettings->getTileset()) {
|
||||
//console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]");
|
||||
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL);
|
||||
lastCheckedCRCTilesetName = gameSettings->getTileset();
|
||||
if(hasNetworkGameSettings() == true) {
|
||||
if( gameSettings->getTileset() != "") {
|
||||
if(lastCheckedCRCTilesetName != gameSettings->getTileset()) {
|
||||
//console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]");
|
||||
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL);
|
||||
lastCheckedCRCTilesetName = gameSettings->getTileset();
|
||||
}
|
||||
gameSettings->setTilesetCRC(lastCheckedCRCTilesetValue);
|
||||
}
|
||||
|
||||
if(config.getBool("DisableServerLobbyTechtreeCRCCheck","false") == false) {
|
||||
if(gameSettings->getTech() != "") {
|
||||
if(lastCheckedCRCTechtreeName != gameSettings->getTech()) {
|
||||
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
|
||||
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/*", ".xml", NULL);
|
||||
|
||||
reloadFactions(true);
|
||||
factionCRCList.clear();
|
||||
for(unsigned int factionIdx = 0; factionIdx < factionFiles.size(); ++factionIdx) {
|
||||
string factionName = factionFiles[factionIdx];
|
||||
int32 factionCRC = 0;
|
||||
if(factionName != GameConstants::RANDOMFACTION_SLOTNAME &&
|
||||
factionName != GameConstants::OBSERVER_SLOTNAME) {
|
||||
factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true);
|
||||
}
|
||||
factionCRCList.push_back(make_pair(factionName,factionCRC));
|
||||
}
|
||||
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
|
||||
lastCheckedCRCTechtreeName = gameSettings->getTech();
|
||||
}
|
||||
|
||||
gameSettings->setFactionCRCList(factionCRCList);
|
||||
gameSettings->setTechCRC(lastCheckedCRCTechtreeValue);
|
||||
}
|
||||
}
|
||||
|
||||
if(gameSettings->getMap() != "") {
|
||||
if(lastCheckedCRCMapName != gameSettings->getMap()) {
|
||||
Checksum checksum;
|
||||
string file = Map::getMapPath(gameSettings->getMap(),"",false);
|
||||
//console.addLine("Checking map CRC [" + file + "]");
|
||||
checksum.addFile(file);
|
||||
lastCheckedCRCMapValue = checksum.getSum();
|
||||
lastCheckedCRCMapName = gameSettings->getMap();
|
||||
}
|
||||
gameSettings->setMapCRC(lastCheckedCRCMapValue);
|
||||
}
|
||||
gameSettings->setTilesetCRC(lastCheckedCRCTilesetValue);
|
||||
}
|
||||
|
||||
if(config.getBool("DisableServerLobbyTechtreeCRCCheck","false") == false) {
|
||||
if(gameSettings->getTech() != "") {
|
||||
if(lastCheckedCRCTechtreeName != gameSettings->getTech()) {
|
||||
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
|
||||
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/*", ".xml", NULL);
|
||||
|
||||
reloadFactions(true);
|
||||
factionCRCList.clear();
|
||||
for(unsigned int factionIdx = 0; factionIdx < factionFiles.size(); ++factionIdx) {
|
||||
string factionName = factionFiles[factionIdx];
|
||||
int32 factionCRC = 0;
|
||||
if(factionName != GameConstants::RANDOMFACTION_SLOTNAME &&
|
||||
factionName != GameConstants::OBSERVER_SLOTNAME) {
|
||||
factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true);
|
||||
}
|
||||
factionCRCList.push_back(make_pair(factionName,factionCRC));
|
||||
}
|
||||
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
|
||||
lastCheckedCRCTechtreeName = gameSettings->getTech();
|
||||
}
|
||||
|
||||
gameSettings->setFactionCRCList(factionCRCList);
|
||||
gameSettings->setTechCRC(lastCheckedCRCTechtreeValue);
|
||||
}
|
||||
}
|
||||
|
||||
if(gameSettings->getMap() != "") {
|
||||
if(lastCheckedCRCMapName != gameSettings->getMap()) {
|
||||
Checksum checksum;
|
||||
string file = Map::getMapPath(gameSettings->getMap(),"",false);
|
||||
//console.addLine("Checking map CRC [" + file + "]");
|
||||
checksum.addFile(file);
|
||||
lastCheckedCRCMapValue = checksum.getSum();
|
||||
lastCheckedCRCMapName = gameSettings->getMap();
|
||||
}
|
||||
gameSettings->setMapCRC(lastCheckedCRCMapValue);
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
WrapMode getWrapMode() const {return wrapMode;}
|
||||
bool getPixmapInit() const {return pixmapInit;}
|
||||
Format getFormat() const {return format;}
|
||||
bool getInited() const {return inited;}
|
||||
|
||||
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
||||
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
||||
|
@ -15,13 +15,23 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "util.h"
|
||||
#include "texture.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Graphics;
|
||||
|
||||
namespace Shared { namespace PlatformCommon {
|
||||
|
||||
//
|
||||
// This interface describes the methods a callback object must implement
|
||||
//
|
||||
class FileCRCPreCacheThreadCallbackInterface {
|
||||
public:
|
||||
virtual vector<Texture2D *> processTech(string techName) = 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FileCRCPreCacheThread
|
||||
// =====================================================
|
||||
@ -31,13 +41,22 @@ class FileCRCPreCacheThread : public BaseThread
|
||||
protected:
|
||||
vector<string> techDataPaths;
|
||||
vector<string> workerThreadTechPaths;
|
||||
FileCRCPreCacheThreadCallbackInterface *processTechCB;
|
||||
|
||||
Mutex mutexPendingTextureList;
|
||||
vector<Texture2D *> pendingTextureList;
|
||||
|
||||
void addPendingTexture(Texture2D *texture);
|
||||
void addPendingTextureList(vector<Texture2D *> textureList);
|
||||
|
||||
public:
|
||||
FileCRCPreCacheThread();
|
||||
FileCRCPreCacheThread(vector<string> techDataPaths,vector<string> workerThreadTechPaths);
|
||||
FileCRCPreCacheThread(vector<string> techDataPaths,vector<string> workerThreadTechPaths,FileCRCPreCacheThreadCallbackInterface *processTechCB);
|
||||
virtual void execute();
|
||||
void setTechDataPaths(vector<string> value) { this->techDataPaths = value; }
|
||||
void setWorkerThreadTechPaths(vector<string> value) { this->workerThreadTechPaths = value; }
|
||||
void setFileCRCPreCacheThreadCallbackInterface(FileCRCPreCacheThreadCallbackInterface *value) { processTechCB = value; }
|
||||
vector<Texture2D *> getPendingTextureList(int maxTexturesToGet);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -28,12 +28,15 @@ const static int MAX_FileCRCPreCacheThread_WORKER_THREADS = 3;
|
||||
FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() {
|
||||
techDataPaths.clear();
|
||||
workerThreadTechPaths.clear();
|
||||
processTechCB = NULL;
|
||||
}
|
||||
|
||||
FileCRCPreCacheThread::FileCRCPreCacheThread(vector<string> techDataPaths,
|
||||
vector<string> workerThreadTechPaths) {
|
||||
this->techDataPaths = techDataPaths;
|
||||
this->workerThreadTechPaths = workerThreadTechPaths;
|
||||
vector<string> workerThreadTechPaths,
|
||||
FileCRCPreCacheThreadCallbackInterface *processTechCB) {
|
||||
this->techDataPaths = techDataPaths;
|
||||
this->workerThreadTechPaths = workerThreadTechPaths;
|
||||
this->processTechCB = processTechCB;
|
||||
}
|
||||
|
||||
void FileCRCPreCacheThread::execute() {
|
||||
@ -93,7 +96,10 @@ void FileCRCPreCacheThread::execute() {
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] workerIdx = %d, currentWorkerMax = %d, endConsumerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,workerIdx,currentWorkerMax,endConsumerIndex);
|
||||
|
||||
FileCRCPreCacheThread *workerThread = new FileCRCPreCacheThread(techDataPaths,workerTechList);
|
||||
FileCRCPreCacheThread *workerThread =
|
||||
new FileCRCPreCacheThread(techDataPaths,
|
||||
workerTechList,
|
||||
this->processTechCB);
|
||||
workerThread->setUniqueID(__FILE__);
|
||||
preCacheWorkerThreadList.push_back(workerThread);
|
||||
workerThread->start();
|
||||
@ -111,15 +117,21 @@ void FileCRCPreCacheThread::execute() {
|
||||
hasRunningWorkerThread = false;
|
||||
for(unsigned int idx = 0; idx < preCacheWorkerThreadList.size(); idx++) {
|
||||
FileCRCPreCacheThread *workerThread = preCacheWorkerThreadList[idx];
|
||||
if(workerThread != NULL && workerThread->getRunningStatus() == true) {
|
||||
hasRunningWorkerThread = true;
|
||||
if(getQuitStatus() == true) {
|
||||
workerThread->signalQuit();
|
||||
|
||||
if(workerThread != NULL) {
|
||||
//vector<Texture2D *> textureList = workerThread->getPendingTextureList(-1);
|
||||
//addPendingTextureList(textureList);
|
||||
|
||||
if(workerThread->getRunningStatus() == true) {
|
||||
hasRunningWorkerThread = true;
|
||||
if(getQuitStatus() == true) {
|
||||
workerThread->signalQuit();
|
||||
}
|
||||
}
|
||||
else if(workerThread->getRunningStatus() == false) {
|
||||
delete workerThread;
|
||||
preCacheWorkerThreadList[idx] = NULL;
|
||||
}
|
||||
}
|
||||
else if(workerThread != NULL && workerThread->getRunningStatus() == false) {
|
||||
delete workerThread;
|
||||
preCacheWorkerThreadList[idx] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,6 +171,16 @@ void FileCRCPreCacheThread::execute() {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime));
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime));
|
||||
}
|
||||
|
||||
// if(processTechCB) {
|
||||
// vector<Texture2D *> files = processTechCB->processTech(techName);
|
||||
// for(unsigned int logoIdx = 0; logoIdx < files.size(); ++logoIdx) {
|
||||
// addPendingTexture(files[logoIdx]);
|
||||
//
|
||||
// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("--------------------- CRC worker thread added texture [%s] for tech [%s] ---------------------------\n",files[logoIdx]->getPath().c_str(),techName.c_str());
|
||||
// }
|
||||
// }
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("--------------------- CRC worker thread END for tech [%s] ---------------------------\n",techName.c_str());
|
||||
|
||||
if(getQuitStatus() == true) {
|
||||
@ -181,6 +203,41 @@ void FileCRCPreCacheThread::execute() {
|
||||
deleteSelfIfRequired();
|
||||
}
|
||||
|
||||
void FileCRCPreCacheThread::addPendingTextureList(vector<Texture2D *> textureList) {
|
||||
for(unsigned int textureIdx = 0; textureIdx < textureList.size(); ++textureIdx) {
|
||||
this->addPendingTexture(textureList[textureIdx]);
|
||||
}
|
||||
}
|
||||
|
||||
void FileCRCPreCacheThread::addPendingTexture(Texture2D *texture) {
|
||||
if(texture == NULL) {
|
||||
return;
|
||||
}
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(&mutexPendingTextureList,mutexOwnerId);
|
||||
pendingTextureList.push_back(texture);
|
||||
safeMutex.ReleaseLock();
|
||||
}
|
||||
|
||||
vector<Texture2D *> FileCRCPreCacheThread::getPendingTextureList(int maxTexturesToGet) {
|
||||
vector<Texture2D *> result;
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(&mutexPendingTextureList,mutexOwnerId);
|
||||
unsigned int listCount = pendingTextureList.size();
|
||||
if(listCount > 0) {
|
||||
if(maxTexturesToGet >= 0) {
|
||||
listCount = maxTexturesToGet;
|
||||
}
|
||||
for(unsigned int i = 0; i < listCount; ++i) {
|
||||
result.push_back(pendingTextureList[i]);
|
||||
}
|
||||
pendingTextureList.erase(pendingTextureList.begin() + 0, pendingTextureList.begin() + listCount);
|
||||
}
|
||||
safeMutex.ReleaseLock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||
unsigned int executionCount,
|
||||
unsigned int millisecsBetweenExecutions,
|
||||
|
Loading…
x
Reference in New Issue
Block a user