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
21 #include "globaldefs.h"
33 #include "funchandlers.h"
37 #include <sys/types.h>
44 #include "iscenegraph.h"
45 #include "qerplugin.h"
54 /*==========================
56 ==========================*/
59 char g_CurrentTexture[256] = "";
61 //=============================================================
62 //=============================================================
64 void ReadCurrentTexture()
66 const char *textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
67 strcpy(g_CurrentTexture, textureName);
70 const char *GetCurrentTexture()
73 return g_CurrentTexture;
76 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)
106 max[0] = min[0] + width;
110 min[0] = max[0] - width;
114 max[1] = min[1] + width;
118 min[1] = max[1] - width;
124 char *TranslateString(char *buf)
126 static char buf2[32768];
128 std::size_t l = strlen(buf);
130 for (std::size_t i = 0; i < l; i++) {
131 if (buf[i] == '\n') {
144 char *UnixToDosPath(char *path)
149 for ( char* p = path; *p; p++ )
159 const char *ExtractFilename(const char *path)
161 const char *p = strrchr(path, '/');
163 p = strrchr(path, '\\');
172 extern char *PLUGIN_NAME;
173 /*char* GetGameFilename(char* buffer, const char* filename)
175 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
176 char* p = strrchr(buffer, '/');
178 strcat(buffer, filename);
179 buffer = UnixToDosPath(buffer);
185 // the bCreateConsole parameter is ignored on linux ..
186 bool Q_Exec(const char *pCmd, bool bCreateConsole)
191 // Error ("CreateProcess failed");
195 printf("Running system...\n");
196 printf("Command: %s\n", pCmd);
198 // NOTE: we could use that to detect when a step finishes. But then it
199 // would not work for remote compiling stuff.
200 // execlp (pCmd, pCmd, NULL);
201 int ret = system(pCmd);
202 printf("system() returned");
215 bool Q_Exec( const char *pCmd, bool bCreateConsole ){
216 // G_DeWan: Don't know if this is needed for linux version
218 PROCESS_INFORMATION pi;
219 STARTUPINFO si = {0}; // Initialize all members to zero
220 si.cb = sizeof( STARTUPINFO ); // Set byte count
221 DWORD dwCreationFlags;
223 if ( bCreateConsole ) {
224 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
227 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
230 for (; *pCmd == ' '; pCmd++ ) ;
232 if ( !CreateProcess( NULL, (char *)pCmd, NULL, NULL, false, dwCreationFlags, NULL, NULL, &si, &pi ) ) {
243 GetFilename(exename, "q3map");
244 UnixToDosPath(exename); // do we want this done in linux version?
247 const char *pn = GlobalRadiant().getMapsPath();
250 strcat(mapname, "/ac_prt.map");
251 UnixToDosPath(mapname);
254 sprintf(command, "%s -nowater -fulldetail %s", exename, mapname);
256 Q_Exec(command, true);
259 class EntityWriteMiniPrt {
260 mutable DEntity world;
262 std::list<Str> *exclusionList;
264 EntityWriteMiniPrt(FILE *pFile, std::list<Str> *exclusionList)
265 : pFile(pFile), exclusionList(exclusionList)
269 void operator()(scene::Instance &instance) const
271 const char *classname = Node_getEntity(instance.path().top())->getKeyValue("classname");
273 if (!strcmp(classname, "worldspawn")) {
274 world.LoadFromEntity(instance.path().top(), false);
275 world.RemoveNonCheckBrushes(exclusionList, true);
276 world.SaveToFile(pFile);
277 } else if (strstr(classname, "info_")) {
278 world.ClearBrushes();
280 world.LoadEPairList(Node_getEntity(instance.path().top()));
281 world.SaveToFile(pFile);
286 void BuildMiniPrt(std::list<Str> *exclusionList)
288 // yes, we could just use -fulldetail option, but, as SPOG said
289 // it'd be faster without all the hint, donotenter etc textures and
295 const char *pn = GlobalRadiant().getMapsPath();
298 strcat(buffer, "/ac_prt.map");
299 FILE *pFile = fopen(buffer, "w");
306 Scene_forEachEntity(EntityWriteMiniPrt(pFile, exclusionList));
313 class EntityFindByTargetName {
314 const char *targetname;
316 mutable const scene::Path *result;
318 EntityFindByTargetName(const char *targetname)
319 : targetname(targetname), result(0)
323 void operator()(scene::Instance &instance) const
326 const char *value = Node_getEntity(instance.path().top())->getKeyValue("targetname");
328 if (!strcmp(value, targetname)) {
329 result = &instance.path();
335 const scene::Path *FindEntityFromTargetname(const char *targetname)
337 return Scene_forEachEntity(EntityFindByTargetName(targetname)).result;
340 void FillDefaultTexture(_QERFaceData *faceData, vec3_t va, vec3_t vb, vec3_t vc, const char *texture)
342 faceData->m_texdef.rotate = 0;
343 faceData->m_texdef.scale[0] = 0.5;
344 faceData->m_texdef.scale[1] = 0.5;
345 faceData->m_texdef.shift[0] = 0;
346 faceData->m_texdef.shift[1] = 0;
347 faceData->contents = 0;
351 faceData->m_shader = texture;
353 faceData->m_shader = "textures/common/caulk";
355 VectorCopy(va, faceData->m_p0);
356 VectorCopy(vb, faceData->m_p1);
357 VectorCopy(vc, faceData->m_p2);
360 float Determinant3x3(float a1, float a2, float a3,
361 float b1, float b2, float b3,
362 float c1, float c2, float c3)
364 return a1 * (b2 * c3 - b3 * c2) - a2 * (b1 * c3 - b3 * c1) + a3 * (b1 * c2 - b2 * c1);
367 bool GetEntityCentre(const char *entity, vec3_t centre)
369 const scene::Path *ent = FindEntityFromTargetname(entity);
374 scene::Instance &instance = *GlobalSceneGraph().find(*ent);
375 VectorCopy(instance.worldAABB().origin, centre);
380 vec_t Min(vec_t a, vec_t b)
388 void MakeNormal(const vec_t *va, const vec_t *vb, const vec_t *vc, vec_t *out)
391 VectorSubtract(va, vb, v1);
392 VectorSubtract(vc, vb, v2);
393 CrossProduct(v1, v2, out);
396 char *GetFilename(char *buffer, const char *filename)
398 strcpy(buffer, GlobalRadiant().getAppPath());
399 strcat(buffer, "plugins/");
400 strcat(buffer, filename);