From d142d80b05710acb487f149dfb6f0d18c748bb5d Mon Sep 17 00:00:00 2001 From: mathusummut Date: Fri, 29 Jun 2018 00:42:44 +0200 Subject: [PATCH] Fading out at death works again --- source/g3d_viewer/renderer.cpp | 4 +- source/g3d_viewer/renderer.h | 5 +- source/glest_game/game/game.cpp | 559 +++---- source/glest_game/graphics/renderer.cpp | 8 +- source/glest_game/main/main.cpp | 1337 ++++++++--------- .../include/graphics/gl/model_renderer_gl.h | 36 +- .../include/graphics/model_renderer.h | 22 +- .../sources/graphics/gl/model_renderer_gl.cpp | 45 +- 8 files changed, 960 insertions(+), 1056 deletions(-) diff --git a/source/g3d_viewer/renderer.cpp b/source/g3d_viewer/renderer.cpp index a3201c4af..e3a716bb1 100644 --- a/source/g3d_viewer/renderer.cpp +++ b/source/g3d_viewer/renderer.cpp @@ -312,7 +312,7 @@ namespace Shared { assert(false); break; } - meshCallbackTeamColor.setTeamTexture(customTexture); + meshCallback.setTeamTexture(customTexture); if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); @@ -371,7 +371,7 @@ namespace Shared { void Renderer::renderTheModel(Model *model, float f) { if (model != NULL) { - modelRenderer->begin(true, true, !wireframe, false, &meshCallbackTeamColor); + modelRenderer->begin(true, true, !wireframe, false, &meshCallback); model->updateInterpolationData(f, true); modelRenderer->render(model); diff --git a/source/g3d_viewer/renderer.h b/source/g3d_viewer/renderer.h index 3cc2f67a9..8ca5ec539 100644 --- a/source/g3d_viewer/renderer.h +++ b/source/g3d_viewer/renderer.h @@ -38,10 +38,9 @@ using Shared::Graphics::Texture2D; using Shared::Graphics::ParticleRenderer; using Shared::Graphics::ParticleManager; using Shared::Graphics::ParticleSystem; -using Shared::Graphics::Gl::MeshCallbackTeamColor; +using Shared::Graphics::Gl::MeshCallback; //#include "model_renderer.h" -using Shared::Graphics::MeshCallback; using Shared::Graphics::Mesh; using Shared::Graphics::Texture; @@ -97,7 +96,7 @@ namespace Shared { Texture2D *customTextureOrange; Texture2D *customTextureMagenta; Texture2D *customTextureTransparent; - MeshCallbackTeamColor meshCallbackTeamColor; + MeshCallback meshCallback; float red; float green; diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index fb4c1f92b..814364b3d 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -6279,339 +6279,262 @@ namespace Glest { //printf("In game checking keypress for key [%d] camera left [%d]\n",key.keysym.sym,configKeys.getSDLKey("CameraModeLeft")); - if (isKeyPressed - (configKeys.getSDLKey("RenderInGamePerformance"), key, - false) == true) { + if (isKeyPressed(configKeys.getSDLKey("RenderInGamePerformance"), key, false) == true) { renderInGamePerformance = !renderInGamePerformance; Config::getInstance().setBool("PerformanceWarningEnabled", renderInGamePerformance, true); } //if(key == configKeys.getCharKey("RenderNetworkStatus")) { - else - if (isKeyPressed - (configKeys.getSDLKey("RenderNetworkStatus"), key, - false) == true) { - renderNetworkStatus = !renderNetworkStatus; - } + else if (isKeyPressed(configKeys.getSDLKey("RenderNetworkStatus"), key, false) == true) { + renderNetworkStatus = !renderNetworkStatus; + } //else if(key == configKeys.getCharKey("ShowFullConsole")) { - else - if (isKeyPressed - (configKeys.getSDLKey("ShowFullConsole"), key, - false) == true) { - showFullConsole = true; - } else - if (isKeyPressed - (configKeys.getSDLKey("SetMarker"), key, - setMarkerKeyAllowsModifier) == true) { - setMarker = true; - printf("%d\n", key.keysym.scancode); + else if (isKeyPressed(configKeys.getSDLKey("ShowFullConsole"), key, false) == true) { + showFullConsole = true; + } else if (isKeyPressed(configKeys.getSDLKey("SetMarker"), key, setMarkerKeyAllowsModifier) == true) { + setMarker = true; + printf("%d\n", key.keysym.scancode); + } + else if (isKeyPressed(configKeys.getSDLKey("TogglePhotoMode"), key, false) == true) { + photoModeEnabled = !photoModeEnabled; + if (photoModeEnabled == true && + this->gameSettings.isNetworkGame() == false) { + gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); + } else if (photoModeEnabled == false) { + gameCamera.setMaxHeight(-1); + } + + } + //Toggle Healthbars + else if (isKeyPressed(configKeys.getSDLKey("ToggleHealthbars"), key, false) == true) { + switch (healthbarMode) { + case hbvUndefined: + healthbarMode = hbvOff; + console.addLine(lang.getString("Healthbar2") + ": " + + lang.getString("HealthbarsOff")); + break; + case hbvOff: + healthbarMode = hbvAlways; + console.addLine(lang.getString("Healthbar2") + ": " + + lang.getString("HealthbarsAlways")); + break; + case hbvAlways: + healthbarMode = hbvIfNeeded; + console.addLine(lang.getString("Healthbar2") + ": " + + lang.getString("HealthbarsIfNeeded")); + break; + case hbvIfNeeded: + healthbarMode = hbvSelected; + console.addLine(lang.getString("Healthbar2") + ": " + + lang.getString("HealthbarsSelected")); + break; + case hbvSelected: + healthbarMode = hbvSelected | hbvIfNeeded; + console.addLine(lang.getString("Healthbar2") + ": " + + lang.getString("HealthbarsSelectedOrNeeded")); + break; + case (hbvSelected | hbvIfNeeded): + healthbarMode = hbvUndefined; + console.addLine(lang.getString("Healthbar2") + ": " + + lang.getString("HealthbarsFactionDefault")); + break; + default: + printf + ("In [%s::%s Line: %d] Toggle Healthbars Hotkey - Invalid Value. Setting to default.\n", + extractFileFromDirectoryPath(__FILE__).c_str(), + __FUNCTION__, __LINE__); + healthbarMode = hbvUndefined; + break; + } + } + //Toggle music + else if (isKeyPressed(configKeys.getSDLKey("ToggleMusic"), key, false) == true) { + if (this->masterserverMode == false) { + Config & config = Config::getInstance(); + StrSound *gameMusic = + world.getThisFaction()->getType()->getMusic(); + if (gameMusic != NULL) { + float + configVolume = (config.getInt("SoundVolumeMusic") / 100.f); + float currentVolume = gameMusic->getVolume(); + if (currentVolume > 0) { + gameMusic->setVolume(0); + console.addLine(lang.getString("GameMusic") + + " " + lang.getString("Off")); + } else { + //If the config says zero, use the default music volume + gameMusic->setVolume(configVolume ? configVolume : 0.9); + console.addLine(lang.getString("GameMusic")); } - //else if(key == configKeys.getCharKey("TogglePhotoMode")) { - else - if (isKeyPressed - (configKeys.getSDLKey("TogglePhotoMode"), key, - false) == true) { - photoModeEnabled = !photoModeEnabled; - if (photoModeEnabled == true && - this->gameSettings.isNetworkGame() == false) { - gameCamera.setMaxHeight(PHOTO_MODE_MAXHEIGHT); - } else if (photoModeEnabled == false) { - gameCamera.setMaxHeight(-1); - } + } + } + } + //move camera left + else if (isKeyPressed(configKeys.getSDLKey("CameraModeLeft"), key, false) == true) { + gameCamera.setMoveX(-1); + camLeftButtonDown = true; + } + //move camera right + else if (isKeyPressed(configKeys.getSDLKey("CameraModeRight"), key, false) == true) { + gameCamera.setMoveX(1); + camRightButtonDown = true; + } + //move camera up + else if (isKeyPressed(configKeys.getSDLKey("CameraModeUp"), key, false) == true) { + gameCamera.setMoveZ(1); + camUpButtonDown = true; + } + //move camera down + else if (isKeyPressed(configKeys.getSDLKey("CameraModeDown"), key, false) == true) { + gameCamera.setMoveZ(-1); + camDownButtonDown = true; + } + //change camera mode + else if (isKeyPressed(configKeys.getSDLKey("FreeCameraMode"), key, false) == true) { + if (gameCamera.getState() == GameCamera::sFree) { + gameCamera.setState(GameCamera::sGame); + string + stateString = + gameCamera.getState() == + GameCamera:: + sGame ? lang.getString("GameCamera") : + lang.getString("FreeCamera"); + console.addLine(lang.getString("CameraModeSet") + " " + + stateString); + } else if (gameCamera.getState() == GameCamera::sGame) { + gameCamera.setState(GameCamera::sFree); + string + stateString = + gameCamera.getState() == + GameCamera:: + sGame ? lang.getString("GameCamera") : + lang.getString("FreeCamera"); + console.addLine(lang.getString("CameraModeSet") + " " + + stateString); + } + //else ignore! + } + //reset camera mode to normal + else if (isKeyPressed(configKeys.getSDLKey("ResetCameraMode"), key, false) == true) { + if (currentCameraFollowUnit != NULL) { + currentCameraFollowUnit = NULL; + } + gameCamera.setState(GameCamera::sGame); + } + //pause + else if (isKeyPressed(configKeys.getSDLKey("PauseGame"), key, false) == true) { + //printf("Toggle pause paused = %d\n",paused); + //setPaused(!paused); - } - //Toggle Healthbars - else - if (isKeyPressed - (configKeys.getSDLKey("ToggleHealthbars"), key, - false) == true) { - switch (healthbarMode) { - case hbvUndefined: - healthbarMode = hbvOff; - console.addLine(lang.getString("Healthbar2") + ": " + - lang.getString("HealthbarsOff")); - break; - case hbvOff: - healthbarMode = hbvAlways; - console.addLine(lang.getString("Healthbar2") + ": " + - lang.getString("HealthbarsAlways")); - break; - case hbvAlways: - healthbarMode = hbvIfNeeded; - console.addLine(lang.getString("Healthbar2") + ": " + - lang.getString("HealthbarsIfNeeded")); - break; - case hbvIfNeeded: - healthbarMode = hbvSelected; - console.addLine(lang.getString("Healthbar2") + ": " + - lang.getString("HealthbarsSelected")); - break; - case hbvSelected: - healthbarMode = hbvSelected | hbvIfNeeded; - console.addLine(lang.getString("Healthbar2") + ": " + - lang.getString("HealthbarsSelectedOrNeeded")); - break; - case (hbvSelected | hbvIfNeeded): - healthbarMode = hbvUndefined; - console.addLine(lang.getString("Healthbar2") + ": " + - lang.getString("HealthbarsFactionDefault")); - break; - default: - printf - ("In [%s::%s Line: %d] Toggle Healthbars Hotkey - Invalid Value. Setting to default.\n", - extractFileFromDirectoryPath(__FILE__).c_str(), - __FUNCTION__, __LINE__); - healthbarMode = hbvUndefined; - break; - } - } - //Toggle music - //else if(key == configKeys.getCharKey("ToggleMusic")) { - else - if (isKeyPressed - (configKeys.getSDLKey("ToggleMusic"), key, false) == true) { + bool allowAdminMenuItems = false; + NetworkManager & networkManager = NetworkManager::getInstance(); + NetworkRole role = networkManager.getNetworkRole(); + if (role == nrServer) { + allowAdminMenuItems = true; + } else if (role == nrClient) { + ClientInterface *clientInterface = + dynamic_cast < + ClientInterface *>(networkManager.getClientInterface()); - if (this->masterserverMode == false) { - Config & config = Config::getInstance(); - StrSound *gameMusic = - world.getThisFaction()->getType()->getMusic(); - if (gameMusic != NULL) { - float - configVolume = (config.getInt("SoundVolumeMusic") / 100.f); - float currentVolume = gameMusic->getVolume(); - if (currentVolume > 0) { - gameMusic->setVolume(0); - console.addLine(lang.getString("GameMusic") + - " " + lang.getString("Off")); - } else { - //If the config says zero, use the default music volume - gameMusic->setVolume(configVolume ? configVolume : 0.9); - console.addLine(lang.getString("GameMusic")); - } - } - } - } - //move camera left - //else if(key == configKeys.getCharKey("CameraModeLeft")) { - else - if (isKeyPressed - (configKeys.getSDLKey("CameraModeLeft"), key, false) == true) { - gameCamera.setMoveX(-1); - camLeftButtonDown = true; - } - //move camera right - //else if(key == configKeys.getCharKey("CameraModeRight")) { - else - if (isKeyPressed - (configKeys.getSDLKey("CameraModeRight"), key, - false) == true) { - gameCamera.setMoveX(1); - camRightButtonDown = true; - } - //move camera up - //else if(key == configKeys.getCharKey("CameraModeUp")) { - else - if (isKeyPressed - (configKeys.getSDLKey("CameraModeUp"), key, false) == true) { - gameCamera.setMoveZ(1); - camUpButtonDown = true; - } - //move camera down - //else if(key == configKeys.getCharKey("CameraModeDown")) { - else - if (isKeyPressed - (configKeys.getSDLKey("CameraModeDown"), key, false) == true) { - gameCamera.setMoveZ(-1); - camDownButtonDown = true; - } - //change camera mode - //else if(key == configKeys.getCharKey("FreeCameraMode")) { - else - if (isKeyPressed - (configKeys.getSDLKey("FreeCameraMode"), key, false) == true) { - if (gameCamera.getState() == GameCamera::sFree) { - gameCamera.setState(GameCamera::sGame); - string - stateString = - gameCamera.getState() == - GameCamera:: - sGame ? lang.getString("GameCamera") : - lang.getString("FreeCamera"); - console.addLine(lang.getString("CameraModeSet") + " " + - stateString); - } else if (gameCamera.getState() == GameCamera::sGame) { - gameCamera.setState(GameCamera::sFree); - string - stateString = - gameCamera.getState() == - GameCamera:: - sGame ? lang.getString("GameCamera") : - lang.getString("FreeCamera"); - console.addLine(lang.getString("CameraModeSet") + " " + - stateString); - } - //else ignore! - } - //reset camera mode to normal - //else if(key == configKeys.getCharKey("ResetCameraMode")) { - else - if (isKeyPressed - (configKeys.getSDLKey("ResetCameraMode"), key, - false) == true) { - if (currentCameraFollowUnit != NULL) { - currentCameraFollowUnit = NULL; - } - gameCamera.setState(GameCamera::sGame); - } - //pause - //else if(key == configKeys.getCharKey("PauseGame")) { - else - if (isKeyPressed - (configKeys.getSDLKey("PauseGame"), key, false) == true) { - //printf("Toggle pause paused = %d\n",paused); - //setPaused(!paused); + if (clientInterface != NULL && + gameSettings.getMasterserver_admin() == + clientInterface->getSessionKey()) { + allowAdminMenuItems = true; + } + } - bool allowAdminMenuItems = false; - NetworkManager & networkManager = NetworkManager::getInstance(); - NetworkRole role = networkManager.getNetworkRole(); - if (role == nrServer) { - allowAdminMenuItems = true; - } else if (role == nrClient) { - ClientInterface *clientInterface = - dynamic_cast < - ClientInterface *>(networkManager.getClientInterface()); + if (allowAdminMenuItems) { + if (getPaused() == false) { + commander.tryPauseGame(false, false); + } else { + commander.tryResumeGame(false, false); + } + } + } else if (isKeyPressed(configKeys.getSDLKey("ExtraTeamColorMarker"), key, false) == true) { + //printf("Toggle ExtraTeamColorMarker\n"); + toggleTeamColorMarker(); + } + //switch display color + else if (isKeyPressed (configKeys.getSDLKey("ChangeFontColor"), key, false) == true) { + gui.switchToNextDisplayColor(); + } + //increment speed + else if (isKeyPressed(configKeys.getSDLKey("GameSpeedIncrease"), key, false) == true) { + bool + speedChangesAllowed = + !NetworkManager:: + getInstance().isNetworkGameWithConnectedClients(); + if (speedChangesAllowed) { + incSpeed(); + } + } + //decrement speed + else if (isKeyPressed(configKeys.getSDLKey("GameSpeedDecrease"), key, false) == true) { + bool + speedChangesAllowed = + !NetworkManager:: + getInstance().isNetworkGameWithConnectedClients(); + if (speedChangesAllowed) { + decSpeed(); + } + } else if (isKeyPressed(configKeys.getSDLKey("BookmarkAdd"), key, false) == true) { + startMarkCell(); + } else if (isKeyPressed(configKeys.getSDLKey("BookmarkRemove"), key, false) == true) { + isUnMarkCellEnabled = true; + } else if (isKeyPressed(configKeys.getSDLKey("CameraFollowSelectedUnit"), key, false) == true) { + startCameraFollowUnit(); + } + //exit + else if (isKeyPressed(configKeys.getSDLKey("ExitKey"), key, false) == true) { + popupMenu.setEnabled(!popupMenu.getEnabled()); + popupMenu.setVisible(popupMenu.getEnabled()); + } - if (clientInterface != NULL && - gameSettings.getMasterserver_admin() == - clientInterface->getSessionKey()) { - allowAdminMenuItems = true; - } - } + //hotkeys + if (SystemFlags:: + getSystemSettingType(SystemFlags::debugSystem).enabled) + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d] gameCamera.getState() = %d\n", + extractFileFromDirectoryPath(__FILE__). + c_str(), __FUNCTION__, __LINE__, + gameCamera.getState()); - if (allowAdminMenuItems) { - if (getPaused() == false) { - commander.tryPauseGame(false, false); - } else { - commander.tryResumeGame(false, false); - } - } - } else - if (isKeyPressed - (configKeys.getSDLKey("ExtraTeamColorMarker"), key, - false) == true) { - //printf("Toggle ExtraTeamColorMarker\n"); - toggleTeamColorMarker(); - } - //switch display color - //else if(key == configKeys.getCharKey("ChangeFontColor")) { - else - if (isKeyPressed - (configKeys.getSDLKey("ChangeFontColor"), key, - false) == true) { - gui.switchToNextDisplayColor(); - } - //increment speed - //else if(key == configKeys.getCharKey("GameSpeedIncrease")) { - else - if (isKeyPressed - (configKeys.getSDLKey("GameSpeedIncrease"), key, - false) == true) { - bool - speedChangesAllowed = - !NetworkManager:: - getInstance().isNetworkGameWithConnectedClients(); - if (speedChangesAllowed) { - incSpeed(); - } - } - //decrement speed - //else if(key == configKeys.getCharKey("GameSpeedDecrease")) { - else - if (isKeyPressed - (configKeys.getSDLKey("GameSpeedDecrease"), key, - false) == true) { - bool - speedChangesAllowed = - !NetworkManager:: - getInstance().isNetworkGameWithConnectedClients(); - if (speedChangesAllowed) { - decSpeed(); - } - } else - if (isKeyPressed - (configKeys.getSDLKey("BookmarkAdd"), key, false) == true) { - startMarkCell(); - } else - if (isKeyPressed - (configKeys.getSDLKey("BookmarkRemove"), key, false) == true) { - isUnMarkCellEnabled = true; - } else - if (isKeyPressed - (configKeys.getSDLKey("CameraFollowSelectedUnit"), key, - false) == true) { - startCameraFollowUnit(); - } - //exit - else - if (isKeyPressed(configKeys.getSDLKey("ExitKey"), key, false) - == true) { - popupMenu.setEnabled(!popupMenu.getEnabled()); - popupMenu.setVisible(popupMenu.getEnabled()); - } + if (gameCamera.getState() != GameCamera::sFree) { + if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem). + enabled) + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d] key = %d\n", + extractFileFromDirectoryPath + (__FILE__).c_str(), __FUNCTION__, + __LINE__, key); - //hotkeys - if (SystemFlags:: - getSystemSettingType(SystemFlags::debugSystem).enabled) - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d] gameCamera.getState() = %d\n", - extractFileFromDirectoryPath(__FILE__). - c_str(), __FUNCTION__, __LINE__, - gameCamera.getState()); + gui.hotKey(key); + } else { + //rotate camera leftt + //if(key == configKeys.getCharKey("CameraRotateLeft")) { + if (isKeyPressed(configKeys.getSDLKey("CameraRotateLeft"), key) == true) { + gameCamera.setRotate(-1); + } + //rotate camera right + //else if(key == configKeys.getCharKey("CameraRotateRight")){ + else if (isKeyPressed(configKeys.getSDLKey("CameraRotateRight"), key) == true) { + gameCamera.setRotate(1); + } + //camera up + //else if(key == configKeys.getCharKey("CameraRotateUp")) { + else if (isKeyPressed(configKeys.getSDLKey("CameraRotateUp"), key) == true) { + gameCamera.setMoveY(1); + } + //camera down + else if (isKeyPressed(configKeys.getSDLKey("CameraRotateDown"), key) == true) { + gameCamera.setMoveY(-1); + } + } - if (gameCamera.getState() != GameCamera::sFree) { - if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem). - enabled) - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d] key = %d\n", - extractFileFromDirectoryPath - (__FILE__).c_str(), __FUNCTION__, - __LINE__, key); - - gui.hotKey(key); - } else { - //rotate camera leftt - //if(key == configKeys.getCharKey("CameraRotateLeft")) { - if (isKeyPressed - (configKeys.getSDLKey("CameraRotateLeft"), key) == true) { - gameCamera.setRotate(-1); - } - //rotate camera right - //else if(key == configKeys.getCharKey("CameraRotateRight")){ - else - if (isKeyPressed - (configKeys.getSDLKey("CameraRotateRight"), key) == true) { - gameCamera.setRotate(1); - } - //camera up - //else if(key == configKeys.getCharKey("CameraRotateUp")) { - else - if (isKeyPressed - (configKeys.getSDLKey("CameraRotateUp"), key) == true) { - gameCamera.setMoveY(1); - } - //camera down - //else if(key == configKeys.getCharKey("CameraRotateDown")) { - else - if (isKeyPressed - (configKeys.getSDLKey("CameraRotateDown"), key) == true) { - gameCamera.setMoveY(-1); - } - } - - if (isKeyPressed(configKeys.getSDLKey("SaveGame"), key) == true) { - saveGame(); - } + if (isKeyPressed(configKeys.getSDLKey("SaveGame"), key) == true) { + saveGame(); + } } } catch (const exception & ex) { char szBuf[8096] = ""; diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index ec722b52d..73e3918b4 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5160,7 +5160,7 @@ namespace Glest { //Unit *unit=NULL; //const World *world= game->getWorld(); - MeshCallbackTeamColor meshCallbackTeamColor; + MeshCallback meshCallback; //assert assertGl(); @@ -5183,7 +5183,7 @@ namespace Glest { if ((airUnits == false && unit->getType()->getField() == fAir) || (airUnits == true && unit->getType()->getField() != fAir)) { continue; } - meshCallbackTeamColor.setTeamTexture(unit->getFaction()->getTexture()); + meshCallback.setTeamTexture(unit->getFaction()->getTexture()); if (modelRenderStarted == false) { modelRenderStarted = true; @@ -5204,7 +5204,7 @@ namespace Glest { } glActiveTexture(baseTexUnit); - modelRenderer->begin(true, true, true, false, &meshCallbackTeamColor); + modelRenderer->begin(true, true, true, false, &meshCallback); } glMatrixMode(GL_MODELVIEW); @@ -5243,7 +5243,7 @@ namespace Glest { model->updateInterpolationData(unit->getAnimProgressAsFloat(), unit->isAlive() && !unit->isAnimProgressBound()); //} - modelRenderer->render(model, alpha); + modelRenderer->render(model, 0, alpha); triangleCount += model->getTriangleCount(); pointCount += model->getVertexCount(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index adf2d9be0..dedeb93fe 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -6815,7 +6815,7 @@ namespace setAllowAltEnterFullscreenToggle(allowAltEnterFullscreenToggle); if (config.getBool("noTeamColors", "false") == true) { - MeshCallbackTeamColor::noTeamColors = true; + MeshCallback::noTeamColors = true; } @@ -7259,770 +7259,747 @@ namespace true) { program->initServer(mainWindow, false, true); gameInitialized = true; - } else - if (hasCommandArgument - (argc, argv, - string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) { - program->initServer(mainWindow, false, true, true); - gameInitialized = true; - } else - if (hasCommandArgument - (argc, argv, - string(GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME])) == true) { - program->initServer(mainWindow, true, false); - gameInitialized = true; - } else - if (hasCommandArgument - (argc, argv, - string(GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME])) == - true) { + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) { + program->initServer(mainWindow, false, true, true); + gameInitialized = true; + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME])) == true) { + program->initServer(mainWindow, true, false); + gameInitialized = true; + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_AUTOSTART_LAST_SAVED_GAME])) == true) { + string + fileName = ""; + int + foundParamIndIndex = -1; + hasCommandArgument(argc, argv, + string(GAME_ARGS + [GAME_ARG_AUTOSTART_LAST_SAVED_GAME]) + + string("="), &foundParamIndIndex); + if (foundParamIndIndex >= 0) { + string + loadfileName = argv[foundParamIndIndex]; + vector < string > paramPartTokens; + Tokenize(loadfileName, paramPartTokens, "="); + if (paramPartTokens.size() >= 2 + && paramPartTokens[1].length() > 0) { + fileName = paramPartTokens[1]; + + if (fileExists(fileName) == false) { + // Save the file now string - fileName = ""; - int - foundParamIndIndex = -1; - hasCommandArgument(argc, argv, - string(GAME_ARGS - [GAME_ARG_AUTOSTART_LAST_SAVED_GAME]) + - string("="), &foundParamIndIndex); - if (foundParamIndIndex >= 0) { - string - loadfileName = argv[foundParamIndIndex]; - vector < string > paramPartTokens; - Tokenize(loadfileName, paramPartTokens, "="); - if (paramPartTokens.size() >= 2 - && paramPartTokens[1].length() > 0) { - fileName = paramPartTokens[1]; - - if (fileExists(fileName) == false) { - // Save the file now - string - saveGameFile = "saved/" + fileName; - if (getGameReadWritePath - (GameConstants::path_logs_CacheLookupKey) != "") { - saveGameFile = - getGameReadWritePath - (GameConstants::path_logs_CacheLookupKey) + saveGameFile; - } else { - saveGameFile = userData + saveGameFile; - } - if (fileExists(saveGameFile) == true) { - fileName = saveGameFile; - } - } - - if (fileExists(fileName) == false) { - char - szBuf[8096] = ""; - snprintf(szBuf, 8096, - "File specified for loading a saved game cannot be found: [%s]", - fileName.c_str()); - printf - ("\n\n======================================================================================\n%s\n======================================================================================\n\n\n", - szBuf); - - throw - megaglest_runtime_error(szBuf); - } - } + saveGameFile = "saved/" + fileName; + if (getGameReadWritePath + (GameConstants::path_logs_CacheLookupKey) != "") { + saveGameFile = + getGameReadWritePath + (GameConstants::path_logs_CacheLookupKey) + saveGameFile; + } else { + saveGameFile = userData + saveGameFile; } - program->initSavedGame(mainWindow, false, fileName); - gameInitialized = true; - } else - if (hasCommandArgument - (argc, argv, string(GAME_ARGS[GAME_ARG_PREVIEW_MAP])) == true) { - int - foundParamIndIndex = -1; - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_PREVIEW_MAP]) + - string("="), &foundParamIndIndex); - if (foundParamIndIndex < 0) { - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_PREVIEW_MAP]), - &foundParamIndIndex); - } - string - mapName = argv[foundParamIndIndex]; - vector < string > paramPartTokens; - Tokenize(mapName, paramPartTokens, "="); - if (paramPartTokens.size() >= 2 - && paramPartTokens[1].length() > 0) { - vector < string > paramPartTokens2; - string - tileset = "forest"; - Tokenize(paramPartTokens[1], paramPartTokens2, ","); - if (paramPartTokens2.size() >= 2 - && paramPartTokens2[1].length() > 0) { - tileset = paramPartTokens2[1]; - } - string - autoloadMapName = paramPartTokens2[0]; - - GameSettings * - gameSettings = &startupGameSettings; - gameSettings->setMap(autoloadMapName); - gameSettings->setTileset(tileset); - gameSettings->setTech("zetapack"); - gameSettings->setDefaultUnits(false); - gameSettings->setDefaultResources(false); - gameSettings->setDefaultVictoryConditions(true); - gameSettings->setFogOfWar(false); - gameSettings->setAllowObservers(true); - gameSettings->setPathFinderType(pfBasic); - - for (int i = 0; i < GameConstants::maxPlayers; ++i) { - ControlType - ct = ctClosed; - - gameSettings->setNetworkPlayerStatuses(i, npst_None); - gameSettings->setFactionControl(i, ct); - gameSettings->setStartLocationIndex(i, i); - gameSettings->setResourceMultiplierIndex(i, 10); - gameSettings->setNetworkPlayerName(i, - GameConstants:: - NETWORK_SLOT_CLOSED_SLOTNAME); - } - - ControlType - ct = ctHuman; - - gameSettings->setNetworkPlayerStatuses(0, npst_None); - gameSettings->setFactionControl(0, ct); - gameSettings->setFactionTypeName(0, - formatString - (GameConstants:: - OBSERVER_SLOTNAME)); - gameSettings->setTeam(0, - GameConstants::maxPlayers + fpt_Observer - - 1); - gameSettings->setStartLocationIndex(0, 0); - gameSettings->setNetworkPlayerName(0, - GameConstants:: - OBSERVER_SLOTNAME); - - gameSettings->setFactionCount(1); - - Config & config = Config::getInstance(); - gameSettings->setEnableServerControlledAI(config.getBool - ("ServerControlledAI", - "true")); - gameSettings->setNetworkFramePeriod(config.getInt - ("NetworkSendFrameCount", - "20")); - - program->initServer(mainWindow, gameSettings); - gameInitialized = true; - } else { - printf - ("\nInvalid map name specified on commandline [%s] map [%s]\n\n", - argv[foundParamIndIndex], - (paramPartTokens.size() >= - 2 ? paramPartTokens[1].c_str() : NULL)); - printParameterHelp(argv[0], foundInvalidArgs); - delete - mainWindow; - mainWindow = NULL; - return 1; - } + if (fileExists(saveGameFile) == true) { + fileName = saveGameFile; } + } - else - if (hasCommandArgument - (argc, argv, string(GAME_ARGS[GAME_ARG_CONNECT])) == true) { - int - foundParamIndIndex = -1; - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_CONNECT]) + - string("="), &foundParamIndIndex); - if (foundParamIndIndex < 0) { - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_CONNECT]), - &foundParamIndIndex); - } - string - serverToConnectTo = argv[foundParamIndIndex]; - vector < string > paramPartTokens; - Tokenize(serverToConnectTo, paramPartTokens, "="); - if (paramPartTokens.size() >= 2 - && paramPartTokens[1].length() > 0) { - string - autoConnectServer = paramPartTokens[1]; + if (fileExists(fileName) == false) { + char + szBuf[8096] = ""; + snprintf(szBuf, 8096, + "File specified for loading a saved game cannot be found: [%s]", + fileName.c_str()); + printf + ("\n\n======================================================================================\n%s\n======================================================================================\n\n\n", + szBuf); - int - port = config.getInt("PortServer", - intToStr(GameConstants:: - serverPort).c_str()); - vector < string > paramPartTokens2; - Tokenize(autoConnectServer, paramPartTokens2, ":"); - autoConnectServer = paramPartTokens2[0]; - if (paramPartTokens2.size() >= 2 - && paramPartTokens2[1].length() > 0) { - port = strToInt(paramPartTokens2[1]); - } + throw + megaglest_runtime_error(szBuf); + } + } + } + program->initSavedGame(mainWindow, false, fileName); + gameInitialized = true; + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_PREVIEW_MAP])) == true) { + int + foundParamIndIndex = -1; + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_PREVIEW_MAP]) + + string("="), &foundParamIndIndex); + if (foundParamIndIndex < 0) { + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_PREVIEW_MAP]), + &foundParamIndIndex); + } + string + mapName = argv[foundParamIndIndex]; + vector < string > paramPartTokens; + Tokenize(mapName, paramPartTokens, "="); + if (paramPartTokens.size() >= 2 + && paramPartTokens[1].length() > 0) { + vector < string > paramPartTokens2; + string + tileset = "forest"; + Tokenize(paramPartTokens[1], paramPartTokens2, ","); + if (paramPartTokens2.size() >= 2 + && paramPartTokens2[1].length() > 0) { + tileset = paramPartTokens2[1]; + } + string + autoloadMapName = paramPartTokens2[0]; - printf("Connecting to host [%s] using port: %d\n", - autoConnectServer.c_str(), port); - if (autoConnectServer == "auto-connect") { - program->initClientAutoFindHost(mainWindow); - } else { - program->initClient(mainWindow, autoConnectServer, port); - } - gameInitialized = true; - } else { + GameSettings * + gameSettings = &startupGameSettings; + gameSettings->setMap(autoloadMapName); + gameSettings->setTileset(tileset); + gameSettings->setTech("zetapack"); + gameSettings->setDefaultUnits(false); + gameSettings->setDefaultResources(false); + gameSettings->setDefaultVictoryConditions(true); + gameSettings->setFogOfWar(false); + gameSettings->setAllowObservers(true); + gameSettings->setPathFinderType(pfBasic); - printf - ("\nInvalid host specified on commandline [%s] host [%s]\n\n", - argv[foundParamIndIndex], - (paramPartTokens.size() >= - 2 ? paramPartTokens[1].c_str() : NULL)); - printParameterHelp(argv[0], foundInvalidArgs); - delete - mainWindow; - mainWindow = NULL; - return 1; - } - } + for (int i = 0; i < GameConstants::maxPlayers; ++i) { + ControlType + ct = ctClosed; - else - if (hasCommandArgument - (argc, argv, string(GAME_ARGS[GAME_ARG_CLIENT])) == true) { - int - foundParamIndIndex = -1; - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_CLIENT]) + - string("="), &foundParamIndIndex); - if (foundParamIndIndex < 0) { - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_CLIENT]), - &foundParamIndIndex); - } - string - serverToConnectTo = argv[foundParamIndIndex]; - vector < string > paramPartTokens; - Tokenize(serverToConnectTo, paramPartTokens, "="); - if (paramPartTokens.size() >= 2 - && paramPartTokens[1].length() > 0) { - string - autoConnectServer = paramPartTokens[1]; + gameSettings->setNetworkPlayerStatuses(i, npst_None); + gameSettings->setFactionControl(i, ct); + gameSettings->setStartLocationIndex(i, i); + gameSettings->setResourceMultiplierIndex(i, 10); + gameSettings->setNetworkPlayerName(i, + GameConstants:: + NETWORK_SLOT_CLOSED_SLOTNAME); + } - if (autoConnectServer == "auto-connect") { - program->initClientAutoFindHost(mainWindow); - } else { - program->initClient(mainWindow, autoConnectServer); - } - gameInitialized = true; - } else { + ControlType + ct = ctHuman; - printf - ("\nInvalid host specified on commandline [%s] host [%s]\n\n", - argv[foundParamIndIndex], - (paramPartTokens.size() >= - 2 ? paramPartTokens[1].c_str() : NULL)); - printParameterHelp(argv[0], foundInvalidArgs); - delete - mainWindow; - mainWindow = NULL; - return 1; - } - } else - if (hasCommandArgument - (argc, argv, string(GAME_ARGS[GAME_ARG_LOADSCENARIO])) == true) { + gameSettings->setNetworkPlayerStatuses(0, npst_None); + gameSettings->setFactionControl(0, ct); + gameSettings->setFactionTypeName(0, + formatString + (GameConstants:: + OBSERVER_SLOTNAME)); + gameSettings->setTeam(0, + GameConstants::maxPlayers + fpt_Observer - + 1); + gameSettings->setStartLocationIndex(0, 0); + gameSettings->setNetworkPlayerName(0, + GameConstants:: + OBSERVER_SLOTNAME); - int - foundParamIndIndex = -1; - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_LOADSCENARIO]) + - string("="), &foundParamIndIndex); - if (foundParamIndIndex < 0) { - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_LOADSCENARIO]), - &foundParamIndIndex); - } - string - scenarioName = argv[foundParamIndIndex]; - vector < string > paramPartTokens; - Tokenize(scenarioName, paramPartTokens, "="); - if (paramPartTokens.size() >= 2 - && paramPartTokens[1].length() > 0) { - string - autoloadScenarioName = paramPartTokens[1]; + gameSettings->setFactionCount(1); - program->initScenario(mainWindow, autoloadScenarioName); - gameInitialized = true; - } else { - printf - ("\nInvalid scenario name specified on commandline [%s] scenario [%s]\n\n", - argv[foundParamIndIndex], - (paramPartTokens.size() >= - 2 ? paramPartTokens[1].c_str() : NULL)); - printParameterHelp(argv[0], foundInvalidArgs); - delete - mainWindow; - mainWindow = NULL; - return 1; - } - } else { - program->initNormal(mainWindow); - } + Config & config = Config::getInstance(); + gameSettings->setEnableServerControlledAI(config.getBool + ("ServerControlledAI", + "true")); + gameSettings->setNetworkFramePeriod(config.getInt + ("NetworkSendFrameCount", + "20")); - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d]\n", __FILE__, - __FUNCTION__, __LINE__); + program->initServer(mainWindow, gameSettings); + gameInitialized = true; + } else { + printf + ("\nInvalid map name specified on commandline [%s] map [%s]\n\n", + argv[foundParamIndIndex], + (paramPartTokens.size() >= + 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0], foundInvalidArgs); + delete + mainWindow; + mainWindow = NULL; + return 1; + } + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_CONNECT])) == true) { + int + foundParamIndIndex = -1; + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_CONNECT]) + + string("="), &foundParamIndIndex); + if (foundParamIndIndex < 0) { + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_CONNECT]), + &foundParamIndIndex); + } + string + serverToConnectTo = argv[foundParamIndIndex]; + vector < string > paramPartTokens; + Tokenize(serverToConnectTo, paramPartTokens, "="); + if (paramPartTokens.size() >= 2 + && paramPartTokens[1].length() > 0) { + string + autoConnectServer = paramPartTokens[1]; - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d] OpenGL Info:\n%s\n", - __FILE__, __FUNCTION__, __LINE__, - renderer.getGlInfo().c_str()); + int + port = config.getInt("PortServer", + intToStr(GameConstants:: + serverPort).c_str()); + vector < string > paramPartTokens2; + Tokenize(autoConnectServer, paramPartTokens2, ":"); + autoConnectServer = paramPartTokens2[0]; + if (paramPartTokens2.size() >= 2 + && paramPartTokens2[1].length() > 0) { + port = strToInt(paramPartTokens2[1]); + } - if (hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_OPENGL_INFO]) - == true) { - printf("%s", renderer.getGlInfo().c_str()); - printf("%s", renderer.getGlMoreInfo().c_str()); + printf("Connecting to host [%s] using port: %d\n", + autoConnectServer.c_str(), port); + if (autoConnectServer == "auto-connect") { + program->initClientAutoFindHost(mainWindow); + } else { + program->initClient(mainWindow, autoConnectServer, port); + } + gameInitialized = true; + } else { - delete - mainWindow; - mainWindow = NULL; - return 0; - } + printf + ("\nInvalid host specified on commandline [%s] host [%s]\n\n", + argv[foundParamIndIndex], + (paramPartTokens.size() >= + 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0], foundInvalidArgs); + delete + mainWindow; + mainWindow = NULL; + return 1; + } + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_CLIENT])) == true) { + int + foundParamIndIndex = -1; + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_CLIENT]) + + string("="), &foundParamIndIndex); + if (foundParamIndIndex < 0) { + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_CLIENT]), + &foundParamIndIndex); + } + string + serverToConnectTo = argv[foundParamIndIndex]; + vector < string > paramPartTokens; + Tokenize(serverToConnectTo, paramPartTokens, "="); + if (paramPartTokens.size() >= 2 + && paramPartTokens[1].length() > 0) { + string + autoConnectServer = paramPartTokens[1]; - if (hasCommandArgument - (argc, argv, GAME_ARGS[GAME_ARG_CONVERT_MODELS]) == true) { - int - foundParamIndIndex = -1; - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_CONVERT_MODELS]) + - string("="), &foundParamIndIndex); - if (foundParamIndIndex < 0) { - hasCommandArgument(argc, argv, - string(GAME_ARGS[GAME_ARG_CONVERT_MODELS]), - &foundParamIndIndex); - } - string - paramValue = argv[foundParamIndIndex]; - vector < string > paramPartTokens; - Tokenize(paramValue, paramPartTokens, "="); - if (paramPartTokens.size() >= 2 - && paramPartTokens[1].length() > 0) { - string - modelFile = paramPartTokens[1]; - printf("About to convert model(s) [%s]\n", modelFile.c_str()); + if (autoConnectServer == "auto-connect") { + program->initClientAutoFindHost(mainWindow); + } else { + program->initClient(mainWindow, autoConnectServer); + } + gameInitialized = true; + } else { - string - textureFormat = ""; - if (paramPartTokens.size() >= 3 - && paramPartTokens[1].length() > 0) { - textureFormat = paramPartTokens[2]; - printf("About to convert using texture format [%s]\n", - textureFormat.c_str()); - } + printf + ("\nInvalid host specified on commandline [%s] host [%s]\n\n", + argv[foundParamIndIndex], + (paramPartTokens.size() >= + 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0], foundInvalidArgs); + delete + mainWindow; + mainWindow = NULL; + return 1; + } + } else if (hasCommandArgument(argc, argv, string(GAME_ARGS[GAME_ARG_LOADSCENARIO])) == true) { + int + foundParamIndIndex = -1; + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_LOADSCENARIO]) + + string("="), &foundParamIndIndex); + if (foundParamIndIndex < 0) { + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_LOADSCENARIO]), + &foundParamIndIndex); + } + string + scenarioName = argv[foundParamIndIndex]; + vector < string > paramPartTokens; + Tokenize(scenarioName, paramPartTokens, "="); + if (paramPartTokens.size() >= 2 + && paramPartTokens[1].length() > 0) { + string + autoloadScenarioName = paramPartTokens[1]; - bool - keepsmallest = false; - if (paramPartTokens.size() >= 4 - && paramPartTokens[1].length() > 0) { - keepsmallest = (paramPartTokens[3] == "keepsmallest"); - printf("About to convert using keepsmallest = %d\n", - keepsmallest); - } + program->initScenario(mainWindow, autoloadScenarioName); + gameInitialized = true; + } else { + printf + ("\nInvalid scenario name specified on commandline [%s] scenario [%s]\n\n", + argv[foundParamIndIndex], + (paramPartTokens.size() >= + 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0], foundInvalidArgs); + delete + mainWindow; + mainWindow = NULL; + return 1; + } + } else { + program->initNormal(mainWindow); + } - showCursor(true); + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); - const - Metrics & - metrics = Metrics::getInstance(); - renderer.clearBuffers(); - renderer.clearZBuffer(); - renderer.reset2d(); + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d] OpenGL Info:\n%s\n", + __FILE__, __FUNCTION__, __LINE__, + renderer.getGlInfo().c_str()); - if (CoreData::getInstance().getMenuFontBig3D() != NULL) { - renderer.renderText3D("Please wait, converting models...", - CoreData::getInstance(). - getMenuFontBig3D(), Vec3f(1.f, 1.f, - 0.f), - (metrics.getScreenW() / 2) - 400, - (metrics.getScreenH() / 2), true); - } else { - renderer.renderText("Please wait, converting models...", - CoreData::getInstance().getMenuFontBig(), - Vec3f(1.f, 1.f, 0.f), - (metrics.getScreenW() / 2) - 400, - (metrics.getScreenH() / 2), true); - } - renderer.swapBuffers(); + if (hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_OPENGL_INFO]) + == true) { + printf("%s", renderer.getGlInfo().c_str()); + printf("%s", renderer.getGlMoreInfo().c_str()); - std::vector < string > models; - if (isdir(modelFile.c_str()) == true) { - models = - getFolderTreeContentsListRecursively(modelFile, ".g3d"); - } else { - models.push_back(modelFile); - } + delete + mainWindow; + mainWindow = NULL; + return 0; + } - sleep(0); - ::Shared::Platform::Window::handleEvent(); - SDL_PumpEvents(); + if (hasCommandArgument + (argc, argv, GAME_ARGS[GAME_ARG_CONVERT_MODELS]) == true) { + int + foundParamIndIndex = -1; + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_CONVERT_MODELS]) + + string("="), &foundParamIndIndex); + if (foundParamIndIndex < 0) { + hasCommandArgument(argc, argv, + string(GAME_ARGS[GAME_ARG_CONVERT_MODELS]), + &foundParamIndIndex); + } + string + paramValue = argv[foundParamIndIndex]; + vector < string > paramPartTokens; + Tokenize(paramValue, paramPartTokens, "="); + if (paramPartTokens.size() >= 2 + && paramPartTokens[1].length() > 0) { + string + modelFile = paramPartTokens[1]; + printf("About to convert model(s) [%s]\n", modelFile.c_str()); - int - result = 0; - char - szTextBuf[8096] = ""; - for (unsigned int i = 0; i < models.size(); ++i) { - string & file = models[i]; + string + textureFormat = ""; + if (paramPartTokens.size() >= 3 + && paramPartTokens[1].length() > 0) { + textureFormat = paramPartTokens[2]; + printf("About to convert using texture format [%s]\n", + textureFormat.c_str()); + } - renderer.clearBuffers(); - renderer.clearZBuffer(); - renderer.reset2d(); - snprintf(szTextBuf, 8096, - "Please wait, converting models [%u of " - MG_SIZE_T_SPECIFIER "] ...", i, models.size()); + bool + keepsmallest = false; + if (paramPartTokens.size() >= 4 + && paramPartTokens[1].length() > 0) { + keepsmallest = (paramPartTokens[3] == "keepsmallest"); + printf("About to convert using keepsmallest = %d\n", + keepsmallest); + } - if (CoreData::getInstance().getMenuFontBig3D() != NULL) { - renderer.renderText3D(szTextBuf, - CoreData::getInstance(). - getMenuFontBig3D(), Vec3f(1.f, 1.f, - 0.f), - (metrics.getScreenW() / 2) - 400, - (metrics.getScreenH() / 2), true); - } else { - renderer.renderText(szTextBuf, - CoreData::getInstance(). - getMenuFontBig(), Vec3f(1.f, 1.f, 0.f), - (metrics.getScreenW() / 2) - 400, - (metrics.getScreenH() / 2), true); - } - renderer.swapBuffers(); + showCursor(true); - sleep(0); - ::Shared::Platform::Window::handleEvent(); - SDL_PumpEvents(); + const + Metrics & + metrics = Metrics::getInstance(); + renderer.clearBuffers(); + renderer.clearZBuffer(); + renderer.reset2d(); - try { - printf("About to load model [%s] [%u of " MG_SIZE_T_SPECIFIER - "]\n", file.c_str(), i, models.size()); - Model * - model = renderer.newModel(rsGlobal, file); - printf("About to save converted model [%s]\n", - file.c_str()); - model->save(file, textureFormat, keepsmallest); - Renderer::getInstance().endModel(rsGlobal, model); - } catch (const exception & ex) { - result = 1; - printf("ERROR loading model [%s] message [%s]\n", - file.c_str(), ex.what()); - } + if (CoreData::getInstance().getMenuFontBig3D() != NULL) { + renderer.renderText3D("Please wait, converting models...", + CoreData::getInstance(). + getMenuFontBig3D(), Vec3f(1.f, 1.f, + 0.f), + (metrics.getScreenW() / 2) - 400, + (metrics.getScreenH() / 2), true); + } else { + renderer.renderText("Please wait, converting models...", + CoreData::getInstance().getMenuFontBig(), + Vec3f(1.f, 1.f, 0.f), + (metrics.getScreenW() / 2) - 400, + (metrics.getScreenH() / 2), true); + } + renderer.swapBuffers(); - } + std::vector < string > models; + if (isdir(modelFile.c_str()) == true) { + models = + getFolderTreeContentsListRecursively(modelFile, ".g3d"); + } else { + models.push_back(modelFile); + } - delete - mainWindow; - mainWindow = NULL; - return result; - } else { - printf - ("\nInvalid model specified on commandline [%s] texture [%s]\n\n", - argv[foundParamIndIndex], - (paramPartTokens.size() >= - 2 ? paramPartTokens[1].c_str() : NULL)); - printParameterHelp(argv[0], foundInvalidArgs); - delete - mainWindow; - mainWindow = NULL; - return 1; - } - } + sleep(0); + ::Shared::Platform::Window::handleEvent(); + SDL_PumpEvents(); - if (hasCommandArgument - (argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true - || hasCommandArgument(argc, argv, - GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == - true - || hasCommandArgument(argc, argv, - GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == - true) { - runTechValidationReport(argc, argv); + int + result = 0; + char + szTextBuf[8096] = ""; + for (unsigned int i = 0; i < models.size(); ++i) { + string & file = models[i]; - delete - mainWindow; - mainWindow = NULL; - return 0; - } + renderer.clearBuffers(); + renderer.clearZBuffer(); + renderer.reset2d(); + snprintf(szTextBuf, 8096, + "Please wait, converting models [%u of " + MG_SIZE_T_SPECIFIER "] ...", i, models.size()); - if (hasCommandArgument - (argc, argv, GAME_ARGS[GAME_ARG_TRANSLATE_TECHTREES]) == true) { - runTechTranslationExtraction(argc, argv); - delete - mainWindow; - mainWindow = NULL; - return 0; - } + if (CoreData::getInstance().getMenuFontBig3D() != NULL) { + renderer.renderText3D(szTextBuf, + CoreData::getInstance(). + getMenuFontBig3D(), Vec3f(1.f, 1.f, + 0.f), + (metrics.getScreenW() / 2) - 400, + (metrics.getScreenH() / 2), true); + } else { + renderer.renderText(szTextBuf, + CoreData::getInstance(). + getMenuFontBig(), Vec3f(1.f, 1.f, 0.f), + (metrics.getScreenW() / 2) - 400, + (metrics.getScreenH() / 2), true); + } + renderer.swapBuffers(); - if (hasCommandArgument - (argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_TILESET]) == true) { - runTilesetValidationReport(argc, argv); + sleep(0); + ::Shared::Platform::Window::handleEvent(); + SDL_PumpEvents(); - delete - mainWindow; - mainWindow = NULL; - return 0; - } + try { + printf("About to load model [%s] [%u of " MG_SIZE_T_SPECIFIER + "]\n", file.c_str(), i, models.size()); + Model * + model = renderer.newModel(rsGlobal, file); + printf("About to save converted model [%s]\n", + file.c_str()); + model->save(file, textureFormat, keepsmallest); + Renderer::getInstance().endModel(rsGlobal, model); + } catch (const exception & ex) { + result = 1; + printf("ERROR loading model [%s] message [%s]\n", + file.c_str(), ex.what()); + } - gameInitialized = true; + } - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d]\n", __FILE__, - __FUNCTION__, __LINE__); + delete + mainWindow; + mainWindow = NULL; + return result; + } else { + printf + ("\nInvalid model specified on commandline [%s] texture [%s]\n\n", + argv[foundParamIndIndex], + (paramPartTokens.size() >= + 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0], foundInvalidArgs); + delete + mainWindow; + mainWindow = NULL; + return 1; + } + } - CheckForDuplicateData(); + if (hasCommandArgument + (argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true + || hasCommandArgument(argc, argv, + GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == + true + || hasCommandArgument(argc, argv, + GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == + true) { + runTechValidationReport(argc, argv); - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d]\n", __FILE__, - __FUNCTION__, __LINE__); + delete + mainWindow; + mainWindow = NULL; + return 0; + } - //throw "BLAH!"; + if (hasCommandArgument + (argc, argv, GAME_ARGS[GAME_ARG_TRANSLATE_TECHTREES]) == true) { + runTechTranslationExtraction(argc, argv); + delete + mainWindow; + mainWindow = NULL; + return 0; + } - // START Test out SIGSEGV error handling - //int *foo = (int*)-1; // make a bad pointer - //printf("%d\n", *foo); // causes segfault - // END + if (hasCommandArgument + (argc, argv, GAME_ARGS[GAME_ARG_VALIDATE_TILESET]) == true) { + runTilesetValidationReport(argc, argv); - bool - startCRCPrecacheThread = - config.getBool("PreCacheCRCThread", "true"); - //printf("### In [%s::%s Line: %d] precache thread enabled = %d SystemFlags::VERBOSE_MODE_ENABLED = %d\n",__FILE__,__FUNCTION__,__LINE__,startCRCPrecacheThread,SystemFlags::VERBOSE_MODE_ENABLED); - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("In [%s::%s Line: %d] precache thread enabled = %d\n", - __FILE__, __FUNCTION__, __LINE__, startCRCPrecacheThread); - if (startCRCPrecacheThread == true - && GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { - static - string - mutexOwnerId = - string(extractFileFromDirectoryPath(__FILE__).c_str()) + - string("_") + intToStr(__LINE__); - vector < string > techDataPaths = - config.getPathListForType(ptTechs); + delete + mainWindow; + mainWindow = NULL; + return 0; + } - FileCRCPreCacheThread::setPreCacheThreadCacheLookupKey - (GameConstants::preCacheThreadCacheLookupKey); - FileCRCPreCacheThread *& - preCacheCRCThreadPtr = - CacheManager::getCachedItem < - FileCRCPreCacheThread * - >(GameConstants::preCacheThreadCacheLookupKey); - if (preCacheCRCThreadPtr == NULL) { - preCacheCRCThreadPtr = new FileCRCPreCacheThread(); - } - preCacheThread = preCacheCRCThreadPtr; - preCacheThread->setUniqueID(mutexOwnerId); - preCacheThread->setTechDataPaths(techDataPaths); - //preCacheThread->setFileCRCPreCacheThreadCallbackInterface(&preCacheThreadGame); - preCacheThread->start(); - } + gameInitialized = true; - auto_ptr < NavtiveLanguageNameListCacheGenerator > lngCacheGen; - auto_ptr < SimpleTaskThread > languageCacheGen; + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); - bool - startNativeLanguageNamesPrecacheThread = - config.getBool("PreCacheNativeLanguageNamesThread", "true"); - if (startNativeLanguageNamesPrecacheThread == true - && GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { - lngCacheGen.reset(new NavtiveLanguageNameListCacheGenerator()); - languageCacheGen.reset(new - SimpleTaskThread(lngCacheGen.get(), 1)); + CheckForDuplicateData(); - languageCacheGen->start(); - } + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); - // test - //Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0); - //throw megaglest_runtime_error("test!"); - //ExceptionHandler::DisplayMessage("test!", false); + //throw "BLAH!"; - // Check for commands being input from stdin - string - command = ""; + // START Test out SIGSEGV error handling + //int *foo = (int*)-1; // make a bad pointer + //printf("%d\n", *foo); // causes segfault + // END + + bool + startCRCPrecacheThread = + config.getBool("PreCacheCRCThread", "true"); + //printf("### In [%s::%s Line: %d] precache thread enabled = %d SystemFlags::VERBOSE_MODE_ENABLED = %d\n",__FILE__,__FUNCTION__,__LINE__,startCRCPrecacheThread,SystemFlags::VERBOSE_MODE_ENABLED); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf("In [%s::%s Line: %d] precache thread enabled = %d\n", + __FILE__, __FUNCTION__, __LINE__, startCRCPrecacheThread); + if (startCRCPrecacheThread == true + && GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { + static + string + mutexOwnerId = + string(extractFileFromDirectoryPath(__FILE__).c_str()) + + string("_") + intToStr(__LINE__); + vector < string > techDataPaths = + config.getPathListForType(ptTechs); + + FileCRCPreCacheThread::setPreCacheThreadCacheLookupKey + (GameConstants::preCacheThreadCacheLookupKey); + FileCRCPreCacheThread *& + preCacheCRCThreadPtr = + CacheManager::getCachedItem < + FileCRCPreCacheThread * + >(GameConstants::preCacheThreadCacheLookupKey); + if (preCacheCRCThreadPtr == NULL) { + preCacheCRCThreadPtr = new FileCRCPreCacheThread(); + } + preCacheThread = preCacheCRCThreadPtr; + preCacheThread->setUniqueID(mutexOwnerId); + preCacheThread->setTechDataPaths(techDataPaths); + //preCacheThread->setFileCRCPreCacheThreadCallbackInterface(&preCacheThreadGame); + preCacheThread->start(); + } + + auto_ptr < NavtiveLanguageNameListCacheGenerator > lngCacheGen; + auto_ptr < SimpleTaskThread > languageCacheGen; + + bool + startNativeLanguageNamesPrecacheThread = + config.getBool("PreCacheNativeLanguageNamesThread", "true"); + if (startNativeLanguageNamesPrecacheThread == true + && GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { + lngCacheGen.reset(new NavtiveLanguageNameListCacheGenerator()); + languageCacheGen.reset(new + SimpleTaskThread(lngCacheGen.get(), 1)); + + languageCacheGen->start(); + } + + // test + //Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0); + //throw megaglest_runtime_error("test!"); + //ExceptionHandler::DisplayMessage("test!", false); + + // Check for commands being input from stdin + string + command = ""; #ifndef WIN32 - pollfd - cinfd[1]; + pollfd + cinfd[1]; #else - HANDLE - h = 0; + HANDLE + h = 0; #endif - if (disableheadless_console == false) { + if (disableheadless_console == false) { #ifndef WIN32 - // Theoretically this should always be 0, but one fileno call isn't going to hurt, and if - // we try to run somewhere that stdin isn't fd 0 then it will still just work - cinfd[0].fd = fileno(stdin); - cinfd[0].events = POLLIN; + // Theoretically this should always be 0, but one fileno call isn't going to hurt, and if + // we try to run somewhere that stdin isn't fd 0 then it will still just work + cinfd[0].fd = fileno(stdin); + cinfd[0].events = POLLIN; #else - h = GetStdHandle(STD_INPUT_HANDLE); - //DWORD dwMode; - //GetConsoleMode(h, &dwMode); - //SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT); - FlushConsoleInputBuffer(h); + h = GetStdHandle(STD_INPUT_HANDLE); + //DWORD dwMode; + //GetConsoleMode(h, &dwMode); + //SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT); + FlushConsoleInputBuffer(h); #endif - } + } - if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { - printf("Headless server is now running...\n"); - printf("To shutdown type: quit\n"); - printf("All commands require you to press ENTER\n"); - } + if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + printf("Headless server is now running...\n"); + printf("To shutdown type: quit\n"); + printf("All commands require you to press ENTER\n"); + } - //throw megaglest_runtime_error("Test!"); - //printf("About to throw an exception...\n"); - //throw 123; + //throw megaglest_runtime_error("Test!"); + //printf("About to throw an exception...\n"); + //throw 123; - //main loop - while (program->isShutdownApplicationEnabled() == false - && ::Shared::Platform::Window::handleEvent()) { - if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + //main loop + while (program->isShutdownApplicationEnabled() == false + && ::Shared::Platform::Window::handleEvent()) { + if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { - if (disableheadless_console == false) { + if (disableheadless_console == false) { #ifndef WIN32 - int - pollresult = poll(cinfd, 1, 0); - int - pollerror = errno; - if (pollresult) + int + pollresult = poll(cinfd, 1, 0); + int + pollerror = errno; + if (pollresult) #else - // This is problematic because input on Windows is not line-buffered so this will return - // even if getline may block. I haven't found a good way to fix it, so for the moment - // I just strongly suggest only running the server from the Python frontend, which does - // line buffer input. This does work okay as long as the user doesn't enter characters - // without pressing enter, and then try to end the server another way (say a remote - // console command), in which case we'll still be waiting for the stdin EOL and hang. + // This is problematic because input on Windows is not line-buffered so this will return + // even if getline may block. I haven't found a good way to fix it, so for the moment + // I just strongly suggest only running the server from the Python frontend, which does + // line buffer input. This does work okay as long as the user doesn't enter characters + // without pressing enter, and then try to end the server another way (say a remote + // console command), in which case we'll still be waiting for the stdin EOL and hang. - DWORD - saveMode; - GetConsoleMode(h, &saveMode); - DWORD - dwMode = saveMode; - dwMode &= ~ENABLE_MOUSE_INPUT; - dwMode &= ~ENABLE_WINDOW_INPUT; - SetConsoleMode(h, dwMode); + DWORD + saveMode; + GetConsoleMode(h, &saveMode); + DWORD + dwMode = saveMode; + dwMode &= ~ENABLE_MOUSE_INPUT; + dwMode &= ~ENABLE_WINDOW_INPUT; + SetConsoleMode(h, dwMode); - bool - gotData = (WaitForSingleObject(h, 0) == WAIT_OBJECT_0); - SetConsoleMode(h, saveMode); - if (gotData == true) + bool + gotData = (WaitForSingleObject(h, 0) == WAIT_OBJECT_0); + SetConsoleMode(h, saveMode); + if (gotData == true) #endif - { + { #ifdef WIN32 - bool - skip = true; - DWORD - nNumberOfCharsToRead = 1024; - DWORD - nRead = 0; - INPUT_RECORD - irInRec[1025]; + bool + skip = true; + DWORD + nNumberOfCharsToRead = 1024; + DWORD + nRead = 0; + INPUT_RECORD + irInRec[1025]; - PeekConsoleInput(h, &irInRec[0], nNumberOfCharsToRead, - &nRead); - for (int i = 0; i < nRead; ++i) { - INPUT_RECORD & inr = irInRec[i]; + PeekConsoleInput(h, &irInRec[0], nNumberOfCharsToRead, + &nRead); + for (int i = 0; i < nRead; ++i) { + INPUT_RECORD & inr = irInRec[i]; - //printf("inr.EventType = %d\n",inr.EventType); - if (inr.EventType == KEY_EVENT) { - if (inr.Event.KeyEvent.bKeyDown) { - char - cHoldKey = inr.Event.KeyEvent.uChar.AsciiChar; - if (cHoldKey == '\r') { - skip = false; - break; - } - } - } - } + //printf("inr.EventType = %d\n",inr.EventType); + if (inr.EventType == KEY_EVENT) { + if (inr.Event.KeyEvent.bKeyDown) { + char + cHoldKey = inr.Event.KeyEvent.uChar.AsciiChar; + if (cHoldKey == '\r') { + skip = false; + break; + } + } + } + } #else - bool - skip = false; + bool + skip = false; #endif - if (skip == false) { - getline(cin, command); - cin.clear(); + if (skip == false) { + getline(cin, command); + cin.clear(); - printf("server command [%s]\n", command.c_str()); - if (command == "quit") { - break; - } + printf("server command [%s]\n", command.c_str()); + if (command == "quit") { + break; + } #ifndef WIN32 - if (cinfd[0].revents & POLLNVAL) { - printf("invalid file descriptor\n"); - } - if (cinfd[0].revents & POLLERR) { - printf("error in file descriptor\n"); - } - if (cinfd[0].revents & POLLHUP) { - printf("hang up in file descriptor\n"); - } + if (cinfd[0].revents & POLLNVAL) { + printf("invalid file descriptor\n"); + } + if (cinfd[0].revents & POLLERR) { + printf("error in file descriptor\n"); + } + if (cinfd[0].revents & POLLHUP) { + printf("hang up in file descriptor\n"); + } - if (pollresult < 0) { - printf("pollresult = %d errno = %d [%s]\n", pollresult, - pollerror, strerror(pollerror)); + if (pollresult < 0) { + printf("pollresult = %d errno = %d [%s]\n", pollresult, + pollerror, strerror(pollerror)); - cinfd[0].fd = fileno(stdin); - cinfd[0].events = POLLIN; - } + cinfd[0].fd = fileno(stdin); + cinfd[0].events = POLLIN; + } #endif - } - } - } - //printf("looping\n"); - } + } + } + } + //printf("looping\n"); + } - program->loop(); + program->loop(); - // Because OpenGL really doesn't do multi-threading well - // if(difftime(time(NULL),lastTextureLoadEvent) >= 3) { - // lastTextureLoadEvent = time(NULL); - // vector 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::findTexture(factionLogo); - // renderer.initTexture(rsGlobal,factionLogo); - // } - // } - // } - } + // Because OpenGL really doesn't do multi-threading well + // if(difftime(time(NULL),lastTextureLoadEvent) >= 3) { + // lastTextureLoadEvent = time(NULL); + // vector 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::findTexture(factionLogo); + // renderer.initTexture(rsGlobal,factionLogo); + // } + // } + // } + } - if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { - printf("\nHeadless server is about to quit...\n"); - } + if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + printf("\nHeadless server is about to quit...\n"); + } - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf - ("In [%s::%s Line: %d] starting normal application shutdown\n", - __FILE__, __FUNCTION__, __LINE__); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("In [%s::%s Line: %d] starting normal application shutdown\n", + __FILE__, __FUNCTION__, __LINE__); - if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { - soundThreadManager = program->getSoundThreadManager(true); - if (soundThreadManager) { - SoundRenderer & soundRenderer = SoundRenderer::getInstance(); - soundRenderer.stopAllSounds(shutdownFadeSoundMilliseconds); - chronoshutdownFadeSound.start(); - } - } + if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { + soundThreadManager = program->getSoundThreadManager(true); + if (soundThreadManager) { + SoundRenderer & soundRenderer = SoundRenderer::getInstance(); + soundRenderer.stopAllSounds(shutdownFadeSoundMilliseconds); + chronoshutdownFadeSound.start(); + } + } - cleanupCRCThread(); - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d]\n", __FILE__, - __FUNCTION__, __LINE__); + cleanupCRCThread(); + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); - showCursor(true); - //showWindowCursorState = true; - SystemFlags::OutputDebug(SystemFlags::debugSystem, - "In [%s::%s Line: %d]\n", __FILE__, - __FUNCTION__, __LINE__); - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__); + showCursor(true); + //showWindowCursorState = true; + SystemFlags::OutputDebug(SystemFlags::debugSystem, + "In [%s::%s Line: %d]\n", __FILE__, + __FUNCTION__, __LINE__); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf("In [%s::%s Line: %d]\n", __FILE__, __FUNCTION__, __LINE__); } catch (const megaglest_runtime_error & e) { if (GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { diff --git a/source/shared_lib/include/graphics/gl/model_renderer_gl.h b/source/shared_lib/include/graphics/gl/model_renderer_gl.h index e3fb4bf84..4793e60c4 100644 --- a/source/shared_lib/include/graphics/gl/model_renderer_gl.h +++ b/source/shared_lib/include/graphics/gl/model_renderer_gl.h @@ -12,7 +12,6 @@ #ifndef _SHARED_GRAPHICS_GL_MODELRENDERERGL_H_ #define _SHARED_GRAPHICS_GL_MODELRENDERERGL_H_ -#include #include "model_renderer.h" #include "model.h" #include "opengl.h" @@ -24,6 +23,23 @@ using ::Shared::Graphics::Gl::Texture2DGl; namespace Shared { namespace Graphics { namespace Gl { + class MeshCallback { + private: + const Texture *teamTexture; + + public: + MeshCallback() { + teamTexture = NULL; + } + + void setTeamTexture(const Texture *teamTexture) { + this->teamTexture = teamTexture; + } + + void execute(const Mesh *mesh, float alpha); + + static bool noTeamColors; + }; // ===================================================== // class ModelRendererGl @@ -55,24 +71,6 @@ namespace Shared { void renderMesh(Mesh *mesh, int renderMode = rmNormal, float alpha = 1.0f); void renderMeshNormals(Mesh *mesh); }; - - class MeshCallbackTeamColor : public MeshCallback { - private: - const Texture *teamTexture; - - public: - MeshCallbackTeamColor() : MeshCallback() { - teamTexture = NULL; - } - - void setTeamTexture(const Texture *teamTexture) { - this->teamTexture = teamTexture; - } - - virtual void execute(const Mesh *mesh); - - static bool noTeamColors; - }; } } }//end namespace diff --git a/source/shared_lib/include/graphics/model_renderer.h b/source/shared_lib/include/graphics/model_renderer.h index 1348cbec7..d3cfa7552 100644 --- a/source/shared_lib/include/graphics/model_renderer.h +++ b/source/shared_lib/include/graphics/model_renderer.h @@ -18,30 +18,18 @@ namespace Shared { namespace Graphics { + namespace Gl { + class MeshCallback; + } enum RenderMode { rmNormal, rmSelection, - renderModeCount }; - class Texture; - // ===================================================== - // class MeshCallback - // - /// This gets called before rendering mesh - // ===================================================== - - class MeshCallback { - public: - virtual ~MeshCallback() { - }; - virtual void execute(const Mesh *mesh) = 0; - }; - // ===================================================== // class ModelRenderer // ===================================================== @@ -52,7 +40,7 @@ namespace Shared { bool renderTextures; bool renderColors; bool colorPickingMode; - MeshCallback *meshCallback; + Gl::MeshCallback *meshCallback; public: ModelRenderer() { @@ -67,7 +55,7 @@ namespace Shared { virtual ~ModelRenderer() { }; - virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, bool colorPickingMode, MeshCallback *meshCallback = NULL) = 0; + virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, bool colorPickingMode, Gl::MeshCallback *meshCallback = NULL) = 0; virtual void end() = 0; virtual void render(Model *model, int renderMode = rmNormal, float alpha = 1.0f) = 0; virtual void renderNormalsOnly(Model *model) = 0; diff --git a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp index f61775a3b..8bccae00d 100644 --- a/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/model_renderer_gl.cpp @@ -22,12 +22,12 @@ using namespace Shared::Platform; namespace Shared { namespace Graphics { namespace Gl { - bool MeshCallbackTeamColor::noTeamColors = false; + bool MeshCallback::noTeamColors = false; - void MeshCallbackTeamColor::execute(const Mesh *mesh) { + void MeshCallback::execute(const Mesh *mesh, float alpha) { //team color uint8 opacity = mesh->getFactionColorOpacity(); - if (!mesh->getCustomTexture() || opacity == 0 || teamTexture == NULL || MeshCallbackTeamColor::noTeamColors) { + if (!mesh->getCustomTexture() || opacity == 0 || teamTexture == NULL || MeshCallback::noTeamColors) { glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -44,7 +44,7 @@ namespace Shared { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); - //set alpha to 1 + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); @@ -56,10 +56,10 @@ namespace Shared { GLuint handle = static_cast(teamTexture)->getHandle(); glBindTexture(GL_TEXTURE_2D, handle); float color[4]; - color[0] = 1.0f; // Red - color[1] = 1.0f; // Green - color[2] = 1.0f; // Blue - color[3] = opacity * 0.00392156862f; // Alpha + color[0] = 1.0f; // Red + color[1] = 1.0f; // Green + color[2] = 1.0f; // Blue + color[3] = opacity * 0.00392156862f; // Alpha glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -72,14 +72,33 @@ namespace Shared { glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); - //set alpha to 1 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); + + if (alpha < 1.f - FLT_EPSILON) { + glActiveTexture(GL_TEXTURE2); + glEnable(GL_TEXTURE_2D); + glMultiTexCoord2f(GL_TEXTURE1, 0.f, 0.f); + glBindTexture(GL_TEXTURE_2D, handle); + color[3] = alpha; + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); + glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); + + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); + glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); + glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); + } glActiveTexture(GL_TEXTURE0); } @@ -248,7 +267,7 @@ namespace Shared { if (this->colorPickingMode == false) { //set color if (renderColors) { - Vec4f color(mesh->getDiffuseColor(), mesh->getOpacity() * alpha); + Vec4f color(mesh->getDiffuseColor(), mesh->getOpacity()); glColor4fv(color.ptr()); } @@ -272,7 +291,7 @@ namespace Shared { } if (meshCallback != NULL) { - meshCallback->execute(mesh); + meshCallback->execute(mesh, alpha); } }