Speed up picking - no need to rebuild the object list as its contents do not change while picking. Fixed transparent stuff always being opaque (although it still appears messed up for some reason)

2013-05-08

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 09 May 2013 02:28:39 +0300 (2013-05-08)
changeset 185
6fea53f1ffc2
parent 184
fae3bc9ce319
child 186
a130960bb220

Speed up picking - no need to rebuild the object list as its contents do not change while picking. Fixed transparent stuff always being opaque (although it still appears messed up for some reason)

src/colors.cpp file | annotate | diff | comparison | revisions
src/extprogs.cpp file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui_editactions.cpp file | annotate | diff | comparison | revisions
src/history.cpp file | annotate | diff | comparison | revisions
src/history.h file | annotate | diff | comparison | revisions
src/historyDialog.cpp file | annotate | diff | comparison | revisions
src/historyDialog.h file | annotate | diff | comparison | revisions
src/ldrawPathDialog.cpp file | annotate | diff | comparison | revisions
src/ldtypes.cpp file | annotate | diff | comparison | revisions
src/ldtypes.h file | annotate | diff | comparison | revisions
src/misc.cpp file | annotate | diff | comparison | revisions
src/misc.h file | annotate | diff | comparison | revisions
--- a/src/colors.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/colors.cpp	Thu May 09 02:28:39 2013 +0300
@@ -114,59 +114,59 @@
 		zLine.replace ("\r", "");
 		
 		StringParser pars (zLine, ' ');
-		short dCode = 0, dAlpha = 255;
-		str zName, zColor, zEdge, zValue;
+		short code = 0, alpha = 255;
+		str name, colname, edge, value;
 		
 		// Check 0 !COLOUR, parse the name
-		if (!pars.tokenCompare (0, "0") || !pars.tokenCompare (1, "!COLOUR") || !pars.getToken (zName, 2))
+		if (!pars.tokenCompare (0, "0") || !pars.tokenCompare (1, "!COLOUR") || !pars.getToken (name, 2))
 			continue;
 		
 		// Replace underscores in the name with spaces for readability
-		zName.replace ("_", " ");
+		name.replace ("_", " ");
 		
 		// get the CODE tag
-		if (!parseLDConfigTag (pars, "CODE", zValue))
+		if (!parseLDConfigTag (pars, "CODE", value))
 			continue;
 		
 		// Ensure that the code is within range. must be within 0 - 512
-		dCode = atoi (zValue);
-		if (dCode < 0 || dCode >= 512)
+		code = atoi (value);
+		if (code < 0 || code >= 512)
 			continue;
 		
 		// Don't let LDConfig.ldr override the special colors 16 and 24. However,
 		// do take the name it gives for the color
-		if (dCode == maincolor || dCode == edgecolor) {
-			g_LDColors[dCode]->zName = zName;
+		if (code == maincolor || code == edgecolor) {
+			g_LDColors[code]->zName = name;
 			continue;
 		}
 		
 		// VALUE tag
-		if (!parseLDConfigTag (pars, "VALUE", zColor))
+		if (!parseLDConfigTag (pars, "VALUE", colname))
 			continue;
 		
 		// EDGE tag
-		if (!parseLDConfigTag (pars, "EDGE", zEdge))
+		if (!parseLDConfigTag (pars, "EDGE", edge))
 			continue;
 		
 		// Ensure that our colors are correct
-		QColor qColor (zColor.chars()),
-			qEdge (zEdge.chars());
+		QColor qColor (colname.chars()),
+			qEdge (edge.chars());
 		
 		if (!qColor.isValid () || !qEdge.isValid ())
 			continue;
 		
 		// Parse alpha if given.
-		if (parseLDConfigTag (pars, "ALPHA", zValue))
-			dAlpha = clamp<short> (atoi (zValue), 0, 255);
+		if (parseLDConfigTag (pars, "ALPHA", value))
+			alpha = clamp<short> (atoi (value), 0, 255);
 		
 		color* col = new color;
-		col->zName = zName;
+		col->zName = name;
 		col->qColor = qColor;
 		col->qEdge = qEdge;
-		col->zColorString = zColor;
-		col->qColor.setAlpha (dAlpha);
+		col->zColorString = colname;
+		col->qColor.setAlpha (alpha);
 		
-		g_LDColors[dCode] = col;
+		g_LDColors[code] = col;
 	}
 	
 	fclose (fp);
--- a/src/extprogs.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/extprogs.cpp	Thu May 09 02:28:39 2013 +0300
@@ -175,7 +175,7 @@
 	// Wait while it runs
 	proc.waitForFinished ();
 	
-#ifndef RELASE
+#ifndef RELEASE
 	printf ("%s", qchars (QString (proc.readAllStandardOutput ())));
 #endif // RELEASE
 	
--- a/src/gldraw.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/gldraw.cpp	Thu May 09 02:28:39 2013 +0300
@@ -162,19 +162,6 @@
 void GLRenderer::initializeGL () {
 	setBackground ();
 	
-	glEnable (GL_POLYGON_OFFSET_FILL);
-	glPolygonOffset (1.0f, 1.0f);
-	
-	glEnable (GL_DEPTH_TEST);
-	glShadeModel (GL_SMOOTH);
-	glEnable (GL_MULTISAMPLE);
-	
-	glEnable (GL_BLEND);
-	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	
-	glEnable (GL_LINE_SMOOTH);
-	glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
-	
 	glLineWidth (gl_linethickness);
 	
 	setAutoFillBackground (false);
@@ -213,13 +200,13 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 static vector<short> g_daWarnedColors;
-void GLRenderer::setObjectColor (LDObject* obj) {
+void GLRenderer::setObjectColor (LDObject* obj, const ListType list) {
 	QColor qcol;
 	
-	if (!obj->isColored())
+	if (!obj->isColored ())
 		return;
 	
-	if (m_picking) {
+	if (list == GL::PickList) {
 		// Make the color by the object's index color if we're picking, so we can
 		// make the index from the color we get from the picking results.
 		long i = obj->getIndex (g_curfile);
@@ -294,24 +281,12 @@
 		b = qcol.blue (),
 		a = qcol.alpha ();
 	
-	// If it's selected, brighten it up, also pulse flash it if desired.
-	if (g_win->isSelected (obj)) {
-		short tick, numTicks;
-		
-		if (gl_selflash) {
-			tick = (g_pulseTick < (g_numPulseTicks / 2)) ? g_pulseTick : (g_numPulseTicks - g_pulseTick);
-			numTicks = g_numPulseTicks;
-		} else {
-			tick = 2;
-			numTicks = 5;
-		}
-		
-		const long add = ((tick * 128) / numTicks);
+	// Brighten it up for the select list.
+	if (list == GL::SelectList) {
+		const uchar add = 51;
 		r = min (r + add, 255l);
 		g = min (g + add, 255l);
 		b = min (b + add, 255l);
-		
-		// a = 255;
 	}
 	
 	glColor4f (
@@ -392,7 +367,7 @@
 		if (obj->hidden ())
 			continue; // Don't draw hidden objects
 		
-		glCallList (m_picking == false ? obj->uGLList : obj->uGLPickList);
+		glCallList (obj->glLists[(m_picking) ? PickList : (obj->selected ()) ? SelectList : NormalList]);
 	}
 	
 	if (gl_axes && !m_picking)
@@ -469,6 +444,19 @@
 	Q_UNUSED (ev)
 	m_virtWidth = m_zoom;
 	m_virtHeight = (m_height * m_virtWidth) / m_width;
+	
+	glEnable (GL_BLEND);
+	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	glEnable (GL_POLYGON_OFFSET_FILL);
+	glPolygonOffset (1.0f, 1.0f);
+	
+	glEnable (GL_DEPTH_TEST);
+	glShadeModel (GL_SMOOTH);
+	glEnable (GL_MULTISAMPLE);
+	
+	glEnable (GL_LINE_SMOOTH);
+	glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
+	
 	drawGLScene ();
 	
 	QPainter paint (this);
@@ -625,24 +613,8 @@
 		return;
 	}
 	
-	for (LDObject* obj : g_curfile->m_objs) {
-		GLuint* upaLists[2] = {
-			&obj->uGLList,
-			&obj->uGLPickList
-		};
-		
-		for (GLuint* upMemberList : upaLists) {
-			GLuint uList = glGenLists (1);
-			glNewList (uList, GL_COMPILE);
-			
-			m_picking = (upMemberList == &obj->uGLPickList);
-			compileOneObject (obj);
-			m_picking = false;
-			
-			glEndList ();
-			*upMemberList = uList;
-		}
-	}
+	for (LDObject* obj : g_curfile->m_objs)
+		compileObject (obj);
 	
 	// Compile axes
 	m_axeslist = glGenLists (1);
@@ -674,8 +646,8 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void GLRenderer::compileOneObject (LDObject* obj) {
-	setObjectColor (obj);
+void GLRenderer::compileList (LDObject* obj, const GLRenderer::ListType list) {
+	setObjectColor (obj, list);
 	
 	switch (obj->getType ()) {
 	case LDObject::Line:
@@ -683,8 +655,10 @@
 		break;
 	
 	case LDObject::CondLine:
-		glLineStipple (1, 0x6666);
-		glEnable (GL_LINE_STIPPLE);
+		if (list != GL::PickList) {
+			glLineStipple (1, 0x6666);
+			glEnable (GL_LINE_STIPPLE);
+		}
 		
 		compileSubObject (obj, GL_LINES);
 		
@@ -705,7 +679,7 @@
 			vector<LDObject*> objs = ref->inlineContents (true, true);
 			
 			for (LDObject* obj : objs) {
-				compileOneObject (obj);
+				compileList (obj, list);
 				delete obj;
 			}
 		}
@@ -717,7 +691,7 @@
 			std::vector<LDObject*> objs = pRadial->decompose (true);
 			
 			for (LDObject* obj : objs) {
-				compileOneObject (obj);
+				compileList (obj, list);
 				delete obj;
 			}
 		}
@@ -750,7 +724,7 @@
 				};
 				
 				pPoly->dColor = pVert->dColor;
-				compileOneObject (pPoly);
+				compileOneObject (pPoly, list);
 				delete pPoly;
 			}
 		}
@@ -791,6 +765,12 @@
 	
 	if (wasLeft) {
 		if (m_planeDraw) {
+			// If we have 4 verts, stop drawing.
+			if (m_planeDrawVerts.size () >= 4) {
+				endPlaneDraw (true);
+				return;
+			}
+			
 			// If we picked an already-existing vertex, stop drawing
 			for (vertex& vert : m_planeDrawVerts) {
 				if (vert == m_hoverpos) {
@@ -799,10 +779,6 @@
 				}
 			}
 			
-			// Also, if have 4 verts, also stop drawing.
-			if (m_planeDrawVerts.size () >= 4)
-				endPlaneDraw (true);
-			
 			m_planeDrawVerts.push_back (m_hoverpos);
 			
 			update ();
@@ -948,16 +924,14 @@
 	}
 	
 	GLint viewport[4];
-	LDObject* removedObject = null;
 	
 	// Clear the selection if we do not wish to add to it.
 	if (!m_addpick) {
 		std::vector<LDObject*> oldsel = g_win->sel ();
 		g_win->sel ().clear ();
 		
-		// Recompile the prior selection to remove the highlight color
 		for (LDObject* obj : oldsel)
-			recompileObject (obj);
+			compileObject (obj);
 	}
 	
 	m_picking = true;
@@ -1009,6 +983,8 @@
 	// Read pixels from the color buffer.
 	glReadPixels (x0, viewport[3] - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata);
 	
+	LDObject* removedObj = null;
+	
 	// Go through each pixel read and add them to the selection.
 	for (long i = 0; i < numpixels; ++i) {
 		uint32 idx =
@@ -1030,8 +1006,8 @@
 			for (ulong i = 0; i < g_win->sel ().size(); ++i) {
 				if (g_win->sel ()[i] == obj) {
 					g_win->sel ().erase (g_win->sel ().begin () + i);
-					removedObject = obj;
 					removed = true;
+					removedObj = obj;
 				}
 			}
 			
@@ -1052,7 +1028,11 @@
 	sel.resize (std::distance (sel.begin (), pos));
 	
 	// Update everything now.
-	g_win->buildObjList ();
+	g_win->updateSelection ();
+	
+	// Recompile the objects now to update their color
+	for (LDObject* obj : sel)
+		compileObject (obj);
 	
 	m_picking = false;
 	m_rangepick = false;
@@ -1061,12 +1041,6 @@
 	setBackground ();
 	updateSelFlash ();
 	
-	for (LDObject* obj : g_win->sel ())
-		recompileObject (obj);
-	
-	if (removedObject != null)
-		recompileObject (removedObject);
-	
 	drawGLScene ();
 	swapBuffers ();
 	update ();
@@ -1137,7 +1111,7 @@
 		
 		if (obj) {
 			g_curfile->addObject (obj);
-			recompileObject (obj);
+			compileObject (obj);
 			g_win->refresh ();
 			
 			History::addEntry (new AddHistory ({(ulong) obj->getIndex (g_curfile)}, {obj->clone ()}));
@@ -1158,15 +1132,16 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void GLRenderer::recompileObject (LDObject* obj) {
-	// Replace the old list with the new one.
-	GLuint uList = glGenLists (1);
-	glNewList (uList, GL_COMPILE);
-	
-	compileOneObject (obj);
-	
-	glEndList ();
-	obj->uGLList = uList;
+void GLRenderer::compileObject (LDObject* obj) {
+	for (const GL::ListType listType : g_glListTypes) {
+		GLuint list = glGenLists (1);
+		glNewList (list, GL_COMPILE);
+		
+		obj->glLists[listType] = list;
+		compileList (obj, listType);
+		
+		glEndList ();
+	}
 }
 
 // =============================================================================
@@ -1193,7 +1168,7 @@
 	++g_pulseTick %= g_numPulseTicks;
 	
 	for (LDObject* obj : g_win->sel ())
-		recompileObject (obj);
+		compileObject (obj);
 	
 	update ();
 }
--- a/src/gldraw.h	Wed May 08 15:30:19 2013 +0300
+++ b/src/gldraw.h	Thu May 09 02:28:39 2013 +0300
@@ -45,6 +45,8 @@
 		Free
 	};
 	
+	enum ListType { NormalList, PickList, SelectList };
+	
 	GLRenderer (QWidget* parent = null);
 	~GLRenderer ();
 	
@@ -53,7 +55,7 @@
 	void setBackground ();
 	void pick (uint mouseX, uint mouseY);
 	QColor getMainColor ();
-	void recompileObject (LDObject* obj);
+	void compileObject (LDObject* obj);
 	void refresh ();
 	void updateSelFlash ();
 	void resetAngles ();
@@ -96,11 +98,11 @@
 	ushort m_width, m_height;
 	std::vector<vertex> m_planeDrawVerts;
 	
-	void compileOneObject (LDObject* obj);
+	void compileList (LDObject* obj, const ListType list);
 	void compileSubObject (LDObject* obj, const GLenum gltype);
 	void compileVertex (const vertex& vrt);
 	void clampAngle (double& angle);
-	void setObjectColor (LDObject* obj);
+	void setObjectColor (LDObject* obj, const ListType list);
 	void drawGLScene () const;
 	void calcCameraIconRects ();
 	
@@ -112,4 +114,13 @@
 	void slot_toolTipTimer ();
 };
 
+// Alias for short namespaces
+typedef GLRenderer GL;
+
+static const GLRenderer::ListType g_glListTypes[] = {
+	GL::NormalList,
+	GL::PickList,
+	GL::SelectList
+};
+
 #endif // GLDRAW_H
\ No newline at end of file
--- a/src/gui.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/gui.cpp	Thu May 09 02:28:39 2013 +0300
@@ -196,6 +196,7 @@
 	addMenuAction ("invert");				// Invert
 	addMenuAction ("inlineContents");		// Inline
 	addMenuAction ("deepInline");			// Deep Inline
+	addMenuAction ("radialResolution");	// Radial Resolution
 	addMenuAction ("splitQuads");			// Split Quads
 	addMenuAction ("setContents");		// Set Contents
 	addMenuAction ("makeBorders");		// Make Borders
@@ -363,6 +364,7 @@
 	addToolBarAction ("invert");
 	addToolBarAction ("inlineContents");
 	addToolBarAction ("deepInline");
+	addToolBarAction ("radialResolution");
 	addToolBarAction ("splitQuads");
 	addToolBarAction ("setContents");
 	addToolBarAction ("makeBorders");
@@ -716,10 +718,10 @@
 	
 	// Update the GL renderer
 	for (LDObject* obj : m_sel)
-		m_renderer->recompileObject (obj);
+		m_renderer->compileObject (obj);
 	
 	for (LDObject* obj : priorSelection)
-		m_renderer->recompileObject (obj);
+		m_renderer->compileObject (obj);
 	
 	m_renderer->updateSelFlash ();
 	m_renderer->refresh ();
@@ -793,9 +795,14 @@
 void ForgeWindow::updateSelection () {
 	g_bSelectionLocked = true;
 	
+	for (LDObject* obj : g_curfile->m_objs)
+		obj->setSelected (false);
+	
 	m_objList->clearSelection ();
-	for (LDObject* obj : m_sel)
+	for (LDObject* obj : m_sel) {
 		obj->qObjListEntry->setSelected (true);
+		obj->setSelected (true);
+	}
 	
 	g_bSelectionLocked = false;
 	slot_selectionChanged ();
--- a/src/gui_editactions.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/gui_editactions.cpp	Thu May 09 02:28:39 2013 +0300
@@ -124,15 +124,15 @@
 	vector<LDObject*> sel = g_win->sel ();
 	
 	// History stuff
-	vector<LDSubfile*> paRefs;
-	vector<ulong> ulaRefIndices, ulaBitIndices;
+	vector<LDSubfile*> refs;
+	vector<ulong> refIndices, bitIndices;
 	
 	for (LDObject* obj : sel) {
 		if (obj->getType() != LDObject::Subfile)
 			continue;
 		
-		ulaRefIndices.push_back (obj->getIndex (g_curfile));
-		paRefs.push_back (static_cast<LDSubfile*> (obj)->clone ());
+		refIndices.push_back (obj->getIndex (g_curfile));
+		refs.push_back (static_cast<LDSubfile*> (obj)->clone ());
 	}
 	
 	for (LDObject* obj : sel) {
@@ -153,7 +153,7 @@
 		
 		// Merge in the inlined objects
 		for (LDObject* inlineobj : objs) {
-			ulaBitIndices.push_back (idx);
+			bitIndices.push_back (idx);
 			
 			// This object is now inlined so it has no parent anymore.
 			inlineobj->parent = null;
@@ -166,7 +166,7 @@
 		delete obj;
 	}
 	
-	History::addEntry (new InlineHistory (ulaBitIndices, ulaRefIndices, paRefs, bDeep));
+	History::addEntry (new InlineHistory (bitIndices, refIndices, refs, bDeep));
 	g_win->refresh ();
 }
 
@@ -180,9 +180,59 @@
 	doInline (true);
 }
 
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
+// =======================================================================================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =======================================================================================================================================
+MAKE_ACTION (radialResolution, "Radial resolution", "radial-resolve", "Resolve radials into primitives.", (0)) {
+	vector<str> fails;
+	vector<LDObject*> sel = g_win->sel ();
+	EditHistory* history = new EditHistory;
+	
+	for (LDObject* obj : sel) {
+		if (obj->getType() != LDObject::Radial)
+			continue;
+		
+		LDRadial* rad = static_cast<LDRadial*> (obj);
+		str name = rad->makeFileName ();
+		
+		OpenFile* file = loadSubfile (name);
+		if (file == null) {
+			fails.push_back (name);
+			continue;
+		}
+		
+		// Create the replacement primitive.
+		LDSubfile* prim = new LDSubfile;
+		memcpy (&prim->vPosition, &rad->vPosition, sizeof rad->vPosition); // inherit position
+		memcpy (&prim->mMatrix, &rad->mMatrix, sizeof rad->mMatrix); // inherit matrix
+		prim->dColor = rad->dColor; // inherit color
+		prim->zFileName = name;
+		prim->pFile = file;
+		
+		// Add the history entry - this must be done while both objects are still valid.
+		history->addEntry (rad, prim);
+		
+		// Replace the radial with the primitive.
+		rad->replace (prim);
+	}
+	
+	// If it was not possible to replace everything, inform the user.
+	if (fails.size() > 0) {
+		str errmsg = fmt ("Couldn't replace %lu radials as replacement subfiles could not be loaded:<br />", (ulong)fails.size ());
+		
+		for (str& fail : fails) 
+			errmsg += fmt ("* %s<br />", fail.chars ());
+		
+		critical (errmsg);
+	}
+	
+	History::addEntry (history);
+	g_win->refresh ();
+}
+
+// =======================================================================================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =======================================================================================================================================
 MAKE_ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.", (0)) {
 	vector<LDObject*> objs = g_win->sel ();
 	
--- a/src/history.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/history.cpp	Thu May 09 02:28:39 2013 +0300
@@ -164,6 +164,17 @@
 	g_win->refresh ();
 }
 
+void EditHistory::addEntry (LDObject* const oldObj, LDObject* const newObj) {
+	printf ("%s at %lu, replaced by a %s\n",
+		g_saObjTypeNames[oldObj->getType()],
+		oldObj->getIndex (g_curfile),
+		g_saObjTypeNames[newObj->getType()]);
+	
+	ulaIndices.push_back (oldObj->getIndex (g_curfile));
+	paOldObjs.push_back (oldObj->clone ());
+	paNewObjs.push_back (newObj->clone ());
+}
+
 EditHistory::~EditHistory () {
 	for (ulong idx : ulaIndices) {
 		delete paOldObjs[idx];
--- a/src/history.h	Wed May 08 15:30:19 2013 +0300
+++ b/src/history.h	Thu May 09 02:28:39 2013 +0300
@@ -94,12 +94,15 @@
 public:
 	IMPLEMENT_HISTORY_TYPE (Edit)
 	
-	const std::vector<ulong> ulaIndices;
-	const std::vector<LDObject*> paOldObjs, paNewObjs;
+	std::vector<ulong> ulaIndices;
+	std::vector<LDObject*> paOldObjs, paNewObjs;
 	
+	EditHistory () {}
 	EditHistory (std::vector<ulong> ulaIndices, std::vector<LDObject*> paOldObjs,
 		std::vector<LDObject*> paNewObjs) :
 		ulaIndices (ulaIndices), paOldObjs (paOldObjs), paNewObjs (paNewObjs) {}
+	
+	void addEntry (LDObject* const oldObj, LDObject* const newObj);
 };
 
 // =============================================================================
--- a/src/historyDialog.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/historyDialog.cpp	Thu May 09 02:28:39 2013 +0300
@@ -16,11 +16,11 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <qboxlayout.h>
+#include <qmessagebox.h>
 #include "historyDialog.h"
 #include "history.h"
 #include "colors.h"
-#include <qboxlayout.h>
-#include <qmessagebox.h>
 
 EXTERN_ACTION (undo);
 EXTERN_ACTION (redo);
@@ -61,7 +61,7 @@
 	
 	setLayout (qLayout);
 	setWindowIcon (getIcon ("history"));
-	setWindowTitle (APPNAME " - Edit history");
+	setWindowTitle ("Edit History");
 	
 	populateList ();
 	updateButtons ();
--- a/src/historyDialog.h	Wed May 08 15:30:19 2013 +0300
+++ b/src/historyDialog.h	Thu May 09 02:28:39 2013 +0300
@@ -31,12 +31,12 @@
 public:
 	explicit HistoryDialog (QWidget* parent = null, Qt::WindowFlags f = 0);
 	void populateList ();
-	
+
+private:
 	QListWidget* historyList;
 	QPushButton* undoButton, *redoButton, *clearButton;
 	QDialogButtonBox* buttons;
 	
-private:
 	void updateButtons ();
 	void updateSelection ();
 	
--- a/src/ldrawPathDialog.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/ldrawPathDialog.cpp	Thu May 09 02:28:39 2013 +0300
@@ -30,7 +30,7 @@
 LDrawPathDialog::LDrawPathDialog (const bool validDefault, QWidget* parent, Qt::WindowFlags f)
 	: QDialog (parent, f), m_validDefault (validDefault)
 {
-	QLabel* lb_description;
+	QLabel* lb_description = null;
 	lb_resolution = new QLabel ("---");
 	
 	if (validDefault == false)
--- a/src/ldtypes.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/ldtypes.cpp	Thu May 09 02:28:39 2013 +0300
@@ -61,6 +61,7 @@
 	qObjListEntry = null;
 	parent = null;
 	m_hidden = false;
+	m_selected = false;
 }
 
 LDGibberish::LDGibberish (str _zContent, str _zReason) {
@@ -616,7 +617,7 @@
 	"disc",
 	"ndis",
 	"ring",
-	"cone",
+	"con",
 	null
 };
 
@@ -649,7 +650,7 @@
 	root -= min<short> (max<short> (extra, 0), 2);
 	
 	// Stick them all together and return the result.
-	return fmt ("%s%s%s%s", prefix.chars(), frac.chars (), root.chars (), ringNum.chars ());
+	return fmt ("%s%s%s%s.dat", prefix.chars(), frac.chars (), root.chars (), ringNum.chars ());
 }
 
 // =============================================================================
--- a/src/ldtypes.h	Wed May 08 15:30:19 2013 +0300
+++ b/src/ldtypes.h	Thu May 09 02:28:39 2013 +0300
@@ -84,7 +84,7 @@
 	short dColor;
 	
 	// OpenGL list for this object
-	uint uGLList, uGLPickList;
+	uint glLists[3];
 	
 	// Vertices of this object
 	vertex vaCoords[4];
@@ -140,9 +140,12 @@
 	
 	bool hidden () const { return m_hidden; }
 	void setHidden (const bool hidden) { m_hidden = hidden; }
+	bool selected () const { return m_selected; }
+	void setSelected (bool selected) { m_selected = selected; }
 
 private:
 	bool m_hidden;
+	bool m_selected;
 };
 
 // =============================================================================
--- a/src/misc.cpp	Wed May 08 15:30:19 2013 +0300
+++ b/src/misc.cpp	Thu May 09 02:28:39 2013 +0300
@@ -24,7 +24,7 @@
 #include "gui.h"
 
 // Prime number table.
-const ushort g_uaPrimes[NUM_PRIMES] = {
+const ushort g_primes[NUM_PRIMES] = {
 	   2,    3,    5,    7,   11,   13,   17,   19,   23,   29, 
 	  31,   37,   41,   43,   47,   53,   59,   61,   67,   71, 
 	  73,   79,   83,   89,   97,  101,  103,  107,  109,  113, 
@@ -106,11 +106,11 @@
 };
 
 // =============================================================================
+// Snap the given coordinate value on the current grid's given axis.
 double Grid::snap (double in, const Grid::Config axis) {
 	const double gridval = currentGrid ().confs[axis]->value;
 	const long mult = abs (in / gridval);
 	const bool neg = (in < 0);
-	
 	double out = mult * gridval;
 	
 	if (abs<double> (in) - (mult * gridval) > gridval / 2)
@@ -125,6 +125,7 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+// Float to string. Removes trailing zeroes and is locale-independant.
 str ftoa (double fCoord) {
 	// Disable the locale first so that the decimal point will not
 	// turn into anything weird (like commas)
@@ -187,7 +188,7 @@
 		
 		for (ulong x = 0; x < NUM_PRIMES; x++) {
 			ulong i = NUM_PRIMES - x - 1;
-			ushort uPrime = g_uaPrimes[i];
+			ushort uPrime = g_primes[i];
 			
 			if (dNum <= uPrime || dDenom <= uPrime)
 				continue;
@@ -205,45 +206,45 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-StringParser::StringParser (str zInText, char cSeparator) {
-	zaTokens = zInText.split (cSeparator, true);
-	dPos = -1;
+StringParser::StringParser (str inText, char sep) {
+	m_tokens = inText.split (sep, true);
+	m_pos = -1;
 }
 
 // -----------------------------------------------------------------------------
 bool StringParser::atBeginning () {
-	return (dPos == -1);
+	return (m_pos == -1);
 }
 
 // -----------------------------------------------------------------------------
 bool StringParser::atEnd () {
-	return (dPos == (signed) zaTokens.size () - 1);
+	return (m_pos == (signed) m_tokens.size () - 1);
 }
 
 // -----------------------------------------------------------------------------
-bool StringParser::getToken (str& zVal, const ushort uInPos) {
-	if (uInPos >= zaTokens.size())
+bool StringParser::getToken (str& val, const ushort pos) {
+	if (pos >= m_tokens.size())
 		return false;
 	
-	zVal = zaTokens[uInPos];
+	val = m_tokens[pos];
 	return true;
 }
 
 // -----------------------------------------------------------------------------
-bool StringParser::next (str& zVal) {
-	return getToken (zVal, ++dPos);
+bool StringParser::next (str& val) {
+	return getToken (val, ++m_pos);
 }
 
 // -----------------------------------------------------------------------------
-bool StringParser::peekNext (str& zVal) {
-	return getToken (zVal, dPos + 1);
+bool StringParser::peekNext (str& val) {
+	return getToken (val, m_pos + 1);
 }
 
 // -----------------------------------------------------------------------------
-bool StringParser::findToken (short& dResult, char const* sNeedle, short dArgs) {
-	for (ushort i = 0; i < (zaTokens.size () - dArgs); ++i) {
-		if (zaTokens[i] == sNeedle) {
-			dResult = i;
+bool StringParser::findToken (short& result, char const* needle, short args) {
+	for (ushort i = 0; i < (m_tokens.size () - args); ++i) {
+		if (m_tokens[i] == needle) {
+			result = i;
 			return true;
 		}
 	}
@@ -253,24 +254,23 @@
 
 // -----------------------------------------------------------------------------
 void StringParser::rewind () {
-	dPos = -1;
+	m_pos = -1;
 }
 
 // -----------------------------------------------------------------------------
-void StringParser::seek (short int dAmount, bool bRelative) {
-	dPos = (bRelative ? dPos : 0) + dAmount;
+void StringParser::seek (short amount, bool rel) {
+	m_pos = (rel ? m_pos : 0) + amount;
 }
 
 // -----------------------------------------------------------------------------
 size_t StringParser::size () {
-	return zaTokens.size();
+	return m_tokens.size();
 }
 
 // -----------------------------------------------------------------------------
-bool StringParser
-::tokenCompare (short int dInPos, const char* sOther) {
+bool StringParser::tokenCompare (short inPos, const char* sOther) {
 	str tok;
-	if (!getToken (tok, dInPos))
+	if (!getToken (tok, inPos))
 		return false;
 	
 	return (tok == sOther);
--- a/src/misc.h	Wed May 08 15:30:19 2013 +0300
+++ b/src/misc.h	Thu May 09 02:28:39 2013 +0300
@@ -29,7 +29,7 @@
 class QAction;
 
 // Prime numbers
-extern const ushort g_uaPrimes[NUM_PRIMES];
+extern const ushort g_primes[NUM_PRIMES];
 
 // Returns whether a given string represents a floating point number.
 bool isNumber (str& zToken);
@@ -86,25 +86,26 @@
 // =============================================================================
 class StringParser {
 public:
-	std::vector<str> zaTokens;
-	short dPos;
-	
-	StringParser (str zInText, char cSeparator);
+	StringParser (str inText, char sep);
 	
 	bool atEnd ();
 	bool atBeginning ();
-	bool next (str& zVal);
-	bool peekNext (str& zVal);
-	bool getToken (str& zVal, const ushort uInPos);
-	bool findToken (short& dResult, char const* sNeedle, short dArgs);
+	bool next (str& val);
+	bool peekNext (str& val);
+	bool getToken (str& val, const ushort pos);
+	bool findToken (short& result, char const* needle, short args);
 	size_t size ();
 	void rewind ();
-	void seek (short dAmount, bool bRelative);
-	bool tokenCompare (short int dInPos, const char* sOther);
+	void seek (short amount, bool rel);
+	bool tokenCompare (short inPos, const char* sOther);
 	
 	str operator[] (const size_t uIndex) {
-		return zaTokens[uIndex];
+		return m_tokens[uIndex];
 	}
+	
+private:
+	std::vector<str> m_tokens;
+	short m_pos;
 };
 
 #endif // MISC_H
\ No newline at end of file

mercurial