From 8a9505e1e826e7f4b1243f51b2f3d1d9ab5b2963 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 23 Mar 2011 00:49:21 +0000 Subject: [PATCH] - added conditional check to only issue a stop command to units if they are not already stopped - memory cleanup on unit errors - mutex for checksum class --- source/glest_game/world/unit_updater.cpp | 12 ++++++++---- source/glest_game/world/world.cpp | 4 ++++ source/shared_lib/include/util/checksum.h | 6 ++++-- source/shared_lib/sources/util/checksum.cpp | 6 ++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 9a1a0e06..be0f310f 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -266,11 +266,15 @@ void UnitUpdater::updateUnitCommand(Unit *unit, int frameIndex) { //if no commands stop and add stop command if(unit->anyCommand() == false && unit->isOperative()) { SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - unit->setCurrSkill(scStop); - if(unit->getType()->hasCommandClass(ccStop)) { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop))); + const SkillType *currSkill= unit->getCurrSkill(); + if(currSkill == NULL || currSkill->getClass() != scStop) { + unit->setCurrSkill(scStop); + + if(unit->getType()->hasCommandClass(ccStop)) { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop))); + } } } } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 184cbd03..5f775450 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -780,6 +780,8 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po scriptManager->onUnitCreated(unit); } else { + delete unit; + unit = NULL; throw runtime_error("Unit cant be placed"); } @@ -1256,6 +1258,8 @@ void World::initUnits() { unit->born(); } else { + delete unit; + unit = NULL; throw runtime_error("Unit cant be placed, this error is caused because there is no enough place to put the units near its start location, make a better map: "+unit->getType()->getName() + " Faction: "+intToStr(i)); } if (unit->getType()->hasSkillClass(scBeBuilt)) { diff --git a/source/shared_lib/include/util/checksum.h b/source/shared_lib/include/util/checksum.h index e4ecdb85..28922b17 100644 --- a/source/shared_lib/include/util/checksum.h +++ b/source/shared_lib/include/util/checksum.h @@ -15,11 +15,11 @@ #include #include #include "types.h" +#include "thread.h" #include "leak_dumper.h" using std::string; -using Shared::Platform::int32; -using Shared::Platform::int8; +using namespace Shared::Platform; namespace Shared{ namespace Util{ @@ -34,6 +34,8 @@ private: int32 c1; int32 c2; std::map fileList; + + static Mutex fileListCacheSynchAccessor; static std::map fileListCache; void addSum(int32 value); diff --git a/source/shared_lib/sources/util/checksum.cpp b/source/shared_lib/sources/util/checksum.cpp index 8829766e..c91636d0 100644 --- a/source/shared_lib/sources/util/checksum.cpp +++ b/source/shared_lib/sources/util/checksum.cpp @@ -23,6 +23,7 @@ #include "util.h" #include "platform_common.h" +#include "conversion.h" #include "leak_dumper.h" using namespace std; @@ -34,6 +35,7 @@ namespace Shared{ namespace Util{ // class Checksum // ===================================================== +Mutex Checksum::fileListCacheSynchAccessor; std::map Checksum::fileListCache; Checksum::Checksum() { @@ -189,6 +191,8 @@ int32 Checksum::getSum() { Checksum newResult; for(std::map::iterator iterMap = fileList.begin(); iterMap != fileList.end(); iterMap++) { + + MutexSafeWrapper safeMutexSocketDestructorFlag(&Checksum::fileListCacheSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); if(Checksum::fileListCache.find(iterMap->first) == Checksum::fileListCache.end()) { Checksum fileResult; fileResult.addFileToSum(iterMap->first); @@ -213,12 +217,14 @@ int32 Checksum::getFileCount() { } void Checksum::removeFileFromCache(const string file) { + MutexSafeWrapper safeMutexSocketDestructorFlag(&Checksum::fileListCacheSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); if(Checksum::fileListCache.find(file) != Checksum::fileListCache.end()) { Checksum::fileListCache.erase(file); } } void Checksum::clearFileCache() { + MutexSafeWrapper safeMutexSocketDestructorFlag(&Checksum::fileListCacheSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); Checksum::fileListCache.clear(); }