- 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
This commit is contained in:
parent
37127cccfc
commit
8a9505e1e8
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#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<string,int32> fileList;
|
||||
|
||||
static Mutex fileListCacheSynchAccessor;
|
||||
static std::map<string,int32> fileListCache;
|
||||
|
||||
void addSum(int32 value);
|
||||
|
|
|
@ -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<string,int32> Checksum::fileListCache;
|
||||
|
||||
Checksum::Checksum() {
|
||||
|
@ -189,6 +191,8 @@ int32 Checksum::getSum() {
|
|||
Checksum newResult;
|
||||
for(std::map<string,int32>::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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue