From 31e911ba156a8548312b17e52b5a400836bd9638 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 27 Jul 2024 18:02:10 +0200 Subject: [PATCH] drawing tool:: improved performance of snapping, by caching --- mapeditor.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mapeditor.cpp b/mapeditor.cpp index f7934965..884c5d2d 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -161,15 +161,26 @@ EX namespace mapeditor { EX void clear_dtshapes() { dtshapes.clear(); } + /** cache the result of full_mouseh */ + EX shiftpoint fmh; + + EX bool fmh_known; + EX shiftpoint full_mouseh() { - #if CAP_EDIT - if(GDIM == 3) return find_mouseh3(); - if(snapping) return mouse_snap(); - #endif - return mouseh; + if(!fmh_known) { + fmh_known = true; + #if CAP_EDIT + if(GDIM == 3) fmh = find_mouseh3(); + else if(snapping) fmh = mouse_snap(); + else + #endif + fmh = mouseh; + } + return fmh; } EX void draw_dtshapes() { + fmh_known = false; #if CAP_EDIT for(auto& shp: dtshapes) { if(shp == nullptr) continue; @@ -192,7 +203,7 @@ EX namespace mapeditor { torus_rug_jump(moh, lstart); queueline(lstart, moh, dtcolor, 4 + vid.linequality, PPR::LINE); } - else if(!holdmouse) { + else if(!holdmouse && !mouseout()) { shiftmatrix T = rgpushxto0(moh); queueline(T * xpush0(-.1), T * xpush0(.1), dtcolor); queueline(T * ypush0(-.1), T * ypush0(.1), dtcolor); @@ -2151,7 +2162,7 @@ EX namespace mapeditor { queueline(drawtrans*ccenter, drawtrans*coldcenter, gridcolor, 4 + vid.linequality); if(snapping && !mouseout()) - queuestr(mouse_snap(), 10, "x", 0xC040C0); + queuestr(fmh, 10, "x", 0xC040C0); } static ld brush_sizes[10] = {