From 21a12a6c7260f4dc0f17d283bdd19d659026b8d8 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Mon, 30 Dec 2013 23:32:06 -0800 Subject: [PATCH] - added ability to render map preview full screen when user clicks on the map preview. Click anywhere on the fullscreen map to restore. --- .../menu/menu_state_connected_game.cpp | 59 +++++++++++++++++- .../menu/menu_state_connected_game.h | 4 ++ .../menu/menu_state_custom_game.cpp | 62 ++++++++++++++++++- .../glest_game/menu/menu_state_custom_game.h | 4 ++ .../shared_lib/sources/util/leak_dumper.cpp | 46 +++++++------- 5 files changed, 149 insertions(+), 26 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 353c76cc..1e7a43f0 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -47,6 +47,11 @@ static const double REPROMPT_DOWNLOAD_SECONDS = 7; const int HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS = 4; static const char *HEADLESS_SAVED_GAME_FILENAME = "lastHeadlessGameSettings.mgg"; +const int mapPreviewTexture_X = 5; +const int mapPreviewTexture_Y = 185; +const int mapPreviewTexture_W = 150; +const int mapPreviewTexture_H = 150; + struct FormatString { void operator()(string &s) { s = formatString(s); @@ -67,6 +72,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM updateDataSynchDetailText = false; launchingNewGame = false; + this->render_mapPreviewTexture_X = mapPreviewTexture_X; + this->render_mapPreviewTexture_Y = mapPreviewTexture_Y; + this->render_mapPreviewTexture_W = mapPreviewTexture_W; + this->render_mapPreviewTexture_H = mapPreviewTexture_H; + needToBroadcastServerSettings=false; broadcastServerSettingsDelayTimer=0; lastGameSettingsReceivedCount=0; @@ -1131,6 +1141,40 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ } } + if(mapPreviewTexture != NULL) { +// printf("X: %d Y: %d [%d, %d, %d, %d]\n", +// x, y, +// this->render_mapPreviewTexture_X, this->render_mapPreviewTexture_X + this->render_mapPreviewTexture_W, +// this->render_mapPreviewTexture_Y, this->render_mapPreviewTexture_Y + this->render_mapPreviewTexture_H); + + if( x >= this->render_mapPreviewTexture_X && x <= this->render_mapPreviewTexture_X + this->render_mapPreviewTexture_W && + y >= this->render_mapPreviewTexture_Y && y <= this->render_mapPreviewTexture_Y + this->render_mapPreviewTexture_H) { + + if( this->render_mapPreviewTexture_X == mapPreviewTexture_X && + this->render_mapPreviewTexture_Y == mapPreviewTexture_Y && + this->render_mapPreviewTexture_W == mapPreviewTexture_W && + this->render_mapPreviewTexture_H == mapPreviewTexture_H) { + + const Metrics &metrics= Metrics::getInstance(); + + this->render_mapPreviewTexture_X = 0; + this->render_mapPreviewTexture_Y = 0; + this->render_mapPreviewTexture_W = metrics.getVirtualW(); + this->render_mapPreviewTexture_H = metrics.getVirtualH(); + + cleanupMapPreviewTexture(); + } + else { + this->render_mapPreviewTexture_X = mapPreviewTexture_X; + this->render_mapPreviewTexture_Y = mapPreviewTexture_Y; + this->render_mapPreviewTexture_W = mapPreviewTexture_W; + this->render_mapPreviewTexture_H = mapPreviewTexture_H; + + cleanupMapPreviewTexture(); + } + } + } + if(mainMessageBox.getEnabled()) { int button= 0; if(mainMessageBox.mouseClick(x, y, button)) { @@ -2386,7 +2430,13 @@ void MenuStateConnectedGame::render() { } if(mapPreviewTexture != NULL) { - renderer.renderTextureQuad(5,185,150,150,mapPreviewTexture,1.0f); + //renderer.renderTextureQuad(5,185,150,150,mapPreviewTexture,1.0f); + renderer.renderTextureQuad( this->render_mapPreviewTexture_X, + this->render_mapPreviewTexture_Y, + this->render_mapPreviewTexture_W, + this->render_mapPreviewTexture_H, + mapPreviewTexture,1.0f); + //printf("=================> Rendering map preview texture\n"); } @@ -2633,8 +2683,13 @@ void MenuStateConnectedGame::render() { if(mapPreviewTexture == NULL) { renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim); + bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 2); - renderer.renderMapPreview(&mapPreview, renderAll, 10, 350, &mapPreviewTexture); + //renderer.renderMapPreview(&mapPreview, renderAll, 10, 350, &mapPreviewTexture); + renderer.renderMapPreview(&mapPreview, renderAll, + this->render_mapPreviewTexture_X, + this->render_mapPreviewTexture_Y, + &mapPreviewTexture); } } renderer.renderChatManager(&chatManager); diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 298f1470..00a3fa06 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -104,6 +104,10 @@ private: MapInfo mapInfo; Texture2D *mapPreviewTexture; + int render_mapPreviewTexture_X; + int render_mapPreviewTexture_Y; + int render_mapPreviewTexture_W; + int render_mapPreviewTexture_H; bool needToSetChangedGameSettings; time_t lastSetChangedGameSettings; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 7cf27bfa..84d243b0 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -47,6 +47,11 @@ static const char *SAVED_GAME_FILENAME = "lastCustomGameSettings.mgg"; static const char *DEFAULT_GAME_FILENAME = "data/defaultGameSetup.mgg"; static const char *DEFAULT_NETWORKGAME_FILENAME = "data/defaultNetworkGameSetup.mgg"; +const int mapPreviewTexture_X = 5; +const int mapPreviewTexture_Y = 185; +const int mapPreviewTexture_W = 150; +const int mapPreviewTexture_H = 150; + struct FormatString { void operator()(string &s) { s = formatString(s); @@ -75,6 +80,11 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, this->gameUUID = getUUIDAsString(); + this->render_mapPreviewTexture_X = mapPreviewTexture_X; + this->render_mapPreviewTexture_Y = mapPreviewTexture_Y; + this->render_mapPreviewTexture_W = mapPreviewTexture_W; + this->render_mapPreviewTexture_H = mapPreviewTexture_H; + this->lastMasterServerSettingsUpdateCount = 0; this->masterserverModeMinimalResources = true; this->parentMenuState=parentMenuState; @@ -1043,6 +1053,40 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { advanceToItemStartingWith = lastKey; } + if(mapPreviewTexture != NULL) { +// printf("X: %d Y: %d [%d, %d, %d, %d]\n", +// x, y, +// this->render_mapPreviewTexture_X, this->render_mapPreviewTexture_X + this->render_mapPreviewTexture_W, +// this->render_mapPreviewTexture_Y, this->render_mapPreviewTexture_Y + this->render_mapPreviewTexture_H); + + if( x >= this->render_mapPreviewTexture_X && x <= this->render_mapPreviewTexture_X + this->render_mapPreviewTexture_W && + y >= this->render_mapPreviewTexture_Y && y <= this->render_mapPreviewTexture_Y + this->render_mapPreviewTexture_H) { + + if( this->render_mapPreviewTexture_X == mapPreviewTexture_X && + this->render_mapPreviewTexture_Y == mapPreviewTexture_Y && + this->render_mapPreviewTexture_W == mapPreviewTexture_W && + this->render_mapPreviewTexture_H == mapPreviewTexture_H) { + + const Metrics &metrics= Metrics::getInstance(); + + this->render_mapPreviewTexture_X = 0; + this->render_mapPreviewTexture_Y = 0; + this->render_mapPreviewTexture_W = metrics.getVirtualW(); + this->render_mapPreviewTexture_H = metrics.getVirtualH(); + + cleanupMapPreviewTexture(); + } + else { + this->render_mapPreviewTexture_X = mapPreviewTexture_X; + this->render_mapPreviewTexture_Y = mapPreviewTexture_Y; + this->render_mapPreviewTexture_W = mapPreviewTexture_W; + this->render_mapPreviewTexture_H = mapPreviewTexture_H; + + cleanupMapPreviewTexture(); + } + } + } + if(activeInputLabel!=NULL && !(activeInputLabel->mouseClick(x,y))){ setActiveInputLabel(NULL); } @@ -1482,7 +1526,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { } } } - } + } } if(hasNetworkGameSettings() == true && listBoxPlayerStatus.mouseClick(x,y)) { @@ -1981,7 +2025,13 @@ void MenuStateCustomGame::render() { } else { if(mapPreviewTexture != NULL) { - renderer.renderTextureQuad(5,185,150,150,mapPreviewTexture,1.0f); + //renderer.renderTextureQuad(5,185,150,150,mapPreviewTexture,1.0f); + renderer.renderTextureQuad( this->render_mapPreviewTexture_X, + this->render_mapPreviewTexture_Y, + this->render_mapPreviewTexture_W, + this->render_mapPreviewTexture_H, + mapPreviewTexture,1.0f); + //printf("=================> Rendering map preview texture\n"); } @@ -2174,7 +2224,13 @@ void MenuStateCustomGame::render() { if(mapPreviewTexture == NULL) { bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 2); //printf("=================> Rendering map preview into a texture BEFORE (%p)\n", mapPreviewTexture); - renderer.renderMapPreview(&mapPreview, renderAll, 10, 350,&mapPreviewTexture); + + //renderer.renderMapPreview(&mapPreview, renderAll, 10, 350,&mapPreviewTexture); + renderer.renderMapPreview(&mapPreview, renderAll, + this->render_mapPreviewTexture_X, + this->render_mapPreviewTexture_Y, + &mapPreviewTexture); + //printf("=================> Rendering map preview into a texture AFTER (%p)\n", mapPreviewTexture); } } diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index f1d191e0..fa8a68ab 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -192,6 +192,10 @@ private: MapPreview mapPreview; Texture2D *mapPreviewTexture; + int render_mapPreviewTexture_X; + int render_mapPreviewTexture_Y; + int render_mapPreviewTexture_W; + int render_mapPreviewTexture_H; bool autostart; GameSettings *autoStartSettings; diff --git a/source/shared_lib/sources/util/leak_dumper.cpp b/source/shared_lib/sources/util/leak_dumper.cpp index 54799b21..133b3e8d 100644 --- a/source/shared_lib/sources/util/leak_dumper.cpp +++ b/source/shared_lib/sources/util/leak_dumper.cpp @@ -31,40 +31,44 @@ AllocRegistry::~AllocRegistry() { } void AllocRegistry::dump(const char *path) { + + int leakCount=0; + size_t leakBytes=0; + + time_t debugTime = time(NULL); + struct tm *loctime = localtime (&debugTime); + char szBuf2[100]=""; + strftime(szBuf2,100,"%Y-%m-%d %H:%M:%S",loctime); + #ifdef WIN32 FILE* f= _wfopen(utf8_decode(path).c_str(), L"wt"); #else FILE *f= fopen(path, "wt"); #endif - int leakCount=0; - size_t leakBytes=0; - time_t debugTime = time(NULL); - struct tm *loctime = localtime (&debugTime); - char szBuf2[100]=""; - strftime(szBuf2,100,"%Y-%m-%d %H:%M:%S",loctime); + if(f) { + fprintf(f, "Memory leak dump at: %s\n\n",szBuf2); - fprintf(f, "Memory leak dump at: %s\n\n",szBuf2); + for(int index = 0; index < maxAllocs; ++index) { + AllocInfo &info = allocs[index]; + if(info.freetouse == false && info.inuse == true) { - for(int i=0; i 0) { + leakBytes += info.bytes; - if(info.line > 0) { - leakBytes += info.bytes; - - //allocs[i].stack = AllocInfo::getStackTrace(); - fprintf(f, "Leak #%d.\tfile: %s, line: %d, ptr [%p], bytes: " MG_SIZE_T_SPECIFIER ", array: %d, inuse: %d\n%s\n", ++leakCount, info.file, info.line, info.ptr, info.bytes, info.array,info.inuse,info.stack.c_str()); + //allocs[i].stack = AllocInfo::getStackTrace(); + fprintf(f, "Leak #%d.\tfile: %s, line: %d, ptr [%p], bytes: " MG_SIZE_T_SPECIFIER ", array: %d, inuse: %d\n%s\n", ++leakCount, info.file, info.line, info.ptr, info.bytes, info.array,info.inuse,info.stack.c_str()); + } } } + + fprintf(f, "\nTotal leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes); + fprintf(f, "Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes); + fprintf(f, "Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes); + + fclose(f); } - fprintf(f, "\nTotal leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes); - fprintf(f, "Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes); - fprintf(f, "Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes); - - if(f) fclose(f); - printf("Memory leak dump summary at: %s\n",szBuf2); printf("Total leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes); printf("Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes);