2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "funchandlers.h"
26 #include <sys/types.h>
30 /*==========================
32 ==========================*/
35 char g_CurrentTexture[256] = "";
37 //=============================================================
38 //=============================================================
40 void ReadCurrentTexture()
42 const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
43 strcpy(g_CurrentTexture, textureName);
46 const char* GetCurrentTexture()
49 return g_CurrentTexture;
52 epair_t* GetNextChainItem(epair_t* lastItem, const char* key, const char* value)
54 epair_t* nextEPair = g_FuncTable.m_pfnAllocateEpair(key, value);
57 lastItem->next = nextEPair;
62 void MoveBlock(int dir, vec3_t min, vec3_t max, float dist)
93 void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)
99 max[0] = min[0] + width;
104 min[0] = max[0] - width;
109 max[1] = min[1] + width;
114 min[1] = max[1] - width;
120 char* TranslateString (const char *buf)
122 static char buf2[32768];
128 for (i=0 ; i<l ; i++)
143 void Sys_ERROR (const char* text, ...)
148 va_start (argptr,text);
149 vsprintf (buf, text,argptr);
152 Sys_Printf("BobToolz::ERROR->%s", buf);
155 /*void Sys_Printf (char *text, ...)
160 va_start (argptr,text);
161 vsprintf (buf, text,argptr);
164 g_FuncTable.m_pfnSysMsg ( buf );
167 char* UnixToDosPath(char* path)
172 for(char* p = path; *p; p++)
181 const char* ExtractFilename(const char* path)
183 char* p = strrchr(path, '/');
186 p = strrchr(path, '\\');
194 extern const char* PLUGIN_NAME;
195 /*char* GetGameFilename(char* buffer, const char* filename)
197 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
198 char* p = strrchr(buffer, '/');
200 strcat(buffer, filename);
201 buffer = UnixToDosPath(buffer);
205 #if defined (__linux__) || defined (__APPLE__)
206 // the bCreateConsole parameter is ignored on linux ..
207 bool Q_Exec( const char *pCmd, bool bCreateConsole )
213 // Error ("CreateProcess failed");
217 printf("Running system...\n");
218 printf("Command: %s\n", pCmd);
220 // NOTE: we could use that to detect when a step finishes. But then it
221 // would not work for remote compiling stuff.
222 // execlp (pCmd, pCmd, NULL);
224 printf ("system() returned");
233 bool Q_Exec( const char *pCmd, bool bCreateConsole )
235 // G_DeWan: Don't know if this is needed for linux version
237 PROCESS_INFORMATION pi;
238 STARTUPINFO si = {0}; // Initialize all members to zero
239 si.cb = sizeof(STARTUPINFO); // Set byte count
240 DWORD dwCreationFlags;
243 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
245 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
247 for(; *pCmd == ' '; pCmd++);
249 if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi))
259 GetFilename(exename, "q3map");
260 UnixToDosPath(exename); // do we want this done in linux version?
263 const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
265 strcpy( mapname, pn );
266 strcat( mapname, "/ac_prt.map" );
267 UnixToDosPath(mapname);
270 sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
272 Q_Exec( command, TRUE );
275 void BuildMiniPrt(list<Str>* exclusionList)
277 // yes, we could just use -fulldetail option, but, as SPOG said
278 // it'd be faster without all the hint, donotenter etc textures and
284 const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
286 strcpy( buffer, pn );
287 strcat( buffer, "/ac_prt.map" );
288 FILE* pFile = fopen(buffer, "w");
294 int count = g_FuncTable.m_pfnGetEntityCount();
295 for(int i = 0; i < count; i++)
297 entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i);
299 epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(ent);
304 if(!strcmp(ep->key, "classname"))
306 if(!strcmp(ep->value, "worldspawn"))
308 world.LoadFromEntity(i, FALSE);
309 world.RemoveNonCheckBrushes(exclusionList, TRUE);
310 world.SaveToFile(pFile);
312 else if(strstr(ep->value, "info_"))
314 world.ClearBrushes();
316 world.LoadEPairList(epl);
317 world.SaveToFile(pFile);
331 entity_s* FindEntityFromTargetname(const char* targetname, int* entNum)
335 int count = g_FuncTable.m_pfnGetEntityCount();
336 for(int i = 0; i < count; i++)
340 entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);
342 world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));
344 DEPair* tn = world.FindEPairByKey("targetname");
347 if(!stricmp(tn->value, targetname)) {
358 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
360 faceData->m_bBPrimit = FALSE;
361 faceData->m_fRotate = 0;
362 faceData->m_fScale[0] = 0.5;
363 faceData->m_fScale[1] = 0.5;
364 faceData->m_fShift[0] = 0;
365 faceData->m_fShift[1] = 0;
366 faceData->m_nContents = 0;
367 faceData->m_nFlags = 0;
368 faceData->m_nValue = 0;
370 strcpy(faceData->m_TextureName, texture);
372 strcpy(faceData->m_TextureName, "textures/common/caulk");
373 VectorCopy(va, faceData->m_v1);
374 VectorCopy(vb, faceData->m_v2);
375 VectorCopy(vc, faceData->m_v3);
378 float Determinant3x3(float a1, float a2, float a3,
379 float b1, float b2, float b3,
380 float c1, float c2, float c3)
382 return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
385 bool GetEntityCentre(const char* entity, vec3_t centre)
387 entity_s* ent = FindEntityFromTargetname(entity, NULL);
391 int cnt = g_FuncTable.m_pfnAllocateEntityBrushHandles(ent);
394 g_FuncTable.m_pfnReleaseEntityBrushHandles();
398 brush_t* brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle(0);
400 cBrush.LoadFromBrush_t(brush, FALSE);
403 cBrush.GetBounds(min, max);
405 VectorAdd(min, max, centre);
406 VectorScale(centre, 0.5f, centre);
408 g_FuncTable.m_pfnReleaseEntityBrushHandles();
412 vec_t Min(vec_t a, vec_t b)
419 void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {
421 VectorSubtract(va, vb, v1);
422 VectorSubtract(vc, vb, v2);
423 CrossProduct(v1, v2, out);