// CFTTTextureCache - [2020-04-13 11:57:46]
#ifndef _CFTTTEXTURECACHE_H_
#define _CFTTTEXTURECACHE_H_

#include "common.h"
#include "CFTTTexture.h"
#include "CFTTTexLoadOptions.h"
#include "CFTTAsyncEvent.h"
#include "CFTTFile.h"

/*
002229FC CFTTTextureCache::SetInitParams(uint ,uint,uint, func_TextureCache_un1 func)
00222A38 CFTTTextureCache::Initialise()
00222AEC CFTTTextureCache::Shutdown()
00222B58 CFTTTextureCache::EmptyCache()
00222BAC CFTTTextureCache::GetUsedTextureCount()
00222BBC CFTTTextureCache::LockMutex()
00222BCC CFTTTextureCache::UnlockMutex()
00222BDC CFTTTextureCache::ReleaseTexture(uint)
00222C68 CFTTTextureCache::ReleaseTexture(char const*)
00222C9C CFTTTextureCache::TextureCached(char const*)
00222CB0 CFTTTextureCache::FindTexture(uint)
00222D0C CFTTTextureCache::GetIndex(CFTTCachedImage *)
00222D20 CFTTTextureCache::GetTexture(char const*,CFTTTexLoadOptions const&,uint)
002230FC CFTTTextureCache::CheckForLoadCompletion(CFTTCachedImage *)
002231A8 CFTTTextureCache::ReleaseOldestTexture(bool)
0022323C CFTTTextureCache::InsertTexture(CFTTCachedImage *)
002232A8 CFTTTextureCache::ManageCache()
00223320 CFTTTextureCache::AsyncLoadCallback(CFTTAsyncEvent<TFTTFileAsyncEventData> *,TFTTFileAsyncEventData const*,void *)
00223368 CFTTTextureCache::IsDummyTexture(CFTTTexture *)

.bss:005CB244 @ int (__fastcall *CFTTTextureCache::m_fpPreCacheTextureProcessingCallback)(_DWORD)
.bss:005CB244 _ZN16CFTTTextureCache37m_fpPreCacheTextureProcessingCallbackE:.ds.b 4
*/

// 0x3C
struct CFTTCachedImage {
  CFTTTexture *pTexture_0;
  uint dHash_4;
  uint len_8;  //.text:0022333E   EORS R1, R3 由此处代码可以判断，类型必为uint
  int uFadeInPeriodMS_C;
  int uFrameNumber_10;
  int field_14;
  CFTTFile *pFile_18;
  CFTTTexLoadOptions loadOpt_1C;
};

class CFTTTextureCache {
public:
  typedef void (*func_PreCacheTextureProcessingCallback)(CFTTTexture **);

  static void SetInitParams(uint uMaxTextures,
                            uint uMaxMainHeapMemory,
                            uint unuse,
                            func_PreCacheTextureProcessingCallback func);  // 002229FC
  static void Initialise();                                                // 00222A38
  static void Shutdown();                                                  // 00222AEC
  static void EmptyCache();                                                // 00222B58
  static int GetUsedTextureCount();                                        // 00222BAC
  static void LockMutex();                                                 // 00222BBC
  static void UnlockMutex();                                               // 00222BCC
  static void ReleaseTexture(uint);                                        // 00222BDC
  static void ReleaseTexture(char const *);                                // 00222C68
  static bool TextureCached(char const *);                                 // 00222C9C
  static CFTTCachedImage *FindTexture(uint);                               // 00222CB0
  static int GetIndex(CFTTCachedImage *pImage);                            // 00222D0C
  static CFTTTexture *GetTexture(char const *,
                                 CFTTTexLoadOptions const &,
                                 uint);                         // 00222D20
  static bool CheckForLoadCompletion(CFTTCachedImage *pImage);  // 002230FC  //CFTTCFTTCachedImage*
  static bool ReleaseOldestTexture(bool);                       // 002231A8
  static int InsertTexture(CFTTCachedImage *pImage);            // 0022323C  //CFTTCFTTCachedImage *
  static void ManageCache();                                    // 002232A8
  static void AsyncLoadCallback(CFTTAsyncEvent<TFTTFileAsyncEventData> *,
                                TFTTFileAsyncEventData const *,
                                void *);      // 00223320
  static bool IsDummyTexture(CFTTTexture *);  // 00223368

  static uint s_uMaxTextures;                  // 00349A34
  static uint s_uMaxMainHeapMemory;            // 00349A38
  static uint s_uFadeInPeriodMS;               // 00349A3C
  static float s_fCurrentAlpha;                // 00349A40
  static bool s_bInitialised;                  // 005CB228
  static uint s_uUsedTextures;                 // 005CB22C used texture count
  static uint s_uUsedMainHeapMemory;           // 005CB230
  static CFTTCachedImage *s_pCachedImages;     // 005CB234
  static CFTTTexture *s_pDummyTexture;         // 005CB238
  static CFTTTexture *s_pCurrentAlphaTexture;  // 005CB23C
  static int s_tTextureCacheMutex;             // 005CB240

  static func_PreCacheTextureProcessingCallback m_fpPreCacheTextureProcessingCallback;  // 005CB244
};

#endif  //_CFTTTEXTURECACHE_H_