#pragma once #include "Shader.hpp" #include "../helpers/Box.hpp" #include "../helpers/Color.hpp" #include "Texture.hpp" #include #include #include #include #include #include struct SPreloadedAsset { CTexture texture; }; class CAsyncResourceGatherer { public: CAsyncResourceGatherer(); std::atomic ready = false; std::atomic applied = false; std::atomic progress = 0; /* only call from ogl thread */ SPreloadedAsset* getAssetByID(const std::string& id); void apply(); enum eTargetType { TARGET_IMAGE = 0, TARGET_TEXT }; struct SPreloadRequest { eTargetType type; std::string asset; std::string id; std::unordered_map props; }; void requestAsyncAssetPreload(const SPreloadRequest& request); void unloadAsset(SPreloadedAsset* asset); void notify(); private: std::thread initThread; std::thread asyncLoopThread; void asyncAssetSpinLock(); void renderText(const SPreloadRequest& rq); struct { std::condition_variable loopGuard; std::mutex loopMutex; std::mutex requestMutex; std::mutex assetsMutex; std::vector requests; bool pending = false; bool busy = false; } asyncLoopState; struct SPreloadTarget { eTargetType type = TARGET_IMAGE; std::string id = ""; void* data; void* cairo; void* cairosurface; Vector2D size; }; std::vector preloadTargets; std::unordered_map assets; void gather(); };