- added a small cache to improve pathfinding a bit
- added logic to IGNORE the following characters when doing CRC checks in XML files (space,tab,CR,LF)
This commit is contained in:
parent
b52ca80388
commit
9e55d8e46b
|
@ -370,6 +370,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
|
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
|
std::map<Vec2i, std::map<Vec2i, std::map<int, std::map<int, std::map<Field,bool> > > > > moveLookupCache;
|
||||||
|
|
||||||
// This cache stores the units free cell movement calcs during the looping below
|
// This cache stores the units free cell movement calcs during the looping below
|
||||||
//std::map<Vec2i,std::map<Vec2i, bool> > localCacheForUnitCellMovement;
|
//std::map<Vec2i,std::map<Vec2i, bool> > localCacheForUnitCellMovement;
|
||||||
int whileLoopCount = 0;
|
int whileLoopCount = 0;
|
||||||
|
@ -412,7 +414,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
// canUnitMoveToCell = iterFind->second.find(sucPos)->second;
|
// canUnitMoveToCell = iterFind->second.find(sucPos)->second;
|
||||||
//}
|
//}
|
||||||
//else {
|
//else {
|
||||||
canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos);
|
|
||||||
|
|
||||||
|
canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos,&moveLookupCache);
|
||||||
//if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
//if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
// localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell;
|
// localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell;
|
||||||
//}
|
//}
|
||||||
|
|
|
@ -488,53 +488,108 @@ bool Map::canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//checks if a unit can move from between 2 cells using only visible cells (for pathfinding)
|
//checks if a unit can move from between 2 cells using only visible cells (for pathfinding)
|
||||||
bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const{
|
bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::map<Vec2i, std::map<Vec2i, std::map<int, std::map<int, std::map<Field,bool> > > > > *lookupCache) const {
|
||||||
int size= unit->getType()->getSize();
|
int size= unit->getType()->getSize();
|
||||||
int teamIndex= unit->getTeam();
|
int teamIndex= unit->getTeam();
|
||||||
Field field= unit->getCurrField();
|
Field field= unit->getCurrField();
|
||||||
|
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
std::map<Vec2i, std::map<Vec2i, std::map<int, std::map<int, std::map<Field,bool> > > > >::const_iterator iterFind1 = lookupCache->find(pos1);
|
||||||
|
if(iterFind1 != lookupCache->end()) {
|
||||||
|
std::map<Vec2i, std::map<int, std::map<int, std::map<Field,bool> > > >::const_iterator iterFind2 = iterFind1->second.find(pos2);
|
||||||
|
if(iterFind2 != iterFind1->second.end()) {
|
||||||
|
std::map<int, std::map<int, std::map<Field,bool> > >::const_iterator iterFind3 = iterFind2->second.find(teamIndex);
|
||||||
|
if(iterFind3 != iterFind2->second.end()) {
|
||||||
|
std::map<int, std::map<Field,bool> >::const_iterator iterFind4 = iterFind3->second.find(size);
|
||||||
|
if(iterFind4 != iterFind3->second.end()) {
|
||||||
|
std::map<Field,bool>::const_iterator iterFind5 = iterFind4->second.find(field);
|
||||||
|
if(iterFind5 != iterFind4->second.end()) {
|
||||||
|
// Found this result in the cache
|
||||||
|
return iterFind5->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//single cell units
|
//single cell units
|
||||||
if(size==1) {
|
if(size == 1) {
|
||||||
if(isAproxFreeCell(pos2, field, teamIndex) == false){
|
if(isAproxFreeCell(pos2, field, teamIndex) == false) {
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(pos1.x != pos2.x && pos1.y != pos2.y){
|
if(pos1.x != pos2.x && pos1.y != pos2.y) {
|
||||||
if(isAproxFreeCell(Vec2i(pos1.x, pos2.y), field, teamIndex) == false) {
|
if(isAproxFreeCell(Vec2i(pos1.x, pos2.y), field, teamIndex) == false) {
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(isAproxFreeCell(Vec2i(pos2.x, pos1.y), field, teamIndex) == false) {
|
if(isAproxFreeCell(Vec2i(pos2.x, pos1.y), field, teamIndex) == false) {
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
|
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//multi cell units
|
//multi cell units
|
||||||
else {
|
else {
|
||||||
for(int i=pos2.x; i<pos2.x+size; ++i) {
|
for(int i = pos2.x; i < pos2.x + size; ++i) {
|
||||||
for(int j=pos2.y; j<pos2.y+size; ++j) {
|
for(int j = pos2.y; j < pos2.y + size; ++j) {
|
||||||
if(isInside(i, j)){
|
if(isInside(i, j)) {
|
||||||
if(getCell(i, j)->getUnit(unit->getCurrField())!=unit) {
|
if(getCell(i, j)->getUnit(unit->getCurrField()) != unit) {
|
||||||
if(isAproxFreeCell(Vec2i(i, j), field, teamIndex) == false) {
|
if(isAproxFreeCell(Vec2i(i, j), field, teamIndex) == false) {
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
|
if(unit == NULL || unit->isBadHarvestPos(pos2) == true) {
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=false;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(lookupCache != NULL) {
|
||||||
|
(*lookupCache)[pos1][pos2][teamIndex][size][field]=true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,7 @@ public:
|
||||||
bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing);
|
bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing);
|
||||||
|
|
||||||
//unit placement
|
//unit placement
|
||||||
bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const;
|
bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::map<Vec2i, std::map<Vec2i, std::map<int, std::map<int, std::map<Field,bool> > > > > *lookupCache=NULL) const;
|
||||||
bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const;
|
bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const;
|
||||||
void putUnitCells(Unit *unit, const Vec2i &pos);
|
void putUnitCells(Unit *unit, const Vec2i &pos);
|
||||||
void clearUnitCells(Unit *unit, const Vec2i &pos);
|
void clearUnitCells(Unit *unit, const Vec2i &pos);
|
||||||
|
|
|
@ -22,9 +22,11 @@
|
||||||
#include <sys/stat.h> // for open()
|
#include <sys/stat.h> // for open()
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "platform_common.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
namespace Shared{ namespace Util{
|
namespace Shared{ namespace Util{
|
||||||
|
|
||||||
|
@ -115,13 +117,14 @@ void Checksum::addFileToSum(const string &path){
|
||||||
|
|
||||||
|
|
||||||
FILE* file= fopen(path.c_str(), "rb");
|
FILE* file= fopen(path.c_str(), "rb");
|
||||||
if(file!=NULL){
|
if(file!=NULL) {
|
||||||
|
|
||||||
addString(lastFile(path));
|
addString(lastFile(path));
|
||||||
|
|
||||||
|
bool isXMLFile = (EndsWith(path, ".xml") == true);
|
||||||
char buf[4096]=""; /* Should be large enough. */
|
char buf[4096]=""; /* Should be large enough. */
|
||||||
int bufSize = sizeof buf;
|
int bufSize = sizeof buf;
|
||||||
while(!feof(file)){
|
while(!feof(file)) {
|
||||||
//int8 byte= 0;
|
//int8 byte= 0;
|
||||||
|
|
||||||
//size_t readBytes = fread(&byte, 1, 1, file);
|
//size_t readBytes = fread(&byte, 1, 1, file);
|
||||||
|
@ -129,6 +132,12 @@ void Checksum::addFileToSum(const string &path){
|
||||||
if(fgets(buf, bufSize, file) != NULL) {
|
if(fgets(buf, bufSize, file) != NULL) {
|
||||||
//addByte(byte);
|
//addByte(byte);
|
||||||
for(int i = 0; buf[i] != 0 && i < bufSize; i++) {
|
for(int i = 0; buf[i] != 0 && i < bufSize; i++) {
|
||||||
|
// Ignore Spaces in XML files as they are
|
||||||
|
// ONLY for formatting
|
||||||
|
if(isXMLFile == true &&
|
||||||
|
(buf[i] == ' ' || buf[i] == '\t' || buf[i] == '\n' || buf[i] == '\r')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
addByte(buf[i]);
|
addByte(buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user