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>
41 #include "iscenegraph.h"
42 #include "qerplugin.h"
51 /*==========================
53 ==========================*/
56 char g_CurrentTexture[256] = "";
58 //=============================================================
59 //=============================================================
61 void ReadCurrentTexture()
63 const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
64 strcpy(g_CurrentTexture, textureName);
67 const char* GetCurrentTexture()
70 return g_CurrentTexture;
73 void MoveBlock(int dir, vec3_t min, vec3_t max, float dist)
104 void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width)
110 max[0] = min[0] + width;
115 min[0] = max[0] - width;
120 max[1] = min[1] + width;
125 min[1] = max[1] - width;
131 char* TranslateString (char *buf)
133 static char buf2[32768];
139 for (i=0 ; i<l ; i++)
155 char* UnixToDosPath(char* path)
160 for(char* p = path; *p; p++)
169 const char* ExtractFilename(const char* path)
171 char* p = strrchr(path, '/');
174 p = strrchr(path, '\\');
182 extern char* PLUGIN_NAME;
183 /*char* GetGameFilename(char* buffer, const char* filename)
185 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
186 char* p = strrchr(buffer, '/');
188 strcat(buffer, filename);
189 buffer = UnixToDosPath(buffer);
193 #if defined (__linux__) || defined (__APPLE__)
194 // the bCreateConsole parameter is ignored on linux ..
195 bool Q_Exec( const char *pCmd, bool bCreateConsole )
201 // Error ("CreateProcess failed");
205 printf("Running system...\n");
206 printf("Command: %s\n", pCmd);
208 // NOTE: we could use that to detect when a step finishes. But then it
209 // would not work for remote compiling stuff.
210 // execlp (pCmd, pCmd, NULL);
212 printf ("system() returned");
226 bool Q_Exec( const char *pCmd, bool bCreateConsole )
228 // G_DeWan: Don't know if this is needed for linux version
230 PROCESS_INFORMATION pi;
231 STARTUPINFO si = {0}; // Initialize all members to zero
232 si.cb = sizeof(STARTUPINFO); // Set byte count
233 DWORD dwCreationFlags;
236 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
238 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
240 for(; *pCmd == ' '; pCmd++);
242 if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi))
252 GetFilename(exename, "q3map");
253 UnixToDosPath(exename); // do we want this done in linux version?
256 const char *pn = GlobalRadiant().getMapsPath();
258 strcpy( mapname, pn );
259 strcat( mapname, "/ac_prt.map" );
260 UnixToDosPath(mapname);
263 sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
265 Q_Exec( command, TRUE );
268 class EntityWriteMiniPrt
270 mutable DEntity world;
272 std::list<Str>* exclusionList;
274 EntityWriteMiniPrt(FILE* pFile, std::list<Str>* exclusionList)
275 : pFile(pFile), exclusionList(exclusionList)
278 void operator()(scene::Instance& instance) const
280 const char* classname = Node_getEntity(instance.path().top())->getKeyValue("classname");
282 if(!strcmp(classname, "worldspawn"))
284 world.LoadFromEntity(instance.path().top(), FALSE);
285 world.RemoveNonCheckBrushes(exclusionList, TRUE);
286 world.SaveToFile(pFile);
288 else if(strstr(classname, "info_"))
290 world.ClearBrushes();
292 world.LoadEPairList(Node_getEntity(instance.path().top()));
293 world.SaveToFile(pFile);
298 void BuildMiniPrt(std::list<Str>* exclusionList)
300 // yes, we could just use -fulldetail option, but, as SPOG said
301 // it'd be faster without all the hint, donotenter etc textures and
307 const char *pn = GlobalRadiant().getMapsPath();
309 strcpy( buffer, pn );
310 strcat( buffer, "/ac_prt.map" );
311 FILE* pFile = fopen(buffer, "w");
317 Scene_forEachEntity(EntityWriteMiniPrt(pFile, exclusionList));
324 class EntityFindByTargetName
326 const char* targetname;
328 mutable const scene::Path* result;
329 EntityFindByTargetName(const char* targetname)
330 : targetname(targetname), result(0)
333 void operator()(scene::Instance& instance) const
337 const char* value = Node_getEntity(instance.path().top())->getKeyValue("targetname");
339 if(!strcmp(value, targetname))
341 result = &instance.path();
347 const scene::Path* FindEntityFromTargetname(const char* targetname)
349 return Scene_forEachEntity(EntityFindByTargetName(targetname)).result;
352 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
354 faceData->m_texdef.rotate = 0;
355 faceData->m_texdef.scale[0] = 0.5;
356 faceData->m_texdef.scale[1] = 0.5;
357 faceData->m_texdef.shift[0] = 0;
358 faceData->m_texdef.shift[1] = 0;
359 faceData->contents = 0;
363 faceData->m_shader = texture;
365 faceData->m_shader = "textures/common/caulk";
366 VectorCopy(va, faceData->m_p0);
367 VectorCopy(vb, faceData->m_p1);
368 VectorCopy(vc, faceData->m_p2);
371 float Determinant3x3(float a1, float a2, float a3,
372 float b1, float b2, float b3,
373 float c1, float c2, float c3)
375 return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
378 bool GetEntityCentre(const char* entity, vec3_t centre)
380 const scene::Path* ent = FindEntityFromTargetname(entity);
384 scene::Instance& instance = *GlobalSceneGraph().find(*ent);
385 VectorCopy(instance.worldAABB().origin, centre);
390 vec_t Min(vec_t a, vec_t b)
397 void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
399 VectorSubtract(va, vb, v1);
400 VectorSubtract(vc, vb, v2);
401 CrossProduct(v1, v2, out);
404 char* GetFilename(char* buffer, const char* filename) {
405 strcpy(buffer, GlobalRadiant().getAppPath());
406 strcat(buffer, "plugins/");
407 strcat(buffer, filename);