#pragma once #include #include "../CollabList.hpp" #include "../DrawComponents/DrawComponent.hpp" #include #include class DrawingProgram; class DrawingProgramCache { public: typedef CollabList, ServerClientID> CollabListType; DrawingProgramCache(DrawingProgram& initDrawP); void update(); void erase_component(const CollabListType::ObjectInfoPtr& c); void add_component(const CollabListType::ObjectInfoPtr& c); void refresh_all_draw_cache(SkCanvas* canvas, const DrawData& drawData); struct BVHNode { SCollision::AABB bounds; std::vector components; std::vector children; CoordSpaceHelper coords; Vector2i resolution; struct DrawCacheData { uint64_t lastDrawnComponentPlacement; sk_sp surface; std::chrono::steady_clock::time_point lastRenderTime; }; std::optional drawCache; }; std::unordered_set nodesWithCachedSurfaces; void traverse_bvh_run_function(const SCollision::AABB& aabb, std::function& components)> f); // Run before actually updating the component void preupdate_component(DrawComponent* c); void invalidate_cache_before_pos(uint64_t placementToInvalidateAt); private: void build_bvh_node_coords_and_resolution(BVHNode& node); void refresh_draw_cache(BVHNode& bvhNode, const DrawData& drawData); void build(std::vector components); void traverse_bvh_run_function_recursive(BVHNode& bvhNode, const SCollision::AABB& aabb, std::function& components)> f); std::pair::iterator> get_bvh_node_fully_containing_recursive(BVHNode& bvhNode, DrawComponent* c); void build_bvh_node(BVHNode& node, std::vector components); BVHNode bvhRoot; std::vector unsortedComponents; DrawingProgram& drawP; };