# HG changeset patch # User Santeri Piippo # Date 1363449013 -7200 # Node ID 335e430a6b4f188928dad2512729a2388b28b33c # Parent 9aebaaafa5daeb7feef7821a199524f9a7d20152 So much for that pointer class, caused more problems than it solved. For instance splitting a second quad after a first one had been split would trigger a peculiar crash... diff -r 9aebaaafa5da -r 335e430a6b4f common.h --- a/common.h Sat Mar 16 16:59:16 2013 +0200 +++ b/common.h Sat Mar 16 17:50:13 2013 +0200 @@ -131,6 +131,4 @@ typedef uint32_t xulong; typedef uint64_t xulonglong; -#include "pointer.h" - #endif \ No newline at end of file diff -r 9aebaaafa5da -r 335e430a6b4f gui.cpp --- a/gui.cpp Sat Mar 16 16:59:16 2013 +0200 +++ b/gui.cpp Sat Mar 16 17:50:13 2013 +0200 @@ -35,6 +35,8 @@ createMenus (); createToolbars (); + slot_selectionChanged (); + setTitle (); setMinimumSize (320, 200); resize (800, 600); @@ -229,7 +231,6 @@ line->dColor = 24; g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulSpot, line); - g_CurrentFile->objects[ulSpot].serialize (); buildObjList (); R->hardRefresh (); @@ -305,10 +306,14 @@ continue; // Was not selected static_cast (obj)->splitToTriangles (); + i++;// Skip past the second triangle } + printf ("build obj list\n"); + buildObjList (); + + printf ("refresh teh renderer\n"); R->hardRefresh (); - buildObjList (); } void LDForgeWindow::slot_setContents () { @@ -377,8 +382,9 @@ qObjList->clear (); - for (ushort i = 0; i < g_CurrentFile->objects.size(); ++i) { + for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) { LDObject* obj = g_CurrentFile->objects[i]; + printf ("%lu: %p\n", i, obj); str zText; switch (obj->getType ()) { @@ -463,6 +469,9 @@ void LDForgeWindow::slot_selectionChanged () { // If the selection isn't 1 exact, disable setting contents qAct_setContents->setEnabled (qObjList->selectedItems().size() == 1); + + // If we have no selection, disable splitting quads + qAct_splitQuads->setEnabled (qObjList->selectedItems().size() > 0); } // ============================================================================= diff -r 9aebaaafa5da -r 335e430a6b4f io.cpp --- a/io.cpp Sat Mar 16 16:59:16 2013 +0200 +++ b/io.cpp Sat Mar 16 17:50:13 2013 +0200 @@ -72,10 +72,6 @@ } } - // Serialize all of the objects - for (ulong i = 0; i < load->objects.size(); ++i) - load->objects[i].serialize (); - g_LoadedFiles.push_back (load); g_CurrentFile = g_LoadedFiles[g_LoadedFiles.size() - 1]; diff -r 9aebaaafa5da -r 335e430a6b4f io.h --- a/io.h Sat Mar 16 16:59:16 2013 +0200 +++ b/io.h Sat Mar 16 17:50:13 2013 +0200 @@ -8,7 +8,7 @@ class OpenFile { public: str zFileName, zTitle; - vector objects; + vector objects; }; // PROTOTYPES diff -r 9aebaaafa5da -r 335e430a6b4f ldforge.pro --- a/ldforge.pro Sat Mar 16 16:59:16 2013 +0200 +++ b/ldforge.pro Sat Mar 16 17:50:13 2013 +0200 @@ -20,7 +20,6 @@ str.h \ config.h \ cfgdef.h \ - pointer.h \ zz_setContentsDialog.h SOURCES += bbox.cpp \ @@ -34,7 +33,6 @@ scanner.cpp \ str.cpp \ config.cpp \ - pointer.cpp \ zz_setContentsDialog.cpp QMAKE_CXXFLAGS += -std=c++0x diff -r 9aebaaafa5da -r 335e430a6b4f ldtypes.cpp --- a/ldtypes.cpp Sat Mar 16 16:59:16 2013 +0200 +++ b/ldtypes.cpp Sat Mar 16 17:50:13 2013 +0200 @@ -2,7 +2,6 @@ #include "ldtypes.h" #include "io.h" #include "misc.h" -#include "pointer.h" const char* g_saObjTypeNames[] = { "unidentified", @@ -164,7 +163,7 @@ // Find the index of this quad ulong ulIndex; for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) - if (g_CurrentFile->objects[ulIndex].ptr == this) + if (g_CurrentFile->objects[ulIndex] == this) break; if (ulIndex >= g_CurrentFile->objects.size()) { @@ -190,18 +189,16 @@ tri2->vaCoords[1] = vaCoords[2]; tri2->vaCoords[2] = vaCoords[3]; + printf ("triangles: %p %p\n", tri1, tri2); + // The triangles also inherit the quad's color tri1->dColor = tri2->dColor = dColor; - // Replace the quad with the first triangle - objPointer::replacePointers (this, tri1); + // Replace the quad with the first triangle and add the second triangle + // after the first one. + g_CurrentFile->objects[ulIndex] = tri1; + g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulIndex + 1, tri2); - // Add the second triangle after the first one. - objPointer ptr (tri2); - ptr.serialize (); - g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulIndex, ptr); - - // Delete this quad now, it has been split. `delete this` isn't exactly - // safe in my experience so we'll tell objPointer to delete the quad. - objPointer::deleteObj (this); + // Delete this quad now, it has been split. + delete this; } \ No newline at end of file diff -r 9aebaaafa5da -r 335e430a6b4f model.cpp --- a/model.cpp Sat Mar 16 16:59:16 2013 +0200 +++ b/model.cpp Sat Mar 16 17:50:13 2013 +0200 @@ -11,10 +11,8 @@ for (ushort i = 0; i < g_LoadedFiles.size(); i++) { OpenFile* f = g_LoadedFiles[i]; - for (ushort j = 0; j < f->objects.size(); ++j) { - f->objects[i].unSerialize (); + for (ushort j = 0; j < f->objects.size(); ++j) delete (LDObject*)f->objects[j]; - } delete f; } diff -r 9aebaaafa5da -r 335e430a6b4f pointer.cpp --- a/pointer.cpp Sat Mar 16 16:59:16 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#include "pointer.h" - -vector g_pObjectPointers; - -void objPointer::replacePointers (LDObject* old, LDObject* repl) { - for (ulong i = 0; i < g_pObjectPointers.size(); ++i) { - objPointer* ptrptr = g_pObjectPointers[i]; - - if ((*ptrptr).ptr == old) - (*ptrptr).ptr = repl; - } -} - -objPointer::~objPointer () { - -} - -objPointer::objPointer () { - ptr = nullptr; -} - -objPointer::objPointer (LDObject* _ptr) { - ptr = _ptr; -} - -void objPointer::serialize () { - g_pObjectPointers.push_back (this); -} - -void objPointer::unSerialize () { - for (ulong i = 0; i < g_pObjectPointers.size(); ++i) - if (g_pObjectPointers[i] == this) - g_pObjectPointers.erase (g_pObjectPointers.begin() + i); -} - -void objPointer::deleteObj (LDObject* obj) { - replacePointers (obj, nullptr); - delete obj; -} \ No newline at end of file diff -r 9aebaaafa5da -r 335e430a6b4f pointer.h --- a/pointer.h Sat Mar 16 16:59:16 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -#ifndef __POINTER_H__ -#define __POINTER_H__ - -#include "ldtypes.h" -#include -using std::vector; - -class objPointer; -extern vector g_pObjectPointers; - -#define POINTER_LDCAST(T) \ - operator T* () { \ - return static_cast (ptr); \ - } - -class objPointer { -public: - LDObject* ptr; - - objPointer (); - objPointer (LDObject*); - ~objPointer (); - - void serialize (); - void unSerialize (); - static void replacePointers (LDObject* old, LDObject* repl); - static void deleteObj (LDObject*); - - LDObject& operator* () { - return *ptr; - } - - LDObject* operator-> () { - return ptr; - } - - operator LDObject* () { - return ptr; - } - - POINTER_LDCAST (LDComment) - POINTER_LDCAST (LDCondLine) - POINTER_LDCAST (LDQuad) - POINTER_LDCAST (LDTriangle) - POINTER_LDCAST (LDSubfile) - POINTER_LDCAST (LDGibberish) - POINTER_LDCAST (LDVector) - POINTER_LDCAST (LDVertex) - POINTER_LDCAST (LDLine) - - LDObject* operator= (LDObject* repl) { - ptr = repl; - return ptr; - } -}; - -#endif // __POINTER_H__ -class LDLine; diff -r 9aebaaafa5da -r 335e430a6b4f zz_setContentsDialog.cpp --- a/zz_setContentsDialog.cpp Sat Mar 16 16:59:16 2013 +0200 +++ b/zz_setContentsDialog.cpp Sat Mar 16 17:50:13 2013 +0200 @@ -70,7 +70,10 @@ delete oldobj; // Replace all instances of the old object with the new object - objPointer::replacePointers (oldobj, obj); + for (ulong i = 0; i < g_CurrentFile->objects.size(); ++i) { + if (g_CurrentFile->objects[i] == oldobj) + g_CurrentFile->objects[i] = obj; + } // Rebuild stuff after this parent->buildObjList ();