From 1efc2dc0a69cbf5cc86f2c8bf05c6a9326cd1753 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 3 May 2010 06:25:54 +0000 Subject: [PATCH] - updates to Chinese font support so Linux will compile - added more debugging and NULL guards --- source/glest_game/game/game.cpp | 56 +++++++++++++- source/glest_game/graphics/renderer.cpp | 5 ++ source/glest_game/main/main.cpp | 6 +- source/glest_game/main/program.cpp | 21 +++--- source/glest_game/sound/sound_renderer.cpp | 22 +++++- source/glest_game/sound/sound_renderer.h | 5 +- source/glest_game/type_instances/faction.cpp | 32 ++++++-- source/glest_game/types/tech_tree.cpp | 10 ++- source/glest_game/types/unit_type.cpp | 21 +----- source/glest_game/world/world.cpp | 73 ++++++++++++++++--- source/glest_game/world/world.h | 8 +- .../shared_lib/include/platform/sdl/gl_wrap.h | 4 + source/shared_lib/sources/util/util.cpp | 6 +- 13 files changed, 207 insertions(+), 62 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 99fc33ef..5a484ec3 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -196,32 +196,43 @@ void Game::load(){ //throw runtime_error("Test!"); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //tileset world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + set factions; for ( int i=0; i < gameSettings.getFactionCount(); ++i ) { factions.insert(gameSettings.getFactionTypeName(i)); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //tech, load before map because of resources world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //map world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //scenario if(!scenarioName.empty()){ Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName); world.loadScenario(gameSettings.getScenarioDir(), &checksum); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); } void Game::init() { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); Logger &logger= Logger::getInstance(); @@ -230,7 +241,7 @@ void Game::init() Map *map= world.getMap(); NetworkManager &networkManager= NetworkManager::getInstance(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); logger.setState(lang.get("Initializing")); //mesage box @@ -318,7 +329,7 @@ void Game::init() logger.add("Launching game"); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -326,6 +337,7 @@ void Game::init() //update void Game::update(){ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); // a) Updates non dependant on speed @@ -336,14 +348,18 @@ void Game::update(){ //console console.update(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); // b) Updates depandant on speed int updateLoops= getUpdateLoops(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //update for(int i=0; igetCpuControl() && scriptManager.getPlayerModifiers(i)->getAiEnabled()){ @@ -351,24 +367,31 @@ void Game::update(){ } } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //World world.update(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); // Commander commander.updateNetwork(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Gui gui.update(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Particle systems if(weatherParticleSystem != NULL){ weatherParticleSystem->setPos(gameCamera.getPos()); } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.updateParticleManager(rsGame); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //call the chat manager chatManager.updateNetwork(); @@ -381,6 +404,8 @@ void Game::update(){ if(Config::getInstance().getBool("AutoTest")){ AutoTest::getInstance().updateGame(this); } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void Game::updateCamera(){ @@ -392,10 +417,20 @@ void Game::updateCamera(){ //render void Game::render(){ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + renderFps++; render3d(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + render2d(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + Renderer::getInstance().swapBuffers(); + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ==================== tick ==================== @@ -785,41 +820,54 @@ void Game::quitGame(){ // ==================== render ==================== void Game::render3d(){ - + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Renderer &renderer= Renderer::getInstance(); //init + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.reset3d(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.computeVisibleQuad(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.loadGameCameraMatrix(); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.setupLighting(); //shadow map + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderShadowsToTexture(); //clear buffers + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.clearBuffers(); //surface + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderSurface(); //selection circles + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderSelectionEffects(); //units + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderUnits(); //objects + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderObjects(); //water + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderWater(); renderer.renderWaterEffects(); //particles + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderParticleManager(rsGame); //mouse 3d + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.renderMouse3d(); } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index ecc9a64e..e13ca004 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2150,7 +2150,10 @@ void Renderer::renderShadowsToTexture(){ //directional light //light pos + assert(game != NULL); + assert(game->getWorld() != NULL); const TimeFlow *tf= game->getWorld()->getTimeFlow(); + assert(tf != NULL); float ang= tf->isDay()? computeSunAngle(tf->getTime()): computeMoonAngle(tf->getTime()); ang= radToDeg(ang); @@ -2462,7 +2465,9 @@ Vec4f Renderer::computeWaterColor(float waterLevel, float cellHeight){ //render units for selection purposes void Renderer::renderUnitsFast(){ + assert(game != NULL); const World *world= game->getWorld(); + assert(world != NULL); assertGl(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 0c9cfdff..27ef910c 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -323,12 +323,12 @@ int glestMain(int argc, char** argv){ // 256 for English // 30000 for Chinese - Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(256).c_str()); - Font::fontTypeName = config.getString("FONT_TYPENAME","Times New Roman"); + Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str()); + Font::fontTypeName = config.getString("FONT_TYPENAME",Font::fontTypeName.c_str()); // Example values: // DEFAULT_CHARSET (English) = 1 // GB2312_CHARSET (Chinese) = 134 - Shared::Platform::charSet = config.getInt("FONT_CHARSET",intToStr(DEFAULT_CHARSET).c_str()); + Shared::Platform::charSet = config.getInt("FONT_CHARSET",intToStr(Shared::Platform::charSet).c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index d4c18c40..d045172f 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -183,17 +183,20 @@ void Program::keyPress(char c){ void Program::loop(){ - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); //render + assert(programState != NULL); programState->render(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + //update camera while(updateCameraTimer.isTime()){ programState->updateCamera(); } - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); //update world while(updateTimer.isTime()){ @@ -244,18 +247,18 @@ void Program::resize(SizeState sizeState){ void Program::setState(ProgramState *programState, bool cleanupOldState) { try { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(cleanupOldState == true) { delete this->programState; } - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); this->programState= programState; programState->load(); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); programState->init(); @@ -265,7 +268,7 @@ void Program::setState(ProgramState *programState, bool cleanupOldState) updateCameraTimer.reset(); fpsTimer.reset(); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } catch(const exception &e){ //exceptionMessage(e); @@ -365,7 +368,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ soundRenderer.init(window); // Run sound streaming in a background thread if enabled - if(config.getBool("ThreadedSoundStream","true") == true) { + if(config.getBool("ThreadedSoundStream","false") == true) { BaseThread::shutdownAndWait(soundThreadManager); delete soundThreadManager; soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,50); @@ -373,8 +376,8 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ } } - NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","0")); - NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","0")); + NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","false")); + NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","false")); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/sound/sound_renderer.cpp b/source/glest_game/sound/sound_renderer.cpp index fb5ec623..71d36c04 100644 --- a/source/glest_game/sound/sound_renderer.cpp +++ b/source/glest_game/sound/sound_renderer.cpp @@ -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 @@ -37,6 +37,7 @@ SoundRenderer::SoundRenderer(){ soundPlayer = NULL; loadConfig(); + runThreadSafe = false; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } @@ -46,6 +47,7 @@ void SoundRenderer::init(Window *window){ SoundInterface &si= SoundInterface::getInstance(); FactoryRepository &fr= FactoryRepository::getInstance(); Config &config= Config::getInstance(); + runThreadSafe = config.getBool("ThreadedSoundStream","false"); //if(soundPlayer == NULL) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -85,7 +87,9 @@ SoundRenderer &SoundRenderer::getInstance(){ void SoundRenderer::update(){ if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->updateStreams(); + if(runThreadSafe == true) mutex.v(); } } @@ -95,16 +99,20 @@ void SoundRenderer::playMusic(StrSound *strSound){ strSound->setVolume(musicVolume); strSound->restart(); if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->play(strSound); + if(runThreadSafe == true) mutex.v(); } } void SoundRenderer::stopMusic(StrSound *strSound){ if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->stop(strSound); if(strSound->getNext() != NULL) { soundPlayer->stop(strSound->getNext()); } + if(runThreadSafe == true) mutex.v(); } } @@ -114,13 +122,15 @@ void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPo if(staticSound!=NULL){ float d= soundPos.dist(camPos); - if(dsetVolume(correctedVol); if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->play(staticSound); + if(runThreadSafe == true) mutex.v(); } } } @@ -130,7 +140,9 @@ void SoundRenderer::playFx(StaticSound *staticSound){ if(staticSound!=NULL){ staticSound->setVolume(fxVolume); if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->play(staticSound); + if(runThreadSafe == true) mutex.v(); } } } @@ -140,13 +152,17 @@ void SoundRenderer::playFx(StaticSound *staticSound){ void SoundRenderer::playAmbient(StrSound *strSound){ strSound->setVolume(ambientVolume); if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->play(strSound, ambientFade); + if(runThreadSafe == true) mutex.v(); } } void SoundRenderer::stopAmbient(StrSound *strSound){ if(soundPlayer != NULL) { + if(runThreadSafe == true) mutex.p(); soundPlayer->stop(strSound, ambientFade); + if(runThreadSafe == true) mutex.v(); } } @@ -154,7 +170,9 @@ void SoundRenderer::stopAmbient(StrSound *strSound){ void SoundRenderer::stopAllSounds(){ if(soundPlayer != NULL) { + mutex.p(); soundPlayer->stopAllSounds(); + mutex.v(); } } diff --git a/source/glest_game/sound/sound_renderer.h b/source/glest_game/sound/sound_renderer.h index 3470b076..57948ce5 100644 --- a/source/glest_game/sound/sound_renderer.h +++ b/source/glest_game/sound/sound_renderer.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 @@ -45,6 +45,9 @@ private: float musicVolume; float ambientVolume; + Mutex mutex; + bool runThreadSafe; + private: SoundRenderer(); diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 502080a9..c403fbbc 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -35,6 +35,8 @@ void Faction::init( const FactionType *factionType, ControlType control, TechTree *techTree, Game *game, int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + this->control= control; this->factionType= factionType; this->startLocationIndex= startLocationIndex; @@ -56,10 +58,14 @@ void Faction::init( texture= Renderer::getInstance().newTexture2D(rsGame); texture->load("data/core/faction_textures/faction"+intToStr(index)+".tga"); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void Faction::end(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); deleteValues(units.begin(), units.end()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ================== get ================== @@ -109,7 +115,7 @@ void Faction::finishUpgrade(const UpgradeType *ut){ //checks if all required units and upgrades are present bool Faction::reqsOk(const RequirableType *rt) const{ - + assert(rt != NULL); //required units for(int i=0; igetUnitReqCount(); ++i){ bool found=false; @@ -137,7 +143,7 @@ bool Faction::reqsOk(const RequirableType *rt) const{ } bool Faction::reqsOk(const CommandType *ct) const{ - + assert(ct != NULL); if(ct->getProduced()!=NULL && !reqsOk(ct->getProduced())){ return false; } @@ -161,6 +167,7 @@ bool Faction::applyCosts(const ProducibleType *p){ return false; } + assert(p != NULL); //for each unit cost spend it //pass 2, decrease resources, except negative static costs (ie: farms) for(int i=0; igetCostCount(); ++i) @@ -179,10 +186,12 @@ bool Faction::applyCosts(const ProducibleType *p){ //apply discount (when a morph ends) void Faction::applyDiscount(const ProducibleType *p, int discount) { + assert(p != NULL); //increase resources for(int i=0; igetCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); + assert(rt != NULL); int cost= p->getCost(i)->getAmount(); if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable) { @@ -194,10 +203,12 @@ void Faction::applyDiscount(const ProducibleType *p, int discount) //apply static production (for starting units) void Faction::applyStaticCosts(const ProducibleType *p) { + assert(p != NULL); //decrease static resources for(int i=0; igetCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); + assert(rt != NULL); if(rt->getClass() == rcStatic) { int cost= p->getCost(i)->getAmount(); @@ -212,10 +223,12 @@ void Faction::applyStaticCosts(const ProducibleType *p) //apply static production (when a mana source is done) void Faction::applyStaticProduction(const ProducibleType *p) { + assert(p != NULL); //decrease static resources for(int i=0; igetCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); + assert(rt != NULL); if(rt->getClass() == rcStatic) { int cost= p->getCost(i)->getAmount(); @@ -230,10 +243,12 @@ void Faction::applyStaticProduction(const ProducibleType *p) //deapply all costs except static production (usually when a building is cancelled) void Faction::deApplyCosts(const ProducibleType *p) { + assert(p != NULL); //increase resources for(int i=0; igetCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); + assert(rt != NULL); int cost= p->getCost(i)->getAmount(); if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable) { @@ -246,10 +261,12 @@ void Faction::deApplyCosts(const ProducibleType *p) //deapply static costs (usually when a unit dies) void Faction::deApplyStaticCosts(const ProducibleType *p) { + assert(p != NULL); //decrease resources for(int i=0; igetCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); + assert(rt != NULL); if(rt->getClass() == rcStatic) { if(rt->getRecoup_cost() == true) @@ -264,10 +281,12 @@ void Faction::deApplyStaticCosts(const ProducibleType *p) //deapply static costs, but not negative costs, for when building gets killed void Faction::deApplyStaticConsumption(const ProducibleType *p) { + assert(p != NULL); //decrease resources for(int i=0; igetCostCount(); ++i) { const ResourceType *rt= p->getCost(i)->getType(); + assert(rt != NULL); if(rt->getClass() == rcStatic) { int cost= p->getCost(i)->getAmount(); @@ -329,14 +348,14 @@ void Faction::applyCostsOnInterval(){ } bool Faction::checkCosts(const ProducibleType *pt){ - + assert(pt != NULL); //for each unit cost check if enough resources for(int i=0; igetCostCount(); ++i){ const ResourceType *rt= pt->getCost(i)->getType(); int cost= pt->getCost(i)->getAmount(); - if(cost>0){ + if(cost > 0) { int available= getResource(rt)->getAmount(); - if(cost>available){ + if(cost > available){ return false; } } @@ -348,6 +367,7 @@ bool Faction::checkCosts(const ProducibleType *pt){ // ================== diplomacy ================== bool Faction::isAlly(const Faction *faction){ + assert(faction != NULL); return teamIndex==faction->getTeam(); } @@ -409,6 +429,7 @@ void Faction::removeUnit(Unit *unit){ } void Faction::addStore(const UnitType *unitType){ + assert(unitType != NULL); for(int i=0; igetStoredResourceCount(); ++i){ const Resource *r= unitType->getStoredResource(i); for(int j=0; jgetStoredResourceCount(); ++i){ const Resource *r= unitType->getStoredResource(i); for(int j=0; j pathList, const string &techName, s } void TechTree::load(const string &dir, set &factions, Checksum* checksum) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); string str; vector filenames; @@ -122,10 +123,12 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum catch(const exception &e){ throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what()); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } TechTree::~TechTree(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Logger::getInstance().add("Tech tree", true); } @@ -133,8 +136,10 @@ TechTree::~TechTree(){ // ==================== get ==================== const FactionType *TechTree::getType(const string &name) const{ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); for(int i=0; igetResourceNumber()==i && rt->getClass()==rcTech) return getResourceType(j); } @@ -155,6 +160,7 @@ const ResourceType *TechTree::getTechResourceType(int i) const{ const ResourceType *TechTree::getFirstTechResourceType() const{ for(int i=0; igetResourceNumber()==1 && rt->getClass()==rcTech) return getResourceType(i); } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index e483ee94..a9799d61 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -25,7 +25,6 @@ #include "game_util.h" #include "leak_dumper.h" #include "unit_particle_type.h" -//#include "socket.h" using namespace Shared::Xml; using namespace Shared::Graphics; @@ -91,7 +90,6 @@ UnitType::~UnitType(){ delete damageParticleSystemTypes.back(); damageParticleSystemTypes.pop_back(); } - } void UnitType::preLoad(const string &dir){ @@ -102,15 +100,15 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + string path = dir + "/" + name + ".xml"; + this->id= id; - string path; try{ Logger::getInstance().add("Unit type: " + formatString(name), true); //file load - path= dir+"/"+name+".xml"; checksum->addFile(path); XmlTree xmlTree; @@ -170,21 +168,6 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa cellMap[i*size+j]= row[j]=='0'? false: true; } } - - /* - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Original Unit cellmap matrix below [%s] [%s]:\n",__FILE__,__FUNCTION__,getName().c_str(),path.c_str()); - for(int iRow = 0; iRow < size; ++iRow) { - const XmlNode *rowNode= cellMapNode->getChild("row", iRow); - string row= rowNode->getAttribute("value")->getRestrictedValue(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] row = %s\n",__FILE__,__FUNCTION__,row.c_str()); - - for(int iCol = 0; iCol < size; ++iCol) { - bool getCellResult = getCellMapCell(iCol, iRow); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] matrix [%d,%d] = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult); - } - } - */ - } //levels diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 7d0f1f31..90ad0eca 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -21,6 +21,7 @@ #include "logger.h" #include "sound_renderer.h" #include "game_settings.h" +#include "cache_manager.h" #include "leak_dumper.h" using namespace Shared::Graphics; @@ -37,8 +38,10 @@ const float World::airHeight= 5.f; // ===================== PUBLIC ======================== World::World(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Config &config= Config::getInstance(); + techTree = NULL; fogOfWarOverride = false; fogOfWarSmoothing= config.getBool("FogOfWarSmoothing"); @@ -51,9 +54,18 @@ World::World(){ this->game = NULL; allowRotateUnits = Config::getInstance().getBool("AllowRotateUnits","0"); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +} + +World::~World() { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + delete techTree; + techTree = NULL; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void World::end(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Logger::getInstance().add("World", true); for(int i= 0; igame = game; scriptManager= game->getScriptManager(); @@ -100,34 +115,59 @@ void World::init(Game *game, bool createUnits){ } //initExplorationState(); ... was only for !fog-of-war, now handled in initCells() computeFow(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } //load tileset void World::loadTileset(const vector pathList, const string &tilesetName, Checksum* checksum) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); tileset.loadTileset(pathList, tilesetName, checksum); timeFlow.init(&tileset); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void World::loadTileset(const string &dir, Checksum *checksum){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); tileset.load(dir, checksum); timeFlow.init(&tileset); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } //load tech void World::loadTech(const vector pathList, const string &techName, set &factions, Checksum *checksum){ - techTree.loadTech(pathList, techName, factions, checksum); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + /* + std::map &techCache = Shared::PlatformCommon::CacheManager::getCachedItem< std::map >("techCache"); + if(techCache.find(techName) != techCache.end()) { + techTree = new TechTree(); + *techTree = *techCache[techName]; + return; + } + */ + + techTree = new TechTree(); + techTree->loadTech(pathList, techName, factions, checksum); + + //techCache[techName] = techTree; } //load map void World::loadMap(const string &path, Checksum *checksum){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + checksum->addFile(path); - map.load(path, &techTree, &tileset); + map.load(path, techTree, &tileset); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } //load map void World::loadScenario(const string &path, Checksum *checksum){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); checksum->addFile(path); scenario.load(path); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ==================== misc ==================== @@ -163,8 +203,8 @@ void World::update(){ } //food costs - for(int i=0; igetResourceTypeCount(); ++i){ + const ResourceType *rt= techTree->getResourceType(i); if(rt->getClass()==rcConsumable && frameCount % (rt->getInterval()*GameConstants::updateFps)==0){ for(int i=0; iapplyCostsOnInterval(); @@ -202,8 +242,8 @@ void World::tick(){ Faction *faction= getFaction(k); //for each resource - for(int i=0; igetResourceTypeCount(); ++i){ + const ResourceType *rt= techTree->getResourceType(i); //if consumable if(rt->getClass()==rcConsumable){ @@ -361,7 +401,7 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po void World::giveResource(const string &resourceName, int factionIndex, int amount){ if(factionIndexgetResourceType(resourceName); faction->incResourceAmount(rt, amount); } else @@ -437,7 +477,7 @@ void World::giveUpgradeCommand(int unitId, const string &upgradeName){ int World::getResourceAmount(const string &resourceName, int factionIndex){ if(factionIndexgetResourceType(resourceName); return faction->getResource(rt)->getAmount(); } else @@ -517,6 +557,7 @@ int World::getUnitCountOfType(int factionIndex, const string &typeName){ //init basic cell state void World::initCells(bool fogOfWar){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Logger::getInstance().add("State cells", true); for(int i=0; isetSurfaceTexture(texture); } } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } //creates each faction looking at each faction name contained in GameSettings void World::initFactionTypes(GameSettings *gs){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Logger::getInstance().add("Faction types", true); if(gs->getFactionCount() > map.getMaxPlayers()){ @@ -573,9 +618,9 @@ void World::initFactionTypes(GameSettings *gs){ this->thisFactionIndex= gs->getThisFactionIndex(); factions.resize(gs->getFactionCount()); for(int i=0; igetFactionTypeName(i)); + const FactionType *ft= techTree->getType(gs->getFactionTypeName(i)); factions[i].init( - ft, gs->getFactionControl(i), &techTree, game, i, gs->getTeam(i), + ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i), gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources()); stats.setTeam(i, gs->getTeam(i)); @@ -584,16 +629,19 @@ void World::initFactionTypes(GameSettings *gs){ } thisTeamIndex= getFaction(thisFactionIndex)->getTeam(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void World::initMinimap(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); minimap.init(map.getW(), map.getH(), this, game->getGameSettings()->getFogOfWar()); Logger::getInstance().add("Compute minimap surface", true); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } //place units randomly aroud start location void World::initUnits(){ - + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Logger::getInstance().add("Generate elements", true); //put starting units @@ -623,10 +671,13 @@ void World::initUnits(){ } map.computeNormals(); map.computeInterpolatedHeights(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void World::initMap(){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); map.init(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ==================== exploration ==================== diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 022ce865..138ec058 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.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 @@ -63,7 +63,8 @@ private: Map map; Tileset tileset; - TechTree techTree; + //TechTree techTree; + TechTree *techTree; TimeFlow timeFlow; Scenario scenario; @@ -93,6 +94,7 @@ private: public: World(); + ~World(); void end(); //to die before selection does //get @@ -103,7 +105,7 @@ public: int getFactionCount() const {return factions.size();} const Map *getMap() const {return ↦} const Tileset *getTileset() const {return &tileset;} - const TechTree *getTechTree() const {return &techTree;} + const TechTree *getTechTree() const {return techTree;} const Scenario *getScenario() const {return &scenario;} const TimeFlow *getTimeFlow() const {return &timeFlow;} Tileset *getTileset() {return &tileset;} diff --git a/source/shared_lib/include/platform/sdl/gl_wrap.h b/source/shared_lib/include/platform/sdl/gl_wrap.h index d58b13c1..79f43e5a 100644 --- a/source/shared_lib/include/platform/sdl/gl_wrap.h +++ b/source/shared_lib/include/platform/sdl/gl_wrap.h @@ -64,7 +64,11 @@ public: // Example values: // DEFAULT_CHARSET (English) = 1 // GB2312_CHARSET (Chinese) = 134 +#ifdef WIN32 static DWORD charSet = DEFAULT_CHARSET; +#else +static int charSet = 1; +#endif void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics); void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics); diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index c05e6f63..32e39ddf 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -189,7 +189,7 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner); - currentDebugLog.mutex->p(); + currentDebugLog.mutex->p(); (*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n"; (*currentDebugLog.fileStream).flush(); @@ -203,12 +203,12 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { assert(currentDebugLog.fileStream != NULL); - currentDebugLog.mutex->p(); + //currentDebugLog.mutex->p(); (*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf; (*currentDebugLog.fileStream).flush(); - currentDebugLog.mutex->v(); + //currentDebugLog.mutex->v(); } // output to console else {