forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjCache.h
100 lines (73 loc) · 2.01 KB
/
ObjCache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include "HashData.h"
#include "PackObj.h"
class DATDisk;
class ObjCache;
class DBObj :
public LongHashData,
public PackObj
{
public:
DBObj(ObjCache*);
virtual ~DBObj();
long Link();
long Unlink();
protected:
ObjCache* m_pCache; // 0x10
long m_lLinks; // 0x14
};
class ObjCache
{
public:
ObjCache(DATDisk *pDisk, DBObj *(*pfnAllocator)(), void (*pfnDestroyer)(DBObj *));
virtual ~ObjCache();
DBObj *Get(DWORD ID);
void Release(DWORD ID);
DWORD GetCachedCount();
protected:
DATDisk *m_pDisk;
DBObj *(*m_pfnAllocator)();
void (*m_pfnDestroyer)(DBObj *);
LongHash< DBObj > m_Objects;
};
namespace ObjCaches
{
extern ObjCache *RegionDescs;
extern ObjCache *LandBlocks;
extern ObjCache *LandBlockInfos;
extern ObjCache *EnvCells;
extern ObjCache *Environments;
extern ObjCache *Setups;
extern ObjCache *GfxObjs;
extern ObjCache *GfxObjDegradeInfos;
extern ObjCache *Surfaces;
extern ObjCache *Textures;
extern ObjCache *Palettes;
extern ObjCache *Animations;
extern ObjCache *PhysicsScripts;
extern ObjCache *PhysicsScriptTables;
extern ObjCache *ParticleEmitterInfos;
extern ObjCache *ImgColors;
extern void InitCaches();
extern void DestroyCaches();
extern void OutputCacheInfo();
};
#define DECLARE_CACHE_FUNCTIONS(classname) \
static DBObj* Allocator(); \
static void Destroyer(DBObj *); \
static classname *Get(DWORD ID); \
static void Release(classname *);
#define DEFINE_CACHE_FUNCTIONS(cachename, classname) \
DBObj* classname::Allocator() { \
return((DBObj *)new classname()); \
} \
void classname::Destroyer(DBObj* pObj) { \
delete ((classname *)pObj); \
} \
classname *classname::Get(DWORD ID) { \
return (classname *)ObjCaches::cachename->Get(ID); \
} \
void classname::Release(classname *pObj) { \
if (pObj) \
ObjCaches::cachename->Release(pObj->m_Key); \
}