]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/misc.cpp
* applied patch by StefanV (from mailinglist) that fixes an error in config.py (broke...
[xonotic/netradiant.git] / contrib / bobtoolz / misc.cpp
index e56c4d89129056299a27bba921889c80733e1c00..a0490b46ff65addb886496fa4a42841b2274be1c 100644 (file)
@@ -17,18 +17,9 @@ License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#include "misc.h"
+#include "StdAfx.h"
 
-#include <list>
-#include "str.h"
-
-#include "DPoint.h"
-#include "DPlane.h"
-#include "DBrush.h"
-#include "DEPair.h"
-#include "DPatch.h"
 #include "DEntity.h"
-
 #include "funchandlers.h"
 
 #ifdef __linux__
@@ -36,16 +27,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include <unistd.h>
 #endif
 
-#include "iundo.h"
-#include "qerplugin.h"
-
-#include <vector>
-#include <list>
-#include <map>
-#include <algorithm>
-
-#include "scenelib.h"
-
 /*==========================
                Global Vars
 ==========================*/
@@ -58,7 +39,7 @@ char  g_CurrentTexture[256] = "";
 
 void ReadCurrentTexture()
 {
-       const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
+       const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
        strcpy(g_CurrentTexture, textureName);
 }
 
@@ -68,6 +49,16 @@ const char*  GetCurrentTexture()
        return g_CurrentTexture;
 }
 
+epair_t* GetNextChainItem(epair_t* lastItem, const char* key, const char* value)
+{
+       epair_t* nextEPair = g_FuncTable.m_pfnAllocateEpair(key, value);
+
+       if(lastItem != NULL)
+               lastItem->next = nextEPair;
+
+       return nextEPair;
+}
+
 void MoveBlock(int dir, vec3_t min, vec3_t max, float dist)
 {
        switch(dir)
@@ -126,7 +117,7 @@ void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)
        }
 }
 
-char* TranslateString (char *buf)
+char* TranslateString (const char *buf)
 {
        static  char    buf2[32768];
        int             i, l;
@@ -149,10 +140,33 @@ char* TranslateString (char *buf)
        return buf2;
 }
 
+void Sys_ERROR (const char* text, ...)
+{
+       va_list argptr;
+       char    buf[32768];
+
+       va_start (argptr,text);
+       vsprintf (buf, text,argptr);
+       va_end (argptr);
+
+       Sys_Printf("BobToolz::ERROR->%s", buf);
+}
+
+/*void Sys_Printf (char *text, ...)
+{
+       va_list argptr;
+       char    buf[32768];
+
+       va_start (argptr,text);
+       vsprintf (buf, text,argptr);
+       va_end (argptr);
+
+       g_FuncTable.m_pfnSysMsg ( buf );
+}*/
 
 char* UnixToDosPath(char* path)
 {
-#ifndef WIN32
+#ifndef _WIN32
        return path;
 #else
        for(char* p = path; *p; p++)
@@ -177,7 +191,7 @@ const char* ExtractFilename(const char* path)
        return ++p;
 }
 
-extern char* PLUGIN_NAME;
+extern const char* PLUGIN_NAME;
 /*char* GetGameFilename(char* buffer, const char* filename)
 {
        strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
@@ -215,12 +229,7 @@ bool Q_Exec( const char *pCmd, bool bCreateConsole )
 }
 #endif
 
-#include <windows.h>
-
-#ifdef WIN32
-
-#include <windows.h>
-
+#ifdef _WIN32
 bool Q_Exec( const char *pCmd, bool bCreateConsole )
 {
        // G_DeWan: Don't know if this is needed for linux version
@@ -250,9 +259,9 @@ void StartBSP()
        GetFilename(exename, "q3map");
        UnixToDosPath(exename); // do we want this done in linux version?
 
-       char mapname[256];  
+       char mapname[256];
   const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
-  
+
        strcpy( mapname, pn );
        strcat( mapname, "/ac_prt.map" );
        UnixToDosPath(mapname);
@@ -263,14 +272,14 @@ void StartBSP()
        Q_Exec( command, TRUE );
 }
 
-void BuildMiniPrt(std::list<Str>* exclusionList)
+void BuildMiniPrt(list<Str>* exclusionList)
 {
        // yes, we could just use -fulldetail option, but, as SPOG said
        // it'd be faster without all the hint, donotenter etc textures and
        // doors, etc
 
        DEntity world;
-       
+
        char buffer[128];
   const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
 
@@ -282,8 +291,7 @@ void BuildMiniPrt(std::list<Str>* exclusionList)
        if(!pFile)
                return;
 
-#if 0
-  int count = g_FuncTable.m_pfnGetEntityCount();
+       int count = g_FuncTable.m_pfnGetEntityCount();
        for(int i = 0; i < count; i++)
        {
                entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i);
@@ -314,41 +322,14 @@ void BuildMiniPrt(std::list<Str>* exclusionList)
                        ep = ep->next;
                }
        }
-#endif
 
        fclose(pFile);
 
        StartBSP();
 }
 
-template<typename Functor>
-class EntityWalker
-{
-  const Functor& functor;
-public:
-  EntityWalker(const Functor& functor) : functor(functor)
-  {
-  }
-  bool pre(const Path& path, Instance& instance) const
-  {
-    if(Node_isEntity(path.top()))
-    {
-      functor(path.top());
-    }
-  }
-};
-
-template<typename Functor>
-const Functor& Scene_forEachEntity(const Functor& functor)
-{
-  GlobalSceneGraph().traverse(EntityWalker<Functor>(functor));
-}
-
-void 
-
-scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
+entity_s* FindEntityFromTargetname(const char* targetname, int* entNum)
 {
-#if 0
        DEntity world;
 
        int count = g_FuncTable.m_pfnGetEntityCount();
@@ -363,7 +344,7 @@ scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
                DEPair* tn = world.FindEPairByKey("targetname");
                if(tn)
                {
-                       if(string_equal_nocase(tn->value, targetname)) {
+                       if(!stricmp(tn->value, targetname)) {
                                if(entNum) {
                                        *entNum = i;
                                }
@@ -371,28 +352,27 @@ scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
                        }
                }
        }
-
-#endif
        return NULL;
 }
 
 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
 {
-       faceData->m_texdef.rotate = 0;
-       faceData->m_texdef.scale[0] = 0.5;
-       faceData->m_texdef.scale[1] = 0.5;
-       faceData->m_texdef.shift[0] = 0;
-       faceData->m_texdef.shift[1] = 0;
-       faceData->m_texdef.contents = 0;
-       faceData->m_texdef.flags = 0;
-       faceData->m_texdef.value = 0;
+       faceData->m_bBPrimit = FALSE;
+       faceData->m_fRotate = 0;
+       faceData->m_fScale[0] = 0.5;
+       faceData->m_fScale[1] = 0.5;
+       faceData->m_fShift[0] = 0;
+       faceData->m_fShift[1] = 0;
+       faceData->m_nContents = 0;
+       faceData->m_nFlags = 0;
+       faceData->m_nValue = 0;
        if(*texture)
-               faceData->m_shader = texture;
+               strcpy(faceData->m_TextureName, texture);
        else
-               faceData->m_shader = "textures/common/caulk";
-       VectorCopy(va, faceData->m_p0);
-       VectorCopy(vb, faceData->m_p1);
-       VectorCopy(vc, faceData->m_p2);
+               strcpy(faceData->m_TextureName, "textures/common/caulk");
+       VectorCopy(va, faceData->m_v1);
+       VectorCopy(vb, faceData->m_v2);
+       VectorCopy(vc, faceData->m_v3);
 }
 
 float Determinant3x3(float a1, float a2, float a3,
@@ -404,13 +384,28 @@ float Determinant3x3(float a1, float a2, float a3,
 
 bool GetEntityCentre(const char* entity, vec3_t centre)
 {
-  const scene::Path* ent = FindEntityFromTargetname(entity, NULL);
+       entity_s* ent = FindEntityFromTargetname(entity, NULL);
        if(!ent)
                return FALSE;
 
-  scene::Instance& instance = *GlobalSceneGraph().find(*ent);
-  VectorCopy(instance.aabb_world().origin, centre);
+       int cnt = g_FuncTable.m_pfnAllocateEntityBrushHandles(ent);
+       if(cnt == 0)
+       {
+               g_FuncTable.m_pfnReleaseEntityBrushHandles();
+               return FALSE;
+       }
+
+       brush_t* brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle(0);
+       DBrush cBrush;
+       cBrush.LoadFromBrush_t(brush, FALSE);
+
+       vec3_t min, max;
+       cBrush.GetBounds(min, max);
+
+       VectorAdd(min, max, centre);
+       VectorScale(centre, 0.5f, centre);
 
+       g_FuncTable.m_pfnReleaseEntityBrushHandles();
        return TRUE;
 }
 
@@ -421,19 +416,9 @@ vec_t Min(vec_t a, vec_t b)
        return b;
 }
 
-void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
+void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {
        vec3_t v1, v2;
        VectorSubtract(va, vb, v1);
        VectorSubtract(vc, vb, v2);
        CrossProduct(v1, v2, out);
 }
-
-char* GetFilename(char* buffer, const char* filename) {
-       strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient));
-       StripFilename( buffer );
-       strcat(buffer, "/");
-       strcat(buffer, filename);
-       //buffer = UnixToDosPath(buffer);
-       return buffer;
-}
-