#pragma once #include #include "../CollabList.hpp" #include "../DrawComponents/DrawComponent.hpp" #include class DrawingProgramCache { public: typedef CollabList, ServerClientID> CollabListType; void update(const std::vector& components); void erase_component(const CollabListType::ObjectInfoPtr& c); void add_component(const CollabListType::ObjectInfoPtr& c); struct BVHNode { SCollision::AABB bounds; std::vector components; std::vector children; struct DrawCacheData { uint64_t lastDrawnComponentPlacement; sk_sp surface; }; std::optional drawCache; }; std::vector 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(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; };