From 62821793c070f287e55152cba144ceeb40ea9031 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 22:00:29 -0800 Subject: [PATCH] - moved core game data asset loading into lazy load methods to try to improve the startup speed of megaglest. --- source/glest_game/global/core_data.cpp | 1029 +++++++++-------- source/glest_game/global/core_data.h | 102 +- source/glest_game/graphics/renderer.cpp | 2 +- source/glest_game/main/program.cpp | 2 +- .../sources/graphics/gl/texture_gl.cpp | 4 +- 5 files changed, 611 insertions(+), 528 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index e3fb222db..f4ba40151 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -193,509 +193,585 @@ void CoreData::cleanupTexture(Texture2D **texture) { *texture=NULL; } -void CoreData::loadTextures(string data_path) { - Renderer &renderer= Renderer::getInstance(); +void CoreData::loadTextureIfRequired(Texture2D **tex,string data_path, + string uniqueFilePath, int texSystemId, + bool setMipMap, bool setAlpha, + bool loadUniqueFilePath, bool compressionDisabled) { + if(*tex == NULL) { + bool attemptToLoadTexture = (texSystemId == tsyst_NONE); + if(attemptToLoadTexture == false && + itemLoadAttempted.find(texSystemId) == itemLoadAttempted.end()) { - //textures - backgroundTexture = renderer.newTexture2D(rsGlobal); - if (backgroundTexture) { - backgroundTexture->setMipmap(false); - try { - backgroundTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "back.tga")); - backgroundTexture->setTextureSystemId(tsyst_backgroundTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&backgroundTexture); + attemptToLoadTexture = true; + itemLoadAttempted[texSystemId] = true; } - } - fireTexture = renderer.newTexture2D(rsGlobal); - if (fireTexture) { - fireTexture->setFormat(Texture::fAlpha); - fireTexture->getPixmap()->init(1); - try { - fireTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "fire_particle.tga")); - fireTexture->setTextureSystemId(tsyst_fireTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&fireTexture); - } - } - teamColorTexture = renderer.newTexture2D(rsGlobal); - if (teamColorTexture) { - teamColorTexture->setFormat(Texture::fAlpha); - teamColorTexture->getPixmap()->init(1); - try { - teamColorTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH - + "team_color_texture.tga")); - teamColorTexture->setTextureSystemId(tsyst_teamColorTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&teamColorTexture); - } - } - snowTexture = renderer.newTexture2D(rsGlobal); - if (snowTexture) { - snowTexture->setMipmap(false); - snowTexture->setFormat(Texture::fAlpha); - snowTexture->getPixmap()->init(1); - try { - snowTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "snow_particle.tga")); - snowTexture->setTextureSystemId(tsyst_snowTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&snowTexture); - } - } - statusReadyTexture = renderer.newTexture2D(rsGlobal); - if (statusReadyTexture) { - try { - statusReadyTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "status_ready.png")); - statusReadyTexture->setTextureSystemId(tsyst_statusReadyTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&statusReadyTexture); - } - } - statusNotReadyTexture = renderer.newTexture2D(rsGlobal); - if (statusNotReadyTexture) { - try { - statusNotReadyTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "status_notready.png")); - statusNotReadyTexture->setTextureSystemId( - tsyst_statusNotReadyTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&statusNotReadyTexture); - } - } - statusBRBTexture = renderer.newTexture2D(rsGlobal); - if (statusBRBTexture) { - try { - statusBRBTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "status_brb.png")); - statusBRBTexture->setTextureSystemId(tsyst_statusBRBTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&statusBRBTexture); - } - } - customTexture = renderer.newTexture2D(rsGlobal); - if (customTexture) { - try { - customTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "custom_texture.tga")); - customTexture->setTextureSystemId(tsyst_customTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&customTexture); - } - } - notOnServerTexture = renderer.newTexture2D(rsGlobal); - if (notOnServerTexture) { - try { - notOnServerTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "not_on_server.tga")); - notOnServerTexture->setTextureSystemId(tsyst_notOnServerTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (¬OnServerTexture); - } - } - onServerDifferentTexture = renderer.newTexture2D(rsGlobal); - if (onServerDifferentTexture) { - try { - onServerDifferentTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH - + "on_server_different.tga")); - onServerDifferentTexture->setTextureSystemId( - tsyst_onServerDifferentTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&onServerDifferentTexture); - } - onServerTexture = renderer.newTexture2D(rsGlobal); - try { - onServerTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "on_server.tga")); - onServerTexture->setTextureSystemId(tsyst_onServerTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&onServerTexture); - } - onServerInstalledTexture = renderer.newTexture2D(rsGlobal); - try { - onServerInstalledTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH - + "on_server_installed.tga")); - onServerInstalledTexture->setTextureSystemId( - tsyst_onServerInstalledTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&onServerInstalledTexture); - } - } - logoTexture = renderer.newTexture2D(rsGlobal); - if (logoTexture) { - logoTexture->setMipmap(false); - try { - logoTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "logo.tga")); - logoTexture->setTextureSystemId(tsyst_logoTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&logoTexture); - } - } - logoTextureList.clear(); - string logosPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + "logo*.*"; - vector logoFilenames; - findAll(logosPath, logoFilenames, false, false); - for (int i = 0; i < (int)logoFilenames.size(); ++i) { - string logo = logoFilenames[i]; - if (strcmp("logo.tga", logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); - try { - logoTextureExtra->getPixmap()->load( - getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + logo); - logoTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture(&logoTextureExtra); + + Renderer &renderer = Renderer::getInstance(); + *tex = renderer.newTexture2D(rsGlobal); + if (*tex) { + + (*tex)->setForceCompressionDisabled(compressionDisabled); + (*tex)->setMipmap(setMipMap); + if(setAlpha == true) { + + (*tex)->setFormat(Texture::fAlpha); + (*tex)->getPixmap()->init(1); + } + + try { + string fileToLoad = uniqueFilePath; + if(loadUniqueFilePath == false) { + + fileToLoad = getGameCustomCoreDataPath(data_path,uniqueFilePath); } + (*tex)->getPixmap()->load(fileToLoad); + (*tex)->setTextureSystemId(texSystemId); + + renderer.initTexture(rsGlobal,*tex); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + cleanupTexture (tex); } } } - if (logoTextureList.empty() == true) { - logosPath = data_path + CORE_MENU_TEXTURES_PATH + "logo*.*"; +} + +string CoreData::getDataPath() { + string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + if(data_path != "") { + endPathWithSlash(data_path); + } + return data_path; +} + +Texture2D * CoreData::getBackgroundTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&backgroundTexture, getDataPath(), + CORE_MENU_TEXTURES_PATH + "back.tga", tsyst_backgroundTexture, + false, false, false); + + return backgroundTexture; +} +Texture2D *CoreData::getFireTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&fireTexture,data_path, + CORE_MISC_TEXTURES_PATH + "fire_particle.tga", tsyst_fireTexture, + true, true, false); + + return fireTexture; +} +Texture2D *CoreData::getTeamColorTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&teamColorTexture,data_path, + CORE_MISC_TEXTURES_PATH + "team_color_texture.tga", tsyst_teamColorTexture, + true, true, false); + + return teamColorTexture; +} +Texture2D *CoreData::getSnowTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&snowTexture,data_path, + CORE_MISC_TEXTURES_PATH + "snow_particle.tga", tsyst_snowTexture, + false, true, false); + + return snowTexture; +} +Texture2D *CoreData::getLogoTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&logoTexture,data_path, + CORE_MENU_TEXTURES_PATH + "logo.tga", tsyst_logoTexture, + false, false, false); + + return logoTexture; +} +Texture2D *CoreData::getWaterSplashTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&waterSplashTexture,data_path, + CORE_MISC_TEXTURES_PATH + "water_splash.tga", tsyst_waterSplashTexture, + true, true, false); + + return waterSplashTexture; +} +Texture2D *CoreData::getCustomTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&customTexture,data_path, + CORE_MENU_TEXTURES_PATH + "custom_texture.tga", tsyst_customTexture, + true, false, false); + + return customTexture; +} +Texture2D *CoreData::getButtonSmallTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&buttonSmallTexture,data_path, + CORE_MENU_TEXTURES_PATH + "button_small.tga", tsyst_buttonSmallTexture, + true, false, false, true); + + return buttonSmallTexture; +} +Texture2D *CoreData::getButtonBigTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&buttonBigTexture,data_path, + CORE_MENU_TEXTURES_PATH + "button_big.tga", tsyst_buttonBigTexture, + true, false, false, true); + + return buttonBigTexture; +} +Texture2D *CoreData::getHorizontalLineTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&horizontalLineTexture,data_path, + CORE_MENU_TEXTURES_PATH + "line_horizontal.tga", tsyst_horizontalLineTexture, + true, false, false, true); + + return horizontalLineTexture; +} +Texture2D *CoreData::getVerticalLineTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&verticalLineTexture,data_path, + CORE_MENU_TEXTURES_PATH + "line_vertical.tga", tsyst_verticalLineTexture, + true, false, false, true); + + return verticalLineTexture; +} +Texture2D *CoreData::getCheckBoxTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&checkBoxTexture,data_path, + CORE_MENU_TEXTURES_PATH + "checkbox.tga", tsyst_checkBoxTexture, + true, false, false, true); + + return checkBoxTexture; +} +Texture2D *CoreData::getCheckedCheckBoxTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&checkedCheckBoxTexture,data_path, + CORE_MENU_TEXTURES_PATH + "checkbox_checked.tga", tsyst_checkedCheckBoxTexture, + true, false, false, true); + + return checkedCheckBoxTexture; +} +Texture2D *CoreData::getNotOnServerTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(¬OnServerTexture,data_path, + CORE_MENU_TEXTURES_PATH + "not_on_server.tga", tsyst_notOnServerTexture, + true, false, false); + + return notOnServerTexture; +} +Texture2D *CoreData::getOnServerDifferentTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&onServerDifferentTexture,data_path, + CORE_MENU_TEXTURES_PATH + "on_server_different.tga", tsyst_onServerDifferentTexture, + true, false, false); + + return onServerDifferentTexture; +} +Texture2D *CoreData::getOnServerTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&onServerTexture,data_path, + CORE_MENU_TEXTURES_PATH + "on_server.tga", tsyst_onServerTexture, + true, false, false); + + return onServerTexture; +} +Texture2D *CoreData::getOnServerInstalledTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&onServerInstalledTexture,data_path, + CORE_MENU_TEXTURES_PATH + "on_server_installed.tga", tsyst_onServerInstalledTexture, + true, false, false); + + return onServerInstalledTexture; +} +Texture2D *CoreData::getStatusReadyTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&statusReadyTexture,data_path, + CORE_MENU_TEXTURES_PATH + "status_ready.png", tsyst_statusReadyTexture, + true, false, false); + + return statusReadyTexture; +} +Texture2D *CoreData::getStatusNotReadyTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&statusNotReadyTexture,data_path, + CORE_MENU_TEXTURES_PATH + "status_notready.png", tsyst_statusNotReadyTexture, + true, false, false); + + return statusNotReadyTexture; +} +Texture2D *CoreData::getStatusBRBTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&statusBRBTexture,data_path, + CORE_MENU_TEXTURES_PATH + "status_brb.png", tsyst_statusBRBTexture, + true, false, false); + + return statusBRBTexture; +} +Texture2D *CoreData::getGameWinnerTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&gameWinnerTexture,data_path, + CORE_MISC_TEXTURES_PATH + "game_winner.png", tsyst_gameWinnerTexture, + true, false, false, true); + + return gameWinnerTexture; +} + +void CoreData::loadLogoTextureExtraIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 1; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + logoTextureList.clear(); + string logosPath = getGameCustomCoreDataPath(data_path, "") + + CORE_MENU_TEXTURES_PATH + "logo*.*"; vector logoFilenames; findAll(logosPath, logoFilenames, false, false); - for (int i = 0; i < (int)logoFilenames.size(); ++i) { - string logo = logoFilenames[i]; + for (int index = 0; index < (int)logoFilenames.size(); ++index) { + + string logo = logoFilenames[index]; if (strcmp("logo.tga", logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); - try { - logoTextureExtra->getPixmap()->load( - data_path + CORE_MENU_TEXTURES_PATH + logo); - logoTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture(&logoTextureExtra); - } + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + getGameCustomCoreDataPath(data_path, "") + + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); + } + } + if (logoTextureList.empty() == true) { + + logosPath = data_path + CORE_MENU_TEXTURES_PATH + "logo*.*"; + vector logoFilenames; + findAll(logosPath, logoFilenames, false, false); + for (int index = 0; index < (int)logoFilenames.size(); ++index) { + + string logo = logoFilenames[index]; + if (strcmp("logo.tga", logo.c_str()) != 0) { + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + data_path + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); } } } } - miscTextureList.clear(); - string introPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + "intro*.*"; - vector introFilenames; - findAll(introPath, introFilenames, false, false); - for (int i = 0; i < (int)introFilenames.size(); ++i) { - string logo = introFilenames[i]; - //if(strcmp("logo.tga",logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); - try { - logoTextureExtra->getPixmap()->load( - getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + logo); - miscTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture(&logoTextureExtra); - } - } - //} - } - if (miscTextureList.empty() == true) { - introPath = data_path + CORE_MENU_TEXTURES_PATH + "intro*.*"; +} +size_t CoreData::getLogoTextureExtraCount() { + loadLogoTextureExtraIfRequired(); + return logoTextureList.size(); +} +Texture2D *CoreData::getLogoTextureExtra(int idx) { + loadLogoTextureExtraIfRequired(); + return logoTextureList[idx]; +} + +void CoreData::loadMiscTextureListIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 2; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + + miscTextureList.clear(); + string introPath = getGameCustomCoreDataPath(data_path, "") + + CORE_MENU_TEXTURES_PATH + "intro*.*"; vector introFilenames; findAll(introPath, introFilenames, false, false); for (int i = 0; i < (int)introFilenames.size(); ++i) { string logo = introFilenames[i]; - //if(strcmp("logo.tga",logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + getGameCustomCoreDataPath(data_path, "") + CORE_MENU_TEXTURES_PATH + + logo, tsyst_NONE, + true, false, true); + + } + if (miscTextureList.empty() == true) { + introPath = data_path + CORE_MENU_TEXTURES_PATH + "intro*.*"; + vector introFilenames; + findAll(introPath, introFilenames, false, false); + for (int i = 0; i < (int)introFilenames.size(); ++i) { + string logo = introFilenames[i]; + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + data_path + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); + } + } + + } +} + +std::vector & CoreData::getMiscTextureList() { + loadMiscTextureListIfRequired(); + return miscTextureList; +} + +void CoreData::loadTextures(string data_path) { + // Required to be loaded at program startup as they may be accessed in + // threads or some other dangerous way so lazy loading is not an option + getCustomTexture(); +} + +StaticSound *CoreData::getClickSoundA() { + int loadAttemptLookupKey = tsyst_COUNT + 3; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + clickSoundA.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "click_a.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + return &clickSoundA; +} + +StaticSound *CoreData::getClickSoundB() { + int loadAttemptLookupKey = tsyst_COUNT + 4; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + clickSoundB.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "click_b.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &clickSoundB; +} +StaticSound *CoreData::getClickSoundC() { + int loadAttemptLookupKey = tsyst_COUNT + 5; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + clickSoundC.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "click_c.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &clickSoundC; +} +StaticSound *CoreData::getAttentionSound() { + int loadAttemptLookupKey = tsyst_COUNT + 6; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + attentionSound.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "attention.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &attentionSound; +} +StaticSound *CoreData::getHighlightSound() { + int loadAttemptLookupKey = tsyst_COUNT + 7; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + highlightSound.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "highlight.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &highlightSound; +} +StaticSound *CoreData::getMarkerSound() { + int loadAttemptLookupKey = tsyst_COUNT + 8; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + markerSound.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "sonar.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &markerSound; +} + +void CoreData::loadWaterSoundsIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 9; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + cleanup(); + waterSounds.resize(6); + + for (int index = 0; index < 6; ++index) { + waterSounds[index] = new StaticSound(); + if (waterSounds[index] != NULL) { try { - logoTextureExtra->getPixmap()->load( - data_path + CORE_MENU_TEXTURES_PATH + logo); - miscTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { + waterSounds[index]->load(getGameCustomCoreDataPath(data_path, + CORE_WATER_SOUNDS_PATH + + "water" + intToStr(index) + ".wav")); + } + catch (const megaglest_runtime_error& ex) { message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), tempDataLocation); - cleanupTexture(&logoTextureExtra); } } - //} - } - } - waterSplashTexture = renderer.newTexture2D(rsGlobal); - if (waterSplashTexture) { - waterSplashTexture->setFormat(Texture::fAlpha); - waterSplashTexture->getPixmap()->init(1); - try { - waterSplashTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "water_splash.tga")); - waterSplashTexture->setTextureSystemId(tsyst_waterSplashTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&waterSplashTexture); - } - } - buttonSmallTexture = renderer.newTexture2D(rsGlobal); - if (buttonSmallTexture) { - buttonSmallTexture->setForceCompressionDisabled(true); - try { - buttonSmallTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "button_small.tga")); - buttonSmallTexture->setTextureSystemId(tsyst_buttonSmallTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&buttonSmallTexture); - } - } - buttonBigTexture = renderer.newTexture2D(rsGlobal); - if (buttonBigTexture) { - buttonBigTexture->setForceCompressionDisabled(true); - try { - buttonBigTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "button_big.tga")); - buttonBigTexture->setTextureSystemId(tsyst_buttonBigTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&buttonBigTexture); - } - } - horizontalLineTexture = renderer.newTexture2D(rsGlobal); - if (horizontalLineTexture) { - horizontalLineTexture->setForceCompressionDisabled(true); - try { - horizontalLineTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "line_horizontal.tga")); - horizontalLineTexture->setTextureSystemId( - tsyst_horizontalLineTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&horizontalLineTexture); - } - } - verticalLineTexture = renderer.newTexture2D(rsGlobal); - if (verticalLineTexture) { - verticalLineTexture->setForceCompressionDisabled(true); - try { - verticalLineTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "line_vertical.tga")); - verticalLineTexture->setTextureSystemId(tsyst_verticalLineTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&verticalLineTexture); - } - } - checkBoxTexture = renderer.newTexture2D(rsGlobal); - if (checkBoxTexture) { - checkBoxTexture->setForceCompressionDisabled(true); - try { - checkBoxTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "checkbox.tga")); - checkBoxTexture->setTextureSystemId(tsyst_checkBoxTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&checkBoxTexture); - } - } - checkedCheckBoxTexture = renderer.newTexture2D(rsGlobal); - if (checkedCheckBoxTexture) { - checkedCheckBoxTexture->setForceCompressionDisabled(true); - try { - checkedCheckBoxTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "checkbox_checked.tga")); - checkedCheckBoxTexture->setTextureSystemId( - tsyst_checkedCheckBoxTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&checkedCheckBoxTexture); - } - } - gameWinnerTexture = renderer.newTexture2D(rsGlobal); - if (gameWinnerTexture) { - gameWinnerTexture->setForceCompressionDisabled(true); - try { - gameWinnerTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "game_winner.png")); - gameWinnerTexture->setTextureSystemId(tsyst_gameWinnerTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&gameWinnerTexture); } } } +StaticSound *CoreData::getWaterSound() { + loadWaterSoundsIfRequired(); + return waterSounds.getRandSound(); +} + void CoreData::loadSounds(string data_path) { // sounds - try { - clickSoundA.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_a.wav")); - clickSoundB.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_b.wav")); - clickSoundC.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_c.wav")); - attentionSound.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "attention.wav")); - highlightSound.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "highlight.wav")); - markerSound.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "sonar.wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - cleanup(); - waterSounds.resize(6); +// try { +// clickSoundA.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_a.wav")); +// clickSoundB.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_b.wav")); +// clickSoundC.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_c.wav")); +// attentionSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "attention.wav")); +// highlightSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "highlight.wav")); +// markerSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "sonar.wav")); +// } +// catch (const megaglest_runtime_error& ex) { +// message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), +// tempDataLocation); +// } - for (int i = 0; i < 6; ++i) { - waterSounds[i] = new StaticSound(); - if (waterSounds[i]) { - try { - waterSounds[i]->load( - getGameCustomCoreDataPath(data_path, - CORE_WATER_SOUNDS_PATH + "water" + intToStr(i) - + ".wav")); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } +// cleanup(); +// waterSounds.resize(6); +// +// for (int i = 0; i < 6; ++i) { +// waterSounds[i] = new StaticSound(); +// if (waterSounds[i]) { +// try { +// waterSounds[i]->load( +// getGameCustomCoreDataPath(data_path, +// CORE_WATER_SOUNDS_PATH + "water" + intToStr(i) +// + ".wav")); +// } catch (const megaglest_runtime_error& ex) { +// message(ex.what(), +// GlobalStaticFlags::getIsNonGraphicalModeEnabled(), +// tempDataLocation); +// } +// } +// } +} + + +void CoreData::loadMusicIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 10; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + + XmlTree xmlTree; + xmlTree.load( + getGameCustomCoreDataPath(data_path, CORE_MENU_PATH + "menu.xml"), + Properties::getTagReplacementValues()); + const XmlNode* menuNode = xmlTree.getRootNode(); + string menuMusicPath = "/menu/music/"; + string menuIntroMusicFile = "intro_music.ogg"; + string menuMusicFile = "menu_music.ogg"; + if (menuNode->hasChild("intro") == true) { + const XmlNode* introNode = menuNode->getChild("intro"); + // intro info + const XmlNode* menuPathNode = introNode->getChild("menu-music-path"); + menuMusicPath = + menuPathNode->getAttribute("value")->getRestrictedValue(); + const XmlNode* menuIntroMusicNode = introNode->getChild( + "menu-intro-music"); + menuIntroMusicFile = + menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); + const XmlNode* menuMusicNode = introNode->getChild("menu-music"); + menuMusicFile = + menuMusicNode->getAttribute("value")->getRestrictedValue(); + } + try { + introMusic.open( + getGameCustomCoreDataPath(data_path, + CORE_PATH + menuMusicPath + menuIntroMusicFile)); + introMusic.setNext(&menuMusic); + menuMusic.open( + getGameCustomCoreDataPath(data_path, + CORE_PATH + menuMusicPath + menuMusicFile)); + menuMusic.setNext(&menuMusic); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); } } } +StrSound *CoreData::getIntroMusic() { + loadMusicIfRequired(); + return &introMusic; +} + +StrSound *CoreData::getMenuMusic() { + loadMusicIfRequired(); + return &menuMusic; +} + void CoreData::loadMusic(string data_path) { - XmlTree xmlTree; - //string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - xmlTree.load( - getGameCustomCoreDataPath(data_path, CORE_MENU_PATH + "menu.xml"), - Properties::getTagReplacementValues()); - const XmlNode* menuNode = xmlTree.getRootNode(); - string menuMusicPath = "/menu/music/"; - string menuIntroMusicFile = "intro_music.ogg"; - string menuMusicFile = "menu_music.ogg"; - if (menuNode->hasChild("intro") == true) { - const XmlNode* introNode = menuNode->getChild("intro"); - // intro info - const XmlNode* menuPathNode = introNode->getChild("menu-music-path"); - menuMusicPath = - menuPathNode->getAttribute("value")->getRestrictedValue(); - const XmlNode* menuIntroMusicNode = introNode->getChild( - "menu-intro-music"); - menuIntroMusicFile = - menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); - const XmlNode* menuMusicNode = introNode->getChild("menu-music"); - menuMusicFile = - menuMusicNode->getAttribute("value")->getRestrictedValue(); - } - try { - introMusic.open( - getGameCustomCoreDataPath(data_path, - CORE_PATH + menuMusicPath + menuIntroMusicFile)); - introMusic.setNext(&menuMusic); - menuMusic.open( - getGameCustomCoreDataPath(data_path, - CORE_PATH + menuMusicPath + menuMusicFile)); - menuMusic.setNext(&menuMusic); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } } void CoreData::loadIntroMedia(string data_path) { @@ -998,12 +1074,8 @@ void CoreData::loadBattleEndMedia(string data_path) { } void CoreData::load() { - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - if(data_path != "") { - endPathWithSlash(data_path); - } + string data_path = CoreData::getDataPath(); - //const string dir = data_path + "data/core"; Logger::getInstance().add(Lang::getInstance().getString("LogScreenCoreDataLoading","",true)); // textures @@ -1021,8 +1093,6 @@ void CoreData::load() { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - loadIntroMedia(data_path); loadMainMenuMedia(data_path); @@ -1032,19 +1102,16 @@ void CoreData::load() { } bool CoreData::hasIntroVideoFilename() const { - //bool result = (introVideoFilename != "" && fileExists(introVideoFilename) == true); bool result = (introVideoFilename != ""); return result; } bool CoreData::hasMainMenuVideoFilename() const { - //bool result = (mainMenuVideoFilename != "" && fileExists(mainMenuVideoFilename) == true); bool result = (mainMenuVideoFilename != ""); return result; } bool CoreData::hasBattleEndVideoFilename(bool won) const { - //bool result = (mainMenuVideoFilename != "" && fileExists(mainMenuVideoFilename) == true); bool result = false; if(won == true) { result =(battleEndWinVideoFilename != ""); @@ -1066,8 +1133,6 @@ void CoreData::loadFonts() { string displayFontNamePostfix = config.getString("FontDisplayPostfix"); int displayFontSize = computeFontSize(config.getInt("FontDisplayBaseSize")); - //printf("Checking if langfile has custom FontDisplayPostfix\n"); - if(lang.hasString("FontDisplayPrefix") == true) { displayFontNamePrefix = lang.getString("FontDisplayPrefix"); } @@ -1078,8 +1143,6 @@ void CoreData::loadFonts() { displayFontSize = computeFontSize(strToInt(lang.getString("FontDisplayBaseSize"))); } - //printf("displayFontNamePostfix [%s]\n",displayFontNamePostfix.c_str()); - string displayFontName = displayFontNamePrefix + intToStr(displayFontSize) + displayFontNamePostfix; if(displayFont) { @@ -1279,8 +1342,6 @@ void CoreData::loadFonts() { } } - //printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); //console font diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 50060b980..82306bac1 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -43,6 +43,8 @@ class GameSettings; class CoreData { private: + std::map itemLoadAttempted; + StrSound introMusic; StrSound menuMusic; StaticSound clickSoundA; @@ -131,8 +133,9 @@ public: tsyst_onServerInstalledTexture, tsyst_statusReadyTexture, tsyst_statusNotReadyTexture, - tsyst_statusBRBTexture + tsyst_statusBRBTexture, + tsyst_COUNT //std::vector miscTextureList; }; @@ -145,46 +148,49 @@ public: void cleanup(); void loadFonts(); + // Textures Texture2D *getTextureBySystemId(TextureSystemType type) const; - Texture2D *getBackgroundTexture() const {return backgroundTexture;} - Texture2D *getFireTexture() const {return fireTexture;} - Texture2D *getTeamColorTexture() const {return teamColorTexture;} - Texture2D *getSnowTexture() const {return snowTexture;} - Texture2D *getLogoTexture() const {return logoTexture;} - Texture2D *getWaterSplashTexture() const {return waterSplashTexture;} - Texture2D *getCustomTexture() const {return customTexture;} - Texture2D *getButtonSmallTexture() const {return buttonSmallTexture;} - Texture2D *getButtonBigTexture() const {return buttonBigTexture;} - Texture2D *getHorizontalLineTexture() const {return horizontalLineTexture;} - Texture2D *getVerticalLineTexture() const {return verticalLineTexture;} - Texture2D *getCheckBoxTexture() const {return checkBoxTexture;} - Texture2D *getCheckedCheckBoxTexture() const {return checkedCheckBoxTexture;} - Texture2D *getNotOnServerTexture() const {return notOnServerTexture;} - Texture2D *getOnServerDifferentTexture() const {return onServerDifferentTexture;} - Texture2D *getOnServerTexture() const {return onServerTexture;} - Texture2D *getOnServerInstalledTexture() const {return onServerInstalledTexture;} - Texture2D *getStatusReadyTexture() const {return statusReadyTexture;} - Texture2D *getStatusNotReadyTexture() const {return statusNotReadyTexture;} - Texture2D *getStatusBRBTexture() const {return statusBRBTexture;} + Texture2D *getBackgroundTexture(); + Texture2D *getFireTexture(); + Texture2D *getTeamColorTexture(); + Texture2D *getSnowTexture(); + Texture2D *getLogoTexture(); + Texture2D *getWaterSplashTexture(); + Texture2D *getCustomTexture(); + Texture2D *getButtonSmallTexture(); + Texture2D *getButtonBigTexture(); + Texture2D *getHorizontalLineTexture(); + Texture2D *getVerticalLineTexture(); + Texture2D *getCheckBoxTexture(); + Texture2D *getCheckedCheckBoxTexture(); + Texture2D *getNotOnServerTexture(); + Texture2D *getOnServerDifferentTexture(); + Texture2D *getOnServerTexture(); + Texture2D *getOnServerInstalledTexture(); + Texture2D *getStatusReadyTexture(); + Texture2D *getStatusNotReadyTexture(); + Texture2D *getStatusBRBTexture(); + Texture2D *getGameWinnerTexture(); - Texture2D *getGameWinnerTexture() const {return gameWinnerTexture;} + size_t getLogoTextureExtraCount(); + Texture2D *getLogoTextureExtra(int idx); - size_t getLogoTextureExtraCount() const {return logoTextureList.size();} - Texture2D *getLogoTextureExtra(int idx) const {return logoTextureList[idx];} + std::vector & getMiscTextureList(); - std::vector & getMiscTextureList() { return miscTextureList; } + // Sounds and Music + StrSound *getIntroMusic(); + StrSound *getMenuMusic(); - StrSound *getIntroMusic() {return &introMusic;} - StrSound *getMenuMusic() {return &menuMusic;} - StaticSound *getClickSoundA() {return &clickSoundA;} - StaticSound *getClickSoundB() {return &clickSoundB;} - StaticSound *getClickSoundC() {return &clickSoundC;} - StaticSound *getAttentionSound() {return &attentionSound;} - StaticSound *getHighlightSound() {return &highlightSound;} - StaticSound *getMarkerSound() {return &markerSound;} - StaticSound *getWaterSound() {return waterSounds.getRandSound();} + StaticSound *getClickSoundA(); + StaticSound *getClickSoundB(); + StaticSound *getClickSoundC(); + StaticSound *getAttentionSound(); + StaticSound *getHighlightSound(); + StaticSound *getMarkerSound(); + StaticSound *getWaterSound(); + // Fonts Font2D *getDisplayFont() const {return displayFont;} Font2D *getDisplayFontSmall() const {return displayFontSmall;} Font2D *getMenuFontNormal() const {return menuFontNormal;} @@ -199,27 +205,29 @@ public: Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;} Font3D *getConsoleFont3D() const {return consoleFont3D;} - string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } + // Helper functions + string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } bool hasMainMenuVideoFilename() const; - string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } + string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } bool hasMainMenuVideoFilenameFallback() const; - string getIntroVideoFilename() const { return introVideoFilename; } + string getIntroVideoFilename() const { return introVideoFilename; } bool hasIntroVideoFilename() const; - string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } + string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } bool hasIntroVideoFilenameFallback() const; - string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; } + string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; } bool hasBattleEndVideoFilename(bool won) const; - string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } + string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } bool hasBattleEndVideoFilenameFallback(bool won) const; - string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } + string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0); bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings); private: + CoreData(); int computeFontSize(int size); @@ -230,6 +238,18 @@ private: void loadIntroMedia(string data_path); void loadMainMenuMedia(string data_path); void loadBattleEndMedia(string data_path); + + string getDataPath(); + void loadTextureIfRequired(Texture2D **tex,string data_path, + string uniqueFilePath, int texSystemId, bool setMipMap, + bool setAlpha, bool loadUniqueFilePath, + bool compressionDisabled = false); + + void loadLogoTextureExtraIfRequired(); + void loadMiscTextureListIfRequired(); + + void loadWaterSoundsIfRequired(); + void loadMusicIfRequired(); }; }} //end namespace diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 0904fdbea..2c05d21c1 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5509,7 +5509,7 @@ void Renderer::renderWaterEffects(){ const World *world= game->getWorld(); const WaterEffects *we= world->getWaterEffects(); const Map *map= world->getMap(); - const CoreData &coreData= CoreData::getInstance(); + CoreData &coreData= CoreData::getInstance(); float height= map->getWaterLevel()+0.001f; assertGl(); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 06da06b0e..04e55725f 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -834,7 +834,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ // END if(initOk == false) { - string sError = "Sound System could not be initialzed!"; + string sError = "Sound System could not be initialized!"; this->showMessage(sError.c_str()); } diff --git a/source/shared_lib/sources/graphics/gl/texture_gl.cpp b/source/shared_lib/sources/graphics/gl/texture_gl.cpp index e02538e75..dac42ec7e 100644 --- a/source/shared_lib/sources/graphics/gl/texture_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/texture_gl.cpp @@ -763,6 +763,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { assertGl(); if(inited == false) { + assertGl(); //params GLint wrap= toWrapModeGl(wrapMode); GLint glFormat= toFormatGl(format, pixmap.getComponents()); @@ -772,6 +773,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { glCompressionFormat = glInternalFormat; } + assertGl(); //pixel init var const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL; @@ -793,7 +795,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { } if(mipmap) { - GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST; + GLuint glFilter= (filter == fTrilinear ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST); //build mipmaps glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter);