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(){
62 const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
63 strcpy( g_CurrentTexture, textureName );
66 const char* GetCurrentTexture(){
68 return g_CurrentTexture;
71 void MoveBlock( int dir, vec3_t min, vec3_t max, float dist ){
101 void SetInitialStairPos( int dir, vec3_t min, vec3_t max, float width ){
106 max[0] = min[0] + width;
111 min[0] = max[0] - width;
116 max[1] = min[1] + width;
121 min[1] = max[1] - width;
127 char* TranslateString( char *buf ){
128 static char buf2[32768];
130 std::size_t l = strlen( buf );
132 for ( int i = 0 ; i < l ; i++ )
134 if ( buf[i] == '\n' ) {
148 char* UnixToDosPath( char* path ){
152 for ( char* p = path; *p; p++ )
162 const char* ExtractFilename( const char* path ){
163 const char* p = strrchr( path, '/' );
165 p = strrchr( path, '\\' );
174 extern char* PLUGIN_NAME;
175 /*char* GetGameFilename(char* buffer, const char* filename)
177 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
178 char* p = strrchr(buffer, '/');
180 strcat(buffer, filename);
181 buffer = UnixToDosPath(buffer);
185 #if defined ( POSIX )
186 // the bCreateConsole parameter is ignored on linux ..
187 bool Q_Exec( const char *pCmd, bool bCreateConsole ){
192 // Error ("CreateProcess failed");
196 printf( "Running system...\n" );
197 printf( "Command: %s\n", pCmd );
199 // NOTE: we could use that to detect when a step finishes. But then it
200 // would not work for remote compiling stuff.
201 // execlp (pCmd, pCmd, NULL);
203 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 ) ) {
242 GetFilename( exename, "q3map" );
243 UnixToDosPath( exename ); // do we want this done in linux version?
246 const char *pn = GlobalRadiant().getMapsPath();
248 strcpy( mapname, pn );
249 strcat( mapname, "/ac_prt.map" );
250 UnixToDosPath( mapname );
253 sprintf( command, "%s -nowater -fulldetail %s", exename, mapname );
255 Q_Exec( command, true );
258 class EntityWriteMiniPrt
260 mutable DEntity world;
262 std::list<Str>* exclusionList;
264 EntityWriteMiniPrt( FILE* pFile, std::list<Str>* exclusionList )
265 : pFile( pFile ), exclusionList( exclusionList ){
267 void operator()( scene::Instance& instance ) const {
268 const char* classname = Node_getEntity( instance.path().top() )->getKeyValue( "classname" );
270 if ( !strcmp( classname, "worldspawn" ) ) {
271 world.LoadFromEntity( instance.path().top(), false );
272 world.RemoveNonCheckBrushes( exclusionList, true );
273 world.SaveToFile( pFile );
275 else if ( strstr( classname, "info_" ) ) {
276 world.ClearBrushes();
278 world.LoadEPairList( Node_getEntity( instance.path().top() ) );
279 world.SaveToFile( pFile );
284 void BuildMiniPrt( std::list<Str>* exclusionList ){
285 // yes, we could just use -fulldetail option, but, as SPOG said
286 // it'd be faster without all the hint, donotenter etc textures and
292 const char *pn = GlobalRadiant().getMapsPath();
294 strcpy( buffer, pn );
295 strcat( buffer, "/ac_prt.map" );
296 FILE* pFile = fopen( buffer, "w" );
303 Scene_forEachEntity( EntityWriteMiniPrt( pFile, exclusionList ) );
310 class EntityFindByTargetName
312 const char* targetname;
314 mutable const scene::Path* result;
315 EntityFindByTargetName( const char* targetname )
316 : targetname( targetname ), result( 0 ){
318 void operator()( scene::Instance& instance ) const {
320 const char* value = Node_getEntity( instance.path().top() )->getKeyValue( "targetname" );
322 if ( !strcmp( value, targetname ) ) {
323 result = &instance.path();
329 const scene::Path* FindEntityFromTargetname( const char* targetname ){
330 return Scene_forEachEntity( EntityFindByTargetName( targetname ) ).result;
333 void FillDefaultTexture( _QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture ){
334 faceData->m_texdef.rotate = 0;
335 faceData->m_texdef.scale[0] = 0.5;
336 faceData->m_texdef.scale[1] = 0.5;
337 faceData->m_texdef.shift[0] = 0;
338 faceData->m_texdef.shift[1] = 0;
339 faceData->contents = 0;
343 faceData->m_shader = texture;
346 faceData->m_shader = "textures/common/caulk";
348 VectorCopy( va, faceData->m_p0 );
349 VectorCopy( vb, faceData->m_p1 );
350 VectorCopy( vc, faceData->m_p2 );
353 float Determinant3x3( float a1, float a2, float a3,
354 float b1, float b2, float b3,
355 float c1, float c2, float c3 ){
356 return a1 * ( b2 * c3 - b3 * c2 ) - a2 * ( b1 * c3 - b3 * c1 ) + a3 * ( b1 * c2 - b2 * c1 );
359 bool GetEntityCentre( const char* entity, vec3_t centre ){
360 const scene::Path* ent = FindEntityFromTargetname( entity );
365 scene::Instance& instance = *GlobalSceneGraph().find( *ent );
366 VectorCopy( instance.worldAABB().origin, centre );
371 vec_t Min( vec_t a, vec_t b ){
378 void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
380 VectorSubtract( va, vb, v1 );
381 VectorSubtract( vc, vb, v2 );
382 CrossProduct( v1, v2, out );
385 char* GetFilename( char* buffer, const char* filename ) {
386 strcpy( buffer, GlobalRadiant().getAppPath() );
387 strcat( buffer, "plugins/" );
388 strcat( buffer, filename );