initial
This commit is contained in:
73
public/vstdlib/coroutine.h
Normal file
73
public/vstdlib/coroutine.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//====== Copyright 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: setjmp/longjmp based cooperative multitasking system
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef COROUTINE_H
|
||||
#define COROUTINE_H
|
||||
#pragma once
|
||||
|
||||
#include "vstdlib/vstdlib.h"
|
||||
|
||||
// enable this to do coroutine tracing
|
||||
// this will tell coroutine API users to set coroutine names
|
||||
// #define COROUTINE_TRACE
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: handles running coroutines
|
||||
// setjmp/longjmp based cooperative multitasking system
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// coroutine callback
|
||||
#ifdef POSIX
|
||||
typedef void (*CoroutineFunc_t )(void *);
|
||||
#else
|
||||
typedef void (__cdecl *CoroutineFunc_t )(void *);
|
||||
#endif
|
||||
|
||||
// handle to a coroutine
|
||||
typedef int32 HCoroutine;
|
||||
|
||||
// creates a new coroutine
|
||||
// no coroutine code is executed until Coroutine_Continue() is called
|
||||
VSTDLIB_INTERFACE HCoroutine Coroutine_Create( CoroutineFunc_t pFunc, void *pvParam );
|
||||
|
||||
// continues the specified coroutine
|
||||
// returns true if the coroutine is still running, false otherwise
|
||||
VSTDLIB_INTERFACE bool Coroutine_Continue( HCoroutine hCoroutine, const char *pchName = NULL );
|
||||
|
||||
// cancels a currently running coroutine
|
||||
VSTDLIB_INTERFACE void Coroutine_Cancel( HCoroutine hCoroutine );
|
||||
|
||||
// 'load' a coroutine only to debug it - immediately breaks into debugger
|
||||
// when continued, pops back to the prior coroutine
|
||||
VSTDLIB_INTERFACE void Coroutine_DebugBreak( HCoroutine hCoroutine );
|
||||
|
||||
// Load a coroutine and generate an assert. Used to get a minidump of a job
|
||||
VSTDLIB_INTERFACE void Coroutine_DebugAssert( HCoroutine hCoroutine, const char *pchMsg );
|
||||
|
||||
// called from the coroutine to return control to the main thread
|
||||
VSTDLIB_INTERFACE void Coroutine_YieldToMain();
|
||||
|
||||
// returns true if the code is currently running inside of a coroutine
|
||||
VSTDLIB_INTERFACE bool Coroutine_IsActive();
|
||||
|
||||
// returns a handle the currently active coroutine
|
||||
VSTDLIB_INTERFACE HCoroutine Coroutine_GetCurrentlyActive();
|
||||
|
||||
// call when a thread is quiting to release any per-thread memory
|
||||
VSTDLIB_INTERFACE void Coroutine_ReleaseThreadMemory();
|
||||
|
||||
// runs a self-test of the coroutine system
|
||||
VSTDLIB_INTERFACE bool Coroutine_Test();
|
||||
|
||||
// memory validation
|
||||
VSTDLIB_INTERFACE void Coroutine_ValidateGlobals( class CValidator &validator );
|
||||
|
||||
// for debugging purposes - returns stack depth of current coroutine
|
||||
VSTDLIB_INTERFACE size_t Coroutine_GetStackDepth();
|
||||
|
||||
|
||||
|
||||
#endif // COROUTINE_H
|
||||
25
public/vstdlib/cvar.h
Normal file
25
public/vstdlib/cvar.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#if !defined( CVAR_H )
|
||||
#define CVAR_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vstdlib/vstdlib.h"
|
||||
#include "icvar.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns a CVar dictionary for tool usage
|
||||
//-----------------------------------------------------------------------------
|
||||
VSTDLIB_INTERFACE CreateInterfaceFn VStdLib_GetICVarFactory();
|
||||
|
||||
|
||||
#endif // CVAR_H
|
||||
273
public/vstdlib/ieventsystem.h
Normal file
273
public/vstdlib/ieventsystem.h
Normal file
@@ -0,0 +1,273 @@
|
||||
//========== Copyright (c) Valve Corporation, All rights reserved. ==========//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef IEVENTSYSTEM_H
|
||||
#define IEVENTSYSTEM_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "appframework/iappsystem.h"
|
||||
#include "tier0/basetypes.h"
|
||||
#include "tier1/functors.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Event queues are used to allow listeners to decide at what point they
|
||||
// want to deal with event processing
|
||||
//-----------------------------------------------------------------------------
|
||||
DECLARE_POINTER_HANDLE( EventQueue_t );
|
||||
#define EVENT_QUEUE_HANDLE_INVALID ( (EventQueue_t)0 )
|
||||
|
||||
DECLARE_POINTER_HANDLE( EventId_t );
|
||||
#define EVENT_ID_INVALID ( (EventId_t)0 )
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global interface for posting/listening to events
|
||||
//
|
||||
// Usage for registering/unregistering listeners and posting events:
|
||||
// DEFINE_EVENT2_WITHNAMES( TestEvent, int, x, int, y );
|
||||
// void OnTestEvent( const int &x, const int &y );
|
||||
// void f()
|
||||
// {
|
||||
// hTest = g_pEventSystem->CreateEventQueue();
|
||||
// TestEvent::RegisterFunc( hTest, OnTestEvent );
|
||||
// or TestEvent::RegisterFunc( hTest, myClassPtr, &CMyClass::OnTestEvent );
|
||||
// TestEvent::Post( 100, 200 );
|
||||
// TestEvent::PostToListener( myClassPtr, 100, 200 );
|
||||
// g_pEventSystem->ProcessEvents( hTest );
|
||||
// TestEvent::UnregisterFunc( hTest, OnTestEvent );
|
||||
// g_pEventSystem->DestroyEventQueue( hTest );
|
||||
// }
|
||||
//
|
||||
// Note that the arguments of the event handlers are always const references
|
||||
// to the arguments specified in the event declaration to avoid extra copies
|
||||
// of the data.
|
||||
//
|
||||
// Also note that it's possible to post an event to a specific listener
|
||||
// using PostToListener. Just specify the class name as the first argument.
|
||||
//
|
||||
// Shit gets funky when you pass pointers to events. You need to be very careful
|
||||
// that the pointer is guaranteed to be valid until the messages are being posted.
|
||||
// Also, because everything is a const reference, the function prototypes
|
||||
// for stuff that accepts pointers looks like this strangeness:
|
||||
//
|
||||
// DEFINE_EVENT2_WITHNAMES( TestEvent, int, x, char *, pName );
|
||||
// void OnTestEvent( const int &x, char * const & pName );
|
||||
//
|
||||
// Also note: You cannot register or unregister while in the middle of processing events
|
||||
//
|
||||
// NOTE: We use EventClass::RegisterMemberFunc / EventClass:RegisterFunc
|
||||
// instead of overloading EventClass::Register to get more sane-looking
|
||||
// error message from the compiler if it happens to be passed an invalid
|
||||
// event handler.
|
||||
//
|
||||
// From a perf standpoint, registering + unregistering listeners, and
|
||||
// destroying event queues all can cause thread stalls. Do them with
|
||||
// low frequency.
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IEventSystem : public IAppSystem
|
||||
{
|
||||
public:
|
||||
// Creates an event queue.
|
||||
// Creation can occur at any time. Destruction can happen at any time
|
||||
// provided you're not simultaneously processing events or registering/unregistering
|
||||
// listeners on the same thread
|
||||
virtual EventQueue_t CreateEventQueue() = 0;
|
||||
virtual void DestroyEventQueue( EventQueue_t hQueue ) = 0;
|
||||
|
||||
// Processess queued events for a event queue
|
||||
virtual void ProcessEvents( EventQueue_t hQueue ) = 0;
|
||||
|
||||
// Ignore that macro magic! It allows us to call PostEvent on an arbitrary event id
|
||||
// with arbitrary arguments. Useful to allow systems to post event ids told to
|
||||
// it by external systems
|
||||
inline void PostEvent( EventId_t nEventId )
|
||||
{
|
||||
CFunctorData *pData = CreateFunctorData( );
|
||||
PostEventInternal( nEventId, EVENT_QUEUE_HANDLE_INVALID, NULL, pData );
|
||||
}
|
||||
|
||||
inline void PostEvent( EventId_t nEventId, EventQueue_t hQueue )
|
||||
{
|
||||
CFunctorData *pData = CreateFunctorData( );
|
||||
PostEventInternal( nEventId, hQueue, NULL, pData );
|
||||
}
|
||||
|
||||
inline void PostEventToListener( EventId_t nEventId, const void *pListener )
|
||||
{
|
||||
CFunctorData *pData = CreateFunctorData( );
|
||||
PostEventInternal( nEventId, EVENT_QUEUE_HANDLE_INVALID, pListener, pData );
|
||||
}
|
||||
|
||||
inline void PostEventToListener( EventId_t nEventId, EventQueue_t hQueue, const void *pListener )
|
||||
{
|
||||
CFunctorData *pData = CreateFunctorData( );
|
||||
PostEventInternal( nEventId, hQueue, pListener, pData );
|
||||
}
|
||||
|
||||
#define DEFINE_POST_EVENT(N) \
|
||||
template < FUNC_SOLO_TEMPLATE_ARG_PARAMS_##N > \
|
||||
inline void PostEvent( EventId_t nEventId FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
PostEventInternal( nEventId, EVENT_QUEUE_HANDLE_INVALID, NULL, pData ); \
|
||||
} \
|
||||
template < FUNC_SOLO_TEMPLATE_ARG_PARAMS_##N > \
|
||||
inline void PostEvent( EventId_t nEventId, EventQueue_t hQueue FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
PostEventInternal( nEventId, hQueue, NULL, pData ); \
|
||||
} \
|
||||
template < FUNC_SOLO_TEMPLATE_ARG_PARAMS_##N > \
|
||||
inline void PostEventToListener( EventId_t nEventId, const void *pListener FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
PostEventInternal( nEventId, EVENT_QUEUE_HANDLE_INVALID, pListener, pData ); \
|
||||
} \
|
||||
template < FUNC_SOLO_TEMPLATE_ARG_PARAMS_##N > \
|
||||
inline void PostEventToListener( EventId_t nEventId, EventQueue_t hQueue, const void *pListener FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
PostEventInternal( nEventId, hQueue, pListener, pData ); \
|
||||
}
|
||||
FUNC_GENERATE_ALL_BUT0( DEFINE_POST_EVENT );
|
||||
#undef DEFINE_POST_EVENT
|
||||
|
||||
private:
|
||||
// NOTE: These are not meant to be called directly. See the comment above
|
||||
// the IEventSystem class definition for how to post/register/unregister events
|
||||
virtual EventId_t RegisterEvent( const char *pEventName ) = 0;
|
||||
virtual void PostEventInternal( EventId_t nEventId, EventQueue_t hQueue, const void *pListener, CFunctorData *pData ) = 0;
|
||||
virtual void RegisterListener( EventId_t nEventId, EventQueue_t hQueue, CFunctorCallback *pCallback ) = 0;
|
||||
virtual void UnregisterListener( EventId_t nEventId, EventQueue_t hQueue, CFunctorCallback *pCallback ) = 0;
|
||||
|
||||
#define DEFINE_FRIEND_CLASSES(N) \
|
||||
template < typename Event_t FUNC_TEMPLATE_ARG_PARAMS_##N > friend class CEventSignature##N
|
||||
FUNC_GENERATE_ALL( DEFINE_FRIEND_CLASSES );
|
||||
#undef DEFINE_FRIEND_CLASSES
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Ignore that man behind the curtain!
|
||||
//-----------------------------------------------------------------------------
|
||||
#define DEFINE_EVENT_INTERNAL(N) \
|
||||
template < typename Event_t FUNC_TEMPLATE_ARG_PARAMS_##N > \
|
||||
class CEventSignature##N \
|
||||
{ \
|
||||
public: \
|
||||
static inline void Post( FUNC_PROXY_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
g_pEventSystem->PostEventInternal( Event_t::GetEventId(), EVENT_QUEUE_HANDLE_INVALID, NULL, pData ); \
|
||||
} \
|
||||
static inline void Post( EventQueue_t hQueue FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
g_pEventSystem->PostEventInternal( Event_t::GetEventId(), hQueue, NULL, pData ); \
|
||||
} \
|
||||
static inline void PostToListener( const void *pListener FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
g_pEventSystem->PostEventInternal( Event_t::GetEventId(), EVENT_QUEUE_HANDLE_INVALID, pListener, pData ); \
|
||||
} \
|
||||
static inline void PostToListener( EventQueue_t hQueue, const void *pListener FUNC_ARG_FORMAL_PARAMS_##N ) \
|
||||
{ \
|
||||
CFunctorData *pData = CreateFunctorData( FUNC_CALL_ARGS_##N ); \
|
||||
g_pEventSystem->PostEventInternal( Event_t::GetEventId(), hQueue, pListener, pData ); \
|
||||
} \
|
||||
static inline void RegisterFunc( EventQueue_t hQueue, void (*pfnProxied)( FUNC_PROXY_ARG_FORMAL_PARAMS_##N ) ) \
|
||||
{ \
|
||||
CFunctorCallback *pCallback = CreateFunctorCallback( pfnProxied ); \
|
||||
g_pEventSystem->RegisterListener( Event_t::GetEventId(), hQueue, pCallback ); \
|
||||
} \
|
||||
static inline void UnregisterFunc( EventQueue_t hQueue, void (*pfnProxied)( FUNC_PROXY_ARG_FORMAL_PARAMS_##N ) ) \
|
||||
{ \
|
||||
CFunctorCallback *pCallback = CreateFunctorCallback( pfnProxied ); \
|
||||
g_pEventSystem->UnregisterListener( Event_t::GetEventId(), hQueue, pCallback ); \
|
||||
} \
|
||||
template < class OBJECT_TYPE_PTR > \
|
||||
static inline void RegisterMemberFunc( EventQueue_t hQueue, OBJECT_TYPE_PTR *pClass, void (OBJECT_TYPE_PTR::*pfnProxied)( FUNC_PROXY_ARG_FORMAL_PARAMS_##N ) ) \
|
||||
{ \
|
||||
CFunctorCallback *pCallback = CreateFunctorCallback( pClass, pfnProxied ); \
|
||||
g_pEventSystem->RegisterListener( Event_t::GetEventId(), hQueue, pCallback ); \
|
||||
} \
|
||||
template < class OBJECT_TYPE_PTR > \
|
||||
static inline void UnregisterMemberFunc( EventQueue_t hQueue, OBJECT_TYPE_PTR *pClass, void (OBJECT_TYPE_PTR::*pfnProxied)( FUNC_PROXY_ARG_FORMAL_PARAMS_##N ) ) \
|
||||
{ \
|
||||
CFunctorCallback *pCallback = CreateFunctorCallback( pClass, pfnProxied ); \
|
||||
g_pEventSystem->UnregisterListener( Event_t::GetEventId(), hQueue, pCallback ); \
|
||||
} \
|
||||
static EventId_t RegisterEvent( const char *pEventName ) \
|
||||
{ \
|
||||
return g_pEventSystem->RegisterEvent( pEventName ); \
|
||||
} \
|
||||
};
|
||||
|
||||
FUNC_GENERATE_ALL( DEFINE_EVENT_INTERNAL )
|
||||
|
||||
#define DEFINE_EVENTID_INTERNAL( _eventName ) \
|
||||
public: \
|
||||
static EventId_t GetEventId() \
|
||||
{ \
|
||||
static EventId_t s_nEventId = EVENT_ID_INVALID; \
|
||||
if ( s_nEventId == EVENT_ID_INVALID ) \
|
||||
{ \
|
||||
s_nEventId = RegisterEvent( #_eventName ); \
|
||||
} \
|
||||
return s_nEventId; \
|
||||
}
|
||||
|
||||
#define DEFINE_EVENT( _eventName ) class _eventName : public CEventSignature0< _eventName > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT1( _eventName, _arg1 ) class _eventName : public CEventSignature1< _eventName, _arg1 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT2( _eventName, _arg1, _arg2 ) class _eventName : public CEventSignature2< _eventName, _arg1, _arg2 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT3( _eventName, _arg1, _arg2, _arg3 ) class _eventName : public CEventSignature3< _eventName, _arg1, _arg2, _arg3 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT4( _eventName, _arg1, _arg2, _arg3, _arg4 ) class _eventName : public CEventSignature4< _eventName, _arg1, _arg2, _arg3, _arg4 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT5( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5 ) class _eventName : public CEventSignature5< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT6( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) class _eventName : public CEventSignature6< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT7( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7 ) class _eventName : public CEventSignature7< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT8( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8 ) class _eventName : public CEventSignature8< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT9( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9 ) class _eventName : public CEventSignature9< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT10( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10 ) class _eventName : public CEventSignature10< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT11( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11 ) class _eventName : public CEventSignature11< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT12( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12 ) class _eventName : public CEventSignature12< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT13( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13 ) class _eventName : public CEventSignature13< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
#define DEFINE_EVENT14( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14 ) class _eventName : public CEventSignature14< _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14 > { DEFINE_EVENTID_INTERNAL( _eventName ); }
|
||||
|
||||
#define DEFINE_EVENT1_WITHNAMES( _eventName, _arg1, _arg1Name ) \
|
||||
DEFINE_EVENT1( _eventName, _arg1 )
|
||||
#define DEFINE_EVENT2_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name ) \
|
||||
DEFINE_EVENT2( _eventName, _arg1, _arg2 )
|
||||
#define DEFINE_EVENT3_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name ) \
|
||||
DEFINE_EVENT3( _eventName, _arg1, _arg2, _arg3 )
|
||||
#define DEFINE_EVENT4_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name ) \
|
||||
DEFINE_EVENT4( _eventName, _arg1, _arg2, _arg3, _arg4 )
|
||||
#define DEFINE_EVENT5_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name ) \
|
||||
DEFINE_EVENT5( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5 )
|
||||
#define DEFINE_EVENT6_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name ) \
|
||||
DEFINE_EVENT6( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 )
|
||||
#define DEFINE_EVENT7_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name ) \
|
||||
DEFINE_EVENT7( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7 )
|
||||
#define DEFINE_EVENT8_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name ) \
|
||||
DEFINE_EVENT8( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8 )
|
||||
#define DEFINE_EVENT9_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name, _arg9, _arg9Name ) \
|
||||
DEFINE_EVENT9( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9 )
|
||||
#define DEFINE_EVENT10_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name, _arg9, _arg9Name, _arg10, _arg10Name ) \
|
||||
DEFINE_EVENT10( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10 )
|
||||
#define DEFINE_EVENT11_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name, _arg9, _arg9Name, _arg10, _arg10Name, _arg11, _arg11Name ) \
|
||||
DEFINE_EVENT11( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11 )
|
||||
#define DEFINE_EVENT12_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name, _arg9, _arg9Name, _arg10, _arg10Name, _arg11, _arg11Name, _arg12, _arg12Name ) \
|
||||
DEFINE_EVENT12( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12 )
|
||||
#define DEFINE_EVENT13_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name, _arg9, _arg9Name, _arg10, _arg10Name, _arg11, _arg11Name, _arg12, _arg12Name, _arg13, _arg13Name ) \
|
||||
DEFINE_EVENT13( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13 )
|
||||
#define DEFINE_EVENT14_WITHNAMES( _eventName, _arg1, _arg1Name, _arg2, _arg2Name, _arg3, _arg3Name, _arg4, _arg4Name, _arg5, _arg5Name, _arg6, _arg6Name, _arg7, _arg7Name, _arg8, _arg8Name, _arg9, _arg9Name, _arg10, _arg10Name, _arg11, _arg11Name, _arg12, _arg12Name, _arg13, _arg13Name, _arg14, _arg14Name ) \
|
||||
DEFINE_EVENT14( _eventName, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11, _arg12, _arg13, _arg14 )
|
||||
|
||||
#endif // IEVENTSYSTEM_H
|
||||
56
public/vstdlib/ikeyvaluessystem.h
Normal file
56
public/vstdlib/ikeyvaluessystem.h
Normal file
@@ -0,0 +1,56 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
#ifndef VSTDLIB_IKEYVALUESSYSTEM_H
|
||||
#define VSTDLIB_IKEYVALUESSYSTEM_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vstdlib/vstdlib.h"
|
||||
|
||||
// handle to a KeyValues key name symbol
|
||||
typedef int HKeySymbol;
|
||||
#define INVALID_KEY_SYMBOL (-1)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Interface to shared data repository for KeyValues (included in vgui_controls.lib)
|
||||
// allows for central data storage point of KeyValues symbol table
|
||||
//-----------------------------------------------------------------------------
|
||||
class IKeyValuesSystem
|
||||
{
|
||||
public:
|
||||
// registers the size of the KeyValues in the specified instance
|
||||
// so it can build a properly sized memory pool for the KeyValues objects
|
||||
// the sizes will usually never differ but this is for versioning safety
|
||||
virtual void RegisterSizeofKeyValues(int size) = 0;
|
||||
|
||||
// allocates/frees a KeyValues object from the shared mempool
|
||||
virtual void *AllocKeyValuesMemory(int size) = 0;
|
||||
virtual void FreeKeyValuesMemory(void *pMem) = 0;
|
||||
|
||||
// symbol table access (used for key names)
|
||||
virtual HKeySymbol GetSymbolForString( const char *name, bool bCreate = true ) = 0;
|
||||
virtual const char *GetStringForSymbol(HKeySymbol symbol) = 0;
|
||||
|
||||
// for debugging, adds KeyValues record into global list so we can track memory leaks
|
||||
virtual void AddKeyValuesToMemoryLeakList(void *pMem, HKeySymbol name) = 0;
|
||||
virtual void RemoveKeyValuesFromMemoryLeakList(void *pMem) = 0;
|
||||
|
||||
// set/get a value for keyvalues resolution symbol
|
||||
// e.g.: SetKeyValuesExpressionSymbol( "LOWVIOLENCE", true ) - enables [$LOWVIOLENCE]
|
||||
virtual void SetKeyValuesExpressionSymbol( const char *name, bool bValue ) = 0;
|
||||
virtual bool GetKeyValuesExpressionSymbol( const char *name ) = 0;
|
||||
|
||||
// symbol table access from code with case-preserving requirements (used for key names)
|
||||
virtual HKeySymbol GetSymbolForStringCaseSensitive( HKeySymbol &hCaseInsensitiveSymbol, const char *name, bool bCreate = true ) = 0;
|
||||
};
|
||||
|
||||
VSTDLIB_INTERFACE IKeyValuesSystem *KeyValuesSystem();
|
||||
|
||||
// #define KEYVALUESSYSTEM_INTERFACE_VERSION "KeyValuesSystem002"
|
||||
|
||||
#endif // VSTDLIB_IKEYVALUESSYSTEM_H
|
||||
130
public/vstdlib/iprocessutils.h
Normal file
130
public/vstdlib/iprocessutils.h
Normal file
@@ -0,0 +1,130 @@
|
||||
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef IPROCESSUTILS_H
|
||||
#define IPROCESSUTILS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
#include "appframework/iappsystem.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Handle to a process. This is only for b/w compatibility.
|
||||
//-----------------------------------------------------------------------------
|
||||
class IProcess;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface version
|
||||
//-----------------------------------------------------------------------------
|
||||
#define PIPEREAD_INFINITE INT32_MAX
|
||||
|
||||
abstract_class IPipeRead
|
||||
{
|
||||
public:
|
||||
// NONBLOCKING FUNCTIONS
|
||||
|
||||
// Returns how much you can Read() without blocking.
|
||||
virtual int GetNumBytesAvailable() = 0;
|
||||
|
||||
// Read whatever is available without blocking.
|
||||
// This is the same as Read( sStr, GetNumBytesAvailable() ).
|
||||
virtual void ReadAvailable( CUtlString &sStr, int32 nMaxBytes=PIPEREAD_INFINITE ) = 0;
|
||||
virtual void ReadAvailable( CUtlBuffer* pOutBuffer, int32 nMaxBytes=PIPEREAD_INFINITE ) = 0;
|
||||
|
||||
|
||||
// (POTENTIALLY) BLOCKING FUNCTIONS
|
||||
|
||||
// Read one line of output (also returns when the process quits).
|
||||
// sStr will not include the \n (or \r\n) at the end of the line.
|
||||
virtual void ReadLine( CUtlString &sStr ) = 0;
|
||||
|
||||
// This will block the calling thread until it gets the number of bytes specified
|
||||
// or until the process exits. If sStr.Length() != nBytes, then you know the process exited.
|
||||
//
|
||||
// The returned string will always be null-terminated.
|
||||
// If you call with nBytes=PIPEREAD_INFINITE, it'll read until the process exits.
|
||||
virtual void Read( CUtlString &sStr, int32 nBytes=PIPEREAD_INFINITE ) = 0;
|
||||
};
|
||||
|
||||
|
||||
abstract_class IProcess
|
||||
{
|
||||
public:
|
||||
// Note: If the process is still running, this will auto kill it unless you started the process with
|
||||
// STARTPROCESS_NOAUTOKILL.
|
||||
virtual void Release() = 0;
|
||||
|
||||
// Kill the running process. You still must call IProcess::Release to free the resources.
|
||||
virtual void Abort() = 0;
|
||||
|
||||
// Returns true if a process is complete
|
||||
virtual bool IsComplete() = 0;
|
||||
|
||||
// Waits until a process is complete.
|
||||
// Returns the return value from the process.
|
||||
virtual int WaitUntilComplete() = 0;
|
||||
|
||||
// Write to the process' stdin.
|
||||
// This blocks until the process has read it.
|
||||
virtual int WriteStdin( char *pBuf, int nBufLen ) = 0;
|
||||
|
||||
// Get stuff to read the outputs.
|
||||
virtual IPipeRead* GetStdout() = 0;
|
||||
virtual IPipeRead* GetStderr() = 0; // NOTE: Only valid if you used STARTPROCESS_SEPARATE_STDERR.
|
||||
|
||||
// Returns the exit code for the process. Doesn't work unless the process is complete.
|
||||
// Returns -1 on error or if the process isn't complete.
|
||||
virtual int GetExitCode() = 0;
|
||||
};
|
||||
|
||||
|
||||
// Flags to IProcessUtils::StartProcess.
|
||||
#define STARTPROCESS_CONNECTSTDPIPES 0x01 // Necessary to use the stdin/stdout/stderr io functions.
|
||||
#define STARTPROCESS_SHARE_CONSOLE 0x02 // The process writes directly to your console. The pipe objects returned by
|
||||
// IProcess::GetStdout and GetStderr won't do anything.
|
||||
#define STARTPROCESS_SEPARATE_STDERR 0x04 // Rather than having to read stdout and stderr to get the output, the default is to put the stderr output into stdout.
|
||||
// This flag can change that behavior so you can get that output separately.
|
||||
// Warning: There may be deadlock problems with this, specifically in CProcessPipeRead::GetActualProcessOutput if
|
||||
// it's blocked reading stdout's pipe but the process is blocked waiting for us to flush stderr's pipe first.
|
||||
// To fully support that case, we'd need threads, overlapped IO, or a more careful (and slower) GetActualProcessOutput call
|
||||
// that bounces between the two pipes and never stalls.
|
||||
//
|
||||
// You can also get around this on the client side by reading the pipes from threads.
|
||||
#define STARTPROCESS_NOAUTOKILL 0x08 // Prevents the process from being auto-terminated in IProcess::Release()
|
||||
// or when IProcessUtils' Shutdown function is called.
|
||||
#define STARTPROCESS_FATPIPES 0x10 // Use I/O pipes larger than the default size for processes that do lots of stdio
|
||||
// (Only works with STARTPROCESS_CONNECTSTDPIPES)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface for makefiles to build differently depending on where they are run from
|
||||
//-----------------------------------------------------------------------------
|
||||
abstract_class IProcessUtils : public IAppSystem
|
||||
{
|
||||
public:
|
||||
// Starts, stops a process.
|
||||
// If pWorkingDir is left at NULL, it'll use this process' working directory.
|
||||
virtual IProcess* StartProcess( const char *pCommandLine, int fFlags, const char *pWorkingDir=NULL )= 0;
|
||||
virtual IProcess* StartProcess( int argc, const char **argv, int fFlags, const char *pWorkingDir=NULL ) = 0;
|
||||
|
||||
// Run a process and get its output.
|
||||
// If pStdout is set, then stdout AND stderr are put into pStdout.
|
||||
// If not, then the text output is ignored.
|
||||
//
|
||||
// Returns -1 if it was unable to run the process. Otherwise, returns the exit code from the process.
|
||||
virtual int SimpleRunProcess( const char *pCommandLine, const char *pWorkingDir=NULL, CUtlString *pStdout=NULL ) = 0;
|
||||
};
|
||||
|
||||
DECLARE_TIER1_INTERFACE( IProcessUtils, g_pProcessUtils );
|
||||
|
||||
|
||||
#endif // IPROCESSUTILS_H
|
||||
1470
public/vstdlib/jobthread.h
Normal file
1470
public/vstdlib/jobthread.h
Normal file
File diff suppressed because it is too large
Load Diff
60
public/vstdlib/osversion.h
Normal file
60
public/vstdlib/osversion.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $Date: $
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// $Log: $
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef OSVERSION_H
|
||||
#define OSVERSION_H
|
||||
#pragma once
|
||||
|
||||
#include "vstdlib/vstdlib.h"
|
||||
|
||||
// OS types we know about
|
||||
// Must be in ascending capability order, we use this for min OS requirements
|
||||
enum EOSType
|
||||
{
|
||||
k_eOSUnknown = -1,
|
||||
k_eMacOSUnknown = -102,
|
||||
k_eMacOS104 = -101,
|
||||
k_eMacOS105 = -100,
|
||||
k_eMacOS1058 = -99,
|
||||
k_eMacOS106 = -95,
|
||||
k_eMacOS1063 = -94,
|
||||
k_eMacOS107 = -90,
|
||||
// k_eMacOSMax = -1
|
||||
k_eLinuxUnknown = -203,
|
||||
k_eLinux22 = -202,
|
||||
k_eLinux24 = -201,
|
||||
k_eLinux26 = -200,
|
||||
// k_eLinuxMax = -103
|
||||
k_eWinUnknown = 0,
|
||||
k_eWin311 = 1,
|
||||
k_eWin95,
|
||||
k_eWin98,
|
||||
k_eWinME,
|
||||
k_eWinNT,
|
||||
k_eWin2000,
|
||||
k_eWinXP,
|
||||
k_eWin2003,
|
||||
k_eWinVista,
|
||||
k_eWindows7,
|
||||
k_eWin2008,
|
||||
k_eWinMAX,
|
||||
k_eOSTypeMax = k_eWinMAX + 11 // win types + other ifdef'd types
|
||||
};
|
||||
|
||||
VSTDLIB_INTERFACE const char *GetNameFromOSType( EOSType eOSType );
|
||||
VSTDLIB_INTERFACE const char *GetOSDetailString( char *pchOutBuf, int cchOutBuf );
|
||||
VSTDLIB_INTERFACE EOSType GetOSType();
|
||||
VSTDLIB_INTERFACE bool OSTypesAreCompatible( EOSType eOSTypeDetected, EOSType eOSTypeRequired );
|
||||
VSTDLIB_INTERFACE const char *GetPlatformName( bool *pbIs64Bit );
|
||||
|
||||
#endif // OSVERSION_H
|
||||
51
public/vstdlib/pch_vstdlib.h
Normal file
51
public/vstdlib/pch_vstdlib.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//======== (C) Copyright 1999, 2000 Valve, L.L.C. All rights reserved. ========
|
||||
//
|
||||
// The copyright to the contents herein is the property of Valve, L.L.C.
|
||||
// The contents may be used and/or copied only with the written permission of
|
||||
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
|
||||
// the agreement/contract under which the contents have been supplied.
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $Workfile: $
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#pragma warning(disable: 4514)
|
||||
|
||||
// First include standard libraries
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <ctype.h>
|
||||
|
||||
// Next, include public
|
||||
#include "tier0/basetypes.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier0/valobject.h"
|
||||
|
||||
// Next, include vstdlib
|
||||
#include "vstdlib/vstdlib.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "vstdlib/random.h"
|
||||
#include "tier1/keyvalues.h"
|
||||
#include "tier1/utlmemory.h"
|
||||
#include "tier1/utlrbtree.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "tier1/utllinkedlist.h"
|
||||
#include "tier1/utlmultilist.h"
|
||||
#include "tier1/utlsymbol.h"
|
||||
#include "tier0/icommandline.h"
|
||||
#include "tier1/netadr.h"
|
||||
#include "tier1/mempool.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlmap.h"
|
||||
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
|
||||
116
public/vstdlib/random.h
Normal file
116
public/vstdlib/random.h
Normal file
@@ -0,0 +1,116 @@
|
||||
//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: Random number generator
|
||||
//
|
||||
// $Workfile: $
|
||||
// $NoKeywords: $
|
||||
//===========================================================================//
|
||||
|
||||
#ifndef VSTDLIB_RANDOM_H
|
||||
#define VSTDLIB_RANDOM_H
|
||||
|
||||
#if !defined( __SPU__ )
|
||||
|
||||
#include "vstdlib/vstdlib.h"
|
||||
#include "tier0/basetypes.h"
|
||||
#include "tier0/threadtools.h"
|
||||
|
||||
#include "tier1/interface.h"
|
||||
|
||||
#define NTAB 32
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning( disable:4251 )
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A generator of uniformly distributed random numbers
|
||||
//-----------------------------------------------------------------------------
|
||||
class IUniformRandomStream
|
||||
{
|
||||
public:
|
||||
// Sets the seed of the random number generator
|
||||
virtual void SetSeed( int iSeed ) = 0;
|
||||
|
||||
// Generates random numbers
|
||||
virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ) = 0;
|
||||
virtual int RandomInt( int iMinVal, int iMaxVal ) = 0;
|
||||
virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The standard generator of uniformly distributed random numbers
|
||||
//-----------------------------------------------------------------------------
|
||||
class VSTDLIB_CLASS CUniformRandomStream : public IUniformRandomStream
|
||||
{
|
||||
public:
|
||||
CUniformRandomStream();
|
||||
|
||||
// Sets the seed of the random number generator
|
||||
virtual void SetSeed( int iSeed );
|
||||
|
||||
// Generates random numbers
|
||||
virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
|
||||
virtual int RandomInt( int iMinVal, int iMaxVal );
|
||||
virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
|
||||
|
||||
private:
|
||||
int GenerateRandomNumber();
|
||||
|
||||
int m_idum;
|
||||
int m_iy;
|
||||
int m_iv[NTAB];
|
||||
|
||||
CThreadFastMutex m_mutex;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A generator of gaussian distributed random numbers
|
||||
//-----------------------------------------------------------------------------
|
||||
class VSTDLIB_CLASS CGaussianRandomStream
|
||||
{
|
||||
public:
|
||||
// Passing in NULL will cause the gaussian stream to use the
|
||||
// installed global random number generator
|
||||
CGaussianRandomStream( IUniformRandomStream *pUniformStream = NULL );
|
||||
|
||||
// Attaches to a random uniform stream
|
||||
void AttachToStream( IUniformRandomStream *pUniformStream = NULL );
|
||||
|
||||
// Generates random numbers
|
||||
float RandomFloat( float flMean = 0.0f, float flStdDev = 1.0f );
|
||||
|
||||
private:
|
||||
IUniformRandomStream *m_pUniformStream;
|
||||
bool m_bHaveValue;
|
||||
float m_flRandomValue;
|
||||
|
||||
CThreadFastMutex m_mutex;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// A couple of convenience functions to access the library's global uniform stream
|
||||
//-----------------------------------------------------------------------------
|
||||
VSTDLIB_INTERFACE void RandomSeed( int iSeed );
|
||||
VSTDLIB_INTERFACE float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
|
||||
VSTDLIB_INTERFACE float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
|
||||
VSTDLIB_INTERFACE int RandomInt( int iMinVal, int iMaxVal );
|
||||
VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev = 1.0f );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Installs a global random number generator, which will affect the Random functions above
|
||||
//-----------------------------------------------------------------------------
|
||||
VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream );
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
#endif // #if !defined( __SPU__ )
|
||||
|
||||
|
||||
#endif // VSTDLIB_RANDOM_H
|
||||
|
||||
|
||||
|
||||
125
public/vstdlib/vcover.h
Normal file
125
public/vstdlib/vcover.h
Normal file
@@ -0,0 +1,125 @@
|
||||
//========== Copyright <20> 2005, Valve Corporation, All rights reserved. ========
|
||||
//
|
||||
// Purpose: A simple tool for coverage tests
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VCOVER_H
|
||||
#define VCOVER_H
|
||||
|
||||
#include "tier1/utlrbtree.h"
|
||||
#include "vstdlib.h"
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class CVCoverage
|
||||
{
|
||||
public:
|
||||
CVCoverage() :
|
||||
m_bActive( false ),
|
||||
m_depth( 0 ),
|
||||
m_token( 1 )
|
||||
{
|
||||
}
|
||||
|
||||
bool IsActive() const
|
||||
{
|
||||
return m_bActive;
|
||||
}
|
||||
|
||||
void SetActive( bool bActive )
|
||||
{
|
||||
Assert( bActive != m_bActive );
|
||||
m_bActive = bActive;
|
||||
if ( bActive )
|
||||
++m_token;
|
||||
}
|
||||
|
||||
void Begin()
|
||||
{
|
||||
++m_depth;
|
||||
}
|
||||
|
||||
void End()
|
||||
{
|
||||
--m_depth;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_locations.RemoveAll();
|
||||
}
|
||||
|
||||
bool ShouldCover( unsigned token ) const
|
||||
{
|
||||
return ( m_bActive && m_depth > 0 && token != m_token );
|
||||
}
|
||||
|
||||
unsigned Cover( const char *pszFile, int line )
|
||||
{
|
||||
Location_t location = { pszFile, line };
|
||||
|
||||
m_locations.Insert( location );
|
||||
|
||||
return m_token;
|
||||
}
|
||||
|
||||
void Report()
|
||||
{
|
||||
for ( int i = m_locations.FirstInorder(); i != m_locations.InvalidIndex(); i = m_locations.NextInorder( i ) )
|
||||
{
|
||||
Msg( "%s(%d) :\n", m_locations[i].pszFile, m_locations[i].line );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
struct Location_t
|
||||
{
|
||||
const char *pszFile;
|
||||
int line;
|
||||
|
||||
};
|
||||
|
||||
class CLocationLess
|
||||
{
|
||||
public:
|
||||
CLocationLess( int ignored ) {}
|
||||
bool operator!() { return false; }
|
||||
|
||||
bool operator()( const Location_t &lhs, const Location_t &rhs ) const
|
||||
{
|
||||
if ( lhs.line < rhs.line )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return CaselessStringLessThan( lhs.pszFile, rhs.pszFile );
|
||||
}
|
||||
};
|
||||
|
||||
bool m_bActive;
|
||||
int m_depth;
|
||||
unsigned m_token;
|
||||
|
||||
CUtlRBTree< Location_t, unsigned short, CLocationLess > m_locations;
|
||||
};
|
||||
|
||||
VSTDLIB_INTERFACE CVCoverage g_VCoverage;
|
||||
|
||||
#ifdef VCOVER_ENABLED
|
||||
#define VCOVER() \
|
||||
do \
|
||||
{ \
|
||||
static token; \
|
||||
if ( g_VCoverage.ShouldCover( token ) ) \
|
||||
{ \
|
||||
token = g_VCoverage.Cover( __FILE__, __LINE__ ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
#else
|
||||
#define VCOVER() ((void)0)
|
||||
#endif
|
||||
|
||||
#endif // VCOVER_H
|
||||
33
public/vstdlib/vstdlib.h
Normal file
33
public/vstdlib/vstdlib.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VSTDLIB_H
|
||||
#define VSTDLIB_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// dll export stuff
|
||||
//-----------------------------------------------------------------------------
|
||||
#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 // VSTDLIB_H
|
||||
276
public/vstdlib/vstrtools.h
Normal file
276
public/vstdlib/vstrtools.h
Normal file
@@ -0,0 +1,276 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Functions for UCS/UTF/Unicode string operations. These functions are in vstdlib
|
||||
// instead of tier1, because on PS/3 they need to load and initialize a system module,
|
||||
// which is more frugal to do from a single place rather than multiple times in different PRX'es.
|
||||
// The functions themselves aren't supposed to be called frequently enough for the DLL/PRX boundary
|
||||
// marshalling, if any, to have any measureable impact on performance.
|
||||
//
|
||||
#ifndef VSTRTOOLS_HDR
|
||||
#define VSTRTOOLS_HDR
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/basetypes.h"
|
||||
#include "tier1/strtools.h"
|
||||
|
||||
#ifdef VSTDLIB_DLL_EXPORT
|
||||
#define VSTRTOOLS_INTERFACE DLL_EXPORT
|
||||
#else
|
||||
#define VSTRTOOLS_INTERFACE DLL_IMPORT
|
||||
#endif
|
||||
|
||||
|
||||
// conversion functions wchar_t <-> char, returning the number of characters converted
|
||||
VSTRTOOLS_INTERFACE int V_UTF8ToUnicode( const char *pUTF8, OUT_Z_BYTECAP(cubDestSizeInBytes) wchar_t *pwchDest, int cubDestSizeInBytes );
|
||||
VSTRTOOLS_INTERFACE int V_UnicodeToUTF8( const wchar_t *pUnicode, OUT_Z_BYTECAP(cubDestSizeInBytes) char *pUTF8, int cubDestSizeInBytes );
|
||||
VSTRTOOLS_INTERFACE int V_UCS2ToUnicode( const ucs2 *pUCS2, OUT_Z_BYTECAP(cubDestSizeInBytes) wchar_t *pUnicode, int cubDestSizeInBytes );
|
||||
VSTRTOOLS_INTERFACE int V_UCS2ToUTF8( const ucs2 *pUCS2, OUT_Z_BYTECAP(cubDestSizeInBytes) char *pUTF8, int cubDestSizeInBytes );
|
||||
VSTRTOOLS_INTERFACE int V_UnicodeToUCS2( const wchar_t *pUnicode, int cubSrcInBytes, OUT_Z_BYTECAP(cubDestSizeInBytes) char *pUCS2, int cubDestSizeInBytes );
|
||||
VSTRTOOLS_INTERFACE int V_UTF8ToUCS2( const char *pUTF8, int cubSrcInBytes, OUT_Z_BYTECAP(cubDestSizeInBytes) ucs2 *pUCS2, int cubDestSizeInBytes );
|
||||
|
||||
// copy at most n bytes into destination, will not corrupt utf-8 multi-byte sequences
|
||||
VSTRTOOLS_INTERFACE void * V_UTF8_strncpy( OUT_Z_BYTECAP(nMaxBytes) char *pDest, const char *pSrc, size_t nMaxBytes );
|
||||
|
||||
|
||||
//
|
||||
// This utility class is for performing UTF-8 <-> UTF-16 conversion.
|
||||
// It is intended for use with function/method parameters.
|
||||
//
|
||||
// For example, you can call
|
||||
// FunctionTakingUTF16( CStrAutoEncode( utf8_string ).ToWString() )
|
||||
// or
|
||||
// FunctionTakingUTF8( CStrAutoEncode( utf16_string ).ToString() )
|
||||
//
|
||||
// The converted string is allocated off the heap, and destroyed when
|
||||
// the object goes out of scope.
|
||||
//
|
||||
// if the string cannot be converted, NULL is returned.
|
||||
//
|
||||
// This class doesn't have any conversion operators; the intention is
|
||||
// to encourage the developer to get used to having to think about which
|
||||
// encoding is desired.
|
||||
//
|
||||
class CStrAutoEncode
|
||||
{
|
||||
public:
|
||||
|
||||
// ctor
|
||||
explicit CStrAutoEncode( const char *pch )
|
||||
{
|
||||
m_pch = pch;
|
||||
m_pwch = NULL;
|
||||
#if !defined( WIN32 ) && !defined(_WIN32)
|
||||
m_pucs2 = NULL;
|
||||
m_bCreatedUCS2 = false;
|
||||
#endif
|
||||
m_bCreatedUTF16 = false;
|
||||
}
|
||||
|
||||
// ctor
|
||||
explicit CStrAutoEncode( const wchar_t *pwch )
|
||||
{
|
||||
m_pch = NULL;
|
||||
m_pwch = pwch;
|
||||
#if !defined( WIN32 ) && !defined(_WIN32)
|
||||
m_pucs2 = NULL;
|
||||
m_bCreatedUCS2 = false;
|
||||
#endif
|
||||
m_bCreatedUTF16 = true;
|
||||
}
|
||||
|
||||
#if !defined(WIN32) && !defined(_WINDOWS) && !defined(_WIN32) && !defined(_PS3)
|
||||
explicit CStrAutoEncode( const ucs2 *pwch )
|
||||
{
|
||||
m_pch = NULL;
|
||||
m_pwch = NULL;
|
||||
m_pucs2 = pwch;
|
||||
m_bCreatedUCS2 = true;
|
||||
m_bCreatedUTF16 = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// returns the UTF-8 string, converting on the fly.
|
||||
const char* ToString()
|
||||
{
|
||||
PopulateUTF8();
|
||||
return m_pch;
|
||||
}
|
||||
|
||||
// Same as ToString() but here to match Steam's interface for this class
|
||||
const char *ToUTF8() { return ToString(); }
|
||||
|
||||
|
||||
// returns the UTF-8 string - a writable pointer.
|
||||
// only use this if you don't want to call const_cast
|
||||
// yourself. We need this for cases like CreateProcess.
|
||||
char* ToStringWritable()
|
||||
{
|
||||
PopulateUTF8();
|
||||
return const_cast< char* >( m_pch );
|
||||
}
|
||||
|
||||
// returns the UTF-16 string, converting on the fly.
|
||||
const wchar_t* ToWString()
|
||||
{
|
||||
PopulateUTF16();
|
||||
return m_pwch;
|
||||
}
|
||||
|
||||
#if !defined( WIN32 ) && !defined(_WIN32)
|
||||
// returns the UTF-16 string, converting on the fly.
|
||||
const ucs2* ToUCS2String()
|
||||
{
|
||||
PopulateUCS2();
|
||||
return m_pucs2;
|
||||
}
|
||||
#endif
|
||||
|
||||
// returns the UTF-16 string - a writable pointer.
|
||||
// only use this if you don't want to call const_cast
|
||||
// yourself. We need this for cases like CreateProcess.
|
||||
wchar_t* ToWStringWritable()
|
||||
{
|
||||
PopulateUTF16();
|
||||
return const_cast< wchar_t* >( m_pwch );
|
||||
}
|
||||
|
||||
// dtor
|
||||
~CStrAutoEncode()
|
||||
{
|
||||
// if we're "native unicode" then the UTF-8 string is something we allocated,
|
||||
// and vice versa.
|
||||
if ( m_bCreatedUTF16 )
|
||||
{
|
||||
delete [] m_pch;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete [] m_pwch;
|
||||
}
|
||||
#if !defined( WIN32 ) && !defined(_WIN32)
|
||||
if ( !m_bCreatedUCS2 && m_pucs2 )
|
||||
delete [] m_pucs2;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
// ensure we have done any conversion work required to farm out a
|
||||
// UTF-8 encoded string.
|
||||
//
|
||||
// We perform two heap allocs here; the first one is the worst-case
|
||||
// (four bytes per Unicode code point). This is usually quite pessimistic,
|
||||
// so we perform a second allocation that's just the size we need.
|
||||
void PopulateUTF8()
|
||||
{
|
||||
if ( !m_bCreatedUTF16 )
|
||||
return; // no work to do
|
||||
if ( m_pwch == NULL )
|
||||
return; // don't have a UTF-16 string to convert
|
||||
if ( m_pch != NULL )
|
||||
return; // already been converted to UTF-8; no work to do
|
||||
|
||||
// each Unicode code point can expand to as many as four bytes in UTF-8; we
|
||||
// also need to leave room for the terminating NUL.
|
||||
uint32 cbMax = 4 * static_cast<uint32>( V_wcslen( m_pwch ) ) + 1;
|
||||
char *pchTemp = new char[ cbMax ];
|
||||
if ( V_UnicodeToUTF8( m_pwch, pchTemp, cbMax ) )
|
||||
{
|
||||
uint32 cchAlloc = static_cast<uint32>( V_strlen( pchTemp ) ) + 1;
|
||||
char *pchHeap = new char[ cchAlloc ];
|
||||
V_strncpy( pchHeap, pchTemp, cchAlloc );
|
||||
delete [] pchTemp;
|
||||
m_pch = pchHeap;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing, and leave the UTF-8 string NULL
|
||||
delete [] pchTemp;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure we have done any conversion work required to farm out a
|
||||
// UTF-16 encoded string.
|
||||
//
|
||||
// We perform two heap allocs here; the first one is the worst-case
|
||||
// (one code point per UTF-8 byte). This is sometimes pessimistic,
|
||||
// so we perform a second allocation that's just the size we need.
|
||||
void PopulateUTF16()
|
||||
{
|
||||
if ( m_bCreatedUTF16 )
|
||||
return; // no work to do
|
||||
if ( m_pch == NULL )
|
||||
return; // no UTF-8 string to convert
|
||||
if ( m_pwch != NULL )
|
||||
return; // already been converted to UTF-16; no work to do
|
||||
|
||||
uint32 cchMax = static_cast<uint32>( V_strlen( m_pch ) ) + 1;
|
||||
wchar_t *pwchTemp = new wchar_t[ cchMax ];
|
||||
if ( V_UTF8ToUnicode( m_pch, pwchTemp, cchMax * sizeof( wchar_t ) ) )
|
||||
{
|
||||
uint32 cchAlloc = static_cast<uint32>( V_wcslen( pwchTemp ) ) + 1;
|
||||
wchar_t *pwchHeap = new wchar_t[ cchAlloc ];
|
||||
V_wcsncpy( pwchHeap, pwchTemp, cchAlloc * sizeof( wchar_t ) );
|
||||
delete [] pwchTemp;
|
||||
m_pwch = pwchHeap;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing, and leave the UTF-16 string NULL
|
||||
delete [] pwchTemp;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined( WIN32 ) && !defined(_WIN32)
|
||||
// ensure we have done any conversion work required to farm out a
|
||||
// UTF-16 encoded string.
|
||||
//
|
||||
// We perform two heap allocs here; the first one is the worst-case
|
||||
// (one code point per UTF-8 byte). This is sometimes pessimistic,
|
||||
// so we perform a second allocation that's just the size we need.
|
||||
void PopulateUCS2()
|
||||
{
|
||||
if ( m_bCreatedUCS2 )
|
||||
return;
|
||||
if ( m_pch == NULL )
|
||||
return; // no UTF-8 string to convert
|
||||
if ( m_pucs2 != NULL )
|
||||
return; // already been converted to UTF-16; no work to do
|
||||
|
||||
uint32 cchMax = static_cast<uint32>( V_strlen( m_pch ) ) + 1;
|
||||
ucs2 *pwchTemp = new ucs2[ cchMax ];
|
||||
if ( V_UTF8ToUCS2( m_pch, cchMax, pwchTemp, cchMax * sizeof( ucs2 ) ) )
|
||||
{
|
||||
uint32 cchAlloc = cchMax;
|
||||
ucs2 *pwchHeap = new ucs2[ cchAlloc ];
|
||||
memcpy( pwchHeap, pwchTemp, cchAlloc * sizeof( ucs2 ) );
|
||||
delete [] pwchTemp;
|
||||
m_pucs2 = pwchHeap;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing, and leave the UTF-16 string NULL
|
||||
delete [] pwchTemp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// one of these pointers is an owned pointer; whichever
|
||||
// one is the encoding OTHER than the one we were initialized
|
||||
// with is the pointer we've allocated and must free.
|
||||
const char *m_pch;
|
||||
const wchar_t *m_pwch;
|
||||
#if !defined( WIN32 ) && !defined(_WIN32)
|
||||
const ucs2 *m_pucs2;
|
||||
bool m_bCreatedUCS2;
|
||||
#endif
|
||||
// "created as UTF-16", means our owned string is the UTF-8 string not the UTF-16 one.
|
||||
bool m_bCreatedUTF16;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define Q_UTF8ToUnicode V_UTF8ToUnicode
|
||||
#define Q_UnicodeToUTF8 V_UnicodeToUTF8
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user