Minor fixes.

This commit is contained in:
Dmitry 2019-07-29 23:11:49 +03:00 committed by jeefo
commit 829e724a2c
9 changed files with 127 additions and 97 deletions

View file

@ -1357,7 +1357,7 @@ bool BotGraph::convertOldFormat () {
return true;
}
template <typename U> bool BotGraph::saveStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, const Array <U, ReservePolicy::PlusOne> &data, uint8 *blob) {
template <typename U> bool BotGraph::saveStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, const SmallArray <U> &data, uint8 *blob) {
bool isGraph = (ext == "graph");
String filename;
@ -1387,7 +1387,7 @@ template <typename U> bool BotGraph::saveStorage (const String &ext, const Strin
ULZ lz;
size_t rawLength = data.length () * sizeof (U);
Array <uint8, ReservePolicy::PlusOne> compressed (rawLength + sizeof (uint8) * ULZ::Excess);
SmallArray <uint8> compressed (rawLength + sizeof (uint8) * ULZ::Excess);
// try to compress
auto compressedLength = lz.compress (reinterpret_cast <uint8 *> (data.data ()), rawLength, reinterpret_cast <uint8 *> (compressed.data ()));
@ -1421,7 +1421,7 @@ template <typename U> bool BotGraph::saveStorage (const String &ext, const Strin
return true;
}
template <typename U> bool BotGraph::loadStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, Array <U, ReservePolicy::PlusOne> &data, uint8 *blob, int32 *outOptions) {
template <typename U> bool BotGraph::loadStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, SmallArray <U> &data, uint8 *blob, int32 *outOptions) {
String filename;
filename.assignf ("%s.%s", game.getMapName (), ext.chars ()).lowercase ();
@ -1552,7 +1552,7 @@ template <typename U> bool BotGraph::loadStorage (const String &ext, const Strin
if ((hdr.options & options) != options) {
return bailout ("Incorrect storage format for %s (filename: '%s').", name.chars (), filename.chars ());
}
Array <uint8, ReservePolicy::PlusOne> compressed (hdr.compressed + sizeof (uint8) * ULZ::Excess);
SmallArray <uint8> compressed (hdr.compressed + sizeof (uint8) * ULZ::Excess);
// graph is not resized upon load
if (isGraph) {
@ -2741,7 +2741,7 @@ BotGraph::Bucket BotGraph::locateBucket (const Vector &pos) {
};
}
const Array <int32, ReservePolicy::PlusOne> &BotGraph::getNodesInBucket (const Vector &pos) {
const SmallArray <int32> &BotGraph::getNodesInBucket (const Vector &pos) {
const auto &bucket = locateBucket (pos);
return m_buckets[bucket.x][bucket.y][bucket.z];
}

View file

@ -1660,13 +1660,16 @@ void BotConfig::loadNamesConfig () {
void BotConfig::loadWeaponsConfig () {
setupMemoryFiles ();
auto addWeaponEntries = [] (Array <WeaponInfo> &weapons, size_t max, bool as, const String &name, const StringArray &data) {
if (data.length () != max) {
logger.error ("%s entry in weapons config is not valid or malformed.", name.chars ());
auto addWeaponEntries = [] (SmallArray <WeaponInfo> &weapons, bool as, const String &name, const StringArray &data) {
// we're have null terminator element in weapons array...
if (data.length () + 1 != weapons.length ()) {
logger.error ("%s entry in weapons config is not valid or malformed (%d/%d).", name.chars (), data.length (), weapons.length ());
return;
}
for (size_t i = 0; i < max; ++i) {
for (size_t i = 0; i < data.length (); ++i) {
if (as) {
weapons[i].teamAS = data[i].int_ ();
}
@ -1676,13 +1679,13 @@ void BotConfig::loadWeaponsConfig () {
}
};
auto addIntEntries = [] (int *to, size_t max, const String &name, const StringArray &data) {
if (data.length () != max) {
logger.error ("%s entry in weapons config is not valid or malformed.", name.chars ());
auto addIntEntries = [] (SmallArray <int32> &to, const String &name, const StringArray &data) {
if (data.length () != to.length ()) {
logger.error ("%s entry in weapons config is not valid or malformed (%d/%d).", name.chars (), data.length (), to.length ());
return;
}
for (size_t i = 0; i < max; ++i) {
for (size_t i = 0; i < to.length (); ++i) {
to[i] = data[i].int_ ();
}
};
@ -1709,35 +1712,30 @@ void BotConfig::loadWeaponsConfig () {
auto splitted = pair[1].split (",");
if (pair[0].startsWith ("MapStandard")) {
addWeaponEntries (m_weapons, kNumWeapons, false, pair[0], splitted);
addWeaponEntries (m_weapons, false, pair[0], splitted);
}
else if (pair[0].startsWith ("MapAS")) {
addWeaponEntries (m_weapons, kNumWeapons, true, pair[0], splitted);
addWeaponEntries (m_weapons, true, pair[0], splitted);
}
else if (pair[0].startsWith ("GrenadePercent")) {
addIntEntries (m_grenadeBuyPrecent, 3, pair[0], splitted);
addIntEntries (m_grenadeBuyPrecent, pair[0], splitted);
}
else if (pair[0].startsWith ("Economics")) {
addIntEntries (m_botBuyEconomyTable, 11, pair[0], splitted);
addIntEntries (m_botBuyEconomyTable, pair[0], splitted);
}
else if (pair[0].startsWith ("PersonalityNormal")) {
addIntEntries (m_normalWeaponPrefs, kNumWeapons, pair[0], splitted);
addIntEntries (m_normalWeaponPrefs, pair[0], splitted);
}
else if (pair[0].startsWith ("PersonalityRusher")) {
addIntEntries (m_rusherWeaponPrefs, kNumWeapons, pair[0], splitted);
addIntEntries (m_rusherWeaponPrefs, pair[0], splitted);
}
else if (pair[0].startsWith ("PersonalityCareful")) {
addIntEntries (m_carefulWeaponPrefs, kNumWeapons, pair[0], splitted);
addIntEntries (m_carefulWeaponPrefs, pair[0], splitted);
}
}
file.close ();
}
// set personality weapon pointers here
m_weaponPrefs[Personality::Normal] = reinterpret_cast <int *> (&m_normalWeaponPrefs);
m_weaponPrefs[Personality::Rusher] = reinterpret_cast <int *> (&m_rusherWeaponPrefs);
m_weaponPrefs[Personality::Careful] = reinterpret_cast <int *> (&m_carefulWeaponPrefs);
}
void BotConfig::loadChatterConfig () {