Minor fixes.
This commit is contained in:
parent
01971c9f0d
commit
829e724a2c
9 changed files with 127 additions and 97 deletions
|
|
@ -14,23 +14,29 @@
|
||||||
#include <crlib/cr-movable.h>
|
#include <crlib/cr-movable.h>
|
||||||
#include <crlib/cr-random.h>
|
#include <crlib/cr-random.h>
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
// policy to reserve memory
|
// policy to reserve memory
|
||||||
CR_DECLARE_SCOPED_ENUM (ReservePolicy,
|
CR_DECLARE_SCOPED_ENUM (ReservePolicy,
|
||||||
MultipleByTwo,
|
Mutiple,
|
||||||
PlusOne
|
Single,
|
||||||
);
|
);
|
||||||
|
|
||||||
CR_NAMESPACE_BEGIN
|
CR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
// simple array class like std::vector
|
// simple array class like std::vector
|
||||||
template <typename T, ReservePolicy R = ReservePolicy::MultipleByTwo> class Array : public DenyCopying {
|
template <typename T, ReservePolicy R = ReservePolicy::Mutiple, size_t S = 0> class Array : public DenyCopying {
|
||||||
public:
|
public:
|
||||||
T *m_data = nullptr;
|
T *m_data = nullptr;
|
||||||
size_t m_capacity = 0;
|
size_t m_capacity = 0;
|
||||||
size_t m_length = 0;
|
size_t m_length = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Array () = default;
|
explicit Array () {
|
||||||
|
if (fix (S > 0)) {
|
||||||
|
reserve (S);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Array (const size_t amount) {
|
Array (const size_t amount) {
|
||||||
reserve (amount);
|
reserve (amount);
|
||||||
|
|
@ -44,6 +50,12 @@ public:
|
||||||
rhs.reset ();
|
rhs.reset ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array (std::initializer_list <T> list) {
|
||||||
|
for (const auto &elem : list) {
|
||||||
|
push (elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~Array () {
|
~Array () {
|
||||||
destroy ();
|
destroy ();
|
||||||
}
|
}
|
||||||
|
|
@ -79,9 +91,9 @@ public:
|
||||||
if (m_length + amount < m_capacity) {
|
if (m_length + amount < m_capacity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto capacity = m_capacity ? m_capacity : 8;
|
auto capacity = m_capacity ? m_capacity : 12;
|
||||||
|
|
||||||
if (cr::fix (R == ReservePolicy::MultipleByTwo)) {
|
if (cr::fix (R == ReservePolicy::Mutiple)) {
|
||||||
while (m_length + amount > capacity) {
|
while (m_length + amount > capacity) {
|
||||||
capacity *= 2;
|
capacity *= 2;
|
||||||
}
|
}
|
||||||
|
|
@ -110,10 +122,10 @@ public:
|
||||||
if (!ensure (amount)) {
|
if (!ensure (amount)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t pushLength = amount - m_length;
|
size_t resizeLength = amount - m_length;
|
||||||
|
|
||||||
for (size_t i = 0; i < pushLength; ++i) {
|
while (resizeLength--) {
|
||||||
push (T ());
|
emplace ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -193,6 +205,9 @@ public:
|
||||||
if (index + count > m_capacity) {
|
if (index + count > m_capacity) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
for (size_t i = m_length; i < m_length + count; i++) {
|
||||||
|
alloc.destruct (&m_data[i]);
|
||||||
|
}
|
||||||
m_length -= count;
|
m_length -= count;
|
||||||
|
|
||||||
for (size_t i = index; i < m_length; ++i) {
|
for (size_t i = index; i < m_length; ++i) {
|
||||||
|
|
@ -386,5 +401,8 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// small array (with minimal reserve policy, something like fixed array, but still able to grow, by default allocates 64 elements)
|
||||||
|
template <typename T> using SmallArray = Array <T, ReservePolicy::Single, 64>;
|
||||||
|
|
||||||
CR_NAMESPACE_END
|
CR_NAMESPACE_END
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,35 +84,39 @@ public:
|
||||||
private:
|
private:
|
||||||
void percolateUp (size_t index) {
|
void percolateUp (size_t index) {
|
||||||
while (index != 0) {
|
while (index != 0) {
|
||||||
size_t parent = this->parent (index);
|
size_t parentIndex = parent (index);
|
||||||
|
|
||||||
if (m_data[parent] <= m_data[index]) {
|
if (m_data[parentIndex] > m_data[index]) {
|
||||||
|
cr::swap (m_data[index], m_data[parentIndex]);
|
||||||
|
index = parentIndex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cr::swap (m_data[index], m_data[parent]);
|
|
||||||
index = parent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void percolateDown (size_t index) {
|
void percolateDown (size_t index) {
|
||||||
while (this->left (index) < m_data.length ()) {
|
while (hasLeft (index)) {
|
||||||
size_t best = this->left (index);
|
size_t bestIndex = left (index);
|
||||||
|
|
||||||
if (this->right (index) < m_data.length ()) {
|
if (hasRight (index)) {
|
||||||
size_t right_index = this->right (index);
|
size_t rightIndex = right (index);
|
||||||
|
|
||||||
if (m_data[right_index] < m_data[best]) {
|
if (m_data[rightIndex] < m_data[bestIndex]) {
|
||||||
best = right_index;
|
bestIndex = rightIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_data[index] <= m_data[best]) {
|
if (m_data[index] > m_data[bestIndex]) {
|
||||||
|
cr::swap (m_data[index], m_data[bestIndex]);
|
||||||
|
|
||||||
|
index = bestIndex;
|
||||||
|
bestIndex = left (index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cr::swap (m_data[index], m_data[best]);
|
|
||||||
|
|
||||||
index = best;
|
|
||||||
best = this->left (index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,16 +129,24 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr size_t parent (size_t index) {
|
||||||
|
return (index - 1) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr size_t left (size_t index) {
|
static constexpr size_t left (size_t index) {
|
||||||
return index << 1 | 1;
|
return (index * 2) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr size_t right (size_t index) {
|
static constexpr size_t right (size_t index) {
|
||||||
return ++index << 1;
|
return (index * 2) + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr size_t parent (size_t index) {
|
bool hasLeft (size_t index) const {
|
||||||
return --index >> 1;
|
return left (index) < m_data.length ();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasRight (size_t index) const {
|
||||||
|
return right (index) < m_data.length ();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ public:
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Array <uint8, ReservePolicy::PlusOne> buffer (m_chunkSize);
|
SmallArray <uint8> buffer (m_chunkSize);
|
||||||
m_code = parseResponseHeader (buffer.data ());
|
m_code = parseResponseHeader (buffer.data ());
|
||||||
|
|
||||||
if (m_code != HttpClientResult::OK) {
|
if (m_code != HttpClientResult::OK) {
|
||||||
|
|
@ -379,7 +379,7 @@ public:
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Array <uint8, ReservePolicy::PlusOne> buffer (m_chunkSize);
|
SmallArray <uint8> buffer (m_chunkSize);
|
||||||
int32 length = 0;
|
int32 length = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,7 @@ public:
|
||||||
template <typename ...Args> String &assignf (const char *fmt, Args ...args) {
|
template <typename ...Args> String &assignf (const char *fmt, Args ...args) {
|
||||||
const size_t size = snprintf (nullptr, 0, fmt, args...);
|
const size_t size = snprintf (nullptr, 0, fmt, args...);
|
||||||
|
|
||||||
Array <char, ReservePolicy::PlusOne> buffer (size + 1);
|
SmallArray <char> buffer (size + 1);
|
||||||
snprintf (buffer.data (), size + 1, fmt, cr::forward <Args> (args)...);
|
snprintf (buffer.data (), size + 1, fmt, cr::forward <Args> (args)...);
|
||||||
|
|
||||||
return assign (buffer.data ());
|
return assign (buffer.data ());
|
||||||
|
|
@ -278,7 +278,7 @@ public:
|
||||||
}
|
}
|
||||||
const size_t size = snprintf (nullptr, 0, fmt, args...) + length ();
|
const size_t size = snprintf (nullptr, 0, fmt, args...) + length ();
|
||||||
|
|
||||||
Array <char, ReservePolicy::PlusOne> buffer (size + 1);
|
SmallArray <char> buffer (size + 1);
|
||||||
snprintf (buffer.data (), size + 1, fmt, cr::forward <Args> (args)...);
|
snprintf (buffer.data (), size + 1, fmt, cr::forward <Args> (args)...);
|
||||||
|
|
||||||
return append (buffer.data ());
|
return append (buffer.data ());
|
||||||
|
|
|
||||||
|
|
@ -50,17 +50,9 @@ public:
|
||||||
return a.second < b.second;
|
return a.second < b.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator <= (const Twin &a, const Twin &b) {
|
|
||||||
return a.second <= b.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend bool operator > (const Twin &a, const Twin &b) {
|
friend bool operator > (const Twin &a, const Twin &b) {
|
||||||
return b.second < a.second;
|
return b.second < a.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator >= (const Twin &a, const Twin &b) {
|
|
||||||
return b.second <= a.second;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// creating pairs
|
// creating pairs
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ private:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Array <int32, ReservePolicy::PlusOne> m_hashTable;
|
SmallArray <int32> m_hashTable;
|
||||||
Array <int32, ReservePolicy::PlusOne> m_prevTable;
|
SmallArray <int32> m_prevTable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ULZ () {
|
ULZ () {
|
||||||
|
|
|
||||||
|
|
@ -1296,10 +1296,11 @@ private:
|
||||||
|
|
||||||
Array <edict_t *> m_activeGrenades; // holds currently active grenades on the map
|
Array <edict_t *> m_activeGrenades; // holds currently active grenades on the map
|
||||||
Array <edict_t *> m_intrestingEntities; // holds currently intresting entities on the map
|
Array <edict_t *> m_intrestingEntities; // holds currently intresting entities on the map
|
||||||
Array <CreateQueue> m_creationTab; // bot creation tab
|
|
||||||
Array <BotTask> m_filters; // task filters
|
|
||||||
|
|
||||||
Array <UniqueBot> m_bots; // all available bots
|
SmallArray <CreateQueue> m_creationTab; // bot creation tab
|
||||||
|
SmallArray <BotTask> m_filters; // task filters
|
||||||
|
SmallArray <UniqueBot> m_bots; // all available bots
|
||||||
|
|
||||||
edict_t *m_killerEntity; // killer entity for bots
|
edict_t *m_killerEntity; // killer entity for bots
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -1389,7 +1390,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the list of filters
|
// get the list of filters
|
||||||
Array <BotTask> &getFilters () {
|
SmallArray <BotTask> &getFilters () {
|
||||||
return m_filters;
|
return m_filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1552,11 +1553,11 @@ private:
|
||||||
IntArray m_rescuePoints;
|
IntArray m_rescuePoints;
|
||||||
IntArray m_visitedGoals;
|
IntArray m_visitedGoals;
|
||||||
|
|
||||||
Array <int32, ReservePolicy::PlusOne> m_buckets[kMaxBucketsInsidePos][kMaxBucketsInsidePos][kMaxBucketsInsidePos];
|
SmallArray <int32> m_buckets[kMaxBucketsInsidePos][kMaxBucketsInsidePos][kMaxBucketsInsidePos];
|
||||||
Array <Matrix, ReservePolicy::PlusOne> m_matrix;
|
SmallArray <Matrix> m_matrix;
|
||||||
Array <Practice, ReservePolicy::PlusOne> m_practice;
|
SmallArray <Practice> m_practice;
|
||||||
Array <Path, ReservePolicy::PlusOne> m_paths;
|
SmallArray <Path> m_paths;
|
||||||
Array <uint8, ReservePolicy::PlusOne> m_vistable;
|
SmallArray <uint8> m_vistable;
|
||||||
|
|
||||||
String m_tempStrings;
|
String m_tempStrings;
|
||||||
edict_t *m_editor;
|
edict_t *m_editor;
|
||||||
|
|
@ -1595,8 +1596,8 @@ public:
|
||||||
bool saveGraphData ();
|
bool saveGraphData ();
|
||||||
bool loadGraphData ();
|
bool loadGraphData ();
|
||||||
|
|
||||||
template <typename U> bool saveStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, const Array <U, ReservePolicy::PlusOne> &data, uint8 *blob);
|
template <typename U> bool saveStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, const SmallArray <U> &data, uint8 *blob);
|
||||||
template <typename U> bool loadStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, Array <U, ReservePolicy::PlusOne> &data, uint8 *blob, int32 *outOptions);
|
template <typename U> bool loadStorage (const String &ext, const String &name, StorageOption options, StorageVersion version, SmallArray <U> &data, uint8 *blob, int32 *outOptions);
|
||||||
|
|
||||||
void saveOldFormat ();
|
void saveOldFormat ();
|
||||||
void initGraph ();
|
void initGraph ();
|
||||||
|
|
@ -1641,7 +1642,7 @@ public:
|
||||||
|
|
||||||
Bucket locateBucket (const Vector &pos);
|
Bucket locateBucket (const Vector &pos);
|
||||||
IntArray searchRadius (float radius, const Vector &origin, int maxCount = -1);
|
IntArray searchRadius (float radius, const Vector &origin, int maxCount = -1);
|
||||||
const Array <int32, ReservePolicy::PlusOne> &getNodesInBucket (const Vector &pos);
|
const SmallArray <int32> &getNodesInBucket (const Vector &pos);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int getHighestDamageForTeam (int team) const {
|
int getHighestDamageForTeam (int team) const {
|
||||||
|
|
@ -1719,19 +1720,18 @@ private:
|
||||||
|
|
||||||
Array <BotName> m_botNames;
|
Array <BotName> m_botNames;
|
||||||
Array <Keywords> m_replies;
|
Array <Keywords> m_replies;
|
||||||
Array <WeaponInfo> m_weapons;
|
SmallArray <WeaponInfo> m_weapons;
|
||||||
Array <WeaponProp> m_weaponProps;
|
SmallArray <WeaponProp> m_weaponProps;
|
||||||
|
|
||||||
StringArray m_logos;
|
StringArray m_logos;
|
||||||
StringArray m_avatars;
|
StringArray m_avatars;
|
||||||
|
|
||||||
// default tables for personality weapon preferences, overridden by general.cfg
|
// default tables for personality weapon preferences, overridden by general.cfg
|
||||||
int m_normalWeaponPrefs[kNumWeapons] = { 0, 2, 1, 4, 5, 6, 3, 12, 10, 24, 25, 13, 11, 8, 7, 22, 23, 18, 21, 17, 19, 15, 17, 9, 14, 16 };
|
SmallArray <int32> m_normalWeaponPrefs = { 0, 2, 1, 4, 5, 6, 3, 12, 10, 24, 25, 13, 11, 8, 7, 22, 23, 18, 21, 17, 19, 15, 17, 9, 14, 16 };
|
||||||
int m_rusherWeaponPrefs[kNumWeapons] = { 0, 2, 1, 4, 5, 6, 3, 24, 19, 22, 23, 20, 21, 10, 12, 13, 7, 8, 11, 9, 18, 17, 19, 25, 15, 16 };
|
SmallArray <int32> m_rusherWeaponPrefs = { 0, 2, 1, 4, 5, 6, 3, 24, 19, 22, 23, 20, 21, 10, 12, 13, 7, 8, 11, 9, 18, 17, 19, 25, 15, 16 };
|
||||||
int m_carefulWeaponPrefs[kNumWeapons] = { 0, 2, 1, 4, 25, 6, 3, 7, 8, 12, 10, 13, 11, 9, 24, 18, 14, 17, 16, 15, 19, 20, 21, 22, 23, 5 };
|
SmallArray <int32> m_carefulWeaponPrefs = { 0, 2, 1, 4, 25, 6, 3, 7, 8, 12, 10, 13, 11, 9, 24, 18, 14, 17, 16, 15, 19, 20, 21, 22, 23, 5 };
|
||||||
int m_grenadeBuyPrecent[kNumWeapons - 23] = { 95, 85, 60 };
|
SmallArray <int32> m_botBuyEconomyTable = { 1900, 2100, 2100, 4000, 6000, 7000, 16000, 1200, 800, 1000, 3000 };
|
||||||
int m_botBuyEconomyTable[kNumWeapons - 15] = { 1900, 2100, 2100, 4000, 6000, 7000, 16000, 1200, 800, 1000, 3000 };
|
SmallArray <int32> m_grenadeBuyPrecent = { 95, 85, 60 };
|
||||||
int *m_weaponPrefs[3] = { m_normalWeaponPrefs, m_rusherWeaponPrefs, m_carefulWeaponPrefs };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BotConfig ();
|
BotConfig ();
|
||||||
|
|
@ -1822,7 +1822,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// get's the weapon info data
|
// get's the weapon info data
|
||||||
Array <WeaponInfo> &getWeapons () {
|
SmallArray <WeaponInfo> &getWeapons () {
|
||||||
return m_weapons;
|
return m_weapons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1842,13 +1842,23 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// get's weapon preferences for personality
|
// get's weapon preferences for personality
|
||||||
int *getWeaponPrefs (int personality) const {
|
int32 *getWeaponPrefs (int personality) const {
|
||||||
return m_weaponPrefs[personality];
|
switch (personality) {
|
||||||
|
case Personality::Normal:
|
||||||
|
default:
|
||||||
|
return m_normalWeaponPrefs.data ();
|
||||||
|
|
||||||
|
case Personality::Rusher:
|
||||||
|
return m_rusherWeaponPrefs.data ();
|
||||||
|
|
||||||
|
case Personality::Careful:
|
||||||
|
return m_carefulWeaponPrefs.data ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get economics value
|
// get economics value
|
||||||
int *getEconLimit () {
|
int32 *getEconLimit () {
|
||||||
return m_botBuyEconomyTable;
|
return m_botBuyEconomyTable.data ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get's grenade buy percents
|
// get's grenade buy percents
|
||||||
|
|
@ -1881,8 +1891,8 @@ private:
|
||||||
float m_welcomeReceiveTime;
|
float m_welcomeReceiveTime;
|
||||||
|
|
||||||
StringArray m_sentences;
|
StringArray m_sentences;
|
||||||
Array <Client> m_clients;
|
SmallArray <Client> m_clients;
|
||||||
Array <Twin <String, String>> m_tags;
|
SmallArray <Twin <String, String>> m_tags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BotUtils ();
|
BotUtils ();
|
||||||
|
|
@ -1966,12 +1976,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// get array of clients
|
// get array of clients
|
||||||
Array <Client> &getClients () {
|
SmallArray <Client> &getClients () {
|
||||||
return m_clients;
|
return m_clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get clients as const-reference
|
// get clients as const-reference
|
||||||
const Array <Client> &getClients () const {
|
const SmallArray <Client> &getClients () const {
|
||||||
return m_clients;
|
return m_clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2146,7 +2156,7 @@ public:
|
||||||
m_args.clear ();
|
m_args.clear ();
|
||||||
|
|
||||||
for (int i = 0; i < engfuncs.pfnCmd_Argc (); i++) {
|
for (int i = 0; i < engfuncs.pfnCmd_Argc (); i++) {
|
||||||
m_args.push (engfuncs.pfnCmd_Argv (i));
|
m_args.emplace (engfuncs.pfnCmd_Argv (i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1357,7 +1357,7 @@ bool BotGraph::convertOldFormat () {
|
||||||
return true;
|
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");
|
bool isGraph = (ext == "graph");
|
||||||
|
|
||||||
String filename;
|
String filename;
|
||||||
|
|
@ -1387,7 +1387,7 @@ template <typename U> bool BotGraph::saveStorage (const String &ext, const Strin
|
||||||
ULZ lz;
|
ULZ lz;
|
||||||
|
|
||||||
size_t rawLength = data.length () * sizeof (U);
|
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
|
// try to compress
|
||||||
auto compressedLength = lz.compress (reinterpret_cast <uint8 *> (data.data ()), rawLength, reinterpret_cast <uint8 *> (compressed.data ()));
|
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;
|
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;
|
String filename;
|
||||||
filename.assignf ("%s.%s", game.getMapName (), ext.chars ()).lowercase ();
|
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) {
|
if ((hdr.options & options) != options) {
|
||||||
return bailout ("Incorrect storage format for %s (filename: '%s').", name.chars (), filename.chars ());
|
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
|
// graph is not resized upon load
|
||||||
if (isGraph) {
|
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);
|
const auto &bucket = locateBucket (pos);
|
||||||
return m_buckets[bucket.x][bucket.y][bucket.z];
|
return m_buckets[bucket.x][bucket.y][bucket.z];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1660,13 +1660,16 @@ void BotConfig::loadNamesConfig () {
|
||||||
void BotConfig::loadWeaponsConfig () {
|
void BotConfig::loadWeaponsConfig () {
|
||||||
setupMemoryFiles ();
|
setupMemoryFiles ();
|
||||||
|
|
||||||
auto addWeaponEntries = [] (Array <WeaponInfo> &weapons, size_t max, bool as, const String &name, const StringArray &data) {
|
auto addWeaponEntries = [] (SmallArray <WeaponInfo> &weapons, 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 ());
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < max; ++i) {
|
for (size_t i = 0; i < data.length (); ++i) {
|
||||||
if (as) {
|
if (as) {
|
||||||
weapons[i].teamAS = data[i].int_ ();
|
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) {
|
auto addIntEntries = [] (SmallArray <int32> &to, const String &name, const StringArray &data) {
|
||||||
if (data.length () != max) {
|
if (data.length () != to.length ()) {
|
||||||
logger.error ("%s entry in weapons config is not valid or malformed.", name.chars ());
|
logger.error ("%s entry in weapons config is not valid or malformed (%d/%d).", name.chars (), data.length (), to.length ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < max; ++i) {
|
for (size_t i = 0; i < to.length (); ++i) {
|
||||||
to[i] = data[i].int_ ();
|
to[i] = data[i].int_ ();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1709,35 +1712,30 @@ void BotConfig::loadWeaponsConfig () {
|
||||||
auto splitted = pair[1].split (",");
|
auto splitted = pair[1].split (",");
|
||||||
|
|
||||||
if (pair[0].startsWith ("MapStandard")) {
|
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")) {
|
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")) {
|
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")) {
|
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")) {
|
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")) {
|
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")) {
|
else if (pair[0].startsWith ("PersonalityCareful")) {
|
||||||
addIntEntries (m_carefulWeaponPrefs, kNumWeapons, pair[0], splitted);
|
addIntEntries (m_carefulWeaponPrefs, pair[0], splitted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close ();
|
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 () {
|
void BotConfig::loadChatterConfig () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue