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
32 #include "funchandlers.h"
35 #include <sys/types.h>
40 #include "qerplugin.h"
49 /*==========================
51 ==========================*/
54 char g_CurrentTexture[256] = "";
56 //=============================================================
57 //=============================================================
59 void ReadCurrentTexture()
61 const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
62 strcpy(g_CurrentTexture, textureName);
65 const char* GetCurrentTexture()
68 return g_CurrentTexture;
71 void MoveBlock(int dir, vec3_t min, vec3_t max, float dist)
102 void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)
108 max[0] = min[0] + width;
113 min[0] = max[0] - width;
118 max[1] = min[1] + width;
123 min[1] = max[1] - width;
129 char* TranslateString (char *buf)
131 static char buf2[32768];
137 for (i=0 ; i<l ; i++)
153 char* UnixToDosPath(char* path)
158 for(char* p = path; *p; p++)
167 const char* ExtractFilename(const char* path)
169 char* p = strrchr(path, '/');
172 p = strrchr(path, '\\');
180 extern char* PLUGIN_NAME;
181 /*char* GetGameFilename(char* buffer, const char* filename)
183 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
184 char* p = strrchr(buffer, '/');
186 strcat(buffer, filename);
187 buffer = UnixToDosPath(buffer);
191 #if defined (__linux__) || defined (__APPLE__)
192 // the bCreateConsole parameter is ignored on linux ..
193 bool Q_Exec( const char *pCmd, bool bCreateConsole )
199 // Error ("CreateProcess failed");
203 printf("Running system...\n");
204 printf("Command: %s\n", pCmd);
206 // NOTE: we could use that to detect when a step finishes. But then it
207 // would not work for remote compiling stuff.
208 // execlp (pCmd, pCmd, NULL);
210 printf ("system() returned");
224 bool Q_Exec( const char *pCmd, bool bCreateConsole )
226 // G_DeWan: Don't know if this is needed for linux version
228 PROCESS_INFORMATION pi;
229 STARTUPINFO si = {0}; // Initialize all members to zero
230 si.cb = sizeof(STARTUPINFO); // Set byte count
231 DWORD dwCreationFlags;
234 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
236 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
238 for(; *pCmd == ' '; pCmd++);
240 if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi))
250 GetFilename(exename, "q3map");
251 UnixToDosPath(exename); // do we want this done in linux version?
254 const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
256 strcpy( mapname, pn );
257 strcat( mapname, "/ac_prt.map" );
258 UnixToDosPath(mapname);
261 sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
263 Q_Exec( command, TRUE );
266 void BuildMiniPrt(std::list<Str>* exclusionList)
268 // yes, we could just use -fulldetail option, but, as SPOG said
269 // it'd be faster without all the hint, donotenter etc textures and
275 const char *pn = g_FuncTable.m_pfnReadProjectKey("mapspath");
277 strcpy( buffer, pn );
278 strcat( buffer, "/ac_prt.map" );
279 FILE* pFile = fopen(buffer, "w");
286 int count = g_FuncTable.m_pfnGetEntityCount();
287 for(int i = 0; i < count; i++)
289 entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle(i);
291 epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList(ent);
296 if(!strcmp(ep->key, "classname"))
298 if(!strcmp(ep->value, "worldspawn"))
300 world.LoadFromEntity(i, FALSE);
301 world.RemoveNonCheckBrushes(exclusionList, TRUE);
302 world.SaveToFile(pFile);
304 else if(strstr(ep->value, "info_"))
306 world.ClearBrushes();
308 world.LoadEPairList(epl);
309 world.SaveToFile(pFile);
324 template<typename Functor>
327 const Functor& functor;
329 EntityWalker(const Functor& functor) : functor(functor)
332 bool pre(const Path& path, Instance& instance) const
334 if(Node_isEntity(path.top()))
341 template<typename Functor>
342 const Functor& Scene_forEachEntity(const Functor& functor)
344 GlobalSceneGraph().traverse(EntityWalker<Functor>(functor));
349 scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
354 int count = g_FuncTable.m_pfnGetEntityCount();
355 for(int i = 0; i < count; i++)
359 entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);
361 world.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));
363 DEPair* tn = world.FindEPairByKey("targetname");
366 if(string_equal_nocase(tn->value, targetname)) {
379 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
381 faceData->m_texdef.rotate = 0;
382 faceData->m_texdef.scale[0] = 0.5;
383 faceData->m_texdef.scale[1] = 0.5;
384 faceData->m_texdef.shift[0] = 0;
385 faceData->m_texdef.shift[1] = 0;
386 faceData->m_texdef.contents = 0;
387 faceData->m_texdef.flags = 0;
388 faceData->m_texdef.value = 0;
390 faceData->m_shader = texture;
392 faceData->m_shader = "textures/common/caulk";
393 VectorCopy(va, faceData->m_p0);
394 VectorCopy(vb, faceData->m_p1);
395 VectorCopy(vc, faceData->m_p2);
398 float Determinant3x3(float a1, float a2, float a3,
399 float b1, float b2, float b3,
400 float c1, float c2, float c3)
402 return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
405 bool GetEntityCentre(const char* entity, vec3_t centre)
407 const scene::Path* ent = FindEntityFromTargetname(entity, NULL);
411 scene::Instance& instance = *GlobalSceneGraph().find(*ent);
412 VectorCopy(instance.aabb_world().origin, centre);
417 vec_t Min(vec_t a, vec_t b)
424 void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
426 VectorSubtract(va, vb, v1);
427 VectorSubtract(vc, vb, v2);
428 CrossProduct(v1, v2, out);
431 char* GetFilename(char* buffer, const char* filename) {
432 strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient));
433 StripFilename( buffer );
435 strcat(buffer, filename);
436 //buffer = UnixToDosPath(buffer);