- moved core game data asset loading into lazy load methods to try to improve the startup speed of megaglest.

This commit is contained in:
SoftCoder 2013-12-27 22:00:29 -08:00
parent 7b7a594359
commit 62821793c0
5 changed files with 611 additions and 528 deletions

File diff suppressed because it is too large Load Diff

View File

@ -43,6 +43,8 @@ class GameSettings;
class CoreData { class CoreData {
private: private:
std::map<int,bool> itemLoadAttempted;
StrSound introMusic; StrSound introMusic;
StrSound menuMusic; StrSound menuMusic;
StaticSound clickSoundA; StaticSound clickSoundA;
@ -131,8 +133,9 @@ public:
tsyst_onServerInstalledTexture, tsyst_onServerInstalledTexture,
tsyst_statusReadyTexture, tsyst_statusReadyTexture,
tsyst_statusNotReadyTexture, tsyst_statusNotReadyTexture,
tsyst_statusBRBTexture tsyst_statusBRBTexture,
tsyst_COUNT
//std::vector<Texture2D *> miscTextureList; //std::vector<Texture2D *> miscTextureList;
}; };
@ -145,46 +148,49 @@ public:
void cleanup(); void cleanup();
void loadFonts(); void loadFonts();
// Textures
Texture2D *getTextureBySystemId(TextureSystemType type) const; Texture2D *getTextureBySystemId(TextureSystemType type) const;
Texture2D *getBackgroundTexture() const {return backgroundTexture;} Texture2D *getBackgroundTexture();
Texture2D *getFireTexture() const {return fireTexture;} Texture2D *getFireTexture();
Texture2D *getTeamColorTexture() const {return teamColorTexture;} Texture2D *getTeamColorTexture();
Texture2D *getSnowTexture() const {return snowTexture;} Texture2D *getSnowTexture();
Texture2D *getLogoTexture() const {return logoTexture;} Texture2D *getLogoTexture();
Texture2D *getWaterSplashTexture() const {return waterSplashTexture;} Texture2D *getWaterSplashTexture();
Texture2D *getCustomTexture() const {return customTexture;} Texture2D *getCustomTexture();
Texture2D *getButtonSmallTexture() const {return buttonSmallTexture;} Texture2D *getButtonSmallTexture();
Texture2D *getButtonBigTexture() const {return buttonBigTexture;} Texture2D *getButtonBigTexture();
Texture2D *getHorizontalLineTexture() const {return horizontalLineTexture;} Texture2D *getHorizontalLineTexture();
Texture2D *getVerticalLineTexture() const {return verticalLineTexture;} Texture2D *getVerticalLineTexture();
Texture2D *getCheckBoxTexture() const {return checkBoxTexture;} Texture2D *getCheckBoxTexture();
Texture2D *getCheckedCheckBoxTexture() const {return checkedCheckBoxTexture;} Texture2D *getCheckedCheckBoxTexture();
Texture2D *getNotOnServerTexture() const {return notOnServerTexture;} Texture2D *getNotOnServerTexture();
Texture2D *getOnServerDifferentTexture() const {return onServerDifferentTexture;} Texture2D *getOnServerDifferentTexture();
Texture2D *getOnServerTexture() const {return onServerTexture;} Texture2D *getOnServerTexture();
Texture2D *getOnServerInstalledTexture() const {return onServerInstalledTexture;} Texture2D *getOnServerInstalledTexture();
Texture2D *getStatusReadyTexture() const {return statusReadyTexture;} Texture2D *getStatusReadyTexture();
Texture2D *getStatusNotReadyTexture() const {return statusNotReadyTexture;} Texture2D *getStatusNotReadyTexture();
Texture2D *getStatusBRBTexture() const {return statusBRBTexture;} Texture2D *getStatusBRBTexture();
Texture2D *getGameWinnerTexture();
Texture2D *getGameWinnerTexture() const {return gameWinnerTexture;} size_t getLogoTextureExtraCount();
Texture2D *getLogoTextureExtra(int idx);
size_t getLogoTextureExtraCount() const {return logoTextureList.size();} std::vector<Texture2D *> & getMiscTextureList();
Texture2D *getLogoTextureExtra(int idx) const {return logoTextureList[idx];}
std::vector<Texture2D *> & getMiscTextureList() { return miscTextureList; } // Sounds and Music
StrSound *getIntroMusic();
StrSound *getMenuMusic();
StrSound *getIntroMusic() {return &introMusic;} StaticSound *getClickSoundA();
StrSound *getMenuMusic() {return &menuMusic;} StaticSound *getClickSoundB();
StaticSound *getClickSoundA() {return &clickSoundA;} StaticSound *getClickSoundC();
StaticSound *getClickSoundB() {return &clickSoundB;} StaticSound *getAttentionSound();
StaticSound *getClickSoundC() {return &clickSoundC;} StaticSound *getHighlightSound();
StaticSound *getAttentionSound() {return &attentionSound;} StaticSound *getMarkerSound();
StaticSound *getHighlightSound() {return &highlightSound;} StaticSound *getWaterSound();
StaticSound *getMarkerSound() {return &markerSound;}
StaticSound *getWaterSound() {return waterSounds.getRandSound();}
// Fonts
Font2D *getDisplayFont() const {return displayFont;} Font2D *getDisplayFont() const {return displayFont;}
Font2D *getDisplayFontSmall() const {return displayFontSmall;} Font2D *getDisplayFontSmall() const {return displayFontSmall;}
Font2D *getMenuFontNormal() const {return menuFontNormal;} Font2D *getMenuFontNormal() const {return menuFontNormal;}
@ -199,27 +205,29 @@ public:
Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;} Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;}
Font3D *getConsoleFont3D() const {return consoleFont3D;} Font3D *getConsoleFont3D() const {return consoleFont3D;}
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } // Helper functions
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; }
bool hasMainMenuVideoFilename() const; bool hasMainMenuVideoFilename() const;
string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; }
bool hasMainMenuVideoFilenameFallback() const; bool hasMainMenuVideoFilenameFallback() const;
string getIntroVideoFilename() const { return introVideoFilename; } string getIntroVideoFilename() const { return introVideoFilename; }
bool hasIntroVideoFilename() const; bool hasIntroVideoFilename() const;
string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; }
bool hasIntroVideoFilenameFallback() const; 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; 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; 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); void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings); bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);
private: private:
CoreData(); CoreData();
int computeFontSize(int size); int computeFontSize(int size);
@ -230,6 +238,18 @@ private:
void loadIntroMedia(string data_path); void loadIntroMedia(string data_path);
void loadMainMenuMedia(string data_path); void loadMainMenuMedia(string data_path);
void loadBattleEndMedia(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 }} //end namespace

View File

@ -5509,7 +5509,7 @@ void Renderer::renderWaterEffects(){
const World *world= game->getWorld(); const World *world= game->getWorld();
const WaterEffects *we= world->getWaterEffects(); const WaterEffects *we= world->getWaterEffects();
const Map *map= world->getMap(); const Map *map= world->getMap();
const CoreData &coreData= CoreData::getInstance(); CoreData &coreData= CoreData::getInstance();
float height= map->getWaterLevel()+0.001f; float height= map->getWaterLevel()+0.001f;
assertGl(); assertGl();

View File

@ -834,7 +834,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
// END // END
if(initOk == false) { if(initOk == false) {
string sError = "Sound System could not be initialzed!"; string sError = "Sound System could not be initialized!";
this->showMessage(sError.c_str()); this->showMessage(sError.c_str());
} }

View File

@ -763,6 +763,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
assertGl(); assertGl();
if(inited == false) { if(inited == false) {
assertGl();
//params //params
GLint wrap= toWrapModeGl(wrapMode); GLint wrap= toWrapModeGl(wrapMode);
GLint glFormat= toFormatGl(format, pixmap.getComponents()); GLint glFormat= toFormatGl(format, pixmap.getComponents());
@ -772,6 +773,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
glCompressionFormat = glInternalFormat; glCompressionFormat = glInternalFormat;
} }
assertGl();
//pixel init var //pixel init var
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL; const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
@ -793,7 +795,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
} }
if(mipmap) { 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 //build mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter);