- 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 no commands stop and add stop command
|
||||||
if(unit->anyCommand() == false && unit->isOperative()) {
|
if(unit->anyCommand() == false && unit->isOperative()) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
unit->setCurrSkill(scStop);
|
|
||||||
|
|
||||||
if(unit->getType()->hasCommandClass(ccStop)) {
|
const SkillType *currSkill= unit->getCurrSkill();
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(currSkill == NULL || currSkill->getClass() != scStop) {
|
||||||
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
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);
|
scriptManager->onUnitCreated(unit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
delete unit;
|
||||||
|
unit = NULL;
|
||||||
throw runtime_error("Unit cant be placed");
|
throw runtime_error("Unit cant be placed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1256,6 +1258,8 @@ void World::initUnits() {
|
||||||
unit->born();
|
unit->born();
|
||||||
}
|
}
|
||||||
else {
|
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));
|
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)) {
|
if (unit->getType()->hasSkillClass(scBeBuilt)) {
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "thread.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using Shared::Platform::int32;
|
using namespace Shared::Platform;
|
||||||
using Shared::Platform::int8;
|
|
||||||
|
|
||||||
namespace Shared{ namespace Util{
|
namespace Shared{ namespace Util{
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ private:
|
||||||
int32 c1;
|
int32 c1;
|
||||||
int32 c2;
|
int32 c2;
|
||||||
std::map<string,int32> fileList;
|
std::map<string,int32> fileList;
|
||||||
|
|
||||||
|
static Mutex fileListCacheSynchAccessor;
|
||||||
static std::map<string,int32> fileListCache;
|
static std::map<string,int32> fileListCache;
|
||||||
|
|
||||||
void addSum(int32 value);
|
void addSum(int32 value);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
|
#include "conversion.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -34,6 +35,7 @@ namespace Shared{ namespace Util{
|
||||||
// class Checksum
|
// class Checksum
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
Mutex Checksum::fileListCacheSynchAccessor;
|
||||||
std::map<string,int32> Checksum::fileListCache;
|
std::map<string,int32> Checksum::fileListCache;
|
||||||
|
|
||||||
Checksum::Checksum() {
|
Checksum::Checksum() {
|
||||||
|
@ -189,6 +191,8 @@ int32 Checksum::getSum() {
|
||||||
Checksum newResult;
|
Checksum newResult;
|
||||||
for(std::map<string,int32>::iterator iterMap = fileList.begin();
|
for(std::map<string,int32>::iterator iterMap = fileList.begin();
|
||||||
iterMap != fileList.end(); iterMap++) {
|
iterMap != fileList.end(); iterMap++) {
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexSocketDestructorFlag(&Checksum::fileListCacheSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
if(Checksum::fileListCache.find(iterMap->first) == Checksum::fileListCache.end()) {
|
if(Checksum::fileListCache.find(iterMap->first) == Checksum::fileListCache.end()) {
|
||||||
Checksum fileResult;
|
Checksum fileResult;
|
||||||
fileResult.addFileToSum(iterMap->first);
|
fileResult.addFileToSum(iterMap->first);
|
||||||
|
@ -213,12 +217,14 @@ int32 Checksum::getFileCount() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Checksum::removeFileFromCache(const string file) {
|
void Checksum::removeFileFromCache(const string file) {
|
||||||
|
MutexSafeWrapper safeMutexSocketDestructorFlag(&Checksum::fileListCacheSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
if(Checksum::fileListCache.find(file) != Checksum::fileListCache.end()) {
|
if(Checksum::fileListCache.find(file) != Checksum::fileListCache.end()) {
|
||||||
Checksum::fileListCache.erase(file);
|
Checksum::fileListCache.erase(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Checksum::clearFileCache() {
|
void Checksum::clearFileCache() {
|
||||||
|
MutexSafeWrapper safeMutexSocketDestructorFlag(&Checksum::fileListCacheSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
Checksum::fileListCache.clear();
|
Checksum::fileListCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue