Isle
Loading...
Searching...
No Matches
legocontainer.cpp
Go to the documentation of this file.
1#include "legocontainer.h"
2
6#include "tgl/d3drm/impl.h"
7
9// DECOMP_SIZE_ASSERT(LegoContainer<LegoTexture>, 0x18);
11
12// FUNCTION: LEGO1 0x10099870
14{
15}
16
17// FUNCTION: LEGO1 0x100998e0
19{
20 DDSURFACEDESC desc, newDesc;
21 DWORD width, height;
22 memset(&desc, 0, sizeof(desc));
23 desc.dwSize = sizeof(desc);
24
25 if (p_textureInfo->m_surface->Lock(NULL, &desc, DDLOCK_SURFACEMEMORYPTR, NULL) == DD_OK) {
26 width = desc.dwWidth;
27 height = desc.dwHeight;
28 p_textureInfo->m_surface->Unlock(desc.lpSurface);
29 }
30
31 for (LegoCachedTextureList::iterator it = m_cached.begin(); it != m_cached.end(); it++) {
32 if ((*it).second == FALSE && (*it).first->m_texture->AddRef() != 0 && (*it).first->m_texture->Release() == 1) {
33 if (!strcmp((*it).first->m_name, p_textureInfo->m_name)) {
34 LPDIRECTDRAWSURFACE surface = (*it).first->m_surface;
35 memset(&newDesc, 0, sizeof(newDesc));
36 newDesc.dwSize = sizeof(newDesc);
37
38 if (surface->Lock(NULL, &newDesc, DDLOCK_SURFACEMEMORYPTR, NULL) == DD_OK) {
39 BOOL und = FALSE;
40 if (newDesc.dwWidth == width && newDesc.dwHeight == height) {
41 und = TRUE;
42 }
43
44 surface->Unlock(newDesc.lpSurface);
45
46 if (und) {
47 (*it).second = TRUE;
48 (*it).first->m_texture->AddRef();
49 return (*it).first;
50 }
51 }
52 }
53 }
54 }
55
56 LegoTextureInfo* textureInfo = new LegoTextureInfo();
57
58 textureInfo->m_palette = p_textureInfo->m_palette;
59 textureInfo->m_palette->AddRef();
60
61 memset(&newDesc, 0, sizeof(newDesc));
62 newDesc.dwWidth = desc.dwWidth;
63 newDesc.dwHeight = desc.dwHeight;
64 newDesc.dwSize = sizeof(newDesc);
67 newDesc.ddpfPixelFormat.dwSize = sizeof(desc.ddpfPixelFormat);
70
71 if (VideoManager()->GetDirect3D()->DirectDraw()->CreateSurface(&newDesc, &textureInfo->m_surface, NULL) == DD_OK) {
72 RECT rect;
73 rect.left = 0;
74 rect.right = newDesc.dwWidth - 1;
75 rect.top = 0;
76 rect.bottom = newDesc.dwHeight - 1;
77
78 textureInfo->m_surface->SetPalette(textureInfo->m_palette);
79
80 if (textureInfo->m_surface->BltFast(0, 0, p_textureInfo->m_surface, &rect, DDBLTFAST_WAIT) != DD_OK) {
81 textureInfo->m_surface->Release();
82 textureInfo->m_palette->Release();
83 delete textureInfo;
84 return NULL;
85 }
86 else {
88 ->CreateTextureFromSurface(textureInfo->m_surface, &textureInfo->m_texture) != D3DRM_OK) {
89 textureInfo->m_surface->Release();
90 textureInfo->m_palette->Release();
91 delete textureInfo;
92 return NULL;
93 }
94 else {
95 textureInfo->m_texture->SetAppData((DWORD) textureInfo);
96 m_cached.push_back(LegoCachedTexture(textureInfo, TRUE));
97
98 textureInfo->m_texture->AddRef();
99
100 if (textureInfo->m_name != NULL) {
101 delete[] textureInfo->m_name;
102 }
103
104 textureInfo->m_name = new char[strlen(p_textureInfo->m_name) + 1];
105 strcpy(textureInfo->m_name, p_textureInfo->m_name);
106 return textureInfo;
107 }
108 }
109 }
110
111 return NULL;
112}
113
114// FUNCTION: LEGO1 0x10099cc0
116{
117 if (p_textureInfo == NULL) {
118 return;
119 }
120
121#ifdef COMPAT_MODE
122 LegoCachedTextureList::iterator it;
123 for (it = m_cached.begin(); it != m_cached.end(); it++) {
124#else
125 for (LegoCachedTextureList::iterator it = m_cached.begin(); it != m_cached.end(); it++) {
126#endif
127 if ((*it).first == p_textureInfo) {
128 (*it).second = FALSE;
129
130 if (p_textureInfo->m_texture->Release() == TRUE) {
131 delete p_textureInfo;
132 m_cached.erase(it);
133 }
134
135 return;
136 }
137 }
138}
Template alias for a map from C-string keys to object pointers, using LegoContainerInfoComparator for...
Definition: legocontainer.h:32
Specialized LegoContainer handling LegoTextureInfo objects and their DirectDraw/Direct3D caching.
LegoCachedTextureList m_cached
List of cached temporary texture objects, pairing texture info with a cache/in-use flag....
void EraseCached(LegoTextureInfo *p_textureInfo)
Mark a cached texture as unused and release its Direct3D/DirectDraw resources if its reference count ...
LegoTextureInfo * GetCached(LegoTextureInfo *p_textureInfo)
Attempt to find and return a cached LegoTextureInfo with the same properties as p_textureInfo,...
~LegoTextureContainer() override
Destructor.
[AI] Contains DirectDraw and Direct3DRM handles and metadata for a texture used in the LEGO Island re...
LPDIRECTDRAWPALETTE m_palette
[AI] DirectDraw palette object (8-bit) assigned to the m_surface.
LPDIRECTDRAWSURFACE m_surface
[AI] DirectDraw surface holding the 8-bit indexed image for the texture.
LPDIRECT3DRMTEXTURE2 m_texture
[AI] Direct3DRM texture object used by retained-mode rendering.
char * m_name
[AI] Pointer to the logical name string for this texture (allocated; e.g., "BROWN_ROOF").
MxDirect3D * GetDirect3D()
[AI] Returns the active Direct3D wrapper (engine/utility) object.
Tgl::Renderer * GetRenderer()
[AI] Returns the underlying renderer for this manager; normally a Direct3D Retained Mode wrapper.
IDirectDraw * DirectDraw()
Returns the DirectDraw device interface pointer.
Definition: mxdirectdraw.h:82
[AI] Implements Tgl::MeshBuilder; facilitates mesh construction [AI]
Definition: impl.h:55
#define D3DRM_OK
Definition: d3drm.h:197
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DDSD_WIDTH
Definition: ddraw.h:1174
#define DDSD_PIXELFORMAT
Definition: ddraw.h:1205
#define DDCAPS_OVERLAY
Definition: ddraw.h:1610
struct IDirectDrawSurface FAR * LPDIRECTDRAWSURFACE
Definition: ddraw.h:74
#define DDSD_HEIGHT
Definition: ddraw.h:1169
#define DDBLTFAST_WAIT
Definition: ddraw.h:2737
typedef DWORD(FAR PASCAL *LPCLIPPERCALLBACK)(LPDIRECTDRAWCLIPPER lpDDClipper
#define DDCAPS_OVERLAYCANTCLIP
Definition: ddraw.h:1615
#define DDPF_RGB
Definition: ddraw.h:2404
#define DD_OK
Definition: ddraw.h:3166
#define DDPF_PALETTEINDEXED8
Definition: ddraw.h:2399
#define DDLOCK_SURFACEMEMORYPTR
Definition: ddraw.h:2909
#define DDSD_CAPS
Definition: ddraw.h:1164
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
typedef BOOL(FAR PASCAL *LPDIENUMDEVICEOBJECTSCALLBACKA)(LPCDIDEVICEOBJECTINSTANCEA
pair< LegoTextureInfo *, BOOL > LegoCachedTexture
Pair associating a LegoTextureInfo pointer with a cache state (BOOL).
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
LegoVideoManager * VideoManager()
[AI] Accessor for the game's LegoVideoManager subsystem. Used for managing 3D/video hardware....
Definition: misc.cpp:29
DWORD dwSize
Definition: ddraw.h:343
DWORD dwRGBBitCount
Definition: ddraw.h:348
DWORD dwFlags
Definition: ddraw.h:344
DWORD dwCaps
Definition: ddraw.h:196
DDSCAPS ddsCaps
Definition: ddraw.h:1158
LPVOID lpSurface
Definition: ddraw.h:1152
DDPIXELFORMAT ddpfPixelFormat
Definition: ddraw.h:1157
DWORD dwSize
Definition: ddraw.h:1134
DWORD dwFlags
Definition: ddraw.h:1135
DWORD dwWidth
Definition: ddraw.h:1137
DWORD dwHeight
Definition: ddraw.h:1136