reformat code! now the code is only ugly on the *inside*
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 6 Jan 2018 02:56:39 +0000 (13:56 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 6 Jan 2018 02:56:40 +0000 (13:56 +1100)
440 files changed:
contrib/bkgrnd2d/bkgrnd2d.cpp
contrib/bkgrnd2d/bkgrnd2d.h
contrib/bkgrnd2d/dialog.cpp
contrib/bkgrnd2d/dialog.h
contrib/bkgrnd2d/plugin.cpp
contrib/bkgrnd2d/plugin.h
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/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/ScriptParser.h
contrib/bobtoolz/bobToolz-GTK.cpp
contrib/bobtoolz/bobToolz.h
contrib/bobtoolz/bobToolz.rc
contrib/bobtoolz/bsploader.cpp
contrib/bobtoolz/bsploader.h
contrib/bobtoolz/cportals.cpp
contrib/bobtoolz/ctfToolz-GTK.cpp
contrib/bobtoolz/dialogs/AboutDialog.cpp
contrib/bobtoolz/dialogs/AboutDialog.h
contrib/bobtoolz/dialogs/AutoCaulkDialog.cpp
contrib/bobtoolz/dialogs/AutoCaulkDialog.h
contrib/bobtoolz/dialogs/AutoCaulkStartDialog.cpp
contrib/bobtoolz/dialogs/AutoCaulkStartDialog.h
contrib/bobtoolz/dialogs/BrushCheckDialog.h
contrib/bobtoolz/dialogs/DoorDialog.cpp
contrib/bobtoolz/dialogs/DoorDialog.h
contrib/bobtoolz/dialogs/IntersectDialog.cpp
contrib/bobtoolz/dialogs/IntersectDialog.h
contrib/bobtoolz/dialogs/IntersectInfoDialog.cpp
contrib/bobtoolz/dialogs/IntersectInfoDialog.h
contrib/bobtoolz/dialogs/PolygonDialog.cpp
contrib/bobtoolz/dialogs/PolygonDialog.h
contrib/bobtoolz/dialogs/StairDialog.cpp
contrib/bobtoolz/dialogs/StairDialog.h
contrib/bobtoolz/dialogs/TextureResetDialog.cpp
contrib/bobtoolz/dialogs/TextureResetDialog.h
contrib/bobtoolz/dialogs/brushcheckdialog.cpp
contrib/bobtoolz/dialogs/dialogs-gtk.cpp
contrib/bobtoolz/dialogs/dialogs-gtk.h
contrib/bobtoolz/dialogs/pathplotterdialog.cpp
contrib/bobtoolz/dialogs/pathplotterdialog.h
contrib/bobtoolz/funchandlers-GTK.cpp
contrib/bobtoolz/funchandlers-ctf-GTK.cpp
contrib/bobtoolz/funchandlers.cpp
contrib/bobtoolz/funchandlers.h
contrib/bobtoolz/lists.cpp
contrib/bobtoolz/lists.h
contrib/bobtoolz/misc.cpp
contrib/bobtoolz/misc.h
contrib/bobtoolz/res/plugin.rc2
contrib/bobtoolz/shapes.cpp
contrib/bobtoolz/shapes.h
contrib/bobtoolz/visfind.cpp
contrib/bobtoolz/visfind.h
contrib/brushexport/callbacks.cpp
contrib/brushexport/callbacks.h
contrib/brushexport/export.cpp
contrib/brushexport/export.h
contrib/brushexport/interface.cpp
contrib/brushexport/plugin.cpp
contrib/brushexport/support.cpp
contrib/brushexport/support.h
contrib/camera/camera.cpp
contrib/camera/camera.h
contrib/camera/dialogs.cpp
contrib/camera/dialogs.h
contrib/camera/dialogs_common.cpp
contrib/camera/funchandlers.cpp
contrib/camera/funchandlers.h
contrib/camera/listener.cpp
contrib/camera/listener.h
contrib/camera/misc.cpp
contrib/camera/misc.h
contrib/camera/renderer.cpp
contrib/camera/renderer.h
contrib/gtkgensurf/bitmap.cpp
contrib/gtkgensurf/dec.cpp
contrib/gtkgensurf/face.cpp
contrib/gtkgensurf/font.cpp
contrib/gtkgensurf/gendlgs.cpp
contrib/gtkgensurf/genmap.cpp
contrib/gtkgensurf/gensurf.cpp
contrib/gtkgensurf/gensurf.h
contrib/gtkgensurf/heretic.cpp
contrib/gtkgensurf/plugin.cpp
contrib/gtkgensurf/triangle.c
contrib/gtkgensurf/triangle.h
contrib/gtkgensurf/view.cpp
contrib/hydratoolz/plugin.cpp
contrib/hydratoolz/plugin.h
contrib/prtview/AboutDialog.cpp
contrib/prtview/ConfigDialog.cpp
contrib/prtview/LoadPortalFileDialog.cpp
contrib/prtview/portals.cpp
contrib/prtview/portals.h
contrib/prtview/prtview.cpp
contrib/prtview/prtview.h
contrib/prtview/res/PrtView.rc2
contrib/shaderplug/shaderplug.cpp
contrib/sunplug/sunplug.cpp
contrib/sunplug/sunplug.h
contrib/ufoaiplug/ufoai.cpp
contrib/ufoaiplug/ufoai_filters.cpp
contrib/ufoaiplug/ufoai_filters.h
contrib/ufoaiplug/ufoai_gtk.cpp
contrib/ufoaiplug/ufoai_gtk.h
contrib/ufoaiplug/ufoai_level.cpp
contrib/ufoaiplug/ufoai_level.h
libs/gtkutil/accelerator.cpp
libs/gtkutil/accelerator.h
libs/gtkutil/button.cpp
libs/gtkutil/button.h
libs/gtkutil/clipboard.cpp
libs/gtkutil/clipboard.h
libs/gtkutil/closure.h
libs/gtkutil/cursor.cpp
libs/gtkutil/cursor.h
libs/gtkutil/dialog.cpp
libs/gtkutil/dialog.h
libs/gtkutil/filechooser.cpp
libs/gtkutil/filechooser.h
libs/gtkutil/frame.cpp
libs/gtkutil/frame.h
libs/gtkutil/glfont.cpp
libs/gtkutil/glfont.h
libs/gtkutil/glwidget.h
libs/gtkutil/idledraw.h
libs/gtkutil/image.cpp
libs/gtkutil/image.h
libs/gtkutil/menu.cpp
libs/gtkutil/menu.h
libs/gtkutil/messagebox.cpp
libs/gtkutil/messagebox.h
libs/gtkutil/nonmodal.h
libs/gtkutil/paned.cpp
libs/gtkutil/paned.h
libs/gtkutil/pointer.h
libs/gtkutil/toolbar.cpp
libs/gtkutil/toolbar.h
libs/gtkutil/window.cpp
libs/gtkutil/xorrectangle.h
plugins/archivepak/archive.cpp
plugins/archivepak/archive.h
plugins/archivepak/pak.h
plugins/archivepak/plugin.cpp
plugins/archivewad/archive.cpp
plugins/archivewad/archive.h
plugins/archivewad/plugin.cpp
plugins/archivewad/wad.h
plugins/archivezip/archive.cpp
plugins/archivezip/archive.h
plugins/archivezip/pkzip.h
plugins/archivezip/plugin.cpp
plugins/archivezip/zlibstream.h
plugins/entity/CMakeLists.txt
plugins/entity/angle.h
plugins/entity/angles.h
plugins/entity/colour.h
plugins/entity/curve.h
plugins/entity/doom3group.cpp
plugins/entity/doom3group.h
plugins/entity/eclassmodel.cpp
plugins/entity/eclassmodel.h
plugins/entity/entity.cpp
plugins/entity/entity.h
plugins/entity/filters.cpp
plugins/entity/filters.h
plugins/entity/generic.cpp
plugins/entity/generic.h
plugins/entity/group.cpp
plugins/entity/group.h
plugins/entity/keyobservers.h
plugins/entity/light.cpp
plugins/entity/light.h
plugins/entity/miscmodel.cpp
plugins/entity/miscmodel.h
plugins/entity/model.h
plugins/entity/modelskinkey.h
plugins/entity/namedentity.h
plugins/entity/namekeys.h
plugins/entity/origin.h
plugins/entity/plugin.cpp
plugins/entity/rotation.h
plugins/entity/scale.h
plugins/entity/skincache.cpp
plugins/entity/skincache.h
plugins/entity/targetable.cpp
plugins/entity/targetable.h
plugins/image/bmp.cpp
plugins/image/bmp.h
plugins/image/dds.cpp
plugins/image/dds.h
plugins/image/image.cpp
plugins/image/jpeg.cpp
plugins/image/jpeg.h
plugins/image/ktx.cpp
plugins/image/ktx.h
plugins/image/pcx.cpp
plugins/image/pcx.h
plugins/image/tga.cpp
plugins/image/tga.h
plugins/imagehl/hlw.cpp
plugins/imagehl/hlw.h
plugins/imagehl/imagehl.cpp
plugins/imagehl/mip.cpp
plugins/imagehl/mip.h
plugins/imagehl/sprite.cpp
plugins/imagehl/sprite.h
plugins/imagepng/plugin.cpp
plugins/imageq2/imageq2.cpp
plugins/imageq2/wal.cpp
plugins/imageq2/wal.h
plugins/imageq2/wal32.cpp
plugins/imageq2/wal32.h
plugins/iqmmodel/iqm.cpp
plugins/iqmmodel/iqm.h
plugins/iqmmodel/plugin.cpp
plugins/mapq3/CMakeLists.txt
plugins/mapq3/parse.cpp
plugins/mapq3/parse.h
plugins/mapq3/plugin.cpp
plugins/mapq3/write.cpp
plugins/mapq3/write.h
plugins/mapxml/plugin.cpp
plugins/mapxml/xmlparse.cpp
plugins/mapxml/xmlparse.h
plugins/mapxml/xmlwrite.cpp
plugins/mapxml/xmlwrite.h
plugins/md3model/ident.h
plugins/md3model/md2.cpp
plugins/md3model/md2.h
plugins/md3model/md3.cpp
plugins/md3model/md3.h
plugins/md3model/md3normals.h
plugins/md3model/md5.cpp
plugins/md3model/md5.h
plugins/md3model/mdc.cpp
plugins/md3model/mdc.h
plugins/md3model/mdl.cpp
plugins/md3model/mdl.h
plugins/md3model/mdlformat.h
plugins/md3model/mdlimage.cpp
plugins/md3model/mdlimage.h
plugins/md3model/mdlnormals.h
plugins/md3model/model.h
plugins/md3model/plugin.cpp
plugins/model/model.cpp
plugins/model/model.h
plugins/model/plugin.cpp
plugins/sample/sample.cpp
plugins/shaders/plugin.cpp
plugins/shaders/shaders.cpp
plugins/shaders/shaders.h
plugins/spritemodel/plugin.cpp
plugins/spritemodel/plugin.h
plugins/spritemodel/spritemodel.cpp
plugins/spritemodel/spritemodel.h
plugins/textool/2DView.cpp
plugins/textool/2DView.h
plugins/textool/ControlPointsManager.cpp
plugins/textool/ControlPointsManager.h
plugins/textool/Doc/TexTool.html
plugins/textool/StdAfx.h
plugins/textool/TexTool.cpp
plugins/textool/TexTool.rc
plugins/vfspk3/archive.cpp
plugins/vfspk3/archive.h
plugins/vfspk3/vfs.cpp
plugins/vfspk3/vfs.h
plugins/vfspk3/vfspk3.cpp
radiant/CMakeLists.txt
radiant/autosave.cpp
radiant/autosave.h
radiant/brush.cpp
radiant/brush.h
radiant/brush_primit.cpp
radiant/brush_primit.h
radiant/brushmanip.cpp
radiant/brushmanip.h
radiant/brushmodule.cpp
radiant/brushmodule.h
radiant/brushnode.h
radiant/brushtokens.h
radiant/brushxml.h
radiant/build.cpp
radiant/build.h
radiant/camwindow.cpp
radiant/camwindow.h
radiant/commands.cpp
radiant/commands.h
radiant/console.cpp
radiant/console.h
radiant/csg.cpp
radiant/csg.h
radiant/dialog.cpp
radiant/dialog.h
radiant/eclass.cpp
radiant/eclass_def.cpp
radiant/eclass_doom3.cpp
radiant/eclass_fgd.cpp
radiant/eclass_xml.cpp
radiant/entity.cpp
radiant/entity.h
radiant/entityinspector.cpp
radiant/entityinspector.h
radiant/entitylist.cpp
radiant/entitylist.h
radiant/environment.cpp
radiant/environment.h
radiant/error.cpp
radiant/error.h
radiant/feedback.cpp
radiant/feedback.h
radiant/filetypes.cpp
radiant/filetypes.h
radiant/filters.cpp
radiant/filters.h
radiant/findtexturedialog.cpp
radiant/findtexturedialog.h
radiant/glwidget.cpp
radiant/grid.cpp
radiant/grid.h
radiant/groupdialog.cpp
radiant/groupdialog.h
radiant/gtkdlgs.cpp
radiant/gtkdlgs.h
radiant/gtkmisc.cpp
radiant/gtkmisc.h
radiant/help.cpp
radiant/help.h
radiant/image.cpp
radiant/image.h
radiant/main.cpp
radiant/mainframe.cpp
radiant/mainframe.h
radiant/map.cpp
radiant/map.h
radiant/mru.cpp
radiant/mru.h
radiant/multimon.cpp
radiant/multimon.h
radiant/nullmodel.cpp
radiant/nullmodel.h
radiant/parse.cpp
radiant/patch.cpp
radiant/patch.h
radiant/patchdialog.cpp
radiant/patchdialog.h
radiant/patchmanip.cpp
radiant/patchmanip.h
radiant/patchmodule.cpp
radiant/plugin.cpp
radiant/plugin.h
radiant/pluginapi.cpp
radiant/pluginapi.h
radiant/pluginmanager.cpp
radiant/pluginmanager.h
radiant/pluginmenu.cpp
radiant/pluginmenu.h
radiant/plugintoolbar.cpp
radiant/plugintoolbar.h
radiant/points.cpp
radiant/points.h
radiant/preferencedictionary.h
radiant/preferences.cpp
radiant/preferences.h
radiant/qe3.cpp
radiant/qe3.h
radiant/qgl.cpp
radiant/qgl.h
radiant/radiant.rc
radiant/referencecache.cpp
radiant/referencecache.h
radiant/renderer.h
radiant/renderstate.cpp
radiant/renderstate.h
radiant/scenegraph.cpp
radiant/select.cpp
radiant/select.h
radiant/selection.cpp
radiant/selection.h
radiant/server.cpp
radiant/server.h
radiant/shaders.cpp
radiant/shaders.h
radiant/sockets.cpp
radiant/sockets.h
radiant/stacktrace.cpp
radiant/stacktrace.h
radiant/surfacedialog.cpp
radiant/surfacedialog.h
radiant/texmanip.cpp
radiant/texmanip.h
radiant/textures.cpp
radiant/textures.h
radiant/texwindow.cpp
radiant/texwindow.h
radiant/timer.cpp
radiant/timer.h
radiant/treemodel.cpp
radiant/treemodel.h
radiant/undo.cpp
radiant/url.cpp
radiant/url.h
radiant/view.cpp
radiant/view.h
radiant/watchbsp.cpp
radiant/watchbsp.h
radiant/winding.cpp
radiant/winding.h
radiant/windowobservers.cpp
radiant/windowobservers.h
radiant/xmlstuff.h
radiant/xywindow.cpp
radiant/xywindow.h

index b115952..7ed6315 100644 (file)
 
 CBackgroundRender render;
 
-CBackgroundImage backgroundXY( XY ),backgroundXZ( XZ ),backgroundYZ( YZ );
+CBackgroundImage backgroundXY(XY), backgroundXZ(XZ), backgroundYZ(YZ);
 
-CBackgroundRender::CBackgroundRender(){
-       refCount = 1;
+CBackgroundRender::CBackgroundRender()
+{
+    refCount = 1;
 }
 
-CBackgroundRender::~CBackgroundRender(){
+CBackgroundRender::~CBackgroundRender()
+{
 }
 
-void CBackgroundRender::Register(){
-       g_QglTable.m_pfnHookGL2DWindow( this );
+void CBackgroundRender::Register()
+{
+    g_QglTable.m_pfnHookGL2DWindow(this);
 }
 
-void CBackgroundRender::Draw2D( VIEWTYPE vt ){
-       switch ( vt )
-       {
-       case XY:
-               backgroundXY.Render();
-               break;
-       case XZ:
-               backgroundXZ.Render();
-               break;
-       case YZ:
-               backgroundYZ.Render();
-               break;
-       }
+void CBackgroundRender::Draw2D(VIEWTYPE vt)
+{
+    switch (vt) {
+        case XY:
+            backgroundXY.Render();
+            break;
+        case XZ:
+            backgroundXZ.Render();
+            break;
+        case YZ:
+            backgroundYZ.Render();
+            break;
+    }
 }
 
 
-CBackgroundImage::CBackgroundImage( VIEWTYPE vt ){
-       m_tex = NULL;
-       m_alpha = 0.5;
-
-       // TODO, sensible defaults ? Or not show until we have extents ?
-       m_xmin = m_ymin = 0.0f;
-       m_xmax = m_ymax = 0.0f;
-
-       m_bActive = false;
-
-       m_vt = vt;
-
-       switch ( m_vt )
-       {
-       case XY:
-               m_ix = 0;
-               m_iy = 1;
-               break;
-       case XZ:
-               m_ix = 0;
-               m_iy = 2;
-               break;
-       case YZ:
-               m_ix = 1;
-               m_iy = 2;
-               break;
-       }
+CBackgroundImage::CBackgroundImage(VIEWTYPE vt)
+{
+    m_tex = NULL;
+    m_alpha = 0.5;
+
+    // TODO, sensible defaults ? Or not show until we have extents ?
+    m_xmin = m_ymin = 0.0f;
+    m_xmax = m_ymax = 0.0f;
+
+    m_bActive = false;
+
+    m_vt = vt;
+
+    switch (m_vt) {
+        case XY:
+            m_ix = 0;
+            m_iy = 1;
+            break;
+        case XZ:
+            m_ix = 0;
+            m_iy = 2;
+            break;
+        case YZ:
+            m_ix = 1;
+            m_iy = 2;
+            break;
+    }
 }
 
 /*
@@ -96,214 +99,214 @@ CBackgroundImage::CBackgroundImage( VIEWTYPE vt ){
    }
  */
 
-void CBackgroundImage::Cleanup(){
-       if ( m_tex ) {
-               g_QglTable.m_pfn_qglDeleteTextures( 1,&m_tex->texture_number );
-               g_free( m_tex );
-               m_tex = NULL;
-       }
+void CBackgroundImage::Cleanup()
+{
+    if (m_tex) {
+        g_QglTable.m_pfn_qglDeleteTextures(1, &m_tex->texture_number);
+        g_free(m_tex);
+        m_tex = NULL;
+    }
 }
 
-void CBackgroundImage::Render(){
-       if ( !m_bActive || !Valid() ) {
-               return;
-       }
-       g_QglTable.m_pfn_qglPushAttrib( GL_ALL_ATTRIB_BITS );
+void CBackgroundImage::Render()
+{
+    if (!m_bActive || !Valid()) {
+        return;
+    }
+    g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
 
-       g_QglTable.m_pfn_qglEnable( GL_TEXTURE_2D );
-       g_QglTable.m_pfn_qglEnable( GL_BLEND );
-       g_QglTable.m_pfn_qglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
-       g_QglTable.m_pfn_qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-       g_QglTable.m_pfn_qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
-       g_QglTable.m_pfn_qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
+    g_QglTable.m_pfn_qglEnable(GL_TEXTURE_2D);
+    g_QglTable.m_pfn_qglEnable(GL_BLEND);
+    g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    g_QglTable.m_pfn_qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+    g_QglTable.m_pfn_qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+    g_QglTable.m_pfn_qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 
-       g_QglTable.m_pfn_qglPolygonMode( GL_FRONT,GL_FILL );
-       // TODO, just so we can tell if we end up going the wrong way
-       // g_QglTable.m_pfn_qglPolygonMode(GL_BACK,GL_LINE);
-       // TODO any other state we should not assume ?
+    g_QglTable.m_pfn_qglPolygonMode(GL_FRONT, GL_FILL);
+    // TODO, just so we can tell if we end up going the wrong way
+    // g_QglTable.m_pfn_qglPolygonMode(GL_BACK,GL_LINE);
+    // TODO any other state we should not assume ?
 
-       g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
-       g_QglTable.m_pfn_qglBegin( GL_QUADS );
+    g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, m_tex->texture_number);
+    g_QglTable.m_pfn_qglBegin(GL_QUADS);
 
-       g_QglTable.m_pfn_qglColor4f( 1.0,1.0,1.0,m_alpha );
-       g_QglTable.m_pfn_qglTexCoord2f( 0.0,1.0 );
-       g_QglTable.m_pfn_qglVertex2f( m_xmin,m_ymin );
+    g_QglTable.m_pfn_qglColor4f(1.0, 1.0, 1.0, m_alpha);
+    g_QglTable.m_pfn_qglTexCoord2f(0.0, 1.0);
+    g_QglTable.m_pfn_qglVertex2f(m_xmin, m_ymin);
 
-       g_QglTable.m_pfn_qglTexCoord2f( 1.0,1.0 );
-       g_QglTable.m_pfn_qglVertex2f( m_xmax,m_ymin );
+    g_QglTable.m_pfn_qglTexCoord2f(1.0, 1.0);
+    g_QglTable.m_pfn_qglVertex2f(m_xmax, m_ymin);
 
-       g_QglTable.m_pfn_qglTexCoord2f( 1.0,0.0 );
-       g_QglTable.m_pfn_qglVertex2f( m_xmax,m_ymax );
+    g_QglTable.m_pfn_qglTexCoord2f(1.0, 0.0);
+    g_QglTable.m_pfn_qglVertex2f(m_xmax, m_ymax);
 
-       g_QglTable.m_pfn_qglTexCoord2f( 0.0,0.0 );
-       g_QglTable.m_pfn_qglVertex2f( m_xmin,m_ymax );
+    g_QglTable.m_pfn_qglTexCoord2f(0.0, 0.0);
+    g_QglTable.m_pfn_qglVertex2f(m_xmin, m_ymax);
 
-       g_QglTable.m_pfn_qglEnd();
-       g_QglTable.m_pfn_qglBindTexture( GL_TEXTURE_2D, 0 );
+    g_QglTable.m_pfn_qglEnd();
+    g_QglTable.m_pfn_qglBindTexture(GL_TEXTURE_2D, 0);
 
-       g_QglTable.m_pfn_qglPopAttrib();
+    g_QglTable.m_pfn_qglPopAttrib();
 }
 
-bool CBackgroundImage::Load( const char *filename ){
-       qtexture_t *newtex;
+bool CBackgroundImage::Load(const char *filename)
+{
+    qtexture_t *newtex;
 
-       unsigned char *image = NULL; // gets allocated with what ? g_malloc
-       int width = 0, height = 0;
+    unsigned char *image = NULL; // gets allocated with what ? g_malloc
+    int width = 0, height = 0;
 
-       g_FuncTable.m_pfnLoadImage( filename,&image,&width,&height );
+    g_FuncTable.m_pfnLoadImage(filename, &image, &width, &height);
 
-       if ( !image ) {
-               Syn_Printf( MSG_WARN "load %s failed\n",filename );
-               return false;
-       }
+    if (!image) {
+        Syn_Printf(MSG_WARN "load %s failed\n", filename);
+        return false;
+    }
 
 // just in case we want to build for an old version
 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=900
 #ifdef BKGRND2D_JPG_WORKAROUND
-       if ( strlen( filename ) > 4 && !strcmp( ".jpg",filename + strlen( filename ) - 4 ) ) {
-               Syn_Printf( MSG_PREFIX ".jpg workaround, clearing alpha channel\n" );
-               int size = width * height * 4;
-               int i;
-               for ( i = 3; i < size; i += 4 ) {
-                       image[i] = 255;
-               }
-       }
+    if ( strlen( filename ) > 4 && !strcmp( ".jpg",filename + strlen( filename ) - 4 ) ) {
+        Syn_Printf( MSG_PREFIX ".jpg workaround, clearing alpha channel\n" );
+        int size = width * height * 4;
+        int i;
+        for ( i = 3; i < size; i += 4 ) {
+            image[i] = 255;
+        }
+    }
 #endif
 
-       //TODO bug for stored texture size
-       //TODO whose gl context are we in, anyway ?
-       newtex = g_FuncTable.m_pfnLoadTextureRGBA( image,width,height );
+    //TODO bug for stored texture size
+    //TODO whose gl context are we in, anyway ?
+    newtex = g_FuncTable.m_pfnLoadTextureRGBA(image, width, height);
 
-       g_free( image );
+    g_free(image);
 
-       if ( !newtex ) {
-               Syn_Printf( MSG_WARN "image to texture failed\n" );
-               return false;
-       }
+    if (!newtex) {
+        Syn_Printf(MSG_WARN "image to texture failed\n");
+        return false;
+    }
 
-       Cleanup();
-       m_tex = newtex;
+    Cleanup();
+    m_tex = newtex;
 
-       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
+    g_FuncTable.m_pfnSysUpdateWindows(W_XY);
 
-       return true;
+    return true;
 }
 
-bool CBackgroundImage::SetExtentsMM(){
-       entity_s *worldentity;
-       const char *val;
-       int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
-
-       worldentity = (entity_s *)g_FuncTable.m_pfnGetEntityHandle( 0 );
-       if ( !worldentity ) {
-               Syn_Printf( MSG_WARN "SetExtentsMM worldspawn not found\n" );
-               return false;
-       }
-       //TODO val is not NULL even if key does not exist
-       val = g_EntityTable.m_pfnValueForKey( worldentity,"mapcoordsmins" );
-       if ( !val || !val[0] ) {
-               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmins not found\n" );
-               return false;
-       }
+bool CBackgroundImage::SetExtentsMM()
+{
+    entity_s *worldentity;
+    const char *val;
+    int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
+
+    worldentity = (entity_s *) g_FuncTable.m_pfnGetEntityHandle(0);
+    if (!worldentity) {
+        Syn_Printf(MSG_WARN "SetExtentsMM worldspawn not found\n");
+        return false;
+    }
+    //TODO val is not NULL even if key does not exist
+    val = g_EntityTable.m_pfnValueForKey(worldentity, "mapcoordsmins");
+    if (!val || !val[0]) {
+        Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmins not found\n");
+        return false;
+    }
 // we could be more robust
 // note contortions due to splashs strange idea of min and max
-       if ( sscanf( val, "%d %d",&xmin,&ymax ) != 2 ) {
-               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmins malformed\n" );
-               return false;
-       }
-
-       val = g_EntityTable.m_pfnValueForKey( worldentity,"mapcoordsmaxs" );
-       if ( !val || !val[0] ) {
-               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmaxs not found\n" );
-               return false;
-       }
-       if ( sscanf( val, "%d %d",&xmax,&ymin ) != 2 ) {
-               Syn_Printf( MSG_WARN "SetExtentsMM mapcoordsmaxs malformed\n" );
-               return false;
-       }
-       //might do sanity check before we commit
-       m_xmin = (float)xmin;
-       m_ymin = (float)ymin;
-       m_xmax = (float)xmax;
-       m_ymax = (float)ymax;
-
-       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
-       return true;
+    if (sscanf(val, "%d %d", &xmin, &ymax) != 2) {
+        Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmins malformed\n");
+        return false;
+    }
+
+    val = g_EntityTable.m_pfnValueForKey(worldentity, "mapcoordsmaxs");
+    if (!val || !val[0]) {
+        Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmaxs not found\n");
+        return false;
+    }
+    if (sscanf(val, "%d %d", &xmax, &ymin) != 2) {
+        Syn_Printf(MSG_WARN "SetExtentsMM mapcoordsmaxs malformed\n");
+        return false;
+    }
+    //might do sanity check before we commit
+    m_xmin = (float) xmin;
+    m_ymin = (float) ymin;
+    m_xmax = (float) xmax;
+    m_ymax = (float) ymax;
+
+    g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+    return true;
 }
 
 // TODO, this should just be exported from core
 // ripped directly from radiant/select.cpp:Select_GetBounds
 //
-static bool get_selection_bounds( vec3_t mins, vec3_t maxs ){
-       brush_t *b;
-       int i;
-       brush_t *selected_brushes = g_DataTable.m_pfnSelectedBrushes();
-       //TODO should never happen
-       if ( !selected_brushes ) {
-               Sys_Printf( MSG_PREFIX "selected_brushes = NULL\n" );
-               return false;
-       }
-       // this should mean no selection
-       if ( selected_brushes == selected_brushes->next ) {
-               Sys_Printf( MSG_PREFIX "nothing selected\n" );
-
-               return false;
-       }
-
-       for ( i = 0 ; i < 3 ; i++ )
-       {
-               mins[i] = 99999;
-               maxs[i] = -99999;
-       }
-
-       for ( b = selected_brushes->next ; b != selected_brushes ; b = b->next )
-       {
-               if ( b->owner->eclass->fixedsize ) {
-                       for ( i = 0 ; i < 3 ; i++ )
-                       {
-                               if ( b->owner->origin[i] < mins[i] ) {
-                                       mins[i] = b->owner->origin[i];
-                               }
-                               if ( b->owner->origin[i] > maxs[i] ) {
-                                       maxs[i] = b->owner->origin[i];
-                               }
-                       }
-               }
-               else
-               {
-                       for ( i = 0 ; i < 3 ; i++ )
-                       {
-                               if ( b->mins[i] < mins[i] ) {
-                                       mins[i] = b->mins[i];
-                               }
-                               if ( b->maxs[i] > maxs[i] ) {
-                                       maxs[i] = b->maxs[i];
-                               }
-                       }
-               }
-       }
-       return true;
+static bool get_selection_bounds(vec3_t mins, vec3_t maxs)
+{
+    brush_t *b;
+    int i;
+    brush_t *selected_brushes = g_DataTable.m_pfnSelectedBrushes();
+    //TODO should never happen
+    if (!selected_brushes) {
+        Sys_Printf(MSG_PREFIX "selected_brushes = NULL\n");
+        return false;
+    }
+    // this should mean no selection
+    if (selected_brushes == selected_brushes->next) {
+        Sys_Printf(MSG_PREFIX "nothing selected\n");
+
+        return false;
+    }
+
+    for (i = 0; i < 3; i++) {
+        mins[i] = 99999;
+        maxs[i] = -99999;
+    }
+
+    for (b = selected_brushes->next; b != selected_brushes; b = b->next) {
+        if (b->owner->eclass->fixedsize) {
+            for (i = 0; i < 3; i++) {
+                if (b->owner->origin[i] < mins[i]) {
+                    mins[i] = b->owner->origin[i];
+                }
+                if (b->owner->origin[i] > maxs[i]) {
+                    maxs[i] = b->owner->origin[i];
+                }
+            }
+        } else {
+            for (i = 0; i < 3; i++) {
+                if (b->mins[i] < mins[i]) {
+                    mins[i] = b->mins[i];
+                }
+                if (b->maxs[i] > maxs[i]) {
+                    maxs[i] = b->maxs[i];
+                }
+            }
+        }
+    }
+    return true;
 }
 
-bool CBackgroundImage::SetExtentsSel(){
-       vec3_t mins,maxs;
+bool CBackgroundImage::SetExtentsSel()
+{
+    vec3_t mins, maxs;
 
-       if ( !get_selection_bounds( mins,maxs ) ) {
-               return false;
-       }
+    if (!get_selection_bounds(mins, maxs)) {
+        return false;
+    }
 
-       if ( ( (int)mins[m_ix] == (int)maxs[m_ix] ) ||
-                ( (int)mins[m_iy] == (int)maxs[m_iy] ) ) {
-               Syn_Printf( MSG_PREFIX "tiny selection\n" );
-               return false;
-       }
+    if (((int) mins[m_ix] == (int) maxs[m_ix]) ||
+        ((int) mins[m_iy] == (int) maxs[m_iy])) {
+        Syn_Printf(MSG_PREFIX "tiny selection\n");
+        return false;
+    }
 
-       m_xmin = mins[m_ix];
-       m_ymin = mins[m_iy];
-       m_xmax = maxs[m_ix];
-       m_ymax = maxs[m_iy];
+    m_xmin = mins[m_ix];
+    m_ymin = mins[m_iy];
+    m_xmax = maxs[m_ix];
+    m_ymax = maxs[m_iy];
 
-       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
+    g_FuncTable.m_pfnSysUpdateWindows(W_XY);
 
-       return true;
+    return true;
 }
index 41ee271..5c3bf3e 100644 (file)
 
 class CBackgroundImage {
 private:
-qtexture_t *m_tex;
-VIEWTYPE m_vt;
+    qtexture_t *m_tex;
+    VIEWTYPE m_vt;
 
 // which components of a vec3_t correspond to x and y in the image
-unsigned m_ix,m_iy;
+    unsigned m_ix, m_iy;
 
 public:
-CBackgroundImage( VIEWTYPE vt );
+    CBackgroundImage(VIEWTYPE vt);
 //  ~CBackgroundImage();
 
-float m_alpha;     // vertex alpha
-bool m_bActive;
+    float m_alpha;     // vertex alpha
+    bool m_bActive;
 
 // x and y axis are in relation to the screen, not world, making rendering
 // the same for each view type. Whoever sets them is responsible for
 // shuffling.
 // units are world units.
 // TODO should be private
-float m_xmin,m_ymin,m_xmax,m_ymax;
+    float m_xmin, m_ymin, m_xmax, m_ymax;
 
 // load file, create new tex, cleanup old tex, set new tex
-bool Load( const char *filename );
-void Cleanup();     // free texture, free tex, set make tex NULL
-bool SetExtentsMM();     // set extents by ET mapcoordsmaxs/mapcoordsmins
-bool SetExtentsSel();     // set extents by selection
-void Render();
-bool Valid() { return ( m_tex && ( m_xmin != m_xmax ) && ( m_ymin != m_ymax ) ); }
+    bool Load(const char *filename);
+
+    void Cleanup();     // free texture, free tex, set make tex NULL
+    bool SetExtentsMM();     // set extents by ET mapcoordsmaxs/mapcoordsmins
+    bool SetExtentsSel();     // set extents by selection
+    void Render();
+
+    bool Valid()
+    { return (m_tex && (m_xmin != m_xmax) && (m_ymin != m_ymax)); }
 };
 
 class CBackgroundRender : public IGL2DWindow {
 public:
 
-CBackgroundRender();
-virtual ~CBackgroundRender();
+    CBackgroundRender();
+
+    virtual ~CBackgroundRender();
 
 protected:
-int refCount;
+    int refCount;
 
 public:
 
 // IGL2DWindow IGL3DWindow interface
-void IncRef() { refCount++; }
-void DecRef() {
-       refCount--; if ( refCount <= 0 ) {
-               delete this;
-       }
-}
-void Draw2D( VIEWTYPE vt );
-void Register();
+    void IncRef()
+    { refCount++; }
+
+    void DecRef()
+    {
+        refCount--;
+        if (refCount <= 0) {
+            delete this;
+        }
+    }
+
+    void Draw2D(VIEWTYPE vt);
+
+    void Register();
 };
 
-extern CBackgroundImage backgroundXY,backgroundXZ,backgroundYZ;
+extern CBackgroundImage backgroundXY, backgroundXZ, backgroundYZ;
 extern CBackgroundRender render;
index 01a1b98..7bdf466 100644 (file)
@@ -38,250 +38,268 @@ static ui::Window pDialogWnd{ui::null};
 static GtkWidget *pNotebook;
 static GtkTooltips *pTooltips;
 
-class CBackgroundDialogPage
-{
+class CBackgroundDialogPage {
 private:
-GtkWidget *m_pWidget;
-GtkWidget *m_pTabLabel;
-ui::Label m_pFileLabel;
-GtkWidget *m_pPosLabel;
-VIEWTYPE m_vt;
-bool m_bValidFile;
+    GtkWidget *m_pWidget;
+    GtkWidget *m_pTabLabel;
+    ui::Label m_pFileLabel;
+    GtkWidget *m_pPosLabel;
+    VIEWTYPE m_vt;
+    bool m_bValidFile;
 
 public:
-CBackgroundImage *m_pImage;
-CBackgroundDialogPage( VIEWTYPE vt );
-void Append( GtkWidget *notebook );
-void Browse();
-void Reload();
-void SetPosLabel();
+    CBackgroundImage *m_pImage;
+
+    CBackgroundDialogPage(VIEWTYPE vt);
+
+    void Append(GtkWidget *notebook);
+
+    void Browse();
+
+    void Reload();
+
+    void SetPosLabel();
 //  ~BackgroundDialogPage();
 };
 
 
 // dialog page callbacks
-static void browse_callback( GtkWidget *widget, gpointer data ){
-       ( (CBackgroundDialogPage *)data )->Browse();
+static void browse_callback(GtkWidget *widget, gpointer data)
+{
+    ((CBackgroundDialogPage *) data)->Browse();
 }
 
-static void reload_callback( GtkWidget *widget, gpointer data ){
-       ( (CBackgroundDialogPage *)data )->Reload();
+static void reload_callback(GtkWidget *widget, gpointer data)
+{
+    ((CBackgroundDialogPage *) data)->Reload();
 }
 
-static void size_sel_callback( GtkWidget *widget, gpointer data ){
-       CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data;
-       if ( pPage->m_pImage->SetExtentsSel() ) {
-               pPage->SetPosLabel();
-       }
+static void size_sel_callback(GtkWidget *widget, gpointer data)
+{
+    CBackgroundDialogPage *pPage = (CBackgroundDialogPage *) data;
+    if (pPage->m_pImage->SetExtentsSel()) {
+        pPage->SetPosLabel();
+    }
 }
 
-static void size_mm_callback( GtkWidget *widget, gpointer data ){
-       CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data;
-       if ( pPage->m_pImage->SetExtentsMM() ) {
-               pPage->SetPosLabel();
-       }
+static void size_mm_callback(GtkWidget *widget, gpointer data)
+{
+    CBackgroundDialogPage *pPage = (CBackgroundDialogPage *) data;
+    if (pPage->m_pImage->SetExtentsMM()) {
+        pPage->SetPosLabel();
+    }
 }
 
-static void alpha_adjust_callback( GtkWidget *widget, gpointer data ){
-       CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data;
-       pPage->m_pImage->m_alpha = (float)gtk_range_get_value( GTK_RANGE( widget ) );
-       g_FuncTable.m_pfnSysUpdateWindows( W_XY );
+static void alpha_adjust_callback(GtkWidget *widget, gpointer data)
+{
+    CBackgroundDialogPage *pPage = (CBackgroundDialogPage *) data;
+    pPage->m_pImage->m_alpha = (float) gtk_range_get_value(GTK_RANGE(widget));
+    g_FuncTable.m_pfnSysUpdateWindows(W_XY);
 }
 
-void CBackgroundDialogPage::Reload(){
-       if ( m_bValidFile ) {
-               m_pImage->Load( gtk_label_get_text( GTK_LABEL( m_pFileLabel ) ) );
-       }
+void CBackgroundDialogPage::Reload()
+{
+    if (m_bValidFile) {
+        m_pImage->Load(gtk_label_get_text(GTK_LABEL(m_pFileLabel)));
+    }
 }
 
-void CBackgroundDialogPage::Browse(){
-       char browsedir[PATH_MAX];
-       const char *ct;
-       const char *newfile;
-       char *t;
+void CBackgroundDialogPage::Browse()
+{
+    char browsedir[PATH_MAX];
+    const char *ct;
+    const char *newfile;
+    char *t;
 
-       //TODO GetMapName saves the map. eeep!
-       //also with no map, returns unnamed.map, otherwise returns full path
+    //TODO GetMapName saves the map. eeep!
+    //also with no map, returns unnamed.map, otherwise returns full path
 //     Syn_Printf(MSG_PREFIX "GetMapName() %s\n",
 //                             g_FuncTable.m_pfnGetMapName());
 
-       ct = g_FuncTable.m_pfnReadProjectKey( "basepath" );
-       // TODO shouldn't need this stuff
-       if ( !ct || !strlen( ct ) ) {
-               Syn_Printf( MSG_PREFIX "basepath = NULL or empty\n" );
-               return;
-       }
-       Syn_Printf( MSG_PREFIX "basepath: %s\n",ct );
-       if ( strlen( ct ) >= PATH_MAX ) {
-               Syn_Printf( MSG_PREFIX "base game dir too long\n" );
-               return;
-       }
-
-       strcpy( browsedir,ct );
-       // make sure we have a trailing /
-       if ( browsedir[strlen( browsedir ) - 1] != '/' ) {
-               strcat( browsedir,"/" );
-       }
-
-       //if we dont have a file yet, don't try to use it for default dir
-       if ( m_bValidFile ) {
-               // filename should always be a nice clean unix style relative path
-               ct = gtk_label_get_text( GTK_LABEL( m_pFileLabel ) );
-               strcat( browsedir,ct );
-               Syn_Printf( MSG_PREFIX "full path: %s\n",browsedir );
-
-               // lop off the file part
-               t = browsedir + strlen( browsedir ) - 1;
-               while ( t != browsedir && *t != '/' )
-                       t--;
-               *t = 0;
-       }
-       Syn_Printf( MSG_PREFIX "browse directory %s\n",browsedir );
+    ct = g_FuncTable.m_pfnReadProjectKey("basepath");
+    // TODO shouldn't need this stuff
+    if (!ct || !strlen(ct)) {
+        Syn_Printf(MSG_PREFIX "basepath = NULL or empty\n");
+        return;
+    }
+    Syn_Printf(MSG_PREFIX "basepath: %s\n", ct);
+    if (strlen(ct) >= PATH_MAX) {
+        Syn_Printf(MSG_PREFIX "base game dir too long\n");
+        return;
+    }
+
+    strcpy(browsedir, ct);
+    // make sure we have a trailing /
+    if (browsedir[strlen(browsedir) - 1] != '/') {
+        strcat(browsedir, "/");
+    }
+
+    //if we dont have a file yet, don't try to use it for default dir
+    if (m_bValidFile) {
+        // filename should always be a nice clean unix style relative path
+        ct = gtk_label_get_text(GTK_LABEL(m_pFileLabel));
+        strcat(browsedir, ct);
+        Syn_Printf(MSG_PREFIX "full path: %s\n", browsedir);
+
+        // lop off the file part
+        t = browsedir + strlen(browsedir) - 1;
+        while (t != browsedir && *t != '/') {
+            t--;
+        }
+        *t = 0;
+    }
+    Syn_Printf(MSG_PREFIX "browse directory %s\n", browsedir);
 
 //does NOT need freeing contrary to include/qerplugin.h comments
 //TODO bug/patch for comments
 //TODO patern gets fucked up sometimes if empty
 //http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=915
-       newfile = g_FuncTable.m_pfnFileDialog( pDialogWnd,TRUE,
-                                                                                  "Load Background Image",browsedir,FILETYPE_KEY );
-       if ( !newfile ) {
-               Syn_Printf( MSG_PREFIX "newfile = NULL\n" );
-               return;
-       }
-       Syn_Printf( MSG_PREFIX "newfile: %s\n",newfile );
-       newfile = g_FileSystemTable.m_pfnExtractRelativePath( newfile );
-
-       if ( !newfile ) {
-               Syn_Printf( MSG_PREFIX "newfile = NULL\n" );
-               return;
-       }
-       Syn_Printf( MSG_PREFIX "newfile: %s\n",newfile );
-
-       if ( m_pImage->Load( newfile ) ) {
-               m_bValidFile = true;
-               m_pFileLabel.text(newfile);
-       }
+    newfile = g_FuncTable.m_pfnFileDialog(pDialogWnd, TRUE,
+                                          "Load Background Image", browsedir, FILETYPE_KEY);
+    if (!newfile) {
+        Syn_Printf(MSG_PREFIX "newfile = NULL\n");
+        return;
+    }
+    Syn_Printf(MSG_PREFIX "newfile: %s\n", newfile);
+    newfile = g_FileSystemTable.m_pfnExtractRelativePath(newfile);
+
+    if (!newfile) {
+        Syn_Printf(MSG_PREFIX "newfile = NULL\n");
+        return;
+    }
+    Syn_Printf(MSG_PREFIX "newfile: %s\n", newfile);
+
+    if (m_pImage->Load(newfile)) {
+        m_bValidFile = true;
+        m_pFileLabel.text(newfile);
+    }
 }
 
-void CBackgroundDialogPage::SetPosLabel(){
-       char s[64];
-       // TODO no snprintf ?
-       sprintf( s, "Size/Position (%d,%d) (%d,%d)",(int)( m_pImage->m_xmin ),
-                        (int)( m_pImage->m_ymin ),(int)( m_pImage->m_xmax ),(int)( m_pImage->m_ymax ) );
-       m_pPosLabel.text(s);
+void CBackgroundDialogPage::SetPosLabel()
+{
+    char s[64];
+    // TODO no snprintf ?
+    sprintf(s, "Size/Position (%d,%d) (%d,%d)", (int) (m_pImage->m_xmin),
+            (int) (m_pImage->m_ymin), (int) (m_pImage->m_xmax), (int) (m_pImage->m_ymax));
+    m_pPosLabel.text(s);
 }
 
-CBackgroundDialogPage::CBackgroundDialogPage( VIEWTYPE vt ){
-       GtkWidget *w;
-
-       m_vt = vt;
-
-       m_bValidFile = false;
-
-       switch ( m_vt )
-       {
-       case XY:
-               m_pTabLabel = ui::Label( "X/Y" );
-               m_pImage = &backgroundXY;
-               break;
-       case XZ:
-               m_pTabLabel = ui::Label( "X/Z" );
-               m_pImage = &backgroundXZ;
-               break;
-       case YZ:
-               m_pTabLabel = ui::Label( "Y/Z" );
-               m_pImage = &backgroundYZ;
-               break;
-       }
+CBackgroundDialogPage::CBackgroundDialogPage(VIEWTYPE vt)
+{
+    GtkWidget *w;
+
+    m_vt = vt;
+
+    m_bValidFile = false;
+
+    switch (m_vt) {
+        case XY:
+            m_pTabLabel = ui::Label("X/Y");
+            m_pImage = &backgroundXY;
+            break;
+        case XZ:
+            m_pTabLabel = ui::Label("X/Z");
+            m_pImage = &backgroundXZ;
+            break;
+        case YZ:
+            m_pTabLabel = ui::Label("Y/Z");
+            m_pImage = &backgroundYZ;
+            break;
+    }
 // A vbox to hold everything
-       m_pWidget = ui::VBox( FALSE,0 );
+    m_pWidget = ui::VBox(FALSE, 0);
 // Frame for file row
-       auto frame = ui::Frame( "File" );
-       m_pWidget.pack_start(frame, FALSE, FALSE, 2 );
+    auto frame = ui::Frame("File");
+    m_pWidget.pack_start(frame, FALSE, FALSE, 2);
 
 // hbox for first row
-       auto hbox = ui::HBox( FALSE,5 );
-       gtk_container_set_border_width( GTK_CONTAINER( hbox ),4 );
-       frame.add(hbox);
+    auto hbox = ui::HBox(FALSE, 5);
+    gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
+    frame.add(hbox);
 
 // label to display filename
-       m_pFileLabel  = ui::Label( NO_FILE_MSG );
-       gtk_label_set_selectable( GTK_LABEL( m_pFileLabel ),TRUE );
+    m_pFileLabel = ui::Label(NO_FILE_MSG);
+    gtk_label_set_selectable(GTK_LABEL(m_pFileLabel), TRUE);
 //TODO set min size ? done with spaces right now
-       hbox.pack_start(m_pFileLabel, TRUE, TRUE, 5 );
+    hbox.pack_start(m_pFileLabel, TRUE, TRUE, 5);
 
-       m_pFileLabel.show();
+    m_pFileLabel.show();
 
-       w = ui::Button( "Browse..." );
-       w.connect( "clicked", G_CALLBACK( browse_callback ), ( gpointer ) this );
-       hbox.pack_start(w, FALSE, FALSE, 5 );
-       gtk_tooltips_set_tip( pTooltips, w, "Select a file", NULL );
-       w.show();
+    w = ui::Button("Browse...");
+    w.connect("clicked", G_CALLBACK(browse_callback), (gpointer) this );
+    hbox.pack_start(w, FALSE, FALSE, 5);
+    gtk_tooltips_set_tip(pTooltips, w, "Select a file", NULL);
+    w.show();
 
-       w = ui::Button( "Reload" );
-       w.connect( "clicked", G_CALLBACK( reload_callback ), ( gpointer ) this );
-       // TODO disable until we have file
-       // gtk_widget_set_sensitive(w,FALSE);
-       gtk_tooltips_set_tip( pTooltips, w, "Reload current file", NULL );
-       hbox.pack_start(w, FALSE, FALSE, 5 );
-       w.show();
+    w = ui::Button("Reload");
+    w.connect("clicked", G_CALLBACK(reload_callback), (gpointer) this );
+    // TODO disable until we have file
+    // gtk_widget_set_sensitive(w,FALSE);
+    gtk_tooltips_set_tip(pTooltips, w, "Reload current file", NULL);
+    hbox.pack_start(w, FALSE, FALSE, 5);
+    w.show();
 
-       hbox.show();
-       frame.show();
+    hbox.show();
+    frame.show();
 
 // second row (rendering options)
-       frame = ui::Frame( "Rendering" );
-       m_pWidget.pack_start(frame, FALSE, FALSE, 2 );
-
-       hbox = ui::HBox( FALSE,5 );
-       gtk_container_set_border_width( GTK_CONTAINER( hbox ),4 );
-       frame.add(hbox);
-
-       w = ui::Label( "Vertex alpha:" );
-       hbox.pack_start(w, FALSE, FALSE, 5 );
-       w.show();
-
-       w = ui::HScale( 0.0, 1.0, 0.01 );
-       gtk_range_set_value( GTK_RANGE( w ),0.5 );
-       gtk_scale_set_value_pos( GTK_SCALE( w ),GTK_POS_LEFT );
-       w.connect( "value-changed", G_CALLBACK( alpha_adjust_callback ), ( gpointer ) this );
-       hbox.pack_start(w, TRUE, TRUE, 5 );
-       gtk_tooltips_set_tip( pTooltips, w, "Set image transparancy", NULL );
-       w.show();
-
-       hbox.show();
-       frame.show();
+    frame = ui::Frame("Rendering");
+    m_pWidget.pack_start(frame, FALSE, FALSE, 2);
+
+    hbox = ui::HBox(FALSE, 5);
+    gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
+    frame.add(hbox);
+
+    w = ui::Label("Vertex alpha:");
+    hbox.pack_start(w, FALSE, FALSE, 5);
+    w.show();
+
+    w = ui::HScale(0.0, 1.0, 0.01);
+    gtk_range_set_value(GTK_RANGE(w), 0.5);
+    gtk_scale_set_value_pos(GTK_SCALE(w), GTK_POS_LEFT);
+    w.connect("value-changed", G_CALLBACK(alpha_adjust_callback), (gpointer) this );
+    hbox.pack_start(w, TRUE, TRUE, 5);
+    gtk_tooltips_set_tip(pTooltips, w, "Set image transparancy", NULL);
+    w.show();
+
+    hbox.show();
+    frame.show();
 // Third row (size and position)
-       frame = ui::Frame( "Size/Position (undefined)" );
-       m_pPosLabel = gtk_frame_get_label_widget( GTK_FRAME( frame ) );
-       m_pWidget.pack_start( frame, FALSE, FALSE, 2 );
-
-       hbox = ui::HBox( FALSE,5 );
-       frame.add(hbox);
-       gtk_container_set_border_width( GTK_CONTAINER( hbox ),4 );
-
-       w = ui::Button( "from selection" );
-       hbox.pack_start(w, TRUE, FALSE, 5 );
-       w.connect( "clicked", G_CALLBACK( size_sel_callback ), ( gpointer ) this );
-       gtk_tooltips_set_tip( pTooltips, w, "Set the size of the image to the bounding rectangle of all selected brushes and entities", NULL );
-       w.show();
-
-       if ( m_vt == XY ) {
-               w = ui::Button( "from map mins/maxs" );
-               hbox.pack_start(w, TRUE, FALSE, 2 );
-               w.connect( "clicked", G_CALLBACK( size_mm_callback ), ( gpointer ) this );
-               gtk_tooltips_set_tip( pTooltips, w, "Set the size of the image using the mapcoordsmins and mapcoordsmaxs keys of the worldspawn entity", NULL );
-               w.show();
-       }
-
-       hbox.show();
-       frame.show();
-
-       m_pWidget.show();
+    frame = ui::Frame("Size/Position (undefined)");
+    m_pPosLabel = gtk_frame_get_label_widget(GTK_FRAME(frame));
+    m_pWidget.pack_start(frame, FALSE, FALSE, 2);
+
+    hbox = ui::HBox(FALSE, 5);
+    frame.add(hbox);
+    gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
+
+    w = ui::Button("from selection");
+    hbox.pack_start(w, TRUE, FALSE, 5);
+    w.connect("clicked", G_CALLBACK(size_sel_callback), (gpointer) this );
+    gtk_tooltips_set_tip(pTooltips, w,
+                         "Set the size of the image to the bounding rectangle of all selected brushes and entities",
+                         NULL);
+    w.show();
+
+    if (m_vt == XY) {
+        w = ui::Button("from map mins/maxs");
+        hbox.pack_start(w, TRUE, FALSE, 2);
+        w.connect("clicked", G_CALLBACK(size_mm_callback), (gpointer) this );
+        gtk_tooltips_set_tip(pTooltips, w,
+                             "Set the size of the image using the mapcoordsmins and mapcoordsmaxs keys of the worldspawn entity",
+                             NULL);
+        w.show();
+    }
+
+    hbox.show();
+    frame.show();
+
+    m_pWidget.show();
 }
 
-void CBackgroundDialogPage::Append( GtkWidget *notebook ){
-       gtk_notebook_append_page( GTK_NOTEBOOK( notebook ), m_pWidget, m_pTabLabel );
+void CBackgroundDialogPage::Append(GtkWidget *notebook)
+{
+    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), m_pWidget, m_pTabLabel);
 }
 
 // dialog global callbacks
@@ -292,53 +310,58 @@ void CBackgroundDialogPage::Append( GtkWidget *notebook ){
    }
  */
 
-static void response_callback( GtkWidget *widget, gint response, gpointer data ){
-       if ( response == GTK_RESPONSE_CLOSE ) {
-               gtk_widget_hide( pDialogWnd );
-       }
+static void response_callback(GtkWidget *widget, gint response, gpointer data)
+{
+    if (response == GTK_RESPONSE_CLOSE) {
+        gtk_widget_hide(pDialogWnd);
+    }
 }
 
-static gint close_callback( GtkWidget *widget, gpointer data ){
-       gtk_widget_hide( pDialogWnd );
-       return TRUE;
+static gint close_callback(GtkWidget *widget, gpointer data)
+{
+    gtk_widget_hide(pDialogWnd);
+    return TRUE;
 }
 
-void InitBackgroundDialog(){
-       CBackgroundDialogPage *pPage;
-
-       pDialogWnd = gtk_dialog_new_with_buttons( "Background Images",
-                                                                                         g_pMainWidget,
-                                                                                         (GtkDialogFlags)( GTK_DIALOG_DESTROY_WITH_PARENT ),
-                                                 // TODO dialog with no buttons
-                                                 //                                                                              GTK_STOCK_CLOSE,
-                                                 //                                                                              GTK_RESPONSE_CLOSE,
-                                                                                         NULL );
-       pDialogWnd.connect( "delete_event", G_CALLBACK( close_callback ), NULL );
-       pDialogWnd.connect( "response", G_CALLBACK( response_callback ), NULL );
+void InitBackgroundDialog()
+{
+    CBackgroundDialogPage *pPage;
+
+    pDialogWnd = gtk_dialog_new_with_buttons("Background Images",
+                                             g_pMainWidget,
+                                             (GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT),
+            // TODO dialog with no buttons
+            //                                                                           GTK_STOCK_CLOSE,
+            //                                                                           GTK_RESPONSE_CLOSE,
+                                             NULL);
+    pDialogWnd.connect("delete_event", G_CALLBACK(close_callback), NULL);
+    pDialogWnd.connect("response", G_CALLBACK(response_callback), NULL);
 //  pDialogWnd.connect( "expose_event", G_CALLBACK( ci_expose ), NULL );
 
-       pTooltips = gtk_tooltips_new();
+    pTooltips = gtk_tooltips_new();
 
-       pNotebook = gtk_notebook_new();
-       pPage = new CBackgroundDialogPage( XY );
-       pPage->Append( pNotebook );
-       pPage = new CBackgroundDialogPage( XZ );
-       pPage->Append( pNotebook );
-       pPage = new CBackgroundDialogPage( YZ );
-       pPage->Append( pNotebook );
+    pNotebook = gtk_notebook_new();
+    pPage = new CBackgroundDialogPage(XY);
+    pPage->Append(pNotebook);
+    pPage = new CBackgroundDialogPage(XZ);
+    pPage->Append(pNotebook);
+    pPage = new CBackgroundDialogPage(YZ);
+    pPage->Append(pNotebook);
 
-       gtk_box_pack_start( GTK_BOX( GTK_DIALOG( pDialogWnd )->vbox ), pNotebook, TRUE, TRUE, 0 );
+    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pDialogWnd)->vbox), pNotebook, TRUE, TRUE, 0);
 
-       pNotebook.show();
+    pNotebook.show();
 
-       gtk_widget_realize( pDialogWnd );
+    gtk_widget_realize(pDialogWnd);
 }
 
-void ShowBackgroundDialog(){
-       gtk_window_present( pDialogWnd );
+void ShowBackgroundDialog()
+{
+    gtk_window_present(pDialogWnd);
 }
 
-void ShowBackgroundDialogPG( int page ){
-       gtk_notebook_set_current_page( GTK_NOTEBOOK( pNotebook ),page );
-       ShowBackgroundDialog();
+void ShowBackgroundDialogPG(int page)
+{
+    gtk_notebook_set_current_page(GTK_NOTEBOOK(pNotebook), page);
+    ShowBackgroundDialog();
 }
index 29a511d..e442dda 100644 (file)
@@ -29,7 +29,9 @@
 #define _BKGRND2D_DIALOG_H_
 
 void InitBackgroundDialog();
+
 void ShowBackgroundDialog();
-void ShowBackgroundDialogPG( int page );
+
+void ShowBackgroundDialogPG(int page);
 
 #endif // _BKGRND2D_DIALOG_H_
index 35fb072..261b541 100644 (file)
@@ -80,224 +80,248 @@ static const char *PLUGIN_NAME = "2d window background plugin";
 
 //backwards for some reason
 static const char *PLUGIN_COMMANDS = CMD_ABOUT ";"
-                                                                        CMD_SEP ";"
-                                                                        CMD_CONFIG
-;
+        CMD_SEP ";"
+        CMD_CONFIG;
 
 static const char *PLUGIN_ABOUT = "2d window background v0.25\n\n"
-                                                                 "By reyalP (hellsownpuppy@yahoo.com)";
-
-
+        "By reyalP (hellsownpuppy@yahoo.com)";
 
 
 void DoBkgrndToggleXY();
+
 void DoBkgrndToggleXZ();
+
 void DoBkgrndToggleYZ();
 
 #define NUM_TOOLBAR_BUTTONS 4
-struct toolbar_button_info_s
-{
-       const char *image;
-       const char *text;
-       const char *tip;
-       void ( *func )();
-       IToolbarButton::EType type;
-};
 
-struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
-{
-       {
-               "bkgrnd2d_xy_toggle.png",
-               "xy background",
-               "Toggle xy background image",
-               DoBkgrndToggleXY,
-               IToolbarButton::eToggleButton
-       },
-       {
-               "bkgrnd2d_xz_toggle.png",
-               "xz background",
-               "Toggle xz background image",
-               DoBkgrndToggleXZ,
-               IToolbarButton::eToggleButton
-       },
-       {
-               "bkgrnd2d_yz_toggle.png",
-               "yz background",
-               "Toggle yz background image",
-               DoBkgrndToggleYZ,
-               IToolbarButton::eToggleButton
-       },
-       {
-               "bkgrnd2d_conf.png",
-               "Configure",
-               "Configure background images",
-               ShowBackgroundDialog,
-               IToolbarButton::eButton
-       },
+struct toolbar_button_info_s {
+    const char *image;
+    const char *text;
+    const char *tip;
+
+    void ( *func )();
+
+    IToolbarButton::EType type;
 };
 
-class Bkgrnd2dButton : public IToolbarButton
-{
+struct toolbar_button_info_s toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
+        {
+                {
+                        "bkgrnd2d_xy_toggle.png",
+                        "xy background",
+                        "Toggle xy background image",
+                        DoBkgrndToggleXY,
+                        IToolbarButton::eToggleButton
+                },
+                {
+                        "bkgrnd2d_xz_toggle.png",
+                        "xz background",
+                        "Toggle xz background image",
+                        DoBkgrndToggleXZ,
+                        IToolbarButton::eToggleButton
+                },
+                {
+                        "bkgrnd2d_yz_toggle.png",
+                        "yz background",
+                        "Toggle yz background image",
+                        DoBkgrndToggleYZ,
+                        IToolbarButton::eToggleButton
+                },
+                {
+                        "bkgrnd2d_conf.png",
+                        "Configure",
+                        "Configure background images",
+                        ShowBackgroundDialog,
+                        IToolbarButton::eButton
+                },
+        };
+
+class Bkgrnd2dButton : public IToolbarButton {
 public:
-const toolbar_button_info_s *bi;
-virtual const char* getImage() const {
-       return bi->image;
-}
-virtual const char* getText() const {
-       return bi->text;
-}
-virtual const char* getTooltip() const {
-       return bi->tip;
-}
-virtual void activate() const {
-       bi->func();
-       return ;
-}
-virtual EType getType() const {
-       return bi->type;
-}
+    const toolbar_button_info_s *bi;
+
+    virtual const char *getImage() const
+    {
+        return bi->image;
+    }
+
+    virtual const char *getText() const
+    {
+        return bi->text;
+    }
+
+    virtual const char *getTooltip() const
+    {
+        return bi->tip;
+    }
+
+    virtual void activate() const
+    {
+        bi->func();
+        return;
+    }
+
+    virtual EType getType() const
+    {
+        return bi->type;
+    }
 };
 
 Bkgrnd2dButton g_bkgrnd2dbuttons[NUM_TOOLBAR_BUTTONS];
 
-unsigned int ToolbarButtonCount(){
-       return NUM_TOOLBAR_BUTTONS;
+unsigned int ToolbarButtonCount()
+{
+    return NUM_TOOLBAR_BUTTONS;
 }
 
-const IToolbarButton* GetToolbarButton( unsigned int index ){
-       g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
-       return &g_bkgrnd2dbuttons[index];
+const IToolbarButton *GetToolbarButton(unsigned int index)
+{
+    g_bkgrnd2dbuttons[index].bi = &toolbar_buttons[index];
+    return &g_bkgrnd2dbuttons[index];
 }
 
-extern "C" const char* QERPlug_Init( void *hApp, void* pMainWidget ){
-       g_pMainWidget = pMainWidget;
+extern "C" const char *QERPlug_Init(void *hApp, void *pMainWidget)
+{
+    g_pMainWidget = pMainWidget;
 
-       InitBackgroundDialog();
-       render.Register();
+    InitBackgroundDialog();
+    render.Register();
 
 //TODO is it right ? is it wrong ? it works
 //TODO figure out supported image types
-       GetFileTypeRegistry()->addType( FILETYPE_KEY, filetype_t( "all files", "*.*" ) );
-       GetFileTypeRegistry()->addType( FILETYPE_KEY, filetype_t( "jpeg files", "*.jpg" ) );
-       GetFileTypeRegistry()->addType( FILETYPE_KEY, filetype_t( "targa files", "*.tga" ) );
-       return (char *) PLUGIN_NAME;
+    GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("all files", "*.*"));
+    GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("jpeg files", "*.jpg"));
+    GetFileTypeRegistry()->addType(FILETYPE_KEY, filetype_t("targa files", "*.tga"));
+    return (char *) PLUGIN_NAME;
 }
 
-extern "C" const char* QERPlug_GetName(){
-       return (char *) PLUGIN_NAME;
+extern "C" const char *QERPlug_GetName()
+{
+    return (char *) PLUGIN_NAME;
 }
 
-extern "C" const char* QERPlug_GetCommandList(){
-       return (char *) PLUGIN_COMMANDS;
+extern "C" const char *QERPlug_GetCommandList()
+{
+    return (char *) PLUGIN_COMMANDS;
 }
 
-extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ){
-       Sys_Printf( MSG_PREFIX "Command \"%s\"\n",p );
-       if ( !strcmp( p, CMD_ABOUT ) ) {
-               g_FuncTable.m_pfnMessageBox( NULL, PLUGIN_ABOUT, "About", MB_OK, NULL );
-       }
-       else if ( !strcmp( p,CMD_CONFIG ) ) {
-               ShowBackgroundDialog();
-       }
+extern "C" void QERPlug_Dispatch(const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
+{
+    Sys_Printf(MSG_PREFIX "Command \"%s\"\n", p);
+    if (!strcmp(p, CMD_ABOUT)) {
+        g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);
+    } else if (!strcmp(p, CMD_CONFIG)) {
+        ShowBackgroundDialog();
+    }
 }
 
 //TODO these three suck
-void DoBkgrndToggleXY(){
-       Sys_Printf( MSG_PREFIX "DoBkgrndToggleXY\n" );
-       // always toggle, since the buttons do
-       backgroundXY.m_bActive = ( backgroundXY.m_bActive ) ? false : true;
-       // if we don't have image or extents, and we activated,
-       // bring up the dialog with the corresponding page
-       // would be better to hide or grey out button, but we can't
-       if ( backgroundXY.m_bActive && !backgroundXY.Valid() ) {
-               ShowBackgroundDialogPG( 0 );
-       }
-       else{
-               g_FuncTable.m_pfnSysUpdateWindows( W_XY );
-       }
+void DoBkgrndToggleXY()
+{
+    Sys_Printf(MSG_PREFIX "DoBkgrndToggleXY\n");
+    // always toggle, since the buttons do
+    backgroundXY.m_bActive = (backgroundXY.m_bActive) ? false : true;
+    // if we don't have image or extents, and we activated,
+    // bring up the dialog with the corresponding page
+    // would be better to hide or grey out button, but we can't
+    if (backgroundXY.m_bActive && !backgroundXY.Valid()) {
+        ShowBackgroundDialogPG(0);
+    } else {
+        g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+    }
 }
 
-void DoBkgrndToggleXZ(){
-       Sys_Printf( MSG_PREFIX "DoBkgrndToggleXZ\n" );
-       backgroundXZ.m_bActive = ( backgroundXZ.m_bActive ) ? false : true;
-       if ( backgroundXZ.m_bActive && !backgroundXZ.Valid() ) {
-               ShowBackgroundDialogPG( 1 );
-       }
-       else{
-               g_FuncTable.m_pfnSysUpdateWindows( W_XY );
-       }
+void DoBkgrndToggleXZ()
+{
+    Sys_Printf(MSG_PREFIX "DoBkgrndToggleXZ\n");
+    backgroundXZ.m_bActive = (backgroundXZ.m_bActive) ? false : true;
+    if (backgroundXZ.m_bActive && !backgroundXZ.Valid()) {
+        ShowBackgroundDialogPG(1);
+    } else {
+        g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+    }
 }
 
-void DoBkgrndToggleYZ(){
-       Sys_Printf( MSG_PREFIX "DoBkgrndToggleYZ\n" );
-       backgroundYZ.m_bActive = ( backgroundYZ.m_bActive ) ? false : true;
-       if ( backgroundYZ.m_bActive && !backgroundYZ.Valid() ) {
-               ShowBackgroundDialogPG( 2 );
-       }
-       else{
-               g_FuncTable.m_pfnSysUpdateWindows( W_XY );
-       }
+void DoBkgrndToggleYZ()
+{
+    Sys_Printf(MSG_PREFIX "DoBkgrndToggleYZ\n");
+    backgroundYZ.m_bActive = (backgroundYZ.m_bActive) ? false : true;
+    if (backgroundYZ.m_bActive && !backgroundYZ.Valid()) {
+        ShowBackgroundDialogPG(2);
+    } else {
+        g_FuncTable.m_pfnSysUpdateWindows(W_XY);
+    }
 }
 
 // =============================================================================
 // SYNAPSE
 
-CSynapseServerg_pSynapseServer = NULL;
+CSynapseServer *g_pSynapseServer = NULL;
 CSynapseClientBkgrnd2d g_SynapseClient;
 
-extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ){
-       if ( strcmp( version, SYNAPSE_VERSION ) ) {
-               Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
-               return NULL;
-       }
-       g_pSynapseServer = pServer;
-       g_pSynapseServer->IncRef();
-       Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
+extern "C" CSynapseClient *SYNAPSE_DLL_EXPORT
 
-       g_SynapseClient.AddAPI( TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof( _QERPlugToolbarTable ) );
-       g_SynapseClient.AddAPI( PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof( _QERPluginTable ) );
-
-       g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
-       g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
+Synapse_EnumerateInterfaces(const char *version, CSynapseServer *pServer)
+{
+    if (strcmp(version, SYNAPSE_VERSION)) {
+        Syn_Printf("ERROR: synapse API version mismatch: should be '"
+        SYNAPSE_VERSION
+        "', got '%s'\n", version );
+        return NULL;
+    }
+    g_pSynapseServer = pServer;
+    g_pSynapseServer->IncRef();
+    Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
+
+    g_SynapseClient.AddAPI(TOOLBAR_MAJOR, BKGRND2D_MINOR, sizeof(_QERPlugToolbarTable));
+    g_SynapseClient.AddAPI(PLUGIN_MAJOR, BKGRND2D_MINOR, sizeof(_QERPluginTable));
+
+    g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
+    g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
 // TODO is this the right way to ask for 'whichever VFS we have loaded' ? Seems to work
 // for misc filename functions
-       g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
+    g_SynapseClient.AddAPI(VFS_MAJOR, "*", sizeof(g_FileSystemTable), SYN_REQUIRE, &g_FileSystemTable);
 // get worldspawn
-       g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
+    g_SynapseClient.AddAPI(ENTITY_MAJOR, NULL, sizeof(g_EntityTable), SYN_REQUIRE, &g_EntityTable);
 // selected brushes
-       g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
+    g_SynapseClient.AddAPI(DATA_MAJOR, NULL, sizeof(g_DataTable), SYN_REQUIRE, &g_DataTable);
 
-       return &g_SynapseClient;
+    return &g_SynapseClient;
 }
 
-bool CSynapseClientBkgrnd2d::RequestAPI( APIDescriptor_t *pAPI ){
-       if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
-               _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
-
-               pTable->m_pfnQERPlug_Init = QERPlug_Init;
-               pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
-               pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
-               pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
-               return true;
-       }
-       if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
-               _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
-
-               pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
-               pTable->m_pfnGetToolbarButton = &GetToolbarButton;
-               return true;
-       }
-
-       Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
-       return false;
+bool CSynapseClientBkgrnd2d::RequestAPI(APIDescriptor_t *pAPI)
+{
+    if (!strcmp(pAPI->major_name, PLUGIN_MAJOR)) {
+        _QERPluginTable *pTable = static_cast<_QERPluginTable *>( pAPI->mpTable );
+
+        pTable->m_pfnQERPlug_Init = QERPlug_Init;
+        pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
+        pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
+        pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
+        return true;
+    }
+    if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR)) {
+        _QERPlugToolbarTable *pTable = static_cast<_QERPlugToolbarTable *>( pAPI->mpTable );
+
+        pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
+        pTable->m_pfnGetToolbarButton = &GetToolbarButton;
+        return true;
+    }
+
+    Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
+    return false;
 }
 
 #include "version.h"
 
-const char* CSynapseClientBkgrnd2d::GetInfo(){
-       return "2d Background plugin built " __DATE__ " " RADIANT_VERSION;
+const char *CSynapseClientBkgrnd2d::GetInfo()
+{
+    return "2d Background plugin built " __DATE__ " "
+    RADIANT_VERSION;
 }
 
-const char* CSynapseClientBkgrnd2d::GetName(){
-       return "bkgrnd2d";
+const char *CSynapseClientBkgrnd2d::GetName()
+{
+    return "bkgrnd2d";
 }
index 13ca737..361bf83 100644 (file)
@@ -41,7 +41,9 @@
 #include "synapse.h"
 #include "iplugin.h"
 #include "itoolbar.h"
+
 #define USE_QERTABLE_DEFINE
+
 #include "qerplugin.h"
 #include "igl.h"
 #include "ifilesystem.h"
@@ -58,19 +60,24 @@ extern _QEREntityTable g_EntityTable;
 extern _QERAppDataTable g_DataTable;
 extern void *g_pMainWidget;
 
-extern CSynapseServerg_pSynapseServer;
+extern CSynapseServer *g_pSynapseServer;
 
-class CSynapseClientBkgrnd2d : public CSynapseClient
-{
+class CSynapseClientBkgrnd2d : public CSynapseClient {
 public:
 // CSynapseClient API
-bool RequestAPI( APIDescriptor_t *pAPI );
-const char* GetInfo();
-const char* GetName();
+    bool RequestAPI(APIDescriptor_t *pAPI);
+
+    const char *GetInfo();
 
-CSynapseClientBkgrnd2d() { }
-virtual ~CSynapseClientBkgrnd2d() { }
+    const char *GetName();
+
+    CSynapseClientBkgrnd2d()
+    {}
+
+    virtual ~CSynapseClientBkgrnd2d()
+    {}
 };
+
 #define MSG_PREFIX "bkgrnd2d: "
 #define MSG_WARN "bkgrnd2d WARNING: "
 #define BKGRND2D_MINOR "bkgrnd2d"
index fc55553..eea867c 100644 (file)
 
 class CBspPoint {
 public:
-float p[3];
+    float p[3];
 };
 
 class CBspPortal {
 public:
-CBspPortal();
-~CBspPortal();
+    CBspPortal();
 
-unsigned point_count;
-CBspPoint *point;
-bool Build( char *def, unsigned int pointCnt, bool bInverse );
+    ~CBspPortal();
+
+    unsigned point_count;
+    CBspPoint *point;
+
+    bool Build(char *def, unsigned int pointCnt, bool bInverse);
 };
 
 
 class CBspNode {
 public:
-CBspPortal *portal;
-unsigned int portal_count;
+    CBspPortal *portal;
+    unsigned int portal_count;
+
+    bool AddPortal(char *def, unsigned int pointCnt, bool bInverse);
 
-bool AddPortal( char* def, unsigned int pointCnt, bool bInverse );
-unsigned int portal_next;
-CBspNode();
-~CBspNode();
+    unsigned int portal_next;
+
+    CBspNode();
+
+    ~CBspNode();
 };
 
 
@@ -50,14 +55,15 @@ CBspNode();
 class CPortals {
 public:
 
-CPortals();
-~CPortals();
+    CPortals();
+
+    ~CPortals();
 
-void Load();     // use filename in fn
-void Purge();
+    void Load();     // use filename in fn
+    void Purge();
 
-char fn[NAME_MAX];
-CBspNode *node;
+    char fn[NAME_MAX];
+    CBspNode *node;
 
-unsigned int node_count;
+    unsigned int node_count;
 };
index decfe77..940d191 100644 (file)
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-DBobView::DBobView(){
-       nPathCount = 0;
+DBobView::DBobView()
+{
+    nPathCount = 0;
 
-       path = NULL;
+    path = NULL;
 
-       boundingShow = BOUNDS_APEX;
+    boundingShow = BOUNDS_APEX;
 
-       constructShaders();
-       GlobalShaderCache().attachRenderable( *this );
+    constructShaders();
+    GlobalShaderCache().attachRenderable(*this);
 }
 
-DBobView::~DBobView(){
-       GlobalShaderCache().detachRenderable( *this );
-       destroyShaders();
+DBobView::~DBobView()
+{
+    GlobalShaderCache().detachRenderable(*this);
+    destroyShaders();
 
-       if ( path ) {
-               delete[] path;
-       }
+    if (path) {
+        delete[] path;
+    }
 
-       g_PathView = NULL;
+    g_PathView = NULL;
 }
 
 //////////////////////////////////////////////////////////////////////
 // Implementation
 //////////////////////////////////////////////////////////////////////
 
-void DBobView::render( RenderStateFlags state ) const {
-       glBegin( GL_LINE_STRIP );
+void DBobView::render(RenderStateFlags state) const
+{
+    glBegin(GL_LINE_STRIP);
 
-       for ( int i = 0; i < nPathCount; i++ )
-               glVertex3fv( path[i] );
+    for (int i = 0; i < nPathCount; i++)
+        glVertex3fv(path[i]);
 
-       glEnd();
+    glEnd();
 }
 
-const char* DBobView_state_line = "$bobtoolz/bobview/line";
-const char* DBobView_state_box = "$bobtoolz/bobview/box";
-
-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 );
+const char *DBobView_state_line = "$bobtoolz/bobview/line";
+const char *DBobView_state_box = "$bobtoolz/bobview/box";
+
+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);
 }
 
-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::destroyShaders()
+{
+    GlobalOpenGLStateLibrary().erase(DBobView_state_line);
+    GlobalOpenGLStateLibrary().erase(DBobView_state_box);
+    GlobalShaderCache().release(DBobView_state_line);
+    GlobalShaderCache().release(DBobView_state_box);
 }
 
-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;
-       }
-
-       renderer.SetState( m_shader_line, Renderer::eWireframeOnly );
-       renderer.SetState( m_shader_line, Renderer::eFullMaterials );
-       renderer.addRenderable( *this, g_matrix4_identity );
-
-       if ( m_bShowExtra ) {
-               renderer.SetState( m_shader_box, Renderer::eWireframeOnly );
-               renderer.SetState( m_shader_box, Renderer::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 );
-       }
+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;
+    }
+
+    renderer.SetState(m_shader_line, Renderer::eWireframeOnly);
+    renderer.SetState(m_shader_line, Renderer::eFullMaterials);
+    renderer.addRenderable(*this, g_matrix4_identity);
+
+    if (m_bShowExtra) {
+        renderer.SetState(m_shader_box, Renderer::eWireframeOnly);
+        renderer.SetState(m_shader_box, Renderer::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::renderWireframe( Renderer& renderer, const VolumeTest& volume ) const {
-       renderSolid( renderer, volume );
+
+void DBobView::renderWireframe(Renderer &renderer, const VolumeTest &volume) const
+{
+    renderSolid(renderer, volume);
 }
 
-void DBobView::SetPath( vec3_t *pPath ){
-       if ( path ) {
-               delete[] path;
-       }
+void DBobView::SetPath(vec3_t *pPath)
+{
+    if (path) {
+        delete[] path;
+    }
 
-       path = pPath;
+    path = pPath;
 }
 
 const float LOCAL_GRAVITY = -800.0f;
 
-bool DBobView::CalculateTrajectory( vec3_t start, vec3_t apex, float multiplier, int points, float varGravity ){
-       if ( apex[2] <= start[2] ) {
-               SetPath( NULL );
-               return false;
-       }
-       // ----think q3a actually would allow these
-       //scrub that, coz the plugin wont :]
+bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier, int points, float varGravity)
+{
+    if (apex[2] <= start[2]) {
+        SetPath(NULL);
+        return false;
+    }
+    // ----think q3a actually would allow these
+    //scrub that, coz the plugin wont :]
 
-       vec3_t dist, speed;
-       VectorSubtract( apex, start, dist );
+    vec3_t dist, speed;
+    VectorSubtract(apex, start, dist);
 
-       vec_t speed_z = (float)sqrt( -2 * LOCAL_GRAVITY * dist[2] );
-       float flight_time = -speed_z / LOCAL_GRAVITY;
+    vec_t speed_z = (float) sqrt(-2 * LOCAL_GRAVITY * dist[2]);
+    float flight_time = -speed_z / LOCAL_GRAVITY;
 
 
-       VectorScale( dist, 1 / flight_time, speed );
-       speed[2] = speed_z;
+    VectorScale(dist, 1 / flight_time, speed);
+    speed[2] = speed_z;
 
 //     Sys_Printf("Speed: (%.4f %.4f %.4f)\n", speed[0], speed[1], speed[2]);
 
-       vec3_t* pPath = new vec3_t[points];
+    vec3_t *pPath = new vec3_t[points];
 
-       float interval = multiplier * flight_time / points;
-       for ( int i = 0; i < points; i++ )
-       {
-               float ltime = interval * i;
+    float interval = multiplier * flight_time / points;
+    for (int i = 0; i < points; i++) {
+        float ltime = interval * i;
 
-               VectorScale( speed, ltime, pPath[i] );
-               VectorAdd( pPath[i], start, pPath[i] );
+        VectorScale(speed, ltime, pPath[i]);
+        VectorAdd(pPath[i], start, pPath[i]);
 
-               // could do this all with vectors
-               // vGrav = {0, 0, -800.0f}
-               // VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
-               // VectorScale(speed, ltime, pPath[i]);
-               // _VectorAdd(pPath[i], start, pPath[i])
-               // _VectorAdd(pPath[i], vAdd, pPath[i])
+        // could do this all with vectors
+        // vGrav = {0, 0, -800.0f}
+        // VectorScale(vGrav, 0.5f*ltime*ltime, vAdd);
+        // VectorScale(speed, ltime, pPath[i]);
+        // _VectorAdd(pPath[i], start, pPath[i])
+        // _VectorAdd(pPath[i], vAdd, pPath[i])
 
-               pPath[i][2] = start[2] + ( speed_z * ltime ) + ( varGravity * 0.5f * ltime * ltime );
-       }
+        pPath[i][2] = start[2] + (speed_z * ltime) + (varGravity * 0.5f * ltime * ltime);
+    }
 
-       SetPath( pPath );
-       return true;
+    SetPath(pPath);
+    return true;
 }
 
-void DBobView::Begin( const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra ){
-       strcpy( entTrigger, trigger );
-       strcpy( entTarget, target );
-
-       fMultiplier = multiplier;
-       fVarGravity = varGravity;
-       nPathCount = points;
-       m_bShowExtra = bShowExtra;
-
-       if ( !UpdatePath() ) {
-               globalErrorStream() << "Initialization Failure in DBobView::Begin";
-               delete this;
-       }
-       globalOutputStream() << "Initialization of Path Plotter succeeded.";
+void
+DBobView::Begin(const char *trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate,
+                bool bShowExtra)
+{
+    strcpy(entTrigger, trigger);
+    strcpy(entTarget, target);
+
+    fMultiplier = multiplier;
+    fVarGravity = varGravity;
+    nPathCount = points;
+    m_bShowExtra = bShowExtra;
+
+    if (!UpdatePath()) {
+        globalErrorStream() << "Initialization Failure in DBobView::Begin";
+        delete this;
+    }
+    globalOutputStream() << "Initialization of Path Plotter succeeded.";
 }
 
-bool DBobView::UpdatePath(){
-       vec3_t start, apex;
-
-       if ( GetEntityCentre( entTrigger, start ) ) {
-               if ( GetEntityCentre( entTarget, apex ) ) {
-                       CalculateTrajectory( start, apex, fMultiplier, nPathCount, fVarGravity );
-                       return true;
-               }
-       }
-       return false;
+bool DBobView::UpdatePath()
+{
+    vec3_t start, apex;
+
+    if (GetEntityCentre(entTrigger, start)) {
+        if (GetEntityCentre(entTarget, apex)) {
+            CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity);
+            return true;
+        }
+    }
+    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 ) {
-                               const scene::Path* entTarget = FindEntityFromTargetname( target_ep->value );
-                               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{
-                                               globalErrorStream() << "bobToolz PathPlotter: trigger_push ARGH\n";
-                                       }
-                               }
-                               else{
-                                       globalErrorStream() << "bobToolz PathPlotter: trigger_push target could not be found..\n";
-                               }
-                       }
-                       else{
-                               globalErrorStream() << "bobToolz PathPlotter: trigger_push has no target..\n";
-                       }
-               }
-               else{
-                       globalErrorStream() << "bobToolz PathPlotter: You must select a 'trigger_push' entity..\n";
-               }
-       }
-       else{
-               globalErrorStream() << "bobToolz PathPlotter: Entity must have a targetname.\n";
-       }
-       return;
+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) {
+                const scene::Path *entTarget = FindEntityFromTargetname(target_ep->value);
+                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 {
+                        globalErrorStream() << "bobToolz PathPlotter: trigger_push ARGH\n";
+                    }
+                } else {
+                    globalErrorStream() << "bobToolz PathPlotter: trigger_push target could not be found..\n";
+                }
+            } else {
+                globalErrorStream() << "bobToolz PathPlotter: trigger_push has no target..\n";
+            }
+        } else {
+            globalErrorStream() << "bobToolz PathPlotter: You must select a 'trigger_push' entity..\n";
+        }
+    } else {
+        globalErrorStream() << "bobToolz PathPlotter: Entity must have a targetname.\n";
+    }
+    return;
 }
index b20ef14..f0f40fd 100644 (file)
 #include "mathlib.h"
 
 class DListener;
+
 class Shader;
 
-const int BOUNDS_ALL  = 0;
+const int BOUNDS_ALL = 0;
 const int BOUNDS_APEX = 1;
 
 #if _MSC_VER > 1000
 #pragma once
 #endif // _MSC_VER > 1000
 
-class DBobView : public Renderable, public OpenGLRenderable, public Entity::Observer
-{
-Shader* m_shader_line;
-Shader* m_shader_box;
+class DBobView : public Renderable, public OpenGLRenderable, public Entity::Observer {
+    Shader *m_shader_line;
+    Shader *m_shader_box;
 public:
-DBobView();
-virtual ~DBobView();
+    DBobView();
+
+    virtual ~DBobView();
 
 protected:
-vec3_t* path;
+    vec3_t *path;
 public:
-bool m_bShowExtra;
-int boundingShow;
-DListener* eyes;
-float fVarGravity;
-float fMultiplier;
-int nPathCount;
-
-Entity* trigger;
-Entity* target;
-
-bool UpdatePath();
-char entTarget[256];
-char entTrigger[256];
-void Begin( const char*, const char*, float, int, float, bool, bool );
-bool CalculateTrajectory( vec3_t, vec3_t, float, int, float );
-
-void SetPath( vec3_t* pPath );
-
-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 MemberCaller<DBobView, void(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;
-       }
-}
+    bool m_bShowExtra;
+    int boundingShow;
+    DListener *eyes;
+    float fVarGravity;
+    float fMultiplier;
+    int nPathCount;
+
+    Entity *trigger;
+    Entity *target;
+
+    bool UpdatePath();
+
+    char entTarget[256];
+    char entTrigger[256];
+
+    void Begin(const char *, const char *, float, int, float, bool, bool);
+
+    bool CalculateTrajectory(vec3_t, vec3_t, float, int, float);
+
+    void SetPath(vec3_t *pPath);
+
+    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 MemberCaller<DBobView, void(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 );
+
+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 a0d9769..a5b18ce 100644 (file)
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-DBrush::DBrush( int ID ){
-       m_nBrushID = ID;
-       bBoundsBuilt = false;
-       QER_entity = NULL;
-       QER_brush = NULL;
+DBrush::DBrush(int ID)
+{
+    m_nBrushID = ID;
+    bBoundsBuilt = false;
+    QER_entity = NULL;
+    QER_brush = NULL;
 }
 
-DBrush::~DBrush(){
-       ClearFaces();
-       ClearPoints();
+DBrush::~DBrush()
+{
+    ClearFaces();
+    ClearPoints();
 }
 
 //////////////////////////////////////////////////////////////////////
 // Implementation
 //////////////////////////////////////////////////////////////////////
 
-DPlane* DBrush::AddFace( const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData ){
+DPlane *DBrush::AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData *texData)
+{
 #if GDEF_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;
-       DPlane* newFace = new DPlane( va, vb, vc, texData );
-       faceList.push_back( newFace );
-
-       return newFace;
-}
-
-int DBrush::BuildPoints(){
-       ClearPoints();
-
-       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 ( std::list<DPlane *>::const_iterator p1 = faceList.begin(); p1 != faceList.end(); p1++ )
-       {
-               std::list<DPlane *>::const_iterator p2 = p1;
-               for ( p2++; p2 != faceList.end(); p2++ )
-               {
-                       std::list<DPlane *>::const_iterator p3 = p2;
-                       for ( p3++; p3 != faceList.end(); p3++ )
-                       {
-                               vec3_t pnt;
-                               if ( ( *p1 )->PlaneIntersection( *p2, *p3, pnt ) ) {
-                                       int pos = PointPosition( pnt );
-
-                                       if ( pos == POINT_IN_BRUSH ) { // ???? shouldn't happen here
-                                               globalErrorStream() << "ERROR:: Build Brush Points: Point IN brush!!!\n";
-                                       }
-                                       else if ( pos == POINT_ON_BRUSH ) { // normal point
-                                               if ( !HasPoint( pnt ) ) {
-                                                       AddPoint( pnt );
-                                               }
+    bBoundsBuilt = false;
+    DPlane *newFace = new DPlane(va, vb, vc, texData);
+    faceList.push_back(newFace);
+
+    return newFace;
+}
+
+int DBrush::BuildPoints()
+{
+    ClearPoints();
+
+    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 (std::list<DPlane *>::const_iterator p1 = faceList.begin(); p1 != faceList.end(); p1++) {
+        std::list<DPlane *>::const_iterator p2 = p1;
+        for (p2++; p2 != faceList.end(); p2++) {
+            std::list<DPlane *>::const_iterator p3 = p2;
+            for (p3++; p3 != faceList.end(); p3++) {
+                vec3_t pnt;
+                if ((*p1)->PlaneIntersection(*p2, *p3, pnt)) {
+                    int pos = PointPosition(pnt);
+
+                    if (pos == POINT_IN_BRUSH) { // ???? shouldn't happen here
+                        globalErrorStream() << "ERROR:: Build Brush Points: Point IN brush!!!\n";
+                    } else if (pos == POINT_ON_BRUSH) { // normal point
+                        if (!HasPoint(pnt)) {
+                            AddPoint(pnt);
+                        }
 /*                                             else
                             Sys_Printf("Duplicate Point Found, pyramids ahoy!!!!!\n");*/
-                                               // point lies on more that 3 planes
-                                       }
+                        // point lies on more that 3 planes
+                    }
 
-                                       // otherwise point is removed due to another plane..
+                    // otherwise point is removed due to another plane..
 
-                                       // Sys_Printf("(%f, %f, %f)\n", pnt[0], pnt[1], pnt[2]);
-                               }
-                       }
-               }
-       }
+                    // Sys_Printf("(%f, %f, %f)\n", pnt[0], pnt[1], pnt[2]);
+                }
+            }
+        }
+    }
 
 #if GDEF_DEBUG
 //     Sys_Printf("%i points on brush\n", pointList.size());
 #endif
 
-       return static_cast<int>( pointList.size() );
+    return static_cast<int>( pointList.size());
 }
 
-void DBrush_addFace( 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 ), 0 );
+void DBrush_addFace(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), 0);
 }
-typedef ReferenceCaller<DBrush, void(const _QERFaceData&), DBrush_addFace> DBrushAddFaceCaller;
 
-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 ReferenceCaller<DBrush, void(const _QERFaceData &), DBrush_addFace> DBrushAddFaceCaller;
+
+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 ReferenceCaller<DBrush, void(const _QERFaceData&), DBrush_addFaceTextured> DBrushAddFaceTexturedCaller;
 
-void DBrush::LoadFromBrush( scene::Instance& brush, bool textured ){
-       ClearFaces();
-       ClearPoints();
+typedef ReferenceCaller<DBrush, void(const _QERFaceData &), DBrush_addFaceTextured> DBrushAddFaceTexturedCaller;
+
+void DBrush::LoadFromBrush(scene::Instance &brush, bool textured)
+{
+    ClearFaces();
+    ClearPoints();
 
-       GlobalBrushCreator().Brush_forEachFace( brush.path().top(), textured ? BrushFaceDataCallback( DBrushAddFaceTexturedCaller( *this ) ) : BrushFaceDataCallback( DBrushAddFaceCaller( *this ) ) );
+    GlobalBrushCreator().Brush_forEachFace(brush.path().top(),
+                                           textured ? BrushFaceDataCallback(DBrushAddFaceTexturedCaller(*this))
+                                                    : BrushFaceDataCallback(DBrushAddFaceCaller(*this)));
 
-       QER_entity = brush.path().parent().get_pointer();
-       QER_brush = brush.path().top().get_pointer();
+    QER_entity = brush.path().parent().get_pointer();
+    QER_brush = brush.path().top().get_pointer();
 }
 
-int DBrush::PointPosition( vec3_t pnt ){
-       int state = POINT_IN_BRUSH; // if nothing happens point is inside brush
+int DBrush::PointPosition(vec3_t pnt)
+{
+    int state = POINT_IN_BRUSH; // if nothing happens point is inside brush
 
-       for ( std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
-       {
-               float dist = ( *chkPlane )->DistanceToPoint( pnt );
+    for (std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+        float dist = (*chkPlane)->DistanceToPoint(pnt);
 
-               if ( dist > MAX_ROUND_ERROR ) {
-                       return POINT_OUT_BRUSH;     // if point is in front of plane, it CANT be in the brush
-               }
-               else if ( fabs( dist ) < MAX_ROUND_ERROR ) {
-                       state = POINT_ON_BRUSH;     // if point is ON plane point is either ON the brush
-               }
-               // or outside it, it can no longer be in it
-       }
+        if (dist > MAX_ROUND_ERROR) {
+            return POINT_OUT_BRUSH;     // if point is in front of plane, it CANT be in the brush
+        } else if (fabs(dist) < MAX_ROUND_ERROR) {
+            state = POINT_ON_BRUSH;     // if point is ON plane point is either ON the brush
+        }
+        // or outside it, it can no longer be in it
+    }
 
-       return state;
+    return state;
 }
 
-void DBrush::ClearPoints(){
-       for ( std::list<DPoint *>::const_iterator deadPoint = pointList.begin(); deadPoint != pointList.end(); deadPoint++ ) {
-               delete *deadPoint;
-       }
-       pointList.clear();
+void DBrush::ClearPoints()
+{
+    for (std::list<DPoint *>::const_iterator deadPoint = pointList.begin(); deadPoint != pointList.end(); deadPoint++) {
+        delete *deadPoint;
+    }
+    pointList.clear();
 }
 
-void DBrush::ClearFaces(){
-       bBoundsBuilt = false;
-       for ( std::list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ )
-       {
-               delete *deadPlane;
-       }
-       faceList.clear();
+void DBrush::ClearFaces()
+{
+    bBoundsBuilt = false;
+    for (std::list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++) {
+        delete *deadPlane;
+    }
+    faceList.clear();
 }
 
-void DBrush::AddPoint( vec3_t pnt ){
-       DPoint* newPoint = new DPoint;
-       VectorCopy( pnt, newPoint->_pnt );
-       pointList.push_back( newPoint );
+void DBrush::AddPoint(vec3_t pnt)
+{
+    DPoint *newPoint = new DPoint;
+    VectorCopy(pnt, newPoint->_pnt);
+    pointList.push_back(newPoint);
 }
 
-bool DBrush::HasPoint( vec3_t pnt ){
-       for ( std::list<DPoint *>::const_iterator chkPoint = pointList.begin(); chkPoint != pointList.end(); chkPoint++ )
-       {
-               if ( **chkPoint == pnt ) {
-                       return true;
-               }
-       }
+bool DBrush::HasPoint(vec3_t pnt)
+{
+    for (std::list<DPoint *>::const_iterator chkPoint = pointList.begin(); chkPoint != pointList.end(); chkPoint++) {
+        if (**chkPoint == pnt) {
+            return true;
+        }
+    }
 
-       return false;
+    return false;
 }
 
-int DBrush::RemoveRedundantPlanes(){
-       int cnt = 0;
-       std::list<DPlane *>::iterator chkPlane;
+int DBrush::RemoveRedundantPlanes()
+{
+    int cnt = 0;
+    std::list<DPlane *>::iterator chkPlane;
+
+    // find duplicate planes
+    std::list<DPlane *>::iterator p1 = faceList.begin();
 
-       // find duplicate planes
-       std::list<DPlane *>::iterator p1 = faceList.begin();
+    while (p1 != faceList.end()) {
+        std::list<DPlane *>::iterator p2 = p1;
 
-       while ( p1 != faceList.end() )
-       {
-               std::list<DPlane *>::iterator p2 = p1;
+        for (p2++; p2 != faceList.end(); p2++) {
+            if (**p1 == **p2) {
+                if (!strcmp((*p1)->m_shader.c_str(), "textures/common/caulk")) {
+                    delete *p1;
+                    p1 = faceList.erase(p1);    // duplicate plane
+                } else {
+                    delete *p2;
+                    p2 = faceList.erase(p2);    // duplicate plane
+                }
 
-               for ( p2++; p2 != faceList.end(); p2++ )
-               {
-                       if ( **p1 == **p2 ) {
-                               if ( !strcmp( ( *p1 )->m_shader.c_str(), "textures/common/caulk" ) ) {
-                                       delete *p1;
-                                       p1 = faceList.erase( p1 );    // duplicate plane
-                               }
-                               else
-                               {
-                                       delete *p2;
-                                       p2 = faceList.erase( p2 );    // duplicate plane
-                               }
+                cnt++;
+                break;
+            }
+        }
+
+        if (p2 == faceList.end()) {
+            p1++;
+        }
+    }
 
-                               cnt++;
-                               break;
-                       }
-               }
-
-               if ( p2 == faceList.end() ) {
-                       p1++;
-               }
-       }
-
-       //+djbob kill planes with bad normal, they are more of a nuisance than losing a brush
-       chkPlane = faceList.begin();
-       while ( chkPlane != faceList.end() )
-       {
-               if ( VectorLength( ( *chkPlane )->normal ) == 0 ) { // plane has bad normal
-                       delete *chkPlane;
-                       chkPlane = faceList.erase( chkPlane );
-                       cnt++;
-               }
-               else {
-                       chkPlane++;
-               }
-       }
-       //-djbob
-
-       if ( pointList.size() == 0 ) { // if points may not have been built, build them
+    //+djbob kill planes with bad normal, they are more of a nuisance than losing a brush
+    chkPlane = faceList.begin();
+    while (chkPlane != faceList.end()) {
+        if (VectorLength((*chkPlane)->normal) == 0) { // plane has bad normal
+            delete *chkPlane;
+            chkPlane = faceList.erase(chkPlane);
+            cnt++;
+        } else {
+            chkPlane++;
+        }
+    }
+    //-djbob
+
+    if (pointList.size() == 0) { // if points may not have been built, build them
 /*             if(BuildPoints() == 0)  // just let the planes die if they are all bad
             return cnt;*/
-               BuildPoints();
-       }
-
-       chkPlane = faceList.begin();
-       while ( chkPlane != faceList.end() )
-       {
-               if ( ( *chkPlane )->IsRedundant( pointList ) ) { // checks that plane "0wnz" :), 3 or more points
-                       delete *chkPlane;
-                       chkPlane = faceList.erase( chkPlane );
-                       cnt++;
-               }
-               else{
-                       chkPlane++;
-               }
-       }
-
-       return cnt;
-}
-
-bool DBrush::GetBounds( vec3_t min, vec3_t max ){
-       BuildBounds();
-
-       if ( !bBoundsBuilt ) {
-               return false;
-       }
-
-       VectorCopy( bbox_min, min );
-       VectorCopy( bbox_max, max );
-
-       return true;
-}
-
-bool DBrush::BBoxCollision( DBrush* chkBrush ){
-       vec3_t min1, min2;
-       vec3_t max1, max2;
-
-       GetBounds( min1, max1 );
-       chkBrush->GetBounds( min2, max2 );
-
-       if ( min1[0] >= max2[0] ) {
-               return false;
-       }
-       if ( min1[1] >= max2[1] ) {
-               return false;
-       }
-       if ( min1[2] >= max2[2] ) {
-               return false;
-       }
-
-       if ( max1[0] <= min2[0] ) {
-               return false;
-       }
-       if ( max1[1] <= min2[1] ) {
-               return false;
-       }
-       if ( max1[2] <= min2[2] ) {
-               return false;
-       }
-
-       return true;
-}
-
-DPlane* DBrush::HasPlane( DPlane* chkPlane ){
-       for ( std::list<DPlane *>::const_iterator brushPlane = faceList.begin(); brushPlane != faceList.end(); brushPlane++ )
-       {
-               if ( **brushPlane == *chkPlane ) {
-                       return *brushPlane;
-               }
-       }
-       return NULL;
-}
-
-bool DBrush::IsCutByPlane( DPlane *cuttingPlane ){
-       bool isInFront;
-
-       if ( pointList.size() == 0 ) {
-               if ( BuildPoints() == 0 ) {
-                       return false;
-               }
-       }
-
-       std::list<DPoint *>::const_iterator chkPnt = pointList.begin();
-
-       if ( chkPnt == pointList.end() ) {
-               return false;
-       }
-
-       float dist = cuttingPlane->DistanceToPoint( ( *chkPnt )->_pnt );
-
-       if ( dist > MAX_ROUND_ERROR ) {
-               isInFront = false;
-       }
-       else if ( dist < MAX_ROUND_ERROR ) {
-               isInFront = true;
-       }
-       else{
-               return true;
-       }
-
-       for ( chkPnt++ = pointList.begin(); chkPnt != pointList.end(); chkPnt++ )
-       {
-               dist = cuttingPlane->DistanceToPoint( ( *chkPnt )->_pnt );
-
-               if ( dist > MAX_ROUND_ERROR ) {
-                       if ( isInFront ) {
-                               return true;
-                       }
-               }
-               else if ( dist < MAX_ROUND_ERROR ) {
-                       if ( !isInFront ) {
-                               return true;
-                       }
-               }
-               else{
-                       return true;
-               }
-       }
-
-       return false;
-}
-
-
-scene::Node* DBrush::BuildInRadiant( bool allowDestruction, int* changeCnt, scene::Node* entity ){
-       if ( allowDestruction ) {
-               bool kill = true;
-
-               for ( std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
-               {
-                       if ( ( *chkPlane )->m_bChkOk ) {
-                               kill = false;
-                               break;
-                       }
-               }
-               if ( kill ) {
-                       return NULL;
-               }
-       }
-
-       //+djbob: fixed bug when brush had no faces "phantom brush" in radiant.
-       if ( faceList.size() < 4 ) {
-               globalErrorStream() << "Possible Phantom Brush Found, will not rebuild\n";
-               return NULL;
-       }
-       //-djbob
-
-       NodeSmartReference node( GlobalBrushCreator().createBrush() );
-
-       for ( std::list<DPlane *>::const_iterator buildPlane = faceList.begin(); buildPlane != faceList.end(); buildPlane++ ) {
-               if ( ( *buildPlane )->AddToBrush( node ) && changeCnt ) {
-                       ( *changeCnt )++;
-               }
-       }
-
-       if ( entity ) {
-               Node_getTraversable( *entity )->insert( node );
-       }
-       else {
-               Node_getTraversable( GlobalRadiant().getMapWorldEntity() )->insert( node );
-       }
-
-       QER_entity = entity;
-       QER_brush = node.get_pointer();
-
-       return node.get_pointer();
-}
-
-void DBrush::CutByPlane( DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2 ){
-       if ( !IsCutByPlane( cutPlane ) ) {
-               *newBrush1 = NULL;
-               *newBrush2 = NULL;
-               return;
-       }
-
-       DBrush* b1 = new DBrush;
-       DBrush* b2 = new DBrush;
-
-       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 );
-       }
-
-       b1->AddFace( cutPlane->points[0], cutPlane->points[1], cutPlane->points[2], NULL );
-       b2->AddFace( cutPlane->points[2], cutPlane->points[1], cutPlane->points[0], NULL );
-
-       b1->RemoveRedundantPlanes();
-       b2->RemoveRedundantPlanes();
-
-       *newBrush1 = b1;
-       *newBrush2 = b2;
-}
-
-bool DBrush::IntersectsWith( DBrush *chkBrush ){
-       if ( pointList.size() == 0 ) {
-               if ( BuildPoints() == 0 ) {
-                       return false;   // invalid brush!!!!
-
-               }
-       }
-       if ( chkBrush->pointList.size() == 0 ) {
-               if ( chkBrush->BuildPoints() == 0 ) {
-                       return false;   // invalid brush!!!!
-
-               }
-       }
-       if ( !BBoxCollision( chkBrush ) ) {
-               return false;
-       }
-
-       std::list<DPlane *>::const_iterator iplPlane;
-
-       for ( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++ )
-       {
-
-               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;
-                               break;
-                       }
-               }
-               if ( allInFront ) {
-                       return false;
-               }
-       }
-
-       for ( iplPlane = chkBrush->faceList.begin(); iplPlane != chkBrush->faceList.end(); iplPlane++ )
-       {
-               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;
-                               break;
-                       }
-               }
-               if ( allInFront ) {
-                       return false;
-               }
-       }
-
-       return true;
-}
-
-bool DBrush::IntersectsWith( DPlane* p1, DPlane* p2, vec3_t v ) {
-       vec3_t vDown = { 0, 0, -1 };
-
-       std::list<DPlane *>::const_iterator iplPlane;
-       for ( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++ ) {
-               DPlane* p = ( *iplPlane );
-
-               vec_t d = DotProduct( p->normal, vDown );
-               if ( d >= 0 ) {
-                       continue;
-               }
-               if ( p->PlaneIntersection( p1, p2, v ) ) {
-                       if ( PointPosition( v ) != POINT_OUT_BRUSH ) {
-                               return true;
-                       }
-               }
-       }
-
-       return false;
-}
-
-void DBrush::BuildBounds(){
-       if ( !bBoundsBuilt ) {
-               if ( pointList.size() == 0 ) { // if points may not have been built, build them
-                       if ( BuildPoints() == 0 ) {
-                               return;
-                       }
-               }
-
-               std::list<DPoint *>::const_iterator first = pointList.begin();
-               VectorCopy( ( *first )->_pnt, bbox_min );
-               VectorCopy( ( *first )->_pnt, bbox_max );
-
-               std::list<DPoint *>::const_iterator point = pointList.begin();
-               for ( point++; point != pointList.end(); point++ )
-               {
-                       if ( ( *point )->_pnt[0] > bbox_max[0] ) {
-                               bbox_max[0] = ( *point )->_pnt[0];
-                       }
-                       if ( ( *point )->_pnt[1] > bbox_max[1] ) {
-                               bbox_max[1] = ( *point )->_pnt[1];
-                       }
-                       if ( ( *point )->_pnt[2] > bbox_max[2] ) {
-                               bbox_max[2] = ( *point )->_pnt[2];
-                       }
-
-                       if ( ( *point )->_pnt[0] < bbox_min[0] ) {
-                               bbox_min[0] = ( *point )->_pnt[0];
-                       }
-                       if ( ( *point )->_pnt[1] < bbox_min[1] ) {
-                               bbox_min[1] = ( *point )->_pnt[1];
-                       }
-                       if ( ( *point )->_pnt[2] < bbox_min[2] ) {
-                               bbox_min[2] = ( *point )->_pnt[2];
-                       }
-               }
-
-               bBoundsBuilt = true;
-       }
-}
-
-bool DBrush::BBoxTouch( DBrush *chkBrush ){
-       vec3_t min1, min2;
-       vec3_t max1, max2;
-
-       GetBounds( min1, max1 );
-       chkBrush->GetBounds( min2, max2 );
-
-       if ( ( min1[0] - max2[0] ) > MAX_ROUND_ERROR ) {
-               return false;
-       }
-       if ( ( min1[1] - max2[1] ) > MAX_ROUND_ERROR ) {
-               return false;
-       }
-       if ( ( min1[2] - max2[2] ) > MAX_ROUND_ERROR ) {
-               return false;
-       }
-
-       if ( ( min2[0] - max1[0] ) > MAX_ROUND_ERROR ) {
-               return false;
-       }
-       if ( ( min2[1] - max1[1] ) > MAX_ROUND_ERROR ) {
-               return false;
-       }
-       if ( ( min2[2] - max1[2] ) > MAX_ROUND_ERROR ) {
-               return false;
-       }
-
-       int cnt = 0;
-
-       if ( ( min2[0] - max1[0] ) == 0 ) {
-               cnt++;
-       }
-
-       if ( ( min2[1] - max1[1] ) == 0 ) {
-               cnt++;
-       }
-
-       if ( ( min2[2] - max1[2] ) == 0 ) {
-               cnt++;
-       }
-
-       if ( ( min1[0] - max2[0] ) == 0 ) {
-               cnt++;
-       }
-
-       if ( ( min1[1] - max2[1] ) == 0 ) {
-               cnt++;
-       }
-
-       if ( ( min1[2] - max2[2] ) == 0 ) {
-               cnt++;
-       }
-
-       if ( cnt > 1 ) {
-               return false;
-       }
-
-       return true;
-}
-
-void DBrush::ResetChecks( std::list<Str>* exclusionList ){
-       for ( std::list<DPlane *>::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ )
-       {
-               bool set = false;
-
-               if ( exclusionList ) {
-                       for ( std::list<Str>::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++ )
-                       {
-                               if ( strstr( ( *resetPlane )->m_shader.c_str(), eTexture->GetBuffer() ) ) {
-                                       set = true;
-                                       break;
-                               }
-                       }
-               }
-
-               ( *resetPlane )->m_bChkOk = set;
-       }
-}
-
-DPlane* DBrush::HasPlaneInverted( DPlane *chkPlane ){
-       for ( std::list<DPlane *>::const_iterator brushPlane = faceList.begin(); brushPlane != faceList.end(); brushPlane++ )
-       {
-               if ( **brushPlane != *chkPlane ) {
-                       if ( fabs( ( *brushPlane )->_d + chkPlane->_d ) < 0.1 ) {
-                               return ( *brushPlane );
-                       }
-               }
-       }
-       return NULL;
-}
-
-bool DBrush::HasTexture( const char *textureName ){
-       for ( std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
-       {
-               if ( strstr( ( *chkPlane )->m_shader.c_str(), textureName ) ) {
-                       return true;
-               }
-
-       }
-       return false;
-}
-
-bool DBrush::IsDetail(){
-       for ( std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
-       {
-               if ( ( *chkPlane )->texInfo.contents & FACE_DETAIL ) {
-                       return true;
-               }
-
-       }
-       return false;
-}
-
-void DBrush::BuildFromWinding( DWinding *w ){
-       if ( w->numpoints < 3 ) {
-               globalErrorStream() << "Winding has invalid number of points";
-               return;
-       }
-
-       DPlane* wPlane = w->WindingPlane();
-
-       DWinding* w2;
-       w2 = w->CopyWinding();
-       int i;
-       for ( i = 0; i < w2->numpoints; i++ )
-               VectorAdd( w2->p[i], wPlane->normal, w2->p[i] );
-
-       AddFace( w2->p[0], w2->p[1], w2->p[2], NULL );
-       AddFace( w->p[2], w->p[1], w->p[0], NULL );
-
-       for ( i = 0; i < w->numpoints - 1; i++ )
-               AddFace( w2->p[i], w->p[i], w->p[i + 1], NULL );
-       AddFace( w2->p[w->numpoints - 1], w->p[w->numpoints - 1], w->p[0], NULL );
-
-       delete wPlane;
-       delete w2;
-}
-
-void DBrush::SaveToFile( FILE *pFile ){
-       fprintf( pFile, "{\n" );
-
-       for ( std::list<DPlane *>::const_iterator pp = faceList.begin(); pp != faceList.end(); pp++ )
-       {
-               char buffer[512];
-
-               sprintf( buffer, "( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) %s %.0f %.0f %f %f %.0f 0 0 0\n",
-                                ( *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 )->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 );
-
-               fprintf( pFile, "%s", buffer );
-       }
-
-       fprintf( pFile, "}\n" );
-}
-
-void DBrush::Rotate( vec3_t vOrigin, vec3_t vRotation ){
-       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 );
-
-               ( *rotPlane )->Rebuild();
-       }
-}
-
-void DBrush::RotateAboutCentre( vec3_t vRotation ){
-       vec3_t min, max, centre;
-       GetBounds( min, max );
-       VectorAdd( min, max, centre );
-       VectorScale( centre, 0.5f, centre );
-
-       Rotate( centre, vRotation );
-}
-
-bool DBrush::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 ){
-       if ( textureName ) {
-               bool changed = false;
-               for ( std::list<DPlane *>::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ )
-               {
-                       if ( !strcmp( ( *resetPlane )->m_shader.c_str(), textureName ) ) {
-                               if ( bResetTextureName ) {
-                                       ( *resetPlane )->m_shader = newTextureName;
-                               }
-
-                               if ( bResetScale[0] ) {
-                                       ( *resetPlane )->texInfo.m_texdef.scale[0] = fScale[0];
-                               }
-                               if ( bResetScale[1] ) {
-                                       ( *resetPlane )->texInfo.m_texdef.scale[1] = fScale[1];
-                               }
-
-                               if ( bResetShift[0] ) {
-                                       ( *resetPlane )->texInfo.m_texdef.shift[0] = fShift[0];
-                               }
-                               if ( bResetShift[1] ) {
-                                       ( *resetPlane )->texInfo.m_texdef.shift[1] = fShift[1];
-                               }
-
-                               if ( bResetRotation ) {
-                                       ( *resetPlane )->texInfo.m_texdef.rotate = (float)rotation;
-                               }
-
-                               changed = true;
-                       }
-               }
-               return changed; // no point rebuilding unless we need to, only slows things down
-       }
-       else
-       {
-               for ( std::list<DPlane *>::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ )
-               {
-                       if ( bResetTextureName ) {
-                               ( *resetPlane )->m_shader = newTextureName;
-                       }
-
-                       if ( bResetScale[0] ) {
-                               ( *resetPlane )->texInfo.m_texdef.scale[0] = fScale[0];
-                       }
-                       if ( bResetScale[1] ) {
-                               ( *resetPlane )->texInfo.m_texdef.scale[1] = fScale[1];
-                       }
-
-                       if ( bResetShift[0] ) {
-                               ( *resetPlane )->texInfo.m_texdef.shift[0] = fShift[0];
-                       }
-                       if ( bResetShift[1] ) {
-                               ( *resetPlane )->texInfo.m_texdef.shift[1] = fShift[1];
-                       }
-
-                       if ( bResetRotation ) {
-                               ( *resetPlane )->texInfo.m_texdef.rotate = (float)rotation;
-                       }
-               }
-               return true;
-       }
-}
-
-bool DBrush::operator ==( DBrush* other ){
-       std::list<DPlane *>::const_iterator chkPlane;
-
-       for ( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
-       {
-               if ( !other->HasPlane( ( *chkPlane ) ) ) {
-                       return false;
-               }
-       }
-
-       for ( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
-       {
-               if ( !HasPlane( ( *chkPlane ) ) ) {
-                       return false;
-               }
-       }
-
-       return true;
-}
-
-DPlane* DBrush::AddFace( const vec3_t va, const vec3_t vb, const vec3_t vc, const char *textureName, bool bDetail ){
-       bBoundsBuilt = false;
-       DPlane* newFace = new DPlane( va, vb, vc, textureName, bDetail );
-       faceList.push_back( newFace );
-
-       return newFace;
-}
-
-DPlane* DBrush::FindPlaneWithClosestNormal( vec_t* normal ) {
-       vec_t bestDot = -2;
-       DPlane* bestDotPlane = NULL;
-       std::list<DPlane *>::const_iterator chkPlane;
-       for ( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ ) {
-               DPlane* pPlane = ( *chkPlane );
-
-               vec_t dot = DotProduct( pPlane->normal, normal );
-               if ( dot > bestDot ) {
-                       bestDot = dot;
-                       bestDotPlane = pPlane;
-               }
-       }
-
-       return bestDotPlane;
-}
-
-int DBrush::FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ) {
-       int numpnts = 0;
-
-       if ( !maxpnts ) {
-               return 0;
-       }
-
-       BuildPoints();
-
-       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 ) {
-                       pnts[numpnts] = point;
-                       numpnts++;
-
-                       if ( numpnts >= maxpnts ) {
-                               return numpnts;
-                       }
-
-               }
-       }
-
-       return numpnts;
-}
-
-void DBrush::RemovePlane( DPlane* plane ) {
-       bBoundsBuilt = false;
-       for ( std::list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) {
-               if ( *deadPlane == plane ) {
-                       delete *deadPlane;
-                       faceList.remove( plane );
-               }
-       }
+        BuildPoints();
+    }
+
+    chkPlane = faceList.begin();
+    while (chkPlane != faceList.end()) {
+        if ((*chkPlane)->IsRedundant(pointList)) { // checks that plane "0wnz" :), 3 or more points
+            delete *chkPlane;
+            chkPlane = faceList.erase(chkPlane);
+            cnt++;
+        } else {
+            chkPlane++;
+        }
+    }
+
+    return cnt;
+}
+
+bool DBrush::GetBounds(vec3_t min, vec3_t max)
+{
+    BuildBounds();
+
+    if (!bBoundsBuilt) {
+        return false;
+    }
+
+    VectorCopy(bbox_min, min);
+    VectorCopy(bbox_max, max);
+
+    return true;
+}
+
+bool DBrush::BBoxCollision(DBrush *chkBrush)
+{
+    vec3_t min1, min2;
+    vec3_t max1, max2;
+
+    GetBounds(min1, max1);
+    chkBrush->GetBounds(min2, max2);
+
+    if (min1[0] >= max2[0]) {
+        return false;
+    }
+    if (min1[1] >= max2[1]) {
+        return false;
+    }
+    if (min1[2] >= max2[2]) {
+        return false;
+    }
+
+    if (max1[0] <= min2[0]) {
+        return false;
+    }
+    if (max1[1] <= min2[1]) {
+        return false;
+    }
+    if (max1[2] <= min2[2]) {
+        return false;
+    }
+
+    return true;
+}
+
+DPlane *DBrush::HasPlane(DPlane *chkPlane)
+{
+    for (std::list<DPlane *>::const_iterator brushPlane = faceList.begin();
+         brushPlane != faceList.end(); brushPlane++) {
+        if (**brushPlane == *chkPlane) {
+            return *brushPlane;
+        }
+    }
+    return NULL;
+}
+
+bool DBrush::IsCutByPlane(DPlane *cuttingPlane)
+{
+    bool isInFront;
+
+    if (pointList.size() == 0) {
+        if (BuildPoints() == 0) {
+            return false;
+        }
+    }
+
+    std::list<DPoint *>::const_iterator chkPnt = pointList.begin();
+
+    if (chkPnt == pointList.end()) {
+        return false;
+    }
+
+    float dist = cuttingPlane->DistanceToPoint((*chkPnt)->_pnt);
+
+    if (dist > MAX_ROUND_ERROR) {
+        isInFront = false;
+    } else if (dist < MAX_ROUND_ERROR) {
+        isInFront = true;
+    } else {
+        return true;
+    }
+
+    for (chkPnt++ = pointList.begin(); chkPnt != pointList.end(); chkPnt++) {
+        dist = cuttingPlane->DistanceToPoint((*chkPnt)->_pnt);
+
+        if (dist > MAX_ROUND_ERROR) {
+            if (isInFront) {
+                return true;
+            }
+        } else if (dist < MAX_ROUND_ERROR) {
+            if (!isInFront) {
+                return true;
+            }
+        } else {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+
+scene::Node *DBrush::BuildInRadiant(bool allowDestruction, int *changeCnt, scene::Node *entity)
+{
+    if (allowDestruction) {
+        bool kill = true;
+
+        for (std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+            if ((*chkPlane)->m_bChkOk) {
+                kill = false;
+                break;
+            }
+        }
+        if (kill) {
+            return NULL;
+        }
+    }
+
+    //+djbob: fixed bug when brush had no faces "phantom brush" in radiant.
+    if (faceList.size() < 4) {
+        globalErrorStream() << "Possible Phantom Brush Found, will not rebuild\n";
+        return NULL;
+    }
+    //-djbob
+
+    NodeSmartReference node(GlobalBrushCreator().createBrush());
+
+    for (std::list<DPlane *>::const_iterator buildPlane = faceList.begin();
+         buildPlane != faceList.end(); buildPlane++) {
+        if ((*buildPlane)->AddToBrush(node) && changeCnt) {
+            (*changeCnt)++;
+        }
+    }
+
+    if (entity) {
+        Node_getTraversable(*entity)->insert(node);
+    } else {
+        Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(node);
+    }
+
+    QER_entity = entity;
+    QER_brush = node.get_pointer();
+
+    return node.get_pointer();
+}
+
+void DBrush::CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2)
+{
+    if (!IsCutByPlane(cutPlane)) {
+        *newBrush1 = NULL;
+        *newBrush2 = NULL;
+        return;
+    }
+
+    DBrush *b1 = new DBrush;
+    DBrush *b2 = new DBrush;
+
+    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);
+    }
+
+    b1->AddFace(cutPlane->points[0], cutPlane->points[1], cutPlane->points[2], NULL);
+    b2->AddFace(cutPlane->points[2], cutPlane->points[1], cutPlane->points[0], NULL);
+
+    b1->RemoveRedundantPlanes();
+    b2->RemoveRedundantPlanes();
+
+    *newBrush1 = b1;
+    *newBrush2 = b2;
+}
+
+bool DBrush::IntersectsWith(DBrush *chkBrush)
+{
+    if (pointList.size() == 0) {
+        if (BuildPoints() == 0) {
+            return false;   // invalid brush!!!!
+
+        }
+    }
+    if (chkBrush->pointList.size() == 0) {
+        if (chkBrush->BuildPoints() == 0) {
+            return false;   // invalid brush!!!!
+
+        }
+    }
+    if (!BBoxCollision(chkBrush)) {
+        return false;
+    }
+
+    std::list<DPlane *>::const_iterator iplPlane;
+
+    for (iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++) {
+
+        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;
+                break;
+            }
+        }
+        if (allInFront) {
+            return false;
+        }
+    }
+
+    for (iplPlane = chkBrush->faceList.begin(); iplPlane != chkBrush->faceList.end(); iplPlane++) {
+        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;
+                break;
+            }
+        }
+        if (allInFront) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+bool DBrush::IntersectsWith(DPlane *p1, DPlane *p2, vec3_t v)
+{
+    vec3_t vDown = {0, 0, -1};
+
+    std::list<DPlane *>::const_iterator iplPlane;
+    for (iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++) {
+        DPlane *p = (*iplPlane);
+
+        vec_t d = DotProduct(p->normal, vDown);
+        if (d >= 0) {
+            continue;
+        }
+        if (p->PlaneIntersection(p1, p2, v)) {
+            if (PointPosition(v) != POINT_OUT_BRUSH) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+void DBrush::BuildBounds()
+{
+    if (!bBoundsBuilt) {
+        if (pointList.size() == 0) { // if points may not have been built, build them
+            if (BuildPoints() == 0) {
+                return;
+            }
+        }
+
+        std::list<DPoint *>::const_iterator first = pointList.begin();
+        VectorCopy((*first)->_pnt, bbox_min);
+        VectorCopy((*first)->_pnt, bbox_max);
+
+        std::list<DPoint *>::const_iterator point = pointList.begin();
+        for (point++; point != pointList.end(); point++) {
+            if ((*point)->_pnt[0] > bbox_max[0]) {
+                bbox_max[0] = (*point)->_pnt[0];
+            }
+            if ((*point)->_pnt[1] > bbox_max[1]) {
+                bbox_max[1] = (*point)->_pnt[1];
+            }
+            if ((*point)->_pnt[2] > bbox_max[2]) {
+                bbox_max[2] = (*point)->_pnt[2];
+            }
+
+            if ((*point)->_pnt[0] < bbox_min[0]) {
+                bbox_min[0] = (*point)->_pnt[0];
+            }
+            if ((*point)->_pnt[1] < bbox_min[1]) {
+                bbox_min[1] = (*point)->_pnt[1];
+            }
+            if ((*point)->_pnt[2] < bbox_min[2]) {
+                bbox_min[2] = (*point)->_pnt[2];
+            }
+        }
+
+        bBoundsBuilt = true;
+    }
+}
+
+bool DBrush::BBoxTouch(DBrush *chkBrush)
+{
+    vec3_t min1, min2;
+    vec3_t max1, max2;
+
+    GetBounds(min1, max1);
+    chkBrush->GetBounds(min2, max2);
+
+    if ((min1[0] - max2[0]) > MAX_ROUND_ERROR) {
+        return false;
+    }
+    if ((min1[1] - max2[1]) > MAX_ROUND_ERROR) {
+        return false;
+    }
+    if ((min1[2] - max2[2]) > MAX_ROUND_ERROR) {
+        return false;
+    }
+
+    if ((min2[0] - max1[0]) > MAX_ROUND_ERROR) {
+        return false;
+    }
+    if ((min2[1] - max1[1]) > MAX_ROUND_ERROR) {
+        return false;
+    }
+    if ((min2[2] - max1[2]) > MAX_ROUND_ERROR) {
+        return false;
+    }
+
+    int cnt = 0;
+
+    if ((min2[0] - max1[0]) == 0) {
+        cnt++;
+    }
+
+    if ((min2[1] - max1[1]) == 0) {
+        cnt++;
+    }
+
+    if ((min2[2] - max1[2]) == 0) {
+        cnt++;
+    }
+
+    if ((min1[0] - max2[0]) == 0) {
+        cnt++;
+    }
+
+    if ((min1[1] - max2[1]) == 0) {
+        cnt++;
+    }
+
+    if ((min1[2] - max2[2]) == 0) {
+        cnt++;
+    }
+
+    if (cnt > 1) {
+        return false;
+    }
+
+    return true;
+}
+
+void DBrush::ResetChecks(std::list<Str> *exclusionList)
+{
+    for (std::list<DPlane *>::const_iterator resetPlane = faceList.begin();
+         resetPlane != faceList.end(); resetPlane++) {
+        bool set = false;
+
+        if (exclusionList) {
+            for (std::list<Str>::iterator eTexture = exclusionList->begin();
+                 eTexture != exclusionList->end(); eTexture++) {
+                if (strstr((*resetPlane)->m_shader.c_str(), eTexture->GetBuffer())) {
+                    set = true;
+                    break;
+                }
+            }
+        }
+
+        (*resetPlane)->m_bChkOk = set;
+    }
+}
+
+DPlane *DBrush::HasPlaneInverted(DPlane *chkPlane)
+{
+    for (std::list<DPlane *>::const_iterator brushPlane = faceList.begin();
+         brushPlane != faceList.end(); brushPlane++) {
+        if (**brushPlane != *chkPlane) {
+            if (fabs((*brushPlane)->_d + chkPlane->_d) < 0.1) {
+                return (*brushPlane);
+            }
+        }
+    }
+    return NULL;
+}
+
+bool DBrush::HasTexture(const char *textureName)
+{
+    for (std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+        if (strstr((*chkPlane)->m_shader.c_str(), textureName)) {
+            return true;
+        }
+
+    }
+    return false;
+}
+
+bool DBrush::IsDetail()
+{
+    for (std::list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+        if ((*chkPlane)->texInfo.contents & FACE_DETAIL) {
+            return true;
+        }
+
+    }
+    return false;
+}
+
+void DBrush::BuildFromWinding(DWinding *w)
+{
+    if (w->numpoints < 3) {
+        globalErrorStream() << "Winding has invalid number of points";
+        return;
+    }
+
+    DPlane *wPlane = w->WindingPlane();
+
+    DWinding *w2;
+    w2 = w->CopyWinding();
+    int i;
+    for (i = 0; i < w2->numpoints; i++)
+        VectorAdd(w2->p[i], wPlane->normal, w2->p[i]);
+
+    AddFace(w2->p[0], w2->p[1], w2->p[2], NULL);
+    AddFace(w->p[2], w->p[1], w->p[0], NULL);
+
+    for (i = 0; i < w->numpoints - 1; i++) {
+        AddFace(w2->p[i], w->p[i], w->p[i + 1], NULL);
+    }
+    AddFace(w2->p[w->numpoints - 1], w->p[w->numpoints - 1], w->p[0], NULL);
+
+    delete wPlane;
+    delete w2;
+}
+
+void DBrush::SaveToFile(FILE *pFile)
+{
+    fprintf(pFile, "{\n");
+
+    for (std::list<DPlane *>::const_iterator pp = faceList.begin(); pp != faceList.end(); pp++) {
+        char buffer[512];
+
+        sprintf(buffer, "( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) %s %.0f %.0f %f %f %.0f 0 0 0\n",
+                (*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)->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);
+
+        fprintf(pFile, "%s", buffer);
+    }
+
+    fprintf(pFile, "}\n");
+}
+
+void DBrush::Rotate(vec3_t vOrigin, vec3_t vRotation)
+{
+    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);
+        }
+
+        (*rotPlane)->Rebuild();
+    }
+}
+
+void DBrush::RotateAboutCentre(vec3_t vRotation)
+{
+    vec3_t min, max, centre;
+    GetBounds(min, max);
+    VectorAdd(min, max, centre);
+    VectorScale(centre, 0.5f, centre);
+
+    Rotate(centre, vRotation);
+}
+
+bool DBrush::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)
+{
+    if (textureName) {
+        bool changed = false;
+        for (std::list<DPlane *>::const_iterator resetPlane = faceList.begin();
+             resetPlane != faceList.end(); resetPlane++) {
+            if (!strcmp((*resetPlane)->m_shader.c_str(), textureName)) {
+                if (bResetTextureName) {
+                    (*resetPlane)->m_shader = newTextureName;
+                }
+
+                if (bResetScale[0]) {
+                    (*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0];
+                }
+                if (bResetScale[1]) {
+                    (*resetPlane)->texInfo.m_texdef.scale[1] = fScale[1];
+                }
+
+                if (bResetShift[0]) {
+                    (*resetPlane)->texInfo.m_texdef.shift[0] = fShift[0];
+                }
+                if (bResetShift[1]) {
+                    (*resetPlane)->texInfo.m_texdef.shift[1] = fShift[1];
+                }
+
+                if (bResetRotation) {
+                    (*resetPlane)->texInfo.m_texdef.rotate = (float) rotation;
+                }
+
+                changed = true;
+            }
+        }
+        return changed; // no point rebuilding unless we need to, only slows things down
+    } else {
+        for (std::list<DPlane *>::const_iterator resetPlane = faceList.begin();
+             resetPlane != faceList.end(); resetPlane++) {
+            if (bResetTextureName) {
+                (*resetPlane)->m_shader = newTextureName;
+            }
+
+            if (bResetScale[0]) {
+                (*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0];
+            }
+            if (bResetScale[1]) {
+                (*resetPlane)->texInfo.m_texdef.scale[1] = fScale[1];
+            }
+
+            if (bResetShift[0]) {
+                (*resetPlane)->texInfo.m_texdef.shift[0] = fShift[0];
+            }
+            if (bResetShift[1]) {
+                (*resetPlane)->texInfo.m_texdef.shift[1] = fShift[1];
+            }
+
+            if (bResetRotation) {
+                (*resetPlane)->texInfo.m_texdef.rotate = (float) rotation;
+            }
+        }
+        return true;
+    }
+}
+
+bool DBrush::operator==(DBrush *other)
+{
+    std::list<DPlane *>::const_iterator chkPlane;
+
+    for (chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+        if (!other->HasPlane((*chkPlane))) {
+            return false;
+        }
+    }
+
+    for (chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+        if (!HasPlane((*chkPlane))) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+DPlane *DBrush::AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const char *textureName, bool bDetail)
+{
+    bBoundsBuilt = false;
+    DPlane *newFace = new DPlane(va, vb, vc, textureName, bDetail);
+    faceList.push_back(newFace);
+
+    return newFace;
+}
+
+DPlane *DBrush::FindPlaneWithClosestNormal(vec_t *normal)
+{
+    vec_t bestDot = -2;
+    DPlane *bestDotPlane = NULL;
+    std::list<DPlane *>::const_iterator chkPlane;
+    for (chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++) {
+        DPlane *pPlane = (*chkPlane);
+
+        vec_t dot = DotProduct(pPlane->normal, normal);
+        if (dot > bestDot) {
+            bestDot = dot;
+            bestDotPlane = pPlane;
+        }
+    }
+
+    return bestDotPlane;
+}
+
+int DBrush::FindPointsForPlane(DPlane *plane, DPoint **pnts, int maxpnts)
+{
+    int numpnts = 0;
+
+    if (!maxpnts) {
+        return 0;
+    }
+
+    BuildPoints();
+
+    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) {
+            pnts[numpnts] = point;
+            numpnts++;
+
+            if (numpnts >= maxpnts) {
+                return numpnts;
+            }
+
+        }
+    }
+
+    return numpnts;
+}
+
+void DBrush::RemovePlane(DPlane *plane)
+{
+    bBoundsBuilt = false;
+    for (std::list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++) {
+        if (*deadPlane == plane) {
+            delete *deadPlane;
+            faceList.remove(plane);
+        }
+    }
 }
index 7b3e8d6..d88bee2 100644 (file)
 #include "str.h"
 
 class DPlane;
+
 class DWinding;
+
 class DPoint;
+
 class _QERFaceData;
 
-namespace scene
-{
-class Node;
-class Instance;
+namespace scene {
+    class Node;
+
+    class Instance;
 }
 
-const int POINT_IN_BRUSH  = 0;
-const int POINT_ON_BRUSH  = 1;
+const int POINT_IN_BRUSH = 0;
+const int POINT_ON_BRUSH = 1;
 const int POINT_OUT_BRUSH = 2;
 
-class DBrush
-{
+class DBrush {
 public:
-DPlane* AddFace( const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail );
-void SaveToFile( FILE* pFile );
+    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);
+
+    void RotateAboutCentre(vec3_t vRotation);
+
+    DPlane *HasPlaneInverted(DPlane *chkPlane);
+
+    DPlane *HasPlane(DPlane *chkPlane);
+
+    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();
+
+    bool HasTexture(const char *textureName);
+
+    bool IntersectsWith(DBrush *chkBrush);
+
+    bool IntersectsWith(DPlane *p1, DPlane *p2, vec3_t v);
+
+    bool IsCutByPlane(DPlane *cuttingPlane);
+
+    bool GetBounds(vec3_t min, vec3_t max);
+
+    bool HasPoint(vec3_t pnt);
+
+    bool BBoxCollision(DBrush *chkBrush);
+
+    bool BBoxTouch(DBrush *chkBrush);
+
+    int BuildPoints();
+
+    void BuildBounds();
+
+    void BuildFromWinding(DWinding *w);
+
+    scene::Node *BuildInRadiant(bool allowDestruction, int *changeCnt, scene::Node *entity = NULL);
+
+    void ResetChecks(std::list<Str> *exclusionList);
+
+    void ClearFaces();
 
-void Rotate( vec3_t vOrigin, vec3_t vRotation );
-void RotateAboutCentre( vec3_t vRotation );
+    void ClearPoints();
 
-DPlane* HasPlaneInverted( DPlane* chkPlane );
-DPlane* HasPlane( DPlane* chkPlane );
-DPlane* AddFace( const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData );
+    int RemoveRedundantPlanes(void);
 
-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();
-bool HasTexture( const char* textureName );
-bool IntersectsWith( DBrush *chkBrush );
-bool IntersectsWith( DPlane* p1, DPlane* p2, vec3_t v );
-bool IsCutByPlane( DPlane* cuttingPlane );
-bool GetBounds( vec3_t min, vec3_t max );
-bool HasPoint( vec3_t pnt );
-bool BBoxCollision( DBrush* chkBrush );
-bool BBoxTouch( DBrush* chkBrush );
+    void RemovePlane(DPlane *plane);
 
-int BuildPoints();
-void BuildBounds();
-void BuildFromWinding( DWinding* w );
-scene::Node* BuildInRadiant( bool allowDestruction, int* changeCnt, scene::Node* entity = NULL );
+    int PointPosition(vec3_t pnt);
 
-void ResetChecks( std::list<Str>* exclusionList );
 
-void ClearFaces();
-void ClearPoints();
+    void CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2);
 
-int RemoveRedundantPlanes( void );
-void RemovePlane( DPlane* plane );
-int PointPosition( vec3_t pnt );
+    void LoadFromBrush(scene::Instance &brush, bool textured);
 
+    void AddPoint(vec3_t pnt);
 
-void CutByPlane( DPlane* cutPlane, DBrush** newBrush1, DBrush** newBrush2 );
+    DPlane *FindPlaneWithClosestNormal(vec_t *normal);
 
-void LoadFromBrush( scene::Instance& brush, bool textured );
-void AddPoint( vec3_t pnt );
+    int FindPointsForPlane(DPlane *plane, DPoint **pnts, int maxpnts);
 
-DPlane* FindPlaneWithClosestNormal( vec_t* normal );
-int FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts );
+    DBrush(int ID = -1);
 
-DBrush( int ID = -1 );
-virtual ~DBrush();
+    virtual ~DBrush();
 
-bool operator==( DBrush* other );
+    bool operator==(DBrush *other);
 
 //     members
-scene::Node* QER_entity;
-scene::Node* QER_brush;
-std::list<DPlane*> faceList;
-std::list<DPoint*> pointList;
-int m_nBrushID;
-vec3_t bbox_min, bbox_max;
-bool bBoundsBuilt;
+    scene::Node *QER_entity;
+    scene::Node *QER_brush;
+    std::list<DPlane *> faceList;
+    std::list<DPoint *> pointList;
+    int m_nBrushID;
+    vec3_t bbox_min, bbox_max;
+    bool bBoundsBuilt;
 };
 
 //typedef CList<DBrush*, DBrush*> DBrushList;
index c75a875..f32ebee 100644 (file)
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-DEPair::DEPair(){
+DEPair::DEPair()
+{
 
 }
 
-DEPair::~DEPair(){
+DEPair::~DEPair()
+{
 
 }
 
@@ -39,7 +41,8 @@ DEPair::~DEPair(){
 // Implementation
 //////////////////////////////////////////////////////////////////////
 
-void DEPair::Build( const char *pKey, const char *pValue ){
-       key = pKey;
-       value = pValue;
+void DEPair::Build(const char *pKey, const char *pValue)
+{
+    key = pKey;
+    value = pValue;
 }
index 3b5ca3a..f3f0ceb 100644 (file)
 
 #include "str.h"
 
-class DEPair
-{
+class DEPair {
 public:
-DEPair();
-virtual ~DEPair();
+    DEPair();
 
-void Build( const char* pKey, const char* pValue );
+    virtual ~DEPair();
 
-Str key;
-Str value;
+    void Build(const char *pKey, const char *pValue);
+
+    Str key;
+    Str value;
 };
 
 //typedef CList<DEPair*, DEPair*> DEPairList;
index 22aa05a..f4d9f0b 100644 (file)
 #include "scenelib.h"
 
 
-const charbrushEntityList[] = {
-       "worldspawn",
-       "trigger_always",
-       "trigger_hurt",
-       "trigger_multiple",
-       "trigger_push",
-       "trigger_teleport",
-       "func_bobbing",
-       "func_button",
-       "func_door",
-       "func_group",
-       "func_pendulum",
-       "func_plat",
-       "func_rotating",
-       "func_static",
-       "func_timer",
-       "func_train",
-       0
+const char *brushEntityList[] = {
+        "worldspawn",
+        "trigger_always",
+        "trigger_hurt",
+        "trigger_multiple",
+        "trigger_push",
+        "trigger_teleport",
+        "func_bobbing",
+        "func_button",
+        "func_door",
+        "func_group",
+        "func_pendulum",
+        "func_plat",
+        "func_rotating",
+        "func_static",
+        "func_timer",
+        "func_train",
+        0
 };
 
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-DEntity::DEntity( const char *classname, int ID ){
-       SetClassname( classname );
-       m_nID = ID;
-       QER_Entity = NULL;
+DEntity::DEntity(const char *classname, int ID)
+{
+    SetClassname(classname);
+    m_nID = ID;
+    QER_Entity = NULL;
 }
 
-DEntity::~DEntity(){
-       ClearPatches();
-       ClearBrushes();
-       ClearEPairs();
+DEntity::~DEntity()
+{
+    ClearPatches();
+    ClearBrushes();
+    ClearEPairs();
 }
 
 //////////////////////////////////////////////////////////////////////
 // Implementation
 //////////////////////////////////////////////////////////////////////
 
-void DEntity::ClearBrushes(){
-       for ( std::list<DBrush *>::const_iterator deadBrush = brushList.begin(); deadBrush != brushList.end(); deadBrush++ )
-       {
-               delete *deadBrush;
-       }
-       brushList.clear();
+void DEntity::ClearBrushes()
+{
+    for (std::list<DBrush *>::const_iterator deadBrush = brushList.begin(); deadBrush != brushList.end(); deadBrush++) {
+        delete *deadBrush;
+    }
+    brushList.clear();
 }
 
-void DEntity::ClearPatches(){
-       for ( std::list<DPatch *>::const_iterator deadPatch = patchList.begin(); deadPatch != patchList.end(); deadPatch++ )
-       {
-               delete *deadPatch;
-       }
-       patchList.clear();
-}
-
-DPatch* DEntity::NewPatch(){
-       DPatch* newPatch = new DPatch;
-
-       patchList.push_back( newPatch );
-
-       return newPatch;
-}
+void DEntity::ClearPatches()
+{
+    for (std::list<DPatch *>::const_iterator deadPatch = patchList.begin(); deadPatch != patchList.end(); deadPatch++) {
+        delete *deadPatch;
+    }
+    patchList.clear();
+}
 
-DBrush* DEntity::NewBrush( int ID ){
-       DBrush* newBrush = new DBrush( ID );
+DPatch *DEntity::NewPatch()
+{
+    DPatch *newPatch = new DPatch;
 
-       brushList.push_back( newBrush );
+    patchList.push_back(newPatch);
 
-       return newBrush;
+    return newPatch;
 }
 
-char* getNextBracket( char* s ){
-       char* p = s;
-       while ( *p )
-       {
-               p++;
-               if ( *p == '(' ) {
-                       break;
-               }
-       }
+DBrush *DEntity::NewBrush(int ID)
+{
+    DBrush *newBrush = new DBrush(ID);
+
+    brushList.push_back(newBrush);
 
-       return p;
+    return newBrush;
 }
 
-bool DEntity::LoadFromPrt( char *filename ){
-       CPortals portals;
-       strcpy( portals.fn, filename );
-       portals.Load();
+char *getNextBracket(char *s)
+{
+    char *p = s;
+    while (*p) {
+        p++;
+        if (*p == '(') {
+            break;
+        }
+    }
 
-       if ( portals.node_count == 0 ) {
-               return false;
-       }
+    return p;
+}
 
-       ClearBrushes();
-       ClearEPairs();
+bool DEntity::LoadFromPrt(char *filename)
+{
+    CPortals portals;
+    strcpy(portals.fn, filename);
+    portals.Load();
+
+    if (portals.node_count == 0) {
+        return false;
+    }
+
+    ClearBrushes();
+    ClearEPairs();
+
+    bool build = false;
+    for (unsigned int i = 0; i < portals.node_count; i++) {
+        build = false;
+        DBrush *brush = NewBrush();
+
+        for (unsigned int j = 0; j < portals.node[i].portal_count; j++) {
+            for (unsigned int k = 0; k < portals.node[i].portal[j].point_count - 2; k++) {
+                vec3_t v1, v2, normal, n;
+                VectorSubtract(portals.node[i].portal[j].point[k + 2].p, portals.node[i].portal[j].point[k + 1].p, v1);
+                VectorSubtract(portals.node[i].portal[j].point[k].p, portals.node[i].portal[j].point[k + 1].p, v2);
+                CrossProduct(v1, v2, n);
+                VectorNormalize(n, v2);
+
+                if (k == 0) {
+                    VectorCopy(v2, normal);
+                } else {
+                    VectorSubtract(v2, normal, v1);
+                    if (VectorLength(v1) > 0.01) {
+                        build = true;
+                        break;
+                    }
+                }
+            }
+
+            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);
+            } 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);
+            }
+        }
+        if (build) {
+            brush->BuildInRadiant(false, NULL);
+        }
+    }
+
+    return true;
+}
+
+DPlane *DEntity::AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData *faceData, int ID)
+{
+    DBrush *buildBrush = GetBrushForID(ID);
+    return buildBrush->AddFace(va, vb, vc, faceData);
+    // slow, dont use much
+}
 
-       bool build = false;
-       for ( unsigned int i = 0; i < portals.node_count; i++ )
-       {
-               build = false;
-               DBrush* brush = NewBrush();
+DBrush *DEntity::GetBrushForID(int ID)
+{
+    DBrush *buildBrush = NULL;
 
-               for ( unsigned int j = 0; j < portals.node[i].portal_count; j++ )
-               {
-                       for ( unsigned int k = 0; k < portals.node[i].portal[j].point_count - 2; k++ )
-                       {
-                               vec3_t v1, v2, normal, n;
-                               VectorSubtract( portals.node[i].portal[j].point[k + 2].p, portals.node[i].portal[j].point[k + 1].p, v1 );
-                               VectorSubtract( portals.node[i].portal[j].point[k].p, portals.node[i].portal[j].point[k + 1].p, v2 );
-                               CrossProduct( v1, v2, n );
-                               VectorNormalize( n, v2 );
+    for (std::list<DBrush *>::const_iterator chkBrush = brushList.begin(); chkBrush != brushList.end(); chkBrush++) {
+        if ((*chkBrush)->m_nBrushID == ID) {
+            buildBrush = (*chkBrush);
+            break;
+        }
+    }
 
-                               if ( k == 0 ) {
-                                       VectorCopy( v2, normal );
-                               }
-                               else
-                               {
-                                       VectorSubtract( v2, normal, v1 );
-                                       if ( VectorLength( v1 ) > 0.01 ) {
-                                               build = true;
-                                               break;
-                                       }
-                               }
-                       }
+    if (!buildBrush) {
+        buildBrush = NewBrush(ID);
+    }
 
-                       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 );
-                       }
-                       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 );
-                       }
-               }
-               if ( build ) {
-                       brush->BuildInRadiant( false, NULL );
-               }
-       }
+    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);
+        }
+    }
+};
 
-       return true;
+template<typename Functor>
+inline const Functor &Scene_forEachSelectedBrush(const Functor &functor)
+{
+    GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor<Functor>(functor));
+    return functor;
 }
 
-DPlane* DEntity::AddFaceToBrush( vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID ){
-       DBrush* buildBrush = GetBrushForID( ID );
-       return buildBrush->AddFace( va, vb, vc, faceData );
-       // slow, dont use much
+void DEntity_loadBrush(DEntity &entity, scene::Instance &brush)
+{
+    DBrush *loadBrush = entity.NewBrush(static_cast<int>( entity.brushList.size()));
+    loadBrush->LoadFromBrush(brush, true);
 }
 
-DBrush* DEntity::GetBrushForID( int ID ){
-       DBrush* buildBrush = NULL;
+typedef ReferenceCaller<DEntity, void(scene::Instance &), DEntity_loadBrush> DEntityLoadBrushCaller;
 
-       for ( std::list<DBrush *>::const_iterator chkBrush = brushList.begin(); chkBrush != brushList.end(); chkBrush++ )
-       {
-               if ( ( *chkBrush )->m_nBrushID == ID ) {
-                       buildBrush = ( *chkBrush );
-                       break;
-               }
-       }
+void DEntity::LoadSelectedBrushes()
+{
+    ClearBrushes();
+    ClearEPairs();
 
-       if ( !buildBrush ) {
-               buildBrush = NewBrush( ID );
-       }
-
-       return buildBrush;
+    Scene_forEachSelectedBrush(DEntityLoadBrushCaller(*this));
 }
 
 template<typename Functor>
-class BrushSelectedVisitor : public SelectionSystem::Visitor
-{
-const Functor& m_functor;
+class PatchSelectedVisitor : 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 );
-       }
-}
+    PatchSelectedVisitor(const Functor &functor) : m_functor(functor)
+    {
+    }
+
+    void visit(scene::Instance &instance) const
+    {
+        if (Node_isPatch(instance.path().top())) {
+            m_functor(instance);
+        }
+    }
 };
 
 template<typename Functor>
-inline const Functor& Scene_forEachSelectedBrush( const Functor& functor ){
-       GlobalSelectionSystem().foreachSelected( BrushSelectedVisitor<Functor>( functor ) );
-       return functor;
+inline const Functor &Scene_forEachSelectedPatch(const Functor &functor)
+{
+    GlobalSelectionSystem().foreachSelected(PatchSelectedVisitor<Functor>(functor));
+    return functor;
 }
 
-void DEntity_loadBrush( DEntity& entity, scene::Instance& brush ){
-       DBrush* loadBrush = entity.NewBrush( static_cast<int>( entity.brushList.size() ) );
-       loadBrush->LoadFromBrush( brush, true );
+void DEntity_loadPatch(DEntity &entity, scene::Instance &patch)
+{
+    DPatch *loadPatch = entity.NewPatch();
+    loadPatch->LoadFromPatch(patch);
 }
-typedef ReferenceCaller<DEntity, void(scene::Instance&), DEntity_loadBrush> DEntityLoadBrushCaller;
 
-void DEntity::LoadSelectedBrushes(){
-       ClearBrushes();
-       ClearEPairs();
+typedef ReferenceCaller<DEntity, void(scene::Instance &), DEntity_loadPatch> DEntityLoadPatchCaller;
 
-       Scene_forEachSelectedBrush( DEntityLoadBrushCaller( *this ) );
+void DEntity::LoadSelectedPatches()
+{
+    ClearPatches();
+    ClearEPairs();
+
+    Scene_forEachSelectedPatch(DEntityLoadPatchCaller(*this));
 }
 
-template<typename Functor>
-class PatchSelectedVisitor : public SelectionSystem::Visitor
+bool *DEntity::BuildIntersectList()
 {
-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 );
-       }
-}
-};
+    int max = GetIDMax();
+    if (max == 0) {
+        return NULL;
+    }
 
-template<typename Functor>
-inline const Functor& Scene_forEachSelectedPatch( const Functor& functor ){
-       GlobalSelectionSystem().foreachSelected( PatchSelectedVisitor<Functor>( functor ) );
-       return functor;
-}
+    bool *pbIntList = new bool[max];
+    memset(pbIntList, 0, sizeof(bool) * (max));
+
+    for (std::list<DBrush *>::const_iterator pB1 = brushList.begin(); pB1 != brushList.end(); 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;
+            }
+        }
+    }
 
-void DEntity_loadPatch( DEntity& entity, scene::Instance& patch ){
-       DPatch* loadPatch = entity.NewPatch();
-       loadPatch->LoadFromPatch( patch );
+    return pbIntList;
 }
-typedef ReferenceCaller<DEntity, void(scene::Instance&), DEntity_loadPatch> DEntityLoadPatchCaller;
 
-void DEntity::LoadSelectedPatches(){
-       ClearPatches();
-       ClearEPairs();
-
-       Scene_forEachSelectedPatch( DEntityLoadPatchCaller( *this ) );
-}
-
-bool* DEntity::BuildIntersectList(){
-       int max = GetIDMax();
-       if ( max == 0 ) {
-               return NULL;
-       }
-
-       bool* pbIntList = new bool[max];
-       memset( pbIntList, 0, sizeof( bool ) * ( max ) );
-
-       for ( std::list<DBrush *>::const_iterator pB1 = brushList.begin(); pB1 != brushList.end(); 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;
-                       }
-               }
-       }
-
-       return pbIntList;
-}
-
-bool* DEntity::BuildDuplicateList(){
-       int max = GetIDMax();
-       if ( max == 0 ) {
-               return NULL;
-       }
-
-       bool* pbDupList = new bool[max];
-       memset( pbDupList, 0, sizeof( bool ) * ( max ) );
-
-       for ( std::list<DBrush *>::const_iterator pB1 = brushList.begin(); pB1 != brushList.end(); 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;
-                       }
-               }
-       }
-
-       return pbDupList;
-}
-
-void DEntity::SelectBrushes( bool *selectList ){
-       if ( selectList == NULL ) {
-               return;
-       }
-
-       GlobalSelectionSystem().setSelectedAll( false );
-
-       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( NodeReference( *( *pBrush )->QER_brush ) );
-                       Instance_getSelectable( *GlobalSceneGraph().find( path ) )->setSelected( true );
-                       path.pop();
-               }
-       }
-}
-
-bool DEntity::LoadFromEntity( scene::Node& ent, bool bLoadPatches ) {
-       ClearPatches();
-       ClearBrushes();
-       ClearEPairs();
-
-       QER_Entity = &ent;
-
-       LoadEPairList( Node_getEntity( ent ) );
-
-       bool keep = false;
-       int i;
-       for ( i = 0; brushEntityList[i]; i++ )
-       {
-               if ( string_equal_nocase( brushEntityList[i], m_Classname ) ) {
-                       keep = true;
-                       break;
-               }
-       }
-
-       if ( !keep ) {
-               return false;
-       }
-
-       if ( Node_getTraversable( ent ) ) {
-               class load_brushes_t : public scene::Traversable::Walker
-               {
-               DEntity* m_entity;
-               mutable int m_count;
-public:
-               load_brushes_t( DEntity* entity )
-                       : m_entity( entity ), m_count( 0 ){
-               }
-               bool pre( scene::Node& node ) const {
-                       scene::Path path( NodeReference( GlobalSceneGraph().root() ) );
-                       path.push( NodeReference( *m_entity->QER_Entity ) );
-                       path.push( NodeReference( node ) );
-                       scene::Instance* instance = GlobalSceneGraph().find( path );
-                       ASSERT_MESSAGE( instance != 0, "" );
+bool *DEntity::BuildDuplicateList()
+{
+    int max = GetIDMax();
+    if (max == 0) {
+        return NULL;
+    }
 
-                       if ( Node_isPatch( node ) ) {
-                               DPatch* loadPatch = m_entity->NewPatch();
-                               loadPatch->LoadFromPatch( *instance );
-                       }
-                       else if ( Node_isBrush( node ) ) {
-                               DBrush* loadBrush = m_entity->NewBrush( m_count++ );
-                               loadBrush->LoadFromBrush( *instance, true );
-                       }
-                       return false;
-               }
-               } load_brushes( this );
+    bool *pbDupList = new bool[max];
+    memset(pbDupList, 0, sizeof(bool) * (max));
 
-               Node_getTraversable( ent )->traverse( load_brushes );
-       }
+    for (std::list<DBrush *>::const_iterator pB1 = brushList.begin(); pB1 != brushList.end(); 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;
+            }
+        }
+    }
 
-       return true;
+    return pbDupList;
 }
 
-void DEntity::RemoveNonCheckBrushes( std::list<Str>* exclusionList, bool useDetail ){
-       std::list<DBrush *>::iterator chkBrush = brushList.begin();
-
-       while ( chkBrush != brushList.end() )
-       {
-               if ( !useDetail ) {
-                       if ( ( *chkBrush )->IsDetail() ) {
-                               delete *chkBrush;
-                               chkBrush = brushList.erase( chkBrush );
-                               continue;
-                       }
-               }
+void DEntity::SelectBrushes(bool *selectList)
+{
+    if (selectList == NULL) {
+        return;
+    }
 
-               std::list<Str>::iterator eTexture;
+    GlobalSelectionSystem().setSelectedAll(false);
 
-               for ( eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++ )
-               {
-                       if ( ( *chkBrush )->HasTexture( ( *eTexture ).GetBuffer() ) ) {
-                               delete *chkBrush;
-                               chkBrush = brushList.erase( chkBrush );
-                               break;
-                       }
-               }
+    scene::Path path(NodeReference(GlobalSceneGraph().root()));
+    path.push(NodeReference(*QER_Entity));
 
-               if ( eTexture == exclusionList->end() ) {
-                       chkBrush++;
-               }
-       }
+    for (std::list<DBrush *>::const_iterator pBrush = brushList.begin(); pBrush != brushList.end(); pBrush++) {
+        if (selectList[(*pBrush)->m_nBrushID]) {
+            path.push(NodeReference(*(*pBrush)->QER_brush));
+            Instance_getSelectable(*GlobalSceneGraph().find(path))->setSelected(true);
+            path.pop();
+        }
+    }
 }
 
-void DEntity::ResetChecks( std::list<Str>* exclusionList ){
-       for ( std::list<DBrush *>::const_iterator resetBrush = brushList.begin(); resetBrush != brushList.end(); resetBrush++ )
-       {
-               ( *resetBrush )->ResetChecks( exclusionList );
-       }
+bool DEntity::LoadFromEntity(scene::Node &ent, bool bLoadPatches)
+{
+    ClearPatches();
+    ClearBrushes();
+    ClearEPairs();
+
+    QER_Entity = &ent;
+
+    LoadEPairList(Node_getEntity(ent));
+
+    bool keep = false;
+    int i;
+    for (i = 0; brushEntityList[i]; i++) {
+        if (string_equal_nocase(brushEntityList[i], m_Classname)) {
+            keep = true;
+            break;
+        }
+    }
+
+    if (!keep) {
+        return false;
+    }
+
+    if (Node_getTraversable(ent)) {
+        class load_brushes_t : public scene::Traversable::Walker {
+            DEntity *m_entity;
+            mutable int m_count;
+        public:
+            load_brushes_t(DEntity *entity)
+                    : m_entity(entity), m_count(0)
+            {
+            }
+
+            bool pre(scene::Node &node) const
+            {
+                scene::Path path(NodeReference(GlobalSceneGraph().root()));
+                path.push(NodeReference(*m_entity->QER_Entity));
+                path.push(NodeReference(node));
+                scene::Instance *instance = GlobalSceneGraph().find(path);
+                ASSERT_MESSAGE(instance != 0, "");
+
+                if (Node_isPatch(node)) {
+                    DPatch *loadPatch = m_entity->NewPatch();
+                    loadPatch->LoadFromPatch(*instance);
+                } else if (Node_isBrush(node)) {
+                    DBrush *loadBrush = m_entity->NewBrush(m_count++);
+                    loadBrush->LoadFromBrush(*instance, true);
+                }
+                return false;
+            }
+        } load_brushes(this);
+
+        Node_getTraversable(ent)->traverse(load_brushes);
+    }
+
+    return true;
+}
+
+void DEntity::RemoveNonCheckBrushes(std::list<Str> *exclusionList, bool useDetail)
+{
+    std::list<DBrush *>::iterator chkBrush = brushList.begin();
+
+    while (chkBrush != brushList.end()) {
+        if (!useDetail) {
+            if ((*chkBrush)->IsDetail()) {
+                delete *chkBrush;
+                chkBrush = brushList.erase(chkBrush);
+                continue;
+            }
+        }
+
+        std::list<Str>::iterator eTexture;
+
+        for (eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++) {
+            if ((*chkBrush)->HasTexture((*eTexture).GetBuffer())) {
+                delete *chkBrush;
+                chkBrush = brushList.erase(chkBrush);
+                break;
+            }
+        }
+
+        if (eTexture == exclusionList->end()) {
+            chkBrush++;
+        }
+    }
+}
+
+void DEntity::ResetChecks(std::list<Str> *exclusionList)
+{
+    for (std::list<DBrush *>::const_iterator resetBrush = brushList.begin();
+         resetBrush != brushList.end(); resetBrush++) {
+        (*resetBrush)->ResetChecks(exclusionList);
+    }
 }
 
-int DEntity::FixBrushes(){
-       int count = 0;
+int DEntity::FixBrushes()
+{
+    int count = 0;
 
-       for ( std::list<DBrush *>::const_iterator fixBrush = brushList.begin(); fixBrush != brushList.end(); fixBrush++ )
-       {
-               count += ( *fixBrush )->RemoveRedundantPlanes();
-       }
+    for (std::list<DBrush *>::const_iterator fixBrush = brushList.begin(); fixBrush != brushList.end(); fixBrush++) {
+        count += (*fixBrush)->RemoveRedundantPlanes();
+    }
 
-       return count;
+    return count;
 }
 
-void DEntity::BuildInRadiant( bool allowDestruction ){
-       bool makeEntity = strcmp( m_Classname, "worldspawn" ) ? true : false;
+void DEntity::BuildInRadiant(bool allowDestruction)
+{
+    bool makeEntity = strcmp(m_Classname, "worldspawn") ? true : false;
 
-       if ( makeEntity ) {
-               NodeSmartReference node( GlobalEntityCreator().createEntity( GlobalEntityClassManager().findOrInsert( m_Classname.GetBuffer(), !brushList.empty() || !patchList.empty() ) ) );
+    if (makeEntity) {
+        NodeSmartReference node(GlobalEntityCreator().createEntity(
+                GlobalEntityClassManager().findOrInsert(m_Classname.GetBuffer(),
+                                                        !brushList.empty() || !patchList.empty())));
 
-               for ( std::list<DEPair* >::const_iterator buildEPair = epairList.begin(); buildEPair != epairList.end(); buildEPair++ )
-               {
-                       Node_getEntity( node )->setKeyValue( ( *buildEPair )->key, ( *buildEPair )->value );
-               }
+        for (std::list<DEPair *>::const_iterator buildEPair = epairList.begin();
+             buildEPair != epairList.end(); buildEPair++) {
+            Node_getEntity(node)->setKeyValue((*buildEPair)->key, (*buildEPair)->value);
+        }
 
-               Node_getTraversable( GlobalSceneGraph().root() )->insert( node );
+        Node_getTraversable(GlobalSceneGraph().root())->insert(node);
 
-               for ( std::list<DBrush *>::const_iterator buildBrush = brushList.begin(); buildBrush != brushList.end(); buildBrush++ )
-                       ( *buildBrush )->BuildInRadiant( allowDestruction, NULL, node.get_pointer() );
+        for (std::list<DBrush *>::const_iterator buildBrush = brushList.begin();
+             buildBrush != brushList.end(); buildBrush++) {
+                 (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node.get_pointer());
+        }
 
-               for ( std::list<DPatch *>::const_iterator buildPatch = patchList.begin(); buildPatch != patchList.end(); buildPatch++ )
-                       ( *buildPatch )->BuildInRadiant( node.get_pointer() );
+        for (std::list<DPatch *>::const_iterator buildPatch = patchList.begin();
+             buildPatch != patchList.end(); buildPatch++) {
+                 (*buildPatch)->BuildInRadiant(node.get_pointer());
+        }
 
-               QER_Entity = node.get_pointer();
-       }
-       else
-       {
-               for ( std::list<DBrush *>::const_iterator buildBrush = brushList.begin(); buildBrush != brushList.end(); buildBrush++ )
-                       ( *buildBrush )->BuildInRadiant( allowDestruction, NULL );
+        QER_Entity = node.get_pointer();
+    } else {
+        for (std::list<DBrush *>::const_iterator buildBrush = brushList.begin();
+             buildBrush != brushList.end(); buildBrush++) {
+                 (*buildBrush)->BuildInRadiant(allowDestruction, NULL);
+        }
 
-               for ( std::list<DPatch *>::const_iterator buildPatch = patchList.begin(); buildPatch != patchList.end(); buildPatch++ )
-                       ( *buildPatch )->BuildInRadiant();
-       }
+        for (std::list<DPatch *>::const_iterator buildPatch = patchList.begin();
+             buildPatch != patchList.end(); buildPatch++) {
+                 (*buildPatch)->BuildInRadiant();
+        }
+    }
 }
 
 
+int DEntity::GetIDMax(void)
+{
+    int max = -1;
+    for (std::list<DBrush *>::const_iterator cntBrush = brushList.begin(); cntBrush != brushList.end(); cntBrush++) {
+        if ((*cntBrush)->m_nBrushID > max) {
+            max = (*cntBrush)->m_nBrushID;
+        }
+    }
+    return max + 1;
+}
 
-int DEntity::GetIDMax( void ) {
-       int max = -1;
-       for ( std::list<DBrush *>::const_iterator cntBrush = brushList.begin(); cntBrush != brushList.end(); cntBrush++ ) {
-               if ( ( *cntBrush )->m_nBrushID > max ) {
-                       max = ( *cntBrush )->m_nBrushID;
-               }
-       }
-       return max + 1;
+void DEntity::SetClassname(const char *classname)
+{
+    m_Classname = classname;
 }
 
-void DEntity::SetClassname( const char *classname ) {
-       m_Classname = classname;
+void DEntity::SaveToFile(FILE *pFile)
+{
+    fprintf(pFile, "{\n");
+
+    fprintf(pFile, "\"classname\" \"%s\"\n", (const char *) m_Classname);
+
+    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 (std::list<DBrush *>::const_iterator bp = brushList.begin(); bp != brushList.end(); bp++) {
+        (*bp)->SaveToFile(pFile);
+    }
+
+    fprintf(pFile, "}\n");
 }
 
-void DEntity::SaveToFile( FILE *pFile ){
-       fprintf( pFile, "{\n" );
+void DEntity::ClearEPairs()
+{
+    for (std::list<DEPair *>::const_iterator deadEPair = epairList.begin(); deadEPair != epairList.end(); deadEPair++) {
+        delete (*deadEPair);
+    }
+    epairList.clear();
+}
 
-       fprintf( pFile, "\"classname\" \"%s\"\n", (const char *)m_Classname );
+void DEntity::AddEPair(const char *key, const char *value)
+{
+    DEPair *newEPair;
+    newEPair = FindEPairByKey(key);
+    if (!newEPair) {
+        newEPair = new DEPair;
+        newEPair->Build(key, value);
+        epairList.push_back(newEPair);
+    } else {
+        newEPair->Build(key, value);
+    }
+}
+
+void DEntity::LoadEPairList(Entity *epl)
+{
+    class load_epairs_t : public Entity::Visitor {
+        DEntity *m_entity;
+    public:
+        load_epairs_t(DEntity *entity)
+                : m_entity(entity)
+        {
+        }
+
+        void visit(const char *key, const char *value)
+        {
+            if (strcmp(key, "classname") == 0) {
+                m_entity->SetClassname(value);
+            } else {
+                m_entity->AddEPair(key, value);
+            }
+        }
+
+    } load_epairs(this);
+
+    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;
+
+    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;
+            if (rebuild) {
+                Node_getTraversable(*(*resetBrush)->QER_entity)->erase(*(*resetBrush)->QER_brush);
+                (*resetBrush)->BuildInRadiant(false, NULL, (*resetBrush)->QER_entity);
+            }
+        }
+    }
+
+    if (bResetTextureName) {
+        for (std::list<DPatch *>::const_iterator resetPatch = patchList.begin();
+             resetPatch != patchList.end(); resetPatch++) {
+            bool tmp = (*resetPatch)->ResetTextures(textureName, newTextureName);
+
+            if (tmp) {
+                reset = true;
+                if (rebuild) {
+                    Node_getTraversable(*(*resetPatch)->QER_entity)->erase(*(*resetPatch)->QER_brush);
+                    (*resetPatch)->BuildInRadiant((*resetPatch)->QER_entity);
+                }
+            }
+        }
+    }
+
+    return reset;
+}
+
+DEPair *DEntity::FindEPairByKey(const char *keyname)
+{
+    for (std::list<DEPair *>::const_iterator ep = epairList.begin(); ep != epairList.end(); ep++) {
+        char *c = (*ep)->key;
+        if (!strcmp(c, keyname)) {
+            return *ep;
+        }
+    }
+    return NULL;
+}
+
+void DEntity::RemoveFromRadiant()
+{
+    Node_getTraversable(GlobalSceneGraph().root())->erase(*QER_Entity);
+
+    QER_Entity = NULL;
+}
 
-       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 );
-       }
+void DEntity::SpawnString(const char *key, const char *defaultstring, const char **out)
+{
+    DEPair *pEP = FindEPairByKey(key);
+    if (pEP) {
+        *out = pEP->value;
+    } else {
+        *out = defaultstring;
+    }
+}
 
-       for ( std::list<DBrush *>::const_iterator bp = brushList.begin(); bp != brushList.end(); bp++ )
-       {
-               ( *bp )->SaveToFile( pFile );
-       }
+void DEntity::SpawnInt(const char *key, const char *defaultstring, int *out)
+{
+    DEPair *pEP = FindEPairByKey(key);
+    if (pEP) {
+        *out = atoi(pEP->value);
+    } else {
+        *out = atoi(defaultstring);
+    }
+}
 
-       fprintf( pFile, "}\n" );
+void DEntity::SpawnFloat(const char *key, const char *defaultstring, float *out)
+{
+    DEPair *pEP = FindEPairByKey(key);
+    if (pEP) {
+        *out = static_cast<float>( atof(pEP->value));
+    } else {
+        *out = static_cast<float>( atof(defaultstring));
+    }
 }
 
-void DEntity::ClearEPairs(){
-       for ( std::list<DEPair *>::const_iterator deadEPair = epairList.begin(); deadEPair != epairList.end(); deadEPair++ )
-       {
-               delete ( *deadEPair );
-       }
-       epairList.clear();
+void DEntity::SpawnVector(const char *key, const char *defaultstring, vec_t *out)
+{
+    DEPair *pEP = FindEPairByKey(key);
+    if (pEP) {
+        sscanf(pEP->value, "%f %f %f", &out[0], &out[1], &out[2]);
+    } else {
+        sscanf(defaultstring, "%f %f %f", &out[0], &out[1], &out[2]);
+    }
 }
 
-void DEntity::AddEPair( const char *key, const char *value ) {
-       DEPair* newEPair;
-       newEPair = FindEPairByKey( key );
-       if ( !newEPair ) {
-               newEPair = new DEPair;
-               newEPair->Build( key, value );
-               epairList.push_back( newEPair );
-       }
-       else {
-               newEPair->Build( key, value );
-       }
+int DEntity::GetBrushCount(void)
+{
+    return static_cast<int>( brushList.size());
 }
 
-void DEntity::LoadEPairList( Entity *epl ){
-       class load_epairs_t : public Entity::Visitor
-       {
-       DEntity* m_entity;
-public:
-       load_epairs_t( DEntity* entity )
-               : m_entity( entity ){
-       }
-       void visit( const char* key, const char* value ){
-               if ( strcmp( key, "classname" ) == 0 ) {
-                       m_entity->SetClassname( value );
-               }
-               else{
-                       m_entity->AddEPair( key, value );
-               }
-       }
-
-       } load_epairs( this );
-
-       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;
-
-       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;
-                       if ( rebuild ) {
-                               Node_getTraversable( *( *resetBrush )->QER_entity )->erase( *( *resetBrush )->QER_brush );
-                               ( *resetBrush )->BuildInRadiant( false, NULL, ( *resetBrush )->QER_entity );
-                       }
-               }
-       }
-
-       if ( bResetTextureName ) {
-               for ( std::list<DPatch *>::const_iterator resetPatch = patchList.begin(); resetPatch != patchList.end(); resetPatch++ )
-               {
-                       bool tmp = ( *resetPatch )->ResetTextures( textureName, newTextureName );
-
-                       if ( tmp ) {
-                               reset = true;
-                               if ( rebuild ) {
-                                       Node_getTraversable( *( *resetPatch )->QER_entity )->erase( *( *resetPatch )->QER_brush );
-                                       ( *resetPatch )->BuildInRadiant( ( *resetPatch )->QER_entity );
-                               }
-                       }
-               }
-       }
-
-       return reset;
-}
-
-DEPair* DEntity::FindEPairByKey( const char* keyname ){
-       for ( std::list<DEPair *>::const_iterator ep = epairList.begin(); ep != epairList.end(); ep++ )
-       {
-               char* c = ( *ep )->key;
-               if ( !strcmp( c, keyname ) ) {
-                       return *ep;
-               }
-       }
-       return NULL;
-}
-
-void DEntity::RemoveFromRadiant(){
-       Node_getTraversable( GlobalSceneGraph().root() )->erase( *QER_Entity );
-
-       QER_Entity = NULL;
-}
-
-void DEntity::SpawnString( const char* key, const char* defaultstring, const char** out ){
-       DEPair* pEP = FindEPairByKey( key );
-       if ( pEP ) {
-               *out = pEP->value;
-       }
-       else {
-               *out = defaultstring;
-       }
-}
-
-void DEntity::SpawnInt( const char* key, const char* defaultstring, int* out ){
-       DEPair* pEP = FindEPairByKey( key );
-       if ( pEP ) {
-               *out = atoi( pEP->value );
-       }
-       else {
-               *out = atoi( defaultstring );
-       }
-}
-
-void DEntity::SpawnFloat( const char* key, const char* defaultstring, float* out ){
-       DEPair* pEP = FindEPairByKey( key );
-       if ( pEP ) {
-               *out = static_cast<float>( atof( pEP->value ) );
-       }
-       else {
-               *out = static_cast<float>( atof( defaultstring ) );
-       }
-}
-
-void DEntity::SpawnVector( const char* key, const char* defaultstring, vec_t* out ){
-       DEPair* pEP = FindEPairByKey( key );
-       if ( pEP ) {
-               sscanf( pEP->value, "%f %f %f", &out[0], &out[1], &out[2] );
-       }
-       else {
-               sscanf( defaultstring, "%f %f %f", &out[0], &out[1], &out[2] );
-       }
-}
-
-int DEntity::GetBrushCount( void ) {
-       return static_cast<int>( brushList.size() );
-}
-
-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 ) {
-                       return pBrush;
-               }
-       }
-       return NULL;
+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) {
+            return pBrush;
+        }
+    }
+    return NULL;
 }
index 415442a..1eb3fec 100644 (file)
 #include "mathlib.h"
 
 class DEPair;
+
 class DBrush;
+
 class DPlane;
+
 class DPatch;
+
 class Entity;
 
-namespace scene
-{
-class Node;
+namespace scene {
+    class Node;
 }
 class _QERFaceData;
 
-class DEntity
-{
+class DEntity {
 public:
-void RemoveFromRadiant();
-scene::Node* QER_Entity;
-int m_nID;
+    void RemoveFromRadiant();
+
+    scene::Node *QER_Entity;
+    int m_nID;
 
 //     Constrcution/Destruction
-DEntity( const char* classname = "worldspawn", int ID = -1 );   // sets classname
-virtual ~DEntity();
+    DEntity(const char *classname = "worldspawn", int ID = -1);   // sets classname
+    virtual ~DEntity();
 //     ---------------------------------------------
 
 //     epair functions........
-void LoadEPairList( Entity* epl );
-void AddEPair( const char* key, const char* value );
-void ClearEPairs();
-DEPair* FindEPairByKey( const char* keyname );
+    void LoadEPairList(Entity *epl);
+
+    void AddEPair(const char *key, const char *value);
+
+    void ClearEPairs();
+
+    DEPair *FindEPairByKey(const char *keyname);
 //     ---------------------------------------------
 
 //     random functions........
-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 rebuild );
-void SaveToFile( FILE* pFile );
-void SetClassname( const char* classname );
-int GetIDMax();
-
-void BuildInRadiant( bool allowDestruction );
-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 );
+    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 rebuild);
+
+    void SaveToFile(FILE *pFile);
+
+    void SetClassname(const char *classname);
+
+    int GetIDMax();
+
+    void BuildInRadiant(bool allowDestruction);
+
+    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);
 //     ---------------------------------------------
 
 
 //     bool list functions
-void SelectBrushes( bool* selectList );
-bool* BuildDuplicateList();
-bool* BuildIntersectList();
+    void SelectBrushes(bool *selectList);
+
+    bool *BuildDuplicateList();
+
+    bool *BuildIntersectList();
 //     ---------------------------------------------
 
 
 //     brush operations
-void ClearBrushes();        // clears brush list and frees memory for brushes
+    void ClearBrushes();        // clears brush list and frees memory for brushes
+
+    DBrush *GetBrushForID(int ID);
 
-DBrush* GetBrushForID( int ID );
-DBrush* NewBrush( int ID = -1 );
+    DBrush *NewBrush(int ID = -1);
 //     ---------------------------------------------
 
 //     patch operations
-void ClearPatches();
+    void ClearPatches();
 
-DPatch* NewPatch();
+    DPatch *NewPatch();
 //     ---------------------------------------------
 
 //     vars
-std::list<DEPair*> epairList;
-std::list<DBrush*> brushList;
+    std::list<DEPair *> epairList;
+    std::list<DBrush *> brushList;
 // new patches, wahey!!!
-std::list<DPatch*> patchList;
-Str m_Classname;
+    std::list<DPatch *> patchList;
+    Str m_Classname;
 //     ---------------------------------------------
 
 
-int FixBrushes();
+    int FixBrushes();
 
-bool LoadFromEntity( scene::Node& ent, bool bLoadPatches = false );
-void LoadSelectedBrushes();
-void LoadSelectedPatches();
+    bool LoadFromEntity(scene::Node &ent, bool bLoadPatches = false);
+
+    void LoadSelectedBrushes();
+
+    void LoadSelectedPatches();
+
+    bool LoadFromPrt(char *filename);
 
-bool LoadFromPrt( char* filename );
 //     ---------------------------------------------
-void SpawnString( const char* key, const char* defaultstring, const char** out );
-void SpawnInt( const char* key, const char* defaultstring, int* out );
-void SpawnFloat( const char* key, const char* defaultstring, float* out );
-void SpawnVector( const char* key, const char* defaultstring, vec_t* out );
+    void SpawnString(const char *key, const char *defaultstring, const char **out);
+
+    void SpawnInt(const char *key, const char *defaultstring, int *out);
+
+    void SpawnFloat(const char *key, const char *defaultstring, float *out);
+
+    void SpawnVector(const char *key, const char *defaultstring, vec_t *out);
 };
 
 #endif // !defined(AFX_DENTITY_H__35B2C523_F0A7_11D4_ACF7_004095A18133__INCLUDED_)
index 18edc3b..13898c8 100644 (file)
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-DMap::DMap(){
-       m_nNextEntity = 1;
-       AddEntity( "worldspawn", 0 );
+DMap::DMap()
+{
+    m_nNextEntity = 1;
+    AddEntity("worldspawn", 0);
 }
 
-DMap::~DMap(){
-       ClearEntities();
+DMap::~DMap()
+{
+    ClearEntities();
 }
 
-DEntity* DMap::AddEntity( const char *classname, int ID ){
-       DEntity* newEntity;
-       if ( ID == -1 ) {
-               newEntity = new DEntity( classname, m_nNextEntity++ );
-       }
-       else{
-               newEntity = new DEntity( classname, ID );
-       }
+DEntity *DMap::AddEntity(const char *classname, int ID)
+{
+    DEntity *newEntity;
+    if (ID == -1) {
+        newEntity = new DEntity(classname, m_nNextEntity++);
+    } else {
+        newEntity = new DEntity(classname, ID);
+    }
 
-       entityList.push_back( newEntity );
+    entityList.push_back(newEntity);
 
-       return newEntity;
+    return newEntity;
 }
 
-void DMap::ClearEntities(){
-       m_nNextEntity = 1;
+void DMap::ClearEntities()
+{
+    m_nNextEntity = 1;
 
-       for ( std::list<DEntity *>::const_iterator deadEntity = entityList.begin(); deadEntity != entityList.end(); deadEntity++ )
-               delete *deadEntity;
+    for (std::list<DEntity *>::const_iterator deadEntity = entityList.begin();
+         deadEntity != entityList.end(); deadEntity++) {
+             delete *deadEntity;
+    }
 
-       entityList.clear();
+    entityList.clear();
 }
 
-DEntity* DMap::GetEntityForID( int ID ){
-       DEntity* findEntity = NULL;
+DEntity *DMap::GetEntityForID(int ID)
+{
+    DEntity *findEntity = NULL;
 
-       for ( std::list<DEntity *>::const_iterator chkEntity = entityList.begin(); chkEntity != entityList.end(); chkEntity++ )
-       {
-               if ( ( *chkEntity )->m_nID == ID ) {
-                       findEntity = ( *chkEntity );
-                       break;
-               }
-       }
+    for (std::list<DEntity *>::const_iterator chkEntity = entityList.begin();
+         chkEntity != entityList.end(); chkEntity++) {
+        if ((*chkEntity)->m_nID == ID) {
+            findEntity = (*chkEntity);
+            break;
+        }
+    }
 
-       if ( !findEntity ) {
-               findEntity = AddEntity( "worldspawn", ID );
-       }
+    if (!findEntity) {
+        findEntity = AddEntity("worldspawn", ID);
+    }
 
-       return findEntity;
+    return findEntity;
 }
 
 
-DEntity* DMap::GetWorldSpawn(){
-       return GetEntityForID( 0 );
+DEntity *DMap::GetWorldSpawn()
+{
+    return GetEntityForID(0);
 }
 
-void DMap::BuildInRadiant( bool bAllowDestruction ){
-       for ( std::list<DEntity *>::const_iterator buildEntity = entityList.begin(); buildEntity != entityList.end(); buildEntity++ )
-               ( *buildEntity )->BuildInRadiant( bAllowDestruction );
+void DMap::BuildInRadiant(bool bAllowDestruction)
+{
+    for (std::list<DEntity *>::const_iterator buildEntity = entityList.begin();
+         buildEntity != entityList.end(); buildEntity++) {
+             (*buildEntity)->BuildInRadiant(bAllowDestruction);
+    }
 }
 
-void DMap::LoadAll( bool bLoadPatches ){
-       ClearEntities();
-
-       GlobalSelectionSystem().setSelectedAll( false );
-
-       class load_entities_t : public scene::Traversable::Walker
-       {
-       DMap* m_map;
-       bool m_bLoadPatches;
-public:
-       load_entities_t( DMap* map, bool bLoadPatches )
-               : m_map( map ), m_bLoadPatches( bLoadPatches ){
-       }
-       bool pre( scene::Node& node ) const {
-               if ( Node_isEntity( node ) ) {
-                       DEntity* loadEntity = m_map->AddEntity( "", 0 );
-                       loadEntity->LoadFromEntity( node, m_bLoadPatches );
-               }
-               return false;
-       }
-       } load_entities( this, bLoadPatches );
-
-       Node_getTraversable( GlobalSceneGraph().root() )->traverse( load_entities );
+void DMap::LoadAll(bool bLoadPatches)
+{
+    ClearEntities();
+
+    GlobalSelectionSystem().setSelectedAll(false);
+
+    class load_entities_t : public scene::Traversable::Walker {
+        DMap *m_map;
+        bool m_bLoadPatches;
+    public:
+        load_entities_t(DMap *map, bool bLoadPatches)
+                : m_map(map), m_bLoadPatches(bLoadPatches)
+        {
+        }
+
+        bool pre(scene::Node &node) const
+        {
+            if (Node_isEntity(node)) {
+                DEntity *loadEntity = m_map->AddEntity("", 0);
+                loadEntity->LoadFromEntity(node, m_bLoadPatches);
+            }
+            return false;
+        }
+    } load_entities(this, bLoadPatches);
+
+    Node_getTraversable(GlobalSceneGraph().root())->traverse(load_entities);
 }
 
-int DMap::FixBrushes(){
-       int count = 0;
-       for ( std::list<DEntity *>::const_iterator fixEntity = entityList.begin(); fixEntity != entityList.end(); fixEntity++ )
-       {
-               count += ( *fixEntity )->FixBrushes();
-       }
+int DMap::FixBrushes()
+{
+    int count = 0;
+    for (std::list<DEntity *>::const_iterator fixEntity = entityList.begin();
+         fixEntity != entityList.end(); fixEntity++) {
+        count += (*fixEntity)->FixBrushes();
+    }
 
-       return count;
+    return count;
 }
 
-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 ( std::list<DEntity *>::const_iterator texEntity = entityList.begin(); texEntity != entityList.end(); texEntity++ )
-       {
-               if ( string_equal_nocase( "worldspawn", ( *texEntity )->m_Classname ) ) {
-                       ( *texEntity )->ResetTextures( textureName,        fScale,       fShift,       rotation, newTextureName,
-                                                                                  bResetTextureName,  bResetScale,  bResetShift,  bResetRotation, true );
-               }
-               else
-               {
-                       if ( ( *texEntity )->ResetTextures( textureName,        fScale,       fShift,       rotation, newTextureName,
-                                                                                               bResetTextureName,  bResetScale,  bResetShift,  bResetRotation, false ) ) {
-                               RebuildEntity( *texEntity );
-                       }
-               }
-       }
+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 (std::list<DEntity *>::const_iterator texEntity = entityList.begin();
+         texEntity != entityList.end(); texEntity++) {
+        if (string_equal_nocase("worldspawn", (*texEntity)->m_Classname)) {
+            (*texEntity)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
+                                        bResetTextureName, bResetScale, bResetShift, bResetRotation, true);
+        } else {
+            if ((*texEntity)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
+                                            bResetTextureName, bResetScale, bResetShift, bResetRotation, false)) {
+                RebuildEntity(*texEntity);
+            }
+        }
+    }
 }
 
-void DMap::RebuildEntity( DEntity *ent ){
-       ent->RemoveFromRadiant();
-       ent->BuildInRadiant( false );
+void DMap::RebuildEntity(DEntity *ent)
+{
+    ent->RemoveFromRadiant();
+    ent->BuildInRadiant(false);
 }
index f527d04..9959034 100644 (file)
 
 class DEntity;
 
-class DMap
-{
+class DMap {
 public:
-static void RebuildEntity( DEntity* ent );
+    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 BuildInRadiant( bool bAllowDestruction );
-int m_nNextEntity;
-DEntity* GetWorldSpawn();
-void ClearEntities();
+    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);
 
-DEntity* GetEntityForID( int ID );
-DEntity* AddEntity( const char* classname = "worldspawn", int ID = -1 );
+    void LoadAll(bool bLoadPatches = false);
 
-std::list<DEntity*> entityList;
+    void BuildInRadiant(bool bAllowDestruction);
 
-DMap();
-virtual ~DMap();
+    int m_nNextEntity;
 
-int FixBrushes();
+    DEntity *GetWorldSpawn();
+
+    void ClearEntities();
+
+    DEntity *GetEntityForID(int ID);
+
+    DEntity *AddEntity(const char *classname = "worldspawn", int ID = -1);
+
+    std::list<DEntity *> entityList;
+
+    DMap();
+
+    virtual ~DMap();
+
+    int FixBrushes();
 };
 
 #endif // !defined(AFX_DMAP_H__ACAE597A_D26D_49AD_AA69_EDE743DB54FA__INCLUDED_)
index be49df4..5c806f8 100644 (file)
 //             problem is, you cant put patches into entities as yet :(
 //
 
-DPatch::DPatch(){
-       width = MIN_PATCH_WIDTH;
-       height = MIN_PATCH_HEIGHT;
-       QER_entity = NULL;
-       QER_brush = NULL;
+DPatch::DPatch()
+{
+    width = MIN_PATCH_WIDTH;
+    height = MIN_PATCH_HEIGHT;
+    QER_entity = NULL;
+    QER_brush = NULL;
 }
 
-DPatch::~DPatch(){
+DPatch::~DPatch()
+{
 
 }
 
-void DPatch::SetTexture( const char *textureName ){
-       strcpy( texture, textureName );
+void DPatch::SetTexture(const char *textureName)
+{
+    strcpy(texture, textureName);
 }
 
-void CopyDrawVert( const drawVert_t* in, drawVert_t* out ){
-       out->lightmap[0] = in->lightmap[0];
-       out->lightmap[1] = in->lightmap[1];
-       out->st[0] = in->st[0];
-       out->st[1] = in->st[1];
-       VectorCopy( in->normal, out->normal );
-       VectorCopy( in->xyz, out->xyz );
+void CopyDrawVert(const drawVert_t *in, drawVert_t *out)
+{
+    out->lightmap[0] = in->lightmap[0];
+    out->lightmap[1] = in->lightmap[1];
+    out->st[0] = in->st[0];
+    out->st[1] = in->st[1];
+    VectorCopy(in->normal, out->normal);
+    VectorCopy(in->xyz, out->xyz);
 }
 
-void DPatch::BuildInRadiant( scene::Node* entity ){
-       NodeSmartReference patch( GlobalPatchCreator().createPatch() );
-
-       scene::Node& parent = entity != 0 ? *entity : GlobalRadiant().getMapWorldEntity();
-       Node_getTraversable( parent )->insert( patch );
-
-       GlobalPatchCreator().Patch_setShader( patch, texture );
-       GlobalPatchCreator().Patch_resize( patch, height, width );
-       PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints( patch );
-       for ( int x = 0; x < width; x++ )
-       {
-               for ( int y = 0; y < height; y++ )
-               {
-                       PatchControl& p = matrix( x, y );
-                       p.m_vertex[0] = points[x][y].xyz[0];
-                       p.m_vertex[1] = points[x][y].xyz[1];
-                       p.m_vertex[2] = points[x][y].xyz[2];
-                       p.m_texcoord[0] = points[x][y].st[0];
-                       p.m_texcoord[1] = points[x][y].st[1];
-               }
-       }
-       GlobalPatchCreator().Patch_controlPointsChanged( patch );
-
-       QER_entity = entity;
-       QER_brush = patch.get_pointer();
+void DPatch::BuildInRadiant(scene::Node *entity)
+{
+    NodeSmartReference patch(GlobalPatchCreator().createPatch());
+
+    scene::Node &parent = entity != 0 ? *entity : GlobalRadiant().getMapWorldEntity();
+    Node_getTraversable(parent)->insert(patch);
+
+    GlobalPatchCreator().Patch_setShader(patch, texture);
+    GlobalPatchCreator().Patch_resize(patch, height, width);
+    PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch);
+    for (int x = 0; x < width; x++) {
+        for (int y = 0; y < height; y++) {
+            PatchControl &p = matrix(x, y);
+            p.m_vertex[0] = points[x][y].xyz[0];
+            p.m_vertex[1] = points[x][y].xyz[1];
+            p.m_vertex[2] = points[x][y].xyz[2];
+            p.m_texcoord[0] = points[x][y].st[0];
+            p.m_texcoord[1] = points[x][y].st[1];
+        }
+    }
+    GlobalPatchCreator().Patch_controlPointsChanged(patch);
+
+    QER_entity = entity;
+    QER_brush = patch.get_pointer();
 
 
 #if 0
-       int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
-       //$ FIXME: m_pfnGetPatchHandle
-       patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData( nIndex );
+    int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
+    //$ FIXME: m_pfnGetPatchHandle
+    patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData( nIndex );
 
-       b->patchBrush = true;
-       b->pPatch = Patch_Alloc();
-       b->pPatch->setDims( width,height );
+    b->patchBrush = true;
+    b->pPatch = Patch_Alloc();
+    b->pPatch->setDims( width,height );
 
-       for ( int x = 0; x < width; x++ )
-               for ( int y = 0; y < height; y++ )
-                       CopyDrawVert( &points[x][y], &pm->ctrl[x][y] );
+    for ( int x = 0; x < width; x++ )
+        for ( int y = 0; y < height; y++ )
+            CopyDrawVert( &points[x][y], &pm->ctrl[x][y] );
 
 /*     if(entity)
     {
@@ -124,216 +127,218 @@ void DPatch::BuildInRadiant( scene::Node* entity ){
     }
     else*/                                                                                                                                                                                                                                                                                                                                                                                                                                                                // patch to entity just plain dont work atm
 
-       if ( entity ) {
-               g_FuncTable.m_pfnCommitPatchHandleToEntity( nIndex, pm, texture, entity );
-       }
-       else{
-               g_FuncTable.m_pfnCommitPatchHandleToMap( nIndex, pm, texture );
-       }
+    if ( entity ) {
+        g_FuncTable.m_pfnCommitPatchHandleToEntity( nIndex, pm, texture, entity );
+    }
+    else{
+        g_FuncTable.m_pfnCommitPatchHandleToMap( nIndex, pm, texture );
+    }
 
-       QER_brush = pm->pSymbiot;
+    QER_brush = pm->pSymbiot;
 #endif
 }
 
-void DPatch::LoadFromPatch( scene::Instance& patch ){
-       QER_entity = patch.path().parent().get_pointer();
-       QER_brush = patch.path().top().get_pointer();
-
-       PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints( patch.path().top() );
-
-       width = static_cast<int>( matrix.x() );
-       height = static_cast<int>( matrix.y() );
-
-       for ( int x = 0; x < width; x++ )
-       {
-               for ( int y = 0; y < height; y++ )
-               {
-                       PatchControl& p = matrix( x, y );
-                       points[x][y].xyz[0] = p.m_vertex[0];
-                       points[x][y].xyz[1] = p.m_vertex[1];
-                       points[x][y].xyz[2] = p.m_vertex[2];
-                       points[x][y].st[0] = p.m_texcoord[0];
-                       points[x][y].st[1] = p.m_texcoord[1];
-               }
-       }
-       SetTexture( GlobalPatchCreator().Patch_getShader( patch.path().top() ) );
+void DPatch::LoadFromPatch(scene::Instance &patch)
+{
+    QER_entity = patch.path().parent().get_pointer();
+    QER_brush = patch.path().top().get_pointer();
+
+    PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch.path().top());
+
+    width = static_cast<int>( matrix.x());
+    height = static_cast<int>( matrix.y());
+
+    for (int x = 0; x < width; x++) {
+        for (int y = 0; y < height; y++) {
+            PatchControl &p = matrix(x, y);
+            points[x][y].xyz[0] = p.m_vertex[0];
+            points[x][y].xyz[1] = p.m_vertex[1];
+            points[x][y].xyz[2] = p.m_vertex[2];
+            points[x][y].st[0] = p.m_texcoord[0];
+            points[x][y].st[1] = p.m_texcoord[1];
+        }
+    }
+    SetTexture(GlobalPatchCreator().Patch_getShader(patch.path().top()));
 
 #if 0
-       SetTexture( brush->pPatch->GetShader() );
-
-       width = brush->pPatch->getWidth();
-       height = brush->pPatch->getHeight();
-
-       for ( int x = 0; x < height; x++ )
-       {
-               for ( int y = 0; y < width; y++ )
-               {
-                       float *p = brush->pPatch->ctrlAt( ROW,x,y );
-                       p[0] = points[x][y].xyz[0];
-                       p[1] = points[x][y].xyz[1];
-                       p[2] = points[x][y].xyz[2];
-                       p[3] = points[x][y].st[0];
-                       p[4] = points[x][y].st[1];
-               }
-       }
+    SetTexture( brush->pPatch->GetShader() );
+
+    width = brush->pPatch->getWidth();
+    height = brush->pPatch->getHeight();
+
+    for ( int x = 0; x < height; x++ )
+    {
+        for ( int y = 0; y < width; y++ )
+        {
+            float *p = brush->pPatch->ctrlAt( ROW,x,y );
+            p[0] = points[x][y].xyz[0];
+            p[1] = points[x][y].xyz[1];
+            p[2] = points[x][y].xyz[2];
+            p[3] = points[x][y].st[0];
+            p[4] = points[x][y].st[1];
+        }
+    }
 #endif
 }
 
-bool DPatch::ResetTextures( const char *oldTextureName, const char *newTextureName ){
-       if ( !oldTextureName || !strcmp( texture, oldTextureName ) ) {
-               strcpy( texture, newTextureName );
-               return true;
-       }
+bool DPatch::ResetTextures(const char *oldTextureName, const char *newTextureName)
+{
+    if (!oldTextureName || !strcmp(texture, oldTextureName)) {
+        strcpy(texture, newTextureName);
+        return true;
+    }
 
-       return false;
+    return false;
 }
 
-void Build1dArray( vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT],
-                                  int startX, int startY, int number, bool horizontal, bool inverse ){
-       int x = startX, y = startY, i, step;
-
-       if ( inverse ) {
-               step = -1;
-       }
-       else{
-               step = 1;
-       }
-
-       for ( i = 0; i < number; i++ )
-       {
-               VectorCopy( points[x][y].xyz, array[i] );
-
-               if ( horizontal ) {
-                       x += step;
-               }
-               else{
-                       y += step;
-               }
-       }
+void Build1dArray(vec3_t *array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT],
+                  int startX, int startY, int number, bool horizontal, bool inverse)
+{
+    int x = startX, y = startY, i, step;
+
+    if (inverse) {
+        step = -1;
+    } else {
+        step = 1;
+    }
+
+    for (i = 0; i < number; i++) {
+        VectorCopy(points[x][y].xyz, array[i]);
+
+        if (horizontal) {
+            x += step;
+        } else {
+            y += step;
+        }
+    }
 }
 
-void Print1dArray( vec3_t* array, int size ){
-       for ( int i = 0; i < size; i++ )
-               globalOutputStream() << "(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t";
-       globalOutputStream() << "\n";
+void Print1dArray(vec3_t *array, int size)
+{
+    for (int i = 0; i < size; i++) {
+        globalOutputStream() << "(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t";
+    }
+    globalOutputStream() << "\n";
 }
 
-bool Compare1dArrays( vec3_t* a1, vec3_t* a2, int size ){
-       int i;
-       bool equal = true;
-
-       for ( i = 0; i < size; i++ )
-       {
-               if ( !VectorCompare( a1[i], a2[size - i - 1] ) ) {
-                       equal = false;
-                       break;
-               }
-       }
-       return equal;
+bool Compare1dArrays(vec3_t *a1, vec3_t *a2, int size)
+{
+    int i;
+    bool equal = true;
+
+    for (i = 0; i < size; i++) {
+        if (!VectorCompare(a1[i], a2[size - i - 1])) {
+            equal = false;
+            break;
+        }
+    }
+    return equal;
 }
 
-patch_merge_t DPatch::IsMergable( DPatch *other ){
-       int i, j;
-       vec3_t p1Array[4][MAX_PATCH_HEIGHT];
-       vec3_t p2Array[4][MAX_PATCH_HEIGHT];
-
-       int p1ArraySizes[4];
-       int p2ArraySizes[4];
-
-       patch_merge_t merge_info;
-
-       Build1dArray( p1Array[0], this->points, 0,               0,              this->width,    true,   false );
-       Build1dArray( p1Array[1], this->points, this->width - 1,   0,              this->height,   false,  false );
-       Build1dArray( p1Array[2], this->points, this->width - 1,   this->height - 1, this->width,    true,   true );
-       Build1dArray( p1Array[3], this->points, 0,               this->height - 1, this->height,   false,  true );
-
-       Build1dArray( p2Array[0], other->points, 0,              0,                  other->width,   true,   false );
-       Build1dArray( p2Array[1], other->points, other->width - 1, 0,                  other->height,  false,  false );
-       Build1dArray( p2Array[2], other->points, other->width - 1, other->height - 1,    other->width,   true,   true );
-       Build1dArray( p2Array[3], other->points, 0,              other->height - 1,    other->height,  false,  true );
-
-       p1ArraySizes[0] = this->width;
-       p1ArraySizes[1] = this->height;
-       p1ArraySizes[2] = this->width;
-       p1ArraySizes[3] = this->height;
-
-       p2ArraySizes[0] = other->width;
-       p2ArraySizes[1] = other->height;
-       p2ArraySizes[2] = other->width;
-       p2ArraySizes[3] = other->height;
-
-       for ( i = 0; i < 4; i++ )
-       {
-               for ( j = 0; j < 4; j++ )
-               {
-                       if ( p1ArraySizes[i] == p2ArraySizes[j] ) {
-                               if ( Compare1dArrays( p1Array[i], p2Array[j], p1ArraySizes[i] ) ) {
-                                       merge_info.pos1 = i;
-                                       merge_info.pos2 = j;
-                                       merge_info.mergable = true;
-                                       return merge_info;
-                               }
-                       }
-               }
-       }
-
-       merge_info.mergable = false;
-       return merge_info;
+patch_merge_t DPatch::IsMergable(DPatch *other)
+{
+    int i, j;
+    vec3_t p1Array[4][MAX_PATCH_HEIGHT];
+    vec3_t p2Array[4][MAX_PATCH_HEIGHT];
+
+    int p1ArraySizes[4];
+    int p2ArraySizes[4];
+
+    patch_merge_t merge_info;
+
+    Build1dArray(p1Array[0], this->points, 0, 0, this->width, true, false);
+    Build1dArray(p1Array[1], this->points, this->width - 1, 0, this->height, false, false);
+    Build1dArray(p1Array[2], this->points, this->width - 1, this->height - 1, this->width, true, true);
+    Build1dArray(p1Array[3], this->points, 0, this->height - 1, this->height, false, true);
+
+    Build1dArray(p2Array[0], other->points, 0, 0, other->width, true, false);
+    Build1dArray(p2Array[1], other->points, other->width - 1, 0, other->height, false, false);
+    Build1dArray(p2Array[2], other->points, other->width - 1, other->height - 1, other->width, true, true);
+    Build1dArray(p2Array[3], other->points, 0, other->height - 1, other->height, false, true);
+
+    p1ArraySizes[0] = this->width;
+    p1ArraySizes[1] = this->height;
+    p1ArraySizes[2] = this->width;
+    p1ArraySizes[3] = this->height;
+
+    p2ArraySizes[0] = other->width;
+    p2ArraySizes[1] = other->height;
+    p2ArraySizes[2] = other->width;
+    p2ArraySizes[3] = other->height;
+
+    for (i = 0; i < 4; i++) {
+        for (j = 0; j < 4; j++) {
+            if (p1ArraySizes[i] == p2ArraySizes[j]) {
+                if (Compare1dArrays(p1Array[i], p2Array[j], p1ArraySizes[i])) {
+                    merge_info.pos1 = i;
+                    merge_info.pos2 = j;
+                    merge_info.mergable = true;
+                    return merge_info;
+                }
+            }
+        }
+    }
+
+    merge_info.mergable = false;
+    return merge_info;
 }
 
-DPatch* DPatch::MergePatches( patch_merge_t merge_info, DPatch *p1, DPatch *p2 ){
-       while ( merge_info.pos1 != 2 )
-       {
-               p1->Transpose();
-               merge_info.pos1--;
-               if ( merge_info.pos1 < 0 ) {
-                       merge_info.pos1 += 4;
-               }
-       }
-
-       while ( merge_info.pos2 != 0 )
-       {
-               p2->Transpose();
-               merge_info.pos2--;
-               if ( merge_info.pos2 < 0 ) {
-                       merge_info.pos2 += 3;
-               }
-       }
-
-       int newHeight = p1->height + p2->height - 1;
-       if ( newHeight > MAX_PATCH_HEIGHT ) {
-               return NULL;
-       }
-
-       DPatch* newPatch = new DPatch();
-
-       newPatch->height    = newHeight;
-       newPatch->width     = p1->width;
-       newPatch->SetTexture( p1->texture );
-
-       for ( int y = 0; y < p1->height; y++ )
-               for ( int x = 0; x < p1->width; x++ )
-                       newPatch->points[x][y] = p1->points[x][y];
-
-       for ( int y = 1; y < p2->height; y++ )
-               for ( int x = 0; x < p2->width; x++ )
-                       newPatch->points[x][( y + p1->height - 1 )] = p2->points[x][y];
+DPatch *DPatch::MergePatches(patch_merge_t merge_info, DPatch *p1, DPatch *p2)
+{
+    while (merge_info.pos1 != 2) {
+        p1->Transpose();
+        merge_info.pos1--;
+        if (merge_info.pos1 < 0) {
+            merge_info.pos1 += 4;
+        }
+    }
+
+    while (merge_info.pos2 != 0) {
+        p2->Transpose();
+        merge_info.pos2--;
+        if (merge_info.pos2 < 0) {
+            merge_info.pos2 += 3;
+        }
+    }
+
+    int newHeight = p1->height + p2->height - 1;
+    if (newHeight > MAX_PATCH_HEIGHT) {
+        return NULL;
+    }
+
+    DPatch *newPatch = new DPatch();
+
+    newPatch->height = newHeight;
+    newPatch->width = p1->width;
+    newPatch->SetTexture(p1->texture);
+
+    for (int y = 0; y < p1->height; y++) {
+        for (int x = 0; x < p1->width; x++) {
+            newPatch->points[x][y] = p1->points[x][y];
+        }
+    }
+
+    for (int y = 1; y < p2->height; y++) {
+        for (int x = 0; x < p2->width; x++) {
+            newPatch->points[x][(y + p1->height - 1)] = p2->points[x][y];
+        }
+    }
 
 //     newPatch->Invert();
-       return newPatch;
+    return newPatch;
 }
 
-void DPatch::Invert(){
-       int i, j;
+void DPatch::Invert()
+{
+    int i, j;
 
-       for ( i = 0 ; i < width ; i++ )
-       {
-               for ( j = 0; j < height / 2; j++ )
-               {
-                       std::swap( points[i][height - 1 - j], points[i][j] );
-               }
-       }
+    for (i = 0; i < width; i++) {
+        for (j = 0; j < height / 2; j++) {
+            std::swap(points[i][height - 1 - j], points[i][j]);
+        }
+    }
 }
+
 /*
    //Was used for debugging, obsolete function
    DPatch* DPatch::TransposePatch(DPatch *p1)
@@ -374,140 +379,122 @@ void DPatch::Invert(){
    }
  */
 
-void DPatch::Transpose(){
-       int i, j, w;
-
-       if ( width > height ) {
-               for ( i = 0 ; i < height ; i++ )
-               {
-                       for ( j = i + 1 ; j < width ; j++ )
-                       {
-                               if ( j < height ) {
-                                       // swap the value
-                                       std::swap( points[j][i], points[i][j] );
-                               }
-                               else
-                               {
-                                       // just copy
-                                       points[i][j] = points[j][i];
-                               }
-                       }
-               }
-       }
-       else
-       {
-               for ( i = 0 ; i < width ; i++ )
-               {
-                       for ( j = i + 1 ; j < height ; j++ )
-                       {
-                               if ( j < width ) {
-                                       // swap the value
-                                       std::swap( points[i][j], points[j][i] );
-                               }
-                               else
-                               {
-                                       // just copy
-                                       points[j][i] = points[i][j];
-                               }
-                       }
-               }
-       }
-
-       w = width;
-       width = height;
-       height = w;
-
-       Invert();
+void DPatch::Transpose()
+{
+    int i, j, w;
+
+    if (width > height) {
+        for (i = 0; i < height; i++) {
+            for (j = i + 1; j < width; j++) {
+                if (j < height) {
+                    // swap the value
+                    std::swap(points[j][i], points[i][j]);
+                } else {
+                    // just copy
+                    points[i][j] = points[j][i];
+                }
+            }
+        }
+    } else {
+        for (i = 0; i < width; i++) {
+            for (j = i + 1; j < height; j++) {
+                if (j < width) {
+                    // swap the value
+                    std::swap(points[i][j], points[j][i]);
+                } else {
+                    // just copy
+                    points[j][i] = points[i][j];
+                }
+            }
+        }
+    }
+
+    w = width;
+    width = height;
+    height = w;
+
+    Invert();
 }
 
-std::list<DPatch> DPatch::SplitCols(){
-       std::list<DPatch> patchList;
-       int i;
-       int x, y;
-
-       if ( height >= 5 ) {
-               for ( i = 0; i < ( height - 1 ) / 2; i++ )
-               {
-                       DPatch p;
-
-                       p.width = width;
-                       p.height = MIN_PATCH_HEIGHT;
-                       p.SetTexture( texture );
-                       for ( x = 0; x < p.width; x++ )
-                       {
-                               for ( y = 0; y < MIN_PATCH_HEIGHT; y++ )
-                               {
-                                       p.points[x][y] = points[x][( i * 2 ) + y];
-                               }
-                       }
-                       patchList.push_back( p );
-               }
-       }
-       else {
-               //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n";
-               patchList.push_back( *this );
-       }
-       return patchList;
+std::list<DPatch> DPatch::SplitCols()
+{
+    std::list<DPatch> patchList;
+    int i;
+    int x, y;
+
+    if (height >= 5) {
+        for (i = 0; i < (height - 1) / 2; i++) {
+            DPatch p;
+
+            p.width = width;
+            p.height = MIN_PATCH_HEIGHT;
+            p.SetTexture(texture);
+            for (x = 0; x < p.width; x++) {
+                for (y = 0; y < MIN_PATCH_HEIGHT; y++) {
+                    p.points[x][y] = points[x][(i * 2) + y];
+                }
+            }
+            patchList.push_back(p);
+        }
+    } else {
+        //globalErrorStream() << "bobToolz SplitPatchRows: Patch has not enough rows for splitting.\n";
+        patchList.push_back(*this);
+    }
+    return patchList;
 }
 
-std::list<DPatch> DPatch::SplitRows(){
-       std::list<DPatch> patchList;
-       int i;
-       int x, y;
-
-       if ( width >= 5 ) {
-               for ( i = 0; i < ( width - 1 ) / 2; i++ )
-               {
-                       DPatch p;
-
-                       p.width = MIN_PATCH_WIDTH;
-                       p.height = height;
-                       p.SetTexture( texture );
-
-                       for ( x = 0; x < MIN_PATCH_WIDTH; x++ )
-                       {