mirror of
https://github.com/0TheSpy/Seaside.git
synced 2025-09-19 12:16:13 +08:00
Add files via upload
This commit is contained in:
316
SpyCustom/sdk/UtlSortVector.h
Normal file
316
SpyCustom/sdk/UtlSortVector.h
Normal file
@ -0,0 +1,316 @@
|
||||
#ifndef UTLSORTVECTOR_H
|
||||
#define UTLSORTVECTOR_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlvector.h"
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
extern void* g_pUtlSortVectorQSortContext;
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
class CUtlSortVectorDefaultLess
|
||||
{
|
||||
public:
|
||||
bool Less(const T& lhs, const T& rhs, void*)
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class LessFunc = CUtlSortVectorDefaultLess<T>, class BaseVector = CUtlVector<T> >
|
||||
class CUtlSortVector : public BaseVector
|
||||
{
|
||||
typedef BaseVector BaseClass;
|
||||
public:
|
||||
CUtlSortVector(int nGrowSize = 0, int initSize = 0);
|
||||
CUtlSortVector(T* pMemory, int numElements);
|
||||
|
||||
int Insert(const T& src);
|
||||
|
||||
int InsertIfNotFound(const T& src);
|
||||
|
||||
template< typename TKey >
|
||||
int Find(const TKey& search) const;
|
||||
template< typename TKey >
|
||||
int FindLessOrEqual(const TKey& search) const;
|
||||
template< typename TKey >
|
||||
int FindLess(const TKey& search) const;
|
||||
|
||||
void Remove(const T& search);
|
||||
void Remove(int i);
|
||||
|
||||
void SetLessContext(void* pCtx);
|
||||
|
||||
int InsertNoSort(const T& src);
|
||||
void RedoSort(bool bForceSort = false);
|
||||
|
||||
int InsertAfter(int nElemIndex, const T& src);
|
||||
|
||||
template< typename TKey >
|
||||
int FindUnsorted(const TKey& src) const;
|
||||
|
||||
protected:
|
||||
CUtlSortVector(const CUtlSortVector<T, LessFunc>&);
|
||||
|
||||
int AddToHead();
|
||||
int AddToTail();
|
||||
int InsertBefore(int elem);
|
||||
int InsertAfter(int elem);
|
||||
int InsertBefore(int elem, const T& src);
|
||||
int AddToHead(const T& src);
|
||||
int AddToTail(const T& src);
|
||||
int AddMultipleToHead(int num);
|
||||
int AddMultipleToTail(int num, const T* pToCopy = NULL);
|
||||
int InsertMultipleBefore(int elem, int num, const T* pToCopy = NULL);
|
||||
int InsertMultipleAfter(int elem, int num);
|
||||
int AddVectorToTail(CUtlVector<T> const& src);
|
||||
|
||||
struct QSortContext_t
|
||||
{
|
||||
void* m_pLessContext;
|
||||
LessFunc* m_pLessFunc;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
static int CompareHelper(void* context, const T* lhs, const T* rhs)
|
||||
{
|
||||
QSortContext_t* ctx = reinterpret_cast<QSortContext_t*>(context);
|
||||
if (ctx->m_pLessFunc->Less(*lhs, *rhs, ctx->m_pLessContext))
|
||||
return -1;
|
||||
if (ctx->m_pLessFunc->Less(*rhs, *lhs, ctx->m_pLessContext))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static int CompareHelper(const T* lhs, const T* rhs)
|
||||
{
|
||||
QSortContext_t* ctx = reinterpret_cast<QSortContext_t*>(g_pUtlSortVectorQSortContext);
|
||||
if (ctx->m_pLessFunc->Less(*lhs, *rhs, ctx->m_pLessContext))
|
||||
return -1;
|
||||
if (ctx->m_pLessFunc->Less(*rhs, *lhs, ctx->m_pLessContext))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void* m_pLessContext;
|
||||
bool m_bNeedsSort;
|
||||
|
||||
private:
|
||||
private:
|
||||
template< typename TKey >
|
||||
int FindLessOrEqual(const TKey& search, bool* pFound) const;
|
||||
|
||||
void QuickSort(LessFunc& less, int X, int I);
|
||||
};
|
||||
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
CUtlSortVector<T, LessFunc, BaseVector>::CUtlSortVector(int nGrowSize, int initSize) :
|
||||
m_pLessContext(NULL), BaseVector(nGrowSize, initSize), m_bNeedsSort(false)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
CUtlSortVector<T, LessFunc, BaseVector>::CUtlSortVector(T* pMemory, int numElements) :
|
||||
m_pLessContext(NULL), BaseVector(pMemory, numElements), m_bNeedsSort(false)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
void CUtlSortVector<T, LessFunc, BaseVector>::SetLessContext(void* pCtx)
|
||||
{
|
||||
m_pLessContext = pCtx;
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::Insert(const T& src)
|
||||
{
|
||||
AssertFatal(!m_bNeedsSort);
|
||||
|
||||
int pos = FindLessOrEqual(src) + 1;
|
||||
this->GrowVector();
|
||||
this->ShiftElementsRight(pos);
|
||||
CopyConstruct<T>(&this->Element(pos), src);
|
||||
return pos;
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::InsertNoSort(const T& src)
|
||||
{
|
||||
m_bNeedsSort = true;
|
||||
int lastElement = BaseVector::m_Size;
|
||||
this->GrowVector();
|
||||
this->ShiftElementsRight(lastElement);
|
||||
CopyConstruct(&this->Element(lastElement), src);
|
||||
return lastElement;
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::InsertIfNotFound(const T& src)
|
||||
{
|
||||
AssertFatal(!m_bNeedsSort);
|
||||
bool bFound;
|
||||
int pos = FindLessOrEqual(src, &bFound);
|
||||
if (bFound)
|
||||
return pos;
|
||||
|
||||
++pos;
|
||||
this->GrowVector();
|
||||
this->ShiftElementsRight(pos);
|
||||
CopyConstruct<T>(&this->Element(pos), src);
|
||||
return pos;
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::InsertAfter(int nIndex, const T& src)
|
||||
{
|
||||
int nInsertedIndex = this->BaseClass::InsertAfter(nIndex, src);
|
||||
|
||||
#ifdef DEBUG
|
||||
LessFunc less;
|
||||
if (nInsertedIndex > 0)
|
||||
{
|
||||
Assert(less.Less(this->Element(nInsertedIndex - 1), src, m_pLessContext));
|
||||
}
|
||||
if (nInsertedIndex < BaseClass::Count() - 1)
|
||||
{
|
||||
Assert(less.Less(src, this->Element(nInsertedIndex + 1), m_pLessContext));
|
||||
}
|
||||
#endif
|
||||
return nInsertedIndex;
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
template < typename TKey >
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::Find(const TKey& src) const
|
||||
{
|
||||
AssertFatal(!m_bNeedsSort);
|
||||
|
||||
LessFunc less;
|
||||
|
||||
int start = 0, end = this->Count() - 1;
|
||||
while (start <= end)
|
||||
{
|
||||
int mid = (start + end) >> 1;
|
||||
if (less.Less(this->Element(mid), src, m_pLessContext))
|
||||
{
|
||||
start = mid + 1;
|
||||
}
|
||||
else if (less.Less(src, this->Element(mid), m_pLessContext))
|
||||
{
|
||||
end = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mid;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class LessFunc, class BaseVector >
|
||||
template < typename TKey >
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::FindUnsorted(const TKey& src) const
|
||||
{
|
||||
LessFunc less;
|
||||
int nCount = this->Count();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
if (less.Less(this->Element(i), src, m_pLessContext))
|
||||
continue;
|
||||
if (less.Less(src, this->Element(i), m_pLessContext))
|
||||
continue;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
template < typename TKey >
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::FindLessOrEqual(const TKey& src, bool* pFound) const
|
||||
{
|
||||
AssertFatal(!m_bNeedsSort);
|
||||
|
||||
LessFunc less;
|
||||
int start = 0, end = this->Count() - 1;
|
||||
while (start <= end)
|
||||
{
|
||||
int mid = (start + end) >> 1;
|
||||
if (less.Less(this->Element(mid), src, m_pLessContext))
|
||||
{
|
||||
start = mid + 1;
|
||||
}
|
||||
else if (less.Less(src, this->Element(mid), m_pLessContext))
|
||||
{
|
||||
end = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pFound = true;
|
||||
return mid;
|
||||
}
|
||||
}
|
||||
|
||||
*pFound = false;
|
||||
return end;
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
template < typename TKey >
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::FindLessOrEqual(const TKey& src) const
|
||||
{
|
||||
bool bFound;
|
||||
return FindLessOrEqual(src, &bFound);
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
template < typename TKey >
|
||||
int CUtlSortVector<T, LessFunc, BaseVector>::FindLess(const TKey& src) const
|
||||
{
|
||||
AssertFatal(!m_bNeedsSort);
|
||||
|
||||
LessFunc less;
|
||||
int start = 0, end = this->Count() - 1;
|
||||
while (start <= end)
|
||||
{
|
||||
int mid = (start + end) >> 1;
|
||||
if (less.Less(this->Element(mid), src, m_pLessContext))
|
||||
{
|
||||
start = mid + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = mid - 1;
|
||||
}
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
void CUtlSortVector<T, LessFunc, BaseVector>::Remove(const T& search)
|
||||
{
|
||||
AssertFatal(!m_bNeedsSort);
|
||||
|
||||
int pos = Find(search);
|
||||
if (pos != -1)
|
||||
{
|
||||
BaseVector::Remove(pos);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, class LessFunc, class BaseVector>
|
||||
void CUtlSortVector<T, LessFunc, BaseVector>::Remove(int i)
|
||||
{
|
||||
BaseVector::Remove(i);
|
||||
}
|
||||
|
||||
#endif
|
90
SpyCustom/sdk/UtlStringMap.h
Normal file
90
SpyCustom/sdk/UtlStringMap.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef UTLSTRINGMAP_H
|
||||
#define UTLSTRINGMAP_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlsymbol.h"
|
||||
|
||||
template <class T>
|
||||
class CUtlStringMap
|
||||
{
|
||||
public:
|
||||
CUtlStringMap(bool caseInsensitive = true) : m_SymbolTable(0, 32, caseInsensitive)
|
||||
{
|
||||
}
|
||||
|
||||
T& operator[](const char* pString)
|
||||
{
|
||||
CUtlSymbol symbol = m_SymbolTable.AddString(pString);
|
||||
int index = (int)(UtlSymId_t)symbol;
|
||||
if (m_Vector.Count() <= index)
|
||||
{
|
||||
m_Vector.EnsureCount(index + 1);
|
||||
}
|
||||
return m_Vector[index];
|
||||
}
|
||||
|
||||
T& operator[](UtlSymId_t n)
|
||||
{
|
||||
Assert(n >= 0 && n <= m_Vector.Count());
|
||||
return m_Vector[n];
|
||||
}
|
||||
|
||||
const T& operator[](UtlSymId_t n) const
|
||||
{
|
||||
Assert(n >= 0 && n <= m_Vector.Count());
|
||||
return m_Vector[n];
|
||||
}
|
||||
|
||||
bool Defined(const char* pString) const
|
||||
{
|
||||
return m_SymbolTable.Find(pString) != UTL_INVAL_SYMBOL;
|
||||
}
|
||||
|
||||
UtlSymId_t Find(const char* pString) const
|
||||
{
|
||||
return m_SymbolTable.Find(pString);
|
||||
}
|
||||
|
||||
static UtlSymId_t InvalidIndex()
|
||||
{
|
||||
return UTL_INVAL_SYMBOL;
|
||||
}
|
||||
|
||||
int GetNumStrings(void) const
|
||||
{
|
||||
return m_SymbolTable.GetNumStrings();
|
||||
}
|
||||
|
||||
const char* String(int n) const
|
||||
{
|
||||
return m_SymbolTable.String(n);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_Vector.RemoveAll();
|
||||
m_SymbolTable.RemoveAll();
|
||||
}
|
||||
|
||||
void Purge()
|
||||
{
|
||||
m_Vector.Purge();
|
||||
m_SymbolTable.RemoveAll();
|
||||
}
|
||||
|
||||
void PurgeAndDeleteElements()
|
||||
{
|
||||
m_Vector.PurgeAndDeleteElements();
|
||||
m_SymbolTable.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
CUtlVector<T> m_Vector;
|
||||
CUtlSymbolTable m_SymbolTable;
|
||||
};
|
||||
|
||||
#endif
|
60
SpyCustom/sdk/VGUI.h
Normal file
60
SpyCustom/sdk/VGUI.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef VGUI_H
|
||||
#define VGUI_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#define null 0L
|
||||
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#pragma warning( disable: 4800 )
|
||||
#pragma warning( disable: 4786 )
|
||||
#pragma warning( disable: 4355 )
|
||||
#pragma warning( disable: 4097 )
|
||||
#pragma warning( disable: 4514 )
|
||||
#pragma warning( disable: 4100 )
|
||||
#pragma warning( disable: 4127 )
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
|
||||
#ifndef _WCHAR_T_DEFINED
|
||||
#if !defined( __x86_64__ ) && !defined( __WCHAR_TYPE__ )
|
||||
typedef unsigned short wchar_t;
|
||||
#define _WCHAR_T_DEFINED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace vgui
|
||||
{
|
||||
typedef unsigned int VPANEL;
|
||||
|
||||
typedef unsigned long HScheme;
|
||||
typedef unsigned long HTexture;
|
||||
typedef unsigned long HCursor;
|
||||
typedef unsigned long HPanel;
|
||||
const HPanel INVALID_PANEL = 0xffffffff;
|
||||
typedef unsigned long HFont;
|
||||
const HFont INVALID_FONT = 0;
|
||||
}
|
||||
|
||||
#include "strtools.h"
|
||||
|
||||
#if 0
|
||||
#define USE_GETKERNEDCHARWIDTH 1
|
||||
#else
|
||||
#define USE_GETKERNEDCHARWIDTH 0
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
797
SpyCustom/sdk/utlintrusivelist.h
Normal file
797
SpyCustom/sdk/utlintrusivelist.h
Normal file
@ -0,0 +1,797 @@
|
||||
#ifndef UTILINTRUSIVELIST_H
|
||||
#define UTILINTRUSIVELIST_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "basetypes.h"
|
||||
#include "utlmemory.h"
|
||||
#include "dbg.h"
|
||||
|
||||
|
||||
|
||||
namespace IntrusiveList
|
||||
{
|
||||
#ifdef SUPERSLOW_DEBUG_VERSION
|
||||
template<class T> inline void ValidateDList(T* head)
|
||||
{
|
||||
if (head)
|
||||
{
|
||||
Assert(head->m_pPrev == 0);
|
||||
}
|
||||
while (head)
|
||||
{
|
||||
if (head->m_pNext)
|
||||
{
|
||||
Assert(head->m_pNext->m_pPrev == head);
|
||||
}
|
||||
if (head->m_pPrev)
|
||||
{
|
||||
Assert(head->m_pPrev->m_pNext == head);
|
||||
}
|
||||
head = head->m_pNext;
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<class T> inline void ValidateDList(T* )
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template <class T> inline void MoveDNodeBackwards(T* which, T*& head)
|
||||
{
|
||||
if (which->m_pPrev)
|
||||
{
|
||||
T* p = which->m_pPrev;
|
||||
T* pp = p->m_pPrev;
|
||||
T* n = which->m_pNext;
|
||||
Assert(p->m_pNext == which);
|
||||
if (n)
|
||||
{
|
||||
Assert(n->m_pPrev == which);
|
||||
n->m_pPrev = p;
|
||||
}
|
||||
if (pp)
|
||||
{
|
||||
Assert(pp->m_pNext == p);
|
||||
pp->m_pNext = which;
|
||||
}
|
||||
else
|
||||
{
|
||||
head = which;
|
||||
}
|
||||
which->m_pNext = p;
|
||||
which->m_pPrev = pp;
|
||||
p->m_pNext = n;
|
||||
p->m_pPrev = which;
|
||||
}
|
||||
ValidateDList(head);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T> inline void RemoveFromDList(T*& head, T* which)
|
||||
{
|
||||
if (which->m_pPrev)
|
||||
{
|
||||
Assert(which->m_pPrev->m_pNext == which);
|
||||
which->m_pPrev->m_pNext = which->m_pNext;
|
||||
if (which->m_pNext)
|
||||
{
|
||||
Assert(which->m_pNext->m_pPrev == which);
|
||||
which->m_pNext->m_pPrev = which->m_pPrev;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (head == which)
|
||||
{
|
||||
head = which->m_pNext;
|
||||
if (head)
|
||||
{
|
||||
Assert(head->m_pPrev == which);
|
||||
head->m_pPrev = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
which->m_pNext = which->m_pPrev = 0;
|
||||
ValidateDList(head);
|
||||
|
||||
}
|
||||
|
||||
template<class T> bool OnDList(T const* head, T const* which)
|
||||
{
|
||||
return (head == which) || (which->m_pNext != 0) || (which->m_pPrev != 0);
|
||||
}
|
||||
|
||||
template<class T> void AddToDTail(T*& head, T* node)
|
||||
{
|
||||
node->m_pNext = 0;
|
||||
if (!head)
|
||||
{
|
||||
head = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
T* ptr = head;
|
||||
while (ptr->m_pNext)
|
||||
{
|
||||
ptr = ptr->m_pNext;
|
||||
}
|
||||
ptr->m_pNext = node;
|
||||
node->m_pPrev = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> inline void AddToDHead(T*& head, T* which)
|
||||
{
|
||||
which->m_pNext = head;
|
||||
if (head)
|
||||
{
|
||||
head->m_pPrev = which;
|
||||
}
|
||||
which->m_pPrev = 0;
|
||||
head = which;
|
||||
ValidateDList(head);
|
||||
}
|
||||
|
||||
template<class T> inline void AddToDHeadWithTailPtr(T*& head, T* which, T*& tailptr)
|
||||
{
|
||||
which->m_pNext = head;
|
||||
if (head)
|
||||
{
|
||||
head->m_pPrev = which;
|
||||
}
|
||||
else
|
||||
{
|
||||
tailptr = which;
|
||||
}
|
||||
which->m_pPrev = 0;
|
||||
head = which;
|
||||
ValidateDList(head);
|
||||
}
|
||||
|
||||
template<class T> inline void AddToDTailWithTailPtr(T*& head, T* which, T*& tailptr)
|
||||
{
|
||||
if (!tailptr)
|
||||
{
|
||||
Assert(!head);
|
||||
which->m_pPrev = which->m_pNext = 0;
|
||||
tailptr = head = which;
|
||||
}
|
||||
else
|
||||
{
|
||||
which->m_pNext = 0;
|
||||
which->m_pPrev = tailptr;
|
||||
tailptr->m_pNext = which;
|
||||
tailptr = which;
|
||||
}
|
||||
ValidateDList(head);
|
||||
}
|
||||
|
||||
template<class T> inline void RemoveFromDListWithTailPtr(T*& head, T* which, T*& tailptr)
|
||||
{
|
||||
if (which == tailptr)
|
||||
{
|
||||
tailptr = which->m_pPrev;
|
||||
}
|
||||
if (which->m_pPrev)
|
||||
{
|
||||
Assert(which->m_pPrev->m_pNext == which);
|
||||
which->m_pPrev->m_pNext = which->m_pNext;
|
||||
if (which->m_pNext)
|
||||
{
|
||||
Assert(which->m_pNext->m_pPrev == which);
|
||||
which->m_pNext->m_pPrev = which->m_pPrev;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (head == which)
|
||||
{
|
||||
head = which->m_pNext;
|
||||
if (head)
|
||||
{
|
||||
Assert(head->m_pPrev == which);
|
||||
head->m_pPrev = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
which->m_pNext = which->m_pPrev = 0;
|
||||
ValidateDList(head);
|
||||
|
||||
}
|
||||
|
||||
template<class T> inline void DeleteFromDListWithTailPtr(T*& head, T* which, T*& tailptr)
|
||||
{
|
||||
T* tmp = which;
|
||||
if (which == tailptr)
|
||||
{
|
||||
tailptr = which->m_pPrev;
|
||||
}
|
||||
if (which->m_pPrev)
|
||||
{
|
||||
Assert(which->m_pPrev->m_pNext == which);
|
||||
which->m_pPrev->m_pNext = which->m_pNext;
|
||||
if (which->m_pNext)
|
||||
{
|
||||
Assert(which->m_pNext->m_pPrev == which);
|
||||
which->m_pNext->m_pPrev = which->m_pPrev;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (head == which)
|
||||
{
|
||||
head = which->m_pNext;
|
||||
if (head)
|
||||
{
|
||||
Assert(head->m_pPrev == which);
|
||||
head->m_pPrev = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
which->m_pNext = which->m_pPrev = 0;
|
||||
delete tmp;
|
||||
ValidateDList(head);
|
||||
}
|
||||
|
||||
template<class T> inline void AddToDPriority(T*& head, T* which)
|
||||
{
|
||||
T* prevnode = 0;
|
||||
for (T* curnode = head; curnode; curnode = curnode->m_pNext)
|
||||
{
|
||||
if (which->m_Priority >= curnode->m_Priority)
|
||||
break;
|
||||
prevnode = curnode;
|
||||
}
|
||||
if (!prevnode)
|
||||
{
|
||||
AddToDHead(head, which);
|
||||
}
|
||||
else
|
||||
{
|
||||
which->m_pNext = prevnode->m_pNext;
|
||||
prevnode->m_pNext = which;
|
||||
which->m_pPrev = prevnode;
|
||||
if (which->m_pNext)
|
||||
which->m_pNext->m_pPrev = which;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> inline void AddToDPriorityLowestFirst(T*& head, T* which)
|
||||
{
|
||||
T* prevnode = 0;
|
||||
for (T* curnode = head; curnode; curnode = curnode->m_pNext)
|
||||
{
|
||||
if (which->m_Priority <= curnode->m_Priority)
|
||||
break;
|
||||
prevnode = curnode;
|
||||
}
|
||||
if (!prevnode)
|
||||
{
|
||||
AddToDHead(head, which);
|
||||
}
|
||||
else
|
||||
{
|
||||
which->m_pNext = prevnode->m_pNext;
|
||||
prevnode->m_pNext = which;
|
||||
which->m_pPrev = prevnode;
|
||||
if (which->m_pNext)
|
||||
which->m_pNext->m_pPrev = which;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T> T* LastNode(T* head)
|
||||
{
|
||||
if (head)
|
||||
{
|
||||
while (head->m_pNext)
|
||||
{
|
||||
head = head->m_pNext;
|
||||
}
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class V> void RemoveFromList(T*& head, V* which)
|
||||
{
|
||||
if (head == which)
|
||||
{
|
||||
head = which->m_pNext;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (T* i = head; i; i = i->m_pNext)
|
||||
{
|
||||
if (i->m_pNext == which)
|
||||
{
|
||||
i->m_pNext = which->m_pNext;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class V> void DeleteFromList(T*& head, V* which)
|
||||
{
|
||||
T* tmp;
|
||||
if (head == which)
|
||||
{
|
||||
tmp = which->m_pNext;
|
||||
delete(head);
|
||||
head = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (T* i = head; i; i = i->m_pNext)
|
||||
{
|
||||
if (i->m_pNext == which)
|
||||
{
|
||||
tmp = which->m_pNext;
|
||||
delete(which);
|
||||
i->m_pNext = tmp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class V> int PositionInList(T* head, V* node)
|
||||
{
|
||||
int pos = 0;
|
||||
while (head)
|
||||
{
|
||||
if (head == node) return pos;
|
||||
head = head->m_pNext;
|
||||
pos++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
template<class T> T* NthNode(T* head, int idx)
|
||||
{
|
||||
while (idx && head)
|
||||
{
|
||||
idx--;
|
||||
head = head->m_pNext;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
template<class T, class V> static inline void AddToHead(T*& head, V* node)
|
||||
{
|
||||
node->m_pNext = head;
|
||||
head = node;
|
||||
}
|
||||
|
||||
template<class T, class V> static inline void AddToTail(T*& head, V* node)
|
||||
{
|
||||
node->m_pNext = NULL;
|
||||
if (!head)
|
||||
head = node;
|
||||
else
|
||||
{
|
||||
T* pLastNode = head;
|
||||
while (pLastNode->m_pNext)
|
||||
pLastNode = pLastNode->m_pNext;
|
||||
pLastNode->m_pNext = node;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class V> static inline void AddToHead(T*& head, T*& tail, V* node)
|
||||
{
|
||||
if (!head)
|
||||
{
|
||||
tail = node;
|
||||
}
|
||||
node->m_pNext = head;
|
||||
head = node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T> static inline T* PrevNode(T* head, T* node)
|
||||
{
|
||||
T* i;
|
||||
for (i = head; i; i = i->m_pNext)
|
||||
{
|
||||
if (i->m_pNext == node)
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class V> void AddToEnd(T*& head, V* node)
|
||||
{
|
||||
node->m_pNext = 0;
|
||||
if (!head)
|
||||
{
|
||||
head = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
T* ptr = head;
|
||||
while (ptr->m_pNext)
|
||||
{
|
||||
ptr = ptr->m_pNext;
|
||||
}
|
||||
ptr->m_pNext = node;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class V> void AddToEndWithTail(T*& head, T*& tail, V* node)
|
||||
{
|
||||
Assert((head && tail) || ((!head) && (!tail)));
|
||||
node->m_pNext = 0;
|
||||
if (!head)
|
||||
{
|
||||
head = tail = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
tail->m_pNext = node;
|
||||
tail = node;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> void AddSortedByName(T*& head, T* node)
|
||||
{
|
||||
if ((!head) ||
|
||||
(stricmp(node->m_Name, head->m_Name) == -1))
|
||||
{
|
||||
node->m_pNext = head;
|
||||
head = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
T* t;
|
||||
for (t = head; t->m_pNext; t = t->m_pNext)
|
||||
if (stricmp(t->m_pNext->m_Name, node->m_Name) >= 0)
|
||||
break;
|
||||
node->m_pNext = t->m_pNext;
|
||||
t->m_pNext = node;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> int ListLength(T* head)
|
||||
{
|
||||
int len = 0;
|
||||
while (head)
|
||||
{
|
||||
len++;
|
||||
head = head->m_pNext;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
template<class T> void KillList(T*& head)
|
||||
{
|
||||
while (head)
|
||||
{
|
||||
delete head;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T> void DeleteList(T*& head)
|
||||
{
|
||||
while (head)
|
||||
{
|
||||
T* tmp = head->m_pNext;
|
||||
delete head;
|
||||
head = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> static inline T* FindNamedNode(T* head, char const* name)
|
||||
{
|
||||
for (; head && stricmp(head->m_Name, name); head = head->m_pNext)
|
||||
{
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
template <class T> static inline T* FindNamedNodeCaseSensitive(T* head, char const* name)
|
||||
{
|
||||
for (; head && strcmp(head->m_Name, name); head = head->m_pNext)
|
||||
{
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
template <class T, class U, class V> static inline T* FindNodeByField(T* head, U data, U V::* field)
|
||||
{
|
||||
while (head)
|
||||
{
|
||||
if (data == (*head).*field)
|
||||
return head;
|
||||
head = head->m_pNext;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class T, class U, class V> static inline T* FindNodeByFieldWithPrev(T* head, U data, U V::* field, T*& prev)
|
||||
{
|
||||
prev = 0;
|
||||
for (T* i = head; i; i = i->m_pNext)
|
||||
{
|
||||
if (data == (*i).*field)
|
||||
return i;
|
||||
prev = i;
|
||||
}
|
||||
prev = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template<class T> void SortList(T*& head, int (*comparefn)(T* a, T* b))
|
||||
{
|
||||
int didswap = 1;
|
||||
while (didswap)
|
||||
{
|
||||
didswap = 0;
|
||||
T* prev = 0;
|
||||
for (T* i = head; i && i->m_pNext; i = i->m_pNext)
|
||||
{
|
||||
int rslt = (*comparefn)(i, i->m_pNext);
|
||||
if (rslt == -1)
|
||||
{
|
||||
didswap = 1;
|
||||
T* newfirst = i->m_pNext;
|
||||
if (prev)
|
||||
{
|
||||
prev->m_pNext = newfirst;
|
||||
i->m_pNext = newfirst->m_pNext;
|
||||
newfirst->m_pNext = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
head = i->m_pNext;
|
||||
i->m_pNext = newfirst->m_pNext;
|
||||
newfirst->m_pNext = i;
|
||||
}
|
||||
i = newfirst;
|
||||
}
|
||||
prev = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> void SortDList(T*& head, int (*comparefn)(T* a, T* b))
|
||||
{
|
||||
SortList(head, comparefn);
|
||||
T* prev = 0;
|
||||
for (T* i = head; i; i = i->m_pNext)
|
||||
{
|
||||
i->m_pPrev = prev;
|
||||
prev = i;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> T* ReversedList(T* head)
|
||||
{
|
||||
T* pNewHead = NULL;
|
||||
while (head)
|
||||
{
|
||||
T* pNext = head->m_pNext;
|
||||
#ifdef INTERVIEW_QUESTION
|
||||
head->m_pNext = pNewHead;
|
||||
pNewHead = head;
|
||||
#else
|
||||
AddToHead(pNewHead, head);
|
||||
#endif
|
||||
head = pNext;
|
||||
}
|
||||
return pNewHead;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T> class CUtlIntrusiveList
|
||||
{
|
||||
public:
|
||||
T* m_pHead;
|
||||
|
||||
FORCEINLINE T* Head(void) const
|
||||
{
|
||||
return m_pHead;
|
||||
}
|
||||
|
||||
FORCEINLINE CUtlIntrusiveList(void)
|
||||
{
|
||||
m_pHead = NULL;
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void RemoveAll(void)
|
||||
{
|
||||
m_pHead = NULL;
|
||||
}
|
||||
FORCEINLINE void AddToHead(T* node)
|
||||
{
|
||||
IntrusiveList::AddToHead(m_pHead, node);
|
||||
}
|
||||
|
||||
FORCEINLINE void AddToTail(T* node)
|
||||
{
|
||||
IntrusiveList::AddToTail(m_pHead, node);
|
||||
}
|
||||
|
||||
void RemoveNode(T* which)
|
||||
{
|
||||
IntrusiveList::RemoveFromList(m_pHead, which);
|
||||
}
|
||||
|
||||
void KillList(void)
|
||||
{
|
||||
while (m_pHead)
|
||||
{
|
||||
delete m_pHead;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
T* PrevNode(T* node)
|
||||
{
|
||||
return IntrusiveList::PrevNode(m_pHead, node);
|
||||
}
|
||||
|
||||
int NthNode(int n)
|
||||
{
|
||||
return NthNode(m_pHead, n);
|
||||
}
|
||||
|
||||
void Purge(void)
|
||||
{
|
||||
while (m_pHead)
|
||||
{
|
||||
T* tmp = m_pHead->m_pNext;
|
||||
delete m_pHead;
|
||||
m_pHead = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int Count(void) const
|
||||
{
|
||||
return IntrusiveList::ListLength(m_pHead);
|
||||
}
|
||||
|
||||
FORCEINLINE T* FindNamedNodeCaseSensitive(char const* pName) const
|
||||
{
|
||||
return IntrusiveList::FindNamedNodeCaseSensitive(m_pHead, pName);
|
||||
|
||||
}
|
||||
|
||||
T* RemoveHead(void)
|
||||
{
|
||||
if (m_pHead)
|
||||
{
|
||||
T* pRet = m_pHead;
|
||||
m_pHead = pRet->m_pNext;
|
||||
return pRet;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T> class CUtlIntrusiveDList : public CUtlIntrusiveList<T>
|
||||
{
|
||||
public:
|
||||
|
||||
FORCEINLINE void AddToHead(T* node)
|
||||
{
|
||||
IntrusiveList::AddToDHead(CUtlIntrusiveList<T>::m_pHead, node);
|
||||
}
|
||||
FORCEINLINE void AddToTail(T* node)
|
||||
{
|
||||
IntrusiveList::AddToDTail(CUtlIntrusiveList<T>::m_pHead, node);
|
||||
}
|
||||
|
||||
void RemoveNode(T* which)
|
||||
{
|
||||
IntrusiveList::RemoveFromDList(CUtlIntrusiveList<T>::m_pHead, which);
|
||||
}
|
||||
|
||||
T* RemoveHead(void)
|
||||
{
|
||||
if (CUtlIntrusiveList<T>::m_pHead)
|
||||
{
|
||||
T* pRet = CUtlIntrusiveList<T>::m_pHead;
|
||||
CUtlIntrusiveList<T>::m_pHead = CUtlIntrusiveList<T>::m_pHead->m_pNext;
|
||||
if (CUtlIntrusiveList<T>::m_pHead)
|
||||
CUtlIntrusiveList<T>::m_pHead->m_pPrev = NULL;
|
||||
return pRet;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
T* PrevNode(T* node)
|
||||
{
|
||||
return (node) ? node->m_Prev : NULL;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class T> class CUtlIntrusiveDListWithTailPtr : public CUtlIntrusiveDList<T>
|
||||
{
|
||||
public:
|
||||
|
||||
T* m_pTailPtr;
|
||||
|
||||
FORCEINLINE CUtlIntrusiveDListWithTailPtr(void) : CUtlIntrusiveDList<T>()
|
||||
{
|
||||
m_pTailPtr = NULL;
|
||||
}
|
||||
|
||||
FORCEINLINE void AddToHead(T* node)
|
||||
{
|
||||
IntrusiveList::AddToDHeadWithTailPtr(CUtlIntrusiveList<T>::m_pHead, node, m_pTailPtr);
|
||||
}
|
||||
FORCEINLINE void AddToTail(T* node)
|
||||
{
|
||||
IntrusiveList::AddToDTailWithTailPtr(CUtlIntrusiveList<T>::m_pHead, node, m_pTailPtr);
|
||||
}
|
||||
|
||||
void RemoveNode(T* pWhich)
|
||||
{
|
||||
IntrusiveList::RemoveFromDListWithTailPtr(CUtlIntrusiveList<T>::m_pHead, pWhich, m_pTailPtr);
|
||||
}
|
||||
|
||||
void Purge(void)
|
||||
{
|
||||
CUtlIntrusiveList<T>::Purge();
|
||||
m_pTailPtr = NULL;
|
||||
}
|
||||
|
||||
void Kill(void)
|
||||
{
|
||||
CUtlIntrusiveList<T>::Purge();
|
||||
m_pTailPtr = NULL;
|
||||
}
|
||||
|
||||
T* RemoveHead(void)
|
||||
{
|
||||
if (CUtlIntrusiveDList<T>::m_pHead)
|
||||
{
|
||||
T* pRet = CUtlIntrusiveDList<T>::m_pHead;
|
||||
CUtlIntrusiveDList<T>::m_pHead = CUtlIntrusiveDList<T>::m_pHead->m_pNext;
|
||||
if (CUtlIntrusiveDList<T>::m_pHead)
|
||||
CUtlIntrusiveDList<T>::m_pHead->m_pPrev = NULL;
|
||||
if (!CUtlIntrusiveDList<T>::m_pHead)
|
||||
m_pTailPtr = NULL;
|
||||
ValidateDList(CUtlIntrusiveDList<T>::m_pHead);
|
||||
return pRet;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
T* PrevNode(T* node)
|
||||
{
|
||||
return (node) ? node->m_Prev : NULL;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class T> void PrependDListWithTailToDList(CUtlIntrusiveDListWithTailPtr<T>& src,
|
||||
CUtlIntrusiveDList<T>& dest)
|
||||
{
|
||||
if (src.m_pHead)
|
||||
{
|
||||
src.m_pTailPtr->m_pNext = dest.m_pHead;
|
||||
if (dest.m_pHead)
|
||||
dest.m_pHead->m_pPrev = src.m_pTailPtr;
|
||||
dest.m_pHead = src.m_pHead;
|
||||
IntrusiveList::ValidateDList(dest.m_pHead);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
1077
SpyCustom/sdk/utllinkedlist.h
Normal file
1077
SpyCustom/sdk/utllinkedlist.h
Normal file
File diff suppressed because it is too large
Load Diff
245
SpyCustom/sdk/utlmap.h
Normal file
245
SpyCustom/sdk/utlmap.h
Normal file
@ -0,0 +1,245 @@
|
||||
#ifndef UTLMAP_H
|
||||
#define UTLMAP_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "dbg.h"
|
||||
#include "utlrbtree.h"
|
||||
|
||||
#define FOR_EACH_MAP( mapName, iteratorName ) \
|
||||
for ( int iteratorName = (mapName).FirstInorder(); (mapName).IsUtlMap && iteratorName != (mapName).InvalidIndex(); iteratorName = (mapName).NextInorder( iteratorName ) )
|
||||
|
||||
#define FOR_EACH_MAP_FAST( mapName, iteratorName ) \
|
||||
for ( int iteratorName = 0; (mapName).IsUtlMap && iteratorName < (mapName).MaxElement(); ++iteratorName ) if ( !(mapName).IsValidIndex( iteratorName ) ) continue; else
|
||||
|
||||
|
||||
struct base_utlmap_t
|
||||
{
|
||||
public:
|
||||
enum { IsUtlMap = true };
|
||||
};
|
||||
|
||||
template <typename K, typename T, typename I = unsigned short, typename LessFunc_t = bool (*)(const K&, const K&)>
|
||||
class CUtlMap : public base_utlmap_t
|
||||
{
|
||||
public:
|
||||
typedef K KeyType_t;
|
||||
typedef T ElemType_t;
|
||||
typedef I IndexType_t;
|
||||
|
||||
CUtlMap(int growSize = 0, int initSize = 0, const LessFunc_t& lessfunc = 0)
|
||||
: m_Tree(growSize, initSize, CKeyLess(lessfunc))
|
||||
{
|
||||
}
|
||||
|
||||
CUtlMap(LessFunc_t lessfunc)
|
||||
: m_Tree(CKeyLess(lessfunc))
|
||||
{
|
||||
}
|
||||
|
||||
void EnsureCapacity(int num) { m_Tree.EnsureCapacity(num); }
|
||||
|
||||
ElemType_t& Element(IndexType_t i) { return m_Tree.Element(i).elem; }
|
||||
const ElemType_t& Element(IndexType_t i) const { return m_Tree.Element(i).elem; }
|
||||
ElemType_t& operator[](IndexType_t i) { return m_Tree.Element(i).elem; }
|
||||
const ElemType_t& operator[](IndexType_t i) const { return m_Tree.Element(i).elem; }
|
||||
KeyType_t& Key(IndexType_t i) { return m_Tree.Element(i).key; }
|
||||
const KeyType_t& Key(IndexType_t i) const { return m_Tree.Element(i).key; }
|
||||
|
||||
|
||||
unsigned int Count() const { return m_Tree.Count(); }
|
||||
|
||||
IndexType_t MaxElement() const { return m_Tree.MaxElement(); }
|
||||
|
||||
bool IsValidIndex(IndexType_t i) const { return m_Tree.IsValidIndex(i); }
|
||||
|
||||
bool IsValid() const { return m_Tree.IsValid(); }
|
||||
|
||||
static IndexType_t InvalidIndex() { return CTree::InvalidIndex(); }
|
||||
|
||||
void SetLessFunc(LessFunc_t func)
|
||||
{
|
||||
m_Tree.SetLessFunc(CKeyLess(func));
|
||||
}
|
||||
|
||||
IndexType_t Insert(const KeyType_t& key, const ElemType_t& insert)
|
||||
{
|
||||
Node_t node;
|
||||
node.key = key;
|
||||
node.elem = insert;
|
||||
return m_Tree.Insert(node);
|
||||
}
|
||||
|
||||
IndexType_t Insert(const KeyType_t& key)
|
||||
{
|
||||
Node_t node;
|
||||
node.key = key;
|
||||
return m_Tree.Insert(node);
|
||||
}
|
||||
|
||||
IndexType_t InsertWithDupes(const KeyType_t& key, const ElemType_t& insert)
|
||||
{
|
||||
Node_t node;
|
||||
node.key = key;
|
||||
node.elem = insert;
|
||||
return m_Tree.Insert(node);
|
||||
}
|
||||
|
||||
IndexType_t InsertWithDupes(const KeyType_t& key)
|
||||
{
|
||||
Node_t node;
|
||||
node.key = key;
|
||||
return m_Tree.Insert(node);
|
||||
}
|
||||
|
||||
|
||||
bool HasElement(const KeyType_t& key) const
|
||||
{
|
||||
Node_t dummyNode;
|
||||
dummyNode.key = key;
|
||||
return m_Tree.HasElement(dummyNode);
|
||||
}
|
||||
|
||||
|
||||
IndexType_t Find(const KeyType_t& key) const
|
||||
{
|
||||
Node_t dummyNode;
|
||||
dummyNode.key = key;
|
||||
return m_Tree.Find(dummyNode);
|
||||
}
|
||||
|
||||
IndexType_t FindFirst(const KeyType_t& key) const
|
||||
{
|
||||
Node_t dummyNode;
|
||||
dummyNode.key = key;
|
||||
return m_Tree.FindFirst(dummyNode);
|
||||
}
|
||||
|
||||
|
||||
const ElemType_t& FindElement(const KeyType_t& key, const ElemType_t& defaultValue) const
|
||||
{
|
||||
IndexType_t i = Find(key);
|
||||
if (i == InvalidIndex())
|
||||
return defaultValue;
|
||||
return Element(i);
|
||||
}
|
||||
|
||||
|
||||
IndexType_t FindClosest(const KeyType_t& key, CompareOperands_t eFindCriteria) const
|
||||
{
|
||||
Node_t dummyNode;
|
||||
dummyNode.key = key;
|
||||
return m_Tree.FindClosest(dummyNode, eFindCriteria);
|
||||
}
|
||||
|
||||
void RemoveAt(IndexType_t i) { m_Tree.RemoveAt(i); }
|
||||
bool Remove(const KeyType_t& key)
|
||||
{
|
||||
Node_t dummyNode;
|
||||
dummyNode.key = key;
|
||||
return m_Tree.Remove(dummyNode);
|
||||
}
|
||||
|
||||
void RemoveAll() { m_Tree.RemoveAll(); }
|
||||
void Purge() { m_Tree.Purge(); }
|
||||
|
||||
void PurgeAndDeleteElements();
|
||||
|
||||
IndexType_t FirstInorder() const { return m_Tree.FirstInorder(); }
|
||||
IndexType_t NextInorder(IndexType_t i) const { return m_Tree.NextInorder(i); }
|
||||
IndexType_t PrevInorder(IndexType_t i) const { return m_Tree.PrevInorder(i); }
|
||||
IndexType_t LastInorder() const { return m_Tree.LastInorder(); }
|
||||
|
||||
IndexType_t NextInorderSameKey(IndexType_t i) const
|
||||
{
|
||||
IndexType_t iNext = NextInorder(i);
|
||||
if (!IsValidIndex(iNext))
|
||||
return InvalidIndex();
|
||||
if (Key(iNext) != Key(i))
|
||||
return InvalidIndex();
|
||||
return iNext;
|
||||
}
|
||||
|
||||
void Reinsert(const KeyType_t& key, IndexType_t i)
|
||||
{
|
||||
m_Tree[i].key = key;
|
||||
m_Tree.Reinsert(i);
|
||||
}
|
||||
|
||||
IndexType_t InsertOrReplace(const KeyType_t& key, const ElemType_t& insert)
|
||||
{
|
||||
IndexType_t i = Find(key);
|
||||
if (i != InvalidIndex())
|
||||
{
|
||||
Element(i) = insert;
|
||||
return i;
|
||||
}
|
||||
|
||||
return Insert(key, insert);
|
||||
}
|
||||
|
||||
void Swap(CUtlMap< K, T, I >& that)
|
||||
{
|
||||
m_Tree.Swap(that.m_Tree);
|
||||
}
|
||||
|
||||
|
||||
struct Node_t
|
||||
{
|
||||
Node_t()
|
||||
{
|
||||
}
|
||||
|
||||
Node_t(const Node_t& from)
|
||||
: key(from.key),
|
||||
elem(from.elem)
|
||||
{
|
||||
}
|
||||
|
||||
KeyType_t key;
|
||||
ElemType_t elem;
|
||||
};
|
||||
|
||||
class CKeyLess
|
||||
{
|
||||
public:
|
||||
CKeyLess(const LessFunc_t& lessFunc) : m_LessFunc(lessFunc) {}
|
||||
|
||||
bool operator!() const
|
||||
{
|
||||
return !m_LessFunc;
|
||||
}
|
||||
|
||||
bool operator()(const Node_t& left, const Node_t& right) const
|
||||
{
|
||||
return m_LessFunc(left.key, right.key);
|
||||
}
|
||||
|
||||
LessFunc_t m_LessFunc;
|
||||
};
|
||||
|
||||
typedef CUtlRBTree<Node_t, I, CKeyLess> CTree;
|
||||
|
||||
CTree* AccessTree() { return &m_Tree; }
|
||||
|
||||
protected:
|
||||
CTree m_Tree;
|
||||
};
|
||||
|
||||
template< typename K, typename T, typename I, typename LessFunc_t >
|
||||
inline void CUtlMap<K, T, I, LessFunc_t>::PurgeAndDeleteElements()
|
||||
{
|
||||
for (I i = 0; i < MaxElement(); ++i)
|
||||
{
|
||||
if (!IsValidIndex(i))
|
||||
continue;
|
||||
|
||||
delete Element(i);
|
||||
}
|
||||
|
||||
Purge();
|
||||
}
|
||||
|
||||
#endif
|
957
SpyCustom/sdk/utlmemory.h
Normal file
957
SpyCustom/sdk/utlmemory.h
Normal file
@ -0,0 +1,957 @@
|
||||
#ifndef UTLMEMORY_H
|
||||
#define UTLMEMORY_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "dbg.h"
|
||||
#include <string.h>
|
||||
#include "platform.h"
|
||||
|
||||
#include "memalloc.h"
|
||||
#include "mathlib.h"
|
||||
#include "memdbgon.h"
|
||||
|
||||
#pragma warning (disable:4100)
|
||||
#pragma warning (disable:4514)
|
||||
|
||||
|
||||
|
||||
#ifdef UTLMEMORY_TRACK
|
||||
#define UTLMEMORY_TRACK_ALLOC() MemAlloc_RegisterAllocation( "||Sum of all UtlMemory||", 0, m_nAllocationCount * sizeof(T), m_nAllocationCount * sizeof(T), 0 )
|
||||
#define UTLMEMORY_TRACK_FREE() if ( !m_pMemory ) ; else MemAlloc_RegisterDeallocation( "||Sum of all UtlMemory||", 0, m_nAllocationCount * sizeof(T), m_nAllocationCount * sizeof(T), 0 )
|
||||
#else
|
||||
#define UTLMEMORY_TRACK_ALLOC() ((void)0)
|
||||
#define UTLMEMORY_TRACK_FREE() ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
template< class T, class I = int >
|
||||
class CUtlMemory
|
||||
{
|
||||
template< class A, class B> friend class CUtlVector;
|
||||
template< class A, size_t B> friend class CUtlVectorFixedGrowableCompat;
|
||||
public:
|
||||
CUtlMemory(int nGrowSize = 0, int nInitSize = 0);
|
||||
CUtlMemory(T* pMemory, int numElements);
|
||||
CUtlMemory(const T* pMemory, int numElements);
|
||||
~CUtlMemory();
|
||||
|
||||
CUtlMemory(const CUtlMemory&) = delete;
|
||||
CUtlMemory& operator=(const CUtlMemory&) = delete;
|
||||
|
||||
CUtlMemory(CUtlMemory&& moveFrom);
|
||||
CUtlMemory& operator=(CUtlMemory&& moveFrom);
|
||||
|
||||
void Init(int nGrowSize = 0, int nInitSize = 0);
|
||||
|
||||
class Iterator_t
|
||||
{
|
||||
public:
|
||||
Iterator_t(I i) : index(i) {}
|
||||
I index;
|
||||
|
||||
bool operator==(const Iterator_t it) const { return index == it.index; }
|
||||
bool operator!=(const Iterator_t it) const { return index != it.index; }
|
||||
};
|
||||
Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); }
|
||||
Iterator_t Next(const Iterator_t& it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); }
|
||||
I GetIndex(const Iterator_t& it) const { return it.index; }
|
||||
bool IsIdxAfter(I i, const Iterator_t& it) const { return i > it.index; }
|
||||
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index); }
|
||||
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); }
|
||||
|
||||
T& operator[](I i);
|
||||
const T& operator[](I i) const;
|
||||
T& Element(I i);
|
||||
const T& Element(I i) const;
|
||||
|
||||
bool IsIdxValid(I i) const;
|
||||
|
||||
static const I INVALID_INDEX = (I)-1;
|
||||
static I InvalidIndex() { return INVALID_INDEX; }
|
||||
|
||||
T* Base();
|
||||
const T* Base() const;
|
||||
|
||||
void SetExternalBuffer(T* pMemory, int numElements);
|
||||
void SetExternalBuffer(const T* pMemory, int numElements);
|
||||
void AssumeMemory(T* pMemory, int nSize);
|
||||
T* Detach();
|
||||
void* DetachMemory();
|
||||
|
||||
void Swap(CUtlMemory< T, I >& mem);
|
||||
|
||||
void ConvertToGrowableMemory(int nGrowSize);
|
||||
|
||||
int NumAllocated() const;
|
||||
int Count() const;
|
||||
|
||||
void Grow(int num = 1);
|
||||
|
||||
void EnsureCapacity(int num);
|
||||
|
||||
void Purge();
|
||||
|
||||
void Purge(int numElements);
|
||||
|
||||
bool IsExternallyAllocated() const;
|
||||
|
||||
bool IsReadOnly() const;
|
||||
|
||||
void SetGrowSize(int size);
|
||||
|
||||
protected:
|
||||
void ValidateGrowSize()
|
||||
{
|
||||
#ifdef _X360
|
||||
if (m_nGrowSize && m_nGrowSize != EXTERNAL_BUFFER_MARKER)
|
||||
{
|
||||
const int MAX_GROW = 128;
|
||||
if (m_nGrowSize * sizeof(T) > MAX_GROW)
|
||||
{
|
||||
m_nGrowSize = max(1, MAX_GROW / sizeof(T));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
EXTERNAL_BUFFER_MARKER = -1,
|
||||
EXTERNAL_CONST_BUFFER_MARKER = -2,
|
||||
};
|
||||
|
||||
T* m_pMemory;
|
||||
int m_nAllocationCount;
|
||||
int m_nGrowSize;
|
||||
};
|
||||
|
||||
|
||||
template< class T, size_t SIZE, class I = int >
|
||||
class CUtlMemoryFixedGrowable : public CUtlMemory< T, I >
|
||||
{
|
||||
typedef CUtlMemory< T, I > BaseClass;
|
||||
|
||||
public:
|
||||
CUtlMemoryFixedGrowable(int nGrowSize = 0, int nInitSize = SIZE) : BaseClass(m_pFixedMemory, SIZE)
|
||||
{
|
||||
Assert(nInitSize == 0 || nInitSize == SIZE);
|
||||
m_nMallocGrowSize = nGrowSize;
|
||||
}
|
||||
|
||||
void Grow(int nCount = 1)
|
||||
{
|
||||
if (this->IsExternallyAllocated())
|
||||
{
|
||||
this->ConvertToGrowableMemory(m_nMallocGrowSize);
|
||||
}
|
||||
BaseClass::Grow(nCount);
|
||||
}
|
||||
|
||||
void EnsureCapacity(int num)
|
||||
{
|
||||
if (CUtlMemory<T>::m_nAllocationCount >= num)
|
||||
return;
|
||||
|
||||
if (this->IsExternallyAllocated())
|
||||
{
|
||||
this->ConvertToGrowableMemory(m_nMallocGrowSize);
|
||||
}
|
||||
|
||||
BaseClass::EnsureCapacity(num);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_nMallocGrowSize;
|
||||
T m_pFixedMemory[SIZE];
|
||||
};
|
||||
|
||||
template< typename T, size_t SIZE, int nAlignment = 0 >
|
||||
class CUtlMemoryFixed
|
||||
{
|
||||
public:
|
||||
CUtlMemoryFixed(int nGrowSize = 0, int nInitSize = 0) { Assert(nInitSize == 0 || nInitSize == SIZE); }
|
||||
CUtlMemoryFixed(T* pMemory, int numElements) { Assert(0); }
|
||||
|
||||
bool IsIdxValid(int i) const { return (i >= 0) && (i < SIZE); }
|
||||
|
||||
static const int INVALID_INDEX = -1;
|
||||
static int InvalidIndex() { return INVALID_INDEX; }
|
||||
|
||||
T* Base() { if (nAlignment == 0) return (T*)(&m_Memory[0]); else return (T*)AlignValue(&m_Memory[0], nAlignment); }
|
||||
const T* Base() const { if (nAlignment == 0) return (T*)(&m_Memory[0]); else return (T*)AlignValue(&m_Memory[0], nAlignment); }
|
||||
|
||||
T& operator[](int i) { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
const T& operator[](int i) const { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
T& Element(int i) { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
const T& Element(int i) const { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
|
||||
void SetExternalBuffer(T* pMemory, int numElements) { Assert(0); }
|
||||
|
||||
int NumAllocated() const { return SIZE; }
|
||||
int Count() const { return SIZE; }
|
||||
|
||||
void Grow(int num = 1) { Assert(0); }
|
||||
|
||||
void EnsureCapacity(int num) { Assert(num <= SIZE); }
|
||||
|
||||
void Purge() {}
|
||||
|
||||
void Purge(int numElements) { Assert(0); }
|
||||
|
||||
bool IsExternallyAllocated() const { return false; }
|
||||
|
||||
void SetGrowSize(int size) {}
|
||||
|
||||
class Iterator_t
|
||||
{
|
||||
public:
|
||||
Iterator_t(int i) : index(i) {}
|
||||
int index;
|
||||
bool operator==(const Iterator_t it) const { return index == it.index; }
|
||||
bool operator!=(const Iterator_t it) const { return index != it.index; }
|
||||
};
|
||||
Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); }
|
||||
Iterator_t Next(const Iterator_t& it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); }
|
||||
int GetIndex(const Iterator_t& it) const { return it.index; }
|
||||
bool IsIdxAfter(int i, const Iterator_t& it) const { return i > it.index; }
|
||||
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index); }
|
||||
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); }
|
||||
|
||||
private:
|
||||
char m_Memory[SIZE * sizeof(T) + nAlignment];
|
||||
};
|
||||
|
||||
#ifdef _LINUX
|
||||
#define REMEMBER_ALLOC_SIZE_FOR_VALGRIND 1
|
||||
#endif
|
||||
|
||||
template< typename T >
|
||||
class CUtlMemoryConservative
|
||||
{
|
||||
|
||||
public:
|
||||
CUtlMemoryConservative(int nGrowSize = 0, int nInitSize = 0) : m_pMemory(NULL)
|
||||
{
|
||||
#ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND
|
||||
m_nCurAllocSize = 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
CUtlMemoryConservative(T* pMemory, int numElements) { Assert(0); }
|
||||
~CUtlMemoryConservative() { if (m_pMemory) free(m_pMemory); }
|
||||
|
||||
bool IsIdxValid(int i) const { return (IsDebug()) ? (i >= 0 && i < NumAllocated()) : (i >= 0); }
|
||||
static int InvalidIndex() { return -1; }
|
||||
|
||||
T* Base() { return m_pMemory; }
|
||||
const T* Base() const { return m_pMemory; }
|
||||
|
||||
T& operator[](int i) { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
const T& operator[](int i) const { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
T& Element(int i) { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
const T& Element(int i) const { Assert(IsIdxValid(i)); return Base()[i]; }
|
||||
|
||||
void SetExternalBuffer(T* pMemory, int numElements) { Assert(0); }
|
||||
|
||||
FORCEINLINE void RememberAllocSize(size_t sz)
|
||||
{
|
||||
#ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND
|
||||
m_nCurAllocSize = sz;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t AllocSize(void) const
|
||||
{
|
||||
#ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND
|
||||
return m_nCurAllocSize;
|
||||
#else
|
||||
return (m_pMemory) ? g_pMemAlloc->GetSize(m_pMemory) : 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int NumAllocated() const
|
||||
{
|
||||
return AllocSize() / sizeof(T);
|
||||
}
|
||||
int Count() const
|
||||
{
|
||||
return NumAllocated();
|
||||
}
|
||||
|
||||
FORCEINLINE void ReAlloc(size_t sz)
|
||||
{
|
||||
m_pMemory = (T*)realloc(m_pMemory, sz);
|
||||
RememberAllocSize(sz);
|
||||
}
|
||||
void Grow(int num = 1)
|
||||
{
|
||||
int nCurN = NumAllocated();
|
||||
ReAlloc((nCurN + num) * sizeof(T));
|
||||
}
|
||||
|
||||
void EnsureCapacity(int num)
|
||||
{
|
||||
size_t nSize = sizeof(T) * MAX(num, Count());
|
||||
ReAlloc(nSize);
|
||||
}
|
||||
|
||||
void Purge()
|
||||
{
|
||||
free(m_pMemory);
|
||||
RememberAllocSize(0);
|
||||
m_pMemory = NULL;
|
||||
}
|
||||
|
||||
void Purge(int numElements) { ReAlloc(numElements * sizeof(T)); }
|
||||
|
||||
bool IsExternallyAllocated() const { return false; }
|
||||
|
||||
void SetGrowSize(int size) {}
|
||||
|
||||
class Iterator_t
|
||||
{
|
||||
public:
|
||||
Iterator_t(int i, int _limit) : index(i), limit(_limit) {}
|
||||
int index;
|
||||
int limit;
|
||||
bool operator==(const Iterator_t it) const { return index == it.index; }
|
||||
bool operator!=(const Iterator_t it) const { return index != it.index; }
|
||||
};
|
||||
Iterator_t First() const { int limit = NumAllocated(); return Iterator_t(limit ? 0 : InvalidIndex(), limit); }
|
||||
Iterator_t Next(const Iterator_t& it) const { return Iterator_t((it.index + 1 < it.limit) ? it.index + 1 : InvalidIndex(), it.limit); }
|
||||
int GetIndex(const Iterator_t& it) const { return it.index; }
|
||||
bool IsIdxAfter(int i, const Iterator_t& it) const { return i > it.index; }
|
||||
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index) && (it.index < it.limit); }
|
||||
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex(), 0); }
|
||||
|
||||
private:
|
||||
T* m_pMemory;
|
||||
#ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND
|
||||
size_t m_nCurAllocSize;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
CUtlMemory<T, I>::CUtlMemory(int nGrowSize, int nInitAllocationCount) : m_pMemory(0),
|
||||
m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
|
||||
{
|
||||
ValidateGrowSize();
|
||||
Assert(nGrowSize >= 0);
|
||||
if (m_nAllocationCount)
|
||||
{
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
CUtlMemory<T, I>::CUtlMemory(T* pMemory, int numElements) : m_pMemory(pMemory),
|
||||
m_nAllocationCount(numElements)
|
||||
{
|
||||
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
CUtlMemory<T, I>::CUtlMemory(const T* pMemory, int numElements) : m_pMemory((T*)pMemory),
|
||||
m_nAllocationCount(numElements)
|
||||
{
|
||||
m_nGrowSize = EXTERNAL_CONST_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
CUtlMemory<T, I>::~CUtlMemory()
|
||||
{
|
||||
Purge();
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_pMemory = reinterpret_cast<T*>(0xFEFEBAAD);
|
||||
m_nAllocationCount = 0x7BADF00D;
|
||||
#endif
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
CUtlMemory<T, I>::CUtlMemory(CUtlMemory&& moveFrom)
|
||||
: m_pMemory(moveFrom.m_pMemory)
|
||||
, m_nAllocationCount(moveFrom.m_nAllocationCount)
|
||||
, m_nGrowSize(moveFrom.m_nGrowSize)
|
||||
{
|
||||
moveFrom.m_pMemory = nullptr;
|
||||
moveFrom.m_nAllocationCount = 0;
|
||||
moveFrom.m_nGrowSize = 0;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
CUtlMemory<T, I>& CUtlMemory<T, I>::operator=(CUtlMemory&& moveFrom)
|
||||
{
|
||||
T* pMemory = moveFrom.m_pMemory;
|
||||
int nAllocationCount = moveFrom.m_nAllocationCount;
|
||||
int nGrowSize = moveFrom.m_nGrowSize;
|
||||
|
||||
moveFrom.m_pMemory = nullptr;
|
||||
moveFrom.m_nAllocationCount = 0;
|
||||
moveFrom.m_nGrowSize = 0;
|
||||
|
||||
Purge();
|
||||
|
||||
m_pMemory = pMemory;
|
||||
m_nAllocationCount = nAllocationCount;
|
||||
m_nGrowSize = nGrowSize;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::Init(int nGrowSize , int nInitSize )
|
||||
{
|
||||
Purge();
|
||||
|
||||
m_nGrowSize = nGrowSize;
|
||||
m_nAllocationCount = nInitSize;
|
||||
ValidateGrowSize();
|
||||
Assert(nGrowSize >= 0);
|
||||
if (m_nAllocationCount)
|
||||
{
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::Swap(CUtlMemory<T, I>& mem)
|
||||
{
|
||||
V_swap(m_nGrowSize, mem.m_nGrowSize);
|
||||
V_swap(m_pMemory, mem.m_pMemory);
|
||||
V_swap(m_nAllocationCount, mem.m_nAllocationCount);
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::ConvertToGrowableMemory(int nGrowSize)
|
||||
{
|
||||
if (!IsExternallyAllocated())
|
||||
return;
|
||||
|
||||
m_nGrowSize = nGrowSize;
|
||||
if (m_nAllocationCount)
|
||||
{
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
|
||||
int nNumBytes = m_nAllocationCount * sizeof(T);
|
||||
T* pMemory = (T*)malloc(nNumBytes);
|
||||
memcpy(pMemory, m_pMemory, nNumBytes);
|
||||
m_pMemory = pMemory;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pMemory = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, int numElements)
|
||||
{
|
||||
Purge();
|
||||
|
||||
m_pMemory = pMemory;
|
||||
m_nAllocationCount = numElements;
|
||||
|
||||
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, int numElements)
|
||||
{
|
||||
Purge();
|
||||
|
||||
m_pMemory = const_cast<T*>(pMemory);
|
||||
m_nAllocationCount = numElements;
|
||||
|
||||
m_nGrowSize = EXTERNAL_CONST_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::AssumeMemory(T* pMemory, int numElements)
|
||||
{
|
||||
Purge();
|
||||
|
||||
m_pMemory = pMemory;
|
||||
m_nAllocationCount = numElements;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void* CUtlMemory<T, I>::DetachMemory()
|
||||
{
|
||||
if (IsExternallyAllocated())
|
||||
return NULL;
|
||||
|
||||
void* pMemory = m_pMemory;
|
||||
m_pMemory = 0;
|
||||
m_nAllocationCount = 0;
|
||||
return pMemory;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
inline T* CUtlMemory<T, I>::Detach()
|
||||
{
|
||||
return (T*)DetachMemory();
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
inline T& CUtlMemory<T, I>::operator[](I i)
|
||||
{
|
||||
Assert(!IsReadOnly());
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
inline const T& CUtlMemory<T, I>::operator[](I i) const
|
||||
{
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
inline T& CUtlMemory<T, I>::Element(I i)
|
||||
{
|
||||
Assert(!IsReadOnly());
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
inline const T& CUtlMemory<T, I>::Element(I i) const
|
||||
{
|
||||
Assert(IsIdxValid(i));
|
||||
return m_pMemory[i];
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
bool CUtlMemory<T, I>::IsExternallyAllocated() const
|
||||
{
|
||||
return (m_nGrowSize < 0);
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
bool CUtlMemory<T, I>::IsReadOnly() const
|
||||
{
|
||||
return (m_nGrowSize == EXTERNAL_CONST_BUFFER_MARKER);
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::SetGrowSize(int nSize)
|
||||
{
|
||||
Assert(!IsExternallyAllocated());
|
||||
Assert(nSize >= 0);
|
||||
m_nGrowSize = nSize;
|
||||
ValidateGrowSize();
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
inline T* CUtlMemory<T, I>::Base()
|
||||
{
|
||||
Assert(!IsReadOnly());
|
||||
return m_pMemory;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
inline const T* CUtlMemory<T, I>::Base() const
|
||||
{
|
||||
return m_pMemory;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
inline int CUtlMemory<T, I>::NumAllocated() const
|
||||
{
|
||||
return m_nAllocationCount;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
inline int CUtlMemory<T, I>::Count() const
|
||||
{
|
||||
return m_nAllocationCount;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
inline bool CUtlMemory<T, I>::IsIdxValid(I i) const
|
||||
{
|
||||
long x = i;
|
||||
return (x >= 0) && (x < m_nAllocationCount);
|
||||
}
|
||||
|
||||
inline int UtlMemory_CalcNewAllocationCount(int nAllocationCount, int nGrowSize, int nNewSize, int nBytesItem)
|
||||
{
|
||||
if (nGrowSize)
|
||||
{
|
||||
nAllocationCount = ((1 + ((nNewSize - 1) / nGrowSize)) * nGrowSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!nAllocationCount)
|
||||
{
|
||||
nAllocationCount = (31 + nBytesItem) / nBytesItem;
|
||||
if (nAllocationCount < nNewSize)
|
||||
nAllocationCount = nNewSize;
|
||||
}
|
||||
|
||||
while (nAllocationCount < nNewSize)
|
||||
{
|
||||
#ifndef _X360
|
||||
nAllocationCount *= 2;
|
||||
#else
|
||||
int nNewAllocationCount = (nAllocationCount * 9) / 8;
|
||||
if (nNewAllocationCount > nAllocationCount)
|
||||
nAllocationCount = nNewAllocationCount;
|
||||
else
|
||||
nAllocationCount *= 2;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return nAllocationCount;
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::Grow(int num)
|
||||
{
|
||||
Assert(num > 0);
|
||||
|
||||
if (IsExternallyAllocated())
|
||||
{
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int nAllocationRequested = m_nAllocationCount + num;
|
||||
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
|
||||
int nNewAllocationCount = UtlMemory_CalcNewAllocationCount(m_nAllocationCount, m_nGrowSize, nAllocationRequested, sizeof(T));
|
||||
|
||||
if ((int)(I)nNewAllocationCount < nAllocationRequested)
|
||||
{
|
||||
if ((int)(I)nNewAllocationCount == 0 && (int)(I)(nNewAllocationCount - 1) >= nAllocationRequested)
|
||||
{
|
||||
--nNewAllocationCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((int)(I)nAllocationRequested != nAllocationRequested)
|
||||
{
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
while ((int)(I)nNewAllocationCount < nAllocationRequested)
|
||||
{
|
||||
nNewAllocationCount = (nNewAllocationCount + nAllocationRequested) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_nAllocationCount = nNewAllocationCount;
|
||||
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
|
||||
if (m_pMemory)
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
Assert(m_pMemory);
|
||||
}
|
||||
else
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
Assert(m_pMemory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
inline void CUtlMemory<T, I>::EnsureCapacity(int num)
|
||||
{
|
||||
if (m_nAllocationCount >= num)
|
||||
return;
|
||||
|
||||
if (IsExternallyAllocated())
|
||||
{
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
|
||||
m_nAllocationCount = num;
|
||||
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
|
||||
if (m_pMemory)
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::Purge()
|
||||
{
|
||||
if (!IsExternallyAllocated())
|
||||
{
|
||||
if (m_pMemory)
|
||||
{
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
free((void*)m_pMemory);
|
||||
m_pMemory = 0;
|
||||
}
|
||||
m_nAllocationCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::Purge(int numElements)
|
||||
{
|
||||
Assert(numElements >= 0);
|
||||
|
||||
if (numElements > m_nAllocationCount)
|
||||
{
|
||||
Assert(numElements <= m_nAllocationCount);
|
||||
return;
|
||||
}
|
||||
|
||||
if (numElements == 0)
|
||||
{
|
||||
Purge();
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsExternallyAllocated())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (numElements == m_nAllocationCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!m_pMemory)
|
||||
{
|
||||
Assert(m_pMemory);
|
||||
return;
|
||||
}
|
||||
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
|
||||
m_nAllocationCount = numElements;
|
||||
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||
}
|
||||
|
||||
template< class T, int nAlignment >
|
||||
class CUtlMemoryAligned : public CUtlMemory<T>
|
||||
{
|
||||
public:
|
||||
CUtlMemoryAligned(int nGrowSize = 0, int nInitSize = 0);
|
||||
CUtlMemoryAligned(T* pMemory, int numElements);
|
||||
CUtlMemoryAligned(const T* pMemory, int numElements);
|
||||
~CUtlMemoryAligned();
|
||||
|
||||
void SetExternalBuffer(T* pMemory, int numElements);
|
||||
void SetExternalBuffer(const T* pMemory, int numElements);
|
||||
|
||||
void Grow(int num = 1);
|
||||
|
||||
void EnsureCapacity(int num);
|
||||
|
||||
void Purge();
|
||||
|
||||
void Purge(int numElements) { Assert(0); }
|
||||
|
||||
private:
|
||||
void* Align(const void* pAddr);
|
||||
};
|
||||
|
||||
|
||||
template< class T, int nAlignment >
|
||||
void* CUtlMemoryAligned<T, nAlignment>::Align(const void* pAddr)
|
||||
{
|
||||
size_t nAlignmentMask = nAlignment - 1;
|
||||
return (void*)(((size_t)pAddr + nAlignmentMask) & (~nAlignmentMask));
|
||||
}
|
||||
|
||||
|
||||
template< class T, int nAlignment >
|
||||
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(int nGrowSize, int nInitAllocationCount)
|
||||
{
|
||||
CUtlMemory<T>::m_pMemory = 0;
|
||||
CUtlMemory<T>::m_nAllocationCount = nInitAllocationCount;
|
||||
CUtlMemory<T>::m_nGrowSize = nGrowSize;
|
||||
this->ValidateGrowSize();
|
||||
|
||||
COMPILE_TIME_ASSERT((nAlignment & (nAlignment - 1)) == 0);
|
||||
Assert((nGrowSize >= 0) && (nGrowSize != CUtlMemory<T>::EXTERNAL_BUFFER_MARKER));
|
||||
if (CUtlMemory<T>::m_nAllocationCount)
|
||||
{
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
CUtlMemory<T>::m_pMemory = (T*)_aligned_malloc(nInitAllocationCount * sizeof(T), nAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
template< class T, int nAlignment >
|
||||
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(T* pMemory, int numElements)
|
||||
{
|
||||
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_BUFFER_MARKER;
|
||||
|
||||
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
|
||||
CUtlMemory<T>::m_nAllocationCount = ((int)(pMemory + numElements) - (int)CUtlMemory<T>::m_pMemory) / sizeof(T);
|
||||
}
|
||||
|
||||
template< class T, int nAlignment >
|
||||
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(const T* pMemory, int numElements)
|
||||
{
|
||||
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_CONST_BUFFER_MARKER;
|
||||
|
||||
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
|
||||
CUtlMemory<T>::m_nAllocationCount = ((int)(pMemory + numElements) - (int)CUtlMemory<T>::m_pMemory) / sizeof(T);
|
||||
}
|
||||
|
||||
template< class T, int nAlignment >
|
||||
CUtlMemoryAligned<T, nAlignment>::~CUtlMemoryAligned()
|
||||
{
|
||||
Purge();
|
||||
}
|
||||
|
||||
|
||||
template< class T, int nAlignment >
|
||||
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(T* pMemory, int numElements)
|
||||
{
|
||||
Purge();
|
||||
|
||||
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
|
||||
CUtlMemory<T>::m_nAllocationCount = ((int)(pMemory + numElements) - (int)CUtlMemory<T>::m_pMemory) / sizeof(T);
|
||||
|
||||
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T, int nAlignment >
|
||||
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, int numElements)
|
||||
{
|
||||
Purge();
|
||||
|
||||
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
|
||||
CUtlMemory<T>::m_nAllocationCount = ((int)(pMemory + numElements) - (int)CUtlMemory<T>::m_pMemory) / sizeof(T);
|
||||
|
||||
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_CONST_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
|
||||
template< class T, int nAlignment >
|
||||
void CUtlMemoryAligned<T, nAlignment>::Grow(int num)
|
||||
{
|
||||
Assert(num > 0);
|
||||
|
||||
if (this->IsExternallyAllocated())
|
||||
{
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
|
||||
int nAllocationRequested = CUtlMemory<T>::m_nAllocationCount + num;
|
||||
|
||||
CUtlMemory<T>::m_nAllocationCount = UtlMemory_CalcNewAllocationCount(CUtlMemory<T>::m_nAllocationCount, CUtlMemory<T>::m_nGrowSize, nAllocationRequested, sizeof(T));
|
||||
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
|
||||
if (CUtlMemory<T>::m_pMemory)
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
CUtlMemory<T>::m_pMemory = (T*)MemAlloc_ReallocAligned(CUtlMemory<T>::m_pMemory, CUtlMemory<T>::m_nAllocationCount * sizeof(T), nAlignment);
|
||||
Assert(CUtlMemory<T>::m_pMemory);
|
||||
}
|
||||
else
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
CUtlMemory<T>::m_pMemory = (T*)MemAlloc_AllocAligned(CUtlMemory<T>::m_nAllocationCount * sizeof(T), nAlignment);
|
||||
Assert(CUtlMemory<T>::m_pMemory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< class T, int nAlignment >
|
||||
inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(int num)
|
||||
{
|
||||
if (CUtlMemory<T>::m_nAllocationCount >= num)
|
||||
return;
|
||||
|
||||
if (this->IsExternallyAllocated())
|
||||
{
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
|
||||
CUtlMemory<T>::m_nAllocationCount = num;
|
||||
|
||||
UTLMEMORY_TRACK_ALLOC();
|
||||
|
||||
if (CUtlMemory<T>::m_pMemory)
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
CUtlMemory<T>::m_pMemory = (T*)MemAlloc_ReallocAligned(CUtlMemory<T>::m_pMemory, CUtlMemory<T>::m_nAllocationCount * sizeof(T), nAlignment);
|
||||
}
|
||||
else
|
||||
{
|
||||
MEM_ALLOC_CREDIT_CLASS();
|
||||
CUtlMemory<T>::m_pMemory = (T*)MemAlloc_AllocAligned(CUtlMemory<T>::m_nAllocationCount * sizeof(T), nAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< class T, int nAlignment >
|
||||
void CUtlMemoryAligned<T, nAlignment>::Purge()
|
||||
{
|
||||
if (!this->IsExternallyAllocated())
|
||||
{
|
||||
if (CUtlMemory<T>::m_pMemory)
|
||||
{
|
||||
UTLMEMORY_TRACK_FREE();
|
||||
MemAlloc_FreeAligned(CUtlMemory<T>::m_pMemory);
|
||||
CUtlMemory<T>::m_pMemory = 0;
|
||||
}
|
||||
CUtlMemory<T>::m_nAllocationCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#include "memdbgoff.h"
|
||||
|
||||
#endif
|
138
SpyCustom/sdk/utlobjectreference.h
Normal file
138
SpyCustom/sdk/utlobjectreference.h
Normal file
@ -0,0 +1,138 @@
|
||||
#ifndef UTLOBJECTREFERENCE_H
|
||||
#define UTLOBJECTREFERENCE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlintrusivelist.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class T> class CUtlReference
|
||||
{
|
||||
public:
|
||||
FORCEINLINE CUtlReference(void)
|
||||
{
|
||||
m_pNext = m_pPrev = NULL;
|
||||
m_pObject = NULL;
|
||||
}
|
||||
|
||||
FORCEINLINE CUtlReference(T* pObj)
|
||||
{
|
||||
m_pNext = m_pPrev = NULL;
|
||||
AddRef(pObj);
|
||||
}
|
||||
|
||||
FORCEINLINE ~CUtlReference(void)
|
||||
{
|
||||
KillRef();
|
||||
}
|
||||
|
||||
FORCEINLINE void Set(T* pObj)
|
||||
{
|
||||
if (m_pObject != pObj)
|
||||
{
|
||||
KillRef();
|
||||
AddRef(pObj);
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE T* operator()(void) const
|
||||
{
|
||||
return m_pObject;
|
||||
}
|
||||
|
||||
FORCEINLINE operator T* ()
|
||||
{
|
||||
return m_pObject;
|
||||
}
|
||||
|
||||
FORCEINLINE operator const T* () const
|
||||
{
|
||||
return m_pObject;
|
||||
}
|
||||
|
||||
FORCEINLINE T* operator->()
|
||||
{
|
||||
return m_pObject;
|
||||
}
|
||||
|
||||
FORCEINLINE const T* operator->() const
|
||||
{
|
||||
return m_pObject;
|
||||
}
|
||||
|
||||
FORCEINLINE CUtlReference& operator=(const CUtlReference& otherRef)
|
||||
{
|
||||
Set(otherRef.m_pObject);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FORCEINLINE CUtlReference& operator=(T* pObj)
|
||||
{
|
||||
Set(pObj);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE bool operator==(const CUtlReference& o) const
|
||||
{
|
||||
return (o.m_pObject == m_pObject);
|
||||
}
|
||||
|
||||
public:
|
||||
CUtlReference* m_pNext;
|
||||
CUtlReference* m_pPrev;
|
||||
|
||||
T* m_pObject;
|
||||
|
||||
FORCEINLINE void AddRef(T* pObj)
|
||||
{
|
||||
m_pObject = pObj;
|
||||
if (pObj)
|
||||
{
|
||||
pObj->m_References.AddToHead(this);
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE void KillRef(void)
|
||||
{
|
||||
if (m_pObject)
|
||||
{
|
||||
m_pObject->m_References.RemoveNode(this);
|
||||
m_pObject = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class T> class CUtlReferenceList : public CUtlIntrusiveDList< CUtlReference<T> >
|
||||
{
|
||||
public:
|
||||
~CUtlReferenceList(void)
|
||||
{
|
||||
CUtlReference<T>* i = CUtlIntrusiveDList<CUtlReference<T> >::m_pHead;
|
||||
while (i)
|
||||
{
|
||||
CUtlReference<T>* n = i->m_pNext;
|
||||
i->m_pNext = NULL;
|
||||
i->m_pPrev = NULL;
|
||||
i->m_pObject = NULL;
|
||||
i = n;
|
||||
}
|
||||
CUtlIntrusiveDList<CUtlReference<T> >::m_pHead = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#define DECLARE_REFERENCED_CLASS( _className ) \
|
||||
private: \
|
||||
CUtlReferenceList< _className > m_References; \
|
||||
template<class T> friend class CUtlReference;
|
||||
|
||||
|
||||
#endif
|
164
SpyCustom/sdk/utlpriorityqueue.h
Normal file
164
SpyCustom/sdk/utlpriorityqueue.h
Normal file
@ -0,0 +1,164 @@
|
||||
#ifndef UTLPRIORITYQUEUE_H
|
||||
#define UTLPRIORITYQUEUE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlvector.h"
|
||||
|
||||
template< class T >
|
||||
class CUtlPriorityQueue
|
||||
{
|
||||
public:
|
||||
typedef bool (*LessFunc_t)(T const&, T const&);
|
||||
|
||||
typedef T ElemType_t;
|
||||
|
||||
CUtlPriorityQueue(int growSize = 0, int initSize = 0, LessFunc_t lessfunc = 0);
|
||||
CUtlPriorityQueue(T* pMemory, int numElements, LessFunc_t lessfunc = 0);
|
||||
|
||||
inline T const& ElementAtHead() const { return m_heap.Element(0); }
|
||||
|
||||
inline bool IsValidIndex(int index) { return m_heap.IsValidIndex(index); }
|
||||
|
||||
void RemoveAtHead();
|
||||
void RemoveAt(int index);
|
||||
|
||||
void Insert(T const& element);
|
||||
void SetLessFunc(LessFunc_t func);
|
||||
|
||||
inline int Count() const { return m_heap.Count(); }
|
||||
|
||||
void RemoveAll() { m_heap.RemoveAll(); }
|
||||
|
||||
void Purge() { m_heap.Purge(); }
|
||||
|
||||
inline const T& Element(int index) const { return m_heap.Element(index); }
|
||||
|
||||
protected:
|
||||
CUtlVector<T> m_heap;
|
||||
|
||||
void Swap(int index1, int index2);
|
||||
|
||||
LessFunc_t m_LessFunc;
|
||||
};
|
||||
|
||||
template< class T >
|
||||
inline CUtlPriorityQueue<T>::CUtlPriorityQueue(int growSize, int initSize, LessFunc_t lessfunc) :
|
||||
m_heap(growSize, initSize), m_LessFunc(lessfunc)
|
||||
{
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline CUtlPriorityQueue<T>::CUtlPriorityQueue(T* pMemory, int numElements, LessFunc_t lessfunc) :
|
||||
m_heap(pMemory, numElements), m_LessFunc(lessfunc)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void CUtlPriorityQueue<T>::RemoveAtHead()
|
||||
{
|
||||
m_heap.FastRemove(0);
|
||||
int index = 0;
|
||||
|
||||
int count = Count();
|
||||
if (!count)
|
||||
return;
|
||||
|
||||
int half = count / 2;
|
||||
int larger = index;
|
||||
while (index < half)
|
||||
{
|
||||
int child = ((index + 1) * 2) - 1;
|
||||
if (child < count)
|
||||
{
|
||||
if (m_LessFunc(m_heap[index], m_heap[child]))
|
||||
{
|
||||
larger = child;
|
||||
}
|
||||
}
|
||||
child++;
|
||||
if (child < count)
|
||||
{
|
||||
if (m_LessFunc(m_heap[larger], m_heap[child]))
|
||||
larger = child;
|
||||
}
|
||||
|
||||
if (larger == index)
|
||||
break;
|
||||
|
||||
Swap(index, larger);
|
||||
index = larger;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void CUtlPriorityQueue<T>::RemoveAt(int index)
|
||||
{
|
||||
Assert(m_heap.IsValidIndex(index));
|
||||
m_heap.FastRemove(index);
|
||||
|
||||
int count = Count();
|
||||
if (!count)
|
||||
return;
|
||||
|
||||
int half = count / 2;
|
||||
int larger = index;
|
||||
while (index < half)
|
||||
{
|
||||
int child = ((index + 1) * 2) - 1;
|
||||
if (child < count)
|
||||
{
|
||||
if (m_LessFunc(m_heap[index], m_heap[child]))
|
||||
{
|
||||
larger = child;
|
||||
}
|
||||
}
|
||||
child++;
|
||||
if (child < count)
|
||||
{
|
||||
if (m_LessFunc(m_heap[larger], m_heap[child]))
|
||||
larger = child;
|
||||
}
|
||||
|
||||
if (larger == index)
|
||||
break;
|
||||
|
||||
Swap(index, larger);
|
||||
index = larger;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void CUtlPriorityQueue<T>::Insert(T const& element)
|
||||
{
|
||||
int index = m_heap.AddToTail();
|
||||
m_heap[index] = element;
|
||||
|
||||
while (index != 0)
|
||||
{
|
||||
int parent = ((index + 1) / 2) - 1;
|
||||
if (m_LessFunc(m_heap[index], m_heap[parent]))
|
||||
break;
|
||||
|
||||
Swap(parent, index);
|
||||
index = parent;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void CUtlPriorityQueue<T>::Swap(int index1, int index2)
|
||||
{
|
||||
T tmp = m_heap[index1];
|
||||
m_heap[index1] = m_heap[index2];
|
||||
m_heap[index2] = tmp;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void CUtlPriorityQueue<T>::SetLessFunc(LessFunc_t lessfunc)
|
||||
{
|
||||
m_LessFunc = lessfunc;
|
||||
}
|
||||
|
||||
#endif
|
95
SpyCustom/sdk/utlqueue.h
Normal file
95
SpyCustom/sdk/utlqueue.h
Normal file
@ -0,0 +1,95 @@
|
||||
#ifndef UTLQUEUE_H
|
||||
#define UTLQUEUE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "utlvector.h"
|
||||
|
||||
template< class T >
|
||||
class CUtlQueue
|
||||
{
|
||||
public:
|
||||
|
||||
CUtlQueue(int growSize = 0, int initSize = 0);
|
||||
CUtlQueue(T* pMemory, int numElements);
|
||||
|
||||
T const& RemoveAtHead();
|
||||
T const& RemoveAtTail();
|
||||
|
||||
T const& Head();
|
||||
T const& Tail();
|
||||
|
||||
void Insert(T const& element);
|
||||
|
||||
bool Check(T const element);
|
||||
|
||||
int Count() const { return m_heap.Count(); }
|
||||
|
||||
void RemoveAll() { m_heap.RemoveAll(); }
|
||||
|
||||
void Purge() { m_heap.Purge(); }
|
||||
|
||||
protected:
|
||||
CUtlVector<T> m_heap;
|
||||
T m_current;
|
||||
};
|
||||
|
||||
template< class T >
|
||||
inline CUtlQueue<T>::CUtlQueue(int growSize, int initSize) :
|
||||
m_heap(growSize, initSize)
|
||||
{
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline CUtlQueue<T>::CUtlQueue(T* pMemory, int numElements) :
|
||||
m_heap(pMemory, numElements)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T const& CUtlQueue<T>::RemoveAtHead()
|
||||
{
|
||||
m_current = m_heap[0];
|
||||
m_heap.Remove((int)0);
|
||||
return m_current;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T const& CUtlQueue<T>::RemoveAtTail()
|
||||
{
|
||||
m_current = m_heap[m_heap.Count() - 1];
|
||||
m_heap.Remove((int)(m_heap.Count() - 1));
|
||||
return m_current;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T const& CUtlQueue<T>::Head()
|
||||
{
|
||||
m_current = m_heap[0];
|
||||
return m_current;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T const& CUtlQueue<T>::Tail()
|
||||
{
|
||||
m_current = m_heap[m_heap.Count() - 1];
|
||||
return m_current;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void CUtlQueue<T>::Insert(T const& element)
|
||||
{
|
||||
int index = m_heap.AddToTail();
|
||||
m_heap[index] = element;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool CUtlQueue<T>::Check(T const element)
|
||||
{
|
||||
int index = m_heap.Find(element);
|
||||
return (index != -1);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
1432
SpyCustom/sdk/utlrbtree.h
Normal file
1432
SpyCustom/sdk/utlrbtree.h
Normal file
File diff suppressed because it is too large
Load Diff
300
SpyCustom/sdk/utlsoacontainer.h
Normal file
300
SpyCustom/sdk/utlsoacontainer.h
Normal file
@ -0,0 +1,300 @@
|
||||
#ifndef UTLSOACONTAINER_H
|
||||
#define UTLSOACONTAINER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "platform.h"
|
||||
#include "dbg.h"
|
||||
#include "threadtools.h"
|
||||
#include "utlmemory.h"
|
||||
#include "utlblockmemory.h"
|
||||
#include "ssemath.h"
|
||||
|
||||
|
||||
template<class T> class CStridedPtr
|
||||
{
|
||||
protected:
|
||||
T* m_pData;
|
||||
size_t m_nStride;
|
||||
|
||||
public:
|
||||
FORCEINLINE CStridedPtr<T>(void* pData, size_t nByteStride)
|
||||
{
|
||||
m_pData = reinterpret_cast<T*>(pData);
|
||||
m_nStride = nByteStride / sizeof(T);
|
||||
}
|
||||
|
||||
FORCEINLINE CStridedPtr<T>(void) {}
|
||||
T* operator->(void) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
T& operator*(void) const
|
||||
{
|
||||
return *m_pData;
|
||||
}
|
||||
|
||||
FORCEINLINE operator T* (void)
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
FORCEINLINE CStridedPtr<T>& operator++(void)
|
||||
{
|
||||
m_pData += m_nStride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
FORCEINLINE void operator+=(size_t nNumElements)
|
||||
{
|
||||
m_pData += nNumElements * m_nStride;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<class T> class CStridedConstPtr
|
||||
{
|
||||
protected:
|
||||
const T* m_pData;
|
||||
size_t m_nStride;
|
||||
|
||||
public:
|
||||
FORCEINLINE CStridedConstPtr<T>(void const* pData, size_t nByteStride)
|
||||
{
|
||||
m_pData = reinterpret_cast<T const*>(pData);
|
||||
m_nStride = nByteStride / sizeof(T);
|
||||
}
|
||||
|
||||
FORCEINLINE CStridedConstPtr<T>(void) {}
|
||||
|
||||
const T* operator->(void) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
const T& operator*(void) const
|
||||
{
|
||||
return *m_pData;
|
||||
}
|
||||
|
||||
FORCEINLINE operator const T* (void) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
FORCEINLINE CStridedConstPtr<T>& operator++(void)
|
||||
{
|
||||
m_pData += m_nStride;
|
||||
return *this;
|
||||
}
|
||||
FORCEINLINE void operator+=(size_t nNumElements)
|
||||
{
|
||||
m_pData += nNumElements * m_nStride;
|
||||
}
|
||||
};
|
||||
|
||||
enum EAttributeDataType
|
||||
{
|
||||
ATTRDATATYPE_FLOAT = 0,
|
||||
ATTRDATATYPE_4V = 1,
|
||||
ATTRDATATYPE_INT = 2,
|
||||
ATTRDATATYPE_POINTER = 3,
|
||||
ATTRDATATYPE_NONE = -1,
|
||||
};
|
||||
|
||||
#define MAX_SOA_FIELDS 32
|
||||
|
||||
class CSOAContainer
|
||||
{
|
||||
|
||||
protected:
|
||||
int m_nColumns;
|
||||
int m_nRows;
|
||||
int m_nSlices;
|
||||
|
||||
int m_nPaddedColumns;
|
||||
int m_nNumQuadsPerRow;
|
||||
|
||||
uint8* m_pDataMemory;
|
||||
uint8* m_pAttributePtrs[MAX_SOA_FIELDS];
|
||||
|
||||
EAttributeDataType m_nDataType[MAX_SOA_FIELDS];
|
||||
|
||||
size_t m_nStrideInBytes[MAX_SOA_FIELDS];
|
||||
size_t m_nRowStrideInBytes[MAX_SOA_FIELDS];
|
||||
size_t m_nSliceStrideInBytes[MAX_SOA_FIELDS];
|
||||
|
||||
|
||||
|
||||
uint32 m_nFieldPresentMask;
|
||||
|
||||
FORCEINLINE void Init(void)
|
||||
{
|
||||
memset(m_nDataType, 0xff, sizeof(m_nDataType));
|
||||
m_pDataMemory = 0;
|
||||
m_nColumns = m_nPaddedColumns = m_nRows = m_nSlices = 0;
|
||||
m_nFieldPresentMask = 0;
|
||||
}
|
||||
public:
|
||||
|
||||
|
||||
CSOAContainer(void)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
void Purge(void);
|
||||
|
||||
~CSOAContainer(void);
|
||||
|
||||
CSOAContainer(int nCols, int nRows, ...);
|
||||
|
||||
size_t ElementSize(void) const;
|
||||
|
||||
FORCEINLINE void SetAttributeType(int nAttrIdx, EAttributeDataType nDataType, bool bAllocateMemory = true)
|
||||
{
|
||||
Assert(!m_pDataMemory);
|
||||
Assert(nAttrIdx < MAX_SOA_FIELDS);
|
||||
m_nDataType[nAttrIdx] = nDataType;
|
||||
if ((m_nDataType[nAttrIdx] != ATTRDATATYPE_NONE) && bAllocateMemory)
|
||||
m_nFieldPresentMask |= (1 << nAttrIdx);
|
||||
else
|
||||
m_nFieldPresentMask &= ~(1 << nAttrIdx);
|
||||
}
|
||||
|
||||
FORCEINLINE int NumRows(void) const
|
||||
{
|
||||
return m_nRows;
|
||||
}
|
||||
|
||||
FORCEINLINE int NumCols(void) const
|
||||
{
|
||||
return m_nColumns;
|
||||
}
|
||||
FORCEINLINE int NumSlices(void) const
|
||||
{
|
||||
return m_nSlices;
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE void AssertDataType(int nAttrIdx, EAttributeDataType nDataType) const
|
||||
{
|
||||
Assert(nAttrIdx >= 0);
|
||||
Assert(nAttrIdx < MAX_SOA_FIELDS);
|
||||
Assert(m_nStrideInBytes[nAttrIdx]);
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE int NumQuadsPerRow(void) const
|
||||
{
|
||||
return m_nNumQuadsPerRow;
|
||||
}
|
||||
|
||||
FORCEINLINE int Count(void) const
|
||||
{
|
||||
return NumCols();
|
||||
}
|
||||
|
||||
FORCEINLINE int NumElements(void) const
|
||||
{
|
||||
return NumCols() * NumRows() * NumSlices();
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE size_t RowToRowStep(int nAttrIdx) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
FORCEINLINE void* RowPtr(int nAttributeIdx, int nRowNumber, int nSliceNumber = 0) const
|
||||
{
|
||||
Assert(nRowNumber < m_nRows);
|
||||
Assert(nAttributeIdx < MAX_SOA_FIELDS);
|
||||
Assert(m_nDataType[nAttributeIdx] != ATTRDATATYPE_NONE);
|
||||
Assert(m_nFieldPresentMask & (1 << nAttributeIdx));
|
||||
return m_pAttributePtrs[nAttributeIdx] +
|
||||
+nRowNumber * m_nRowStrideInBytes[nAttributeIdx]
|
||||
+ nSliceNumber * m_nSliceStrideInBytes[nAttributeIdx];
|
||||
}
|
||||
|
||||
FORCEINLINE void const* ConstRowPtr(int nAttributeIdx, int nRowNumber, int nSliceNumber = 0) const
|
||||
{
|
||||
Assert(nRowNumber < m_nRows);
|
||||
Assert(nAttributeIdx < MAX_SOA_FIELDS);
|
||||
Assert(m_nDataType[nAttributeIdx] != ATTRDATATYPE_NONE);
|
||||
return m_pAttributePtrs[nAttributeIdx]
|
||||
+ nRowNumber * m_nRowStrideInBytes[nAttributeIdx]
|
||||
+ nSliceNumber * m_nSliceStrideInBytes[nAttributeIdx];
|
||||
}
|
||||
|
||||
|
||||
template<class T> FORCEINLINE T* ElementPointer(int nAttributeIdx,
|
||||
int nX = 0, int nY = 0, int nZ = 0) const
|
||||
{
|
||||
Assert(nAttributeIdx < MAX_SOA_FIELDS);
|
||||
Assert(nX < m_nColumns);
|
||||
Assert(nY < m_nRows);
|
||||
Assert(nZ < m_nSlices);
|
||||
Assert(m_nDataType[nAttributeIdx] != ATTRDATATYPE_NONE);
|
||||
Assert(m_nDataType[nAttributeIdx] != ATTRDATATYPE_4V);
|
||||
return reinterpret_cast<T*>(m_pAttributePtrs[nAttributeIdx]
|
||||
+ nX * sizeof(float)
|
||||
+ nY * m_nRowStrideInBytes[nAttributeIdx]
|
||||
+ nZ * m_nSliceStrideInBytes[nAttributeIdx]
|
||||
);
|
||||
}
|
||||
|
||||
FORCEINLINE size_t ItemByteStride(int nAttributeIdx) const
|
||||
{
|
||||
Assert(nAttributeIdx < MAX_SOA_FIELDS);
|
||||
Assert(m_nDataType[nAttributeIdx] != ATTRDATATYPE_NONE);
|
||||
return m_nStrideInBytes[nAttributeIdx];
|
||||
}
|
||||
|
||||
void CopyAttrFrom(CSOAContainer const& other, int nAttributeIdx);
|
||||
|
||||
void CopyAttrToAttr(int nSrcAttributeIndex, int nDestAttributeIndex);
|
||||
|
||||
FORCEINLINE void MoveDataFrom(CSOAContainer other)
|
||||
{
|
||||
(*this) = other;
|
||||
other.Init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AllocateData(int nNCols, int nNRows, int nSlices = 1);
|
||||
|
||||
void RandomizeAttribute(int nAttr, float flMin, float flMax) const;
|
||||
|
||||
void FillAttrWithInterpolatedValues(int nAttr, float flValue00, float flValue10, float flValue01, float flValue11) const;
|
||||
void FillAttrWithInterpolatedValues(int nAttr, Vector flValue00, Vector flValue10,
|
||||
Vector const& flValue01, Vector const& flValue11) const;
|
||||
|
||||
};
|
||||
|
||||
class CFltX4AttributeIterator : public CStridedConstPtr<fltx4>
|
||||
{
|
||||
FORCEINLINE CFltX4AttributeIterator(CSOAContainer const* pContainer, int nAttribute, int nRowNumber = 0)
|
||||
: CStridedConstPtr<fltx4>(pContainer->ConstRowPtr(nAttribute, nRowNumber),
|
||||
pContainer->ItemByteStride(nAttribute))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class CFltX4AttributeWriteIterator : public CStridedPtr<fltx4>
|
||||
{
|
||||
FORCEINLINE CFltX4AttributeWriteIterator(CSOAContainer const* pContainer, int nAttribute, int nRowNumber = 0)
|
||||
: CStridedPtr<fltx4>(pContainer->RowPtr(nAttribute, nRowNumber),
|
||||
pContainer->ItemByteStride(nAttribute))
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
238
SpyCustom/sdk/utlstack.h
Normal file
238
SpyCustom/sdk/utlstack.h
Normal file
@ -0,0 +1,238 @@
|
||||
#ifndef UTLSTACK_H
|
||||
#define UTLSTACK_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "utlmemory.h"
|
||||
|
||||
|
||||
template< class T, class M = CUtlMemory< T > >
|
||||
class CUtlStack
|
||||
{
|
||||
public:
|
||||
CUtlStack(int growSize = 0, int initSize = 0);
|
||||
~CUtlStack();
|
||||
|
||||
void CopyFrom(const CUtlStack<T, M>& from);
|
||||
|
||||
T& operator[](int i);
|
||||
T const& operator[](int i) const;
|
||||
T& Element(int i);
|
||||
T const& Element(int i) const;
|
||||
|
||||
T* Base();
|
||||
T const* Base() const;
|
||||
|
||||
T& Top();
|
||||
T const& Top() const;
|
||||
|
||||
int Count() const;
|
||||
|
||||
bool IsIdxValid(int i) const;
|
||||
|
||||
int Push();
|
||||
|
||||
int Push(T const& src);
|
||||
|
||||
void Pop();
|
||||
void Pop(T& oldTop);
|
||||
void PopMultiple(int num);
|
||||
|
||||
void EnsureCapacity(int num);
|
||||
|
||||
void Clear();
|
||||
|
||||
void Purge();
|
||||
|
||||
private:
|
||||
void GrowStack();
|
||||
|
||||
void ResetDbgInfo();
|
||||
|
||||
M m_Memory;
|
||||
int m_Size;
|
||||
|
||||
T* m_pElements;
|
||||
};
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
inline void CUtlStack<T, M>::ResetDbgInfo()
|
||||
{
|
||||
m_pElements = m_Memory.Base();
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
CUtlStack<T, M>::CUtlStack(int growSize, int initSize) :
|
||||
m_Memory(growSize, initSize), m_Size(0)
|
||||
{
|
||||
ResetDbgInfo();
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
CUtlStack<T, M>::~CUtlStack()
|
||||
{
|
||||
Purge();
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::CopyFrom(const CUtlStack<T, M>& from)
|
||||
{
|
||||
Purge();
|
||||
EnsureCapacity(from.Count());
|
||||
for (int i = 0; i < from.Count(); i++)
|
||||
{
|
||||
Push(from[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T& CUtlStack<T, M>::operator[](int i)
|
||||
{
|
||||
assert(IsIdxValid(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T const& CUtlStack<T, M>::operator[](int i) const
|
||||
{
|
||||
assert(IsIdxValid(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T& CUtlStack<T, M>::Element(int i)
|
||||
{
|
||||
assert(IsIdxValid(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T const& CUtlStack<T, M>::Element(int i) const
|
||||
{
|
||||
assert(IsIdxValid(i));
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
inline T* CUtlStack<T, M>::Base()
|
||||
{
|
||||
return m_Memory.Base();
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T const* CUtlStack<T, M>::Base() const
|
||||
{
|
||||
return m_Memory.Base();
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T& CUtlStack<T, M>::Top()
|
||||
{
|
||||
assert(m_Size > 0);
|
||||
return Element(m_Size - 1);
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline T const& CUtlStack<T, M>::Top() const
|
||||
{
|
||||
assert(m_Size > 0);
|
||||
return Element(m_Size - 1);
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
inline int CUtlStack<T, M>::Count() const
|
||||
{
|
||||
return m_Size;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
inline bool CUtlStack<T, M>::IsIdxValid(int i) const
|
||||
{
|
||||
return (i >= 0) && (i < m_Size);
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::GrowStack()
|
||||
{
|
||||
if (m_Size >= m_Memory.NumAllocated())
|
||||
m_Memory.Grow();
|
||||
|
||||
++m_Size;
|
||||
|
||||
ResetDbgInfo();
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::EnsureCapacity(int num)
|
||||
{
|
||||
m_Memory.EnsureCapacity(num);
|
||||
ResetDbgInfo();
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
int CUtlStack<T, M>::Push()
|
||||
{
|
||||
GrowStack();
|
||||
Construct(&Element(m_Size - 1));
|
||||
return m_Size - 1;
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
int CUtlStack<T, M>::Push(T const& src)
|
||||
{
|
||||
GrowStack();
|
||||
CopyConstruct(&Element(m_Size - 1), src);
|
||||
return m_Size - 1;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::Pop()
|
||||
{
|
||||
assert(m_Size > 0);
|
||||
Destruct(&Element(m_Size - 1));
|
||||
--m_Size;
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::Pop(T& oldTop)
|
||||
{
|
||||
assert(m_Size > 0);
|
||||
oldTop = Top();
|
||||
Pop();
|
||||
}
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::PopMultiple(int num)
|
||||
{
|
||||
assert(m_Size >= num);
|
||||
for (int i = 0; i < num; ++i)
|
||||
Destruct(&Element(m_Size - i - 1));
|
||||
m_Size -= num;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::Clear()
|
||||
{
|
||||
for (int i = m_Size; --i >= 0; )
|
||||
Destruct(&Element(i));
|
||||
|
||||
m_Size = 0;
|
||||
}
|
||||
|
||||
|
||||
template< class T, class M >
|
||||
void CUtlStack<T, M>::Purge()
|
||||
{
|
||||
Clear();
|
||||
m_Memory.Purge();
|
||||
ResetDbgInfo();
|
||||
}
|
||||
|
||||
#endif
|
331
SpyCustom/sdk/utlstring.h
Normal file
331
SpyCustom/sdk/utlstring.h
Normal file
@ -0,0 +1,331 @@
|
||||
#ifndef UTLSTRING_H
|
||||
#define UTLSTRING_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "utlmemory.h"
|
||||
#include "strtools.h"
|
||||
#include "limits.h"
|
||||
|
||||
#if defined( OSX )
|
||||
#define wcsdup wcsdup_osx
|
||||
inline wchar_t* wcsdup_osx(const wchar_t* pString)
|
||||
{
|
||||
wchar_t* pMemory;
|
||||
|
||||
if (!pString)
|
||||
return NULL;
|
||||
|
||||
size_t len = (wcslen(pString) + 1);
|
||||
if ((pMemory = (wchar_t*)malloc(len * sizeof(wchar_t))) != NULL)
|
||||
{
|
||||
return wcscpy(pMemory, pString);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
class CUtlBinaryBlock
|
||||
{
|
||||
public:
|
||||
CUtlBinaryBlock(int growSize = 0, int initSize = 0);
|
||||
|
||||
CUtlBinaryBlock(void* pMemory, int nSizeInBytes, int nInitialLength);
|
||||
CUtlBinaryBlock(const void* pMemory, int nSizeInBytes);
|
||||
CUtlBinaryBlock(const CUtlBinaryBlock& src);
|
||||
|
||||
void Get(void* pValue, int nMaxLen) const;
|
||||
void Set(const void* pValue, int nLen);
|
||||
const void* Get() const;
|
||||
void* Get();
|
||||
|
||||
unsigned char& operator[](int i);
|
||||
const unsigned char& operator[](int i) const;
|
||||
|
||||
int Length() const;
|
||||
void SetLength(int nLength);
|
||||
bool IsEmpty() const;
|
||||
void Clear();
|
||||
void Purge();
|
||||
|
||||
bool IsReadOnly() const;
|
||||
|
||||
CUtlBinaryBlock& operator=(const CUtlBinaryBlock& src);
|
||||
|
||||
bool operator==(const CUtlBinaryBlock& src) const;
|
||||
|
||||
private:
|
||||
CUtlMemory<unsigned char> m_Memory;
|
||||
int m_nActualLength;
|
||||
};
|
||||
|
||||
|
||||
inline const void* CUtlBinaryBlock::Get() const
|
||||
{
|
||||
return m_Memory.Base();
|
||||
}
|
||||
|
||||
inline void* CUtlBinaryBlock::Get()
|
||||
{
|
||||
return m_Memory.Base();
|
||||
}
|
||||
|
||||
inline int CUtlBinaryBlock::Length() const
|
||||
{
|
||||
return m_nActualLength;
|
||||
}
|
||||
|
||||
inline unsigned char& CUtlBinaryBlock::operator[](int i)
|
||||
{
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
inline const unsigned char& CUtlBinaryBlock::operator[](int i) const
|
||||
{
|
||||
return m_Memory[i];
|
||||
}
|
||||
|
||||
inline bool CUtlBinaryBlock::IsReadOnly() const
|
||||
{
|
||||
return m_Memory.IsReadOnly();
|
||||
}
|
||||
|
||||
inline bool CUtlBinaryBlock::IsEmpty() const
|
||||
{
|
||||
return Length() == 0;
|
||||
}
|
||||
|
||||
inline void CUtlBinaryBlock::Clear()
|
||||
{
|
||||
SetLength(0);
|
||||
}
|
||||
|
||||
inline void CUtlBinaryBlock::Purge()
|
||||
{
|
||||
SetLength(0);
|
||||
m_Memory.Purge();
|
||||
}
|
||||
|
||||
|
||||
class CUtlString
|
||||
{
|
||||
public:
|
||||
typedef enum
|
||||
{
|
||||
PATTERN_NONE = 0x00000000,
|
||||
PATTERN_DIRECTORY = 0x00000001
|
||||
} TUtlStringPattern;
|
||||
|
||||
public:
|
||||
CUtlString();
|
||||
CUtlString(const char* pString);
|
||||
CUtlString(const CUtlString& string);
|
||||
|
||||
CUtlString(void* pMemory, int nSizeInBytes, int nInitialLength);
|
||||
CUtlString(const void* pMemory, int nSizeInBytes);
|
||||
|
||||
const char* Get() const;
|
||||
void Set(const char* pValue);
|
||||
|
||||
void Clear() { Set(NULL); }
|
||||
|
||||
operator const char* () const;
|
||||
|
||||
const char* String() const { return Get(); }
|
||||
|
||||
int Length() const;
|
||||
bool IsEmpty() const;
|
||||
|
||||
void SetLength(int nLen);
|
||||
char* Get();
|
||||
void Purge();
|
||||
|
||||
void ToLower();
|
||||
void ToUpper();
|
||||
|
||||
void Append(const char* pchAddition);
|
||||
|
||||
void StripTrailingSlash();
|
||||
|
||||
CUtlString& operator=(const CUtlString& src);
|
||||
CUtlString& operator=(const char* src);
|
||||
|
||||
bool operator==(const CUtlString& src) const;
|
||||
bool operator==(const char* src) const;
|
||||
bool operator!=(const CUtlString& src) const { return !operator==(src); }
|
||||
bool operator!=(const char* src) const { return !operator==(src); }
|
||||
|
||||
inline friend bool operator==(const char* lhs, const CUtlString& rhs) { return rhs.operator==(lhs); }
|
||||
inline friend bool operator!=(const char* lhs, const CUtlString& rhs) { return rhs.operator!=(lhs); }
|
||||
|
||||
CUtlString& operator+=(const CUtlString& rhs);
|
||||
CUtlString& operator+=(const char* rhs);
|
||||
CUtlString& operator+=(char c);
|
||||
CUtlString& operator+=(int rhs);
|
||||
CUtlString& operator+=(double rhs);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool MatchesPattern(const CUtlString& Pattern, int nFlags = 0);
|
||||
|
||||
int Format(PRINTF_FORMAT_STRING const char* pFormat, ...);
|
||||
void SetDirect(const char* pValue, int nChars);
|
||||
|
||||
typedef const char* AltArgumentType_t;
|
||||
|
||||
CUtlString Slice(int32 nStart = 0, int32 nEnd = INT_MAX);
|
||||
|
||||
CUtlString Left(int32 nChars);
|
||||
CUtlString Right(int32 nChars);
|
||||
|
||||
CUtlString Replace(char cFrom, char cTo);
|
||||
|
||||
CUtlString AbsPath(const char* pStartingDir = NULL);
|
||||
|
||||
CUtlString UnqualifiedFilename();
|
||||
|
||||
CUtlString DirName();
|
||||
|
||||
static CUtlString PathJoin(const char* pStr1, const char* pStr2);
|
||||
|
||||
static int __cdecl SortCaseInsensitive(const CUtlString* pString1, const CUtlString* pString2);
|
||||
static int __cdecl SortCaseSensitive(const CUtlString* pString1, const CUtlString* pString2);
|
||||
|
||||
private:
|
||||
CUtlBinaryBlock m_Storage;
|
||||
};
|
||||
|
||||
inline bool CUtlString::IsEmpty() const
|
||||
{
|
||||
return Length() == 0;
|
||||
}
|
||||
|
||||
inline bool CUtlString::IsValid() const
|
||||
{
|
||||
return (String() != NULL);
|
||||
}
|
||||
|
||||
inline int __cdecl CUtlString::SortCaseInsensitive(const CUtlString* pString1, const CUtlString* pString2)
|
||||
{
|
||||
return V_stricmp(pString1->String(), pString2->String());
|
||||
}
|
||||
|
||||
inline int __cdecl CUtlString::SortCaseSensitive(const CUtlString* pString1, const CUtlString* pString2)
|
||||
{
|
||||
return V_strcmp(pString1->String(), pString2->String());
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
class StringFuncs
|
||||
{
|
||||
public:
|
||||
static T* Duplicate(const T* pValue);
|
||||
static void Copy(T* out_pOut, const T* pIn, int iLengthInChars);
|
||||
static int Compare(const T* pLhs, const T* pRhs);
|
||||
static int CaselessCompare(const T* pLhs, const T* pRhs);
|
||||
static int Length(const T* pValue);
|
||||
static const T* FindChar(const T* pStr, const T cSearch);
|
||||
static const T* EmptyString();
|
||||
static const T* NullDebugString();
|
||||
};
|
||||
|
||||
template < >
|
||||
class StringFuncs<char>
|
||||
{
|
||||
public:
|
||||
static char* Duplicate(const char* pValue) { return strdup(pValue); }
|
||||
static void Copy(OUT_CAP(iLengthInChars) char* out_pOut, const char* pIn, int iLengthInChars) { strncpy(out_pOut, pIn, iLengthInChars); }
|
||||
static int Compare(const char* pLhs, const char* pRhs) { return strcmp(pLhs, pRhs); }
|
||||
static int CaselessCompare(const char* pLhs, const char* pRhs) { return Q_strcasecmp(pLhs, pRhs); }
|
||||
static int Length(const char* pValue) { return (int)strlen(pValue); }
|
||||
static const char* FindChar(const char* pStr, const char cSearch) { return strchr(pStr, cSearch); }
|
||||
static const char* EmptyString() { return ""; }
|
||||
static const char* NullDebugString() { return "(null)"; }
|
||||
};
|
||||
|
||||
template < >
|
||||
class StringFuncs<wchar_t>
|
||||
{
|
||||
public:
|
||||
static wchar_t* Duplicate(const wchar_t* pValue) { return wcsdup(pValue); }
|
||||
static void Copy(OUT_CAP(iLengthInChars) wchar_t* out_pOut, const wchar_t* pIn, int iLengthInChars) { wcsncpy(out_pOut, pIn, iLengthInChars); }
|
||||
static int Compare(const wchar_t* pLhs, const wchar_t* pRhs) { return wcscmp(pLhs, pRhs); }
|
||||
static int CaselessCompare(const wchar_t* pLhs, const wchar_t* pRhs);
|
||||
static int Length(const wchar_t* pValue) { return (int)wcslen(pValue); }
|
||||
static const wchar_t* FindChar(const wchar_t* pStr, const wchar_t cSearch) { return wcschr(pStr, cSearch); }
|
||||
static const wchar_t* EmptyString() { return L""; }
|
||||
static const wchar_t* NullDebugString() { return L"(null)"; }
|
||||
};
|
||||
|
||||
template < typename T = char >
|
||||
class CUtlConstStringBase
|
||||
{
|
||||
public:
|
||||
CUtlConstStringBase() : m_pString(NULL) {}
|
||||
explicit CUtlConstStringBase(const T* pString) : m_pString(NULL) { Set(pString); }
|
||||
CUtlConstStringBase(const CUtlConstStringBase& src) : m_pString(NULL) { Set(src.m_pString); }
|
||||
~CUtlConstStringBase() { Set(NULL); }
|
||||
|
||||
void Set(const T* pValue);
|
||||
void Clear() { Set(NULL); }
|
||||
|
||||
const T* Get() const { return m_pString ? m_pString : StringFuncs<T>::EmptyString(); }
|
||||
operator const T* () const { return m_pString ? m_pString : StringFuncs<T>::EmptyString(); }
|
||||
|
||||
bool IsEmpty() const { return m_pString == NULL; }
|
||||
|
||||
int Compare(const T* rhs) const;
|
||||
|
||||
bool operator<(const T* rhs) const { return Compare(rhs) < 0; }
|
||||
bool operator==(const T* rhs) const { return Compare(rhs) == 0; }
|
||||
bool operator!=(const T* rhs) const { return Compare(rhs) != 0; }
|
||||
bool operator<(const CUtlConstStringBase& rhs) const { return Compare(rhs.m_pString) < 0; }
|
||||
bool operator==(const CUtlConstStringBase& rhs) const { return Compare(rhs.m_pString) == 0; }
|
||||
bool operator!=(const CUtlConstStringBase& rhs) const { return Compare(rhs.m_pString) != 0; }
|
||||
|
||||
inline friend bool operator<(const T* lhs, const CUtlConstStringBase& rhs) { return rhs.Compare(lhs) > 0; }
|
||||
inline friend bool operator==(const T* lhs, const CUtlConstStringBase& rhs) { return rhs.Compare(lhs) == 0; }
|
||||
inline friend bool operator!=(const T* lhs, const CUtlConstStringBase& rhs) { return rhs.Compare(lhs) != 0; }
|
||||
|
||||
CUtlConstStringBase& operator=(const T* src) { Set(src); return *this; }
|
||||
CUtlConstStringBase& operator=(const CUtlConstStringBase& src) { Set(src.m_pString); return *this; }
|
||||
|
||||
typedef const T* AltArgumentType_t;
|
||||
|
||||
protected:
|
||||
const T* m_pString;
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
void CUtlConstStringBase<T>::Set(const T* pValue)
|
||||
{
|
||||
if (pValue != m_pString)
|
||||
{
|
||||
free((void*)m_pString);
|
||||
m_pString = pValue && pValue[0] ? StringFuncs<T>::Duplicate(pValue) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
int CUtlConstStringBase<T>::Compare(const T* rhs) const
|
||||
{
|
||||
if (!rhs || !rhs[0])
|
||||
return m_pString ? 1 : 0;
|
||||
|
||||
if (!m_pString)
|
||||
return -1;
|
||||
|
||||
return StringFuncs<T>::Compare(m_pString, rhs);
|
||||
}
|
||||
|
||||
typedef CUtlConstStringBase<char> CUtlConstString;
|
||||
typedef CUtlConstStringBase<wchar_t> CUtlConstWideString;
|
||||
|
||||
template < typename T > struct UTLConstStringCaselessStringLessFunctor { bool operator()(const CUtlConstStringBase<T>& a, const char* b) const { return StringFuncs<T>::CaselessCompare(a.Get(), b) < 0; } };
|
||||
template < typename T > struct UTLConstStringCaselessStringEqualFunctor { bool operator()(const CUtlConstStringBase<T>& a, const char* b) const { return StringFuncs<T>::CaselessCompare(a.Get(), b) == 0; } };
|
||||
|
||||
|
||||
#endif
|
210
SpyCustom/sdk/utlsymbol.h
Normal file
210
SpyCustom/sdk/utlsymbol.h
Normal file
@ -0,0 +1,210 @@
|
||||
#ifndef UTLSYMBOL_H
|
||||
#define UTLSYMBOL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "threadtools.h"
|
||||
#include "utlrbtree.h"
|
||||
#include "utlvector.h"
|
||||
|
||||
|
||||
class CUtlSymbolTable;
|
||||
class CUtlSymbolTableMT;
|
||||
|
||||
|
||||
typedef unsigned short UtlSymId_t;
|
||||
|
||||
#define UTL_INVAL_SYMBOL ((UtlSymId_t)~0)
|
||||
|
||||
class CUtlSymbol
|
||||
{
|
||||
public:
|
||||
CUtlSymbol() : m_Id(UTL_INVAL_SYMBOL) {}
|
||||
CUtlSymbol(UtlSymId_t id) : m_Id(id) {}
|
||||
CUtlSymbol(const char* pStr);
|
||||
CUtlSymbol(CUtlSymbol const& sym) : m_Id(sym.m_Id) {}
|
||||
|
||||
CUtlSymbol& operator=(CUtlSymbol const& src) { m_Id = src.m_Id; return *this; }
|
||||
|
||||
bool operator==(CUtlSymbol const& src) const { return m_Id == src.m_Id; }
|
||||
bool operator==(const char* pStr) const;
|
||||
|
||||
bool IsValid() const { return m_Id != UTL_INVAL_SYMBOL; }
|
||||
|
||||
operator UtlSymId_t const() const { return m_Id; }
|
||||
|
||||
const char* String() const;
|
||||
|
||||
static void DisableStaticSymbolTable();
|
||||
|
||||
protected:
|
||||
UtlSymId_t m_Id;
|
||||
|
||||
static void Initialize();
|
||||
|
||||
static CUtlSymbolTableMT* CurrTable();
|
||||
|
||||
static CUtlSymbolTableMT* s_pSymbolTable;
|
||||
|
||||
static bool s_bAllowStaticSymbolTable;
|
||||
|
||||
friend class CCleanupUtlSymbolTable;
|
||||
};
|
||||
|
||||
|
||||
class CUtlSymbolTable
|
||||
{
|
||||
public:
|
||||
CUtlSymbolTable(int growSize = 0, int initSize = 32, bool caseInsensitive = false);
|
||||
~CUtlSymbolTable();
|
||||
|
||||
CUtlSymbol AddString(const char* pString);
|
||||
|
||||
CUtlSymbol Find(const char* pString) const;
|
||||
|
||||
const char* String(CUtlSymbol id) const;
|
||||
|
||||
void RemoveAll();
|
||||
|
||||
int GetNumStrings(void) const
|
||||
{
|
||||
return m_Lookup.Count();
|
||||
}
|
||||
|
||||
protected:
|
||||
class CStringPoolIndex
|
||||
{
|
||||
public:
|
||||
inline CStringPoolIndex()
|
||||
{
|
||||
}
|
||||
|
||||
inline CStringPoolIndex(unsigned short iPool, unsigned short iOffset)
|
||||
{
|
||||
m_iPool = iPool;
|
||||
m_iOffset = iOffset;
|
||||
}
|
||||
|
||||
inline bool operator==(const CStringPoolIndex& other) const
|
||||
{
|
||||
return m_iPool == other.m_iPool && m_iOffset == other.m_iOffset;
|
||||
}
|
||||
|
||||
unsigned short m_iPool;
|
||||
unsigned short m_iOffset;
|
||||
};
|
||||
|
||||
class CLess
|
||||
{
|
||||
public:
|
||||
CLess(int ignored = 0) {}
|
||||
bool operator!() const { return false; }
|
||||
bool operator()(const CStringPoolIndex& left, const CStringPoolIndex& right) const;
|
||||
};
|
||||
|
||||
class CTree : public CUtlRBTree<CStringPoolIndex, unsigned short, CLess>
|
||||
{
|
||||
public:
|
||||
CTree(int growSize, int initSize) : CUtlRBTree<CStringPoolIndex, unsigned short, CLess>(growSize, initSize) {}
|
||||
friend class CUtlSymbolTable::CLess;
|
||||
};
|
||||
|
||||
struct StringPool_t
|
||||
{
|
||||
int m_TotalLen;
|
||||
int m_SpaceUsed;
|
||||
char m_Data[1];
|
||||
};
|
||||
|
||||
CTree m_Lookup;
|
||||
bool m_bInsensitive;
|
||||
mutable const char* m_pUserSearchString;
|
||||
|
||||
CUtlVector<StringPool_t*> m_StringPools;
|
||||
|
||||
private:
|
||||
int FindPoolWithSpace(int len) const;
|
||||
const char* StringFromIndex(const CStringPoolIndex& index) const;
|
||||
|
||||
friend class CLess;
|
||||
};
|
||||
|
||||
class CUtlSymbolTableMT : private CUtlSymbolTable
|
||||
{
|
||||
public:
|
||||
CUtlSymbolTableMT(int growSize = 0, int initSize = 32, bool caseInsensitive = false)
|
||||
: CUtlSymbolTable(growSize, initSize, caseInsensitive)
|
||||
{
|
||||
}
|
||||
|
||||
CUtlSymbol AddString(const char* pString)
|
||||
{
|
||||
m_lock.LockForWrite();
|
||||
CUtlSymbol result = CUtlSymbolTable::AddString(pString);
|
||||
m_lock.UnlockWrite();
|
||||
return result;
|
||||
}
|
||||
|
||||
CUtlSymbol Find(const char* pString) const
|
||||
{
|
||||
m_lock.LockForRead();
|
||||
CUtlSymbol result = CUtlSymbolTable::Find(pString);
|
||||
m_lock.UnlockRead();
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* String(CUtlSymbol id) const
|
||||
{
|
||||
m_lock.LockForRead();
|
||||
const char* pszResult = CUtlSymbolTable::String(id);
|
||||
m_lock.UnlockRead();
|
||||
return pszResult;
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
mutable CThreadSpinRWLock m_lock;
|
||||
#else
|
||||
mutable CThreadRWLock m_lock;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef void* FileNameHandle_t;
|
||||
#define FILENAMEHANDLE_INVALID 0
|
||||
|
||||
class CUtlFilenameSymbolTable
|
||||
{
|
||||
struct FileNameHandleInternal_t
|
||||
{
|
||||
FileNameHandleInternal_t()
|
||||
{
|
||||
path = 0;
|
||||
file = 0;
|
||||
}
|
||||
|
||||
unsigned short path;
|
||||
unsigned short file;
|
||||
};
|
||||
|
||||
class HashTable;
|
||||
|
||||
public:
|
||||
CUtlFilenameSymbolTable();
|
||||
~CUtlFilenameSymbolTable();
|
||||
FileNameHandle_t FindOrAddFileName(const char* pFileName);
|
||||
FileNameHandle_t FindFileName(const char* pFileName);
|
||||
int PathIndex(const FileNameHandle_t& handle) { return ((const FileNameHandleInternal_t*)&handle)->path; }
|
||||
bool String(const FileNameHandle_t& handle, char* buf, int buflen);
|
||||
void RemoveAll();
|
||||
|
||||
private:
|
||||
HashTable* m_Strings;
|
||||
mutable CThreadSpinRWLock m_lock;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
424
SpyCustom/sdk/utlsymbollarge.h
Normal file
424
SpyCustom/sdk/utlsymbollarge.h
Normal file
@ -0,0 +1,424 @@
|
||||
#ifndef UTLSYMBOLLARGE_H
|
||||
#define UTLSYMBOLLARGE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "threadtools.h"
|
||||
#include "utltshash.h"
|
||||
#include "stringpool.h"
|
||||
#include "vprof.h"
|
||||
#include "utltshash.h"
|
||||
|
||||
typedef intp UtlSymLargeId_t;
|
||||
|
||||
#define UTL_INVAL_SYMBOL_LARGE ((UtlSymLargeId_t)~0)
|
||||
|
||||
class CUtlSymbolLarge
|
||||
{
|
||||
public:
|
||||
CUtlSymbolLarge()
|
||||
{
|
||||
u.m_Id = UTL_INVAL_SYMBOL_LARGE;
|
||||
}
|
||||
|
||||
CUtlSymbolLarge(UtlSymLargeId_t id)
|
||||
{
|
||||
u.m_Id = id;
|
||||
}
|
||||
CUtlSymbolLarge(CUtlSymbolLarge const& sym)
|
||||
{
|
||||
u.m_Id = sym.u.m_Id;
|
||||
}
|
||||
|
||||
CUtlSymbolLarge& operator=(CUtlSymbolLarge const& src)
|
||||
{
|
||||
u.m_Id = src.u.m_Id;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(CUtlSymbolLarge const& src) const
|
||||
{
|
||||
return u.m_Id == src.u.m_Id;
|
||||
}
|
||||
|
||||
bool operator==(UtlSymLargeId_t const& src) const
|
||||
{
|
||||
return u.m_Id == src;
|
||||
}
|
||||
|
||||
bool operator!=(CUtlSymbolLarge const& src) const
|
||||
{
|
||||
return u.m_Id != src.u.m_Id;
|
||||
}
|
||||
|
||||
bool operator!=(UtlSymLargeId_t const& src) const
|
||||
{
|
||||
return u.m_Id != src;
|
||||
}
|
||||
|
||||
operator UtlSymLargeId_t const() const
|
||||
{
|
||||
return u.m_Id;
|
||||
}
|
||||
|
||||
inline const char* String() const
|
||||
{
|
||||
if (u.m_Id == UTL_INVAL_SYMBOL_LARGE)
|
||||
return "";
|
||||
return u.m_pAsString;
|
||||
}
|
||||
|
||||
inline bool IsValid() const
|
||||
{
|
||||
return u.m_Id != UTL_INVAL_SYMBOL_LARGE ? true : false;
|
||||
}
|
||||
|
||||
private:
|
||||
CUtlSymbolLarge(const char* pStr);
|
||||
bool operator==(const char* pStr) const;
|
||||
|
||||
union
|
||||
{
|
||||
UtlSymLargeId_t m_Id;
|
||||
char const* m_pAsString;
|
||||
} u;
|
||||
};
|
||||
|
||||
#define MIN_STRING_POOL_SIZE 2048
|
||||
|
||||
inline uint32 CUtlSymbolLarge_Hash(bool CASEINSENSITIVE, const char* pString, int len)
|
||||
{
|
||||
return (CASEINSENSITIVE ? HashStringCaseless(pString) : HashString(pString));
|
||||
}
|
||||
|
||||
typedef uint32 LargeSymbolTableHashDecoration_t;
|
||||
|
||||
struct CUtlSymbolTableLargeBaseTreeEntry_t
|
||||
{
|
||||
LargeSymbolTableHashDecoration_t m_Hash;
|
||||
char m_String[1];
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return ((m_Hash == 0) && (0 == m_String[0]));
|
||||
}
|
||||
|
||||
char const* String() const
|
||||
{
|
||||
return (const char*)&m_String[0];
|
||||
}
|
||||
|
||||
CUtlSymbolLarge ToSymbol() const
|
||||
{
|
||||
return reinterpret_cast<UtlSymLargeId_t>(String());
|
||||
}
|
||||
|
||||
LargeSymbolTableHashDecoration_t HashValue() const
|
||||
{
|
||||
return m_Hash;
|
||||
}
|
||||
};
|
||||
|
||||
template< class TreeType, bool CASEINSENSITIVE >
|
||||
class CTreeEntryLess
|
||||
{
|
||||
public:
|
||||
CTreeEntryLess(int ignored = 0) {}
|
||||
bool operator!() const { return false; }
|
||||
bool operator()(CUtlSymbolTableLargeBaseTreeEntry_t* const& left, CUtlSymbolTableLargeBaseTreeEntry_t* const& right) const
|
||||
{
|
||||
if (left->m_Hash == right->m_Hash)
|
||||
{
|
||||
if (!CASEINSENSITIVE)
|
||||
return strcmp(left->String(), right->String()) < 0;
|
||||
else
|
||||
return V_stricmp(left->String(), right->String()) < 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return left->m_Hash < right->m_Hash;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template< bool CASEINSENSITIVE >
|
||||
class CNonThreadsafeTree : public CUtlRBTree<CUtlSymbolTableLargeBaseTreeEntry_t*, intp, CTreeEntryLess< CNonThreadsafeTree< CASEINSENSITIVE >, CASEINSENSITIVE > >
|
||||
{
|
||||
public:
|
||||
typedef CUtlRBTree<CUtlSymbolTableLargeBaseTreeEntry_t*, intp, CTreeEntryLess< CNonThreadsafeTree, CASEINSENSITIVE > > CNonThreadsafeTreeType;
|
||||
|
||||
CNonThreadsafeTree() :
|
||||
CNonThreadsafeTreeType(0, 16)
|
||||
{
|
||||
}
|
||||
inline void Commit()
|
||||
{
|
||||
}
|
||||
inline intp Insert(CUtlSymbolTableLargeBaseTreeEntry_t* entry)
|
||||
{
|
||||
return CNonThreadsafeTreeType::Insert(entry);
|
||||
}
|
||||
inline intp Find(CUtlSymbolTableLargeBaseTreeEntry_t* entry) const
|
||||
{
|
||||
return CNonThreadsafeTreeType::Find(entry);
|
||||
}
|
||||
inline intp InvalidIndex() const
|
||||
{
|
||||
return CNonThreadsafeTreeType::InvalidIndex();
|
||||
}
|
||||
inline int GetElements(int nFirstElement, int nCount, CUtlSymbolLarge* pElements) const
|
||||
{
|
||||
CUtlVector< CUtlSymbolTableLargeBaseTreeEntry_t* > list;
|
||||
list.EnsureCount(nCount);
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
pElements[i] = CNonThreadsafeTreeType::Element(i)->ToSymbol();
|
||||
}
|
||||
|
||||
return nCount;
|
||||
}
|
||||
};
|
||||
|
||||
template < int BUCKET_COUNT, class KEYTYPE, bool CASEINSENSITIVE >
|
||||
class CCThreadsafeTreeHashMethod
|
||||
{
|
||||
public:
|
||||
static int Hash(const KEYTYPE& key, int nBucketMask)
|
||||
{
|
||||
uint32 nHash = key->HashValue();
|
||||
return (nHash & nBucketMask);
|
||||
}
|
||||
|
||||
static bool Compare(CUtlSymbolTableLargeBaseTreeEntry_t* const& lhs, CUtlSymbolTableLargeBaseTreeEntry_t* const& rhs)
|
||||
{
|
||||
if (lhs->m_Hash != rhs->m_Hash)
|
||||
return false;
|
||||
if (!CASEINSENSITIVE)
|
||||
{
|
||||
return (!Q_strcmp(lhs->String(), rhs->String()) ? true : false);
|
||||
}
|
||||
|
||||
return (!Q_stricmp(lhs->String(), rhs->String()) ? true : false);
|
||||
}
|
||||
};
|
||||
|
||||
template < bool CASEINSENSITIVE >
|
||||
class CThreadsafeTree : public CUtlTSHash< CUtlSymbolTableLargeBaseTreeEntry_t*, 2048, CUtlSymbolTableLargeBaseTreeEntry_t*, CCThreadsafeTreeHashMethod< 2048, CUtlSymbolTableLargeBaseTreeEntry_t*, CASEINSENSITIVE > >
|
||||
{
|
||||
public:
|
||||
typedef CUtlTSHash< CUtlSymbolTableLargeBaseTreeEntry_t*, 2048, CUtlSymbolTableLargeBaseTreeEntry_t*, CCThreadsafeTreeHashMethod< 2048, CUtlSymbolTableLargeBaseTreeEntry_t*, CASEINSENSITIVE > > CThreadsafeTreeType;
|
||||
|
||||
CThreadsafeTree() :
|
||||
CThreadsafeTreeType(32)
|
||||
{
|
||||
}
|
||||
inline void Commit()
|
||||
{
|
||||
CThreadsafeTreeType::Commit();
|
||||
}
|
||||
inline UtlTSHashHandle_t Insert(CUtlSymbolTableLargeBaseTreeEntry_t* entry)
|
||||
{
|
||||
return CThreadsafeTreeType::Insert(entry, entry);
|
||||
}
|
||||
inline UtlTSHashHandle_t Find(CUtlSymbolTableLargeBaseTreeEntry_t* entry)
|
||||
{
|
||||
return CThreadsafeTreeType::Find(entry);
|
||||
}
|
||||
inline UtlTSHashHandle_t InvalidIndex() const
|
||||
{
|
||||
return CThreadsafeTreeType::InvalidHandle();
|
||||
}
|
||||
inline int GetElements(UtlTSHashHandle_t nFirstElement, int nCount, CUtlSymbolLarge* pElements) const
|
||||
{
|
||||
CUtlVector< UtlTSHashHandle_t > list;
|
||||
list.EnsureCount(nCount);
|
||||
int c = CThreadsafeTreeType::GetElements(nFirstElement, nCount, list.Base());
|
||||
for (int i = 0; i < c; ++i)
|
||||
{
|
||||
pElements[i] = CThreadsafeTreeType::Element(list[i])->ToSymbol();
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE = MIN_STRING_POOL_SIZE >
|
||||
class CUtlSymbolTableLargeBase
|
||||
{
|
||||
public:
|
||||
CUtlSymbolTableLargeBase();
|
||||
~CUtlSymbolTableLargeBase();
|
||||
|
||||
CUtlSymbolLarge AddString(const char* pString);
|
||||
|
||||
CUtlSymbolLarge Find(const char* pString) const;
|
||||
|
||||
void RemoveAll();
|
||||
|
||||
int GetNumStrings(void) const
|
||||
{
|
||||
return m_Lookup.Count();
|
||||
}
|
||||
|
||||
void Commit()
|
||||
{
|
||||
m_Lookup.Commit();
|
||||
}
|
||||
|
||||
int GetElements(int nFirstElement, int nCount, CUtlSymbolLarge* pElements) const
|
||||
{
|
||||
return m_Lookup.GetElements(nFirstElement, nCount, pElements);
|
||||
}
|
||||
|
||||
const char* GetElementString(int nElement) const
|
||||
{
|
||||
return m_Lookup.Element(nElement)->String();
|
||||
}
|
||||
|
||||
uint64 GetMemoryUsage() const
|
||||
{
|
||||
uint64 unBytesUsed = 0u;
|
||||
|
||||
for (int i = 0; i < m_StringPools.Count(); i++)
|
||||
{
|
||||
StringPool_t* pPool = m_StringPools[i];
|
||||
|
||||
unBytesUsed += (uint64)pPool->m_TotalLen;
|
||||
}
|
||||
return unBytesUsed;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
struct StringPool_t
|
||||
{
|
||||
int m_TotalLen;
|
||||
int m_SpaceUsed;
|
||||
char m_Data[1];
|
||||
};
|
||||
|
||||
TreeType m_Lookup;
|
||||
|
||||
CUtlVector< StringPool_t* > m_StringPools;
|
||||
|
||||
private:
|
||||
int FindPoolWithSpace(int len) const;
|
||||
};
|
||||
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE >
|
||||
inline CUtlSymbolTableLargeBase<TreeType, CASEINSENSITIVE, POOL_SIZE >::CUtlSymbolTableLargeBase() :
|
||||
m_StringPools(8)
|
||||
{
|
||||
}
|
||||
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE >
|
||||
inline CUtlSymbolTableLargeBase<TreeType, CASEINSENSITIVE, POOL_SIZE>::~CUtlSymbolTableLargeBase()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE >
|
||||
inline CUtlSymbolLarge CUtlSymbolTableLargeBase<TreeType, CASEINSENSITIVE, POOL_SIZE>::Find(const char* pString) const
|
||||
{
|
||||
VPROF("CUtlSymbolLarge::Find");
|
||||
if (!pString)
|
||||
return CUtlSymbolLarge();
|
||||
|
||||
int len = Q_strlen(pString) + 1;
|
||||
|
||||
CUtlSymbolTableLargeBaseTreeEntry_t* search = (CUtlSymbolTableLargeBaseTreeEntry_t*)_alloca(len + sizeof(LargeSymbolTableHashDecoration_t));
|
||||
search->m_Hash = CUtlSymbolLarge_Hash(CASEINSENSITIVE, pString, len);
|
||||
Q_memcpy((char*)&search->m_String[0], pString, len);
|
||||
|
||||
intp idx = const_cast<TreeType&>(m_Lookup).Find(search);
|
||||
|
||||
if (idx == m_Lookup.InvalidIndex())
|
||||
return UTL_INVAL_SYMBOL_LARGE;
|
||||
|
||||
const CUtlSymbolTableLargeBaseTreeEntry_t* entry = m_Lookup[idx];
|
||||
return entry->ToSymbol();
|
||||
}
|
||||
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE >
|
||||
inline int CUtlSymbolTableLargeBase<TreeType, CASEINSENSITIVE, POOL_SIZE>::FindPoolWithSpace(int len) const
|
||||
{
|
||||
for (int i = 0; i < m_StringPools.Count(); i++)
|
||||
{
|
||||
StringPool_t* pPool = m_StringPools[i];
|
||||
|
||||
if ((pPool->m_TotalLen - pPool->m_SpaceUsed) >= len)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE >
|
||||
inline CUtlSymbolLarge CUtlSymbolTableLargeBase<TreeType, CASEINSENSITIVE, POOL_SIZE>::AddString(const char* pString)
|
||||
{
|
||||
VPROF("CUtlSymbolLarge::AddString");
|
||||
if (!pString)
|
||||
return UTL_INVAL_SYMBOL_LARGE;
|
||||
|
||||
CUtlSymbolLarge id = Find(pString);
|
||||
if (id != UTL_INVAL_SYMBOL_LARGE)
|
||||
return id;
|
||||
|
||||
int lenString = Q_strlen(pString) + 1;
|
||||
int lenDecorated = lenString + sizeof(LargeSymbolTableHashDecoration_t);
|
||||
lenDecorated = ALIGN_VALUE(lenDecorated, sizeof(LargeSymbolTableHashDecoration_t));
|
||||
|
||||
int iPool = FindPoolWithSpace(lenDecorated);
|
||||
if (iPool == -1)
|
||||
{
|
||||
int newPoolSize = MAX(lenDecorated + sizeof(StringPool_t), POOL_SIZE);
|
||||
StringPool_t* pPool = (StringPool_t*)malloc(newPoolSize);
|
||||
|
||||
pPool->m_TotalLen = newPoolSize - sizeof(StringPool_t);
|
||||
pPool->m_SpaceUsed = 0;
|
||||
iPool = m_StringPools.AddToTail(pPool);
|
||||
}
|
||||
|
||||
LargeSymbolTableHashDecoration_t hash = CUtlSymbolLarge_Hash(CASEINSENSITIVE, pString, lenString);
|
||||
|
||||
StringPool_t* pPool = m_StringPools[iPool];
|
||||
CUtlSymbolTableLargeBaseTreeEntry_t* entry = (CUtlSymbolTableLargeBaseTreeEntry_t*)&pPool->m_Data[pPool->m_SpaceUsed];
|
||||
|
||||
pPool->m_SpaceUsed += lenDecorated;
|
||||
|
||||
entry->m_Hash = hash;
|
||||
char* pText = (char*)&entry->m_String[0];
|
||||
Q_memcpy(pText, pString, lenString);
|
||||
|
||||
MEM_ALLOC_CREDIT();
|
||||
return m_Lookup.Element(m_Lookup.Insert(entry))->ToSymbol();
|
||||
}
|
||||
|
||||
#ifdef ANALYZE_SUPPRESS
|
||||
ANALYZE_SUPPRESS(6001);
|
||||
#endif
|
||||
template < class TreeType, bool CASEINSENSITIVE, size_t POOL_SIZE >
|
||||
inline void CUtlSymbolTableLargeBase<TreeType, CASEINSENSITIVE, POOL_SIZE>::RemoveAll()
|
||||
{
|
||||
m_Lookup.Purge();
|
||||
|
||||
for (int i = 0; i < m_StringPools.Count(); i++)
|
||||
free(m_StringPools[i]);
|
||||
|
||||
m_StringPools.RemoveAll();
|
||||
}
|
||||
#ifdef ANALYZE_UNSUPPRESS
|
||||
ANALYZE_UNSUPPRESS();
|
||||
#endif
|
||||
|
||||
typedef CUtlSymbolTableLargeBase< CNonThreadsafeTree< false >, false > CUtlSymbolTableLarge;
|
||||
typedef CUtlSymbolTableLargeBase< CNonThreadsafeTree< true >, true > CUtlSymbolTableLarge_CI;
|
||||
typedef CUtlSymbolTableLargeBase< CThreadsafeTree< false >, false > CUtlSymbolTableLargeMT;
|
||||
typedef CUtlSymbolTableLargeBase< CThreadsafeTree< true >, true > CUtlSymbolTableLargeMT_CI;
|
||||
|
||||
#endif
|
531
SpyCustom/sdk/utltshash.h
Normal file
531
SpyCustom/sdk/utltshash.h
Normal file
@ -0,0 +1,531 @@
|
||||
#ifndef UTLTSHASH_H
|
||||
#define UTLTSHASH_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include "threadtools.h"
|
||||
#include "mempool.h"
|
||||
#include "generichash.h"
|
||||
|
||||
|
||||
typedef intp UtlTSHashHandle_t;
|
||||
|
||||
template < class T >
|
||||
abstract_class ITSHashConstructor
|
||||
{
|
||||
public:
|
||||
virtual void Construct(T * pElement) = 0;
|
||||
};
|
||||
|
||||
template < class T >
|
||||
class CDefaultTSHashConstructor : public ITSHashConstructor< T >
|
||||
{
|
||||
public:
|
||||
virtual void Construct(T* pElement)
|
||||
{
|
||||
::Construct(pElement);
|
||||
}
|
||||
};
|
||||
|
||||
template < int BUCKET_COUNT, class KEYTYPE = intp >
|
||||
class CUtlTSHashGenericHash
|
||||
{
|
||||
public:
|
||||
static int Hash(const KEYTYPE& key, int nBucketMask)
|
||||
{
|
||||
int nHash = HashIntConventional((intp)key);
|
||||
if (BUCKET_COUNT <= USHRT_MAX)
|
||||
{
|
||||
nHash ^= (nHash >> 16);
|
||||
}
|
||||
if (BUCKET_COUNT <= UCHAR_MAX)
|
||||
{
|
||||
nHash ^= (nHash >> 8);
|
||||
}
|
||||
return (nHash & nBucketMask);
|
||||
}
|
||||
|
||||
static bool Compare(const KEYTYPE& lhs, const KEYTYPE& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template < int BUCKET_COUNT, class KEYTYPE >
|
||||
class CUtlTSHashUseKeyHashMethod
|
||||
{
|
||||
public:
|
||||
static int Hash(const KEYTYPE& key, int nBucketMask)
|
||||
{
|
||||
uint32 nHash = key.HashValue();
|
||||
return (nHash & nBucketMask);
|
||||
}
|
||||
|
||||
static bool Compare(const KEYTYPE& lhs, const KEYTYPE& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
||||
template< class T, int BUCKET_COUNT, class KEYTYPE = intp, class HashFuncs = CUtlTSHashGenericHash< BUCKET_COUNT, KEYTYPE >, int nAlignment = 0 >
|
||||
class CUtlTSHash
|
||||
{
|
||||
public:
|
||||
CUtlTSHash(int nAllocationCount);
|
||||
~CUtlTSHash();
|
||||
|
||||
static UtlTSHashHandle_t InvalidHandle(void) { return (UtlTSHashHandle_t)0; }
|
||||
|
||||
UtlTSHashHandle_t Find(KEYTYPE uiKey);
|
||||
|
||||
UtlTSHashHandle_t Insert(KEYTYPE uiKey, const T& data, bool* pDidInsert = NULL);
|
||||
UtlTSHashHandle_t Insert(KEYTYPE uiKey, ITSHashConstructor<T>* pConstructor, bool* pDidInsert = NULL);
|
||||
|
||||
UtlTSHashHandle_t FastInsert(KEYTYPE uiKey, const T& data);
|
||||
UtlTSHashHandle_t FastInsert(KEYTYPE uiKey, ITSHashConstructor<T>* pConstructor);
|
||||
|
||||
void Commit();
|
||||
|
||||
void FindAndRemove(KEYTYPE uiKey);
|
||||
void Remove(UtlTSHashHandle_t hHash) { FindAndRemove(GetID(hHash)); }
|
||||
void RemoveAll(void);
|
||||
void Purge(void);
|
||||
|
||||
int Count() const;
|
||||
|
||||
int GetElements(int nFirstElement, int nCount, UtlTSHashHandle_t* pHandles) const;
|
||||
|
||||
T& Element(UtlTSHashHandle_t hHash);
|
||||
T const& Element(UtlTSHashHandle_t hHash) const;
|
||||
T& operator[](UtlTSHashHandle_t hHash);
|
||||
T const& operator[](UtlTSHashHandle_t hHash) const;
|
||||
KEYTYPE GetID(UtlTSHashHandle_t hHash) const;
|
||||
|
||||
UtlTSHashHandle_t ElementPtrToHandle(T* pElement) const;
|
||||
|
||||
private:
|
||||
template < typename Data_t >
|
||||
struct HashFixedDataInternal_t
|
||||
{
|
||||
KEYTYPE m_uiKey;
|
||||
HashFixedDataInternal_t< Data_t >* m_pNext;
|
||||
Data_t m_Data;
|
||||
};
|
||||
|
||||
typedef HashFixedDataInternal_t<T> HashFixedData_t;
|
||||
|
||||
enum
|
||||
{
|
||||
BUCKET_MASK = BUCKET_COUNT - 1
|
||||
};
|
||||
|
||||
struct HashBucket_t
|
||||
{
|
||||
HashFixedData_t* m_pFirst;
|
||||
HashFixedData_t* m_pFirstUncommitted;
|
||||
CThreadSpinRWLock m_AddLock;
|
||||
};
|
||||
|
||||
UtlTSHashHandle_t Find(KEYTYPE uiKey, HashFixedData_t* pFirstElement, HashFixedData_t* pLastElement);
|
||||
UtlTSHashHandle_t InsertUncommitted(KEYTYPE uiKey, HashBucket_t& bucket);
|
||||
CMemoryPoolMT m_EntryMemory;
|
||||
HashBucket_t m_aBuckets[BUCKET_COUNT];
|
||||
bool m_bNeedsCommit;
|
||||
|
||||
#ifdef _DEBUG
|
||||
CInterlockedInt m_ContentionCheck;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::CUtlTSHash(int nAllocationCount) :
|
||||
m_EntryMemory(sizeof(HashFixedData_t), nAllocationCount, CUtlMemoryPool::GROW_SLOW, MEM_ALLOC_CLASSNAME(HashFixedData_t), nAlignment)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck = 0;
|
||||
#endif
|
||||
m_bNeedsCommit = false;
|
||||
for (int i = 0; i < BUCKET_COUNT; i++)
|
||||
{
|
||||
HashBucket_t& bucket = m_aBuckets[i];
|
||||
bucket.m_pFirst = NULL;
|
||||
bucket.m_pFirstUncommitted = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::~CUtlTSHash()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_ContentionCheck != 0)
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
#endif
|
||||
Purge();
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline void CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Purge(void)
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline int CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Count() const
|
||||
{
|
||||
return m_EntryMemory.Count();
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
int CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::GetElements(int nFirstElement, int nCount, UtlTSHashHandle_t* pHandles) const
|
||||
{
|
||||
int nIndex = 0;
|
||||
for (int i = 0; i < BUCKET_COUNT; i++)
|
||||
{
|
||||
const HashBucket_t& bucket = m_aBuckets[i];
|
||||
bucket.m_AddLock.LockForRead();
|
||||
for (HashFixedData_t* pElement = bucket.m_pFirstUncommitted; pElement; pElement = pElement->m_pNext)
|
||||
{
|
||||
if (--nFirstElement >= 0)
|
||||
continue;
|
||||
|
||||
pHandles[nIndex++] = (UtlTSHashHandle_t)pElement;
|
||||
if (nIndex >= nCount)
|
||||
{
|
||||
bucket.m_AddLock.UnlockRead();
|
||||
return nIndex;
|
||||
}
|
||||
}
|
||||
bucket.m_AddLock.UnlockRead();
|
||||
}
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::InsertUncommitted(KEYTYPE uiKey, HashBucket_t& bucket)
|
||||
{
|
||||
m_bNeedsCommit = true;
|
||||
HashFixedData_t* pNewElement = static_cast<HashFixedData_t*>(m_EntryMemory.Alloc());
|
||||
pNewElement->m_pNext = bucket.m_pFirstUncommitted;
|
||||
bucket.m_pFirstUncommitted = pNewElement;
|
||||
pNewElement->m_uiKey = uiKey;
|
||||
return (UtlTSHashHandle_t)pNewElement;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Insert(KEYTYPE uiKey, const T& data, bool* pDidInsert)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_ContentionCheck != 0)
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pDidInsert)
|
||||
{
|
||||
*pDidInsert = false;
|
||||
}
|
||||
|
||||
int iBucket = HashFuncs::Hash(uiKey, BUCKET_MASK);
|
||||
HashBucket_t& bucket = m_aBuckets[iBucket];
|
||||
|
||||
UtlTSHashHandle_t h = Find(uiKey);
|
||||
if (h != InvalidHandle())
|
||||
return h;
|
||||
|
||||
bucket.m_AddLock.LockForWrite();
|
||||
|
||||
h = Find(uiKey, bucket.m_pFirstUncommitted, bucket.m_pFirst);
|
||||
if (h == InvalidHandle())
|
||||
{
|
||||
h = InsertUncommitted(uiKey, bucket);
|
||||
CopyConstruct(&Element(h), data);
|
||||
if (pDidInsert)
|
||||
{
|
||||
*pDidInsert = true;
|
||||
}
|
||||
}
|
||||
|
||||
bucket.m_AddLock.UnlockWrite();
|
||||
return h;
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Insert(KEYTYPE uiKey, ITSHashConstructor<T>* pConstructor, bool* pDidInsert)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_ContentionCheck != 0)
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pDidInsert)
|
||||
{
|
||||
*pDidInsert = false;
|
||||
}
|
||||
|
||||
UtlTSHashHandle_t h = Find(uiKey);
|
||||
if (h != InvalidHandle())
|
||||
return h;
|
||||
|
||||
int iBucket = HashFuncs::Hash(uiKey, BUCKET_MASK);
|
||||
HashBucket_t& bucket = m_aBuckets[iBucket];
|
||||
bucket.m_AddLock.LockForWrite();
|
||||
|
||||
h = Find(uiKey, bucket.m_pFirstUncommitted, bucket.m_pFirst);
|
||||
if (h == InvalidHandle())
|
||||
{
|
||||
h = InsertUncommitted(uiKey, bucket);
|
||||
pConstructor->Construct(&Element(h));
|
||||
if (pDidInsert)
|
||||
{
|
||||
*pDidInsert = true;
|
||||
}
|
||||
}
|
||||
|
||||
bucket.m_AddLock.UnlockWrite();
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::FastInsert(KEYTYPE uiKey, const T& data)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_ContentionCheck != 0)
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
#endif
|
||||
int iBucket = HashFuncs::Hash(uiKey, BUCKET_MASK);
|
||||
HashBucket_t& bucket = m_aBuckets[iBucket];
|
||||
bucket.m_AddLock.LockForWrite();
|
||||
UtlTSHashHandle_t h = InsertUncommitted(uiKey, bucket);
|
||||
CopyConstruct(&Element(h), data);
|
||||
bucket.m_AddLock.UnlockWrite();
|
||||
return h;
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::FastInsert(KEYTYPE uiKey, ITSHashConstructor<T>* pConstructor)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_ContentionCheck != 0)
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
#endif
|
||||
int iBucket = HashFuncs::Hash(uiKey, BUCKET_MASK);
|
||||
HashBucket_t& bucket = m_aBuckets[iBucket];
|
||||
bucket.m_AddLock.LockForWrite();
|
||||
UtlTSHashHandle_t h = InsertUncommitted(uiKey, bucket);
|
||||
pConstructor->Construct(&Element(h));
|
||||
bucket.m_AddLock.UnlockWrite();
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline void CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Commit()
|
||||
{
|
||||
if (!m_bNeedsCommit)
|
||||
return;
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck++;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < BUCKET_COUNT; i++)
|
||||
{
|
||||
HashBucket_t& bucket = m_aBuckets[i];
|
||||
bucket.m_AddLock.LockForRead();
|
||||
bucket.m_pFirst = bucket.m_pFirstUncommitted;
|
||||
bucket.m_AddLock.UnlockRead();
|
||||
}
|
||||
|
||||
m_bNeedsCommit = false;
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck--;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline void CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::FindAndRemove(KEYTYPE uiKey)
|
||||
{
|
||||
if (m_EntryMemory.Count() == 0)
|
||||
return;
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck++;
|
||||
#endif
|
||||
|
||||
int iBucket = HashFuncs::Hash(uiKey, BUCKET_MASK);
|
||||
HashBucket_t& bucket = m_aBuckets[iBucket];
|
||||
bucket.m_AddLock.LockForWrite();
|
||||
|
||||
HashFixedData_t* pPrev = NULL;
|
||||
for (HashFixedData_t* pElement = bucket.m_pFirstUncommitted; pElement; pPrev = pElement, pElement = pElement->m_pNext)
|
||||
{
|
||||
if (!HashFuncs::Compare(pElement->m_uiKey, uiKey))
|
||||
continue;
|
||||
|
||||
if (pPrev)
|
||||
{
|
||||
pPrev->m_pNext = pElement->m_pNext;
|
||||
}
|
||||
else
|
||||
{
|
||||
bucket.m_pFirstUncommitted = pElement->m_pNext;
|
||||
}
|
||||
|
||||
if (bucket.m_pFirst == pElement)
|
||||
{
|
||||
bucket.m_pFirst = bucket.m_pFirst->m_pNext;
|
||||
}
|
||||
|
||||
Destruct(&pElement->m_Data);
|
||||
|
||||
#ifdef _DEBUG
|
||||
memset(pElement, 0xDD, sizeof(HashFixedData_t));
|
||||
#endif
|
||||
|
||||
m_EntryMemory.Free(pElement);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
bucket.m_AddLock.UnlockWrite();
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck--;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline void CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::RemoveAll(void)
|
||||
{
|
||||
m_bNeedsCommit = false;
|
||||
if (m_EntryMemory.Count() == 0)
|
||||
return;
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck++;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < BUCKET_COUNT; i++)
|
||||
{
|
||||
HashBucket_t& bucket = m_aBuckets[i];
|
||||
|
||||
bucket.m_AddLock.LockForWrite();
|
||||
|
||||
for (HashFixedData_t* pElement = bucket.m_pFirstUncommitted; pElement; pElement = pElement->m_pNext)
|
||||
{
|
||||
Destruct(&pElement->m_Data);
|
||||
}
|
||||
|
||||
bucket.m_pFirst = NULL;
|
||||
bucket.m_pFirstUncommitted = NULL;
|
||||
bucket.m_AddLock.UnlockWrite();
|
||||
}
|
||||
|
||||
m_EntryMemory.Clear();
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_ContentionCheck--;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Find(KEYTYPE uiKey, HashFixedData_t* pFirstElement, HashFixedData_t* pLastElement)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_ContentionCheck != 0)
|
||||
{
|
||||
DebuggerBreak();
|
||||
}
|
||||
#endif
|
||||
|
||||
for (HashFixedData_t* pElement = pFirstElement; pElement != pLastElement; pElement = pElement->m_pNext)
|
||||
{
|
||||
if (HashFuncs::Compare(pElement->m_uiKey, uiKey))
|
||||
return (UtlTSHashHandle_t)pElement;
|
||||
}
|
||||
return InvalidHandle();
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Find(KEYTYPE uiKey)
|
||||
{
|
||||
int iBucket = HashFuncs::Hash(uiKey, BUCKET_MASK);
|
||||
const HashBucket_t& bucket = m_aBuckets[iBucket];
|
||||
UtlTSHashHandle_t h = Find(uiKey, bucket.m_pFirst, NULL);
|
||||
if (h != InvalidHandle())
|
||||
return h;
|
||||
|
||||
bucket.m_AddLock.LockForRead();
|
||||
h = Find(uiKey, bucket.m_pFirstUncommitted, bucket.m_pFirst);
|
||||
bucket.m_AddLock.UnlockRead();
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline T& CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Element(UtlTSHashHandle_t hHash)
|
||||
{
|
||||
return ((HashFixedData_t*)hHash)->m_Data;
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline T const& CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::Element(UtlTSHashHandle_t hHash) const
|
||||
{
|
||||
return ((HashFixedData_t*)hHash)->m_Data;
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline T& CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::operator[](UtlTSHashHandle_t hHash)
|
||||
{
|
||||
return ((HashFixedData_t*)hHash)->m_Data;
|
||||
}
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline T const& CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::operator[](UtlTSHashHandle_t hHash) const
|
||||
{
|
||||
return ((HashFixedData_t*)hHash)->m_Data;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline KEYTYPE CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::GetID(UtlTSHashHandle_t hHash) const
|
||||
{
|
||||
return ((HashFixedData_t*)hHash)->m_uiKey;
|
||||
}
|
||||
|
||||
|
||||
template<class T, int BUCKET_COUNT, class KEYTYPE, class HashFuncs, int nAlignment>
|
||||
inline UtlTSHashHandle_t CUtlTSHash<T, BUCKET_COUNT, KEYTYPE, HashFuncs, nAlignment>::ElementPtrToHandle(T* pElement) const
|
||||
{
|
||||
Assert(pElement);
|
||||
HashFixedData_t* pFixedData = (HashFixedData_t*)((uint8*)pElement - offsetof(HashFixedData_t, m_Data));
|
||||
Assert(m_EntryMemory.IsAllocationWithinPool(pFixedData));
|
||||
return (UtlTSHashHandle_t)pFixedData;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
1016
SpyCustom/sdk/utlvector.h
Normal file
1016
SpyCustom/sdk/utlvector.h
Normal file
File diff suppressed because it is too large
Load Diff
8
SpyCustom/sdk/valve_minmax_on.h
Normal file
8
SpyCustom/sdk/valve_minmax_on.h
Normal file
@ -0,0 +1,8 @@
|
||||
#if !defined(POSIX)
|
||||
#ifndef min
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
#endif
|
12
SpyCustom/sdk/valve_off.h
Normal file
12
SpyCustom/sdk/valve_off.h
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
#ifdef STEAM
|
||||
|
||||
#undef char
|
||||
|
||||
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef _expand
|
||||
#undef free
|
||||
|
||||
#endif
|
13
SpyCustom/sdk/valve_on.h
Normal file
13
SpyCustom/sdk/valve_on.h
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#ifdef STEAM
|
||||
#ifdef ENFORCE_WCHAR
|
||||
#define char DontUseChar_SeeWcharOn.h
|
||||
#endif
|
||||
|
||||
|
||||
#define malloc( cub ) HEY_DONT_USE_MALLOC_USE_PVALLOC
|
||||
#define realloc( pvOld, cub ) HEY_DONT_USE_REALLOC_USE_PVREALLOC
|
||||
#define _expand( pvOld, cub ) HEY_DONT_USE_EXPAND_USE_PVEXPAND
|
||||
#define free( pv ) HEY_DONT_USE_FREE_USE_FREEPV
|
||||
|
||||
#endif
|
18
SpyCustom/sdk/vcollide.h
Normal file
18
SpyCustom/sdk/vcollide.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef VCOLLIDE_H
|
||||
#define VCOLLIDE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class CPhysCollide;
|
||||
|
||||
struct vcollide_t
|
||||
{
|
||||
unsigned short solidCount : 15;
|
||||
unsigned short isPacked : 1;
|
||||
unsigned short descSize;
|
||||
CPhysCollide** solids;
|
||||
char* pKeyValues;
|
||||
};
|
||||
|
||||
#endif
|
281
SpyCustom/sdk/vcrmode.h
Normal file
281
SpyCustom/sdk/vcrmode.h
Normal file
@ -0,0 +1,281 @@
|
||||
#ifndef VCRMODE_H
|
||||
#define VCRMODE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
#define VCRFILE_VERSION 2
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VCREvent_Sys_FloatTime = 0,
|
||||
VCREvent_recvfrom,
|
||||
VCREvent_SyncToken,
|
||||
VCREvent_GetCursorPos,
|
||||
VCREvent_SetCursorPos,
|
||||
VCREvent_ScreenToClient,
|
||||
VCREvent_Cmd_Exec,
|
||||
VCREvent_CmdLine,
|
||||
VCREvent_RegOpenKeyEx,
|
||||
VCREvent_RegSetValueEx,
|
||||
VCREvent_RegQueryValueEx,
|
||||
VCREvent_RegCreateKeyEx,
|
||||
VCREvent_RegCloseKey,
|
||||
VCREvent_PeekMessage,
|
||||
VCREvent_GameMsg,
|
||||
VCREvent_GetNumberOfConsoleInputEvents,
|
||||
VCREvent_ReadConsoleInput,
|
||||
VCREvent_GetKeyState,
|
||||
VCREvent_recv,
|
||||
VCREvent_send,
|
||||
VCREvent_Generic,
|
||||
VCREvent_CreateThread,
|
||||
VCREvent_WaitForSingleObject,
|
||||
VCREvent_EnterCriticalSection,
|
||||
VCREvent_Time,
|
||||
VCREvent_LocalTime,
|
||||
VCREvent_GenericString,
|
||||
VCREvent_NUMEVENTS
|
||||
} VCREvent;
|
||||
|
||||
#include "dbg.h"
|
||||
|
||||
#ifdef POSIX
|
||||
DBG_INTERFACE const char* BuildCmdLine(int argc, char** argv, bool fAddSteam = true);
|
||||
tchar* GetCommandLine();
|
||||
#endif
|
||||
|
||||
#ifdef _X360
|
||||
#define NO_VCR 1
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_VCR
|
||||
#define NOVCR(x) \
|
||||
{\
|
||||
VCRSetEnabled(0);\
|
||||
x;\
|
||||
VCRSetEnabled(1);\
|
||||
}
|
||||
#else
|
||||
#define NOVCR(x) \
|
||||
{\
|
||||
x;\
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct InputEvent_t;
|
||||
|
||||
|
||||
enum VCRMode_t
|
||||
{
|
||||
VCR_Invalid = -1,
|
||||
VCR_Disabled = 0,
|
||||
VCR_Record,
|
||||
VCR_Playback
|
||||
};
|
||||
|
||||
|
||||
abstract_class IVCRHelpers
|
||||
{
|
||||
public:
|
||||
virtual void ErrorMessage(const tchar * pMsg) = 0;
|
||||
virtual void* GetMainWindow() = 0;
|
||||
};
|
||||
|
||||
|
||||
abstract_class IVCRTrace
|
||||
{
|
||||
public:
|
||||
virtual VCREvent ReadEvent() = 0;
|
||||
virtual void Read(void* pDest, int size) = 0;
|
||||
};
|
||||
|
||||
typedef struct VCR_s
|
||||
{
|
||||
int (*Start)(tchar const* pFilename, bool bRecord, IVCRHelpers* pHelpers);
|
||||
void (*End)();
|
||||
|
||||
IVCRTrace* (*GetVCRTraceInterface)();
|
||||
|
||||
VCRMode_t(*GetMode)();
|
||||
|
||||
void (*SetEnabled)(int bEnabled);
|
||||
|
||||
void (*SyncToken)(tchar const* pToken);
|
||||
|
||||
double (*Hook_Sys_FloatTime)(double time);
|
||||
|
||||
int (*Hook_PeekMessage)(
|
||||
struct tagMSG* msg,
|
||||
void* hWnd,
|
||||
unsigned int wMsgFilterMin,
|
||||
unsigned int wMsgFilterMax,
|
||||
unsigned int wRemoveMsg
|
||||
);
|
||||
|
||||
void (*Hook_RecordGameMsg)(const InputEvent_t& event);
|
||||
void (*Hook_RecordEndGameMsg)();
|
||||
|
||||
bool (*Hook_PlaybackGameMsg)(InputEvent_t* pEvent);
|
||||
|
||||
int (*Hook_recvfrom)(int s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen);
|
||||
|
||||
void (*Hook_GetCursorPos)(struct tagPOINT* pt);
|
||||
void (*Hook_ScreenToClient)(void* hWnd, struct tagPOINT* pt);
|
||||
|
||||
void (*Hook_Cmd_Exec)(tchar** f);
|
||||
|
||||
tchar* (*Hook_GetCommandLine)();
|
||||
|
||||
long (*Hook_RegOpenKeyEx)(void* hKey, const tchar* lpSubKey, unsigned long ulOptions, unsigned long samDesired, void* pHKey);
|
||||
long (*Hook_RegSetValueEx)(void* hKey, tchar const* lpValueName, unsigned long Reserved, unsigned long dwType, uint8 const* lpData, unsigned long cbData);
|
||||
long (*Hook_RegQueryValueEx)(void* hKey, tchar const* lpValueName, unsigned long* lpReserved, unsigned long* lpType, uint8* lpData, unsigned long* lpcbData);
|
||||
long (*Hook_RegCreateKeyEx)(void* hKey, tchar const* lpSubKey, unsigned long Reserved, tchar* lpClass, unsigned long dwOptions, unsigned long samDesired, void* lpSecurityAttributes, void* phkResult, unsigned long* lpdwDisposition);
|
||||
void (*Hook_RegCloseKey)(void* hKey);
|
||||
|
||||
int (*Hook_GetNumberOfConsoleInputEvents)(void* hInput, unsigned long* pNumEvents);
|
||||
|
||||
int (*Hook_ReadConsoleInput)(void* hInput, void* pRecs, int nMaxRecs, unsigned long* pNumRead);
|
||||
|
||||
|
||||
void (*Hook_LocalTime)(struct tm* today);
|
||||
|
||||
short (*Hook_GetKeyState)(int nVirtKey);
|
||||
|
||||
int (*Hook_recv)(int s, char* buf, int len, int flags);
|
||||
int (*Hook_send)(int s, const char* buf, int len, int flags);
|
||||
|
||||
void (*GenericRecord)(const tchar* pEventName, const void* pData, int len);
|
||||
|
||||
|
||||
int (*GenericPlayback)(const tchar* pEventName, void* pOutData, int maxLen, bool bForceLenSame);
|
||||
|
||||
void (*GenericValue)(const tchar* pEventName, void* pData, int maxLen);
|
||||
|
||||
double (*GetPercentCompleted)();
|
||||
|
||||
void* (*Hook_CreateThread)(
|
||||
void* lpThreadAttributes,
|
||||
unsigned long dwStackSize,
|
||||
void* lpStartAddress,
|
||||
void* lpParameter,
|
||||
unsigned long dwCreationFlags,
|
||||
unsigned long* lpThreadID);
|
||||
|
||||
unsigned long (*Hook_WaitForSingleObject)(
|
||||
void* handle,
|
||||
unsigned long dwMilliseconds);
|
||||
|
||||
void (*Hook_EnterCriticalSection)(void* pCS);
|
||||
|
||||
void (*Hook_Time)(long* pTime);
|
||||
|
||||
void (*GenericString)(const char* pEventName, const char* pString);
|
||||
|
||||
void (*GenericValueVerify)(const tchar* pEventName, const void* pData, int maxLen);
|
||||
|
||||
unsigned long (*Hook_WaitForMultipleObjects)(uint32 nHandles, const void** pHandles, int bWaitAll, uint32 timeout);
|
||||
|
||||
} VCR_t;
|
||||
|
||||
#ifndef NO_VCR
|
||||
|
||||
PLATFORM_INTERFACE VCR_t* g_pVCR;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_VCR
|
||||
#define VCRStart g_pVCR->Start
|
||||
#define VCREnd g_pVCR->End
|
||||
#define VCRGetVCRTraceInterface g_pVCR->GetVCRTraceInterface
|
||||
#define VCRGetMode g_pVCR->GetMode
|
||||
#define VCRSetEnabled g_pVCR->SetEnabled
|
||||
#define VCRSyncToken g_pVCR->SyncToken
|
||||
#define VCRGenericString g_pVCR->GenericString
|
||||
#define VCRGenericValueVerify g_pVCR->GenericValueVerify
|
||||
#define VCRHook_Sys_FloatTime g_pVCR->Hook_Sys_FloatTime
|
||||
#define VCRHook_PeekMessage g_pVCR->Hook_PeekMessage
|
||||
#define VCRHook_RecordGameMsg g_pVCR->Hook_RecordGameMsg
|
||||
#define VCRHook_RecordEndGameMsg g_pVCR->Hook_RecordEndGameMsg
|
||||
#define VCRHook_PlaybackGameMsg g_pVCR->Hook_PlaybackGameMsg
|
||||
#define VCRHook_recvfrom g_pVCR->Hook_recvfrom
|
||||
#define VCRHook_GetCursorPos g_pVCR->Hook_GetCursorPos
|
||||
#define VCRHook_ScreenToClient g_pVCR->Hook_ScreenToClient
|
||||
#define VCRHook_Cmd_Exec g_pVCR->Hook_Cmd_Exec
|
||||
#define VCRHook_GetCommandLine g_pVCR->Hook_GetCommandLine
|
||||
#define VCRHook_RegOpenKeyEx g_pVCR->Hook_RegOpenKeyEx
|
||||
#define VCRHook_RegSetValueEx g_pVCR->Hook_RegSetValueEx
|
||||
#define VCRHook_RegQueryValueEx g_pVCR->Hook_RegQueryValueEx
|
||||
#define VCRHook_RegCreateKeyEx g_pVCR->Hook_RegCreateKeyEx
|
||||
#define VCRHook_RegCloseKey g_pVCR->Hook_RegCloseKey
|
||||
#define VCRHook_GetNumberOfConsoleInputEvents g_pVCR->Hook_GetNumberOfConsoleInputEvents
|
||||
#define VCRHook_ReadConsoleInput g_pVCR->Hook_ReadConsoleInput
|
||||
#define VCRHook_LocalTime g_pVCR->Hook_LocalTime
|
||||
#define VCRHook_GetKeyState g_pVCR->Hook_GetKeyState
|
||||
#define VCRHook_recv g_pVCR->Hook_recv
|
||||
#define VCRHook_send g_pVCR->Hook_send
|
||||
#define VCRGenericRecord g_pVCR->GenericRecord
|
||||
#define VCRGenericPlayback g_pVCR->GenericPlayback
|
||||
#define VCRGenericValue g_pVCR->GenericValue
|
||||
#define VCRGetPercentCompleted g_pVCR->GetPercentCompleted
|
||||
#define VCRHook_CreateThread g_pVCR->Hook_CreateThread
|
||||
#define VCRHook_WaitForSingleObject g_pVCR->Hook_WaitForSingleObject
|
||||
#define VCRHook_EnterCriticalSection g_pVCR->Hook_EnterCriticalSection
|
||||
#define VCRHook_Time g_pVCR->Hook_Time
|
||||
#define VCRHook_WaitForMultipleObjects( a, b, c, d) g_pVCR->Hook_WaitForMultipleObjects( a, (const void **)b, c, d)
|
||||
#else
|
||||
#define VCRStart( a, b, c ) (1)
|
||||
#define VCREnd ((void)(0))
|
||||
#define VCRGetVCRTraceInterface (NULL)
|
||||
#define VCRGetMode() (VCR_Disabled)
|
||||
#define VCRSetEnabled( a ) ((void)(0))
|
||||
#define VCRSyncToken( a ) ((void)(0))
|
||||
#define VCRGenericRecord MUST_IFDEF_OUT_GenericRecord
|
||||
#define VCRGenericPlayback MUST_IFDEF_OUT_GenericPlayback
|
||||
#define VCRGenericValue MUST_IFDEF_OUT_GenericValue
|
||||
#define VCRGenericString MUST_IFDEF_OUT_GenericString
|
||||
#define VCRGenericValueVerify MUST_IFDEF_OUT_GenericValueVerify
|
||||
#define VCRGetPercentCompleted() (0.0f)
|
||||
#define VCRHook_Sys_FloatTime Sys_FloatTime
|
||||
#define VCRHook_PeekMessage PeekMessage
|
||||
#define VCRHook_RecordGameMsg RecordGameMsg
|
||||
#define VCRHook_RecordEndGameMsg RecordEndGameMsg
|
||||
#define VCRHook_PlaybackGameMsg PlaybackGameMsg
|
||||
#define VCRHook_recvfrom recvfrom
|
||||
#define VCRHook_GetCursorPos GetCursorPos
|
||||
#define VCRHook_ScreenToClient ScreenToClient
|
||||
#define VCRHook_Cmd_Exec( a ) ((void)(0))
|
||||
#define VCRHook_GetCommandLine GetCommandLine
|
||||
#define VCRHook_RegOpenKeyEx RegOpenKeyEx
|
||||
#define VCRHook_RegSetValueEx RegSetValueEx
|
||||
#define VCRHook_RegQueryValueEx RegQueryValueEx
|
||||
#define VCRHook_RegCreateKeyEx RegCreateKeyEx
|
||||
#define VCRHook_RegCloseKey RegCloseKey
|
||||
#define VCRHook_GetNumberOfConsoleInputEvents GetNumberOfConsoleInputEvents
|
||||
#define VCRHook_ReadConsoleInput ReadConsoleInput
|
||||
#define VCRHook_LocalTime( a ) memset(a, 0, sizeof(*a));
|
||||
#define VCRHook_GetKeyState GetKeyState
|
||||
#define VCRHook_recv recv
|
||||
#define VCRHook_send send
|
||||
#if defined( _X360 )
|
||||
#define VCRHook_CreateThread CreateThread
|
||||
#else
|
||||
#define VCRHook_CreateThread (void*)_beginthreadex
|
||||
#endif
|
||||
#define VCRHook_WaitForSingleObject WaitForSingleObject
|
||||
#define VCRHook_EnterCriticalSection EnterCriticalSection
|
||||
#define VCRHook_WaitForMultipleObjects( a, b, c, d) WaitForMultipleObjects( a, (const HANDLE *)b, c, d)
|
||||
#define VCRHook_Time Time
|
||||
#endif
|
||||
|
||||
#endif
|
1878
SpyCustom/sdk/vector.h
Normal file
1878
SpyCustom/sdk/vector.h
Normal file
File diff suppressed because it is too large
Load Diff
533
SpyCustom/sdk/vector2d.h
Normal file
533
SpyCustom/sdk/vector2d.h
Normal file
@ -0,0 +1,533 @@
|
||||
#ifndef VECTOR2D_H
|
||||
#define VECTOR2D_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "dbg.h"
|
||||
#include "math_pfns.h"
|
||||
|
||||
|
||||
class Vector2D
|
||||
{
|
||||
public:
|
||||
vec_t x, y;
|
||||
|
||||
Vector2D(void);
|
||||
Vector2D(vec_t X, vec_t Y);
|
||||
Vector2D(const float* pFloat);
|
||||
|
||||
void Init(vec_t ix = 0.0f, vec_t iy = 0.0f);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
vec_t operator[](int i) const;
|
||||
vec_t& operator[](int i);
|
||||
|
||||
vec_t* Base();
|
||||
vec_t const* Base() const;
|
||||
|
||||
void Random(float minVal, float maxVal);
|
||||
|
||||
bool operator==(const Vector2D& v) const;
|
||||
bool operator!=(const Vector2D& v) const;
|
||||
|
||||
Vector2D& operator+=(const Vector2D& v);
|
||||
Vector2D& operator-=(const Vector2D& v);
|
||||
Vector2D& operator*=(const Vector2D& v);
|
||||
Vector2D& operator*=(float s);
|
||||
Vector2D& operator/=(const Vector2D& v);
|
||||
Vector2D& operator/=(float s);
|
||||
|
||||
void Negate();
|
||||
|
||||
vec_t Length() const;
|
||||
|
||||
vec_t LengthSqr(void) const;
|
||||
|
||||
bool IsZero(float tolerance = 0.01f) const
|
||||
{
|
||||
return (x > -tolerance && x < tolerance&&
|
||||
y > -tolerance && y < tolerance);
|
||||
}
|
||||
|
||||
vec_t NormalizeInPlace();
|
||||
|
||||
bool IsLengthGreaterThan(float val) const;
|
||||
bool IsLengthLessThan(float val) const;
|
||||
|
||||
vec_t DistTo(const Vector2D& vOther) const;
|
||||
|
||||
vec_t DistToSqr(const Vector2D& vOther) const;
|
||||
|
||||
void CopyToArray(float* rgfl) const;
|
||||
|
||||
void MulAdd(const Vector2D& a, const Vector2D& b, float scalar);
|
||||
|
||||
vec_t Dot(const Vector2D& vOther) const;
|
||||
|
||||
Vector2D& operator=(const Vector2D& vOther);
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
Vector2D(const Vector2D& vOther);
|
||||
|
||||
Vector2D operator-(void) const;
|
||||
|
||||
Vector2D operator+(const Vector2D& v) const;
|
||||
Vector2D operator-(const Vector2D& v) const;
|
||||
Vector2D operator*(const Vector2D& v) const;
|
||||
Vector2D operator/(const Vector2D& v) const;
|
||||
Vector2D operator*(float fl) const;
|
||||
Vector2D operator/(float fl) const;
|
||||
|
||||
Vector2D Cross(const Vector2D& vOther) const;
|
||||
|
||||
Vector2D Min(const Vector2D& vOther) const;
|
||||
Vector2D Max(const Vector2D& vOther) const;
|
||||
|
||||
#else
|
||||
|
||||
private:
|
||||
Vector2D(const Vector2D& vOther);
|
||||
#endif
|
||||
};
|
||||
|
||||
const Vector2D vec2_origin(0, 0);
|
||||
const Vector2D vec2_invalid(FLT_MAX, FLT_MAX);
|
||||
|
||||
void Vector2DClear(Vector2D& a);
|
||||
|
||||
void Vector2DCopy(const Vector2D& src, Vector2D& dst);
|
||||
|
||||
void Vector2DAdd(const Vector2D& a, const Vector2D& b, Vector2D& result);
|
||||
void Vector2DSubtract(const Vector2D& a, const Vector2D& b, Vector2D& result);
|
||||
void Vector2DMultiply(const Vector2D& a, vec_t b, Vector2D& result);
|
||||
void Vector2DMultiply(const Vector2D& a, const Vector2D& b, Vector2D& result);
|
||||
void Vector2DDivide(const Vector2D& a, vec_t b, Vector2D& result);
|
||||
void Vector2DDivide(const Vector2D& a, const Vector2D& b, Vector2D& result);
|
||||
void Vector2DMA(const Vector2D& start, float s, const Vector2D& dir, Vector2D& result);
|
||||
|
||||
void Vector2DMin(const Vector2D& a, const Vector2D& b, Vector2D& result);
|
||||
void Vector2DMax(const Vector2D& a, const Vector2D& b, Vector2D& result);
|
||||
|
||||
#define Vector2DExpand( v ) (v).x, (v).y
|
||||
|
||||
vec_t Vector2DNormalize(Vector2D& v);
|
||||
|
||||
vec_t Vector2DLength(const Vector2D& v);
|
||||
|
||||
vec_t DotProduct2D(const Vector2D& a, const Vector2D& b);
|
||||
|
||||
void Vector2DLerp(const Vector2D& src1, const Vector2D& src2, vec_t t, Vector2D& dest);
|
||||
|
||||
|
||||
|
||||
inline Vector2D::Vector2D(void)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
x = y = VEC_T_NAN;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline Vector2D::Vector2D(vec_t X, vec_t Y)
|
||||
{
|
||||
x = X; y = Y;
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline Vector2D::Vector2D(const float* pFloat)
|
||||
{
|
||||
Assert(pFloat);
|
||||
x = pFloat[0]; y = pFloat[1];
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
|
||||
inline Vector2D::Vector2D(const Vector2D& vOther)
|
||||
{
|
||||
Assert(vOther.IsValid());
|
||||
x = vOther.x; y = vOther.y;
|
||||
}
|
||||
|
||||
inline void Vector2D::Init(vec_t ix, vec_t iy)
|
||||
{
|
||||
x = ix; y = iy;
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline void Vector2D::Random(float minVal, float maxVal)
|
||||
{
|
||||
x = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
|
||||
y = minVal + ((float)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
|
||||
}
|
||||
|
||||
inline void Vector2DClear(Vector2D& a)
|
||||
{
|
||||
a.x = a.y = 0.0f;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator=(const Vector2D& vOther)
|
||||
{
|
||||
Assert(vOther.IsValid());
|
||||
x = vOther.x; y = vOther.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline vec_t& Vector2D::operator[](int i)
|
||||
{
|
||||
Assert((i >= 0) && (i < 2));
|
||||
return ((vec_t*)this)[i];
|
||||
}
|
||||
|
||||
inline vec_t Vector2D::operator[](int i) const
|
||||
{
|
||||
Assert((i >= 0) && (i < 2));
|
||||
return ((vec_t*)this)[i];
|
||||
}
|
||||
|
||||
inline vec_t* Vector2D::Base()
|
||||
{
|
||||
return (vec_t*)this;
|
||||
}
|
||||
|
||||
inline vec_t const* Vector2D::Base() const
|
||||
{
|
||||
return (vec_t const*)this;
|
||||
}
|
||||
|
||||
inline bool Vector2D::IsValid() const
|
||||
{
|
||||
return IsFinite(x) && IsFinite(y);
|
||||
}
|
||||
|
||||
inline bool Vector2D::operator==(const Vector2D& src) const
|
||||
{
|
||||
Assert(src.IsValid() && IsValid());
|
||||
return (src.x == x) && (src.y == y);
|
||||
}
|
||||
|
||||
inline bool Vector2D::operator!=(const Vector2D& src) const
|
||||
{
|
||||
Assert(src.IsValid() && IsValid());
|
||||
return (src.x != x) || (src.y != y);
|
||||
}
|
||||
|
||||
|
||||
inline void Vector2DCopy(const Vector2D& src, Vector2D& dst)
|
||||
{
|
||||
Assert(src.IsValid());
|
||||
dst.x = src.x;
|
||||
dst.y = src.y;
|
||||
}
|
||||
|
||||
inline void Vector2D::CopyToArray(float* rgfl) const
|
||||
{
|
||||
Assert(IsValid());
|
||||
Assert(rgfl);
|
||||
rgfl[0] = x; rgfl[1] = y;
|
||||
}
|
||||
|
||||
inline void Vector2D::Negate()
|
||||
{
|
||||
Assert(IsValid());
|
||||
x = -x; y = -y;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator+=(const Vector2D& v)
|
||||
{
|
||||
Assert(IsValid() && v.IsValid());
|
||||
x += v.x; y += v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator-=(const Vector2D& v)
|
||||
{
|
||||
Assert(IsValid() && v.IsValid());
|
||||
x -= v.x; y -= v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator*=(float fl)
|
||||
{
|
||||
x *= fl;
|
||||
y *= fl;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator*=(const Vector2D& v)
|
||||
{
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator/=(float fl)
|
||||
{
|
||||
Assert(fl != 0.0f);
|
||||
float oofl = 1.0f / fl;
|
||||
x *= oofl;
|
||||
y *= oofl;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector2D::operator/=(const Vector2D& v)
|
||||
{
|
||||
Assert(v.x != 0.0f && v.y != 0.0f);
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Vector2DAdd(const Vector2D& a, const Vector2D& b, Vector2D& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
c.x = a.x + b.x;
|
||||
c.y = a.y + b.y;
|
||||
}
|
||||
|
||||
inline void Vector2DSubtract(const Vector2D& a, const Vector2D& b, Vector2D& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
c.x = a.x - b.x;
|
||||
c.y = a.y - b.y;
|
||||
}
|
||||
|
||||
inline void Vector2DMultiply(const Vector2D& a, vec_t b, Vector2D& c)
|
||||
{
|
||||
Assert(a.IsValid() && IsFinite(b));
|
||||
c.x = a.x * b;
|
||||
c.y = a.y * b;
|
||||
}
|
||||
|
||||
inline void Vector2DMultiply(const Vector2D& a, const Vector2D& b, Vector2D& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
c.x = a.x * b.x;
|
||||
c.y = a.y * b.y;
|
||||
}
|
||||
|
||||
|
||||
inline void Vector2DDivide(const Vector2D& a, vec_t b, Vector2D& c)
|
||||
{
|
||||
Assert(a.IsValid());
|
||||
Assert(b != 0.0f);
|
||||
vec_t oob = 1.0f / b;
|
||||
c.x = a.x * oob;
|
||||
c.y = a.y * oob;
|
||||
}
|
||||
|
||||
inline void Vector2DDivide(const Vector2D& a, const Vector2D& b, Vector2D& c)
|
||||
{
|
||||
Assert(a.IsValid());
|
||||
Assert((b.x != 0.0f) && (b.y != 0.0f));
|
||||
c.x = a.x / b.x;
|
||||
c.y = a.y / b.y;
|
||||
}
|
||||
|
||||
inline void Vector2DMA(const Vector2D& start, float s, const Vector2D& dir, Vector2D& result)
|
||||
{
|
||||
Assert(start.IsValid() && IsFinite(s) && dir.IsValid());
|
||||
result.x = start.x + s * dir.x;
|
||||
result.y = start.y + s * dir.y;
|
||||
}
|
||||
|
||||
inline void Vector2D::MulAdd(const Vector2D& a, const Vector2D& b, float scalar)
|
||||
{
|
||||
x = a.x + b.x * scalar;
|
||||
y = a.y + b.y * scalar;
|
||||
}
|
||||
|
||||
inline void Vector2DLerp(const Vector2D& src1, const Vector2D& src2, vec_t t, Vector2D& dest)
|
||||
{
|
||||
dest[0] = src1[0] + (src2[0] - src1[0]) * t;
|
||||
dest[1] = src1[1] + (src2[1] - src1[1]) * t;
|
||||
}
|
||||
|
||||
inline vec_t DotProduct2D(const Vector2D& a, const Vector2D& b)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
return(a.x * b.x + a.y * b.y);
|
||||
}
|
||||
|
||||
inline vec_t Vector2D::Dot(const Vector2D& vOther) const
|
||||
{
|
||||
return DotProduct2D(*this, vOther);
|
||||
}
|
||||
|
||||
|
||||
inline vec_t Vector2DLength(const Vector2D& v)
|
||||
{
|
||||
Assert(v.IsValid());
|
||||
return (vec_t)FastSqrt(v.x * v.x + v.y * v.y);
|
||||
}
|
||||
|
||||
inline vec_t Vector2D::LengthSqr(void) const
|
||||
{
|
||||
Assert(IsValid());
|
||||
return (x * x + y * y);
|
||||
}
|
||||
|
||||
inline vec_t Vector2D::NormalizeInPlace()
|
||||
{
|
||||
return Vector2DNormalize(*this);
|
||||
}
|
||||
|
||||
inline bool Vector2D::IsLengthGreaterThan(float val) const
|
||||
{
|
||||
return LengthSqr() > val * val;
|
||||
}
|
||||
|
||||
inline bool Vector2D::IsLengthLessThan(float val) const
|
||||
{
|
||||
return LengthSqr() < val * val;
|
||||
}
|
||||
|
||||
inline vec_t Vector2D::Length(void) const
|
||||
{
|
||||
return Vector2DLength(*this);
|
||||
}
|
||||
|
||||
|
||||
inline void Vector2DMin(const Vector2D& a, const Vector2D& b, Vector2D& result)
|
||||
{
|
||||
result.x = (a.x < b.x) ? a.x : b.x;
|
||||
result.y = (a.y < b.y) ? a.y : b.y;
|
||||
}
|
||||
|
||||
|
||||
inline void Vector2DMax(const Vector2D& a, const Vector2D& b, Vector2D& result)
|
||||
{
|
||||
result.x = (a.x > b.x) ? a.x : b.x;
|
||||
result.y = (a.y > b.y) ? a.y : b.y;
|
||||
}
|
||||
|
||||
|
||||
inline vec_t Vector2DNormalize(Vector2D& v)
|
||||
{
|
||||
Assert(v.IsValid());
|
||||
vec_t l = v.Length();
|
||||
if (l != 0.0f)
|
||||
{
|
||||
v /= l;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.x = v.y = 0.0f;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
inline vec_t Vector2D::DistTo(const Vector2D& vOther) const
|
||||
{
|
||||
Vector2D delta;
|
||||
Vector2DSubtract(*this, vOther, delta);
|
||||
return delta.Length();
|
||||
}
|
||||
|
||||
inline vec_t Vector2D::DistToSqr(const Vector2D& vOther) const
|
||||
{
|
||||
Vector2D delta;
|
||||
Vector2DSubtract(*this, vOther, delta);
|
||||
return delta.LengthSqr();
|
||||
}
|
||||
|
||||
|
||||
inline void ComputeClosestPoint2D(const Vector2D& vecStart, float flMaxDist, const Vector2D& vecTarget, Vector2D* pResult)
|
||||
{
|
||||
Vector2D vecDelta;
|
||||
Vector2DSubtract(vecTarget, vecStart, vecDelta);
|
||||
float flDistSqr = vecDelta.LengthSqr();
|
||||
if (flDistSqr <= flMaxDist * flMaxDist)
|
||||
{
|
||||
*pResult = vecTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
vecDelta /= FastSqrt(flDistSqr);
|
||||
Vector2DMA(vecStart, flMaxDist, vecDelta, *pResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline Vector2D Vector2D::Min(const Vector2D& vOther) const
|
||||
{
|
||||
return Vector2D(x < vOther.x ? x : vOther.x,
|
||||
y < vOther.y ? y : vOther.y);
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::Max(const Vector2D& vOther) const
|
||||
{
|
||||
return Vector2D(x > vOther.x ? x : vOther.x,
|
||||
y > vOther.y ? y : vOther.y);
|
||||
}
|
||||
|
||||
|
||||
inline Vector2D Vector2D::operator-(void) const
|
||||
{
|
||||
return Vector2D(-x, -y);
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::operator+(const Vector2D& v) const
|
||||
{
|
||||
Vector2D res;
|
||||
Vector2DAdd(*this, v, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::operator-(const Vector2D& v) const
|
||||
{
|
||||
Vector2D res;
|
||||
Vector2DSubtract(*this, v, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::operator*(float fl) const
|
||||
{
|
||||
Vector2D res;
|
||||
Vector2DMultiply(*this, fl, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::operator*(const Vector2D& v) const
|
||||
{
|
||||
Vector2D res;
|
||||
Vector2DMultiply(*this, v, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::operator/(float fl) const
|
||||
{
|
||||
Vector2D res;
|
||||
Vector2DDivide(*this, fl, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2D Vector2D::operator/(const Vector2D& v) const
|
||||
{
|
||||
Vector2D res;
|
||||
Vector2DDivide(*this, v, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2D operator*(float fl, const Vector2D& v)
|
||||
{
|
||||
return v * fl;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
554
SpyCustom/sdk/vector4d.h
Normal file
554
SpyCustom/sdk/vector4d.h
Normal file
@ -0,0 +1,554 @@
|
||||
#ifndef VECTOR4D_H
|
||||
#define VECTOR4D_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <float.h>
|
||||
#if !defined( _X360 )
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
#include "basetypes.h"
|
||||
#include "dbg.h"
|
||||
#include "math_pfns.h"
|
||||
|
||||
class Vector;
|
||||
class Vector2D;
|
||||
|
||||
class Vector4D
|
||||
{
|
||||
public:
|
||||
vec_t x, y, z, w;
|
||||
|
||||
Vector4D(void);
|
||||
Vector4D(vec_t X, vec_t Y, vec_t Z, vec_t W);
|
||||
Vector4D(const float* pFloat);
|
||||
|
||||
void Init(vec_t ix = 0.0f, vec_t iy = 0.0f, vec_t iz = 0.0f, vec_t iw = 0.0f);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
vec_t operator[](int i) const;
|
||||
vec_t& operator[](int i);
|
||||
|
||||
inline vec_t* Base();
|
||||
inline vec_t const* Base() const;
|
||||
|
||||
Vector& AsVector3D();
|
||||
Vector const& AsVector3D() const;
|
||||
|
||||
Vector2D& AsVector2D();
|
||||
Vector2D const& AsVector2D() const;
|
||||
|
||||
void Random(vec_t minVal, vec_t maxVal);
|
||||
|
||||
bool operator==(const Vector4D& v) const;
|
||||
bool operator!=(const Vector4D& v) const;
|
||||
|
||||
Vector4D& operator+=(const Vector4D& v);
|
||||
Vector4D& operator-=(const Vector4D& v);
|
||||
Vector4D& operator*=(const Vector4D& v);
|
||||
Vector4D& operator*=(float s);
|
||||
Vector4D& operator/=(const Vector4D& v);
|
||||
Vector4D& operator/=(float s);
|
||||
|
||||
void Negate();
|
||||
|
||||
vec_t Length() const;
|
||||
|
||||
vec_t LengthSqr(void) const;
|
||||
|
||||
bool IsZero(float tolerance = 0.01f) const
|
||||
{
|
||||
return (x > -tolerance && x < tolerance&&
|
||||
y > -tolerance && y < tolerance&&
|
||||
z > -tolerance && z < tolerance&&
|
||||
w > -tolerance && w < tolerance);
|
||||
}
|
||||
|
||||
vec_t DistTo(const Vector4D& vOther) const;
|
||||
|
||||
vec_t DistToSqr(const Vector4D& vOther) const;
|
||||
|
||||
void CopyToArray(float* rgfl) const;
|
||||
|
||||
void MulAdd(Vector4D const& a, Vector4D const& b, float scalar);
|
||||
|
||||
vec_t Dot(Vector4D const& vOther) const;
|
||||
|
||||
#ifdef VECTOR_NO_SLOW_OPERATIONS
|
||||
private:
|
||||
#else
|
||||
public:
|
||||
#endif
|
||||
Vector4D(Vector4D const& vOther);
|
||||
|
||||
Vector4D& operator=(Vector4D const& src);
|
||||
};
|
||||
|
||||
const Vector4D vec4_origin(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
const Vector4D vec4_invalid(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX);
|
||||
|
||||
class ALIGN16 Vector4DAligned : public Vector4D
|
||||
{
|
||||
public:
|
||||
Vector4DAligned(void) {}
|
||||
Vector4DAligned(vec_t X, vec_t Y, vec_t Z, vec_t W);
|
||||
|
||||
inline void Set(vec_t X, vec_t Y, vec_t Z, vec_t W);
|
||||
inline void InitZero(void);
|
||||
|
||||
inline __m128& AsM128() { return *(__m128*) & x; }
|
||||
inline const __m128& AsM128() const { return *(const __m128*) & x; }
|
||||
|
||||
private:
|
||||
Vector4DAligned(Vector4DAligned const& vOther);
|
||||
|
||||
Vector4DAligned& operator=(Vector4DAligned const& src);
|
||||
} ALIGN16_POST;
|
||||
|
||||
void Vector4DClear(Vector4D& a);
|
||||
|
||||
void Vector4DCopy(Vector4D const& src, Vector4D& dst);
|
||||
|
||||
void Vector4DAdd(Vector4D const& a, Vector4D const& b, Vector4D& result);
|
||||
void Vector4DSubtract(Vector4D const& a, Vector4D const& b, Vector4D& result);
|
||||
void Vector4DMultiply(Vector4D const& a, vec_t b, Vector4D& result);
|
||||
void Vector4DMultiply(Vector4D const& a, Vector4D const& b, Vector4D& result);
|
||||
void Vector4DDivide(Vector4D const& a, vec_t b, Vector4D& result);
|
||||
void Vector4DDivide(Vector4D const& a, Vector4D const& b, Vector4D& result);
|
||||
void Vector4DMA(Vector4D const& start, float s, Vector4D const& dir, Vector4D& result);
|
||||
|
||||
void Vector4DMultiplyAligned(Vector4DAligned const& a, vec_t b, Vector4DAligned& result);
|
||||
|
||||
|
||||
#define Vector4DExpand( v ) (v).x, (v).y, (v).z, (v).w
|
||||
|
||||
vec_t Vector4DNormalize(Vector4D& v);
|
||||
|
||||
vec_t Vector4DLength(Vector4D const& v);
|
||||
|
||||
vec_t DotProduct4D(Vector4D const& a, Vector4D const& b);
|
||||
|
||||
void Vector4DLerp(Vector4D const& src1, Vector4D const& src2, vec_t t, Vector4D& dest);
|
||||
|
||||
|
||||
|
||||
inline Vector4D::Vector4D(void)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
x = y = z = w = VEC_T_NAN;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline Vector4D::Vector4D(vec_t X, vec_t Y, vec_t Z, vec_t W)
|
||||
{
|
||||
x = X; y = Y; z = Z; w = W;
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline Vector4D::Vector4D(const float* pFloat)
|
||||
{
|
||||
Assert(pFloat);
|
||||
x = pFloat[0]; y = pFloat[1]; z = pFloat[2]; w = pFloat[3];
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
|
||||
inline Vector4D::Vector4D(const Vector4D& vOther)
|
||||
{
|
||||
Assert(vOther.IsValid());
|
||||
x = vOther.x; y = vOther.y; z = vOther.z; w = vOther.w;
|
||||
}
|
||||
|
||||
inline void Vector4D::Init(vec_t ix, vec_t iy, vec_t iz, vec_t iw)
|
||||
{
|
||||
x = ix; y = iy; z = iz; w = iw;
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline void Vector4D::Random(vec_t minVal, vec_t maxVal)
|
||||
{
|
||||
x = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
|
||||
y = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
|
||||
z = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
|
||||
w = minVal + ((vec_t)rand() / VALVE_RAND_MAX) * (maxVal - minVal);
|
||||
}
|
||||
|
||||
inline void Vector4DClear(Vector4D& a)
|
||||
{
|
||||
a.x = a.y = a.z = a.w = 0.0f;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator=(const Vector4D& vOther)
|
||||
{
|
||||
Assert(vOther.IsValid());
|
||||
x = vOther.x; y = vOther.y; z = vOther.z; w = vOther.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline vec_t& Vector4D::operator[](int i)
|
||||
{
|
||||
Assert((i >= 0) && (i < 4));
|
||||
return ((vec_t*)this)[i];
|
||||
}
|
||||
|
||||
inline vec_t Vector4D::operator[](int i) const
|
||||
{
|
||||
Assert((i >= 0) && (i < 4));
|
||||
return ((vec_t*)this)[i];
|
||||
}
|
||||
|
||||
inline Vector& Vector4D::AsVector3D()
|
||||
{
|
||||
return *(Vector*)this;
|
||||
}
|
||||
|
||||
inline Vector const& Vector4D::AsVector3D() const
|
||||
{
|
||||
return *(Vector const*)this;
|
||||
}
|
||||
|
||||
inline Vector2D& Vector4D::AsVector2D()
|
||||
{
|
||||
return *(Vector2D*)this;
|
||||
}
|
||||
|
||||
inline Vector2D const& Vector4D::AsVector2D() const
|
||||
{
|
||||
return *(Vector2D const*)this;
|
||||
}
|
||||
|
||||
inline vec_t* Vector4D::Base()
|
||||
{
|
||||
return (vec_t*)this;
|
||||
}
|
||||
|
||||
inline vec_t const* Vector4D::Base() const
|
||||
{
|
||||
return (vec_t const*)this;
|
||||
}
|
||||
|
||||
inline bool Vector4D::IsValid() const
|
||||
{
|
||||
return IsFinite(x) && IsFinite(y) && IsFinite(z) && IsFinite(w);
|
||||
}
|
||||
|
||||
inline bool Vector4D::operator==(Vector4D const& src) const
|
||||
{
|
||||
Assert(src.IsValid() && IsValid());
|
||||
return (src.x == x) && (src.y == y) && (src.z == z) && (src.w == w);
|
||||
}
|
||||
|
||||
inline bool Vector4D::operator!=(Vector4D const& src) const
|
||||
{
|
||||
Assert(src.IsValid() && IsValid());
|
||||
return (src.x != x) || (src.y != y) || (src.z != z) || (src.w != w);
|
||||
}
|
||||
|
||||
|
||||
inline void Vector4DCopy(Vector4D const& src, Vector4D& dst)
|
||||
{
|
||||
Assert(src.IsValid());
|
||||
dst.x = src.x;
|
||||
dst.y = src.y;
|
||||
dst.z = src.z;
|
||||
dst.w = src.w;
|
||||
}
|
||||
|
||||
inline void Vector4D::CopyToArray(float* rgfl) const
|
||||
{
|
||||
Assert(IsValid());
|
||||
Assert(rgfl);
|
||||
rgfl[0] = x; rgfl[1] = y; rgfl[2] = z; rgfl[3] = w;
|
||||
}
|
||||
|
||||
inline void Vector4D::Negate()
|
||||
{
|
||||
Assert(IsValid());
|
||||
x = -x; y = -y; z = -z; w = -w;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator+=(const Vector4D& v)
|
||||
{
|
||||
Assert(IsValid() && v.IsValid());
|
||||
x += v.x; y += v.y; z += v.z; w += v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator-=(const Vector4D& v)
|
||||
{
|
||||
Assert(IsValid() && v.IsValid());
|
||||
x -= v.x; y -= v.y; z -= v.z; w -= v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator*=(float fl)
|
||||
{
|
||||
x *= fl;
|
||||
y *= fl;
|
||||
z *= fl;
|
||||
w *= fl;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator*=(Vector4D const& v)
|
||||
{
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
w *= v.w;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator/=(float fl)
|
||||
{
|
||||
Assert(fl != 0.0f);
|
||||
float oofl = 1.0f / fl;
|
||||
x *= oofl;
|
||||
y *= oofl;
|
||||
z *= oofl;
|
||||
w *= oofl;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector4D& Vector4D::operator/=(Vector4D const& v)
|
||||
{
|
||||
Assert(v.x != 0.0f && v.y != 0.0f && v.z != 0.0f && v.w != 0.0f);
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
z /= v.z;
|
||||
w /= v.w;
|
||||
Assert(IsValid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Vector4DAdd(Vector4D const& a, Vector4D const& b, Vector4D& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
c.x = a.x + b.x;
|
||||
c.y = a.y + b.y;
|
||||
c.z = a.z + b.z;
|
||||
c.w = a.w + b.w;
|
||||
}
|
||||
|
||||
inline void Vector4DSubtract(Vector4D const& a, Vector4D const& b, Vector4D& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
c.x = a.x - b.x;
|
||||
c.y = a.y - b.y;
|
||||
c.z = a.z - b.z;
|
||||
c.w = a.w - b.w;
|
||||
}
|
||||
|
||||
inline void Vector4DMultiply(Vector4D const& a, vec_t b, Vector4D& c)
|
||||
{
|
||||
Assert(a.IsValid() && IsFinite(b));
|
||||
c.x = a.x * b;
|
||||
c.y = a.y * b;
|
||||
c.z = a.z * b;
|
||||
c.w = a.w * b;
|
||||
}
|
||||
|
||||
inline void Vector4DMultiply(Vector4D const& a, Vector4D const& b, Vector4D& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
c.x = a.x * b.x;
|
||||
c.y = a.y * b.y;
|
||||
c.z = a.z * b.z;
|
||||
c.w = a.w * b.w;
|
||||
}
|
||||
|
||||
inline void Vector4DDivide(Vector4D const& a, vec_t b, Vector4D& c)
|
||||
{
|
||||
Assert(a.IsValid());
|
||||
Assert(b != 0.0f);
|
||||
vec_t oob = 1.0f / b;
|
||||
c.x = a.x * oob;
|
||||
c.y = a.y * oob;
|
||||
c.z = a.z * oob;
|
||||
c.w = a.w * oob;
|
||||
}
|
||||
|
||||
inline void Vector4DDivide(Vector4D const& a, Vector4D const& b, Vector4D& c)
|
||||
{
|
||||
Assert(a.IsValid());
|
||||
Assert((b.x != 0.0f) && (b.y != 0.0f) && (b.z != 0.0f) && (b.w != 0.0f));
|
||||
c.x = a.x / b.x;
|
||||
c.y = a.y / b.y;
|
||||
c.z = a.z / b.z;
|
||||
c.w = a.w / b.w;
|
||||
}
|
||||
|
||||
inline void Vector4DMA(Vector4D const& start, float s, Vector4D const& dir, Vector4D& result)
|
||||
{
|
||||
Assert(start.IsValid() && IsFinite(s) && dir.IsValid());
|
||||
result.x = start.x + s * dir.x;
|
||||
result.y = start.y + s * dir.y;
|
||||
result.z = start.z + s * dir.z;
|
||||
result.w = start.w + s * dir.w;
|
||||
}
|
||||
|
||||
inline void Vector4D::MulAdd(Vector4D const& a, Vector4D const& b, float scalar)
|
||||
{
|
||||
x = a.x + b.x * scalar;
|
||||
y = a.y + b.y * scalar;
|
||||
z = a.z + b.z * scalar;
|
||||
w = a.w + b.w * scalar;
|
||||
}
|
||||
|
||||
inline void Vector4DLerp(const Vector4D& src1, const Vector4D& src2, vec_t t, Vector4D& dest)
|
||||
{
|
||||
dest[0] = src1[0] + (src2[0] - src1[0]) * t;
|
||||
dest[1] = src1[1] + (src2[1] - src1[1]) * t;
|
||||
dest[2] = src1[2] + (src2[2] - src1[2]) * t;
|
||||
dest[3] = src1[3] + (src2[3] - src1[3]) * t;
|
||||
}
|
||||
|
||||
inline vec_t DotProduct4D(const Vector4D& a, const Vector4D& b)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
|
||||
}
|
||||
|
||||
inline vec_t Vector4D::Dot(Vector4D const& vOther) const
|
||||
{
|
||||
return DotProduct4D(*this, vOther);
|
||||
}
|
||||
|
||||
|
||||
inline vec_t Vector4DLength(Vector4D const& v)
|
||||
{
|
||||
Assert(v.IsValid());
|
||||
return (vec_t)FastSqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
|
||||
}
|
||||
|
||||
inline vec_t Vector4D::LengthSqr(void) const
|
||||
{
|
||||
Assert(IsValid());
|
||||
return (x * x + y * y + z * z + w * w);
|
||||
}
|
||||
|
||||
inline vec_t Vector4D::Length(void) const
|
||||
{
|
||||
return Vector4DLength(*this);
|
||||
}
|
||||
|
||||
|
||||
inline vec_t Vector4DNormalize(Vector4D& v)
|
||||
{
|
||||
Assert(v.IsValid());
|
||||
vec_t l = v.Length();
|
||||
if (l != 0.0f)
|
||||
{
|
||||
v /= l;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.x = v.y = v.z = v.w = 0.0f;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
inline vec_t Vector4D::DistTo(const Vector4D& vOther) const
|
||||
{
|
||||
Vector4D delta;
|
||||
Vector4DSubtract(*this, vOther, delta);
|
||||
return delta.Length();
|
||||
}
|
||||
|
||||
inline vec_t Vector4D::DistToSqr(const Vector4D& vOther) const
|
||||
{
|
||||
Vector4D delta;
|
||||
Vector4DSubtract(*this, vOther, delta);
|
||||
return delta.LengthSqr();
|
||||
}
|
||||
|
||||
|
||||
inline Vector4DAligned::Vector4DAligned(vec_t X, vec_t Y, vec_t Z, vec_t W)
|
||||
{
|
||||
x = X; y = Y; z = Z; w = W;
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline void Vector4DAligned::Set(vec_t X, vec_t Y, vec_t Z, vec_t W)
|
||||
{
|
||||
x = X; y = Y; z = Z; w = W;
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline void Vector4DAligned::InitZero(void)
|
||||
{
|
||||
#if !defined( _X360 )
|
||||
this->AsM128() = _mm_set1_ps(0.0f);
|
||||
#else
|
||||
this->AsM128() = __vspltisw(0);
|
||||
#endif
|
||||
Assert(IsValid());
|
||||
}
|
||||
|
||||
inline void Vector4DMultiplyAligned(Vector4DAligned const& a, Vector4DAligned const& b, Vector4DAligned& c)
|
||||
{
|
||||
Assert(a.IsValid() && b.IsValid());
|
||||
#if !defined( _X360 )
|
||||
c.x = a.x * b.x;
|
||||
c.y = a.y * b.y;
|
||||
c.z = a.z * b.z;
|
||||
c.w = a.w * b.w;
|
||||
#else
|
||||
c.AsM128() = __vmulfp(a.AsM128(), b.AsM128());
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Vector4DWeightMAD(vec_t w, Vector4DAligned const& vInA, Vector4DAligned& vOutA, Vector4DAligned const& vInB, Vector4DAligned& vOutB)
|
||||
{
|
||||
Assert(vInA.IsValid() && vInB.IsValid() && IsFinite(w));
|
||||
|
||||
#if !defined( _X360 )
|
||||
vOutA.x += vInA.x * w;
|
||||
vOutA.y += vInA.y * w;
|
||||
vOutA.z += vInA.z * w;
|
||||
vOutA.w += vInA.w * w;
|
||||
|
||||
vOutB.x += vInB.x * w;
|
||||
vOutB.y += vInB.y * w;
|
||||
vOutB.z += vInB.z * w;
|
||||
vOutB.w += vInB.w * w;
|
||||
#else
|
||||
__vector4 temp;
|
||||
|
||||
temp = __lvlx(&w, 0);
|
||||
temp = __vspltw(temp, 0);
|
||||
|
||||
vOutA.AsM128() = __vmaddfp(vInA.AsM128(), temp, vOutA.AsM128());
|
||||
vOutB.AsM128() = __vmaddfp(vInB.AsM128(), temp, vOutB.AsM128());
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Vector4DWeightMADSSE(vec_t w, Vector4DAligned const& vInA, Vector4DAligned& vOutA, Vector4DAligned const& vInB, Vector4DAligned& vOutB)
|
||||
{
|
||||
Assert(vInA.IsValid() && vInB.IsValid() && IsFinite(w));
|
||||
|
||||
#if !defined( _X360 )
|
||||
__m128 packed = _mm_set1_ps(w);
|
||||
|
||||
vOutA.AsM128() = _mm_add_ps(vOutA.AsM128(), _mm_mul_ps(vInA.AsM128(), packed));
|
||||
vOutB.AsM128() = _mm_add_ps(vOutB.AsM128(), _mm_mul_ps(vInB.AsM128(), packed));
|
||||
#else
|
||||
__vector4 temp;
|
||||
|
||||
temp = __lvlx(&w, 0);
|
||||
temp = __vspltw(temp, 0);
|
||||
|
||||
vOutA.AsM128() = __vmaddfp(vInA.AsM128(), temp, vOutA.AsM128());
|
||||
vOutB.AsM128() = __vmaddfp(vInB.AsM128(), temp, vOutB.AsM128());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
89
SpyCustom/sdk/vertexcolor.h
Normal file
89
SpyCustom/sdk/vertexcolor.h
Normal file
@ -0,0 +1,89 @@
|
||||
#ifndef VERTEXCOLOR_H
|
||||
#define VERTEXCOLOR_H
|
||||
|
||||
#ifdef COMPILER_MSVC
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
struct VertexColor_t
|
||||
{
|
||||
VertexColor_t() {};
|
||||
VertexColor_t(const VertexColor_t& src);
|
||||
VertexColor_t(uint8 ir, uint8 ig, uint8 ib, uint8 ia);
|
||||
|
||||
uint32 AsUint32() const;
|
||||
uint32* AsUint32Ptr();
|
||||
const uint32* AsUint32Ptr() const;
|
||||
|
||||
VertexColor_t& operator=(const VertexColor_t& src);
|
||||
VertexColor_t& operator=(const color32& src);
|
||||
|
||||
bool operator==(const VertexColor_t& src) const;
|
||||
bool operator!=(const VertexColor_t& src) const;
|
||||
|
||||
#ifdef PLATFORM_X360
|
||||
uint8 a, b, g, r;
|
||||
#else
|
||||
uint8 r, g, b, a;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
inline VertexColor_t::VertexColor_t(const VertexColor_t& src)
|
||||
{
|
||||
*AsUint32Ptr() = src.AsUint32();
|
||||
}
|
||||
|
||||
inline VertexColor_t::VertexColor_t(uint8 ir, uint8 ig, uint8 ib, uint8 ia) : r(ir), g(ig), b(ib), a(ia)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline uint32 VertexColor_t::AsUint32() const
|
||||
{
|
||||
return *reinterpret_cast<const uint32*>(this);
|
||||
}
|
||||
|
||||
inline uint32* VertexColor_t::AsUint32Ptr()
|
||||
{
|
||||
return reinterpret_cast<uint32*>(this);
|
||||
}
|
||||
|
||||
inline const uint32* VertexColor_t::AsUint32Ptr() const
|
||||
{
|
||||
return reinterpret_cast<const uint32*>(this);
|
||||
}
|
||||
|
||||
|
||||
inline VertexColor_t& VertexColor_t::operator=(const VertexColor_t& src)
|
||||
{
|
||||
*AsUint32Ptr() = src.AsUint32();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline VertexColor_t& VertexColor_t::operator=(const color32& src)
|
||||
{
|
||||
r = src.r;
|
||||
g = src.g;
|
||||
b = src.b;
|
||||
a = src.a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline bool VertexColor_t::operator==(const VertexColor_t& src) const
|
||||
{
|
||||
return AsUint32() == src.AsUint32();
|
||||
}
|
||||
|
||||
inline bool VertexColor_t::operator!=(const VertexColor_t& src) const
|
||||
{
|
||||
return AsUint32() != src.AsUint32();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
62
SpyCustom/sdk/vgui_basepanel.h
Normal file
62
SpyCustom/sdk/vgui_basepanel.h
Normal file
@ -0,0 +1,62 @@
|
||||
#if !defined( VGUI_BASEPANEL_H )
|
||||
#define VGUI_BASEPANEL_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "Panel.h"
|
||||
#include "Label.h"
|
||||
#include "Controls.h"
|
||||
#include "ISurface.h"
|
||||
|
||||
class CBasePanel : public vgui::Panel
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS_GAMEROOT(CBasePanel, vgui::Panel);
|
||||
|
||||
CBasePanel(vgui::Panel* pParent, const char* panelName);
|
||||
CBasePanel(vgui::Panel* pParent, const char* panelName, int x, int y, int w, int h);
|
||||
virtual ~CBasePanel(void);
|
||||
|
||||
virtual bool ShouldDraw(void) { return true; }
|
||||
|
||||
virtual void PaintBackground(void);
|
||||
|
||||
virtual void SetTexture(const char* texname, bool tiled = false);
|
||||
|
||||
virtual void SetReflectMouse(bool reflect);
|
||||
virtual void OnCursorMoved(int x, int y);
|
||||
virtual void OnMousePressed(vgui::MouseCode code);
|
||||
virtual void OnMouseDoublePressed(vgui::MouseCode code);
|
||||
virtual void OnMouseReleased(vgui::MouseCode code);
|
||||
virtual void OnMouseWheeled(int delta);
|
||||
|
||||
virtual void OnTick(void);
|
||||
|
||||
protected:
|
||||
bool m_bTexturedBackground;
|
||||
int m_nBackgroundMaterial;
|
||||
char m_szBgTexture[256];
|
||||
bool m_bTiled;
|
||||
int m_nTextureSize[2];
|
||||
|
||||
bool m_bReflectMouse;
|
||||
};
|
||||
|
||||
class CHudLabel : public vgui::Label
|
||||
{
|
||||
typedef vgui::Label BaseClass;
|
||||
public:
|
||||
CHudLabel(vgui::Panel* parent, const char* panelName, const char* text);
|
||||
virtual void ApplySchemeSettings(vgui::IScheme* pScheme);
|
||||
|
||||
void SetSelected(bool bSelected);
|
||||
|
||||
bool m_bSelected;
|
||||
|
||||
private:
|
||||
CHudLabel(const CHudLabel&);
|
||||
};
|
||||
|
||||
#endif
|
95
SpyCustom/sdk/view_shared.h
Normal file
95
SpyCustom/sdk/view_shared.h
Normal file
@ -0,0 +1,95 @@
|
||||
#ifndef VIEW_SHARED_H
|
||||
#define VIEW_SHARED_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "convar.h"
|
||||
#include "vector.h"
|
||||
#include "MaterialSystemUtil.h"
|
||||
|
||||
|
||||
enum ClearFlags_t
|
||||
{
|
||||
VIEW_CLEAR_COLOR = 0x1,
|
||||
VIEW_CLEAR_DEPTH = 0x2,
|
||||
VIEW_CLEAR_FULL_TARGET = 0x4,
|
||||
VIEW_NO_DRAW = 0x8,
|
||||
VIEW_CLEAR_OBEY_STENCIL = 0x10,
|
||||
VIEW_CLEAR_STENCIL = 0x20,
|
||||
};
|
||||
|
||||
enum StereoEye_t
|
||||
{
|
||||
STEREO_EYE_MONO = 0,
|
||||
STEREO_EYE_LEFT = 1,
|
||||
STEREO_EYE_RIGHT = 2,
|
||||
STEREO_EYE_MAX = 3,
|
||||
};
|
||||
|
||||
|
||||
class CViewSetup
|
||||
{
|
||||
public:
|
||||
CViewSetup()
|
||||
{
|
||||
m_flAspectRatio = 0.0f;
|
||||
m_bRenderToSubrectOfLargerScreen = false;
|
||||
m_bDoBloomAndToneMapping = true;
|
||||
m_bOrtho = false;
|
||||
m_bOffCenter = false;
|
||||
m_bCacheFullSceneState = false;
|
||||
m_bViewToProjectionOverride = false;
|
||||
m_eStereoEye = STEREO_EYE_MONO;
|
||||
}
|
||||
|
||||
int x;
|
||||
int m_nUnscaledX;
|
||||
int y;
|
||||
int m_nUnscaledY;
|
||||
int width;
|
||||
int m_nUnscaledWidth;
|
||||
int height;
|
||||
StereoEye_t m_eStereoEye;
|
||||
int m_nUnscaledHeight;
|
||||
|
||||
bool m_bOrtho;
|
||||
float m_OrthoLeft;
|
||||
float m_OrthoTop;
|
||||
float m_OrthoRight;
|
||||
float m_OrthoBottom;
|
||||
|
||||
float fov;
|
||||
float fovViewmodel;
|
||||
|
||||
Vector origin;
|
||||
|
||||
QAngle angles;
|
||||
float zNear;
|
||||
float zFar;
|
||||
|
||||
float zNearViewmodel;
|
||||
float zFarViewmodel;
|
||||
|
||||
bool m_bRenderToSubrectOfLargerScreen;
|
||||
|
||||
float m_flAspectRatio;
|
||||
|
||||
bool m_bOffCenter;
|
||||
float m_flOffCenterTop;
|
||||
float m_flOffCenterBottom;
|
||||
float m_flOffCenterLeft;
|
||||
float m_flOffCenterRight;
|
||||
|
||||
bool m_bDoBloomAndToneMapping;
|
||||
|
||||
bool m_bCacheFullSceneState;
|
||||
|
||||
bool m_bViewToProjectionOverride;
|
||||
VMatrix m_ViewToProjection;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
724
SpyCustom/sdk/viewrender.h
Normal file
724
SpyCustom/sdk/viewrender.h
Normal file
@ -0,0 +1,724 @@
|
||||
#if !defined( VIEWRENDER_H )
|
||||
#define VIEWRENDER_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shareddefs.h"
|
||||
#include "utlstack.h"
|
||||
#include "tier2.h"
|
||||
#include "iviewrender.h"
|
||||
#include "ivrenderview.h"
|
||||
#include "view_shared.h"
|
||||
|
||||
#if defined(_PS3)
|
||||
#include "buildrenderables_ps3.h"
|
||||
#endif
|
||||
#include "volumeculler.h"
|
||||
#include "jobthread.h"
|
||||
|
||||
#include "bspfile.h"
|
||||
#include "const.h"
|
||||
|
||||
class ConVar;
|
||||
class CClientRenderablesList;
|
||||
class IClientVehicle;
|
||||
class C_PointCamera;
|
||||
class C_EnvProjectedTexture;
|
||||
class IScreenSpaceEffect;
|
||||
class CClientViewSetup;
|
||||
class CViewRender;
|
||||
struct ClientWorldListInfo_t;
|
||||
class C_BaseEntity;
|
||||
class CJob;
|
||||
|
||||
#ifdef HL2_EPISODIC
|
||||
class CStunEffect;
|
||||
#endif
|
||||
|
||||
struct IntroDataBlendPass_t
|
||||
{
|
||||
int m_BlendMode;
|
||||
float m_Alpha;
|
||||
};
|
||||
|
||||
struct IntroData_t
|
||||
{
|
||||
bool m_bDrawPrimary;
|
||||
Vector m_vecCameraView;
|
||||
QAngle m_vecCameraViewAngles;
|
||||
float m_playerViewFOV;
|
||||
CUtlVector<IntroDataBlendPass_t> m_Passes;
|
||||
|
||||
float m_flCurrentFadeColor[4];
|
||||
};
|
||||
|
||||
extern IntroData_t* g_pIntroData;
|
||||
|
||||
enum view_id_t
|
||||
{
|
||||
VIEW_ILLEGAL = -2,
|
||||
VIEW_NONE = -1,
|
||||
VIEW_MAIN = 0,
|
||||
VIEW_3DSKY = 1,
|
||||
VIEW_MONITOR = 2,
|
||||
VIEW_REFLECTION = 3,
|
||||
VIEW_REFRACTION = 4,
|
||||
VIEW_INTRO_PLAYER = 5,
|
||||
VIEW_INTRO_CAMERA = 6,
|
||||
VIEW_SHADOW_DEPTH_TEXTURE = 7,
|
||||
VIEW_SSAO = 8,
|
||||
VIEW_ID_COUNT
|
||||
};
|
||||
view_id_t CurrentViewID();
|
||||
|
||||
#if defined(_PS3)
|
||||
#define PASS_BUILDLISTS_PS3 (1<<0)
|
||||
#define PASS_DRAWLISTS_PS3 (1<<1)
|
||||
#else
|
||||
#define PASS_BUILDLISTS (1<<0)
|
||||
#define PASS_DRAWLISTS (1<<1)
|
||||
#endif
|
||||
|
||||
class CPitchDrift
|
||||
{
|
||||
public:
|
||||
float pitchvel;
|
||||
bool nodrift;
|
||||
float driftmove;
|
||||
double laststop;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct ViewCustomVisibility_t
|
||||
{
|
||||
ViewCustomVisibility_t()
|
||||
{
|
||||
m_nNumVisOrigins = 0;
|
||||
m_VisData.m_fDistToAreaPortalTolerance = FLT_MAX;
|
||||
m_iForceViewLeaf = -1;
|
||||
}
|
||||
|
||||
void AddVisOrigin(const Vector& origin)
|
||||
{
|
||||
AssertMsg(m_nNumVisOrigins < MAX_VIS_LEAVES, "Added more origins than will fit in the array!");
|
||||
|
||||
if (m_nNumVisOrigins >= MAX_VIS_LEAVES)
|
||||
return;
|
||||
|
||||
m_rgVisOrigins[m_nNumVisOrigins++] = origin;
|
||||
}
|
||||
|
||||
void ForceVisOverride(VisOverrideData_t& visData)
|
||||
{
|
||||
m_VisData = visData;
|
||||
}
|
||||
|
||||
void ForceViewLeaf(int iViewLeaf)
|
||||
{
|
||||
m_iForceViewLeaf = iViewLeaf;
|
||||
}
|
||||
|
||||
int m_nNumVisOrigins;
|
||||
Vector m_rgVisOrigins[MAX_VIS_LEAVES];
|
||||
|
||||
VisOverrideData_t m_VisData;
|
||||
|
||||
int m_iForceViewLeaf;
|
||||
};
|
||||
|
||||
struct WaterRenderInfo_t
|
||||
{
|
||||
bool m_bCheapWater : 1;
|
||||
bool m_bReflect : 1;
|
||||
bool m_bRefract : 1;
|
||||
bool m_bReflectEntities : 1;
|
||||
bool m_bReflectOnlyMarkedEntities : 1;
|
||||
bool m_bDrawWaterSurface : 1;
|
||||
bool m_bOpaqueWater : 1;
|
||||
bool m_bPseudoTranslucentWater : 1;
|
||||
bool m_bReflect2DSkybox : 1;
|
||||
};
|
||||
|
||||
class CBase3dView : public CRefCounted<>,
|
||||
protected CViewSetup
|
||||
{
|
||||
DECLARE_CLASS_NOBASE(CBase3dView);
|
||||
public:
|
||||
explicit CBase3dView(CViewRender* pMainView);
|
||||
|
||||
VPlane* GetFrustum();
|
||||
virtual int GetDrawFlags() { return 0; }
|
||||
|
||||
#ifdef PORTAL
|
||||
virtual void EnableWorldFog() {};
|
||||
#endif
|
||||
|
||||
protected:
|
||||
VPlane* m_Frustum;
|
||||
CViewRender* m_pMainView;
|
||||
int m_nSlot;
|
||||
};
|
||||
|
||||
struct FrustumCache_t
|
||||
{
|
||||
int m_nFrameCount;
|
||||
Frustum_t m_Frustums[MAX_SPLITSCREEN_PLAYERS];
|
||||
|
||||
FrustumCache_t() { m_nFrameCount = 0; }
|
||||
|
||||
bool IsValid(void);
|
||||
void SetUpdated(void);
|
||||
|
||||
void Add(const CViewSetup* pView, int iSlot);
|
||||
};
|
||||
|
||||
FrustumCache_t* FrustumCache(void);
|
||||
|
||||
class CRendering3dView : public CBase3dView
|
||||
{
|
||||
DECLARE_CLASS(CRendering3dView, CBase3dView);
|
||||
public:
|
||||
explicit CRendering3dView(CViewRender* pMainView);
|
||||
virtual ~CRendering3dView() { ReleaseLists(); }
|
||||
|
||||
void Setup(const CViewSetup& setup);
|
||||
|
||||
virtual int GetDrawFlags();
|
||||
virtual void Draw() {};
|
||||
|
||||
protected:
|
||||
|
||||
void EnableWorldFog(void);
|
||||
void SetFogVolumeState(const VisibleFogVolumeInfo_t& fogInfo, bool bUseHeightFog);
|
||||
|
||||
void SetupRenderablesList(int viewID, bool bFastEntityRendering = false, bool bDrawDepthViewNonCachedObjectsOnly = false);
|
||||
|
||||
void BuildWorldRenderLists(bool bDrawEntities, int iForceViewLeaf = -1, bool bUseCacheIfEnabled = true, bool bShadowDepth = false, float* pReflectionWaterHeight = NULL);
|
||||
|
||||
#if defined(_PS3)
|
||||
void SetupRenderablesList_PS3_Epilogue(void);
|
||||
|
||||
void BuildWorldRenderLists_PS3_Epilogue(bool bShadowDepth);
|
||||
void BuildRenderableRenderLists_PS3_Epilogue(void);
|
||||
#else
|
||||
void BuildWorldRenderLists_Epilogue(bool bShadowDepth);
|
||||
void BuildRenderableRenderLists_Epilogue(int viewID);
|
||||
#endif
|
||||
|
||||
void BuildRenderableRenderLists(int viewID, bool bFastEntityRendering = false, bool bDrawDepthViewNonCachedObjectsOnly = false);
|
||||
|
||||
void BuildShadowDepthRenderableRenderLists();
|
||||
|
||||
void DrawWorld(IMatRenderContext* pRenderContext, float waterZAdjust);
|
||||
|
||||
enum RenderablesRenderPath_t
|
||||
{
|
||||
RENDERABLES_RENDER_PATH_NORMAL = 0,
|
||||
RENDERABLES_RENDER_PATH_SHADOWDEPTH_DEFAULT = (1 << 0),
|
||||
RENDERABLES_RENDER_PATH_SHADOWDEPTH_BUILD_GEOCACHE = (1 << 1),
|
||||
RENDERABLES_RENDER_PATH_SHADOWDEPTH_USE_GEOCACHE = (1 << 2),
|
||||
};
|
||||
void DrawOpaqueRenderables(IMatRenderContext* pRenderContext, RenderablesRenderPath_t eRenderPath, ERenderDepthMode_t DepthMode, CUtlVector< CClientRenderablesList::CEntry* >* pDeferClippedOpaqueRenderables_Out, RenderGroup_t nGroup = RENDER_GROUP_OPAQUE);
|
||||
void DrawDeferredClippedOpaqueRenderables(IMatRenderContext* pRenderContext, RenderablesRenderPath_t eRenderPath, ERenderDepthMode_t DepthMode, CUtlVector< CClientRenderablesList::CEntry* >* pDeferClippedOpaqueRenderables);
|
||||
void DrawTranslucentRenderables(bool bInSkybox, bool bShadowDepth);
|
||||
|
||||
#if defined( PORTAL )
|
||||
void DrawRecursivePortalViews(void);
|
||||
#endif
|
||||
|
||||
void DrawTranslucentRenderablesNoWorld(bool bInSkybox);
|
||||
|
||||
void DrawNoZBufferTranslucentRenderables(void);
|
||||
|
||||
void DrawTranslucentWorldInLeaves(IMatRenderContext* pRenderContext, bool bShadowDepth);
|
||||
|
||||
void DrawTranslucentWorldAndDetailPropsInLeaves(IMatRenderContext* pRenderContext, int iCurLeaf, int iFinalLeaf, int nEngineDrawFlags, int& nDetailLeafCount, LeafIndex_t* pDetailLeafList, bool bShadowDepth);
|
||||
|
||||
void PruneWorldListInfo();
|
||||
|
||||
void BeginConsoleZPass();
|
||||
void EndConsoleZPass();
|
||||
|
||||
|
||||
#ifdef PORTAL
|
||||
virtual bool ShouldDrawPortals() { return true; }
|
||||
#endif
|
||||
|
||||
void ReleaseLists();
|
||||
|
||||
int m_DrawFlags;
|
||||
int m_ClearFlags;
|
||||
|
||||
|
||||
IWorldRenderList* m_pWorldRenderList;
|
||||
|
||||
#if defined( CSTRIKE15 ) && defined(_PS3)
|
||||
CClientRenderablesList* m_pRenderablesList[MAX_CONCURRENT_BUILDVIEWS];
|
||||
ClientWorldListInfo_t* m_pWorldListInfo[MAX_CONCURRENT_BUILDVIEWS];
|
||||
#else
|
||||
CClientRenderablesList* m_pRenderables;
|
||||
ClientWorldListInfo_t* m_pWorldListInfo;
|
||||
#endif
|
||||
|
||||
ViewCustomVisibility_t* m_pCustomVisibility;
|
||||
};
|
||||
|
||||
|
||||
class CRenderExecutor
|
||||
{
|
||||
DECLARE_CLASS_NOBASE(CRenderExecutor);
|
||||
public:
|
||||
|
||||
virtual void AddView(CRendering3dView* pView) = 0;
|
||||
|
||||
virtual void Execute() = 0;
|
||||
|
||||
protected:
|
||||
explicit CRenderExecutor(CViewRender* pMainView) : m_pMainView(pMainView) {}
|
||||
CViewRender* m_pMainView;
|
||||
};
|
||||
|
||||
class CSimpleRenderExecutor : public CRenderExecutor
|
||||
{
|
||||
DECLARE_CLASS(CSimpleRenderExecutor, CRenderExecutor);
|
||||
public:
|
||||
explicit CSimpleRenderExecutor(CViewRender* pMainView) : CRenderExecutor(pMainView) {}
|
||||
|
||||
void AddView(CRendering3dView* pView);
|
||||
|
||||
void Execute() {}
|
||||
};
|
||||
|
||||
|
||||
#if defined(_PS3)
|
||||
class CConcurrentViewBuilderPS3
|
||||
{
|
||||
public:
|
||||
|
||||
CConcurrentViewBuilderPS3();
|
||||
~CConcurrentViewBuilderPS3() { Purge(); };
|
||||
|
||||
void Init(void);
|
||||
void Purge(void);
|
||||
|
||||
void ResetBuildViewID(void);
|
||||
|
||||
int GetBuildViewID(void);
|
||||
|
||||
void PushBuildView(void);
|
||||
void PopBuildView(void);
|
||||
|
||||
void SyncViewBuilderJobs(void);
|
||||
|
||||
void SPUBuildRWJobsOn(bool jobOn) { m_bSPUBuildRWJobsOn = jobOn; };
|
||||
bool IsSPUBuildRWJobsOn(void) { return m_bSPUBuildRWJobsOn; };
|
||||
|
||||
int GetPassFlags(void) { return m_passFlags; };
|
||||
void SetPassFlags(int flags) { m_passFlags = flags; };
|
||||
|
||||
IWorldRenderList* GetWorldRenderListElement(void);
|
||||
void SetWorldRenderListElement(IWorldRenderList* pRenderList);
|
||||
|
||||
int GetDrawFlags(void) { return m_drawFlags; };
|
||||
void SetDrawFlags(int drawFlags) { m_drawFlags = drawFlags; };
|
||||
|
||||
unsigned int GetVisFlags(void);
|
||||
void SetVisFlags(unsigned int visFlags);
|
||||
|
||||
void CacheFrustumData(Frustum_t* pFrustum, Frustum_t* pAreaFrustum, void* pRenderAreaBits, int numArea, bool bViewerInSolidSpace);
|
||||
void CacheBuildViewVolumeCuller(void* pVC);
|
||||
void* GetBuildViewVolumeCuller(void);
|
||||
Frustum_t* GetBuildViewFrustum(void);
|
||||
Frustum_t* GetBuildViewAreaFrustum(void);
|
||||
unsigned char* GetBuildViewRenderAreaBits(void);
|
||||
|
||||
int GetNumAreaFrustum(void);
|
||||
Frustum_t* GetBuildViewAreaFrustumID(int frustumID);
|
||||
|
||||
|
||||
void PushBuildRenderableJobs(void);
|
||||
|
||||
private:
|
||||
|
||||
int m_buildViewID;
|
||||
int m_nextFreeBuildViewID;
|
||||
|
||||
int* m_pBuildViewStack;
|
||||
int m_buildViewStack[MAX_CONCURRENT_BUILDVIEWS];
|
||||
|
||||
int m_passFlags;
|
||||
int m_drawFlags;
|
||||
unsigned int m_visFlags[MAX_CONCURRENT_BUILDVIEWS];
|
||||
|
||||
|
||||
IWorldRenderList* m_pWorldRenderListCache[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
|
||||
|
||||
Frustum_t m_gFrustum[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
|
||||
CUtlVector<Frustum_t> m_gAreaFrustum[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
|
||||
unsigned char m_gRenderAreaBits[MAX_CONCURRENT_BUILDVIEWS][32] ALIGN16;
|
||||
bool m_bViewerInSolidSpace[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
|
||||
|
||||
CVolumeCuller m_volumeCullerCache[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
|
||||
|
||||
bool m_bSPUBuildRWJobsOn;
|
||||
};
|
||||
|
||||
extern CConcurrentViewBuilderPS3 g_viewBuilder;
|
||||
|
||||
#else
|
||||
|
||||
class CConcurrentViewData
|
||||
{
|
||||
public:
|
||||
|
||||
void Init(void);
|
||||
void Purge(void);
|
||||
|
||||
CVolumeCuller m_volumeCuller;
|
||||
Frustum_t m_Frustum;
|
||||
CUtlVector< Frustum_t, CUtlMemoryAligned< Frustum_t, 16 > > m_AreaFrustums;
|
||||
Frustum_t* m_frustumList[MAX_MAP_AREAS];
|
||||
|
||||
IWorldRenderList* m_pWorldRenderList;
|
||||
ClientWorldListInfo_t* m_pWorldListInfo;
|
||||
CClientRenderablesList* m_pRenderablesList;
|
||||
|
||||
CJob* m_pBuildWorldListJob;
|
||||
CJob* m_pBuildRenderablesListJob;
|
||||
bool m_bWaitForWorldList;
|
||||
};
|
||||
|
||||
class CConcurrentViewBuilder
|
||||
{
|
||||
public:
|
||||
|
||||
CConcurrentViewBuilder();
|
||||
~CConcurrentViewBuilder();
|
||||
|
||||
void Init(void);
|
||||
void Purge(void);
|
||||
|
||||
void SetBuildWRThreaded(bool bThreaded) { m_bThreaded = bThreaded; }
|
||||
bool GetBuildWRThreaded(void) { return m_bThreaded; }
|
||||
|
||||
void ResetBuildViewID(void);
|
||||
|
||||
int GetBuildViewID(void);
|
||||
|
||||
void PushBuildView(void);
|
||||
void PopBuildView(void);
|
||||
|
||||
int GetPassFlags(void) { return m_passFlags; };
|
||||
void SetPassFlags(int flags) { m_passFlags = flags; };
|
||||
|
||||
void CacheBuildViewVolumeCuller(const CVolumeCuller* pVC);
|
||||
const CVolumeCuller* GetBuildViewVolumeCuller(int buildViewID = -1) const;
|
||||
|
||||
void CacheFrustumData(const Frustum_t& frustum, const CUtlVector< Frustum_t, CUtlMemoryAligned< Frustum_t, 16 > >& aeraFrustums);
|
||||
void CacheFrustumData(void);
|
||||
const Frustum_t* GetBuildViewFrustum(int buildViewID = -1) const;
|
||||
const CUtlVector< Frustum_t, CUtlMemoryAligned< Frustum_t, 16 > >* GetBuildViewAeraFrustums(int buildViewID = -1) const;
|
||||
Frustum_t** GetBuildViewFrustumList(int buildViewID = -1);
|
||||
|
||||
IWorldRenderList* GetWorldRenderListElement(void);
|
||||
void SetWorldRenderListElement(IWorldRenderList* pRenderList);
|
||||
|
||||
ClientWorldListInfo_t* GetClientWorldListInfoElement(int buildViewID = -1);
|
||||
WorldListInfo_t* GetWorldListInfoElement(int buildViewID);
|
||||
void SetWorldListInfoElement(ClientWorldListInfo_t* pWorldListInfo, int buildViewID = -1);
|
||||
|
||||
CClientRenderablesList* GetRenderablesListElement(int buildViewID = -1);
|
||||
void SetRenderablesListElement(CClientRenderablesList* pRenderables);
|
||||
|
||||
void QueueBuildWorldListJob(CJob* pJob);
|
||||
void WaitForBuildWorldListJob(void);
|
||||
void FlushBuildWorldListJob(void);
|
||||
|
||||
void QueueBuildRenderablesListJob(CJob* pJob);
|
||||
void WaitForBuildRenderablesListJob(void);
|
||||
void FlushBuildRenderablesListJob(void);
|
||||
void AddDependencyToWorldList(void);
|
||||
|
||||
private:
|
||||
|
||||
void AddJobToThreadPool(CJob* pJob);
|
||||
void AddToSequentialJobs(CJob* pJob);
|
||||
void TryRunSequentialJobs(void);
|
||||
void WaitForCurrentSequentialJobAndRunPending();
|
||||
void InternalWaitForBuildWorldListJob(int buildViewID);
|
||||
|
||||
class SequentialJobs : public CJob
|
||||
{
|
||||
public:
|
||||
|
||||
explicit SequentialJobs(CJob* pJob = NULL);
|
||||
~SequentialJobs();
|
||||
|
||||
void AddJob(CJob* pJob);
|
||||
|
||||
virtual JobStatus_t DoExecute();
|
||||
|
||||
private:
|
||||
|
||||
CUtlVectorFixed<CJob*, 16> m_jobs;
|
||||
};
|
||||
|
||||
bool m_bThreaded;
|
||||
|
||||
int m_buildViewID;
|
||||
int m_nextFreeBuildViewID;
|
||||
|
||||
int* m_pBuildViewStack;
|
||||
int m_buildViewStack[MAX_CONCURRENT_BUILDVIEWS];
|
||||
|
||||
int m_passFlags;
|
||||
|
||||
CConcurrentViewData m_viewData[MAX_CONCURRENT_BUILDVIEWS];
|
||||
|
||||
SequentialJobs* m_pCurrentSeqJobs;
|
||||
SequentialJobs* m_pPendingSeqJobs;
|
||||
|
||||
CUtlVector<CJob*> mJobsAddedToThreadPool;
|
||||
};
|
||||
|
||||
extern CConcurrentViewBuilder g_viewBuilder;
|
||||
|
||||
#endif
|
||||
|
||||
class CViewRender : public IViewRender
|
||||
{
|
||||
DECLARE_CLASS_NOBASE(CViewRender);
|
||||
public:
|
||||
virtual void Init(void);
|
||||
virtual void Shutdown(void);
|
||||
|
||||
const CViewSetup* GetPlayerViewSetup(int nSlot = -1) const;
|
||||
|
||||
virtual void StartPitchDrift(void);
|
||||
virtual void StopPitchDrift(void);
|
||||
|
||||
virtual float GetZNear();
|
||||
virtual float GetZFar();
|
||||
|
||||
virtual void OnRenderStart();
|
||||
void DriftPitch(void);
|
||||
|
||||
static CViewRender* GetMainView() { return assert_cast<CViewRender*>(view); }
|
||||
|
||||
void AddViewToScene(CRendering3dView* pView) { m_SimpleExecutor.AddView(pView); }
|
||||
|
||||
CMaterialReference& GetWhite();
|
||||
|
||||
virtual void InitFadeData(void);
|
||||
|
||||
protected:
|
||||
void SetUpView();
|
||||
|
||||
void SetUpOverView();
|
||||
void SetUpChaseOverview();
|
||||
|
||||
virtual void WriteSaveGameScreenshotOfSize(const char* pFilename, int width, int height);
|
||||
void WriteSaveGameScreenshot(const char* filename);
|
||||
|
||||
CViewSetup& GetView(int nSlot = -1);
|
||||
const CViewSetup& GetView(int nSlot = -1) const;
|
||||
|
||||
CViewSetup m_UserView[MAX_SPLITSCREEN_PLAYERS];
|
||||
bool m_bAllowViewAccess;
|
||||
CPitchDrift m_PitchDrift;
|
||||
|
||||
virtual void RenderPreScene(const CViewSetup& view) { }
|
||||
virtual void PreViewDrawScene(const CViewSetup& view) {}
|
||||
virtual void PostViewDrawScene(const CViewSetup& view) {}
|
||||
|
||||
float m_flOldChaseOverviewScale;
|
||||
float m_flIdealChaseOverviewScale;
|
||||
float m_flNextIdealOverviewScaleUpdate;
|
||||
public:
|
||||
CViewRender();
|
||||
virtual ~CViewRender(void) {}
|
||||
|
||||
public:
|
||||
|
||||
void SetupVis(const CViewSetup& view, unsigned int& visFlags, ViewCustomVisibility_t* pCustomVisibility = NULL);
|
||||
|
||||
|
||||
virtual void Render(vrect_t* rect);
|
||||
virtual void RenderView(const CViewSetup& view, const CViewSetup& hudViewSetup, int nClearFlags, int whatToDraw);
|
||||
virtual void RenderPlayerSprites();
|
||||
virtual void Render2DEffectsPreHUD(const CViewSetup& view);
|
||||
virtual void Render2DEffectsPostHUD(const CViewSetup& view);
|
||||
virtual void RenderSmokeOverlay(bool bPreViewModel = true) {};
|
||||
float GetLastRenderSmokeOverlayAmount() const { return m_flSmokeOverlayAmount; }
|
||||
|
||||
|
||||
void DisableFog(void);
|
||||
|
||||
void LevelInit(void);
|
||||
void LevelShutdown(void);
|
||||
|
||||
bool ShouldDrawEntities(void);
|
||||
bool ShouldDrawBrushModels(void);
|
||||
|
||||
const CViewSetup* GetViewSetup() const;
|
||||
|
||||
void DisableVis(void);
|
||||
|
||||
void MoveViewModels();
|
||||
|
||||
void GetViewModelPosition(int nIndex, Vector* pPos, QAngle* pAngle);
|
||||
|
||||
void SetCheapWaterStartDistance(float flCheapWaterStartDistance);
|
||||
void SetCheapWaterEndDistance(float flCheapWaterEndDistance);
|
||||
|
||||
void GetWaterLODParams(float& flCheapWaterStartDistance, float& flCheapWaterEndDistance);
|
||||
|
||||
virtual void QueueOverlayRenderView(const CViewSetup& view, int nClearFlags, int whatToDraw);
|
||||
|
||||
virtual void GetScreenFadeDistances(float* pMin, float* pMax, float* pScale);
|
||||
|
||||
virtual C_BaseEntity* GetCurrentlyDrawingEntity();
|
||||
virtual void SetCurrentlyDrawingEntity(C_BaseEntity* pEnt);
|
||||
|
||||
virtual bool UpdateShadowDepthTexture(ITexture* pRenderTarget, ITexture* pDepthTexture, const CViewSetup& shadowView, bool bRenderWorldAndObjects = true, bool bRenderViewModels = false);
|
||||
|
||||
int GetBaseDrawFlags() { return m_BaseDrawFlags; }
|
||||
virtual bool ShouldForceNoVis() { return m_bForceNoVis; }
|
||||
int BuildRenderablesListsNumber() const { return m_BuildRenderableListsNumber; }
|
||||
int IncRenderablesListsNumber() { return ++m_BuildRenderableListsNumber; }
|
||||
|
||||
int BuildWorldListsNumber() const;
|
||||
int IncWorldListsNumber() { return ++m_BuildWorldListsNumber; }
|
||||
|
||||
virtual VPlane* GetFrustum() { return (m_pActiveRenderer) ? m_pActiveRenderer->GetFrustum() : m_Frustum; }
|
||||
|
||||
virtual int GetDrawFlags() { return (m_pActiveRenderer) ? m_pActiveRenderer->GetDrawFlags() : 0; }
|
||||
|
||||
CBase3dView* GetActiveRenderer() { return m_pActiveRenderer; }
|
||||
CBase3dView* SetActiveRenderer(CBase3dView* pActiveRenderer) { CBase3dView* pPrevious = m_pActiveRenderer; m_pActiveRenderer = pActiveRenderer; return pPrevious; }
|
||||
|
||||
void FreezeFrame(float flFreezeTime);
|
||||
|
||||
void SetWaterOverlayMaterial(IMaterial* pMaterial)
|
||||
{
|
||||
m_UnderWaterOverlayMaterial.Init(pMaterial);
|
||||
}
|
||||
|
||||
void DrawViewModelsShadowDepth(const CViewSetup& view);
|
||||
|
||||
protected:
|
||||
int m_BuildWorldListsNumber;
|
||||
|
||||
|
||||
void ViewDrawScene(bool bDrew3dSkybox, SkyboxVisibility_t nSkyboxVisible, const CViewSetup& view, int nClearFlags, view_id_t viewID, bool bDrawViewModel = false, int baseDrawFlags = 0, ViewCustomVisibility_t* pCustomVisibility = NULL);
|
||||
|
||||
void DrawMonitors(const CViewSetup& cameraView);
|
||||
|
||||
bool DrawOneMonitor(ITexture* pRenderTarget, int cameraNum, C_PointCamera* pCameraEnt, const CViewSetup& cameraView, void* localPlayer,
|
||||
int x, int y, int width, int height);
|
||||
|
||||
bool ShouldDrawViewModel(bool drawViewmodel);
|
||||
#ifdef IRONSIGHT
|
||||
void DrawViewModels(const CViewSetup& view, bool drawViewmodel, bool bDrawScopeLensMask = false);
|
||||
#else
|
||||
void DrawViewModels(const CViewSetup& view, bool drawViewmodel);
|
||||
#endif
|
||||
|
||||
void PerformScreenSpaceEffects(int x, int y, int w, int h);
|
||||
|
||||
void SetScreenOverlayMaterial(IMaterial* pMaterial);
|
||||
IMaterial* GetScreenOverlayMaterial();
|
||||
void PerformScreenOverlay(int x, int y, int w, int h);
|
||||
|
||||
void DrawUnderwaterOverlay(void);
|
||||
|
||||
void DrawWorldAndEntities(bool drawSkybox, const CViewSetup& view, int nClearFlags, ViewCustomVisibility_t* pCustomVisibility = NULL);
|
||||
|
||||
virtual void ViewDrawScene_Intro(const CViewSetup& view, int nClearFlags, const IntroData_t& introData);
|
||||
|
||||
#ifdef PORTAL
|
||||
void ViewDrawScene_PortalStencil(const CViewSetup& view, ViewCustomVisibility_t* pCustomVisibility);
|
||||
void Draw3dSkyboxworld_Portal(const CViewSetup& view, int& nClearFlags, bool& bDrew3dSkybox, SkyboxVisibility_t& nSkyboxVisible, ITexture* pRenderTarget = NULL);
|
||||
#endif
|
||||
|
||||
#ifdef PORTAL2
|
||||
void ViewDrawPhoto(ITexture* pRenderTarget, C_BaseEntity* pEnt);
|
||||
#endif
|
||||
|
||||
void DetermineWaterRenderInfo(const VisibleFogVolumeInfo_t& fogVolumeInfo, WaterRenderInfo_t& info);
|
||||
|
||||
bool UpdateRefractIfNeededByList(CViewModelRenderablesList::RenderGroups_t& list);
|
||||
void DrawRenderablesInList(CViewModelRenderablesList::RenderGroups_t& list, int flags = 0);
|
||||
|
||||
void SetupMain3DView(int nSlot, const CViewSetup& view, const CViewSetup& hudViewSetup, int& nClearFlags, ITexture* pRenderTarget);
|
||||
void CleanupMain3DView(const CViewSetup& view);
|
||||
|
||||
void GetLetterBoxRectangles(int nSlot, const CViewSetup& view, CUtlVector< vrect_t >& vecLetterBoxRectangles);
|
||||
void DrawLetterBoxRectangles(int nSlot, const CUtlVector< vrect_t >& vecLetterBoxRectangles);
|
||||
|
||||
void EnableWaterDepthFeathing(IMaterial* pWaterMaterial, bool bEnable);
|
||||
|
||||
#if defined(_PS3)
|
||||
void InitSPUBuildRenderingJobs(void);
|
||||
#endif
|
||||
|
||||
CViewSetup m_CurrentView;
|
||||
|
||||
bool m_bForceNoVis;
|
||||
|
||||
const ConVar* m_pDrawEntities;
|
||||
const ConVar* m_pDrawBrushModels;
|
||||
|
||||
CMaterialReference m_TranslucentSingleColor;
|
||||
CMaterialReference m_ModulateSingleColor;
|
||||
CMaterialReference m_ScreenOverlayMaterial;
|
||||
CMaterialReference m_UnderWaterOverlayMaterial;
|
||||
|
||||
Vector m_vecLastFacing;
|
||||
float m_flCheapWaterStartDistance;
|
||||
float m_flCheapWaterEndDistance;
|
||||
|
||||
CViewSetup m_OverlayViewSetup;
|
||||
int m_OverlayClearFlags;
|
||||
int m_OverlayDrawFlags;
|
||||
bool m_bDrawOverlay;
|
||||
|
||||
int m_BaseDrawFlags;
|
||||
C_BaseEntity* m_pCurrentlyDrawingEntity;
|
||||
|
||||
#ifdef PORTAL
|
||||
friend class CPortalRender;
|
||||
friend class CPortalRenderable;
|
||||
#endif
|
||||
int m_BuildRenderableListsNumber;
|
||||
|
||||
friend class CBase3dView;
|
||||
|
||||
Frustum m_Frustum;
|
||||
|
||||
CBase3dView* m_pActiveRenderer;
|
||||
CSimpleRenderExecutor m_SimpleExecutor;
|
||||
|
||||
struct FreezeParams_t
|
||||
{
|
||||
FreezeParams_t() : m_bTakeFreezeFrame(false), m_flFreezeFrameUntil(0.0f) {}
|
||||
|
||||
bool m_bTakeFreezeFrame;
|
||||
float m_flFreezeFrameUntil;
|
||||
};
|
||||
|
||||
FreezeParams_t m_FreezeParams[MAX_SPLITSCREEN_PLAYERS];
|
||||
|
||||
FadeData_t m_FadeData;
|
||||
|
||||
CMaterialReference m_WhiteMaterial;
|
||||
|
||||
CON_COMMAND_MEMBER_F(CViewRender, "screenfademinsize", OnScreenFadeMinSize, "Modify global screen fade min size in pixels", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY);
|
||||
CON_COMMAND_MEMBER_F(CViewRender, "screenfademaxsize", OnScreenFadeMaxSize, "Modify global screen fade max size in pixels", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY);
|
||||
|
||||
float m_flSmokeOverlayAmount;
|
||||
};
|
||||
|
||||
#endif
|
747
SpyCustom/sdk/vmatrix.h
Normal file
747
SpyCustom/sdk/vmatrix.h
Normal file
@ -0,0 +1,747 @@
|
||||
#ifndef VMATRIX_H
|
||||
#define VMATRIX_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "vector.h"
|
||||
#include "vplane.h"
|
||||
#include "vector4d.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
struct cplane_t;
|
||||
|
||||
|
||||
class VMatrix
|
||||
{
|
||||
public:
|
||||
|
||||
VMatrix();
|
||||
VMatrix(
|
||||
vec_t m00, vec_t m01, vec_t m02, vec_t m03,
|
||||
vec_t m10, vec_t m11, vec_t m12, vec_t m13,
|
||||
vec_t m20, vec_t m21, vec_t m22, vec_t m23,
|
||||
vec_t m30, vec_t m31, vec_t m32, vec_t m33
|
||||
);
|
||||
|
||||
VMatrix(const Vector& forward, const Vector& left, const Vector& up);
|
||||
VMatrix(const Vector& forward, const Vector& left, const Vector& up, const Vector& translation);
|
||||
|
||||
VMatrix(const matrix3x4_t& matrix3x4);
|
||||
|
||||
void Init(
|
||||
vec_t m00, vec_t m01, vec_t m02, vec_t m03,
|
||||
vec_t m10, vec_t m11, vec_t m12, vec_t m13,
|
||||
vec_t m20, vec_t m21, vec_t m22, vec_t m23,
|
||||
vec_t m30, vec_t m31, vec_t m32, vec_t m33
|
||||
);
|
||||
|
||||
|
||||
void Init(const matrix3x4_t& matrix3x4);
|
||||
|
||||
inline float* operator[](int i)
|
||||
{
|
||||
return m[i];
|
||||
}
|
||||
|
||||
inline const float* operator[](int i) const
|
||||
{
|
||||
return m[i];
|
||||
}
|
||||
|
||||
inline float* Base()
|
||||
{
|
||||
return &m[0][0];
|
||||
}
|
||||
|
||||
inline const float* Base() const
|
||||
{
|
||||
return &m[0][0];
|
||||
}
|
||||
|
||||
void SetLeft(const Vector& vLeft);
|
||||
void SetUp(const Vector& vUp);
|
||||
void SetForward(const Vector& vForward);
|
||||
|
||||
void GetBasisVectors(Vector& vForward, Vector& vLeft, Vector& vUp) const;
|
||||
void SetBasisVectors(const Vector& vForward, const Vector& vLeft, const Vector& vUp);
|
||||
|
||||
Vector& GetTranslation(Vector& vTrans) const;
|
||||
void SetTranslation(const Vector& vTrans);
|
||||
|
||||
void PreTranslate(const Vector& vTrans);
|
||||
void PostTranslate(const Vector& vTrans);
|
||||
|
||||
const matrix3x4_t& As3x4() const;
|
||||
void CopyFrom3x4(const matrix3x4_t& m3x4);
|
||||
void Set3x4(matrix3x4_t& matrix3x4) const;
|
||||
|
||||
bool operator==(const VMatrix& src) const;
|
||||
bool operator!=(const VMatrix& src) const { return !(*this == src); }
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
Vector GetLeft() const;
|
||||
Vector GetUp() const;
|
||||
Vector GetForward() const;
|
||||
Vector GetTranslation() const;
|
||||
#endif
|
||||
|
||||
|
||||
public:
|
||||
void V3Mul(const Vector& vIn, Vector& vOut) const;
|
||||
|
||||
void V4Mul(const Vector4D& vIn, Vector4D& vOut) const;
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
Vector ApplyRotation(const Vector& vVec) const;
|
||||
|
||||
Vector operator*(const Vector& vVec) const;
|
||||
|
||||
Vector VMul3x3(const Vector& vVec) const;
|
||||
|
||||
Vector VMul3x3Transpose(const Vector& vVec) const;
|
||||
|
||||
Vector VMul4x3(const Vector& vVec) const;
|
||||
|
||||
Vector VMul4x3Transpose(const Vector& vVec) const;
|
||||
#endif
|
||||
|
||||
|
||||
public:
|
||||
void TransformPlane(const VPlane& inPlane, VPlane& outPlane) const;
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
VPlane operator*(const VPlane& thePlane) const;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
VMatrix& operator=(const VMatrix& mOther);
|
||||
|
||||
void MatrixMul(const VMatrix& vm, VMatrix& out) const;
|
||||
|
||||
const VMatrix& operator+=(const VMatrix& other);
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
VMatrix operator*(const VMatrix& mOther) const;
|
||||
|
||||
VMatrix operator+(const VMatrix& other) const;
|
||||
VMatrix operator-(const VMatrix& other) const;
|
||||
|
||||
VMatrix operator-() const;
|
||||
|
||||
VMatrix operator~() const;
|
||||
#endif
|
||||
|
||||
public:
|
||||
void Identity();
|
||||
|
||||
bool IsIdentity() const;
|
||||
|
||||
void SetupMatrixOrgAngles(const Vector& origin, const QAngle& vAngles);
|
||||
|
||||
void SetupMatrixAngles(const QAngle& vAngles);
|
||||
|
||||
bool InverseGeneral(VMatrix& vInverse) const;
|
||||
|
||||
void InverseTR(VMatrix& mRet) const;
|
||||
|
||||
bool IsRotationMatrix() const;
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
VMatrix InverseTR() const;
|
||||
|
||||
Vector GetScale() const;
|
||||
|
||||
VMatrix Scale(const Vector& vScale);
|
||||
|
||||
VMatrix NormalizeBasisVectors() const;
|
||||
|
||||
VMatrix Transpose() const;
|
||||
|
||||
VMatrix Transpose3x3() const;
|
||||
#endif
|
||||
|
||||
public:
|
||||
vec_t m[4][4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
VMatrix SetupMatrixIdentity();
|
||||
|
||||
VMatrix SetupMatrixScale(const Vector& vScale);
|
||||
|
||||
VMatrix SetupMatrixTranslation(const Vector& vTranslation);
|
||||
|
||||
VMatrix SetupMatrixReflection(const VPlane& thePlane);
|
||||
|
||||
VMatrix SetupMatrixProjection(const Vector& vOrigin, const VPlane& thePlane);
|
||||
|
||||
VMatrix SetupMatrixAxisRot(const Vector& vAxis, vec_t fDegrees);
|
||||
|
||||
VMatrix SetupMatrixAngles(const QAngle& vAngles);
|
||||
|
||||
VMatrix SetupMatrixOrgAngles(const Vector& origin, const QAngle& vAngles);
|
||||
|
||||
#endif
|
||||
|
||||
#define VMatToString(mat) (static_cast<const char *>(CFmtStr("[ (%f, %f, %f), (%f, %f, %f), (%f, %f, %f), (%f, %f, %f) ]", mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[0][3], mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[1][3], mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[2][3], mat.m[3][0], mat.m[3][1], mat.m[3][2], mat.m[3][3] )))
|
||||
|
||||
bool PlaneIntersection(const VPlane& vp1, const VPlane& vp2, const VPlane& vp3, Vector& vOut);
|
||||
|
||||
|
||||
void MatrixSetIdentity(VMatrix& dst);
|
||||
void MatrixTranspose(const VMatrix& src, VMatrix& dst);
|
||||
void MatrixCopy(const VMatrix& src, VMatrix& dst);
|
||||
void MatrixMultiply(const VMatrix& src1, const VMatrix& src2, VMatrix& dst);
|
||||
|
||||
void MatrixGetColumn(const VMatrix& src, int nCol, Vector* pColumn);
|
||||
void MatrixSetColumn(VMatrix& src, int nCol, const Vector& column);
|
||||
void MatrixGetRow(const VMatrix& src, int nCol, Vector* pColumn);
|
||||
void MatrixSetRow(VMatrix& src, int nCol, const Vector& column);
|
||||
|
||||
void Vector3DMultiply(const VMatrix& src1, const Vector& src2, Vector& dst);
|
||||
|
||||
inline void Vector3DMultiplyPosition(const VMatrix& src1, const VectorByValue src2, Vector& dst);
|
||||
|
||||
void Vector3DMultiplyPositionProjective(const VMatrix& src1, const Vector& src2, Vector& dst);
|
||||
|
||||
void Vector3DMultiplyProjective(const VMatrix& src1, const Vector& src2, Vector& dst);
|
||||
|
||||
void Vector4DMultiply(const VMatrix& src1, const Vector4D& src2, Vector4D& dst);
|
||||
|
||||
void Vector4DMultiplyPosition(const VMatrix& src1, const Vector& src2, Vector4D& dst);
|
||||
|
||||
void Vector3DMultiplyTranspose(const VMatrix& src1, const Vector& src2, Vector& dst);
|
||||
void Vector4DMultiplyTranspose(const VMatrix& src1, const Vector4D& src2, Vector4D& dst);
|
||||
|
||||
void MatrixTransformPlane(const VMatrix& src, const cplane_t& inPlane, cplane_t& outPlane);
|
||||
|
||||
void MatrixTransformAxisAlignedPlane(const VMatrix& src, int nDim, float flSign, float flDist, cplane_t& outPlane);
|
||||
|
||||
void MatrixBuildTranslation(VMatrix& dst, float x, float y, float z);
|
||||
void MatrixBuildTranslation(VMatrix& dst, const Vector& translation);
|
||||
|
||||
inline void MatrixTranslate(VMatrix& dst, const Vector& translation)
|
||||
{
|
||||
VMatrix matTranslation, temp;
|
||||
MatrixBuildTranslation(matTranslation, translation);
|
||||
MatrixMultiply(dst, matTranslation, temp);
|
||||
dst = temp;
|
||||
}
|
||||
|
||||
|
||||
void MatrixBuildRotationAboutAxis(VMatrix& dst, const Vector& vAxisOfRot, float angleDegrees);
|
||||
void MatrixBuildRotateZ(VMatrix& dst, float angleDegrees);
|
||||
|
||||
inline void MatrixRotate(VMatrix& dst, const Vector& vAxisOfRot, float angleDegrees)
|
||||
{
|
||||
VMatrix rotation, temp;
|
||||
MatrixBuildRotationAboutAxis(rotation, vAxisOfRot, angleDegrees);
|
||||
MatrixMultiply(dst, rotation, temp);
|
||||
dst = temp;
|
||||
}
|
||||
|
||||
void MatrixBuildRotation(VMatrix& dst, const Vector& initialDirection, const Vector& finalDirection);
|
||||
|
||||
void MatrixBuildScale(VMatrix& dst, float x, float y, float z);
|
||||
void MatrixBuildScale(VMatrix& dst, const Vector& scale);
|
||||
|
||||
void MatrixBuildPerspective(VMatrix& dst, float fovX, float fovY, float zNear, float zFar);
|
||||
|
||||
void CalculateAABBFromProjectionMatrix(const VMatrix& worldToVolume, Vector* pMins, Vector* pMaxs);
|
||||
|
||||
void CalculateSphereFromProjectionMatrix(const VMatrix& worldToVolume, Vector* pCenter, float* pflRadius);
|
||||
|
||||
void CalculateAABBFromProjectionMatrixInverse(const VMatrix& volumeToWorld, Vector* pMins, Vector* pMaxs);
|
||||
|
||||
void CalculateSphereFromProjectionMatrixInverse(const VMatrix& volumeToWorld, Vector* pCenter, float* pflRadius);
|
||||
|
||||
void FrustumPlanesFromMatrix(const VMatrix& clipToWorld, Frustum_t& frustum);
|
||||
|
||||
void MatrixFromAngles(const QAngle& vAngles, VMatrix& dst);
|
||||
|
||||
void MatrixToAngles(const VMatrix& src, QAngle& vAngles);
|
||||
|
||||
void MatrixInverseTR(const VMatrix& src, VMatrix& dst);
|
||||
|
||||
bool MatrixInverseGeneral(const VMatrix& src, VMatrix& dst);
|
||||
|
||||
void MatrixInverseTranspose(const VMatrix& src, VMatrix& dst);
|
||||
|
||||
|
||||
|
||||
inline VMatrix::VMatrix()
|
||||
{
|
||||
}
|
||||
|
||||
inline VMatrix::VMatrix(
|
||||
vec_t m00, vec_t m01, vec_t m02, vec_t m03,
|
||||
vec_t m10, vec_t m11, vec_t m12, vec_t m13,
|
||||
vec_t m20, vec_t m21, vec_t m22, vec_t m23,
|
||||
vec_t m30, vec_t m31, vec_t m32, vec_t m33)
|
||||
{
|
||||
Init(
|
||||
m00, m01, m02, m03,
|
||||
m10, m11, m12, m13,
|
||||
m20, m21, m22, m23,
|
||||
m30, m31, m32, m33
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
inline VMatrix::VMatrix(const matrix3x4_t& matrix3x4)
|
||||
{
|
||||
Init(matrix3x4);
|
||||
}
|
||||
|
||||
|
||||
inline VMatrix::VMatrix(const Vector& xAxis, const Vector& yAxis, const Vector& zAxis)
|
||||
{
|
||||
Init(
|
||||
xAxis.x, yAxis.x, zAxis.x, 0.0f,
|
||||
xAxis.y, yAxis.y, zAxis.y, 0.0f,
|
||||
xAxis.z, yAxis.z, zAxis.z, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
}
|
||||
|
||||
inline VMatrix::VMatrix(const Vector& xAxis, const Vector& yAxis, const Vector& zAxis, const Vector& translation)
|
||||
{
|
||||
Init(
|
||||
xAxis.x, yAxis.x, zAxis.x, translation.x,
|
||||
xAxis.y, yAxis.y, zAxis.y, translation.y,
|
||||
xAxis.z, yAxis.z, zAxis.z, translation.z,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
inline void VMatrix::Init(
|
||||
vec_t m00, vec_t m01, vec_t m02, vec_t m03,
|
||||
vec_t m10, vec_t m11, vec_t m12, vec_t m13,
|
||||
vec_t m20, vec_t m21, vec_t m22, vec_t m23,
|
||||
vec_t m30, vec_t m31, vec_t m32, vec_t m33
|
||||
)
|
||||
{
|
||||
m[0][0] = m00;
|
||||
m[0][1] = m01;
|
||||
m[0][2] = m02;
|
||||
m[0][3] = m03;
|
||||
|
||||
m[1][0] = m10;
|
||||
m[1][1] = m11;
|
||||
m[1][2] = m12;
|
||||
m[1][3] = m13;
|
||||
|
||||
m[2][0] = m20;
|
||||
m[2][1] = m21;
|
||||
m[2][2] = m22;
|
||||
m[2][3] = m23;
|
||||
|
||||
m[3][0] = m30;
|
||||
m[3][1] = m31;
|
||||
m[3][2] = m32;
|
||||
m[3][3] = m33;
|
||||
}
|
||||
|
||||
|
||||
inline void VMatrix::Init(const matrix3x4_t& matrix3x4)
|
||||
{
|
||||
memcpy(m, matrix3x4.Base(), sizeof(matrix3x4_t));
|
||||
|
||||
m[3][0] = 0.0f;
|
||||
m[3][1] = 0.0f;
|
||||
m[3][2] = 0.0f;
|
||||
m[3][3] = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline Vector VMatrix::GetForward() const
|
||||
{
|
||||
return Vector(m[0][0], m[1][0], m[2][0]);
|
||||
}
|
||||
|
||||
inline Vector VMatrix::GetLeft() const
|
||||
{
|
||||
return Vector(m[0][1], m[1][1], m[2][1]);
|
||||
}
|
||||
|
||||
inline Vector VMatrix::GetUp() const
|
||||
{
|
||||
return Vector(m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline void VMatrix::SetForward(const Vector& vForward)
|
||||
{
|
||||
m[0][0] = vForward.x;
|
||||
m[1][0] = vForward.y;
|
||||
m[2][0] = vForward.z;
|
||||
}
|
||||
|
||||
inline void VMatrix::SetLeft(const Vector& vLeft)
|
||||
{
|
||||
m[0][1] = vLeft.x;
|
||||
m[1][1] = vLeft.y;
|
||||
m[2][1] = vLeft.z;
|
||||
}
|
||||
|
||||
inline void VMatrix::SetUp(const Vector& vUp)
|
||||
{
|
||||
m[0][2] = vUp.x;
|
||||
m[1][2] = vUp.y;
|
||||
m[2][2] = vUp.z;
|
||||
}
|
||||
|
||||
inline void VMatrix::GetBasisVectors(Vector& vForward, Vector& vLeft, Vector& vUp) const
|
||||
{
|
||||
vForward.Init(m[0][0], m[1][0], m[2][0]);
|
||||
vLeft.Init(m[0][1], m[1][1], m[2][1]);
|
||||
vUp.Init(m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
inline void VMatrix::SetBasisVectors(const Vector& vForward, const Vector& vLeft, const Vector& vUp)
|
||||
{
|
||||
SetForward(vForward);
|
||||
SetLeft(vLeft);
|
||||
SetUp(vUp);
|
||||
}
|
||||
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline Vector VMatrix::GetTranslation() const
|
||||
{
|
||||
return Vector(m[0][3], m[1][3], m[2][3]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline Vector& VMatrix::GetTranslation(Vector& vTrans) const
|
||||
{
|
||||
vTrans.x = m[0][3];
|
||||
vTrans.y = m[1][3];
|
||||
vTrans.z = m[2][3];
|
||||
return vTrans;
|
||||
}
|
||||
|
||||
inline void VMatrix::SetTranslation(const Vector& vTrans)
|
||||
{
|
||||
m[0][3] = vTrans.x;
|
||||
m[1][3] = vTrans.y;
|
||||
m[2][3] = vTrans.z;
|
||||
}
|
||||
|
||||
|
||||
inline void VMatrix::PreTranslate(const Vector& vTrans)
|
||||
{
|
||||
Vector tmp;
|
||||
Vector3DMultiplyPosition(*this, vTrans, tmp);
|
||||
m[0][3] = tmp.x;
|
||||
m[1][3] = tmp.y;
|
||||
m[2][3] = tmp.z;
|
||||
}
|
||||
|
||||
|
||||
inline void VMatrix::PostTranslate(const Vector& vTrans)
|
||||
{
|
||||
m[0][3] += vTrans.x;
|
||||
m[1][3] += vTrans.y;
|
||||
m[2][3] += vTrans.z;
|
||||
}
|
||||
|
||||
inline const matrix3x4_t& VMatrix::As3x4() const
|
||||
{
|
||||
return *((const matrix3x4_t*)this);
|
||||
}
|
||||
|
||||
inline void VMatrix::CopyFrom3x4(const matrix3x4_t& m3x4)
|
||||
{
|
||||
memcpy(m, m3x4.Base(), sizeof(matrix3x4_t));
|
||||
m[3][0] = m[3][1] = m[3][2] = 0;
|
||||
m[3][3] = 1;
|
||||
}
|
||||
|
||||
inline void VMatrix::Set3x4(matrix3x4_t& matrix3x4) const
|
||||
{
|
||||
memcpy(matrix3x4.Base(), m, sizeof(matrix3x4_t));
|
||||
}
|
||||
|
||||
|
||||
inline const VMatrix& VMatrix::operator+=(const VMatrix& other)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
m[i][j] += other.m[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline VMatrix VMatrix::operator+(const VMatrix& other) const
|
||||
{
|
||||
VMatrix ret;
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
((float*)ret.m)[i] = ((float*)m)[i] + ((float*)other.m)[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline VMatrix VMatrix::operator-(const VMatrix& other) const
|
||||
{
|
||||
VMatrix ret;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
ret.m[i][j] = m[i][j] - other.m[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline VMatrix VMatrix::operator-() const
|
||||
{
|
||||
VMatrix ret;
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
((float*)ret.m)[i] = ((float*)m)[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline Vector VMatrix::operator*(const Vector& vVec) const
|
||||
{
|
||||
Vector vRet;
|
||||
vRet.x = m[0][0] * vVec.x + m[0][1] * vVec.y + m[0][2] * vVec.z + m[0][3];
|
||||
vRet.y = m[1][0] * vVec.x + m[1][1] * vVec.y + m[1][2] * vVec.z + m[1][3];
|
||||
vRet.z = m[2][0] * vVec.x + m[2][1] * vVec.y + m[2][2] * vVec.z + m[2][3];
|
||||
|
||||
return vRet;
|
||||
}
|
||||
|
||||
inline Vector VMatrix::VMul4x3(const Vector& vVec) const
|
||||
{
|
||||
Vector vResult;
|
||||
Vector3DMultiplyPosition(*this, vVec, vResult);
|
||||
return vResult;
|
||||
}
|
||||
|
||||
|
||||
inline Vector VMatrix::VMul4x3Transpose(const Vector& vVec) const
|
||||
{
|
||||
Vector tmp = vVec;
|
||||
tmp.x -= m[0][3];
|
||||
tmp.y -= m[1][3];
|
||||
tmp.z -= m[2][3];
|
||||
|
||||
return Vector(
|
||||
m[0][0] * tmp.x + m[1][0] * tmp.y + m[2][0] * tmp.z,
|
||||
m[0][1] * tmp.x + m[1][1] * tmp.y + m[2][1] * tmp.z,
|
||||
m[0][2] * tmp.x + m[1][2] * tmp.y + m[2][2] * tmp.z
|
||||
);
|
||||
}
|
||||
|
||||
inline Vector VMatrix::VMul3x3(const Vector& vVec) const
|
||||
{
|
||||
return Vector(
|
||||
m[0][0] * vVec.x + m[0][1] * vVec.y + m[0][2] * vVec.z,
|
||||
m[1][0] * vVec.x + m[1][1] * vVec.y + m[1][2] * vVec.z,
|
||||
m[2][0] * vVec.x + m[2][1] * vVec.y + m[2][2] * vVec.z
|
||||
);
|
||||
}
|
||||
|
||||
inline Vector VMatrix::VMul3x3Transpose(const Vector& vVec) const
|
||||
{
|
||||
return Vector(
|
||||
m[0][0] * vVec.x + m[1][0] * vVec.y + m[2][0] * vVec.z,
|
||||
m[0][1] * vVec.x + m[1][1] * vVec.y + m[2][1] * vVec.z,
|
||||
m[0][2] * vVec.x + m[1][2] * vVec.y + m[2][2] * vVec.z
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
inline void VMatrix::V3Mul(const Vector& vIn, Vector& vOut) const
|
||||
{
|
||||
vec_t rw;
|
||||
|
||||
rw = 1.0f / (m[3][0] * vIn.x + m[3][1] * vIn.y + m[3][2] * vIn.z + m[3][3]);
|
||||
vOut.x = (m[0][0] * vIn.x + m[0][1] * vIn.y + m[0][2] * vIn.z + m[0][3]) * rw;
|
||||
vOut.y = (m[1][0] * vIn.x + m[1][1] * vIn.y + m[1][2] * vIn.z + m[1][3]) * rw;
|
||||
vOut.z = (m[2][0] * vIn.x + m[2][1] * vIn.y + m[2][2] * vIn.z + m[2][3]) * rw;
|
||||
}
|
||||
|
||||
inline void VMatrix::V4Mul(const Vector4D& vIn, Vector4D& vOut) const
|
||||
{
|
||||
vOut[0] = m[0][0] * vIn[0] + m[0][1] * vIn[1] + m[0][2] * vIn[2] + m[0][3] * vIn[3];
|
||||
vOut[1] = m[1][0] * vIn[0] + m[1][1] * vIn[1] + m[1][2] * vIn[2] + m[1][3] * vIn[3];
|
||||
vOut[2] = m[2][0] * vIn[0] + m[2][1] * vIn[1] + m[2][2] * vIn[2] + m[2][3] * vIn[3];
|
||||
vOut[3] = m[3][0] * vIn[0] + m[3][1] * vIn[1] + m[3][2] * vIn[2] + m[3][3] * vIn[3];
|
||||
}
|
||||
|
||||
|
||||
inline void VMatrix::TransformPlane(const VPlane& inPlane, VPlane& outPlane) const
|
||||
{
|
||||
Vector vTrans;
|
||||
Vector3DMultiply(*this, inPlane.m_Normal, outPlane.m_Normal);
|
||||
outPlane.m_Dist = inPlane.m_Dist * DotProduct(outPlane.m_Normal, outPlane.m_Normal);
|
||||
outPlane.m_Dist += DotProduct(outPlane.m_Normal, GetTranslation(vTrans));
|
||||
}
|
||||
|
||||
|
||||
inline void VMatrix::Identity()
|
||||
{
|
||||
MatrixSetIdentity(*this);
|
||||
}
|
||||
|
||||
|
||||
inline bool VMatrix::IsIdentity() const
|
||||
{
|
||||
return
|
||||
m[0][0] == 1.0f && m[0][1] == 0.0f && m[0][2] == 0.0f && m[0][3] == 0.0f &&
|
||||
m[1][0] == 0.0f && m[1][1] == 1.0f && m[1][2] == 0.0f && m[1][3] == 0.0f &&
|
||||
m[2][0] == 0.0f && m[2][1] == 0.0f && m[2][2] == 1.0f && m[2][3] == 0.0f &&
|
||||
m[3][0] == 0.0f && m[3][1] == 0.0f && m[3][2] == 0.0f && m[3][3] == 1.0f;
|
||||
}
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline Vector VMatrix::ApplyRotation(const Vector& vVec) const
|
||||
{
|
||||
return VMul3x3(vVec);
|
||||
}
|
||||
|
||||
inline VMatrix VMatrix::operator~() const
|
||||
{
|
||||
VMatrix mRet;
|
||||
InverseGeneral(mRet);
|
||||
return mRet;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
inline void MatrixGetColumn(const VMatrix& src, int nCol, Vector* pColumn)
|
||||
{
|
||||
Assert((nCol >= 0) && (nCol <= 3));
|
||||
|
||||
pColumn->x = src[0][nCol];
|
||||
pColumn->y = src[1][nCol];
|
||||
pColumn->z = src[2][nCol];
|
||||
}
|
||||
|
||||
inline void MatrixSetColumn(VMatrix& src, int nCol, const Vector& column)
|
||||
{
|
||||
Assert((nCol >= 0) && (nCol <= 3));
|
||||
|
||||
src.m[0][nCol] = column.x;
|
||||
src.m[1][nCol] = column.y;
|
||||
src.m[2][nCol] = column.z;
|
||||
}
|
||||
|
||||
inline void MatrixGetRow(const VMatrix& src, int nRow, Vector* pRow)
|
||||
{
|
||||
Assert((nRow >= 0) && (nRow <= 3));
|
||||
*pRow = *(Vector*)src[nRow];
|
||||
}
|
||||
|
||||
inline void MatrixSetRow(VMatrix& dst, int nRow, const Vector& row)
|
||||
{
|
||||
Assert((nRow >= 0) && (nRow <= 3));
|
||||
*(Vector*)dst[nRow] = row;
|
||||
}
|
||||
|
||||
|
||||
inline void Vector3DMultiplyPosition(const VMatrix& src1, const VectorByValue src2, Vector& dst)
|
||||
{
|
||||
dst[0] = src1[0][0] * src2.x + src1[0][1] * src2.y + src1[0][2] * src2.z + src1[0][3];
|
||||
dst[1] = src1[1][0] * src2.x + src1[1][1] * src2.y + src1[1][2] * src2.z + src1[1][3];
|
||||
dst[2] = src1[2][0] * src2.x + src1[2][1] * src2.y + src1[2][2] * src2.z + src1[2][3];
|
||||
}
|
||||
|
||||
|
||||
inline void MatrixTransformAxisAlignedPlane(const VMatrix& src, int nDim, float flSign, float flDist, cplane_t& outPlane)
|
||||
{
|
||||
MatrixGetColumn(src, nDim, &outPlane.normal);
|
||||
outPlane.normal *= flSign;
|
||||
outPlane.dist = flDist * DotProduct(outPlane.normal, outPlane.normal);
|
||||
|
||||
outPlane.dist += outPlane.normal.x * src.m[0][3] + outPlane.normal.y * src.m[1][3] + outPlane.normal.z * src.m[2][3];
|
||||
}
|
||||
|
||||
|
||||
inline bool MatricesAreEqual(const VMatrix& src1, const VMatrix& src2, float flTolerance)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
if (fabs(src1[i][j] - src2[i][j]) > flTolerance)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MatrixBuildOrtho(VMatrix& dst, double left, double top, double right, double bottom, double zNear, double zFar);
|
||||
void MatrixBuildPerspectiveX(VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar);
|
||||
void MatrixBuildPerspectiveOffCenterX(VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right);
|
||||
void MatrixBuildPerspectiveZRange(VMatrix& dst, double flZNear, double flZFar);
|
||||
|
||||
inline void MatrixOrtho(VMatrix& dst, double left, double top, double right, double bottom, double zNear, double zFar)
|
||||
{
|
||||
VMatrix mat;
|
||||
MatrixBuildOrtho(mat, left, top, right, bottom, zNear, zFar);
|
||||
|
||||
VMatrix temp;
|
||||
MatrixMultiply(dst, mat, temp);
|
||||
dst = temp;
|
||||
}
|
||||
|
||||
inline void MatrixPerspectiveX(VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar)
|
||||
{
|
||||
VMatrix mat;
|
||||
MatrixBuildPerspectiveX(mat, flFovX, flAspect, flZNear, flZFar);
|
||||
|
||||
VMatrix temp;
|
||||
MatrixMultiply(dst, mat, temp);
|
||||
dst = temp;
|
||||
}
|
||||
|
||||
inline void MatrixPerspectiveOffCenterX(VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right)
|
||||
{
|
||||
VMatrix mat;
|
||||
MatrixBuildPerspectiveOffCenterX(mat, flFovX, flAspect, flZNear, flZFar, bottom, top, left, right);
|
||||
|
||||
VMatrix temp;
|
||||
MatrixMultiply(dst, mat, temp);
|
||||
dst = temp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
88
SpyCustom/sdk/volumeculler.h
Normal file
88
SpyCustom/sdk/volumeculler.h
Normal file
@ -0,0 +1,88 @@
|
||||
#ifndef VOLUME_CULLER_H
|
||||
#define VOLUME_CULLER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vector.h"
|
||||
#include "vplane.h"
|
||||
#include "ssemath.h"
|
||||
#include "memalloc.h"
|
||||
|
||||
class CVolumeCuller : public CAlignedNewDelete< 16 >
|
||||
{
|
||||
public:
|
||||
inline CVolumeCuller() { Clear(); }
|
||||
|
||||
inline void Clear() { m_nNumInclusionVolumePlanes = 0; m_bHasExclusionFrustum = false; m_bHasBaseFrustum = false; m_bCullSmallObjects = false; ClearCullCheckStats(); }
|
||||
|
||||
inline bool IsValid() const { return m_bHasExclusionFrustum || (m_nNumInclusionVolumePlanes != 0); }
|
||||
|
||||
bool CheckBox(const VectorAligned& mins, const VectorAligned& maxs) const;
|
||||
bool CheckBox(const Vector& mins, const Vector& maxs) const;
|
||||
bool CheckBoxCenterHalfDiagonal(const VectorAligned& center, const VectorAligned& halfDiagonal) const;
|
||||
|
||||
enum
|
||||
{
|
||||
cNumBaseFrustumPlanes = 6,
|
||||
|
||||
cNumExclusionFrustumPlanes = 6,
|
||||
|
||||
cMaxInclusionVolumePlanes = 12
|
||||
};
|
||||
|
||||
inline bool HasBaseFrustum() const { return m_bHasBaseFrustum; }
|
||||
void SetBaseFrustumPlanes(const VPlane* pPlanes);
|
||||
|
||||
void GetBaseFrustumPlanes(VPlane* pBasePlanes) const;
|
||||
int GetNumBaseFrustumPlanes() const { return cNumBaseFrustumPlanes; }
|
||||
|
||||
inline bool HasExclusionFrustum() const { return m_bHasExclusionFrustum; }
|
||||
void SetExclusionFrustumPlanes(const VPlane* pPlanes);
|
||||
|
||||
int GetNumExclusionFrustumPlanes() const { return cNumExclusionFrustumPlanes; }
|
||||
const fltx4* GetExclusionFrustumPlanes() const { return m_ExclusionFrustumPlanes; }
|
||||
|
||||
inline bool HasInclusionVolume() const { return m_nNumInclusionVolumePlanes != 0; }
|
||||
void SetInclusionVolumePlanes(const VPlane* pPlanes, uint nNumPlanes);
|
||||
|
||||
int GetNumInclusionVolumePlanes() const { return m_nNumInclusionVolumePlanes; }
|
||||
const fltx4* GetInclusionVolumePlanes() const { return m_InclusionVolumePlanes; }
|
||||
|
||||
bool GetCullSmallObjects() const { return m_bCullSmallObjects; }
|
||||
float GetSmallObjectCullVolumeThreshold() const { return m_flSmallObjectCullVolumeThreshold; }
|
||||
|
||||
void SetCullSmallObjects(bool bCullSmallObjects, float flCullVolumeThreshold) { m_bCullSmallObjects = bCullSmallObjects; m_flSmallObjectCullVolumeThreshold = flCullVolumeThreshold; }
|
||||
|
||||
struct CullCheckStats_t
|
||||
{
|
||||
uint m_nTotalAABB;
|
||||
uint m_nTotalAABBPassed;
|
||||
|
||||
uint m_nTotalCenterHalfDiagonal;
|
||||
uint m_nTotalCenterHalfDiagonalPassed;
|
||||
};
|
||||
|
||||
inline void ClearCullCheckStats() { memset(&m_Stats, 0, sizeof(m_Stats)); }
|
||||
inline CullCheckStats_t& GetStats() const { return m_Stats; }
|
||||
|
||||
private:
|
||||
fourplanes_t m_baseplanes[2];
|
||||
|
||||
fltx4 m_ExclusionFrustumPlanes[cNumExclusionFrustumPlanes];
|
||||
|
||||
fltx4 m_InclusionVolumePlanes[cMaxInclusionVolumePlanes];
|
||||
|
||||
uint m_nNumInclusionVolumePlanes;
|
||||
|
||||
bool m_bHasBaseFrustum : 1;
|
||||
bool m_bHasExclusionFrustum : 1;
|
||||
|
||||
bool m_bCullSmallObjects : 1;
|
||||
float m_flSmallObjectCullVolumeThreshold;
|
||||
|
||||
mutable CullCheckStats_t m_Stats;
|
||||
};
|
||||
|
||||
#endif
|
898
SpyCustom/sdk/vphysics_interface.h
Normal file
898
SpyCustom/sdk/vphysics_interface.h
Normal file
@ -0,0 +1,898 @@
|
||||
#ifndef VPHYSICS_INTERFACE_H
|
||||
#define VPHYSICS_INTERFACE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "interface.h"
|
||||
#include "IAppSystem.h"
|
||||
#include "vector.h"
|
||||
#include "vector4d.h"
|
||||
#include "vcollide.h"
|
||||
|
||||
|
||||
#define METERS_PER_INCH (0.0254f)
|
||||
#define CUBIC_METERS_PER_CUBIC_INCH (METERS_PER_INCH*METERS_PER_INCH*METERS_PER_INCH)
|
||||
#define POUNDS_PER_KG (2.2f)
|
||||
#define KG_PER_POUND (1.0f/POUNDS_PER_KG)
|
||||
|
||||
#define lbs2kg(x) ((x)*KG_PER_POUND)
|
||||
#define kg2lbs(x) ((x)*POUNDS_PER_KG)
|
||||
|
||||
const float VPHYSICS_MIN_MASS = 0.1f;
|
||||
const float VPHYSICS_MAX_MASS = 5e4f;
|
||||
|
||||
class IPhysicsObject;
|
||||
class IPhysicsEnvironment;
|
||||
class IPhysicsSurfaceProps;
|
||||
class IPhysicsConstraint;
|
||||
class IPhysicsConstraintGroup;
|
||||
class IPhysicsFluidController;
|
||||
class IPhysicsSpring;
|
||||
class IPhysicsVehicleController;
|
||||
class IConvexInfo;
|
||||
class IPhysicsObjectPairHash;
|
||||
class IPhysicsCollisionSet;
|
||||
class IPhysicsPlayerController;
|
||||
class IPhysicsFrictionSnapshot;
|
||||
|
||||
struct Ray_t;
|
||||
struct constraint_ragdollparams_t;
|
||||
struct constraint_hingeparams_t;
|
||||
struct constraint_fixedparams_t;
|
||||
struct constraint_ballsocketparams_t;
|
||||
struct constraint_slidingparams_t;
|
||||
struct constraint_pulleyparams_t;
|
||||
struct constraint_lengthparams_t;
|
||||
struct constraint_groupparams_t;
|
||||
|
||||
struct vehicleparams_t;
|
||||
struct matrix3x4_t;
|
||||
|
||||
struct fluidparams_t;
|
||||
struct springparams_t;
|
||||
struct objectparams_t;
|
||||
struct debugcollide_t;
|
||||
class CGameTrace;
|
||||
typedef CGameTrace trace_t;
|
||||
struct physics_stats_t;
|
||||
struct physics_performanceparams_t;
|
||||
struct virtualmeshparams_t;
|
||||
|
||||
struct physsaveparams_t;
|
||||
struct physrestoreparams_t;
|
||||
struct physprerestoreparams_t;
|
||||
|
||||
enum PhysInterfaceId_t
|
||||
{
|
||||
PIID_UNKNOWN,
|
||||
PIID_IPHYSICSOBJECT,
|
||||
PIID_IPHYSICSFLUIDCONTROLLER,
|
||||
PIID_IPHYSICSSPRING,
|
||||
PIID_IPHYSICSCONSTRAINTGROUP,
|
||||
PIID_IPHYSICSCONSTRAINT,
|
||||
PIID_IPHYSICSSHADOWCONTROLLER,
|
||||
PIID_IPHYSICSPLAYERCONTROLLER,
|
||||
PIID_IPHYSICSMOTIONCONTROLLER,
|
||||
PIID_IPHYSICSVEHICLECONTROLLER,
|
||||
PIID_IPHYSICSGAMETRACE,
|
||||
|
||||
PIID_NUM_TYPES
|
||||
};
|
||||
|
||||
|
||||
class ISave;
|
||||
class IRestore;
|
||||
|
||||
|
||||
#define VPHYSICS_DEBUG_OVERLAY_INTERFACE_VERSION "VPhysicsDebugOverlay001"
|
||||
|
||||
abstract_class IVPhysicsDebugOverlay
|
||||
{
|
||||
public:
|
||||
virtual void AddEntityTextOverlay(int ent_index, int line_offset, float duration, int r, int g, int b, int a, PRINTF_FORMAT_STRING const char* format, ...) = 0;
|
||||
virtual void AddBoxOverlay(const Vector& origin, const Vector& mins, const Vector& max, QAngle const& orientation, int r, int g, int b, int a, float duration) = 0;
|
||||
virtual void AddTriangleOverlay(const Vector& p1, const Vector& p2, const Vector& p3, int r, int g, int b, int a, bool noDepthTest, float duration) = 0;
|
||||
virtual void AddLineOverlay(const Vector& origin, const Vector& dest, int r, int g, int b,bool noDepthTest, float duration) = 0;
|
||||
virtual void AddTextOverlay(const Vector& origin, float duration, PRINTF_FORMAT_STRING const char* format, ...) = 0;
|
||||
virtual void AddTextOverlay(const Vector& origin, int line_offset, float duration, PRINTF_FORMAT_STRING const char* format, ...) = 0;
|
||||
virtual void AddScreenTextOverlay(float flXPos, float flYPos,float flDuration, int r, int g, int b, int a, const char* text) = 0;
|
||||
virtual void AddSweptBoxOverlay(const Vector& start, const Vector& end, const Vector& mins, const Vector& max, const QAngle& angles, int r, int g, int b, int a, float flDuration) = 0;
|
||||
virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, float r, float g, float b, float alpha, PRINTF_FORMAT_STRING const char* format, ...) = 0;
|
||||
};
|
||||
|
||||
#define VPHYSICS_INTERFACE_VERSION "VPhysics031"
|
||||
|
||||
abstract_class IPhysics : public IAppSystem
|
||||
{
|
||||
public:
|
||||
virtual IPhysicsEnvironment * CreateEnvironment(void) = 0;
|
||||
virtual void DestroyEnvironment(IPhysicsEnvironment*) = 0;
|
||||
virtual IPhysicsEnvironment* GetActiveEnvironmentByIndex(int index) = 0;
|
||||
|
||||
virtual IPhysicsObjectPairHash* CreateObjectPairHash() = 0;
|
||||
virtual void DestroyObjectPairHash(IPhysicsObjectPairHash* pHash) = 0;
|
||||
|
||||
virtual IPhysicsCollisionSet* FindOrCreateCollisionSet(unsigned int id, int maxElementCount) = 0;
|
||||
virtual IPhysicsCollisionSet* FindCollisionSet(unsigned int id) = 0;
|
||||
virtual void DestroyAllCollisionSets() = 0;
|
||||
};
|
||||
|
||||
|
||||
class CPhysConvex;
|
||||
class CPhysPolysoup;
|
||||
class ICollisionQuery;
|
||||
class IVPhysicsKeyParser;
|
||||
struct convertconvexparams_t;
|
||||
class CPackedPhysicsDescription;
|
||||
|
||||
class CPolyhedron;
|
||||
|
||||
struct truncatedcone_t
|
||||
{
|
||||
Vector origin;
|
||||
Vector normal;
|
||||
float h;
|
||||
float theta;
|
||||
};
|
||||
|
||||
|
||||
#define VPHYSICS_COLLISION_INTERFACE_VERSION "VPhysicsCollision007"
|
||||
|
||||
abstract_class IPhysicsCollision
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsCollision(void) {}
|
||||
|
||||
virtual CPhysConvex * ConvexFromVerts(Vector * *pVerts, int vertCount) = 0;
|
||||
virtual CPhysConvex* ConvexFromPlanes(float* pPlanes, int planeCount, float mergeDistance) = 0;
|
||||
virtual float ConvexVolume(CPhysConvex* pConvex) = 0;
|
||||
|
||||
virtual float ConvexSurfaceArea(CPhysConvex* pConvex) = 0;
|
||||
virtual void SetConvexGameData(CPhysConvex* pConvex, unsigned int gameData) = 0;
|
||||
virtual void ConvexFree(CPhysConvex* pConvex) = 0;
|
||||
virtual CPhysConvex* BBoxToConvex(const Vector& mins, const Vector& maxs) = 0;
|
||||
virtual CPhysConvex* ConvexFromConvexPolyhedron(const CPolyhedron& ConvexPolyhedron) = 0;
|
||||
virtual void ConvexesFromConvexPolygon(const Vector& vPolyNormal, const Vector* pPoints, int iPointCount, CPhysConvex** pOutput) = 0;
|
||||
|
||||
virtual CPhysPolysoup* PolysoupCreate(void) = 0;
|
||||
virtual void PolysoupDestroy(CPhysPolysoup* pSoup) = 0;
|
||||
virtual void PolysoupAddTriangle(CPhysPolysoup* pSoup, const Vector& a, const Vector& b, const Vector& c, int materialIndex7bits) = 0;
|
||||
virtual CPhysCollide* ConvertPolysoupToCollide(CPhysPolysoup* pSoup, bool useMOPP) = 0;
|
||||
|
||||
virtual CPhysCollide* ConvertConvexToCollide(CPhysConvex** pConvex, int convexCount) = 0;
|
||||
virtual CPhysCollide* ConvertConvexToCollideParams(CPhysConvex** pConvex, int convexCount, const convertconvexparams_t& convertParams) = 0;
|
||||
virtual void DestroyCollide(CPhysCollide* pCollide) = 0;
|
||||
|
||||
virtual int CollideSize(CPhysCollide* pCollide) = 0;
|
||||
virtual int CollideWrite(char* pDest, CPhysCollide* pCollide, bool bSwap = false) = 0;
|
||||
virtual CPhysCollide* UnserializeCollide(char* pBuffer, int size, int index) = 0;
|
||||
|
||||
virtual float CollideVolume(CPhysCollide* pCollide) = 0;
|
||||
virtual float CollideSurfaceArea(CPhysCollide* pCollide) = 0;
|
||||
|
||||
virtual Vector CollideGetExtent(const CPhysCollide* pCollide, const Vector& collideOrigin, const QAngle& collideAngles, const Vector& direction) = 0;
|
||||
|
||||
virtual void CollideGetAABB(Vector* pMins, Vector* pMaxs, const CPhysCollide* pCollide, const Vector& collideOrigin, const QAngle& collideAngles) = 0;
|
||||
|
||||
virtual void CollideGetMassCenter(CPhysCollide* pCollide, Vector* pOutMassCenter) = 0;
|
||||
virtual void CollideSetMassCenter(CPhysCollide* pCollide, const Vector& massCenter) = 0;
|
||||
virtual Vector CollideGetOrthographicAreas(const CPhysCollide* pCollide) = 0;
|
||||
virtual void CollideSetOrthographicAreas(CPhysCollide* pCollide, const Vector& areas) = 0;
|
||||
|
||||
virtual int CollideIndex(const CPhysCollide* pCollide) = 0;
|
||||
|
||||
virtual CPhysCollide* BBoxToCollide(const Vector& mins, const Vector& maxs) = 0;
|
||||
virtual int GetConvexesUsedInCollideable(const CPhysCollide* pCollideable, CPhysConvex** pOutputArray, int iOutputArrayLimit) = 0;
|
||||
|
||||
|
||||
virtual void TraceBox(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, const CPhysCollide* pCollide, const Vector& collideOrigin, const QAngle& collideAngles, trace_t* ptr) = 0;
|
||||
virtual void TraceBox(const Ray_t& ray, const CPhysCollide* pCollide, const Vector& collideOrigin, const QAngle& collideAngles, trace_t* ptr) = 0;
|
||||
virtual void TraceBox(const Ray_t& ray, unsigned int contentsMask, IConvexInfo* pConvexInfo, const CPhysCollide* pCollide, const Vector& collideOrigin, const QAngle& collideAngles, trace_t* ptr) = 0;
|
||||
|
||||
virtual void TraceCollide(const Vector& start, const Vector& end, const CPhysCollide* pSweepCollide, const QAngle& sweepAngles, const CPhysCollide* pCollide, const Vector& collideOrigin, const QAngle& collideAngles, trace_t* ptr) = 0;
|
||||
|
||||
virtual bool IsBoxIntersectingCone(const Vector& boxAbsMins, const Vector& boxAbsMaxs, const truncatedcone_t& cone) = 0;
|
||||
|
||||
virtual void VCollideLoad(vcollide_t* pOutput, int solidCount, const char* pBuffer, int size, bool swap = false) = 0;
|
||||
virtual void VCollideUnload(vcollide_t* pVCollide) = 0;
|
||||
|
||||
virtual IVPhysicsKeyParser* VPhysicsKeyParserCreate(const char* pKeyData) = 0;
|
||||
virtual void VPhysicsKeyParserDestroy(IVPhysicsKeyParser* pParser) = 0;
|
||||
|
||||
virtual int CreateDebugMesh(CPhysCollide const* pCollisionModel, Vector** outVerts) = 0;
|
||||
virtual void DestroyDebugMesh(int vertCount, Vector* outVerts) = 0;
|
||||
|
||||
virtual ICollisionQuery* CreateQueryModel(CPhysCollide* pCollide) = 0;
|
||||
virtual void DestroyQueryModel(ICollisionQuery* pQuery) = 0;
|
||||
|
||||
virtual IPhysicsCollision* ThreadContextCreate(void) = 0;
|
||||
virtual void ThreadContextDestroy(IPhysicsCollision* pThreadContex) = 0;
|
||||
|
||||
virtual CPhysCollide* CreateVirtualMesh(const virtualmeshparams_t& params) = 0;
|
||||
virtual bool SupportsVirtualMesh() = 0;
|
||||
|
||||
|
||||
virtual bool GetBBoxCacheSize(int* pCachedSize, int* pCachedCount) = 0;
|
||||
|
||||
|
||||
virtual CPolyhedron* PolyhedronFromConvex(CPhysConvex* const pConvex, bool bUseTempPolyhedron) = 0;
|
||||
|
||||
virtual void OutputDebugInfo(const CPhysCollide* pCollide) = 0;
|
||||
virtual unsigned int ReadStat(int statID) = 0;
|
||||
};
|
||||
|
||||
abstract_class ICollisionQuery
|
||||
{
|
||||
public:
|
||||
virtual ~ICollisionQuery() {}
|
||||
virtual int ConvexCount(void) = 0;
|
||||
virtual int TriangleCount(int convexIndex) = 0;
|
||||
virtual unsigned int GetGameData(int convexIndex) = 0;
|
||||
virtual void GetTriangleVerts(int convexIndex, int triangleIndex, Vector* verts) = 0;
|
||||
|
||||
virtual void SetTriangleVerts(int convexIndex, int triangleIndex, const Vector* verts) = 0;
|
||||
|
||||
virtual int GetTriangleMaterialIndex(int convexIndex, int triangleIndex) = 0;
|
||||
virtual void SetTriangleMaterialIndex(int convexIndex, int triangleIndex, int index7bits) = 0;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsGameTrace
|
||||
{
|
||||
public:
|
||||
virtual void VehicleTraceRay(const Ray_t & ray, void* pVehicle, trace_t * pTrace) = 0;
|
||||
virtual void VehicleTraceRayWithWater(const Ray_t& ray, void* pVehicle, trace_t* pTrace) = 0;
|
||||
virtual bool VehiclePointInWater(const Vector& vecPoint) = 0;
|
||||
};
|
||||
|
||||
abstract_class IConvexInfo
|
||||
{
|
||||
public:
|
||||
virtual unsigned int GetContents(int convexGameData) = 0;
|
||||
};
|
||||
|
||||
class CPhysicsEventHandler;
|
||||
abstract_class IPhysicsCollisionData
|
||||
{
|
||||
public:
|
||||
virtual void GetSurfaceNormal(Vector & out) = 0;
|
||||
virtual void GetContactPoint(Vector& out) = 0;
|
||||
virtual void GetContactSpeed(Vector& out) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct vcollisionevent_t
|
||||
{
|
||||
IPhysicsObject* pObjects[2];
|
||||
int surfaceProps[2];
|
||||
bool isCollision;
|
||||
bool isShadowCollision;
|
||||
float deltaCollisionTime;
|
||||
|
||||
float collisionSpeed;
|
||||
IPhysicsCollisionData* pInternalData;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsCollisionEvent
|
||||
{
|
||||
public:
|
||||
virtual void PreCollision(vcollisionevent_t * pEvent) = 0;
|
||||
virtual void PostCollision(vcollisionevent_t* pEvent) = 0;
|
||||
|
||||
virtual void Friction(IPhysicsObject* pObject, float energy, int surfaceProps, int surfacePropsHit, IPhysicsCollisionData* pData) = 0;
|
||||
|
||||
virtual void StartTouch(IPhysicsObject* pObject1, IPhysicsObject* pObject2, IPhysicsCollisionData* pTouchData) = 0;
|
||||
virtual void EndTouch(IPhysicsObject* pObject1, IPhysicsObject* pObject2, IPhysicsCollisionData* pTouchData) = 0;
|
||||
|
||||
virtual void FluidStartTouch(IPhysicsObject* pObject, IPhysicsFluidController* pFluid) = 0;
|
||||
virtual void FluidEndTouch(IPhysicsObject* pObject, IPhysicsFluidController* pFluid) = 0;
|
||||
|
||||
virtual void PostSimulationFrame() = 0;
|
||||
|
||||
virtual void ObjectEnterTrigger(IPhysicsObject* pTrigger, IPhysicsObject* pObject) {}
|
||||
virtual void ObjectLeaveTrigger(IPhysicsObject* pTrigger, IPhysicsObject* pObject) {}
|
||||
};
|
||||
|
||||
|
||||
abstract_class IPhysicsObjectEvent
|
||||
{
|
||||
public:
|
||||
virtual void ObjectWake(IPhysicsObject * pObject) = 0;
|
||||
virtual void ObjectSleep(IPhysicsObject* pObject) = 0;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsConstraintEvent
|
||||
{
|
||||
public:
|
||||
virtual void ConstraintBroken(IPhysicsConstraint*) = 0;
|
||||
};
|
||||
|
||||
struct hlshadowcontrol_params_t
|
||||
{
|
||||
Vector targetPosition;
|
||||
QAngle targetRotation;
|
||||
float maxAngular;
|
||||
float maxDampAngular;
|
||||
float maxSpeed;
|
||||
float maxDampSpeed;
|
||||
float dampFactor;
|
||||
float teleportDistance;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsShadowController
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsShadowController(void) {}
|
||||
|
||||
virtual void Update(const Vector & position, const QAngle & angles, float timeOffset) = 0;
|
||||
virtual void MaxSpeed(float maxSpeed, float maxAngularSpeed) = 0;
|
||||
virtual void StepUp(float height) = 0;
|
||||
|
||||
virtual void SetTeleportDistance(float teleportDistance) = 0;
|
||||
virtual bool AllowsTranslation() = 0;
|
||||
virtual bool AllowsRotation() = 0;
|
||||
|
||||
virtual void SetPhysicallyControlled(bool isPhysicallyControlled) = 0;
|
||||
virtual bool IsPhysicallyControlled() = 0;
|
||||
virtual void GetLastImpulse(Vector* pOut) = 0;
|
||||
virtual void UseShadowMaterial(bool bUseShadowMaterial) = 0;
|
||||
virtual void ObjectMaterialChanged(int materialIndex) = 0;
|
||||
|
||||
|
||||
virtual float GetTargetPosition(Vector* pPositionOut, QAngle* pAnglesOut) = 0;
|
||||
|
||||
virtual float GetTeleportDistance(void) = 0;
|
||||
virtual void GetMaxSpeed(float* pMaxSpeedOut, float* pMaxAngularSpeedOut) = 0;
|
||||
};
|
||||
|
||||
class CPhysicsSimObject;
|
||||
class IPhysicsMotionController;
|
||||
|
||||
class IMotionEvent
|
||||
{
|
||||
public:
|
||||
enum simresult_e { SIM_NOTHING = 0, SIM_LOCAL_ACCELERATION, SIM_LOCAL_FORCE, SIM_GLOBAL_ACCELERATION, SIM_GLOBAL_FORCE };
|
||||
virtual simresult_e Simulate(IPhysicsMotionController* pController, IPhysicsObject* pObject, float deltaTime, Vector& linear, AngularImpulse& angular) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
abstract_class IPhysicsMotionController
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsMotionController(void) {}
|
||||
virtual void SetEventHandler(IMotionEvent * handler) = 0;
|
||||
virtual void AttachObject(IPhysicsObject* pObject, bool checkIfAlreadyAttached) = 0;
|
||||
virtual void DetachObject(IPhysicsObject* pObject) = 0;
|
||||
|
||||
virtual int CountObjects(void) = 0;
|
||||
virtual void GetObjects(IPhysicsObject** pObjectList) = 0;
|
||||
virtual void ClearObjects(void) = 0;
|
||||
virtual void WakeObjects(void) = 0;
|
||||
|
||||
enum priority_t
|
||||
{
|
||||
LOW_PRIORITY = 0,
|
||||
MEDIUM_PRIORITY = 1,
|
||||
HIGH_PRIORITY = 2,
|
||||
};
|
||||
virtual void SetPriority(priority_t priority) = 0;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsCollisionSolver
|
||||
{
|
||||
public:
|
||||
virtual int ShouldCollide(IPhysicsObject * pObj0, IPhysicsObject * pObj1, void* pGameData0, void* pGameData1) = 0;
|
||||
virtual int ShouldSolvePenetration(IPhysicsObject* pObj0, IPhysicsObject* pObj1, void* pGameData0, void* pGameData1, float dt) = 0;
|
||||
|
||||
virtual bool ShouldFreezeObject(IPhysicsObject* pObject) = 0;
|
||||
|
||||
virtual int AdditionalCollisionChecksThisTick(int currentChecksDone) = 0;
|
||||
|
||||
virtual bool ShouldFreezeContacts(IPhysicsObject** pObjectList, int objectCount) = 0;
|
||||
};
|
||||
|
||||
enum PhysicsTraceType_t
|
||||
{
|
||||
VPHYSICS_TRACE_EVERYTHING = 0,
|
||||
VPHYSICS_TRACE_STATIC_ONLY,
|
||||
VPHYSICS_TRACE_MOVING_ONLY,
|
||||
VPHYSICS_TRACE_TRIGGERS_ONLY,
|
||||
VPHYSICS_TRACE_STATIC_AND_MOVING,
|
||||
};
|
||||
|
||||
abstract_class IPhysicsTraceFilter
|
||||
{
|
||||
public:
|
||||
virtual bool ShouldHitObject(IPhysicsObject * pObject, int contentsMask) = 0;
|
||||
virtual PhysicsTraceType_t GetTraceType() const = 0;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsEnvironment
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsEnvironment(void) {}
|
||||
|
||||
virtual void SetDebugOverlay(CreateInterfaceFn debugOverlayFactory) = 0;
|
||||
virtual IVPhysicsDebugOverlay* GetDebugOverlay(void) = 0;
|
||||
|
||||
virtual void SetGravity(const Vector& gravityVector) = 0;
|
||||
virtual void GetGravity(Vector* pGravityVector) const = 0;
|
||||
|
||||
virtual void SetAirDensity(float density) = 0;
|
||||
virtual float GetAirDensity(void) const = 0;
|
||||
|
||||
virtual IPhysicsObject* CreatePolyObject(const CPhysCollide* pCollisionModel, int materialIndex, const Vector& position, const QAngle& angles, objectparams_t* pParams) = 0;
|
||||
virtual IPhysicsObject* CreatePolyObjectStatic(const CPhysCollide* pCollisionModel, int materialIndex, const Vector& position, const QAngle& angles, objectparams_t* pParams) = 0;
|
||||
virtual IPhysicsObject* CreateSphereObject(float radius, int materialIndex, const Vector& position, const QAngle& angles, objectparams_t* pParams, bool isStatic) = 0;
|
||||
virtual void DestroyObject(IPhysicsObject*) = 0;
|
||||
|
||||
virtual IPhysicsFluidController* CreateFluidController(IPhysicsObject* pFluidObject, fluidparams_t* pParams) = 0;
|
||||
virtual void DestroyFluidController(IPhysicsFluidController*) = 0;
|
||||
|
||||
virtual IPhysicsSpring* CreateSpring(IPhysicsObject* pObjectStart, IPhysicsObject* pObjectEnd, springparams_t* pParams) = 0;
|
||||
virtual void DestroySpring(IPhysicsSpring*) = 0;
|
||||
|
||||
virtual IPhysicsConstraint* CreateRagdollConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_ragdollparams_t& ragdoll) = 0;
|
||||
virtual IPhysicsConstraint* CreateHingeConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_hingeparams_t& hinge) = 0;
|
||||
virtual IPhysicsConstraint* CreateFixedConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_fixedparams_t& fixed) = 0;
|
||||
virtual IPhysicsConstraint* CreateSlidingConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_slidingparams_t& sliding) = 0;
|
||||
virtual IPhysicsConstraint* CreateBallsocketConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_ballsocketparams_t& ballsocket) = 0;
|
||||
virtual IPhysicsConstraint* CreatePulleyConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_pulleyparams_t& pulley) = 0;
|
||||
virtual IPhysicsConstraint* CreateLengthConstraint(IPhysicsObject* pReferenceObject, IPhysicsObject* pAttachedObject, IPhysicsConstraintGroup* pGroup, const constraint_lengthparams_t& length) = 0;
|
||||
|
||||
virtual void DestroyConstraint(IPhysicsConstraint*) = 0;
|
||||
|
||||
virtual IPhysicsConstraintGroup* CreateConstraintGroup(const constraint_groupparams_t& groupParams) = 0;
|
||||
virtual void DestroyConstraintGroup(IPhysicsConstraintGroup* pGroup) = 0;
|
||||
|
||||
virtual IPhysicsShadowController* CreateShadowController(IPhysicsObject* pObject, bool allowTranslation, bool allowRotation) = 0;
|
||||
virtual void DestroyShadowController(IPhysicsShadowController*) = 0;
|
||||
|
||||
virtual IPhysicsPlayerController* CreatePlayerController(IPhysicsObject* pObject) = 0;
|
||||
virtual void DestroyPlayerController(IPhysicsPlayerController*) = 0;
|
||||
|
||||
virtual IPhysicsMotionController* CreateMotionController(IMotionEvent* pHandler) = 0;
|
||||
virtual void DestroyMotionController(IPhysicsMotionController* pController) = 0;
|
||||
|
||||
virtual IPhysicsVehicleController* CreateVehicleController(IPhysicsObject* pVehicleBodyObject, const vehicleparams_t& params, unsigned int nVehicleType, IPhysicsGameTrace* pGameTrace) = 0;
|
||||
virtual void DestroyVehicleController(IPhysicsVehicleController*) = 0;
|
||||
|
||||
virtual void SetCollisionSolver(IPhysicsCollisionSolver* pSolver) = 0;
|
||||
|
||||
virtual void Simulate(float deltaTime) = 0;
|
||||
virtual bool IsInSimulation() const = 0;
|
||||
|
||||
virtual float GetSimulationTimestep() const = 0;
|
||||
virtual void SetSimulationTimestep(float timestep) = 0;
|
||||
|
||||
virtual float GetSimulationTime() const = 0;
|
||||
virtual void ResetSimulationClock() = 0;
|
||||
virtual float GetNextFrameTime(void) const = 0;
|
||||
|
||||
virtual void SetCollisionEventHandler(IPhysicsCollisionEvent* pCollisionEvents) = 0;
|
||||
virtual void SetObjectEventHandler(IPhysicsObjectEvent* pObjectEvents) = 0;
|
||||
virtual void SetConstraintEventHandler(IPhysicsConstraintEvent* pConstraintEvents) = 0;
|
||||
|
||||
virtual void SetQuickDelete(bool bQuick) = 0;
|
||||
|
||||
virtual int GetActiveObjectCount() const = 0;
|
||||
virtual void GetActiveObjects(IPhysicsObject** pOutputObjectList) const = 0;
|
||||
virtual const IPhysicsObject** GetObjectList(int* pOutputObjectCount) const = 0;
|
||||
virtual bool TransferObject(IPhysicsObject* pObject, IPhysicsEnvironment* pDestinationEnvironment) = 0;
|
||||
|
||||
virtual void CleanupDeleteList(void) = 0;
|
||||
virtual void EnableDeleteQueue(bool enable) = 0;
|
||||
|
||||
virtual bool Save(const physsaveparams_t& params) = 0;
|
||||
virtual void PreRestore(const physprerestoreparams_t& params) = 0;
|
||||
virtual bool Restore(const physrestoreparams_t& params) = 0;
|
||||
virtual void PostRestore() = 0;
|
||||
|
||||
virtual bool IsCollisionModelUsed(CPhysCollide* pCollide) const = 0;
|
||||
|
||||
virtual void TraceRay(const Ray_t& ray, unsigned int fMask, IPhysicsTraceFilter* pTraceFilter, trace_t* pTrace) = 0;
|
||||
virtual void SweepCollideable(const CPhysCollide* pCollide, const Vector& vecAbsStart, const Vector& vecAbsEnd,
|
||||
const QAngle& vecAngles, unsigned int fMask, IPhysicsTraceFilter* pTraceFilter, trace_t* pTrace) = 0;
|
||||
|
||||
virtual void GetPerformanceSettings(physics_performanceparams_t* pOutput) const = 0;
|
||||
virtual void SetPerformanceSettings(const physics_performanceparams_t* pSettings) = 0;
|
||||
|
||||
virtual void ReadStats(physics_stats_t* pOutput) = 0;
|
||||
virtual void ClearStats() = 0;
|
||||
|
||||
virtual unsigned int GetObjectSerializeSize(IPhysicsObject* pObject) const = 0;
|
||||
virtual void SerializeObjectToBuffer(IPhysicsObject* pObject, unsigned char* pBuffer, unsigned int bufferSize) = 0;
|
||||
virtual IPhysicsObject* UnserializeObjectFromBuffer(void* pGameData, unsigned char* pBuffer, unsigned int bufferSize, bool enableCollisions) = 0;
|
||||
|
||||
|
||||
virtual void EnableConstraintNotify(bool bEnable) = 0;
|
||||
virtual void DebugCheckContacts(void) = 0;
|
||||
};
|
||||
|
||||
enum callbackflags
|
||||
{
|
||||
CALLBACK_GLOBAL_COLLISION = 0x0001,
|
||||
CALLBACK_GLOBAL_FRICTION = 0x0002,
|
||||
CALLBACK_GLOBAL_TOUCH = 0x0004,
|
||||
CALLBACK_GLOBAL_TOUCH_STATIC = 0x0008,
|
||||
CALLBACK_SHADOW_COLLISION = 0x0010,
|
||||
CALLBACK_GLOBAL_COLLIDE_STATIC = 0x0020,
|
||||
CALLBACK_IS_VEHICLE_WHEEL = 0x0040,
|
||||
CALLBACK_FLUID_TOUCH = 0x0100,
|
||||
CALLBACK_NEVER_DELETED = 0x0200,
|
||||
CALLBACK_MARKED_FOR_DELETE = 0x0400,
|
||||
CALLBACK_ENABLING_COLLISION = 0x0800,
|
||||
CALLBACK_DO_FLUID_SIMULATION = 0x1000,
|
||||
CALLBACK_IS_PLAYER_CONTROLLER = 0x2000,
|
||||
CALLBACK_CHECK_COLLISION_DISABLE = 0x4000,
|
||||
CALLBACK_MARKED_FOR_TEST = 0x8000,
|
||||
};
|
||||
|
||||
abstract_class IPhysicsObject
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsObject(void) {}
|
||||
|
||||
virtual bool IsStatic() const = 0;
|
||||
virtual bool IsAsleep() const = 0;
|
||||
virtual bool IsTrigger() const = 0;
|
||||
virtual bool IsFluid() const = 0;
|
||||
virtual bool IsHinged() const = 0;
|
||||
virtual bool IsCollisionEnabled() const = 0;
|
||||
virtual bool IsGravityEnabled() const = 0;
|
||||
virtual bool IsDragEnabled() const = 0;
|
||||
virtual bool IsMotionEnabled() const = 0;
|
||||
virtual bool IsMoveable() const = 0;
|
||||
virtual bool IsAttachedToConstraint(bool bExternalOnly) const = 0;
|
||||
|
||||
virtual void EnableCollisions(bool enable) = 0;
|
||||
virtual void EnableGravity(bool enable) = 0;
|
||||
virtual void EnableDrag(bool enable) = 0;
|
||||
virtual void EnableMotion(bool enable) = 0;
|
||||
|
||||
virtual void SetGameData(void* pGameData) = 0;
|
||||
virtual void* GetGameData(void) const = 0;
|
||||
virtual void SetGameFlags(unsigned short userFlags) = 0;
|
||||
virtual unsigned short GetGameFlags(void) const = 0;
|
||||
virtual void SetGameIndex(unsigned short gameIndex) = 0;
|
||||
virtual unsigned short GetGameIndex(void) const = 0;
|
||||
|
||||
virtual void SetCallbackFlags(unsigned short callbackflags) = 0;
|
||||
virtual unsigned short GetCallbackFlags(void) const = 0;
|
||||
|
||||
virtual void Wake(void) = 0;
|
||||
virtual void Sleep(void) = 0;
|
||||
virtual void RecheckCollisionFilter() = 0;
|
||||
virtual void RecheckContactPoints() = 0;
|
||||
|
||||
virtual void SetMass(float mass) = 0;
|
||||
virtual float GetMass(void) const = 0;
|
||||
virtual float GetInvMass(void) const = 0;
|
||||
virtual Vector GetInertia(void) const = 0;
|
||||
virtual Vector GetInvInertia(void) const = 0;
|
||||
virtual void SetInertia(const Vector& inertia) = 0;
|
||||
|
||||
virtual void SetDamping(const float* speed, const float* rot) = 0;
|
||||
virtual void GetDamping(float* speed, float* rot) const = 0;
|
||||
|
||||
virtual void SetDragCoefficient(float* pDrag, float* pAngularDrag) = 0;
|
||||
virtual void SetBuoyancyRatio(float ratio) = 0;
|
||||
|
||||
virtual int GetMaterialIndex() const = 0;
|
||||
virtual void SetMaterialIndex(int materialIndex) = 0;
|
||||
|
||||
virtual unsigned int GetContents() const = 0;
|
||||
virtual void SetContents(unsigned int contents) = 0;
|
||||
|
||||
virtual float GetSphereRadius() const = 0;
|
||||
virtual float GetEnergy() const = 0;
|
||||
virtual Vector GetMassCenterLocalSpace() const = 0;
|
||||
|
||||
virtual void SetPosition(const Vector& worldPosition, const QAngle& angles, bool isTeleport) = 0;
|
||||
virtual void SetPositionMatrix(const matrix3x4_t& matrix, bool isTeleport) = 0;
|
||||
|
||||
virtual void GetPosition(Vector* worldPosition, QAngle* angles) const = 0;
|
||||
virtual void GetPositionMatrix(matrix3x4_t* positionMatrix) const = 0;
|
||||
virtual void SetVelocity(const Vector* velocity, const AngularImpulse* angularVelocity) = 0;
|
||||
|
||||
virtual void SetVelocityInstantaneous(const Vector* velocity, const AngularImpulse* angularVelocity) = 0;
|
||||
|
||||
virtual void GetVelocity(Vector* velocity, AngularImpulse* angularVelocity) const = 0;
|
||||
|
||||
virtual void AddVelocity(const Vector* velocity, const AngularImpulse* angularVelocity) = 0;
|
||||
virtual void GetVelocityAtPoint(const Vector& worldPosition, Vector* pVelocity) const = 0;
|
||||
virtual void GetImplicitVelocity(Vector* velocity, AngularImpulse* angularVelocity) const = 0;
|
||||
virtual void LocalToWorld(Vector* worldPosition, const Vector& localPosition) const = 0;
|
||||
virtual void WorldToLocal(Vector* localPosition, const Vector& worldPosition) const = 0;
|
||||
|
||||
virtual void LocalToWorldVector(Vector* worldVector, const Vector& localVector) const = 0;
|
||||
virtual void WorldToLocalVector(Vector* localVector, const Vector& worldVector) const = 0;
|
||||
|
||||
virtual void ApplyForceCenter(const Vector& forceVector) = 0;
|
||||
virtual void ApplyForceOffset(const Vector& forceVector, const Vector& worldPosition) = 0;
|
||||
virtual void ApplyTorqueCenter(const AngularImpulse& torque) = 0;
|
||||
|
||||
virtual void CalculateForceOffset(const Vector& forceVector, const Vector& worldPosition, Vector* centerForce, AngularImpulse* centerTorque) const = 0;
|
||||
virtual void CalculateVelocityOffset(const Vector& forceVector, const Vector& worldPosition, Vector* centerVelocity, AngularImpulse* centerAngularVelocity) const = 0;
|
||||
virtual float CalculateLinearDrag(const Vector& unitDirection) const = 0;
|
||||
virtual float CalculateAngularDrag(const Vector& objectSpaceRotationAxis) const = 0;
|
||||
|
||||
virtual bool GetContactPoint(Vector* contactPoint, IPhysicsObject** contactObject) const = 0;
|
||||
|
||||
virtual void SetShadow(float maxSpeed, float maxAngularSpeed, bool allowPhysicsMovement, bool allowPhysicsRotation) = 0;
|
||||
virtual void UpdateShadow(const Vector& targetPosition, const QAngle& targetAngles, bool tempDisableGravity, float timeOffset) = 0;
|
||||
|
||||
virtual int GetShadowPosition(Vector* position, QAngle* angles) const = 0;
|
||||
virtual IPhysicsShadowController* GetShadowController(void) const = 0;
|
||||
virtual void RemoveShadowController() = 0;
|
||||
virtual float ComputeShadowControl(const hlshadowcontrol_params_t& params, float secondsToArrival, float dt) = 0;
|
||||
|
||||
|
||||
virtual const CPhysCollide* GetCollide(void) const = 0;
|
||||
virtual const char* GetName() const = 0;
|
||||
|
||||
virtual void BecomeTrigger() = 0;
|
||||
virtual void RemoveTrigger() = 0;
|
||||
|
||||
virtual void BecomeHinged(int localAxis) = 0;
|
||||
virtual void RemoveHinged() = 0;
|
||||
|
||||
virtual IPhysicsFrictionSnapshot* CreateFrictionSnapshot() = 0;
|
||||
virtual void DestroyFrictionSnapshot(IPhysicsFrictionSnapshot* pSnapshot) = 0;
|
||||
|
||||
virtual void OutputDebugInfo() const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
abstract_class IPhysicsSpring
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsSpring(void) {}
|
||||
virtual void GetEndpoints(Vector * worldPositionStart, Vector * worldPositionEnd) = 0;
|
||||
virtual void SetSpringConstant(float flSpringContant) = 0;
|
||||
virtual void SetSpringDamping(float flSpringDamping) = 0;
|
||||
virtual void SetSpringLength(float flSpringLenght) = 0;
|
||||
|
||||
virtual IPhysicsObject* GetStartObject(void) = 0;
|
||||
|
||||
virtual IPhysicsObject* GetEndObject(void) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct surfacephysicsparams_t
|
||||
{
|
||||
float friction;
|
||||
float elasticity;
|
||||
float density;
|
||||
float thickness;
|
||||
float dampening;
|
||||
};
|
||||
|
||||
struct surfaceaudioparams_t
|
||||
{
|
||||
float reflectivity;
|
||||
float hardnessFactor;
|
||||
float roughnessFactor;
|
||||
|
||||
float roughThreshold;
|
||||
float hardThreshold;
|
||||
float hardVelocityThreshold;
|
||||
};
|
||||
|
||||
struct surfacesoundnames_t
|
||||
{
|
||||
unsigned short stepleft;
|
||||
unsigned short stepright;
|
||||
|
||||
unsigned short impactSoft;
|
||||
unsigned short impactHard;
|
||||
|
||||
unsigned short scrapeSmooth;
|
||||
unsigned short scrapeRough;
|
||||
|
||||
unsigned short bulletImpact;
|
||||
unsigned short rolling;
|
||||
|
||||
unsigned short breakSound;
|
||||
unsigned short strainSound;
|
||||
};
|
||||
|
||||
struct surfacesoundhandles_t
|
||||
{
|
||||
short stepleft;
|
||||
short stepright;
|
||||
|
||||
short impactSoft;
|
||||
short impactHard;
|
||||
|
||||
short scrapeSmooth;
|
||||
short scrapeRough;
|
||||
|
||||
short bulletImpact;
|
||||
short rolling;
|
||||
|
||||
short breakSound;
|
||||
short strainSound;
|
||||
};
|
||||
|
||||
struct surfacegameprops_t
|
||||
{
|
||||
float maxSpeedFactor;
|
||||
float jumpFactor;
|
||||
unsigned short material;
|
||||
unsigned char climbable;
|
||||
unsigned char pad;
|
||||
};
|
||||
|
||||
struct surfacedata_t
|
||||
{
|
||||
surfacephysicsparams_t physics;
|
||||
surfaceaudioparams_t audio;
|
||||
surfacesoundnames_t sounds;
|
||||
surfacegameprops_t game;
|
||||
|
||||
surfacesoundhandles_t soundhandles;
|
||||
};
|
||||
|
||||
#define VPHYSICS_SURFACEPROPS_INTERFACE_VERSION "VPhysicsSurfaceProps001"
|
||||
abstract_class IPhysicsSurfaceProps
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsSurfaceProps(void) {}
|
||||
|
||||
virtual int ParseSurfaceData(const char* pFilename, const char* pTextfile) = 0;
|
||||
virtual int SurfacePropCount(void) const = 0;
|
||||
|
||||
virtual int GetSurfaceIndex(const char* pSurfacePropName) const = 0;
|
||||
virtual void GetPhysicsProperties(int surfaceDataIndex, float* density, float* thickness, float* friction, float* elasticity) const = 0;
|
||||
|
||||
virtual surfacedata_t* GetSurfaceData(int surfaceDataIndex) = 0;
|
||||
virtual const char* GetString(unsigned short stringTableIndex) const = 0;
|
||||
|
||||
|
||||
virtual const char* GetPropName(int surfaceDataIndex) const = 0;
|
||||
|
||||
virtual void SetWorldMaterialIndexTable(int* pMapArray, int mapSize) = 0;
|
||||
|
||||
virtual void GetPhysicsParameters(int surfaceDataIndex, surfacephysicsparams_t* pParamsOut) const = 0;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsFluidController
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsFluidController(void) {}
|
||||
|
||||
virtual void SetGameData(void* pGameData) = 0;
|
||||
virtual void* GetGameData(void) const = 0;
|
||||
|
||||
virtual void GetSurfacePlane(Vector* pNormal, float* pDist) const = 0;
|
||||
virtual float GetDensity() const = 0;
|
||||
virtual void WakeAllSleepingObjects() = 0;
|
||||
virtual int GetContents() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct fluidparams_t
|
||||
{
|
||||
Vector4D surfacePlane;
|
||||
Vector currentVelocity;
|
||||
float damping;
|
||||
float torqueFactor;
|
||||
float viscosityFactor;
|
||||
void* pGameData;
|
||||
bool useAerodynamics;
|
||||
int contents;
|
||||
|
||||
fluidparams_t() {}
|
||||
fluidparams_t(fluidparams_t const& src)
|
||||
{
|
||||
Vector4DCopy(src.surfacePlane, surfacePlane);
|
||||
VectorCopy(src.currentVelocity, currentVelocity);
|
||||
damping = src.damping;
|
||||
torqueFactor = src.torqueFactor;
|
||||
viscosityFactor = src.viscosityFactor;
|
||||
contents = src.contents;
|
||||
}
|
||||
};
|
||||
|
||||
struct springparams_t
|
||||
{
|
||||
springparams_t()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
}
|
||||
float constant;
|
||||
float naturalLength;
|
||||
float damping;
|
||||
float relativeDamping;
|
||||
Vector startPosition;
|
||||
Vector endPosition;
|
||||
bool useLocalPositions;
|
||||
bool onlyStretch;
|
||||
};
|
||||
|
||||
struct objectparams_t
|
||||
{
|
||||
Vector* massCenterOverride;
|
||||
float mass;
|
||||
float inertia;
|
||||
float damping;
|
||||
float rotdamping;
|
||||
float rotInertiaLimit;
|
||||
const char* pName;
|
||||
void* pGameData;
|
||||
float volume;
|
||||
float dragCoefficient;
|
||||
bool enableCollisions;
|
||||
};
|
||||
|
||||
struct convertconvexparams_t
|
||||
{
|
||||
bool buildOuterConvexHull;
|
||||
bool buildDragAxisAreas;
|
||||
bool buildOptimizedTraceTables;
|
||||
float dragAreaEpsilon;
|
||||
CPhysConvex* pForcedOuterHull;
|
||||
|
||||
void Defaults()
|
||||
{
|
||||
dragAreaEpsilon = 0.25f;
|
||||
buildOuterConvexHull = false;
|
||||
buildDragAxisAreas = false;
|
||||
buildOptimizedTraceTables = false;
|
||||
pForcedOuterHull = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct physsaveparams_t
|
||||
{
|
||||
ISave* pSave;
|
||||
void* pObject;
|
||||
PhysInterfaceId_t type;
|
||||
};
|
||||
|
||||
struct physrestoreparams_t
|
||||
{
|
||||
IRestore* pRestore;
|
||||
void** ppObject;
|
||||
PhysInterfaceId_t type;
|
||||
void* pGameData;
|
||||
const char* pName;
|
||||
const CPhysCollide* pCollisionModel;
|
||||
IPhysicsEnvironment* pEnvironment;
|
||||
IPhysicsGameTrace* pGameTrace;
|
||||
};
|
||||
|
||||
struct physrecreateparams_t
|
||||
{
|
||||
void* pOldObject;
|
||||
void* pNewObject;
|
||||
};
|
||||
|
||||
struct physprerestoreparams_t
|
||||
{
|
||||
int recreatedObjectCount;
|
||||
physrecreateparams_t recreatedObjectList[1];
|
||||
};
|
||||
|
||||
#define DEFINE_PIID( type, enumval ) \
|
||||
template <> inline PhysInterfaceId_t GetPhysIID<type>( type ** ) { return enumval; }
|
||||
|
||||
template <class PHYSPTR> inline PhysInterfaceId_t GetPhysIID(PHYSPTR**);
|
||||
|
||||
DEFINE_PIID(IPhysicsObject, PIID_IPHYSICSOBJECT);
|
||||
DEFINE_PIID(IPhysicsFluidController, PIID_IPHYSICSFLUIDCONTROLLER);
|
||||
DEFINE_PIID(IPhysicsSpring, PIID_IPHYSICSSPRING);
|
||||
DEFINE_PIID(IPhysicsConstraintGroup, PIID_IPHYSICSCONSTRAINTGROUP);
|
||||
DEFINE_PIID(IPhysicsConstraint, PIID_IPHYSICSCONSTRAINT);
|
||||
DEFINE_PIID(IPhysicsShadowController, PIID_IPHYSICSSHADOWCONTROLLER);
|
||||
DEFINE_PIID(IPhysicsPlayerController, PIID_IPHYSICSPLAYERCONTROLLER);
|
||||
DEFINE_PIID(IPhysicsMotionController, PIID_IPHYSICSMOTIONCONTROLLER);
|
||||
DEFINE_PIID(IPhysicsVehicleController, PIID_IPHYSICSVEHICLECONTROLLER);
|
||||
DEFINE_PIID(IPhysicsGameTrace, PIID_IPHYSICSGAMETRACE);
|
||||
|
||||
#endif
|
153
SpyCustom/sdk/vplane.h
Normal file
153
SpyCustom/sdk/vplane.h
Normal file
@ -0,0 +1,153 @@
|
||||
#ifndef VPLANE_H
|
||||
#define VPLANE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
typedef int SideType;
|
||||
|
||||
#define SIDE_FRONT 0
|
||||
#define SIDE_BACK 1
|
||||
#define SIDE_ON 2
|
||||
|
||||
#define VP_EPSILON 0.01f
|
||||
|
||||
|
||||
class VPlane
|
||||
{
|
||||
public:
|
||||
VPlane();
|
||||
VPlane(const Vector& vNormal, vec_t dist);
|
||||
|
||||
void Init(const Vector& vNormal, vec_t dist);
|
||||
|
||||
vec_t DistTo(const Vector& vVec) const;
|
||||
|
||||
VPlane& operator=(const VPlane& thePlane);
|
||||
|
||||
SideType GetPointSide(const Vector& vPoint, vec_t sideEpsilon = VP_EPSILON) const;
|
||||
|
||||
SideType GetPointSideExact(const Vector& vPoint) const;
|
||||
|
||||
SideType BoxOnPlaneSide(const Vector& vMin, const Vector& vMax) const;
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
VPlane Flip();
|
||||
|
||||
Vector GetPointOnPlane() const;
|
||||
|
||||
Vector SnapPointToPlane(const Vector& vPoint) const;
|
||||
#endif
|
||||
|
||||
public:
|
||||
Vector m_Normal;
|
||||
vec_t m_Dist;
|
||||
|
||||
#ifdef VECTOR_NO_SLOW_OPERATIONS
|
||||
private:
|
||||
VPlane(const VPlane& vOther);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
inline VPlane::VPlane()
|
||||
{
|
||||
}
|
||||
|
||||
inline VPlane::VPlane(const Vector& vNormal, vec_t dist)
|
||||
{
|
||||
m_Normal = vNormal;
|
||||
m_Dist = dist;
|
||||
}
|
||||
|
||||
inline void VPlane::Init(const Vector& vNormal, vec_t dist)
|
||||
{
|
||||
m_Normal = vNormal;
|
||||
m_Dist = dist;
|
||||
}
|
||||
|
||||
inline vec_t VPlane::DistTo(const Vector& vVec) const
|
||||
{
|
||||
return vVec.Dot(m_Normal) - m_Dist;
|
||||
}
|
||||
|
||||
inline VPlane& VPlane::operator=(const VPlane& thePlane)
|
||||
{
|
||||
m_Normal = thePlane.m_Normal;
|
||||
m_Dist = thePlane.m_Dist;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef VECTOR_NO_SLOW_OPERATIONS
|
||||
|
||||
inline VPlane VPlane::Flip()
|
||||
{
|
||||
return VPlane(-m_Normal, -m_Dist);
|
||||
}
|
||||
|
||||
inline Vector VPlane::GetPointOnPlane() const
|
||||
{
|
||||
return m_Normal * m_Dist;
|
||||
}
|
||||
|
||||
inline Vector VPlane::SnapPointToPlane(const Vector& vPoint) const
|
||||
{
|
||||
return vPoint - m_Normal * DistTo(vPoint);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline SideType VPlane::GetPointSide(const Vector& vPoint, vec_t sideEpsilon) const
|
||||
{
|
||||
vec_t fDist;
|
||||
|
||||
fDist = DistTo(vPoint);
|
||||
if (fDist >= sideEpsilon)
|
||||
return SIDE_FRONT;
|
||||
else if (fDist <= -sideEpsilon)
|
||||
return SIDE_BACK;
|
||||
else
|
||||
return SIDE_ON;
|
||||
}
|
||||
|
||||
inline SideType VPlane::GetPointSideExact(const Vector& vPoint) const
|
||||
{
|
||||
return DistTo(vPoint) > 0.0f ? SIDE_FRONT : SIDE_BACK;
|
||||
}
|
||||
|
||||
|
||||
inline SideType VPlane::BoxOnPlaneSide(const Vector& vMin, const Vector& vMax) const
|
||||
{
|
||||
int i, firstSide, side;
|
||||
TableVector vPoints[8] =
|
||||
{
|
||||
{ vMin.x, vMin.y, vMin.z },
|
||||
{ vMin.x, vMin.y, vMax.z },
|
||||
{ vMin.x, vMax.y, vMax.z },
|
||||
{ vMin.x, vMax.y, vMin.z },
|
||||
|
||||
{ vMax.x, vMin.y, vMin.z },
|
||||
{ vMax.x, vMin.y, vMax.z },
|
||||
{ vMax.x, vMax.y, vMax.z },
|
||||
{ vMax.x, vMax.y, vMin.z },
|
||||
};
|
||||
|
||||
firstSide = GetPointSideExact(vPoints[0]);
|
||||
for (i = 1; i < 8; i++)
|
||||
{
|
||||
side = GetPointSideExact(vPoints[i]);
|
||||
|
||||
if (side != firstSide)
|
||||
return SIDE_ON;
|
||||
}
|
||||
|
||||
return firstSide;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
1359
SpyCustom/sdk/vprof.h
Normal file
1359
SpyCustom/sdk/vprof.h
Normal file
File diff suppressed because it is too large
Load Diff
34
SpyCustom/sdk/vprof_sn.h
Normal file
34
SpyCustom/sdk/vprof_sn.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef TIER_V0PROF_SN_HDR
|
||||
#define TIER_V0PROF_SN_HDR
|
||||
|
||||
#if defined( SN_TARGET_PS3 ) && !defined(_CERT)
|
||||
extern "C" void(*g_pfnPushMarker)(const char* pName);
|
||||
extern "C" void(*g_pfnPopMarker)();
|
||||
|
||||
class CVProfSnMarkerScope
|
||||
{
|
||||
public:
|
||||
CVProfSnMarkerScope(const char* pszName)
|
||||
{
|
||||
g_pfnPushMarker(pszName);
|
||||
}
|
||||
~CVProfSnMarkerScope()
|
||||
{
|
||||
g_pfnPopMarker();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#define SNPROF(name) ((void)0)
|
||||
#define SNPROF_ANIM(name) ((void)0)
|
||||
|
||||
#else
|
||||
|
||||
class CVProfSnMarkerScope { public: CVProfSnMarkerScope(const char*) {} };
|
||||
|
||||
#define SNPROF(name) TM_ZONE( TELEMETRY_LEVEL1, TMZF_NONE, "%s", name );
|
||||
#define SNPROF_ANIM(name) TM_ZONE( TELEMETRY_LEVEL1, TMZF_NONE, "anim %s", name );
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
471
SpyCustom/sdk/vprof_telemetry.h
Normal file
471
SpyCustom/sdk/vprof_telemetry.h
Normal file
@ -0,0 +1,471 @@
|
||||
#ifndef VPROF_TELEMETRY_H
|
||||
#define VPROF_TELEMETRY_H
|
||||
|
||||
#if !defined( MAKE_VPC )
|
||||
|
||||
#if !defined( RAD_TELEMETRY_DISABLED ) && ( defined( IS_WINDOWS_PC ) || defined( _LINUX ) )
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
enum TelemetryZonePlotSlot_t
|
||||
{
|
||||
TELEMETRY_ZONE_PLOT_SLOT_1,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_2,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_3,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_4,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_5,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_6,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_7,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_8,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_9,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_10,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_11,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_12,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_13,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_14,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_15,
|
||||
TELEMETRY_ZONE_PLOT_SLOT_16,
|
||||
|
||||
TELEMETRY_ZONE_PLOT_SLOT_MAX
|
||||
};
|
||||
|
||||
|
||||
#if !defined( RAD_TELEMETRY_ENABLED )
|
||||
|
||||
#define NTELEMETRY 1
|
||||
#undef RADCOPYRIGHT
|
||||
|
||||
inline void TelemetryTick() {}
|
||||
inline void TelemetrySetLevel(unsigned int Level) {}
|
||||
|
||||
#define TELEMETRY_REQUIRED( tmRequiredCode )
|
||||
#define TELEMETRY_REQUIRED_REPLACE( tmRequiredCode, replacementCode ) replacementCode
|
||||
|
||||
#else
|
||||
|
||||
#include "../../thirdparty/telemetry/include/telemetry.h"
|
||||
#undef RADCOPYRIGHT
|
||||
|
||||
PLATFORM_INTERFACE void TelemetryTick();
|
||||
PLATFORM_INTERFACE void TelemetrySetLevel(unsigned int Level);
|
||||
|
||||
struct TelemetryZonePlotData
|
||||
{
|
||||
const char* m_Name;
|
||||
TmU64 m_CurrFrameTime;
|
||||
};
|
||||
|
||||
struct TelemetryData
|
||||
{
|
||||
HTELEMETRY tmContext[32];
|
||||
float flRDTSCToMilliSeconds;
|
||||
uint32 FrameCount;
|
||||
char ServerAddress[128];
|
||||
uint32 ZoneFilterVal;
|
||||
int playbacktick;
|
||||
float dotatime;
|
||||
uint32 DemoTickStart;
|
||||
uint32 DemoTickEnd;
|
||||
uint32 Level;
|
||||
TelemetryZonePlotData m_ZonePlot[TELEMETRY_ZONE_PLOT_SLOT_MAX];
|
||||
};
|
||||
PLATFORM_INTERFACE TelemetryData g_Telemetry;
|
||||
|
||||
#define TELEMETRY_REQUIRED( tmRequiredCode ) tmRequiredCode
|
||||
#define TELEMETRY_REQUIRED_REPLACE( tmRequiredCode, replacementCode ) tmRequiredCode
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define TELEMETRY_ERROR_BUILD_DISABLED TELEMETRY_REQUIRED_REPLACE( TMERR_DISABLED, 0x0001 )
|
||||
#define TELEMETRY_ERROR_DISCONNECTED TELEMETRY_REQUIRED_REPLACE( TMCS_DISCONNECTED, 0 )
|
||||
|
||||
|
||||
#define TELEMETRY_LEVEL0 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[0], 0 )
|
||||
#define TELEMETRY_LEVEL1 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[1], 0 )
|
||||
#define TELEMETRY_LEVEL2 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[2], 0 )
|
||||
#define TELEMETRY_LEVEL3 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[3], 0 )
|
||||
#define TELEMETRY_LEVEL4 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[4], 0 )
|
||||
#define TELEMETRY_LEVEL5 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[5], 0 )
|
||||
#define TELEMETRY_LEVEL6 TELEMETRY_REQUIRED_REPLACE( g_Telemetry.tmContext[6], 0 )
|
||||
|
||||
#define TM_FAST_TIME() TELEMETRY_REQUIRED_REPLACE( tmFastTime(), 0 )
|
||||
|
||||
|
||||
#define TM_LOAD_TELEMETRY(kUseCheckedDll) TELEMETRY_REQUIRED_REPLACE( tmLoadTelemetry(kUseCheckedDll), 0 )
|
||||
|
||||
|
||||
#define TM_STARTUP() TELEMETRY_REQUIRED_REPLACE( tmStartup(), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_SHUTDOWN() TELEMETRY_REQUIRED( tmShutdown() )
|
||||
|
||||
|
||||
#define TM_INITIALIZE_CONTEXT( pContext, pArena, kArenaSize ) TELEMETRY_REQUIRED_REPLACE( tmInitializeContext( pContext, pArena, kArenaSize ), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_ZONE_FILTERED( context, kThreshold, kFlags, kpFormat, ... ) TELEMETRY_REQUIRED( tmZoneFiltered( context, kThreshold, kFlags, kpFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_ZONE( context, kFlags, kpFormat, ... ) TELEMETRY_REQUIRED( tmZone( context, kFlags, kpFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
#define TM_ZONE_DEFAULT( context ) TM_ZONE( context, TMZF_NONE, __FUNCTION__ )
|
||||
#define TM_ZONE_IDLE( context ) TM_ZONE( context, TMZF_IDLE, __FUNCTION__ )
|
||||
#define TM_ZONE_STALL( context ) TM_ZONE( context, TMZF_STALL, __FUNCTION__ )
|
||||
|
||||
|
||||
#define TM_CHECK_VERSION( context, major, minor, build, cust ) TELEMETRY_REQUIRED_REPLACE( tmCheckVersion( context, major, minor, build, cust ), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_LISTEN_IPC( context, name ) TELEMETRY_REQUIRED_REPLACE( tmListenIPC( context, name ), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_UPDATE_SYMBOL_DATA( context ) TELEMETRY_REQUIRED( tmUpdateSymbolData( context ) )
|
||||
|
||||
|
||||
#define TM_GET_SESSION_NAME( context, dst, kDstSize ) TELEMETRY_REQUIRED_REPLACE( tmGetSessionName( context, dst, kDstSize ), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_UNWIND_TO_DEBUG_ZONE_LEVEL( context, kLevel ) TELEMETRY_REQUIRED( tmUnwindToDebugZoneLevel( context, kLevel ) )
|
||||
|
||||
|
||||
#define TM_SET_DEBUG_ZONE_LEVEL( context, kLevel ) TELEMETRY_REQUIRED( tmSetDebugZoneLevel( context, kLevel ) )
|
||||
|
||||
|
||||
#define TM_CHECK_DEBUG_ZONE_LEVEL( context, kLevel ) TELEMETRY_REQUIRED( tmCheckDebugZoneLevel( context, kLevel ) )
|
||||
|
||||
|
||||
#define TM_GET_CALL_STACK( context, TmCallStack_Ptr ) TELEMETRY_REQUIRED_REPLACE( tmGetCallStack( context, TmCallStack_Ptr ), 0 )
|
||||
|
||||
|
||||
#define TM_SEND_CALL_STACK( context, TmCallStack_Ptr ) TELEMETRY_REQUIRED_REPLACE( tmSendCallStack( context, TmCallStack_Ptr ), 0 )
|
||||
|
||||
|
||||
#define TM_GET_LAST_ERROR( context ) TELEMETRY_REQUIRED_REPLACE( tmGetLastError( context ), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_SHUTDOWN_CONTEXT( context ) TELEMETRY_REQUIRED( tmShutdownContext( context ) )
|
||||
|
||||
|
||||
#define TM_GET_ACCUMULATION_START( context ) TELEMETRY_REQUIRED_REPLACE( tmGetAccumulationStart( context ), 0 )
|
||||
|
||||
|
||||
#define TM_GET_LAST_CONTEXT_SWITCH_TIME( context ) TELEMETRY_REQUIRED_REPLACE( tmGetLastContextSwitchTime( context ), 0 )
|
||||
|
||||
|
||||
#define TM_ENTER_ACCUMULATION_ZONE( context, zone_variable ) TELEMETRY_REQUIRED( tmEnterAccumulationZone( context, zone_variable ) )
|
||||
|
||||
|
||||
#define TM_LEAVE_ACCUMULATION_ZONE( context, zone_variable ) TELEMETRY_REQUIRED( tmLeaveAccumulationZone( context, zone_variable ) )
|
||||
|
||||
|
||||
#define TM_GET_FORMAT_CODE( context, pCode, kpFmt ) TELEMETRY_REQUIRED( tmGetFormatCode( context, pCode, kpFmt ) )
|
||||
|
||||
|
||||
#define TM_DYNAMIC_STRING( context, kpString ) TELEMETRY_REQUIRED_REPLACE( tmDynamicString( context, kpString ), NULL )
|
||||
|
||||
|
||||
#define TM_CLEAR_STATIC_STRING( context, kpString ) TELEMETRY_REQUIRED( tmClearStaticString( context, kpString ) )
|
||||
|
||||
|
||||
#define TM_ENABLE( context, kOption, kValue ) TELEMETRY_REQUIRED( tmEnable( context, kOption, kValue ) )
|
||||
|
||||
|
||||
#define TM_IS_ENABLED( context, kOption ) TELEMETRY_REQUIRED_REPLACE( tmIsEnabled( context, kOption ), 0 )
|
||||
|
||||
#define TM_SET_PARAMETER( context, kParameter, kpValue ) TELEMETRY_REQUIRED( tmSetParameter( context, kParameter, kpValue ) )
|
||||
|
||||
|
||||
#define TM_OPEN( context, kpAppName, kpBuildInfo, kpServerAddress, kConnection, kServerPort, kFlags, kTimeoutMS ) TELEMETRY_REQUIRED_REPLACE( tmOpen( context, kpAppName, kpBuildInfo, kpServerAddress, kConnection, kServerPort, kFlags, kTimeoutMS ), TELEMETRY_ERROR_BUILD_DISABLED )
|
||||
|
||||
|
||||
#define TM_CLOSE( context ) TELEMETRY_REQUIRED( tmClose( context ) )
|
||||
|
||||
|
||||
#define TM_TICK( context ) TELEMETRY_REQUIRED( tmTick( context ) )
|
||||
|
||||
|
||||
#define TM_FLUSH( context ) TELEMETRY_REQUIRED( tmFlush( context ) )
|
||||
|
||||
|
||||
#define TM_PAUSE( context, kPause ) TELEMETRY_REQUIRED( tmPause( context, kPause ) )
|
||||
|
||||
|
||||
#define TM_IS_PAUSED( context ) TELEMETRY_REQUIRED_REPLACE( tmIsPaused( context ), 0 )
|
||||
|
||||
|
||||
#define TM_GET_CONNECTION_STATUS( context ) TELEMETRY_REQUIRED_REPLACE( tmGetConnectionStatus( context ), TELEMETRY_ERROR_DISCONNECTED )
|
||||
|
||||
|
||||
#define TM_FREE( context, kpPtr ) TELEMETRY_REQUIRED( tmFree( context, kpPtr ) )
|
||||
|
||||
|
||||
#define TM_GET_STAT_I( context, kStat ) TELEMETRY_REQUIRED_REPLACE( tmGetStati( context, kStat ), 0 )
|
||||
|
||||
|
||||
#define TM_LEAVE( context ) TELEMETRY_REQUIRED( tmLeave( context ) )
|
||||
|
||||
|
||||
#define TM_LEAVE_EX( context, kMatchId, kThreadId, kpFilename, kLine ) TELEMETRY_REQUIRED( tmLeaveEx( context, kMatchId, kThreadId, kpFilename, kLine ) )
|
||||
|
||||
|
||||
#define TM_TRY_LOCK( context, kPtr, kpLockName, ... ) TELEMETRY_REQUIRED( tmTryLock( context, kPtr, kpLockName, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_TRY_LOCK_EX( context, matcher, kThreshold, kpFileName, kLine, kPtr, kpLockName, ... ) TELEMETRY_REQUIRED( tmTryLockEx( context, matcher, kThreshold, kpFileName, kLine, kPtr, kpLockName, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_END_TRY_LOCK( context, kPtr, kResult ) TELEMETRY_REQUIRED( tmEndTryLock( context, kPtr, kResult ) )
|
||||
|
||||
|
||||
#define TM_END_TRY_LOCK_EX( context, kMatchId, kpFileName, kLine, kPtr, kResult ) TELEMETRY_REQUIRED( tmEndTryLockEx( context, kMatchId, kpFileName, kLine, kPtr, kResult ) )
|
||||
|
||||
|
||||
#define TM_BEGIN_TIME_SPAN( context, kId, kFlags, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmBeginTimeSpan( context, kId, kFlags, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_END_TIME_SPAN( context, kId, kFlags, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmEndTimeSpan( context, kId, kFlags, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_BEGIN_TIME_SPAN_AT( context, kId, kFlags, kTimeStamp, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmBeginTimeSpanAt( context, kId, kFlags, kTimeStamp, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_END_TIME_SPAN_AT( context, kId, kFlags, kTimeStamp, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmEndTimeSpanAt( context, kId, kFlags, kTimeStamp, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SIGNAL_LOCK_COUNT( context, kPtr, kCount, kpDescription, ... ) TELEMETRY_REQUIRED( tmSignalLockCount( context, kPtr, kCount, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SET_LOCK_STATE( context, kPtr, kState, kpDescription, ... ) TELEMETRY_REQUIRED( tmSetLockState( context, kPtr, kState, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SET_LOCK_STATE_EX( context, kpFileName, kLine, kPtr, kState, kpDescription, ... ) TELEMETRY_REQUIRED( tmSetLockStateEx( context, kpFileName, kLine, kPtr, kState, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SET_LOCK_STATE_MIN_TIME( context, buf, kPtr, kState, kpDescription, ... ) TELEMETRY_REQUIRED( tmSetLockStateMinTime( context, buf, kPtr, kState, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SET_LOCK_STATE_MIN_TIME_EX( context, buf, kpFilename, kLine, kPtr, kState, kpDescription, ... ) TELEMETRY_REQUIRED( tmSetLockStateMinTimeEx( context, buf, kpFilename, kLine, kPtr, kState, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_THREAD_NAME( context, kThreadID, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmThreadName( context, kThreadID, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_LOCK_NAME( context, kPtr, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmLockName( context, kPtr, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_EMIT_ACCUMULATION_ZONE( context, kZoneFlags, pStart, kCount, kTotal, kpZoneFormat, ... ) TELEMETRY_REQUIRED( tmEmitAccumulationZone( context, kZoneFlags, pStart, kCount, kTotal, kpZoneFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SET_VARIABLE( context, kpKey, kpValueFormat, ... ) TELEMETRY_REQUIRED( tmSetVariable( context, kpKey, kpValueFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_SET_TIMELINE_SECTION_NAME( context, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmSetTimelineSectionName( context, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_ENTER( context, kFlags, kpZoneName, ... ) TELEMETRY_REQUIRED( tmEnter( context, kFlags, kpZoneName, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_ENTER_EX( context, pMatchId, kThreadId, kThreshold, kpFilename, kLine, kFlags, kpZoneName, ... ) TELEMETRY_REQUIRED( tmEnterEx( context, pMatchId, kThreadId, kThreshold, kpFilename, kLine, kFlags, kpZoneName, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_ALLOC( context, kPtr, kSize, kpDescription, ... ) TELEMETRY_REQUIRED( tmAlloc( context, kPtr, kSize, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_ALLOC_EX( context, kpFilename, kLineNumber, kPtr, kSize, kpDescription, ... ) TELEMETRY_REQUIRED( tmAllocEx( context, kpFilename, kLineNumber, kPtr, kSize, kpDescription, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_MESSAGE( context, kFlags, kpFormatString, ... ) TELEMETRY_REQUIRED( tmMessage( context, kFlags, kpFormatString, ##__VA_ARGS__ ) )
|
||||
#define TM_LOG( context, kpFormatString, ... ) TM_MESSAGE( context, TMMF_SEVERITY_LOG, kpFormatString, ##__VA_ARGS__ )
|
||||
#define TM_WARNING( context, kpFormatString, ... ) TM_MESSAGE( context, TMMF_SEVERITY_WARNING, kpFormatString, ##__VA_ARGS__ )
|
||||
#define TM_ERROR( context, kpFormatString, ... ) TM_MESSAGE( context, TMMF_SEVERITY_ERROR, kpFormatString, ##__VA_ARGS__ )
|
||||
|
||||
|
||||
|
||||
#define TM_PLOT( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlot( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_PLOT_F32( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlotF32( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_PLOT_F64( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlotF64( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_PLOT_I32( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlotI32( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_PLOT_U32( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlotU32( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_PLOT_I64( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlotI64( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_PLOT_U64( context, kType, kFlags, kValue, kpNameFormat, ... ) TELEMETRY_REQUIRED( tmPlotU64( context, kType, kFlags, kValue, kpNameFormat, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_BLOB( context, kpData, kDataSize, kpPluginIdentifier, kpBlobName, ...) TELEMETRY_REQUIRED( tmBlob( context, kpData, kDataSize, kpPluginIdentifier, kpBlobName, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
#define TM_DISJOINT_BLOB( context, kNumPieces, kpData, kDataSizes, kpPluginIdentifier, kpBlobName, ... ) TELEMETRY_REQUIRED( tmDisjointBlob( context, kNumPieces, kpData, kDataSizes, kpPluginIdentifier, kpBlobName, ##__VA_ARGS__ ) )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined( RAD_TELEMETRY_ENABLED )
|
||||
|
||||
class CTelemetryLock
|
||||
{
|
||||
public:
|
||||
CTelemetryLock(void* plocation, const char* description) {}
|
||||
~CTelemetryLock() {}
|
||||
void Locked() {}
|
||||
void Unlocked() {}
|
||||
};
|
||||
|
||||
class CTelemetrySpikeDetector
|
||||
{
|
||||
public:
|
||||
CTelemetrySpikeDetector(const char* msg, unsigned int threshold = 50) {}
|
||||
~CTelemetrySpikeDetector() { }
|
||||
};
|
||||
|
||||
class CTelemetryZonePlotScope
|
||||
{
|
||||
public:
|
||||
|
||||
CTelemetryZonePlotScope(const char* pName, TelemetryZonePlotSlot_t slot) {}
|
||||
~CTelemetryZonePlotScope() {}
|
||||
};
|
||||
|
||||
#define TelemetrySetLockName( _ctx, _location, _description )
|
||||
#define TM_ZONE_PLOT( context, name, slot )
|
||||
|
||||
#else
|
||||
|
||||
#define TelemetrySetLockName( _ctx, _location, _description ) \
|
||||
do \
|
||||
{ \
|
||||
static bool s_bNameSet = false; \
|
||||
if( _ctx && !s_bNameSet ) \
|
||||
{ \
|
||||
tmLockName( _ctx, _location, _description ); \
|
||||
s_bNameSet = true; \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
class CTelemetryLock
|
||||
{
|
||||
public:
|
||||
CTelemetryLock(void* plocation, const char* description)
|
||||
{
|
||||
m_plocation = (const char*)plocation;
|
||||
m_description = description;
|
||||
TelemetrySetLockName(TELEMETRY_LEVEL1, m_plocation, m_description);
|
||||
TM_TRY_LOCK(TELEMETRY_LEVEL1, m_plocation, "%s", m_description);
|
||||
}
|
||||
~CTelemetryLock()
|
||||
{
|
||||
Unlocked();
|
||||
}
|
||||
void Locked()
|
||||
{
|
||||
TM_END_TRY_LOCK(TELEMETRY_LEVEL1, m_plocation, TMLR_SUCCESS);
|
||||
TM_SET_LOCK_STATE(TELEMETRY_LEVEL1, m_plocation, TMLS_LOCKED, "%s Locked", m_description);
|
||||
}
|
||||
void Unlocked()
|
||||
{
|
||||
if (m_plocation)
|
||||
{
|
||||
TM_SET_LOCK_STATE(TELEMETRY_LEVEL1, m_plocation, TMLS_RELEASED, "%s Released", m_description);
|
||||
m_plocation = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
const char* m_plocation;
|
||||
const char* m_description;
|
||||
};
|
||||
|
||||
class CTelemetrySpikeDetector
|
||||
{
|
||||
public:
|
||||
CTelemetrySpikeDetector(const char* msg, float threshold = 5) :
|
||||
m_message(msg), m_threshold(threshold), time0(tmFastTime()) {}
|
||||
~CTelemetrySpikeDetector()
|
||||
{
|
||||
float time = (tmFastTime() - time0) * g_Telemetry.flRDTSCToMilliSeconds;
|
||||
if (time >= m_threshold)
|
||||
{
|
||||
TM_MESSAGE(TELEMETRY_LEVEL0, TMMF_ICON_NOTE | TMMF_SEVERITY_WARNING, "(dota/spike)%s %.2fms %t", m_message, time, tmSendCallStack(TELEMETRY_LEVEL0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
TmU64 time0;
|
||||
float m_threshold;
|
||||
const char* m_message;
|
||||
};
|
||||
|
||||
#define TM_ZONE_PLOT( context, name, slot ) CTelemetryZonePlotScope _telemetryZonePlot##__LINE__(context, name, slot);
|
||||
|
||||
class CTelemetryZonePlotScope
|
||||
{
|
||||
public:
|
||||
|
||||
CTelemetryZonePlotScope(HTELEMETRY context, const char* pName, TelemetryZonePlotSlot_t slot)
|
||||
:
|
||||
m_Context(context),
|
||||
m_SlotData(NULL),
|
||||
m_StartTime(0)
|
||||
{
|
||||
if (slot < TELEMETRY_ZONE_PLOT_SLOT_MAX)
|
||||
{
|
||||
m_SlotData = &g_Telemetry.m_ZonePlot[slot];
|
||||
m_SlotData->m_Name = pName;
|
||||
m_StartTime = TM_FAST_TIME();
|
||||
}
|
||||
TM_ENTER(m_Context, TMZF_NONE, "%s", pName);
|
||||
}
|
||||
|
||||
~CTelemetryZonePlotScope()
|
||||
{
|
||||
TM_LEAVE(m_Context);
|
||||
if (m_SlotData)
|
||||
{
|
||||
m_SlotData->m_CurrFrameTime += (TM_FAST_TIME() - m_StartTime);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
HTELEMETRY m_Context;
|
||||
TelemetryZonePlotData* m_SlotData;
|
||||
TmU64 m_StartTime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
22
SpyCustom/sdk/vstdlib.h
Normal file
22
SpyCustom/sdk/vstdlib.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef VSTDLIB_H
|
||||
#define VSTDLIB_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef VSTDLIB_DLL_EXPORT
|
||||
#define VSTDLIB_INTERFACE DLL_EXPORT
|
||||
#define VSTDLIB_OVERLOAD DLL_GLOBAL_EXPORT
|
||||
#define VSTDLIB_CLASS DLL_CLASS_EXPORT
|
||||
#define VSTDLIB_GLOBAL DLL_GLOBAL_EXPORT
|
||||
#else
|
||||
#define VSTDLIB_INTERFACE DLL_IMPORT
|
||||
#define VSTDLIB_OVERLOAD DLL_GLOBAL_IMPORT
|
||||
#define VSTDLIB_CLASS DLL_CLASS_IMPORT
|
||||
#define VSTDLIB_GLOBAL DLL_GLOBAL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif
|
410
SpyCustom/sdk/vtf.h
Normal file
410
SpyCustom/sdk/vtf.h
Normal file
@ -0,0 +1,410 @@
|
||||
#ifndef VTF_H
|
||||
#define VTF_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "imageformat.h"
|
||||
#include "platform.h"
|
||||
|
||||
#ifndef VTF_FILE_FORMAT_ONLY
|
||||
|
||||
class CUtlBuffer;
|
||||
class Vector;
|
||||
struct Rect_t;
|
||||
class IFileSystem;
|
||||
|
||||
enum CompiledVtfFlags
|
||||
{
|
||||
TEXTUREFLAGS_POINTSAMPLE = 0x00000001,
|
||||
TEXTUREFLAGS_TRILINEAR = 0x00000002,
|
||||
TEXTUREFLAGS_CLAMPS = 0x00000004,
|
||||
TEXTUREFLAGS_CLAMPT = 0x00000008,
|
||||
TEXTUREFLAGS_ANISOTROPIC = 0x00000010,
|
||||
TEXTUREFLAGS_HINT_DXT5 = 0x00000020,
|
||||
TEXTUREFLAGS_SRGB = 0x00000040,
|
||||
TEXTUREFLAGS_NORMAL = 0x00000080,
|
||||
TEXTUREFLAGS_NOMIP = 0x00000100,
|
||||
TEXTUREFLAGS_NOLOD = 0x00000200,
|
||||
TEXTUREFLAGS_ALL_MIPS = 0x00000400,
|
||||
TEXTUREFLAGS_PROCEDURAL = 0x00000800,
|
||||
|
||||
TEXTUREFLAGS_ONEBITALPHA = 0x00001000,
|
||||
TEXTUREFLAGS_EIGHTBITALPHA = 0x00002000,
|
||||
|
||||
TEXTUREFLAGS_ENVMAP = 0x00004000,
|
||||
TEXTUREFLAGS_RENDERTARGET = 0x00008000,
|
||||
TEXTUREFLAGS_DEPTHRENDERTARGET = 0x00010000,
|
||||
TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000,
|
||||
TEXTUREFLAGS_SINGLECOPY = 0x00040000,
|
||||
|
||||
TEXTUREFLAGS_STAGING_MEMORY = 0x00080000,
|
||||
TEXTUREFLAGS_IMMEDIATE_CLEANUP = 0x00100000,
|
||||
TEXTUREFLAGS_IGNORE_PICMIP = 0x00200000,
|
||||
TEXTUREFLAGS_UNUSED_00400000 = 0x00400000,
|
||||
|
||||
TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000,
|
||||
|
||||
TEXTUREFLAGS_UNUSED_01000000 = 0x01000000,
|
||||
|
||||
TEXTUREFLAGS_CLAMPU = 0x02000000,
|
||||
|
||||
TEXTUREFLAGS_VERTEXTEXTURE = 0x04000000,
|
||||
|
||||
TEXTUREFLAGS_SSBUMP = 0x08000000,
|
||||
|
||||
TEXTUREFLAGS_UNUSED_10000000 = 0x10000000,
|
||||
|
||||
TEXTUREFLAGS_BORDER = 0x20000000,
|
||||
|
||||
TEXTUREFLAGS_UNUSED_40000000 = 0x40000000,
|
||||
TEXTUREFLAGS_UNUSED_80000000 = 0x80000000,
|
||||
};
|
||||
|
||||
enum VersionedVtfFlags
|
||||
{
|
||||
VERSIONED_VTF_FLAGS_MASK_7_3 = ~0xD1780400,
|
||||
};
|
||||
|
||||
|
||||
struct VtfProcessingOptions
|
||||
{
|
||||
uint32 cbSize;
|
||||
|
||||
enum Flags0
|
||||
{
|
||||
OPT_DECAY_R = 0x00000001,
|
||||
OPT_DECAY_G = 0x00000002,
|
||||
OPT_DECAY_B = 0x00000004,
|
||||
OPT_DECAY_A = 0x00000008,
|
||||
|
||||
OPT_DECAY_EXP_R = 0x00000010,
|
||||
OPT_DECAY_EXP_G = 0x00000020,
|
||||
OPT_DECAY_EXP_B = 0x00000040,
|
||||
OPT_DECAY_EXP_A = 0x00000080,
|
||||
|
||||
OPT_NOCOMPRESS = 0x00000100,
|
||||
OPT_NORMAL_DUDV = 0x00000200,
|
||||
OPT_FILTER_NICE = 0x00000400,
|
||||
|
||||
OPT_SET_ALPHA_ONEOVERMIP = 0x00001000,
|
||||
OPT_PREMULT_COLOR_ONEOVERMIP = 0x00002000,
|
||||
OPT_MIP_ALPHATEST = 0x00004000,
|
||||
};
|
||||
|
||||
uint32 flags0;
|
||||
|
||||
uint8 clrDecayGoal[4];
|
||||
uint8 numNotDecayMips[4];
|
||||
float fDecayExponentBase[4];
|
||||
};
|
||||
|
||||
|
||||
enum CubeMapFaceIndex_t
|
||||
{
|
||||
CUBEMAP_FACE_RIGHT = 0,
|
||||
CUBEMAP_FACE_LEFT,
|
||||
CUBEMAP_FACE_BACK,
|
||||
CUBEMAP_FACE_FRONT,
|
||||
CUBEMAP_FACE_UP,
|
||||
CUBEMAP_FACE_DOWN,
|
||||
|
||||
CUBEMAP_FACE_SPHEREMAP,
|
||||
|
||||
CUBEMAP_FACE_COUNT
|
||||
};
|
||||
|
||||
|
||||
enum LookDir_t
|
||||
{
|
||||
LOOK_DOWN_X = 0,
|
||||
LOOK_DOWN_NEGX,
|
||||
LOOK_DOWN_Y,
|
||||
LOOK_DOWN_NEGY,
|
||||
LOOK_DOWN_Z,
|
||||
LOOK_DOWN_NEGZ,
|
||||
};
|
||||
|
||||
|
||||
#define IMAGE_FORMAT_DEFAULT ((ImageFormat)-2)
|
||||
|
||||
class IVTFTexture
|
||||
{
|
||||
public:
|
||||
virtual ~IVTFTexture() {}
|
||||
|
||||
virtual bool Init(int nWidth, int nHeight, int nDepth, ImageFormat fmt, int nFlags, int iFrameCount, int nForceMipCount = -1) = 0;
|
||||
|
||||
virtual void SetBumpScale(float flScale) = 0;
|
||||
virtual void SetReflectivity(const Vector& vecReflectivity) = 0;
|
||||
|
||||
virtual void InitLowResImage(int nWidth, int nHeight, ImageFormat fmt) = 0;
|
||||
|
||||
virtual void* SetResourceData(uint32 eType, void const* pData, size_t nDataSize) = 0;
|
||||
|
||||
virtual void* GetResourceData(uint32 eType, size_t* pDataSize) const = 0;
|
||||
|
||||
virtual bool HasResourceEntry(uint32 eType) const = 0;
|
||||
|
||||
virtual unsigned int GetResourceTypes(uint32* arrTypesBuffer, int numTypesBufferElems) const = 0;
|
||||
|
||||
virtual bool Unserialize(CUtlBuffer& buf, bool bHeaderOnly = false, int nSkipMipLevels = 0) = 0;
|
||||
virtual bool Serialize(CUtlBuffer& buf) = 0;
|
||||
|
||||
virtual void LowResFileInfo(int* pStartLocation, int* pSizeInBytes) const = 0;
|
||||
virtual void ImageFileInfo(int nFrame, int nFace, int nMip, int* pStartLocation, int* pSizeInBytes) const = 0;
|
||||
virtual int FileSize(int nMipSkipCount = 0) const = 0;
|
||||
|
||||
virtual int Width() const = 0;
|
||||
virtual int Height() const = 0;
|
||||
virtual int Depth() const = 0;
|
||||
virtual int MipCount() const = 0;
|
||||
|
||||
virtual int RowSizeInBytes(int nMipLevel) const = 0;
|
||||
|
||||
virtual int FaceSizeInBytes(int nMipLevel) const = 0;
|
||||
|
||||
virtual ImageFormat Format() const = 0;
|
||||
virtual int FaceCount() const = 0;
|
||||
virtual int FrameCount() const = 0;
|
||||
virtual int Flags() const = 0;
|
||||
|
||||
virtual float BumpScale() const = 0;
|
||||
|
||||
virtual int LowResWidth() const = 0;
|
||||
virtual int LowResHeight() const = 0;
|
||||
virtual ImageFormat LowResFormat() const = 0;
|
||||
|
||||
virtual const Vector& Reflectivity() const = 0;
|
||||
|
||||
virtual bool IsCubeMap() const = 0;
|
||||
virtual bool IsNormalMap() const = 0;
|
||||
virtual bool IsVolumeTexture() const = 0;
|
||||
|
||||
virtual void ComputeMipLevelDimensions(int iMipLevel, int* pMipWidth, int* pMipHeight, int* pMipDepth) const = 0;
|
||||
|
||||
virtual int ComputeMipSize(int iMipLevel) const = 0;
|
||||
|
||||
virtual void ComputeMipLevelSubRect(Rect_t* pSrcRect, int nMipLevel, Rect_t* pSubRect) const = 0;
|
||||
|
||||
virtual int ComputeFaceSize(int iStartingMipLevel = 0) const = 0;
|
||||
|
||||
virtual int ComputeTotalSize() const = 0;
|
||||
|
||||
virtual unsigned char* ImageData() = 0;
|
||||
|
||||
virtual unsigned char* ImageData(int iFrame, int iFace, int iMipLevel) = 0;
|
||||
|
||||
virtual unsigned char* ImageData(int iFrame, int iFace, int iMipLevel, int x, int y, int z = 0) = 0;
|
||||
|
||||
virtual unsigned char* LowResImageData() = 0;
|
||||
|
||||
virtual void ConvertImageFormat(ImageFormat fmt, bool bNormalToDUDV) = 0;
|
||||
|
||||
virtual void GenerateSpheremap(LookDir_t lookDir = LOOK_DOWN_Z) = 0;
|
||||
|
||||
virtual void GenerateHemisphereMap(unsigned char* pSphereMapBitsRGBA, int targetWidth,
|
||||
int targetHeight, LookDir_t lookDir, int iFrame) = 0;
|
||||
|
||||
virtual void FixCubemapFaceOrientation() = 0;
|
||||
|
||||
virtual void GenerateMipmaps() = 0;
|
||||
|
||||
virtual void PutOneOverMipLevelInAlpha() = 0;
|
||||
|
||||
virtual void ComputeReflectivity() = 0;
|
||||
|
||||
virtual void ComputeAlphaFlags() = 0;
|
||||
|
||||
virtual bool ConstructLowResImage() = 0;
|
||||
|
||||
virtual void PostProcess(bool bGenerateSpheremap, LookDir_t lookDir = LOOK_DOWN_Z, bool bAllowFixCubemapOrientation = true) = 0;
|
||||
|
||||
virtual void MatchCubeMapBorders(int iStage, ImageFormat finalFormat, bool bSkybox) = 0;
|
||||
|
||||
virtual void SetAlphaTestThreshholds(float flBase, float flHighFreq) = 0;
|
||||
|
||||
#if defined( _X360 )
|
||||
virtual int UpdateOrCreate(const char* pFilename, const char* pPathID = NULL, bool bForce = false) = 0;
|
||||
virtual bool UnserializeFromBuffer(CUtlBuffer& buf, bool bBufferIsVolatile, bool bHeaderOnly, bool bPreloadOnly, int nMipSkipCount) = 0;
|
||||
virtual int FileSize(bool bPreloadOnly, int nMipSkipCount) const = 0;
|
||||
virtual int MappingWidth() const = 0;
|
||||
virtual int MappingHeight() const = 0;
|
||||
virtual int MappingDepth() const = 0;
|
||||
virtual int MipSkipCount() const = 0;
|
||||
virtual bool IsPreTiled() const = 0;
|
||||
virtual unsigned char* LowResImageSample() = 0;
|
||||
virtual void ReleaseImageMemory() = 0;
|
||||
#endif
|
||||
|
||||
virtual void SetPostProcessingSettings(VtfProcessingOptions const* pOptions) = 0;
|
||||
};
|
||||
|
||||
IVTFTexture* CreateVTFTexture();
|
||||
void DestroyVTFTexture(IVTFTexture* pTexture);
|
||||
|
||||
int VTFFileHeaderSize(int nMajorVersion = -1, int nMinorVersion = -1);
|
||||
|
||||
typedef bool (*CompressFunc_t)(CUtlBuffer& inputBuffer, CUtlBuffer& outputBuffer);
|
||||
bool ConvertVTFTo360Format(const char* pDebugName, CUtlBuffer& sourceBuf, CUtlBuffer& targetBuf, CompressFunc_t pCompressFunc);
|
||||
|
||||
bool GetVTFPreload360Data(const char* pDebugName, CUtlBuffer& fileBufferIn, CUtlBuffer& preloadBufferOut);
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include "datamap.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
#define VTF_MAJOR_VERSION 7
|
||||
#define VTF_MINOR_VERSION 4
|
||||
|
||||
struct VTFFileBaseHeader_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
char fileTypeString[4];
|
||||
int version[2];
|
||||
int headerSize;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_1_t : public VTFFileBaseHeader_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned int flags;
|
||||
unsigned short numFrames;
|
||||
unsigned short startFrame;
|
||||
#if !defined( POSIX ) && !defined( _X360 )
|
||||
VectorAligned reflectivity;
|
||||
#else
|
||||
char pad1[4];
|
||||
Vector reflectivity;
|
||||
char pad2[4];
|
||||
#endif
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char numMipLevels;
|
||||
ImageFormat lowResImageFormat;
|
||||
unsigned char lowResImageWidth;
|
||||
unsigned char lowResImageHeight;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_2_t : public VTFFileHeaderV7_1_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
unsigned short depth;
|
||||
};
|
||||
|
||||
#define BYTE_POS( byteVal, shft ) uint32( uint32(uint8(byteVal)) << uint8(shft * 8) )
|
||||
#if !defined( _X360 )
|
||||
#define MK_VTF_RSRC_ID(a, b, c) uint32( BYTE_POS(a, 0) | BYTE_POS(b, 1) | BYTE_POS(c, 2) )
|
||||
#define MK_VTF_RSRCF(d) BYTE_POS(d, 3)
|
||||
#else
|
||||
#define MK_VTF_RSRC_ID(a, b, c) uint32( BYTE_POS(a, 3) | BYTE_POS(b, 2) | BYTE_POS(c, 1) )
|
||||
#define MK_VTF_RSRCF(d) BYTE_POS(d, 0)
|
||||
#endif
|
||||
|
||||
enum ResourceEntryType
|
||||
{
|
||||
VTF_LEGACY_RSRC_LOW_RES_IMAGE = MK_VTF_RSRC_ID(0x01, 0, 0),
|
||||
VTF_LEGACY_RSRC_IMAGE = MK_VTF_RSRC_ID(0x30, 0, 0),
|
||||
|
||||
VTF_RSRC_SHEET = MK_VTF_RSRC_ID(0x10, 0, 0),
|
||||
};
|
||||
|
||||
enum ResourceEntryTypeFlag
|
||||
{
|
||||
RSRCF_HAS_NO_DATA_CHUNK = MK_VTF_RSRCF(0x02),
|
||||
RSRCF_MASK = MK_VTF_RSRCF(0xFF)
|
||||
};
|
||||
|
||||
enum HeaderDetails
|
||||
{
|
||||
MAX_RSRC_DICTIONARY_ENTRIES = 32,
|
||||
MAX_X360_RSRC_DICTIONARY_ENTRIES = 4,
|
||||
};
|
||||
|
||||
struct ResourceEntryInfo
|
||||
{
|
||||
union
|
||||
{
|
||||
unsigned int eType;
|
||||
unsigned char chTypeBytes[4];
|
||||
};
|
||||
unsigned int resData;
|
||||
};
|
||||
|
||||
struct VTFFileHeaderV7_3_t : public VTFFileHeaderV7_2_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
|
||||
char pad4[3];
|
||||
unsigned int numResources;
|
||||
|
||||
#if defined( _X360 ) || defined( POSIX )
|
||||
char pad5[8];
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
struct VTFFileHeader_t : public VTFFileHeaderV7_3_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
};
|
||||
|
||||
#define VTF_X360_MAJOR_VERSION 0x0360
|
||||
#define VTF_X360_MINOR_VERSION 8
|
||||
struct VTFFileHeaderX360_t : public VTFFileBaseHeader_t
|
||||
{
|
||||
DECLARE_BYTESWAP_DATADESC();
|
||||
unsigned int flags;
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
unsigned short depth;
|
||||
unsigned short numFrames;
|
||||
unsigned short preloadDataSize;
|
||||
unsigned char mipSkipCount;
|
||||
unsigned char numResources;
|
||||
Vector reflectivity;
|
||||
float bumpScale;
|
||||
ImageFormat imageFormat;
|
||||
unsigned char lowResImageSample[4];
|
||||
unsigned int compressedSize;
|
||||
|
||||
};
|
||||
|
||||
#define VTF_RSRC_TEXTURE_LOD_SETTINGS ( MK_VTF_RSRC_ID( 'L','O','D' ) )
|
||||
struct TextureLODControlSettings_t
|
||||
{
|
||||
uint8 m_ResolutionClampX;
|
||||
uint8 m_ResolutionClampY;
|
||||
|
||||
uint8 m_ResolutionClampX_360;
|
||||
uint8 m_ResolutionClampY_360;
|
||||
};
|
||||
|
||||
#define VTF_RSRC_TEXTURE_SETTINGS_EX ( MK_VTF_RSRC_ID( 'T','S','0' ) )
|
||||
struct TextureSettingsEx_t
|
||||
{
|
||||
enum Flags0
|
||||
{
|
||||
UNUSED = 0x01,
|
||||
};
|
||||
|
||||
uint8 m_flags0;
|
||||
uint8 m_flags1;
|
||||
uint8 m_flags2;
|
||||
uint8 m_flags3;
|
||||
};
|
||||
|
||||
#define VTF_RSRC_TEXTURE_CRC ( MK_VTF_RSRC_ID( 'C','R','C' ) )
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif
|
71
SpyCustom/sdk/wchartypes.h
Normal file
71
SpyCustom/sdk/wchartypes.h
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
#ifndef WCHARTYPES_H
|
||||
#define WCHARTYPES_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef _INC_TCHAR
|
||||
#error ("Must include tier0 type headers before tchar.h")
|
||||
#endif
|
||||
|
||||
#if !defined(_WCHAR_T_DEFINED) && !defined(GNUC)
|
||||
typedef unsigned short wchar_t;
|
||||
#define _WCHAR_T_DEFINED
|
||||
#endif
|
||||
|
||||
typedef char char8;
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned char byte;
|
||||
|
||||
typedef wchar_t wchar;
|
||||
#define WIDEN2(x) L ## x
|
||||
#define WIDEN(x) WIDEN2(x)
|
||||
#define __WFILE__ WIDEN(__FILE__)
|
||||
|
||||
#ifdef STEAM
|
||||
#ifndef _UNICODE
|
||||
#define FORCED_UNICODE
|
||||
#endif
|
||||
#define _UNICODE
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
#else
|
||||
#define _tcsstr strstr
|
||||
#define _tcsicmp stricmp
|
||||
#define _tcscmp strcmp
|
||||
#define _tcscpy strcpy
|
||||
#define _tcsncpy strncpy
|
||||
#define _tcsrchr strrchr
|
||||
#define _tcslen strlen
|
||||
#define _tfopen fopen
|
||||
#define _stprintf sprintf
|
||||
#define _ftprintf fprintf
|
||||
#define _vsntprintf _vsnprintf
|
||||
#define _tprintf printf
|
||||
#define _sntprintf _snprintf
|
||||
#define _T(s) s
|
||||
#endif
|
||||
|
||||
#if defined(_UNICODE)
|
||||
typedef wchar tchar;
|
||||
#define tstring wstring
|
||||
#define __TFILE__ __WFILE__
|
||||
#define TCHAR_IS_WCHAR
|
||||
#else
|
||||
typedef char tchar;
|
||||
#define tstring string
|
||||
#define __TFILE__ __FILE__
|
||||
#define TCHAR_IS_CHAR
|
||||
#endif
|
||||
|
||||
#ifdef FORCED_UNICODE
|
||||
#undef _UNICODE
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
216
SpyCustom/sdk/weapon_parse.h
Normal file
216
SpyCustom/sdk/weapon_parse.h
Normal file
@ -0,0 +1,216 @@
|
||||
#ifndef WEAPON_PARSE_H
|
||||
#define WEAPON_PARSE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "shareddefs.h"
|
||||
#include "GameEventListener.h"
|
||||
#include "utlsortvector.h"
|
||||
#include "gamestringpool.h"
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
#define CEconItemView C_EconItemView
|
||||
#endif
|
||||
|
||||
class IFileSystem;
|
||||
class CEconItemView;
|
||||
|
||||
typedef unsigned short WEAPON_FILE_INFO_HANDLE;
|
||||
|
||||
|
||||
enum WeaponSound_t {
|
||||
EMPTY,
|
||||
SINGLE,
|
||||
SINGLE_ACCURATE,
|
||||
SINGLE_NPC,
|
||||
WPN_DOUBLE,
|
||||
DOUBLE_NPC,
|
||||
BURST,
|
||||
RELOAD,
|
||||
RELOAD_NPC,
|
||||
MELEE_MISS,
|
||||
MELEE_HIT,
|
||||
MELEE_HIT_WORLD,
|
||||
SPECIAL1,
|
||||
SPECIAL2,
|
||||
SPECIAL3,
|
||||
TAUNT,
|
||||
NEARLYEMPTY,
|
||||
FAST_RELOAD,
|
||||
|
||||
NUM_SHOOT_SOUND_TYPES,
|
||||
};
|
||||
|
||||
int GetWeaponSoundFromString(const char* pszString);
|
||||
|
||||
#define MAX_SHOOT_SOUNDS 16
|
||||
|
||||
#define MAX_WEAPON_STRING 80
|
||||
#define MAX_WEAPON_PREFIX 16
|
||||
#define MAX_WEAPON_AMMO_NAME 32
|
||||
|
||||
#define WEAPON_PRINTNAME_MISSING "!!! Missing printname on weapon"
|
||||
|
||||
|
||||
class CHudTexture;
|
||||
class KeyValues;
|
||||
|
||||
struct WeaponInfoLookup
|
||||
{
|
||||
size_t m_nWeaponParseDataOffset;
|
||||
_fieldtypes m_fieldType;
|
||||
CGameString m_iszAttribClassName;
|
||||
|
||||
WeaponInfoLookup(void) {}
|
||||
WeaponInfoLookup(size_t offset, _fieldtypes p_fieldType, const char* szAttribClassName);
|
||||
WeaponInfoLookup(const WeaponInfoLookup& WepInfoLookup);
|
||||
};
|
||||
|
||||
|
||||
class CWeaponInfoLookupListLess
|
||||
{
|
||||
public:
|
||||
bool Less(WeaponInfoLookup* const& src1, WeaponInfoLookup* const& src2, void* pCtx)
|
||||
{
|
||||
if (src1->m_iszAttribClassName.Get() < src2->m_iszAttribClassName.Get())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class FileWeaponInfo_t
|
||||
{
|
||||
public:
|
||||
|
||||
FileWeaponInfo_t();
|
||||
virtual ~FileWeaponInfo_t() {}
|
||||
|
||||
virtual void Parse(KeyValues* pKeyValuesData, const char* szWeaponName);
|
||||
|
||||
virtual void RefreshDynamicParameters() {};
|
||||
|
||||
public:
|
||||
bool bParsedScript;
|
||||
bool bLoadedHudElements;
|
||||
|
||||
char szClassName[MAX_WEAPON_STRING];
|
||||
char szPrintName[MAX_WEAPON_STRING];
|
||||
|
||||
int GetIndexofAttribute(string_t iszAttribClassName) const;
|
||||
static CUtlSortVector< WeaponInfoLookup*, CWeaponInfoLookupListLess > ms_vecWeaponInfoLookup;
|
||||
|
||||
protected:
|
||||
char szViewModel[MAX_WEAPON_STRING];
|
||||
char szWorldModel[MAX_WEAPON_STRING];
|
||||
char szAmmo1[MAX_WEAPON_AMMO_NAME];
|
||||
char szWorldDroppedModel[MAX_WEAPON_STRING];
|
||||
|
||||
static bool ms_bWeaponInfoLookupInitialized;
|
||||
|
||||
public:
|
||||
char szAnimationPrefix[MAX_WEAPON_PREFIX];
|
||||
int iSlot;
|
||||
int iPosition;
|
||||
int iMaxClip1;
|
||||
int iMaxClip2;
|
||||
int iDefaultClip1;
|
||||
int iDefaultClip2;
|
||||
int iWeight;
|
||||
int iRumbleEffect;
|
||||
bool bAutoSwitchTo;
|
||||
bool bAutoSwitchFrom;
|
||||
int iFlags;
|
||||
|
||||
char szAmmo2[MAX_WEAPON_AMMO_NAME];
|
||||
char szAIAddOn[MAX_WEAPON_STRING];
|
||||
|
||||
char aShootSounds[NUM_SHOOT_SOUND_TYPES][MAX_WEAPON_STRING];
|
||||
|
||||
private:
|
||||
int iAmmoType;
|
||||
int iAmmo2Type;
|
||||
|
||||
public:
|
||||
|
||||
bool m_bMeleeWeapon;
|
||||
|
||||
bool m_bBuiltRightHanded;
|
||||
bool m_bAllowFlipping;
|
||||
|
||||
|
||||
virtual int GetPrimaryClipSize(const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f) const { return 0; }
|
||||
virtual int GetSecondaryClipSize(const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f) const { return 0; }
|
||||
virtual int GetDefaultPrimaryClipSize(const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f) const { return 0; }
|
||||
virtual int GetDefaultSecondaryClipSize(const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f) const { return 0; }
|
||||
virtual int GetPrimaryReserveAmmoMax(const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f) const { return 0; }
|
||||
virtual int GetSecondaryReserveAmmoMax(const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f) const { return 0; }
|
||||
|
||||
const char* GetWorldModel(const CEconItemView* pWepView = NULL, int iTeam = 0) const;
|
||||
const char* GetViewModel(const CEconItemView* pWepView = NULL, int iTeam = 0) const;
|
||||
const char* GetWorldDroppedModel(const CEconItemView* pWepView = NULL, int iTeam = 0) const;
|
||||
const char* GetPrimaryAmmo(const CEconItemView* pWepView = NULL) const;
|
||||
|
||||
int GetPrimaryAmmoType(const CEconItemView* pWepView = NULL) const;
|
||||
|
||||
int iSpriteCount;
|
||||
CHudTexture* iconActive;
|
||||
CHudTexture* iconInactive;
|
||||
CHudTexture* iconAmmo;
|
||||
CHudTexture* iconAmmo2;
|
||||
CHudTexture* iconCrosshair;
|
||||
CHudTexture* iconAutoaim;
|
||||
CHudTexture* iconZoomedCrosshair;
|
||||
CHudTexture* iconZoomedAutoaim;
|
||||
CHudTexture* iconSmall;
|
||||
|
||||
bool bShowUsageHint;
|
||||
|
||||
};
|
||||
|
||||
WEAPON_FILE_INFO_HANDLE LookupWeaponInfoSlot(const char* name);
|
||||
FileWeaponInfo_t* GetFileWeaponInfoFromHandle(WEAPON_FILE_INFO_HANDLE handle);
|
||||
WEAPON_FILE_INFO_HANDLE GetInvalidWeaponInfoHandle(void);
|
||||
|
||||
void PrecacheFileWeaponInfoDatabase();
|
||||
|
||||
|
||||
KeyValues* ReadEncryptedKVFile(IFileSystem* filesystem, const char* szFilenameWithoutExtension, const unsigned char* pICEKey, bool bForceReadEncryptedFile = false);
|
||||
|
||||
|
||||
extern FileWeaponInfo_t* CreateWeaponInfo();
|
||||
|
||||
extern void LoadEquipmentData();
|
||||
|
||||
class CWeaponDatabase : public CAutoGameSystem, public CGameEventListener
|
||||
{
|
||||
public:
|
||||
CWeaponDatabase();
|
||||
|
||||
void Reset();
|
||||
bool LoadManifest();
|
||||
void PrecacheAllWeapons();
|
||||
void RefreshAllWeapons();
|
||||
|
||||
WEAPON_FILE_INFO_HANDLE FindWeaponInfo(const char* name);
|
||||
FileWeaponInfo_t* GetFileWeaponInfoFromHandle(WEAPON_FILE_INFO_HANDLE handle);
|
||||
|
||||
protected:
|
||||
friend void LoadEquipmentData();
|
||||
|
||||
virtual bool Init();
|
||||
|
||||
WEAPON_FILE_INFO_HANDLE FindOrCreateWeaponInfo(const char* name);
|
||||
bool LoadWeaponDataFromFile(IFileSystem* filesystem, const char* szWeaponName, const unsigned char* pICEKey);
|
||||
void FireGameEvent(IGameEvent* event);
|
||||
|
||||
private:
|
||||
CUtlDict< FileWeaponInfo_t*, unsigned short > m_WeaponInfoDatabase;
|
||||
bool m_bPreCached;
|
||||
};
|
||||
|
||||
extern CWeaponDatabase g_WeaponDatabase;
|
||||
|
||||
|
||||
#endif
|
24
SpyCustom/sdk/win32consoleio.h
Normal file
24
SpyCustom/sdk/win32consoleio.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef WIN32_CONSOLE_IO_H
|
||||
#define WIN32_CONSOLE_IO_H
|
||||
|
||||
#if defined( COMPILER_MSVC )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
PLATFORM_INTERFACE bool SetupWin32ConsoleIO();
|
||||
|
||||
struct Win32ConsoleColorContext_t
|
||||
{
|
||||
int m_InitialColor;
|
||||
uint16 m_LastColor;
|
||||
uint16 m_BadColor;
|
||||
uint16 m_BackgroundFlags;
|
||||
};
|
||||
|
||||
PLATFORM_INTERFACE void InitWin32ConsoleColorContext(Win32ConsoleColorContext_t* pContext);
|
||||
|
||||
PLATFORM_INTERFACE uint16 SetWin32ConsoleColor(Win32ConsoleColorContext_t* pContext, int nRed, int nGreen, int nBlue, int nIntensity);
|
||||
|
||||
PLATFORM_INTERFACE void RestoreWin32ConsoleColor(Win32ConsoleColorContext_t* pContext, uint16 prevColor);
|
||||
|
||||
#endif
|
210
SpyCustom/sdk/xboxstubs.h
Normal file
210
SpyCustom/sdk/xboxstubs.h
Normal file
@ -0,0 +1,210 @@
|
||||
#if !defined( XBOXSTUBS_H ) && !defined( _X360 )
|
||||
#define XBOXSTUBS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#define XCONTENTFLAG_NONE 0x00
|
||||
#define XCONTENTFLAG_CREATENEW 0x00
|
||||
#define XCONTENTFLAG_CREATEALWAYS 0x00
|
||||
#define XCONTENTFLAG_OPENEXISTING 0x00
|
||||
#define XCONTENTFLAG_OPENALWAYS 0x00
|
||||
#define XCONTENTFLAG_TRUNCATEEXISTING 0x00
|
||||
|
||||
#define XCONTENTFLAG_NOPROFILE_TRANSFER 0x00
|
||||
#define XCONTENTFLAG_NODEVICE_TRANSFER 0x00
|
||||
#define XCONTENTFLAG_STRONG_SIGNED 0x00
|
||||
#define XCONTENTFLAG_ALLOWPROFILE_TRANSFER 0x00
|
||||
#define XCONTENTFLAG_MOVEONLY_TRANSFER 0x00
|
||||
|
||||
#define XDEVICE_PORT0 0
|
||||
#define XDEVICE_PORT1 1
|
||||
#define XDEVICE_PORT2 2
|
||||
#define XDEVICE_PORT3 3
|
||||
#define XUSER_MAX_COUNT 4
|
||||
#define XUSER_INDEX_NONE 0x000000FE
|
||||
|
||||
#define XBX_CLR_DEFAULT 0xFF000000
|
||||
#define XBX_CLR_WARNING 0x0000FFFF
|
||||
#define XBX_CLR_ERROR 0x000000FF
|
||||
|
||||
#define XBOX_MINBORDERSAFE 0
|
||||
#define XBOX_MAXBORDERSAFE 0
|
||||
|
||||
typedef enum
|
||||
{
|
||||
XK_NULL,
|
||||
XK_BUTTON_UP,
|
||||
XK_BUTTON_DOWN,
|
||||
XK_BUTTON_LEFT,
|
||||
XK_BUTTON_RIGHT,
|
||||
XK_BUTTON_START,
|
||||
XK_BUTTON_BACK,
|
||||
XK_BUTTON_STICK1,
|
||||
XK_BUTTON_STICK2,
|
||||
XK_BUTTON_A,
|
||||
XK_BUTTON_B,
|
||||
XK_BUTTON_X,
|
||||
XK_BUTTON_Y,
|
||||
XK_BUTTON_LEFT_SHOULDER,
|
||||
XK_BUTTON_RIGHT_SHOULDER,
|
||||
XK_BUTTON_LTRIGGER,
|
||||
XK_BUTTON_RTRIGGER,
|
||||
XK_STICK1_UP,
|
||||
XK_STICK1_DOWN,
|
||||
XK_STICK1_LEFT,
|
||||
XK_STICK1_RIGHT,
|
||||
XK_STICK2_UP,
|
||||
XK_STICK2_DOWN,
|
||||
XK_STICK2_LEFT,
|
||||
XK_STICK2_RIGHT,
|
||||
XK_MAX_KEYS,
|
||||
} xKey_t;
|
||||
|
||||
typedef unsigned short WORD;
|
||||
#ifndef POSIX
|
||||
typedef unsigned long DWORD;
|
||||
typedef void* HANDLE;
|
||||
typedef unsigned __int64 ULONGLONG;
|
||||
#endif
|
||||
|
||||
#ifdef POSIX
|
||||
typedef DWORD COLORREF;
|
||||
#endif
|
||||
|
||||
#ifndef INVALID_HANDLE_VALUE
|
||||
#define INVALID_HANDLE_VALUE ((HANDLE)-1)
|
||||
#endif
|
||||
|
||||
typedef int XNADDR;
|
||||
typedef uint64 XUID;
|
||||
|
||||
typedef struct {
|
||||
BYTE ab[8];
|
||||
} XNKID;
|
||||
|
||||
typedef struct {
|
||||
BYTE ab[16];
|
||||
} XNKEY;
|
||||
|
||||
typedef struct _XSESSION_INFO
|
||||
{
|
||||
XNKID sessionID;
|
||||
XNADDR hostAddress;
|
||||
XNKEY keyExchangeKey;
|
||||
} XSESSION_INFO, * PXSESSION_INFO;
|
||||
|
||||
typedef struct _XUSER_DATA
|
||||
{
|
||||
BYTE type;
|
||||
|
||||
union
|
||||
{
|
||||
int nData;
|
||||
int64 i64Data;
|
||||
double dblData;
|
||||
struct
|
||||
{
|
||||
uint cbData;
|
||||
char* pwszData;
|
||||
} string;
|
||||
float fData;
|
||||
struct
|
||||
{
|
||||
uint cbData;
|
||||
char* pbData;
|
||||
} binary;
|
||||
};
|
||||
} XUSER_DATA, * PXUSER_DATA;
|
||||
|
||||
typedef struct _XUSER_PROPERTY
|
||||
{
|
||||
DWORD dwPropertyId;
|
||||
XUSER_DATA value;
|
||||
} XUSER_PROPERTY, * PXUSER_PROPERTY;
|
||||
|
||||
typedef struct _XUSER_CONTEXT
|
||||
{
|
||||
DWORD dwContextId;
|
||||
DWORD dwValue;
|
||||
} XUSER_CONTEXT, * PXUSER_CONTEXT;
|
||||
|
||||
typedef struct _XSESSION_SEARCHRESULT
|
||||
{
|
||||
XSESSION_INFO info;
|
||||
DWORD dwOpenPublicSlots;
|
||||
DWORD dwOpenPrivateSlots;
|
||||
DWORD dwFilledPublicSlots;
|
||||
DWORD dwFilledPrivateSlots;
|
||||
DWORD cProperties;
|
||||
DWORD cContexts;
|
||||
PXUSER_PROPERTY pProperties;
|
||||
PXUSER_CONTEXT pContexts;
|
||||
} XSESSION_SEARCHRESULT, * PXSESSION_SEARCHRESULT;
|
||||
|
||||
typedef struct _XSESSION_SEARCHRESULT_HEADER
|
||||
{
|
||||
DWORD dwSearchResults;
|
||||
XSESSION_SEARCHRESULT* pResults;
|
||||
} XSESSION_SEARCHRESULT_HEADER, * PXSESSION_SEARCHRESULT_HEADER;
|
||||
|
||||
typedef struct _XSESSION_REGISTRANT
|
||||
{
|
||||
uint64 qwMachineID;
|
||||
DWORD bTrustworthiness;
|
||||
DWORD bNumUsers;
|
||||
XUID* rgUsers;
|
||||
|
||||
} XSESSION_REGISTRANT;
|
||||
|
||||
typedef struct _XSESSION_REGISTRATION_RESULTS
|
||||
{
|
||||
DWORD wNumRegistrants;
|
||||
XSESSION_REGISTRANT* rgRegistrants;
|
||||
} XSESSION_REGISTRATION_RESULTS, * PXSESSION_REGISTRATION_RESULTS;
|
||||
|
||||
typedef struct {
|
||||
BYTE bFlags;
|
||||
BYTE bReserved;
|
||||
WORD cProbesXmit;
|
||||
WORD cProbesRecv;
|
||||
WORD cbData;
|
||||
BYTE* pbData;
|
||||
WORD wRttMinInMsecs;
|
||||
WORD wRttMedInMsecs;
|
||||
DWORD dwUpBitsPerSec;
|
||||
DWORD dwDnBitsPerSec;
|
||||
} XNQOSINFO;
|
||||
|
||||
typedef struct {
|
||||
uint cxnqos;
|
||||
uint cxnqosPending;
|
||||
XNQOSINFO axnqosinfo[1];
|
||||
} XNQOS;
|
||||
|
||||
#define XSESSION_CREATE_HOST 0
|
||||
#define XUSER_DATA_TYPE_INT32 0
|
||||
#define XSESSION_CREATE_USES_ARBITRATION 0
|
||||
#define XNET_QOS_LISTEN_ENABLE 0
|
||||
#define XNET_QOS_LISTEN_DISABLE 0
|
||||
#define XNET_QOS_LISTEN_SET_DATA 0
|
||||
|
||||
FORCEINLINE void XBX_ProcessEvents() {}
|
||||
FORCEINLINE unsigned int XBX_GetSystemTime() { return 0; }
|
||||
FORCEINLINE int XBX_GetPrimaryUserId() { return 0; }
|
||||
FORCEINLINE void XBX_SetPrimaryUserId(DWORD idx) {}
|
||||
FORCEINLINE int XBX_GetStorageDeviceId() { return 0; }
|
||||
FORCEINLINE void XBX_SetStorageDeviceId(DWORD idx) {}
|
||||
FORCEINLINE const char* XBX_GetLanguageString() { return ""; }
|
||||
FORCEINLINE bool XBX_IsLocalized() { return false; }
|
||||
|
||||
#define XCONTENT_MAX_DISPLAYNAME_LENGTH 128
|
||||
#define XCONTENT_MAX_FILENAME_LENGTH 42
|
||||
|
||||
#define XBX_INVALID_STORAGE_ID ((DWORD) -1)
|
||||
#define XBX_STORAGE_DECLINED ((DWORD) -2)
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user