На этом коммите всё компилируется, дальше разработка профилей нод
This commit is contained in:
@@ -26,7 +26,6 @@ namespace fs = std::filesystem;
|
||||
тогда обычным оповещениям клиентам дойдёт новая версия
|
||||
|
||||
Подержать какое-то время ресурс в памяти
|
||||
|
||||
*/
|
||||
|
||||
class BinaryResourceManager : public AsyncObject {
|
||||
@@ -34,34 +33,52 @@ public:
|
||||
|
||||
private:
|
||||
struct Resource {
|
||||
// Файл загруженный на диск
|
||||
// Файл загруженный с диска
|
||||
std::shared_ptr<ResourceFile> Loaded;
|
||||
// Источник
|
||||
std::string Uri;
|
||||
bool IsLoading = false;
|
||||
size_t LastUsedTime = 0;
|
||||
|
||||
std::string LastError;
|
||||
};
|
||||
|
||||
struct UriParse {
|
||||
std::string Orig, Protocol, Path;
|
||||
std::string Protocol, Path;
|
||||
|
||||
std::string getFull() const {
|
||||
return Protocol + "://" + Path;
|
||||
}
|
||||
};
|
||||
|
||||
// Последовательная регистрация ресурсов
|
||||
BinTextureId_t NextIdTexture = 0, NextIdAnimation = 0, NextIdModel = 0,
|
||||
NextIdSound = 0, NextIdFont = 0;
|
||||
|
||||
// Ресурсы - кешированные в оперативную память или в процессе загрузки
|
||||
std::map<BinTextureId_t, std::shared_ptr<Resource>>
|
||||
|
||||
// Известные ресурсы
|
||||
std::map<std::string, ResourceId_t> KnownResource;
|
||||
std::map<ResourceId_t, std::shared_ptr<Resource>> ResourcesInfo;
|
||||
// Сюда
|
||||
TOS::SpinlockObject<std::vector<ResourceId_t>> UpdatedResources;
|
||||
// Подготовленая таблица оповещения об изменениях ресурсов
|
||||
// Должна забираться сервером и отчищаться
|
||||
std::unordered_map<ResourceId_t, std::shared_ptr<ResourceFile>> PreparedInformation;
|
||||
// Поток сервера
|
||||
// Последовательная регистрация ресурсов
|
||||
ResourceId_t NextId[(int) EnumBinResource::MAX_ENUM] = {0};
|
||||
// Известные ресурсы, им присвоен идентификатор
|
||||
std::unordered_map<std::string, ResourceId_t> KnownResource[(int) EnumBinResource::MAX_ENUM];
|
||||
std::unordered_map<ResourceId_t, std::shared_ptr<Resource>> ResourcesInfo[(int) EnumBinResource::MAX_ENUM];
|
||||
|
||||
// Местные потоки
|
||||
struct LocalObj_t {
|
||||
// Ресурсы - кешированные в оперативную память или в процессе загрузки
|
||||
std::map<BinTextureId_t, std::shared_ptr<Resource>> InMemory[(int) EnumBinResource::MAX_ENUM];
|
||||
// Кому-то нужно сопоставить идентификаторы с хэшами
|
||||
std::vector<ResourceId_t> BinToHash[(int) EnumBinResource::MAX_ENUM];
|
||||
// Запрос ресурсов, по которым потоки загружают ресурсы с диска
|
||||
std::vector<Hash_t> Hashes;
|
||||
};
|
||||
|
||||
TOS::SpinlockObject<LocalObj_t> Local;
|
||||
public:
|
||||
// Подготовленные оповещения о ресурсах
|
||||
struct OutObj_t {
|
||||
std::unordered_map<ResourceId_t, ResourceFile::Hash_t> BinToHash[(int) EnumBinResource::MAX_ENUM];
|
||||
std::vector<std::shared_ptr<ResourceFile>> HashToResource;
|
||||
};
|
||||
|
||||
private:
|
||||
TOS::SpinlockObject<OutObj_t> Out;
|
||||
|
||||
public:
|
||||
// Если ресурс будет обновлён или загружен будет вызвано onResourceUpdate
|
||||
@@ -71,17 +88,48 @@ public:
|
||||
// Перепроверка изменений ресурсов
|
||||
void recheckResources(std::vector<fs::path> assets /* Пути до активных папок assets */);
|
||||
// Выдаёт или назначает идентификатор для ресурса
|
||||
BinTextureId_t getTexture (const std::string& uri);
|
||||
BinAnimationId_t getAnimation(const std::string& uri);
|
||||
BinModelId_t getModel (const std::string& uri);
|
||||
BinSoundId_t getSound (const std::string& uri);
|
||||
BinFontId_t getFont (const std::string& uri);
|
||||
ResourceId_t getResource(const std::string& uri, EnumBinResource bin) {
|
||||
std::string fullUri = parseUri(uri).getFull();
|
||||
int index = (int) bin;
|
||||
|
||||
auto &container = KnownResource[index];
|
||||
auto iter = container.find(fullUri);
|
||||
if(iter == container.end()) {
|
||||
assert(NextId[index] != ResourceId_t(-1));
|
||||
ResourceId_t nextId = NextId[index]++;
|
||||
container.insert(iter, {fullUri, nextId});
|
||||
return nextId;
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
BinTextureId_t getTexture(const std::string& uri) {
|
||||
return getResource(uri, EnumBinResource::Texture);
|
||||
}
|
||||
|
||||
BinAnimationId_t getAnimation(const std::string& uri) {
|
||||
return getResource(uri, EnumBinResource::Animation);
|
||||
}
|
||||
|
||||
BinModelId_t getModel(const std::string& uri) {
|
||||
return getResource(uri, EnumBinResource::Model);
|
||||
}
|
||||
|
||||
BinSoundId_t getSound(const std::string& uri) {
|
||||
return getResource(uri, EnumBinResource::Sound);
|
||||
}
|
||||
|
||||
BinFontId_t getFont(const std::string& uri) {
|
||||
return getResource(uri, EnumBinResource::Font);
|
||||
}
|
||||
|
||||
// Запросить ресурсы через pushPreparedPackets
|
||||
void needResourceResponse(const ResourceRequest& resources);
|
||||
|
||||
// Запросить ресурсы через onResourceUpdate
|
||||
void needResourceResponse(const ResourceRequest &&resources);
|
||||
// Получение обновлений или оповещений ресурсов
|
||||
std::unordered_map<ResourceId_t, std::shared_ptr<ResourceFile>> takePreparedInformation() {
|
||||
return std::move(PreparedInformation);
|
||||
OutObj_t takePreparedInformation() {
|
||||
return std::move(*Out.lock());
|
||||
}
|
||||
|
||||
// Серверный такт
|
||||
@@ -89,8 +137,6 @@ public:
|
||||
|
||||
protected:
|
||||
UriParse parseUri(const std::string &uri);
|
||||
ResourceId_t getResource_Assets(std::string path);
|
||||
coro<> checkResource_Assets(ResourceId_t id, fs::path path, std::shared_ptr<Resource> res);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user