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);
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");
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 = GlobalRadiant().getMapsPath();
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 class EntityWriteMiniPrt
268 mutable DEntity world;
270 std::list<Str>* exclusionList;
272 EntityWriteMiniPrt(FILE* pFile, std::list<Str>* exclusionList)
273 : pFile(pFile), exclusionList(exclusionList)
276 void operator()(scene::Instance& instance) const
278 const char* classname = Node_getEntity(instance.path().top())->getKeyValue("classname");
280 if(!strcmp(classname, "worldspawn"))
282 world.LoadFromEntity(instance.path().top(), false);
283 world.RemoveNonCheckBrushes(exclusionList, true);
284 world.SaveToFile(pFile);
286 else if(strstr(classname, "info_"))
288 world.ClearBrushes();
290 world.LoadEPairList(Node_getEntity(instance.path().top()));
291 world.SaveToFile(pFile);
296 void BuildMiniPrt(std::list<Str>* exclusionList)
298 // yes, we could just use -fulldetail option, but, as SPOG said
299 // it'd be faster without all the hint, donotenter etc textures and
305 const char *pn = GlobalRadiant().getMapsPath();
307 strcpy( buffer, pn );
308 strcat( buffer, "/ac_prt.map" );
309 FILE* pFile = fopen(buffer, "w");
315 Scene_forEachEntity(EntityWriteMiniPrt(pFile, exclusionList));
322 class EntityFindByTargetName
324 const char* targetname;
326 mutable const scene::Path* result;
327 EntityFindByTargetName(const char* targetname)
328 : targetname(targetname), result(0)
331 void operator()(scene::Instance& instance) const
335 const char* value = Node_getEntity(instance.path().top())->getKeyValue("targetname");
337 if(!strcmp(value, targetname))
339 result = &instance.path();
345 const scene::Path* FindEntityFromTargetname(const char* targetname)
347 return Scene_forEachEntity(EntityFindByTargetName(targetname)).result;
350 void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture)
352 faceData->m_texdef.rotate = 0;
353 faceData->m_texdef.scale[0] = 0.5;
354 faceData->m_texdef.scale[1] = 0.5;
355 faceData->m_texdef.shift[0] = 0;
356 faceData->m_texdef.shift[1] = 0;
357 faceData->contents = 0;
361 faceData->m_shader = texture;
363 faceData->m_shader = "textures/common/caulk";
364 VectorCopy(va, faceData->m_p0);
365 VectorCopy(vb, faceData->m_p1);
366 VectorCopy(vc, faceData->m_p2);
369 float Determinant3x3(float a1, float a2, float a3,
370 float b1, float b2, float b3,
371 float c1, float c2, float c3)
373 return a1*(b2*c3-b3*c2) - a2*(b1*c3-b3*c1) + a3*(b1*c2-b2*c1);
376 bool GetEntityCentre(const char* entity, vec3_t centre)
378 const scene::Path* ent = FindEntityFromTargetname(entity);
382 scene::Instance& instance = *GlobalSceneGraph().find(*ent);
383 VectorCopy(instance.worldAABB().origin, centre);
388 vec_t Min(vec_t a, vec_t b)
395 void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
397 VectorSubtract(va, vb, v1);
398 VectorSubtract(vc, vb, v2);
399 CrossProduct(v1, v2, out);
402 char* GetFilename(char* buffer, const char* filename) {
403 strcpy(buffer, GlobalRadiant().getAppPath());
404 strcat(buffer, "plugins/");
405 strcat(buffer, filename);