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
23 #include "funchandlers.h"
26 #include <sys/types.h>
30 /*==========================
32 ==========================*/
35 char g_CurrentTexture[256] = "";
37 //=============================================================
38 //=============================================================
40 void ReadCurrentTexture(){
41 const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
42 strcpy( g_CurrentTexture, textureName );
45 const char* GetCurrentTexture(){
47 return g_CurrentTexture;
50 epair_t* GetNextChainItem( epair_t* lastItem, const char* key, const char* value ){
51 epair_t* nextEPair = g_FuncTable.m_pfnAllocateEpair( key, value );
53 if ( lastItem != NULL ) {
54 lastItem->next = nextEPair;
60 void MoveBlock( int dir, vec3_t min, vec3_t max, float dist ){
90 void SetInitialStairPos( int dir, vec3_t min, vec3_t max, float width ){
95 max[0] = min[0] + width;
100 min[0] = max[0] - width;
105 max[1] = min[1] + width;
110 min[1] = max[1] - width;
116 char* TranslateString( const char *buf ){
117 static char buf2[32768];
123 for ( i = 0 ; i < l ; i++ )
125 if ( buf[i] == '\n' ) {
138 void Sys_ERROR( const char* text, ... ){
142 va_start( argptr,text );
143 vsprintf( buf, text,argptr );
146 Sys_Printf( "BobToolz::ERROR->%s", buf );
149 /*void Sys_Printf (char *text, ...)
154 va_start (argptr,text);
155 vsprintf (buf, text,argptr);
158 g_FuncTable.m_pfnSysMsg ( buf );
161 char* UnixToDosPath( char* path ){
165 for ( char* p = path; *p; p++ )
175 const char* ExtractFilename( const char* path ){
176 const char* p = strrchr( path, '/' );
178 p = strrchr( path, '\\' );
187 extern const char* PLUGIN_NAME;
188 /*char* GetGameFilename(char* buffer, const char* filename)
190 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
191 char* p = strrchr(buffer, '/');
193 strcat(buffer, filename);
194 buffer = UnixToDosPath(buffer);
198 #if defined ( __linux__ ) || defined ( __APPLE__ )
199 // the bCreateConsole parameter is ignored on linux ..
200 bool Q_Exec( const char *pCmd, bool bCreateConsole ){
205 // Error ("CreateProcess failed");
209 printf( "Running system...\n" );
210 printf( "Command: %s\n", pCmd );
212 // NOTE: we could use that to detect when a step finishes. But then it
213 // would not work for remote compiling stuff.
214 // execlp (pCmd, pCmd, NULL);
216 printf( "system() returned" );
225 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;
233 if ( bCreateConsole ) {
234 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
237 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 = g_FuncTable.m_pfnReadProjectKey( "mapspath" );
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 void BuildMiniPrt( list<Str>* exclusionList ){
269 // yes, we could just use -fulldetail option, but, as SPOG said
270 // it'd be faster without all the hint, donotenter etc textures and
276 const char *pn = g_FuncTable.m_pfnReadProjectKey( "mapspath" );
278 strcpy( buffer, pn );
279 strcat( buffer, "/ac_prt.map" );
280 FILE* pFile = fopen( buffer, "w" );
287 int count = g_FuncTable.m_pfnGetEntityCount();
288 for ( int i = 0; i < count; i++ )
290 entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle( i );
292 epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList( ent );
297 if ( !strcmp( ep->key, "classname" ) ) {
298 if ( !strcmp( ep->value, "worldspawn" ) ) {
299 world.LoadFromEntity( i, FALSE );
300 world.RemoveNonCheckBrushes( exclusionList, TRUE );
301 world.SaveToFile( pFile );
303 else if ( strstr( ep->value, "info_" ) ) {
304 world.ClearBrushes();
306 world.LoadEPairList( epl );
307 world.SaveToFile( pFile );
321 entity_s* FindEntityFromTargetname( const char* targetname, int* entNum ){
324 int count = g_FuncTable.m_pfnGetEntityCount();
325 for ( int i = 0; i < count; i++ )
329 entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle( i );
331 world.LoadEPairList( *g_EntityTable.m_pfnGetEntityKeyValList( ent ) );
333 DEPair* tn = world.FindEPairByKey( "targetname" );
335 if ( !stricmp( tn->value, targetname ) ) {
346 void FillDefaultTexture( _QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture ){
347 faceData->m_bBPrimit = FALSE;
348 faceData->m_fRotate = 0;
349 faceData->m_fScale[0] = 0.5;
350 faceData->m_fScale[1] = 0.5;
351 faceData->m_fShift[0] = 0;
352 faceData->m_fShift[1] = 0;
353 faceData->m_nContents = 0;
354 faceData->m_nFlags = 0;
355 faceData->m_nValue = 0;
357 strcpy( faceData->m_TextureName, texture );
360 strcpy( faceData->m_TextureName, "textures/common/caulk" );
362 VectorCopy( va, faceData->m_v1 );
363 VectorCopy( vb, faceData->m_v2 );
364 VectorCopy( vc, faceData->m_v3 );
367 float Determinant3x3( float a1, float a2, float a3,
368 float b1, float b2, float b3,
369 float c1, float c2, float c3 ){
370 return a1 * ( b2 * c3 - b3 * c2 ) - a2 * ( b1 * c3 - b3 * c1 ) + a3 * ( b1 * c2 - b2 * c1 );
373 bool GetEntityCentre( const char* entity, vec3_t centre ){
374 entity_s* ent = FindEntityFromTargetname( entity, NULL );
379 int cnt = g_FuncTable.m_pfnAllocateEntityBrushHandles( ent );
381 g_FuncTable.m_pfnReleaseEntityBrushHandles();
385 brush_t* brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle( 0 );
387 cBrush.LoadFromBrush_t( brush, FALSE );
390 cBrush.GetBounds( min, max );
392 VectorAdd( min, max, centre );
393 VectorScale( centre, 0.5f, centre );
395 g_FuncTable.m_pfnReleaseEntityBrushHandles();
399 vec_t Min( vec_t a, vec_t b ){
406 void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {
408 VectorSubtract( va, vb, v1 );
409 VectorSubtract( vc, vb, v2 );
410 CrossProduct( v1, v2, out );