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"
36 #include <sys/types.h>
42 #include "iscenegraph.h"
43 #include "qerplugin.h"
52 /*==========================
54 ==========================*/
57 char g_CurrentTexture[256] = "";
59 //=============================================================
60 //=============================================================
62 void ReadCurrentTexture(){
63 const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
64 strcpy( g_CurrentTexture, textureName );
67 const char* GetCurrentTexture(){
69 return g_CurrentTexture;
72 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 ){
107 max[0] = min[0] + width;
112 min[0] = max[0] - width;
117 max[1] = min[1] + width;
122 min[1] = max[1] - width;
128 char* TranslateString( char *buf ){
129 static char buf2[32768];
131 std::size_t l = strlen( buf );
133 for ( std::size_t i = 0 ; i < l ; i++ )
135 if ( buf[i] == '\n' ) {
149 char* UnixToDosPath( char* path ){
153 for ( char* p = path; *p; p++ )
163 const char* ExtractFilename( const char* path ){
164 const char* p = strrchr( path, '/' );
166 p = strrchr( path, '\\' );
175 extern char* PLUGIN_NAME;
176 /*char* GetGameFilename(char* buffer, const char* filename)
178 strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
179 char* p = strrchr(buffer, '/');
181 strcat(buffer, filename);
182 buffer = UnixToDosPath(buffer);
187 // the bCreateConsole parameter is ignored on linux ..
188 bool Q_Exec( const char *pCmd, bool bCreateConsole ){
193 // Error ("CreateProcess failed");
197 printf( "Running system...\n" );
198 printf( "Command: %s\n", pCmd );
200 // NOTE: we could use that to detect when a step finishes. But then it
201 // would not work for remote compiling stuff.
202 // execlp (pCmd, pCmd, NULL);
204 printf( "system() returned" );
216 bool Q_Exec( const char *pCmd, bool bCreateConsole ){
217 // G_DeWan: Don't know if this is needed for linux version
219 PROCESS_INFORMATION pi;
220 STARTUPINFO si = {0}; // Initialize all members to zero
221 si.cb = sizeof( STARTUPINFO ); // Set byte count
222 DWORD dwCreationFlags;
224 if ( bCreateConsole ) {
225 dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
228 dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
231 for (; *pCmd == ' '; pCmd++ ) ;
233 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();
249 strcpy( mapname, pn );
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
261 mutable DEntity world;
263 std::list<Str>* exclusionList;
265 EntityWriteMiniPrt( FILE* pFile, std::list<Str>* exclusionList )
266 : pFile( pFile ), exclusionList( exclusionList ){
268 void operator()( scene::Instance& instance ) const {
269 const char* classname = Node_getEntity( instance.path().top() )->getKeyValue( "classname" );
271 if ( !strcmp( classname, "worldspawn" ) ) {
272 world.LoadFromEntity( instance.path().top(), false );
273 world.RemoveNonCheckBrushes( exclusionList, true );
274 world.SaveToFile( pFile );
276 else if ( strstr( classname, "info_" ) ) {
277 world.ClearBrushes();
279 world.LoadEPairList( Node_getEntity( instance.path().top() ) );
280 world.SaveToFile( pFile );
285 void BuildMiniPrt( std::list<Str>* exclusionList ){
286 // yes, we could just use -fulldetail option, but, as SPOG said
287 // it'd be faster without all the hint, donotenter etc textures and
293 const char *pn = GlobalRadiant().getMapsPath();
295 strcpy( buffer, pn );
296 strcat( buffer, "/ac_prt.map" );
297 FILE* pFile = fopen( buffer, "w" );
304 Scene_forEachEntity( EntityWriteMiniPrt( pFile, exclusionList ) );
311 class EntityFindByTargetName
313 const char* targetname;
315 mutable const scene::Path* result;
316 EntityFindByTargetName( const char* targetname )
317 : targetname( targetname ), result( 0 ){
319 void operator()( scene::Instance& instance ) const {
321 const char* value = Node_getEntity( instance.path().top() )->getKeyValue( "targetname" );
323 if ( !strcmp( value, targetname ) ) {
324 result = &instance.path();
330 const scene::Path* FindEntityFromTargetname( const char* targetname ){
331 return Scene_forEachEntity( EntityFindByTargetName( targetname ) ).result;
334 void FillDefaultTexture( _QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture ){
335 faceData->m_texdef.rotate = 0;
336 faceData->m_texdef.scale[0] = 0.5;
337 faceData->m_texdef.scale[1] = 0.5;
338 faceData->m_texdef.shift[0] = 0;
339 faceData->m_texdef.shift[1] = 0;
340 faceData->contents = 0;
344 faceData->m_shader = texture;
347 faceData->m_shader = "textures/common/caulk";
349 VectorCopy( va, faceData->m_p0 );
350 VectorCopy( vb, faceData->m_p1 );
351 VectorCopy( vc, faceData->m_p2 );
354 float Determinant3x3( float a1, float a2, float a3,
355 float b1, float b2, float b3,
356 float c1, float c2, float c3 ){
357 return a1 * ( b2 * c3 - b3 * c2 ) - a2 * ( b1 * c3 - b3 * c1 ) + a3 * ( b1 * c2 - b2 * c1 );
360 bool GetEntityCentre( const char* entity, vec3_t centre ){
361 const scene::Path* ent = FindEntityFromTargetname( entity );
366 scene::Instance& instance = *GlobalSceneGraph().find( *ent );
367 VectorCopy( instance.worldAABB().origin, centre );
372 vec_t Min( vec_t a, vec_t b ){
379 void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
381 VectorSubtract( va, vb, v1 );
382 VectorSubtract( vc, vb, v2 );
383 CrossProduct( v1, v2, out );
386 char* GetFilename( char* buffer, const char* filename ) {
387 strcpy( buffer, GlobalRadiant().getAppPath() );
388 strcat( buffer, "plugins/" );
389 strcat( buffer, filename );