initial
This commit is contained in:
76
datacache/_vpc_/manifest_datacache/win32/manifest.txt
Normal file
76
datacache/_vpc_/manifest_datacache/win32/manifest.txt
Normal file
@@ -0,0 +1,76 @@
|
||||
// ----------------------------------------- //
|
||||
// File generated by VPC //
|
||||
// ----------------------------------------- //
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\datacache\datacache.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\datacache\datacache.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\datacache\datacache.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\utils\common\datalinker.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\utils\common\datalinker.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\utils\common\datalinker.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\common\debug_dll_check.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\datacache\mdlcache.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\datacache\mdlcache.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\datacache\mdlcache.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\datacache\mdlcombine.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\datacache\mdlcombine.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\datacache\mdlcombine.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\public\tier0\memoverride.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\datacache\precachesystem.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\datacache\precachesystem.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\datacache\precachesystem.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\datacache\resourceaccesscontrol.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\datacache\resourceaccesscontrol.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\datacache\resourceaccesscontrol.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\public\studio.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\public\studio.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\public\studio.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\public\studio_virtualmodel.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\public\studio_virtualmodel.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\public\studio_virtualmodel.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\common\studiobyteswap.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\common\studiobyteswap.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\common\studiobyteswap.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\datacache\vtfcombine.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\datacache\vtfcombine.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\datacache\vtfcombine.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
1535
datacache/datacache.cpp
Normal file
1535
datacache/datacache.cpp
Normal file
File diff suppressed because it is too large
Load Diff
391
datacache/datacache.h
Normal file
391
datacache/datacache.h
Normal file
@@ -0,0 +1,391 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef DATACACHE_H
|
||||
#define DATACACHE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "datamanager.h"
|
||||
#include "utlhash.h"
|
||||
#include "mempool.h"
|
||||
#include "tier0/tslist.h"
|
||||
#include "datacache_common.h"
|
||||
#include "tier3/tier3.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Data Cache class declarations
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDataCache;
|
||||
class CDataCacheSection;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct DataCacheItemData_t
|
||||
{
|
||||
const void * pItemData;
|
||||
unsigned size;
|
||||
DataCacheClientID_t clientId;
|
||||
CDataCacheSection * pSection;
|
||||
};
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
#define DC_NO_NEXT_LOCKED ((DataCacheItem_t *)-1)
|
||||
#define DC_MAX_THREADS_FRAMELOCKED 6
|
||||
|
||||
|
||||
struct DataCacheItem_t : DataCacheItemData_t
|
||||
{
|
||||
DataCacheItem_t( const DataCacheItemData_t &data )
|
||||
: DataCacheItemData_t( data ),
|
||||
hLRU( INVALID_MEMHANDLE )
|
||||
{
|
||||
memset( pNextFrameLocked, 0xff, sizeof(pNextFrameLocked) );
|
||||
}
|
||||
|
||||
static DataCacheItem_t *CreateResource( const DataCacheItemData_t &data ) { return new DataCacheItem_t(data); }
|
||||
static unsigned int EstimatedSize( const DataCacheItemData_t &data ) { return data.size; }
|
||||
void DestroyResource();
|
||||
DataCacheItem_t *GetData() { return this; }
|
||||
unsigned int Size() { return size; }
|
||||
|
||||
memhandle_t hLRU;
|
||||
DataCacheItem_t *pNextFrameLocked[DC_MAX_THREADS_FRAMELOCKED];
|
||||
|
||||
DECLARE_FIXEDSIZE_ALLOCATOR_MT(DataCacheItem_t);
|
||||
};
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
typedef CDataManager<DataCacheItem_t, DataCacheItemData_t, DataCacheItem_t *, CThreadFastMutex> CDataCacheLRU;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDataCacheSection
|
||||
//
|
||||
// Purpose: Implements a sub-section of the global cache. Subsections are
|
||||
// areas of the cache with thier own memory constraints and common
|
||||
// management.
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDataCacheSection : public IDataCacheSection
|
||||
{
|
||||
public:
|
||||
CDataCacheSection( CDataCache *pSharedCache, IDataCacheClient *pClient, const char *pszName );
|
||||
~CDataCacheSection();
|
||||
|
||||
IDataCache *GetSharedCache();
|
||||
IDataCacheClient *GetClient() { return m_pClient; }
|
||||
const char *GetName() { return szName; }
|
||||
|
||||
//--------------------------------------------------------
|
||||
// IDataCacheSection methods
|
||||
//--------------------------------------------------------
|
||||
virtual void SetLimits( const DataCacheLimits_t &limits );
|
||||
const DataCacheLimits_t &GetLimits();
|
||||
virtual void SetOptions( unsigned options );
|
||||
virtual void GetStatus( DataCacheStatus_t *pStatus, DataCacheLimits_t *pLimits = NULL );
|
||||
|
||||
inline unsigned GetNumBytes() { return m_status.nBytes; }
|
||||
inline unsigned GetNumItems() { return m_status.nItems; }
|
||||
|
||||
inline unsigned GetNumBytesLocked() { return m_status.nBytesLocked; }
|
||||
inline unsigned GetNumItemsLocked() { return m_status.nItemsLocked; }
|
||||
|
||||
inline unsigned GetNumBytesUnlocked() { return m_status.nBytes - m_status.nBytesLocked; }
|
||||
inline unsigned GetNumItemsUnlocked() { return m_status.nItems - m_status.nItemsLocked; }
|
||||
|
||||
virtual void EnsureCapacity( unsigned nBytes, unsigned nItems = 1 );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual bool Add( DataCacheClientID_t clientId, const void *pItemData, unsigned size, DataCacheHandle_t *pHandle );
|
||||
virtual bool AddEx( DataCacheClientID_t clientId, const void *pItemData, unsigned size, unsigned flags, DataCacheHandle_t *pHandle );
|
||||
virtual DataCacheHandle_t Find( DataCacheClientID_t clientId );
|
||||
virtual DataCacheRemoveResult_t Remove( DataCacheHandle_t handle, const void **ppItemData = NULL, unsigned *pItemSize = NULL, bool bNotify = false );
|
||||
virtual bool IsPresent( DataCacheHandle_t handle );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual void *Lock( DataCacheHandle_t handle );
|
||||
virtual int Unlock( DataCacheHandle_t handle );
|
||||
virtual void *Get( DataCacheHandle_t handle, bool bFrameLock = false );
|
||||
virtual void *GetNoTouch( DataCacheHandle_t handle, bool bFrameLock = false );
|
||||
virtual void GetAndLockMultiple( void **ppData, int nCount, DataCacheHandle_t *pHandles );
|
||||
virtual void LockMutex();
|
||||
virtual void UnlockMutex();
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual int BeginFrameLocking();
|
||||
virtual bool IsFrameLocking();
|
||||
virtual void *FrameLock( DataCacheHandle_t handle );
|
||||
virtual int EndFrameLocking();
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual int GetLockCount( DataCacheHandle_t handle );
|
||||
virtual int BreakLock( DataCacheHandle_t handle );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual int *GetFrameUnlockCounterPtr();
|
||||
int m_nFrameUnlockCounter;
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual bool Touch( DataCacheHandle_t handle );
|
||||
virtual bool Age( DataCacheHandle_t handle );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual unsigned Flush( bool bUnlockedOnly = true, bool bNotify = true );
|
||||
virtual unsigned Purge( unsigned nBytes );
|
||||
unsigned PurgeItems( unsigned nItems );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual void OutputReport( DataCacheReportType_t reportType = DC_SUMMARY_REPORT );
|
||||
|
||||
virtual void UpdateSize( DataCacheHandle_t handle, unsigned int nNewSize );
|
||||
|
||||
virtual unsigned int GetOptions();
|
||||
|
||||
private:
|
||||
friend void DataCacheItem_t::DestroyResource();
|
||||
|
||||
virtual void OnAdd( DataCacheClientID_t clientId, DataCacheHandle_t hCacheItem ) {}
|
||||
virtual DataCacheHandle_t DoFind( DataCacheClientID_t clientId );
|
||||
virtual void OnRemove( DataCacheClientID_t clientId ) {}
|
||||
|
||||
memhandle_t GetFirstUnlockedItem();
|
||||
memhandle_t GetFirstLockedItem();
|
||||
memhandle_t GetNextItem( memhandle_t );
|
||||
DataCacheItem_t *AccessItem( memhandle_t hCurrent );
|
||||
bool DiscardItem( memhandle_t hItem, DataCacheNotificationType_t type );
|
||||
bool DiscardItemData( DataCacheItem_t *pItem, DataCacheNotificationType_t type );
|
||||
void NoteAdd( int size );
|
||||
void NoteRemove( int size );
|
||||
void NoteLock( int size );
|
||||
void NoteUnlock( int size );
|
||||
void NoteSizeChanged( int oldSize, int newSize );
|
||||
|
||||
// for debugging only, under user cvar enabling, causes datacache stress flushing
|
||||
void ForceFlushDebug( bool bFlush );
|
||||
|
||||
struct FrameLock_t
|
||||
{
|
||||
int m_iLock;
|
||||
DataCacheItem_t *m_pFirst;
|
||||
int m_iThread;
|
||||
};
|
||||
//typedef CThreadLocal<FrameLock_t *> CThreadFrameLock;
|
||||
|
||||
CDataCacheLRU & m_LRU;
|
||||
FrameLock_t * m_FrameLocks[MAX_THREADS_SUPPORTED];
|
||||
DataCacheStatus_t m_status;
|
||||
DataCacheLimits_t m_limits;
|
||||
IDataCacheClient * m_pClient;
|
||||
unsigned m_options;
|
||||
CDataCache * m_pSharedCache;
|
||||
char szName[DC_MAX_CLIENT_NAME + 1];
|
||||
CTSSimpleList<FrameLock_t> m_FreeFrameLocks;
|
||||
|
||||
protected:
|
||||
CThreadFastMutex & m_mutex;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDataCacheSectionFastFind
|
||||
//
|
||||
// Purpose: A section variant that allows clients to have cache support tracking
|
||||
// efficiently (a true cache, not just an LRU)
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDataCacheSectionFastFind : public CDataCacheSection
|
||||
{
|
||||
public:
|
||||
CDataCacheSectionFastFind(CDataCache *pSharedCache, IDataCacheClient *pClient, const char *pszName )
|
||||
: CDataCacheSection( pSharedCache, pClient, pszName )
|
||||
{
|
||||
m_Handles.Init( 1024 );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual DataCacheHandle_t DoFind( DataCacheClientID_t clientId );
|
||||
virtual void OnAdd( DataCacheClientID_t clientId, DataCacheHandle_t hCacheItem );
|
||||
virtual void OnRemove( DataCacheClientID_t clientId );
|
||||
|
||||
CUtlHashFast<DataCacheHandle_t> m_Handles;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CDataCache
|
||||
//
|
||||
// Purpose: The global shared cache. Manages sections and overall budgets.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDataCache : public CTier3AppSystem< IDataCache >
|
||||
{
|
||||
typedef CTier3AppSystem< IDataCache > BaseClass;
|
||||
|
||||
public:
|
||||
CDataCache();
|
||||
|
||||
//--------------------------------------------------------
|
||||
// IAppSystem methods
|
||||
//--------------------------------------------------------
|
||||
virtual bool Connect( CreateInterfaceFn factory );
|
||||
virtual void Disconnect();
|
||||
virtual void *QueryInterface( const char *pInterfaceName );
|
||||
virtual InitReturnVal_t Init();
|
||||
virtual void Shutdown();
|
||||
|
||||
//--------------------------------------------------------
|
||||
// IDataCache methods
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual void SetSize( int nMaxBytes );
|
||||
virtual void SetOptions( unsigned options );
|
||||
virtual void SetSectionLimits( const char *pszSectionName, const DataCacheLimits_t &limits );
|
||||
virtual void GetStatus( DataCacheStatus_t *pStatus, DataCacheLimits_t *pLimits = NULL );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual IDataCacheSection *AddSection( IDataCacheClient *pClient, const char *pszSectionName, const DataCacheLimits_t &limits = DataCacheLimits_t(), bool bSupportFastFind = false );
|
||||
virtual void RemoveSection( const char *pszClientName, bool bCallFlush = true );
|
||||
virtual IDataCacheSection *FindSection( const char *pszClientName );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
void EnsureCapacity( unsigned nBytes );
|
||||
virtual unsigned Purge( unsigned nBytes );
|
||||
virtual unsigned Flush( bool bUnlockedOnly = true, bool bNotify = true );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
virtual void OutputReport( DataCacheReportType_t reportType = DC_SUMMARY_REPORT, const char *pszSection = NULL );
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
inline unsigned GetNumBytes() { return m_status.nBytes; }
|
||||
inline unsigned GetNumItems() { return m_status.nItems; }
|
||||
|
||||
inline unsigned GetNumBytesLocked() { return m_status.nBytesLocked; }
|
||||
inline unsigned GetNumItemsLocked() { return m_status.nItemsLocked; }
|
||||
|
||||
inline unsigned GetNumBytesUnlocked() { return m_status.nBytes - m_status.nBytesLocked; }
|
||||
inline unsigned GetNumItemsUnlocked() { return m_status.nItems - m_status.nItemsLocked; }
|
||||
|
||||
virtual int GetSectionCount( void );
|
||||
virtual const char *GetSectionName( int iIndex );
|
||||
|
||||
private:
|
||||
//-----------------------------------------------------
|
||||
|
||||
friend class CDataCacheSection;
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
DataCacheItem_t *AccessItem( memhandle_t hCurrent );
|
||||
|
||||
bool IsInFlush() { return m_bInFlush; }
|
||||
int FindSectionIndex( const char *pszSection );
|
||||
|
||||
// Utilities used by the data cache report
|
||||
void OutputItemReport( memhandle_t hItem, void *pXboxData = NULL );
|
||||
static bool SortMemhandlesBySizeLessFunc( const memhandle_t& lhs, const memhandle_t& rhs );
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
CDataCacheLRU m_LRU;
|
||||
DataCacheStatus_t m_status;
|
||||
CUtlVector<CDataCacheSection *> m_Sections;
|
||||
bool m_bInFlush;
|
||||
CThreadFastMutex & m_mutex;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
extern CDataCache g_DataCache;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline DataCacheItem_t *CDataCache::AccessItem( memhandle_t hCurrent )
|
||||
{
|
||||
return m_LRU.GetResource_NoLockNoLRUTouch( hCurrent );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline IDataCache *CDataCacheSection::GetSharedCache()
|
||||
{
|
||||
return m_pSharedCache;
|
||||
}
|
||||
|
||||
inline DataCacheItem_t *CDataCacheSection::AccessItem( memhandle_t hCurrent )
|
||||
{
|
||||
return m_pSharedCache->AccessItem( hCurrent );
|
||||
}
|
||||
|
||||
// Note: if status updates are moved out of a mutexed section, will need to change these to use interlocked instructions
|
||||
|
||||
inline void CDataCacheSection::NoteSizeChanged( int oldSize, int newSize )
|
||||
{
|
||||
int nBytes = ( newSize - oldSize );
|
||||
|
||||
m_status.nBytes += nBytes;
|
||||
m_status.nBytesLocked += nBytes;
|
||||
ThreadInterlockedExchangeAdd( &m_pSharedCache->m_status.nBytes, nBytes );
|
||||
ThreadInterlockedExchangeAdd( &m_pSharedCache->m_status.nBytesLocked, nBytes );
|
||||
}
|
||||
|
||||
inline void CDataCacheSection::NoteAdd( int size )
|
||||
{
|
||||
m_status.nBytes += size;
|
||||
m_status.nItems++;
|
||||
|
||||
ThreadInterlockedExchangeAdd( &m_pSharedCache->m_status.nBytes, size );
|
||||
ThreadInterlockedIncrement( &m_pSharedCache->m_status.nItems );
|
||||
}
|
||||
|
||||
inline void CDataCacheSection::NoteRemove( int size )
|
||||
{
|
||||
m_status.nBytes -= size;
|
||||
m_status.nItems--;
|
||||
|
||||
ThreadInterlockedExchangeAdd( &m_pSharedCache->m_status.nBytes, -size );
|
||||
ThreadInterlockedDecrement( &m_pSharedCache->m_status.nItems );
|
||||
}
|
||||
|
||||
inline void CDataCacheSection::NoteLock( int size )
|
||||
{
|
||||
m_status.nBytesLocked += size;
|
||||
m_status.nItemsLocked++;
|
||||
|
||||
ThreadInterlockedExchangeAdd( &m_pSharedCache->m_status.nBytesLocked, size );
|
||||
ThreadInterlockedIncrement( &m_pSharedCache->m_status.nItemsLocked );
|
||||
}
|
||||
|
||||
inline void CDataCacheSection::NoteUnlock( int size )
|
||||
{
|
||||
m_status.nBytesLocked -= size;
|
||||
m_status.nItemsLocked--;
|
||||
|
||||
ThreadInterlockedExchangeAdd( &m_pSharedCache->m_status.nBytesLocked, -size );
|
||||
ThreadInterlockedDecrement( &m_pSharedCache->m_status.nItemsLocked );
|
||||
|
||||
// something has been unlocked, assume cached pointers are now invalid
|
||||
m_nFrameUnlockCounter++;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // DATACACHE_H
|
||||
73
datacache/datacache.vpc
Normal file
73
datacache/datacache.vpc
Normal file
@@ -0,0 +1,73 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// DATACACHE.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$macro SRCDIR ".."
|
||||
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Linker [!$PS3]
|
||||
{
|
||||
$SystemLibraries "iconv" [$OSXALL]
|
||||
}
|
||||
$Linker [$WINDOWS]
|
||||
{
|
||||
$AdditionalDependencies "$BASE libedgegeomtool.Release.Win32.vs8.lib" [$PS3SDKINSTALLED]
|
||||
$AdditionalLibraryDirectories "$BASE;$SRCDIR\ps3sdk\cell\host-win32\lib" [$PS3SDKINSTALLED]
|
||||
}
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,$SRCDIR\ps3sdk\cell\host-common\include,$SRCDIR\ps3sdk\cell\target\common\include" [$PS3SDKINSTALLED]
|
||||
$PreprocessorDefinitions "$BASE;MDLCACHE_DLL_EXPORT"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$Project "datacache"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "datacache.cpp"
|
||||
$File "mdlcache.cpp"
|
||||
$File "mdlcombine.cpp"
|
||||
$File "vtfcombine.cpp"
|
||||
$File "resourceaccesscontrol.cpp"
|
||||
$File "precachesystem.cpp"
|
||||
$File "$SRCDIR\public\studio.cpp"
|
||||
$File "$SRCDIR\public\studio_virtualmodel.cpp"
|
||||
$File "$SRCDIR\common\studiobyteswap.cpp"
|
||||
$File "$SRCDIR\utils\common\datalinker.cpp"
|
||||
}
|
||||
|
||||
$Folder "Header Files"
|
||||
{
|
||||
$File "datacache.h"
|
||||
$File "datacache_common.h"
|
||||
$File "mdlcombine.h"
|
||||
$File "vtfcombine.h"
|
||||
$File "$SRCDIR\public\studio.h"
|
||||
$File "$SRCDIR\common\studiobyteswap.h"
|
||||
$File "$SRCDIR\utils\common\datalinker.h"
|
||||
}
|
||||
|
||||
$Folder "Interface"
|
||||
{
|
||||
$File "$SRCDIR\public\datacache\idatacache.h"
|
||||
$File "$SRCDIR\public\datacache\imdlcache.h"
|
||||
$File "$SRCDIR\public\datacache\iresourceaccesscontrol.h"
|
||||
$File "$SRCDIR\public\datacache\iprecachesystem.h"
|
||||
$File "$SRCDIR\public\vcollide.h"
|
||||
}
|
||||
|
||||
$folder "Link Libraries"
|
||||
{
|
||||
$lib tier2
|
||||
$lib tier3
|
||||
$Lib mathlib
|
||||
}
|
||||
}
|
||||
13
datacache/datacache.vpc.vpc_cache
Normal file
13
datacache/datacache.vpc.vpc_cache
Normal file
@@ -0,0 +1,13 @@
|
||||
"vpc_cache"
|
||||
{
|
||||
"CacheVersion" "1"
|
||||
"win32"
|
||||
{
|
||||
"CRCFile" "datacache.vcxproj.vpc_crc"
|
||||
"OutputFiles"
|
||||
{
|
||||
"0" "datacache.vcxproj"
|
||||
"1" "datacache.vcxproj.filters"
|
||||
}
|
||||
}
|
||||
}
|
||||
29
datacache/datacache_common.h
Normal file
29
datacache/datacache_common.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef DATACACHE_COMMON_H
|
||||
#define DATACACHE_COMMON_H
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier3/tier3.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
class IDataCacheSection;
|
||||
FORWARD_DECLARE_HANDLE( memhandle_t );
|
||||
typedef memhandle_t DataCacheHandle_t;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Console commands
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // DATACACHE_COMMON_H
|
||||
5807
datacache/mdlcache.cpp
Normal file
5807
datacache/mdlcache.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2893
datacache/mdlcombine.cpp
Normal file
2893
datacache/mdlcombine.cpp
Normal file
File diff suppressed because it is too large
Load Diff
313
datacache/mdlcombine.h
Normal file
313
datacache/mdlcombine.h
Normal file
@@ -0,0 +1,313 @@
|
||||
//========= Copyright c 1996-2011, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//====================================================================================//
|
||||
|
||||
#ifndef __MDLCOMBINE_H
|
||||
#define __MDLCOMBINE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "utlbuffer.h"
|
||||
|
||||
|
||||
struct studiohdr2_t;
|
||||
struct studiodata_t;
|
||||
struct mstudiobone_t;
|
||||
struct mstudioanimdesc_t;
|
||||
struct mstudiomodel_t;
|
||||
class CModelCombine;
|
||||
class KeyValues;
|
||||
|
||||
|
||||
namespace OptimizedModel
|
||||
{
|
||||
struct StripGroupHeader_t;
|
||||
struct StripHeader_t;
|
||||
struct MeshHeader_t;
|
||||
struct ModelLODHeader_t;
|
||||
struct ModelHeader_t;
|
||||
struct BodyPartHeader_t;
|
||||
}
|
||||
|
||||
|
||||
//#define DEBUG_COMBINE 1
|
||||
|
||||
|
||||
#define COMBINER_MAX_STRINGS 2000
|
||||
#define COMBINER_MAX_BONES ( 53 * 2 )
|
||||
#define COMBINER_MAX_SUB_MODELS 20
|
||||
#define COMBINER_WORK_BUFFER_SIZE ( 2 * 1024 * 1024 )
|
||||
#define COMBINER_MAX_MATERIALS ( COMBINER_MAX_MATERIALS_PER_INPUT_MODEL * COMBINER_MAX_MODELS )
|
||||
#define COMBINER_MAX_BODYPARTS_PER_MODEL 5
|
||||
|
||||
typedef struct SAtlasGroup
|
||||
{
|
||||
unsigned char *m_pCombinedTextures[ COMBINER_MAX_TEXTURES_PER_MATERIAL ];
|
||||
int m_nCombinedTextureSizes[ COMBINER_MAX_TEXTURES_PER_MATERIAL ];
|
||||
KeyValues *m_pCombinedMaterial;
|
||||
char m_szCombinedMaterialName[ MAX_PATH ];
|
||||
} TAtlasGroup;
|
||||
|
||||
|
||||
typedef struct SCombinedStudioData
|
||||
{
|
||||
studiodata_t *m_pPlaceholderStudioData;
|
||||
MDLHandle_t m_PlaceholderHandle;
|
||||
studiodata_t *m_pFinalStudioData;
|
||||
MDLHandle_t m_FinalHandle;
|
||||
void *m_pCombinedUserData;
|
||||
unsigned int m_nReferenceFlags;
|
||||
CombinedModelLoadedCallback m_CallbackFunc;
|
||||
CModelCombine *m_pCombineData;
|
||||
|
||||
SCombinerModelInput_t m_ModelInputData[ COMBINER_MAX_MODELS ];
|
||||
int m_nNumModels;
|
||||
|
||||
int m_nModelMaterialCounts[ COMBINER_MAX_MODELS ];
|
||||
int m_nModelMaterialIndices[ COMBINER_MAX_MODELS ][ COMBINER_MAX_MATERIALS ];
|
||||
|
||||
int m_MeshToMaterialMap[ COMBINER_MAX_MODELS ][ COMBINER_MAX_BODYPARTS_PER_MODEL ][ COMBINER_MAX_MATERIALS_PER_INPUT_MODEL ];
|
||||
|
||||
TAtlasGroup m_AtlasGroups[ COMBINER_MAX_ATLAS_GROUPS ];
|
||||
int m_nNumAtlasGroups;
|
||||
|
||||
char m_szNonAtlasedMaterialPaths[ COMBINER_MAX_MODELS ][ MAX_PATH ];
|
||||
int m_nNumNonAtlasedMaterialPaths;
|
||||
|
||||
KeyValues *m_pNonAtlasedMaterialKVs[ COMBINER_MAX_MODELS ];
|
||||
char m_szNonAtlasedMaterialBaseName[ COMBINER_MAX_MODELS ][ MAX_PATH ];
|
||||
int m_nNumNonAtlasedMaterialBaseNames;
|
||||
|
||||
char m_szCombinedModelName[ MAX_PATH ];
|
||||
|
||||
// returned results
|
||||
TCombinedResults m_Results;
|
||||
|
||||
} TCombinedStudioData;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
WRITE_AREA_MDL = 0,
|
||||
WRITE_AREA_VTX,
|
||||
WRITE_AREA_VVD,
|
||||
WRITE_AREA_VTF,
|
||||
|
||||
MAX_WRITE_AREAS
|
||||
};
|
||||
|
||||
|
||||
class CCombinerMemoryWriter
|
||||
{
|
||||
public:
|
||||
CCombinerMemoryWriter( );
|
||||
~CCombinerMemoryWriter( );
|
||||
|
||||
void Init( );
|
||||
|
||||
void InitWriteArea( int nArea, char *pPosition );
|
||||
void SetWriteArea( int nArea );
|
||||
|
||||
char *AllocWrite( int nSize );
|
||||
char *WriteOffset( int &nOffsetIndex );
|
||||
char *WriteOffset( int &nOffsetIndex, void *pBasePtr );
|
||||
char *WriteOffset( short &nOffsetIndex, void *pBasePtr );
|
||||
char *WriteBuffer( const void *pData, int nSize );
|
||||
char *WriteBufferWithOffset( const void *pData, int nSize, int &nOffsetIndex );
|
||||
char *WriteString( const char *pszString ); // adds NULL terminator
|
||||
char *WriteText( const char *pszString ); // does not add NULL terminator
|
||||
void AlignWrite( int nAlignSize );
|
||||
|
||||
char *GetSaveWritePos( int nArea ) { return m_pSaveWritePos[ nArea ]; }
|
||||
char *GetWritePos( ) { return m_pWritePos; }
|
||||
char *GetWriteArea( ) { return m_pWriteArea; }
|
||||
|
||||
private:
|
||||
char *m_pWorkBuffer;
|
||||
char *m_pEndBuffer;
|
||||
char *m_pWriteArea;
|
||||
char *m_pSaveWriteArea[ MAX_WRITE_AREAS ];
|
||||
char *m_pWritePos;
|
||||
char *m_pSaveWritePos[ MAX_WRITE_AREAS ];
|
||||
int m_nWriteArea;
|
||||
#ifdef DEBUG_COMBINE
|
||||
char *m_pErrorPos;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern CCombinerMemoryWriter g_CombinerWriter;
|
||||
|
||||
|
||||
class CModelCombine
|
||||
{
|
||||
public:
|
||||
CModelCombine( );
|
||||
~CModelCombine( );
|
||||
|
||||
void Init( TCombinedStudioData *pCombinedStudioData );
|
||||
|
||||
bool Resolve( );
|
||||
|
||||
void *GetCombinedMDLPtr( ) { return ( void * )m_pCombinedStudioHdr; }
|
||||
int GetCombinedMDLSize( ) { return g_CombinerWriter.GetSaveWritePos( WRITE_AREA_MDL ) - ( char *)m_pCombinedStudioHdr; }
|
||||
bool GetCombinedMDLAvailability( ) { return GetCombinedMDLSize() != 0; }
|
||||
|
||||
void *GetCombinedVTXPtr( ) { return ( void * )m_pCombinedHardwareHeader; }
|
||||
int GetCombinedVTXSize( ) { return g_CombinerWriter.GetSaveWritePos( WRITE_AREA_VTX ) - ( char *)m_pCombinedHardwareHeader; }
|
||||
bool GetCombinedVTXAvailability( ) { return GetCombinedVTXSize() != 0; }
|
||||
|
||||
void *GetCombinedVVDPtr( ) { return ( void * )m_pCombinedVertex; }
|
||||
int GetCombinedVVDSize( ) { return g_CombinerWriter.GetSaveWritePos( WRITE_AREA_VVD ) - ( char *)m_pCombinedVertex; }
|
||||
bool GetCombinedVVDAvailability( ) { return GetCombinedVVDSize() != 0; }
|
||||
|
||||
TCombinedResults *GetResults( ) { return &m_pCombinedStudioData->m_Results; }
|
||||
|
||||
static int GetNextAssetID( ) { return ++m_nNextAssetID; }
|
||||
|
||||
private:
|
||||
static int BoneNameCompare( const void *elem1, const void *elem2 );
|
||||
|
||||
void BeginStringTable( );
|
||||
void AddToStringTable( void *base, int *ptr, const char *string );
|
||||
void WriteStringTable( );
|
||||
|
||||
void VerifyField( int nField, const char *pszDescription );
|
||||
void VerifyField2( int nField, const char *pszDescription );
|
||||
void VerifyOffset( void *pPtr, const char *pszDescription, void *pWritePos = 0 );
|
||||
|
||||
void DetermineMasterBoneList( );
|
||||
|
||||
//
|
||||
void CombineMDL_PreintStrings( );
|
||||
|
||||
void RemapBone( int nModel, int &nBone ) { nBone = m_nBoneRemap[ nModel ][ nBone ]; }
|
||||
|
||||
void WriteBoneProc( int nSize, int nType1, int nType2 = -999 );
|
||||
void WriteBoneQuatInterp( );
|
||||
void WriteBoneTwist( );
|
||||
void WriteBoneConstraints( );
|
||||
void WriteBoneAttachments( );
|
||||
void WriteHitBoxes( );
|
||||
void WriteBoneTable( );
|
||||
void CombineMDL_Bones( );
|
||||
|
||||
void WriteAnimation( mstudioanimdesc_t *pOrigAnim, void *pAnimData, int nFrameSize );
|
||||
void CombineMDL_Anims( );
|
||||
|
||||
void CombineMDL_SequenceInfo( );
|
||||
|
||||
void WriteModel( int nModel );
|
||||
void CombineMDL_Model( );
|
||||
|
||||
void CombineMDL_Textures( );
|
||||
|
||||
void CombineMDL_KeyValues( );
|
||||
|
||||
void CombineMDL_BoneTransforms( );
|
||||
|
||||
void CombineMDL_BoneFlexDrivers( );
|
||||
|
||||
void CombineMDL_AssignMeshIDs( );
|
||||
|
||||
void CombineMDL( bool bNoStringTable );
|
||||
#ifdef DEBUG_COMBINE
|
||||
void TestCombineMDL( );
|
||||
#endif // DEBUG_COMBINE
|
||||
|
||||
void CalcVTXInfo();
|
||||
|
||||
void WriteStrip( OptimizedModel::StripGroupHeader_t *pNewStripGroup, int nModel, OptimizedModel::StripGroupHeader_t *pOrigStripGroup, OptimizedModel::StripHeader_t *pOrigStrip );
|
||||
void MergeStripGroup( int nLOD, OptimizedModel::StripGroupHeader_t *pNewStripGroup, int nModel, OptimizedModel::StripGroupHeader_t *pOrigStripGroup );
|
||||
void WriteStripGroup( int nLOD, int nMaterialIndex, unsigned char nStripGroupFlags, OptimizedModel::MeshHeader_t *pNewMesh );
|
||||
void WriteMeshes( int nLOD, int nMaterialIndex, OptimizedModel::ModelLODHeader_t *pNewModelLOD, OptimizedModel::ModelLODHeader_t *pOrigModelLOD );
|
||||
void WriteModelLOD( int nLOD, OptimizedModel::ModelHeader_t *pNewModel, OptimizedModel::ModelHeader_t *pOrigModel );
|
||||
void WriteModel( int nModel, OptimizedModel::BodyPartHeader_t *pNewBodyPart, OptimizedModel::BodyPartHeader_t *pOrigBodyPart );
|
||||
void WriteBodyPart( int nBodyPart );
|
||||
void CombineVTX( );
|
||||
#ifdef DEBUG_COMBINE
|
||||
void TestCombineVTX( );
|
||||
#endif // DEBUG_COMBINE
|
||||
|
||||
//
|
||||
void CombineVVD_OffsetVerts( );
|
||||
void CombineVVD( );
|
||||
|
||||
//
|
||||
void CombineTextures( );
|
||||
int AddMaterialToTextureCombiner( int nTextureIndex, int nModel, int nModelMaterialIndex );
|
||||
|
||||
void Test( );
|
||||
|
||||
typedef struct SHardwareData
|
||||
{
|
||||
int m_nBodyParts;
|
||||
int m_nMaxBodyParts;
|
||||
int m_nModels;
|
||||
int m_nModelLODs;
|
||||
int m_nMeshes;
|
||||
int m_nStripGroups;
|
||||
int m_nStrips;
|
||||
int m_nVerts;
|
||||
int m_nIndices;
|
||||
int m_nBoneStateChanges;
|
||||
int m_nStringTable;
|
||||
int m_nTopology;
|
||||
int m_nMaterialReplacements;
|
||||
} THardwareData;
|
||||
|
||||
TCombinedStudioData *m_pCombinedStudioData;
|
||||
|
||||
CUtlBuffer *MDL_Data[ COMBINER_MAX_MODELS ];
|
||||
CUtlBuffer *VTX_Data[ COMBINER_MAX_MODELS ];
|
||||
CUtlBuffer *VVD_Data[ COMBINER_MAX_MODELS ];
|
||||
|
||||
studiohdr_t *m_pStudioHdr[ COMBINER_MAX_MODELS ];
|
||||
studiohdr2_t *m_pStudioHdr2[ COMBINER_MAX_MODELS ];
|
||||
vertexFileHeader_t *m_pVertexFileHeader[ COMBINER_MAX_MODELS ];
|
||||
|
||||
const mstudiobone_t *m_pMasterBoneList[ COMBINER_MAX_BONES ];
|
||||
int m_nBoneModelOwner[ COMBINER_MAX_BONES ];
|
||||
int m_nNumMasterBones;
|
||||
int m_nBoneRemap[ COMBINER_MAX_MODELS ][ COMBINER_MAX_BONES ];
|
||||
int m_nMasterToLocalBoneRemap[ COMBINER_MAX_MODELS ][ COMBINER_MAX_BONES ];
|
||||
mstudiomodel_t *m_pMasterModels[ COMBINER_MAX_MODELS ][ COMBINER_MAX_SUB_MODELS ];
|
||||
mstudiomodel_t *m_pMasterFlexModels[ COMBINER_MAX_SUB_MODELS ];
|
||||
int *m_nVertexRemap[ COMBINER_MAX_MODELS ];
|
||||
int m_nFlexModelSource;
|
||||
THardwareData m_MaxHardwareData;
|
||||
THardwareData m_CurrentHardwareData;
|
||||
THardwareData m_HardwareOffsets;
|
||||
|
||||
studiohdr_t *m_pCombinedStudioHdr;
|
||||
studiohdr2_t *m_pCombinedStudioHdr2;
|
||||
OptimizedModel::FileHeader_t *m_pCombinedHardwareHeader;
|
||||
mstudiomodel_t *m_pCombinedModels;
|
||||
vertexFileHeader_t *m_pCombinedVertex;
|
||||
|
||||
struct stringtable_t
|
||||
{
|
||||
byte *base;
|
||||
int *ptr;
|
||||
const char *string;
|
||||
int dupindex;
|
||||
byte *addr;
|
||||
};
|
||||
int numStrings;
|
||||
stringtable_t strings[ COMBINER_MAX_STRINGS ];
|
||||
|
||||
static unsigned int m_nNextAssetID;
|
||||
};
|
||||
|
||||
|
||||
extern CModelCombine g_ModelCombiner;
|
||||
|
||||
|
||||
#endif // __MDLCOMBINE_H
|
||||
171
datacache/precachesystem.cpp
Normal file
171
datacache/precachesystem.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "tier1/utlsymbol.h"
|
||||
#include "tier1/UtlStringMap.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "datacache/iprecachesystem.h"
|
||||
#include "datacache/iresourceaccesscontrol.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation class
|
||||
//-----------------------------------------------------------------------------
|
||||
class CPrecacheSystem : public CTier2AppSystem< IPrecacheSystem >
|
||||
{
|
||||
typedef CTier2AppSystem< IPrecacheSystem > BaseClass;
|
||||
|
||||
// Inherited from IAppSystem
|
||||
public:
|
||||
|
||||
// Inherited from IResourceAccessControl
|
||||
public:
|
||||
void Register( IResourcePrecacher *pResourcePrecacherFirst, PrecacheSystem_t nSystem );
|
||||
|
||||
// Precaches/uncaches all resources used by a particular system
|
||||
void Cache( IPrecacheHandler *pPrecacheHandler, PrecacheSystem_t nSystem, const char *pName, bool bPrecache, ResourceList_t hResourceList, bool bBuildResourceList );
|
||||
|
||||
void UncacheAll( IPrecacheHandler *pPrecacheHandler );
|
||||
|
||||
// Limits resource access to only resources used by this particular system
|
||||
// Use GLOBAL system, and NULL name to disable limited resource access
|
||||
void LimitResourceAccess( PrecacheSystem_t nSystem, const char *pName );
|
||||
void EndLimitedResourceAccess();
|
||||
|
||||
private:
|
||||
IResourcePrecacher *m_pFirstPrecacher[PRECACHE_SYSTEM_COUNT];
|
||||
CUtlStringMap< ResourceList_t > m_ResourceList[ PRECACHE_SYSTEM_COUNT ];
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// String names corresponding to resource types
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pResourceSystemName[] =
|
||||
{
|
||||
"global client resource",
|
||||
"global server resource",
|
||||
"vgui panel",
|
||||
"dispatch effect",
|
||||
"shared system",
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton
|
||||
//-----------------------------------------------------------------------------
|
||||
CPrecacheSystem g_PrecacheSystem;
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CPrecacheSystem, IPrecacheSystem,
|
||||
PRECACHE_SYSTEM_INTERFACE_VERSION, g_PrecacheSystem );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Precaches/uncaches all resources used by a particular system
|
||||
//-----------------------------------------------------------------------------
|
||||
void CPrecacheSystem::Cache( IPrecacheHandler *pPrecacheHandler, PrecacheSystem_t nSystem, const char *pName, bool bPrecache, ResourceList_t hResourceList, bool bBuildResourceList )
|
||||
{
|
||||
COMPILE_TIME_ASSERT( ARRAYSIZE( s_pResourceSystemName ) == PRECACHE_SYSTEM_COUNT );
|
||||
|
||||
IResourcePrecacher *pPrecacher = m_pFirstPrecacher[nSystem];
|
||||
for( ; pPrecacher; pPrecacher = pPrecacher->GetNext() )
|
||||
{
|
||||
if ( pName && Q_stricmp( pName, pPrecacher->GetName() ) )
|
||||
continue;
|
||||
|
||||
if ( bBuildResourceList && g_pResourceAccessControl )
|
||||
{
|
||||
Assert( hResourceList == RESOURCE_LIST_INVALID );
|
||||
UtlSymId_t idx = m_ResourceList[ nSystem ].Find( pName );
|
||||
if ( idx != UTL_INVAL_SYMBOL )
|
||||
{
|
||||
hResourceList = m_ResourceList[ nSystem ][ idx ];
|
||||
}
|
||||
else
|
||||
{
|
||||
char pDebugName[256];
|
||||
Q_snprintf( pDebugName, sizeof(pDebugName), "%s \"%s\"", s_pResourceSystemName[nSystem], pName );
|
||||
hResourceList = g_pResourceAccessControl->CreateResourceList( pDebugName );
|
||||
m_ResourceList[ nSystem ][ pName ] = hResourceList;
|
||||
}
|
||||
}
|
||||
pPrecacher->Cache( pPrecacheHandler, bPrecache, hResourceList, false );
|
||||
|
||||
if ( !bPrecache )
|
||||
{
|
||||
m_ResourceList[ nSystem ][ pName ] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uncaches everything
|
||||
//-----------------------------------------------------------------------------
|
||||
void CPrecacheSystem::UncacheAll( IPrecacheHandler *pPrecacheHandler )
|
||||
{
|
||||
int nSystem;
|
||||
for ( nSystem = 0; nSystem < PRECACHE_SYSTEM_COUNT; nSystem ++ )
|
||||
{
|
||||
IResourcePrecacher *pPrecacher = m_pFirstPrecacher[nSystem];
|
||||
for( ; pPrecacher; pPrecacher = pPrecacher->GetNext() )
|
||||
{
|
||||
pPrecacher->Cache( pPrecacheHandler, false, RESOURCE_LIST_INVALID, false );
|
||||
}
|
||||
|
||||
m_ResourceList[nSystem].Purge();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Called to register a list of resource precachers for a given system
|
||||
//-----------------------------------------------------------------------------
|
||||
void CPrecacheSystem::Register( IResourcePrecacher *pResourcePrecacherFirst, PrecacheSystem_t nSystem )
|
||||
{
|
||||
// do we already have any precachers registered for this system?
|
||||
IResourcePrecacher *pCur = m_pFirstPrecacher[nSystem];
|
||||
|
||||
if ( pCur )
|
||||
{
|
||||
while ( pCur->GetNext() != NULL )
|
||||
{
|
||||
pCur = pCur->GetNext();
|
||||
}
|
||||
// add the head of the new list to the tail of the existing list
|
||||
pCur->SetNext( pResourcePrecacherFirst );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pFirstPrecacher[nSystem] = pResourcePrecacherFirst;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Limits resource access to only resources used by this particular system
|
||||
// Use GLOBAL system, and NULL name to disable limited resource access
|
||||
//-----------------------------------------------------------------------------
|
||||
void CPrecacheSystem::LimitResourceAccess( PrecacheSystem_t nSystem, const char *pName )
|
||||
{
|
||||
if ( g_pResourceAccessControl )
|
||||
{
|
||||
UtlSymId_t nSym = ( pName != NULL ) ? m_ResourceList[nSystem].Find( pName ) : UTL_INVAL_SYMBOL;
|
||||
if ( nSym != UTL_INVAL_SYMBOL )
|
||||
{
|
||||
g_pResourceAccessControl->LimitAccess( m_ResourceList[nSystem][nSym] );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pResourceAccessControl->LimitAccess( RESOURCE_LIST_INVALID );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CPrecacheSystem::EndLimitedResourceAccess()
|
||||
{
|
||||
if ( g_pResourceAccessControl )
|
||||
{
|
||||
g_pResourceAccessControl->LimitAccess( RESOURCE_LIST_INVALID );
|
||||
}
|
||||
}
|
||||
226
datacache/resourceaccesscontrol.cpp
Normal file
226
datacache/resourceaccesscontrol.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "datacache/iresourceaccesscontrol.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier2/tier2.h"
|
||||
#include "tier1/convar.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// NOTE: Necessary until we have all our resources wrangled.
|
||||
//-----------------------------------------------------------------------------
|
||||
static ConVar res_restrict_access( "res_restrict_access", "0" );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Implementation class
|
||||
//-----------------------------------------------------------------------------
|
||||
class CResourceAccessControl : public CTier1AppSystem< IResourceAccessControl >
|
||||
{
|
||||
typedef CTier1AppSystem< IResourceAccessControl > BaseClass;
|
||||
|
||||
// Inherited from IAppSystem
|
||||
public:
|
||||
virtual void Shutdown();
|
||||
|
||||
// Inherited from IResourceAccessControl
|
||||
public:
|
||||
virtual ResourceList_t CreateResourceList( const char *pDebugName );
|
||||
virtual void DestroyAllResourceLists( );
|
||||
virtual void AddResource( ResourceList_t hResourceList, ResourceTypeOld_t nType, const char *pResourceName );
|
||||
virtual void LimitAccess( ResourceList_t hResourceList );
|
||||
virtual bool IsAccessAllowed( ResourceTypeOld_t nType, const char *pResource );
|
||||
|
||||
// Other public methods
|
||||
public:
|
||||
CResourceAccessControl();
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
MAX_THREADS = 16
|
||||
};
|
||||
|
||||
struct ResourceInfo_t
|
||||
{
|
||||
CUtlString m_DebugName;
|
||||
CUtlVector< CUtlString > m_Resources[RESOURCE_TYPE_OLD_COUNT];
|
||||
};
|
||||
|
||||
bool ContainsResource( ResourceList_t hResourceList, ResourceTypeOld_t nType, const char *pResourceName );
|
||||
int FindOrAddCurrentThreadID();
|
||||
void FixupResourceName( const char *pResourceName, char *pBuf, int nBufLen );
|
||||
|
||||
CUtlVector< ResourceInfo_t > m_ResourceLists;
|
||||
int m_pLimitAccess[MAX_THREADS];
|
||||
unsigned long m_pThread[MAX_THREADS];
|
||||
int m_nThreadCount;
|
||||
CThreadMutex m_Mutex;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Singleton
|
||||
//-----------------------------------------------------------------------------
|
||||
CResourceAccessControl g_ResourceAccessControl;
|
||||
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CResourceAccessControl, IResourceAccessControl,
|
||||
RESOURCE_ACCESS_CONTROL_INTERFACE_VERSION, g_ResourceAccessControl );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Resource type names
|
||||
//-----------------------------------------------------------------------------
|
||||
static const char *s_pResourceTypeName[] =
|
||||
{
|
||||
"vgui panel", // .res file
|
||||
"material", // .vmt file
|
||||
"model", // .mdl file
|
||||
"particle system", // particle system
|
||||
"game sound", // game sound
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CResourceAccessControl::CResourceAccessControl()
|
||||
{
|
||||
m_nThreadCount = 0;
|
||||
memset( m_pLimitAccess, 0xFF, sizeof(m_pLimitAccess) );
|
||||
memset( m_pThread, 0, sizeof(m_pThread) );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Shutdown
|
||||
//-----------------------------------------------------------------------------
|
||||
void CResourceAccessControl::Shutdown()
|
||||
{
|
||||
DestroyAllResourceLists();
|
||||
memset( m_pLimitAccess, 0xFF, sizeof(m_pLimitAccess) );
|
||||
BaseClass::Shutdown();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates a resource list
|
||||
//-----------------------------------------------------------------------------
|
||||
int CResourceAccessControl::FindOrAddCurrentThreadID()
|
||||
{
|
||||
unsigned long nThreadId = ThreadGetCurrentId();
|
||||
for ( int i = 0; i < m_nThreadCount; ++i )
|
||||
{
|
||||
if ( m_pThread[i] == nThreadId )
|
||||
return i;
|
||||
}
|
||||
|
||||
if ( m_nThreadCount >= MAX_THREADS )
|
||||
{
|
||||
Error( "Exceeded maximum number of unique threads (%d) attempting to access datacache.\n", MAX_THREADS );
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_Mutex.Lock();
|
||||
int nIndex = m_nThreadCount;
|
||||
m_pThread[m_nThreadCount++] = nThreadId;
|
||||
m_Mutex.Unlock();
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fixes up the asset name
|
||||
//-----------------------------------------------------------------------------
|
||||
void CResourceAccessControl::FixupResourceName( const char *pResourceName, char *pBuf, int nBufLen )
|
||||
{
|
||||
Q_StripExtension( pResourceName, pBuf, nBufLen );
|
||||
Q_FixSlashes( pBuf, '/' );
|
||||
V_RemoveDotSlashes( pBuf, '/' );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates a resource list
|
||||
//-----------------------------------------------------------------------------
|
||||
ResourceList_t CResourceAccessControl::CreateResourceList( const char *pDebugName )
|
||||
{
|
||||
int nIndex = m_ResourceLists.AddToTail();
|
||||
m_ResourceLists[nIndex].m_DebugName.Set( pDebugName );
|
||||
return (ResourceList_t)(intp)nIndex;
|
||||
}
|
||||
|
||||
void CResourceAccessControl::DestroyAllResourceLists( )
|
||||
{
|
||||
m_ResourceLists.Purge();
|
||||
memset( m_pLimitAccess, 0xFF, sizeof(m_pLimitAccess) );
|
||||
}
|
||||
|
||||
bool CResourceAccessControl::ContainsResource( ResourceList_t hResourceList, ResourceTypeOld_t nType, const char *pResourceName )
|
||||
{
|
||||
char pBuf[MAX_PATH];
|
||||
FixupResourceName( pResourceName, pBuf, sizeof(pBuf) );
|
||||
|
||||
int nIndex = size_cast< int >( (intp)hResourceList );
|
||||
CUtlVector< CUtlString > &list = m_ResourceLists[nIndex].m_Resources[nType];
|
||||
int nCount = list.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pBuf, list[i].Get() ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CResourceAccessControl::AddResource( ResourceList_t hResourceList, ResourceTypeOld_t nType, const char *pResourceName )
|
||||
{
|
||||
if ( ContainsResource( hResourceList, nType, pResourceName ) )
|
||||
return;
|
||||
|
||||
int nIndex = size_cast< int >( (intp)hResourceList );
|
||||
int nSubIndex = m_ResourceLists[nIndex].m_Resources[nType].AddToTail();
|
||||
|
||||
char pBuf[MAX_PATH];
|
||||
FixupResourceName( pResourceName, pBuf, sizeof(pBuf) );
|
||||
m_ResourceLists[nIndex].m_Resources[nType][nSubIndex].Set( pBuf );
|
||||
}
|
||||
|
||||
void CResourceAccessControl::LimitAccess( ResourceList_t hResourceList )
|
||||
{
|
||||
if ( !res_restrict_access.GetInt() )
|
||||
return;
|
||||
|
||||
int nIndex = FindOrAddCurrentThreadID();
|
||||
if ( ( m_pLimitAccess[nIndex] >= 0 ) && ( hResourceList != RESOURCE_LIST_INVALID ) )
|
||||
{
|
||||
Warning( "Attempted to limit access while already limiting access!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
m_pLimitAccess[nIndex] = size_cast< int >( (intp)hResourceList );
|
||||
}
|
||||
|
||||
bool CResourceAccessControl::IsAccessAllowed( ResourceTypeOld_t nType, const char *pResourceName )
|
||||
{
|
||||
int nIndex = FindOrAddCurrentThreadID();
|
||||
if ( m_pLimitAccess[nIndex] < 0 )
|
||||
return true;
|
||||
|
||||
int hResourceList = m_pLimitAccess[nIndex];
|
||||
if ( ContainsResource( (ResourceList_t)( intp )hResourceList, nType, pResourceName ) )
|
||||
return true;
|
||||
|
||||
COMPILE_TIME_ASSERT( ARRAYSIZE( s_pResourceTypeName ) == RESOURCE_TYPE_OLD_COUNT );
|
||||
Warning( "Access to %s resource \"%s\" denied. Missing precache in %s?\n",
|
||||
s_pResourceTypeName[nType], pResourceName, m_ResourceLists[hResourceList].m_DebugName.Get() );
|
||||
|
||||
return false;
|
||||
}
|
||||
2
datacache/vsi.nul
Normal file
2
datacache/vsi.nul
Normal file
@@ -0,0 +1,2 @@
|
||||
SN Visual Studio Integration
|
||||
IMPORTANT: Do not remove the custom build step for this file
|
||||
1212
datacache/vtfcombine.cpp
Normal file
1212
datacache/vtfcombine.cpp
Normal file
File diff suppressed because it is too large
Load Diff
117
datacache/vtfcombine.h
Normal file
117
datacache/vtfcombine.h
Normal file
@@ -0,0 +1,117 @@
|
||||
//========= Copyright c 1996-2011, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//====================================================================================//
|
||||
|
||||
#ifndef __VTFCOMBINE_H
|
||||
#define __VTFCOMBINE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "mdlcombine.h"
|
||||
|
||||
|
||||
class KeyValues;
|
||||
struct VTFFileHeader_t;
|
||||
struct ResourceEntryInfo;
|
||||
class CSimpleTexturePacker;
|
||||
|
||||
|
||||
//#define DEBUG_VTF_COMBINE 1
|
||||
|
||||
|
||||
#define MAX_COMBINED_MIP_LEVELS 11
|
||||
#define MAX_COMBINED_WIDTH 1024
|
||||
#define MAX_COMBINED_HEIGHT 1024
|
||||
#define MAX_COMBINED_TEXTURE_MEMORY ( ( 1024 + ( ( MAX_COMBINED_WIDTH >> 2 ) * ( MAX_COMBINED_HEIGHT >> 2 ) * 16 * 2 ) ) )
|
||||
|
||||
#define ATLAS_INFO_GROUP_INDEX 0
|
||||
#define ATLAS_INFO_MATERIAL_INDEX 1
|
||||
#define ATLAS_INFO_COUNT (ATLAS_INFO_MATERIAL_INDEX + 1)
|
||||
|
||||
enum
|
||||
{
|
||||
COMBINED_MATERIAL_FLAG_NOCULL = 0x00000001,
|
||||
};
|
||||
|
||||
|
||||
struct AtlasGroupData
|
||||
{
|
||||
int m_nNumMaterials;
|
||||
int m_nMaterialIndices[ COMBINER_MAX_MATERIALS ];
|
||||
|
||||
CUtlBuffer *m_pVTFData[ COMBINER_MAX_MATERIALS ];
|
||||
VTFFileHeader_t *m_pVTFFileHeader[ COMBINER_MAX_MATERIALS ];
|
||||
ResourceEntryInfo *m_pResources[ COMBINER_MAX_MATERIALS ];
|
||||
bool m_bIsFlat[ COMBINER_MAX_MATERIALS ];
|
||||
|
||||
KeyValues *m_pCombinedMaterialKVs;
|
||||
|
||||
byte m_CombinedTextureMemory[ COMBINER_MAX_TEXTURES_PER_MATERIAL ][ MAX_COMBINED_TEXTURE_MEMORY ];
|
||||
int m_nCombinedTextureSize[ COMBINER_MAX_TEXTURES_PER_MATERIAL ];
|
||||
VTFFileHeader_t *m_CombinedHeaders[ COMBINER_MAX_TEXTURES_PER_MATERIAL ];
|
||||
|
||||
CSimpleTexturePacker *m_pSimpleTexturePacker;
|
||||
};
|
||||
|
||||
class CTextureCombine
|
||||
{
|
||||
public:
|
||||
CTextureCombine( );
|
||||
|
||||
void Init( TCombinedStudioData *pCombinedStudioData );
|
||||
void Cleanup( );
|
||||
|
||||
int AddMaterial( const char *pszFileName );
|
||||
|
||||
void Resolve( );
|
||||
|
||||
void GetTextureInfo( int nIndex, Vector2D &vStartST, Vector2D &vSizeST, Vector2D &vPixelSize );
|
||||
|
||||
void FreeCombinedMaterials( );
|
||||
|
||||
int GetAtlasGroupIndex( int nIndex ) const
|
||||
{
|
||||
Assert( nIndex < COMBINER_MAX_MATERIALS );
|
||||
return m_nMaterialAtlasInfo[ nIndex ][ ATLAS_INFO_GROUP_INDEX ];
|
||||
}
|
||||
int GetAtlasGroupMaterialIndex( int nIndex ) const
|
||||
{
|
||||
Assert( nIndex < COMBINER_MAX_MATERIALS );
|
||||
return m_nMaterialAtlasInfo[ nIndex ][ ATLAS_INFO_MATERIAL_INDEX ];
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
TCombinedStudioData *m_pCombinedStudioData;
|
||||
|
||||
int m_nNumMaterials;
|
||||
char m_szMaterials[ COMBINER_MAX_MATERIALS ][ MAX_PATH ];
|
||||
int m_nMaterialAtlasInfo[ COMBINER_MAX_MATERIALS ][ ATLAS_INFO_COUNT ];
|
||||
int m_nMaxAtlasGroup;
|
||||
AtlasGroupData m_AtlasGroups[ COMBINER_MAX_ATLAS_GROUPS ];
|
||||
|
||||
KeyValues *m_pMaterialKVs[ COMBINER_MAX_MATERIALS ];
|
||||
|
||||
int m_nMaterialToTexture;
|
||||
|
||||
void GatherAtlasInfo( );
|
||||
void FindMaterialToTexture( );
|
||||
void AddNonAtlasedMaterial( int nMaterial );
|
||||
|
||||
bool LoadVTFs( int nAtlasGroup, const char *pszTextureField, const char *pszFlatReplacement, char szTextureNames[ COMBINER_MAX_MATERIALS ][ MAX_PATH ] );
|
||||
|
||||
bool CombineTexture( int nAtlasGroup, int nTexture, const char *pszTextureField, const char *pszFlatReplacement );
|
||||
|
||||
friend class CSimpleTexturePacker;
|
||||
};
|
||||
|
||||
|
||||
extern CTextureCombine& GetTextureCombiner();
|
||||
|
||||
|
||||
#endif // __VTFCOMBINE_H
|
||||
3
datacache/xbox/xbox.def
Normal file
3
datacache/xbox/xbox.def
Normal file
@@ -0,0 +1,3 @@
|
||||
LIBRARY datacache_360.dll
|
||||
EXPORTS
|
||||
CreateInterface @1
|
||||
Reference in New Issue
Block a user