Counter Strike : Global Offensive Source Code
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.

164 lines
5.7 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef QUEUEDLOADER_H
  7. #define QUEUEDLOADER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/platform.h"
  12. #include "appframework/iappsystem.h"
  13. enum LoaderError_t
  14. {
  15. LOADERERROR_NONE = 0,
  16. LOADERERROR_FILEOPEN = -1,
  17. LOADERERROR_READING = -2,
  18. };
  19. enum LoaderPriority_t
  20. {
  21. LOADERPRIORITY_ANYTIME = 0, // low priority, job can finish during gameplay
  22. LOADERPRIORITY_BEFOREPLAY = 1, // job must complete before load ends
  23. LOADERPRIORITY_DURINGPRELOAD = 2, // job must be complete during preload phase
  24. };
  25. typedef void ( *QueuedLoaderCallback_t )( void *pContext, void *pContext2, const void *pData, int nSize, LoaderError_t loaderError );
  26. struct LoaderJob_t
  27. {
  28. LoaderJob_t()
  29. {
  30. memset( this, 0, sizeof( *this ) );
  31. }
  32. const char *m_pFilename; // path to resource
  33. const char *m_pPathID; // optional, can be NULL
  34. QueuedLoaderCallback_t m_pCallback; // called at i/o delivery
  35. void *m_pContext; // caller provided data
  36. void *m_pContext2; // caller provided data
  37. void *m_pTargetData; // optional, caller provided target buffer
  38. int m_nBytesToRead; // optional read clamp, otherwise 0
  39. unsigned int m_nStartOffset; // optional start offset, otherwise 0
  40. LoaderPriority_t m_Priority; // data must arrive by specified interval
  41. bool m_bPersistTargetData; // caller wants ownership of i/o buffer
  42. bool m_bAnonymousDecode; // anonymous job wants a lzma decode
  43. };
  44. enum ResourcePreload_t
  45. {
  46. RESOURCEPRELOAD_UNKNOWN,
  47. RESOURCEPRELOAD_SOUND,
  48. RESOURCEPRELOAD_MATERIAL,
  49. RESOURCEPRELOAD_MODEL,
  50. RESOURCEPRELOAD_CUBEMAP,
  51. RESOURCEPRELOAD_STATICPROPLIGHTING,
  52. RESOURCEPRELOAD_GPUBUFFERALLOCATOR,
  53. RESOURCEPRELOAD_ANONYMOUS,
  54. RESOURCEPRELOAD_COUNT
  55. };
  56. abstract_class IResourcePreload
  57. {
  58. public:
  59. // Sent as a warning shot. Some callers may choose to do pre-emptive purging.
  60. virtual void PrepareForCreate( bool bSameMap ) = 0;
  61. // Called during preload phase for ALL the resources expected by the level.
  62. // Caller should not do i/o but generate AddJob() requests. Resources that already exist
  63. // and are not referenced by this function would be candidates for purge.
  64. virtual bool CreateResource( const char *pName ) = 0;
  65. // Sent as an event hint during preload, that creation has completed, AddJob() i/o is about to commence.
  66. // Caller should purge any unreferenced resources before the AddJobs are performed.
  67. // "Must Complete" data will be guaranteed finished, at preload conclusion, before the normal load phase commences.
  68. virtual void PurgeUnreferencedResources() = 0;
  69. // Sent as an event hint that gameplay rendering is imminent.
  70. // Low priority jobs may still be in async flight.
  71. virtual void OnEndMapLoading( bool bAbort ) = 0;
  72. virtual void PurgeAll() = 0;
  73. #if defined( _PS3 )
  74. virtual bool RequiresRendererLock() = 0;
  75. #endif // _PS3
  76. };
  77. // Default implementation
  78. class CResourcePreload : public IResourcePreload
  79. {
  80. void PrepareForCreate( bool bSameMap ) {}
  81. void PurgeUnreferencedResources() {}
  82. void OnEndMapLoading( bool bAbort ) {}
  83. void PurgeAll() {}
  84. #if defined( _PS3 )
  85. virtual bool RequiresRendererLock() { return false; }
  86. #endif // _PS3
  87. };
  88. // UI can install progress notification
  89. abstract_class ILoaderProgress
  90. {
  91. public:
  92. // implementation must ignore UpdateProgress() if not scoped by Begin/End
  93. virtual void BeginProgress() = 0;
  94. virtual void EndProgress() = 0;
  95. virtual void UpdateProgress( float progress, bool bForce = false ) = 0;
  96. virtual void PauseNonInteractiveProgress( bool bPause ) = 0;
  97. };
  98. // spew detail
  99. #define LOADER_DETAIL_NONE 0
  100. #define LOADER_DETAIL_TIMING (1<<0)
  101. #define LOADER_DETAIL_COMPLETIONS (1<<1)
  102. #define LOADER_DETAIL_LATECOMPLETIONS (1<<2)
  103. #define LOADER_DETAIL_PURGES (1<<3)
  104. #define LOADER_DETAIL_CREATIONS (1<<3)
  105. abstract_class IQueuedLoader : public IAppSystem
  106. {
  107. public:
  108. virtual void InstallLoader( ResourcePreload_t type, IResourcePreload *pLoader ) = 0;
  109. virtual void InstallProgress( ILoaderProgress *pProgress ) = 0;
  110. // Set bOptimizeReload if you want appropriate data (such as static prop lighting)
  111. // to persist - rather than being purged and reloaded - when going from map A to map A.
  112. virtual bool BeginMapLoading( const char *pMapName, bool bLoadForHDR, bool bOptimizeMapReload, void (*pfnBeginMapLoadingCallback)( int nStage ) ) = 0;
  113. virtual void EndMapLoading( bool bAbort ) = 0;
  114. virtual bool AddJob( const LoaderJob_t *pLoaderJob ) = 0;
  115. // injects a resource into the map's reslist, rejected if not understood
  116. virtual void AddMapResource( const char *pFilename ) = 0;
  117. // callback is asynchronous
  118. virtual bool ClaimAnonymousJob( const char *pFilename, QueuedLoaderCallback_t pCallback, void *pContext, void *pContext2 = NULL ) = 0;
  119. // provides data if loaded, caller owns data
  120. virtual bool ClaimAnonymousJob( const char *pFilename, void **pData, int *pDataSize, LoaderError_t *pError = NULL ) = 0;
  121. virtual bool IsMapLoading() const = 0;
  122. virtual bool IsSameMapLoading() const = 0;
  123. virtual bool IsFinished() const = 0;
  124. // callers can expect that jobs are not immediately started when batching
  125. virtual bool IsBatching() const = 0;
  126. // callers can conditionalize operational spew
  127. virtual int GetSpewDetail() const = 0;
  128. virtual void PurgeAll( ResourcePreload_t *pDontPurgeList = NULL, int nPurgeListSize = 0 ) = 0;
  129. #ifdef _PS3
  130. // hack to prevent PS/3 deadlock on queued loader render mutex when quitting during loading a map
  131. virtual uint UnlockProgressBarMutex() = 0;
  132. virtual void LockProgressBarMutex( uint nLockCount ) = 0;
  133. #endif
  134. };
  135. DECLARE_TIER2_INTERFACE( IQueuedLoader, g_pQueuedLoader );
  136. #endif // QUEUEDLOADER_H