Added cache related settings

This commit is contained in:
Yousef Khadadeh 2026-01-24 12:31:55 +03:00
parent 428a56e0d1
commit 2e9e8eaf8b
5 changed files with 54 additions and 17 deletions

View file

@ -36,6 +36,9 @@
#include "Tools/EraserTool.hpp"
size_t DrawingProgram::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH = 33; // Around 30FPS
size_t DrawingProgram::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH = 400;
DrawingProgram::DrawingProgram(World& initWorld):
world(initWorld),
drawCache(*this),
@ -233,10 +236,10 @@ void DrawingProgram::modify_grid(const NetworkingObjects::NetObjWeakPtr<WorldGri
}
void DrawingProgram::update() {
if(world.main.window.lastFrameTime > std::chrono::milliseconds(33)) { // Around 30FPS
if(world.main.window.lastFrameTime > std::chrono::milliseconds(MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH)) {
if(!badFrametimeTimePoint)
badFrametimeTimePoint = std::chrono::steady_clock::now();
else if(unorderedObjectsExistTimePoint && std::chrono::steady_clock::now() - badFrametimeTimePoint.value() >= std::chrono::seconds(5) && std::chrono::steady_clock::now() - unorderedObjectsExistTimePoint.value() >= std::chrono::seconds(5)) {
else if(unorderedObjectsExistTimePoint && std::chrono::steady_clock::now() - badFrametimeTimePoint.value() >= std::chrono::milliseconds(MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH) && std::chrono::steady_clock::now() - unorderedObjectsExistTimePoint.value() >= std::chrono::milliseconds(MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH)) {
rebuild_cache();
unorderedObjectsExistTimePoint = std::nullopt;
badFrametimeTimePoint = std::nullopt;

View file

@ -22,6 +22,8 @@ class World;
class DrawingProgram {
public:
static size_t MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH;
static size_t MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH;
DrawingProgram(World& initWorld);
void server_init_no_file();
void toolbar_gui();

View file

@ -11,6 +11,11 @@
#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#endif
size_t DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD = 1000;
size_t DrawingProgramCache::MAXIMUM_COMPONENTS_IN_SINGLE_NODE = 50;
size_t DrawingProgramCache::MAXIMUM_DRAW_CACHE_SURFACES = 40;
size_t DrawingProgramCache::CACHE_NODE_RESOLUTION = 2048;
std::unordered_map<std::shared_ptr<DrawingProgramCacheBVHNode>, DrawingProgramCache::NodeCache> DrawingProgramCache::nodeCacheMap;
DrawingProgramCache::WindowCache DrawingProgramCache::windowCache;
@ -178,16 +183,14 @@ void DrawingProgramCache::build_bvh_node_coords_and_resolution(DrawingProgramCac
// - We dont have to recalculate it every time we refresh the cache
// - Some of the data here is needed to determine whether to generate the cache in the first place
constexpr int MAX_DIMENSION_RESOLUTION = 2048;
WorldVec cacheBoundDim = node.bounds.dim();
if(cacheBoundDim.x() > cacheBoundDim.y()) {
node.resolution.x() = MAX_DIMENSION_RESOLUTION;
node.resolution.y() = MAX_DIMENSION_RESOLUTION * static_cast<double>(cacheBoundDim.y() / cacheBoundDim.x());
node.resolution.x() = CACHE_NODE_RESOLUTION;
node.resolution.y() = CACHE_NODE_RESOLUTION * static_cast<double>(cacheBoundDim.y() / cacheBoundDim.x());
}
else {
node.resolution.y() = MAX_DIMENSION_RESOLUTION;
node.resolution.x() = MAX_DIMENSION_RESOLUTION * static_cast<double>(cacheBoundDim.x() / cacheBoundDim.y());
node.resolution.y() = CACHE_NODE_RESOLUTION;
node.resolution.x() = CACHE_NODE_RESOLUTION * static_cast<double>(cacheBoundDim.x() / cacheBoundDim.y());
}
node.coords.rotation = 0.0;
node.coords.pos = node.bounds.min;

View file

@ -15,9 +15,10 @@ struct DrawingProgramCacheBVHNode {
class DrawingProgramCache {
public:
static constexpr size_t MINIMUM_COMPONENTS_TO_START_REBUILD = 1000;
static constexpr size_t MAXIMUM_COMPONENTS_IN_SINGLE_NODE = 50;
static constexpr size_t MAXIMUM_DRAW_CACHE_SURFACES = 40;
static size_t MINIMUM_COMPONENTS_TO_START_REBUILD;
static size_t MAXIMUM_COMPONENTS_IN_SINGLE_NODE;
static size_t MAXIMUM_DRAW_CACHE_SURFACES;
static size_t CACHE_NODE_RESOLUTION;
DrawingProgramCache(DrawingProgram& initDrawP);
void add_component(CanvasComponentContainer::ObjInfo* c);