mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
use bitset for presenceFlags and steady_clock for measurments
This commit is contained in:
parent
794595184e
commit
44a645b5e0
@ -320,9 +320,9 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
|
|||||||
return stack->waited() ? BattleAction::makeDefend(stack) : BattleAction::makeWait(stack);
|
return stack->waited() ? BattleAction::makeDefend(stack) : BattleAction::makeWait(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t timeElapsed(std::chrono::time_point<std::chrono::high_resolution_clock> start)
|
uint64_t timeElapsed(std::chrono::time_point<std::chrono::steady_clock> start)
|
||||||
{
|
{
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
StorageType internalStorage;
|
StorageType internalStorage;
|
||||||
std::array<uint8_t, totalSize> presenceFlags = {};
|
std::bitset<totalSize> presenceFlags = {};
|
||||||
|
|
||||||
[[nodiscard]] inline bool BattleHexArray::isNotValidForInsertion(BattleHex hex) const
|
[[nodiscard]] inline bool BattleHexArray::isNotValidForInsertion(BattleHex hex) const
|
||||||
{
|
{
|
||||||
|
@ -111,13 +111,13 @@ const BattleHexArray & Unit::getHexes(BattleHex assumedPos) const
|
|||||||
|
|
||||||
const BattleHexArray & Unit::getHexes(BattleHex assumedPos, bool twoHex, BattleSide side)
|
const BattleHexArray & Unit::getHexes(BattleHex assumedPos, bool twoHex, BattleSide side)
|
||||||
{
|
{
|
||||||
static BattleHexArray::ArrayOfBattleHexArrays cache[4];
|
static BattleHexArray::ArrayOfBattleHexArrays precomputed[4];
|
||||||
int index = side == BattleSide::ATTACKER ? 0 : 2;
|
int index = side == BattleSide::ATTACKER ? 0 : 2;
|
||||||
|
|
||||||
if(!cache[index + twoHex][assumedPos].empty())
|
if(!precomputed[index + twoHex][assumedPos].empty())
|
||||||
return cache[index + twoHex][assumedPos];
|
return precomputed[index + twoHex][assumedPos];
|
||||||
|
|
||||||
// first run, initialize
|
// first run, compute
|
||||||
|
|
||||||
BattleHexArray hexes;
|
BattleHexArray hexes;
|
||||||
hexes.insert(assumedPos);
|
hexes.insert(assumedPos);
|
||||||
@ -125,9 +125,9 @@ const BattleHexArray & Unit::getHexes(BattleHex assumedPos, bool twoHex, BattleS
|
|||||||
if(twoHex)
|
if(twoHex)
|
||||||
hexes.insert(occupiedHex(assumedPos, twoHex, side));
|
hexes.insert(occupiedHex(assumedPos, twoHex, side));
|
||||||
|
|
||||||
cache[index + twoHex][assumedPos] = std::move(hexes);
|
precomputed[index + twoHex][assumedPos] = std::move(hexes);
|
||||||
|
|
||||||
return cache[index + twoHex][assumedPos];
|
return precomputed[index + twoHex][assumedPos];
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleHex Unit::occupiedHex() const
|
BattleHex Unit::occupiedHex() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user