Sun, 18 Aug 2013 17:30:58 +0300
Rewrote stud logo support, restructuring inlining stuff in the process. Logoed studs must only be used for rendering scenes, otherwise they will for instance get inlined in and that's not desired, or the vertex snapper will catch onto the logo's coordinates.
src/configDialog.cpp | file | annotate | diff | comparison | revisions | |
src/extprogs.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/types.cpp | file | annotate | diff | comparison | revisions |
--- a/src/configDialog.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/configDialog.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -50,7 +50,7 @@ extern_cfg (str, net_downloadpath); extern_cfg (bool, net_guesspaths); extern_cfg (bool, net_autoclose); -extern_cfg (bool, io_logostuds); +extern_cfg (bool, gl_logostuds); extern_cfg (str, prog_ytruder); extern_cfg (str, prog_rectifier); @@ -121,7 +121,7 @@ ui->blackEdges->setChecked (gl_blackedges); // ui->scemanticInlining->setChecked (edit_schemanticinline); ui->implicitFiles->setChecked (gui_implicitfiles); - ui->m_logostuds->setChecked (io_logostuds); + ui->m_logostuds->setChecked (gl_logostuds); } // ============================================================================= @@ -591,7 +591,7 @@ net_downloadpath = dlg.getUI()->downloadPath->text(); net_guesspaths = dlg.getUI()->guessNetPaths->isChecked(); net_autoclose = dlg.getUI()->autoCloseNetPrompt->isChecked(); - io_logostuds = dlg.getUI()->m_logostuds->isChecked(); + gl_logostuds = dlg.getUI()->m_logostuds->isChecked(); if (net_downloadpath.value.right (1) != DIRSLASH) net_downloadpath += DIRSLASH; @@ -620,6 +620,7 @@ config::save(); reloadAllSubfiles(); + loadLogoedStuds(); g_win->R()->setBackground(); g_win->fullRefresh(); g_win->updateToolBars();
--- a/src/extprogs.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/extprogs.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -151,7 +151,8 @@ void writeObjects (List<LDObject*>& objects, File& f) { for (LDObject* obj : objects) { if (obj->getType() == LDObject::Subfile) { - List<LDObject*> objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, false); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); + List<LDObject*> objs = ref->inlineContents (LDSubfileObject::DeepInline); writeObjects (objs, f);
--- a/src/file.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/file.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -34,12 +34,14 @@ cfg (str, io_ldpath, ""); cfg (str, io_recentfiles, ""); -cfg (bool, io_logostuds, false); extern_cfg (str, net_downloadpath); +extern_cfg (bool, gl_logostuds); static bool g_loadingMainFile = false; static const int g_MaxRecentFiles = 5; static bool g_aborted = false; +static LDFile* g_logoedStud = null; +static LDFile* g_logoedStud2 = null; LDFile* LDFile::m_curfile = null; @@ -177,26 +179,6 @@ // ============================================================================= // ----------------------------------------------------------------------------- File* openLDrawFile (str relpath, bool subdirs) { - { - File* logofile; - - // Special exception for logoed studs: - // stud.dat -> stud-logo.dat - // stud2.dat -> stud2-logo.dat - // NOTE: This is probably going to change in the very near future! - if ( - relpath == "stud.dat" && - (logofile = openLDrawFile ("stud-logo.dat", subdirs)) != null - ) - return logofile; - - if ( - relpath == "stud2.dat" && - (logofile = openLDrawFile ("stud2-logo.dat", subdirs)) != null - ) - return logofile; - } - print ("%1: Try to open %2\n", __func__, relpath); File* f = new File; str fullPath; @@ -993,6 +975,69 @@ // ============================================================================= // ----------------------------------------------------------------------------- +List<LDObject*> LDFile::inlineContents (int flags) { + // Possibly substitute with logoed studs: + // stud.dat -> stud-logo.dat + // stud2.dat -> stud-logo2.dat + if (gl_logostuds && (flags & LDSubfileObject::RendererInline)) { + if (name() == "stud.dat" && g_logoedStud) + return g_logoedStud->inlineContents (flags); + elif (name() == "stud2.dat" && g_logoedStud2) + return g_logoedStud2->inlineContents (flags); + } + + List<LDObject*> objs, objcache; + + bool deep = flags & LDSubfileObject::DeepInline, + doCache = flags & LDSubfileObject::CacheInline; + + // If we have this cached, just clone that + if (deep && cache().size()) { + for (LDObject* obj : cache()) + objs << obj->clone(); + } else { + if (!deep) + doCache = false; + + for (LDObject* obj : m_objs) { + // Skip those without scemantic meaning + if (!obj->isScemantic()) + continue; + + // Got another sub-file reference, inline it if we're deep-inlining. If not, + // just add it into the objects normally. Also, we only cache immediate + // subfiles and this is not one. Yay, recursion! + if (deep && obj->getType() == LDObject::Subfile) { + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); + + // We only want to cache immediate subfiles, so shed the caching + // flag when recursing deeper in hierarchy. + List<LDObject*> otherobjs = ref->inlineContents (flags & ~(LDSubfileObject::CacheInline)); + + for (LDObject* otherobj : otherobjs) { + // Cache this object, if desired + if (doCache) + objcache << otherobj->clone(); + + objs << otherobj; + } + } else { + if (doCache) + objcache << obj->clone(); + + objs << obj->clone(); + } + } + + if (doCache) + setCache (objcache); + } + + return objs; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- LDFile* LDFile::current() { return m_curfile; } @@ -1048,4 +1093,16 @@ !g_loadedFiles[0]->hasUnsavedChanges() ) delete g_loadedFiles[0]; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void loadLogoedStuds() { + print ("Loading logoed studs...\n"); + + delete g_logoedStud; + delete g_logoedStud2; + + g_logoedStud = openDATFile ("stud-logo.dat", true); + g_logoedStud2 = openDATFile ("stud2-logo.dat", true); } \ No newline at end of file
--- a/src/file.h Sun Aug 18 16:33:38 2013 +0300 +++ b/src/file.h Sun Aug 18 17:30:58 2013 +0300 @@ -130,6 +130,7 @@ static void closeInitialFile(); static int countExplicitFiles(); str getShortName(); + List<LDObject*> inlineContents (int flags); private: static LDFile* m_curfile; @@ -171,6 +172,7 @@ extern List<LDFile*> g_loadedFiles; void addRecentFile (str path); +void loadLogoedStuds(); str basename (str path); str dirname (str path);
--- a/src/gldraw.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/gldraw.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -60,6 +60,7 @@ cfg (bool, gl_blackedges, true); cfg (bool, gl_axes, false); cfg (bool, gl_wireframe, false); +cfg (bool, gl_logostuds, false); // argh const char* g_CameraNames[7] = { @@ -752,8 +753,12 @@ case LDObject::Subfile: { LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); - List<LDObject*> objs = ref->inlineContents (true, true); + List<LDObject*> objs; + objs = ref->inlineContents ( + LDSubfileObject::DeepInline | + LDSubfileObject::CacheInline | + LDSubfileObject::RendererInline); bool oldinvert = g_glInvert; if (ref->transform().determinant() < 0) @@ -1277,7 +1282,8 @@ for (int i = 0; i < obj->vertices(); ++i) verts << obj->getVertex (i); } elif (obj->getType() == LDObject::Subfile) { - List<LDObject*> objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, true); + LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); + List<LDObject*> objs = ref->inlineContents (LDSubfileObject::DeepCacheInline); for(LDObject* obj : objs) { verts << getVertices (obj);
--- a/src/gui_editactions.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/gui_editactions.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -120,7 +120,11 @@ List<LDObject*> objs; if (obj->getType() == LDObject::Subfile) - objs = static_cast<LDSubfileObject*> (obj)->inlineContents (deep, true); + objs = static_cast<LDSubfileObject*> (obj)->inlineContents ( + (LDSubfileObject::InlineFlags) + ((deep) ? LDSubfileObject::DeepInline : 0) | + LDSubfileObject::CacheInline + ); else continue;
--- a/src/ldtypes.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/ldtypes.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -298,48 +298,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- -List<LDObject*> LDSubfileObject::inlineContents (bool deep, bool cache) { - List<LDObject*> objs, objcache; - - // If we have this cached, just clone that - if (deep && fileInfo()->cache().size()) { - for (LDObject* obj : fileInfo()->cache()) - objs << obj->clone(); - } else { - if (!deep) - cache = false; - - for (LDObject* obj : *fileInfo()) { - // Skip those without scemantic meaning - if (!obj->isScemantic()) - continue; - - // Got another sub-file reference, inline it if we're deep-inlining. If not, - // just add it into the objects normally. Also, we only cache immediate - // subfiles and this is not one. Yay, recursion! - if (deep && obj->getType() == LDObject::Subfile) { - LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); - - List<LDObject*> otherobjs = ref->inlineContents (true, false); - - for (LDObject* otherobj : otherobjs) { - // Cache this object, if desired - if (cache) - objcache << otherobj->clone(); - - objs << otherobj; - } - } else { - if (cache) - objcache << obj->clone(); - - objs << obj->clone(); - } - } - - if (cache) - fileInfo()->setCache (objcache); - } +List<LDObject*> LDSubfileObject::inlineContents (int flags) { + List<LDObject*> objs = fileInfo()->inlineContents (flags); // Transform the objects for (LDObject* obj : objs) {
--- a/src/ldtypes.h Sun Aug 18 16:33:38 2013 +0300 +++ b/src/ldtypes.h Sun Aug 18 17:30:58 2013 +0300 @@ -284,10 +284,18 @@ LDSubfileObject() { setLinkPointer (this); } - + + enum InlineFlags { + DeepInline = (1 << 0), + CacheInline = (1 << 1), + RendererInline = (1 << 2), + + DeepCacheInline = DeepInline | CacheInline, + }; + // Inlines this subfile. Note that return type is an array of heap-allocated // LDObject-clones, they must be deleted one way or another. - List<LDObject*> inlineContents (bool deep, bool cache); + List<LDObject*> inlineContents (int flags); }; // =============================================================================
--- a/src/main.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/main.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -28,6 +28,7 @@ #include "colors.h" #include "types.h" #include "primitives.h" +#include "gldraw.h" List<LDFile*> g_loadedFiles; ForgeWindow* g_win = null; @@ -60,6 +61,7 @@ LDPaths::initPaths(); initColors(); + loadLogoedStuds(); ForgeWindow* win = new ForgeWindow;
--- a/src/types.cpp Sun Aug 18 16:33:38 2013 +0300 +++ b/src/types.cpp Sun Aug 18 17:30:58 2013 +0300 @@ -523,7 +523,7 @@ case LDObject::Subfile: { LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); - List<LDObject*> objs = ref->inlineContents (true, true); + List<LDObject*> objs = ref->inlineContents (LDSubfileObject::DeepCacheInline); for (LDObject* obj : objs) { calcObject (obj);