diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index a6768564..18b10d63 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -280,6 +280,22 @@ void Game::load(){ //tech, load before map because of resources world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum); + // Validate the faction setup to ensure we don't have any bad associations + /* + std::vector results = world.validateFactionTypes(); + if(results.size() > 0) { + // Display the validation errors + string errorText = "Errors were detected:\n"; + for(int i = 0; i < results.size(); ++i) { + if(i > 0) { + errorText += "\n"; + } + errorText += results[i]; + } + throw runtime_error(errorText); + } + */ + // give CPU time to update other things to avoid apperance of hanging sleep(0); SDL_PumpEvents(); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e7fa091b..11886400 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -156,6 +156,22 @@ const int MIN_FPS_NORMAL_RENDERING = 20; // ==================== constructor and destructor ==================== Renderer::Renderer(){ + this->allowRenderUnitTitles = false; + this->menu = NULL; + this->game = NULL; + showDebugUI = false; + modelRenderer = NULL; + textRenderer = NULL; + particleRenderer = NULL; + + //resources + for(int i=0; iallowRenderUnitTitles = false; - this->menu = NULL; - this->game = NULL; - modelRenderer= graphicsFactory->newModelRenderer(); textRenderer= graphicsFactory->newTextRenderer2D(); particleRenderer= graphicsFactory->newParticleRenderer(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index e34eb29b..3355b079 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -30,6 +30,7 @@ #include "font.h" #include #include "menu_state_masterserver.h" +#include "checksum.h" #include "leak_dumper.h" @@ -415,7 +416,8 @@ int glestMain(int argc, char** argv){ bool haveSpecialOutputCommandLineOption = false; if( hasCommandArgument(argc, argv,"--opengl-info") == true || - hasCommandArgument(argc, argv,"--version") == true) { + hasCommandArgument(argc, argv,"--version") == true || + hasCommandArgument(argc, argv,"--validate-techtrees") == true) { haveSpecialOutputCommandLineOption = true; } @@ -430,7 +432,8 @@ int glestMain(int argc, char** argv){ } if( hasCommandArgument(argc, argv,"--version") == true && - hasCommandArgument(argc, argv,"--opengl-info") == false) { + hasCommandArgument(argc, argv,"--opengl-info") == false && + hasCommandArgument(argc, argv,"validate-factions") == false) { return -1; } @@ -582,6 +585,79 @@ int glestMain(int argc, char** argv){ return -1; } + if(hasCommandArgument(argc, argv,"--validate-techtrees") == true) { + + Config &config = Config::getInstance(); + vector results; + findDirs(config.getPathListForType(ptTechs), results); + vector techTreeFiles = results; + World world; + + vector techPaths = config.getPathListForType(ptTechs); + for(int idx = 0; idx < techPaths.size(); idx++) { + string &techPath = techPaths[idx]; + for(int idx2 = 0; idx2 < techTreeFiles.size(); idx2++) { + string &techName = techTreeFiles[idx2]; + + vector factionsList; + findAll(techPath + "/" + techName + "/factions/*.", factionsList, false, false); + + if(factionsList.size() > 0) { + Checksum checksum; + set factions; + for(int j = 0; j < factionsList.size(); ++j) { + factions.insert(factionsList[j]); + } + + printf("\nChecking techPath [%s] techName [%s] factionsList.size() = %d\n",techPath.c_str(), techName.c_str(),factionsList.size()); + for(int j = 0; j < factionsList.size(); ++j) { + printf("Found faction [%s]\n",factionsList[j].c_str()); + } + + world.loadTech(config.getPathListForType(ptTechs,""), techName, factions, &checksum); + // Validate the faction setup to ensure we don't have any bad associations + std::vector resultErrors = world.validateFactionTypes(); + if(resultErrors.size() > 0) { + // Display the validation errors + string errorText = "\nErrors were detected:\n=====================\n"; + for(int i = 0; i < resultErrors.size(); ++i) { + if(i > 0) { + errorText += "\n"; + } + errorText += resultErrors[i]; + } + errorText += "\n=====================\n"; + //throw runtime_error(errorText); + printf("%s",errorText.c_str()); + } + + // Validate the faction resource setup to ensure we don't have any bad associations + printf("\nChecking resources, count = %d\n",world.getTechTree()->getResourceTypeCount()); + + for(int i = 0; i < world.getTechTree()->getResourceTypeCount(); ++i) { + printf("Found techtree resource [%s]\n",world.getTechTree()->getResourceType(i)->getName().c_str()); + } + + resultErrors = world.validateResourceTypes(); + if(resultErrors.size() > 0) { + // Display the validation errors + string errorText = "\nErrors were detected:\n=====================\n"; + for(int i = 0; i < resultErrors.size(); ++i) { + if(i > 0) { + errorText += "\n"; + } + errorText += resultErrors[i]; + } + errorText += "\n=====================\n"; + //throw runtime_error(errorText); + printf("%s",errorText.c_str()); + } + } + } + } + + return -1; + } if(config.getBool("AllowGameDataSynchCheck","false") == true) { vector techDataPaths = config.getPathListForType(ptTechs); diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index d6fc76f6..7d3e5996 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -138,6 +138,83 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch FactionType::~FactionType(){ delete music; + music = NULL; +} + +std::vector FactionType::validateFactionType() { + std::vector results; + + // Check every unit's commands to validate that for every upgrade-requirements + // upgrade we have a unit that can do the upgrade in the faction. + for(int i=0; igetUpgradeReqCount(); ++k) { + const UpgradeType *upgradeType = cmdType->getUpgradeReq(k); + + if(upgradeType != NULL) { + // Now lets find a unit that can produced-upgrade this upgrade + bool foundUpgraderUnit = false; + for(int l=0; l(cmdType2) != NULL) { + const UpgradeCommandType *uct = dynamic_cast(cmdType2); + const UpgradeType *upgradeType2 = uct->getProducedUpgrade(); + if(upgradeType2 != NULL && upgradeType2->getName() == upgradeType->getName()) { + foundUpgraderUnit = true; + } + } + } + } + + if(foundUpgraderUnit == false) { + char szBuf[4096]=""; + sprintf(szBuf,"The Unit [%s] in Faction [%s] has the command [%s]\nwhich has upgrade requirement [%s] but there are no units able to perform the upgrade!",unitType.getName().c_str(),this->getName().c_str(),cmdType->getName().c_str(),upgradeType->getName().c_str()); + results.push_back(szBuf); + } + } + } + } + } + } + + return results; +} + +std::vector FactionType::validateFactionTypeResourceTypes(vector &resourceTypes) { + std::vector results; + + // Check every unit's commands to validate that for every upgrade-requirements + // upgrade we have a unit that can do the upgrade in the faction. + for(int i=0; igetType() != NULL) { + bool foundResourceType = false; + // Now lets find a matching faction resource type for the unit + for(int k=0; kgetType()->getName() == rt.getName()) { + foundResourceType = true; + } + } + + if(foundResourceType == false) { + char szBuf[4096]=""; + sprintf(szBuf,"The Unit [%s] in Faction [%s] has the resource req [%s]\nbut there are no such resources in this tech!",unitType.getName().c_str(),this->getName().c_str(),r->getType()->getName().c_str()); + results.push_back(szBuf); + } + } + } + } + + return results; } // ==================== get ==================== diff --git a/source/glest_game/types/faction_type.h b/source/glest_game/types/faction_type.h index 3ac726cc..ca9b2d41 100644 --- a/source/glest_game/types/faction_type.h +++ b/source/glest_game/types/faction_type.h @@ -64,6 +64,8 @@ public: int getStartingResourceAmount(const ResourceType *resourceType) const; std::string toString() const; + std::vector validateFactionType(); + std::vector validateFactionTypeResourceTypes(vector &resourceTypes); }; }}//end namespace diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 75c35f52..e8882cfc 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -145,7 +145,6 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum // give CPU time to update other things to avoid apperance of hanging sleep(0); SDL_PumpEvents(); - } } catch(const exception &e){ @@ -160,6 +159,24 @@ TechTree::~TechTree(){ Logger::getInstance().add("Tech tree", true); } +std::vector TechTree::validateFactionTypes() { + std::vector results; + for (int i = 0; i < factionTypes.size(); ++i) { + std::vector factionResults = factionTypes[i].validateFactionType(); + results.insert(results.end(), factionResults.begin(), factionResults.end()); + } + + return results; +} + +std::vector TechTree::validateResourceTypes() { + std::vector results; + for (int i = 0; i < factionTypes.size(); ++i) { + std::vector factionResults = factionTypes[i].validateFactionTypeResourceTypes(resourceTypes); + results.insert(results.end(), factionResults.begin(), factionResults.end()); + } + return results; +} // ==================== get ==================== diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index 79c01ad4..54a88548 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -60,6 +60,8 @@ public: const ArmorType *getArmorType(const string &name) const; const AttackType *getAttackType(const string &name) const; float getDamageMultiplier(const AttackType *att, const ArmorType *art) const; + std::vector validateFactionTypes(); + std::vector validateResourceTypes(); }; }} //end namespace diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 525f8d33..42c2f2c7 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -190,6 +190,14 @@ void World::loadTech(const vector pathList, const string &techName, set< //techCache[techName] = techTree; } +std::vector World::validateFactionTypes() { + return techTree->validateFactionTypes(); +} + +std::vector World::validateResourceTypes() { + return techTree->validateResourceTypes(); +} + //load map void World::loadMap(const string &path, Checksum *checksum){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 75e52e38..257dcc16 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -182,6 +182,9 @@ public: Game * getGame() { return game; } + std::vector validateFactionTypes(); + std::vector validateResourceTypes(); + void setFogOfWar(bool value); std::string DumpWorldToLog(bool consoleBasicInfoOnly = false) const; diff --git a/source/shared_lib/include/graphics/font_manager.h b/source/shared_lib/include/graphics/font_manager.h new file mode 100644 index 00000000..41069ad0 --- /dev/null +++ b/source/shared_lib/include/graphics/font_manager.h @@ -0,0 +1,49 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _SHARED_GRAPHICS_FONTMANAGER_H_ +#define _SHARED_GRAPHICS_FONTMANAGER_H_ + +#include "font.h" + +#include + +using namespace std; + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// class FontManager +// +/// Creates, Intializes, Finalizes, and Deletes fonts +// ===================================================== + +class FontManager{ +protected: + typedef vector FontContainer; + +protected: + FontContainer fonts; + +public: + FontManager(); + virtual ~FontManager(); + + Font2D *newFont2D(); + Font3D *newFont3D(); + + void init(); + void end(); +}; + +}}//end namespace + +#endif diff --git a/source/shared_lib/sources/graphics/font_manager.cpp b/source/shared_lib/sources/graphics/font_manager.cpp new file mode 100644 index 00000000..79c28e15 --- /dev/null +++ b/source/shared_lib/sources/graphics/font_manager.cpp @@ -0,0 +1,62 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "font_manager.h" + +#include "graphics_interface.h" +#include "graphics_factory.h" +#include "leak_dumper.h" + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// class FontManager +// ===================================================== +FontManager::FontManager(){ + fonts.clear(); +} + +FontManager::~FontManager(){ + end(); +} + +Font2D *FontManager::newFont2D(){ + Font2D *font= GraphicsInterface::getInstance().getFactory()->newFont2D(); + fonts.push_back(font); + return font; +} + +Font3D *FontManager::newFont3D(){ + Font3D *font= GraphicsInterface::getInstance().getFactory()->newFont3D(); + fonts.push_back(font); + return font; +} + +void FontManager::init(){ + for(size_t i=0; iinit(); + } + } +} + +void FontManager::end(){ + for(size_t i=0; iend(); + delete fonts[i]; + } + } + fonts.clear(); +} + + +}}//end namespace diff --git a/source/shared_lib/sources/graphics/gl/font_gl.cpp b/source/shared_lib/sources/graphics/gl/font_gl.cpp new file mode 100644 index 00000000..e243f55c --- /dev/null +++ b/source/shared_lib/sources/graphics/gl/font_gl.cpp @@ -0,0 +1,77 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "font_gl.h" + +#include "opengl.h" +#include "gl_wrap.h" +#include "leak_dumper.h" + +namespace Shared{ namespace Graphics{ namespace Gl{ + +using namespace Platform; + +// ===================================================== +// class Font2DGl +// ===================================================== + +void Font2DGl::init(){ + assertGl(); + + if(!inited){ + handle= glGenLists(charCount); + createGlFontBitmaps(handle, type, size, width, charCount, metrics); + inited= true; + } + + assertGl(); +} + +void Font2DGl::end(){ + assertGl(); + + if(inited){ + //assert(glIsList(handle)); + glDeleteLists(handle, 1); + inited= false; + } + + assertGl(); +} + +// ===================================================== +// class Font3DGl +// ===================================================== + +void Font3DGl::init(){ + assertGl(); + + if(!inited){ + handle= glGenLists(charCount); + createGlFontOutlines(handle, type, width, depth, charCount, metrics); + inited= true; + } + + assertGl(); +} + +void Font3DGl::end(){ + assertGl(); + + if(inited){ + assert(glIsList(handle)); + glDeleteLists(handle, 1); + } + + assertGl(); +} + +}}}//end namespace