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
22 #include "gtkr_list.h"
34 #include "funchandlers.h"
37 #include <sys/types.h>
43 #include "refcounted_ptr.h"
52 /*==========================
54 ==========================*/
57 char g_CurrentTexture[256] = "";
59 //=============================================================
60 //=============================================================
62 void ReadCurrentTexture()
64 const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
65 strcpy(g_CurrentTexture, textureName);
68 const char* GetCurrentTexture()
71 return g_CurrentTexture;
74 void MoveBlock(int dir, vec3_t min, vec3_t max, float dist)
105 void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)
111 max[0] = min[0] + width;
116 min[0] = max[0] - width;
121 max[1] = min[1] + width;
126 min[1] = max[1] - width;
132 char* TranslateString (char *buf)
134 static char buf2[32768];
140 for (i=0 ; i<l ; i++)
155 void Sys_ERROR (char* text, ...)
160 va_start (argptr,text);
161 vsprintf (buf, text,argptr);
164 Sys_Printf("BobToolz::ERROR->%s", buf);
167 /*void Sys_Printf (char *text, ...)
172 va_start (argptr,text);
173 vsprintf (buf, text,argptr);
176 g_FuncTable.m_pfnSysMsg ( buf );
179 char* UnixToDosPath(char* path)
184 for(char* p = path; *p; p++)
193 const char* ExtractFilename(const char* path)
195 char* p = strrchr(path, '/');
198 p = strrchr(path, '\\');
206 extern char* PLUGIN_NAME;
207 /*char* GetGameFilename(char* buffer, const char* filename)
209 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
210 char* p = strrchr(buffer, '/');
212 strcat(buffer, filename);
213 buffer = UnixToDosPath(buffer);
217 #if defined (__linux__) || defined (__APPLE__)
218 // the bCreateConsole parameter is ignored on linux ..
219 bool Q_Exec( const char *pCmd, bool bCreateConsole )
225 // Error ("CreateProcess failed");
229 printf("Running system...\n");
230 printf("Command: %s\n", pCmd);
232 // NOTE: we could use that to detect when a step finishes. But then it
233 // would not work for remote compiling stuff.
234 // execlp (pCmd, pCmd, NULL);
236 printf ("system() returned");
250 bool Q_Exec( const char *pCmd, bool bCreateConsole )
252 // G_DeWan: Don't know if this is needed for linux version
254 PROCESS_INFORMATION pi;
255 STARTUPINFO si = {0}; // Initialize all members to zero
256 si.cb = sizeof(STARTUPINFO); // Set byte count
257 DWORD dwCreationFlags;
260 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
262 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
264 for(; *pCmd == ' '; pCmd++);
266 if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi))
276 GetFilename(exename, "q3map");
277 UnixToDosPath(exename); // do we want this done in linux version?
280 const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
282 strcpy( mapname, pn );
283 strcat( mapname, "/ac_prt.map" );
284 UnixToDosPath(mapname);
287 sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
289 Q_Exec( command, TRUE );
292 void BuildMiniPrt(list<Str>* exclusionList)
294 // yes, we could just use -fulldetail option, but, as SPOG said
295 // it'd be faster without all the hint, donotenter etc textures and
301 const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
303 strcpy( buffer, pn );
304 strcat( buffer, "/ac_prt.map" );
305 FILE* pFile = fopen(buffer, "w");
312 int count = g_FuncTable.m_pfnGetEntityCount();
313 for(int i = 0; i < count; i++)
315 entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i);
317 epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(ent);
322 if(!strcmp(ep->key, "classname"))
324 if(!strcmp(ep->value, "worldspawn"))
326 world.LoadFromEntity(i, FALSE);
327 world.RemoveNonCheckBrushes(exclusionList, TRUE);
328 world.SaveToFile(pFile);
330 else if(strstr(ep->value, "info_"))
332 world.ClearBrushes();
334 world.LoadEPairList(epl);
335 world.SaveToFile(pFile);
350 scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
355 int count = g_FuncTable.m_pfnGetEntityCount();
356 for(int i = 0; i < count; i++)
360 entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);
362 world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));
364 DEPair* tn = world.FindEPairByKey("targetname");
367 if(!stricmp(tn->value, targetname)) {
380 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
382 faceData->m_texdef.rotate = 0;
383 faceData->m_texdef.scale[0] = 0.5;
384 faceData->m_texdef.scale[1] = 0.5;
385 faceData->m_texdef.shift[0] = 0;
386 faceData->m_texdef.shift[1] = 0;
387 faceData->m_texdef.contents = 0;
388 faceData->m_texdef.flags = 0;
389 faceData->m_texdef.value = 0;
391 faceData->m_texdef.SetName(texture);
393 faceData->m_texdef.SetName("textures/common/caulk");
394 VectorCopy(va, faceData->m_p0);
395 VectorCopy(vb, faceData->m_p1);
396 VectorCopy(vc, faceData->m_p2);
399 float Determinant3x3(float a1, float a2, float a3,
400 float b1, float b2, float b3,
401 float c1, float c2, float c3)
403 return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
406 bool GetEntityCentre(const char* entity, vec3_t centre)
408 const scene::Path* ent = FindEntityFromTargetname(entity, NULL);
412 scene::Instance& instance = *GlobalSceneGraph().find(*ent);
413 VectorCopy(instance.aabb_world().origin, centre);
418 vec_t Min(vec_t a, vec_t b)
425 void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {
427 VectorSubtract(va, vb, v1);
428 VectorSubtract(vc, vb, v2);
429 CrossProduct(v1, v2, out);