]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/misc.cpp
more eol-style
[xonotic/netradiant.git] / contrib / bobtoolz / misc.cpp
index bebc2b24d6105295cf3802c4326ee86fcbf3d3ec..a061e8672414f9e3c730c9ea1e8630ffd0d928c6 100644 (file)
-/*\r
-BobToolz plugin for GtkRadiant\r
-Copyright (C) 2001 Gordon Biggans\r
-\r
-This library is free software; you can redistribute it and/or\r
-modify it under the terms of the GNU Lesser General Public\r
-License as published by the Free Software Foundation; either\r
-version 2.1 of the License, or (at your option) any later version.\r
-\r
-This library is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
-Lesser General Public License for more details.\r
-\r
-You should have received a copy of the GNU Lesser General Public\r
-License along with this library; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
-*/\r
-\r
-#include "StdAfx.h"\r
-\r
-#include "DEntity.h"\r
-#include "funchandlers.h"\r
-\r
-#ifdef __linux__\r
-#include <sys/types.h>\r
-#include <unistd.h>\r
-#endif\r
-\r
-/*==========================\r
-               Global Vars\r
-==========================*/\r
-\r
-//HANDLE bsp_process;\r
-char   g_CurrentTexture[256] = "";\r
-\r
-//=============================================================\r
-//=============================================================\r
-\r
-void ReadCurrentTexture()\r
-{\r
-       const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();\r
-       strcpy(g_CurrentTexture, textureName);\r
-}\r
-\r
-const char*  GetCurrentTexture()\r
-{\r
-       ReadCurrentTexture();\r
-       return g_CurrentTexture;\r
-}\r
-\r
-epair_t* GetNextChainItem(epair_t* lastItem, char* key, char* value)\r
-{\r
-       epair_t* nextEPair = g_FuncTable.m_pfnAllocateEpair(key, value);\r
-\r
-       if(lastItem != NULL)\r
-               lastItem->next = nextEPair;\r
-\r
-       return nextEPair;\r
-}\r
-\r
-void MoveBlock(int dir, vec3_t min, vec3_t max, float dist)\r
-{\r
-       switch(dir)\r
-       {\r
-               case MOVE_EAST:\r
-               {\r
-                       min[0]+=dist;\r
-                       max[0]+=dist;\r
-                       break;\r
-               }\r
-               case MOVE_WEST:\r
-               {\r
-                       min[0]-=dist;\r
-                       max[0]-=dist;\r
-                       break;\r
-               }\r
-               case MOVE_NORTH:\r
-               {\r
-                       min[1]+=dist;\r
-                       max[1]+=dist;\r
-                       break;\r
-               }\r
-               case MOVE_SOUTH:\r
-               {\r
-                       min[1]-=dist;\r
-                       max[1]-=dist;\r
-                       break;\r
-               }\r
-       }\r
-}\r
-\r
-void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)\r
-{\r
-       switch(dir)\r
-       {\r
-               case MOVE_EAST:\r
-               {\r
-                       max[0] = min[0] + width;\r
-                       break;\r
-               }\r
-               case MOVE_WEST:\r
-               {\r
-                       min[0] = max[0] - width;\r
-                       break;\r
-               }\r
-               case MOVE_NORTH:\r
-               {\r
-                       max[1] = min[1] + width;\r
-                       break;\r
-               }\r
-               case MOVE_SOUTH:\r
-               {\r
-                       min[1] = max[1] - width;\r
-                       break;\r
-               }\r
-       }\r
-}\r
-\r
-char* TranslateString (char *buf)\r
-{\r
-       static  char    buf2[32768];\r
-       int             i, l;\r
-       char    *out;\r
-\r
-       l = strlen(buf);\r
-       out = buf2;\r
-       for (i=0 ; i<l ; i++)\r
-       {\r
-               if (buf[i] == '\n')\r
-               {\r
-                       *out++ = '\r';\r
-                       *out++ = '\n';\r
-               }\r
-               else\r
-                       *out++ = buf[i];\r
-       }\r
-       *out++ = 0;\r
-\r
-       return buf2;\r
-}\r
-\r
-void Sys_ERROR (char* text, ...)\r
-{\r
-       va_list argptr;\r
-       char    buf[32768];\r
-\r
-       va_start (argptr,text);\r
-       vsprintf (buf, text,argptr);\r
-       va_end (argptr);\r
-\r
-       Sys_Printf("BobToolz::ERROR->%s", buf);\r
-}\r
-\r
-/*void Sys_Printf (char *text, ...)\r
-{\r
-       va_list argptr;\r
-       char    buf[32768];\r
-\r
-       va_start (argptr,text);\r
-       vsprintf (buf, text,argptr);\r
-       va_end (argptr);\r
-\r
-       g_FuncTable.m_pfnSysMsg ( buf );\r
-}*/\r
-\r
-char* UnixToDosPath(char* path)\r
-{\r
-#ifndef _WIN32\r
-       return path;\r
-#else\r
-       for(char* p = path; *p; p++)\r
-       {\r
-               if(*p == '/')\r
-                       *p = '\\';\r
-       }\r
-       return path;\r
-#endif\r
-}\r
-\r
-const char* ExtractFilename(const char* path)\r
-{\r
-       char* p = strrchr(path, '/');\r
-       if(!p)\r
-       {\r
-               p = strrchr(path, '\\');\r
-\r
-               if(!p)\r
-                       return path;\r
-       }\r
-       return ++p;\r
-}\r
-\r
-extern char* PLUGIN_NAME;\r
-/*char* GetGameFilename(char* buffer, const char* filename)\r
-{\r
-       strcpy(buffer, g_FuncTable.m_pfnGetGamePath());\r
-       char* p = strrchr(buffer, '/');\r
-       *++p = '\0';\r
-       strcat(buffer, filename);\r
-       buffer = UnixToDosPath(buffer);\r
-       return buffer;\r
-}*/\r
-\r
-#if defined (__linux__) || defined (__APPLE__)\r
-// the bCreateConsole parameter is ignored on linux ..\r
-bool Q_Exec( const char *pCmd, bool bCreateConsole )\r
-{\r
-       switch (fork())\r
-    {\r
-       case -1:\r
-      return false;\r
-//      Error ("CreateProcess failed");\r
-      break;\r
-    case 0:\r
-#ifdef _DEBUG\r
-                 printf("Running system...\n");\r
-                       printf("Command: %s\n", pCmd);\r
-#endif\r
-                       // NOTE: we could use that to detect when a step finishes. But then it\r
-                       // would not work for remote compiling stuff.\r
-//      execlp (pCmd, pCmd, NULL);\r
-                       system( pCmd );\r
-      printf ("system() returned");\r
-      _exit (0);\r
-      break;\r
-    }\r
-    return true;\r
-}\r
-#endif\r
-\r
-#ifdef _WIN32\r
-bool Q_Exec( const char *pCmd, bool bCreateConsole )\r
-{\r
-       // G_DeWan: Don't know if this is needed for linux version\r
-\r
-       PROCESS_INFORMATION pi;\r
-       STARTUPINFO si = {0};            // Initialize all members to zero\r
-       si.cb = sizeof(STARTUPINFO);     // Set byte count\r
-  DWORD dwCreationFlags;\r
-\r
-  if (bCreateConsole)\r
-    dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;\r
-  else\r
-    dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;\r
-\r
-       for(; *pCmd == ' '; pCmd++);\r
-\r
-       if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi))\r
-               return false;\r
-\r
-  return true;\r
-}\r
-#endif\r
-\r
-void StartBSP()\r
-{\r
-       char exename[256];\r
-       GetFilename(exename, "q3map");\r
-       UnixToDosPath(exename); // do we want this done in linux version?\r
-\r
-       char mapname[256];  \r
-  const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");\r
-  \r
-       strcpy( mapname, pn );\r
-       strcat( mapname, "/ac_prt.map" );\r
-       UnixToDosPath(mapname);\r
-\r
-       char command[1024];\r
-       sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);\r
-\r
-       Q_Exec( command, TRUE );\r
-}\r
-\r
-void BuildMiniPrt(list<Str>* exclusionList)\r
-{\r
-       // yes, we could just use -fulldetail option, but, as SPOG said\r
-       // it'd be faster without all the hint, donotenter etc textures and\r
-       // doors, etc\r
-\r
-       DEntity world;\r
-       \r
-       char buffer[128];\r
-  const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");\r
-\r
-       strcpy( buffer, pn );\r
-       strcat( buffer, "/ac_prt.map" );\r
-       FILE* pFile = fopen(buffer, "w");\r
-\r
-       // ahem, thx rr2\r
-       if(!pFile)\r
-               return;\r
-\r
-       int count = g_FuncTable.m_pfnGetEntityCount();\r
-       for(int i = 0; i < count; i++)\r
-       {\r
-               entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i);\r
-\r
-               epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(ent);\r
-\r
-               epair_t* ep = epl;\r
-               while(ep)\r
-               {\r
-                       if(!strcmp(ep->key, "classname"))\r
-                       {\r
-                               if(!strcmp(ep->value, "worldspawn"))\r
-                               {\r
-                                       world.LoadFromEntity(i, FALSE);\r
-                                       world.RemoveNonCheckBrushes(exclusionList, TRUE);\r
-                                       world.SaveToFile(pFile);\r
-                               }\r
-                               else if(strstr(ep->value, "info_"))\r
-                               {\r
-                                       world.ClearBrushes();\r
-                                       world.ClearEPairs();\r
-                                       world.LoadEPairList(epl);\r
-                                       world.SaveToFile(pFile);\r
-                               }\r
-                               break;\r
-                       }\r
-\r
-                       ep = ep->next;\r
-               }\r
-       }\r
-\r
-       fclose(pFile);\r
-\r
-       StartBSP();\r
-}\r
-\r
-entity_s* FindEntityFromTargetname(const char* targetname, int* entNum)\r
-{\r
-       DEntity world;\r
-\r
-       int count = g_FuncTable.m_pfnGetEntityCount();\r
-       for(int i = 0; i < count; i++)\r
-       {\r
-               world.ClearEPairs();\r
-\r
-               entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);\r
-\r
-               world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));\r
-\r
-               DEPair* tn = world.FindEPairByKey("targetname");\r
-               if(tn)\r
-               {\r
-                       if(!stricmp(tn->value, targetname)) {\r
-                               if(entNum) {\r
-                                       *entNum = i;\r
-                               }\r
-                               return ent;\r
-                       }\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-\r
-void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)\r
-{\r
-       faceData->m_bBPrimit = FALSE;\r
-       faceData->m_fRotate = 0;\r
-       faceData->m_fScale[0] = 0.5;\r
-       faceData->m_fScale[1] = 0.5;\r
-       faceData->m_fShift[0] = 0;\r
-       faceData->m_fShift[1] = 0;\r
-       faceData->m_nContents = 0;\r
-       faceData->m_nFlags = 0;\r
-       faceData->m_nValue = 0;\r
-       if(*texture)\r
-               strcpy(faceData->m_TextureName, texture);\r
-       else\r
-               strcpy(faceData->m_TextureName, "textures/common/caulk");\r
-       VectorCopy(va, faceData->m_v1);\r
-       VectorCopy(vb, faceData->m_v2);\r
-       VectorCopy(vc, faceData->m_v3);\r
-}\r
-\r
-float Determinant3x3(float a1, float a2, float a3,\r
-                                        float b1, float b2, float b3,\r
-                                        float c1, float c2, float c3)\r
-{\r
-       return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);\r
-}\r
-\r
-bool GetEntityCentre(const char* entity, vec3_t centre)\r
-{\r
-       entity_s* ent = FindEntityFromTargetname(entity, NULL);\r
-       if(!ent)\r
-               return FALSE;\r
-\r
-       int cnt = g_FuncTable.m_pfnAllocateEntityBrushHandles(ent);\r
-       if(cnt == 0)\r
-       {\r
-               g_FuncTable.m_pfnReleaseEntityBrushHandles();\r
-               return FALSE;\r
-       }\r
-\r
-       brush_t* brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle(0);\r
-       DBrush cBrush;\r
-       cBrush.LoadFromBrush_t(brush, FALSE);\r
-\r
-       vec3_t min, max;\r
-       cBrush.GetBounds(min, max);\r
-\r
-       VectorAdd(min, max, centre);\r
-       VectorScale(centre, 0.5f, centre);\r
-\r
-       g_FuncTable.m_pfnReleaseEntityBrushHandles();\r
-       return TRUE;\r
-}\r
-\r
-vec_t Min(vec_t a, vec_t b)\r
-{\r
-       if(a < b)\r
-               return a;\r
-       return b;\r
-}\r
-\r
-void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {\r
-       vec3_t v1, v2;\r
-       VectorSubtract(va, vb, v1);\r
-       VectorSubtract(vc, vb, v2);\r
-       CrossProduct(v1, v2, out);\r
-}\r
+/*
+BobToolz plugin for GtkRadiant
+Copyright (C) 2001 Gordon Biggans
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "StdAfx.h"
+
+#include "DEntity.h"
+#include "funchandlers.h"
+
+#ifdef __linux__
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+/*==========================
+               Global Vars
+==========================*/
+
+//HANDLE bsp_process;
+char   g_CurrentTexture[256] = "";
+
+//=============================================================
+//=============================================================
+
+void ReadCurrentTexture()
+{
+       const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
+       strcpy(g_CurrentTexture, textureName);
+}
+
+const char*  GetCurrentTexture()
+{
+       ReadCurrentTexture();
+       return g_CurrentTexture;
+}
+
+epair_t* GetNextChainItem(epair_t* lastItem, char* key, 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)
+       {
+               case MOVE_EAST:
+               {
+                       min[0]+=dist;
+                       max[0]+=dist;
+                       break;
+               }
+               case MOVE_WEST:
+               {
+                       min[0]-=dist;
+                       max[0]-=dist;
+                       break;
+               }
+               case MOVE_NORTH:
+               {
+                       min[1]+=dist;
+                       max[1]+=dist;
+                       break;
+               }
+               case MOVE_SOUTH:
+               {
+                       min[1]-=dist;
+                       max[1]-=dist;
+                       break;
+               }
+       }
+}
+
+void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)
+{
+       switch(dir)
+       {
+               case MOVE_EAST:
+               {
+                       max[0] = min[0] + width;
+                       break;
+               }
+               case MOVE_WEST:
+               {
+                       min[0] = max[0] - width;
+                       break;
+               }
+               case MOVE_NORTH:
+               {
+                       max[1] = min[1] + width;
+                       break;
+               }
+               case MOVE_SOUTH:
+               {
+                       min[1] = max[1] - width;
+                       break;
+               }
+       }
+}
+
+char* TranslateString (char *buf)
+{
+       static  char    buf2[32768];
+       int             i, l;
+       char    *out;
+
+       l = strlen(buf);
+       out = buf2;
+       for (i=0 ; i<l ; i++)
+       {
+               if (buf[i] == '\n')
+               {
+                       *out++ = '\r';
+                       *out++ = '\n';
+               }
+               else
+                       *out++ = buf[i];
+       }
+       *out++ = 0;
+
+       return buf2;
+}
+
+void Sys_ERROR (char* text, ...)
+{
+       va_list argptr;
+       char    buf[32768];
+
+       va_start (argptr,text);
+       vsprintf (buf, text,argptr);
+       va_end (argptr);
+
+       Sys_Printf("BobToolz::ERROR->%s", buf);
+}
+
+/*void Sys_Printf (char *text, ...)
+{
+       va_list argptr;
+       char    buf[32768];
+
+       va_start (argptr,text);
+       vsprintf (buf, text,argptr);
+       va_end (argptr);
+
+       g_FuncTable.m_pfnSysMsg ( buf );
+}*/
+
+char* UnixToDosPath(char* path)
+{
+#ifndef _WIN32
+       return path;
+#else
+       for(char* p = path; *p; p++)
+       {
+               if(*p == '/')
+                       *p = '\\';
+       }
+       return path;
+#endif
+}
+
+const char* ExtractFilename(const char* path)
+{
+       char* p = strrchr(path, '/');
+       if(!p)
+       {
+               p = strrchr(path, '\\');
+
+               if(!p)
+                       return path;
+       }
+       return ++p;
+}
+
+extern char* PLUGIN_NAME;
+/*char* GetGameFilename(char* buffer, const char* filename)
+{
+       strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
+       char* p = strrchr(buffer, '/');
+       *++p = '\0';
+       strcat(buffer, filename);
+       buffer = UnixToDosPath(buffer);
+       return buffer;
+}*/
+
+#if defined (__linux__) || defined (__APPLE__)
+// the bCreateConsole parameter is ignored on linux ..
+bool Q_Exec( const char *pCmd, bool bCreateConsole )
+{
+       switch (fork())
+    {
+       case -1:
+      return false;
+//      Error ("CreateProcess failed");
+      break;
+    case 0:
+#ifdef _DEBUG
+                 printf("Running system...\n");
+                       printf("Command: %s\n", pCmd);
+#endif
+                       // NOTE: we could use that to detect when a step finishes. But then it
+                       // would not work for remote compiling stuff.
+//      execlp (pCmd, pCmd, NULL);
+                       system( pCmd );
+      printf ("system() returned");
+      _exit (0);
+      break;
+    }
+    return true;
+}
+#endif
+
+#ifdef _WIN32
+bool Q_Exec( const char *pCmd, bool bCreateConsole )
+{
+       // G_DeWan: Don't know if this is needed for linux version
+
+       PROCESS_INFORMATION pi;
+       STARTUPINFO si = {0};            // Initialize all members to zero
+       si.cb = sizeof(STARTUPINFO);     // Set byte count
+  DWORD dwCreationFlags;
+
+  if (bCreateConsole)
+    dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
+  else
+    dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
+
+       for(; *pCmd == ' '; pCmd++);
+
+       if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi))
+               return false;
+
+  return true;
+}
+#endif
+
+void StartBSP()
+{
+       char exename[256];
+       GetFilename(exename, "q3map");
+       UnixToDosPath(exename); // do we want this done in linux version?
+
+       char mapname[256];  
+  const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
+  
+       strcpy( mapname, pn );
+       strcat( mapname, "/ac_prt.map" );
+       UnixToDosPath(mapname);
+
+       char command[1024];
+       sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
+
+       Q_Exec( command, TRUE );
+}
+
+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");
+
+       strcpy( buffer, pn );
+       strcat( buffer, "/ac_prt.map" );
+       FILE* pFile = fopen(buffer, "w");
+
+       // ahem, thx rr2
+       if(!pFile)
+               return;
+
+       int count = g_FuncTable.m_pfnGetEntityCount();
+       for(int i = 0; i < count; i++)
+       {
+               entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i);
+
+               epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(ent);
+
+               epair_t* ep = epl;
+               while(ep)
+               {
+                       if(!strcmp(ep->key, "classname"))
+                       {
+                               if(!strcmp(ep->value, "worldspawn"))
+                               {
+                                       world.LoadFromEntity(i, FALSE);
+                                       world.RemoveNonCheckBrushes(exclusionList, TRUE);
+                                       world.SaveToFile(pFile);
+                               }
+                               else if(strstr(ep->value, "info_"))
+                               {
+                                       world.ClearBrushes();
+                                       world.ClearEPairs();
+                                       world.LoadEPairList(epl);
+                                       world.SaveToFile(pFile);
+                               }
+                               break;
+                       }
+
+                       ep = ep->next;
+               }
+       }
+
+       fclose(pFile);
+
+       StartBSP();
+}
+
+entity_s* FindEntityFromTargetname(const char* targetname, int* entNum)
+{
+       DEntity world;
+
+       int count = g_FuncTable.m_pfnGetEntityCount();
+       for(int i = 0; i < count; i++)
+       {
+               world.ClearEPairs();
+
+               entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);
+
+               world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));
+
+               DEPair* tn = world.FindEPairByKey("targetname");
+               if(tn)
+               {
+                       if(!stricmp(tn->value, targetname)) {
+                               if(entNum) {
+                                       *entNum = i;
+                               }
+                               return ent;
+                       }
+               }
+       }
+       return NULL;
+}
+
+void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
+{
+       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)
+               strcpy(faceData->m_TextureName, texture);
+       else
+               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,
+                                        float b1, float b2, float b3,
+                                        float c1, float c2, float c3)
+{
+       return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
+}
+
+bool GetEntityCentre(const char* entity, vec3_t centre)
+{
+       entity_s* ent = FindEntityFromTargetname(entity, NULL);
+       if(!ent)
+               return FALSE;
+
+       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;
+}
+
+vec_t Min(vec_t a, vec_t b)
+{
+       if(a < b)
+               return a;
+       return b;
+}
+
+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);
+}