2023-05-02 09:42:43 +03:00
|
|
|
//
|
2023-05-24 23:41:23 +03:00
|
|
|
// YaPB, based on PODBot by Markus Klinge ("CountFloyd").
|
|
|
|
|
// Copyright © YaPB Project Developers <yapb@jeefo.net>.
|
2023-05-02 09:42:43 +03:00
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
// storage file magic (podbot)
|
2023-05-12 20:00:06 +03:00
|
|
|
constexpr char kPodbotMagic[8] = { 'P', 'O', 'D', 'W', 'A', 'Y', '!', kNullChar };
|
2023-05-02 09:42:43 +03:00
|
|
|
|
|
|
|
|
constexpr int32_t kStorageMagic = 0x59415042; // storage magic for yapb-data files
|
2024-10-27 20:51:37 +03:00
|
|
|
constexpr int32_t kStorageMagicUB = 0x544f4255; // support also the fork format (merged back into yapb)
|
2023-05-02 09:42:43 +03:00
|
|
|
|
|
|
|
|
// storage header options
|
|
|
|
|
CR_DECLARE_SCOPED_ENUM (StorageOption,
|
|
|
|
|
Practice = cr::bit (0), // this is practice (experience) file
|
|
|
|
|
Matrix = cr::bit (1), // this is floyd warshal path & distance matrix
|
|
|
|
|
Vistable = cr::bit (2), // this is vistable data
|
|
|
|
|
Graph = cr::bit (3), // this is a node graph data
|
|
|
|
|
Official = cr::bit (4), // this is additional flag for graph indicates graph are official
|
|
|
|
|
Recovered = cr::bit (5), // this is additional flag indicates graph converted from podbot and was bad
|
|
|
|
|
Exten = cr::bit (6), // this is additional flag indicates that there's extension info
|
|
|
|
|
Analyzed = cr::bit (7) // this graph has been analyzed
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// storage header versions
|
|
|
|
|
CR_DECLARE_SCOPED_ENUM (StorageVersion,
|
|
|
|
|
Graph = 2,
|
|
|
|
|
Practice = 2,
|
2024-04-17 21:20:45 +03:00
|
|
|
Vistable = 4,
|
2023-05-02 09:42:43 +03:00
|
|
|
Matrix = 2,
|
|
|
|
|
Podbot = 7
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
CR_DECLARE_SCOPED_ENUM_TYPE (BotFile, uint32_t,
|
|
|
|
|
Vistable = 0,
|
|
|
|
|
LogFile = 1,
|
|
|
|
|
Practice = 2,
|
|
|
|
|
Graph = 3,
|
|
|
|
|
Pathmatrix = 4,
|
|
|
|
|
PodbotPWF = 5,
|
|
|
|
|
EbotEWP = 6
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class BotStorage final : public Singleton <BotStorage> {
|
|
|
|
|
private:
|
|
|
|
|
struct SaveLoadData {
|
|
|
|
|
String name {};
|
|
|
|
|
int32_t option {};
|
|
|
|
|
int32_t version {};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
SaveLoadData (StringRef name, int32_t option, int32_t version) : name (name), option (option), version (version) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_retries {};
|
2025-02-28 00:39:52 +03:00
|
|
|
ULZ *m_ulz {};
|
2023-05-02 09:42:43 +03:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
BotStorage () = default;
|
|
|
|
|
~BotStorage () = default;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// converts type to save/load options
|
|
|
|
|
template <typename U> SaveLoadData guessType ();
|
|
|
|
|
|
|
|
|
|
// loads the data and decompress ulz
|
|
|
|
|
template <typename U> bool load (SmallArray <U> &data, ExtenHeader *exten = nullptr, int32_t *outOptions = nullptr);
|
|
|
|
|
|
|
|
|
|
// saves the data and compress with ulz
|
|
|
|
|
template <typename U> bool save (const SmallArray <U> &data, ExtenHeader *exten = nullptr, int32_t passOptions = 0);
|
|
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
// report fatal error loading stuff
|
2023-05-02 09:42:43 +03:00
|
|
|
template <typename ...Args> bool error (bool isGraph, bool isDebug, MemFile &file, const char *fmt, Args &&...args);
|
|
|
|
|
|
|
|
|
|
// builds the filename to requested filename
|
2024-01-30 14:37:14 +03:00
|
|
|
String buildPath (int32_t type, bool isMemoryLoad = false, bool withoutMapName = false);
|
2023-05-02 09:42:43 +03:00
|
|
|
|
2023-12-20 00:06:45 +03:00
|
|
|
// get's relative path against bot library (bot library should reside in bin dir)
|
2024-01-26 19:52:00 +03:00
|
|
|
StringRef getRunningPath ();
|
2023-12-20 00:06:45 +03:00
|
|
|
|
|
|
|
|
// same as above, but with valve-specific filesystem paths (loadfileforme)
|
2024-01-26 19:52:00 +03:00
|
|
|
StringRef getRunningPathVFS ();
|
2023-12-20 00:06:45 +03:00
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
// converts storage option to storage filename
|
2023-05-02 09:42:43 +03:00
|
|
|
int32_t storageToBotFile (int32_t options);
|
|
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
// remove all bot related files from disk
|
2025-01-31 20:40:08 +03:00
|
|
|
void unlinkFromDisk (bool onlyTrainingData);
|
2023-05-02 09:42:43 +03:00
|
|
|
|
|
|
|
|
public:
|
2023-05-12 22:12:22 +03:00
|
|
|
// loading the graph may attempt to recurse loading, with converting or download, reset retry counter
|
2023-05-02 09:42:43 +03:00
|
|
|
void resetRetries () {
|
|
|
|
|
m_retries = 0;
|
|
|
|
|
}
|
2025-02-28 00:39:52 +03:00
|
|
|
|
|
|
|
|
// set the compressor instance
|
|
|
|
|
void setUlzInstance (ULZ *ulz) {
|
|
|
|
|
m_ulz = ulz;
|
|
|
|
|
}
|
2023-05-02 09:42:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#if !defined (BOT_STORAGE_EXPLICIT_INSTANTIATIONS)
|
|
|
|
|
# define BOT_STORAGE_EXPLICIT_INSTANTIATIONS
|
|
|
|
|
# include "../src/storage.cpp"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#undef BOT_STORAGE_EXPLICIT_INSTANTIATIONS
|
|
|
|
|
|
2023-05-12 22:12:22 +03:00
|
|
|
// expose global
|
2023-05-02 09:42:43 +03:00
|
|
|
CR_EXPOSE_GLOBAL_SINGLETON (BotStorage, bstor);
|
|
|
|
|
|