refactored plugin api; refactored callback library; added signals library
authorspog <spog>
Sun, 9 Apr 2006 17:15:13 +0000 (17:15 +0000)
committerspog <spog>
Sun, 9 Apr 2006 17:15:13 +0000 (17:15 +0000)
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@44 8a3a26a2-13c4-0310-b231-cf6edde360e5

127 files changed:
CHANGES
GtkRadiant.sln
contrib/bobtoolz/CPortals.h
contrib/bobtoolz/DBobView.cpp
contrib/bobtoolz/DBobView.h
contrib/bobtoolz/DBrush.cpp
contrib/bobtoolz/DBrush.h
contrib/bobtoolz/DEPair.cpp
contrib/bobtoolz/DEPair.h
contrib/bobtoolz/DEntity.cpp
contrib/bobtoolz/DEntity.h
contrib/bobtoolz/DListener.cpp
contrib/bobtoolz/DMap.cpp
contrib/bobtoolz/DMap.h
contrib/bobtoolz/DPatch.cpp
contrib/bobtoolz/DPatch.h
contrib/bobtoolz/DPlane.cpp
contrib/bobtoolz/DPlane.h
contrib/bobtoolz/DPoint.cpp
contrib/bobtoolz/DPoint.h
contrib/bobtoolz/DShape.cpp
contrib/bobtoolz/DShape.h
contrib/bobtoolz/DTrainDrawer.cpp
contrib/bobtoolz/DTrainDrawer.h
contrib/bobtoolz/DTreePlanter.cpp
contrib/bobtoolz/DTreePlanter.h
contrib/bobtoolz/DVisDrawer.cpp
contrib/bobtoolz/DVisDrawer.h
contrib/bobtoolz/DWinding.cpp
contrib/bobtoolz/DWinding.h
contrib/bobtoolz/ScriptParser.cpp
contrib/bobtoolz/StdAfx.h
contrib/bobtoolz/bobToolz-GTK.cpp
contrib/bobtoolz/bobToolz.def
contrib/bobtoolz/bsploader.cpp
contrib/bobtoolz/bsploader.h
contrib/bobtoolz/cportals.cpp
contrib/bobtoolz/dialogs/dialogs-gtk.cpp
contrib/bobtoolz/dialogs/dialogs-gtk.h
contrib/bobtoolz/funchandlers-GTK.cpp
contrib/bobtoolz/funchandlers.cpp
contrib/bobtoolz/lists.cpp
contrib/bobtoolz/lists.h
contrib/bobtoolz/misc.cpp
contrib/bobtoolz/misc.h
contrib/bobtoolz/shapes.cpp
contrib/bobtoolz/shapes.h
contrib/bobtoolz/visfind.cpp
contrib/bobtoolz/visfind.h
contrib/gtkgensurf/genmap.cpp
contrib/prtview/portals.cpp
include/ibrush.h
include/icamera.h
include/ientity.h
include/ifilesystem.h
include/irender.h
include/iscenegraph.h
include/iselection.h
include/ishaders.h
include/iundo.h
include/mapfile.h
include/modelskin.h
include/nameable.h
include/namespace.h
include/preferencesystem.h
include/qerplugin.h
include/selectable.h
libs/container/hashtable.h
libs/debugging/debugging.h
libs/entitylib.h
libs/generic/callback.cpp
libs/generic/callback.h
libs/generic/callbackfwd.cpp [new file with mode: 0644]
libs/generic/callbackfwd.h [new file with mode: 0644]
libs/generic/functional.cpp [new file with mode: 0644]
libs/generic/functional.h [new file with mode: 0644]
libs/gtkutil/button.h
libs/gtkutil/menu.h
libs/gtkutil/toolbar.h
libs/libs.vcproj
libs/math/vector.h
libs/signal/isignal.cpp [new file with mode: 0644]
libs/signal/isignal.h [new file with mode: 0644]
libs/signal/signal.cpp [new file with mode: 0644]
libs/signal/signal.h [new file with mode: 0644]
libs/signal/signalfwd.cpp [new file with mode: 0644]
libs/signal/signalfwd.h [new file with mode: 0644]
libs/xml/xmlelement.h
plugins/entity/curve.h
plugins/entity/doom3group.cpp
plugins/entity/keyobservers.h
plugins/entity/namekeys.h
plugins/entity/targetable.h
radiant/brush.cpp
radiant/brush.h
radiant/brushmanip.cpp
radiant/brushmanip.h
radiant/brushmodule.cpp
radiant/camwindow.cpp
radiant/camwindow.h
radiant/csg.cpp
radiant/dialog.cpp
radiant/dialog.h
radiant/eclass_xml.cpp
radiant/grid.cpp
radiant/grid.h
radiant/mainframe.cpp
radiant/mainframe.h
radiant/map.cpp
radiant/map.h
radiant/patch.cpp
radiant/patch.h
radiant/patchdialog.cpp
radiant/plugin.cpp
radiant/preferences.h
radiant/scenegraph.cpp
radiant/select.cpp
radiant/selection.cpp
radiant/selection.h
radiant/surfacedialog.cpp
radiant/textureentry.h
radiant/textures.h
radiant/texwindow.cpp
radiant/texwindow.h
radiant/undo.cpp
radiant/xywindow.cpp
radiant/xywindow.h

diff --git a/CHANGES b/CHANGES
index 3ab71a6..a7b3a7f 100644 (file)
--- 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.
index 7ee5bd3..2eacd63 100644 (file)
@@ -146,6 +146,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrtView", "contrib\prtview\
                {853632F4-6420-40C5-B80B-38B678E472B8} = {853632F4-6420-40C5-B80B-38B678E472B8}\r
        EndProjectSection\r
 EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bobtoolz", "contrib\bobtoolz\bobtoolz.vcproj", "{B20364D1-4329-4D4E-B9CE-C9767618FDD6}"\r
+       ProjectSection(ProjectDependencies) = postProject\r
+       EndProjectSection\r
+EndProject\r
 Global\r
        GlobalSection(SolutionConfiguration) = preSolution\r
                Debug = Debug\r
@@ -272,6 +276,10 @@ Global
                {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32\r
                {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32\r
                {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32\r
+               {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.ActiveCfg = Debug|Win32\r
+               {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32\r
+               {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32\r
+               {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32\r
        EndGlobalSection\r
        GlobalSection(ExtensibilityGlobals) = postSolution\r
        EndGlobalSection\r
index baab0a7..71f399b 100644 (file)
@@ -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:
 
index f4d36de..c5de46f 100644 (file)
@@ -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 <list>
+
+#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
index 9490260..6869e6b 100644 (file)
@@ -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<DBobView, const char*, &DBobView::valueChanged> 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_)
index 835e091..75b2a6e 100644 (file)
@@ -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 <list>
 #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<DPlane *>::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++)
+       for(std::list<DPlane *>::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++)
        {
-               list<DPlane *>::const_iterator p2=p1;
+               std::list<DPlane *>::const_iterator p2=p1;
                for(p2++; p2!=faceList.end(); p2++)
                {
-                       list<DPlane *>::const_iterator p3=p2;
+                       std::list<DPlane *>::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<DBrush, const _QERFaceData&, DBrush_addFace> 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<DBrush, const _QERFaceData&, DBrush_addFaceTextured> 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<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+       for(std::list<DPlane *>::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<DPoint *>::const_iterator deadPoint=pointList.begin(); deadPoint!=pointList.end(); deadPoint++) {
+       for(std::list<DPoint *>::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<DPlane *>::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++)
+       bBoundsBuilt = false;
+       for(std::list<DPlane *>::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<DPoint *>::const_iterator chkPoint=pointList.begin(); chkPoint!=pointList.end(); chkPoint++)
+       for(std::list<DPoint *>::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<DPlane *>::iterator chkPlane;
+       std::list<DPlane *>::iterator chkPlane;
 
        // find duplicate planes
-       list<DPlane *>::iterator p1=faceList.begin();
+       std::list<DPlane *>::iterator p1=faceList.begin();
 
        while( p1!=faceList.end() )
        {
-               list<DPlane *>::iterator p2 = p1;
+               std::list<DPlane *>::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<DPlane *>::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++)
+       for(std::list<DPlane *>::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<DPoint *>::const_iterator chkPnt = pointList.begin();
+       std::list<DPoint *>::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<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+               for(std::list<DPlane *>::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<DPlane *>::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) {
-               if((*buildPlane)->AddToBrush(node->m_brush) && changeCnt) {
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator parsePlane=faceList.begin(); parsePlane!=faceList.end(); parsePlane++)
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator iplPlane;
+       std::list<DPlane *>::const_iterator iplPlane;
 
        for( iplPlane=faceList.begin(); iplPlane!=faceList.end(); iplPlane++)
        {
 
-               bool allInFront = TRUE;
-               for(list<DPoint *>::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++)
+               bool allInFront = true;
+               for(std::list<DPoint *>::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<DPoint *>::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++)
+               bool allInFront = true;
+               for(std::list<DPoint *>::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<DPlane *>::const_iterator iplPlane;
+       std::list<DPlane *>::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<DPoint *>::const_iterator first = pointList.begin();
+               std::list<DPoint *>::const_iterator first = pointList.begin();
                VectorCopy((*first)->_pnt, bbox_min);
                VectorCopy((*first)->_pnt, bbox_max);
 
-               list<DPoint *>::const_iterator point=pointList.begin();
+               std::list<DPoint *>::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<Str>* exclusionList)
+void DBrush::ResetChecks(std::list<Str>* exclusionList)
 {
-       for(list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
+       for(std::list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
        {
-               bool set = FALSE;
+               bool set = false;
 
                if(exclusionList)
                {
-                       for(list<Str>::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++)
+                       for(std::list<Str>::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<Str>* exclusionList)
 
 DPlane* DBrush::HasPlaneInverted(DPlane *chkPlane)
 {
-       for(list<DPlane *>::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++)
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator pp=faceList.begin(); pp!=faceList.end(); pp++)
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator rotPlane=faceList.begin(); rotPlane!=faceList.end(); rotPlane++)
+       for(std::list<DPlane *>::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<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
+               bool changed = false;
+               for(std::list<DPlane *>::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<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
+               for(std::list<DPlane *>::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<DPlane *>::const_iterator chkPlane;
+       std::list<DPlane *>::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<DPlane *>::const_iterator chkPlane;
+       std::list<DPlane *>::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<DPoint *>::const_iterator points = pointList.begin(); points != pointList.end(); points++ ) {
+       for( std::list<DPoint *>::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<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) {          
+       bBoundsBuilt = false;
+       for( std::list<DPlane *>::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
-       }
-}
index b285bc0..9915d0f 100644 (file)
@@ -28,6 +28,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #pragma once
 #endif // _MSC_VER > 1000
 
+#include <stdio.h>
+#include <list>
+#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<Str>* exclusionList);
+       void ResetChecks(std::list<Str>* 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<DPlane*> faceList;
-       list<DPoint*> pointList;
+       std::list<DPlane*> faceList;
+       std::list<DPoint*> pointList;
        int m_nBrushID;
        vec3_t bbox_min, bbox_max;
        bool bBoundsBuilt;
index e7cc1ed..72dda4b 100644 (file)
@@ -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"
 
 //////////////////////////////////////////////////////////////////////
index bf8d7ad..fac4c33 100644 (file)
@@ -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:
index 5a76ca1..f69b358 100644 (file)
@@ -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 <list>
 #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 <vector>
 #include <list>
@@ -97,7 +98,7 @@ DEntity::~DEntity()
 
 void DEntity::ClearBrushes()
 {
-       for(list<DBrush *>::const_iterator deadBrush=brushList.begin(); deadBrush!=brushList.end(); deadBrush++)
+       for(std::list<DBrush *>::const_iterator deadBrush=brushList.begin(); deadBrush!=brushList.end(); deadBrush++)
        {
                delete *deadBrush;
        }
@@ -106,7 +107,7 @@ void DEntity::ClearBrushes()
 
 void DEntity::ClearPatches()
 {
-       for(list<DPatch *>::const_iterator deadPatch=patchList.begin(); deadPatch!=patchList.end(); deadPatch++)
+       for(std::list<DPatch *>::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<DBrush *>::const_iterator chkBrush=brushList.begin(); chkBrush!=brushList.end(); chkBrush++)
+       for(std::list<DBrush *>::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<typename Functor>
+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<typename Functor>
+inline const Functor& Scene_forEachSelectedBrush(const Functor& functor)
+{
+  GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor<Functor>(functor));
+  return functor;
+}
+
+void DEntity_loadBrush(DEntity& entity, scene::Node& brush)
+{
+  DBrush* loadBrush = entity.NewBrush(entity.brushList.size());
+       loadBrush->LoadFromBrush(brush, true);
+}
+typedef ReferenceCaller1<DEntity, scene::Node&, DEntity_loadBrush> 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<typename Functor>
+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<typename Functor>
+inline const Functor& Scene_forEachSelectedPatch(const Functor& functor)
+{
+  GlobalSelectionSystem().foreachSelected(PatchSelectedVisitor<Functor>(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<DEntity, scene::Node&, DEntity_loadPatch> 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<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
+       for(std::list<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
        {
-               list<DBrush *>::const_iterator pB2=pB1;
+               std::list<DBrush *>::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<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
+       for(std::list<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
        {
-               list<DBrush *>::const_iterator pB2=pB1;
+               std::list<DBrush *>::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<DBrush *>::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<Str>* exclusionList, bool useDetail)
+void DEntity::RemoveNonCheckBrushes(std::list<Str>* exclusionList, bool useDetail)
 {
-       list<DBrush *>::iterator chkBrush=brushList.begin();
+       std::list<DBrush *>::iterator chkBrush=brushList.begin();
 
        while( chkBrush!=brushList.end() )
        {
@@ -414,7 +447,7 @@ void DEntity::RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail)
                        }
                }
 
-               list<Str>::iterator eTexture;
+               std::list<Str>::iterator eTexture;
 
                for( eTexture=exclusionList->begin(); eTexture!=exclusionList->end(); eTexture++ )
                {
@@ -431,9 +464,9 @@ void DEntity::RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail)
        }
 }
 
-void DEntity::ResetChecks(list<Str>* exclusionList)
+void DEntity::ResetChecks(std::list<Str>* exclusionList)
 {
-       for(list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
+       for(std::list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
        {
                (*resetBrush)->ResetChecks(exclusionList);
        }
@@ -443,7 +476,7 @@ int DEntity::FixBrushes()
 {
        int count = 0;
 
-       for(list<DBrush *>::const_iterator fixBrush=brushList.begin(); fixBrush!=brushList.end(); fixBrush++)
+       for(std::list<DBrush *>::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<DEPair* >::const_iterator buildEPair=epairList.begin(); buildEPair!=epairList.end(); buildEPair++)
+               for(std::list<DEPair* >::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<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
-                       (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node);
+               for(std::list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
+                       (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node.get_pointer());
 
-               for(list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
-                       (*buildPatch)->BuildInRadiant(node);
+               for(std::list<DPatch *>::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<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
+               for(std::list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
                        (*buildBrush)->BuildInRadiant(allowDestruction, NULL);
 
-               for(list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
+               for(std::list<DPatch *>::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<DBrush *>::const_iterator cntBrush=brushList.begin(); cntBrush!=brushList.end(); cntBrush++) {
+       for(std::list<DBrush *>::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<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
+       for(std::list<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
        {
                fprintf(pFile, "\"%s\" \"%s\"\n", (const char *)(*ep)->key, (const char *)(*ep)->value);
        }
 
-       for(list<DBrush *>::const_iterator bp=brushList.begin(); bp!=brushList.end(); bp++)
+       for(std::list<DBrush *>::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<DEPair *>::const_iterator deadEPair=epairList.begin(); deadEPair!=epairList.end(); deadEPair++)
+       for(std::list<DEPair *>::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<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
+       for(std::list<DBrush *>::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<DPatch *>::const_iterator resetPatch=patchList.begin(); resetPatch!=patchList.end(); resetPatch++)
+         for(std::list<DPatch *>::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<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
+       for(std::list<DEPair *>::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<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) {
+DBrush* DEntity::FindBrushByPointer( scene::Node& brush ) {
+       for(std::list<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) {
                DBrush* pBrush = (*listBrush);
-               if(pBrush->QER_brush == brush) {
+               if(pBrush->QER_brush == &brush) {
                        return pBrush;
                }
        }
index ba3794d..5baa3d3 100644 (file)
@@ -28,6 +28,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #pragma once
 #endif // _MSC_VER > 1000
 
+#include <list>
+#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<Str>* exclusionList);
-       void RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail);
+       void ResetChecks(std::list<Str>* exclusionList);
+       void RemoveNonCheckBrushes(std::list<Str>* 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<DEPair*> epairList;
-       list<DBrush*> brushList;
+       std::list<DEPair*> epairList;
+       std::list<DBrush*> brushList;
        // new patches, wahey!!!
-       list<DPatch*> patchList;
+       std::list<DPatch*> 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();
 
index cd688f4..3d04a42 100644 (file)
@@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
 //////////////////////////////////////////////////////////////////////
 
-#include "StdAfx.h"
 #include "DListener.h"
 
 //////////////////////////////////////////////////////////////////////
index 382a025..18e4318 100644 (file)
@@ -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 <list>
 
 #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 <vector>
 #include <list>
@@ -78,7 +77,7 @@ void DMap::ClearEntities()
 {
        m_nNextEntity = 1;
 
-       for(list<DEntity *>::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++)
+       for(std::list<DEntity *>::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<DEntity *>::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++)
+       for(std::list<DEntity *>::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<DEntity *>::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++)
+       for(std::list<DEntity *>::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<DEntity *>::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++)
+       for(std::list<DEntity *>::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<DEntity *>::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++)
+       for(std::list<DEntity *>::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);
 }
index 7568234..970b958 100644 (file)
@@ -28,13 +28,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #pragma once
 #endif // _MSC_VER > 1000
 
+#include <list>
+
+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<DEntity*> entityList;
+       std::list<DEntity*> entityList;
 
        DMap();
        virtual ~DMap();
index 50bca9f..2158eff 100644 (file)
@@ -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 <list>
 #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> DPatch::Split(bool rows, bool cols)
+std::list<DPatch> DPatch::Split(bool rows, bool cols)
 {
-       list<DPatch> patchList;
+       std::list<DPatch> patchList;
        int i;
        int x, y;
 
@@ -419,13 +412,13 @@ list<DPatch> DPatch::Split(bool rows, bool cols)
 
                if(cols && width >= 5)
                {
-                       list<DPatch> patchList2;
+                       std::list<DPatch> patchList2;
 
-                       for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++)
+                       for(std::list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++)
                        {
-                               list<DPatch> patchList3 = (*patches).Split(false, true);
+                               std::list<DPatch> patchList3 = (*patches).Split(false, true);
                                
-                               for(list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++)
+                               for(std::list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++)
                                        patchList2.push_front(*patches2);
                        }
 
index 4d85e90..d1442ce 100644 (file)
@@ -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 <list>
 
 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<DPatch> Split(bool rows, bool cols);
+       std::list<DPatch> 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;
index f577683..c9c7b67 100644 (file)
@@ -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 <list>
 
 #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<DPoint*>& pointList)
+bool DPlane::IsRedundant(std::list<DPoint*>& pointList)
 {
        int cnt = 0;
 
-       //list<DPoint *>::const_iterator point=pointList.begin();
-       for(list<DPoint *>::const_iterator point=pointList.begin(); point!=pointList.end(); point++)
+       //std::list<DPoint *>::const_iterator point=pointList.begin();
+       for(std::list<DPoint *>::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;
 }
index 11c3f68..68db6ed 100644 (file)
@@ -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 <list>
+#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<DPoint*>& pointList);
+       bool IsRedundant(std::list<DPoint*>& 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;
index a56e91f..b0b6015 100644 (file)
@@ -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;
 }
index 394352c..1213734 100644 (file)
@@ -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:
index ebe2c0d..9201d29 100644 (file)
@@ -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 <list>
+#include <time.h>
 #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;
 }
index 4bc4baa..3c4ed75 100644 (file)
@@ -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
 
index 35ee494..38abb65 100644 (file)
@@ -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 <list>
 #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<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
+       for(std::list<splinePoint_t *>::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<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
+       for(std::list<controlPoint_t *>::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<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+void DTrainDrawer::render(RenderStateFlags state) const
+{
+       for(std::list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
                splinePoint_t* pSP = (*sp);
 
-               __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
-                       for(list<DPoint >::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<DPoint >::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<splinePoint_t* >::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<DPoint >::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<splinePoint_t* >::const_iterator sp;
+  std::list<splinePoint_t* >::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<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {                        
+               for(std::list<controlPoint_t >::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<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
+               for(std::list<controlPoint_t>::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<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
+       for(std::list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
                if(!strcmp(name, (*cp)->strName)) {
                        return (*cp);
                }
        }
 
-       for(list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+       for(std::list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
                if(!strcmp(name, (*sp)->point.strName)) {
                        return &((*sp)->point);
                }
index ae9fa2c..9d8903e 100644 (file)
@@ -29,6 +29,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #pragma once
 #endif // _MSC_VER > 1000
 
+#include <list>
+#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<controlPoint_t> m_pointList;
-       list<DPoint> m_vertexList;
+       std::list<controlPoint_t> m_pointList;
+       std::list<DPoint> m_vertexList;
 
        controlPoint_t* pTarget;
 } splinePoint_t;
 
-class DTrainDrawer :
-       public IGL2DWindow,
-       public IGL3DWindow
+class DTrainDrawer : public Renderable, public OpenGLRenderable
 {
 private:
-       list<splinePoint_t*> m_splineList;
-       list<controlPoint_t*> m_pointList;
-       int refCount;
+       std::list<splinePoint_t*> m_splineList;
+       std::list<controlPoint_t*> 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();
index 237c9cc..54850ce 100644 (file)
@@ -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 <list>
 #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<int>(x), static_cast<int>(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 );
        }*/
 }
index 87d0d6c..61bc1e8 100644 (file)
@@ -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<DTreePlanter, const WindowVector&, ButtonIdentifier, ModifierFlags, SignalHandlerResult, &DTreePlanter::mouseDown> 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;
index 46ddca5..0a93694 100644 (file)
@@ -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 <list>
 #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<DWinding *>::const_iterator l=m_list->begin();
+       std::list<DWinding *>::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<DWinding *>::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<DWinding*> *pointList)
@@ -178,7 +137,7 @@ void DVisDrawer::SetList(std::list<DWinding*> *pointList)
 
 void DVisDrawer::ClearPoints()
 {
-  list<DWinding *>::const_iterator deadPoint=m_list->begin();
+  std::list<DWinding *>::const_iterator deadPoint=m_list->begin();
        for(; deadPoint!=m_list->end(); deadPoint++)
                delete *deadPoint;
        m_list->clear();
index d09c36f..83a80cb 100644 (file)
@@ -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 <list>
+#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<DWinding*>* m_list;
+       std::list<DWinding*>* m_list;
        int refCount;
 public:
        void ClearPoints();
-       void SetList(list<DWinding*>* 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<DWinding*>* 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_)
index d3c7afd..2068f3f 100644 (file)
@@ -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 <list>
 
 #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;
 }
index 6d58e06..52846aa 100644 (file)
@@ -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  
index 2b2354c..b5d8859 100644 (file)
@@ -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): 
index e7e58a6..b8897f3 100644 (file)
@@ -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 <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "time.h"
-
-#define NAME_MAX 255
-
-#if defined (__linux__) || defined (__APPLE__)
-
-#include <GL/glx.h>
-
-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 <string.h>
-#include "qertypes.h"
-#include <stdio.h>
-
-#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
index 08cd00d..b0940e0 100644 (file)
@@ -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;
-}
index c22c76d..74f9189 100644 (file)
@@ -5,4 +5,4 @@ LIBRARY      "bobToolz"
 
 EXPORTS
     ; Explicit exports can go here
-       Synapse_EnumerateInterfaces @1
+       Radiant_RegisterModules @1
index 27c2e6d..287c5ff 100644 (file)
@@ -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<unsigned char*>(&l), reinterpret_cast<unsigned char*>(&l) + sizeof(int));
+#endif
        return l;
 }
 
 float  LittleFloat (float l)
 {
+#if defined(__BIG_ENDIAN__)
+  std::reverse(reinterpret_cast<unsigned char*>(&l), reinterpret_cast<unsigned char*>(&l) + sizeof(float));
+#endif
        return l;
-}*/
+}
 
 /*
 =============
index 9414566..3cea233 100644 (file)
@@ -1,3 +1,6 @@
+
+#include "mathlib.h"
+
 #define        LUMP_ENTITIES           0
 #define        LUMP_SHADERS            1
 #define        LUMP_PLANES                     2
index 01edc0e..5048eef 100644 (file)
@@ -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 <string.h>
+#include <math.h>
+
+#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;
                }
index 57177ef..0058ea7 100644 (file)
@@ -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 <list>
 
 #include "../lists.h"
 #include "../misc.h"
index 5838db6..bcafdae 100644 (file)
@@ -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
index deb3ff8..d492d74 100644 (file)
@@ -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 <list>
 #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 <vector>
 #include <list>
 #include <map>
@@ -60,8 +57,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include "scenelib.h"
 
 // for autocaulk
-list<Str> exclusionList;               // whole brush exclusion
-list<Str> exclusionList_Face;  // single face exclusion
+std::list<Str> exclusionList;          // whole brush exclusion
+std::list<Str> 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<DPatch> patchList = patch.Split( true, true );
-       for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) {
+       std::list<DPatch> patchList = patch.Split( true, true );
+       for(std::list<DPatch>::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<DWinding*> *pointList = BuildTrace(filename, origin);
+       std::list<DWinding*> *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]);
        }
 
 
index c83d2ae..ca218f5 100644 (file)
@@ -39,8 +39,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include "DShape.h"
 
 // for autocaulk
-list<Str> exclusionList;               // whole brush exclusion
-list<Str> exclusionList_Face;  // single face exclusion
+std::list<Str> exclusionList;          // whole brush exclusion
+std::list<Str> exclusionList_Face;     // single face exclusion
 
 BOOL el1Loaded;
 BOOL el2Loaded;
index b8b1dd4..faacbb7 100644 (file)
@@ -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 <glib/glist.h>
 
-#include "lists.h"
 #include "misc.h"
 
-bool LoadExclusionList(char* filename, list<Str>* exclusionList)
+bool LoadExclusionList(char* filename, std::list<Str>* exclusionList)
 {
        FILE* eFile = fopen(filename, "r");
        if(eFile)
@@ -52,7 +50,7 @@ bool LoadExclusionList(char* filename, list<Str>* exclusionList)
                return TRUE;
        }
 
-       Sys_ERROR("Failed To Load Exclusion List: %s\n", filename);
+       globalErrorStream() << "Failed To Load Exclusion List: " << filename << "\n";
        return FALSE;
 }
 
index 6f9774f..c4ccf77 100644 (file)
@@ -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<Str>* exclusionList);
+#include <list>
+#include "str.h"
+typedef struct _GList          GList;
+
+bool LoadExclusionList(char* filename, std::list<Str>* exclusionList);
 bool LoadGList(char* filename, GList** loadlist);
index f793bcc..e56c4d8 100644 (file)
@@ -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 <list>
 #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 <vector>
 #include <list>
@@ -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<Str>* exclusionList)
+void BuildMiniPrt(std::list<Str>* 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<Str>* exclusionList)
        StartBSP();
 }
 
+template<typename Functor>
+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<typename Functor>
+const Functor& Scene_forEachEntity(const Functor& functor)
+{
+  GlobalSceneGraph().traverse(EntityWalker<Functor>(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;
+}
+
index f1431c4..e011b67 100644 (file)
@@ -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 <list>
+#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<Str>* exclusionList);
+void BuildMiniPrt(std::list<Str>* 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
index 84bdc01..3c5e373 100644 (file)
@@ -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 <list>
 
 #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;
index d48969e..c277d42 100644 (file)
@@ -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---
index ae3602d..e5b890b 100644 (file)
@@ -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 <list>
 
 typedef struct {
        int             portalclusters;
@@ -122,7 +122,7 @@ int bsp_countclusters_mask(byte *bitvector, byte *maskvector, int length)
        return(c);
 }
 
-void AddCluster(list<DWinding*> *pointlist, dleaf_t    *cl, bool* repeatlist, vec3_t clr)
+void AddCluster(std::list<DWinding*> *pointlist, dleaf_t       *cl, bool* repeatlist, vec3_t clr)
 {
        DWinding*       w;
        
@@ -164,11 +164,11 @@ void AddCluster(list<DWinding*> *pointlist, dleaf_t       *cl, bool* repeatlist, vec3_
 CreateTrace
 =============
 */
-list<DWinding*> *CreateTrace( dleaf_t *leaf, int c, vis_header *header, byte *visdata, byte *seen )
+std::list<DWinding*> *CreateTrace( dleaf_t *leaf, int c, vis_header *header, byte *visdata, byte *seen )
 {
        byte            *vis;
        int                     i, j, clusterNum;
-       list<DWinding*> *pointlist = new list<DWinding*>;
+       std::list<DWinding*> *pointlist = new std::list<DWinding*>;
        bool*   repeatlist = new bool[numDrawSurfaces];
        dleaf_t         *cl;
 
@@ -214,7 +214,7 @@ TraceCluster
 setup for CreateTrace
 =============
 */
-list<DWinding*> *TraceCluster (int leafnum)
+std::list<DWinding*> *TraceCluster (int leafnum)
 {
        byte                    seen[(MAX_MAP_LEAFS/8) + 1];
        vis_header              *vheader;
@@ -232,14 +232,14 @@ list<DWinding*> *TraceCluster (int leafnum)
        return CreateTrace(leaf, leaf->cluster, vheader, visdata, seen);
 }
 
-list<DWinding *>* BuildTrace(char* filename, vec3_t v_origin)
+std::list<DWinding *>* BuildTrace(char* filename, vec3_t v_origin)
 {
        if(!LoadBSPFile(filename))
                return NULL;
        
        int leafnum = bsp_leafnumfororigin(v_origin);
 
-       list<DWinding*> *pointlist = TraceCluster(leafnum);
+       std::list<DWinding*> *pointlist = TraceCluster(leafnum);
 
        FreeBSPData();
 
index 0a4b601..3476d86 100644 (file)
@@ -1 +1,7 @@
-list<DWinding*> *BuildTrace(char* filename, vec3_t v_origin);
+
+#include <list>
+#include "mathlib.h"
+
+class DWinding;
+
+std::list<DWinding*> *BuildTrace(char* filename, vec3_t v_origin);
index ef5001c..6e9c95d 100644 (file)
@@ -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()
index 6b3178c..e5dea30 100644 (file)
@@ -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)
   {
index 318ee55..187ebcc 100644 (file)
@@ -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<const _QERFaceData&> 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"
index 0c6f4dd..c98fdc0 100644 (file)
@@ -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:
index 34a5638..f96e049 100644 (file)
@@ -29,11 +29,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 class EntityClass;
 
+typedef Callback1<const char*> 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
index b44c7fb..339c82f 100644 (file)
@@ -24,9 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <cstddef>
 #include "generic/constant.h"
+#include "generic/callbackfwd.h"
 
-template<typename FirstArgument>
-class Callback1;
 typedef Callback1<const char*> ArchiveNameCallback;
 typedef Callback1<const char*> FileNameCallback;
 
index 77cdf0e..2846670 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
-
 class Renderable;
 typedef Callback1<const Renderable&> RenderableCallback;
 
index 48e99aa..18e50f7 100644 (file)
@@ -24,14 +24,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <cstddef>
 #include "generic/constant.h"
+#include "signal/signalfwd.h"
 
 template<typename value_type>
 class Stack;
 template<typename Contained>
 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()
 {
index 2a86a31..ec32561 100644 (file)
@@ -24,15 +24,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <cstddef>
 #include "generic/constant.h"
+#include "generic/callbackfwd.h"
+#include "signal/signalfwd.h"
 
 class Renderer;
 class View;
 
-class Callback;
-
-template<typename FirstArgument>
-class Callback1;
-
 class Selectable
 {
 public:
@@ -61,6 +58,7 @@ class Matrix4;
 typedef Vector4 Quaternion;
 
 typedef Callback1<const Selectable&> SelectionChangeCallback;
+typedef SignalHandler1<const Selectable&> 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;
 
index 49ddf46..928dd1d 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
 typedef Callback1<const ShaderLayer&> ShaderLayerCallback;
 
 
@@ -133,7 +132,6 @@ public:
   virtual qtexture_t* lightFalloffImage() const = 0;
 };
 
-class Callback;
 typedef struct _GSList GSList;
 typedef Callback1<const char*> ShaderNameCallback;
 
index 6719a49..4dcbad8 100644 (file)
@@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <cstddef>
 #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:
index 2df91a7..e53d79c 100644 (file)
@@ -25,8 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <limits>
 
 #include "iscenegraph.h"
-
-class Callback;
+#include "generic/callbackfwd.h"
 
 const std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits<std::size_t>::max();
 
index 1104800..c01b5f3 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
 typedef Callback1<SkinRemap> SkinRemapCallback;
 class ModuleObserver;
 
index 9147554..8e1357a 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
 typedef Callback1<const char*> NameCallback;
 
 class Nameable
index df8fda4..30367bf 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
 typedef Callback1<const char*> NameCallback;
 typedef Callback1<const NameCallback&> NameCallbackCallback;
 
index f1891ae..f5ebae1 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
 typedef Callback1<const char*> StringImportCallback;
 typedef Callback1<const StringImportCallback&> StringExportCallback;
 
index 1a45919..3e352e5 100644 (file)
@@ -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<const WindowVector&, ButtonIdentifier, ModifierFlags> MouseEventHandler;
+typedef SignalFwd<MouseEventHandler>::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;
index f6da5cc..774f4e0 100644 (file)
@@ -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<typename FirstArgument>
-class Callback1;
 class Plane3;
 typedef Callback1<const Plane3&> PlaneCallback;
 
index c4b1ade..88d672c 100644 (file)
@@ -109,11 +109,11 @@ namespace HashTableDetail
      : m_hash(hash), m_value(key, value)
     {
     }
-    BucketNode* getNext()
+    BucketNode* getNext() const
     {
       return static_cast<BucketNode*>(next);
     }
-    BucketNode* getPrev()
+    BucketNode* getPrev() const
     {
       return static_cast<BucketNode*>(prev);
     }
index 2a9cbe7..642283f 100644 (file)
@@ -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")
index b9e9300..4a34f0a 100644 (file)
@@ -304,13 +304,11 @@ public:
 };
 
 
-typedef Callback1<const char*> 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<KeyObserver> 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<StringPool, KeyContext>::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");
   }
 
index 6152b9d..2344830 100644 (file)
@@ -107,3 +107,179 @@ namespace ExampleReferenceCaller
 }
 
 #endif
+
+namespace
+{
+  class A1
+  {
+  };
+  class A2
+  {
+  };
+  class A3
+  {
+  };
+  class A4
+  {
+  };
+
+  class Test
+  {
+  public:
+    void test0()
+    {
+    }
+    typedef Member<Test, void, &Test::test0> Test0;
+    typedef MemberCaller<Test, &Test::test0> Test0Caller;
+    void test0const() const
+    {
+    }
+    typedef ConstMember<Test, void, &Test::test0const> Test0Const;
+    typedef ConstMemberCaller<Test, &Test::test0const> Test0ConstCaller;
+    void test1(A1)
+    {
+    }
+    typedef Member1<Test, A1, void, &Test::test1> Test1;
+    typedef MemberCaller1<Test, A1, &Test::test1> Test1Caller;
+    void test1const(A1) const
+    {
+    }
+    typedef ConstMember1<Test, A1, void, &Test::test1const> Test1Const;
+    typedef ConstMemberCaller1<Test, A1, &Test::test1const> Test1ConstCaller;
+    void test2(A1, A2)
+    {
+    }
+    typedef Member2<Test, A1, A2, void, &Test::test2> Test2;
+    void test2const(A1, A2) const
+    {
+    }
+    typedef ConstMember2<Test, A1, A2, void, &Test::test2const> Test2Const;
+    void test3(A1, A2, A3)
+    {
+    }
+    typedef Member3<Test, A1, A2, A3, void, &Test::test3> Test3;
+    void test3const(A1, A2, A3) const
+    {
+    }
+    typedef ConstMember3<Test, A1, A2, A3, void, &Test::test3const> Test3Const;
+  };
+
+  void test0free()
+  {
+  }
+  typedef FreeCaller<&test0free> Test0FreeCaller;
+  void test1free(A1)
+  {
+  }
+  typedef FreeCaller1<A1, &test1free> Test1FreeCaller;
+  void test2free(A1, A2)
+  {
+  }
+  typedef Function2<A1, A2, void, &test2free> Test2Free;
+  void test3free(A1, A2, A3)
+  {
+  }
+  typedef Function3<A1, A2, A3, void, &test3free> Test3Free;
+
+
+  void test0(Test& test)
+  {
+  }
+  typedef ReferenceCaller<Test, &test0> Test0Caller;
+
+  void test0const(const Test& test)
+  {
+  }
+  typedef ConstReferenceCaller<Test, &test0const> Test0ConstCaller;
+
+  void test0p(Test* test)
+  {
+  }
+  typedef PointerCaller<Test, &test0p> Test0PCaller;
+
+  void test0constp(const Test* test)
+  {
+  }
+  typedef ConstPointerCaller<Test, &test0constp> Test0ConstPCaller;
+
+  void test1(Test& test, A1)
+  {
+  }
+  typedef ReferenceCaller1<Test, A1, &test1> Test1Caller;
+
+  void test1const(const Test& test, A1)
+  {
+  }
+  typedef ConstReferenceCaller1<Test, A1, &test1const> Test1ConstCaller;
+
+  void test1p(Test* test, A1)
+  {
+  }
+  typedef PointerCaller1<Test, A1, &test1p> Test1PCaller;
+
+  void test1constp(const Test* test, A1)
+  {
+  }
+  typedef ConstPointerCaller1<Test, A1, &test1constp> Test1ConstPCaller;
+
+  void test2(Test& test, A1, A2)
+  {
+  }
+  typedef Function3<Test&, A1, A2, void, &test2> Test2;
+
+  void test3(Test& test, A1, A2, A3)
+  {
+  }
+  typedef Function4<Test&, A1, A2, A3, void, &test3> 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<A1> 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<A1, A2> 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<A1, A2, A3> 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;
+    }
+  }
+}
index e5a8c8b..68fc066 100644 (file)
@@ -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 <cstddef>
+#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<typename Type>
+inline void* convertToOpaque(Type* t)
 {
-  typedef void (*Thunk)(void*);
-  void* m_environment;
-  Thunk m_thunk;
+  return t;
+}
+template<typename Type>
+inline void* convertToOpaque(const Type* t)
+{
+  return const_cast<Type*>(t);
+}
+template<typename Type>
+inline void* convertToOpaque(Type& t)
+{
+  return &t;
+}
+template<typename Type>
+inline void* convertToOpaque(const Type& t)
+{
+  return const_cast<Type*>(&t);
+}
+
+
+template<typename Type>
+class ConvertFromOpaque
+{
+};
+
+template<typename Type>
+class ConvertFromOpaque<Type&>
+{
+public:
+  static Type& apply(void* p)
+  {
+    return *static_cast<Type*>(p);
+  }
+};
 
-  static void nullThunk(void*)
+template<typename Type>
+class ConvertFromOpaque<const Type&>
+{
+public:
+  static const Type& apply(void* p)
   {
+    return *static_cast<Type*>(p);
   }
+};
 
+
+template<typename Type>
+class ConvertFromOpaque<Type*>
+{
+public:
+  static Type* apply(void* p)
+  {
+    return static_cast<Type*>(p);
+  }
+};
+
+template<typename Type>
+class ConvertFromOpaque<const Type*>
+{
+public:
+  static const Type* apply(void* p)
+  {
+    return static_cast<Type*>(p);
+  }
+};
+
+template<typename Caller>
+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<FirstBound>::apply(environment));
+  }
+  void* getEnvironment() const
+  {
+    return convertToOpaque(firstBound);
+  }
+};
+
+template<typename Caller>
+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<FirstBound>::apply(environment), a1);
+  }
+  void* getEnvironment() const
+  {
+    return convertToOpaque(firstBound);
+  }
+};
+
+template<typename Caller>
+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<FirstBound>::apply(environment), a1, a2);
+  }
+  void* getEnvironment() const
+  {
+    return convertToOpaque(firstBound);
+  }
+};
+
+template<typename Caller>
+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<FirstBound>::apply(environment), a1, a2, a3);
+  }
+  void* getEnvironment() const
+  {
+    return convertToOpaque(firstBound);
+  }
+};
+
+template<typename typename Thunk_>
+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<typename typename Thunk>
+inline bool operator==(const CallbackBase<Thunk>& self, const CallbackBase<Thunk>& other)
 {
   return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk();
 }
-inline bool operator<(const Callback& self, const Callback& other)
+template<typename typename Thunk>
+inline bool operator!=(const CallbackBase<Thunk>& self, const CallbackBase<Thunk>& other)
+{
+  return !(self == other);
+}
+template<typename typename Thunk>
+inline bool operator<(const CallbackBase<Thunk>& self, const CallbackBase<Thunk>& 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<typename FirstArgument>
-class Callback1
+/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller.
+template<typename Result>
+class Callback0 : public CallbackBase<Result (*)(void*)>
 {
-  typedef void (*Thunk)(void*, FirstArgument);
-  void* m_environment;
-  Thunk m_thunk;
-
-  static void nullThunk(void*, FirstArgument)
+  typedef CallbackBase<Result (*)(void*)> 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<typename Caller>
+  Callback0(const BindFirstOpaque<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque<Caller>::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<typename FirstArgument>
-inline bool operator==(const Callback1<FirstArgument>& self, const Callback1<FirstArgument>& other)
+template<typename Caller>
+inline Callback0<typename Caller::result_type> makeCallback0(const Caller& caller, typename Caller::first_argument_type callee)
 {
-  return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk();
+  return Callback0<typename Caller::result_type>(BindFirstOpaque<Caller>(callee));
 }
-template<typename FirstArgument>
-inline bool operator<(const Callback1<FirstArgument>& self, const Callback1<FirstArgument>& other)
+template<typename Caller>
+inline Callback0<typename Caller::result_type> makeStatelessCallback0(const Caller& caller)
 {
-  return self.getEnvironment() < other.getEnvironment() || 
-        (!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk()); 
+  return makeCallback0(Caller0To1<Caller>(), 0);
 }
 
-template<typename Functor>
-class FunctorInvoke
+typedef Callback0<void> 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<typename FirstArgument, typename Result>
+class Callback1 : public CallbackBase<Result (*)(void*, FirstArgument)>
 {
+  typedef CallbackBase<Result (*)(void*, FirstArgument)> 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<typename Caller>
+  Callback1(const BindFirstOpaque1<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque1<Caller>::thunk)
+  {
+  }
+  Callback1(void* environment, Thunk function) : Base(environment, function)
+  {
+  }
+  result_type operator()(FirstArgument firstArgument) const
+  {
+    return getThunk()(getEnvironment(), firstArgument);
   }
 };
 
-typedef FunctorInvoke<Callback> CallbackInvoke;
+template<typename Caller>
+inline Callback1<typename Caller::second_argument_type, typename Caller::result_type> makeCallback1(const Caller& caller, typename Caller::first_argument_type callee)
+{
+  return Callback1<typename Caller::second_argument_type, typename Caller::result_type>(BindFirstOpaque1<Caller>(callee));
+}
+template<typename Caller>
+inline Callback1<typename Caller::second_argument_type, typename Caller::result_type> makeStatelessCallback1(const Caller& caller)
+{
+  return makeCallback1(Caller1To2<Caller>(), 0);
+}
 
 
-template<typename Functor, typename FirstArgument>
-class Functor1Invoke
+/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and two other arguments. 
+///
+template<typename FirstArgument, typename SecondArgument, typename Result>
+class Callback2 : public CallbackBase<Result (*)(void*, FirstArgument, SecondArgument)>
 {
-  FirstArgument m_firstArgument;
+  typedef CallbackBase<Result (*)(void*, FirstArgument, SecondArgument)> 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<typename Caller>
+  Callback2(const BindFirstOpaque2<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque2<Caller>::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<typename Caller>
+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<Caller>(callee));
+}
+template<typename Caller>
+inline Callback2<
+  typename Caller::first_argument_type,
+  typename Caller::second_argument_type,
+  typename Caller::result_type
+> makeStatelessCallback2(const Caller& caller)
+{
+  return makeCallback2(Caller2To3<Caller>(), 0);
+}
 
-typedef Callback1<bool> BoolImportCallback;
-typedef Callback1<const BoolImportCallback&> BoolExportCallback;
 
-typedef Callback1<int> IntImportCallback;
-typedef Callback1<const IntImportCallback&> IntExportCallback;
+/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and three other arguments. 
+///
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument, typename Result>
+class Callback3 : public CallbackBase<Result (*)(void*, FirstArgument, SecondArgument, ThirdArgument)>
+{
+  typedef CallbackBase<Result (*)(void*, FirstArgument, SecondArgument, ThirdArgument)> Base;
+  static Result nullThunk(void*, FirstArgument, SecondArgument, ThirdArgument)
+  {
+  }
 
-typedef Callback1<float> FloatImportCallback;
-typedef Callback1<const FloatImportCallback&> FloatExportCallback;
+public:
+  typedef FirstArgument first_argument_type;
+  typedef SecondArgument second_argument_type;
+  typedef ThirdArgument third_argument_type;
+  typedef Result result_type;
 
-typedef Callback1<const char*> StringImportCallback;
-typedef Callback1<const StringImportCallback&> StringExportCallback;
+  Callback3() : Base(0, nullThunk)
+  {
+  }
+  template<typename Caller>
+  Callback3(const BindFirstOpaque3<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque3<Caller>::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<std::size_t> SizeImportCallback;
-typedef Callback1<const SizeImportCallback&> SizeExportCallback;
+template<typename Caller>
+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<Caller>(callee));
+}
+template<typename Caller>
+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<Caller>(), 0);
+}
 
 
 /// \brief Forms a Callback from a non-const Environment reference and a non-const Environment member-function.
@@ -170,24 +461,11 @@ typedef Callback1<const SizeImportCallback&> SizeExportCallback;
 /// \skipline MemberCaller example
 /// \until end example
 template<typename Environment, void (Environment::*member)()>
-class MemberCaller
+class MemberCaller : public BindFirstOpaque< Member<Environment, void, member> >
 {
-  Environment& m_environment;
 public:
-  MemberCaller(Environment& environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
+  MemberCaller(Environment& environment) : BindFirstOpaque< Member<Environment, void, member> >(environment)
   {
-    return &m_environment;
-  }
-  static void thunk(void* environment)
-  {
-    ((*reinterpret_cast<Environment*>(environment)).*member)();
-  }
-  operator Callback() const
-  {
-    return Callback(getEnvironment(), thunk);
   }
 };
 
@@ -197,71 +475,32 @@ public:
 /// \skipline MemberCaller example
 /// \until end example
 template<typename Environment, void (Environment::*member)() const>
-class ConstMemberCaller
+class ConstMemberCaller : public BindFirstOpaque< ConstMember<Environment, void, member> >
 {
-  const Environment& m_environment;
 public:
-  ConstMemberCaller(const Environment& environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
+  ConstMemberCaller(const Environment& environment) : BindFirstOpaque< ConstMember<Environment, void, member> >(environment)
   {
-    return const_cast<Environment*>(&m_environment);
-  }
-  static void thunk(void* environment)
-  {
-    ((*reinterpret_cast<const Environment*>(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<typename Environment, typename FirstArgument, void (Environment::*member)(FirstArgument)>
-class MemberCaller1
+class MemberCaller1 : public BindFirstOpaque1< Member1<Environment, FirstArgument, void, member> >
 {
-  Environment& m_environment;
 public:
-  MemberCaller1(Environment& environment) : m_environment(environment)
+  MemberCaller1(Environment& environment) : BindFirstOpaque1< Member1<Environment, FirstArgument, void, member> >(environment)
   {
   }
-  void* getEnvironment() const
-  {
-    return &m_environment;
-  }
-  static void thunk(void* environment, FirstArgument firstArgument)
-  {
-    ((*reinterpret_cast<Environment*>(environment)).*member)(firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(getEnvironment(), thunk);
-  }
 };
 
 /// \brief Forms a Callback from a const Environment reference and a const Environment member-function which takes one argument.
 template<typename Environment, typename FirstArgument, void (Environment::*member)(FirstArgument) const>
-class ConstMemberCaller1
+class ConstMemberCaller1 : public BindFirstOpaque1< ConstMember1<Environment, FirstArgument, void, member> >
 {
-  const Environment& m_environment;
 public:
-  ConstMemberCaller1(const Environment& environment) : m_environment(environment)
+  ConstMemberCaller1(const Environment& environment) : BindFirstOpaque1< ConstMember1<Environment, FirstArgument, void, member> >(environment)
   {
   }
-  void* getEnvironment() const
-  {
-    return const_cast<Environment*>(&m_environment);
-  }
-  static void thunk(void* environment, FirstArgument firstArgument)
-  {
-    ((*reinterpret_cast<Environment*>(environment)).*member)(firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(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<typename Environment, void (*func)(Environment&)> 
-class ReferenceCaller
+class ReferenceCaller : public BindFirstOpaque< Function1<Environment&, void, func> >
 {
-  Environment& m_environment;
 public:
-  ReferenceCaller(Environment& environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
+  ReferenceCaller(Environment& environment) : BindFirstOpaque< Function1<Environment&, void, func> >(environment)
   {
-    return &m_environment;
-  }
-  static void thunk(void* environment)
-  {
-    (func)(*reinterpret_cast<Environment*>(environment));
-  }
-  operator Callback() const
-  {
-    return Callback(getEnvironment(), thunk);
   }
 };
 
@@ -297,201 +523,91 @@ public:
 /// \skipline ReferenceCaller example
 /// \until end example
 template<typename Environment, void (*func)(const Environment&)> 
-class ConstReferenceCaller
+class ConstReferenceCaller : public BindFirstOpaque< Function1<const Environment&, void, func> >
 {
-  const Environment& m_environment;
 public:
-  ConstReferenceCaller(const Environment& environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
-  {
-    return const_cast<Environment*>(&m_environment);
-  }
-  static void thunk(void* environment)
+  ConstReferenceCaller(const Environment& environment) : BindFirstOpaque< Function1<const Environment&, void, func> >(environment)
   {
-    (func)(*reinterpret_cast<const Environment*>(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<typename Environment, typename FirstArgument, void (*func)(Environment&, FirstArgument)> 
-class ReferenceCaller1
+class ReferenceCaller1 : public BindFirstOpaque1< Function2<Environment&, FirstArgument, void, func> >
 {
-  Environment& m_environment;
 public:
-  ReferenceCaller1(Environment& environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
+  ReferenceCaller1(Environment& environment) : BindFirstOpaque1< Function2<Environment&, FirstArgument, void, func> >(environment)
   {
-    return &m_environment;
-  }
-  static void thunk(void* environment, FirstArgument firstArgument)
-  {
-    (func)(*reinterpret_cast<Environment*>(environment), firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(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<typename Environment, typename FirstArgument, void (*func)(const Environment&, FirstArgument)> 
-class ConstReferenceCaller1
+class ConstReferenceCaller1 : public BindFirstOpaque1< Function2<const Environment&, FirstArgument, void, func> >
 {
-  const Environment& m_environment;
 public:
-  ConstReferenceCaller1(const Environment& environment) : m_environment(environment)
+  ConstReferenceCaller1(const Environment& environment) : BindFirstOpaque1< Function2<const Environment&, FirstArgument, void, func> >(environment)
   {
   }
-  void* getEnvironment() const
-  {
-    return const_cast<Environment*>(&m_environment);
-  }
-  static void thunk(void* environment, FirstArgument firstArgument)
-  {
-    (func)(*reinterpret_cast<const Environment*>(environment), firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(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<typename Environment, void (*func)(Environment*)> 
-class PointerCaller
+class PointerCaller : public BindFirstOpaque< Function1<Environment*, void, func> >
 {
-  Environment* m_environment;
 public:
-  PointerCaller(Environment* environment) : m_environment(environment)
+  PointerCaller(Environment* environment) : BindFirstOpaque< Function1<Environment*, void, func> >(environment)
   {
   }
-  void* getEnvironment() const
-  {
-    return m_environment;
-  }
-  static void thunk(void* environment)
-  {
-    (func)(reinterpret_cast<Environment*>(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<typename Environment, void (*func)(const Environment*)> 
-class ConstPointerCaller
+class ConstPointerCaller : public BindFirstOpaque< Function1<const Environment*, void, func> >
 {
-  const Environment* m_environment;
 public:
-  ConstPointerCaller(const Environment* environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
-  {
-    return const_cast<Environment*>(m_environment);
-  }
-  static void thunk(void* environment)
-  {
-    (func)(reinterpret_cast<const Environment*>(environment));
-  }
-  operator Callback() const
+  ConstPointerCaller(const Environment* environment) : BindFirstOpaque< Function1<const Environment*, void, func> >(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<typename Environment, typename FirstArgument, void (*func)(Environment*, FirstArgument)> 
-class PointerCaller1
+class PointerCaller1 : public BindFirstOpaque1< Function2<Environment*, FirstArgument, void, func> >
 {
-  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*, FirstArgument, void, func> >(environment)
   {
-    (func)(reinterpret_cast<Environment*>(environment), firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(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<typename Environment, typename FirstArgument, void (*func)(const Environment*, FirstArgument)> 
-class ConstPointerCaller1
+class ConstPointerCaller1 : public BindFirstOpaque1< Function2<const Environment*, FirstArgument, void, func> >
 {
-  const Environment* m_environment;
 public:
-  ConstPointerCaller1(const Environment* environment) : m_environment(environment)
-  {
-  }
-  void* getEnvironment() const
+  ConstPointerCaller1(const Environment* environment) : BindFirstOpaque1< Function2<const Environment*, FirstArgument, void, func> >(environment)
   {
-    return const_cast<Environment*>(m_environment);
-  }
-  static void thunk(void* environment, FirstArgument firstArgument)
-  {
-    (func)(reinterpret_cast<const Environment*>(environment), firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(getEnvironment(), thunk);
   }
 };
 
-
 /// \brief Forms a Callback from a free function which takes no arguments.
 template<void (*func)()> 
-class FreeCaller
+class FreeCaller : public BindFirstOpaque< Caller0To1< Function0<void, func> > >
 {
 public:
-  void* getEnvironment() const
-  {
-    return 0;
-  }
-  static void thunk(void*)
-  {
-    (func)();
-  }
-  operator Callback() const
+  FreeCaller() : BindFirstOpaque< Caller0To1< Function0<void, func> > >(0)
   {
-    return Callback(getEnvironment(), thunk);
   }
 };
 
 /// \brief Forms a Callback from a free function which takes a single argument.
 template<typename FirstArgument, void (*func)(FirstArgument)> 
-class FreeCaller1
+class FreeCaller1 : public BindFirstOpaque1< Caller1To2< Function1<FirstArgument, void, func> > >
 {
 public:
-  void* getEnvironment() const
-  {
-    return 0;
-  }
-  static void thunk(void*, FirstArgument firstArgument)
+  FreeCaller1() : BindFirstOpaque1< Caller1To2< Function1<FirstArgument, void, func> > >(0)
   {
-    (func)(firstArgument);
-  }
-  operator Callback1<FirstArgument>() const
-  {
-    return Callback1<FirstArgument>(getEnvironment(), thunk);
   }
 };
 
@@ -534,4 +650,21 @@ inline Callback1<typename Functor::first_argument_type> makeCallback1(const Func
   return Callback1<FirstArgument>(ConstMemberCaller1<Functor, FirstArgument, &Functor::operator()>(functor));
 }
 
+
+typedef Callback1<bool> BoolImportCallback;
+typedef Callback1<const BoolImportCallback&> BoolExportCallback;
+
+typedef Callback1<int> IntImportCallback;
+typedef Callback1<const IntImportCallback&> IntExportCallback;
+
+typedef Callback1<float> FloatImportCallback;
+typedef Callback1<const FloatImportCallback&> FloatExportCallback;
+
+typedef Callback1<const char*> StringImportCallback;
+typedef Callback1<const StringImportCallback&> StringExportCallback;
+
+typedef Callback1<std::size_t> SizeImportCallback;
+typedef Callback1<const SizeImportCallback&> SizeExportCallback;
+
+
 #endif
diff --git a/libs/generic/callbackfwd.cpp b/libs/generic/callbackfwd.cpp
new file mode 100644 (file)
index 0000000..a2faa66
--- /dev/null
@@ -0,0 +1,3 @@
+
+#include "callbackfwd.h"
+
diff --git a/libs/generic/callbackfwd.h b/libs/generic/callbackfwd.h
new file mode 100644 (file)
index 0000000..f89f909
--- /dev/null
@@ -0,0 +1,18 @@
+
+#if !defined(INCLUDED_CALLBACKFWD_H)
+#define INCLUDED_CALLBACKFWD_H
+
+template<typename Return>
+class Callback0;
+typedef Callback0<void> Callback;
+
+template<typename FirstArgument, typename Result = void>
+class Callback1;
+
+template<typename FirstArgument, typename SecondArgument, typename Result = void>
+class Callback2;
+
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument, typename Result = void>
+class Callback3;
+
+#endif
diff --git a/libs/generic/functional.cpp b/libs/generic/functional.cpp
new file mode 100644 (file)
index 0000000..4717c8e
--- /dev/null
@@ -0,0 +1,3 @@
+
+#include "functional.h"
+
diff --git a/libs/generic/functional.h b/libs/generic/functional.h
new file mode 100644 (file)
index 0000000..ca1d863
--- /dev/null
@@ -0,0 +1,319 @@
+
+#if !defined(INCLUDED_FUNCTIONAL_H)
+#define INCLUDED_FUNCTIONAL_H
+
+template<typename Object, typename R, R (Object::*member)()>
+class Member
+{
+public:
+  typedef Object& first_argument_type;
+  typedef R result_type;
+  static result_type call(first_argument_type object)
+  {
+    return (object.*member)();
+  }
+};
+
+template<typename Object, typename R, R (Object::*member)() const>
+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<typename Object, typename A1, typename R, R (Object::*member)(A1)>
+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<typename Object, typename A1, typename R, R (Object::*member)(A1) const>
+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<typename Object, typename A2, typename A3, typename R, R (Object::*member)(A2, A3)>
+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<typename Object, typename A2, typename A3, typename R, R (Object::*member)(A2, A3) const>
+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<typename Object, typename A2, typename A3, typename A4, typename R, R (Object::*member)(A2, A3, A4)>
+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<typename Object, typename A2, typename A3, typename A4, typename R, R (Object::*member)(A2, A3, A4) const>
+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<typename R, R (*func)()> 
+class Function0
+{
+public:
+  typedef R result_type;
+  static result_type call()
+  {
+    return (func)();
+  }
+};
+
+template<typename A1, typename R, R (*func)(A1)> 
+class Function1
+{
+public:
+  typedef A1 first_argument_type;
+  typedef R result_type;
+  static result_type call(first_argument_type a1)
+  {
+    return (func)(a1);
+  }
+};
+
+template<typename A1, typename A2, typename R, R (*func)(A1, A2)> 
+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<typename A1, typename A2, typename A3, typename R, R (*func)(A1, A2, A3)> 
+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<typename A1, typename A2, typename A3, typename A4, typename R, R (*func)(A1, A2, A3, A4)> 
+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<typename Caller, typename FirstArgument = void*> 
+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<typename Caller, typename FirstArgument = void*> 
+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<typename Caller, typename FirstArgument = void*> 
+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<typename Caller, typename FirstArgument = void*> 
+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<typename Functor>
+class FunctorInvoke
+{
+public:
+  typedef typename Functor::result_type result_type;
+  inline result_type operator()(Functor functor)
+  {
+    return functor();
+  }
+};
+
+template<typename Functor>
+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<typename Functor>
+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<typename Functor>
+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<typename Type, typename Other, typename True, typename False>
+class TypeEqual
+{
+  template<typename Matched>
+  class Match
+  {
+  public:
+    typedef False type;
+  };
+  template<>
+  class Match<Other>
+  {
+  public:
+    typedef True type;
+  };
+public:
+  typedef typename Match<Type>::type type;
+};
+
+
+#endif
index 3da5b07..69ddac4 100644 (file)
@@ -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);
index 3372c02..a394d82 100644 (file)
@@ -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;
index d0c83a8..9bf847d 100644 (file)
@@ -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;
index c418b70..00bd4e0 100644 (file)
                                RelativePath=".\generic\callback.h">
                        </File>
                        <File
+                               RelativePath=".\generic\callbackfwd.cpp">
+                       </File>
+                       <File
+                               RelativePath=".\generic\callbackfwd.h">
+                       </File>
+                       <File
                                RelativePath=".\generic\constant.cpp">
                        </File>
                        <File
                                RelativePath=".\generic\enumeration.h">
                        </File>
                        <File
+                               RelativePath=".\generic\functional.cpp">
+                       </File>
+                       <File
+                               RelativePath=".\generic\functional.h">
+                       </File>
+                       <File
                                RelativePath=".\generic\object.cpp">
                        </File>
                        <File
                                RelativePath=".\debugging\debugging.h">
                        </File>
                </Filter>
+               <Filter
+                       Name="signal"
+                       Filter="">
+                       <File
+                               RelativePath=".\signal\isignal.cpp">
+                       </File>
+                       <File
+                               RelativePath=".\signal\isignal.h">
+                       </File>
+                       <File
+                               RelativePath=".\signal\signal.cpp">
+                       </File>
+                       <File
+                               RelativePath=".\signal\signal.h">
+                       </File>
+                       <File
+                               RelativePath=".\signal\signalfwd.cpp">
+                       </File>
+                       <File
+                               RelativePath=".\signal\signalfwd.h">
+                       </File>
+               </Filter>
                <File
                        RelativePath=".\archivelib.cpp">
                </File>
index ef0d225..a9d2a80 100644 (file)
@@ -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<Vector3*>(array);
+}
+inline const Vector3& vector3_from_array(const float* array)
+{
+  return *reinterpret_cast<const Vector3*>(array);
+}
+
 template<typename Element>
 inline Element* vector3_to_array(BasicVector3<Element>& self)
 {
diff --git a/libs/signal/isignal.cpp b/libs/signal/isignal.cpp
new file mode 100644 (file)
index 0000000..ee7e4cb
--- /dev/null
@@ -0,0 +1,3 @@
+
+#include "isignal.h"
+
diff --git a/libs/signal/isignal.h b/libs/signal/isignal.h
new file mode 100644 (file)
index 0000000..e6cb215
--- /dev/null
@@ -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<typename Caller> 
+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<typename Caller> 
+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<typename Caller> 
+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<typename Caller> 
+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<SignalHandlerResult>
+{
+public:
+  template<typename Caller>
+  SignalHandler(const BindFirstOpaque<Caller>& caller)
+    : Callback0<SignalHandlerResult>(BindFirstOpaque<typename TypeEqual<
+      typename Caller::result_type,
+      SignalHandlerResult,
+      Caller,
+      SignalHandlerCaller1<Caller>
+    >::type>(caller.getBound()))
+  {
+  }
+};
+
+template<typename Caller>
+inline SignalHandler makeSignalHandler(const BindFirstOpaque<Caller>& caller)
+{
+  return SignalHandler(caller);
+}
+template<typename Caller>
+inline SignalHandler makeSignalHandler(const Caller& caller, typename Caller::first_argument_type callee)
+{
+  return SignalHandler(BindFirstOpaque<Caller>(callee));
+}
+
+
+template<typename FirstArgument>
+class SignalHandler1 : public Callback1<FirstArgument, SignalHandlerResult>
+{
+public:
+  template<typename Caller>
+  SignalHandler1(const BindFirstOpaque1<Caller>& caller)
+    : Callback1<FirstArgument, SignalHandlerResult>(BindFirstOpaque1<typename TypeEqual<
+      typename Caller::result_type,
+      SignalHandlerResult,
+      Caller,
+      SignalHandlerCaller2<Caller>
+    >::type>(caller.getBound()))
+  {
+  }
+};
+
+template<typename Caller>
+inline SignalHandler1<typename Caller::second_argument_type> makeSignalHandler1(const BindFirstOpaque1<Caller>& caller)
+{
+  return SignalHandler1<typename Caller::second_argument_type>(caller);
+}
+template<typename Caller>
+inline SignalHandler1<typename Caller::second_argument_type> makeSignalHandler1(const Caller& caller, typename Caller::first_argument_type callee)
+{
+  return SignalHandler1<typename Caller::second_argument_type>(BindFirstOpaque1<Caller>(callee));
+}
+
+
+template<typename FirstArgument, typename SecondArgument>
+class SignalHandler2 : public Callback2<FirstArgument, SecondArgument, SignalHandlerResult>
+{
+public:
+  template<typename Caller>
+  SignalHandler2(const BindFirstOpaque2<Caller>& caller)
+    : Callback2<FirstArgument, SecondArgument, SignalHandlerResult>(BindFirstOpaque2<typename TypeEqual<
+      typename Caller::result_type,
+      SignalHandlerResult,
+      Caller,
+      SignalHandlerCaller3<Caller>
+    >::type>(caller.getBound()))
+  {
+  }
+};
+
+template<typename Caller>
+inline SignalHandler2<
+  typename Caller::second_argument_type,
+  typename Caller::third_argument_type
+> makeSignalHandler2(const BindFirstOpaque2<Caller>& caller)
+{
+  return SignalHandler2<
+    typename Caller::second_argument_type,
+    typename Caller::third_argument_type
+  >(caller);
+}
+template<typename Caller>
+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<Caller>(callee));
+}
+
+
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument>
+class SignalHandler3 : public Callback3<FirstArgument, SecondArgument, ThirdArgument, SignalHandlerResult>
+{
+public:
+  template<typename Caller>