mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-16 05:37:00 +00:00
1
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,106 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// IHVTEST1.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR "..\.."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin\unittests"
|
||||
|
||||
$Include "$SRCDIR\vpc_scripts\source_exe_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\game\shared"
|
||||
$PreprocessorDefinitions "$BASE;IHVTEST"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "ihvtest1"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "$SRCDIR\public\bone_setup.cpp"
|
||||
$File "$SRCDIR\public\collisionutils.cpp"
|
||||
$File "ihvtest1.cpp"
|
||||
$File "$SRCDIR\public\studio.cpp"
|
||||
$File "sys_clock.cpp" [$WIN32]
|
||||
}
|
||||
|
||||
$Folder "Public Header Files"
|
||||
{
|
||||
$File "$SRCDIR\public\mathlib\amd3dx.h"
|
||||
$File "$SRCDIR\public\basehandle.h"
|
||||
$File "$SRCDIR\public\tier0\basetypes.h"
|
||||
$File "$SRCDIR\public\bitvec.h"
|
||||
$File "$SRCDIR\public\bone_accessor.h"
|
||||
$File "$SRCDIR\public\bone_setup.h"
|
||||
$File "$SRCDIR\public\bspflags.h"
|
||||
$File "$SRCDIR\public\clientstats.h"
|
||||
$File "$SRCDIR\public\cmodel.h"
|
||||
$File "$SRCDIR\public\CollisionUtils.h"
|
||||
$File "$SRCDIR\public\tier0\commonmacros.h"
|
||||
$File "$SRCDIR\public\mathlib\compressed_vector.h"
|
||||
$File "$SRCDIR\public\const.h"
|
||||
$File "$SRCDIR\public\tier0\dbg.h"
|
||||
$File "$SRCDIR\public\tier0\fasttimer.h"
|
||||
$File "$SRCDIR\public\filesystem.h"
|
||||
$File "$SRCDIR\public\gametrace.h"
|
||||
$File "$SRCDIR\public\appframework\IAppSystem.h"
|
||||
$File "$SRCDIR\public\tier0\icommandline.h"
|
||||
$File "$SRCDIR\public\ihandleentity.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterialproxyfactory.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterialsystem.h"
|
||||
$File "$SRCDIR\public\materialsystem\imaterialsystemhardwareconfig.h"
|
||||
$File "$SRCDIR\public\tier1\interface.h"
|
||||
$File "$SRCDIR\public\istudiorender.h"
|
||||
$File "$SRCDIR\public\materialsystem\materialsystem_config.h"
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
$File "$SRCDIR\public\tier0\mem.h"
|
||||
$File "$SRCDIR\public\tier0\memalloc.h"
|
||||
$File "$SRCDIR\public\tier0\memdbgon.h"
|
||||
$File "$SRCDIR\public\tier0\platform.h"
|
||||
$File "$SRCDIR\public\tier0\protected_things.h"
|
||||
$File "$SRCDIR\public\vstdlib\random.h"
|
||||
$File "$SRCDIR\public\string_t.h"
|
||||
$File "$SRCDIR\public\tier1\strtools.h"
|
||||
$File "$SRCDIR\public\studio.h"
|
||||
$File "$SRCDIR\public\tier1\utlbuffer.h"
|
||||
$File "$SRCDIR\public\tier1\utldict.h"
|
||||
$File "$SRCDIR\public\tier1\utlmemory.h"
|
||||
$File "$SRCDIR\public\tier1\utlrbtree.h"
|
||||
$File "$SRCDIR\public\tier1\utlsymbol.h"
|
||||
$File "$SRCDIR\public\tier1\utlvector.h"
|
||||
$File "$SRCDIR\public\vcollide.h"
|
||||
$File "$SRCDIR\public\mathlib\vector.h"
|
||||
$File "$SRCDIR\public\mathlib\vector2d.h"
|
||||
$File "$SRCDIR\public\mathlib\vector4d.h"
|
||||
$File "$SRCDIR\public\tier0\vprof.h"
|
||||
$File "$SRCDIR\public\vstdlib\vstdlib.h"
|
||||
}
|
||||
|
||||
$Folder "Build Bat Files" [$0]
|
||||
{
|
||||
$File "copybin.bat"
|
||||
$File "copycommonsrc.bat"
|
||||
$File "copydx8.bat"
|
||||
$File "copygamesharedsrc.bat"
|
||||
$File "copyihvtestsrc.bat"
|
||||
$File "copylib.bat"
|
||||
$File "copymatsyssrc.bat"
|
||||
$File "copypublicsrc.bat"
|
||||
$File "copyshaderdx8src.bat"
|
||||
$File "copysrc.bat"
|
||||
$File "copystudiorendersrc.bat"
|
||||
}
|
||||
|
||||
$Folder "Link Libraries"
|
||||
{
|
||||
$Lib appframework
|
||||
$Lib mathlib
|
||||
$Lib $LIBCOMMON\vtuneapi [$WIN32&&!$VS2015]
|
||||
$Lib $SRCDIR\lib\common\vtuneapi [$WIN32&&$VS2015]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#pragma optimize( "", off )
|
||||
|
||||
#pragma pack( push, thing )
|
||||
#pragma pack( 4 )
|
||||
static long g_cw, g_single_cw, g_highchop_cw, g_full_cw, g_ceil_cw, g_pushed_cw;
|
||||
static struct
|
||||
{
|
||||
long dummy[8];
|
||||
} g_fpenv;
|
||||
#pragma pack( pop, thing )
|
||||
|
||||
|
||||
void __declspec ( naked ) MaskExceptions()
|
||||
{
|
||||
_asm
|
||||
{
|
||||
fnstenv ds:dword ptr[g_fpenv]
|
||||
or ds:dword ptr[g_fpenv],03Fh
|
||||
fldenv ds:dword ptr[g_fpenv]
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec ( naked ) Sys_SetFPCW()
|
||||
{
|
||||
_asm
|
||||
{
|
||||
fnstcw ds:word ptr[g_cw]
|
||||
mov eax,ds:dword ptr[g_cw]
|
||||
and ah,0F0h
|
||||
or ah,003h
|
||||
mov ds:dword ptr[g_full_cw],eax
|
||||
mov ds:dword ptr[g_highchop_cw],eax
|
||||
and ah,0F0h
|
||||
or ah,00Ch
|
||||
mov ds:dword ptr[g_single_cw],eax
|
||||
and ah,0F0h
|
||||
or ah,008h
|
||||
mov ds:dword ptr[g_ceil_cw],eax
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec ( naked ) Sys_PushFPCW_SetHigh()
|
||||
{
|
||||
_asm
|
||||
{
|
||||
fnstcw ds:word ptr[g_pushed_cw]
|
||||
fldcw ds:word ptr[g_full_cw]
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec ( naked ) Sys_PopFPCW()
|
||||
{
|
||||
_asm
|
||||
{
|
||||
fldcw ds:word ptr[g_pushed_cw]
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#pragma optimize( "", on )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Implements high precision clock
|
||||
// TODO: Make into an interface?
|
||||
//-----------------------------------------------------------------------------
|
||||
class CSysClock
|
||||
{
|
||||
public:
|
||||
// Construction
|
||||
CSysClock( void );
|
||||
|
||||
// Initialization
|
||||
void Init( void );
|
||||
void SetStartTime( void );
|
||||
|
||||
// Sample the clock
|
||||
double GetTime( void );
|
||||
|
||||
private:
|
||||
// High performance clock frequency
|
||||
double m_dClockFrequency;
|
||||
// Current accumulated time
|
||||
double m_dCurrentTime;
|
||||
// How many bits to shift raw 64 bit sample count by
|
||||
int m_nTimeSampleShift;
|
||||
// Previous 32 bit sample count
|
||||
unsigned int m_uiPreviousTime;
|
||||
|
||||
bool m_bInitialized;
|
||||
};
|
||||
|
||||
static CSysClock g_Clock;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
CSysClock::CSysClock( void )
|
||||
{
|
||||
m_bInitialized = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Initialize the clock
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSysClock::Init( void )
|
||||
{
|
||||
BOOL success;
|
||||
LARGE_INTEGER PerformanceFreq;
|
||||
unsigned int lowpart, highpart;
|
||||
|
||||
MaskExceptions ();
|
||||
Sys_SetFPCW ();
|
||||
|
||||
// Start clock at zero
|
||||
m_dCurrentTime = 0.0;
|
||||
|
||||
success = QueryPerformanceFrequency( &PerformanceFreq );
|
||||
assert( success );
|
||||
|
||||
// get 32 out of the 64 time bits such that we have around
|
||||
// 1 microsecond resolution
|
||||
lowpart = (unsigned int)PerformanceFreq.LowPart;
|
||||
highpart = (unsigned int)PerformanceFreq.HighPart;
|
||||
|
||||
m_nTimeSampleShift = 0;
|
||||
|
||||
while ( highpart || ( lowpart > 2000000.0 ) )
|
||||
{
|
||||
m_nTimeSampleShift++;
|
||||
lowpart >>= 1;
|
||||
lowpart |= (highpart & 1) << 31;
|
||||
highpart >>= 1;
|
||||
}
|
||||
|
||||
m_dClockFrequency = 1.0 / (double)lowpart;
|
||||
|
||||
// Get initial sample
|
||||
unsigned int temp;
|
||||
LARGE_INTEGER PerformanceCount;
|
||||
QueryPerformanceCounter( &PerformanceCount );
|
||||
if ( !m_nTimeSampleShift )
|
||||
{
|
||||
temp = (unsigned int)PerformanceCount.LowPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rotate counter to right by m_nTimeSampleShift places
|
||||
temp = ((unsigned int)PerformanceCount.LowPart >> m_nTimeSampleShift) |
|
||||
((unsigned int)PerformanceCount.HighPart << (32 - m_nTimeSampleShift));
|
||||
}
|
||||
|
||||
// Set first time stamp
|
||||
m_uiPreviousTime = temp;
|
||||
|
||||
m_bInitialized = true;
|
||||
|
||||
SetStartTime();
|
||||
}
|
||||
|
||||
void CSysClock::SetStartTime( void )
|
||||
{
|
||||
GetTime();
|
||||
|
||||
m_dCurrentTime = 0.0;
|
||||
|
||||
m_uiPreviousTime = ( unsigned int )m_dCurrentTime;
|
||||
}
|
||||
|
||||
double CSysClock::GetTime( void )
|
||||
{
|
||||
LARGE_INTEGER PerformanceCount;
|
||||
unsigned int temp, t2;
|
||||
double time;
|
||||
|
||||
if ( !m_bInitialized )
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Sys_PushFPCW_SetHigh();
|
||||
|
||||
// Get sample counter
|
||||
QueryPerformanceCounter( &PerformanceCount );
|
||||
|
||||
if ( !m_nTimeSampleShift )
|
||||
{
|
||||
temp = (unsigned int)PerformanceCount.LowPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rotate counter to right by m_nTimeSampleShift places
|
||||
temp = ((unsigned int)PerformanceCount.LowPart >> m_nTimeSampleShift) |
|
||||
((unsigned int)PerformanceCount.HighPart << (32 - m_nTimeSampleShift));
|
||||
}
|
||||
|
||||
// check for turnover or backward time
|
||||
if ( ( temp <= m_uiPreviousTime ) &&
|
||||
( ( m_uiPreviousTime - temp ) < 0x10000000) )
|
||||
{
|
||||
m_uiPreviousTime = temp; // so we can't get stuck
|
||||
}
|
||||
else
|
||||
{
|
||||
// gap in performance clocks
|
||||
t2 = temp - m_uiPreviousTime;
|
||||
|
||||
// Convert to time using frequencey of clock
|
||||
time = (double)t2 * m_dClockFrequency;
|
||||
|
||||
// Remember old time
|
||||
m_uiPreviousTime = temp;
|
||||
|
||||
// Increment clock
|
||||
m_dCurrentTime += time;
|
||||
}
|
||||
|
||||
Sys_PopFPCW();
|
||||
|
||||
// Convert to float
|
||||
return m_dCurrentTime;
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Sample the high-precision clock
|
||||
// Output : double
|
||||
//-----------------------------------------------------------------------------
|
||||
double Sys_FloatTime( void )
|
||||
{
|
||||
return g_Clock.GetTime();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Initialize high-precision clock
|
||||
//-----------------------------------------------------------------------------
|
||||
void Sys_InitFloatTime( void )
|
||||
{
|
||||
g_Clock.Init();
|
||||
}
|
||||
Reference in New Issue
Block a user