From 6ee91d153ea09f2dafa62ed2f022f4183c090168 Mon Sep 17 00:00:00 2001 From: spog Date: Sun, 9 Apr 2006 17:15:13 +0000 Subject: [PATCH] refactored plugin api; refactored callback library; added signals library git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@44 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- CHANGES | 8 + GtkRadiant.sln | 8 + contrib/bobtoolz/CPortals.h | 4 +- contrib/bobtoolz/DBobView.cpp | 333 +++++------ contrib/bobtoolz/DBobView.h | 60 +- contrib/bobtoolz/DBrush.cpp | 277 +++++----- contrib/bobtoolz/DBrush.h | 28 +- contrib/bobtoolz/DEPair.cpp | 2 - contrib/bobtoolz/DEPair.h | 2 + contrib/bobtoolz/DEntity.cpp | 239 ++++---- contrib/bobtoolz/DEntity.h | 30 +- contrib/bobtoolz/DListener.cpp | 1 - contrib/bobtoolz/DMap.cpp | 36 +- contrib/bobtoolz/DMap.h | 8 +- contrib/bobtoolz/DPatch.cpp | 57 +- contrib/bobtoolz/DPatch.h | 17 +- contrib/bobtoolz/DPlane.cpp | 76 +-- contrib/bobtoolz/DPlane.h | 15 +- contrib/bobtoolz/DPoint.cpp | 6 +- contrib/bobtoolz/DPoint.h | 2 + contrib/bobtoolz/DShape.cpp | 46 +- contrib/bobtoolz/DShape.h | 8 +- contrib/bobtoolz/DTrainDrawer.cpp | 169 +++--- contrib/bobtoolz/DTrainDrawer.h | 38 +- contrib/bobtoolz/DTreePlanter.cpp | 62 +-- contrib/bobtoolz/DTreePlanter.h | 67 +-- contrib/bobtoolz/DVisDrawer.cpp | 139 ++--- contrib/bobtoolz/DVisDrawer.h | 32 +- contrib/bobtoolz/DWinding.cpp | 43 +- contrib/bobtoolz/DWinding.h | 2 + contrib/bobtoolz/ScriptParser.cpp | 1 - contrib/bobtoolz/StdAfx.h | 116 ---- contrib/bobtoolz/bobToolz-GTK.cpp | 46 +- contrib/bobtoolz/bobToolz.def | 2 +- contrib/bobtoolz/bsploader.cpp | 15 +- contrib/bobtoolz/bsploader.h | 3 + contrib/bobtoolz/cportals.cpp | 49 +- contrib/bobtoolz/dialogs/dialogs-gtk.cpp | 5 +- contrib/bobtoolz/dialogs/dialogs-gtk.h | 9 + contrib/bobtoolz/funchandlers-GTK.cpp | 73 +-- contrib/bobtoolz/funchandlers.cpp | 4 +- contrib/bobtoolz/lists.cpp | 10 +- contrib/bobtoolz/lists.h | 6 +- contrib/bobtoolz/misc.cpp | 79 +-- contrib/bobtoolz/misc.h | 20 +- contrib/bobtoolz/shapes.cpp | 58 +- contrib/bobtoolz/shapes.h | 2 +- contrib/bobtoolz/visfind.cpp | 16 +- contrib/bobtoolz/visfind.h | 8 +- contrib/gtkgensurf/genmap.cpp | 4 +- contrib/prtview/portals.cpp | 2 +- include/ibrush.h | 71 +++ include/icamera.h | 3 +- include/ientity.h | 21 + include/ifilesystem.h | 3 +- include/irender.h | 4 +- include/iscenegraph.h | 13 +- include/iselection.h | 10 +- include/ishaders.h | 4 +- include/iundo.h | 3 +- include/mapfile.h | 3 +- include/modelskin.h | 3 +- include/nameable.h | 3 +- include/namespace.h | 3 +- include/preferencesystem.h | 3 +- include/qerplugin.h | 27 + include/selectable.h | 3 +- libs/container/hashtable.h | 4 +- libs/debugging/debugging.h | 9 +- libs/entitylib.h | 16 +- libs/generic/callback.cpp | 176 ++++++ libs/generic/callback.h | 669 ++++++++++++++--------- libs/generic/callbackfwd.cpp | 3 + libs/generic/callbackfwd.h | 18 + libs/generic/functional.cpp | 3 + libs/generic/functional.h | 319 +++++++++++ libs/gtkutil/button.h | 3 +- libs/gtkutil/menu.h | 3 +- libs/gtkutil/toolbar.h | 3 +- libs/libs.vcproj | 34 ++ libs/math/vector.h | 9 + libs/signal/isignal.cpp | 3 + libs/signal/isignal.h | 224 ++++++++ libs/signal/signal.cpp | 105 ++++ libs/signal/signal.h | 377 +++++++++++++ libs/signal/signalfwd.cpp | 3 + libs/signal/signalfwd.h | 48 ++ libs/xml/xmlelement.h | 16 +- plugins/entity/curve.h | 27 +- plugins/entity/doom3group.cpp | 10 +- plugins/entity/keyobservers.h | 6 +- plugins/entity/namekeys.h | 18 +- plugins/entity/targetable.h | 12 +- radiant/brush.cpp | 9 +- radiant/brush.h | 228 +++++++- radiant/brushmanip.cpp | 369 ++++--------- radiant/brushmanip.h | 6 +- radiant/brushmodule.cpp | 23 + radiant/camwindow.cpp | 11 +- radiant/camwindow.h | 4 +- radiant/csg.cpp | 130 ++++- radiant/dialog.cpp | 6 +- radiant/dialog.h | 12 +- radiant/eclass_xml.cpp | 2 +- radiant/grid.cpp | 11 +- radiant/grid.h | 5 +- radiant/mainframe.cpp | 12 +- radiant/mainframe.h | 5 +- radiant/map.cpp | 63 ++- radiant/map.h | 3 +- radiant/patch.cpp | 9 +- radiant/patch.h | 3 +- radiant/patchdialog.cpp | 1 + radiant/plugin.cpp | 34 +- radiant/preferences.h | 6 +- radiant/scenegraph.cpp | 25 +- radiant/select.cpp | 7 +- radiant/selection.cpp | 18 +- radiant/selection.h | 4 +- radiant/surfacedialog.cpp | 2 +- radiant/textureentry.h | 5 +- radiant/textures.h | 3 +- radiant/texwindow.cpp | 22 +- radiant/texwindow.h | 9 +- radiant/undo.cpp | 2 +- radiant/xywindow.cpp | 44 +- radiant/xywindow.h | 38 +- 127 files changed, 3700 insertions(+), 2069 deletions(-) create mode 100644 libs/generic/callbackfwd.cpp create mode 100644 libs/generic/callbackfwd.h create mode 100644 libs/generic/functional.cpp create mode 100644 libs/generic/functional.h create mode 100644 libs/signal/isignal.cpp create mode 100644 libs/signal/isignal.h create mode 100644 libs/signal/signal.cpp create mode 100644 libs/signal/signal.h create mode 100644 libs/signal/signalfwd.cpp create mode 100644 libs/signal/signalfwd.h diff --git a/CHANGES b/CHANGES index 3ab71a63..a7b3a7fd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,14 @@ This is the changelog for developers, != changelog for the end user that we distribute with the binaries. (see changelog) +01/04/2006 +SPoG +- Added key-observer interface to entity module API. +- Rewrote callback library to add support for return-values. +- Added minimal API to support bobtoolz plugin. +- Refactored brush for-each functions to take Functor instead of Visitor. +- Added signals library. + 31/03/2006 SPoG - Changed doom3 light creation to use size of selected brushes. diff --git a/GtkRadiant.sln b/GtkRadiant.sln index 7ee5bd39..2eacd630 100644 --- a/GtkRadiant.sln +++ b/GtkRadiant.sln @@ -146,6 +146,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrtView", "contrib\prtview\ {853632F4-6420-40C5-B80B-38B678E472B8} = {853632F4-6420-40C5-B80B-38B678E472B8} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bobtoolz", "contrib\bobtoolz\bobtoolz.vcproj", "{B20364D1-4329-4D4E-B9CE-C9767618FDD6}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -272,6 +276,10 @@ Global {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32 {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32 {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32 + {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.ActiveCfg = Debug|Win32 + {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32 + {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32 + {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/contrib/bobtoolz/CPortals.h b/contrib/bobtoolz/CPortals.h index baab0a75..71f399b7 100644 --- a/contrib/bobtoolz/CPortals.h +++ b/contrib/bobtoolz/CPortals.h @@ -17,8 +17,6 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" // Added by ClassView - class CBspPoint { public: float p[3]; @@ -47,6 +45,8 @@ public: }; +#define NAME_MAX 255 + class CPortals { public: diff --git a/contrib/bobtoolz/DBobView.cpp b/contrib/bobtoolz/DBobView.cpp index f4d36de4..c5de46f6 100644 --- a/contrib/bobtoolz/DBobView.cpp +++ b/contrib/bobtoolz/DBobView.cpp @@ -21,16 +21,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" #include "DBobView.h" -#include "DListener.h" //#include "misc.h" #include "funchandlers.h" -#include "gtkr_list.h" +#include + +#include "iglrender.h" +#include "qerplugin.h" #include "str.h" +#include "math/matrix.h" +#include "DEntity.h" +#include "DEPair.h" #include "misc.h" +#include "dialogs/dialogs-gtk.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -39,28 +44,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA DBobView::DBobView() { nPathCount = 0; - refCount = 1; - m_bHooked = FALSE; - path = NULL; - eyes = NULL; boundingShow = BOUNDS_APEX; + + constructShaders(); + GlobalShaderCache().attachRenderable(*this); } DBobView::~DBobView() { - if(path) - delete[] path; - - // oops forgot to remove our eyes, was causing access violation when it tried - // to talk to it's parent - if(eyes) - delete eyes; + GlobalShaderCache().detachRenderable(*this); + destroyShaders(); - if(m_bHooked) - UnRegister(); + if(path) + delete[] path; g_PathView = NULL; } @@ -69,201 +68,77 @@ DBobView::~DBobView() // Implementation ////////////////////////////////////////////////////////////////////// -void DBobView::Draw2D(VIEWTYPE vt) +void DBobView::render(RenderStateFlags state) const { - if(!path) - return; - - __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); - - __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH); - - __QGLTABLENAME.m_pfn_qglPushMatrix(); - - switch(vt) - { - case XY: - break; - case XZ: - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f); - break; - case YZ: - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f); - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f); - break; - } - - __QGLTABLENAME.m_pfn_qglLineWidth(1.0f); - __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f); - - int i; - - __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP); - - for(i = 0; i < nPathCount; i++) - __QGLTABLENAME.m_pfn_qglVertex3fv(path[i]); - - __QGLTABLENAME.m_pfn_qglEnd(); - - if(m_bShowExtra) - { - // +mars - // for the bounding box stuff - __QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f); + glBegin(GL_LINE_STRIP); - __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f ); - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - - // --------------- - - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - - // -------------- - - __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were - __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - - // ---------------- - - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were - -/* __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos + for(int i = 0; i < nPathCount; i++) + glVertex3fv(path[i]); - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - if ( boundingShow == BOUNDS_ALL ) - { - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - } - else if ( boundingShow == BOUNDS_APEX ) - { - for ( i = (nPathCount/4); i < (nPathCount/4) * 3; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - } + glEnd(); +} - __QGLTABLENAME.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting - } +const char* DBobView_state_line = "$bobtoolz/bobview/line"; +const char* DBobView_state_box = "$bobtoolz/bobview/box"; - // -mars - - __QGLTABLENAME.m_pfn_qglPopMatrix(); +void DBobView::constructShaders() +{ + OpenGLState state; + GlobalOpenGLStateLibrary().getDefaultState(state); + state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_BLEND|RENDER_LINESMOOTH; + state.m_sort = OpenGLState::eSortOpaque; + state.m_linewidth = 1; + state.m_colour[0] = 1; + state.m_colour[1] = 0; + state.m_colour[2] = 0; + state.m_colour[3] = 1; + GlobalOpenGLStateLibrary().insert(DBobView_state_line, state); + + state.m_colour[0] = 0.25f; + state.m_colour[1] = 0.75f; + state.m_colour[2] = 0.75f; + state.m_colour[3] = 1; + GlobalOpenGLStateLibrary().insert(DBobView_state_box, state); + + m_shader_line = GlobalShaderCache().capture(DBobView_state_line); + m_shader_box = GlobalShaderCache().capture(DBobView_state_box); +} - __QGLTABLENAME.m_pfn_qglPopAttrib(); +void DBobView::destroyShaders() +{ + GlobalOpenGLStateLibrary().erase(DBobView_state_line); + GlobalOpenGLStateLibrary().erase(DBobView_state_box); + GlobalShaderCache().release(DBobView_state_line); + GlobalShaderCache().release(DBobView_state_box); } -void DBobView::Draw3D() +Matrix4 g_transform_box1 = matrix4_translation_for_vec3(Vector3(16.0f, 16.0f, 28.0f)); +Matrix4 g_transform_box2 = matrix4_translation_for_vec3(Vector3(-16.0f, 16.0f, 28.0f)); +Matrix4 g_transform_box3 = matrix4_translation_for_vec3(Vector3(16.0f, -16.0f, -28.0f)); +Matrix4 g_transform_box4 = matrix4_translation_for_vec3(Vector3(-16.0f, -16.0f, -28.0f)); + +void DBobView::renderSolid(Renderer& renderer, const VolumeTest& volume) const { if(!path) return; - __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); - - __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH); - - __QGLTABLENAME.m_pfn_qglLineWidth(1.0f); - __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f); - - __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP); - - for(int i = 0; i < nPathCount; i++) - __QGLTABLENAME.m_pfn_qglVertex3fv(path[i]); - - __QGLTABLENAME.m_pfn_qglEnd(); + renderer.SetState(m_shader_line, eWireframeOnly); + renderer.SetState(m_shader_line, eFullMaterials); + renderer.addRenderable(*this, g_matrix4_identity); if(m_bShowExtra) { - // +mars - // ahhh -- a nice C&P job :) - // for the bounding box stuff - __QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f); - - __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f ); - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - int i; - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - - // --------------- - - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - - // -------------- - - __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were - __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - - // ---------------- - - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were - __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos - - __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP ); - - for ( i = 0; i < nPathCount; i++ ) - __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] ); - - __QGLTABLENAME.m_pfn_qglEnd(); - } - // -mars - - __QGLTABLENAME.m_pfn_qglPopAttrib(); + renderer.SetState(m_shader_box, eWireframeOnly); + renderer.SetState(m_shader_box, eFullMaterials); + renderer.addRenderable(*this, g_transform_box1); + renderer.addRenderable(*this, g_transform_box2); + renderer.addRenderable(*this, g_transform_box3); + renderer.addRenderable(*this, g_transform_box4); + } } - -void DBobView::Register() +void DBobView::renderWireframe(Renderer& renderer, const VolumeTest& volume) const { - __QGLTABLENAME.m_pfnHookGL2DWindow( this ); - __QGLTABLENAME.m_pfnHookGL3DWindow( this ); - m_bHooked = TRUE; -} - -void DBobView::UnRegister() -{ - __QGLTABLENAME.m_pfnUnHookGL2DWindow( this ); - __QGLTABLENAME.m_pfnUnHookGL3DWindow( this ); - m_bHooked = FALSE; + renderSolid(renderer, volume); } void DBobView::SetPath(vec3_t *pPath) @@ -281,7 +156,7 @@ bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier, if(apex[2] <= start[2]) { SetPath(NULL); - return FALSE; + return false; } // ----think q3a actually would allow these //scrub that, coz the plugin wont :] @@ -319,7 +194,7 @@ bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier, } SetPath(pPath); - return TRUE; + return true; } void DBobView::Begin(const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra) @@ -332,20 +207,9 @@ void DBobView::Begin(const char* trigger, const char *target, float multiplier, nPathCount = points; m_bShowExtra = bShowExtra; - Register(); - - if(UpdatePath()) - { - if(!bNoUpdate) - { - eyes = new DListener; - eyes->parent = this; - eyes->Register(); - } - } - else + if(!UpdatePath()) { - Sys_ERROR("Initialization Failure in DBobView::Begin"); + globalErrorStream() << "Initialization Failure in DBobView::Begin"; delete this; } } @@ -359,8 +223,55 @@ bool DBobView::UpdatePath() if(GetEntityCentre(entTarget, apex)) { CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity); - return TRUE; + return true; } } - return FALSE; + return false; } + +void DBobView_setEntity(Entity& entity, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra) +{ + DEntity trigger; + trigger.LoadEPairList(&entity); + + DEPair* trigger_ep = trigger.FindEPairByKey("targetname"); + + if(trigger_ep) + { + if(!strcmp(trigger.m_Classname, "trigger_push")) + { + DEPair* target_ep = trigger.FindEPairByKey("target"); + if(target_ep) + { + scene::Path* entTarget = FindEntityFromTargetname(target_ep->value, NULL); + if(entTarget) + { + if(g_PathView) + delete g_PathView; + g_PathView = new DBobView; + + Entity* target = Node_getEntity(entTarget->top()); + if(target != 0) + { + if(!bNoUpdate) + { + g_PathView->trigger = &entity; + entity.attach(*g_PathView); + g_PathView->target = target; + target->attach(*g_PathView); + } + g_PathView->Begin(trigger_ep->value, target_ep->value, multiplier, points, varGravity, bNoUpdate, bShowExtra); + } + } + else + DoMessageBox("trigger_push target could not be found.", "Error", eMB_OK); + } + else + DoMessageBox("trigger_push has no target.", "Error", eMB_OK); + } + else + DoMessageBox("You must select a 'trigger_push' entity.", "Error", eMB_OK); + } + else + DoMessageBox("Entity must have a targetname", "Error", eMB_OK); +} \ No newline at end of file diff --git a/contrib/bobtoolz/DBobView.h b/contrib/bobtoolz/DBobView.h index 94902607..6869e6bd 100644 --- a/contrib/bobtoolz/DBobView.h +++ b/contrib/bobtoolz/DBobView.h @@ -24,7 +24,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #if !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_) #define AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_ +#include "ientity.h" +#include "irender.h" +#include "renderable.h" +#include "mathlib.h" + class DListener; +class Shader; #define BOUNDS_ALL 0 #define BOUNDS_APEX 1 @@ -33,22 +39,26 @@ class DListener; #pragma once #endif // _MSC_VER > 1000 -class DBobView : - public IGL2DWindow, - public IGL3DWindow +class DBobView : public Renderable, public OpenGLRenderable, public Entity::Observer { + Shader* m_shader_line; + Shader* m_shader_box; public: DBobView(); virtual ~DBobView(); protected: vec3_t* path; - int refCount; public: bool m_bShowExtra; int boundingShow; DListener* eyes; float fVarGravity; + float fMultiplier; + int nPathCount; + + Entity* trigger; + Entity* target; bool UpdatePath(); char entTarget[256]; @@ -57,16 +67,40 @@ public: bool CalculateTrajectory(vec3_t, vec3_t, float, int, float); void SetPath(vec3_t* pPath); - void UnRegister(); - void Register(); - void Draw3D(); - void Draw2D(VIEWTYPE vt); - void IncRef() { refCount++; } - void DecRef() { refCount--; if (refCount <= 0) delete this; } - float fMultiplier; - bool m_bHooked; - int nPathCount; + void render(RenderStateFlags state) const; + void renderSolid(Renderer& renderer, const VolumeTest& volume) const; + void renderWireframe(Renderer& renderer, const VolumeTest& volume) const; + + void constructShaders(); + void destroyShaders(); + + void valueChanged(const char* value) + { + UpdatePath(); + } + typedef MemberCaller1 ValueChangedCaller; + void insert(const char* key, EntityKeyValue& value) + { + value.attach(ValueChangedCaller(*this)); + } + void erase(const char* key, EntityKeyValue& value) + { + value.detach(ValueChangedCaller(*this)); + } + void clear() + { + if(trigger != 0) + { + trigger->detach(*this); + target->detach(*this); + trigger = 0; + target = 0; + } + } }; +class Entity; +void DBobView_setEntity(Entity& entity, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra); + #endif // !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_) diff --git a/contrib/bobtoolz/DBrush.cpp b/contrib/bobtoolz/DBrush.cpp index 835e091e..75b2a6e8 100644 --- a/contrib/bobtoolz/DBrush.cpp +++ b/contrib/bobtoolz/DBrush.cpp @@ -21,32 +21,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DBrush.h" #ifdef WIN32 #pragma warning(disable : 4786) #endif -#include "StdAfx.h" - -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" #include "DPlane.h" -#include "DBrush.h" #include "DEPair.h" #include "DPatch.h" #include "DEntity.h" #include "DWinding.h" -#include "dialogs-gtk.h" +#include "dialogs/dialogs-gtk.h" #include "misc.h" #include "iundo.h" -#include "refcounted_ptr.h" +#include "generic/referencecounted.h" #include "scenelib.h" @@ -57,7 +54,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA DBrush::DBrush(int ID) { m_nBrushID = ID; - bBoundsBuilt = FALSE; + bBoundsBuilt = false; QER_brush = NULL; } @@ -71,12 +68,12 @@ DBrush::~DBrush() // Implementation ////////////////////////////////////////////////////////////////////// -DPlane* DBrush::AddFace(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData) +DPlane* DBrush::AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData) { #ifdef _DEBUG // Sys_Printf("(%f %f %f) (%f %f %f) (%f %f %f)\n", va[0], va[1], va[2], vb[0], vb[1], vb[2], vc[0], vc[1], vc[2]); #endif - bBoundsBuilt = FALSE; + bBoundsBuilt = false; DPlane* newFace = new DPlane(va, vb, vc, texData); faceList.push_back(newFace); @@ -90,12 +87,12 @@ int DBrush::BuildPoints() if(faceList.size() <= 3) // if less than 3 faces, there can be no points return 0; // with only 3 faces u can't have a bounded soild - for(list::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++) + for(std::list::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++) { - list::const_iterator p2=p1; + std::list::const_iterator p2=p1; for(p2++; p2!=faceList.end(); p2++) { - list::const_iterator p3=p2; + std::list::const_iterator p3=p2; for(p3++; p3!=faceList.end(); p3++) { vec3_t pnt; @@ -105,7 +102,7 @@ int DBrush::BuildPoints() if(pos == POINT_IN_BRUSH) { // ???? shouldn't happen here - Sys_Printf("ERROR:: Build Brush Points: Point IN brush!!!\n"); + globalErrorStream() << "ERROR:: Build Brush Points: Point IN brush!!!\n"; } else if(pos == POINT_ON_BRUSH) { // normal point @@ -131,34 +128,33 @@ int DBrush::BuildPoints() return pointList.size(); } -void DBrush::LoadFromBrush(scene::Node* brush, bool textured) +void DBrush_addFace(DBrush& brush, const _QERFaceData& faceData) { - ClearFaces(); - ClearPoints(); + brush.AddFace(vector3_to_array(faceData.m_p0), vector3_to_array(faceData.m_p1), vector3_to_array(faceData.m_p2), 0); +} +typedef ReferenceCaller1 DBrushAddFaceCaller; -#if 0 - for(int i = g_FuncTable.m_pfnGetFaceCount(brush)-1; i >= 0 ; i--) - { // running backwards so i dont have to use the count function each time (OPT) - _QERFaceData* faceData = g_FuncTable.m_pfnGetFaceData(brush, i); +void DBrush_addFaceTextured(DBrush& brush, const _QERFaceData& faceData) +{ + brush.AddFace(vector3_to_array(faceData.m_p0), vector3_to_array(faceData.m_p1), vector3_to_array(faceData.m_p2), &faceData); +} +typedef ReferenceCaller1 DBrushAddFaceTexturedCaller; - if(faceData == NULL) - DoMessageBox("Null pointer returned", "WARNING!", MB_OK); +void DBrush::LoadFromBrush(scene::Node& brush, bool textured) +{ + ClearFaces(); + ClearPoints(); - if(textured) - AddFace(faceData->m_v1, faceData->m_v2, faceData->m_v3, faceData); - else - AddFace(faceData->m_v1, faceData->m_v2, faceData->m_v3, NULL); - } -#endif + GlobalBrushCreator().forEachBrushFace(brush, textured ? BrushFaceDataCallback(DBrushAddFaceTexturedCaller(*this)) : BrushFaceDataCallback(DBrushAddFaceCaller(*this))); - QER_brush = brush; + QER_brush = &brush; } int DBrush::PointPosition(vec3_t pnt) { int state = POINT_IN_BRUSH; // if nothing happens point is inside brush - for(list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) + for(std::list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) { float dist = (*chkPlane)->DistanceToPoint(pnt); @@ -174,7 +170,7 @@ int DBrush::PointPosition(vec3_t pnt) void DBrush::ClearPoints() { - for(list::const_iterator deadPoint=pointList.begin(); deadPoint!=pointList.end(); deadPoint++) { + for(std::list::const_iterator deadPoint=pointList.begin(); deadPoint!=pointList.end(); deadPoint++) { delete *deadPoint; } pointList.clear(); @@ -182,8 +178,8 @@ void DBrush::ClearPoints() void DBrush::ClearFaces() { - bBoundsBuilt = FALSE; - for(list::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++) + bBoundsBuilt = false; + for(std::list::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++) { delete *deadPlane; } @@ -199,32 +195,32 @@ void DBrush::AddPoint(vec3_t pnt) bool DBrush::HasPoint(vec3_t pnt) { - for(list::const_iterator chkPoint=pointList.begin(); chkPoint!=pointList.end(); chkPoint++) + for(std::list::const_iterator chkPoint=pointList.begin(); chkPoint!=pointList.end(); chkPoint++) { if(**chkPoint == pnt) - return TRUE; + return true; } - return FALSE; + return false; } int DBrush::RemoveRedundantPlanes() { int cnt = 0; - list::iterator chkPlane; + std::list::iterator chkPlane; // find duplicate planes - list::iterator p1=faceList.begin(); + std::list::iterator p1=faceList.begin(); while( p1!=faceList.end() ) { - list::iterator p2 = p1; + std::list::iterator p2 = p1; for(p2++; p2!=faceList.end(); p2++) { if(**p1 == **p2) { - if(!strcmp((*p1)->texInfo.m_texdef.GetName(), "textures/common/caulk")) + if(!strcmp((*p1)->m_shader.c_str(), "textures/common/caulk")) { delete *p1; p1 = faceList.erase(p1); // duplicate plane @@ -285,12 +281,12 @@ bool DBrush::GetBounds(vec3_t min, vec3_t max) BuildBounds(); if(!bBoundsBuilt) - return FALSE; + return false; VectorCopy(bbox_min, min); VectorCopy(bbox_max, max); - return TRUE; + return true; } bool DBrush::BBoxCollision(DBrush* chkBrush) @@ -302,25 +298,25 @@ bool DBrush::BBoxCollision(DBrush* chkBrush) chkBrush->GetBounds(min2, max2); if(min1[0] >= max2[0]) - return FALSE; + return false; if(min1[1] >= max2[1]) - return FALSE; + return false; if(min1[2] >= max2[2]) - return FALSE; + return false; if(max1[0] <= min2[0]) - return FALSE; + return false; if(max1[1] <= min2[1]) - return FALSE; + return false; if(max1[2] <= min2[2]) - return FALSE; + return false; - return TRUE; + return true; } DPlane* DBrush::HasPlane(DPlane* chkPlane) { - for(list::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++) + for(std::list::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++) { if(**brushPlane == *chkPlane) return *brushPlane; @@ -334,21 +330,21 @@ bool DBrush::IsCutByPlane(DPlane *cuttingPlane) if(pointList.size() == 0) if(BuildPoints() == 0) - return FALSE; + return false; - list::const_iterator chkPnt = pointList.begin(); + std::list::const_iterator chkPnt = pointList.begin(); if(chkPnt == pointList.end()) - return FALSE; + return false; float dist = cuttingPlane->DistanceToPoint((*chkPnt)->_pnt); if(dist > MAX_ROUND_ERROR) - isInFront = FALSE; + isInFront = false; else if(dist < MAX_ROUND_ERROR) - isInFront = TRUE; + isInFront = true; else - return TRUE; + return true; for(chkPnt++=pointList.begin(); chkPnt!=pointList.end(); chkPnt++) { @@ -357,31 +353,32 @@ bool DBrush::IsCutByPlane(DPlane *cuttingPlane) if(dist > MAX_ROUND_ERROR) { if(isInFront) - return TRUE; + return true; } else if(dist < MAX_ROUND_ERROR) { if(!isInFront) - return TRUE; + return true; } else - return TRUE; + return true; } - return FALSE; + return false; } + scene::Node* DBrush::BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity) { if(allowDestruction) { - bool kill = TRUE; + bool kill = true; - for(list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) + for(std::list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) { if((*chkPlane)->m_bChkOk) { - kill = FALSE; + kill = false; break; } } @@ -392,26 +389,26 @@ scene::Node* DBrush::BuildInRadiant(bool allowDestruction, int* changeCnt, scene //+djbob: fixed bug when brush had no faces "phantom brush" in radiant. if(faceList.size() < 4) { - Sys_Printf("Possible Phantom Brush Found, will not rebuild\n"); + globalErrorStream() << "Possible Phantom Brush Found, will not rebuild\n"; return NULL; } //-djbob - NodePtr node(Brush_AllocNode()); + scene::Node& node = GlobalBrushCreator().createBrush(); - for(list::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) { - if((*buildPlane)->AddToBrush(node->m_brush) && changeCnt) { + for(std::list::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) { + if((*buildPlane)->AddToBrush(node) && changeCnt) { (*changeCnt)++; } } if(entity) { - entity->m_traverse->insert(node); + Node_getTraversable(*entity)->insert(node); } else { - GetWorldspawn()->m_traverse->insert(node); + Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(node); } - return node; + return &node; } void DBrush::CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2) @@ -426,7 +423,7 @@ void DBrush::CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2 DBrush* b1 = new DBrush; DBrush* b2 = new DBrush; - for(list::const_iterator parsePlane=faceList.begin(); parsePlane!=faceList.end(); parsePlane++) + for(std::list::const_iterator parsePlane=faceList.begin(); parsePlane!=faceList.end(); parsePlane++) { b1->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL); b2->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL); @@ -446,55 +443,55 @@ bool DBrush::IntersectsWith(DBrush *chkBrush) { if(pointList.size() == 0) if(BuildPoints() == 0) - return FALSE; // invalid brush!!!! + return false; // invalid brush!!!! if(chkBrush->pointList.size() == 0) if(chkBrush->BuildPoints() == 0) - return FALSE; // invalid brush!!!! + return false; // invalid brush!!!! if(!BBoxCollision(chkBrush)) - return FALSE; + return false; - list::const_iterator iplPlane; + std::list::const_iterator iplPlane; for( iplPlane=faceList.begin(); iplPlane!=faceList.end(); iplPlane++) { - bool allInFront = TRUE; - for(list::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++) + bool allInFront = true; + for(std::list::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++) { if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR) { - allInFront = FALSE; + allInFront = false; break; } } if(allInFront) - return FALSE; + return false; } for( iplPlane=chkBrush->faceList.begin(); iplPlane!=chkBrush->faceList.end(); iplPlane++) { - bool allInFront = TRUE; - for(list::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++) + bool allInFront = true; + for(std::list::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++) { if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR) { - allInFront = FALSE; + allInFront = false; break; } } if(allInFront) - return FALSE; + return false; } - return TRUE; + return true; } bool DBrush::IntersectsWith(DPlane* p1, DPlane* p2, vec3_t v) { vec3_t vDown = { 0, 0, -1 }; - list::const_iterator iplPlane; + std::list::const_iterator iplPlane; for( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++) { DPlane* p = (*iplPlane); @@ -504,12 +501,12 @@ bool DBrush::IntersectsWith(DPlane* p1, DPlane* p2, vec3_t v) { } if(p->PlaneIntersection(p1, p2, v)) { if(PointPosition( v ) != POINT_OUT_BRUSH) { - return TRUE; + return true; } } } - return FALSE; + return false; } void DBrush::BuildBounds() @@ -520,11 +517,11 @@ void DBrush::BuildBounds() if(BuildPoints() == 0) return; - list::const_iterator first = pointList.begin(); + std::list::const_iterator first = pointList.begin(); VectorCopy((*first)->_pnt, bbox_min); VectorCopy((*first)->_pnt, bbox_max); - list::const_iterator point=pointList.begin(); + std::list::const_iterator point=pointList.begin(); for( point++; point!=pointList.end(); point++) { if((*point)->_pnt[0] > bbox_max[0]) @@ -542,7 +539,7 @@ void DBrush::BuildBounds() bbox_min[2] = (*point)->_pnt[2]; } - bBoundsBuilt = TRUE; + bBoundsBuilt = true; } } @@ -555,18 +552,18 @@ bool DBrush::BBoxTouch(DBrush *chkBrush) chkBrush->GetBounds(min2, max2); if((min1[0] - max2[0]) > MAX_ROUND_ERROR) - return FALSE; + return false; if((min1[1] - max2[1]) > MAX_ROUND_ERROR) - return FALSE; + return false; if((min1[2] - max2[2]) > MAX_ROUND_ERROR) - return FALSE; + return false; if((min2[0] - max1[0]) > MAX_ROUND_ERROR) - return FALSE; + return false; if((min2[1] - max1[1]) > MAX_ROUND_ERROR) - return FALSE; + return false; if((min2[2] - max1[2]) > MAX_ROUND_ERROR) - return FALSE; + return false; int cnt = 0; @@ -589,24 +586,24 @@ bool DBrush::BBoxTouch(DBrush *chkBrush) cnt++; if(cnt > 1) - return FALSE; + return false; - return TRUE; + return true; } -void DBrush::ResetChecks(list* exclusionList) +void DBrush::ResetChecks(std::list* exclusionList) { - for(list::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++) + for(std::list::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++) { - bool set = FALSE; + bool set = false; if(exclusionList) { - for(list::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++) + for(std::list::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++) { - if(strstr((*resetPlane)->texInfo.m_texdef.GetName(), eTexture->GetBuffer())) + if(strstr((*resetPlane)->m_shader.c_str(), eTexture->GetBuffer())) { - set = TRUE; + set = true; break; } } @@ -618,7 +615,7 @@ void DBrush::ResetChecks(list* exclusionList) DPlane* DBrush::HasPlaneInverted(DPlane *chkPlane) { - for(list::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++) + for(std::list::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++) { if(**brushPlane != *chkPlane) { @@ -631,31 +628,31 @@ DPlane* DBrush::HasPlaneInverted(DPlane *chkPlane) bool DBrush::HasTexture(const char *textureName) { - for(list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) + for(std::list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) { - if(strstr((*chkPlane)->texInfo.m_texdef.GetName(), textureName)) - return TRUE; + if(strstr((*chkPlane)->m_shader.c_str(), textureName)) + return true; } - return FALSE; + return false; } bool DBrush::IsDetail() { - for(list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) + for(std::list::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) { - if((*chkPlane)->texInfo.m_texdef.contents & FACE_DETAIL) - return TRUE; + if((*chkPlane)->texInfo.contents & FACE_DETAIL) + return true; } - return FALSE; + return false; } void DBrush::BuildFromWinding(DWinding *w) { if(w->numpoints < 3) { - Sys_ERROR("Winding has invalid number of points"); + globalErrorStream() << "Winding has invalid number of points"; return; } @@ -682,7 +679,7 @@ void DBrush::SaveToFile(FILE *pFile) { fprintf(pFile, "{\n"); - for(list::const_iterator pp=faceList.begin(); pp!=faceList.end(); pp++) + for(std::list::const_iterator pp=faceList.begin(); pp!=faceList.end(); pp++) { char buffer[512]; @@ -690,7 +687,7 @@ void DBrush::SaveToFile(FILE *pFile) (*pp)->points[0][0], (*pp)->points[0][1], (*pp)->points[0][2], (*pp)->points[1][0], (*pp)->points[1][1], (*pp)->points[1][2], (*pp)->points[2][0], (*pp)->points[2][1], (*pp)->points[2][2], - (*pp)->texInfo.m_texdef.GetName(), + (*pp)->m_shader.c_str(), (*pp)->texInfo.m_texdef.shift[0], (*pp)->texInfo.m_texdef.shift[1], (*pp)->texInfo.m_texdef.scale[0], (*pp)->texInfo.m_texdef.scale[0], (*pp)->texInfo.m_texdef.rotate); @@ -703,7 +700,7 @@ void DBrush::SaveToFile(FILE *pFile) void DBrush::Rotate(vec3_t vOrigin, vec3_t vRotation) { - for(list::const_iterator rotPlane=faceList.begin(); rotPlane!=faceList.end(); rotPlane++) + for(std::list::const_iterator rotPlane=faceList.begin(); rotPlane!=faceList.end(); rotPlane++) { for(int i = 0; i < 3; i++) VectorRotate((*rotPlane)->points[i], vRotation, vOrigin); @@ -727,13 +724,13 @@ bool DBrush::ResetTextures(const char* textureName, float fScale[2], float fS { if(textureName) { - bool changed = FALSE; - for(list::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++) + bool changed = false; + for(std::list::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++) { - if(!strcmp((*resetPlane)->texInfo.m_texdef.GetName(), textureName)) + if(!strcmp((*resetPlane)->m_shader.c_str(), textureName)) { if(bResetTextureName) - (*resetPlane)->texInfo.m_texdef.SetName(newTextureName); + (*resetPlane)->m_shader = newTextureName; if(bResetScale[0]) (*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0]; @@ -748,17 +745,17 @@ bool DBrush::ResetTextures(const char* textureName, float fScale[2], float fS if(bResetRotation) (*resetPlane)->texInfo.m_texdef.rotate = (float)rotation; - changed = TRUE; + changed = true; } } return changed; // no point rebuilding unless we need to, only slows things down } else { - for(list::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++) + for(std::list::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++) { if(bResetTextureName) - (*resetPlane)->texInfo.m_texdef.SetName(newTextureName); + (*resetPlane)->m_shader = newTextureName; if(bResetScale[0]) (*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0]; @@ -773,32 +770,32 @@ bool DBrush::ResetTextures(const char* textureName, float fScale[2], float fS if(bResetRotation) (*resetPlane)->texInfo.m_texdef.rotate = (float)rotation; } - return TRUE; + return true; } } bool DBrush::operator ==(DBrush* other) { - list::const_iterator chkPlane; + std::list::const_iterator chkPlane; for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) { if(!other->HasPlane((*chkPlane))) - return FALSE; + return false; } for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) { if(!HasPlane((*chkPlane))) - return FALSE; + return false; } - return TRUE; + return true; } -DPlane* DBrush::AddFace(vec3_t va, vec3_t vb, vec3_t vc, const char *textureName, bool bDetail) +DPlane* DBrush::AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const char *textureName, bool bDetail) { - bBoundsBuilt = FALSE; + bBoundsBuilt = false; DPlane* newFace = new DPlane(va, vb, vc, textureName, bDetail); faceList.push_back(newFace); @@ -808,7 +805,7 @@ DPlane* DBrush::AddFace(vec3_t va, vec3_t vb, vec3_t vc, const char *textureName DPlane* DBrush::FindPlaneWithClosestNormal( vec_t* normal ) { vec_t bestDot = -2; DPlane* bestDotPlane = NULL; - list::const_iterator chkPlane; + std::list::const_iterator chkPlane; for( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ ) { DPlane* pPlane = (*chkPlane); @@ -831,7 +828,7 @@ int DBrush::FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ) { BuildPoints(); - for( list::const_iterator points = pointList.begin(); points != pointList.end(); points++ ) { + for( std::list::const_iterator points = pointList.begin(); points != pointList.end(); points++ ) { DPoint* point = (*points); if( fabs(plane->DistanceToPoint( point->_pnt )) < MAX_ROUND_ERROR ) { @@ -849,19 +846,11 @@ int DBrush::FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ) { } void DBrush::RemovePlane( DPlane* plane ) { - bBoundsBuilt = FALSE; - for( list::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) { + bBoundsBuilt = false; + for( std::list::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) { if(*deadPlane == plane) { delete *deadPlane; faceList.remove( plane ); } } } - -void DBrush::RemoveFromRadiant( void ) { - if(QER_brush) { -#if 0 - g_FuncTable.m_pfnDeleteBrushHandle(QER_brush); -#endif - } -} diff --git a/contrib/bobtoolz/DBrush.h b/contrib/bobtoolz/DBrush.h index b285bc00..9915d0f9 100644 --- a/contrib/bobtoolz/DBrush.h +++ b/contrib/bobtoolz/DBrush.h @@ -28,6 +28,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include +#include +#include "mathlib.h" +#include "str.h" + +class DPlane; +class DWinding; +class DPoint; +class _QERFaceData; + +namespace scene +{ + class Node; +} + #define POINT_IN_BRUSH 0 #define POINT_ON_BRUSH 1 #define POINT_OUT_BRUSH 2 @@ -35,7 +50,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA class DBrush { public: - DPlane* AddFace(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bDetail); + DPlane* AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail); void SaveToFile(FILE* pFile); void Rotate(vec3_t vOrigin, vec3_t vRotation); @@ -43,7 +58,7 @@ public: DPlane* HasPlaneInverted(DPlane* chkPlane); DPlane* HasPlane(DPlane* chkPlane); - DPlane* AddFace(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData); + DPlane* AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData); bool ResetTextures(const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation); bool IsDetail(); @@ -61,7 +76,7 @@ public: void BuildFromWinding(DWinding* w); scene::Node* BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity = NULL); - void ResetChecks(list* exclusionList); + void ResetChecks(std::list* exclusionList); void ClearFaces(); void ClearPoints(); @@ -69,12 +84,11 @@ public: int RemoveRedundantPlanes( void ); void RemovePlane( DPlane* plane ); int PointPosition(vec3_t pnt); - void RemoveFromRadiant( void ); void CutByPlane(DPlane* cutPlane, DBrush** newBrush1, DBrush** newBrush2); - void LoadFromBrush(scene::Node* brush, bool textured); + void LoadFromBrush(scene::Node& brush, bool textured); void AddPoint(vec3_t pnt); DPlane* FindPlaneWithClosestNormal( vec_t* normal ); @@ -87,8 +101,8 @@ public: // members scene::Node* QER_brush; - list faceList; - list pointList; + std::list faceList; + std::list pointList; int m_nBrushID; vec3_t bbox_min, bbox_max; bool bBoundsBuilt; diff --git a/contrib/bobtoolz/DEPair.cpp b/contrib/bobtoolz/DEPair.cpp index e7cc1ed5..72dda4b3 100644 --- a/contrib/bobtoolz/DEPair.cpp +++ b/contrib/bobtoolz/DEPair.cpp @@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" -#include "str.h" #include "DEPair.h" ////////////////////////////////////////////////////////////////////// diff --git a/contrib/bobtoolz/DEPair.h b/contrib/bobtoolz/DEPair.h index bf8d7ad5..fac4c334 100644 --- a/contrib/bobtoolz/DEPair.h +++ b/contrib/bobtoolz/DEPair.h @@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include "str.h" + class DEPair { public: diff --git a/contrib/bobtoolz/DEntity.cpp b/contrib/bobtoolz/DEntity.cpp index 5a76ca12..f69b358c 100644 --- a/contrib/bobtoolz/DEntity.cpp +++ b/contrib/bobtoolz/DEntity.cpp @@ -21,13 +21,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// +#include "DEntity.h" + #ifdef WIN32 #pragma warning(disable : 4786) #endif -#include "StdAfx.h" - -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" @@ -35,15 +35,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DBrush.h" #include "DEPair.h" #include "DPatch.h" -#include "DEntity.h" -#include "dialogs-gtk.h" +#include "dialogs/dialogs-gtk.h" #include "misc.h" #include "CPortals.h" #include "iundo.h" +#include "ientity.h" +#include "ieclass.h" -#include "refcounted_ptr.h" +#include "generic/referencecounted.h" #include #include @@ -97,7 +98,7 @@ DEntity::~DEntity() void DEntity::ClearBrushes() { - for(list::const_iterator deadBrush=brushList.begin(); deadBrush!=brushList.end(); deadBrush++) + for(std::list::const_iterator deadBrush=brushList.begin(); deadBrush!=brushList.end(); deadBrush++) { delete *deadBrush; } @@ -106,7 +107,7 @@ void DEntity::ClearBrushes() void DEntity::ClearPatches() { - for(list::const_iterator deadPatch=patchList.begin(); deadPatch!=patchList.end(); deadPatch++) + for(std::list::const_iterator deadPatch=patchList.begin(); deadPatch!=patchList.end(); deadPatch++) { delete *deadPatch; } @@ -151,7 +152,7 @@ bool DEntity::LoadFromPrt(char *filename) portals.Load(); if(portals.node_count == 0) - return FALSE; + return false; ClearBrushes(); ClearEPairs(); @@ -188,15 +189,15 @@ bool DEntity::LoadFromPrt(char *filename) } if(!build) - brush->AddFace(portals.node[i].portal[j].point[2].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[0].p, "textures/common/caulk", FALSE); + brush->AddFace(portals.node[i].portal[j].point[2].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[0].p, "textures/common/caulk", false); else - brush->AddFace(portals.node[i].portal[j].point[0].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[2].p, "textures/common/caulk", FALSE); + brush->AddFace(portals.node[i].portal[j].point[0].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[2].p, "textures/common/caulk", false); } if(build) - brush->BuildInRadiant(FALSE, NULL); + brush->BuildInRadiant(false, NULL); } - return TRUE; + return true; } DPlane* DEntity::AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID) @@ -210,7 +211,7 @@ DBrush* DEntity::GetBrushForID(int ID) { DBrush* buildBrush = NULL; - for(list::const_iterator chkBrush=brushList.begin(); chkBrush!=brushList.end(); chkBrush++) + for(std::list::const_iterator chkBrush=brushList.begin(); chkBrush!=brushList.end(); chkBrush++) { if((*chkBrush)->m_nBrushID == ID) { @@ -225,47 +226,82 @@ DBrush* DEntity::GetBrushForID(int ID) return buildBrush; } +template +class BrushSelectedVisitor : public SelectionSystem::Visitor +{ + const Functor& m_functor; +public: + BrushSelectedVisitor(const Functor& functor) : m_functor(functor) + { + } + void visit(scene::Instance& instance) const + { + if(Node_isBrush(instance.path().top())) + { + m_functor(*instance.path().top()); + } + } +}; + +template +inline const Functor& Scene_forEachSelectedBrush(const Functor& functor) +{ + GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor(functor)); + return functor; +} + +void DEntity_loadBrush(DEntity& entity, scene::Node& brush) +{ + DBrush* loadBrush = entity.NewBrush(entity.brushList.size()); + loadBrush->LoadFromBrush(brush, true); +} +typedef ReferenceCaller1 DEntityLoadBrushCaller; + void DEntity::LoadSelectedBrushes() { ClearBrushes(); ClearEPairs(); -#if 0 - int count = g_FuncTable.m_pfnAllocateSelectedBrushHandles(); - - for(int i = 0; i < count; i++) { - brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i); + Scene_forEachSelectedBrush(DEntityLoadBrushCaller(*this)); +} - if(brush->patchBrush) - continue; +template +class PatchSelectedVisitor : public SelectionSystem::Visitor +{ + const Functor& m_functor; +public: + PatchSelectedVisitor(const Functor& functor) : m_functor(functor) + { + } + void visit(scene::Instance& instance) const + { + if(Node_isPatch(instance.path().top())) + { + m_functor(*instance.path().top()); + } + } +}; - DBrush* loadBrush = NewBrush(i); - loadBrush->LoadFromBrush_t(brush, TRUE); - } +template +inline const Functor& Scene_forEachSelectedPatch(const Functor& functor) +{ + GlobalSelectionSystem().foreachSelected(PatchSelectedVisitor(functor)); + return functor; +} - g_FuncTable.m_pfnReleaseSelectedBrushHandles(); -#endif +void DEntity_loadPatch(DEntity& entity, scene::Node& patch) +{ + DPatch* loadPatch = entity.NewPatch(); + loadPatch->LoadFromBrush(patch); } +typedef ReferenceCaller1 DEntityLoadPatchCaller; void DEntity::LoadSelectedPatches() { ClearPatches(); ClearEPairs(); -#if 0 - int count = g_FuncTable.m_pfnAllocateSelectedPatchHandles(); - - for(int i = 0; i < count; i++) - { - //$ FIXME: m_pfnGetPatchHandle - patchMesh_t *pmesh = (patchMesh_t*)g_FuncTable.m_pfnGetPatchData(i); - - DPatch* loadPatch = NewPatch(); - loadPatch->LoadFromBrush_t(pmesh->pSymbiot); - } - - g_FuncTable.m_pfnReleasePatchHandles(); -#endif + Scene_forEachSelectedPatch(DEntityLoadPatchCaller(*this)); } bool* DEntity::BuildIntersectList() @@ -277,15 +313,15 @@ bool* DEntity::BuildIntersectList() bool* pbIntList = new bool[max]; memset(pbIntList, 0, sizeof(bool)*(max)); - for(list::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++) + for(std::list::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++) { - list::const_iterator pB2=pB1; + std::list::const_iterator pB2=pB1; for(pB2++; pB2!=brushList.end(); pB2++) { if((*pB1)->IntersectsWith((*pB2))) { - pbIntList[(*pB1)->m_nBrushID] = TRUE; - pbIntList[(*pB2)->m_nBrushID] = TRUE; + pbIntList[(*pB1)->m_nBrushID] = true; + pbIntList[(*pB2)->m_nBrushID] = true; } } } @@ -302,15 +338,15 @@ bool* DEntity::BuildDuplicateList() bool* pbDupList = new bool[max]; memset(pbDupList, 0, sizeof(bool)*(max)); - for(list::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++) + for(std::list::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++) { - list::const_iterator pB2=pB1; + std::list::const_iterator pB2=pB1; for(pB2++; pB2!=brushList.end(); pB2++) { if(**pB1 == *pB2) { - pbDupList[(*pB1)->m_nBrushID] = TRUE; - pbDupList[(*pB2)->m_nBrushID] = TRUE; + pbDupList[(*pB1)->m_nBrushID] = true; + pbDupList[(*pB2)->m_nBrushID] = true; } } } @@ -323,84 +359,81 @@ void DEntity::SelectBrushes(bool *selectList) if(selectList == NULL) return; - GlobalSelectionSystem().Select(false); + GlobalSelectionSystem().setSelectedAll(false); - scene::Path path(GlobalSceneGraph().root()); - path.push(QER_Entity); + scene::Path path(NodeReference(GlobalSceneGraph().root())); + path.push(NodeReference(*QER_Entity)); for(std::list::const_iterator pBrush=brushList.begin(); pBrush!=brushList.end(); pBrush++) { if(selectList[(*pBrush)->m_nBrushID]) { - path.push((*pBrush)->QER_brush); - GlobalSceneGraph().find(path)->selectable()->select(true); + path.push(NodeReference(*(*pBrush)->QER_brush)); + Instance_getSelectable(*GlobalSceneGraph().find(path))->setSelected(true); path.pop(); } } } -bool DEntity::LoadFromEntity(scene::Node* ent, bool bLoadPatches) { +bool DEntity::LoadFromEntity(scene::Node& ent, bool bLoadPatches) { ClearPatches(); ClearBrushes(); ClearEPairs(); - QER_Entity = ent; + QER_Entity = &ent; - LoadEPairList(ent->m_entity); + LoadEPairList(Node_getEntity(ent)); - bool keep = FALSE; + bool keep = false; int i; for(i = 0; brushEntityList[i]; i++) { - if(!stricmp(brushEntityList[i], m_Classname)) + if(string_equal_nocase(brushEntityList[i], m_Classname)) { - keep = TRUE; + keep = true; break; } } if(!keep) - return FALSE; + return false; - if(ent->m_traverse) + if(Node_getTraversable(ent)) { class load_brushes_t : public scene::Traversable::Walker { DEntity* m_entity; - int m_count; + mutable int m_count; public: load_brushes_t(DEntity* entity) : m_entity(entity), m_count(0) { } - bool pre(scene::Node* node) + bool pre(scene::Node& node) const { - if(node->m_brush) + if(Node_isPatch(node)) { DPatch* loadPatch = m_entity->NewPatch(); loadPatch->LoadFromBrush(node); } - else if(node->m_patch) + else if(Node_isBrush(node)) { DBrush* loadBrush = m_entity->NewBrush(m_count++); - loadBrush->LoadFromBrush(node, TRUE); + loadBrush->LoadFromBrush(node, true); } return false; } - void post(scene::Node* node) - { - } } load_brushes(this); - ent->m_traverse->traverse(load_brushes); + Node_getTraversable(ent)->traverse(load_brushes); } - return TRUE; + return true; } -void DEntity::RemoveNonCheckBrushes(list* exclusionList, bool useDetail) +void DEntity::RemoveNonCheckBrushes(std::list* exclusionList, bool useDetail) { - list::iterator chkBrush=brushList.begin(); + std::list::iterator chkBrush=brushList.begin(); while( chkBrush!=brushList.end() ) { @@ -414,7 +447,7 @@ void DEntity::RemoveNonCheckBrushes(list* exclusionList, bool useDetail) } } - list::iterator eTexture; + std::list::iterator eTexture; for( eTexture=exclusionList->begin(); eTexture!=exclusionList->end(); eTexture++ ) { @@ -431,9 +464,9 @@ void DEntity::RemoveNonCheckBrushes(list* exclusionList, bool useDetail) } } -void DEntity::ResetChecks(list* exclusionList) +void DEntity::ResetChecks(std::list* exclusionList) { - for(list::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++) + for(std::list::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++) { (*resetBrush)->ResetChecks(exclusionList); } @@ -443,7 +476,7 @@ int DEntity::FixBrushes() { int count = 0; - for(list::const_iterator fixBrush=brushList.begin(); fixBrush!=brushList.end(); fixBrush++) + for(std::list::const_iterator fixBrush=brushList.begin(); fixBrush!=brushList.end(); fixBrush++) { count += (*fixBrush)->RemoveRedundantPlanes(); } @@ -457,29 +490,29 @@ void DEntity::BuildInRadiant(bool allowDestruction) if(makeEntity) { - NodePtr node(GlobalEntityCreator().createEntity(m_Classname.GetBuffer())); + NodeReference node(GlobalEntityCreator().createEntity(GlobalEntityClassManager().findOrInsert(m_Classname.GetBuffer(), !brushList.empty() || !patchList.empty()))); - for(list::const_iterator buildEPair=epairList.begin(); buildEPair!=epairList.end(); buildEPair++) + for(std::list::const_iterator buildEPair=epairList.begin(); buildEPair!=epairList.end(); buildEPair++) { - node->m_entity->setkeyvalue((*buildEPair)->key, (*buildEPair)->value); + Node_getEntity(node)->setKeyValue((*buildEPair)->key, (*buildEPair)->value); } - GlobalSceneGraph().root()->m_traverse->insert(node); + Node_getTraversable(GlobalSceneGraph().root())->insert(node); - for(list::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++) - (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node); + for(std::list::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++) + (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node.get_pointer()); - for(list::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++) - (*buildPatch)->BuildInRadiant(node); + for(std::list::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++) + (*buildPatch)->BuildInRadiant(node.get_pointer()); - QER_Entity = node; + QER_Entity = node.get_pointer(); } else { - for(list::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++) + for(std::list::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++) (*buildBrush)->BuildInRadiant(allowDestruction, NULL); - for(list::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++) + for(std::list::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++) (*buildPatch)->BuildInRadiant(); } } @@ -488,7 +521,7 @@ void DEntity::BuildInRadiant(bool allowDestruction) int DEntity::GetIDMax( void ) { int max = -1; - for(list::const_iterator cntBrush=brushList.begin(); cntBrush!=brushList.end(); cntBrush++) { + for(std::list::const_iterator cntBrush=brushList.begin(); cntBrush!=brushList.end(); cntBrush++) { if((*cntBrush)->m_nBrushID > max) max = (*cntBrush)->m_nBrushID; } @@ -505,12 +538,12 @@ void DEntity::SaveToFile(FILE *pFile) fprintf(pFile, "\"classname\" \"%s\"\n", (const char *)m_Classname); - for(list::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++) + for(std::list::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++) { fprintf(pFile, "\"%s\" \"%s\"\n", (const char *)(*ep)->key, (const char *)(*ep)->value); } - for(list::const_iterator bp=brushList.begin(); bp!=brushList.end(); bp++) + for(std::list::const_iterator bp=brushList.begin(); bp!=brushList.end(); bp++) { (*bp)->SaveToFile(pFile); } @@ -520,7 +553,7 @@ void DEntity::SaveToFile(FILE *pFile) void DEntity::ClearEPairs() { - for(list::const_iterator deadEPair=epairList.begin(); deadEPair!=epairList.end(); deadEPair++) + for(std::list::const_iterator deadEPair=epairList.begin(); deadEPair!=epairList.end(); deadEPair++) { delete (*deadEPair); } @@ -559,34 +592,34 @@ void DEntity::LoadEPairList(Entity *epl) } load_epairs(this); - epl->accept(load_epairs); + epl->forEachKeyValue(load_epairs); } bool DEntity::ResetTextures(const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation, bool rebuild) { - bool reset = FALSE; + bool reset = false; - for(list::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++) + for(std::list::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++) { bool tmp = (*resetBrush)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName, bResetTextureName, bResetScale, bResetShift, bResetRotation); if(tmp) { - reset = TRUE; + reset = true; } } if(bResetTextureName) { - for(list::const_iterator resetPatch=patchList.begin(); resetPatch!=patchList.end(); resetPatch++) + for(std::list::const_iterator resetPatch=patchList.begin(); resetPatch!=patchList.end(); resetPatch++) { bool tmp = (*resetPatch)->ResetTextures(textureName, newTextureName); if(tmp) { - reset = TRUE; + reset = true; } } } @@ -596,7 +629,7 @@ bool DEntity::ResetTextures(const char* textureName, float fScale[2], float DEPair* DEntity::FindEPairByKey(const char* keyname) { - for(list::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++) + for(std::list::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++) { char* c = (*ep)->key; if(!strcmp(c, keyname)) @@ -607,7 +640,7 @@ DEPair* DEntity::FindEPairByKey(const char* keyname) void DEntity::RemoveFromRadiant() { - GlobalSceneGraph().root()->m_traverse->erase(QER_Entity); + Node_getTraversable(GlobalSceneGraph().root())->erase(*QER_Entity); QER_Entity = NULL; } @@ -656,10 +689,10 @@ int DEntity::GetBrushCount( void ) { return brushList.size(); } -DBrush* DEntity::FindBrushByPointer( scene::Node* brush ) { - for(list::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) { +DBrush* DEntity::FindBrushByPointer( scene::Node& brush ) { + for(std::list::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) { DBrush* pBrush = (*listBrush); - if(pBrush->QER_brush == brush) { + if(pBrush->QER_brush == &brush) { return pBrush; } } diff --git a/contrib/bobtoolz/DEntity.h b/contrib/bobtoolz/DEntity.h index ba3794de..5baa3d3d 100644 --- a/contrib/bobtoolz/DEntity.h +++ b/contrib/bobtoolz/DEntity.h @@ -28,6 +28,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include +#include "str.h" +#include "mathlib.h" + +class DEPair; +class DBrush; +class DPlane; +class DPatch; +class Entity; + +namespace scene +{ + class Node; +} +class _QERFaceData; + class DEntity { public: @@ -54,12 +70,12 @@ public: int GetIDMax(); void BuildInRadiant(bool allowDestruction); - void ResetChecks(list* exclusionList); - void RemoveNonCheckBrushes(list* exclusionList, bool useDetail); + void ResetChecks(std::list* exclusionList); + void RemoveNonCheckBrushes(std::list* exclusionList, bool useDetail); DPlane* AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID); // slow, try not to use much int GetBrushCount( void ); - DBrush* FindBrushByPointer( scene::Node* brush ); + DBrush* FindBrushByPointer( scene::Node& brush ); // --------------------------------------------- @@ -84,17 +100,17 @@ public: // --------------------------------------------- // vars - list epairList; - list brushList; + std::list epairList; + std::list brushList; // new patches, wahey!!! - list patchList; + std::list patchList; Str m_Classname; // --------------------------------------------- int FixBrushes(); - bool LoadFromEntity(scene::Node* ent, bool bLoadPatches = FALSE); + bool LoadFromEntity(scene::Node& ent, bool bLoadPatches = false); void LoadSelectedBrushes(); void LoadSelectedPatches(); diff --git a/contrib/bobtoolz/DListener.cpp b/contrib/bobtoolz/DListener.cpp index cd688f46..3d04a423 100644 --- a/contrib/bobtoolz/DListener.cpp +++ b/contrib/bobtoolz/DListener.cpp @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" #include "DListener.h" ////////////////////////////////////////////////////////////////////// diff --git a/contrib/bobtoolz/DMap.cpp b/contrib/bobtoolz/DMap.cpp index 382a0254..18e43188 100644 --- a/contrib/bobtoolz/DMap.cpp +++ b/contrib/bobtoolz/DMap.cpp @@ -21,10 +21,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DMap.h" #include "str.h" -#include "gtkr_list.h" +#include #include "DPoint.h" #include "DPlane.h" @@ -32,11 +32,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DEPair.h" #include "DPatch.h" #include "DEntity.h" -#include "DMap.h" #include "iundo.h" -#include "refcounted_ptr.h" +#include "generic/referencecounted.h" #include #include @@ -78,7 +77,7 @@ void DMap::ClearEntities() { m_nNextEntity = 1; - for(list::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++) + for(std::list::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++) delete *deadEntity; entityList.clear(); @@ -88,7 +87,7 @@ DEntity* DMap::GetEntityForID(int ID) { DEntity* findEntity = NULL; - for(list::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++) + for(std::list::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++) { if((*chkEntity)->m_nID == ID) { @@ -111,7 +110,7 @@ DEntity* DMap::GetWorldSpawn() void DMap::BuildInRadiant(bool bAllowDestruction) { - for(list::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++) + for(std::list::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++) (*buildEntity)->BuildInRadiant(bAllowDestruction); } @@ -119,7 +118,7 @@ void DMap::LoadAll(bool bLoadPatches) { ClearEntities(); - GlobalSelectionSystem().Select(false); + GlobalSelectionSystem().setSelectedAll(false); class load_entities_t : public scene::Traversable::Walker { @@ -130,27 +129,24 @@ void DMap::LoadAll(bool bLoadPatches) : m_map(map), m_bLoadPatches(bLoadPatches) { } - bool pre(scene::Node* node) + bool pre(scene::Node& node) const { - if(node->m_entity) + if(Node_isEntity(node)) { DEntity* loadEntity = m_map->AddEntity("", 0); loadEntity->LoadFromEntity(node, m_bLoadPatches); } return false; } - void post(scene::Node* node) - { - } } load_entities(this, bLoadPatches); - GlobalSceneGraph().root()->m_traverse->traverse(load_entities); + Node_getTraversable(GlobalSceneGraph().root())->traverse(load_entities); } int DMap::FixBrushes() { int count = 0; - for(list::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++) + for(std::list::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++) { count += (*fixEntity)->FixBrushes(); } @@ -161,15 +157,15 @@ int DMap::FixBrushes() void DMap::ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation) { - for(list::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++) + for(std::list::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++) { - if(!stricmp("worldspawn", (*texEntity)->m_Classname)) + if(string_equal_nocase("worldspawn", (*texEntity)->m_Classname)) (*texEntity)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName, - bResetTextureName, bResetScale, bResetShift, bResetRotation, TRUE); + bResetTextureName, bResetScale, bResetShift, bResetRotation, true); else { if((*texEntity)->ResetTextures( textureName, fScale, fShift, rotation, newTextureName, - bResetTextureName, bResetScale, bResetShift, bResetRotation, FALSE)) + bResetTextureName, bResetScale, bResetShift, bResetRotation, false)) RebuildEntity(*texEntity); } } @@ -178,5 +174,5 @@ void DMap::ResetTextures( const char* textureName, float fScale[2], float f void DMap::RebuildEntity(DEntity *ent) { ent->RemoveFromRadiant(); - ent->BuildInRadiant(FALSE); + ent->BuildInRadiant(false); } diff --git a/contrib/bobtoolz/DMap.h b/contrib/bobtoolz/DMap.h index 75682340..970b958a 100644 --- a/contrib/bobtoolz/DMap.h +++ b/contrib/bobtoolz/DMap.h @@ -28,13 +28,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include + +class DEntity; + class DMap { public: static void RebuildEntity(DEntity* ent); void ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation); - void LoadAll(bool bLoadPatches = FALSE); + void LoadAll(bool bLoadPatches = false); void BuildInRadiant(bool bAllowDestruction); int m_nNextEntity; DEntity* GetWorldSpawn(); @@ -43,7 +47,7 @@ public: DEntity* DMap::GetEntityForID(int ID); DEntity* AddEntity(char* classname = "worldspawn", int ID = -1); - list entityList; + std::list entityList; DMap(); virtual ~DMap(); diff --git a/contrib/bobtoolz/DPatch.cpp b/contrib/bobtoolz/DPatch.cpp index 50bca9fa..2158eff7 100644 --- a/contrib/bobtoolz/DPatch.cpp +++ b/contrib/bobtoolz/DPatch.cpp @@ -21,17 +21,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DPatch.h" -#include "gtkr_list.h" +#include #include "str.h" +#include "scenelib.h" -//#include "DPoint.h" -//#include "DPlane.h" -//#include "DBrush.h" -//#include "DEPair.h" -#include "DPatch.h" -//#include "DEntity.h" +#include "ipatch.h" #include "misc.h" #include "./dialogs/dialogs-gtk.h" @@ -73,8 +69,15 @@ void CopyDrawVert(const drawVert_t* in, drawVert_t* out) VectorCopy(in->xyz, out->xyz); } -void DPatch::BuildInRadiant(void* entity) +void DPatch::BuildInRadiant(scene::Node* entity) { + NodeSmartReference node(GlobalPatchCreator().createPatch()); + + if(entity) { + Node_getTraversable(*entity)->insert(node); + } else { + Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(node); + } #if 0 int nIndex = g_FuncTable.m_pfnCreatePatchHandle(); //$ FIXME: m_pfnGetPatchHandle @@ -113,7 +116,7 @@ void DPatch::BuildInRadiant(void* entity) // strcpy(pm->d_texture->name, texture); brush_t* brush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle(); - brush->patchBrush = TRUE; + brush->patchBrush = true; brush->pPatch = pm; pm->pSymbiot = brush; @@ -135,9 +138,9 @@ void DPatch::BuildInRadiant(void* entity) #endif } -void DPatch::LoadFromBrush(scene::Node* brush) +void DPatch::LoadFromBrush(scene::Node& brush) { - QER_brush = brush; + QER_brush = &brush; #if 0 SetTexture(brush->pPatch->GetShader()); @@ -160,25 +163,15 @@ void DPatch::LoadFromBrush(scene::Node* brush) #endif } -void DPatch::RemoveFromRadiant() -{ - if(QER_brush) - { -#if 0 - g_FuncTable.m_pfnDeleteBrushHandle(QER_brush); -#endif - } -} - bool DPatch::ResetTextures(const char *oldTextureName, const char *newTextureName) { if( !oldTextureName || !strcmp(texture, oldTextureName)) { strcpy(texture, newTextureName); - return TRUE; + return true; } - return FALSE; + return false; } void Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT], @@ -205,8 +198,8 @@ void Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HE void Print1dArray(vec3_t* array, int size) { for(int i = 0; i < size; i++) - Sys_Printf("(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t"); - Sys_Printf("\n"); + globalOutputStream() << "(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t"; + globalOutputStream() << "\n"; } bool Compare1dArrays(vec3_t* a1, vec3_t* a2, int size) @@ -391,9 +384,9 @@ void DPatch::Transpose() Invert(); } -list DPatch::Split(bool rows, bool cols) +std::list DPatch::Split(bool rows, bool cols) { - list patchList; + std::list patchList; int i; int x, y; @@ -419,13 +412,13 @@ list DPatch::Split(bool rows, bool cols) if(cols && width >= 5) { - list patchList2; + std::list patchList2; - for(list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) + for(std::list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) { - list patchList3 = (*patches).Split(false, true); + std::list patchList3 = (*patches).Split(false, true); - for(list::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) + for(std::list::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++) patchList2.push_front(*patches2); } diff --git a/contrib/bobtoolz/DPatch.h b/contrib/bobtoolz/DPatch.h index 4d85e909..d1442ce4 100644 --- a/contrib/bobtoolz/DPatch.h +++ b/contrib/bobtoolz/DPatch.h @@ -24,10 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #if !defined(AFX_DPATCH_H__26C6B083_CE5B_420B_836B_1DDA733C04CE__INCLUDED_) #define AFX_DPATCH_H__26C6B083_CE5B_420B_836B_1DDA733C04CE__INCLUDED_ -#include "StdAfx.h" // Added by ClassView -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 +#include typedef struct { @@ -43,7 +40,10 @@ typedef struct { float lightmap[2]; } drawVert_t; -class Patch; +namespace scene +{ + class Node; +} #define MAX_PATCH_WIDTH 16 #define MAX_PATCH_HEIGHT 16 @@ -53,16 +53,15 @@ class Patch; class DPatch { public: - list Split(bool rows, bool cols); + std::list Split(bool rows, bool cols); void Transpose(); void Invert(); DPatch* MergePatches(patch_merge_t merge_info, DPatch* p1, DPatch* p2); patch_merge_t IsMergable(DPatch* other); bool ResetTextures(const char *oldTextureName, const char *newTextureName); - void RemoveFromRadiant(void); scene::Node* QER_brush; - void LoadFromBrush(scene::Node* brush); - void BuildInRadiant(void* entity = NULL); + void LoadFromBrush(scene::Node& brush); + void BuildInRadiant(scene::Node* entity = NULL); void SetTexture(const char* textureName); char texture[256]; int width, height; diff --git a/contrib/bobtoolz/DPlane.cpp b/contrib/bobtoolz/DPlane.cpp index f5776839..c9c7b67f 100644 --- a/contrib/bobtoolz/DPlane.cpp +++ b/contrib/bobtoolz/DPlane.cpp @@ -21,12 +21,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DPlane.h" -#include "gtkr_list.h" +#include #include "DPoint.h" -#include "DPlane.h" #include "DWinding.h" #include "str.h" @@ -36,11 +35,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Construction/Destruction ////////////////////////////////////////////////////////////////////// -DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData) +DPlane::DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData) { MakeNormal( va, vb, vc, normal ); if(VectorNormalize(normal, normal) == 0) // normalizes and returns length - Sys_ERROR("DPlane::DPlane: Bad Normal.\n"); + globalErrorStream() << "DPlane::DPlane: Bad Normal.\n"; _d = (normal[0]*va[0]) + (normal[1]*va[1]) + (normal[2]*va[2]); @@ -48,7 +47,7 @@ DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData) VectorCopy(vb, points[1]); VectorCopy(vc, points[2]); - m_bChkOk = TRUE; + m_bChkOk = true; if(texData) memcpy(&texInfo, texData, sizeof(_QERFaceData)); @@ -85,7 +84,7 @@ bool DPlane::PlaneIntersection(DPlane *pl1, DPlane *pl2, vec3_t out) float d = Determinant3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3); if(d == 0) - return FALSE; + return false; float v1 = _d; float v2 = pl1->_d; @@ -99,23 +98,23 @@ bool DPlane::PlaneIntersection(DPlane *pl1, DPlane *pl2, vec3_t out) out[1] = d2/d; out[2] = d3/d; - return TRUE; + return true; } -bool DPlane::IsRedundant(list& pointList) +bool DPlane::IsRedundant(std::list& pointList) { int cnt = 0; - //list::const_iterator point=pointList.begin(); - for(list::const_iterator point=pointList.begin(); point!=pointList.end(); point++) + //std::list::const_iterator point=pointList.begin(); + for(std::list::const_iterator point=pointList.begin(); point!=pointList.end(); point++) { if(fabs(DistanceToPoint((*point)->_pnt)) < MAX_ROUND_ERROR) cnt++; if(cnt == 3) - return FALSE; + return false; } - return TRUE; + return true; } bool DPlane::operator == (DPlane& other) @@ -123,12 +122,12 @@ bool DPlane::operator == (DPlane& other) vec3_t chk; VectorSubtract(other.normal, normal, chk); if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR) - return FALSE; + return false; if(fabs(other._d - _d) > MAX_ROUND_ERROR) - return FALSE; + return false; - return TRUE; + return true; } bool DPlane::operator != (DPlane& other) @@ -136,9 +135,9 @@ bool DPlane::operator != (DPlane& other) vec3_t chk; VectorAdd(other.normal, normal, chk); if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR) - return FALSE; + return false; - return TRUE; + return true; } DWinding* DPlane::BaseWindingForPlane() @@ -161,7 +160,7 @@ DWinding* DPlane::BaseWindingForPlane() } } if (x==-1) - Sys_Printf ("BaseWindingForPlane: no axis found"); + globalOutputStream() << "BaseWindingForPlane: no axis found"; VectorCopy (vec3_origin, vup); switch (x) @@ -213,7 +212,7 @@ void DPlane::Rebuild() CrossProduct(v1, v2, normal); if(VectorNormalize(normal, normal) == 0) // normalizes and returns length - Sys_ERROR("DPlane::Rebuild: Bad Normal.\n"); + globalErrorStream() << "DPlane::Rebuild: Bad Normal.\n"; _d = (normal[0]*points[0][0]) + (normal[1]*points[0][1]) + (normal[2]*points[0][2]); @@ -222,25 +221,30 @@ void DPlane::Rebuild() VectorCopy(points[2], texInfo.m_p2); } -bool DPlane::AddToBrush(Brush *brush) +bool DPlane::AddToBrush(scene::Node& brush) { -#if 0 - if(m_bChkOk || !strcmp(texInfo.m_TextureName, "textures/common/caulk")) - { - brush->addPlane(m_p0, m_p1, m_p2, m_texdef, false); - return FALSE; - } - - strcpy(texInfo.m_TextureName, "textures/common/caulk"); - brush->addPlane(m_p0, m_p1, m_p2, m_texdef, false); -#endif - return TRUE; + bool changed = false; + if(!(m_bChkOk || !strcmp(m_shader.c_str(), "textures/common/caulk"))) + { + m_shader = "textures/common/caulk"; + changed = true; + } + + _QERFaceData faceData; + faceData.m_p0 = vector3_from_array(points[0]); + faceData.m_p1 = vector3_from_array(points[1]); + faceData.m_p2 = vector3_from_array(points[2]); + faceData.m_texdef = texInfo.m_texdef; + faceData.m_shader = m_shader.c_str(); + GlobalBrushCreator().addBrushFace(brush, faceData); + + return changed; } void DPlane::ScaleTexture() { } -DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bDetail) +DPlane::DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail) { vec3_t v1, v2; VectorSubtract(va, vb, v1); @@ -248,7 +252,7 @@ DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bD CrossProduct(v1, v2, normal); if(VectorNormalize(normal, normal) == 0) // normalizes and returns length - Sys_ERROR("DPlane::DPlane: Bad Normal.\n"); + globalErrorStream() << "DPlane::DPlane: Bad Normal.\n"; _d = (normal[0]*va[0]) + (normal[1]*va[1]) + (normal[2]*va[2]); @@ -256,9 +260,9 @@ DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bD VectorCopy(vb, points[1]); VectorCopy(vc, points[2]); - m_bChkOk = TRUE; + m_bChkOk = true; FillDefaultTexture(&texInfo, points[0], points[1], points[2], textureName); if(bDetail) - texInfo.m_texdef.contents |= FACE_DETAIL; + texInfo.contents |= FACE_DETAIL; } diff --git a/contrib/bobtoolz/DPlane.h b/contrib/bobtoolz/DPlane.h index 11c3f685..68db6ed9 100644 --- a/contrib/bobtoolz/DPlane.h +++ b/contrib/bobtoolz/DPlane.h @@ -24,7 +24,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #if !defined(AFX_DPLANE_H__FC37C021_F0A1_11D4_ACF7_004095A18133__INCLUDED_) #define AFX_DPLANE_H__FC37C021_F0A1_11D4_ACF7_004095A18133__INCLUDED_ +#include +#include "ibrush.h" +#include "string/string.h" +#include "mathlib.h" + class Brush; +class DPoint; #define FACE_DETAIL 0x8000000 @@ -37,27 +43,28 @@ class DWinding; class DPlane { public: - DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bDetail); + DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail); void ScaleTexture(); DWinding* BaseWindingForPlane(); void Rebuild(); - bool AddToBrush(Brush *brush); + bool AddToBrush(scene::Node& brush); bool operator != (DPlane& other); bool operator == (DPlane& other); - bool IsRedundant(list& pointList); + bool IsRedundant(std::list& pointList); bool PlaneIntersection(DPlane* pl1, DPlane* pl2, vec3_t out);; vec_t DistanceToPoint(vec3_t pnt); - DPlane(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData); + DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData); DPlane() { } virtual ~DPlane(); bool m_bChkOk; _QERFaceData texInfo; + CopiedString m_shader; vec3_t points[3]; // djbob:do we really need these any more? vec3_t normal; float _d; diff --git a/contrib/bobtoolz/DPoint.cpp b/contrib/bobtoolz/DPoint.cpp index a56e91f0..b0b60153 100644 --- a/contrib/bobtoolz/DPoint.cpp +++ b/contrib/bobtoolz/DPoint.cpp @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" #include "DPoint.h" +#include "misc.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -47,6 +47,6 @@ bool DPoint::operator ==(vec3_t other) vec3_t test; VectorSubtract(other, _pnt, test); if(fabs(VectorLength(test)) > MAX_ROUND_ERROR) - return FALSE; - return TRUE; + return false; + return true; } diff --git a/contrib/bobtoolz/DPoint.h b/contrib/bobtoolz/DPoint.h index 394352cf..12137341 100644 --- a/contrib/bobtoolz/DPoint.h +++ b/contrib/bobtoolz/DPoint.h @@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include "mathlib.h" + class DPoint { public: diff --git a/contrib/bobtoolz/DShape.cpp b/contrib/bobtoolz/DShape.cpp index ebe2c0da..9201d29c 100644 --- a/contrib/bobtoolz/DShape.cpp +++ b/contrib/bobtoolz/DShape.cpp @@ -21,9 +21,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DShape.h" -#include "gtkr_list.h" +#include +#include #include "str.h" #include "DPoint.h" @@ -32,7 +33,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DEPair.h" #include "DPatch.h" #include "DEntity.h" -#include "DShape.h" //#include "dialogs-gtk.h" @@ -43,7 +43,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // Construction/Destruction ////////////////////////////////////////////////////////////////////// -bool bFacesAll[6] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE}; +bool bFacesAll[6] = {true, true, true, true, true, true}; DShape::DShape() { @@ -104,16 +104,16 @@ void DShape::BuildRegularPrism(vec3_t min, vec3_t max, int nSides, bool bAlignTo DBrush* pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++); for(i = 1; i <= nSides; i++) - pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE); + pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), false); - pB->AddFace(vc[2], vc[1], vc[0], "textures/common/caulk", FALSE); - pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", FALSE); + pB->AddFace(vc[2], vc[1], vc[0], "textures/common/caulk", false); + pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", false); } void DShape::Commit() { m_Container.GetWorldSpawn()->FixBrushes(); - m_Container.BuildInRadiant(TRUE); + m_Container.BuildInRadiant(true); } void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop) @@ -180,11 +180,11 @@ void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTo if(top[1] != bottom[1]) // internal line is flat already if true { - pB->AddFace(va[i-1], top, vb[i-1], "textures/common/caulk", FALSE); - pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", FALSE); + pB->AddFace(va[i-1], top, vb[i-1], "textures/common/caulk", false); + pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", false); } // add cut-off planes - pB->AddFace(va[i-1], vb[i-1], vb[i], GetCurrentTexture(), FALSE); + pB->AddFace(va[i-1], vb[i-1], vb[i], GetCurrentTexture(), false); // add internal polygon plane } } @@ -264,11 +264,11 @@ void DShape::BuildBorderedPrism(vec3_t min, vec3_t max, int nSides, int nBorder, { DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk"); - pB->AddFace(origin, vc[i-1], vd[i-1], "textures/common/caulk", FALSE); - pB->AddFace(origin, vd[i], vc[i], "textures/common/caulk", FALSE); + pB->AddFace(origin, vc[i-1], vd[i-1], "textures/common/caulk", false); + pB->AddFace(origin, vd[i], vc[i], "textures/common/caulk", false); - pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE); - pB->AddFace(vb[i], va[i], va[i-1], GetCurrentTexture(), FALSE); + pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), false); + pB->AddFace(vb[i], va[i], va[i-1], GetCurrentTexture(), false); } } @@ -343,18 +343,18 @@ DBrush* DShape::GetBoundingCube(vec3_t min, vec3_t max, const char *textureName, //----- Add Six Cube Faces --------- if(bUseFaces[0]) - pB->AddFace(v1, v2, v3, textureName, FALSE); + pB->AddFace(v1, v2, v3, textureName, false); if(bUseFaces[1]) - pB->AddFace(v1, v3, v6, textureName, FALSE); + pB->AddFace(v1, v3, v6, textureName, false); if(bUseFaces[2]) - pB->AddFace(v1, v7, v2, textureName, FALSE); + pB->AddFace(v1, v7, v2, textureName, false); if(bUseFaces[3]) - pB->AddFace(v5, v6, v3, textureName, FALSE); + pB->AddFace(v5, v6, v3, textureName, false); if(bUseFaces[4]) - pB->AddFace(v5, v2, v7, textureName, FALSE); + pB->AddFace(v5, v2, v7, textureName, false); if(bUseFaces[5]) - pB->AddFace(v5, v7, v6, textureName, FALSE); + pB->AddFace(v5, v7, v6, textureName, false); //---------------------------------- @@ -364,7 +364,7 @@ DBrush* DShape::GetBoundingCube(vec3_t min, vec3_t max, const char *textureName, bool DShape::BuildPit(vec3_t min, vec3_t max) { if((max[2] - min[2]) < 196) - return FALSE; + return false; srand(time(NULL)); @@ -465,5 +465,5 @@ bool DShape::BuildPit(vec3_t min, vec3_t max) // ****** END NODROP ******** - return TRUE; + return true; } diff --git a/contrib/bobtoolz/DShape.h b/contrib/bobtoolz/DShape.h index 4bc4baa8..3c4ed75e 100644 --- a/contrib/bobtoolz/DShape.h +++ b/contrib/bobtoolz/DShape.h @@ -24,13 +24,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #if !defined(AFX_DSHAPE_H__0B30B302_9D21_4C2D_836A_61F3C8D4244D__INCLUDED_) #define AFX_DSHAPE_H__0B30B302_9D21_4C2D_836A_61F3C8D4244D__INCLUDED_ -#include "DMap.h" // Added by ClassView -#include "StdAfx.h" // Added by ClassView - #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 +#include "mathlib.h" +#include "DMap.h" +class DBrush; +class DEntity; + // defines for polygon stuff #define MAX_POLYGON_FACES 128 diff --git a/contrib/bobtoolz/DTrainDrawer.cpp b/contrib/bobtoolz/DTrainDrawer.cpp index 35ee494d..38abb659 100644 --- a/contrib/bobtoolz/DTrainDrawer.cpp +++ b/contrib/bobtoolz/DTrainDrawer.cpp @@ -17,9 +17,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" +#include "DTrainDrawer.h" -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" @@ -28,31 +28,33 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DEPair.h" #include "DPatch.h" #include "DEntity.h" -#include "DTrainDrawer.h" #include "misc.h" #include "funchandlers.h" +#include "iglrender.h" +#include "math/matrix.h" + #include "dialogs/dialogs-gtk.h" DTrainDrawer::DTrainDrawer() { - refCount = 1; - m_bHooked = FALSE; - m_bDisplay = FALSE; + m_bDisplay = false; BuildPaths(); + constructShaders(); + GlobalShaderCache().attachRenderable(*this); } DTrainDrawer::~DTrainDrawer(void) { - if(m_bHooked) - UnRegister(); + GlobalShaderCache().detachRenderable(*this); + destroyShaders(); ClearPoints(); ClearSplines(); } void DTrainDrawer::ClearSplines() { - for(list::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) { + for(std::list::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) { (*deadSpline)->m_pointList.clear(); (*deadSpline)->m_vertexList.clear(); delete (*deadSpline); @@ -62,25 +64,13 @@ void DTrainDrawer::ClearSplines() { } void DTrainDrawer::ClearPoints() { - for(list::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) { + for(std::list::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) { delete *deadPoint; } m_pointList.clear(); } -void DTrainDrawer::Register() { - __QGLTABLENAME.m_pfnHookGL2DWindow( this ); - __QGLTABLENAME.m_pfnHookGL3DWindow( this ); - m_bHooked = TRUE; -} - -void DTrainDrawer::UnRegister() { - __QGLTABLENAME.m_pfnUnHookGL2DWindow( this ); - __QGLTABLENAME.m_pfnUnHookGL3DWindow( this ); - m_bHooked = FALSE; -} - void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) { vec3_t dist; @@ -106,93 +96,70 @@ void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) { delete[] v2; } -void DTrainDrawer::Draw3D() { - - if(!m_bDisplay) { - return; - } - - __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); - - __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH); - - __QGLTABLENAME.m_pfn_qglPushMatrix(); - - __QGLTABLENAME.m_pfn_qglLineWidth(2.0f); - __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH); - - __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS); - - for(list::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { +void DTrainDrawer::render(RenderStateFlags state) const +{ + for(std::list::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { splinePoint_t* pSP = (*sp); - __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP); - for(list::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) { - __QGLTABLENAME.m_pfn_qglVertex3fv((*v)._pnt); + glBegin(GL_LINE_STRIP); + for(std::list::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) { + glVertex3fv((*v)._pnt); } - __QGLTABLENAME.m_pfn_qglEnd(); + glEnd(); } - - __QGLTABLENAME.m_pfn_qglPopMatrix(); - __QGLTABLENAME.m_pfn_qglPopAttrib(); } -void DTrainDrawer::Draw2D(VIEWTYPE vt) { +const char* DTrainDrawer_state_wireframe = "$bobtoolz/traindrawer/wireframe"; +const char* DTrainDrawer_state_solid = "$bobtoolz/traindrawer/solid"; - if(!m_bDisplay) { - return; - } - - __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); - - __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH); - - __QGLTABLENAME.m_pfn_qglPushMatrix(); - - switch(vt) - { - case XY: - break; - case XZ: - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f); - break; - case YZ: - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f); - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f); - break; - } - - __QGLTABLENAME.m_pfn_qglLineWidth(1.0f); - __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f); - - __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH); - - __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS); - - __QGLTABLENAME.m_pfn_qglColor4f(1.f, 0.f, 0.f, 1.f); +void DTrainDrawer::constructShaders() +{ + OpenGLState state; + GlobalOpenGLStateLibrary().getDefaultState(state); + state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_BLEND; + state.m_sort = OpenGLState::eSortOverlayFirst; + state.m_linewidth = 1; + state.m_colour[0] = 1; + state.m_colour[1] = 0; + state.m_colour[2] = 0; + state.m_colour[3] = 1; + state.m_linewidth = 1; + GlobalOpenGLStateLibrary().insert(DTrainDrawer_state_wireframe, state); + + state.m_colour[0] = 1; + state.m_colour[1] = 1; + state.m_colour[2] = 1; + state.m_colour[3] = 1; + state.m_linewidth = 2; + GlobalOpenGLStateLibrary().insert(DTrainDrawer_state_solid, state); + + m_shader_wireframe = GlobalShaderCache().capture(DTrainDrawer_state_wireframe); + m_shader_solid = GlobalShaderCache().capture(DTrainDrawer_state_solid); +} - for(list::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { - splinePoint_t* pSP = (*sp); +void DTrainDrawer::destroyShaders() +{ + GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_wireframe); + GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_solid); + GlobalShaderCache().release(DTrainDrawer_state_wireframe); + GlobalShaderCache().release(DTrainDrawer_state_solid); +} - __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP); - for(list::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) { - __QGLTABLENAME.m_pfn_qglVertex3fv((*v)._pnt); - } - __QGLTABLENAME.m_pfn_qglEnd(); +void DTrainDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const +{ + if(!m_bDisplay) { + return; } - __QGLTABLENAME.m_pfn_qglPopMatrix(); - __QGLTABLENAME.m_pfn_qglPopAttrib(); + renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly); + renderer.SetState(m_shader_solid, Renderer::eFullMaterials); + renderer.addRenderable(*this, g_matrix4_identity); +} +void DTrainDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const +{ + renderSolid(renderer, volume); } void AddSplineControl(const char* control, splinePoint_t* pSP) { @@ -263,7 +230,7 @@ void DTrainDrawer::BuildPaths() { } } - list::const_iterator sp; + std::list::const_iterator sp; for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { splinePoint_t* pSP = (*sp); @@ -278,7 +245,7 @@ void DTrainDrawer::BuildPaths() { pSP->pTarget = pTarget; - for(list::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) { + for(std::list::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) { controlPoint_t* pControl = FindControlPoint( (*cp).strName ); if(!pControl) { Sys_Printf( "couldn't find control %s", (*cp).strName ); @@ -306,7 +273,7 @@ void DTrainDrawer::BuildPaths() { VectorCopy(pSP->point.vOrigin, v[0]); int i = 1; - for(list::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) { + for(std::list::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) { VectorCopy((*cp).vOrigin, v[i]); i++; } @@ -350,13 +317,13 @@ splinePoint_t* DTrainDrawer::AddSplinePoint(const char* name, const char* target controlPoint_t* DTrainDrawer::FindControlPoint(const char* name) { - for(list::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) { + for(std::list::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) { if(!strcmp(name, (*cp)->strName)) { return (*cp); } } - for(list::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { + for(std::list::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { if(!strcmp(name, (*sp)->point.strName)) { return &((*sp)->point); } diff --git a/contrib/bobtoolz/DTrainDrawer.h b/contrib/bobtoolz/DTrainDrawer.h index ae9fa2c0..9d8903ee 100644 --- a/contrib/bobtoolz/DTrainDrawer.h +++ b/contrib/bobtoolz/DTrainDrawer.h @@ -29,6 +29,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include +#include "mathlib.h" + +#include "irender.h" +#include "renderable.h" + +class DPoint; +class Shader; + typedef struct { char strName[64]; @@ -41,34 +50,33 @@ typedef struct { char strControl[64]; char strTarget[64]; - list m_pointList; - list m_vertexList; + std::list m_pointList; + std::list m_vertexList; controlPoint_t* pTarget; } splinePoint_t; -class DTrainDrawer : - public IGL2DWindow, - public IGL3DWindow +class DTrainDrawer : public Renderable, public OpenGLRenderable { private: - list m_splineList; - list m_pointList; - int refCount; + std::list m_splineList; + std::list m_pointList; - bool m_bHooked; bool m_bDisplay; + Shader* m_shader_wireframe; + Shader* m_shader_solid; public: - void UnRegister(); - void Register(); DTrainDrawer(); virtual ~DTrainDrawer(void); - void Draw3D(); - void Draw2D(VIEWTYPE vt); - void IncRef() { refCount++; } - void DecRef() { refCount--; if (refCount <= 0) delete this; } + void render(RenderStateFlags state) const; + void renderSolid(Renderer& renderer, const VolumeTest& volume) const; + void renderWireframe(Renderer& renderer, const VolumeTest& volume) const; + + void constructShaders(); + void destroyShaders(); + void ClearSplines(); void ClearPoints(); void BuildPaths(); diff --git a/contrib/bobtoolz/DTreePlanter.cpp b/contrib/bobtoolz/DTreePlanter.cpp index 237c9ccf..54850ceb 100644 --- a/contrib/bobtoolz/DTreePlanter.cpp +++ b/contrib/bobtoolz/DTreePlanter.cpp @@ -17,9 +17,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" +#include "DTreePlanter.h" -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" @@ -32,17 +32,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "ScriptParser.h" #include "misc.h" -#include "DTreePlanter.h" #include "funchandlers.h" -bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { - VIEWTYPE vt = m_XYWrapper->GetViewType(); +SignalHandlerResult DTreePlanter::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers) +{ + if(button != c_buttonLeft) + { + return SIGNAL_CONTINUE_EMISSION; + } + VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType(); switch(vt) { case XY: @@ -50,14 +50,14 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { case YZ: case XZ: default: - return false; + return SIGNAL_CONTINUE_EMISSION; } - vec3_t pt, vhit; + Vector3 pt, vhit; - m_XYWrapper->SnapToGrid( static_cast(x), static_cast(y), pt ); + pt = vector3_snapped(GlobalRadiant().XYWindow_windowToWorld(position)); - if(FindDropPoint(pt, vhit)) { + if(FindDropPoint(vector3_to_array(pt), vector3_to_array(vhit))) { vhit[2] += m_offset; char buffer[128]; @@ -96,7 +96,7 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { e2.LoadFromEntity(lastEntNum, TRUE); e2.AddEPair("target", buffer); e2.RemoveFromRadiant(); - e2.BuildInRadiant(FALSE); + e2.BuildInRadiant(false); } #endif } @@ -121,34 +121,14 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { e.AddEPair("modelscale", buffer); } - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } if(m_autoLink) { DoTrainPathPlot(); } - return true; -} - -bool DTreePlanter::OnLButtonUp(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnRButtonDown(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnMButtonDown(guint32 nFlags, gdouble x, gdouble y) { - return false; -} - -bool DTreePlanter::OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) { - return false; + return SIGNAL_STOP_EMISSION; } bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) { @@ -226,7 +206,7 @@ void DTreePlanter::DropEntsToGround( void ) { sprintf( buffer, "%f %f %f", out[0], out[1], out[2] ); ent.AddEPair( "origin", buffer ); ent.RemoveFromRadiant(); - ent.BuildInRadiant(FALSE); + ent.BuildInRadiant(false); } g_FuncTable.m_pfnReleaseSelectedBrushHandles(); @@ -254,7 +234,7 @@ void DTreePlanter::MakeChain( void ) { e.AddEPair( "control", buffer ); } - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } for(i = 0; i < m_linkNum-1; i++) { @@ -266,7 +246,7 @@ void DTreePlanter::MakeChain( void ) { sprintf( buffer, "0 %i 0", (i * 64) + 32); e.AddEPair( "origin", buffer ); - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } } @@ -290,7 +270,7 @@ void DTreePlanter::SelectChain( void ) { e.AddEPair( "control", buffer ); } - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); } for(int i = 0; i < m_linkNum-1; i++) { @@ -302,6 +282,6 @@ void DTreePlanter::SelectChain( void ) { sprintf( buffer, "0 %i 0", (i * 64) + 32); e.AddEPair( "origin", buffer ); - e.BuildInRadiant( FALSE ); + e.BuildInRadiant( false ); }*/ } diff --git a/contrib/bobtoolz/DTreePlanter.h b/contrib/bobtoolz/DTreePlanter.h index 87d0d6c8..61bc1e89 100644 --- a/contrib/bobtoolz/DTreePlanter.h +++ b/contrib/bobtoolz/DTreePlanter.h @@ -20,6 +20,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #ifndef __DTREE_H__ #define __DTREE_H__ +#include "qerplugin.h" +#include "signal/isignal.h" +#include "string/string.h" + +#include "DEntity.h" +#include "scriptparser.h" +#include "mathlib.h" +#include "misc.h" #define MAX_QPATH 64 @@ -29,23 +37,13 @@ typedef struct treeModel_s { #define MAX_TP_MODELS 256 -class DTreePlanter : public IWindowListener { +class DTreePlanter { + MouseEventHandlerId m_mouseDown; public: - virtual bool OnMouseMove(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnLButtonDown(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnMButtonDown(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnRButtonDown(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnLButtonUp(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y); - virtual bool OnKeyPressed(char *s) { return false; } - virtual bool Paint() { return true; } - virtual void Close() { } - - DTreePlanter() { - m_refCount = 1; - m_hooked = false; - m_XYWrapper = NULL; + SignalHandlerResult mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers); + typedef Member3 MouseDownCaller; + + DTreePlanter() { m_numModels = 0; m_offset = 0; m_maxPitch = 0; @@ -57,8 +55,6 @@ public: m_autoLink = false; m_linkNum = 0; - Register(); - m_world.LoadSelectedBrushes(); char buffer[256]; @@ -85,9 +81,16 @@ public: fclose( file ); } + + m_mouseDown = GlobalRadiant().XYWindowMouseDown_connect(makeSignalHandler3(MouseDownCaller(), *this)); } -#define MT(t) !stricmp( pToken, t ) + virtual ~DTreePlanter() + { + GlobalRadiant().XYWindowMouseDown_disconnect(m_mouseDown); + } + +#define MT(t) string_equal_nocase( pToken, t ) #define GT pToken = pScriptParser->GetToken( true ) #define CT if(!*pToken) { return; } @@ -161,41 +164,16 @@ public: } while( true ); } - virtual ~DTreePlanter() { - UnRegister(); - } - - virtual void IncRef() { m_refCount++; } - virtual void DecRef() { m_refCount--; if (m_refCount <= 0) delete this; } - - void Register() { - if(!m_hooked) { - g_MessageTable.m_pfnHookWindow( this ); - m_XYWrapper = g_MessageTable.m_pfnGetXYWndWrapper(); - m_hooked = true; - } - } - - void UnRegister() { - if(m_hooked) { - g_MessageTable.m_pfnUnHookWindow( this ); - m_XYWrapper = NULL; - m_hooked = false; - } - } - bool FindDropPoint(vec3_t in, vec3_t out); void DropEntsToGround( void ); void MakeChain( void ); void SelectChain( void ); private: - IXYWndWrapper* m_XYWrapper; DEntity m_world; treeModel_t m_trees[MAX_TP_MODELS]; - int m_refCount; int m_numModels; int m_offset; int m_maxPitch; @@ -210,7 +188,6 @@ private: float m_minScale; float m_maxScale; - bool m_hooked; bool m_useScale; bool m_setAngles; bool m_autoLink; diff --git a/contrib/bobtoolz/DVisDrawer.cpp b/contrib/bobtoolz/DVisDrawer.cpp index 46ddca55..0a936941 100644 --- a/contrib/bobtoolz/DVisDrawer.cpp +++ b/contrib/bobtoolz/DVisDrawer.cpp @@ -21,14 +21,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DVisDrawer.h" + +#include "iglrender.h" +#include "math/matrix.h" -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" #include "DWinding.h" -#include "DVisDrawer.h" #include "misc.h" #include "funchandlers.h" @@ -39,15 +41,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA DVisDrawer::DVisDrawer() { - refCount = 1; - m_bHooked = FALSE; m_list = NULL; + + constructShaders(); + GlobalShaderCache().attachRenderable(*this); } DVisDrawer::~DVisDrawer() { - if(m_bHooked) - UnRegister(); + GlobalShaderCache().detachRenderable(*this); + destroyShaders(); g_VisView = NULL; } @@ -55,117 +58,73 @@ DVisDrawer::~DVisDrawer() ////////////////////////////////////////////////////////////////////// // Implementation ////////////////////////////////////////////////////////////////////// +const char* g_state_solid = "$bobtoolz/visdrawer/solid"; +const char* g_state_wireframe = "$bobtoolz/visdrawer/wireframe"; -void DVisDrawer::Draw2D(VIEWTYPE vt) +void DVisDrawer::constructShaders() { - if(!m_list) - return; - - __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); + OpenGLState state; + GlobalOpenGLStateLibrary().getDefaultState(state); + state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_COLOURCHANGE; + state.m_linewidth = 1; - __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH); + GlobalOpenGLStateLibrary().insert(g_state_wireframe, state); - __QGLTABLENAME.m_pfn_qglPushMatrix(); - - switch(vt) - { - case XY: - break; - case XZ: - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f); - break; - case YZ: - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f); - __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f); - break; - } + GlobalOpenGLStateLibrary().getDefaultState(state); + state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH|RENDER_DEPTHWRITE; - __QGLTABLENAME.m_pfn_qglLineWidth(1.0f); - __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f); + GlobalOpenGLStateLibrary().insert(g_state_solid, state); - __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH); + m_shader_solid = GlobalShaderCache().capture(g_state_solid); + m_shader_wireframe = GlobalShaderCache().capture(g_state_wireframe); +} - __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS); +void DVisDrawer::destroyShaders() +{ + GlobalShaderCache().release(g_state_solid); + GlobalShaderCache().release(g_state_wireframe); + GlobalOpenGLStateLibrary().erase(g_state_solid); + GlobalOpenGLStateLibrary().erase(g_state_wireframe); +} +void DVisDrawer::render(RenderStateFlags state) const +{ //bleh - list::const_iterator l=m_list->begin(); + std::list::const_iterator l=m_list->begin(); for(; l != m_list->end(); l++) { DWinding* w = *l; - __QGLTABLENAME.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f); + glColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f); - __QGLTABLENAME.m_pfn_qglBegin(GL_POLYGON); + glBegin(GL_POLYGON); for(int i = 0; i < w->numpoints; i++) { - __QGLTABLENAME.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]); + glVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]); } - __QGLTABLENAME.m_pfn_qglEnd(); + glEnd(); } - - - __QGLTABLENAME.m_pfn_qglPopMatrix(); - - __QGLTABLENAME.m_pfn_qglPopAttrib(); } -void DVisDrawer::Draw3D() +void DVisDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const { if(!m_list) return; - __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); - - __QGLTABLENAME.m_pfn_qglColor4f(1.0, 0.0, 0.0, 0.5f); - -// __QGLTABLENAME.m_pfn_qglHint(GL_FOG_HINT, GL_NICEST); - -// __QGLTABLENAME.m_pfn_qglDisable(GL_CULL_FACE); - __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH); - -// __QGLTABLENAME.m_pfn_qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); -// __QGLTABLENAME.m_pfn_qglShadeModel(GL_SMOOTH); + renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly); - __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND); - __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH); - - __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS); - - //bleh - list::const_iterator l=m_list->begin(); - - for(; l != m_list->end(); l++) - { - DWinding* w = *l; - - __QGLTABLENAME.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f); - - __QGLTABLENAME.m_pfn_qglBegin(GL_POLYGON); - for(int i = 0; i < w->numpoints; i++) { - __QGLTABLENAME.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]); - } - __QGLTABLENAME.m_pfn_qglEnd(); - } - - __QGLTABLENAME.m_pfn_qglPopAttrib(); + renderer.addRenderable(*this, g_matrix4_identity); } -void DVisDrawer::Register() +void DVisDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const { - __QGLTABLENAME.m_pfnHookGL2DWindow( this ); - __QGLTABLENAME.m_pfnHookGL3DWindow( this ); - m_bHooked = TRUE; -} + if(!m_list) + return; -void DVisDrawer::UnRegister() -{ - __QGLTABLENAME.m_pfnUnHookGL2DWindow( this ); - __QGLTABLENAME.m_pfnUnHookGL3DWindow( this ); - m_bHooked = FALSE; + renderer.SetState(m_shader_solid, Renderer::eWireframeOnly); + renderer.SetState(m_shader_solid, Renderer::eFullMaterials); + + renderer.addRenderable(*this, g_matrix4_identity); } void DVisDrawer::SetList(std::list *pointList) @@ -178,7 +137,7 @@ void DVisDrawer::SetList(std::list *pointList) void DVisDrawer::ClearPoints() { - list::const_iterator deadPoint=m_list->begin(); + std::list::const_iterator deadPoint=m_list->begin(); for(; deadPoint!=m_list->end(); deadPoint++) delete *deadPoint; m_list->clear(); diff --git a/contrib/bobtoolz/DVisDrawer.h b/contrib/bobtoolz/DVisDrawer.h index d09c36fc..83a80cb1 100644 --- a/contrib/bobtoolz/DVisDrawer.h +++ b/contrib/bobtoolz/DVisDrawer.h @@ -29,28 +29,34 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 -class DVisDrawer : - public IGL2DWindow, - public IGL3DWindow +#include +#include "renderable.h" +#include "irender.h" + +#include "DWinding.h" + +class DVisDrawer : public Renderable, public OpenGLRenderable { + Shader* m_shader_solid; + Shader* m_shader_wireframe; public: DVisDrawer(); virtual ~DVisDrawer(); protected: - list* m_list; + std::list* m_list; int refCount; public: void ClearPoints(); - void SetList(list* pointList); - void UnRegister(); - void Register(); - void Draw3D(); - void Draw2D(VIEWTYPE vt); - void IncRef() { refCount++; } - void DecRef() { refCount--; if (refCount <= 0) delete this; } - - bool m_bHooked; + void SetList(std::list* pointList); + + void render(RenderStateFlags state) const; + void renderSolid(Renderer& renderer, const VolumeTest& volume) const; + void renderWireframe(Renderer& renderer, const VolumeTest& volume) const; + + void constructShaders(); + void destroyShaders(); + }; #endif // !defined(AFX_VISDRAWER_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_) diff --git a/contrib/bobtoolz/DWinding.cpp b/contrib/bobtoolz/DWinding.cpp index d3c7afdd..2068f3f8 100644 --- a/contrib/bobtoolz/DWinding.cpp +++ b/contrib/bobtoolz/DWinding.cpp @@ -21,12 +21,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ////////////////////////////////////////////////////////////////////// -#include "StdAfx.h" +#include "DWinding.h" -#include "gtkr_list.h" +#include #include "DPoint.h" -#include "DWinding.h" #include "DPlane.h" ////////////////////////////////////////////////////////////////////// @@ -157,8 +156,8 @@ DWinding* DWinding::CopyWinding() int DWinding::WindingOnPlaneSide(vec3_t normal, vec_t dist) { - bool front = FALSE; - bool back = FALSE; + bool front = false; + bool back = false; for (int i = 0; i < numpoints; i++) { @@ -167,14 +166,14 @@ int DWinding::WindingOnPlaneSide(vec3_t normal, vec_t dist) { if (front) return SIDE_CROSS; - back = TRUE; + back = true; continue; } if (d > ON_EPSILON) { if (back) return SIDE_CROSS; - front = TRUE; + front = true; continue; } } @@ -193,11 +192,11 @@ void DWinding::CheckWinding() vec3_t dir, edgenormal; if (numpoints < 3) - Sys_Printf ("CheckWinding: %i points", numpoints); + globalOutputStream() << "CheckWinding: " << numpoints << " points\n"; vec_t area = WindingArea(); if (area < 1) - Sys_Printf ("CheckWinding: %f area", area); + globalOutputStream() << "CheckWinding: " << area << " area\n"; DPlane* wPlane = WindingPlane (); int i; @@ -208,21 +207,21 @@ void DWinding::CheckWinding() int j; for (j = 0; j < 3; j++) if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE) - Sys_Printf ("CheckFace: BUGUS_RANGE: %f", p1[j]); + globalOutputStream() << "CheckFace: BOGUS_RANGE: " << p1[j] << "\n"; j = i + 1 == numpoints ? 0 : i + 1; // check the point is on the face plane vec_t d = DotProduct (p1, wPlane->normal) - wPlane->_d; if (d < -ON_EPSILON || d > ON_EPSILON) - Sys_Printf ("CheckWinding: point off plane"); + globalOutputStream() << "CheckWinding: point off plane\n"; // check the edge isnt degenerate p2 = p[j]; VectorSubtract (p2, p1, dir); if (VectorLength (dir) < ON_EPSILON) - Sys_Printf ("CheckWinding: degenerate edge"); + globalOutputStream() << "CheckWinding: degenerate edge\n"; CrossProduct (wPlane->normal, dir, edgenormal); VectorNormalize (edgenormal, edgenormal); @@ -236,7 +235,7 @@ void DWinding::CheckWinding() d = DotProduct (p[j], edgenormal); if (d > (edgedist + ON_EPSILON)) - Sys_Printf ("CheckWinding: non-convex"); + globalOutputStream() << "CheckWinding: non-convex\n"; } } @@ -287,11 +286,11 @@ bool DWinding::ChopWindingInPlace(DPlane* chopPlane, vec_t epsilon) if (!counts[0]) { delete this; - return FALSE; + return false; } if (!counts[1]) - return TRUE; + return true; int maxpts = numpoints+4; // cant use counts[0]+2 because // of fp grouping errors @@ -339,15 +338,15 @@ bool DWinding::ChopWindingInPlace(DPlane* chopPlane, vec_t epsilon) } if (f->numpoints > maxpts) - Sys_Printf ("ClipWinding: points exceeded estimate"); + globalOutputStream() << "ClipWinding: points exceeded estimate\n"; if (f->numpoints > MAX_POINTS_ON_WINDING) - Sys_Printf ("ClipWinding: MAX_POINTS_ON_WINDING"); + globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n"; delete[] p; p = f->p; f->p = NULL; delete f; - return TRUE; + return true; } void DWinding::ClipWindingEpsilon(DPlane* chopPlane, vec_t epsilon, DWinding **front, DWinding **back) @@ -455,9 +454,9 @@ void DWinding::ClipWindingEpsilon(DPlane* chopPlane, vec_t epsilon, DWinding **f } if (f->numpoints > maxpts || b->numpoints > maxpts) - Sys_Printf ("ClipWinding: points exceeded estimate"); + globalOutputStream() << "ClipWinding: points exceeded estimate\n"; if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING) - Sys_Printf ("ClipWinding: MAX_POINTS_ON_WINDING"); + globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n"; } bool DWinding::ChopWinding(DPlane* chopPlane) @@ -473,7 +472,7 @@ bool DWinding::ChopWinding(DPlane* chopPlane) if(!f) { delete this; - return FALSE; + return false; } delete[] p; @@ -482,5 +481,5 @@ bool DWinding::ChopWinding(DPlane* chopPlane) numpoints = f->numpoints; delete f; - return TRUE; + return true; } diff --git a/contrib/bobtoolz/DWinding.h b/contrib/bobtoolz/DWinding.h index 6d58e06e..52846aab 100644 --- a/contrib/bobtoolz/DWinding.h +++ b/contrib/bobtoolz/DWinding.h @@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #pragma once #endif // _MSC_VER > 1000 +#include "mathlib.h" + class DPlane; class DWinding diff --git a/contrib/bobtoolz/ScriptParser.cpp b/contrib/bobtoolz/ScriptParser.cpp index 2b2354cf..b5d8859f 100644 --- a/contrib/bobtoolz/ScriptParser.cpp +++ b/contrib/bobtoolz/ScriptParser.cpp @@ -17,7 +17,6 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" #include "ScriptParser.h" CScriptParser::CScriptParser(void): diff --git a/contrib/bobtoolz/StdAfx.h b/contrib/bobtoolz/StdAfx.h index e7e58a69..b8897f39 100644 --- a/contrib/bobtoolz/StdAfx.h +++ b/contrib/bobtoolz/StdAfx.h @@ -20,122 +20,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #ifndef __STDAFX_BOBTOOLZ__ #define __STDAFX_BOBTOOLZ__ -#define BOBTOOLZ_MINOR "bobtoolz" -#include -#include -#include -#include - -#include "time.h" - -#define NAME_MAX 255 - -#if defined (__linux__) || defined (__APPLE__) - -#include - -typedef void* HMODULE; -typedef void* LPVOID; -typedef char* LPCSTR; -//typedef int bool; - - -#define WINAPI -#define APIENTRY - -#ifndef GUID_DEFINED -#define GUID_DEFINED -typedef struct _GUID -{ - unsigned long Data1; - unsigned short Data2; - unsigned short Data3; - unsigned char Data4[8]; -} GUID; - -#define stricmp strcasecmp - -#endif - -#if defined(__cplusplus) -#ifndef _REFGUID_DEFINED -#define _REFGUID_DEFINED -#define REFGUID const GUID & -#endif // !_REFGUID_DEFINED -#endif - -typedef struct tagRECT -{ - long left; - long top; - long right; - long bottom; -} RECT, *PRECT, *LPRECT; - -typedef uint UINT; - -#endif // __linux__ - -#include "mathlib.h" -#include -#include "qertypes.h" -#include - -#define USE_SCENEGRAPHTABLE_DEFINE -#include "iscenegraph.h" - -#define USE_QERTABLE_DEFINE -#include "qerplugin.h" -extern _QERFuncTable_1 __QERTABLENAME; - -#define USE_ENTITYTABLE_DEFINE -#include "ientity.h" -extern _QEREntityTable __ENTITYTABLENAME; - -#define USE_BRUSHTABLE_DEFINE -#include "ibrush.h" -extern _QERBrushTable __BRUSHTABLENAME; - -#define USE_PATCHTABLE_DEFINE -#include "ipatch.h" -extern _QERPatchTable __PATCHTABLENAME; - -#define USE_SHADERSTABLE_DEFINE -#include "ishaders.h" -extern _QERShadersTable __SHADERSTABLENAME; - -#define USE_QGLTABLE_DEFINE -#include "igl.h" -extern _QERQglTable __QGLTABLENAME; - -#include "ibspfrontend.h" -extern _QERAppBSPFrontendTable g_BSPTable; - -#include "iui.h" -extern _QERUITable g_MessageTable; - -#define USE_RENDERTABLE_DEFINE -#include "irender.h" - -#define USE_SELECTIONTABLE_DEFINE -#include "iselection.h" - -#include "itoolbar.h" - - -#include "iplugin.h" - -#define MAX_ROUND_ERROR 0.05 - -#include "itexdef.h" - -struct _QERFaceData -{ - vec3_t m_p0; - vec3_t m_p1; - vec3_t m_p2; - texdef_t m_texdef; -}; #endif diff --git a/contrib/bobtoolz/bobToolz-GTK.cpp b/contrib/bobtoolz/bobToolz-GTK.cpp index 08cd00dd..b0940e08 100644 --- a/contrib/bobtoolz/bobToolz-GTK.cpp +++ b/contrib/bobtoolz/bobToolz-GTK.cpp @@ -19,17 +19,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "libxml/parser.h" -#include "StdAfx.h" #include "str.h" -//#include "gtkr_list.h" #include "funchandlers.h" -//#include "misc.h" #include "dialogs/dialogs-gtk.h" #include "../../libs/cmdlib.h" +void BobToolz_construct() +{ +} + +void BobToolz_destroy() +{ +} + // Radiant function table _QERFuncTable_1 __QERTABLENAME; _QERShadersTable __SHADERSTABLENAME; // vvvvvvvvvvvvvvvvvvvv @@ -71,31 +76,31 @@ extern "C" const char* QERPlug_GetCommandList() { extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) { LoadLists(); - if( !stricmp( p, "brush cleanup" ) ) { + if( string_equal_nocase( p, "brush cleanup" ) ) { DoFixBrushes(); - } else if( !stricmp( p, "polygon builder" ) ) { + } else if( string_equal_nocase( p, "polygon builder" ) ) { DoPolygonsTB(); - } else if( !stricmp( p, "caulk selection" ) ) { + } else if( string_equal_nocase( p, "caulk selection" ) ) { DoCaulkSelection(); - } else if( !stricmp( p, "tree planter" ) ) { + } else if( string_equal_nocase( p, "tree planter" ) ) { DoTreePlanter(); - } else if( !stricmp( p, "plot splines" ) ) { + } else if( string_equal_nocase( p, "plot splines" ) ) { DoTrainPathPlot(); - } else if( !stricmp( p, "drop entity" ) ) { + } else if( string_equal_nocase( p, "drop entity" ) ) { DoDropEnts(); - } else if( !stricmp( p, "merge patches" ) ) { + } else if( string_equal_nocase( p, "merge patches" ) ) { DoMergePatches(); - } else if( !stricmp( p, "split patches" ) ) { + } else if( string_equal_nocase( p, "split patches" ) ) { DoSplitPatch(); - } else if( !stricmp( p, "turn edge" ) ) { + } else if( string_equal_nocase( p, "turn edge" ) ) { DoFlipTerrain(); - } else if( !stricmp(p, "reset textures...") ) { + } else if( string_equal_nocase(p, "reset textures...") ) { DoResetTextures(); - } else if( !stricmp(p, "pitomatic") ) { + } else if( string_equal_nocase(p, "pitomatic") ) { DoPitBuilder(); - } else if( !stricmp(p, "vis viewer") ) { + } else if( string_equal_nocase(p, "vis viewer") ) { DoVisAnalyse(); - } else if( !stricmp(p, "about...") ) { + } else if( string_equal_nocase(p, "about...") ) { DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK); } } @@ -221,6 +226,7 @@ public: virtual ~CSynapseClientBobtoolz() { } }; +#define BOBTOOLZ_MINOR "bobtoolz" CSynapseServer* g_pSynapseServer = NULL; CSynapseClientBobtoolz g_SynapseClient; @@ -288,11 +294,3 @@ const char* CSynapseClientBobtoolz::GetInfo() return "bobToolz module built " __DATE__ " " RADIANT_VERSION; } -char* GetFilename(char* buffer, const char* filename) { - strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient)); - StripFilename( buffer ); - strcat(buffer, "/"); - strcat(buffer, filename); - //buffer = UnixToDosPath(buffer); - return buffer; -} diff --git a/contrib/bobtoolz/bobToolz.def b/contrib/bobtoolz/bobToolz.def index c22c76d3..74f9189b 100644 --- a/contrib/bobtoolz/bobToolz.def +++ b/contrib/bobtoolz/bobToolz.def @@ -5,4 +5,4 @@ LIBRARY "bobToolz" EXPORTS ; Explicit exports can go here - Synapse_EnumerateInterfaces @1 + Radiant_RegisterModules @1 diff --git a/contrib/bobtoolz/bsploader.cpp b/contrib/bobtoolz/bsploader.cpp index 27c2e6d5..287c5fff 100644 --- a/contrib/bobtoolz/bsploader.cpp +++ b/contrib/bobtoolz/bsploader.cpp @@ -1,7 +1,6 @@ -#include "StdAfx.h" -#include "./dialogs/dialogs-gtk.h" #include "bsploader.h" -#include "../../libs/cmdlib.h" +#include "dialogs/dialogs-gtk.h" +#include "cmdlib.h" int numnodes; int numplanes; @@ -72,15 +71,21 @@ bool LoadFile( const char *filename, byte **bufferptr) return true; } -/*int LittleLong (int l) +int LittleLong (int l) { +#if defined(__BIG_ENDIAN__) + std::reverse(reinterpret_cast(&l), reinterpret_cast(&l) + sizeof(int)); +#endif return l; } float LittleFloat (float l) { +#if defined(__BIG_ENDIAN__) + std::reverse(reinterpret_cast(&l), reinterpret_cast(&l) + sizeof(float)); +#endif return l; -}*/ +} /* ============= diff --git a/contrib/bobtoolz/bsploader.h b/contrib/bobtoolz/bsploader.h index 9414566a..3cea233b 100644 --- a/contrib/bobtoolz/bsploader.h +++ b/contrib/bobtoolz/bsploader.h @@ -1,3 +1,6 @@ + +#include "mathlib.h" + #define LUMP_ENTITIES 0 #define LUMP_SHADERS 1 #define LUMP_PLANES 2 diff --git a/contrib/bobtoolz/cportals.cpp b/contrib/bobtoolz/cportals.cpp index 01edc0e1..5048eef0 100644 --- a/contrib/bobtoolz/cportals.cpp +++ b/contrib/bobtoolz/cportals.cpp @@ -17,9 +17,12 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" #include "CPortals.h" -//#include "misc.h" + +#include +#include + +#include "misc.h" #define LINE_BUF 1000 #define MSG_PREFIX "bobToolz plugin: " @@ -60,7 +63,7 @@ bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse) point_count = pointCnt; if(point_count < 3) - return FALSE; + return false; point = new CBspPoint[point_count]; @@ -69,7 +72,7 @@ bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse) for(; *c != 0 && *c != '('; c++); if(*c == 0) - return FALSE; + return false; c++; @@ -86,7 +89,7 @@ bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse) ClampFloat(&point[x].p[2]); } - return TRUE; + return true; } CPortals::CPortals() @@ -115,7 +118,7 @@ void CPortals::Load() Purge(); - Sys_Printf(MSG_PREFIX "Loading portal file %s.\n", fn); + globalOutputStream() << MSG_PREFIX "Loading portal file " << fn << ".\n"; FILE *in; @@ -123,7 +126,7 @@ void CPortals::Load() if(in == NULL) { - Sys_Printf(" ERROR - could not open file.\n"); + globalOutputStream() << " ERROR - could not open file.\n"; return; } @@ -132,7 +135,7 @@ void CPortals::Load() { fclose(in); - Sys_Printf(" ERROR - File ended prematurely.\n"); + globalOutputStream() << " ERROR - File ended prematurely.\n"; return; } @@ -141,7 +144,7 @@ void CPortals::Load() { fclose(in); - Sys_Printf(" ERROR - File header indicates wrong file type (should be \"PRT1\").\n"); + globalOutputStream() << " ERROR - File header indicates wrong file type (should be \"PRT1\").\n"; return; } @@ -150,7 +153,7 @@ void CPortals::Load() { fclose(in); - Sys_Printf(" ERROR - File ended prematurely.\n"); + globalOutputStream() << " ERROR - File ended prematurely.\n"; return; } @@ -163,7 +166,7 @@ void CPortals::Load() node_count = 0; - Sys_Printf(" ERROR - Extreme number of nodes, aborting.\n"); + globalOutputStream() << " ERROR - Extreme number of nodes, aborting.\n"; return; } @@ -174,7 +177,7 @@ void CPortals::Load() node_count = 0; - Sys_Printf(" ERROR - File ended prematurely.\n"); + globalOutputStream() << " ERROR - File ended prematurely.\n"; return; } @@ -188,7 +191,7 @@ void CPortals::Load() node_count = 0; - Sys_Printf(" ERROR - File ended prematurely.\n"); + globalOutputStream() << " ERROR - File ended prematurely.\n"; return; } @@ -207,7 +210,7 @@ void CPortals::Load() node_count = 0; - Sys_Printf(" ERROR - File ended prematurely.\n"); + globalOutputStream() << " ERROR - File ended prematurely.\n"; return; } @@ -227,7 +230,7 @@ void CPortals::Load() node_count = 0; - Sys_Printf(" ERROR - File ended prematurely.\n"); + globalOutputStream() << " ERROR - File ended prematurely.\n"; return; } @@ -259,7 +262,7 @@ void CPortals::Load() Purge(); - Sys_Printf(" ERROR - Could not find information for portal number %d of %d.\n", n + 1, p_count); + globalOutputStream() << " ERROR - Could not find information for portal number " << n + 1 << " of " << p_count << ".\n"; return; } @@ -267,24 +270,24 @@ void CPortals::Load() unsigned int pCount, node1, node2; sscanf(buf, "%u %u %u", &pCount, &node1, &node2); - if(!node[node1].AddPortal(buf, pCount, FALSE)) + if(!node[node1].AddPortal(buf, pCount, false)) { fclose(in); Purge(); - Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count); + globalOutputStream() << " ERROR - Information for portal number " << n + 1 << " of " << p_count << " is not formatted correctly.\n"; return; } - if(!node[node2].AddPortal(buf, pCount, TRUE)) + if(!node[node2].AddPortal(buf, pCount, true)) { fclose(in); Purge(); - Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count); + globalOutputStream() << " ERROR - Information for portal number " << n + 1 << " of " << p_count << " is not formatted correctly.\n"; return; } @@ -298,7 +301,7 @@ void CPortals::Load() Purge(); - Sys_Printf(" ERROR - Could not find information for portal number %d of %d.\n", n + 1, p_count); + globalOutputStream() << " ERROR - Could not find information for portal number " << n + 1 << " of " << p_count << ".\n"; return; } @@ -306,13 +309,13 @@ void CPortals::Load() unsigned int pCount, node1; sscanf(buf, "%u %u", &pCount, &node1); - if(!node[node1].AddPortal(buf, pCount, FALSE)) + if(!node[node1].AddPortal(buf, pCount, false)) { fclose(in); Purge(); - Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count); + globalOutputStream() << " ERROR - Information for portal number " << n + 1 << " of " << p_count << " is not formatted correctly.\n"; return; } diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp index 57177ef4..0058ea7a 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.cpp +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.cpp @@ -17,14 +17,11 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "../StdAfx.h" - - #include "dialogs-gtk.h" #include "../funchandlers.h" #include "str.h" -#include "gtkr_list.h" +#include #include "../lists.h" #include "../misc.h" diff --git a/contrib/bobtoolz/dialogs/dialogs-gtk.h b/contrib/bobtoolz/dialogs/dialogs-gtk.h index 5838db6f..bcafdae8 100644 --- a/contrib/bobtoolz/dialogs/dialogs-gtk.h +++ b/contrib/bobtoolz/dialogs/dialogs-gtk.h @@ -17,6 +17,11 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if !defined(INCLUDED_DIALOGS_GTK_H) +#define INCLUDED_DIALOGS_GTK_H + +#include "qerplugin.h" + struct BuildStairsRS{ char mainTexture[256]; char riserTexture[256]; @@ -80,6 +85,8 @@ struct PathPlotterRS{ bool bShowExtra; }; +typedef struct _GtkWidget GtkWidget; + struct TwinWidget{ GtkWidget* one; GtkWidget* two; @@ -96,3 +103,5 @@ EMessageBoxReturn DoCTFColourChangeBox(); EMessageBoxReturn DoTrainThingBox (TrainThingRS* rs); //GtkWidget* GetProgressWindow(char* title, GtkProgressBar* feedback); + +#endif diff --git a/contrib/bobtoolz/funchandlers-GTK.cpp b/contrib/bobtoolz/funchandlers-GTK.cpp index deb3ff82..d492d742 100644 --- a/contrib/bobtoolz/funchandlers-GTK.cpp +++ b/contrib/bobtoolz/funchandlers-GTK.cpp @@ -17,7 +17,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" +#include "funchandlers.h" #ifdef WIN32 #pragma warning(disable : 4786) @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "dialogs/dialogs-gtk.h" -#include "gtkr_list.h" +#include #include "str.h" #include "DPoint.h" @@ -45,13 +45,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "shapes.h" #include "lists.h" -#include "funchandlers.h" #include "visfind.h" #include "iundo.h" -#include "refcounted_ptr.h" - #include #include #include @@ -60,8 +57,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "scenelib.h" // for autocaulk -list exclusionList; // whole brush exclusion -list exclusionList_Face; // single face exclusion +std::list exclusionList; // whole brush exclusion +std::list exclusionList_Face; // single face exclusion bool el1Loaded = FALSE; bool el2Loaded = FALSE; @@ -166,7 +163,7 @@ void DoPolygons() VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin); VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax); - instance.path().parent()->m_traverse->erase(instance.path().top()); + Node_getTraversable(instance.path().parent())->erase(instance.path().top()); } if(rs.bInverse) @@ -269,7 +266,7 @@ void DoBuildStairs() { { scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); - instance.path().parent()->m_traverse->erase(instance.path().top()); + Node_getTraversable(instance.path().parent())->erase(instance.path().top()); } // Get Step Count @@ -340,7 +337,7 @@ void DoBuildDoors() scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin); VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax); - instance.path().parent()->m_traverse->erase(instance.path().top()); + Node_getTraversable(instance.path().parent())->erase(instance.path().top()); } BuildDoorsX2(vMin, vMax, @@ -371,40 +368,11 @@ void DoPathPlotter() return; } - scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); - - DEntity world; - world.LoadEPairList(instance.path().top()->m_entity); - - DEPair* trigger_ep = world.FindEPairByKey("targetname"); - - if(trigger_ep) - { - if(!strcmp(world.m_Classname, "trigger_push")) - { - DEPair* target_ep = world.FindEPairByKey("target"); - if(target_ep) - { - scene::Path* entTarget = FindEntityFromTargetname(target_ep->value, NULL); - if(entTarget) - { - if(g_PathView) - delete g_PathView; - g_PathView = new DBobView; - - g_PathView->Begin(trigger_ep->value, target_ep->value, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra); - } - else - DoMessageBox("trigger_push target could not be found.", "Error", eMB_OK); - } - else - DoMessageBox("trigger_push has no target.", "Error", eMB_OK); - } - else - DoMessageBox("You must select a 'trigger_push' entity.", "Error", eMB_OK); - } - else - DoMessageBox("Entity must have a targetname", "Error", eMB_OK); + Entity* entity = Node_getEntity(GlobalSelectionSystem().ultimateSelected().path().top()); + if(entity != 0) + { + DBobView_setEntity(*entity, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra); + } } void DoPitBuilder() @@ -428,7 +396,7 @@ void DoPitBuilder() { pit.Commit(); - instance.path().parent()->m_traverse->erase(instance.path().top()); + Node_getTraversable(instance.path().parent())->erase(instance.path().top()); } else DoMessageBox("Failed To Make Pit\nTry Making The Brush Bigger", "Error", eMB_OK); @@ -450,6 +418,9 @@ void DoMergePatches() scene::Node* patches[2]; patches[0] = GlobalSelectionSystem().ultimateSelected().path().top(); patches[1] = GlobalSelectionSystem().penultimateSelected().path().top(); + scene::Node* ents[2]; + ents[0] = GlobalSelectionSystem().ultimateSelected().path().parent(); + ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent(); for (i = 0; i < 2; i++) { @@ -488,8 +459,8 @@ void DoMergePatches() { } else { - mrgPatches[0].RemoveFromRadiant(); - mrgPatches[1].RemoveFromRadiant(); + Node_getTraversable(*ents[0])->erase(*patches[0]); + Node_getTraversable(*ents[1])->erase(*patches[1]); newPatch->BuildInRadiant(); delete newPatch; @@ -516,8 +487,8 @@ void DoSplitPatch() { patch.LoadFromBrush(node); - list patchList = patch.Split( true, true ); - for(list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) { + std::list patchList = patch.Split( true, true ); + for(std::list::iterator patches = patchList.begin(); patches != patchList.end(); patches++) { (*patches).BuildInRadiant(); } @@ -568,7 +539,7 @@ void DoVisAnalyse() char* ext = strrchr(filename, '.')+1; strcpy(ext, "bsp");// rename the extension - list *pointList = BuildTrace(filename, origin); + std::list *pointList = BuildTrace(filename, origin); if(!g_VisView) { @@ -662,7 +633,7 @@ void DoFlipTerrain() { ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent(); for( i = 0; i < 2; i++ ) { - Brushes[i].RemoveFromRadiant(); + Node_getTraversable(*ents[i])->erase(*brushes[i]); } diff --git a/contrib/bobtoolz/funchandlers.cpp b/contrib/bobtoolz/funchandlers.cpp index c83d2ae0..ca218f5b 100644 --- a/contrib/bobtoolz/funchandlers.cpp +++ b/contrib/bobtoolz/funchandlers.cpp @@ -39,8 +39,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DShape.h" // for autocaulk -list exclusionList; // whole brush exclusion -list exclusionList_Face; // single face exclusion +std::list exclusionList; // whole brush exclusion +std::list exclusionList_Face; // single face exclusion BOOL el1Loaded; BOOL el2Loaded; diff --git a/contrib/bobtoolz/lists.cpp b/contrib/bobtoolz/lists.cpp index b8b1dd44..faacbb77 100644 --- a/contrib/bobtoolz/lists.cpp +++ b/contrib/bobtoolz/lists.cpp @@ -17,19 +17,17 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" +#include "lists.h" #ifdef WIN32 #pragma warning(disable : 4786) #endif -#include "gtkr_list.h" -#include "str.h" +#include -#include "lists.h" #include "misc.h" -bool LoadExclusionList(char* filename, list* exclusionList) +bool LoadExclusionList(char* filename, std::list* exclusionList) { FILE* eFile = fopen(filename, "r"); if(eFile) @@ -52,7 +50,7 @@ bool LoadExclusionList(char* filename, list* exclusionList) return TRUE; } - Sys_ERROR("Failed To Load Exclusion List: %s\n", filename); + globalErrorStream() << "Failed To Load Exclusion List: " << filename << "\n"; return FALSE; } diff --git a/contrib/bobtoolz/lists.h b/contrib/bobtoolz/lists.h index 6f9774f6..c4ccf77e 100644 --- a/contrib/bobtoolz/lists.h +++ b/contrib/bobtoolz/lists.h @@ -17,5 +17,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -bool LoadExclusionList(char* filename, list* exclusionList); +#include +#include "str.h" +typedef struct _GList GList; + +bool LoadExclusionList(char* filename, std::list* exclusionList); bool LoadGList(char* filename, GList** loadlist); diff --git a/contrib/bobtoolz/misc.cpp b/contrib/bobtoolz/misc.cpp index f793bcc4..e56c4d89 100644 --- a/contrib/bobtoolz/misc.cpp +++ b/contrib/bobtoolz/misc.cpp @@ -17,13 +17,11 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" +#include "misc.h" -#include "gtkr_list.h" +#include #include "str.h" -#include "misc.h" - #include "DPoint.h" #include "DPlane.h" #include "DBrush.h" @@ -39,8 +37,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #endif #include "iundo.h" - -#include "refcounted_ptr.h" +#include "qerplugin.h" #include #include @@ -61,7 +58,7 @@ char g_CurrentTexture[256] = ""; void ReadCurrentTexture() { - const char* textureName = g_FuncTable.m_pfnGetCurrentTexture(); + const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader(); strcpy(g_CurrentTexture, textureName); } @@ -152,29 +149,6 @@ char* TranslateString (char *buf) return buf2; } -void Sys_ERROR (char* text, ...) -{ - va_list argptr; - char buf[32768]; - - va_start (argptr,text); - vsprintf (buf, text,argptr); - va_end (argptr); - - Sys_Printf("BobToolz::ERROR->%s", buf); -} - -/*void Sys_Printf (char *text, ...) -{ - va_list argptr; - char buf[32768]; - - va_start (argptr,text); - vsprintf (buf, text,argptr); - va_end (argptr); - - g_FuncTable.m_pfnSysMsg ( buf ); -}*/ char* UnixToDosPath(char* path) { @@ -289,7 +263,7 @@ void StartBSP() Q_Exec( command, TRUE ); } -void BuildMiniPrt(list* exclusionList) +void BuildMiniPrt(std::list* exclusionList) { // yes, we could just use -fulldetail option, but, as SPOG said // it'd be faster without all the hint, donotenter etc textures and @@ -347,6 +321,31 @@ void BuildMiniPrt(list* exclusionList) StartBSP(); } +template +class EntityWalker +{ + const Functor& functor; +public: + EntityWalker(const Functor& functor) : functor(functor) + { + } + bool pre(const Path& path, Instance& instance) const + { + if(Node_isEntity(path.top())) + { + functor(path.top()); + } + } +}; + +template +const Functor& Scene_forEachEntity(const Functor& functor) +{ + GlobalSceneGraph().traverse(EntityWalker(functor)); +} + +void + scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum) { #if 0 @@ -364,7 +363,7 @@ scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum) DEPair* tn = world.FindEPairByKey("targetname"); if(tn) { - if(!stricmp(tn->value, targetname)) { + if(string_equal_nocase(tn->value, targetname)) { if(entNum) { *entNum = i; } @@ -388,9 +387,9 @@ void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, faceData->m_texdef.flags = 0; faceData->m_texdef.value = 0; if(*texture) - faceData->m_texdef.SetName(texture); + faceData->m_shader = texture; else - faceData->m_texdef.SetName("textures/common/caulk"); + faceData->m_shader = "textures/common/caulk"; VectorCopy(va, faceData->m_p0); VectorCopy(vb, faceData->m_p1); VectorCopy(vc, faceData->m_p2); @@ -422,9 +421,19 @@ vec_t Min(vec_t a, vec_t b) return b; } -void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) { +void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) { vec3_t v1, v2; VectorSubtract(va, vb, v1); VectorSubtract(vc, vb, v2); CrossProduct(v1, v2, out); } + +char* GetFilename(char* buffer, const char* filename) { + strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient)); + StripFilename( buffer ); + strcat(buffer, "/"); + strcat(buffer, filename); + //buffer = UnixToDosPath(buffer); + return buffer; +} + diff --git a/contrib/bobtoolz/misc.h b/contrib/bobtoolz/misc.h index f1431c43..e011b67e 100644 --- a/contrib/bobtoolz/misc.h +++ b/contrib/bobtoolz/misc.h @@ -17,16 +17,24 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if !defined(INCLUDED_MISC_H) +#define INCLUDED_MISC_H + +#include "mathlib.h" +#include +#include "str.h" +#include "iscenegraph.h" + +#define MAX_ROUND_ERROR 0.05 + vec_t Min(vec_t a, vec_t b); // reads current texture into global, returns pointer to it const char* GetCurrentTexture(); -void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture); +void FillDefaultTexture(void* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture); -void Sys_ERROR (char* text, ...); - -void BuildMiniPrt(list* exclusionList); +void BuildMiniPrt(std::list* exclusionList); void MoveBlock(int dir, vec3_t min, vec3_t max, float dist); void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width); @@ -43,4 +51,6 @@ float Determinant3x3(float a1, float a2, float a3, float c1, float c2, float c3); bool GetEntityCentre(const char* entity, vec3_t centre); -void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ); +void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ); + +#endif diff --git a/contrib/bobtoolz/shapes.cpp b/contrib/bobtoolz/shapes.cpp index 84bdc011..3c5e3734 100644 --- a/contrib/bobtoolz/shapes.cpp +++ b/contrib/bobtoolz/shapes.cpp @@ -18,11 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "StdAfx.h" - #include "shapes.h" -#include "gtkr_list.h" +#include #include "DPoint.h" #include "DPlane.h" @@ -80,18 +78,16 @@ float Deg2Rad(float angle) return (float)(angle*Q_PI/180); } -void AddFaceWithTexture(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail) +void AddFaceWithTexture(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail) { _QERFaceData faceData; FillDefaultTexture(&faceData, va, vb, vc, texture); if(detail) faceData.m_texdef.contents |= FACE_DETAIL; -#if 0 - brush->m_brush->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_texdef); -#endif + GlobalBrushCreator().addBrushFace(brush, faceData); } -void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc, +void AddFaceWithTextureScaled(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool bVertScale, bool bHorScale, float minX, float minY, float maxX, float maxY) { @@ -135,9 +131,7 @@ void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t v addFace.m_texdef.shift[0] = shift[0]; addFace.m_texdef.shift[1] = shift[1]; -#if 0 - brush->m_brush->addPlane(addFace.m_p0, addFace.m_p1, addFace.m_p2, addFace.m_texdef); -#endif + GlobalBrushCreator().addBrushFace(brush, addFace); } else { @@ -156,7 +150,7 @@ void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t v void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp) { - scene::Node* newBrush = Brush_AllocNode(); + NodeSmartReference newBrush(GlobalBrushCreator().createBrush()); vec3_t v1, v2, v3, v5, v6, v7, v8; VectorCopy(min, v1); @@ -233,7 +227,7 @@ void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp) AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE); } - GetWorldspawn()->m_traverse->insert(newBrush); + Node_getTraversable(GetWorldspawn())->insert(newBrush); } //----------------------------------------------------------------------------------- @@ -241,7 +235,7 @@ void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp) void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail) { - scene::Node* newBrush = Brush_AllocNode(); + NodeSmartReference newBrush(GlobalBrushCreator().createBrush()); //----- Build Outer Bounds --------- @@ -312,16 +306,16 @@ void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainText if(dir == MOVE_SOUTH) AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail); - GetWorldspawn()->m_traverse->insert(newBrush); + Node_getTraversable(GetWorldspawn())->insert(newBrush); } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- // internal use only, to get a box without finishing construction -scene::Node* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces) +scene::Node& Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces) { - scene::Node* newBrush = Brush_AllocNode(); + scene::Node& newBrush(GlobalBrushCreator().createBrush()); //----- Build Outer Bounds --------- @@ -362,7 +356,7 @@ scene::Node* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* text return newBrush; } -scene::Node* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture) +scene::Node& Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture) { return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll); } @@ -372,7 +366,7 @@ scene::Node* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture) void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction) { - scene::Node* newBrush = Brush_AllocNode(); + scene::Node& newBrush(GlobalBrushCreator().createBrush()); //----- Build Outer Bounds --------- @@ -422,7 +416,7 @@ void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE); // base is caulked - GetWorldspawn()->m_traverse->insert(newBrush); + Node_getTraversable(GetWorldspawn())->insert(newBrush); // finish brush } @@ -478,8 +472,8 @@ void BuildDoorsX2(vec3_t min, vec3_t max, //---------------------------------- - scene::Node* newBrush1 = Brush_AllocNode(); - scene::Node* newBrush2 = Brush_AllocNode(); + NodeSmartReference newBrush1(GlobalBrushCreator().createBrush()); + NodeSmartReference newBrush2(GlobalBrushCreator().createBrush()); AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE); AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE); @@ -543,8 +537,8 @@ void BuildDoorsX2(vec3_t min, vec3_t max, //---------------------------------- - scene::Node* pEDoor1 = GlobalEntityCreator().createEntity("func_door"); - scene::Node* pEDoor2 = GlobalEntityCreator().createEntity("func_door"); + NodeSmartReference pEDoor1 = GlobalEntityCreator().createEntity("func_door"); + NodeSmartReference pEDoor2 = GlobalEntityCreator().createEntity("func_door"); if(direction == 0) { @@ -564,11 +558,11 @@ void BuildDoorsX2(vec3_t min, vec3_t max, pEDoor1->m_entity->setkeyvalue("team", teamname); pEDoor2->m_entity->setkeyvalue("team", teamname); - pEDoor1->m_traverse->insert(newBrush1); - pEDoor2->m_traverse->insert(newBrush2); + Node_getTraversable(pEDoor1)->insert(newBrush1); + Node_getTraversable(pEDoor2)->insert(newBrush2); - GlobalSceneGraph().root()->m_traverse->insert(pEDoor1); - GlobalSceneGraph().root()->m_traverse->insert(pEDoor2); + Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor1); + Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor2); // ResetCurrentTexture(); } @@ -578,14 +572,14 @@ void BuildDoorsX2(vec3_t min, vec3_t max, void MakeBevel(vec3_t vMin, vec3_t vMax) { - scene::Node* patch = Patch_AllocNode(); + NodeSmartReference patch(GlobalPatchCreator().createPatch()); aabb_t aabb; aabb_construct_for_vec3(&aabb, vMin, vMax); #if 0 patch->m_patch->ConstructPrefab(&aabb, eBevel, 2); // 2 == XY view #endif - GetWorldspawn()->m_traverse->insert(patch); + Node_getTraversable(GetWorldspawn())->insert(patch); } void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex) @@ -628,7 +622,7 @@ void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTex for(i = 0; i < nSteps; i++) { - scene::Node* brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse); + scene::Node& brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse); for(int j = 0; j < 3; j++) tp[j][2] = vTop[2]; @@ -638,7 +632,7 @@ void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTex AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE); AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE); - GetWorldspawn()->m_traverse->insert(brush); + Node_getTraversable(GetWorldspawn())->insert(brush); vTop[2] += height; vBot[2] += height; diff --git a/contrib/bobtoolz/shapes.h b/contrib/bobtoolz/shapes.h index d48969e1..c277d428 100644 --- a/contrib/bobtoolz/shapes.h +++ b/contrib/bobtoolz/shapes.h @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define MAX_POLYGON_FACES 128 // generic (detail added 12/01/01, for AC+) -void AddFaceWithTexture(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail); +void AddFaceWithTexture(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail); // ------------- // ---caulked--- diff --git a/contrib/bobtoolz/visfind.cpp b/contrib/bobtoolz/visfind.cpp index ae3602d1..e5b890b1 100644 --- a/contrib/bobtoolz/visfind.cpp +++ b/contrib/bobtoolz/visfind.cpp @@ -2,12 +2,12 @@ // Date: Oct 5, 2001 // Written by: Brad Whitehead (whiteheb@gamerstv.net) -#include "StdAfx.h" +#include "visfind.h" #include "dialogs/dialogs-gtk.h" #include "DWinding.h" #include "bsploader.h" -#include "gtkr_list.h" +#include typedef struct { int portalclusters; @@ -122,7 +122,7 @@ int bsp_countclusters_mask(byte *bitvector, byte *maskvector, int length) return(c); } -void AddCluster(list *pointlist, dleaf_t *cl, bool* repeatlist, vec3_t clr) +void AddCluster(std::list *pointlist, dleaf_t *cl, bool* repeatlist, vec3_t clr) { DWinding* w; @@ -164,11 +164,11 @@ void AddCluster(list *pointlist, dleaf_t *cl, bool* repeatlist, vec3_ CreateTrace ============= */ -list *CreateTrace( dleaf_t *leaf, int c, vis_header *header, byte *visdata, byte *seen ) +std::list *CreateTrace( dleaf_t *leaf, int c, vis_header *header, byte *visdata, byte *seen ) { byte *vis; int i, j, clusterNum; - list *pointlist = new list; + std::list *pointlist = new std::list; bool* repeatlist = new bool[numDrawSurfaces]; dleaf_t *cl; @@ -214,7 +214,7 @@ TraceCluster setup for CreateTrace ============= */ -list *TraceCluster (int leafnum) +std::list *TraceCluster (int leafnum) { byte seen[(MAX_MAP_LEAFS/8) + 1]; vis_header *vheader; @@ -232,14 +232,14 @@ list *TraceCluster (int leafnum) return CreateTrace(leaf, leaf->cluster, vheader, visdata, seen); } -list* BuildTrace(char* filename, vec3_t v_origin) +std::list* BuildTrace(char* filename, vec3_t v_origin) { if(!LoadBSPFile(filename)) return NULL; int leafnum = bsp_leafnumfororigin(v_origin); - list *pointlist = TraceCluster(leafnum); + std::list *pointlist = TraceCluster(leafnum); FreeBSPData(); diff --git a/contrib/bobtoolz/visfind.h b/contrib/bobtoolz/visfind.h index 0a4b601e..3476d864 100644 --- a/contrib/bobtoolz/visfind.h +++ b/contrib/bobtoolz/visfind.h @@ -1 +1,7 @@ -list *BuildTrace(char* filename, vec3_t v_origin); + +#include +#include "mathlib.h" + +class DWinding; + +std::list *BuildTrace(char* filename, vec3_t v_origin); diff --git a/contrib/gtkgensurf/genmap.cpp b/contrib/gtkgensurf/genmap.cpp index ef5001cd..6e9c95dc 100644 --- a/contrib/gtkgensurf/genmap.cpp +++ b/contrib/gtkgensurf/genmap.cpp @@ -1979,7 +1979,7 @@ scene::Node* MakePatch(void) #if 0 patch->m_patch->SetShader(Texture[Game][0]); #endif - h_worldspawn->m_traverse->insert(patch); + Node_getTraversable(h_worldspawn)->insert(patch); return patch; } @@ -2021,7 +2021,7 @@ void MakeBrush(BRUSH *brush) } #endif - h_func_group->m_traverse->insert(node); + Node_getTraversable(h_func_group)->insert(node); } //============================================================= void OpenFuncGroup() diff --git a/contrib/prtview/portals.cpp b/contrib/prtview/portals.cpp index 6b3178c0..e5dea308 100644 --- a/contrib/prtview/portals.cpp +++ b/contrib/prtview/portals.cpp @@ -337,7 +337,7 @@ void Portals_constructShaders() GlobalOpenGLStateLibrary().insert(g_state_wireframe, state); GlobalOpenGLStateLibrary().getDefaultState(state); - state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH|RENDER_POLYGONSMOOTH; + state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH; if(portals.aa_3d) { diff --git a/include/ibrush.h b/include/ibrush.h index 318ee552..187ebcc4 100644 --- a/include/ibrush.h +++ b/include/ibrush.h @@ -23,12 +23,81 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_IBRUSH_H #include "generic/constant.h" +#include "generic/callback.h" +#include "math/vector.h" +#include "itexdef.h" namespace scene { class Node; } +#if 0 +class IBrushFace +{ +public: + virtual const char* GetShader() const = 0; + virtual void SetShader(const char* name) = 0; + virtual const TextureProjection& GetTexdef() const = 0; + virtual void GetTexdef(TextureProjection& projection) const = 0; + virtual void SetTexdef(const TextureProjection& projection) = 0; + virtual void GetFlags(ContentsFlagsValue& flags) const = 0; + virtual void SetFlags(const ContentsFlagsValue& flags) = 0; + virtual void ShiftTexdef(float s, float t) = 0; + virtual void ScaleTexdef(float s, float t) = 0; + virtual void RotateTexdef(float angle) = 0; + virtual void FitTexture(float s_repeat, float t_repeat) = 0; + virtual bool isDetail() const = 0; + virtual void setDetail(bool detail) = 0; +}; + +class IBrush +{ +public: + STRING_CONSTANT(Name, "IBrush"); + virtual void reserve(std::size_t count) = 0; + virtual void clear() = 0; + virtual void copy(const IBrush& other) = 0; + virtual IBrushFace* addPlane(const Vector3& p0, const Vector3& p1, const Vector3& p2, const char* shader, const TextureProjection& projection) = 0; + virtual const AABB& localAABB() const = 0; + virtual void removeEmptyFaces() = 0; +}; + +class IBrushFaceInstance +{ +public: + virtual IBrushFace& getFace() = 0; + virtual const IBrushFace& getFace() const = 0; + virtual bool isSelected() const = 0; + virtual void setSelected(SelectionSystem::EComponentMode mode, bool select) const = 0; +}; + +class IBrushInstance +{ +public: + STRING_CONSTANT(Name, "IBrushInstance"); + virtual void forEachFaceInstance(const BrushInstanceVisitor& visitor) = 0; +}; +#endif + +class _QERFaceData +{ +public: + _QERFaceData() : contents(0), flags(0), value(0), m_shader("") + { + } + Vector3 m_p0; + Vector3 m_p1; + Vector3 m_p2; + texdef_t m_texdef; + const char* m_shader; + int contents; + int flags; + int value; +}; + +typedef Callback1 BrushFaceDataCallback; + class BrushCreator { public: @@ -36,6 +105,8 @@ public: STRING_CONSTANT(Name, "brush"); virtual scene::Node& createBrush() = 0; virtual bool useAlternativeTextureProjection() const = 0; + virtual void forEachBrushFace(scene::Node& brush, const BrushFaceDataCallback& callback) = 0; + virtual bool addBrushFace(scene::Node& brush, const _QERFaceData& faceData) = 0; }; #include "modulesystem.h" diff --git a/include/icamera.h b/include/icamera.h index 0c6f4dd9..c98fdc06 100644 --- a/include/icamera.h +++ b/include/icamera.h @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_ICAMERA_H #include "generic/constant.h" +#include "generic/callbackfwd.h" class Matrix4; @@ -39,8 +40,6 @@ public: virtual void setFieldOfView(float fieldOfView) = 0; }; -class Callback; - class CameraModel { public: diff --git a/include/ientity.h b/include/ientity.h index 34a5638d..f96e0495 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -29,11 +29,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA class EntityClass; +typedef Callback1 KeyObserver; + +class EntityKeyValue +{ +public: + virtual const char* c_str() const = 0; + virtual void assign(const char* other) = 0; + virtual void attach(const KeyObserver& observer) = 0; + virtual void detach(const KeyObserver& observer) = 0; +}; + class Entity { public: STRING_CONSTANT(Name, "Entity"); + class Observer + { + public: + virtual void insert(const char* key, EntityKeyValue& value) = 0; + virtual void erase(const char* key, EntityKeyValue& value) = 0; + virtual void clear() { }; + }; + class Visitor { public: @@ -45,6 +64,8 @@ public: virtual void setKeyValue(const char* key, const char* value) = 0; virtual const char* getKeyValue(const char* key) const = 0; virtual bool isContainer() const = 0; + void attach(Observer& observer); + void detach(Observer& observer); }; class EntityCopyingVisitor : public Entity::Visitor diff --git a/include/ifilesystem.h b/include/ifilesystem.h index b44c7fbc..339c82f1 100644 --- a/include/ifilesystem.h +++ b/include/ifilesystem.h @@ -24,9 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "generic/constant.h" +#include "generic/callbackfwd.h" -template -class Callback1; typedef Callback1 ArchiveNameCallback; typedef Callback1 FileNameCallback; diff --git a/include/irender.h b/include/irender.h index 77cdf0e8..28466708 100644 --- a/include/irender.h +++ b/include/irender.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_IRENDER_H #include "generic/constant.h" +#include "generic/callbackfwd.h" // Rendering states to sort by. @@ -88,9 +89,6 @@ public: } }; -template -class Callback1; - class Renderable; typedef Callback1 RenderableCallback; diff --git a/include/iscenegraph.h b/include/iscenegraph.h index 48e99aaf..18e50f77 100644 --- a/include/iscenegraph.h +++ b/include/iscenegraph.h @@ -24,14 +24,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "generic/constant.h" +#include "signal/signalfwd.h" template class Stack; template class Reference; -class Callback; - namespace scene { class Instance; @@ -105,15 +104,15 @@ namespace scene virtual void sceneChanged() = 0; /// \brief Add a \p callback to be invoked when the scene changes. /// \todo Move to a separate class. - virtual void addSceneChangedCallback(const Callback& callback) = 0; + virtual void addSceneChangedCallback(const SignalHandler& handler) = 0; /// \brief Invokes all bounds-changed callbacks. Called when the bounds of any instance in the scene change. /// \todo Move to a separate class. virtual void boundsChanged() = 0; /// \brief Add a \p callback to be invoked when the bounds of any instance in the scene change. - virtual void addBoundsChangedCallback(const Callback& callback) = 0; + virtual SignalHandlerId addBoundsChangedCallback(const SignalHandler& boundsChanged) = 0; /// \brief Remove a \p callback to be invoked when the bounds of any instance in the scene change. - virtual void removeBoundsChangedCallback(const Callback& callback) = 0; + virtual void removeBoundsChangedCallback(SignalHandlerId id) = 0; virtual TypeId getNodeTypeId(const char* name) = 0; virtual TypeId getInstanceTypeId(const char* name) = 0; @@ -208,9 +207,9 @@ inline scene::Graph& GlobalSceneGraph() return GlobalSceneGraphModule::getTable(); } -inline void AddSceneChangeCallback(const Callback& callback) +inline void AddSceneChangeCallback(const SignalHandler& handler) { - GlobalSceneGraph().addSceneChangedCallback(callback); + GlobalSceneGraph().addSceneChangedCallback(handler); } inline void SceneChangeNotify() { diff --git a/include/iselection.h b/include/iselection.h index 2a86a31e..ec32561e 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -24,15 +24,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "generic/constant.h" +#include "generic/callbackfwd.h" +#include "signal/signalfwd.h" class Renderer; class View; -class Callback; - -template -class Callback1; - class Selectable { public: @@ -61,6 +58,7 @@ class Matrix4; typedef Vector4 Quaternion; typedef Callback1 SelectionChangeCallback; +typedef SignalHandler1 SelectionChangeHandler; class SelectionSystem { @@ -117,7 +115,7 @@ public: virtual void foreachSelected(const Visitor& visitor) const = 0; virtual void foreachSelectedComponent(const Visitor& visitor) const = 0; - virtual void addSelectionChangeCallback(const SelectionChangeCallback& callback) = 0; + virtual void addSelectionChangeCallback(const SelectionChangeHandler& handler) = 0; virtual void NudgeManipulator(const Vector3& nudge, const Vector3& view) = 0; diff --git a/include/ishaders.h b/include/ishaders.h index 49ddf46b..928dd1de 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_ISHADERS_H #include "generic/constant.h" +#include "generic/callbackfwd.h" enum { @@ -78,8 +79,6 @@ public: virtual float alphaTest() const = 0; }; -template -class Callback1; typedef Callback1 ShaderLayerCallback; @@ -133,7 +132,6 @@ public: virtual qtexture_t* lightFalloffImage() const = 0; }; -class Callback; typedef struct _GSList GSList; typedef Callback1 ShaderNameCallback; diff --git a/include/iundo.h b/include/iundo.h index 6719a497..4dcbad85 100644 --- a/include/iundo.h +++ b/include/iundo.h @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "generic/constant.h" +#include "generic/callbackfwd.h" class UndoMemento { @@ -47,8 +48,6 @@ public: virtual void save(Undoable* undoable) = 0; }; -class Callback; - class UndoTracker { public: diff --git a/include/mapfile.h b/include/mapfile.h index 2df91a7d..e53d79c1 100644 --- a/include/mapfile.h +++ b/include/mapfile.h @@ -25,8 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "iscenegraph.h" - -class Callback; +#include "generic/callbackfwd.h" const std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits::max(); diff --git a/include/modelskin.h b/include/modelskin.h index 1104800d..c01b5f30 100644 --- a/include/modelskin.h +++ b/include/modelskin.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_MODELSKIN_H #include "generic/constant.h" +#include "generic/callbackfwd.h" class SkinRemap { @@ -34,8 +35,6 @@ public: } }; -template -class Callback1; typedef Callback1 SkinRemapCallback; class ModuleObserver; diff --git a/include/nameable.h b/include/nameable.h index 9147554e..8e1357a4 100644 --- a/include/nameable.h +++ b/include/nameable.h @@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_NAMEABLE_H #include "generic/constant.h" +#include "generic/callbackfwd.h" -template -class Callback1; typedef Callback1 NameCallback; class Nameable diff --git a/include/namespace.h b/include/namespace.h index df8fda4a..30367bfd 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_NAMESPACE_H #include "generic/constant.h" +#include "generic/callbackfwd.h" -template -class Callback1; typedef Callback1 NameCallback; typedef Callback1 NameCallbackCallback; diff --git a/include/preferencesystem.h b/include/preferencesystem.h index f1891ae3..f5ebae1d 100644 --- a/include/preferencesystem.h +++ b/include/preferencesystem.h @@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_PREFERENCESYSTEM_H #include "generic/constant.h" +#include "generic/callbackfwd.h" -template -class Callback1; typedef Callback1 StringImportCallback; typedef Callback1 StringExportCallback; diff --git a/include/qerplugin.h b/include/qerplugin.h index 1a459195..3e352e53 100644 --- a/include/qerplugin.h +++ b/include/qerplugin.h @@ -90,8 +90,27 @@ typedef GtkImage* (* PFN_QERAPP_NEWIMAGE) (const char* filename); // ======================================== +namespace scene +{ + class Node; +} + class ModuleObserver; +#include "signal/signalfwd.h" +#include "windowobserver.h" +#include "math/vector.h" + +typedef SignalHandler3 MouseEventHandler; +typedef SignalFwd::handler_id_type MouseEventHandlerId; + +enum VIEWTYPE +{ + YZ = 0, + XZ = 1, + XY = 2 +}; + // the radiant core API struct _QERFuncTable_1 { @@ -107,6 +126,8 @@ struct _QERFuncTable_1 const char* (*getGameMode)(); const char* (*getMapName)(); + scene::Node& (*getMapWorldEntity)(); + float (*getGridSize)(); const char* (*getGameDescriptionKeyValue)(const char* key); const char* (*getRequiredGameDescriptionKeyValue)(const char* key); @@ -120,6 +141,12 @@ struct _QERFuncTable_1 void (*attachGameModeObserver)(ModuleObserver& observer); void (*detachGameModeObserver)(ModuleObserver& observer); + MouseEventHandlerId (*XYWindowMouseDown_connect)(const MouseEventHandler& handler); + void (*XYWindowMouseDown_disconnect)(MouseEventHandlerId id); + VIEWTYPE (*XYWindow_getViewType)(); + Vector3 (*XYWindow_windowToWorld)(const WindowVector& position); + const char* (*TextureBrowser_getSelectedShader)(); + // GTK+ functions PFN_QERAPP_MESSAGEBOX m_pfnMessageBox; PFN_QERAPP_FILEDIALOG m_pfnFileDialog; diff --git a/include/selectable.h b/include/selectable.h index f6da5cc5..774f4e0b 100644 --- a/include/selectable.h +++ b/include/selectable.h @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "math/vector.h" #include "scenelib.h" +#include "generic/callbackfwd.h" class SelectionIntersection { @@ -281,8 +282,6 @@ inline SelectionTestable* Instance_getSelectionTestable(scene::Instance& instanc } -template -class Callback1; class Plane3; typedef Callback1 PlaneCallback; diff --git a/libs/container/hashtable.h b/libs/container/hashtable.h index c4b1aded..88d672cf 100644 --- a/libs/container/hashtable.h +++ b/libs/container/hashtable.h @@ -109,11 +109,11 @@ namespace HashTableDetail : m_hash(hash), m_value(key, value) { } - BucketNode* getNext() + BucketNode* getNext() const { return static_cast(next); } - BucketNode* getPrev() + BucketNode* getPrev() const { return static_cast(prev); } diff --git a/libs/debugging/debugging.h b/libs/debugging/debugging.h index 2a9cbe70..642283fd 100644 --- a/libs/debugging/debugging.h +++ b/libs/debugging/debugging.h @@ -39,8 +39,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define DEBUGGER_BREAKPOINT() raise(SIGTRAP); #endif - -#define FILE_LINE __FILE__ ":" << __LINE__ +#define STR(x) #x +#define STR2(x) STR(x) +#define FILE_LINE __FILE__ ":" STR2(__LINE__) #if defined(_DEBUG) || 1 #define DEBUG_ASSERTS @@ -114,13 +115,13 @@ inline DebugMessageHandler& globalDebugMessageHandler() #define ASSERT_MESSAGE(condition, message)\ if(!(condition))\ {\ - globalDebugMessageHandler().getOutputStream() << FILE_LINE << "\nassertion failure: " << message << "\n";\ + globalDebugMessageHandler().getOutputStream() << FILE_LINE "\nassertion failure: " << message << "\n";\ if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); }\ } else\ /// \brief Sends a \p message to the current debug-message-handler text-output-stream. #define ERROR_MESSAGE(message)\ -globalDebugMessageHandler().getOutputStream() << FILE_LINE << "\nruntime error: " << message << "\n";\ +globalDebugMessageHandler().getOutputStream() << FILE_LINE "\nruntime error: " << message << "\n";\ if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); } else\ #define ASSERT_NOTNULL(ptr) ASSERT_MESSAGE(ptr != 0, "pointer \"" #ptr "\" is null") diff --git a/libs/entitylib.h b/libs/entitylib.h index b9e93002..4a34f0a5 100644 --- a/libs/entitylib.h +++ b/libs/entitylib.h @@ -304,13 +304,11 @@ public: }; -typedef Callback1 KeyObserver; - /// \brief A key/value pair of strings. /// /// - Notifies observers when value changes - value changes to "" on destruction. /// - Provides undo support through the global undo system. -class KeyValue +class KeyValue : public EntityKeyValue { typedef UnsortedSet KeyObservers; @@ -414,13 +412,6 @@ class EntityKeyValues : public Entity public: typedef KeyValue Value; - class Observer - { - public: - virtual void insert(const char* key, Value& value) = 0; - virtual void erase(const char* key, Value& value) = 0; - }; - static StringPool& getPool() { return Static::instance(); @@ -553,6 +544,11 @@ public: } ~EntityKeyValues() { + for(Observers::iterator i = m_observers.begin(); i != m_observers.end();) + { + // post-increment to allow current element to be removed safely + (*i++)->clear(); + } ASSERT_MESSAGE(m_observers.empty(), "EntityKeyValues::~EntityKeyValues: observers still attached"); } diff --git a/libs/generic/callback.cpp b/libs/generic/callback.cpp index 6152b9dc..2344830a 100644 --- a/libs/generic/callback.cpp +++ b/libs/generic/callback.cpp @@ -107,3 +107,179 @@ namespace ExampleReferenceCaller } #endif + +namespace +{ + class A1 + { + }; + class A2 + { + }; + class A3 + { + }; + class A4 + { + }; + + class Test + { + public: + void test0() + { + } + typedef Member Test0; + typedef MemberCaller Test0Caller; + void test0const() const + { + } + typedef ConstMember Test0Const; + typedef ConstMemberCaller Test0ConstCaller; + void test1(A1) + { + } + typedef Member1 Test1; + typedef MemberCaller1 Test1Caller; + void test1const(A1) const + { + } + typedef ConstMember1 Test1Const; + typedef ConstMemberCaller1 Test1ConstCaller; + void test2(A1, A2) + { + } + typedef Member2 Test2; + void test2const(A1, A2) const + { + } + typedef ConstMember2 Test2Const; + void test3(A1, A2, A3) + { + } + typedef Member3 Test3; + void test3const(A1, A2, A3) const + { + } + typedef ConstMember3 Test3Const; + }; + + void test0free() + { + } + typedef FreeCaller<&test0free> Test0FreeCaller; + void test1free(A1) + { + } + typedef FreeCaller1 Test1FreeCaller; + void test2free(A1, A2) + { + } + typedef Function2 Test2Free; + void test3free(A1, A2, A3) + { + } + typedef Function3 Test3Free; + + + void test0(Test& test) + { + } + typedef ReferenceCaller Test0Caller; + + void test0const(const Test& test) + { + } + typedef ConstReferenceCaller Test0ConstCaller; + + void test0p(Test* test) + { + } + typedef PointerCaller Test0PCaller; + + void test0constp(const Test* test) + { + } + typedef ConstPointerCaller Test0ConstPCaller; + + void test1(Test& test, A1) + { + } + typedef ReferenceCaller1 Test1Caller; + + void test1const(const Test& test, A1) + { + } + typedef ConstReferenceCaller1 Test1ConstCaller; + + void test1p(Test* test, A1) + { + } + typedef PointerCaller1 Test1PCaller; + + void test1constp(const Test* test, A1) + { + } + typedef ConstPointerCaller1 Test1ConstPCaller; + + void test2(Test& test, A1, A2) + { + } + typedef Function3 Test2; + + void test3(Test& test, A1, A2, A3) + { + } + typedef Function4 Test3; + + void instantiate() + { + Test test; + const Test& testconst = test; + { + Callback a = Test0FreeCaller(); + Callback b = Test::Test0Caller(test); + b = makeCallback0(Test::Test0(), test); + Callback c = Test::Test0ConstCaller(testconst); + c = makeCallback0(Test::Test0Const(), test); + Callback d = Test0Caller(test); + Callback e = Test0ConstCaller(testconst); + Callback f = Test0PCaller(&test); + Callback g = Test0ConstPCaller(&testconst); + a(); + bool u = a != b; + } + { + typedef Callback1 TestCallback1; + TestCallback1 a = Test1FreeCaller(); + TestCallback1 b = Test::Test1Caller(test); + b = makeCallback1(Test::Test1(), test); + TestCallback1 c = Test::Test1ConstCaller(testconst); + c = makeCallback1(Test::Test1Const(), test); + TestCallback1 d = Test1Caller(test); + TestCallback1 e = Test1ConstCaller(testconst); + TestCallback1 f = Test1PCaller(&test); + TestCallback1 g = Test1ConstPCaller(&testconst); + a(A1()); + bool u = a != b; + } + { + typedef Callback2 TestCallback2; + TestCallback2 a = makeStatelessCallback2(Test2Free()); + TestCallback2 b = makeCallback2(Test2(), test); + TestCallback2 c = makeCallback2(Test::Test2(), test); + TestCallback2 d = makeCallback2(Test::Test2Const(), test); + a(A1(), A2()); + bool u = a != b; + } + { + typedef Callback3 TestCallback3; + TestCallback3 a = makeStatelessCallback3(Test3Free()); + TestCallback3 b = makeCallback3(Test3(), test); + TestCallback3 c = makeCallback3(Test::Test3(), test); + TestCallback3 d = makeCallback3(Test::Test3Const(), test); + a(A1(), A2(), A3()); + bool u = a != b; + } + } +} diff --git a/libs/generic/callback.h b/libs/generic/callback.h index e5a8c8b4..68fc0662 100644 --- a/libs/generic/callback.h +++ b/libs/generic/callback.h @@ -23,28 +23,206 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_GENERIC_CLOSURE_H /// \file -/// \brief Type-safe techniques for binding the first argument of an anonymous callback. +/// \brief Type-safe techniques for binding the first argument of an opaque callback. #include +#include "functional.h" +#include "callbackfwd.h" -/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer. -/// -/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller. -class Callback +template +inline void* convertToOpaque(Type* t) { - typedef void (*Thunk)(void*); - void* m_environment; - Thunk m_thunk; + return t; +} +template +inline void* convertToOpaque(const Type* t) +{ + return const_cast(t); +} +template +inline void* convertToOpaque(Type& t) +{ + return &t; +} +template +inline void* convertToOpaque(const Type& t) +{ + return const_cast(&t); +} + + +template +class ConvertFromOpaque +{ +}; + +template +class ConvertFromOpaque +{ +public: + static Type& apply(void* p) + { + return *static_cast(p); + } +}; - static void nullThunk(void*) +template +class ConvertFromOpaque +{ +public: + static const Type& apply(void* p) { + return *static_cast(p); } +}; + +template +class ConvertFromOpaque +{ +public: + static Type* apply(void* p) + { + return static_cast(p); + } +}; + +template +class ConvertFromOpaque +{ +public: + static const Type* apply(void* p) + { + return static_cast(p); + } +}; + +template +class BindFirstOpaque +{ + typedef typename Caller::first_argument_type FirstBound; + FirstBound firstBound; public: - Callback() : m_environment(0), m_thunk(nullThunk) + typedef typename Caller::result_type result_type; + explicit BindFirstOpaque(FirstBound firstBound) : firstBound(firstBound) { } - Callback(void* environment, Thunk function) : m_environment(environment), m_thunk(function) + result_type operator()() const + { + return Caller::call(firstBound); + } + FirstBound getBound() const + { + return firstBound; + } + static result_type thunk(void* environment) + { + return Caller::call(ConvertFromOpaque::apply(environment)); + } + void* getEnvironment() const + { + return convertToOpaque(firstBound); + } +}; + +template +class BindFirstOpaque1 +{ + typedef typename Caller::first_argument_type FirstBound; + FirstBound firstBound; +public: + typedef typename Caller::second_argument_type first_argument_type; + typedef typename Caller::result_type result_type; + explicit BindFirstOpaque1(FirstBound firstBound) : firstBound(firstBound) + { + } + result_type operator()(first_argument_type a1) const + { + return Caller::call(firstBound, a1); + } + FirstBound getBound() const + { + return firstBound; + } + static result_type thunk(void* environment, first_argument_type a1) + { + return Caller::call(ConvertFromOpaque::apply(environment), a1); + } + void* getEnvironment() const + { + return convertToOpaque(firstBound); + } +}; + +template +class BindFirstOpaque2 +{ + typedef typename Caller::first_argument_type FirstBound; + FirstBound firstBound; +public: + typedef typename Caller::second_argument_type first_argument_type; + typedef typename Caller::third_argument_type second_argument_type; + typedef typename Caller::result_type result_type; + explicit BindFirstOpaque2(FirstBound firstBound) : firstBound(firstBound) + { + } + result_type operator()(first_argument_type a1, second_argument_type a2) const + { + return Caller::call(firstBound, a1, a2); + } + FirstBound getBound() const + { + return firstBound; + } + static result_type thunk(void* environment, first_argument_type a1, second_argument_type a2) + { + return Caller::call(ConvertFromOpaque::apply(environment), a1, a2); + } + void* getEnvironment() const + { + return convertToOpaque(firstBound); + } +}; + +template +class BindFirstOpaque3 +{ + typedef typename Caller::first_argument_type FirstBound; + FirstBound firstBound; +public: + typedef typename Caller::second_argument_type first_argument_type; + typedef typename Caller::third_argument_type second_argument_type; + typedef typename Caller::fourth_argument_type third_argument_type; + typedef typename Caller::result_type result_type; + explicit BindFirstOpaque3(FirstBound firstBound) : firstBound(firstBound) + { + } + result_type operator()(first_argument_type a1, second_argument_type a2, third_argument_type a3) const + { + return Caller::call(firstBound, a1, a2, a3); + } + FirstBound getBound() const + { + return firstBound; + } + static result_type thunk(void* environment, first_argument_type a1, second_argument_type a2, third_argument_type a3) + { + return Caller::call(ConvertFromOpaque::apply(environment), a1, a2, a3); + } + void* getEnvironment() const + { + return convertToOpaque(firstBound); + } +}; + +template +class CallbackBase +{ + void* m_environment; + Thunk_ m_thunk; +public: + typedef Thunk_ Thunk; + CallbackBase(void* environment, Thunk function) : m_environment(environment), m_thunk(function) { } void* getEnvironment() const @@ -55,113 +233,226 @@ public: { return m_thunk; } - void operator()() const - { - m_thunk(m_environment); - } }; -inline bool operator==(const Callback& self, const Callback& other) +template +inline bool operator==(const CallbackBase& self, const CallbackBase& other) { return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk(); } -inline bool operator<(const Callback& self, const Callback& other) +template +inline bool operator!=(const CallbackBase& self, const CallbackBase& other) +{ + return !(self == other); +} +template +inline bool operator<(const CallbackBase& self, const CallbackBase& other) { return self.getEnvironment() < other.getEnvironment() || (!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk()); } -/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and one other argument. + +/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer. /// -/// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1. -template -class Callback1 +/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller. +template +class Callback0 : public CallbackBase { - typedef void (*Thunk)(void*, FirstArgument); - void* m_environment; - Thunk m_thunk; - - static void nullThunk(void*, FirstArgument) + typedef CallbackBase Base; + static Result nullThunk(void*) { } public: - typedef FirstArgument first_argument_type; + typedef Result result_type; - Callback1() : m_environment(0), m_thunk(nullThunk) - { - } - Callback1(void* environment, Thunk function) : m_environment(environment), m_thunk(function) + Callback0() : Base(0, nullThunk) { } - void* getEnvironment() const + template + Callback0(const BindFirstOpaque& caller) : Base(caller.getEnvironment(), BindFirstOpaque::thunk) { - return m_environment; } - Thunk getThunk() const + Callback0(void* environment, Thunk function) : Base(environment, function) { - return m_thunk; } - void operator()(FirstArgument firstArgument) const + result_type operator()() const { - m_thunk(m_environment, firstArgument); + return getThunk()(getEnvironment()); } }; -template -inline bool operator==(const Callback1& self, const Callback1& other) +template +inline Callback0 makeCallback0(const Caller& caller, typename Caller::first_argument_type callee) { - return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk(); + return Callback0(BindFirstOpaque(callee)); } -template -inline bool operator<(const Callback1& self, const Callback1& other) +template +inline Callback0 makeStatelessCallback0(const Caller& caller) { - return self.getEnvironment() < other.getEnvironment() || - (!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk()); + return makeCallback0(Caller0To1(), 0); } -template -class FunctorInvoke +typedef Callback0 Callback; + + + +/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and one other argument. +/// +/// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1. +template +class Callback1 : public CallbackBase { + typedef CallbackBase Base; + static Result nullThunk(void*, FirstArgument) + { + } + public: - inline void operator()(Functor functor) + typedef FirstArgument first_argument_type; + typedef Result result_type; + + Callback1() : Base(0, nullThunk) { - functor(); + } + template + Callback1(const BindFirstOpaque1& caller) : Base(caller.getEnvironment(), BindFirstOpaque1::thunk) + { + } + Callback1(void* environment, Thunk function) : Base(environment, function) + { + } + result_type operator()(FirstArgument firstArgument) const + { + return getThunk()(getEnvironment(), firstArgument); } }; -typedef FunctorInvoke CallbackInvoke; +template +inline Callback1 makeCallback1(const Caller& caller, typename Caller::first_argument_type callee) +{ + return Callback1(BindFirstOpaque1(callee)); +} +template +inline Callback1 makeStatelessCallback1(const Caller& caller) +{ + return makeCallback1(Caller1To2(), 0); +} -template -class Functor1Invoke +/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and two other arguments. +/// +template +class Callback2 : public CallbackBase { - FirstArgument m_firstArgument; + typedef CallbackBase Base; + static Result nullThunk(void*, FirstArgument, SecondArgument) + { + } + public: - Functor1Invoke(FirstArgument firstArgument) : m_firstArgument(firstArgument) + typedef FirstArgument first_argument_type; + typedef SecondArgument second_argument_type; + typedef Result result_type; + + Callback2() : Base(0, nullThunk) + { + } + template + Callback2(const BindFirstOpaque2& caller) : Base(caller.getEnvironment(), BindFirstOpaque2::thunk) { } - inline void operator()(Functor functor) + Callback2(void* environment, Thunk function) : Base(environment, function) { - functor(m_firstArgument); + } + result_type operator()(FirstArgument firstArgument, SecondArgument secondArgument) const + { + return getThunk()(getEnvironment(), firstArgument, secondArgument); } }; +template +inline Callback2< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::result_type +> makeCallback2(const Caller& caller, typename Caller::first_argument_type callee) +{ + return Callback2< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::result_type + >(BindFirstOpaque2(callee)); +} +template +inline Callback2< + typename Caller::first_argument_type, + typename Caller::second_argument_type, + typename Caller::result_type +> makeStatelessCallback2(const Caller& caller) +{ + return makeCallback2(Caller2To3(), 0); +} -typedef Callback1 BoolImportCallback; -typedef Callback1 BoolExportCallback; -typedef Callback1 IntImportCallback; -typedef Callback1 IntExportCallback; +/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and three other arguments. +/// +template +class Callback3 : public CallbackBase +{ + typedef CallbackBase Base; + static Result nullThunk(void*, FirstArgument, SecondArgument, ThirdArgument) + { + } -typedef Callback1 FloatImportCallback; -typedef Callback1 FloatExportCallback; +public: + typedef FirstArgument first_argument_type; + typedef SecondArgument second_argument_type; + typedef ThirdArgument third_argument_type; + typedef Result result_type; -typedef Callback1 StringImportCallback; -typedef Callback1 StringExportCallback; + Callback3() : Base(0, nullThunk) + { + } + template + Callback3(const BindFirstOpaque3& caller) : Base(caller.getEnvironment(), BindFirstOpaque3::thunk) + { + } + Callback3(void* environment, Thunk function) : Base(environment, function) + { + } + result_type operator()(FirstArgument firstArgument, SecondArgument secondArgument, ThirdArgument thirdArgument) const + { + return getThunk()(getEnvironment(), firstArgument, secondArgument, thirdArgument); + } +}; -typedef Callback1 SizeImportCallback; -typedef Callback1 SizeExportCallback; +template +inline Callback3< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::fourth_argument_type, + typename Caller::result_type +> makeCallback3(const Caller& caller, typename Caller::first_argument_type callee) +{ + return Callback3< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::fourth_argument_type, + typename Caller::result_type + >(BindFirstOpaque3(callee)); +} +template +inline Callback3< + typename Caller::first_argument_type, + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::result_type +> makeStatelessCallback3(const Caller& caller) +{ + return makeCallback3(Caller3To4(), 0); +} /// \brief Forms a Callback from a non-const Environment reference and a non-const Environment member-function. @@ -170,24 +461,11 @@ typedef Callback1 SizeExportCallback; /// \skipline MemberCaller example /// \until end example template -class MemberCaller +class MemberCaller : public BindFirstOpaque< Member > { - Environment& m_environment; public: - MemberCaller(Environment& environment) : m_environment(environment) - { - } - void* getEnvironment() const + MemberCaller(Environment& environment) : BindFirstOpaque< Member >(environment) { - return &m_environment; - } - static void thunk(void* environment) - { - ((*reinterpret_cast(environment)).*member)(); - } - operator Callback() const - { - return Callback(getEnvironment(), thunk); } }; @@ -197,71 +475,32 @@ public: /// \skipline MemberCaller example /// \until end example template -class ConstMemberCaller +class ConstMemberCaller : public BindFirstOpaque< ConstMember > { - const Environment& m_environment; public: - ConstMemberCaller(const Environment& environment) : m_environment(environment) - { - } - void* getEnvironment() const + ConstMemberCaller(const Environment& environment) : BindFirstOpaque< ConstMember >(environment) { - return const_cast(&m_environment); - } - static void thunk(void* environment) - { - ((*reinterpret_cast(environment)).*member)(); - } - operator Callback() const - { - return Callback(getEnvironment(), thunk); } }; /// \brief Forms a Callback from a non-const Environment reference and a const Environment member-function which takes one argument. template -class MemberCaller1 +class MemberCaller1 : public BindFirstOpaque1< Member1 > { - Environment& m_environment; public: - MemberCaller1(Environment& environment) : m_environment(environment) + MemberCaller1(Environment& environment) : BindFirstOpaque1< Member1 >(environment) { } - void* getEnvironment() const - { - return &m_environment; - } - static void thunk(void* environment, FirstArgument firstArgument) - { - ((*reinterpret_cast(environment)).*member)(firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); - } }; /// \brief Forms a Callback from a const Environment reference and a const Environment member-function which takes one argument. template -class ConstMemberCaller1 +class ConstMemberCaller1 : public BindFirstOpaque1< ConstMember1 > { - const Environment& m_environment; public: - ConstMemberCaller1(const Environment& environment) : m_environment(environment) + ConstMemberCaller1(const Environment& environment) : BindFirstOpaque1< ConstMember1 >(environment) { } - void* getEnvironment() const - { - return const_cast(&m_environment); - } - static void thunk(void* environment, FirstArgument firstArgument) - { - ((*reinterpret_cast(environment)).*member)(firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); - } }; /// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference. @@ -270,24 +509,11 @@ public: /// \skipline ReferenceCaller example /// \until end example template -class ReferenceCaller +class ReferenceCaller : public BindFirstOpaque< Function1 > { - Environment& m_environment; public: - ReferenceCaller(Environment& environment) : m_environment(environment) - { - } - void* getEnvironment() const + ReferenceCaller(Environment& environment) : BindFirstOpaque< Function1 >(environment) { - return &m_environment; - } - static void thunk(void* environment) - { - (func)(*reinterpret_cast(environment)); - } - operator Callback() const - { - return Callback(getEnvironment(), thunk); } }; @@ -297,201 +523,91 @@ public: /// \skipline ReferenceCaller example /// \until end example template -class ConstReferenceCaller +class ConstReferenceCaller : public BindFirstOpaque< Function1 > { - const Environment& m_environment; public: - ConstReferenceCaller(const Environment& environment) : m_environment(environment) - { - } - void* getEnvironment() const - { - return const_cast(&m_environment); - } - static void thunk(void* environment) + ConstReferenceCaller(const Environment& environment) : BindFirstOpaque< Function1 >(environment) { - (func)(*reinterpret_cast(environment)); - } - operator Callback() const - { - return Callback(getEnvironment(), thunk); } }; /// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference and one other argument. template -class ReferenceCaller1 +class ReferenceCaller1 : public BindFirstOpaque1< Function2 > { - Environment& m_environment; public: - ReferenceCaller1(Environment& environment) : m_environment(environment) - { - } - void* getEnvironment() const + ReferenceCaller1(Environment& environment) : BindFirstOpaque1< Function2 >(environment) { - return &m_environment; - } - static void thunk(void* environment, FirstArgument firstArgument) - { - (func)(*reinterpret_cast(environment), firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); } }; /// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference and one other argument. template -class ConstReferenceCaller1 +class ConstReferenceCaller1 : public BindFirstOpaque1< Function2 > { - const Environment& m_environment; public: - ConstReferenceCaller1(const Environment& environment) : m_environment(environment) + ConstReferenceCaller1(const Environment& environment) : BindFirstOpaque1< Function2 >(environment) { } - void* getEnvironment() const - { - return const_cast(&m_environment); - } - static void thunk(void* environment, FirstArgument firstArgument) - { - (func)(*reinterpret_cast(environment), firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); - } }; /// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer. template -class PointerCaller +class PointerCaller : public BindFirstOpaque< Function1 > { - Environment* m_environment; public: - PointerCaller(Environment* environment) : m_environment(environment) + PointerCaller(Environment* environment) : BindFirstOpaque< Function1 >(environment) { } - void* getEnvironment() const - { - return m_environment; - } - static void thunk(void* environment) - { - (func)(reinterpret_cast(environment)); - } - operator Callback() const - { - return Callback(getEnvironment(), thunk); - } }; /// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer. template -class ConstPointerCaller +class ConstPointerCaller : public BindFirstOpaque< Function1 > { - const Environment* m_environment; public: - ConstPointerCaller(const Environment* environment) : m_environment(environment) - { - } - void* getEnvironment() const - { - return const_cast(m_environment); - } - static void thunk(void* environment) - { - (func)(reinterpret_cast(environment)); - } - operator Callback() const + ConstPointerCaller(const Environment* environment) : BindFirstOpaque< Function1 >(environment) { - return Callback(getEnvironment(), thunk); } }; /// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer and one other argument. template -class PointerCaller1 +class PointerCaller1 : public BindFirstOpaque1< Function2 > { - Environment* m_environment; public: - PointerCaller1(Environment* environment) : m_environment(environment) - { - } - void* getEnvironment() const - { - return m_environment; - } - static void thunk(void* environment, FirstArgument firstArgument) + PointerCaller1(Environment* environment) : BindFirstOpaque1< Function2 >(environment) { - (func)(reinterpret_cast(environment), firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); } }; /// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer and one other argument. template -class ConstPointerCaller1 +class ConstPointerCaller1 : public BindFirstOpaque1< Function2 > { - const Environment* m_environment; public: - ConstPointerCaller1(const Environment* environment) : m_environment(environment) - { - } - void* getEnvironment() const + ConstPointerCaller1(const Environment* environment) : BindFirstOpaque1< Function2 >(environment) { - return const_cast(m_environment); - } - static void thunk(void* environment, FirstArgument firstArgument) - { - (func)(reinterpret_cast(environment), firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); } }; - /// \brief Forms a Callback from a free function which takes no arguments. template -class FreeCaller +class FreeCaller : public BindFirstOpaque< Caller0To1< Function0 > > { public: - void* getEnvironment() const - { - return 0; - } - static void thunk(void*) - { - (func)(); - } - operator Callback() const + FreeCaller() : BindFirstOpaque< Caller0To1< Function0 > >(0) { - return Callback(getEnvironment(), thunk); } }; /// \brief Forms a Callback from a free function which takes a single argument. template -class FreeCaller1 +class FreeCaller1 : public BindFirstOpaque1< Caller1To2< Function1 > > { public: - void* getEnvironment() const - { - return 0; - } - static void thunk(void*, FirstArgument firstArgument) + FreeCaller1() : BindFirstOpaque1< Caller1To2< Function1 > >(0) { - (func)(firstArgument); - } - operator Callback1() const - { - return Callback1(getEnvironment(), thunk); } }; @@ -534,4 +650,21 @@ inline Callback1 makeCallback1(const Func return Callback1(ConstMemberCaller1(functor)); } + +typedef Callback1 BoolImportCallback; +typedef Callback1 BoolExportCallback; + +typedef Callback1 IntImportCallback; +typedef Callback1 IntExportCallback; + +typedef Callback1 FloatImportCallback; +typedef Callback1 FloatExportCallback; + +typedef Callback1 StringImportCallback; +typedef Callback1 StringExportCallback; + +typedef Callback1 SizeImportCallback; +typedef Callback1 SizeExportCallback; + + #endif diff --git a/libs/generic/callbackfwd.cpp b/libs/generic/callbackfwd.cpp new file mode 100644 index 00000000..a2faa664 --- /dev/null +++ b/libs/generic/callbackfwd.cpp @@ -0,0 +1,3 @@ + +#include "callbackfwd.h" + diff --git a/libs/generic/callbackfwd.h b/libs/generic/callbackfwd.h new file mode 100644 index 00000000..f89f9090 --- /dev/null +++ b/libs/generic/callbackfwd.h @@ -0,0 +1,18 @@ + +#if !defined(INCLUDED_CALLBACKFWD_H) +#define INCLUDED_CALLBACKFWD_H + +template +class Callback0; +typedef Callback0 Callback; + +template +class Callback1; + +template +class Callback2; + +template +class Callback3; + +#endif diff --git a/libs/generic/functional.cpp b/libs/generic/functional.cpp new file mode 100644 index 00000000..4717c8e2 --- /dev/null +++ b/libs/generic/functional.cpp @@ -0,0 +1,3 @@ + +#include "functional.h" + diff --git a/libs/generic/functional.h b/libs/generic/functional.h new file mode 100644 index 00000000..ca1d8630 --- /dev/null +++ b/libs/generic/functional.h @@ -0,0 +1,319 @@ + +#if !defined(INCLUDED_FUNCTIONAL_H) +#define INCLUDED_FUNCTIONAL_H + +template +class Member +{ +public: + typedef Object& first_argument_type; + typedef R result_type; + static result_type call(first_argument_type object) + { + return (object.*member)(); + } +}; + +template +class ConstMember +{ +public: + typedef const Object& first_argument_type; + typedef R result_type; + static result_type call(first_argument_type object) + { + return (object.*member)(); + } +}; + +template +class Member1 +{ +public: + typedef Object& first_argument_type; + typedef A1 second_argument_type; + typedef R result_type; + static result_type call(first_argument_type object, second_argument_type a1) + { + return (object.*member)(a1); + } +}; + +template +class ConstMember1 +{ +public: + typedef const Object& first_argument_type; + typedef A1 second_argument_type; + typedef R result_type; + static result_type call(first_argument_type object, second_argument_type a1) + { + return (object.*member)(a1); + } +}; + +template +class Member2 +{ +public: + typedef Object& first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef R result_type; + static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3) + { + return (object.*member)(a2, a3); + } +}; + +template +class ConstMember2 +{ +public: + typedef const Object& first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef R result_type; + static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3) + { + return (object.*member)(a2, a3); + } +}; + +template +class Member3 +{ +public: + typedef Object& first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef A4 fourth_argument_type; + typedef R result_type; + static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) + { + return (object.*member)(a2, a3, a4); + } +}; + +template +class ConstMember3 +{ +public: + typedef const Object& first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef A4 fourth_argument_type; + typedef R result_type; + static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) + { + return (object.*member)(a2, a3, a4); + } +}; + +template +class Function0 +{ +public: + typedef R result_type; + static result_type call() + { + return (func)(); + } +}; + +template +class Function1 +{ +public: + typedef A1 first_argument_type; + typedef R result_type; + static result_type call(first_argument_type a1) + { + return (func)(a1); + } +}; + +template +class Function2 +{ +public: + typedef A1 first_argument_type; + typedef A2 second_argument_type; + typedef R result_type; + static result_type call(first_argument_type a1, second_argument_type a2) + { + return (func)(a1, a2); + } +}; + +template +class Function3 +{ +public: + typedef A1 first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef R result_type; + static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3) + { + return (func)(a1, a2, a3); + } +}; + +template +class Function4 +{ +public: + typedef A1 first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef A4 fourth_argument_type; + typedef R result_type; + static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) + { + return (func)(a1, a2, a3, a4); + } +}; + +template +class Caller0To1 +{ +public: + typedef FirstArgument first_argument_type; + typedef typename Caller::result_type result_type; + static result_type call(first_argument_type) + { + return Caller::call(); + } +}; + +template +class Caller1To2 +{ +public: + typedef FirstArgument first_argument_type; + typedef typename Caller::first_argument_type second_argument_type; + typedef typename Caller::result_type result_type; + static result_type call(first_argument_type, second_argument_type a2) + { + return Caller::call(a2); + } +}; + +template +class Caller2To3 +{ +public: + typedef FirstArgument first_argument_type; + typedef typename Caller::first_argument_type second_argument_type; + typedef typename Caller::second_argument_type third_argument_type; + typedef typename Caller::result_type result_type; + static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3) + { + return Caller::call(a2, a3); + } +}; + +template +class Caller3To4 +{ +public: + typedef FirstArgument first_argument_type; + typedef typename Caller::first_argument_type second_argument_type; + typedef typename Caller::second_argument_type third_argument_type; + typedef typename Caller::third_argument_type fourth_argument_type; + typedef typename Caller::result_type result_type; + static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) + { + return Caller::call(a2, a3, a4); + } +}; + +template +class FunctorInvoke +{ +public: + typedef typename Functor::result_type result_type; + inline result_type operator()(Functor functor) + { + return functor(); + } +}; + +template +class Functor1Invoke +{ + typename Functor::first_argument_type a1; +public: + typedef typename Functor::first_argument_type first_argument_type; + typedef typename Functor::result_type result_type; + Functor1Invoke(first_argument_type a1) : a1(a1) + { + } + inline result_type operator()(Functor functor) + { + return functor(a1); + } +}; + +template +class Functor2Invoke +{ + typename Functor::first_argument_type a1; + typename Functor::second_argument_type a2; +public: + typedef typename Functor::first_argument_type first_argument_type; + typedef typename Functor::second_argument_type second_argument_type; + typedef typename Functor::result_type result_type; + Functor2Invoke(first_argument_type a1, second_argument_type a2) + : a1(a1), a2(a2) + { + } + inline result_type operator()(Functor functor) + { + return functor(a1, a2); + } +}; + +template +class Functor3Invoke +{ + typename Functor::first_argument_type a1; + typename Functor::second_argument_type a2; + typename Functor::third_argument_type a3; +public: + typedef typename Functor::first_argument_type first_argument_type; + typedef typename Functor::second_argument_type second_argument_type; + typedef typename Functor::third_argument_type third_argument_type; + typedef typename Functor::result_type result_type; + Functor3Invoke(first_argument_type a1, second_argument_type a2, third_argument_type a3) + : a1(a1), a2(a2), a3(a3) + { + } + inline result_type operator()(Functor functor) + { + return functor(a1, a2, a3); + } +}; + +template +class TypeEqual +{ + template + class Match + { + public: + typedef False type; + }; + template<> + class Match + { + public: + typedef True type; + }; +public: + typedef typename Match::type type; +}; + + +#endif diff --git a/libs/gtkutil/button.h b/libs/gtkutil/button.h index 3da5b073..69ddac4b 100644 --- a/libs/gtkutil/button.h +++ b/libs/gtkutil/button.h @@ -22,13 +22,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if !defined(INCLUDED_GTKUTIL_BUTTON_H) #define INCLUDED_GTKUTIL_BUTTON_H +#include "generic/callbackfwd.h" + typedef struct _GtkButton GtkButton; typedef struct _GtkToggleButton GtkToggleButton; typedef struct _GtkRadioButton GtkRadioButton; typedef int gint; typedef gint gboolean; typedef unsigned int guint; -class Callback; void button_connect_callback(GtkButton* button, const Callback& callback); guint toggle_button_connect_callback(GtkToggleButton* button, const Callback& callback); diff --git a/libs/gtkutil/menu.h b/libs/gtkutil/menu.h index 3372c029..a394d823 100644 --- a/libs/gtkutil/menu.h +++ b/libs/gtkutil/menu.h @@ -22,7 +22,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if !defined(INCLUDED_GTKUTIL_MENU_H) #define INCLUDED_GTKUTIL_MENU_H -class Callback; +#include "generic/callbackfwd.h" + typedef int gint; typedef gint gboolean; typedef struct _GSList GSList; diff --git a/libs/gtkutil/toolbar.h b/libs/gtkutil/toolbar.h index d0c83a8f..9bf847d2 100644 --- a/libs/gtkutil/toolbar.h +++ b/libs/gtkutil/toolbar.h @@ -22,7 +22,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if !defined(INCLUDED_GTKUTIL_TOOLBAR_H) #define INCLUDED_GTKUTIL_TOOLBAR_H -class Callback; +#include "generic/callbackfwd.h" + typedef struct _GtkButton GtkButton; typedef struct _GtkToggleButton GtkToggleButton; typedef struct _GtkToolbar GtkToolbar; diff --git a/libs/libs.vcproj b/libs/libs.vcproj index c418b703..00bd4e06 100644 --- a/libs/libs.vcproj +++ b/libs/libs.vcproj @@ -379,6 +379,12 @@ + + + + @@ -391,6 +397,12 @@ + + + + @@ -436,6 +448,28 @@ RelativePath=".\debugging\debugging.h"> + + + + + + + + + + + + + + diff --git a/libs/math/vector.h b/libs/math/vector.h index ef0d2251..a9d2a809 100644 --- a/libs/math/vector.h +++ b/libs/math/vector.h @@ -416,6 +416,15 @@ const Vector3 g_vector3_axis_z(0, 0, 1); const Vector3 g_vector3_axes[3] = { g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z }; +inline Vector3& vector3_from_array(float* array) +{ + return *reinterpret_cast(array); +} +inline const Vector3& vector3_from_array(const float* array) +{ + return *reinterpret_cast(array); +} + template inline Element* vector3_to_array(BasicVector3& self) { diff --git a/libs/signal/isignal.cpp b/libs/signal/isignal.cpp new file mode 100644 index 00000000..ee7e4cb7 --- /dev/null +++ b/libs/signal/isignal.cpp @@ -0,0 +1,3 @@ + +#include "isignal.h" + diff --git a/libs/signal/isignal.h b/libs/signal/isignal.h new file mode 100644 index 00000000..e6cb215d --- /dev/null +++ b/libs/signal/isignal.h @@ -0,0 +1,224 @@ + +#if !defined(INCLUDED_ISIGNAL_H) +#define INCLUDED_ISIGNAL_H + +#include "generic/callback.h" +#include "signal/signalfwd.h" + +class SignalHandlerResult +{ + bool value; +public: + explicit SignalHandlerResult(bool value) : value(value) + { + } + bool operator==(SignalHandlerResult other) const + { + return value == other.value; + } + bool operator!=(SignalHandlerResult other) const + { + return !operator==(other); + } +}; + +const SignalHandlerResult SIGNAL_CONTINUE_EMISSION = SignalHandlerResult(false); +const SignalHandlerResult SIGNAL_STOP_EMISSION = SignalHandlerResult(true); + +template +class SignalHandlerCaller1 +{ +public: + typedef typename Caller::first_argument_type first_argument_type; + typedef SignalHandlerResult result_type; + static result_type call(first_argument_type a1) + { + Caller::call(a1); + return SIGNAL_CONTINUE_EMISSION; + } +}; + +template +class SignalHandlerCaller2 +{ +public: + typedef typename Caller::first_argument_type first_argument_type; + typedef typename Caller::second_argument_type second_argument_type; + typedef SignalHandlerResult result_type; + static result_type call(first_argument_type a1, second_argument_type a2) + { + Caller::call(a1, a2); + return SIGNAL_CONTINUE_EMISSION; + } +}; + +template +class SignalHandlerCaller3 +{ +public: + typedef typename Caller::first_argument_type first_argument_type; + typedef typename Caller::second_argument_type second_argument_type; + typedef typename Caller::third_argument_type third_argument_type; + typedef SignalHandlerResult result_type; + static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3) + { + Caller::call(a1, a2, a3); + return SIGNAL_CONTINUE_EMISSION; + } +}; + +template +class SignalHandlerCaller4 +{ +public: + typedef typename Caller::first_argument_type first_argument_type; + typedef typename Caller::second_argument_type second_argument_type; + typedef typename Caller::third_argument_type third_argument_type; + typedef typename Caller::fourth_argument_type fourth_argument_type; + typedef SignalHandlerResult result_type; + static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) + { + Caller::call(a1, a2, a3, a4); + return SIGNAL_CONTINUE_EMISSION; + } +}; + +class SignalHandler : public Callback0 +{ +public: + template + SignalHandler(const BindFirstOpaque& caller) + : Callback0(BindFirstOpaque + >::type>(caller.getBound())) + { + } +}; + +template +inline SignalHandler makeSignalHandler(const BindFirstOpaque& caller) +{ + return SignalHandler(caller); +} +template +inline SignalHandler makeSignalHandler(const Caller& caller, typename Caller::first_argument_type callee) +{ + return SignalHandler(BindFirstOpaque(callee)); +} + + +template +class SignalHandler1 : public Callback1 +{ +public: + template + SignalHandler1(const BindFirstOpaque1& caller) + : Callback1(BindFirstOpaque1 + >::type>(caller.getBound())) + { + } +}; + +template +inline SignalHandler1 makeSignalHandler1(const BindFirstOpaque1& caller) +{ + return SignalHandler1(caller); +} +template +inline SignalHandler1 makeSignalHandler1(const Caller& caller, typename Caller::first_argument_type callee) +{ + return SignalHandler1(BindFirstOpaque1(callee)); +} + + +template +class SignalHandler2 : public Callback2 +{ +public: + template + SignalHandler2(const BindFirstOpaque2& caller) + : Callback2(BindFirstOpaque2 + >::type>(caller.getBound())) + { + } +}; + +template +inline SignalHandler2< + typename Caller::second_argument_type, + typename Caller::third_argument_type +> makeSignalHandler2(const BindFirstOpaque2& caller) +{ + return SignalHandler2< + typename Caller::second_argument_type, + typename Caller::third_argument_type + >(caller); +} +template +inline SignalHandler2< + typename Caller::second_argument_type, + typename Caller::third_argument_type +> makeSignalHandler2(const Caller& caller, typename Caller::first_argument_type callee) +{ + return SignalHandler2< + typename Caller::second_argument_type, + typename Caller::third_argument_type + >(BindFirstOpaque2(callee)); +} + + +template +class SignalHandler3 : public Callback3 +{ +public: + template + SignalHandler3(const BindFirstOpaque3& caller) + : Callback3(BindFirstOpaque3 + >::type>(caller.getBound())) + { + } +}; + +template +inline SignalHandler3< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::fourth_argument_type +> makeSignalHandler3(const BindFirstOpaque3& caller) +{ + return SignalHandler3< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::fourth_argument_type + >(caller); +} +template +inline SignalHandler3< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::fourth_argument_type +> makeSignalHandler3(const Caller& caller, typename Caller::first_argument_type callee) +{ + return SignalHandler3< + typename Caller::second_argument_type, + typename Caller::third_argument_type, + typename Caller::fourth_argument_type + >(BindFirstOpaque3(callee)); +} + +#endif diff --git a/libs/signal/signal.cpp b/libs/signal/signal.cpp new file mode 100644 index 00000000..617a3a4e --- /dev/null +++ b/libs/signal/signal.cpp @@ -0,0 +1,105 @@ + +#include "signal.h" + + + +namespace +{ + class Test + { + }; + class A1 + { + }; + class A2 + { + }; + class A3 + { + }; + + SignalHandlerResult handler0(Test&) + { + return SIGNAL_CONTINUE_EMISSION; + } + typedef Function1 TestHandler0; + + int function0(Test&) + { + return 7; + } + typedef Function1 TestFunction0; + + SignalHandlerResult handler1(Test&, A1) + { + return SIGNAL_CONTINUE_EMISSION; + } + typedef Function2 TestHandler1; + + void function1(Test&, A1) + { + } + typedef ReferenceCaller1 TestFunction1; + + SignalHandlerResult handler2(Test&, A1, A2) + { + return SIGNAL_CONTINUE_EMISSION; + } + typedef Function3 TestHandler2; + + void function2(Test&, A1, A2) + { + } + typedef Function3 TestFunction2; + + SignalHandlerResult handler3(Test&, A1, A2, A3) + { + return SIGNAL_CONTINUE_EMISSION; + } + typedef Function4 TestHandler3; + + void function3(Test&, A1, A2, A3) + { + } + typedef Function4 TestFunction3; + + void testSignals() + { + Test test; + { + Signal0 e0; + Signal0::handler_id_type a = e0.connectLast(makeSignalHandler(TestHandler0(), test)); // signal handler from direct caller returning result + Signal0::handler_id_type b = e0.connectFirst(makeSignalHandler(TestFunction0(), test)); // signal handler from direct caller returning int + e0(); + e0.disconnect(a); + e0.disconnect(b); + } + { + typedef Signal1 Signal1Test; + Signal1Test e1; + Signal1Test::handler_id_type a = e1.connectLast(makeSignalHandler1(TestHandler1(), test)); // signal handler from direct caller with one argument, returning result + Signal1Test::handler_id_type b = e1.connectFirst(makeSignalHandler1(TestFunction1(test))); // signal handler from opaque caller with one argument, returning void + e1(A1()); + e1.disconnect(a); + e1.disconnect(b); + } + { + typedef Signal2 Signal2Test; + Signal2Test e2; + Signal2Test::handler_id_type a = e2.connectLast(makeSignalHandler2(TestHandler2(), test)); // signal handler from direct caller with two arguments, returning result + Signal2Test::handler_id_type b = e2.connectLast(makeSignalHandler2(TestFunction2(), test)); // signal handler from direct caller with two arguments, returning void + e2(A1(), A2()); + e2.disconnect(a); + e2.disconnect(b); + } + { + typedef Signal3 Signal3Test; + Signal3Test e3; + Signal3Test::handler_id_type a = e3.connectLast(makeSignalHandler3(TestHandler3(), test)); // signal handler from direct caller with three arguments, returning result + Signal3Test::handler_id_type b = e3.connectLast(makeSignalHandler3(TestFunction3(), test)); // signal handler from direct caller with three arguments, returning void + e3(A1(), A2(), A3()); + e3.disconnect(a); + e3.disconnect(b); + } + } +} diff --git a/libs/signal/signal.h b/libs/signal/signal.h new file mode 100644 index 00000000..dc187e96 --- /dev/null +++ b/libs/signal/signal.h @@ -0,0 +1,377 @@ + +#if !defined(INCLUDED_SIGNAL_H) +#define INCLUDED_SIGNAL_H + +#include "isignal.h" +#include "memory/allocator.h" +#include "debugging/debugging.h" +#include + +namespace ListDetail +{ + struct ListNodeBase + { + ListNodeBase* next; + ListNodeBase* prev; + }; + + inline void list_initialise(ListNodeBase& self) + { + self.next = self.prev = &self; + } + + inline void list_swap(ListNodeBase& self, ListNodeBase& other) + { + ListNodeBase tmp(self); + if(other.next == &other) + { + list_initialise(self); + } + else + { + self = other; + self.next->prev = self.prev->next = &self; + } + if(tmp.next == &self) + { + list_initialise(other); + } + else + { + other = tmp; + other.next->prev = other.prev->next = &other; + } + } + + inline void node_link(ListNodeBase* node, ListNodeBase* next) + { + node->next = next; + node->prev = next->prev; + next->prev = node; + node->prev->next = node; + } + inline void node_unlink(ListNodeBase* node) + { + node->prev->next = node->next; + node->next->prev = node->prev; + } + + template + struct ListNode : public ListNodeBase + { + Value value; + + ListNode(const Value& value) : value(value) + { + } + ListNode* getNext() const + { + return static_cast(next); + } + ListNode* getPrev() const + { + return static_cast(prev); + } + }; + + template + class NonConstTraits + { + public: + typedef Type value_type; + typedef value_type* pointer; + typedef value_type& reference; + + template + struct rebind + { + typedef NonConstTraits other; + }; + }; + + template + class ConstTraits + { + public: + typedef Type value_type; + typedef const value_type* pointer; + typedef const value_type& reference; + + template + struct rebind + { + typedef ConstTraits other; + }; + }; + + template + class ListIterator + { + public: + typedef std::forward_iterator_tag iterator_category; + typedef std::ptrdiff_t difference_type; + typedef difference_type distance_type; + typedef typename Traits::value_type value_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + + private: + typedef ListNode Node; + typedef typename Traits::template rebind::other NodeTraits; + typedef typename NodeTraits::pointer NodePointer; + typedef typename Traits::template rebind< Opaque >::other OpaqueTraits; + typedef typename OpaqueTraits::pointer OpaquePointer; + NodePointer m_node; + + void increment() + { + m_node = m_node->getNext(); + } + void decrement() + { + m_node = m_node->getPrev(); + } + + + public: + explicit ListIterator(NodePointer node) : m_node(node) + { + } + explicit ListIterator(OpaquePointer p) : m_node(reinterpret_cast(p)) + { + } + + NodePointer node() + { + return m_node; + } + OpaquePointer opaque() const + { + return reinterpret_cast(m_node); + } + + bool operator==(const ListIterator& other) const + { + return m_node == other.m_node; + } + bool operator!=(const ListIterator& other) const + { + return !operator==(other); + } + ListIterator& operator++() + { + increment(); + return *this; + } + ListIterator operator++(int) + { + ListIterator tmp = *this; + increment(); + return tmp; + } + ListIterator& operator--() + { + decrement(); + return *this; + } + ListIterator operator--(int) + { + ListIterator tmp = *this; + decrement(); + return tmp; + } + reference operator*() const + { + return m_node->value; + } + pointer operator->() const + { + return &(operator*()); + } + }; +} + +class Opaque; + +template > +class List : private Allocator +{ + typedef ListDetail::ListNode Node; + ListDetail::ListNodeBase list; + typedef typename Allocator::template rebind::other NodeAllocator; +public: + typedef Value value_type; + typedef ListDetail::ListIterator< ListDetail::NonConstTraits > iterator; + typedef ListDetail::ListIterator< ListDetail::ConstTraits > const_iterator; + + List() + { + list_initialise(list); + } + explicit List(const Allocator& allocator) : Allocator(allocator) + { + list_initialise(list); + } + iterator begin() + { + return iterator(static_cast(list.next)); + } + iterator end() + { + return iterator(static_cast(&list)); + } + const_iterator begin() const + { + return const_iterator(static_cast(list.next)); + } + const_iterator end() const + { + return const_iterator(static_cast(&list)); + } + void push_back(const Value& value) + { + insert(end(), value); + } + void pop_back(const Value& value) + { + erase(--end(), value); + } + void push_front(const Value& value) + { + insert(begin(), value); + } + void pop_front(const Value& value) + { + erase(begin(), value); + } + iterator insert(iterator pos, const Value& x) + { + Node* node = new (NodeAllocator(*this).allocate(1)) Node(x); + node_link(node, pos.node()); + return iterator(node); + } + iterator erase(iterator pos) + { + Node* node = pos.node(); + Node* next = node->getNext(); + node_unlink(node); + node->~Node(); + NodeAllocator(*this).deallocate(node, 1); + return iterator(next); + } +}; + +template +class SignalBase +{ + typedef List SignalList; + SignalList events; + +public: + + typedef Functor handler_type; + typedef Handle< Opaque > handler_id_type; + typedef typename SignalList::iterator iterator; + typedef typename SignalList::const_iterator const_iterator; + iterator begin() + { + return events.begin(); + } + iterator end() + { + return events.end(); + } + const_iterator begin() const + { + return events.begin(); + } + const_iterator end() const + { + return events.end(); + } + handler_id_type connectFirst(const Functor& event) + { + events.push_front(event); + return handler_id_type(begin().opaque()); + } + handler_id_type connectLast(const Functor& event) + { + events.push_back(event); + return handler_id_type((--end()).opaque()); + } + bool isConnected(handler_id_type id) + { + for(iterator i = begin(); i != end(); ++i) + { + if(id.get() == i.opaque()) + { + return true; + } + } + return false; + } + handler_id_type connectBefore(handler_id_type id, const Functor& event) + { + ASSERT_MESSAGE(isConnected(id), "SignalBase::connectBefore: invalid id"); + return events.insert(iterator(id.get()), event).opaque(); + } + handler_id_type connectAfter(handler_id_type id, const Functor& event) + { + ASSERT_MESSAGE(isConnected(id), "SignalBase::connectAfter: invalid id"); + return events.insert(++iterator(id.get()), event).opaque(); + } + void disconnect(handler_id_type id) + { + ASSERT_MESSAGE(isConnected(id), "SignalBase::disconnect: invalid id"); + events.erase(iterator(id.get())); + } +}; + +///\brief +// It is safe to disconnect the signal handler currently being invoked. +template +inline void invokeSignalHandlers(InputIterator first, InputIterator last, SignalHandlerInvoke invoke) +{ + while(first != last && invoke(*first++) != SIGNAL_STOP_EMISSION); +} + +class Signal0 : public SignalBase +{ +public: + void operator()() const + { + invokeSignalHandlers(begin(), end(), FunctorInvoke()); + } +}; + +template +class Signal1 : public SignalBase< SignalHandler1 > +{ +public: + void operator()(FirstArgument a1) const + { + invokeSignalHandlers(begin(), end(), Functor1Invoke(a1)); + } +}; + +template +class Signal2 : public SignalBase< SignalHandler2 > +{ +public: + void operator()(FirstArgument a1, SecondArgument a2) const + { + invokeSignalHandlers(begin(), end(), Functor2Invoke(a1, a2)); + } +}; + +template +class Signal3 : public SignalBase< SignalHandler3 > +{ +public: + void operator()(FirstArgument a1, SecondArgument a2, ThirdArgument a3) const + { + invokeSignalHandlers(begin(), end(), Functor3Invoke(a1, a2, a3)); + } +}; + +#endif diff --git a/libs/signal/signalfwd.cpp b/libs/signal/signalfwd.cpp new file mode 100644 index 00000000..c274b06c --- /dev/null +++ b/libs/signal/signalfwd.cpp @@ -0,0 +1,3 @@ + +#include "signalfwd.h" + diff --git a/libs/signal/signalfwd.h b/libs/signal/signalfwd.h new file mode 100644 index 00000000..79597e21 --- /dev/null +++ b/libs/signal/signalfwd.h @@ -0,0 +1,48 @@ + +#if !defined(INCLUDED_SIGNALFWD_H) +#define INCLUDED_SIGNALFWD_H + +class SignalHandler; +template +class SignalHandler1; +template +class SignalHandler2; +template +class SignalHandler3; + +template +class Opaque; + +///\brief A pointer that always has a well-defined value. +/// If no value is specified, the appropriate null value is used. +template +class Handle +{ + Type* p; +public: + Handle() : p(0) + { + } + explicit Handle(Type* p) : p(p) + { + } + Type* get() const + { + return p; + } + bool isNull() const + { + return p == 0; + } +}; + +template +class SignalFwd +{ +public: + typedef Handle< Opaque > handler_id_type; +}; + +typedef SignalFwd::handler_id_type SignalHandlerId; + +#endif diff --git a/libs/xml/xmlelement.h b/libs/xml/xmlelement.h index 2e354e32..26200253 100644 --- a/libs/xml/xmlelement.h +++ b/libs/xml/xmlelement.h @@ -27,17 +27,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include +///\brief All string pointers passed to an instance of this class are not +/// copied and must stay valid for the lifetime of the instance. class StaticElement : public XMLElement { - struct strless - { - bool operator()(const char* s1, const char* s2) const - { - return strcmp(s1, s2) < 0; - } - }; - - typedef std::map attrs_t; + typedef std::map attrs_t; public: StaticElement(const char* name) : m_name(name) @@ -71,13 +65,15 @@ private: attrs_t m_attrs; }; +///\brief All string pointers passed to an instance of this class are copied. class DynamicElement : public XMLElement { typedef std::map attrs_t; public: DynamicElement(const char* name) : m_name(name) - {} + { + } void insertAttribute(const char* name, const char* value) { m_attrs.insert(attrs_t::value_type(name, value)); diff --git a/plugins/entity/curve.h b/plugins/entity/curve.h index 6f3ad9e7..71ff385a 100644 --- a/plugins/entity/curve.h +++ b/plugins/entity/curve.h @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "math/curve.h" #include "stream/stringstream.h" +#include "signal/signal.h" #include "selectionlib.h" #include "render.h" #include "stringio.h" @@ -339,8 +340,7 @@ const int NURBS_degree = 3; class NURBSCurve { - typedef std::set Callbacks; - Callbacks m_curveChanged; + Signal0 m_curveChanged; Callback m_boundsChanged; public: ControlPoints m_controlPoints; @@ -354,18 +354,18 @@ public: { } - void attach(const Callback& curveChanged) + SignalHandlerId connect(const SignalHandler& curveChanged) { - m_curveChanged.insert(curveChanged); curveChanged(); + return m_curveChanged.connectLast(curveChanged); } - void detach(const Callback& curveChanged) + void disconnect(SignalHandlerId id) { - m_curveChanged.erase(curveChanged); + m_curveChanged.disconnect(id); } void notify() { - std::for_each(m_curveChanged.begin(), m_curveChanged.end(), CallbackInvoke()); + m_curveChanged(); } void tesselate() @@ -437,8 +437,7 @@ public: class CatmullRomSpline { - typedef std::set Callbacks; - Callbacks m_curveChanged; + Signal0 m_curveChanged; Callback m_boundsChanged; public: ControlPoints m_controlPoints; @@ -450,18 +449,18 @@ public: { } - void attach(const Callback& curveChanged) + SignalHandlerId connect(const SignalHandler& curveChanged) { - m_curveChanged.insert(curveChanged); curveChanged(); + return m_curveChanged.connectLast(curveChanged); } - void detach(const Callback& curveChanged) + void disconnect(SignalHandlerId id) { - m_curveChanged.erase(curveChanged); + m_curveChanged.disconnect(id); } void notify() { - std::for_each(m_curveChanged.begin(), m_curveChanged.end(), CallbackInvoke()); + m_curveChanged(); } void tesselate() diff --git a/plugins/entity/doom3group.cpp b/plugins/entity/doom3group.cpp index 5d819909..72048bdb 100644 --- a/plugins/entity/doom3group.cpp +++ b/plugins/entity/doom3group.cpp @@ -96,7 +96,9 @@ class Doom3Group : public: NURBSCurve m_curveNURBS; + SignalHandlerId m_curveNURBSChanged; CatmullRomSpline m_curveCatmullRom; + SignalHandlerId m_curveCatmullRomChanged; private: mutable AABB m_curveBounds; @@ -522,8 +524,8 @@ public: m_curveCatmullRom(m_contained.m_curveCatmullRom.m_controlPointsTransformed, SelectionChangedComponentCaller(*this)) { m_contained.instanceAttach(Instance::path()); - m_contained.m_curveNURBS.attach(CurveEdit::CurveChangedCaller(m_curveNURBS)); - m_contained.m_curveCatmullRom.attach(CurveEdit::CurveChangedCaller(m_curveCatmullRom)); + m_contained.m_curveNURBSChanged = m_contained.m_curveNURBS.connect(CurveEdit::CurveChangedCaller(m_curveNURBS)); + m_contained.m_curveCatmullRomChanged = m_contained.m_curveCatmullRom.connect(CurveEdit::CurveChangedCaller(m_curveCatmullRom)); StaticRenderableConnectionLines::instance().attach(*this); } @@ -531,8 +533,8 @@ public: { StaticRenderableConnectionLines::instance().detach(*this); - m_contained.m_curveCatmullRom.detach(CurveEdit::CurveChangedCaller(m_curveCatmullRom)); - m_contained.m_curveNURBS.detach(CurveEdit::CurveChangedCaller(m_curveNURBS)); + m_contained.m_curveCatmullRom.disconnect(m_contained.m_curveCatmullRomChanged); + m_contained.m_curveNURBS.disconnect(m_contained.m_curveNURBSChanged); m_contained.instanceDetach(Instance::path()); } void renderSolid(Renderer& renderer, const VolumeTest& volume) const diff --git a/plugins/entity/keyobservers.h b/plugins/entity/keyobservers.h index a10109fc..3921e364 100644 --- a/plugins/entity/keyobservers.h +++ b/plugins/entity/keyobservers.h @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "entitylib.h" #include -class KeyObserverMap : public EntityKeyValues::Observer +class KeyObserverMap : public Entity::Observer { typedef std::multimap KeyObservers; KeyObservers m_keyObservers; @@ -34,14 +34,14 @@ public: { m_keyObservers.insert(KeyObservers::value_type(key, observer)); } - void insert(const char* key, EntityKeyValues::Value& value) + void insert(const char* key, EntityKeyValue& value) { for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i) { value.attach((*i).second); } } - void erase(const char* key, EntityKeyValues::Value& value) + void erase(const char* key, EntityKeyValue& value) { for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i) { diff --git a/plugins/entity/namekeys.h b/plugins/entity/namekeys.h index 0afdaaa4..bb0405e6 100644 --- a/plugins/entity/namekeys.h +++ b/plugins/entity/namekeys.h @@ -48,11 +48,11 @@ public: }; -typedef MemberCaller1 KeyValueAssignCaller; -typedef MemberCaller1 KeyValueAttachCaller; -typedef MemberCaller1 KeyValueDetachCaller; +typedef MemberCaller1 KeyValueAssignCaller; +typedef MemberCaller1 KeyValueAttachCaller; +typedef MemberCaller1 KeyValueDetachCaller; -class NameKeys : public EntityKeyValues::Observer, public Namespaced +class NameKeys : public Entity::Observer, public Namespaced { Namespace* m_namespace; EntityKeyValues& m_entity; @@ -60,10 +60,10 @@ class NameKeys : public EntityKeyValues::Observer, public Namespaced NameKeys(const NameKeys& other); NameKeys& operator=(const NameKeys& other); - typedef std::map KeyValues; + typedef std::map KeyValues; KeyValues m_keyValues; - void insertName(const char* key, EntityKeyValues::Value& value) + void insertName(const char* key, EntityKeyValue& value) { if(m_namespace != 0 && m_keyIsName(key)) { @@ -71,7 +71,7 @@ class NameKeys : public EntityKeyValues::Observer, public Namespaced m_namespace->attach(KeyValueAssignCaller(value), KeyValueAttachCaller(value)); } } - void eraseName(const char* key, EntityKeyValues::Value& value) + void eraseName(const char* key, EntityKeyValue& value) { if(m_namespace != 0 && m_keyIsName(key)) { @@ -114,12 +114,12 @@ public: m_keyIsName = keyIsName; insertAll(); } - void insert(const char* key, EntityKeyValues::Value& value) + void insert(const char* key, EntityKeyValue& value) { m_keyValues.insert(KeyValues::value_type(key, &value)); insertName(key, value); } - void erase(const char* key, EntityKeyValues::Value& value) + void erase(const char* key, EntityKeyValue& value) { eraseName(key, value); m_keyValues.erase(key); diff --git a/plugins/entity/targetable.h b/plugins/entity/targetable.h index 234bac39..82dd43af 100644 --- a/plugins/entity/targetable.h +++ b/plugins/entity/targetable.h @@ -209,7 +209,7 @@ public: } }; -class TargetKeys : public EntityKeyValues::Observer +class TargetKeys : public Entity::Observer { TargetingEntities m_targetingEntities; Callback m_targetsChanged; @@ -236,7 +236,7 @@ public: m_targetsChanged(); } - void insert(const char* key, EntityKeyValues::Value& value) + void insert(const char* key, EntityKeyValue& value) { std::size_t index; if(readTargetKey(key, index)) @@ -246,7 +246,7 @@ public: targetsChanged(); } } - void erase(const char* key, EntityKeyValues::Value& value) + void erase(const char* key, EntityKeyValue& value) { std::size_t index; if(readTargetKey(key, index)) @@ -328,7 +328,7 @@ public: class TargetableInstance : public SelectableInstance, public Targetable, -public EntityKeyValues::Observer +public Entity::Observer { mutable Vertex3f m_position; EntityKeyValues& m_entity; @@ -368,14 +368,14 @@ public: m_targeting.targetsChanged(); } - void insert(const char* key, EntityKeyValues::Value& value) + void insert(const char* key, EntityKeyValue& value) { if(string_equal(key, g_targetable_nameKey)) { value.attach(TargetedEntity::TargetnameChangedCaller(m_targeted)); } } - void erase(const char* key, EntityKeyValues::Value& value) + void erase(const char* key, EntityKeyValue& value) { if(string_equal(key, g_targetable_nameKey)) { diff --git a/radiant/brush.cpp b/radiant/brush.cpp index 2250b45a..00212509 100644 --- a/radiant/brush.cpp +++ b/radiant/brush.cpp @@ -20,17 +20,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "brush.h" +#include "signal/signal.h" -std::set g_brushTextureChangedCallbacks; +Signal0 g_brushTextureChangedCallbacks; -void Brush_addTextureChangedCallback(const Callback& callback) +void Brush_addTextureChangedCallback(const SignalHandler& handler) { - g_brushTextureChangedCallbacks.insert(callback); + g_brushTextureChangedCallbacks.connectLast(handler); } void Brush_textureChanged() { - std::for_each(g_brushTextureChangedCallbacks.begin(), g_brushTextureChangedCallbacks.end(), CallbackInvoke()); + g_brushTextureChangedCallbacks(); } QuantiseFunc Face::m_quantise; diff --git a/radiant/brush.h b/radiant/brush.h index 8645063f..b0a932d8 100644 --- a/radiant/brush.h +++ b/radiant/brush.h @@ -60,6 +60,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "texturelib.h" #include "container/container.h" #include "generic/bitfield.h" +#include "signal/signalfwd.h" #include "winding.h" #include "brush_primit.h" @@ -560,13 +561,6 @@ public: }; -inline void FaceShader_getFlags(const FaceShader& faceShader, ContentsFlagsValue& flags) -{ - flags = faceShader.getFlags(); -} - - - class FaceTexdef : public FaceShaderObserver @@ -703,11 +697,6 @@ public: } }; -inline void FaceTexdef_getTexdef(const FaceTexdef& faceTexdef, TextureProjection& projection) -{ - projection = faceTexdef.normalised(); -} - inline void planepts_print(const PlanePoints& planePoints, TextOutputStream& ostream) { ostream << "( " << planePoints[0][0] << " " << planePoints[0][1] << " " << planePoints[0][2] << " ) " @@ -938,6 +927,10 @@ public: } }; +inline void Winding_testSelect(Winding& winding, SelectionTest& test, SelectionIntersection& best) +{ + test.TestPolygon(VertexPointer(reinterpret_cast(&winding.points.data()->vertex), sizeof(WindingVertex)), winding.numpoints, best); +} const double GRID_MIN = 0.125; @@ -963,7 +956,7 @@ public: bool face_filtered(Face& face); -void Brush_addTextureChangedCallback(const Callback& callback); +void Brush_addTextureChangedCallback(const SignalHandler& callback); void Brush_textureChanged(); @@ -1269,10 +1262,9 @@ public: } } - void testSelect(SelectionTest& test, SelectionIntersection& best) { - test.TestPolygon(VertexPointer(reinterpret_cast(&m_winding.points.data()->vertex), sizeof(WindingVertex)), m_winding.numpoints, best); + Winding_testSelect(m_winding, test, best); } void testSelect_centroid(SelectionTest& test, SelectionIntersection& best) @@ -1311,6 +1303,10 @@ public: Brush_textureChanged(); } + void GetTexdef(TextureProjection& projection) const + { + projection = m_texdef.normalised(); + } void SetTexdef(const TextureProjection& projection) { undoSave(); @@ -1318,6 +1314,10 @@ public: texdefChanged(); } + void GetFlags(ContentsFlagsValue& flags) const + { + flags = m_shader.getFlags(); + } void SetFlags(const ContentsFlagsValue& flags) { undoSave(); @@ -2145,12 +2145,12 @@ public: { return m_faces.back(); } - void reserve(std::size_t size) + void reserve(std::size_t count) { - m_faces.reserve(size); + m_faces.reserve(count); for(Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i) { - (*i)->reserve(size); + (*i)->reserve(count); } } void push_back(Faces::value_type face) @@ -2203,6 +2203,7 @@ public: void clear() { + undoSave(); if(m_instanceCounter.m_count != 0) { forEachFace_instanceDetach(m_map); @@ -3557,12 +3558,13 @@ public: } typedef MemberCaller1 SelectedChangedComponentCaller; - void forEachFaceInstance(const BrushInstanceVisitor& visitor) + const BrushInstanceVisitor& forEachFaceInstance(const BrushInstanceVisitor& visitor) { for(FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) { visitor.visit(*i); } + return visitor; } static void constructStatic() @@ -3985,9 +3987,10 @@ public: }; template -inline void Scene_forEachSelectedBrush(const Functor& functor) +inline const Functor& Scene_forEachSelectedBrush(const Functor& functor) { GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor(functor)); + return functor; } template @@ -4010,9 +4013,192 @@ public: }; template -inline void Scene_forEachVisibleSelectedBrush(const Functor& functor) +inline const Functor& Scene_forEachVisibleSelectedBrush(const Functor& functor) { GlobalSelectionSystem().foreachSelected(BrushVisibleSelectedVisitor(functor)); + return functor; } +class BrushForEachFace +{ + const BrushInstanceVisitor& m_visitor; +public: + BrushForEachFace(const BrushInstanceVisitor& visitor) : m_visitor(visitor) + { + } + void operator()(BrushInstance& brush) const + { + brush.forEachFaceInstance(m_visitor); + } +}; + +template +class FaceInstanceVisitFace : public BrushInstanceVisitor +{ + const Functor& functor; +public: + FaceInstanceVisitFace(const Functor& functor) + : functor(functor) + { + } + void visit(FaceInstance& face) const + { + functor(face.getFace()); + } +}; + +template +inline const Functor& Brush_forEachFace(BrushInstance& brush, const Functor& functor) +{ + brush.forEachFaceInstance(FaceInstanceVisitFace(functor)); + return functor; +} + +template +class FaceVisitAll : public BrushVisitor +{ + const Functor& functor; +public: + FaceVisitAll(const Functor& functor) + : functor(functor) + { + } + void visit(Face& face) const + { + functor(face); + } +}; + +template +inline const Functor& Brush_forEachFace(const Brush& brush, const Functor& functor) +{ + brush.forEachFace(FaceVisitAll(functor)); + return functor; +} + +template +inline const Functor& Brush_forEachFace(Brush& brush, const Functor& functor) +{ + brush.forEachFace(FaceVisitAll(functor)); + return functor; +} + +template +class FaceInstanceVisitAll : public BrushInstanceVisitor +{ + const Functor& functor; +public: + FaceInstanceVisitAll(const Functor& functor) + : functor(functor) + { + } + void visit(FaceInstance& face) const + { + functor(face); + } +}; + +template +inline const Functor& Brush_ForEachFaceInstance(BrushInstance& brush, const Functor& functor) +{ + brush.forEachFaceInstance(FaceInstanceVisitAll(functor))); + return functor; +} + +template +inline const Functor& Scene_forEachBrush(scene::Graph& graph, const Functor& functor) +{ + graph.traverse(InstanceWalker< InstanceApply >(functor)); + return functor; +} + +template +class InstanceIfVisible : public Functor +{ +public: + InstanceIfVisible(const Functor& functor) : Functor(functor) + { + } + void operator()(scene::Instance& instance) + { + if(instance.path().top().get().visible()) + { + Functor::operator()(instance); + } + } +}; + +template +class BrushVisibleWalker : public scene::Graph::Walker +{ + const Functor& m_functor; +public: + BrushVisibleWalker(const Functor& functor) : m_functor(functor) + { + } + bool pre(const scene::Path& path, scene::Instance& instance) const + { + if(path.top().get().visible()) + { + BrushInstance* brush = Instance_getIBrush(instance); + if(brush != 0) + { + m_functor(*brush); + } + } + return true; + } +}; + +template +inline const Functor& Scene_forEachVisibleBrush(scene::Graph& graph, const Functor& functor) +{ + graph.traverse(BrushVisibleWalker(functor)); + return functor; +} + +template +inline const Functor& Scene_ForEachBrush_ForEachFace(scene::Graph& graph, const Functor& functor) +{ + Scene_forEachBrush(graph, BrushForEachFace(FaceInstanceVisitFace(functor))); + return functor; +} + +template +inline const Functor& Scene_ForEachSelectedBrush_ForEachFace(scene::Graph& graph, const Functor& functor) +{ + Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitFace(functor))); + return functor; +} + +template +inline const Functor& Scene_ForEachSelectedBrush_ForEachFaceInstance(scene::Graph& graph, const Functor& functor) +{ + Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitAll(functor))); + return functor; +} + +template +class FaceVisitorWrapper +{ + const Functor& functor; +public: + FaceVisitorWrapper(const Functor& functor) : functor(functor) + { + } + + void operator()(FaceInstance& faceInstance) const + { + functor(faceInstance.getFace()); + } +}; + +template +inline const Functor& Scene_ForEachSelectedBrushFace(scene::Graph& graph, const Functor& functor) +{ + g_SelectedFaceInstances.foreach(FaceVisitorWrapper(functor)); + return functor; +} + + #endif diff --git a/radiant/brushmanip.cpp b/radiant/brushmanip.cpp index e9f6ca21..76748797 100644 --- a/radiant/brushmanip.cpp +++ b/radiant/brushmanip.cpp @@ -37,14 +37,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include - void Brush_ConstructCuboid(Brush& brush, const AABB& bounds, const char* shader, const TextureProjection& projection) { const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } }; Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents)); Vector3 maxs(vector3_added(bounds.origin, bounds.extents)); - brush.undoSave(); brush.clear(); brush.reserve(6); @@ -107,7 +105,6 @@ void Brush_ConstructPrism(Brush& brush, const AABB& bounds, std::size_t sides, i return; } - brush.undoSave(); brush.clear(); brush.reserve(sides+2); @@ -180,7 +177,6 @@ void Brush_ConstructCone(Brush& brush, const AABB& bounds, std::size_t sides, co return; } - brush.undoSave(); brush.clear(); brush.reserve(sides+1); @@ -235,7 +231,6 @@ void Brush_ConstructSphere(Brush& brush, const AABB& bounds, std::size_t sides, return; } - brush.undoSave(); brush.clear(); brush.reserve(sides*sides); @@ -362,168 +357,14 @@ void ConstructRegionBrushes(scene::Node* brushes[6], const Vector3& region_mins, } -class BrushForEachFace -{ - const BrushInstanceVisitor& m_visitor; -public: - BrushForEachFace(const BrushInstanceVisitor& visitor) : m_visitor(visitor) - { - } - void operator()(BrushInstance& brush) const - { - brush.forEachFaceInstance(m_visitor); - } -}; - -template -class FaceVisitAll : public BrushInstanceVisitor -{ - const Visitor& m_visitor; -public: - FaceVisitAll(const Visitor& visitor) - : m_visitor(visitor) - { - } - void visit(FaceInstance& face) const - { - m_visitor.visit(face.getFace()); - } -}; - -template -class FaceInstanceVisitAll : public BrushInstanceVisitor -{ - const Visitor& m_visitor; -public: - FaceInstanceVisitAll(const Visitor& visitor) - : m_visitor(visitor) - { - } - void visit(FaceInstance& face) const - { - m_visitor.visit(face); - } -}; - -#if 0 -template -class FaceVisitSelected : public BrushInstanceVisitor -{ - const Visitor& m_visitor; -public: - FaceVisitSelected(const Visitor& visitor) - : m_visitor(visitor) - { - } - void visit(FaceInstance& face) const - { - if(face.isSelected(SelectionSystem::eFace)) - { - m_visitor.visit(face.getFace()); - } - } -}; -#endif - -template -inline void Scene_forEachBrush(scene::Graph& graph, const Functor& functor) -{ - graph.traverse(InstanceWalker< InstanceApply >(functor)); -} - -template -class InstanceIfVisible : public Functor -{ -public: - InstanceIfVisible(const Functor& functor) : Functor(functor) - { - } - void operator()(scene::Instance& instance) - { - if(instance.path().top().get().visible()) - { - Functor::operator()(instance); - } - } -}; - -template -class BrushVisibleWalker : public scene::Graph::Walker -{ - const Functor& m_functor; -public: - BrushVisibleWalker(const Functor& functor) : m_functor(functor) - { - } - bool pre(const scene::Path& path, scene::Instance& instance) const - { - if(path.top().get().visible()) - { - BrushInstance* brush = Instance_getBrush(instance); - if(brush != 0) - { - m_functor(*brush); - } - } - return true; - } -}; - -template -inline void Scene_forEachVisibleBrush(scene::Graph& graph, const Functor& functor) -{ - graph.traverse(BrushVisibleWalker(functor)); -} - -template -inline void Scene_ForEachBrush_ForEachFace(scene::Graph& graph, const Visitor& visitor) -{ - Scene_forEachBrush(graph, BrushForEachFace(FaceVisitAll(visitor))); -} - -template -inline void Scene_ForEachSelectedBrush_ForEachFace(scene::Graph& graph, const Visitor& visitor) -{ - Scene_forEachSelectedBrush(BrushForEachFace(FaceVisitAll(visitor))); -} - -template -inline void Scene_ForEachSelectedBrush_ForEachFaceInstance(scene::Graph& graph, const Visitor& visitor) -{ - Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitAll(visitor))); -} - -template -class FaceVisitorWrapper -{ - Visitor& m_visitor; -public: - FaceVisitorWrapper(Visitor& visitor) : m_visitor(visitor) - { - } - - void operator()(FaceInstance& faceInstance) - { - m_visitor.visit(faceInstance.getFace()); - } -}; - -template -inline void Scene_ForEachSelectedBrushFace(scene::Graph& graph, Visitor& faceVisitor) -{ - g_SelectedFaceInstances.foreach(FaceVisitorWrapper(faceVisitor)); -} - - - -class FaceSetTexdefVisitor +class FaceSetTexdef { const TextureProjection& m_projection; public: - FaceSetTexdefVisitor(const TextureProjection& projection) : m_projection(projection) + FaceSetTexdef(const TextureProjection& projection) : m_projection(projection) { } - void visit(Face& face) const + void operator()(Face& face) const { face.SetTexdef(m_projection); } @@ -531,26 +372,25 @@ public: void Scene_BrushSetTexdef_Selected(scene::Graph& graph, const TextureProjection& projection) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdefVisitor(projection)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdef(projection)); SceneChangeNotify(); } void Scene_BrushSetTexdef_Component_Selected(scene::Graph& graph, const TextureProjection& projection) { - FaceSetTexdefVisitor visitor(projection); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceSetTexdef(projection)); SceneChangeNotify(); } -class FaceSetFlagsVisitor +class FaceSetFlags { const ContentsFlagsValue& m_projection; public: - FaceSetFlagsVisitor(const ContentsFlagsValue& flags) : m_projection(flags) + FaceSetFlags(const ContentsFlagsValue& flags) : m_projection(flags) { } - void visit(Face& face) const + void operator()(Face& face) const { face.SetFlags(m_projection); } @@ -558,25 +398,24 @@ public: void Scene_BrushSetFlags_Selected(scene::Graph& graph, const ContentsFlagsValue& flags) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlagsVisitor(flags)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlags(flags)); SceneChangeNotify(); } void Scene_BrushSetFlags_Component_Selected(scene::Graph& graph, const ContentsFlagsValue& flags) { - FaceSetFlagsVisitor visitor(flags); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceSetFlags(flags)); SceneChangeNotify(); } -class FaceShiftTexdefVisitor +class FaceShiftTexdef { float m_s, m_t; public: - FaceShiftTexdefVisitor(float s, float t) : m_s(s), m_t(t) + FaceShiftTexdef(float s, float t) : m_s(s), m_t(t) { } - void visit(Face& face) const + void operator()(Face& face) const { face.ShiftTexdef(m_s, m_t); } @@ -584,25 +423,24 @@ public: void Scene_BrushShiftTexdef_Selected(scene::Graph& graph, float s, float t) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceShiftTexdefVisitor(s, t)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceShiftTexdef(s, t)); SceneChangeNotify(); } void Scene_BrushShiftTexdef_Component_Selected(scene::Graph& graph, float s, float t) { - FaceShiftTexdefVisitor visitor(s, t); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceShiftTexdef(s, t)); SceneChangeNotify(); } -class FaceScaleTexdefVisitor +class FaceScaleTexdef { float m_s, m_t; public: - FaceScaleTexdefVisitor(float s, float t) : m_s(s), m_t(t) + FaceScaleTexdef(float s, float t) : m_s(s), m_t(t) { } - void visit(Face& face) const + void operator()(Face& face) const { face.ScaleTexdef(m_s, m_t); } @@ -610,25 +448,24 @@ public: void Scene_BrushScaleTexdef_Selected(scene::Graph& graph, float s, float t) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceScaleTexdefVisitor(s, t)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceScaleTexdef(s, t)); SceneChangeNotify(); } void Scene_BrushScaleTexdef_Component_Selected(scene::Graph& graph, float s, float t) { - FaceScaleTexdefVisitor visitor(s, t); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceScaleTexdef(s, t)); SceneChangeNotify(); } -class FaceRotateTexdefVisitor +class FaceRotateTexdef { float m_angle; public: - FaceRotateTexdefVisitor(float angle) : m_angle(angle) + FaceRotateTexdef(float angle) : m_angle(angle) { } - void visit(Face& face) const + void operator()(Face& face) const { face.RotateTexdef(m_angle); } @@ -636,24 +473,23 @@ public: void Scene_BrushRotateTexdef_Selected(scene::Graph& graph, float angle) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdefVisitor(angle)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdef(angle)); SceneChangeNotify(); } void Scene_BrushRotateTexdef_Component_Selected(scene::Graph& graph, float angle) { - FaceRotateTexdefVisitor visitor(angle); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceRotateTexdef(angle)); SceneChangeNotify(); } -class FaceSetShaderVisitor +class FaceSetShader { const char* m_name; public: - FaceSetShaderVisitor(const char* name) : m_name(name) {} - void visit(Face& face) const + FaceSetShader(const char* name) : m_name(name) {} + void operator()(Face& face) const { face.SetShader(m_name); } @@ -661,25 +497,24 @@ public: void Scene_BrushSetShader_Selected(scene::Graph& graph, const char* name) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShaderVisitor(name)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShader(name)); SceneChangeNotify(); } void Scene_BrushSetShader_Component_Selected(scene::Graph& graph, const char* name) { - FaceSetShaderVisitor visitor(name); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceSetShader(name)); SceneChangeNotify(); } -class FaceSetDetailVisitor +class FaceSetDetail { bool m_detail; public: - FaceSetDetailVisitor(bool detail) : m_detail(detail) + FaceSetDetail(bool detail) : m_detail(detail) { } - void visit(Face& face) const + void operator()(Face& face) const { face.setDetail(m_detail); } @@ -687,7 +522,7 @@ public: void Scene_BrushSetDetail_Selected(scene::Graph& graph, bool detail) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetailVisitor(detail)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetail(detail)); SceneChangeNotify(); } @@ -701,15 +536,15 @@ bool Face_FindReplaceShader(Face& face, const char* find, const char* replace) return false; } -class FaceFindReplaceShaderVisitor +class FaceFindReplaceShader { const char* m_find; const char* m_replace; public: - FaceFindReplaceShaderVisitor(const char* find, const char* replace) : m_find(find), m_replace(replace) + FaceFindReplaceShader(const char* find, const char* replace) : m_find(find), m_replace(replace) { } - void visit(Face& face) const + void operator()(Face& face) const { Face_FindReplaceShader(face, m_find, m_replace); } @@ -717,29 +552,28 @@ public: void Scene_BrushFindReplaceShader(scene::Graph& graph, const char* find, const char* replace) { - Scene_ForEachBrush_ForEachFace(graph, FaceFindReplaceShaderVisitor(find, replace)); + Scene_ForEachBrush_ForEachFace(graph, FaceFindReplaceShader(find, replace)); } void Scene_BrushFindReplaceShader_Selected(scene::Graph& graph, const char* find, const char* replace) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFindReplaceShaderVisitor(find, replace)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFindReplaceShader(find, replace)); } void Scene_BrushFindReplaceShader_Component_Selected(scene::Graph& graph, const char* find, const char* replace) { - FaceFindReplaceShaderVisitor visitor(find, replace); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceFindReplaceShader(find, replace)); } -class FaceFitTextureVisitor +class FaceFitTexture { float m_s_repeat, m_t_repeat; public: - FaceFitTextureVisitor(float s_repeat, float t_repeat) : m_s_repeat(s_repeat), m_t_repeat(t_repeat) + FaceFitTexture(float s_repeat, float t_repeat) : m_s_repeat(s_repeat), m_t_repeat(t_repeat) { } - void visit(Face& face) const + void operator()(Face& face) const { face.FitTexture(m_s_repeat, m_t_repeat); } @@ -747,17 +581,22 @@ public: void Scene_BrushFitTexture_Selected(scene::Graph& graph, float s_repeat, float t_repeat) { - Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFitTextureVisitor(s_repeat, t_repeat)); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFitTexture(s_repeat, t_repeat)); SceneChangeNotify(); } void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat) { - FaceFitTextureVisitor visitor(s_repeat, t_repeat); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceFitTexture(s_repeat, t_repeat)); SceneChangeNotify(); } +TextureProjection g_defaultTextureProjection; +const TextureProjection& TextureTransform_getDefault() +{ + TexDef_Construct_Default(g_defaultTextureProjection); + return g_defaultTextureProjection; +} void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::size_t sides, const char* shader) { @@ -768,10 +607,8 @@ void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::siz Brush* brush = Node_getBrush(path.top()); if(brush != 0) { - AABB bounds = brush->localAABB(); - TextureProjection projection; - TexDef_Construct_Default(projection); - Brush_ConstructPrefab(*brush, type, bounds, sides, shader, projection); + AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified + Brush_ConstructPrefab(*brush, type, bounds, sides, shader, TextureTransform_getDefault()); SceneChangeNotify(); } } @@ -786,9 +623,7 @@ void Scene_BrushResize_Selected(scene::Graph& graph, const AABB& bounds, const c Brush* brush = Node_getBrush(path.top()); if(brush != 0) { - TextureProjection projection; - TexDef_Construct_Default(projection); - Brush_ConstructCuboid(*brush, bounds, shader, projection); + Brush_ConstructCuboid(*brush, bounds, shader, TextureTransform_getDefault()); SceneChangeNotify(); } } @@ -833,15 +668,15 @@ void Scene_BrushSelectByShader(scene::Graph& graph, const char* name) graph.traverse(BrushSelectByShaderWalker(name)); } -class FaceSelectByShaderVisitor : public BrushInstanceVisitor +class FaceSelectByShader { const char* m_name; public: - FaceSelectByShaderVisitor(const char* name) + FaceSelectByShader(const char* name) : m_name(name) { } - void visit(FaceInstance& face) const + void operator()(FaceInstance& face) const { if(shader_equal(face.getFace().GetShader(), m_name)) { @@ -852,24 +687,24 @@ public: void Scene_BrushSelectByShader_Component(scene::Graph& graph, const char* name) { - Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, FaceSelectByShaderVisitor(name)); + Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, FaceSelectByShader(name)); } -class FaceGetTexdefVisitor +class FaceGetTexdef { TextureProjection& m_projection; mutable bool m_done; public: - FaceGetTexdefVisitor(TextureProjection& projection) + FaceGetTexdef(TextureProjection& projection) : m_projection(projection), m_done(false) { } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_done) { m_done = true; - FaceTexdef_getTexdef(face.getTexdef(), m_projection); + face.GetTexdef(m_projection); } } }; @@ -877,8 +712,7 @@ public: void Scene_BrushGetTexdef_Selected(scene::Graph& graph, TextureProjection& projection) { - FaceGetTexdefVisitor visitor(projection); - Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetTexdef(projection)); } void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProjection& projection) @@ -887,30 +721,30 @@ void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProject if(!g_SelectedFaceInstances.empty()) { FaceInstance& faceInstance = g_SelectedFaceInstances.last(); - FaceTexdef_getTexdef(faceInstance.getFace().getTexdef(), projection); + faceInstance.getFace().GetTexdef(projection); } #else - FaceGetTexdefVisitor visitor(projection); + FaceGetTexdef visitor(projection); Scene_ForEachSelectedBrushFace(graph, visitor); #endif } -class FaceGetFlagsVisitor +class FaceGetFlags { ContentsFlagsValue& m_flags; mutable bool m_done; public: - FaceGetFlagsVisitor(ContentsFlagsValue& flags) + FaceGetFlags(ContentsFlagsValue& flags) : m_flags(flags), m_done(false) { } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_done) { m_done = true; - FaceShader_getFlags(face.getShader(), m_flags); + face.GetFlags(m_flags); } } }; @@ -918,8 +752,18 @@ public: void Scene_BrushGetFlags_Selected(scene::Graph& graph, ContentsFlagsValue& flags) { - FaceGetFlagsVisitor visitor(flags); - Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); +#if 1 + if(GlobalSelectionSystem().countSelected() != 0) + { + BrushInstance* brush = Instance_getBrush(GlobalSelectionSystem().ultimateSelected()); + if(brush != 0) + { + Brush_forEachFace(*brush, FaceGetFlags(flags)); + } + } +#else + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetFlags(flags)); +#endif } void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsValue& flags) @@ -928,38 +772,47 @@ void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsVa if(!g_SelectedFaceInstances.empty()) { FaceInstance& faceInstance = g_SelectedFaceInstances.last(); - FaceShader_getFlags(faceInstance.getFace().getShader(), flags); + faceInstance.getFace().GetFlags(flags); } #else - FaceGetFlagsVisitor visitor(flags); - Scene_ForEachSelectedBrushFace(graph, visitor); + Scene_ForEachSelectedBrushFace(graph, FaceGetFlags(flags)); #endif } -class FaceGetShaderVisitor +class FaceGetShader { CopiedString& m_shader; mutable bool m_done; public: - FaceGetShaderVisitor(CopiedString& shader) + FaceGetShader(CopiedString& shader) : m_shader(shader), m_done(false) { } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_done) { m_done = true; - m_shader = face.getShader().getShader(); + m_shader = face.GetShader(); } } }; void Scene_BrushGetShader_Selected(scene::Graph& graph, CopiedString& shader) { - FaceGetShaderVisitor visitor(shader); - Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); +#if 1 + if(GlobalSelectionSystem().countSelected() != 0) + { + BrushInstance* brush = Instance_getBrush(GlobalSelectionSystem().ultimateSelected()); + if(brush != 0) + { + Brush_forEachFace(*brush, FaceGetShader(shader)); + } + } +#else + Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetShader(shader)); +#endif } void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString& shader) @@ -968,10 +821,10 @@ void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString& if(!g_SelectedFaceInstances.empty()) { FaceInstance& faceInstance = g_SelectedFaceInstances.last(); - shader = faceInstance.getFace().getShader().getShader(); + shader = faceInstance.getFace().GetShader(); } #else - FaceGetShaderVisitor visitor(shader); + FaceGetShader visitor(shader); Scene_ForEachSelectedBrushFace(graph, visitor); #endif } @@ -1031,16 +884,16 @@ public: -class FaceFilterAnyVisitor : public BrushVisitor +class FaceFilterAny { FaceFilter* m_filter; bool& m_filtered; public: - FaceFilterAnyVisitor(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) + FaceFilterAny(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) { m_filtered = false; } - void visit(Face& face) const + void operator()(Face& face) const { if(m_filter->filter(face)) { @@ -1059,21 +912,21 @@ public: bool filter(const Brush& brush) const { bool filtered; - brush.forEachFace(FaceFilterAnyVisitor(m_filter, filtered)); + Brush_forEachFace(brush, FaceFilterAny(m_filter, filtered)); return filtered; } }; -class FaceFilterAllVisitor : public BrushVisitor +class FaceFilterAll { FaceFilter* m_filter; bool& m_filtered; public: - FaceFilterAllVisitor(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) + FaceFilterAll(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered) { m_filtered = true; } - void visit(Face& face) const + void operator()(Face& face) const { if(!m_filter->filter(face)) { @@ -1092,7 +945,7 @@ public: bool filter(const Brush& brush) const { bool filtered; - brush.forEachFace(FaceFilterAllVisitor(m_filter, filtered)); + Brush_forEachFace(brush, FaceFilterAll(m_filter, filtered)); return filtered; } }; @@ -1602,7 +1455,7 @@ bool Scene_BrushGetClosestFaceTexture(scene::Graph& graph, SelectionTest& test, if(face != 0) { shader = face->GetShader(); - FaceTexdef_getTexdef(face->getTexdef(), projection); + face->GetTexdef(projection); flags = face->getShader().m_flags; return true; } @@ -1671,7 +1524,7 @@ void SelectedFaces_copyTexture() if(!g_SelectedFaceInstances.empty()) { Face& face = g_SelectedFaceInstances.last().getFace(); - FaceTexdef_getTexdef(face.getTexdef(), g_faceTextureClipboard.m_projection); + face.GetTexdef(g_faceTextureClipboard.m_projection); g_faceTextureClipboard.m_flags = face.getShader().m_flags; TextureBrowser_SetSelectedShader(g_TextureBrowser, face.getShader().getShader()); diff --git a/radiant/brushmanip.h b/radiant/brushmanip.h index 9c41f7a3..2c5cb951 100644 --- a/radiant/brushmanip.h +++ b/radiant/brushmanip.h @@ -22,7 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if !defined (INCLUDED_BRUSHWRAPPER_H) #define INCLUDED_BRUSHWRAPPER_H -#include "string/string.h" +#include +#include "string/stringfwd.h" +#include "generic/callbackfwd.h" enum EBrushPrefab { @@ -67,8 +69,6 @@ void Scene_BrushSelectByShader_Component(scene::Graph& graph, const char* name); void Scene_BrushFitTexture_Selected(scene::Graph& graph, float s_repeat, float t_repeat); void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat); -class Callback; - typedef struct _GtkMenu GtkMenu; void Brush_constructMenu(GtkMenu* menu); diff --git a/radiant/brushmodule.cpp b/radiant/brushmodule.cpp index ae9d8126..e289f3cc 100644 --- a/radiant/brushmodule.cpp +++ b/radiant/brushmodule.cpp @@ -157,6 +157,21 @@ void Brush_clipperColourChanged() BrushClipPlane::constructStatic(); } +void BrushFaceData_fromFace(const BrushFaceDataCallback& callback, Face& face) +{ + _QERFaceData faceData; + faceData.m_p0 = face.getPlane().planePoints()[0]; + faceData.m_p1 = face.getPlane().planePoints()[1]; + faceData.m_p2 = face.getPlane().planePoints()[2]; + faceData.m_shader = face.GetShader(); + faceData.m_texdef = face.getTexdef().m_projection.m_texdef; + faceData.contents = face.getShader().m_flags.m_contentFlags; + faceData.flags = face.getShader().m_flags.m_surfaceFlags; + faceData.value = face.getShader().m_flags.m_value; + callback(faceData); +} +typedef ConstReferenceCaller1 BrushFaceDataFromFaceCaller; +typedef Callback1 FaceCallback; class Quake3BrushCreator : public BrushCreator { @@ -169,6 +184,14 @@ public: { return g_useAlternativeTextureProjection.m_value; } + void forEachBrushFace(scene::Node& brush, const BrushFaceDataCallback& callback) + { + Brush_forEachFace(*Node_getBrush(brush), FaceCallback(BrushFaceDataFromFaceCaller(callback))); + } + bool addBrushFace(scene::Node& brush, const _QERFaceData& faceData) + { + return Node_getBrush(brush)->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_shader, TextureProjection(faceData.m_texdef, brushprimit_texdef_t(), Vector3(0, 0, 0), Vector3(0, 0, 0))) != 0; + } }; Quake3BrushCreator g_Quake3BrushCreator; diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 04de6b40..62e209b8 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "renderable.h" #include "preferencesystem.h" -#include "generic/callback.h" +#include "signal/signal.h" #include "container/array.h" #include "scenelib.h" #include "render.h" @@ -60,16 +60,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "timer.h" -std::vector g_cameraMoved_callbacks; +Signal0 g_cameraMoved_callbacks; -void AddCameraMovedCallback(const Callback& callback) +void AddCameraMovedCallback(const SignalHandler& handler) { - g_cameraMoved_callbacks.push_back(callback); + g_cameraMoved_callbacks.connectLast(handler); } void CameraMovedNotify() { - std::for_each(g_cameraMoved_callbacks.begin(), g_cameraMoved_callbacks.end(), CallbackInvoke()); + g_cameraMoved_callbacks(); } @@ -1120,6 +1120,7 @@ void CamWnd_Move_Discrete_Import(bool value) } + void CamWnd_Add_Handlers_Move(CamWnd& camwnd) { camwnd.m_selection_button_press_handler = g_signal_connect(G_OBJECT(camwnd.m_gl_widget), "button_press_event", G_CALLBACK(selection_button_press), camwnd.m_window_observer); diff --git a/radiant/camwindow.h b/radiant/camwindow.h index 66f4bfac..2c8c59f7 100644 --- a/radiant/camwindow.h +++ b/radiant/camwindow.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_CAMWINDOW_H #include "math/vector.h" +#include "signal/signalfwd.h" typedef struct _GtkWidget GtkWidget; typedef struct _GtkWindow GtkWindow; @@ -31,8 +32,7 @@ class CamWnd; CamWnd* NewCamWnd(); void DeleteCamWnd(CamWnd* camwnd); -class Callback; -void AddCameraMovedCallback(const Callback& callback); +void AddCameraMovedCallback(const SignalHandler& handler); void CamWnd_Update(CamWnd& camwnd); diff --git a/radiant/csg.cpp b/radiant/csg.cpp index c8a5fbd4..34029f6b 100644 --- a/radiant/csg.cpp +++ b/radiant/csg.cpp @@ -30,26 +30,42 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "brushnode.h" #include "grid.h" - - -void Brush_makeHollow(const Brush& brush, brush_vector_t& out, float offset) +void Face_makeBrush(Face& face, const Brush& brush, brush_vector_t& out, float offset) { - for(Brush::const_iterator i(brush.begin()); i != brush.end(); ++i) + if(face.contributes()) { - if((*i)->contributes()) + out.push_back(new Brush(brush)); + Face* newFace = out.back()->addFace(face); + if(newFace != 0) { - out.push_back(new Brush(brush)); - Face* newFace = out.back()->addFace(*(*i)); - if(newFace != 0) - { - newFace->flipWinding(); - newFace->getPlane().offset(offset); - newFace->planeChanged(); - } + newFace->flipWinding(); + newFace->getPlane().offset(offset); + newFace->planeChanged(); } } } +class FaceMakeBrush +{ + const Brush& brush; + brush_vector_t& out; + float offset; +public: + FaceMakeBrush(const Brush& brush, brush_vector_t& out, float offset) + : brush(brush), out(out), offset(offset) + { + } + void operator()(Face& face) const + { + Face_makeBrush(face, brush, out, offset); + } +}; + +void Brush_makeHollow(const Brush& brush, brush_vector_t& out, float offset) +{ + Brush_forEachFace(brush, FaceMakeBrush(brush, out, offset)); +} + class BrushHollowSelectedWalker : public scene::Graph::Walker { float m_offset; @@ -71,8 +87,8 @@ public: Brush_makeHollow(*brush, out, m_offset); for(brush_vector_t::const_iterator i = out.begin(); i != out.end(); ++i) { - NodeSmartReference node((new BrushNode())->node()); (*i)->removeEmptyFaces(); + NodeSmartReference node((new BrushNode())->node()); Node_getBrush(node)->copy(*(*i)); delete (*i); Node_getTraversable(path.parent())->insert(node); @@ -151,6 +167,86 @@ void CSG_MakeHollow (void) SceneChangeNotify(); } +template +class Dereference +{ + const Functor& functor; +public: + typedef typename Functor::first_argument_type first_argument_type; + typedef typename Functor::result_type result_type; + Dereference(const Functor& functor) : functor(functor) + { + } + result_type operator()(first_argument_type firstArgument) const + { + return functor(*firstArgument); + } +}; + +template +inline Dereference makeDereference(const Functor& functor) +{ + return Dereference(functor); +} + +template +Face* Brush_findIf(const Brush& brush, const Predicate& predicate) +{ + Brush::const_iterator i = std::find_if(brush.begin(), brush.end(), makeDereference(predicate)); + return i == brush.end() ? 0 : *i; +} + +template +class BindArguments1 +{ + typedef typename Caller::SecondArgument FirstBound; + FirstBound firstBound; +public: + typedef typename Caller::Return Return; + typedef typename Caller::FirstArgument FirstArgument; + BindArguments1(FirstBound firstBound) + : firstBound(firstBound) + { + } + Return operator()(FirstArgument firstArgument) const + { + return Caller::call(firstArgument, firstBound); + } +}; + +template +class BindArguments2 +{ + typedef typename Caller::SecondArgument FirstBound; + typedef typename Caller::ThirdArgument SecondBound; + FirstBound firstBound; + SecondBound secondBound; +public: + typedef typename Caller::Return Return; + typedef typename Caller::FirstArgument FirstArgument; + BindArguments2(FirstBound firstBound, SecondBound secondBound) + : firstBound(firstBound), secondBound(secondBound) + { + } + Return operator()(FirstArgument firstArgument) const + { + return Caller::call(firstArgument, firstBound, secondBound); + } +}; + +template +BindArguments2 bindArguments(const Caller& caller, FirstBound firstBound, SecondBound secondBound) +{ + return BindArguments2(firstBound, secondBound); +} + +inline bool Face_testPlane(const Face& face, const Plane3& plane, bool flipped) +{ + return face.contributes() && !Winding_TestPlane(face.getWinding(), plane, flipped); +} +typedef Function3 FaceTestPlane; + + /// \brief Returns true if /// \li !flipped && brush is BACK or ON @@ -158,14 +254,18 @@ void CSG_MakeHollow (void) bool Brush_testPlane(const Brush& brush, const Plane3& plane, bool flipped) { brush.evaluateBRep(); +#if 1 for(Brush::const_iterator i(brush.begin()); i != brush.end(); ++i) { - if((*i)->contributes() && !Winding_TestPlane((*i)->getWinding(), plane, flipped)) + if(Face_testPlane(*(*i), plane, flipped)) { return false; } } return true; +#else + return Brush_findIf(brush, bindArguments(FaceTestPlane(), makeReference(plane), flipped)) == 0; +#endif } brushsplit_t Brush_classifyPlane(const Brush& brush, const Plane3& plane) diff --git a/radiant/dialog.cpp b/radiant/dialog.cpp index e57dae78..0240e675 100644 --- a/radiant/dialog.cpp +++ b/radiant/dialog.cpp @@ -676,7 +676,7 @@ void Dialog::addRadioIcons(GtkWidget* vbox, const char* name, int& data, StringA addRadioIcons(vbox, name, icons, IntImportCaller(data), IntExportCaller(data)); } -GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer) +GtkWidget* Dialog::addIntEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer) { DialogEntryRow row(DialogEntryRow_new(name)); AddIntEntryData(*row.m_entry, importViewer, exportViewer); @@ -684,7 +684,7 @@ GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const IntImportCa return row.m_row; } -GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer) +GtkWidget* Dialog::addSizeEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer) { DialogEntryRow row(DialogEntryRow_new(name)); AddSizeEntryData(*row.m_entry, importViewer, exportViewer); @@ -692,7 +692,7 @@ GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const SizeImportC return row.m_row; } -GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer) +GtkWidget* Dialog::addFloatEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer) { DialogEntryRow row(DialogEntryRow_new(name)); AddFloatEntryData(*row.m_entry, importViewer, exportViewer); diff --git a/radiant/dialog.h b/radiant/dialog.h index 882985e3..d7ac94bd 100644 --- a/radiant/dialog.h +++ b/radiant/dialog.h @@ -159,20 +159,20 @@ public: void addRadio(GtkWidget* vbox, const char* name, int& data, StringArrayRange names); void addRadioIcons(GtkWidget* vbox, const char* name, StringArrayRange icons, const IntImportCallback& importCallback, const IntExportCallback& exportCallback); void addRadioIcons(GtkWidget* vbox, const char* name, int& data, StringArrayRange icons); - GtkWidget* addEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback); + GtkWidget* addIntEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback); GtkWidget* addEntry(GtkWidget* vbox, const char* name, int& data) { - return addEntry(vbox, name, IntImportCaller(data), IntExportCaller(data)); + return addIntEntry(vbox, name, IntImportCaller(data), IntExportCaller(data)); } - GtkWidget* addEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback); + GtkWidget* addSizeEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback); GtkWidget* addEntry(GtkWidget* vbox, const char* name, std::size_t& data) { - return addEntry(vbox, name, SizeImportCaller(data), SizeExportCaller(data)); + return addSizeEntry(vbox, name, SizeImportCaller(data), SizeExportCaller(data)); } - GtkWidget* addEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback); + GtkWidget* addFloatEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback); GtkWidget* addEntry(GtkWidget* vbox, const char* name, float& data) { - return addEntry(vbox, name, FloatImportCaller(data), FloatExportCaller(data)); + return addFloatEntry(vbox, name, FloatImportCaller(data), FloatExportCaller(data)); } GtkWidget* addPathEntry(GtkWidget* vbox, const char* name, bool browse_directory, const StringImportCallback& importCallback, const StringExportCallback& exportCallback); GtkWidget* addPathEntry(GtkWidget* vbox, const char* name, CopiedString& data, bool directory); diff --git a/radiant/eclass_xml.cpp b/radiant/eclass_xml.cpp index aeaca03c..5195b4e7 100644 --- a/radiant/eclass_xml.cpp +++ b/radiant/eclass_xml.cpp @@ -67,7 +67,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /// skin the VFS path to a skin file /// /// -/// flag attributes define a flag in the spawnflags key: +/// flag attributes define a flag in the "spawnflags" key: /// /// g_gridChange_callbacks; +Signal0 g_gridChange_callbacks; -void AddGridChangeCallback(const Callback& callback) +void AddGridChangeCallback(const SignalHandler& handler) { - g_gridChange_callbacks.push_back(callback); - callback(); + g_gridChange_callbacks.connectLast(handler); + handler(); } void GridChangeNotify() { - std::for_each(g_gridChange_callbacks.begin(), g_gridChange_callbacks.end(), CallbackInvoke()); + g_gridChange_callbacks(); } enum GridPower diff --git a/radiant/grid.h b/radiant/grid.h index 02e664fe..cf2671e9 100644 --- a/radiant/grid.h +++ b/radiant/grid.h @@ -22,11 +22,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if !defined(INCLUDED_GRID_H) #define INCLUDED_GRID_H +#include "signal/signalfwd.h" + float GetGridSize(); int Grid_getPower(); -class Callback; -void AddGridChangeCallback(const Callback& callback); +void AddGridChangeCallback(const SignalHandler& handler); void Grid_registerCommands(); typedef struct _GtkMenu GtkMenu; diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index d0b90001..ee4f8cbb 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -58,6 +58,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "cmdlib.h" #include "scenelib.h" #include "stream/stringstream.h" +#include "signal/isignal.h" #include "os/path.h" #include "os/file.h" #include "eclasslib.h" @@ -181,7 +182,6 @@ void VFS_Destroy() Radiant_detachHomePathsObserver(g_VFSModuleObserver); } - // Home Paths void HomePaths_Realise() @@ -2631,6 +2631,16 @@ public: MainWindowActive g_MainWindowActive; +MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler) +{ + return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst(handler); +} + +void XYWindowMouseDown_disconnect(MouseEventHandlerId id) +{ + g_pParentWnd->GetXYWnd()->onMouseDown.disconnect(id); +} + // ============================================================================= // MainFrame class diff --git a/radiant/mainframe.h b/radiant/mainframe.h index ab8278e7..4fadaae5 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -27,6 +27,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "gtkutil/widget.h" #include "string/string.h" +#include "qerplugin.h" + class IPlugIn; class IToolbarButton; @@ -274,6 +276,7 @@ extern int (*GridStatus_getFarClipDistance)(); extern bool (*GridStatus_getTextureLockEnabled)(); void GridStatus_onTextureLockEnabledChanged(); - +MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler); +void XYWindowMouseDown_disconnect(MouseEventHandlerId id); #endif diff --git a/radiant/map.cpp b/radiant/map.cpp index c846ca7e..67f528ec 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -64,6 +64,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "modulesystem/singletonmodule.h" #include "modulesystem/moduleregistry.h" #include "stream/stringstream.h" +#include "signal/signal.h" #include "gtkutil/filechooser.h" #include "timer.h" @@ -311,8 +312,7 @@ public: bool m_modified; void (*m_modified_changed)(const Map&); - typedef std::vector MapValidCallbacks; - MapValidCallbacks m_mapValidCallbacks; + Signal0 m_mapValidCallbacks; WorldNode m_world_node; // "classname" "worldspawn" ! @@ -363,9 +363,9 @@ public: Map g_map; Map* g_currentMap = 0; -void Map_addValidCallback(Map& map, const Callback& callback) +void Map_addValidCallback(Map& map, const SignalHandler& handler) { - map.m_mapValidCallbacks.push_back(callback); + map.m_mapValidCallbacks.connectLast(handler); } bool Map_Valid(const Map& map) @@ -376,7 +376,7 @@ bool Map_Valid(const Map& map) void Map_SetValid(Map& map, bool valid) { map.m_valid = valid; - std::for_each(map.m_mapValidCallbacks.begin(), map.m_mapValidCallbacks.end(), CallbackInvoke()); + map.m_mapValidCallbacks(); } @@ -1870,25 +1870,21 @@ void NewMap() } } -void maps_directory(StringOutputStream& buffer) +CopiedString g_mapsPath; + +const char* getMapsPath() { - ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "maps_directory: user-game-path is empty"); - buffer << g_qeglobals.m_userGamePath.c_str() << "maps/"; - Q_mkdir(buffer.c_str()); + return g_mapsPath.c_str(); } const char* map_open(const char* title) { - StringOutputStream buf(256); - maps_directory(buf); - return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, buf.c_str(), MapFormat::Name()); + return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name()); } const char* map_save(const char* title) { - StringOutputStream buf(256); - maps_directory(buf); - return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, buf.c_str(), MapFormat::Name()); + return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name()); } void OpenMap() @@ -2232,6 +2228,11 @@ void DoFind() gtk_widget_destroy(GTK_WIDGET(window)); } +void Map_constructPreferences(PreferencesPage& page) +{ + page.appendCheckBox("", "Load last map on open", g_bLoadLastMap); +} + class MapEntityClasses : public ModuleObserver { @@ -2267,10 +2268,34 @@ public: MapEntityClasses g_MapEntityClasses; -void Map_constructPreferences(PreferencesPage& page) +class MapModuleObserver : public ModuleObserver { - page.appendCheckBox("", "Load last map on open", g_bLoadLastMap); -} + std::size_t m_unrealised; +public: + MapModuleObserver() : m_unrealised(1) + { + } + void realise() + { + if(--m_unrealised == 0) + { + ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "maps_directory: user-game-path is empty"); + StringOutputStream buffer(256); + buffer << g_qeglobals.m_userGamePath.c_str() << "maps/"; + Q_mkdir(buffer.c_str()); + g_mapsPath = buffer.c_str(); + } + } + void unrealise() + { + if(++m_unrealised == 1) + { + g_mapsPath = ""; + } + } +}; + +MapModuleObserver g_MapModuleObserver; #include "preferencesystem.h" @@ -2291,9 +2316,11 @@ void Map_Construct() PreferencesDialog_addSettingsPreferences(FreeCaller1()); GlobalEntityClassManager().attach(g_MapEntityClasses); + Radiant_attachHomePathsObserver(g_MapModuleObserver); } void Map_Destroy() { + Radiant_detachHomePathsObserver(g_MapModuleObserver); GlobalEntityClassManager().detach(g_MapEntityClasses); } diff --git a/radiant/map.h b/radiant/map.h index 5640afd1..e74d8981 100644 --- a/radiant/map.h +++ b/radiant/map.h @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "iscenegraph.h" #include "generic/callback.h" +#include "signal/signalfwd.h" #include "string/stringfwd.h" class Map; @@ -31,7 +32,7 @@ extern Map g_map; class MapFormat; -void Map_addValidCallback(Map& map, const Callback& callback); +void Map_addValidCallback(Map& map, const SignalHandler& handler); bool Map_Valid(const Map& map); class DeferredDraw diff --git a/radiant/patch.cpp b/radiant/patch.cpp index 0da6d69d..80ffe351 100644 --- a/radiant/patch.cpp +++ b/radiant/patch.cpp @@ -24,18 +24,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "preferences.h" #include "brush_primit.h" +#include "signal/signal.h" -std::set g_patchTextureChangedCallbacks; +Signal0 g_patchTextureChangedCallbacks; -void Patch_addTextureChangedCallback(const Callback& callback) +void Patch_addTextureChangedCallback(const SignalHandler& handler) { - g_patchTextureChangedCallbacks.insert(callback); + g_patchTextureChangedCallbacks.connectLast(handler); } void Patch_textureChanged() { - std::for_each(g_patchTextureChangedCallbacks.begin(), g_patchTextureChangedCallbacks.end(), CallbackInvoke()); + g_patchTextureChangedCallbacks(); } diff --git a/radiant/patch.h b/radiant/patch.h index ebb291fc..614a4eb2 100644 --- a/radiant/patch.h +++ b/radiant/patch.h @@ -57,6 +57,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "stringio.h" #include "shaderlib.h" #include "generic/callback.h" +#include "signal/signalfwd.h" #include "texturelib.h" #include "xml/ixml.h" #include "dragplanes.h" @@ -164,7 +165,7 @@ public: bool patch_filtered(Patch& patch); void add_patch_filter(PatchFilter& filter, int mask, bool invert = false); -void Patch_addTextureChangedCallback(const Callback& callback); +void Patch_addTextureChangedCallback(const SignalHandler& handler); void Patch_textureChanged(); inline void BezierCurveTreeArray_deleteAll(Array& curveTrees) diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index a8fb1569..04b2aed0 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -52,6 +52,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "patch.h" #include "commands.h" #include "preferences.h" +#include "signal/isignal.h" #include diff --git a/radiant/plugin.cpp b/radiant/plugin.cpp index cd85e2a5..1e57eeb3 100644 --- a/radiant/plugin.cpp +++ b/radiant/plugin.cpp @@ -93,11 +93,33 @@ const char* GameDescription_getRequiredKeyValue(const char* key) return g_pGameDescription->getRequiredKeyValue(key); } -const char* mapname_get() +const char* getMapName() { return Map_Name(g_map); } +scene::Node& getMapWorldEntity() +{ + return Map_FindOrInsertWorldspawn(g_map); +} + +VIEWTYPE XYWindow_getViewType() +{ + return g_pParentWnd->GetXYWnd()->GetViewType(); +} + +Vector3 XYWindow_windowToWorld(const WindowVector& position) +{ + Vector3 result(0, 0, 0); + g_pParentWnd->GetXYWnd()->XY_ToPoint(static_cast(position.x()), static_cast(position.y()), result); + return result; +} + +const char* TextureBrowser_getSelectedShader() +{ + return TextureBrowser_GetSelectedShader(GlobalTextureBrowser()); +} + class RadiantCoreAPI { _QERFuncTable_1 m_radiantcore; @@ -115,7 +137,9 @@ public: m_radiantcore.getGameName = &gamename_get; m_radiantcore.getGameMode = &gamemode_get; - m_radiantcore.getMapName = &mapname_get; + m_radiantcore.getMapName = &getMapName; + m_radiantcore.getMapWorldEntity = getMapWorldEntity; + m_radiantcore.getGridSize = GetGridSize; m_radiantcore.getGameDescriptionKeyValue = &GameDescription_getKeyValue; m_radiantcore.getRequiredGameDescriptionKeyValue = &GameDescription_getRequiredKeyValue; @@ -129,6 +153,12 @@ public: m_radiantcore.attachGameModeObserver = Radiant_attachGameModeObserver; m_radiantcore.detachGameModeObserver = Radiant_detachGameModeObserver; + m_radiantcore.XYWindowMouseDown_connect = XYWindowMouseDown_connect; + m_radiantcore.XYWindowMouseDown_disconnect = XYWindowMouseDown_disconnect; + m_radiantcore.XYWindow_getViewType = XYWindow_getViewType; + m_radiantcore.XYWindow_windowToWorld = XYWindow_windowToWorld; + m_radiantcore.TextureBrowser_getSelectedShader = TextureBrowser_getSelectedShader; + m_radiantcore.m_pfnMessageBox = >k_MessageBox; m_radiantcore.m_pfnFileDialog = &file_dialog; m_radiantcore.m_pfnColorDialog = &color_dialog; diff --git a/radiant/preferences.h b/radiant/preferences.h index 49c9a5e9..497f183c 100644 --- a/radiant/preferences.h +++ b/radiant/preferences.h @@ -82,7 +82,7 @@ public: } GtkWidget* appendEntry(const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback) { - return m_dialog.addEntry(m_vbox, name, importCallback, exportCallback); + return m_dialog.addIntEntry(m_vbox, name, importCallback, exportCallback); } GtkWidget* appendEntry(const char* name, int& data) { @@ -90,7 +90,7 @@ public: } GtkWidget* appendEntry(const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback) { - return m_dialog.addEntry(m_vbox, name, importCallback, exportCallback); + return m_dialog.addSizeEntry(m_vbox, name, importCallback, exportCallback); } GtkWidget* appendEntry(const char* name, std::size_t& data) { @@ -98,7 +98,7 @@ public: } GtkWidget* appendEntry(const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback) { - return m_dialog.addEntry(m_vbox, name, importCallback, exportCallback); + return m_dialog.addFloatEntry(m_vbox, name, importCallback, exportCallback); } GtkWidget* appendEntry(const char* name, float& data) { diff --git a/radiant/scenegraph.cpp b/radiant/scenegraph.cpp index 84648d03..b58cea41 100644 --- a/radiant/scenegraph.cpp +++ b/radiant/scenegraph.cpp @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "string/string.h" -#include "generic/callback.h" +#include "signal/signal.h" #include "scenelib.h" #include "instancelib.h" #include "treemodel.h" @@ -76,10 +76,9 @@ class CompiledGraph : public scene::Graph, public scene::Instantiable::Observer InstanceMap m_instances; scene::Instantiable::Observer* m_observer; - typedef std::set BoundsChangedCallbacks; - BoundsChangedCallbacks m_boundsChanged; + Signal0 m_boundsChanged; scene::Path m_rootpath; - std::vector m_sceneChangedCallbacks; + Signal0 m_sceneChangedCallbacks; TypeIdMap m_nodeTypeIds; TypeIdMap m_instanceTypeIds; @@ -91,13 +90,13 @@ public: { } - void addSceneChangedCallback(const Callback& callback) + void addSceneChangedCallback(const SignalHandler& handler) { - m_sceneChangedCallbacks.push_back(callback); + m_sceneChangedCallbacks.connectLast(handler); } void sceneChanged() { - std::for_each(m_sceneChangedCallbacks.begin(), m_sceneChangedCallbacks.end(), CallbackInvoke()); + m_sceneChangedCallbacks(); } scene::Node& root() @@ -133,7 +132,7 @@ public: } void boundsChanged() { - std::for_each(m_boundsChanged.begin(), m_boundsChanged.end(), CallbackInvoke()); + m_boundsChanged(); } void traverse(const Walker& walker) @@ -172,15 +171,13 @@ public: m_instances.erase(PathConstReference(instance->path())); } - void addBoundsChangedCallback(const Callback& boundsChanged) + SignalHandlerId addBoundsChangedCallback(const SignalHandler& boundsChanged) { - ASSERT_MESSAGE(m_boundsChanged.find(boundsChanged) == m_boundsChanged.end(), "bounds-changed callback already registered"); - m_boundsChanged.insert(boundsChanged); + return m_boundsChanged.connectLast(boundsChanged); } - void removeBoundsChangedCallback(const Callback& boundsChanged) + void removeBoundsChangedCallback(SignalHandlerId id) { - ASSERT_MESSAGE(m_boundsChanged.find(boundsChanged) != m_boundsChanged.end(), "bounds-changed callback not registered"); - m_boundsChanged.erase(boundsChanged); + m_boundsChanged.disconnect(id); } TypeId getNodeTypeId(const char* name) diff --git a/radiant/select.cpp b/radiant/select.cpp index 36b2e3e8..09f0709c 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "stream/stringstream.h" +#include "signal/isignal.h" #include "shaderlib.h" #include "scenelib.h" @@ -730,16 +731,18 @@ void SceneSelectionChange(const Selectable& selectable) SceneChangeNotify(); } +SignalHandlerId Selection_boundsChanged; + void Selection_construct() { GlobalSelectionSystem().addSelectionChangeCallback(FreeCaller1()); GlobalSelectionSystem().addSelectionChangeCallback(FreeCaller1()); - GlobalSceneGraph().addBoundsChangedCallback(FreeCaller()); + Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(FreeCaller()); } void Selection_destroy() { - GlobalSceneGraph().removeBoundsChangedCallback(FreeCaller()); + GlobalSceneGraph().removeBoundsChangedCallback(Selection_boundsChanged); } diff --git a/radiant/selection.cpp b/radiant/selection.cpp index 15e7d146..e6142d4e 100644 --- a/radiant/selection.cpp +++ b/radiant/selection.cpp @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "editable.h" #include "math/frustum.h" -#include "generic/callback.h" +#include "signal/signal.h" #include "generic/object.h" #include "selectionlib.h" #include "render.h" @@ -2797,7 +2797,7 @@ private: selection_t m_selection; selection_t m_component_selection; - std::vector m_selectionChanged_callbacks; + Signal1 m_selectionChanged_callbacks; void ConstructPivot() const; mutable bool m_pivotChanged; @@ -2975,14 +2975,13 @@ public: } } - void addSelectionChangeCallback(const SelectionChangeCallback& callback) + void addSelectionChangeCallback(const SelectionChangeHandler& handler) { - m_selectionChanged_callbacks.push_back(callback); + m_selectionChanged_callbacks.connectLast(handler); } void selectionChanged(const Selectable& selectable) { - typedef Functor1Invoke SelectionChangeCallbackInvoke; - std::for_each(m_selectionChanged_callbacks.begin(), m_selectionChanged_callbacks.end(), SelectionChangeCallbackInvoke(selectable)); + m_selectionChanged_callbacks(selectable); } typedef MemberCaller1 SelectionChangedCaller; @@ -3341,7 +3340,6 @@ namespace inline RadiantSelectionSystem& getSelectionSystem() { - ASSERT_NOTNULL(g_RadiantSelectionSystem); return *g_RadiantSelectionSystem; } } @@ -3757,13 +3755,15 @@ void SelectionSystem_OnBoundsChanged() } +SignalHandlerId SelectionSystem_boundsChanged; + void SelectionSystem_Construct() { RadiantSelectionSystem::constructStatic(); g_RadiantSelectionSystem = new RadiantSelectionSystem; - GlobalSceneGraph().addBoundsChangedCallback(FreeCaller()); + SelectionSystem_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(FreeCaller()); GlobalShaderCache().attachRenderable(getSelectionSystem()); } @@ -3772,7 +3772,7 @@ void SelectionSystem_Destroy() { GlobalShaderCache().detachRenderable(getSelectionSystem()); - GlobalSceneGraph().removeBoundsChangedCallback(FreeCaller()); + GlobalSceneGraph().removeBoundsChangedCallback(SelectionSystem_boundsChanged); delete g_RadiantSelectionSystem; diff --git a/radiant/selection.h b/radiant/selection.h index 429ac0f9..8334ec63 100644 --- a/radiant/selection.h +++ b/radiant/selection.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_SELECTION_H #include "windowobserver.h" +#include "generic/callbackfwd.h" struct rect_t { @@ -30,12 +31,9 @@ struct rect_t float max[2]; }; -template -class Callback1; typedef Callback1 RectangleCallback; class View; -class Callback; class SelectionSystemWindowObserver : public WindowObserver { diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index b938dd03..1ec06951 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -45,7 +45,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include //Shamus: For Textool -#include "generic/callback.h" +#include "signal/isignal.h" #include "generic/object.h" #include "math/vector.h" #include "texturelib.h" diff --git a/radiant/textureentry.h b/radiant/textureentry.h index 4325c095..3965fe29 100644 --- a/radiant/textureentry.h +++ b/radiant/textureentry.h @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "gtkutil/idledraw.h" #include "generic/static.h" +#include "signal/isignal.h" #include "shaderlib.h" #include "texwindow.h" @@ -100,7 +101,7 @@ public: } } } - void connect(const Callback& update) const + void connect(const SignalHandler& update) const { TextureBrowser_addActiveShadersChangedCallback(update); } @@ -116,7 +117,7 @@ public: { GlobalShaderSystem().foreachShaderName(callback); } - void connect(const Callback& update) const + void connect(const SignalHandler& update) const { TextureBrowser_addShadersRealiseCallback(update); } diff --git a/radiant/textures.h b/radiant/textures.h index 02b45621..0a570b7d 100644 --- a/radiant/textures.h +++ b/radiant/textures.h @@ -22,11 +22,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if !defined (INCLUDED_TEXTURES_H) #define INCLUDED_TEXTURES_H +#include "generic/callbackfwd.h" + void Textures_Realise(); void Textures_Unrealise(); void Textures_sharedContextDestroyed(); -class Callback; void Textures_setModeChangedNotify(const Callback& notify); #endif diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 58285259..23374ec8 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -53,7 +53,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include "generic/callback.h" +#include "signal/signal.h" #include "math/vector.h" #include "texturelib.h" #include "string/string.h" @@ -715,27 +715,27 @@ void TextureBrowser_setOriginY(TextureBrowser& textureBrowser, int originy) } -std::set g_activeShadersChangedCallbacks; +Signal0 g_activeShadersChangedCallbacks; -void TextureBrowser_addActiveShadersChangedCallback(const Callback& callback) +void TextureBrowser_addActiveShadersChangedCallback(const SignalHandler& handler) { - g_activeShadersChangedCallbacks.insert(callback); + g_activeShadersChangedCallbacks.connectLast(handler); } class ShadersObserver : public ModuleObserver { - std::set m_realiseCallbacks; + Signal0 m_realiseCallbacks; public: void realise() { - std::for_each(m_realiseCallbacks.begin(), m_realiseCallbacks.end(), CallbackInvoke()); + m_realiseCallbacks(); } void unrealise() { } - void insert(const Callback& callback) + void insert(const SignalHandler& handler) { - m_realiseCallbacks.insert(callback); + m_realiseCallbacks.connectLast(handler); } }; @@ -744,9 +744,9 @@ namespace ShadersObserver g_ShadersObserver; } -void TextureBrowser_addShadersRealiseCallback(const Callback& callback) +void TextureBrowser_addShadersRealiseCallback(const SignalHandler& handler) { - g_ShadersObserver.insert(callback); + g_ShadersObserver.insert(handler); } void TextureBrowser_activeShadersChanged(TextureBrowser& textureBrowser) @@ -754,7 +754,7 @@ void TextureBrowser_activeShadersChanged(TextureBrowser& textureBrowser) TextureBrowser_heightChanged(textureBrowser); textureBrowser.m_originInvalid = true; - std::for_each(g_activeShadersChangedCallbacks.begin(), g_activeShadersChangedCallbacks.end(), CallbackInvoke()); + g_activeShadersChangedCallbacks(); } void TextureBrowser_importShowScrollbar(TextureBrowser& textureBrowser, bool value) diff --git a/radiant/texwindow.h b/radiant/texwindow.h index 4921fa05..dd871b37 100644 --- a/radiant/texwindow.h +++ b/radiant/texwindow.h @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_TEXWINDOW_H #include "math/vector.h" +#include "generic/callbackfwd.h" +#include "signal/signalfwd.h" // textures menu @@ -57,8 +59,6 @@ const char* TextureBrowser_GetSelectedShader(TextureBrowser& textureBrower); void TextureBrowser_Construct(); void TextureBrowser_Destroy(); -template -class Callback1; typedef Callback1 StringImportCallback; template class FreeCaller1; @@ -70,8 +70,7 @@ typedef FreeCaller1 Tex const Vector3& TextureBrowser_getBackgroundColour(TextureBrowser& textureBrowser); void TextureBrowser_setBackgroundColour(TextureBrowser& textureBrowser, const Vector3& colour); -class Callback; -void TextureBrowser_addActiveShadersChangedCallback(const Callback& callback); -void TextureBrowser_addShadersRealiseCallback(const Callback& callback); +void TextureBrowser_addActiveShadersChangedCallback(const SignalHandler& handler); +void TextureBrowser_addShadersRealiseCallback(const SignalHandler& handler); #endif diff --git a/radiant/undo.cpp b/radiant/undo.cpp index 001adbf9..aa75d950 100644 --- a/radiant/undo.cpp +++ b/radiant/undo.cpp @@ -467,7 +467,7 @@ typedef ConstReferenceCaller1type == GDK_BUTTON_PRESS) { - xywnd->XY_MouseDown(static_cast(event->x), static_cast(event->y), buttons_for_event_button(event)); + g_pParentWnd->SetActiveXY(xywnd); + + xywnd->ButtonState_onMouseDown(buttons_for_event_button(event)); + + xywnd->onMouseDown(WindowVector(event->x, event->y), button_for_button(event->button), modifiers_for_state(event->state)); } return FALSE; } @@ -733,6 +761,8 @@ gboolean xywnd_button_release(GtkWidget* widget, GdkEventButton* event, XYWnd* x if(event->type == GDK_BUTTON_RELEASE) { xywnd->XY_MouseUp(static_cast(event->x), static_cast(event->y), buttons_for_event_button(event)); + + xywnd->ButtonState_onMouseUp(buttons_for_event_button(event)); } return FALSE; } @@ -852,6 +882,8 @@ XYWnd::XYWnd() : AddCameraMovedCallback(ReferenceCaller(*this)); PressedButtons_connect(g_pressedButtons, m_gl_widget); + + onMouseDown.connectLast(makeSignalHandler3(MouseDownCaller(), *this)); } XYWnd::~XYWnd() @@ -1308,12 +1340,12 @@ inline WindowVector WindowVector_forInteger(int x, int y) return WindowVector(static_cast(x), static_cast(y)); } +void XYWnd::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers) +{ + XY_MouseDown(static_cast(position.x()), static_cast(position.y()), buttons_for_button_and_modifiers(button, modifiers)); +} void XYWnd::XY_MouseDown (int x, int y, unsigned int buttons) { - g_pParentWnd->SetActiveXY(this); - - ButtonState_onMouseDown(buttons); - if(buttons == Move_buttons()) { Move_Begin(); @@ -1371,8 +1403,6 @@ void XYWnd::XY_MouseUp(int x, int y, unsigned int buttons) { m_window_observer->onMouseUp(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons)); } - - ButtonState_onMouseUp(buttons); } void XYWnd::XY_MouseMoved (int x, int y, unsigned int buttons) diff --git a/radiant/xywindow.h b/radiant/xywindow.h index 5891c038..317ec591 100644 --- a/radiant/xywindow.h +++ b/radiant/xywindow.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define INCLUDED_XYWINDOW_H #include "math/matrix.h" +#include "signal/signal.h" #include "gtkutil/cursor.h" #include "gtkutil/window.h" @@ -30,6 +31,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "view.h" #include "map.h" +#include "qerplugin.h" + class Shader; class SelectionSystemWindowObserver; namespace scene @@ -46,13 +49,6 @@ void Clip(); void OnClipMode(bool enabled); bool ClipMode(); -enum VIEWTYPE -{ - YZ = 0, - XZ = 1, - XY = 2 -}; - inline const char* ViewType_getTitle(VIEWTYPE viewtype) { if(viewtype == XY) @@ -177,18 +173,6 @@ private: int m_ptCursorX, m_ptCursorY; unsigned int m_buttonstate; - void ButtonState_onMouseDown(unsigned int buttons) - { - m_buttonstate |= buttons; - } - void ButtonState_onMouseUp(unsigned int buttons) - { - m_buttonstate &= ~buttons; - } - unsigned int getButtonState() const - { - return m_buttonstate; - } int m_nNewBrushPressx; int m_nNewBrushPressy; @@ -209,6 +193,18 @@ private: bool m_entityCreate; public: + void ButtonState_onMouseDown(unsigned int buttons) + { + m_buttonstate |= buttons; + } + void ButtonState_onMouseUp(unsigned int buttons) + { + m_buttonstate &= ~buttons; + } + unsigned int getButtonState() const + { + return m_buttonstate; + } void EntityCreate_MouseDown(int x, int y); void EntityCreate_MouseMove(int x, int y); void EntityCreate_MouseUp(int x, int y); @@ -231,6 +227,10 @@ public: { return m_nHeight; } + + Signal3 onMouseDown; + void mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers); + typedef Member3 MouseDownCaller; }; inline void XYWnd_Update(XYWnd& xywnd) -- 2.39.2