]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/DEntity.cpp
Fixing Linux SCons build.
[xonotic/netradiant.git] / contrib / bobtoolz / DEntity.cpp
index 5a76ca123fb31d8dfa0957274524f4b18697dcbe..ca035b830770115cc74afeb16101017ba6c852ea 100644 (file)
@@ -21,38 +21,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
 //////////////////////////////////////////////////////////////////////
 
-#ifdef WIN32
-#pragma warning(disable : 4786)
-#endif
-
 #include "StdAfx.h"
 
-#include "gtkr_list.h"
-#include "str.h"
+#ifdef _WIN32
+#pragma warning(disable : 4786)
+#endif
 
-#include "DPoint.h"
-#include "DPlane.h"
-#include "DBrush.h"
-#include "DEPair.h"
-#include "DPatch.h"
 #include "DEntity.h"
 
-#include "dialogs-gtk.h"
+#include "dialogs/dialogs-gtk.h"
 #include "misc.h"
 #include "CPortals.h"
 
-#include "iundo.h"
-
-#include "refcounted_ptr.h"
-
-#include <vector>
-#include <list>
-#include <map>
-#include <algorithm>
-
-#include "scenelib.h"
-
-
 const char* brushEntityList[] = {
        "worldspawn",
        "trigger_always",
@@ -77,7 +57,7 @@ const char* brushEntityList[] = {
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
-DEntity::DEntity(const char *classname, int ID)
+DEntity::DEntity(char *classname, int ID)
 {
        SetClassname(classname);
        m_nID = ID;
@@ -155,7 +135,7 @@ bool DEntity::LoadFromPrt(char *filename)
 
        ClearBrushes();
        ClearEPairs();
-       
+
   bool build = false;
        for(unsigned int i = 0; i < portals.node_count; i++)
        {
@@ -164,7 +144,7 @@ bool DEntity::LoadFromPrt(char *filename)
 
                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++) 
+      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);
@@ -172,7 +152,7 @@ bool DEntity::LoadFromPrt(char *filename)
              CrossProduct(v1, v2, n);
         VectorNormalize(n, v2);
 
-        if(k == 0) 
+        if(k == 0)
         {
           VectorCopy(v2, normal);
         }
@@ -230,13 +210,12 @@ void DEntity::LoadSelectedBrushes()
        ClearBrushes();
        ClearEPairs();
 
-#if 0
        int count = g_FuncTable.m_pfnAllocateSelectedBrushHandles();
 
        for(int i = 0; i < count; i++) {
                brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
 
-               if(brush->patchBrush)
+               if(brush->pPatch)
                        continue;
 
                DBrush* loadBrush = NewBrush(i);
@@ -244,7 +223,6 @@ void DEntity::LoadSelectedBrushes()
        }
 
        g_FuncTable.m_pfnReleaseSelectedBrushHandles();
-#endif
 }
 
 void DEntity::LoadSelectedPatches()
@@ -252,7 +230,6 @@ void DEntity::LoadSelectedPatches()
        ClearPatches();
        ClearEPairs();
 
-#if 0
   int count = g_FuncTable.m_pfnAllocateSelectedPatchHandles();
 
        for(int i = 0; i < count; i++)
@@ -265,7 +242,6 @@ void DEntity::LoadSelectedPatches()
        }
 
   g_FuncTable.m_pfnReleasePatchHandles();
-#endif
 }
 
 bool* DEntity::BuildIntersectList()
@@ -323,30 +299,31 @@ void DEntity::SelectBrushes(bool *selectList)
        if(selectList == NULL)
                return;
 
-  GlobalSelectionSystem().Select(false);
+       g_FuncTable.m_pfnDeselectAllBrushes();
 
-  scene::Path path(GlobalSceneGraph().root());
-  path.push(QER_Entity);
+       g_FuncTable.m_pfnAllocateActiveBrushHandles();
 
-       for(std::list<DBrush *>::const_iterator pBrush=brushList.begin(); pBrush!=brushList.end(); pBrush++)
+       for(list<DBrush *>::const_iterator pBrush=brushList.begin(); pBrush!=brushList.end(); pBrush++)
        {
                if(selectList[(*pBrush)->m_nBrushID])
-    {
-      path.push((*pBrush)->QER_brush);
-      GlobalSceneGraph().find(path)->selectable()->select(true);
-      path.pop();
-    }
+                       g_FuncTable.m_pfnSelectBrush((*pBrush)->QER_brush);
        }
+       g_FuncTable.m_pfnReleaseActiveBrushHandles();
+}
+
+bool DEntity::LoadFromEntity(int id, bool bLoadPatches) {
+       return LoadFromEntity((entity_t*)g_FuncTable.m_pfnGetEntityHandle(id), bLoadPatches);
 }
 
-bool DEntity::LoadFromEntity(scene::Node* ent, bool bLoadPatches) {
+bool DEntity::LoadFromEntity(entity_t* ent, bool bLoadPatches) {
        ClearPatches();
        ClearBrushes();
        ClearEPairs();
 
        QER_Entity = ent;
 
-       LoadEPairList(ent->m_entity);
+       epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(QER_Entity);
+       LoadEPairList(epl);
 
        bool keep = FALSE;
        int i;
@@ -362,38 +339,34 @@ bool DEntity::LoadFromEntity(scene::Node* ent, bool bLoadPatches) {
        if(!keep)
                return FALSE;
 
-  if(ent->m_traverse)
-  {
-    class load_brushes_t : public scene::Traversable::Walker
-    {
-      DEntity* m_entity;
-      int m_count;
-    public:
-      load_brushes_t(DEntity* entity)
-        : m_entity(entity), m_count(0)
-      {
-      }
-      bool pre(scene::Node* node)
-      {
-        if(node->m_brush)
-        {
-          DPatch* loadPatch = m_entity->NewPatch();
-                                 loadPatch->LoadFromBrush(node);
-        }
-        else if(node->m_patch)
-        {
-                           DBrush* loadBrush = m_entity->NewBrush(m_count++);
-                           loadBrush->LoadFromBrush(node, TRUE);
-        }
-        return false;
-      }
-      void post(scene::Node* node)
-      {
-      }
-    } load_brushes(this);
+       int count = g_FuncTable.m_pfnAllocateEntityBrushHandles(QER_Entity);
 
-    ent->m_traverse->traverse(load_brushes);
-  }
+       for(i = 0; i < count; i++)
+       {
+
+               brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle(i);
+
+    if(brush == NULL) {
+                       DoMessageBox("GTKRadiant returned a NULL pointer, NOT a good sign", "WARNING!!!", MB_OK);
+      continue;
+    }
+
+               if(brush->pPatch)
+               {
+                       if(bLoadPatches)
+                       {
+                               DPatch* loadPatch = NewPatch();
+                               loadPatch->LoadFromBrush_t(brush);
+                       }
+               }
+               else
+               {
+                       DBrush* loadBrush = NewBrush(i);
+                       loadBrush->LoadFromBrush_t(brush, TRUE);
+               }
+       }
+
+       g_FuncTable.m_pfnReleaseEntityBrushHandles();
 
        return TRUE;
 }
@@ -439,16 +412,30 @@ void DEntity::ResetChecks(list<Str>* exclusionList)
        }
 }
 
-int DEntity::FixBrushes()
+int DEntity::FixBrushes(bool rebuild)
 {
-       int count = 0;
+       g_FuncTable.m_pfnAllocateActiveBrushHandles();
+
+       int cnt = 0;
 
        for(list<DBrush *>::const_iterator fixBrush=brushList.begin(); fixBrush!=brushList.end(); fixBrush++)
        {
-    count += (*fixBrush)->RemoveRedundantPlanes();
+               int count = (*fixBrush)->RemoveRedundantPlanes();
+               if(count)
+               {
+                       cnt += count;
+                       if(rebuild)
+                       {
+                               g_FuncTable.m_pfnDeleteBrushHandle((*fixBrush)->QER_brush);
+
+                               (*fixBrush)->BuildInRadiant(FALSE, NULL);
+                       }
+               }
        }
 
-       return count;
+       g_FuncTable.m_pfnReleaseActiveBrushHandles();
+
+       return cnt;
 }
 
 void DEntity::BuildInRadiant(bool allowDestruction)
@@ -457,22 +444,28 @@ void DEntity::BuildInRadiant(bool allowDestruction)
 
        if(makeEntity)
        {
-    NodePtr node(GlobalEntityCreator().createEntity(m_Classname.GetBuffer()));
+               entity_t* pE = (entity_t*)g_FuncTable.m_pfnCreateEntityHandle();
+
+               epair_t* pEpS = GetNextChainItem(NULL, "classname", m_Classname);
+
+               epair_t* pEp = pEpS;
 
                for(list<DEPair* >::const_iterator buildEPair=epairList.begin(); buildEPair!=epairList.end(); buildEPair++)
                {
-      node->m_entity->setkeyvalue((*buildEPair)->key, (*buildEPair)->value);
+                       pEp = GetNextChainItem(pEp, (*buildEPair)->key, (*buildEPair)->value);
                }
 
-               GlobalSceneGraph().root()->m_traverse->insert(node);
+               g_EntityTable.m_pfnSetEntityKeyValList(pE, pEpS);
+
+               g_FuncTable.m_pfnCommitEntityHandleToMap(pE);
 
                for(list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
-                       (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node);
+                       (*buildBrush)->BuildInRadiant(allowDestruction, NULL, pE);
 
                for(list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
-                       (*buildPatch)->BuildInRadiant(node);
+                       (*buildPatch)->BuildInRadiant(pE);
 
-               QER_Entity = node;
+               QER_Entity = pE;
        }
        else
        {
@@ -495,7 +488,7 @@ int DEntity::GetIDMax( void ) {
        return max+1;
 }
 
-void DEntity::SetClassname( const char *classname ) {
+void DEntity::SetClassname( char *classname ) {
        m_Classname = classname;
 }
 
@@ -527,8 +520,8 @@ void DEntity::ClearEPairs()
        epairList.clear();
 }
 
-void DEntity::AddEPair(const char *key, const char *value) {   
-       DEPair* newEPair; 
+void DEntity::AddEPair(const char *key, const char *value) {
+       DEPair* newEPair;
        newEPair = FindEPairByKey( key );
        if(!newEPair) {
                newEPair = new DEPair;
@@ -539,42 +532,48 @@ void DEntity::AddEPair(const char *key, const char *value) {
        }
 }
 
-void DEntity::LoadEPairList(Entity *epl)
+void DEntity::LoadEPairList(epair_t *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);
+       epair_t* ep = epl;
+       while(ep)
+       {
+               if(!strcmp(ep->key, "classname"))
+                       SetClassname(ep->value);
+               else
+                       AddEPair(ep->key, ep->value);
 
-  epl->accept(load_epairs);
+               ep = ep->next;
+       }
 }
 
-bool DEntity::ResetTextures(const char* textureName, float fScale[2],     float fShift[2],    int rotation, const char* newTextureName, 
+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)
 {
+       g_FuncTable.m_pfnDeselectAllBrushes();
+
+       g_FuncTable.m_pfnAllocateActiveBrushHandles();
+
        bool reset = FALSE;
 
        for(list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
        {
-               bool tmp = (*resetBrush)->ResetTextures(textureName,        fScale,       fShift,       rotation, newTextureName, 
+               bool tmp = (*resetBrush)->ResetTextures(textureName,        fScale,       fShift,       rotation, newTextureName,
                                             bResetTextureName,  bResetScale,  bResetShift,  bResetRotation);
 
                if(tmp)
                {
                        reset = TRUE;
+
+                       if(rebuild)
+                       {
+        entity_t *pE = (*resetBrush)->QER_brush->owner;
+                               g_FuncTable.m_pfnDeleteBrushHandle((*resetBrush)->QER_brush);
+        (*resetBrush)->BuildInRadiant(FALSE, NULL, pE->entityId == 0 ? NULL : pE);
+
+        if( pE->entityId == 0 ? NULL : pE )
+        {
+        }
+                       }
                }
        }
 
@@ -587,10 +586,19 @@ bool DEntity::ResetTextures(const char* textureName, float fScale[2],     float
                  if(tmp)
                  {
                          reset = TRUE;
+
+                         if(rebuild)
+                         {
+          entity_t *pE = (*resetPatch)->QER_brush->owner;
+                                 g_FuncTable.m_pfnDeleteBrushHandle((*resetPatch)->QER_brush);
+          (*resetPatch)->BuildInRadiant(pE->entityId == 0 ? NULL : pE);
+                         }
                  }
          }
   }
 
+       g_FuncTable.m_pfnReleaseActiveBrushHandles();
+
        return reset;
 }
 
@@ -607,7 +615,7 @@ DEPair* DEntity::FindEPairByKey(const char* keyname)
 
 void DEntity::RemoveFromRadiant()
 {
-       GlobalSceneGraph().root()->m_traverse->erase(QER_Entity);
+       g_EntityTable.m_pfnEntity_Free( (entity_t*)QER_Entity );
 
        QER_Entity = NULL;
 }
@@ -636,9 +644,9 @@ void DEntity::SpawnFloat(const char* key, const char* defaultstring, float* out)
 {
        DEPair* pEP = FindEPairByKey(key);
        if(pEP) {
-               *out = static_cast<float>(atof(pEP->value));
+               *out = static_cast< float >( atof( pEP->value ) );
        } else {
-               *out = static_cast<float>(atof(defaultstring));
+               *out = static_cast< float >( atof(defaultstring) );
        }
 }
 
@@ -656,7 +664,7 @@ int DEntity::GetBrushCount( void ) {
        return brushList.size();
 }
 
-DBrush* DEntity::FindBrushByPointer( scene::Node* brush ) {
+DBrush* DEntity::FindBrushByPointer( brush_t* brush ) {
        for(list<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) {
                DBrush* pBrush = (*listBrush);
                if(pBrush->QER_brush == brush) {