Skip to content

Commit

Permalink
Merge branch 'release' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Mar 2, 2013
2 parents f031cec + 1b6739b commit 81a6e05
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 44 deletions.
4 changes: 2 additions & 2 deletions rts/Sim/Features/FeatureHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ FeatureDef* CFeatureHandler::CreateFeatureDef(const LuaTable& fdTable, const std

fd->upright = fdTable.GetBool("upright", false);

fd->xsize = std::max(1 * 2, fdTable.GetInt("footprintX", 1) * 2);
fd->zsize = std::max(1 * 2, fdTable.GetInt("footprintZ", 1) * 2);
fd->xsize = std::max(1 * SPRING_FOOTPRINT_SCALE, fdTable.GetInt("footprintX", 1) * SPRING_FOOTPRINT_SCALE);
fd->zsize = std::max(1 * SPRING_FOOTPRINT_SCALE, fdTable.GetInt("footprintZ", 1) * SPRING_FOOTPRINT_SCALE);

const float minMass = CSolidObject::MINIMUM_MASS;
const float maxMass = CSolidObject::MAXIMUM_MASS;
Expand Down
10 changes: 10 additions & 0 deletions rts/Sim/Misc/GlobalConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
*/
const int SQUARE_SIZE = 8;

/**
* @brief footprint scale
*
* Multiplier for {Unit, Feature, Move}Def footprint sizes which are
* assumed to be expressed in "TA units". The resolution of Spring's
* blocking-map is twice that of TA's; a "TA-footprint" square covers
* SQUARE_SIZE*2 x SQUARE_SIZE*2 elmos.
*/
const int SPRING_FOOTPRINT_SCALE = 2;

/**
* conversion factor from elmos to meters
*/
Expand Down
2 changes: 1 addition & 1 deletion rts/Sim/Misc/NanoPieceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int NanoPieceCache::GetNanoPiece(CUnitScript* ownerScript) {
nanoPiece = nanoPieces[rnd % cnt];
}

if (lastNanoPieceCnt <= 30) {
if (lastNanoPieceCnt <= MAX_QUERYNANOPIECE_CALLS) {
// only do so 30 times and then use the cache
const int scriptPiece = ownerScript->QueryNanoPiece();
const int modelPiece = ownerScript->ScriptToModel(scriptPiece);
Expand Down
4 changes: 3 additions & 1 deletion rts/Sim/Misc/NanoPieceCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ struct NanoPieceCache {
const std::vector<int>& GetNanoPieces() const { return nanoPieces; }
std::vector<int>& GetNanoPieces() { return nanoPieces; }

void StopPolling() { lastNanoPieceCnt = 1e6; }
void StopPolling() { lastNanoPieceCnt = MAX_QUERYNANOPIECE_CALLS * 2; }

private:
// model-piece indices
std::vector<int> nanoPieces;

static const int MAX_QUERYNANOPIECE_CALLS = 30;

int lastNanoPieceCnt;
int curBuildPowerMask;
};
Expand Down
5 changes: 2 additions & 3 deletions rts/Sim/MoveTypes/MoveDefHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,12 @@ MoveDef::MoveDef(const LuaTable& moveTable, int moveDefID) {

const int xsizeDef = std::max(1, moveTable.GetInt("footprintX", 1));
const int zsizeDef = std::max(1, moveTable.GetInt("footprintZ", xsizeDef));
const int scale = 2;

// make all mobile footprints point-symmetric in heightmap space
// (meaning that only non-even dimensions are possible and each
// footprint always has a unique center square)
xsize = xsizeDef * scale;
zsize = zsizeDef * scale;
xsize = xsizeDef * SPRING_FOOTPRINT_SCALE;
zsize = zsizeDef * SPRING_FOOTPRINT_SCALE;
xsize -= ((xsize & 1)? 0: 1);
zsize -= ((zsize & 1)? 0: 1);
// precalculated data for MoveMath
Expand Down
75 changes: 38 additions & 37 deletions rts/Sim/Units/UnitDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,8 @@ UnitDef::UnitDef(const LuaTable& udTable, const std::string& unitName, int id)
activateWhenBuilt = udTable.GetBool("activateWhenBuilt", false);
onoffable = udTable.GetBool("onoffable", false);

// footprint sizes are assumed to be expressed in TA-engine units;
// Spring's heightmap resolution is double the footprint (yardmap)
// resolution, so we scale the values (which are not allowed to be
// 0)
// NOTE that this is done for the FeatureDef and MoveDef footprints
// as well
xsize = std::max(1 * 2, (udTable.GetInt("footprintX", 1) * 2));
zsize = std::max(1 * 2, (udTable.GetInt("footprintZ", 1) * 2));
xsize = std::max(1 * SPRING_FOOTPRINT_SCALE, (udTable.GetInt("footprintX", 1) * SPRING_FOOTPRINT_SCALE));
zsize = std::max(1 * SPRING_FOOTPRINT_SCALE, (udTable.GetInt("footprintZ", 1) * SPRING_FOOTPRINT_SCALE));

if (IsImmobileUnit()) {
CreateYardMap(udTable.GetString("yardMap", ""));
Expand Down Expand Up @@ -784,21 +778,27 @@ void UnitDef::CreateYardMap(std::string yardMapStr)
// defined, assume it is not supposed to be a building
// (so do not assign a default per facing)
return;
} else {
yardmap.resize(xsize * zsize);
}

StringToLowerInPlace(yardMapStr);

// read the yardmap in half resolution from the LuaDef string
const unsigned int hxsize = xsize >> 1;
const unsigned int hzsize = zsize >> 1;
const bool highResMap = (yardMapStr[0] == 'h');

const unsigned int hxsize = xsize >> (1 - highResMap);
const unsigned int hzsize = zsize >> (1 - highResMap);

std::vector<YardMapStatus> yardMap(hxsize * hzsize, YARDMAP_BLOCKED);
std::string foundUnknownChars;
// if high-res yardmap, start at second character
unsigned int ymReadIdx = highResMap;
unsigned int ymCopyIdx = 0;

unsigned int idx = 0;
std::vector<YardMapStatus> defYardMap(hxsize * hzsize, YARDMAP_BLOCKED);
std::string unknownChars;

for (unsigned int n = 0; n < yardMapStr.size(); n++) {
const unsigned char c = yardMapStr[n];
// read the yardmap from the LuaDef string
while (ymReadIdx < yardMapStr.size()) {
const unsigned char c = yardMapStr[ymReadIdx++];

if (isspace(c))
continue;
Expand All @@ -816,33 +816,34 @@ void UnitDef::CreateYardMap(std::string yardMapStr)
case 'f':
case 'o': ys = YARDMAP_BLOCKED; break;
default:
if (foundUnknownChars.find_first_of(c) == std::string::npos)
foundUnknownChars += c;
if (unknownChars.find_first_of(c) == std::string::npos)
unknownChars += c;
}

if (idx < hxsize * hzsize) {
yardMap[idx] = ys;
if (ymCopyIdx < defYardMap.size()) {
defYardMap[ymCopyIdx++] = ys;
}
idx++;
}

// print warnings
if (idx > yardMap.size())
LOG_L(L_WARNING, "%s: Given yardmap/blockmap contains "_STPF_" excess char(s)!", name.c_str(), idx - yardMap.size());

if (idx > 0 && idx < yardMap.size())
LOG_L(L_WARNING, "%s: Given yardmap/blockmap requires "_STPF_" extra char(s)!", name.c_str(), yardMap.size() - idx);

if (!foundUnknownChars.empty())
LOG_L(L_WARNING, "%s: Unknown char(s) in yardmap/blockmap \"%s\"!", name.c_str(), foundUnknownChars.c_str());

// write in doubled resolution to final unitdef tag
yardmap.resize(xsize * zsize);
for (unsigned int z = 0; z < zsize; z++) {
for (unsigned int x = 0; x < xsize; x++) {
const unsigned int yardMapIdx = (x >> 1) + ((z >> 1) * hxsize);
const YardMapStatus yardMapChar = yardMap[yardMapIdx];
yardmap[x + z * xsize] = yardMapChar;
if (ymCopyIdx > defYardMap.size())
LOG_L(L_WARNING, "%s: Given yardmap contains "_STPF_" excess char(s)!", name.c_str(), ymCopyIdx - defYardMap.size());

if (ymCopyIdx > 0 && ymCopyIdx < defYardMap.size())
LOG_L(L_WARNING, "%s: Given yardmap requires "_STPF_" extra char(s)!", name.c_str(), defYardMap.size() - ymCopyIdx);

if (!unknownChars.empty())
LOG_L(L_WARNING, "%s: Given yardmap contains unknown char(s) \"%s\"!", name.c_str(), unknownChars.c_str());

// write the final yardmap at blocking-map resolution
// (in case of a high-res map this becomes a 1:1 copy,
// otherwise the given yardmap will be upsampled)
for (unsigned int bmz = 0; bmz < zsize; bmz++) {
for (unsigned int bmx = 0; bmx < xsize; bmx++) {
const unsigned int yardMapIdx = (bmx >> (1 - highResMap)) + ((bmz >> (1 - highResMap)) * hxsize);
const YardMapStatus yardMapChar = defYardMap[yardMapIdx];

yardmap[bmx + bmz * xsize] = yardMapChar;
}
}
}
Expand Down

0 comments on commit 81a6e05

Please sign in to comment.