# HG changeset patch # User Santeri Piippo # Date 1397852221 -10800 # Node ID f2cc5964f52d0338bc0cd9e5d2a317f10ba14136 # Parent a2cbef6336738833d72be978fd169af1c6053174 - sped up known vertex information gathering by an order of magnitude diff -r a2cbef633673 -r f2cc5964f52d src/ldDocument.cc --- a/src/ldDocument.cc Fri Apr 18 18:58:13 2014 +0300 +++ b/src/ldDocument.cc Fri Apr 18 23:17:01 2014 +0300 @@ -132,7 +132,7 @@ setTabIndex (-1); setHistory (new History); history()->setDocument (this); - m_needsGLReInit = true; + m_needsReCache = true; } // ============================================================================= @@ -1114,10 +1114,12 @@ if (obj->type() == LDObject::ESubfile) { - for (LDObject* sub : static_cast (obj)->inlineContents (true, false)) + LDSubfile* ref = static_cast (obj); + + for (Vertex vrt : ref->fileInfo()->inlineVertices()) { - addKnownVerticesOf (sub); - sub->destroy(); + vrt.transform (ref->transform(), ref->position()); + addKnownVertexReference (vrt); } } else @@ -1136,10 +1138,12 @@ if (obj->type() == LDObject::ESubfile) { - for (LDObject* sub : static_cast (obj)->inlineContents (true, false)) + LDSubfile* ref = static_cast (obj); + + for (Vertex vrt : ref->fileInfo()->inlineVertices()) { - removeKnownVerticesOf (sub); - sub->destroy(); + vrt.transform (ref->transform(), ref->position()); + removeKnownVertexReference (vrt); } } else @@ -1293,10 +1297,13 @@ // ============================================================================= // -void LDDocument::initializeGLData() +void LDDocument::initializeCachedData() { - print (getDisplayName() + ": Initializing GL data"); + if (not m_needsReCache) + return; + LDObjectList objs = inlineContents (true, true); + m_storedVertices.clear(); for (LDObject* obj : objs) { @@ -1309,19 +1316,21 @@ delete data; } + for (int i = 0; i < obj->vertices(); ++i) + m_storedVertices << obj->vertex (i); + obj->destroy(); } - m_needsGLReInit = false; + removeDuplicates (m_storedVertices); + m_needsReCache = false; } // ============================================================================= // QList LDDocument::inlinePolygons() { - if (m_needsGLReInit == true) - initializeGLData(); - + initializeCachedData(); return polygonData(); } @@ -1530,3 +1539,11 @@ if (references().isEmpty()) invokeLater (closeUnused); } + +// ============================================================================= +// +QList LDDocument::inlineVertices() +{ + initializeCachedData(); + return m_storedVertices; +} diff -r a2cbef633673 -r f2cc5964f52d src/ldDocument.h --- a/src/ldDocument.h Fri Apr 18 18:58:13 2014 +0300 +++ b/src/ldDocument.h Fri Apr 18 23:17:01 2014 +0300 @@ -94,7 +94,7 @@ QString getDisplayName(); const LDObjectList& getSelection() const; bool hasUnsavedChanges() const; // Does this document have unsaved changes? - void initializeGLData(); + void initializeCachedData(); LDObjectList inlineContents (bool deep, bool renderinline); void insertObj (int pos, LDObject* obj); int getObjectCount() const; @@ -109,6 +109,7 @@ void vertexChanged (const Vertex& a, const Vertex& b); void addKnownVerticesOf(LDObject* obj); void removeKnownVerticesOf (LDObject* sub); + QList inlineVertices(); inline LDDocument& operator<< (LDObject* obj) { @@ -165,10 +166,11 @@ private: LDObjectList m_sel; LDGLData* m_gldata; + QList m_storedVertices; // If set to true, next polygon inline of this document discards the // stored polygon data and re-builds it. - bool m_needsGLReInit; + bool m_needsReCache; static LDDocument* m_curdoc; diff -r a2cbef633673 -r f2cc5964f52d src/ldObject.cc --- a/src/ldObject.cc Fri Apr 18 18:58:13 2014 +0300 +++ b/src/ldObject.cc Fri Apr 18 23:17:01 2014 +0300 @@ -890,6 +890,6 @@ a->isImplicit() == false && a->polygonData().isEmpty()) { - a->initializeGLData(); + a->initializeCachedData(); } };