Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMXLOADER_H
  7. #define DMXLOADER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. //-----------------------------------------------------------------------------
  12. // Forward declarations
  13. //-----------------------------------------------------------------------------
  14. class CUtlBuffer;
  15. class CDmxElement;
  16. //-----------------------------------------------------------------------------
  17. // Serialization/Unserialization
  18. //-----------------------------------------------------------------------------
  19. bool SerializeDMX( CUtlBuffer &buf, CDmxElement *pRoot, const char *pFileName = NULL );
  20. bool SerializeDMX( const char *pFileName, const char *pPathID, bool bTextMode, CDmxElement *pRoot );
  21. bool UnserializeDMX( CUtlBuffer &buf, CDmxElement **ppRoot, const char *pFileName = NULL );
  22. bool UnserializeDMX( const char *pFileName, const char *pPathID, bool bTextMode, CDmxElement **ppRoot );
  23. //-----------------------------------------------------------------------------
  24. // DMX elements/attributes can only be accessed inside a dmx context
  25. //-----------------------------------------------------------------------------
  26. void BeginDMXContext( );
  27. void EndDMXContext( bool bDecommitMemory );
  28. void DecommitDMXMemory();
  29. //-----------------------------------------------------------------------------
  30. // Helper macro
  31. //-----------------------------------------------------------------------------
  32. class CDMXContextHelper
  33. {
  34. public:
  35. CDMXContextHelper( bool bDecommitMemory ) { m_bDecommitMemory = bDecommitMemory; BeginDMXContext(); }
  36. ~CDMXContextHelper() { EndDMXContext( m_bDecommitMemory ); }
  37. private:
  38. bool m_bDecommitMemory;
  39. };
  40. #define DECLARE_DMX_CONTEXT( ) CDMXContextHelper __dmxContextHelper( true );
  41. #define DECLARE_DMX_CONTEXT_NODECOMMIT( ) CDMXContextHelper __dmxContextHelper( false );
  42. #define DECLARE_DMX_CONTEXT_DECOMMIT( _decommit ) CDMXContextHelper __dmxContextHelper( _decommit );
  43. //-----------------------------------------------------------------------------
  44. // Used for allocation. All will be freed when we leave the DMX context
  45. //-----------------------------------------------------------------------------
  46. void* DMXAlloc( size_t size );
  47. //-----------------------------------------------------------------------------
  48. // Helper macro
  49. //-----------------------------------------------------------------------------
  50. #define DECLARE_DMX_ALLOCATOR( ) \
  51. public: \
  52. inline void* operator new( size_t size ) { MEM_ALLOC_CREDIT_( "DMXAlloc" ); return DMXAlloc(size); } \
  53. inline void* operator new( size_t size, int nBlockUse, const char *pFileName, int nLine ) { MEM_ALLOC_CREDIT_( "DMXAlloc" ); return DMXAlloc(size); } \
  54. inline void operator delete( void* p ) { } \
  55. inline void operator delete( void* p, int nBlockUse, const char *pFileName, int nLine ) { } \
  56. #endif // DMXLOADER_H