]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/shapes.cpp
Merge commit '4645e19ce9e8f8034233ac965a4103a13b75714c' into garux-merge
[xonotic/netradiant.git] / contrib / bobtoolz / shapes.cpp
index 490c113868aa1f2f7c24d19df9fba628d2cefd54..2e47035d75b5e0630c611bc8395369198edc32b4 100644 (file)
  */
 
 
-#include "StdAfx.h"
-
 #include "shapes.h"
 
+#include <list>
+
+#include "DPoint.h"
 #include "DPlane.h"
 
+#include "str.h"
 #include "misc.h"
 #include "funchandlers.h"
 
+#include "iundo.h"
+#include "ishaders.h"
+#include "ientity.h"
+#include "ieclass.h"
+#include "ipatch.h"
+#include "qerplugin.h"
+
+#include <vector>
+#include <list>
+#include <map>
+#include <algorithm>
+#include <time.h>
+
+#include "scenelib.h"
+#include "texturelib.h"
+
 //#include "dialogs-gtk.h"
 
 /************************
@@ -40,9 +58,9 @@
        / |   / |
       /  |  /  |
     4 ----- 6  |
- |  2|_|___|8
- |  /  |   /
- | /   |  /       ----> WEST, definitely
    |  2|_|___|8
    |  /  |   /
    | /   |  /       ----> WEST, definitely
  ||/    | /
     1|_____|/3
 
@@ -64,21 +82,18 @@ float Deg2Rad( float angle ){
        return (float)( angle * Q_PI / 180 );
 }
 
-void AddFaceWithTexture( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail ){
+void AddFaceWithTexture( scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail ){
        _QERFaceData faceData;
        FillDefaultTexture( &faceData, va, vb, vc, texture );
        if ( detail ) {
-               faceData.m_nContents |= FACE_DETAIL;
+               faceData.contents |= FACE_DETAIL;
        }
-
-       g_FuncTable.m_pfnAddFaceData( brush, &faceData );
+       GlobalBrushCreator().Brush_addFace( brush, faceData );
 }
 
-void AddFaceWithTextureScaled( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc,
+void AddFaceWithTextureScaled( scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc,
                                                           const char* texture, bool bVertScale, bool bHorScale,
                                                           float minX, float minY, float maxX, float maxY ){
-       g_ShadersTable.m_pfnShader_ForName( texture ); // need to call frist to load?
-
        qtexture_t* pqtTexInfo;
 
        // TTimo: there used to be a call to pfnHasShader here
@@ -86,7 +101,7 @@ void AddFaceWithTextureScaled( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc,
        //   If a texture doesn't have a shader script, a default shader object is used.
        // The IShader object was leaking also
        // collect texture info: sizes, etc
-       IShader* i = g_ShadersTable.m_pfnShader_ForName( texture );
+       IShader* i = GlobalShaderSystem().getShaderForName( texture );
        pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly
 
        if ( pqtTexInfo ) {
@@ -94,36 +109,34 @@ void AddFaceWithTextureScaled( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc,
                float shift[2] = {0, 0};
 
                if ( bHorScale ) {
-                       int texWidth = pqtTexInfo->width;
                        float width = maxX - minX;
 
-                       scale[0] = width / texWidth;
+                       scale[0] = width / pqtTexInfo->width;
                        shift[0] = -(float)( (int)maxX % (int)width ) / scale[0];
                }
 
                if ( bVertScale ) {
-                       int texHeight = pqtTexInfo->height;
                        float height = maxY - minY;
 
-                       scale[1] = height / texHeight;
+                       scale[1] = height / pqtTexInfo->height;
                        shift[1] = (float)( (int)minY % (int)height ) / scale[1];
                }
 
                _QERFaceData addFace;
                FillDefaultTexture( &addFace, va, vb, vc, texture );
-               addFace.m_fScale[0] = scale[0];
-               addFace.m_fScale[1] = scale[1];
-               addFace.m_fShift[0] = shift[0];
-               addFace.m_fShift[1] = shift[1];
+               addFace.m_texdef.scale[0] = scale[0];
+               addFace.m_texdef.scale[1] = scale[1];
+               addFace.m_texdef.shift[0] = shift[0];
+               addFace.m_texdef.shift[1] = shift[1];
 
-               g_FuncTable.m_pfnAddFaceData( brush, &addFace );
+               GlobalBrushCreator().Brush_addFace( brush, addFace );
        }
        else
        {
                // shouldn't even get here, as default missing texture should be returned if
                // texture doesn't exist, but just in case
-               AddFaceWithTexture( brush, va, vb, vc, texture, FALSE );
-               Sys_ERROR( "BobToolz::Invalid Texture Name-> %s", texture );
+               AddFaceWithTexture( brush, va, vb, vc, texture, false );
+               globalErrorStream() << "BobToolz::Invalid Texture Name-> " << texture;
        }
        // the IShader is not kept referenced, DecRef it
        i->DecRef();
@@ -134,7 +147,7 @@ void AddFaceWithTextureScaled( brush_t* brush, vec3_t va, vec3_t vb, vec3_t vc,
 ************************/
 
 void Build_Wedge( int dir, vec3_t min, vec3_t max, bool bUp ){
-       brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
+       NodeSmartReference newBrush( GlobalBrushCreator().createBrush() );
 
        vec3_t v1, v2, v3, v5, v6, v7, v8;
        VectorCopy( min, v1 );
@@ -155,85 +168,85 @@ void Build_Wedge( int dir, vec3_t min, vec3_t max, bool bUp ){
        if ( bUp ) {
 
                if ( dir != MOVE_EAST ) {
-                       AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", false );
                }
 
                if ( dir != MOVE_WEST ) {
-                       AddFaceWithTexture( newBrush, v7, v5, v8, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v7, v5, v8, "textures/common/caulk", false );
                }
 
                if ( dir != MOVE_NORTH ) {
-                       AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", false );
                }
 
                if ( dir != MOVE_SOUTH ) {
-                       AddFaceWithTexture( newBrush, v3, v8, v6, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v3, v8, v6, "textures/common/caulk", false );
                }
 
-               AddFaceWithTexture( newBrush, v1, v2, v3, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush, v1, v2, v3, "textures/common/caulk", false );
 
                if ( dir == MOVE_EAST ) {
-                       AddFaceWithTexture( newBrush, v1, v3, v5, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v3, v5, "textures/common/caulk", false );
                }
 
                if ( dir == MOVE_WEST ) {
-                       AddFaceWithTexture( newBrush, v2, v6, v8, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v2, v6, v8, "textures/common/caulk", false );
                }
 
                if ( dir == MOVE_NORTH ) {
-                       AddFaceWithTexture( newBrush, v1, v6, v5, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v6, v5, "textures/common/caulk", false );
                }
 
                if ( dir == MOVE_SOUTH ) {
-                       AddFaceWithTexture( newBrush, v7, v3, v8, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v7, v3, v8, "textures/common/caulk", false );
                }
        }
        else
        {
                if ( dir != MOVE_WEST ) {
-                       AddFaceWithTexture( newBrush, v7, v5, v8, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v7, v5, v8, "textures/common/caulk", false );
                }
 
                if ( dir != MOVE_EAST ) {
-                       AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", false );
                }
 
                if ( dir != MOVE_NORTH ) {
-                       AddFaceWithTexture( newBrush, v3, v8, v6, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v3, v8, v6, "textures/common/caulk", false );
                }
 
                if ( dir != MOVE_SOUTH ) {
-                       AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", false );
                }
 
 
-               AddFaceWithTexture( newBrush, v6, v5, v7, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush, v6, v5, v7, "textures/common/caulk", false );
 
                if ( dir == MOVE_WEST ) {
-                       AddFaceWithTexture( newBrush, v1, v5, v3, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v5, v3, "textures/common/caulk", false );
                }
 
                if ( dir == MOVE_EAST ) {
-                       AddFaceWithTexture( newBrush, v2, v8, v6, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v2, v8, v6, "textures/common/caulk", false );
                }
 
                if ( dir == MOVE_NORTH ) {
-                       AddFaceWithTexture( newBrush, v1, v5, v6, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v1, v5, v6, "textures/common/caulk", false );
                }
 
                if ( dir == MOVE_SOUTH ) {
-                       AddFaceWithTexture( newBrush, v7, v8, v3, "textures/common/caulk", FALSE );
+                       AddFaceWithTexture( newBrush, v7, v8, v3, "textures/common/caulk", false );
                }
        }
 
-       g_FuncTable.m_pfnCommitBrushHandle( newBrush );
+       Node_getTraversable( GlobalRadiant().getMapWorldEntity() )->insert( newBrush );
 }
 
 //-----------------------------------------------------------------------------------
 //-----------------------------------------------------------------------------------
 
 void Build_StairStep_Wedge( int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail ){
-       brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
+       NodeSmartReference newBrush( GlobalBrushCreator().createBrush() );
 
        //----- Build Outer Bounds ---------
 
@@ -312,15 +325,15 @@ void Build_StairStep_Wedge( int dir, vec3_t min, vec3_t max, const char* mainTex
                AddFaceWithTexture( newBrush, v7, v8, v3, "textures/common/caulk", detail );
        }
 
-       g_FuncTable.m_pfnCommitBrushHandle( newBrush );
+       Node_getTraversable( GlobalRadiant().getMapWorldEntity() )->insert( newBrush );
 }
 
 //-----------------------------------------------------------------------------------
 //-----------------------------------------------------------------------------------
 
 // internal use only, to get a box without finishing construction
-brush_t* Build_Get_BoundingCube_Selective( vec3_t min, vec3_t max, char* texture, bool* useFaces ){
-       brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
+scene::Node& Build_Get_BoundingCube_Selective( vec3_t min, vec3_t max, char* texture, bool* useFaces ){
+       NodeSmartReference newBrush( GlobalBrushCreator().createBrush() );
 
        //----- Build Outer Bounds ---------
 
@@ -343,23 +356,23 @@ brush_t* Build_Get_BoundingCube_Selective( vec3_t min, vec3_t max, char* texture
        //----- Add Six Cube Faces ---------
 
        if ( useFaces[0] ) {
-               AddFaceWithTexture( newBrush, v1, v2, v3, texture, FALSE );
+               AddFaceWithTexture( newBrush, v1, v2, v3, texture, false );
        }
        if ( useFaces[1] ) {
-               AddFaceWithTexture( newBrush, v1, v3, v6, texture, FALSE );
+               AddFaceWithTexture( newBrush, v1, v3, v6, texture, false );
        }
        if ( useFaces[2] ) {
-               AddFaceWithTexture( newBrush, v1, v7, v2, texture, FALSE );
+               AddFaceWithTexture( newBrush, v1, v7, v2, texture, false );
        }
 
        if ( useFaces[3] ) {
-               AddFaceWithTexture( newBrush, v5, v6, v3, texture, FALSE );
+               AddFaceWithTexture( newBrush, v5, v6, v3, texture, false );
        }
        if ( useFaces[4] ) {
-               AddFaceWithTexture( newBrush, v5, v2, v7, texture, FALSE );
+               AddFaceWithTexture( newBrush, v5, v2, v7, texture, false );
        }
        if ( useFaces[5] ) {
-               AddFaceWithTexture( newBrush, v5, v7, v6, texture, FALSE );
+               AddFaceWithTexture( newBrush, v5, v7, v6, texture, false );
        }
 
        //----------------------------------
@@ -367,7 +380,7 @@ brush_t* Build_Get_BoundingCube_Selective( vec3_t min, vec3_t max, char* texture
        return newBrush;
 }
 
-brush_t* Build_Get_BoundingCube( vec3_t min, vec3_t max, char* texture ){
+scene::Node& Build_Get_BoundingCube( vec3_t min, vec3_t max, char* texture ){
        return Build_Get_BoundingCube_Selective( min, max, texture, bFacesAll );
 }
 
@@ -375,7 +388,7 @@ brush_t* Build_Get_BoundingCube( vec3_t min, vec3_t max, char* texture ){
 //-----------------------------------------------------------------------------------
 
 void Build_StairStep( vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction ){
-       brush_t* newBrush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
+       NodeSmartReference newBrush( GlobalBrushCreator().createBrush() );
 
        //----- Build Outer Bounds ---------
 
@@ -395,45 +408,45 @@ void Build_StairStep( vec3_t min, vec3_t max, const char* mainTexture, const cha
 
        //----------------------------------
 
-       AddFaceWithTexture( newBrush, v6, v5, v7, mainTexture, FALSE );
+       AddFaceWithTexture( newBrush, v6, v5, v7, mainTexture, false );
        // top gets current texture
 
 
        if ( direction == MOVE_EAST ) {
-               AddFaceWithTexture( newBrush, v1, v3, v6, riserTexture, FALSE );
+               AddFaceWithTexture( newBrush, v1, v3, v6, riserTexture, false );
        }
        else{
-               AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush, v1, v3, v6, "textures/common/caulk", false );
        }
        // west facing side, etc...
 
 
        if ( direction == MOVE_NORTH ) {
-               AddFaceWithTexture( newBrush, v1, v7, v2, riserTexture, FALSE );
+               AddFaceWithTexture( newBrush, v1, v7, v2, riserTexture, false );
        }
        else{
-               AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush, v1, v7, v2, "textures/common/caulk", false );
        }
 
        if ( direction == MOVE_SOUTH ) {
-               AddFaceWithTexture( newBrush, v3, v5, v6, riserTexture, FALSE );
+               AddFaceWithTexture( newBrush, v3, v5, v6, riserTexture, false );
        }
        else{
-               AddFaceWithTexture( newBrush, v3, v5, v6, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush, v3, v5, v6, "textures/common/caulk", false );
        }
 
        if ( direction == MOVE_WEST ) {
-               AddFaceWithTexture( newBrush, v7, v5, v2, riserTexture, FALSE );
+               AddFaceWithTexture( newBrush, v7, v5, v2, riserTexture, false );
        }
        else{
-               AddFaceWithTexture( newBrush, v7, v5, v2, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush, v7, v5, v2, "textures/common/caulk", false );
        }
 
 
-       AddFaceWithTexture( newBrush, v1, v2, v3, "textures/common/caulk", FALSE );
+       AddFaceWithTexture( newBrush, v1, v2, v3, "textures/common/caulk", false );
        // base is caulked
 
-       g_FuncTable.m_pfnCommitBrushHandle( newBrush );
+       Node_getTraversable( GlobalRadiant().getMapWorldEntity() )->insert( newBrush );
        // finish brush
 }
 
@@ -489,23 +502,23 @@ void BuildDoorsX2( vec3_t min, vec3_t max,
 
        //----------------------------------
 
-       brush_t* newBrush1 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
-       brush_t* newBrush2 = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
+       NodeSmartReference newBrush1( GlobalBrushCreator().createBrush() );
+       NodeSmartReference newBrush2( GlobalBrushCreator().createBrush() );
 
-       AddFaceWithTexture( newBrush1, v1, v2, v3, "textures/common/caulk", FALSE );
-       AddFaceWithTexture( newBrush1, v5, v7, v6, "textures/common/caulk", FALSE );
+       AddFaceWithTexture( newBrush1, v1, v2, v3, "textures/common/caulk", false );
+       AddFaceWithTexture( newBrush1, v5, v7, v6, "textures/common/caulk", false );
 
-       AddFaceWithTexture( newBrush2, v1, v2, v3, "textures/common/caulk", FALSE );
-       AddFaceWithTexture( newBrush2, v5, v7, v6, "textures/common/caulk", FALSE );
+       AddFaceWithTexture( newBrush2, v1, v2, v3, "textures/common/caulk", false );
+       AddFaceWithTexture( newBrush2, v5, v7, v6, "textures/common/caulk", false );
 
        if ( direction == 0 ) {
-               AddFaceWithTexture( newBrush1, v1, v3, v6, "textures/common/caulk", FALSE );
-               AddFaceWithTexture( newBrush2, v5, v2, v7, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush1, v1, v3, v6, "textures/common/caulk", false );
+               AddFaceWithTexture( newBrush2, v5, v2, v7, "textures/common/caulk", false );
        }
        else
        {
-               AddFaceWithTexture( newBrush1, v1, v7, v2, "textures/common/caulk", FALSE );
-               AddFaceWithTexture( newBrush2, v5, v6, v3, "textures/common/caulk", FALSE );
+               AddFaceWithTexture( newBrush1, v1, v7, v2, "textures/common/caulk", false );
+               AddFaceWithTexture( newBrush2, v5, v6, v3, "textures/common/caulk", false );
        }
 
        if ( direction == 0 ) {
@@ -552,40 +565,32 @@ void BuildDoorsX2( vec3_t min, vec3_t max,
        //----------------------------------
 
 
-       entity_t* pEDoor1 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
-       entity_t* pEDoor2 = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
-
-       epair_t* epDoor11 = GetNextChainItem( NULL, "classname", "func_door" );
-       epair_t* epDoor21 = GetNextChainItem( NULL, "classname", "func_door" );
-
-       epair_t* epDoor12;
-       epair_t* epDoor22;
+       EntityClass* doorClass = GlobalEntityClassManager().findOrInsert( "func_door", true );
+       NodeSmartReference pEDoor1( GlobalEntityCreator().createEntity( doorClass ) );
+       NodeSmartReference pEDoor2( GlobalEntityCreator().createEntity( doorClass ) );
 
        if ( direction == 0 ) {
-               epDoor12 = GetNextChainItem( epDoor11, "angle", "180" );
-               epDoor22 = GetNextChainItem( epDoor21, "angle", "360" );
+               Node_getEntity( pEDoor1 )->setKeyValue( "angle", "180" );
+               Node_getEntity( pEDoor2 )->setKeyValue( "angle", "360" );
        }
        else
        {
-               epDoor12 = GetNextChainItem( epDoor11, "angle", "270" );
-               epDoor22 = GetNextChainItem( epDoor21, "angle", "90" );
+               Node_getEntity( pEDoor1 )->setKeyValue( "angle", "270" );
+               Node_getEntity( pEDoor2 )->setKeyValue( "angle", "90" );
        }
 
        srand( (unsigned)time( NULL ) );
 
        char teamname[256];
        sprintf( teamname, "t%i", rand() );
-       /*epair_t* epDoor13 = */ GetNextChainItem( epDoor12, "team", teamname );
-       /*epair_t* epDoor23 = */ GetNextChainItem( epDoor22, "team", teamname );
+       Node_getEntity( pEDoor1 )->setKeyValue( "team", teamname );
+       Node_getEntity( pEDoor2 )->setKeyValue( "team", teamname );
 
-       g_FuncTable.m_pfnCommitBrushHandleToEntity( newBrush1, pEDoor1 );
-       g_FuncTable.m_pfnCommitBrushHandleToEntity( newBrush2, pEDoor2 );
+       Node_getTraversable( pEDoor1 )->insert( newBrush1 );
+       Node_getTraversable( pEDoor2 )->insert( newBrush2 );
 
-       g_EntityTable.m_pfnSetEntityKeyValList( pEDoor1, epDoor11 );
-       g_EntityTable.m_pfnSetEntityKeyValList( pEDoor2, epDoor21 );
-
-       g_FuncTable.m_pfnCommitEntityHandleToMap( pEDoor1 );
-       g_FuncTable.m_pfnCommitEntityHandleToMap( pEDoor2 );
+       Node_getTraversable( GlobalSceneGraph().root() )->insert( pEDoor1 );
+       Node_getTraversable( GlobalSceneGraph().root() )->insert( pEDoor2 );
 
 //     ResetCurrentTexture();
 }
@@ -594,41 +599,50 @@ void BuildDoorsX2( vec3_t min, vec3_t max,
 //-----------------------------------------------------------------------------------
 
 void MakeBevel( vec3_t vMin, vec3_t vMax ){
-       int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
-       //$ FIXME: m_pfnGetPatchHandle
-       patchMesh_t* pm = g_FuncTable.m_pfnGetPatchData( nIndex );
-
-       pm->height = 3;
-       pm->width = 3;
-
+       NodeSmartReference patch( GlobalPatchCreator().createPatch() );
+       GlobalPatchCreator().Patch_resize( patch, 3, 3 );
+       GlobalPatchCreator().Patch_setShader( patch, "textures/common/caulk" );
+       PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints( patch );
        vec3_t x_3, y_3, z_3;
        x_3[0] = vMin[0];   x_3[1] = vMin[0];               x_3[2] = vMax[0];
        y_3[0] = vMin[1];   y_3[1] = vMax[1];               y_3[2] = vMax[1];
        z_3[0] = vMin[2];   z_3[1] = ( vMax[2] + vMin[2] ) / 2; z_3[2] = vMax[2];
-
-/*     x_3[0] = 0;             x_3[1] = 0;             x_3[2] = 64;
-    y_3[0] = 0;                y_3[1] = 64;    y_3[2] = 64;
-    z_3[0] = 0;                z_3[1] = 32;    z_3[2] = 64;*/
-
+       /*
+          x_3[0] = 0;          x_3[1] = 0;             x_3[2] = 64;
+          y_3[0] = 0;          y_3[1] = 64;    y_3[2] = 64;
+          z_3[0] = 0;          z_3[1] = 32;    z_3[2] = 64;*/
        for ( int i = 0; i < 3; i++ )
        {
                for ( int j = 0; j < 3; j++ )
                {
-                       pm->ctrl[i][j].xyz[0] = x_3[i];
-                       pm->ctrl[i][j].xyz[1] = y_3[i];
-                       pm->ctrl[i][j].xyz[2] = z_3[j];
+                       PatchControl& p = matrix( i, j );
+                       p.m_vertex[0] = x_3[i];
+                       p.m_vertex[1] = y_3[i];
+                       p.m_vertex[2] = z_3[j];
                }
        }
-
-
-       g_FuncTable.m_pfnCommitPatchHandleToMap( nIndex, pm, "textures/common/caulk" );
+       //does invert the matrix, else the patch face is on wrong side.
+       for ( int i = 0 ; i < 3 ; i++ )
+       {
+               for ( int j = 0; j < 1; j++ )
+               {
+                       PatchControl& p = matrix( i,2 - j );
+                       PatchControl& q = matrix( i, j );
+                       std::swap( p.m_vertex, q.m_vertex );
+                       //std::swap(p.m_texcoord, q.m_texcoord);
+               }
+       }
+       GlobalPatchCreator().Patch_controlPointsChanged( patch );
+       //TODO - the patch has textures weird, patchmanip.h has all function it needs.. lots of duplicate code..
+       //NaturalTexture(patch);
+       Node_getTraversable( GlobalRadiant().getMapWorldEntity() )->insert( patch );
 }
 
 void BuildCornerStairs( vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex ){
        vec3_t* topPoints = new vec3_t[nSteps + 1];
        vec3_t* botPoints = new vec3_t[nSteps + 1];
 
-       bool bFacesUse[6] = {TRUE, TRUE, FALSE, TRUE, FALSE, FALSE};
+       //bool bFacesUse[6] = {true, true, false, true, false, false};
 
        vec3_t centre;
        VectorCopy( vMin, centre );
@@ -663,17 +677,34 @@ void BuildCornerStairs( vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTe
 
        for ( i = 0; i < nSteps; i++ )
        {
-               brush_t* brush = Build_Get_BoundingCube_Selective( vBot, vTop, "textures/common/caulk", bFacesUse );
+               NodeSmartReference brush( GlobalBrushCreator().createBrush() );
+               vec3_t v1, v2, v3, v5, v6, v7;
+               VectorCopy( vBot, v1 );
+               VectorCopy( vBot, v2 );
+               VectorCopy( vBot, v3 );
+               VectorCopy( vTop, v5 );
+               VectorCopy( vTop, v6 );
+               VectorCopy( vTop, v7 );
+
+               v2[0] = vTop[0];
+               v3[1] = vTop[1];
+
+               v6[0] = vBot[0];
+               v7[1] = vBot[1];
+
+               AddFaceWithTexture( brush, v1, v2, v3, "textures/common/caulk", false );
+               AddFaceWithTexture( brush, v1, v3, v6, "textures/common/caulk", false );
+               AddFaceWithTexture( brush, v5, v6, v3, "textures/common/caulk", false );
 
                for ( int j = 0; j < 3; j++ )
                        tp[j][2] = vTop[2];
 
-               AddFaceWithTexture( brush, tp[2], tp[1], tp[0], mainTexture, FALSE );
+               AddFaceWithTexture( brush, tp[2], tp[1], tp[0], mainTexture, false );
 
-               AddFaceWithTexture( brush, centre, botPoints[i + 1], topPoints[i + 1], "textures/common/caulk", FALSE );
-               AddFaceWithTexture( brush, centre, topPoints[i], botPoints[i], riserTex, FALSE );
+               AddFaceWithTexture( brush, centre, botPoints[i + 1], topPoints[i + 1], "textures/common/caulk", false );
+               AddFaceWithTexture( brush, centre, topPoints[i], botPoints[i], riserTex, false );
 
-               g_FuncTable.m_pfnCommitBrushHandle( brush );
+               Node_getTraversable( GlobalRadiant().getMapWorldEntity() )->insert( brush );
 
                vTop[2] += height;
                vBot[2] += height;