add utils

This commit is contained in:
Er2 2023-05-09 19:57:22 +03:00
parent 523f4e9eaa
commit f9added066
77 changed files with 1610 additions and 509 deletions

View File

@ -2,12 +2,15 @@
//
//=============================================================================
#ifndef POSIX
#include <windows.h>
#include <tier0/dbg.h>
#include <io.h>
#include <WorldSize.h>
#include "fgdlib/GameData.h"
#include "fgdlib/HelperInfo.h"
#endif
#include "worldsize.h"
#include "fgdlib/gamedata.h"
#include "fgdlib/helperinfo.h"
#include "KeyValues.h"
#include "filesystem_tools.h"
#include "tier1/strtools.h"
@ -276,12 +279,14 @@ void GameData::ClearData(void)
// Input : pszFilename -
// Output : Returns TRUE on success, FALSE on failure.
//-----------------------------------------------------------------------------
BOOL GameData::Load(const char *pszFilename)
bool GameData::Load(const char *pszFilename)
{
TokenReader tr;
#ifndef POSIX
if(GetFileAttributes(pszFilename) == 0xffffffff)
return FALSE;
#endif
if(!tr.Open(pszFilename))
return FALSE;

View File

@ -4,8 +4,8 @@
//
//=============================================================================
#include "fgdlib/GameData.h" // FGDLIB: eliminate dependency
#include "fgdlib/GDClass.h"
#include "fgdlib/gamedata.h" // FGDLIB: eliminate dependency
#include "fgdlib/gdclass.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

View File

@ -3,8 +3,8 @@
//=============================================================================
#include "fgdlib/fgdlib.h"
#include "fgdlib/GameData.h"
#include "fgdlib/WCKeyValues.h"
#include "fgdlib/gamedata.h"
#include "fgdlib/wckeyvalues.h"
#include "fgdlib/gdvar.h"
// memdbgon must be the last include file in a .cpp file!!!
@ -669,7 +669,7 @@ void GDinputvariable::ToKeyValue(MDkeyvalue *pkv)
}
else if (eStoreAs == INTEGER)
{
itoa(m_nValue, pkv->szValue, 10);
Q_snprintf(pkv->szValue, sizeof(pkv->szValue), "%d", m_nValue);
}
}

View File

@ -6,7 +6,7 @@
#include <tier0/dbg.h>
#include "fgdlib/InputOutput.h"
#include "fgdlib/inputoutput.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

View File

@ -4,7 +4,7 @@
//
//=============================================================================
#include "fgdlib/WCKeyValues.h"
#include "fgdlib/wckeyvalues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
@ -34,11 +34,11 @@ MDkeyvalue &MDkeyvalue::operator =(const MDkeyvalue &other)
void WCKVBase_Vector::RemoveKeyAt(int nIndex)
{
Assert(nIndex >= 0);
Assert(nIndex < (int)m_KeyValues.Count());
Assert(nIndex < (int)this->m_KeyValues.Count());
if ((nIndex >= 0) && (nIndex < (int)m_KeyValues.Count()))
if ((nIndex >= 0) && (nIndex < (int)this->m_KeyValues.Count()))
{
m_KeyValues.Remove(nIndex);
this->m_KeyValues.Remove(nIndex);
}
}
@ -71,14 +71,14 @@ void WCKVBase_Vector::AddKeyValue(const char *pszKey, const char *pszValue)
MDkeyvalue newkv;
V_strcpy_safe(newkv.szKey, szTmpKey);
V_strcpy_safe(newkv.szValue, szTmpValue);
m_KeyValues.AddToTail(newkv);
this->m_KeyValues.AddToTail(newkv);
}
int WCKVBase_Vector::FindByKeyName( const char *pKeyName ) const
{
for ( int i=0; i < m_KeyValues.Count(); i++ )
for ( int i=0; i < this->m_KeyValues.Count(); i++ )
{
if ( V_stricmp( m_KeyValues[i].szKey, pKeyName ) == 0 )
if ( V_stricmp( this->m_KeyValues[i].szKey, pKeyName ) == 0 )
return i;
}
return GetInvalidIndex();
@ -86,7 +86,7 @@ int WCKVBase_Vector::FindByKeyName( const char *pKeyName ) const
void WCKVBase_Vector::InsertKeyValue( const MDkeyvalue &kv )
{
m_KeyValues.AddToTail( kv );
this->m_KeyValues.AddToTail( kv );
}
@ -94,18 +94,18 @@ void WCKVBase_Vector::InsertKeyValue( const MDkeyvalue &kv )
//-----------------------------------------------------------------------------
void WCKVBase_Dict::RemoveKeyAt(int nIndex)
{
m_KeyValues.RemoveAt(nIndex);
this->m_KeyValues.RemoveAt(nIndex);
}
int WCKVBase_Dict::FindByKeyName( const char *pKeyName ) const
{
return m_KeyValues.Find( pKeyName );
return this->m_KeyValues.Find( pKeyName );
}
void WCKVBase_Dict::InsertKeyValue( const MDkeyvalue &kv )
{
m_KeyValues.Insert( kv.szKey, kv );
this->m_KeyValues.Insert( kv.szKey, kv );
}
@ -125,9 +125,9 @@ template<class Base>
WCKeyValuesT<Base>::~WCKeyValuesT(void)
{
//int i = 0;
//while (i < m_KeyValues.GetSize())
//while (i < this->m_KeyValues.GetSize())
//{
// delete m_KeyValues.GetAt(i++);
// delete this->m_KeyValues.GetAt(i++);
//}
RemoveAll();
@ -139,8 +139,8 @@ WCKeyValuesT<Base>::~WCKeyValuesT(void)
template<class Base>
const char *WCKeyValuesT<Base>::GetValue(const char *pszKey, int *piIndex) const
{
int i = FindByKeyName( pszKey );
if ( i == GetInvalidIndex() )
int i = this->FindByKeyName( pszKey );
if ( i == this->GetInvalidIndex() )
{
return NULL;
}
@ -149,7 +149,7 @@ const char *WCKeyValuesT<Base>::GetValue(const char *pszKey, int *piIndex) const
if(piIndex)
piIndex[0] = i;
return m_KeyValues[i].szValue;
return this->m_KeyValues[i].szValue;
}
}
@ -169,7 +169,7 @@ template<class Base>
void WCKeyValuesT<Base>::SetValue(const char *pszKey, int iValue)
{
char szValue[100];
itoa(iValue, szValue, 10);
Q_snprintf(szValue, sizeof(szValue), "%d", iValue);
SetValue(pszKey, szValue);
}
@ -233,8 +233,8 @@ void WCKeyValuesT<Base>::SetValue(const char *pszKey, const char *pszValue)
StripEdgeWhiteSpace(szTmpKey);
StripEdgeWhiteSpace(szTmpValue);
int i = FindByKeyName( szTmpKey );
if ( i == GetInvalidIndex() )
int i = this->FindByKeyName( szTmpKey );
if ( i == this->GetInvalidIndex() )
{
if ( pszValue )
{
@ -244,21 +244,21 @@ void WCKeyValuesT<Base>::SetValue(const char *pszKey, const char *pszValue)
MDkeyvalue newkv;
Q_strncpy( newkv.szKey, szTmpKey, sizeof( newkv.szKey ) );
Q_strncpy( newkv.szValue, szTmpValue, sizeof( newkv.szValue ) );
InsertKeyValue( newkv );
this->InsertKeyValue( newkv );
}
}
else
{
if (pszValue != NULL)
{
V_strncpy(m_KeyValues[i].szValue, szTmpValue, sizeof(m_KeyValues[i].szValue));
V_strncpy(this->m_KeyValues[i].szValue, szTmpValue, sizeof(this->m_KeyValues[i].szValue));
}
//
// If we are setting to a NULL value, delete the key.
//
else
{
RemoveKeyAt( i );
this->RemoveKeyAt( i );
}
}
}
@ -270,7 +270,7 @@ void WCKeyValuesT<Base>::SetValue(const char *pszKey, const char *pszValue)
template<class Base>
void WCKeyValuesT<Base>::RemoveAll(void)
{
m_KeyValues.RemoveAll();
this->m_KeyValues.RemoveAll();
}

54
fgdlib/wscript Executable file
View File

@ -0,0 +1,54 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'fgdlib'
def options(opt):
# stub
return
def configure(conf):
return
def build(bld):
source = [
'gamedata.cpp',
'gdclass.cpp',
'gdvar.cpp',
'inputoutput.cpp',
'wckeyvalues.cpp',
]
includes = [
'.',
'../public',
'../public/tier0',
'../public/tier1',
'../public/fgdlib',
'../utils/common'
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'tier3', 'vstdlib', 'mathlib']
if bld.env.DEST_OS == 'win32':
libs += ['USER32']
bld.stlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -151,7 +151,7 @@ ChunkHandler_t CChunkHandlerMap::GetHandler(const char *pszChunkName, void **ppD
pNode = pNode->pNext;
}
return(false);
return NULL;
}

View File

@ -10,9 +10,9 @@
#pragma once
#endif
#include "HelperInfo.h"
#include "GameData.h"
#include "GDClass.h"
#include "InputOutput.h"
#include "helperinfo.h"
#include "gamedata.h"
#include "gdclass.h"
#include "inputoutput.h"
#endif // FGDLIB_H

View File

@ -10,24 +10,19 @@
#pragma once
#endif
#pragma warning(push, 1)
#pragma warning(disable:4701 4702 4530)
#include <fstream>
#pragma warning(pop)
#include "TokenReader.h"
#include "GDClass.h"
#include "InputOutput.h"
#include "UtlString.h"
#include "tier0/platform.h"
#include "tier1/tokenreader.h"
#include "gdclass.h"
#include "inputoutput.h"
#include "utlstring.h"
#include "utlvector.h"
#include "utlmap.h"
class MDkeyvalue;
class GameData;
class KeyValues;
enum TEXTUREFORMAT;
typedef void (*GameDataMessageFunc_t)(int level, PRINTF_FORMAT_STRING const char *fmt, ...);
// FGD-based AutoMaterialExclusion data
@ -71,7 +66,7 @@ class GameData
GameData();
~GameData();
BOOL Load(const char *pszFilename);
bool Load(const char *pszFilename);
GDclass *ClassForName(const char *pszName, int *piIndex = NULL);

View File

@ -17,10 +17,10 @@
#pragma once
#endif
#include "HelperInfo.h"
#include "TokenReader.h"
#include "GDVar.h"
#include "InputOutput.h"
#include "helperinfo.h"
#include "tokenreader.h"
#include "gdvar.h"
#include "inputoutput.h"
#include "mathlib/vector.h"
class CHelperInfo;

View File

@ -10,7 +10,7 @@
#pragma once
#include <utlvector.h>
#include <TokenReader.h> // dvs: for MAX_STRING. Fix.
#include "tokenreader.h" // dvs: for MAX_STRING. Fix.
class MDkeyvalue;

View File

@ -10,7 +10,7 @@
#include <utlvector.h>
#include "fgdlib/EntityDefs.h"
#include "fgdlib/entitydefs.h"
enum InputOutputType_t

View File

@ -112,8 +112,8 @@ class WCKVBase_Vector
public:
// Iteration helpers.
inline int GetCount() const { return m_KeyValues.Count(); }
inline int GetFirst() const { return m_KeyValues.Count() - 1; }
inline int GetCount() const { return this->m_KeyValues.Count(); }
inline int GetFirst() const { return this->m_KeyValues.Count() - 1; }
inline int GetNext( int i ) const { return i - 1; }
static inline int GetInvalidIndex() { return -1; }
@ -138,8 +138,8 @@ public:
// Iteration helpers. Note that there is no GetCount() because you can't iterate
// these by incrementing a counter.
inline int GetFirst() const { return m_KeyValues.First(); }
inline int GetNext( int i ) const { return m_KeyValues.Next( i ); }
inline int GetFirst() const { return this->m_KeyValues.First(); }
inline int GetNext( int i ) const { return this->m_KeyValues.Next( i ); }
static inline int GetInvalidIndex() { return CUtlDict<MDkeyvalue,unsigned short>::InvalidIndex(); }
int FindByKeyName( const char *pKeyName ) const; // Returns the same value as GetInvalidIndex if not found.
@ -188,7 +188,7 @@ typedef WCKeyValuesT<WCKVBase_Vector> WCKeyValuesVector;
template<class Base>
inline const char *WCKeyValuesT<Base>::GetKey(int nIndex) const
{
return(m_KeyValues.Element(nIndex).szKey);
return(this->m_KeyValues.Element(nIndex).szKey);
}
@ -200,7 +200,7 @@ inline const char *WCKeyValuesT<Base>::GetKey(int nIndex) const
template<class Base>
inline MDkeyvalue &WCKeyValuesT<Base>::GetKeyValue(int nIndex)
{
return(m_KeyValues.Element(nIndex));
return(this->m_KeyValues.Element(nIndex));
}
@ -212,7 +212,7 @@ inline MDkeyvalue &WCKeyValuesT<Base>::GetKeyValue(int nIndex)
template<class Base>
inline const MDkeyvalue& WCKeyValuesT<Base>::GetKeyValue(int nIndex) const
{
return(m_KeyValues.Element(nIndex));
return(this->m_KeyValues.Element(nIndex));
}
@ -223,7 +223,7 @@ inline const MDkeyvalue& WCKeyValuesT<Base>::GetKeyValue(int nIndex) const
template<class Base>
inline const char *WCKeyValuesT<Base>::GetValue(int nIndex) const
{
return(m_KeyValues.Element(nIndex).szValue);
return(this->m_KeyValues.Element(nIndex).szValue);
}

View File

@ -7,7 +7,7 @@
#include "KeyValues.h"
#include "tier1/strtools.h"
#include "FileSystem_Tools.h"
#include "filesystem_tools.h"
#include "tier1/utlstring.h"
// So we know whether or not we own argv's memory

View File

@ -520,7 +520,7 @@ PLATFORM_INTERFACE void ThreadNotifySyncReleasing(void *p);
#ifndef NO_THREAD_LOCAL
#if defined(WIN32) || defined(OSX) || defined( _PS3 ) || ( defined (_LINUX) ) || defined(PLATFORM_BSD)
#if defined(WIN32) || defined(POSIX) || defined( _PS3 )
#ifndef __AFXTLS_H__ // not compatible with some Windows headers
#if defined(_PS3)

View File

@ -7,7 +7,7 @@
// If we are going to include windows.h then we need to disable protected_things.h
// or else we get many warnings.
#undef PROTECTED_THINGS_ENABLE
#include <tier0/platform.h>
#include "tier0/platform.h"
#ifdef IS_WINDOWS_PC
#include <windows.h>
#else

53
raytrace/wscript Executable file
View File

@ -0,0 +1,53 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'raytrace'
def options(opt):
# stub
return
def configure(conf):
return
def build(bld):
source = [
'raytrace.cpp',
'trace2.cpp',
'trace3.cpp',
]
includes = [
'.',
'../public',
'../public/tier0',
'../public/tier1',
'../public/tier2',
'../public/tier3',
'../utils/common'
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'vstdlib', 'mathlib']
if bld.env.DEST_OS == 'win32':
libs += ['USER32']
bld.stlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

70
utils/bsppack/wscript Executable file
View File

@ -0,0 +1,70 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'bsppack'
def options(opt):
# stub
return
def configure(conf):
conf.define('BSPPACK_EXPORTS', 1)
conf.define('ZIP_SUPPORT_LZMA_ENCODE', 1)
return
def build(bld):
source = [
'bsppack.cpp',
'../common/bsplib.cpp',
'../common/cmdlib.cpp',
'../common/scriplib.cpp',
'../common/filesystem_tools.cpp',
'../../public/filesystem_helpers.cpp',
'../../public/filesystem_init.cpp',
'../../public/lumpfiles.cpp',
'../../public/zip_utils.cpp',
]
if bld.env.DEST_OS != 'win32':
source += ['../../filesystem/linux_support.cpp']
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
'../../public/tier3',
'../../public/mathlib'
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'tier3', 'mathlib', 'lzma', 'vstdlib']
if bld.env.DEST_OS == 'win32':
libs += ['ADVAPI32', 'WS2_32']
else:
libs += ['DL', 'M', 'LOG']
install_path = bld.env.LIBDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -61,8 +61,6 @@ CUtlLinkedList<SpewHookFn, unsigned short> g_ExtraSpewHooks;
bool g_bStopOnExit = false;
void (*g_ExtraSpewHook)(const char*) = NULL;
#if defined( _WIN32 ) || defined( WIN32 )
void CmdLib_FPrintf( FileHandle_t hFile, const char *pFormat, ... )
{
static CUtlVector<char> buf;
@ -128,10 +126,6 @@ char* CmdLib_FGets( char *pOut, int outSize, FileHandle_t hFile )
return pOut;
}
#if !defined( _X360 )
#include <wincon.h>
#endif
// This pauses before exiting if they use -StopOnExit. Useful for debugging.
class CExitStopper
{
@ -141,7 +135,7 @@ public:
if ( g_bStopOnExit )
{
Warning( "\nPress any key to quit.\n" );
getch();
getchar();
}
}
} g_ExitStopper;
@ -153,7 +147,7 @@ static unsigned short g_BadColor = 0xFFFF;
static WORD g_BackgroundFlags = 0xFFFF;
static void GetInitialColors( )
{
#if !defined( _X360 )
#if !defined( _X360 ) && defined( _WIN32 )
// Get the old background attributes.
CONSOLE_SCREEN_BUFFER_INFO oldInfo;
GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &oldInfo );
@ -175,7 +169,7 @@ static void GetInitialColors( )
WORD SetConsoleTextColor( int red, int green, int blue, int intensity )
{
WORD ret = g_LastColor;
#if !defined( _X360 )
#if !defined( _X360 ) && defined( _WIN32 )
g_LastColor = 0;
if( red ) g_LastColor |= FOREGROUND_RED;
@ -194,7 +188,7 @@ WORD SetConsoleTextColor( int red, int green, int blue, int intensity )
void RestoreConsoleTextColor( WORD color )
{
#if !defined( _X360 )
#if !defined( _X360 ) && defined( _WIN32 )
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), color | g_BackgroundFlags );
g_LastColor = color;
#endif
@ -216,6 +210,7 @@ void Error( char const *pMsg, ... )
#else
#ifdef _WIN32
CRITICAL_SECTION g_SpewCS;
bool g_bSpewCSInitted = false;
bool g_bSuppressPrintfOutput = false;
@ -326,14 +321,16 @@ SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg )
return retVal;
}
#endif
void InstallSpewFunction()
{
setvbuf( stdout, NULL, _IONBF, 0 );
setvbuf( stderr, NULL, _IONBF, 0 );
#ifdef _WIN32
SpewOutputFunc( CmdLib_SpewOutputFunc );
#endif
GetInitialColors();
}
@ -413,18 +410,13 @@ void CmdLib_Cleanup()
void CmdLib_Exit( int exitCode )
{
TerminateProcess( GetCurrentProcess(), 1 );
exit(exitCode);
}
#endif
#endif
/*
===================
ExpandWildcards

View File

@ -132,7 +132,9 @@ void CmdLib_Cleanup();
void CmdLib_Exit( int exitCode ); // Use this to cleanup and call exit().
// entrypoint if chaining spew functions
#ifdef _WIN32
SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg );
#endif
unsigned short SetConsoleTextColor( int red, int green, int blue, int intensity );
void RestoreConsoleTextColor( unsigned short color );
@ -175,4 +177,4 @@ typedef struct
} cblock_t;
#endif // CMDLIB_H
#endif // CMDLIB_H

View File

@ -11,7 +11,7 @@
#endif
#include "ChunkFile.h"
#include "chunkfile.h"
#include "bsplib.h"
#include "cmdlib.h"

View File

@ -867,7 +867,7 @@ public:
int iFirstUsed;
int iOrigIndex;
bool operator<(const SortEntry& rhs)
bool operator<(const SortEntry& rhs) const
{
return iFirstUsed < rhs.iFirstUsed;
}

View File

@ -1216,7 +1216,7 @@ int CScriptLib::GetFileList( const char* pDirPath, const char* pPattern, CUtlVec
FIND_DATA findData;
Q_FixSlashes( fullPath );
void *h = FindFirstFile( fullPath, &findData );
if ( (int)h == -1 )
if ( (int)(size_t)h == -1 )
{
return 0;
}

View File

@ -13,14 +13,21 @@
#define USED
#ifdef _WIN32
#include <windows.h>
#elif defined(POSIX)
#include <pthread.h>
#else
#error
#endif
#include "cmdlib.h"
#define NO_THREAD_NAMES
#include "threads.h"
#include "pacifier.h"
#define MAX_THREADS 16
#define MAX_THREADS 40
int numthreads = -1;
class CRunThreadsData
{
@ -40,8 +47,11 @@ qboolean pacifier;
qboolean threaded;
bool g_bLowPriorityThreads = false;
#ifdef _WIN32
HANDLE g_ThreadHandles[MAX_THREADS];
#elif defined(POSIX)
pthread_t g_ThreadHandles[MAX_THREADS];
#endif
/*
@ -97,7 +107,21 @@ void RunThreadsOnIndividual (int workcnt, qboolean showpacifier, ThreadWorkerFn
RunThreadsOn (workcnt, showpacifier, ThreadWorkerFunction);
}
void ThreadSetDefault (void)
{
const CPUInformation *ci;
if (numthreads == -1) // not set manually
{
ci = GetCPUInformation();
numthreads = ci->m_nLogicalProcessors;
if (numthreads < 1) numthreads = 1;
if (numthreads > MAX_THREADS) numthreads = MAX_THREADS;
}
Msg ("%i threads\n", numthreads);
}
#ifdef _WIN32
/*
===================================================================
@ -106,7 +130,6 @@ WIN32
===================================================================
*/
int numthreads = -1;
CRITICAL_SECTION crit;
static int enter;
@ -120,30 +143,12 @@ public:
}
} g_CritInit;
void SetLowPriority()
{
SetPriorityClass( GetCurrentProcess(), IDLE_PRIORITY_CLASS );
}
void ThreadSetDefault (void)
{
SYSTEM_INFO info;
if (numthreads == -1) // not set manually
{
GetSystemInfo (&info);
numthreads = info.dwNumberOfProcessors;
if (numthreads < 1 || numthreads > 32)
numthreads = 1;
}
Msg ("%i threads\n", numthreads);
}
void ThreadLock (void)
{
if (!threaded)
@ -173,7 +178,6 @@ DWORD WINAPI InternalRunThreadsFn( LPVOID pParameter )
return 0;
}
void RunThreads_Start( RunThreadsFn fn, void *pUserData, ERunThreadsPriority ePriority )
{
Assert( numthreads > 0 );
@ -218,7 +222,76 @@ void RunThreads_End()
threaded = false;
}
#elif defined(POSIX)
/*
===================================================================
POSIX
===================================================================
*/
pthread_mutex_t crit = PTHREAD_MUTEX_INITIALIZER;
static int enter;
void SetLowPriority()
{
}
void ThreadLock (void)
{
if (!threaded)
return;
pthread_mutex_lock (&crit);
if (enter)
Error ("Recursive ThreadLock\n");
enter = 1;
}
void ThreadUnlock (void)
{
if (!threaded)
return;
if (!enter)
Error ("ThreadUnlock without lock\n");
enter = 0;
pthread_mutex_unlock (&crit);
}
void *InternalRunThreadsFn( void *pParameter )
{
CRunThreadsData *pData = (CRunThreadsData*)pParameter;
pData->m_Fn( pData->m_iThread, pData->m_pUserData );
return NULL;
}
void RunThreads_Start( RunThreadsFn fn, void *pUserData, ERunThreadsPriority ePriority )
{
Assert( numthreads > 0 );
threaded = true;
if ( numthreads > MAX_TOOL_THREADS )
numthreads = MAX_TOOL_THREADS;
for ( int i=0; i < numthreads ;i++ )
{
g_RunThreadsData[i].m_iThread = i;
g_RunThreadsData[i].m_pUserData = pUserData;
g_RunThreadsData[i].m_Fn = fn;
pthread_create( &g_ThreadHandles[i], NULL, InternalRunThreadsFn, &g_RunThreadsData[i] );
}
}
void RunThreads_End()
{
for ( int i=0; i < numthreads; i++ )
pthread_join( g_ThreadHandles[i], NULL );
threaded = false;
}
#endif
/*
=============

View File

@ -12,26 +12,25 @@
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include <cmdlib.h>
#include "cmdlib.h"
#include "utilmatlib.h"
#include "tier0/dbg.h"
#include <windows.h>
#include "filesystem.h"
#include "materialsystem/materialsystem_config.h"
#include "mathlib/Mathlib.h"
#include "mathlib/mathlib.h"
void LoadMaterialSystemInterface( CreateInterfaceFn fileSystemFactory )
{
if( g_pMaterialSystem )
return;
// materialsystem.dll should be in the path, it's in bin along with vbsp.
const char *pDllName = "materialsystem.dll";
const char *pDllName = "materialsystem" DLL_EXT_STRING;
CSysModule *materialSystemDLLHInst;
materialSystemDLLHInst = g_pFullFileSystem->LoadModule( pDllName );
if( !materialSystemDLLHInst )
{
Error( "Can't load MaterialSystem.dll\n" );
Error( "Can't load MaterialSystem\n" );
}
CreateInterfaceFn clientFactory = Sys_GetFactory( materialSystemDLLHInst );
@ -40,17 +39,17 @@ void LoadMaterialSystemInterface( CreateInterfaceFn fileSystemFactory )
g_pMaterialSystem = (IMaterialSystem *)clientFactory( MATERIAL_SYSTEM_INTERFACE_VERSION, NULL );
if ( !g_pMaterialSystem )
{
Error( "Could not get the material system interface from materialsystem.dll (" __FILE__ ")" );
Error( "Could not get the material system interface from materialsystem library (" __FILE__ ")" );
}
}
else
{
Error( "Could not find factory interface in library MaterialSystem.dll" );
Error( "Could not find factory interface in library MaterialSystem!" );
}
if (!g_pMaterialSystem->Init( "shaderapiempty.dll", 0, fileSystemFactory ))
if (!g_pMaterialSystem->Init( "shaderapiempty" DLL_EXT_STRING, 0, fileSystemFactory ))
{
Error( "Could not start the empty shader (shaderapiempty.dll)!" );
Error( "Could not start the empty shader (shaderapiempty)!" );
}
}

56
utils/lzma/wscript Executable file
View File

@ -0,0 +1,56 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'lzma'
def options(opt):
# stub
return
def configure(conf):
conf.define('_NO_EXCEPTIONS', 1)
conf.define('_LZMA_PROB32', 1)
conf.define('_7ZIP_ST', 1)
return
def build(bld):
source = [
'lzma.cpp',
'C/LzmaEnc.c',
'C/LzmaDec.c',
'C/LzFind.c',
]
includes = [
'.',
'./C',
'../common',
'../../public',
]
defines = []
libs = []
if bld.env.DEST_OS == 'win32':
libs += ['ADVAPI32', 'WS2_32']
else:
libs += ['DL', 'M', 'LOG']
bld.stlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -6,7 +6,7 @@
//=============================================================================//
#include "vbsp.h"
#include "BoundBox.h"
#include "boundbox.h"
//#include "hammer_mathlib.h"
//#include "MapDefs.h"

View File

@ -337,7 +337,7 @@ bspbrush_t *AllocBrush (int numsides)
bspbrush_t *bb;
int c;
c = (int)&(((bspbrush_t *)0)->sides[numsides]);
c = (int)(size_t)&(((bspbrush_t *)0)->sides[numsides]);
bb = (bspbrush_t*)malloc(c);
memset (bb, 0, c);
bb->id = s_BrushId++;
@ -394,7 +394,7 @@ bspbrush_t *CopyBrush (bspbrush_t *brush)
int size;
int i;
size = (int)&(((bspbrush_t *)0)->sides[brush->numsides]);
size = (int)(size_t)&(((bspbrush_t *)0)->sides[brush->numsides]);
newbrush = AllocBrush (brush->numsides);
memcpy (newbrush, brush, size);

View File

@ -7,7 +7,7 @@
#include "vbsp.h"
#include "bsplib.h"
#include "tier1/UtlBuffer.h"
#include "tier1/utlbuffer.h"
#include "tier1/utlvector.h"
#include "bitmap/imageformat.h"
#include <KeyValues.h>

View File

@ -6,26 +6,23 @@
// $NoKeywords: $
//=============================================================================//
#include <windows.h>
#include "vbsp.h"
#include "bsplib.h"
#include "KeyValues.h"
#include "utlsymbol.h"
#include "utlvector.h"
#include <io.h>
#include "bspfile.h"
#include "utilmatlib.h"
#include "gamebspfile.h"
#include "mathlib/VMatrix.h"
#include "mathlib/vmatrix.h"
#include "materialpatch.h"
#include "pacifier.h"
#include "vstdlib/random.h"
#include "builddisp.h"
#include "disp_vbsp.h"
#include "UtlBuffer.h"
#include "CollisionUtils.h"
#include <float.h>
#include "UtlLinkedList.h"
#include "utlbuffer.h"
#include "collisionutils.h"
#include "utllinkedlist.h"
#include "byteswap.h"
#include "writebsp.h"

View File

@ -13,7 +13,7 @@
#include "mstristrip.h"
#include "writebsp.h"
#include "pacifier.h"
#include "disp_ivp.h"
#include "disp_vbsp.h"
#include "builddisp.h"
#include "mathlib/vector.h"

View File

@ -11,13 +11,37 @@
#pragma once
#endif
#include "vbsp.h"
#include "utlvector.h"
#include "disp_tesselate.h"
class CPhysCollisionEntry;
class CCoreDispInfo;
struct dmodel_t;
// This provides the template functions that the engine's tesselation code needs
// so we can share the code in VBSP.
class CVBSPTesselateHelper : public CBaseTesselateHelper
{
public:
void EndTriangle()
{
m_pIndices->AddToTail( m_TempIndices[0] );
m_pIndices->AddToTail( m_TempIndices[1] );
m_pIndices->AddToTail( m_TempIndices[2] );
}
DispNodeInfo_t& GetNodeInfo( int iNodeBit )
{
// VBSP doesn't care about these. Give it back something to play with.
static DispNodeInfo_t dummy;
return dummy;
}
public:
CUtlVector<unsigned short> *m_pIndices;
};
extern CUtlVector<CCoreDispInfo*> g_CoreDispInfos;

View File

@ -7,7 +7,7 @@
//=============================================================================//
#include "vbsp.h"
#include "color.h"
#include "Color.h"
/*
==============================================================================
@ -165,4 +165,4 @@ void AreaportalLeakFile( tree_t *tree, portal_t *pStartPortal, portal_t *pEndPor
Warning( "Wrote %s\n", filename );
Color red(255,0,0,255);
ColorSpewMessage( SPEW_MESSAGE, &red, "Areaportal leak ! File: %s ", filename );
}
}

View File

@ -3,7 +3,9 @@
#include "map_shared.h"
#include "fgdlib/fgdlib.h"
#include "manifest.h"
#ifdef _WIN32
#include "windows.h"
#endif
//-----------------------------------------------------------------------------
// Purpose: default constructor
@ -358,6 +360,7 @@ bool CManifest::LoadVMFManifestUserPrefs( const char *pszFileName )
char UserName[ MAX_PATH ], FileName[ MAX_PATH ], UserPrefsFileName[ MAX_PATH ];
DWORD UserNameSize;
#ifdef _WIN32
UserNameSize = sizeof( UserName );
if ( GetUserName( UserName, &UserNameSize ) == 0 )
{
@ -365,6 +368,10 @@ bool CManifest::LoadVMFManifestUserPrefs( const char *pszFileName )
}
sprintf( UserPrefsFileName, "\\%s.vmm_prefs", UserName );
#else
// TODO: Er2: Detect user
Q_strcpy(UserPrefsFileName, "default.vmm_prefs");
#endif
V_StripExtension( pszFileName, FileName, sizeof( FileName ) );
strcat( FileName, UserPrefsFileName );

View File

@ -1271,7 +1271,7 @@ void ConvertSideList( entity_t *mapent, char *key )
}
char szIndex[15];
itoa( nIndex, szIndex, 10 );
Q_snprintf( szIndex, sizeof(szIndex), "%d", szNewValue );
strcat( szNewValue, szIndex );
}
}

View File

@ -6,7 +6,7 @@
//
//=============================================================================//
#include "vbsp.h"
#include "UtlBuffer.h"
#include "utlbuffer.h"
#include "utlsymbol.h"
#include "utlrbtree.h"
#include "KeyValues.h"

View File

@ -11,14 +11,13 @@
#include "utlvector.h"
#include "bspfile.h"
#include "gamebspfile.h"
#include "VPhysics_Interface.h"
#include "Studio.h"
#include "vphysics_interface.h"
#include "studio.h"
#include "byteswap.h"
#include "UtlBuffer.h"
#include "CollisionUtils.h"
#include <float.h>
#include "CModel.h"
#include "PhysDll.h"
#include "utlbuffer.h"
#include "collisionutils.h"
#include "cmodel.h"
#include "physdll.h"
#include "utlsymbol.h"
#include "tier1/strtools.h"
#include "KeyValues.h"
@ -183,8 +182,8 @@ bool LoadStudioModel( char const* pModelName, char const* pEntityType, CUtlBuffe
}
// ensure reset
pHdr->pVertexBase = NULL;
pHdr->pIndexBase = NULL;
pHdr->SetVertexBase(NULL);
pHdr->SetIndexBase(NULL);
return true;
}
@ -247,7 +246,7 @@ static CPhysCollide* GetCollisionModel( char const* pModelName )
// Convert to a common string
char* pTemp = (char*)_alloca(strlen(pModelName) + 1);
strcpy( pTemp, pModelName );
_strlwr( pTemp );
strlwr( pTemp );
char* pSlash = strchr( pTemp, '\\' );
while( pSlash )
@ -296,7 +295,9 @@ static CPhysCollide* GetCollisionModel( char const* pModelName )
static int propNum = 0;
char tmp[128];
sprintf( tmp, "staticprop%03d.txt", propNum );
#ifdef _WIN32
DumpCollideToGlView( lookup.m_pCollide, tmp );
#endif
++propNum;
}
@ -692,10 +693,10 @@ static void FreeCurrentModelVertexes()
{
Assert( g_pActiveStudioHdr );
if ( g_pActiveStudioHdr->pVertexBase )
if ( g_pActiveStudioHdr->VertexBase() )
{
free( g_pActiveStudioHdr->pVertexBase );
g_pActiveStudioHdr->pVertexBase = NULL;
free( g_pActiveStudioHdr->VertexBase() );
g_pActiveStudioHdr->SetVertexBase(NULL);
}
}
@ -708,9 +709,9 @@ const vertexFileHeader_t * mstudiomodel_t::CacheVertexData( void * pModelData )
Assert( pModelData == NULL );
Assert( g_pActiveStudioHdr );
if ( g_pActiveStudioHdr->pVertexBase )
if ( g_pActiveStudioHdr->VertexBase() )
{
return (vertexFileHeader_t *)g_pActiveStudioHdr->pVertexBase;
return (vertexFileHeader_t *)g_pActiveStudioHdr->VertexBase();
}
// mandatory callback to make requested data resident
@ -753,7 +754,7 @@ const vertexFileHeader_t * mstudiomodel_t::CacheVertexData( void * pModelData )
Error("Error Vertex File %s checksum %d should be %d\n", fileName, pVvdHdr->checksum, g_pActiveStudioHdr->checksum);
}
g_pActiveStudioHdr->pVertexBase = (void*)pVvdHdr;
g_pActiveStudioHdr->SetVertexBase((void*)pVvdHdr);
return pVvdHdr;
}

View File

@ -10,7 +10,6 @@
#include "utilmatlib.h"
#include "physdll.h"
#include <assert.h>
#include <malloc.h>
#include "tier1/strtools.h"
#include "materialpatch.h"
#include "KeyValues.h"

View File

@ -14,7 +14,9 @@
#include "tier0/icommandline.h"
#include "materialsystem/imaterialsystem.h"
#include "map.h"
#ifdef _WIN32
#include "tools_minidump.h"
#endif
#include "materialsub.h"
#include "loadcmdline.h"
#include "byteswap.h"
@ -46,7 +48,9 @@ qboolean noopt;
qboolean leaktest;
qboolean verboseentities;
qboolean dumpcollide = false;
#ifdef _WIN32
qboolean g_bLowPriority = false;
#endif
qboolean g_DumpStaticProps = false;
qboolean g_bSkyVis = false; // skybox vis is off by default, toggle this to enable it
bool g_bLightIfMissing = false;
@ -1088,10 +1092,12 @@ int RunVBSP( int argc, char **argv )
{
g_BumpAll = true;
}
#ifdef _WIN32
else if( !Q_stricmp( argv[i], "-low" ) )
{
g_bLowPriority = true;
}
#endif
else if( !Q_stricmp( argv[i], "-lightifmissing" ) )
{
g_bLightIfMissing = true;
@ -1133,10 +1139,12 @@ int RunVBSP( int argc, char **argv )
{
g_NodrawTriggers = true;
}
#ifdef _WIN32
else if ( !Q_stricmp( argv[i], "-FullMinidumps" ) )
{
EnableFullMinidumps( true );
}
#endif
else if ( !Q_stricmp( argv[i], "-embed" ) && i < argc - 1 )
{
V_MakeAbsolutePath( g_szEmbedDir, sizeof( g_szEmbedDir ), argv[++i], "." );
@ -1182,7 +1190,9 @@ int RunVBSP( int argc, char **argv )
" -nodetail : Get rid of all detail geometry. The geometry left over is\n"
" what affects visibility.\n"
" -nowater : Get rid of water brushes.\n"
#ifdef _WIN32
" -low : Run as an idle-priority process.\n"
#endif
" -embed <directory> : Use <directory> as an additional search path for assets\n"
" and embed all assets in this directory into the compiled\n"
" map\n"
@ -1235,7 +1245,9 @@ int RunVBSP( int argc, char **argv )
" -x360 : Generate Xbox360 version of vsp\n"
" -nox360 : Disable generation Xbox360 version of vsp (default)\n"
" -replacematerials : Substitute materials according to materialsub.txt in content\\maps\n"
#ifdef _WIN32
" -FullMinidumps : Write large minidumps on crash.\n"
#endif
);
}
@ -1257,11 +1269,13 @@ int RunVBSP( int argc, char **argv )
start = Plat_FloatTime();
#ifdef _WIN32
// Run in the background?
if( g_bLowPriority )
{
SetLowPriority();
}
#endif
if( ( g_nDXLevel != 0 ) && ( g_nDXLevel < 80 ) )
{
@ -1332,7 +1346,7 @@ int RunVBSP( int argc, char **argv )
g_nCubemapSamples = 0;
// Mark as stale since the lighting could be screwed with new ents.
AddBufferToPak( GetPakFile(), "stale.txt", "stale", strlen( "stale" ) + 1, false );
AddBufferToPak( GetPakFile(), "stale.txt", (void *)"stale", strlen( "stale" ) + 1, false );
LoadMapFile (name);
SetModelNumbers ();
@ -1389,7 +1403,7 @@ int RunVBSP( int argc, char **argv )
{
LoadBSPFile_FileSystemOnly (mapFile);
// Mark as stale since the lighting could be screwed with new ents.
AddBufferToPak( GetPakFile(), "stale.txt", "stale", strlen( "stale" ) + 1, false );
AddBufferToPak( GetPakFile(), "stale.txt", (void *)"stale", strlen( "stale" ) + 1, false );
}
LoadMapFile (name);
@ -1435,8 +1449,10 @@ main
*/
int main (int argc, char **argv)
{
#ifdef _WIN32
// Install an exception handler.
SetupDefaultToolsMinidumpHandler();
#endif
return RunVBSP( argc, argv );
}

View File

@ -18,7 +18,7 @@
#include "bsplib.h"
#include "qfiles.h"
#include "utilmatlib.h"
#include "ChunkFile.h"
#include "chunkfile.h"
#ifdef WIN32
#pragma warning( disable: 4706 )

View File

@ -6,7 +6,7 @@
#include "bsplib.h"
#include "vbsp.h"
#include "tier1/UtlBuffer.h"
#include "tier1/utlbuffer.h"
#include "tier1/utlvector.h"
#include "KeyValues.h"
#include "materialpatch.h"
@ -209,4 +209,4 @@ void WorldVertexTransitionFixup( void )
pSide->texinfo = CreateBrushVersionOfWorldVertexTransitionMaterial( pSide->texinfo );
}
}
}

View File

@ -931,7 +931,7 @@ void WriteBSP (node_t *headnode, face_t *pLeafFaceList )
}
}
EmitWaterVolumesForBSP( &dmodels[nummodels], headnode );
// EmitWaterVolumesForBSP( &dmodels[nummodels], headnode );
qprintf ("%5i nodes with faces\n", c_facenodes);
qprintf ("%5i nodes without faces\n", c_nofaces);
qprintf ("%5i faces\n", numfaces-oldfaces);
@ -1257,7 +1257,7 @@ void EndBSPFile (void)
OverlayTransition_EmitOverlayFaces();
// phys collision needs dispinfo to operate (needs to generate phys collision for displacement surfs)
EmitPhysCollision();
// EmitPhysCollision();
// We can't calculate this properly until vvis (since we need vis to do this), so we set
// to zero everywhere by default.

122
utils/vbsp/wscript Executable file
View File

@ -0,0 +1,122 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vbsp'
def options(opt):
# stub
return
def configure(conf):
return
def build(bld):
source = [
'boundbox.cpp',
'brushbsp.cpp',
'csg.cpp',
'cubemap.cpp',
'detail.cpp',
'detailobjects.cpp',
'disp_vbsp.cpp',
'faces.cpp',
'glfile.cpp',
'leakfile.cpp',
'map.cpp',
'manifest.cpp',
'materialpatch.cpp',
'materialsub.cpp',
'nodraw.cpp',
'normals.cpp',
'overlay.cpp',
'portals.cpp',
'prtfile.cpp',
'staticprop.cpp',
'textures.cpp',
'tree.cpp',
'vbsp.cpp',
'worldvertextransitionfixup.cpp',
'writebsp.cpp',
'../common/mstristrip.cpp',
'../common/physdll.cpp',
# '../common/scratchpad_helpers.cpp',
'../common/utilmatlib.cpp',
'../../public/collisionutils.cpp',
'../../public/disp_common.cpp',
'../../public/disp_powerinfo.cpp',
'../../public/loadcmdline.cpp',
'../../public/lumpfiles.cpp',
# '../../public/scratchpad3d.cpp',
'../../public/zip_utils.cpp',
# Common files
'../common/bsplib.cpp',
'../common/cmdlib.cpp',
'../common/filesystem_tools.cpp',
'../common/map_shared.cpp',
'../common/pacifier.cpp',
'../common/polylib.cpp',
'../common/scriplib.cpp',
'../common/threads.cpp',
'../../public/builddisp.cpp',
'../../public/chunkfile.cpp',
'../../public/filesystem_helpers.cpp',
'../../public/filesystem_init.cpp',
]
if bld.env.DEST_OS == 'win32':
source += ['../common/tools_minidump.cpp']
else:
source += ['../../filesystem/linux_support.cpp']
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
'../../public/tier3',
'../../public/vtf',
'../../public/vstdlib',
'../../public/fgdlib',
]
defines = []
libs = [
'tier0', 'tier1', 'tier2',
'vtf',
'bitmap',
'fgdlib',
'mathlib',
'vstdlib',
'lzma',
'vphysics',
'shaderapiempty',
'materialsystem',
]
if bld.env.DEST_OS == 'win32':
libs += ['USER32']
install_path = bld.env.BINDIR
bld(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx cxxprogram',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -9,17 +9,23 @@
#include "mathlib/mathlib.h"
#include "bsplib.h"
#include "tier0/icommandline.h"
#ifdef ENABLE_SCRATCHPAD
#include "iscratchpad3d.h"
#endif
#include "filesystem_tools.h"
#include "tier2/fileutils.h"
#include "gamebspfile.h"
#include "tier1/utlstringmap.h"
#include "tier1/UtlStringMap.h"
#ifdef _WIN32
#include "tools_minidump.h"
#endif
#include "cmdlib.h"
bool g_bTreeInfo = false;
#ifdef ENABLE_SCRATCHPAD
bool g_bDrawTree = false;
#endif
float g_nOptimumDepth;
int g_nMinTreeDepth;
@ -48,7 +54,7 @@ void CalculateTreeInfo_R( int iNode, int depth )
}
}
#ifdef ENABLE_SCRATCHPAD
void DrawTreeToScratchPad_R(
IScratchPad3D *pPad,
int iNode, // Which node we're drawing.
@ -98,7 +104,7 @@ void DrawTreeToScratchPad_R(
&vMyPos );
}
}
#endif
void CalcTreeDepth_R( int iNode, int iLevel, int &iMaxDepth )
{
@ -110,7 +116,7 @@ void CalcTreeDepth_R( int iNode, int iLevel, int &iMaxDepth )
CalcTreeDepth_R( dnodes[iNode].children[1], iLevel+1, iMaxDepth );
}
#ifdef ENABLE_SCRATCHPAD
void DrawTreeToScratchPad()
{
IScratchPad3D *pPad = ScratchPad3D_Create();
@ -131,6 +137,7 @@ void DrawTreeToScratchPad()
pPad->Release();
}
#endif
struct WorldTextureStats_t
{
@ -319,10 +326,12 @@ void PrintCommandLine( int argc, char **argv )
Warning( "\n\n" );
}
void main (int argc, char **argv)
int main( int argc, char **argv )
{
#ifdef _WIN32
// Install an exception handler.
SetupDefaultToolsMinidumpHandler();
#endif
int i;
char source[1024];
@ -347,15 +356,17 @@ void main (int argc, char **argv)
printf("usage: vbspinfo [parameters] bspfile [bspfiles]\n");
printf(" -treeinfo \n");
// printf(" -drawtree \n"); Remove for now until the option can be fixed
#ifdef ENABLE_SCRATCHPAD
printf(" -drawtree \n");
#endif
printf(" -worldtexturestats \n");
printf(" -modelstats \n");
printf(" -liststaticprops \n");
printf(" -X[lump ID] Extract BSP lump to file. i.e -X0 extracts entity lump.\n");
printf(" -size Show .bsp worldmodel bounds\n");
Error("Incorrect syntax.");
printf(" -size Show .bsp worldmodel bounds\n");
Error("Incorrect syntax.\n");
}
bool bWorldTextureStats = false;
bool bModelStats = false;
bool bListStaticProps = false;
@ -368,11 +379,13 @@ void main (int argc, char **argv)
g_bTreeInfo = true;
continue;
}
#ifdef ENABLE_SCRATCHPAD
else if ( stricmp( argv[i], "-drawtree" ) == 0 )
{
g_bDrawTree = true;
continue;
}
#endif
else if( stricmp( argv[i], "-worldtexturestats" ) == 0 )
{
bWorldTextureStats = true;
@ -415,7 +428,7 @@ void main (int argc, char **argv)
}
strcpy (source, argv[i]);
Q_DefaultExtension (source, ".bsp", sizeof( source ) );
strcpy( source, ExpandPath( source ) );
f = fopen (source, "rb");
if (f)
@ -430,8 +443,8 @@ void main (int argc, char **argv)
if( !bWorldTextureStats && !bModelStats && !bListStaticProps )
{
Msg ("reading %s (%d)\n", source, size);
}
}
// If we're extracting, do that and quit.
if ( bHaveAnyToExtract )
@ -440,7 +453,11 @@ void main (int argc, char **argv)
// If the filename doesn't have a path, prepend with the current directory
char fullbspname[MAX_PATH];
#ifdef _WIN32
_fullpath( fullbspname, source, sizeof( fullbspname ) );
#else
realpath( source, fullbspname );
#endif
for ( int extract = 0; extract < HEADER_LUMPS; extract++ )
{
@ -454,12 +471,12 @@ void main (int argc, char **argv)
CloseBSPFile();
printf ("Finished extraction.\n" );
return;
return 0;
}
LoadBSPFile (source);
LoadBSPFile (source);
if( bWorldTextureStats )
{
@ -519,8 +536,6 @@ void main (int argc, char **argv)
PrintBSPFileSizes ();
}
if ( g_bTreeInfo )
{
g_nOptimumDepth = (int)( log( ( float )numnodes ) / log( 2.0f ) );
@ -547,15 +562,19 @@ void main (int argc, char **argv)
(float)g_TotalTreeDepth / numnodes,
(float)g_TotalVariance / numnodes );
}
#ifdef ENABLE_SCRATCHPAD
if ( g_bDrawTree )
{
DrawTreeToScratchPad();
}
#endif
if( !bWorldTextureStats && !bModelStats && !bListStaticProps )
{
printf ("---------------------\n");
}
}
return 0;
}

71
utils/vbspinfo/wscript Executable file
View File

@ -0,0 +1,71 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vbspinfo'
def options(opt):
# stub
return
def configure(conf):
conf.define('DONT_PROTECT_FILEIO_FUNCTIONS', 1)
return
def build(bld):
source = [
'vbspinfo.cpp',
'../common/bsplib.cpp',
'../common/cmdlib.cpp',
'../common/scriplib.cpp',
'../common/filesystem_tools.cpp',
'../../public/filesystem_helpers.cpp',
'../../public/filesystem_init.cpp',
'../../public/lumpfiles.cpp',
'../../public/zip_utils.cpp',
]
if bld.env.DEST_OS == 'win32':
source += ['../common/tools_minidump.cpp']
else:
source += ['../../filesystem/linux_support.cpp']
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
'../../public/tier3',
'../../public/mathlib'
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'mathlib', 'lzma', 'vstdlib']
if bld.env.DEST_OS == 'win32':
libs += ['ADVAPI32', 'WS2_32']
else:
libs += ['DL', 'M', 'LOG']
install_path = bld.env.BINDIR
bld(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx cxxprogram',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -1922,7 +1922,7 @@ int main(int argc, char **argv)
{
switch( argv[nCurArg][1] )
{
case '?': // args
case 'h': // args
{
PrintArgSummaryAndExit( 0 ); // return success in this case.
}
@ -2012,7 +2012,7 @@ int main(int argc, char **argv)
if ( argc < 2 )
{
Error( "No command specified. Try 'vpk -?' for info.\n" );
Error( "No command specified. Try 'vpk -h' for info.\n" );
}
const char *pszCommand = argv[1];
@ -2144,6 +2144,7 @@ int main(int argc, char **argv)
//BenchMark( files );
//printf( " time pack = %f\n", Plat_FloatTime() - stime );
}
#ifdef VPK_ENABLE_SIGNING
else if ( V_strcmp( pszCommand, "rehash" ) == 0 )
{
if ( argc != 3 )
@ -2168,7 +2169,6 @@ int main(int argc, char **argv)
CheckHashes( argv[2] );
}
#ifdef VPK_ENABLE_SIGNING
else if ( V_strcmp( pszCommand, "generate_keypair" ) == 0 )
{
if ( argc != 3 )
@ -2210,7 +2210,7 @@ int main(int argc, char **argv)
}
else
{
Error( "Unknown command '%s'. Try 'vpk -?' for info.\n", pszCommand );
Error( "Unknown command '%s'. Try 'vpk -h' for info.\n", pszCommand );
}
return 0;

61
utils/vpk/wscript Executable file
View File

@ -0,0 +1,61 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vpk'
def options(opt):
# stub
return
def configure(conf):
return
def build(bld):
source = [
'packtest.cpp',
'../../public/filesystem_init.cpp',
'../../filesystem/linux_support.cpp',
]
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
]
defines = []
libs = [
'tier0', 'tier1', 'tier2', 'tier3',
'vstdlib',
'mathlib',
'vpklib',
'bitmap',
]
if bld.env.DEST_OS == 'win32':
libs += ['USER32']
install_path = bld.env.BINDIR
bld(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx cxxprogram',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -8,13 +8,10 @@
#include "disp_vrad.h"
#include "utllinkedlist.h"
#include "utlvector.h"
#if defined( USE_SCRATCHPAD )
#include "iscratchpad3d.h"
#include "scratchpadutils.h"
//#define USE_SCRATCHPAD
#if defined( USE_SCRATCHPAD )
static IScratchPad3D *g_pPad = 0;
static IScratchPad3D *g_pPad = 0;
#endif

View File

@ -310,10 +310,13 @@ void CIncremental::AddLightToFace(
else
{
bool bNew;
#ifdef _WIN32
EnterCriticalSection( &pLight->m_CS );
#endif
pFace = pLight->FindOrCreateLightFace( iFace, lmSize, &bNew );
#ifdef _WIN32
LeaveCriticalSection( &pLight->m_CS );
#endif
pLight->m_pCachedFaces[iThread] = pFace;
@ -460,10 +463,14 @@ void CIncremental::FinishFace(
if( pFace->m_CompressedData.TellPut() == 0 )
{
// No contribution.. delete this face from the light.
#ifdef _WIN32
EnterCriticalSection( &pLight->m_CS );
#endif
pLight->m_LightFaces.Remove( pFace->m_LightFacesIndex );
delete pFace;
#ifdef _WIN32
LeaveCriticalSection( &pLight->m_CS );
#endif
}
else
{
@ -574,7 +581,7 @@ void CIncremental::AddLightsForActiveLights()
// Copy the light information.
pLight->m_Light = dl->light;
pLight->m_flMaxIntensity = max( dl->light.intensity[0], max( dl->light.intensity[1], dl->light.intensity[2] ) );
pLight->m_flMaxIntensity = MAX( dl->light.intensity[0], MAX( dl->light.intensity[1], dl->light.intensity[2] ) );
}
}
@ -609,8 +616,8 @@ bool CIncremental::LoadIncrementalFile()
FileRead( fp, pLight->m_Light );
pLight->m_flMaxIntensity =
max( pLight->m_Light.intensity.x,
max( pLight->m_Light.intensity.y, pLight->m_Light.intensity.z ) );
MAX( pLight->m_Light.intensity.x,
MAX( pLight->m_Light.intensity.y, pLight->m_Light.intensity.z ) );
int nFaces;
FileRead( fp, nFaces );
@ -719,14 +726,18 @@ void CIncremental::LinkLightsToFaces( CUtlVector<CFaceLightList> &faceLights )
CIncLight::CIncLight()
{
memset( m_pCachedFaces, 0, sizeof(m_pCachedFaces) );
#ifdef _WIN32
InitializeCriticalSection( &m_CS );
#endif
}
CIncLight::~CIncLight()
{
m_LightFaces.PurgeAndDeleteElements();
#ifdef _WIN32
DeleteCriticalSection( &m_CS );
#endif
}

View File

@ -58,8 +58,9 @@ public:
public:
#ifdef _WIN32
CRITICAL_SECTION m_CS;
#endif
// This is the light for which m_LightFaces was built.
dworldlight_t m_Light;

View File

@ -13,9 +13,11 @@
#include "coordsize.h"
#include "vstdlib/random.h"
#include "bsptreedata.h"
#ifdef MPI
#include "messbuf.h"
#include "vmpi.h"
#include "vmpi_distribute_work.h"
#endif
static TableVector g_BoxDirections[6] =
{
@ -191,8 +193,8 @@ bool IsLeafAmbientSurfaceLight( dworldlight_t *wl )
if ( wl->style != 0 )
return false;
float intensity = max( wl->intensity[0], wl->intensity[1] );
intensity = max( intensity, wl->intensity[2] );
float intensity = MAX( wl->intensity[0], wl->intensity[1] );
intensity = MAX( intensity, wl->intensity[2] );
return (intensity * g_flWorldLightMinEmitSurfaceDistanceRatio) < g_flWorldLightMinEmitSurface;
}
@ -584,6 +586,7 @@ static void ThreadComputeLeafAmbient( int iThread, void *pUserData )
}
}
#ifdef MPI
void VMPI_ProcessLeafAmbient( int iThread, uint64 iLeaf, MessageBuffer *pBuf )
{
CUtlVector<ambientsample_t> list;
@ -615,7 +618,7 @@ void VMPI_ReceiveLeafAmbientResults( uint64 leafID, MessageBuffer *pBuf, int iWo
pBuf->read(g_LeafAmbientSamples[leafID].Base(), nSamples * sizeof(ambientsample_t) );
}
}
#endif
void ComputePerLeafAmbientLighting()
{
@ -642,6 +645,7 @@ void ComputePerLeafAmbientLighting()
g_LeafAmbientSamples.SetCount(numleafs);
#ifdef MPI
if ( g_bUseMPI )
{
// Distribute the work among the workers.
@ -649,6 +653,7 @@ void ComputePerLeafAmbientLighting()
DistributeWork( numleafs, VMPI_DISTRIBUTEWORK_PACKETID, VMPI_ProcessLeafAmbient, VMPI_ReceiveLeafAmbientResults );
}
else
#endif
{
RunThreadsOn(numleafs, true, ThreadComputeLeafAmbient);
}

View File

@ -11,7 +11,9 @@
#include "radial.h"
#include "mathlib/bumpvects.h"
#include "tier1/utlvector.h"
#ifdef MPI
#include "vmpi.h"
#endif
#include "mathlib/anorms.h"
#include "map_utils.h"
#include "mathlib/halton.h"
@ -90,8 +92,8 @@ int CNormalList::FindOrAddNormal( Vector const &vNormal )
for( int iDim=0; iDim < 3; iDim++ )
{
gi[iDim] = (int)( ((vNormal[iDim] + 1.0f) * 0.5f) * NUM_SUBDIVS - 0.000001f );
gi[iDim] = min( gi[iDim], NUM_SUBDIVS );
gi[iDim] = max( gi[iDim], 0 );
gi[iDim] = MIN( gi[iDim], NUM_SUBDIVS );
gi[iDim] = MAX( gi[iDim], 0 );
}
// Look for a matching vector in there.
@ -1327,8 +1329,8 @@ bool CanLeafTraceToSky( int iLeaf )
for ( int j = 0; j < NUMVERTEXNORMALS; j+=4 )
{
// search back to see if we can hit a sky brush
delta.LoadAndSwizzle( g_anorms[j], g_anorms[min( j+1, NUMVERTEXNORMALS-1 )],
g_anorms[min( j+2, NUMVERTEXNORMALS-1 )], g_anorms[min( j+3, NUMVERTEXNORMALS-1 )] );
delta.LoadAndSwizzle( g_anorms[j], g_anorms[MIN( j+1, NUMVERTEXNORMALS-1 )],
g_anorms[MIN( j+2, NUMVERTEXNORMALS-1 )], g_anorms[MIN( j+3, NUMVERTEXNORMALS-1 )] );
delta *= -MAX_TRACE_LENGTH;
delta += center4;
@ -2534,7 +2536,11 @@ static void GatherSampleLightAt4Points( SSE_SampleInfo_t& info, int sampleIdx, i
if (info.m_WarnFace != info.m_FaceNum)
{
Warning ("\nWARNING: Too many light styles on a face at (%f, %f, %f)\n",
#ifdef VRAD_SSE
info.m_Points.x.m128_f32[0], info.m_Points.y.m128_f32[0], info.m_Points.z.m128_f32[0] );
#else
info.m_Points.x[0], info.m_Points.y[0], info.m_Points.z[0] );
#endif
info.m_WarnFace = info.m_FaceNum;
}
continue;
@ -3119,7 +3125,7 @@ void BuildFacelights (int iThread, int facenum)
int nSample = 4 * grp;
sample_t *sample = sampleInfo.m_pFaceLight->sample + nSample;
int numSamples = min ( 4, sampleInfo.m_pFaceLight->numsamples - nSample );
int numSamples = MIN ( 4, sampleInfo.m_pFaceLight->numsamples - nSample );
FourVectors positions;
FourVectors normals;
@ -3174,7 +3180,9 @@ void BuildFacelights (int iThread, int facenum)
}
}
#ifdef MPI
if (!g_bUseMPI)
#endif
{
//
// This is done on the master node when MPI is used

View File

@ -10,8 +10,8 @@
#include "lightmap.h"
#include "radial.h"
#include "mathlib/bumpvects.h"
#include "utlrbtree.h"
#include "mathlib/VMatrix.h"
#include "tier1/utlrbtree.h"
#include "mathlib/vmatrix.h"
#include "macro_texture.h"
@ -89,19 +89,19 @@ void AddDirectToRadial( radial_t *rad,
s_max = ( int )( coordmaxs[0] + 0.9999f ) + 1; // ????
t_max = ( int )( coordmaxs[1] + 0.9999f ) + 1;
s_min = max( s_min, 0 );
t_min = max( t_min, 0 );
s_max = min( s_max, rad->w );
t_max = min( t_max, rad->h );
s_min = MAX( s_min, 0 );
t_min = MAX( t_min, 0 );
s_max = MIN( s_max, rad->w );
t_max = MIN( t_max, rad->h );
for( s = s_min; s < s_max; s++ )
{
for( t = t_min; t < t_max; t++ )
{
float s0 = max( coordmins[0] - s, -1.0 );
float t0 = max( coordmins[1] - t, -1.0 );
float s1 = min( coordmaxs[0] - s, 1.0 );
float t1 = min( coordmaxs[1] - t, 1.0 );
float s0 = MAX( coordmins[0] - s, -1.0 );
float t0 = MAX( coordmins[1] - t, -1.0 );
float s1 = MIN( coordmaxs[0] - s, 1.0 );
float t1 = MIN( coordmaxs[1] - t, 1.0 );
area = (s1 - s0) * (t1 - t0);
@ -110,7 +110,7 @@ void AddDirectToRadial( radial_t *rad,
ds = fabs( coord[0] - s );
dt = fabs( coord[1] - t );
r = max( ds, dt );
r = MAX( ds, dt );
if (r < 0.1)
{
@ -176,8 +176,8 @@ void AddBouncedToRadial( radial_t *rad,
distt = (coordmaxs[1] - coordmins[1]);
// patches less than a luxel in size could be mistakeningly filtered, so clamp.
dists = max( 1.0, dists );
distt = max( 1.0, distt );
dists = MAX( 1.0, dists );
distt = MAX( 1.0, distt );
// find possible domain of patch influence
s_min = ( int )( coord[0] - dists * RADIALDIST );
@ -186,10 +186,10 @@ void AddBouncedToRadial( radial_t *rad,
t_max = ( int )( coord[1] + distt * RADIALDIST + 1.0f );
// clamp to valid luxel
s_min = max( s_min, 0 );
t_min = max( t_min, 0 );
s_max = min( s_max, rad->w );
t_max = min( t_max, rad->h );
s_min = MAX( s_min, 0 );
t_min = MAX( t_min, 0 );
s_max = MIN( s_max, rad->w );
t_max = MIN( t_max, rad->h );
for( s = s_min; s < s_max; s++ )
{
@ -249,10 +249,10 @@ void PatchLightmapCoordRange( radial_t *rad, int ndxPatch, Vector2D &mins, Vecto
for (i = 0; i < w->numpoints; i++)
{
WorldToLuxelSpace( &rad->l, w->p[i], coord );
mins[0] = min( mins[0], coord[0] );
maxs[0] = max( maxs[0], coord[0] );
mins[1] = min( mins[1], coord[1] );
maxs[1] = max( maxs[1], coord[1] );
mins[0] = MIN( mins[0], coord[0] );
maxs[0] = MAX( maxs[0], coord[0] );
mins[1] = MIN( mins[1], coord[1] );
maxs[1] = MAX( maxs[1], coord[1] );
}
}
@ -810,7 +810,7 @@ void FinalLightFace( int iThread, int facenum )
// garymct: minlight is a per entity minimum light value?
for( i=0; i<3; i++ )
{
lb[bumpSample].m_vecLighting[i] = max( lb[bumpSample].m_vecLighting[i], minlight );
lb[bumpSample].m_vecLighting[i] = MAX( lb[bumpSample].m_vecLighting[i], minlight );
}
// Do the average light computation, I'm assuming (perhaps incorrectly?)

View File

@ -11,7 +11,7 @@
#include "vrad.h"
#include "trace.h"
#include "Cmodel.h"
#include "cmodel.h"
#include "mathlib/vmatrix.h"
@ -133,7 +133,11 @@ public:
addedCoverage[s] = 0.0f;
if ( ( sign >> s) & 0x1 )
{
#ifdef VRAD_SSE
addedCoverage[s] = ComputeCoverageFromTexture( b0->m128_f32[s], b1->m128_f32[s], b2->m128_f32[s], hitID );
#else
addedCoverage[s] = ComputeCoverageFromTexture( b0[0][s], b1[0][s], b2[0][s], hitID );
#endif
}
}
m_coverage = AddSIMD( m_coverage, LoadUnalignedSIMD( addedCoverage ) );
@ -169,7 +173,11 @@ void TestLine( const FourVectors& start, const FourVectors& stop,
{
visibility[i] = 1.0f;
if ( ( rt_result.HitIds[i] != -1 ) &&
#ifdef VRAD_SSE
( rt_result.HitDistance.m128_f32[i] < len.m128_f32[i] ) )
#else
( rt_result.HitDistance[i] < len[i] ) )
#endif
{
visibility[i] = 0.0f;
}
@ -373,7 +381,11 @@ void TestLine_DoesHitSky( FourVectors const& start, FourVectors const& stop,
{
aOcclusion[i] = 0.0f;
if ( ( rt_result.HitIds[i] != -1 ) &&
#ifdef VRAD_SSE
( rt_result.HitDistance.m128_f32[i] < len.m128_f32[i] ) )
#else
( rt_result.HitDistance[i] < len[i] ) )
#endif
{
int id = g_RtEnv.OptimizedTriangleList[rt_result.HitIds[i]].m_Data.m_IntersectData.m_nTriangleID;
if ( !( id & TRACE_ID_SKY ) )

View File

@ -7,8 +7,8 @@
//=============================================================================//
#include "vrad.h"
#include "vmpi.h"
#ifdef MPI
#include "vmpi.h"
#include "messbuf.h"
static MessageBuffer mb;
#endif
@ -467,11 +467,13 @@ BuildVisMatrix
*/
void BuildVisMatrix (void)
{
#ifdef MPI
if ( g_bUseMPI )
{
RunMPIBuildVisLeafs();
}
else
#endif
{
RunThreadsOn (dvis->numclusters, true, BuildVisLeafs);
}

View File

@ -12,9 +12,11 @@
#include "physdll.h"
#include "lightmap.h"
#include "tier1/strtools.h"
#ifdef MPI
#include "vmpi.h"
#include "macro_texture.h"
#include "vmpi_tools_shared.h"
#endif
#include "macro_texture.h"
#include "leaf_ambient_lighting.h"
#include "tools_minidump.h"
#include "loadcmdline.h"
@ -24,6 +26,10 @@
static FileHandle_t pFpTrans = NULL;
#ifdef POSIX
char g_FileName[MAX_PATH];
#endif
/*
NOTES
@ -94,7 +100,7 @@ bool g_bOnlyStaticProps = false;
bool g_bShowStaticPropNormals = false;
float gamma = 0.5;
float qgamma = 0.5;
float indirect_sun = 1.0;
float reflectivityScale = 1.0;
qboolean do_extra = true;
@ -284,7 +290,7 @@ void ReadLightFile (char *filename)
texlights[j].filename = filename;
file_texlights ++;
num_texlights = max( num_texlights, j + 1 );
num_texlights = MAX( num_texlights, j + 1 );
}
}
qprintf ( "[%i texlights parsed from '%s']\n\n", file_texlights, filename);
@ -819,7 +825,7 @@ int CreateChildPatch( int nParentIndex, winding_t *pWinding, float flArea, const
if ( (child->face_maxs[i] == child->maxs[i] || child->face_mins[i] == child->mins[i] )
&& total[i] > minchop )
{
child->chop = max( minchop, child->chop / 2 );
child->chop = MAX( minchop, child->chop / 2 );
break;
}
}
@ -879,7 +885,7 @@ void SubdividePatch( int ndxPatch )
if (patch->chop > minchop)
{
bSubdivide = true;
patch->chop = max( minchop, patch->chop / 2 );
patch->chop = MAX( minchop, patch->chop / 2 );
}
}
}
@ -2019,6 +2025,7 @@ bool RadWorld_Go()
BuildFacesVisibleToLights( true );
}
#ifdef MPI
// build initial facelights
if (g_bUseMPI)
{
@ -2026,6 +2033,7 @@ bool RadWorld_Go()
RunMPIBuildFacelights();
}
else
#endif
{
RunThreadsOnIndividual (numfaces, true, BuildFacelights);
}
@ -2079,13 +2087,16 @@ bool RadWorld_Go()
StaticDispMgr()->InsertPatchSampleDataIntoHashTable();
StaticDispMgr()->EndTimer();
#ifdef MPI
// blend bounced light into direct light and save
VMPI_SetCurrentStage( "FinalLightFace" );
if ( !g_bUseMPI || g_bMPIMaster )
#endif
RunThreadsOnIndividual (numfaces, true, FinalLightFace);
#ifdef MPI
// Distribute the lighting data to workers.
VMPI_DistributeLightData();
#endif
Msg("FinalLightFace Done\n"); fflush(stdout);
}
@ -2099,7 +2110,7 @@ FileHandle_t pFileSamples[4][4];
void LoadPhysicsDLL( void )
{
PhysicsDLLPath( "VPHYSICS.DLL" );
PhysicsDLLPath( "vphysics" DLL_EXT_STRING );
}
@ -2128,10 +2139,12 @@ void VRAD_LoadBSP( char const *pFilename )
g_flStartTime = Plat_FloatTime();
#ifdef _WIN32
if( g_bLowPriority )
{
SetLowPriority();
}
#endif
strcpy( level_name, source );
@ -2143,7 +2156,9 @@ void VRAD_LoadBSP( char const *pFilename )
// so we prepend qdir here.
strcpy( source, ExpandPath( source ) );
#ifdef MPI
if ( !g_bUseMPI )
#endif
{
// Setup the logfile.
char logFile[512];
@ -2160,7 +2175,11 @@ void VRAD_LoadBSP( char const *pFilename )
// Otherwise, try looking in the BIN directory from which we were run from
Msg( "Could not find lights.rad in %s.\nTrying VRAD BIN directory instead...\n",
global_lights );
#ifdef _WIN32
GetModuleFileName( NULL, global_lights, sizeof( global_lights ) );
#else
Q_strncpy(global_lights, g_FileName, sizeof(global_lights));
#endif
Q_ExtractFilePath( global_lights, global_lights, sizeof( global_lights ) );
strcat( global_lights, "lights.rad" );
}
@ -2181,9 +2200,12 @@ void VRAD_LoadBSP( char const *pFilename )
Q_DefaultExtension(source, ".bsp", sizeof( source ));
Msg( "Loading %s\n", source );
#ifdef MPI
VMPI_SetCurrentStage( "LoadBSPFile" );
#endif
LoadBSPFile (source);
#ifdef MPI
// Add this bsp to our search path so embedded resources can be found
if ( g_bUseMPI && g_bMPIMaster )
{
@ -2192,6 +2214,7 @@ void VRAD_LoadBSP( char const *pFilename )
g_pOriginalPassThruFileSystem->AddSearchPath(source, "MOD", PATH_ADD_TO_HEAD);
}
else if ( !g_bUseMPI )
#endif
{
// Non-MPI
g_pFullFileSystem->AddSearchPath(source, "GAME", PATH_ADD_TO_HEAD);
@ -2323,7 +2346,9 @@ void VRAD_Finish()
}
Msg( "Writing %s\n", source );
#ifdef MPI
VMPI_SetCurrentStage( "WriteBSPFile" );
#endif
WriteBSPFile(source);
if ( g_bDumpPatches )
@ -2601,10 +2626,12 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail )
{
++i;
}
#ifdef _WIN32
else if ( !Q_stricmp( argv[i], "-FullMinidumps" ) )
{
EnableFullMinidumps( true );
}
#endif
else if ( !Q_stricmp( argv[i], "-hdr" ) )
{
SetHDRMode( true );
@ -2640,7 +2667,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail )
Warning("Error: expected positive value after '-chop'\n" );
return -1;
}
minchop = min( minchop, maxchop );
minchop = MIN( minchop, maxchop );
}
else
{
@ -2751,6 +2778,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail )
}
}
#endif
#ifdef MPI
// NOTE: the -mpi checks must come last here because they allow the previous argument
// to be -mpi as well. If it game before something else like -game, then if the previous
// argument was -mpi and the current argument was something valid like -game, it would skip it.
@ -2763,6 +2791,7 @@ int ParseCommandLine( int argc, char **argv, bool *onlydetail )
if ( i == argc - 1 && V_stricmp( argv[i], "-mpi_ListParams" ) != 0 )
break;
}
#endif
else if ( mapArg == -1 )
{
mapArg = i;
@ -2805,7 +2834,9 @@ void PrintUsage( int argc, char **argv )
" -final : High quality processing. equivalent to -extrasky 16.\n"
" -extrasky n : trace N times as many rays for indirect light and sky ambient.\n"
" -low : Run as an idle-priority process.\n"
#ifdef MPI
" -mpi : Use VMPI to distribute computations.\n"
#endif
" -rederror : Show errors in red.\n"
"\n"
" -vproject <directory> : Override the VPROJECT environment variable.\n"
@ -2828,7 +2859,9 @@ void PrintUsage( int argc, char **argv )
" -dlightmap : Force direct lighting into different lightmap than\n"
" radiosity.\n"
" -stoponexit : Wait for a keypress on exit.\n"
#ifdef MPI
" -mpi_pw <pw> : Use a password to choose a specific set of VMPI workers.\n"
#endif
" -nodetaillight : Don't light detail props.\n"
" -centersamples : Move sample centers.\n"
" -luxeldensity # : Rescale all luxels by the specified amount (default: 1.0).\n"
@ -2840,7 +2873,9 @@ void PrintUsage( int argc, char **argv )
" -softsun <n> : Treat the sun as an area light source of size <n> degrees."
" Produces soft shadows.\n"
" Recommended values are between 0 and 5. Default is 0.\n"
#ifdef _WIN32
" -FullMinidumps : Write large minidumps on crash.\n"
#endif
" -chop : Smallest number of luxel widths for a bounce patch, used on edges\n"
" -maxchop : Coarsest allowed number of luxel widths for a patch, used in face interiors\n"
"\n"
@ -2885,16 +2920,24 @@ void PrintUsage( int argc, char **argv )
#endif
}
#ifdef _WIN32
#define APP_EXT ".exe"
#else
#define APP_EXT ""
#endif
int RunVRAD( int argc, char **argv )
{
#if defined(_MSC_VER) && ( _MSC_VER >= 1310 )
Msg("Valve Software - vrad.exe SSE (" __DATE__ ")\n" );
Msg("Valve Software - vrad" APP_EXT " SSE (" __DATE__ ")\n" );
#else
Msg("Valve Software - vrad.exe (" __DATE__ ")\n" );
Msg("Valve Software - vrad" APP_EXT " (" __DATE__ ")\n" );
#endif
Msg("\n Valve Radiosity Simulator \n");
Q_strncpy(g_FileName, argv[0], MAX_PATH);
verbose = true; // Originally FALSE
bool onlydetail;
@ -2922,7 +2965,9 @@ int RunVRAD( int argc, char **argv )
VRAD_Finish();
#ifdef MPI
VMPI_SetCurrentStage( "master done" );
#endif
DeleteCmdLine( argc, argv );
CmdLib_Cleanup();
@ -2936,6 +2981,7 @@ int VRAD_Main(int argc, char **argv)
VRAD_Init();
#ifdef MPI
// This must come first.
VRAD_SetupMPI( argc, argv );
@ -2945,10 +2991,13 @@ int VRAD_Main(int argc, char **argv)
SetupToolsMinidumpHandler( VMPI_ExceptionFilter );
}
else
#endif
#endif
{
LoadCmdLineFromFile( argc, argv, source, "vrad" ); // Don't do this if we're a VMPI worker..
#ifdef _WIN32
SetupDefaultToolsMinidumpHandler();
#endif
}
return RunVRAD( argc, argv );

View File

@ -24,9 +24,9 @@
#include "polylib.h"
#include "threads.h"
#include "builddisp.h"
#include "VRAD_DispColl.h"
#include "UtlMemory.h"
#include "UtlHash.h"
#include "vrad_dispcoll.h"
#include "utlmemory.h"
#include "utlhash.h"
#include "utlvector.h"
#include "iincremental.h"
#include "raytrace.h"
@ -34,17 +34,13 @@
#ifdef _WIN32
#include <windows.h>
#include <io.h>
#include <direct.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#pragma warning(disable: 4142 4028)
#include <io.h>
#pragma warning(default: 4142 4028)
#include <fcntl.h>
#include <direct.h>
#include <ctype.h>
@ -337,7 +333,7 @@ extern dface_t *g_pFaces;
extern bool g_bMPIProps;
extern byte nodehit[MAX_MAP_NODES];
extern float gamma;
extern float qgamma;
extern float indirect_sun;
extern float smoothing_threshold;
extern int dlight_map;

View File

@ -6,11 +6,11 @@
//=============================================================================//
#include "vrad.h"
#include "VRAD_DispColl.h"
#include "DispColl_Common.h"
#include "vrad_dispcoll.h"
#include "dispcoll_common.h"
#include "radial.h"
#include "CollisionUtils.h"
#include "tier0\dbg.h"
#include "collisionutils.h"
#include "tier0/dbg.h"
#define SAMPLE_BBOX_SLOP 5.0f
#define TRIEDGE_EPSILON 0.001f
@ -110,6 +110,7 @@ void CVRADDispColl::CalcSampleRadius2AndBox( dface_t *pFace )
// Calculate the patch radius - the max sample edge length * the number of luxels per edge "chop."
float flSampleSize = max( m_flSampleWidth, m_flSampleHeight );
// Calculate the patch radius - the MAX sample edge length * the number of luxels per edge "chop."
float flPatchSampleRadius = flSampleSize * dispchop * 2.2f;
if ( flPatchSampleRadius > g_MaxDispPatchRadius )
{
@ -440,7 +441,7 @@ void CVRADDispColl::CreateChildPatchesFromRoot( int iParentPatch, int *pChildPat
vecEdges[3] = pParentPatch->winding->p[3] - pParentPatch->winding->p[0];
// Should the patch be subdivided - check the area.
float flMaxLength = max( m_flSampleWidth, m_flSampleHeight );
float flMaxLength = MAX( m_flSampleWidth, m_flSampleHeight );
float flMinEdgeLength = flMaxLength * dispchop;
// Find the longest edge.
@ -551,7 +552,7 @@ void CVRADDispColl::CreateChildPatches( int iParentPatch, int nLevel )
return;
// Should the patch be subdivided - check the area.
float flMaxLength = max( m_flSampleWidth, m_flSampleHeight );
float flMaxLength = MAX( m_flSampleWidth, m_flSampleHeight );
float flMinEdgeLength = flMaxLength * dispchop;
// Split along the longest edge.
@ -659,7 +660,7 @@ void CVRADDispColl::CreateChildPatchesSub( int iParentPatch )
return;
// Should the patch be subdivided - check the area.
float flMaxLength = max( m_flSampleWidth, m_flSampleHeight );
float flMaxLength = MAX( m_flSampleWidth, m_flSampleHeight );
float flMinEdgeLength = flMaxLength * dispchop;
// Split along the longest edge.
@ -1077,4 +1078,4 @@ void CVRADDispColl::AddPolysForRayTrace( void )
fullCoverage.x = 1.0f;
g_RtEnv.AddTriangle( TRACE_ID_OPAQUE, m_aVerts[v[0]], m_aVerts[v[1]], m_aVerts[v[2]], fullCoverage );
}
}
}

View File

@ -10,7 +10,7 @@
#pragma once
#include <assert.h>
#include "DispColl_Common.h"
#include "dispcoll_common.h"
//=============================================================================
//
@ -77,4 +77,4 @@ protected:
CUtlVector<Vector> m_aVertNormals; // Displacement vertex normals
};
#endif // VRAD_DISPCOLL_H
#endif // VRAD_DISPCOLL_H

View File

@ -10,16 +10,18 @@
//=============================================================================//
#include "vrad.h"
#include "Bsplib.h"
#include "GameBSPFile.h"
#include "UtlBuffer.h"
#include "utlvector.h"
#include "CModel.h"
#include "bsplib.h"
#include "gamebspfile.h"
#include "tier1/utlbuffer.h"
#include "tier1/utlvector.h"
#include "cmodel.h"
#include "studio.h"
#include "pacifier.h"
#include "vraddetailprops.h"
#include "mathlib/halton.h"
#ifdef MPI
#include "messbuf.h"
#endif
#include "byteswap.h"
bool LoadStudioModel( char const* pModelName, CUtlBuffer& buf );
@ -227,7 +229,11 @@ static void ComputeMaxDirectLighting( DetailObjectLump_t& prop, Vector* maxcolor
normal4.DuplicateVector( normal );
GatherSampleLightSSE ( out, dl, -1, origin4, &normal4, 1, iThread );
#ifdef VRAD_SSE
VectorMA( maxcolor[dl->light.style], out.m_flFalloff.m128_f32[0] * out.m_flDot[0].m128_f32[0], dl->light.intensity, maxcolor[dl->light.style] );
#else
VectorMA( maxcolor[dl->light.style], out.m_flFalloff[0] * out.m_flDot[0][0], dl->light.intensity, maxcolor[dl->light.style] );
#endif
}
}
@ -524,7 +530,8 @@ private:
bool TestPointAgainstSkySurface( Vector const &pt, dface_t *pFace )
{
// Create sky face winding.
winding_t *pWinding = WindingFromFace( pFace, Vector( 0.0f, 0.0f, 0.0f ) );
Vector vec( 0.0f, 0.0f, 0.0f );
winding_t *pWinding = WindingFromFace( pFace, vec );
// Test point in winding. (Since it is at the node, it is in the plane.)
bool bRet = PointInWinding( pt, pWinding );
@ -958,6 +965,7 @@ void UnserializeDetailPropLighting( int lumpID, int lumpVersion, CUtlVector<Deta
buf.Get( lumpData.Base(), lightsize );
}
#ifdef MPI
DetailObjectLump_t *g_pMPIDetailProps = NULL;
void VMPI_ProcessDetailPropWU( int iThread, int iWorkUnit, MessageBuffer *pBuf )
@ -1000,6 +1008,7 @@ void VMPI_ReceiveDetailPropWU( int iWorkUnit, MessageBuffer *pBuf, int iWorker )
pBuf->read( &l->m_Style, sizeof( l->m_Style ) );
}
}
#endif
//-----------------------------------------------------------------------------
// Computes lighting for the detail props

View File

@ -8,14 +8,13 @@
#include "vrad.h"
#include "utlvector.h"
#include "cmodel.h"
#include "BSPTreeData.h"
#include "VRAD_DispColl.h"
#include "CollisionUtils.h"
#include "bsptreedata.h"
#include "vrad_dispcoll.h"
#include "collisionutils.h"
#include "lightmap.h"
#include "Radial.h"
#include "CollisionUtils.h"
#include "radial.h"
#include "mathlib/bumpvects.h"
#include "utlrbtree.h"
#include "tier1/utlrbtree.h"
#include "tier0/fasttimer.h"
#include "disp_vrad.h"
@ -562,7 +561,7 @@ bool CVRadDispMgr::ClipRayToDisp( DispTested_t &dispTested, Ray_t const &ray )
ctx.m_pDispTested = &dispTested;
// If it got through without a hit, it returns true
return !m_pBSPTreeData->EnumerateLeavesAlongRay( ray, &m_EnumDispRay, ( int )&ctx );
return !m_pBSPTreeData->EnumerateLeavesAlongRay( ray, &m_EnumDispRay, ( int )(size_t)&ctx );
}
@ -575,7 +574,7 @@ bool CVRadDispMgr::ClipRayToDispInLeaf( DispTested_t &dispTested, Ray_t const &r
ctx.m_pRay = &ray;
ctx.m_pDispTested = &dispTested;
return !m_pBSPTreeData->EnumerateElementsInLeaf( ndxLeaf, &m_EnumDispRay, ( int )&ctx );
return !m_pBSPTreeData->EnumerateElementsInLeaf( ndxLeaf, &m_EnumDispRay, ( int )(size_t)&ctx );
}
//-----------------------------------------------------------------------------
@ -1135,7 +1134,7 @@ void AddPatchLightToRadial( Vector const &patchOrigin, Vector const &patchNormal
if( bNeighborBump )
{
float flScale = patchNormal.Dot( normals[0] );
flScale = max( 0.0f, flScale );
flScale = MAX( 0.0f, flScale );
float flBumpInfluence = influence * flScale;
for( int ndxBump = 0; ndxBump < ( NUM_BUMP_VECTS+1 ); ndxBump++ )
@ -1148,7 +1147,7 @@ void AddPatchLightToRadial( Vector const &patchOrigin, Vector const &patchNormal
else
{
float flScale = patchNormal.Dot( normals[0] );
flScale = max( 0.0f, flScale );
flScale = MAX( 0.0f, flScale );
float flBumpInfluence = influence * flScale * 0.05f;
for( int ndxBump = 0; ndxBump < ( NUM_BUMP_VECTS+1 ); ndxBump++ )
@ -1162,7 +1161,7 @@ void AddPatchLightToRadial( Vector const &patchOrigin, Vector const &patchNormal
else
{
float flScale = patchNormal.Dot( luxelNormal );
flScale = max( 0.0f, flScale );
flScale = MAX( 0.0f, flScale );
influence *= flScale;
pRadial->light[0][ndxRadial].AddWeighted( pPatchLight[0], influence );

View File

@ -119,7 +119,9 @@ bool CVRadDLL::Init( char const *pFilename )
// Set options and run vrad startup code.
do_fast = true;
#ifdef _WIN32
g_bLowPriorityThreads = true;
#endif
g_pIncremental = GetIncremental();
VRAD_LoadBSP( pFilename );
@ -169,10 +171,18 @@ void CVRadDLL::GetBSPInfo( CBSPInfo *pInfo )
bool CVRadDLL::DoIncrementalLight( char const *pVMFFile )
{
char tempPath[MAX_PATH], tempFilename[MAX_PATH];
char
#ifdef _WIN32
tempPath[MAX_PATH],
#endif
tempFilename[MAX_PATH];
#ifdef _WIN32
GetTempPath( sizeof( tempPath ), tempPath );
GetTempFileName( tempPath, "vmf_entities_", 0, tempFilename );
#else
struct tm *timeinfo = localtime(NULL);
strftime( tempFilename, MAX_PATH, "/tmp/vmf_entities_%F-%T", timeinfo );
#endif
FileHandle_t fp = g_pFileSystem->Open( tempFilename, "wb" );
if( !fp )
return false;

View File

@ -11,16 +11,16 @@
#include "vrad.h"
#include "mathlib/vector.h"
#include "UtlBuffer.h"
#include "utlbuffer.h"
#include "utlvector.h"
#include "GameBSPFile.h"
#include "BSPTreeData.h"
#include "VPhysics_Interface.h"
#include "Studio.h"
#include "Optimize.h"
#include "Bsplib.h"
#include "CModel.h"
#include "PhysDll.h"
#include "gamebspfile.h"
#include "bsptreedata.h"
#include "vphysics_interface.h"
#include "studio.h"
#include "optimize.h"
#include "bsplib.h"
#include "cmodel.h"
#include "physdll.h"
#include "phyfile.h"
#include "collisionutils.h"
#include "tier1/KeyValues.h"
@ -29,15 +29,17 @@
#include "materialsystem/hardwareverts.h"
#include "materialsystem/hardwaretexels.h"
#include "byteswap.h"
#include "mpivrad.h"
#include "vtf/vtf.h"
#include "tier1/utldict.h"
#include "tier1/utlsymbol.h"
#include "bitmap/tgawriter.h"
#ifdef MPI
#include "mpivrad.h"
#include "messbuf.h"
#include "vmpi.h"
#include "vmpi_distribute_work.h"
#endif
#define ALIGN_TO_POW2(x,y) (((x)+(y-1))&~(y-1))
@ -155,20 +157,20 @@ void Rasterizer::Build()
const float baseY = mUvStepY / 2.0f;
float fMinX = min(min(mT0.x, mT1.x), mT2.x);
float fMinY = min(min(mT0.y, mT1.y), mT2.y);
float fMaxX = max(max(mT0.x, mT1.x), mT2.x);
float fMaxY = max(max(mT0.y, mT1.y), mT2.y);
float fMinX = MIN(MIN(mT0.x, mT1.x), mT2.x);
float fMinY = MIN(MIN(mT0.y, mT1.y), mT2.y);
float fMaxX = MAX(MAX(mT0.x, mT1.x), mT2.x);
float fMaxY = MAX(MAX(mT0.y, mT1.y), mT2.y);
// Degenerate. Consider warning about these, but otherwise no problem.
if (fMinX == fMaxX || fMinY == fMaxY)
return;
// Clamp to 0..1
fMinX = max(0, fMinX);
fMinY = max(0, fMinY);
fMaxX = min(1.0f, fMaxX);
fMaxY = min(1.0f, fMaxY);
fMinX = MAX(0, fMinX);
fMinY = MAX(0, fMinY);
fMaxX = MIN(1.0f, fMaxX);
fMaxY = MIN(1.0f, fMaxY);
// We puff the interesting area up by 1 so we can hit an inflated region for the necessary bilerp data.
// If we wanted to support better texturing (almost definitely unnecessary), we'd change this to a larger size.
@ -180,13 +182,14 @@ void Rasterizer::Build()
int iMaxY = GetRow(fMaxY) + 1 + kFilterSampleRadius;
// Clamp to valid texture (integer) locations
iMinX = max(0, iMinX);
iMinY = max(0, iMinY);
iMaxX = min(iMaxX, mResX - 1);
iMaxY = min(iMaxY, mResY - 1);
iMinX = MAX(0, iMinX);
iMinY = MAX(0, iMinY);
iMaxX = MIN(iMaxX, mResX - 1);
iMaxY = MIN(iMaxY, mResY - 1);
// Set the size to be as expected.
// TODO: Pass this in from outside to minimize allocations
// TODO: Pass this in from outside to minimize allocations
int count = (iMaxY - iMinY + 1)
* (iMaxX - iMinX + 1);
mRasterizedLocations.EnsureCount(count);
@ -259,11 +262,13 @@ public:
void ComputeLighting( int iThread );
private:
#ifdef MPI
// VMPI stuff.
static void VMPI_ProcessStaticProp_Static( int iThread, uint64 iStaticProp, MessageBuffer *pBuf );
static void VMPI_ReceiveStaticPropResults_Static( uint64 iStaticProp, MessageBuffer *pBuf, int iWorker );
void VMPI_ProcessStaticProp( int iThread, int iStaticProp, MessageBuffer *pBuf );
void VMPI_ReceiveStaticPropResults( int iStaticProp, MessageBuffer *pBuf, int iWorker );
#endif
// local thread version
static void ThreadComputeStaticPropLighting( int iThread, void *pUserData );
@ -495,8 +500,8 @@ bool LoadStudioModel( char const* pModelName, CUtlBuffer& buf )
}
// ensure reset
pHdr->pVertexBase = NULL;
pHdr->pIndexBase = NULL;
pHdr->SetVertexBase(NULL);
pHdr->SetIndexBase(NULL);
return true;
}
@ -779,15 +784,15 @@ public:
// HACKHACK: Compute the average coverage for this triangle by sampling the AABB of its texture space
float ComputeCoverageForTriangle( int shadowTextureIndex, const Vector2D &t0, const Vector2D &t1, const Vector2D &t2 )
{
float umin = min(t0.x, t1.x);
umin = min(umin, t2.x);
float umax = max(t0.x, t1.x);
umax = max(umax, t2.x);
float umin = MIN(t0.x, t1.x);
umin = MIN(umin, t2.x);
float umax = MAX(t0.x, t1.x);
umax = MAX(umax, t2.x);
float vmin = min(t0.y, t1.y);
vmin = min(vmin, t2.y);
float vmax = max(t0.y, t1.y);
vmax = max(vmax, t2.y);
float vmin = MIN(t0.y, t1.y);
vmin = MIN(vmin, t2.y);
float vmax = MAX(t0.y, t1.y);
vmax = MAX(vmax, t2.y);
// UNDONE: Do something about tiling
umin = clamp(umin, 0, 1);
@ -1064,7 +1069,7 @@ void CVradStaticPropMgr::UnserializeStaticProps()
if ( g_GameLumps.GetGameLumpVersion( handle ) != GAMELUMP_STATIC_PROPS_VERSION )
{
Error( "Cannot load the static props... encountered a stale map version. Re-vbsp the map." );
Error( "Cannot load the static props... encountered a stale map version. Re-vbsp the map.\n" );
}
if ( g_GameLumps.GetGameLump( handle ) )
@ -1110,9 +1115,9 @@ void CVradStaticPropMgr::Shutdown()
studiohdr_t *pStudioHdr = m_StaticPropDict[i].m_pStudioHdr;
if ( pStudioHdr )
{
if ( pStudioHdr->pVertexBase )
if ( pStudioHdr->VertexBase() )
{
free( pStudioHdr->pVertexBase );
free( pStudioHdr->VertexBase() );
}
free( pStudioHdr );
}
@ -1200,8 +1205,12 @@ void ComputeDirectLightingAtPoint( Vector &position, Vector &normal, Vector &out
GatherSampleLightSSE( sampleOutput, dl, -1, adjusted_pos4, &normal4, 1, iThread, nLFlags | GATHERLFLAGS_FORCE_FAST,
static_prop_id_to_skip, flEpsilon );
#ifdef VRAD_SSE
VectorMA( outColor, sampleOutput.m_flFalloff.m128_f32[0] * sampleOutput.m_flDot[0].m128_f32[0], dl->light.intensity, outColor );
#else
VectorMA( outColor, sampleOutput.m_flFalloff[0] * sampleOutput.m_flDot[0][0], dl->light.intensity, outColor );
#endif
}
}
@ -1329,7 +1338,9 @@ void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int pr
const int skip_prop = (g_bDisablePropSelfShadowing || (prop.m_Flags & STATIC_PROP_NO_SELF_SHADOWING)) ? prop_index : -1;
const int nFlags = ( prop.m_Flags & STATIC_PROP_IGNORE_NORMALS ) ? GATHERLFLAGS_IGNORE_NORMALS : 0;
#ifdef MPI
VMPI_SetCurrentStage( "ComputeLighting" );
#endif
matrix3x4_t matPos, matNormal;
AngleMatrix(prop.m_Angles, prop.m_Origin, matPos);
@ -1553,7 +1564,7 @@ void CVradStaticPropMgr::SerializeLighting()
// align to start of vertex data
unsigned char *pVertexData = (unsigned char *)(sizeof( HardwareVerts::FileHeader_t ) + m_StaticProps[i].m_MeshData.Count()*sizeof(HardwareVerts::MeshHeader_t));
pVertexData = (unsigned char*)pVhvHdr + ALIGN_TO_POW2( (unsigned int)pVertexData, 512 );
pVertexData = (unsigned char*)pVhvHdr + ALIGN_TO_POW2( (uintp)pVertexData, 512 );
// construct header
pVhvHdr->m_nVersion = VHV_VERSION;
@ -1569,7 +1580,7 @@ void CVradStaticPropMgr::SerializeLighting()
HardwareVerts::MeshHeader_t *pMesh = pVhvHdr->pMesh( n );
pMesh->m_nLod = m_StaticProps[i].m_MeshData[n].m_nLod;
pMesh->m_nVertexes = m_StaticProps[i].m_MeshData[n].m_VertexColors.Count();
pMesh->m_nOffset = (unsigned int)pVertexData - (unsigned int)pVhvHdr;
pMesh->m_nOffset = (uintp)pVertexData - (uintp)pVhvHdr;
// construct vertexes
for (int k=0; k<pMesh->m_nVertexes; k++)
@ -1591,8 +1602,8 @@ void CVradStaticPropMgr::SerializeLighting()
}
// align to end of file
pVertexData = (unsigned char *)((unsigned int)pVertexData - (unsigned int)pVhvHdr);
pVertexData = (unsigned char*)pVhvHdr + ALIGN_TO_POW2( (unsigned int)pVertexData, 512 );
pVertexData = (unsigned char *)((uintp)pVertexData - (uintp)pVhvHdr);
pVertexData = (unsigned char*)pVhvHdr + ALIGN_TO_POW2( (uintp)pVertexData, 512 );
AddBufferToPak( GetPakFile(), filename, (void*)pVhvHdr, pVertexData - (unsigned char*)pVhvHdr, false );
}
@ -1609,7 +1620,7 @@ void CVradStaticPropMgr::SerializeLighting()
ImageFormat fmt = m_StaticProps[i].m_LightmapImageFormat;
unsigned int totalTexelSizeBytes = 0;
uintp totalTexelSizeBytes = 0;
for (int j = 0; j < m_StaticProps[i].m_MeshData.Count(); j++)
{
totalTexelSizeBytes += m_StaticProps[i].m_MeshData[j].m_TexelsEncoded.Count();
@ -1628,7 +1639,7 @@ void CVradStaticPropMgr::SerializeLighting()
// align start of texel data
unsigned char *pTexelData = (unsigned char *)(sizeof(HardwareTexels::FileHeader_t) + m_StaticProps[i].m_MeshData.Count() * sizeof(HardwareTexels::MeshHeader_t));
pTexelData = (unsigned char*)pVhtHdr + ALIGN_TO_POW2((unsigned int)pTexelData, kAlignment);
pTexelData = (unsigned char*)pVhtHdr + ALIGN_TO_POW2((uintp)pTexelData, kAlignment);
pVhtHdr->m_nVersion = VHT_VERSION;
pVhtHdr->m_nChecksum = m_StaticPropDict[m_StaticProps[i].m_ModelIdx].m_pStudioHdr->checksum;
@ -1639,7 +1650,7 @@ void CVradStaticPropMgr::SerializeLighting()
{
HardwareTexels::MeshHeader_t *pMesh = pVhtHdr->pMesh(n);
pMesh->m_nLod = m_StaticProps[i].m_MeshData[n].m_nLod;
pMesh->m_nOffset = (unsigned int)pTexelData - (unsigned int)pVhtHdr;
pMesh->m_nOffset = (uintp)pTexelData - (uintp)pVhtHdr;
pMesh->m_nBytes = m_StaticProps[i].m_MeshData[n].m_TexelsEncoded.Count();
pMesh->m_nWidth = m_StaticProps[i].m_LightmapImageWidth;
pMesh->m_nHeight = m_StaticProps[i].m_LightmapImageHeight;
@ -1648,13 +1659,14 @@ void CVradStaticPropMgr::SerializeLighting()
pTexelData += m_StaticProps[i].m_MeshData[n].m_TexelsEncoded.Count();
}
pTexelData = (unsigned char *)((unsigned int)pTexelData - (unsigned int)pVhtHdr);
pTexelData = (unsigned char*)pVhtHdr + ALIGN_TO_POW2((unsigned int)pTexelData, kAlignment);
pTexelData = (unsigned char *)((uintp)pTexelData - (uintp)pVhtHdr);
pTexelData = (unsigned char*)pVhtHdr + ALIGN_TO_POW2((uintp)pTexelData, kAlignment);
AddBufferToPak(GetPakFile(), filename, (void*)pVhtHdr, pTexelData - (unsigned char*)pVhtHdr, false);
}
}
#ifdef MPI
void CVradStaticPropMgr::VMPI_ProcessStaticProp_Static( int iThread, uint64 iStaticProp, MessageBuffer *pBuf )
{
g_StaticPropMgr.VMPI_ProcessStaticProp( iThread, iStaticProp, pBuf );
@ -1739,7 +1751,7 @@ void CVradStaticPropMgr::VMPI_ReceiveStaticPropResults( int iStaticProp, Message
// Apply the results.
ApplyLightingToStaticProp( iStaticProp, m_StaticProps[iStaticProp], &results );
}
#endif
void CVradStaticPropMgr::ComputeLightingForProp( int iThread, int iStaticProp )
{
@ -1780,6 +1792,7 @@ void CVradStaticPropMgr::ComputeLighting( int iThread )
// ensure any traces against us are ignored because we have no inherit lighting contribution
m_bIgnoreStaticPropTrace = true;
#ifdef MPI
if ( g_bUseMPI )
{
// Distribute the work among the workers.
@ -1792,6 +1805,7 @@ void CVradStaticPropMgr::ComputeLighting( int iThread )
&CVradStaticPropMgr::VMPI_ReceiveStaticPropResults_Static );
}
else
#endif
{
RunThreadsOn(count, true, ThreadComputeStaticPropLighting);
}
@ -2169,9 +2183,9 @@ const vertexFileHeader_t * mstudiomodel_t::CacheVertexData( void *pModelData )
studiohdr_t *pActiveStudioHdr = static_cast<studiohdr_t *>(pModelData);
Assert( pActiveStudioHdr );
if ( pActiveStudioHdr->pVertexBase )
if ( pActiveStudioHdr->VertexBase() )
{
return (vertexFileHeader_t *)pActiveStudioHdr->pVertexBase;
return (vertexFileHeader_t *)pActiveStudioHdr->VertexBase();
}
// mandatory callback to make requested data resident
@ -2230,7 +2244,7 @@ const vertexFileHeader_t * mstudiomodel_t::CacheVertexData( void *pModelData )
free( pVvdHdr );
pVvdHdr = pNewVvdHdr;
pActiveStudioHdr->pVertexBase = (void*)pVvdHdr;
pActiveStudioHdr->SetVertexBase((void*)pVvdHdr);
return pVvdHdr;
}
@ -2247,8 +2261,8 @@ struct ColorTexelValue
// ------------------------------------------------------------------------------------------------
inline int ComputeLinearPos( int _x, int _y, int _resX, int _resY )
{
return Min( Max( 0, _y ), _resY - 1 ) * _resX
+ Min( Max( 0, _x ), _resX - 1 );
return MIN( MAX( 0, _y ), _resY - 1 ) * _resX
+ MIN( MAX( 0, _x ), _resX - 1 );
}
// ------------------------------------------------------------------------------------------------
@ -2455,8 +2469,8 @@ static int GetTexelCount(unsigned int _resX, unsigned int _resY, bool _mipmaps)
while (_resX > 1 || _resY > 1)
{
retVal += _resX * _resY;
_resX = max(1, _resX >> 1);
_resY = max(1, _resY >> 1);
_resX = MAX(1, _resX >> 1);
_resY = MAX(1, _resY >> 1);
}
// Add in the 1x1 mipmap level, which wasn't hit above. This could be done in the initializer of
@ -2582,8 +2596,8 @@ static void FilterCoarserMipmaps(unsigned int _resX, unsigned int _resY, CUtlVec
int srcResX = _resX;
int srcResY = _resY;
int dstResX = max(1, (srcResX >> 1));
int dstResY = max(1, (srcResY >> 1));
int dstResX = MAX(1, (srcResX >> 1));
int dstResY = MAX(1, (srcResY >> 1));
int dstOffset = GetTexelCount(srcResX, srcResY, false);
// Build mipmaps here, after being converted to linear space.
@ -2618,8 +2632,8 @@ static void FilterCoarserMipmaps(unsigned int _resX, unsigned int _resY, CUtlVec
srcResX = dstResX;
srcResY = dstResY;
dstResX = max(1, (srcResX >> 1));
dstResY = max(1, (srcResY >> 1));
dstResX = MAX(1, (srcResX >> 1));
dstResY = MAX(1, (srcResY >> 1));
dstOffset += GetTexelCount(srcResX, srcResY, false);
}
}
@ -2650,8 +2664,8 @@ static void ConvertToDestinationFormat(unsigned int _resX, unsigned int _resY, I
srcOffset += GetTexelCount(srcResX, srcResY, false);
dstOffset += ImageLoader::GetMemRequired(srcResX, srcResY, 1, _destFmt, false);
srcResX = max(1, (srcResX >> 1));
srcResY = max(1, (srcResY >> 1));
srcResX = MAX(1, (srcResX >> 1));
srcResY = MAX(1, (srcResY >> 1));
}
// Do the 1x1 level also.

118
utils/vrad/wscript Executable file
View File

@ -0,0 +1,118 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vrad'
def options(opt):
# stub
return
def configure(conf):
conf.define('PROTECTED_THINGS_DISABLE', 1)
conf.define('VRAD', 1)
conf.define('MAX_TOOL_THREADS', 1)
conf.define('THREADINDEX_MAIN', 0)
conf.define('NO_THREAD_NAMES', 1)
return
def build(bld):
source = [
'disp_vrad.cpp',
'imagepacker.cpp',
'incremental.cpp',
'leaf_ambient_lighting.cpp',
'lightmap.cpp',
'macro_texture.cpp',
'origface.cpp',
'radial.cpp',
'samplehash.cpp',
'trace.cpp',
'vismat.cpp',
'vrad.cpp',
'vrad_dispcoll.cpp',
'vraddetailprops.cpp',
'vraddisps.cpp',
'vraddll.cpp',
'vradstaticprops.cpp',
'../common/physdll.cpp',
'../common/utilmatlib.cpp',
'../../public/bsptreedata.cpp',
'../../public/collisionutils.cpp',
'../../public/disp_common.cpp',
'../../public/disp_powerinfo.cpp',
'../../public/dispcoll_common.cpp',
'../../public/loadcmdline.cpp',
'../../public/lumpfiles.cpp',
'../../public/zip_utils.cpp',
# Common files
'../common/bsplib.cpp',
'../common/cmdlib.cpp',
'../common/filesystem_tools.cpp',
'../common/map_shared.cpp',
'../common/polylib.cpp',
'../common/scriplib.cpp',
'../common/threads.cpp',
'../common/pacifier.cpp',
'../../public/builddisp.cpp',
'../../public/chunkfile.cpp',
'../../public/filesystem_helpers.cpp',
'../../public/filesystem_init.cpp',
'../../filesystem/linux_support.cpp',
]
if bld.env.DEST_OS == 'win32' and False:
source += [
'mpivrad.cpp',
'../common/MySqlDatabase.cpp',
'../common/mpi_stats.cpp',
'../common/vmpi_tools_shared.cpp',
'../common/tools_minidump.cpp',
# '../common/scratchpad_helpers.cpp',
# '../../public/scratchpad3d.cpp',
]
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
'../../public/tier3',
'../../public/mathlib'
]
defines = []
libs = [
'tier0', 'tier1', 'tier2', 'tier3',
'vtf',
'bitmap',
'raytrace',
'mathlib',
'lzma',
'vphysics',
'vstdlib',
]
install_path = bld.env.LIBDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -1,15 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// stdafx.cpp : source file that includes just the standard includes
// vrad_launcher.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@ -1,32 +0,0 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__4A047C84_94D7_4563_A08C_35E52A52AECC__INCLUDED_)
#define AFX_STDAFX_H__4A047C84_94D7_4563_A08C_35E52A52AECC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdio.h>
#include "interface.h"
#include "ivraddll.h"
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__4A047C84_94D7_4563_A08C_35E52A52AECC__INCLUDED_)

View File

@ -8,12 +8,18 @@
// vrad_launcher.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#ifdef _WIN32
#include <windows.h>
#include <direct.h>
#else
#include <dlfcn.h>
#endif
#include "ivraddll.h"
#include "tier1/strtools.h"
#include "tier1/interface.h"
#include "tier0/icommandline.h"
#ifdef _WIN32
char* GetLastErrorString()
{
static char err[2048];
@ -38,6 +44,9 @@ char* GetLastErrorString()
return err;
}
#else
#define GetLastErrorString dlerror
#endif
void MakeFullPath( const char *pIn, char *pOut, int outLen )
@ -107,7 +116,7 @@ int main(int argc, char* argv[])
// If it didn't load the module above, then use the
if ( !pModule )
{
strcpy( dllName, "vrad_dll.dll" );
strcpy( dllName, "vrad" DLL_EXT_STRING );
pModule = Sys_LoadModule( dllName );
}

55
utils/vrad_launcher/wscript Executable file
View File

@ -0,0 +1,55 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vrad_launcher'
def options(opt):
# stub
return
def configure(conf):
return
def build(bld):
source = [
'vrad_launcher.cpp'
]
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'vrad']
if bld.env.DEST_OS == 'win32':
libs += ['ADVAPI32', 'WS2_32']
else:
libs += ['DL', 'LOG']
install_path = bld.env.BINDIR
bld(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx cxxprogram',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -6,7 +6,9 @@
//
//=============================================================================//
#include "vis.h"
#ifdef _WIN32
#include "vmpi.h"
#endif
int g_TraceClusterStart = -1;
int g_TraceClusterStop = -1;
@ -50,8 +52,9 @@ int c_chop, c_nochop;
int active;
#ifdef _WIN32
extern bool g_bVMPIEarlyExit;
#endif
void CheckStack (leaf_t *leaf, threaddata_t *thread)
{
@ -485,11 +488,13 @@ void RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
long *test, *might, *vis, more;
int pnum;
#ifdef _WIN32
// Early-out if we're a VMPI worker that's told to exit. If we don't do this here, then the
// worker might spin its wheels for a while on an expensive work unit and not be available to the pool.
// This is pretty common in vis.
if ( g_bVMPIEarlyExit )
return;
#endif
if ( leafnum == g_TraceClusterStop )
{

View File

@ -7,19 +7,21 @@
//=============================================================================//
// vis.c
#ifdef _WIN32
#include <windows.h>
#include "vmpi_tools_shared.h"
#include "vmpi.h"
#include "mpivis.h"
#include "tools_minidump.h"
#endif
#include "vis.h"
#include "threads.h"
#include "stdlib.h"
#include "pacifier.h"
#include "vmpi.h"
#include "mpivis.h"
#include "tier1/strtools.h"
#include "collisionutils.h"
#include "tier0/icommandline.h"
#include "vmpi_tools_shared.h"
#include "ilaunchabledll.h"
#include "tools_minidump.h"
#include "loadcmdline.h"
#include "byteswap.h"
@ -54,7 +56,9 @@ portal_t *sorted_portals[MAX_MAP_PORTALS*2];
bool g_bUseRadius = false;
double g_VisRadius = 4096.0f * 4096.0f;
#ifdef _WIN32
bool g_bLowPriority = false;
#endif
//=============================================================================
@ -84,7 +88,7 @@ winding_t *NewWinding (int points)
if (points > MAX_POINTS_ON_WINDING)
Error ("NewWinding: %i points, max %d", points, MAX_POINTS_ON_WINDING);
size = (int)(&((winding_t *)0)->points[points]);
size = (int)(size_t)(&((winding_t *)0)->points[points]);
w = (winding_t*)malloc (size);
memset (w, 0, size);
@ -302,11 +306,13 @@ void CalcPortalVis (void)
}
#ifdef _WIN32
if (g_bUseMPI)
{
RunMPIPortalFlow();
}
else
#endif
{
RunThreadsOnIndividual (g_numportals*2, true, PortalFlow);
}
@ -315,7 +321,7 @@ void CalcPortalVis (void)
void CalcVisTrace (void)
{
RunThreadsOnIndividual (g_numportals*2, true, BasePortalVis);
RunThreadsOnIndividual (g_numportals*2, true, BasePortalVis);
BuildTracePortals( g_TraceClusterStart );
// NOTE: We only schedule the one-way portals out of the start cluster here
// so don't run g_numportals*2 in this case
@ -331,11 +337,13 @@ void CalcVis (void)
{
int i;
#ifdef _WIN32
if (g_bUseMPI)
{
RunMPIBasePortalVis();
}
else
#endif
{
RunThreadsOnIndividual (g_numportals*2, true, BasePortalVis);
}
@ -413,6 +421,7 @@ void LoadPortals (char *name)
FILE *f;
#ifdef _WIN32
// Open the portal file.
if ( g_bUseMPI )
{
@ -448,6 +457,7 @@ void LoadPortals (char *name)
f = fopen( tempFile, "rSTD" ); // read only, sequential, temporary, delete on close
}
else
#endif
{
f = fopen( name, "r" );
}
@ -949,6 +959,7 @@ int ParseCommandLine( int argc, char **argv )
}
else if (!Q_stricmp (argv[i],"-tmpin"))
strcpy (inbase, "/tmp");
#ifdef _WIN32
else if( !Q_stricmp( argv[i], "-low" ) )
{
g_bLowPriority = true;
@ -957,6 +968,7 @@ int ParseCommandLine( int argc, char **argv )
{
EnableFullMinidumps( true );
}
#endif
else if ( !Q_stricmp( argv[i], CMDLINEOPTION_NOVCONFIG ) )
{
}
@ -968,6 +980,7 @@ int ParseCommandLine( int argc, char **argv )
{
// nothing to do here, but don't bail on this option
}
#ifdef _WIN32
// NOTE: the -mpi checks must come last here because they allow the previous argument
// to be -mpi as well. If it game before something else like -game, then if the previous
// argument was -mpi and the current argument was something valid like -game, it would skip it.
@ -980,6 +993,7 @@ int ParseCommandLine( int argc, char **argv )
if ( i == argc - 1 )
break;
}
#endif
else if (argv[i][0] == '-')
{
Warning("VBSP: Unknown option \"%s\"\n\n", argv[i]);
@ -1016,8 +1030,10 @@ void PrintUsage( int argc, char **argv )
"\n"
" -v (or -verbose): Turn on verbose output (also shows more command\n"
" -fast : Only do first quick pass on vis calculations.\n"
#ifdef _WIN32
" -mpi : Use VMPI to distribute computations.\n"
" -low : Run as an idle-priority process.\n"
#endif
" env_fog_controller specifies one.\n"
"\n"
" -vproject <directory> : Override the VPROJECT environment variable.\n"
@ -1026,14 +1042,18 @@ void PrintUsage( int argc, char **argv )
"Other options:\n"
" -novconfig : Don't bring up graphical UI on vproject errors.\n"
" -radius_override: Force a vis radius, regardless of whether an\n"
#ifdef _WIN32
" -mpi_pw <pw> : Use a password to choose a specific set of VMPI workers.\n"
#endif
" -threads : Control the number of threads vbsp uses (defaults to the #\n"
" or processors on your machine).\n"
" -nosort : Don't sort portals (sorting is an optimization).\n"
" -tmpin : Make portals come from \\tmp\\<mapname>.\n"
" -tmpout : Make portals come from \\tmp\\<mapname>.\n"
" -trace <start cluster> <end cluster> : Writes a linefile that traces the vis from one cluster to another for debugging map vis.\n"
#ifdef _WIN32
" -FullMinidumps : Write large minidumps on crash.\n"
#endif
" -x360 : Generate Xbox360 version of vsp\n"
" -nox360 : Disable generation Xbox360 version of vsp (default)\n"
"\n"
@ -1070,7 +1090,7 @@ void PrintUsage( int argc, char **argv )
int RunVVis( int argc, char **argv )
{
char portalfile[1024];
char portalfile[1024];
char source[1024];
char mapFile[1024];
double start, end;
@ -1109,7 +1129,7 @@ int RunVVis( int argc, char **argv )
start = Plat_FloatTime();
#ifdef _WIN32
if (!g_bUseMPI)
{
// Setup the logfile.
@ -1123,6 +1143,7 @@ int RunVVis( int argc, char **argv )
{
SetLowPriority();
}
#endif
ThreadSetDefault ();
@ -1187,10 +1208,12 @@ int RunVVis( int argc, char **argv )
{
Error("Invalid cluster trace: %d to %d, valid range is 0 to %d\n", g_TraceClusterStart, g_TraceClusterStop, portalclusters-1 );
}
#ifdef _WIN32
if ( g_bUseMPI )
{
Warning("Can't compile trace in MPI mode\n");
}
#endif
CalcVisTrace ();
WritePortalTrace(source);
}
@ -1203,7 +1226,9 @@ int RunVVis( int argc, char **argv )
ReleasePakFileLumps();
DeleteCmdLine( argc, argv );
#ifdef _WIN32
CmdLib_Cleanup();
#endif
return 0;
}
@ -1218,6 +1243,7 @@ int main (int argc, char **argv)
CommandLine()->CreateCmdLine( argc, argv );
MathLib_Init( 2.2f, 2.2f, 0.0f, 1.0f, false, false, false, false );
#ifdef _WIN32
InstallAllocationFunctions();
InstallSpewFunction();
@ -1228,6 +1254,7 @@ int main (int argc, char **argv)
SetupToolsMinidumpHandler( VMPI_ExceptionFilter );
else
SetupDefaultToolsMinidumpHandler();
#endif
return RunVVis( argc, argv );
}

79
utils/vvis/wscript Executable file
View File

@ -0,0 +1,79 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vvis'
def options(opt):
# stub
return
def configure(conf):
conf.define('PROTECTED_THINGS_DISABLE', 1)
return
def build(bld):
source = [
'WaterDist.cpp',
'flow.cpp',
'vvis.cpp',
'../common/bsplib.cpp',
'../common/cmdlib.cpp',
'../common/scriplib.cpp',
'../common/filesystem_tools.cpp',
'../common/pacifier.cpp',
'../common/threads.cpp',
'../../public/collisionutils.cpp',
'../../public/filesystem_helpers.cpp',
'../../public/filesystem_init.cpp',
'../../public/loadcmdline.cpp',
'../../public/lumpfiles.cpp',
'../../public/zip_utils.cpp',
'../../filesystem/linux_support.cpp',
]
if bld.env.DEST_OS == 'win32':
source += [
'mpivis.cpp',
'../common/mpi_stats.cpp',
'../common/MySqlDatabase.cpp',
'../common/tools_minidump.cpp',
'../common/vmpi_tools_shared.cpp',
'../common/scratchpad_helpers.cpp',
'../../public/scratchpad3d.cpp',
]
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
'../../public/tier3',
'../../public/mathlib'
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'tier3', 'mathlib', 'lzma', 'vstdlib']
install_path = bld.env.LIBDIR
bld.shlib(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -8,14 +8,18 @@
// vvis_launcher.cpp : Defines the entry point for the console application.
//
#ifdef _WIN32
#include "stdafx.h"
#include <direct.h>
#else
#include <dlfcn.h>
#endif
#include "tier1/interface.h"
#include "tier1/strtools.h"
#include "tier0/icommandline.h"
#include "ilaunchabledll.h"
#ifdef _WIN32
char* GetLastErrorString()
{
static char err[2048];
@ -40,12 +44,15 @@ char* GetLastErrorString()
return err;
}
#elif defined(POSIX)
#define GetLastErrorString dlerror
#endif
int main(int argc, char* argv[])
{
CommandLine()->CreateCmdLine( argc, argv );
const char *pDLLName = "vvis_dll.dll";
const char *pDLLName = "vvis" DLL_EXT_STRING;
CSysModule *pModule = Sys_LoadModule( pDLLName );
if ( !pModule )

53
utils/vvis_launcher/wscript Executable file
View File

@ -0,0 +1,53 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'vvis_launcher'
def options(opt):
# stub
return
def configure(conf):
return
def build(bld):
source = [
'vvis_launcher.cpp'
]
includes = [
'.',
'../common',
'../../public',
'../../public/tier0',
'../../public/tier1',
'../../public/tier2',
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'vvis']
if bld.env.DEST_OS != 'win32':
libs += ['DL', 'LOG']
install_path = bld.env.BINDIR
bld(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx cxxprogram',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

53
utils/xbox/xbspinfo/wscript Executable file
View File

@ -0,0 +1,53 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
from waflib import Utils
import os
top = '.'
PROJECT_NAME = 'xbspinfo'
def options(opt):
# stub
return
def configure(conf):
conf.define('DONT_PROTECT_FILEIO_FUNCTIONS', 1)
return
def build(bld):
source = [
'xbspinfo.cpp'
]
includes = [
'.',
'../../common',
'../../../public',
'../../../public/tier0',
'../../../public/tier1',
]
defines = []
libs = ['tier0', 'tier1', 'tier2', 'tier3', 'lzma', 'mathlib']
if bld.env.DEST_OS != 'win32':
libs += ['DL', 'LOG']
install_path = bld.env.BINDIR
bld(
source = source,
target = PROJECT_NAME,
name = PROJECT_NAME,
features = 'c cxx cxxprogram',
includes = includes,
defines = defines,
use = libs,
install_path = install_path,
subsystem = bld.env.MSVC_SUBSYSTEM,
idx = bld.get_taskgen_count()
)

View File

@ -17,7 +17,7 @@ BEGIN_BYTESWAP_DATADESC( lump_t )
DEFINE_FIELD( fileofs, FIELD_INTEGER ),
DEFINE_FIELD( filelen, FIELD_INTEGER ),
DEFINE_FIELD( version, FIELD_INTEGER ),
DEFINE_ARRAY( fourCC, FIELD_CHARACTER, 4 ),
// DEFINE_ARRAY( fourCC, FIELD_CHARACTER, 4 ),
END_BYTESWAP_DATADESC()
typedef struct
@ -267,6 +267,7 @@ void DumpInfo( const char *pFilename, void *pBSPFile, int bspSize )
bool LoadBSPFile( const char* pFilename, void **ppBSPBuffer, int *pBSPSize )
{
CByteswap byteSwap;
dheader_t *pBSPHeader;
*ppBSPBuffer = NULL;
*pBSPSize = 0;
@ -298,7 +299,7 @@ bool LoadBSPFile( const char* pFilename, void **ppBSPBuffer, int *pBSPSize )
goto cleanUp;
}
dheader_t *pBSPHeader = (dheader_t *)*ppBSPBuffer;
pBSPHeader = (dheader_t *)*ppBSPBuffer;
if ( pBSPHeader->ident != IDBSPHEADER )
{
@ -327,7 +328,7 @@ bool LoadBSPFile( const char* pFilename, void **ppBSPBuffer, int *pBSPSize )
goto cleanUp;
}
// sucess
// success
return true;
cleanUp:
@ -427,4 +428,4 @@ int main( int argc, char* argv[] )
}
return ( 0 );
}
}

View File

@ -6,22 +6,25 @@
#pragma once
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#include <io.h>
#include <sys/utime.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utime.h>
#include "icommandline.h"
#include "tier0/icommandline.h"
#include "tier1/strtools.h"
#include "tier1/utlvector.h"
#include "tier1/utlbuffer.h"
#include "tier1/utlstring.h"
#include "tier1/byteswap.h"
#include "datamap.h"
#include "byteswap.h"
#include "../../common/bsplib.h"
#include "bsplib.h"

210
wscript
View File

@ -1,5 +1,6 @@
#! /usr/bin/env python
# encoding: utf-8
# vim: noexpandtab
# nillerusr
from __future__ import print_function
@ -29,8 +30,18 @@ int main() { return (int)FcInit(); }
Context.Context.line_just = 55 # should fit for everything on 80x26
projects={
'game': [
'base': [
'appframework',
'filesystem',
'tier0',
'tier1',
'tier2',
'tier3',
'mathlib',
'vstdlib',
'vpklib',
],
'main': [
'bitmap',
'choreoobjects',
'datacache',
@ -38,7 +49,6 @@ projects={
'dmxloader',
'engine',
'engine/voice_codecs/minimp3',
'filesystem',
'game/client',
'game/server',
'gameui',
@ -55,17 +65,12 @@ projects={
'materialsystem/shaderapidx9',
'materialsystem/shaderlib',
'materialsystem/stdshaders',
'mathlib',
'particles',
'scenefilecache',
'serverbrowser',
'soundemittersystem',
'studiorender',
'thirdparty/StubSteamAPI',
'tier0',
'tier1',
'tier2',
'tier3',
'vgui2/matsys_controls',
'vgui2/src',
'vgui2/vgui_controls',
@ -73,24 +78,13 @@ projects={
'vguimatsurface',
'video',
'vphysics',
'vpklib',
'vstdlib',
'vtf',
'utils/vtex',
'unicode',
'video',
],
'tests': [
'appframework',
'tier0',
'tier1',
'tier2',
'tier3',
'unitlib',
'mathlib',
'vstdlib',
'filesystem',
'vpklib',
'unittests/tier0test',
'unittests/tier1test',
'unittests/tier2test',
@ -99,7 +93,6 @@ projects={
'utils/unittest'
],
'dedicated': [
'appframework',
'bitmap',
'choreoobjects',
'datacache',
@ -114,23 +107,42 @@ projects={
'ivp/ivp_compact_builder',
'ivp/ivp_physics',
'materialsystem',
'mathlib',
'particles',
'scenefilecache',
'materialsystem/shaderapiempty',
'materialsystem/shaderlib',
'soundemittersystem',
'studiorender',
'tier0',
'tier1',
'tier2',
'tier3',
'vphysics',
'vpklib',
'vstdlib',
'vtf',
'thirdparty/StubSteamAPI'
]
],
'utils': [
'bitmap',
'vtf',
'fgdlib',
'raytrace',
'vphysics',
'ivp/havana',
'ivp/havana/havok/hk_base',
'ivp/havana/havok/hk_math',
'ivp/ivp_compact_builder',
'ivp/ivp_physics',
'materialsystem',
'materialsystem/shaderapiempty',
'materialsystem/shaderlib',
'utils/vtex',
'utils/lzma',
'utils/bsppack',
'utils/vbspinfo',
'utils/xbox/xbspinfo',
'utils/vvis',
'utils/vvis_launcher',
'utils/vrad',
'utils/vrad_launcher',
'utils/vbsp',
'utils/vpk',
],
}
@Configure.conf
@ -156,38 +168,49 @@ def get_taskgen_count(self):
return idx
def define_platform(conf):
conf.env.DEDICATED = conf.options.DEDICATED
conf.env.TESTS = conf.options.TESTS
conf.env.TOGLES = conf.options.TOGLES
conf.env.GL = conf.options.GL and not conf.options.TESTS and not conf.options.DEDICATED
conf.env.OPUS = conf.options.OPUS
if conf.options.ALLOW64:
conf.define('PLATFORM_64BITS', 1)
conf.env.projects = ['base']
conf.env.targets = []
if conf.options.DEDICATED:
conf.env.DEDICATED = True
conf.env.projects += ['dedicated']
conf.options.SDL = False
conf.define('DEDICATED', 1)
if conf.options.TESTS:
conf.define('UNITTESTS', 1)
if conf.options.LAUNCHER:
conf.env.projects += ['main']
if conf.options.GL:
conf.env.GL = True
conf.env.targets += ['togl']
conf.env.append_unique('DEFINES', [
'DX_TO_GL_ABSTRACTION',
'GL_GLEXT_PROTOTYPES',
'BINK_VIDEO'
])
elif conf.options.TOGLES:
conf.env.TOGLES = True
conf.env.targets += ['togles']
conf.env.append_unique('DEFINES', ['TOGLES'])
if conf.env.GL:
conf.env.append_unique('DEFINES', [
'DX_TO_GL_ABSTRACTION',
'GL_GLEXT_PROTOTYPES',
'BINK_VIDEO'
])
if conf.options.TOGLES:
conf.env.append_unique('DEFINES', ['TOGLES'])
if conf.options.SDL:
conf.env.SDL = True
conf.define('USE_SDL', 1)
if conf.options.TESTS:
conf.env.TESTS = True
conf.env.projects += ['tests']
conf.define('UNITTESTS', 1)
if conf.options.SDL and not conf.options.TESTS:
conf.env.SDL = 1
conf.define('USE_SDL', 1)
if conf.options.UTILS:
conf.env.projects += ['utils']
if conf.options.ALLOW64:
conf.define('PLATFORM_64BITS', 1)
if conf.env.DEST_OS == 'win32' and not conf.env.TESTS:
conf.env.targets += ['utils/bzip2']
if conf.options.OPUS or conf.env.DEST_OS == 'android' and conf.env.LAUNCHER:
conf.env.OPUS = True
conf.env.targets += ['engine/voice_codecs/opus']
if conf.env.DEST_OS == 'linux':
conf.define('_GLIBCXX_USE_CXX11_ABI',0)
@ -252,42 +275,55 @@ def options(opt):
grp = opt.add_option_group('Common options')
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
help = 'allow targetting 64-bit engine(Linux/Windows/OSX x86 only) [default: %default]')
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
help = 'build dedicated server [default: %default]')
grp.add_option('--tests', action = 'store_true', dest = 'TESTS', default = False,
help = 'build unit tests [default: %default]')
help = 'allow targetting 64-bit engine [default: %default]')
grp.add_option('-D', '--debug-engine', action = 'store_true', dest = 'DEBUG_ENGINE', default = False,
help = 'build with -DDEBUG [default: %default]')
grp.add_option('--use-sdl', action = 'store', dest = 'SDL', type = 'int', default = sys.platform != 'win32',
help = 'build engine with SDL [default: %default]')
if sys.platform == 'win32':
grp.add_option('--use-sdl', action = 'store_true', dest = 'SDL', default = False,
help = 'build engine with SDL [default: %default]')
grp.add_option('--use-togl', action = 'store_true', dest = 'SDL', default = False,
help = 'build engine with ToGL [default: %default]')
else:
grp.add_option('--no-sdl', action = 'store_false', dest = 'SDL', default = True,
help = 'build engine with SDL [default: %default]')
grp.add_option('--no-togl', action = 'store_false', dest = 'GL', default = True,
help = 'build engine with ToGL [default: %default]')
grp.add_option('--use-togl', action = 'store', dest = 'GL', type = 'int', default = sys.platform != 'win32',
help = 'build engine with ToGL [default: %default]')
grp.add_option('--build-games', action = 'store', dest = 'GAMES', type = 'string', default = 'hl2',
help = 'build games [default: %default]')
grp.add_option('--use-togles', action = 'store_true', dest = 'TOGLES', default = False,
help = 'build engine with ToGLES [default: %default]')
grp.add_option('--use-ccache', action = 'store_true', dest = 'CCACHE', default = False,
help = 'build using ccache [default: %default]')
grp.add_option('--disable-warns', action = 'store_true', dest = 'DISABLE_WARNS', default = False,
help = 'build using ccache [default: %default]')
grp.add_option('--no-warns', action = 'store_true', dest = 'DISABLE_WARNS', default = False,
help = 'build without warnings [default: %default]')
grp.add_option('--togles', action = 'store_true', dest = 'TOGLES', default = False,
help = 'build engine with ToGLES [default: %default]')
grp.add_option('--build-games', action = 'store', dest = 'GAMES', type = 'string', default = 'hl2',
help = 'build games [default: %default]')
# TODO(nillerusr): add wscript for opus building
grp.add_option('--enable-opus', action = 'store_true', dest = 'OPUS', default = False,
grp.add_option('--use-opus', action = 'store_true', dest = 'OPUS', default = False,
help = 'build engine with Opus voice codec [default: %default]')
grp.add_option('--sanitize', action = 'store', dest = 'SANITIZE', default = '',
help = 'build with sanitizers [default: %default]')
targ = opt.add_option_group('Targets options')
targ.add_option('-d', '--use-dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
help = 'build dedicated server [default: %default]')
targ.add_option('-l', '--no-launcher', action = 'store_false', dest = 'LAUNCHER', default = True,
help = 'build launcher [default: %default]')
targ.add_option('-t', '--use-tests', action = 'store_true', dest = 'TESTS', default = False,
help = 'build unit tests [default: %default]')
targ.add_option('-u', '--use-utils', action = 'store_true', dest = 'UTILS', default = False,
help = 'build Valve utilities such as vbsp, vrad, vvis [default: %default]')
opt.load('compiler_optimizations subproject')
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install_v2 waf_unit_test subproject')
@ -420,17 +456,6 @@ def configure(conf):
define_platform(conf)
conf.define('GIT_COMMIT_HASH', conf.env.GIT_VERSION)
if conf.env.TOGLES:
projects['game'] += ['togles']
elif conf.env.GL:
projects['game'] += ['togl']
if conf.env.DEST_OS == 'win32':
projects['game'] += ['utils/bzip2']
projects['dedicated'] += ['utils/bzip2']
if conf.options.OPUS or conf.env.DEST_OS == 'android':
projects['game'] += ['engine/voice_codecs/opus']
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64
if conf.env.BIT32_MANDATORY:
Logs.info('WARNING: will build engine for 32-bit target')
@ -583,12 +608,8 @@ def configure(conf):
conf.env.CC.insert(0, 'ccache')
conf.env.CXX.insert(0, 'ccache')
if conf.options.TESTS:
conf.add_subproject(projects['tests'])
elif conf.options.DEDICATED:
conf.add_subproject(projects['dedicated'])
else:
conf.add_subproject(projects['game'])
for proj in conf.env.projects:
conf.add_subproject(projects[proj])
def build(bld):
os.environ["CCACHE_DIR"] = os.path.abspath('.ccache/'+bld.env.COMPILER_CC+'/'+bld.env.DEST_OS+'/'+bld.env.DEST_CPU)
@ -598,21 +619,8 @@ def build(bld):
sdl_path = os.path.join('lib', bld.env.DEST_OS, bld.env.DEST_CPU, sdl_name)
bld.install_files(bld.env.LIBDIR, [sdl_path])
if bld.env.DEST_OS == 'win32':
projects['game'] += ['utils/bzip2']
projects['dedicated'] += ['utils/bzip2']
for proj in bld.env.projects:
bld.add_subproject(projects[proj])
for targ in bld.env.targets:
bld.add_subproject(targ)
if bld.env.OPUS or bld.env.DEST_OS == 'android':
projects['game'] += ['engine/voice_codecs/opus']
if bld.env.TESTS:
bld.add_subproject(projects['tests'])
elif bld.env.DEDICATED:
bld.add_subproject(projects['dedicated'])
else:
if bld.env.TOGLES:
projects['game'] += ['togles']
elif bld.env.GL:
projects['game'] += ['togl']
bld.add_subproject(projects['game'])