From 3f5c4398737e026a2f2ee7dd3372cde4a60d56fd Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Mon, 29 Jun 2009 23:24:36 -0800 Subject: [PATCH] A very important optimisation; if we know that our mesh/shell is identical to the previous group's (because our thisShell and thisMesh are empty), then display the previous group's instead. This saves us re-triangulating the shell (or recalculating the edges of a triangle mesh) every time our group gets regenerated, which was horribly slow. [git-p4: depot-paths = "//depot/solvespace/": change = 2004] --- groupmesh.cpp | 32 ++++++++++++++++++++++---------- sketch.h | 3 ++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/groupmesh.cpp b/groupmesh.cpp index aff4ab0..599c6ed 100644 --- a/groupmesh.cpp +++ b/groupmesh.cpp @@ -376,20 +376,13 @@ Group *Group::PreviousGroup(void) { Group *g = &(SK.group.elem[i]); if(g->h.v == h.v) break; } - if(i == 0 || i >= SK.group.n) oops(); + if(i == 0 || i >= SK.group.n) return NULL; return &(SK.group.elem[i-1]); } -void Group::Draw(void) { - // Everything here gets drawn whether or not the group is hidden; we - // can control this stuff independently, with show/hide solids, edges, - // mesh, etc. - - // Triangulate the shells if necessary. - GenerateDisplayItems(); - +void Group::DrawDisplayItems(int t) { int specColor; - if(type == DRAWING_3D || type == DRAWING_WORKPLANE) { + if(t == DRAWING_3D || t == DRAWING_WORKPLANE) { specColor = RGB(25, 25, 25); // force the color to something dim } else { specColor = -1; // use the model color @@ -425,6 +418,25 @@ void Group::Draw(void) { } if(SS.GW.showMesh) glxDebugMesh(&displayMesh); +} + +void Group::Draw(void) { + // Everything here gets drawn whether or not the group is hidden; we + // can control this stuff independently, with show/hide solids, edges, + // mesh, etc. + + Group *pg = PreviousGroup(); + if(pg && thisMesh.IsEmpty() && thisShell.IsEmpty()) { + // We don't contribute any new solid model in this group, so our + // display items are identical to the previous group's; which means + // that we can just display those, and stop ourselves from + // recalculating for those every time we get a change in this group. + pg->GenerateDisplayItems(); + pg->DrawDisplayItems(type); + } else { + GenerateDisplayItems(); + DrawDisplayItems(type); + } // And finally show the polygons too if(!SS.GW.showShaded) return; diff --git a/sketch.h b/sketch.h index 2da9169..cfea758 100644 --- a/sketch.h +++ b/sketch.h @@ -210,10 +210,11 @@ public: void GenerateLoops(void); // And the mesh stuff Group *PreviousGroup(void); - void GenerateDisplayItems(void); void GenerateShellAndMesh(void); template void GenerateForStepAndRepeat(T *a, T *b, T *o, int how); template void GenerateForBoolean(T *a, T *b, T *o); + void GenerateDisplayItems(void); + void DrawDisplayItems(int t); void Draw(void); SPolygon GetPolygon(void);