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];
135 std::size_t l = strlen(buf);
137 for (int 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 const 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);
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");
222 bool Q_Exec( const char *pCmd, bool bCreateConsole )
224 // G_DeWan: Don't know if this is needed for linux version
226 PROCESS_INFORMATION pi;
227 STARTUPINFO si = {0}; // Initialize all members to zero
228 si.cb = sizeof(STARTUPINFO); // Set byte count
229 DWORD dwCreationFlags;
232 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
234 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
236 for(; *pCmd == ' '; pCmd++);
238 if(!CreateProcess(NULL, (char *)pCmd, NULL, NULL, false, dwCreationFlags, NULL, NULL, &si, &pi))
248 GetFilename(exename, "q3map");
249 UnixToDosPath(exename); // do we want this done in linux version?
252 const char *pn = GlobalRadiant().getMapsPath();
254 strcpy( mapname, pn );
255 strcat( mapname, "/ac_prt.map" );
256 UnixToDosPath(mapname);
259 sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
261 Q_Exec( command, true );
264 class EntityWriteMiniPrt
266 mutable DEntity world;
268 std::list<Str>* exclusionList;
270 EntityWriteMiniPrt(FILE* pFile, std::list<Str>* exclusionList)
271 : pFile(pFile), exclusionList(exclusionList)
274 void operator()(scene::Instance& instance) const
276 const char* classname = Node_getEntity(instance.path().top())->getKeyValue("classname");
278 if(!strcmp(classname, "worldspawn"))
280 world.LoadFromEntity(instance.path().top(), false);
281 world.RemoveNonCheckBrushes(exclusionList, true);
282 world.SaveToFile(pFile);
284 else if(strstr(classname, "info_"))
286 world.ClearBrushes();
288 world.LoadEPairList(Node_getEntity(instance.path().top()));
289 world.SaveToFile(pFile);
294 void BuildMiniPrt(std::list<Str>* exclusionList)
296 // yes, we could just use -fulldetail option, but, as SPOG said
297 // it'd be faster without all the hint, donotenter etc textures and
303 const char *pn = GlobalRadiant().getMapsPath();
305 strcpy( buffer, pn );
306 strcat( buffer, "/ac_prt.map" );
307 FILE* pFile = fopen(buffer, "w");
313 Scene_forEachEntity(EntityWriteMiniPrt(pFile, exclusionList));
320 class EntityFindByTargetName
322 const char* targetname;
324 mutable const scene::Path* result;
325 EntityFindByTargetName(const char* targetname)
326 : targetname(targetname), result(0)
329 void operator()(scene::Instance& instance) const
333 const char* value = Node_getEntity(instance.path().top())->getKeyValue("targetname");
335 if(!strcmp(value, targetname))
337 result = &instance.path();
343 const scene::Path* FindEntityFromTargetname(const char* targetname)
345 return Scene_forEachEntity(EntityFindByTargetName(targetname)).result;
348 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
350 faceData->m_texdef.rotate = 0;
351 faceData->m_texdef.scale[0] = 0.5;
352 faceData->m_texdef.scale[1] = 0.5;
353 faceData->m_texdef.shift[0] = 0;
354 faceData->m_texdef.shift[1] = 0;
355 faceData->contents = 0;
359 faceData->m_shader = texture;
361 faceData->m_shader = "textures/common/caulk";
362 VectorCopy(va, faceData->m_p0);
363 VectorCopy(vb, faceData->m_p1);
364 VectorCopy(vc, faceData->m_p2);
367 float Determinant3x3(float a1, float a2, float a3,
368 float b1, float b2, float b3,
369 float c1, float c2, float c3)
371 return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
374 bool GetEntityCentre(const char* entity, vec3_t centre)
376 const scene::Path* ent = FindEntityFromTargetname(entity);
380 scene::Instance& instance = *GlobalSceneGraph().find(*ent);
381 VectorCopy(instance.worldAABB().origin, centre);
386 vec_t Min(vec_t a, vec_t b)
393 void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
395 VectorSubtract(va, vb, v1);
396 VectorSubtract(vc, vb, v2);
397 CrossProduct(v1, v2, out);
400 char* GetFilename(char* buffer, const char* filename) {
401 strcpy(buffer, GlobalRadiant().getAppPath());
402 strcat(buffer, "plugins/");
403 strcat(buffer, filename);