2#include "Systems/ComponentSystem.h"
3#include "TexAtlasComponent.h"
5namespace Cogs::Core::TexAtlas
7 using SlotIx = uint16_t;
8 static constexpr SlotIx NoSlotIx =
static_cast<SlotIx
>(~0u);
10 using TreeIx = uint64_t;
11 static constexpr TreeIx NoTreeIx = ~static_cast<TreeIx>(0u);
31 TreeIx treeIx = NoTreeIx;
32 SlotIx slotIx = NoSlotIx;
49 std::string_view chars;
53 std::vector<UrlBuilderOp> urlBuilder;
54 std::vector<LoadItem> loaded;
55 std::vector<LoadItem> loading;
56 std::vector<LoadItem> tmp;
58 uint32_t currentFrame = 0;
59 uint32_t currentTime = 0;
61 uint32_t issuedThisFrame = 0;
63 uint32_t maxQueueSize = 10;
64 uint32_t maxIssuesPerFrame = 3;
66 uint32_t tileWidth = 0;
67 uint32_t tileHeight = 0;
69 glm::dvec2 datasetExtentMin;
70 glm::dvec2 datasetExtentMax;
73 void update(
Context* context, uint32_t currentFrame, uint32_t currentTime, uint32_t timeout, std::string_view urlTemplate);
83 const glm::uvec3& tileId,
100 State state = State::None;
101 TreeIx treePos = NoTreeIx;
102 uint32_t lastTouched = 0;
103 uint32_t stateChangeTime = 0;
104 uint8_t revision = 0;
108 uint32_t currentFrame = 0;
109 uint32_t currentTime = 0;
110 std::unordered_map<TreeIx, SlotIx> tree;
112 std::vector<Slot> slots;
118 void setStateNone(
Slot& slot) { slot.stateChangeTime =
currentTime; slot.state = Slot::State::None; slot.retries = 0; }
119 void setStateLoading(Slot& slot) { slot.stateChangeTime =
currentTime; slot.state = Slot::State::Loading; }
120 void setStateFailed(Slot& slot) { slot.stateChangeTime =
currentTime; slot.state = Slot::State::Failed; }
121 void setStateCancelled(Slot& slot) { slot.stateChangeTime =
currentTime; slot.state = Slot::State::Cancelled; slot.retries = 0; }
122 void setStateLoaded(Slot& slot) { slot.stateChangeTime = currentTime; slot.state = Slot::State::Loaded; slot.retries = 0; }
126 SlotIx getOrAllocCacheSlot(Context* context, Fetcher& fetcher,
const glm::uvec3& tileId);
141 std::vector<Tile> candidates;
142 std::vector<Tile> tiles;
143 std::vector<uint16_t> encoded;
145 void update(
Context* context,
const Geometry& geo,
Cache& cache,
Fetcher& fetcher,
const Layout& layout,
float tolerance,
bool restrictBetweenNearAndFar,
bool lodFreeze);
150 glm::dvec2 domain[2] = {};
151 glm::vec2 invDomainMapShift = glm::vec2(0.f);
152 glm::vec2 invDomainMapScale = glm::vec2(0.f);
154 float elevationMin = 0.f;
155 float elevationMax = 0.f;
157 void calcTileCorners(glm::vec4* corners,
const LodTree::Tile& tile)
const;
163 uint32_t lastSeen = 0;
170 std::string floatCoeffs;
171 std::string intCoeffs;
185 size_t treeHashValue = 0;
195 glm::mat4 floatCoefficients;
196 glm::ivec4 intCoefficients;
219 std::unordered_map<Material*, TexAtlas::TrackedMaterial> trackedMaterials;
221 std::vector<TexAtlas::MaterialKeys> materialKeys;
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Base allocator implementation.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ Geometry
Store entity vector fields (vector<vec3>, vector<vec2>, vector<int>, vector<float>).
ComponentIndex SizeType
Type used to track the size of pools.
COGSFOUNDATION_API Time currentTime()
High resolution clock time (NTP / UTC time). Returns an implementation defined absolute timestamp,...
Handle to a Component instance.
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.
void destroyComponent(ComponentHandle component) override
void initialize(Context *context) override
Initialize the system.
ComponentHandle createComponent() override
std::vector< SlotIx > lru
Slots sorted s.t. the least recently used items is at end.
uint32_t maxItemCount
Number of tiles in cache.
uint32_t minRetryDelay
Initial delay for retrying a fetch. For subsequent retries this delay is doubled each time.
uint32_t lruPointer
Points to one past the least recently and recycable item, decrements and zero means nothing to recycl...
void issueFetch(Context *context, const glm::uvec3 &tileId, TreeIx treeIx, SlotIx slotIx)
void update(Context *context, uint32_t currentFrame, uint32_t currentTime, uint32_t timeout, std::string_view urlTemplate)
void processLoadQueue(Context *context, Cache &cache)
glm::vec2 coefficients[4]
Coefficients wrt engine origin.
uint32_t level
Base level.
uint32_t maxLevel
Maximum level.
uint32_t tileScale
1 << level.
glm::uvec2 size
Size of grid.
glm::ivec2 offset
Indices of the grid cell with smallest indices.