2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
BobToolz plugin for GtkRadiant
|
|
|
|
Copyright (C) 2001 Gordon Biggans
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
|
|
#include "DEntity.h"
|
|
|
|
#include "funchandlers.h"
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*==========================
|
2012-03-17 20:01:54 +00:00
|
|
|
Global Vars
|
|
|
|
==========================*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//HANDLE bsp_process;
|
2012-03-17 20:01:54 +00:00
|
|
|
char g_CurrentTexture[256] = "";
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//=============================================================
|
|
|
|
//=============================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void ReadCurrentTexture(){
|
2007-11-04 03:51:54 +00:00
|
|
|
const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
|
2012-03-17 20:01:54 +00:00
|
|
|
strcpy( g_CurrentTexture, textureName );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const char* GetCurrentTexture(){
|
2007-11-04 03:51:54 +00:00
|
|
|
ReadCurrentTexture();
|
|
|
|
return g_CurrentTexture;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
epair_t* GetNextChainItem( epair_t* lastItem, const char* key, const char* value ){
|
|
|
|
epair_t* nextEPair = g_FuncTable.m_pfnAllocateEpair( key, value );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lastItem != NULL ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
lastItem->next = nextEPair;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return nextEPair;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void MoveBlock( int dir, vec3_t min, vec3_t max, float dist ){
|
|
|
|
switch ( dir )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
case MOVE_EAST:
|
|
|
|
{
|
|
|
|
min[0] += dist;
|
|
|
|
max[0] += dist;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOVE_WEST:
|
|
|
|
{
|
|
|
|
min[0] -= dist;
|
|
|
|
max[0] -= dist;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOVE_NORTH:
|
|
|
|
{
|
|
|
|
min[1] += dist;
|
|
|
|
max[1] += dist;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOVE_SOUTH:
|
|
|
|
{
|
|
|
|
min[1] -= dist;
|
|
|
|
max[1] -= dist;
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void SetInitialStairPos( int dir, vec3_t min, vec3_t max, float width ){
|
|
|
|
switch ( dir )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
case MOVE_EAST:
|
|
|
|
{
|
|
|
|
max[0] = min[0] + width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOVE_WEST:
|
|
|
|
{
|
|
|
|
min[0] = max[0] - width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOVE_NORTH:
|
|
|
|
{
|
|
|
|
max[1] = min[1] + width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MOVE_SOUTH:
|
|
|
|
{
|
|
|
|
min[1] = max[1] - width;
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char* TranslateString( const char *buf ){
|
|
|
|
static char buf2[32768];
|
|
|
|
int i, l;
|
|
|
|
char *out;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
l = strlen( buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
out = buf2;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < l ; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( buf[i] == '\n' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
*out++ = '\r';
|
|
|
|
*out++ = '\n';
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:51:54 +00:00
|
|
|
*out++ = buf[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
*out++ = 0;
|
|
|
|
|
|
|
|
return buf2;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Sys_ERROR( const char* text, ... ){
|
2007-11-04 03:51:54 +00:00
|
|
|
va_list argptr;
|
2012-03-17 20:01:54 +00:00
|
|
|
char buf[32768];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr,text );
|
|
|
|
vsprintf( buf, text,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2016-05-16 19:20:20 +00:00
|
|
|
Sys_FPrintf( SYS_ERR, "BobToolz::ERROR->%s", buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*void Sys_Printf (char *text, ...)
|
2012-03-17 20:01:54 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char buf[32768];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start (argptr,text);
|
|
|
|
vsprintf (buf, text,argptr);
|
|
|
|
va_end (argptr);
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnSysMsg ( buf );
|
|
|
|
}*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char* UnixToDosPath( char* path ){
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
return path;
|
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( char* p = path; *p; p++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *p == '/' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
*p = '\\';
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const char* ExtractFilename( const char* path ){
|
|
|
|
const char* p = strrchr( path, '/' );
|
|
|
|
if ( !p ) {
|
|
|
|
p = strrchr( path, '\\' );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !p ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return path;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return ++p;
|
|
|
|
}
|
|
|
|
|
2008-09-06 08:35:17 +00:00
|
|
|
extern const char* PLUGIN_NAME;
|
2007-11-04 03:51:54 +00:00
|
|
|
/*char* GetGameFilename(char* buffer, const char* filename)
|
2012-03-17 20:01:54 +00:00
|
|
|
{
|
|
|
|
strcpy(buffer, g_FuncTable.m_pfnGetGamePath());
|
|
|
|
char* p = strrchr(buffer, '/');
|
|
|
|
*++p = '\0';
|
|
|
|
strcat(buffer, filename);
|
|
|
|
buffer = UnixToDosPath(buffer);
|
|
|
|
return buffer;
|
|
|
|
}*/
|
|
|
|
|
2017-08-30 11:07:42 +00:00
|
|
|
#if defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __APPLE__ )
|
2007-11-04 03:51:54 +00:00
|
|
|
// the bCreateConsole parameter is ignored on linux ..
|
2012-03-17 20:01:54 +00:00
|
|
|
bool Q_Exec( const char *pCmd, bool bCreateConsole ){
|
|
|
|
switch ( fork() )
|
|
|
|
{
|
2007-11-04 03:51:54 +00:00
|
|
|
case -1:
|
2012-03-17 20:01:54 +00:00
|
|
|
return false;
|
2007-11-04 03:51:54 +00:00
|
|
|
// Error ("CreateProcess failed");
|
2012-03-17 20:01:54 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "Running system...\n" );
|
|
|
|
printf( "Command: %s\n", pCmd );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
// NOTE: we could use that to detect when a step finishes. But then it
|
|
|
|
// would not work for remote compiling stuff.
|
2007-11-04 03:51:54 +00:00
|
|
|
// execlp (pCmd, pCmd, NULL);
|
2012-03-17 20:01:54 +00:00
|
|
|
system( pCmd );
|
|
|
|
printf( "system() returned" );
|
|
|
|
_exit( 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2012-03-17 20:01:54 +00:00
|
|
|
bool Q_Exec( const char *pCmd, bool bCreateConsole ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// G_DeWan: Don't know if this is needed for linux version
|
|
|
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si = {0}; // Initialize all members to zero
|
2012-03-17 20:01:54 +00:00
|
|
|
si.cb = sizeof( STARTUPINFO ); // Set byte count
|
|
|
|
DWORD dwCreationFlags;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bCreateConsole ) {
|
|
|
|
dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for (; *pCmd == ' '; pCmd++ ) ;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !CreateProcess( NULL, (char *)pCmd, NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &pi ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return true;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void StartBSP(){
|
2007-11-04 03:51:54 +00:00
|
|
|
char exename[256];
|
2012-03-17 20:01:54 +00:00
|
|
|
GetFilename( exename, "q3map" );
|
|
|
|
UnixToDosPath( exename ); // do we want this done in linux version?
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2008-07-25 19:14:48 +00:00
|
|
|
char mapname[256];
|
2012-03-17 20:01:54 +00:00
|
|
|
const char *pn = g_FuncTable.m_pfnReadProjectKey( "mapspath" );
|
2008-07-25 19:14:48 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
strcpy( mapname, pn );
|
|
|
|
strcat( mapname, "/ac_prt.map" );
|
2012-03-17 20:01:54 +00:00
|
|
|
UnixToDosPath( mapname );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
char command[1024];
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( command, "%s -nowater -fulldetail %s", exename, mapname );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
Q_Exec( command, TRUE );
|
|
|
|
}
|
|
|
|
|
Do not do `using namespace std` to avoid type conflict
The STL now defines `std::byte` so doing `using namespace std`
will conflict will custom definition of `byte`, which this
legacy code is full of.
It looks like NetRadiant went the route of making explicit
usage of `std::` prefixed types and did not renamed the
custom definition of byte, so doing the same reduces diff
noise between the two trees.
This also makes the code future proof if the STL decides
to define some other types with common name.
This patches replaces all usages of `map`, `pair` and
`vector` with `std::map`, `std::pair` and `std::vector`
and remove the `using namespace std` line in `stl_check.h`.
```
libs/mathlib.h:132:44: error: reference to ‘byte’ is ambiguous
132 | void NormalToLatLong( const vec3_t normal, byte bytes[2] );
| ^~~~
In file included from /usr/include/c++/11/bits/stl_algobase.h:61,
from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from libs/missing.h:76,
from radiant/qe3.h:40,
from radiant/stdafx.h:39,
from radiant/bp_dlg.cpp:28:
/usr/include/c++/11/bits/cpp_type_traits.h:404:30: note: candidates are: ‘enum class std::byte’
404 | enum class byte : unsigned char;
| ^~~~
```
2022-07-14 15:18:51 +00:00
|
|
|
void BuildMiniPrt( std::list<Str>* exclusionList ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// yes, we could just use -fulldetail option, but, as SPOG said
|
|
|
|
// it'd be faster without all the hint, donotenter etc textures and
|
|
|
|
// doors, etc
|
|
|
|
|
|
|
|
DEntity world;
|
2008-07-25 19:14:48 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
char buffer[128];
|
2012-03-17 20:01:54 +00:00
|
|
|
const char *pn = g_FuncTable.m_pfnReadProjectKey( "mapspath" );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
strcpy( buffer, pn );
|
|
|
|
strcat( buffer, "/ac_prt.map" );
|
2012-03-17 20:01:54 +00:00
|
|
|
FILE* pFile = fopen( buffer, "w" );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// ahem, thx rr2
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !pFile ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
int count = g_FuncTable.m_pfnGetEntityCount();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < count; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
entity_t* ent = (entity_t*)g_FuncTable.m_pfnGetEntityHandle( i );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
epair_t* epl = *g_EntityTable.m_pfnGetEntityKeyValList( ent );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
epair_t* ep = epl;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( ep )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( ep->key, "classname" ) ) {
|
|
|
|
if ( !strcmp( ep->value, "worldspawn" ) ) {
|
|
|
|
world.LoadFromEntity( i, FALSE );
|
|
|
|
world.RemoveNonCheckBrushes( exclusionList, TRUE );
|
|
|
|
world.SaveToFile( pFile );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( strstr( ep->value, "info_" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
world.ClearBrushes();
|
|
|
|
world.ClearEPairs();
|
2012-03-17 20:01:54 +00:00
|
|
|
world.LoadEPairList( epl );
|
|
|
|
world.SaveToFile( pFile );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ep = ep->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( pFile );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
StartBSP();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
entity_s* FindEntityFromTargetname( const char* targetname, int* entNum ){
|
2007-11-04 03:51:54 +00:00
|
|
|
DEntity world;
|
|
|
|
|
|
|
|
int count = g_FuncTable.m_pfnGetEntityCount();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < count; i++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
world.ClearEPairs();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle( i );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
world.LoadEPairList( *g_EntityTable.m_pfnGetEntityKeyValList( ent ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DEPair* tn = world.FindEPairByKey( "targetname" );
|
|
|
|
if ( tn ) {
|
|
|
|
if ( !stricmp( tn->value, targetname ) ) {
|
|
|
|
if ( entNum ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
*entNum = i;
|
|
|
|
}
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FillDefaultTexture( _QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture ){
|
2007-11-04 03:51:54 +00:00
|
|
|
faceData->m_bBPrimit = FALSE;
|
|
|
|
faceData->m_fRotate = 0;
|
|
|
|
faceData->m_fScale[0] = 0.5;
|
|
|
|
faceData->m_fScale[1] = 0.5;
|
|
|
|
faceData->m_fShift[0] = 0;
|
|
|
|
faceData->m_fShift[1] = 0;
|
|
|
|
faceData->m_nContents = 0;
|
|
|
|
faceData->m_nFlags = 0;
|
|
|
|
faceData->m_nValue = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *texture ) {
|
|
|
|
strcpy( faceData->m_TextureName, texture );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
strcpy( faceData->m_TextureName, "textures/common/caulk" );
|
|
|
|
}
|
|
|
|
VectorCopy( va, faceData->m_v1 );
|
|
|
|
VectorCopy( vb, faceData->m_v2 );
|
|
|
|
VectorCopy( vc, faceData->m_v3 );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float Determinant3x3( float a1, float a2, float a3,
|
|
|
|
float b1, float b2, float b3,
|
|
|
|
float c1, float c2, float c3 ){
|
|
|
|
return a1 * ( b2 * c3 - b3 * c2 ) - a2 * ( b1 * c3 - b3 * c1 ) + a3 * ( b1 * c2 - b2 * c1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool GetEntityCentre( const char* entity, vec3_t centre ){
|
|
|
|
entity_s* ent = FindEntityFromTargetname( entity, NULL );
|
|
|
|
if ( !ent ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int cnt = g_FuncTable.m_pfnAllocateEntityBrushHandles( ent );
|
|
|
|
if ( cnt == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
g_FuncTable.m_pfnReleaseEntityBrushHandles();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
brush_t* brush = (brush_t*)g_FuncTable.m_pfnGetEntityBrushHandle( 0 );
|
2007-11-04 03:51:54 +00:00
|
|
|
DBrush cBrush;
|
2012-03-17 20:01:54 +00:00
|
|
|
cBrush.LoadFromBrush_t( brush, FALSE );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
vec3_t min, max;
|
2012-03-17 20:01:54 +00:00
|
|
|
cBrush.GetBounds( min, max );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorAdd( min, max, centre );
|
|
|
|
VectorScale( centre, 0.5f, centre );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
g_FuncTable.m_pfnReleaseEntityBrushHandles();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vec_t Min( vec_t a, vec_t b ){
|
|
|
|
if ( a < b ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return a;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {
|
|
|
|
vec3_t v1, v2;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( va, vb, v1 );
|
|
|
|
VectorSubtract( vc, vb, v2 );
|
|
|
|
CrossProduct( v1, v2, out );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|