Isle
Loading...
Searching...
No Matches
legocontainer.h
Go to the documentation of this file.
1#ifndef LEGOCONTAINER_H
2#define LEGOCONTAINER_H
3
4#include "compat.h"
5#include "decomp.h"
6#include "legotexture.h"
7#include "legotypes.h"
8#include "mxstl/stlcompat.h"
9
10// Note: dependency on LegoOmni
12
13#pragma warning(disable : 4237)
14
20 LegoBool operator()(const char* const& p_key0, const char* const& p_key1) const
21 {
22 return strcmp(p_key0, p_key1) > 0;
23 }
24};
25
31template <class T>
32class LegoContainerInfo : public map<const char*, T*, LegoContainerInfoComparator> {}; // [AI]
33
39template <class T>
41public:
47
53 {
54#ifdef COMPAT_MODE
56#else
58#endif
59 for (it = m_map.begin(); it != m_map.end(); it++) {
60 // DECOMP: Use of const_cast here matches ~ViewLODListManager from 96 source.
61 const char* const& key = (*it).first;
62 delete[] const_cast<char*>(key);
63
64 if (m_ownership) {
65 delete (*it).second;
66 }
67 }
68 }
69
74 void Clear()
75 {
76#ifdef COMPAT_MODE
77 for (typename LegoContainerInfo<T>::iterator it = m_map.begin(); it != m_map.end(); it++)
78#else
79 for (LegoContainerInfo<T>::iterator it = m_map.begin(); it != m_map.end(); it++)
80#endif
81 {
82 delete (*it).second;
83 }
84 }
85
92 T* Get(const char* p_name)
93 {
94 T* value = NULL;
95
96#ifdef COMPAT_MODE
97 typename LegoContainerInfo<T>::iterator it = m_map.find(p_name);
98#else
99 LegoContainerInfo<T>::iterator it = m_map.find(p_name);
100#endif
101
102 if (it != m_map.end()) {
103 value = (*it).second;
104 }
105
106 return value;
107 }
108
115 void Add(const char* p_name, T* p_value)
116 {
117#ifdef COMPAT_MODE
118 typename LegoContainerInfo<T>::iterator it = m_map.find(p_name);
119#else
120 LegoContainerInfo<T>::iterator it = m_map.find(p_name);
121#endif
122
123 char* name;
124 if (it != m_map.end()) {
125 name = const_cast<char*>((*it).first);
126
127 if (m_ownership) {
128 delete (*it).second;
129 }
130 }
131 else {
132 name = new char[strlen(p_name) + 1];
133 strcpy(name, p_name);
134 }
135
136 m_map[name] = p_value;
137 }
138
143 void SetOwnership(LegoBool p_ownership) { m_ownership = p_ownership; }
144
145protected:
148};
149
155typedef pair<LegoTextureInfo*, BOOL> LegoCachedTexture;
156
162typedef list<LegoCachedTexture> LegoCachedTextureList;
163
169class LegoTextureContainer : public LegoContainer<LegoTextureInfo> {
170public:
175 ~LegoTextureContainer() override;
176
184
190 void EraseCached(LegoTextureInfo* p_textureInfo);
191
192protected:
194};
195
196#endif // LEGOCONTAINER_H
Template alias for a map from C-string keys to object pointers, using LegoContainerInfoComparator for...
Definition: legocontainer.h:32
Template container associating string names with object pointers, optional lifetime management.
Definition: legocontainer.h:40
LegoContainer()
Default constructor, sets this container to own its elements.
Definition: legocontainer.h:46
void SetOwnership(LegoBool p_ownership)
Set whether this container owns/deletes its objects (and name strings) on removal/destruction.
void Clear()
Remove and delete all mapped objects; preserves key strings.
Definition: legocontainer.h:74
LegoContainerInfo< T > m_map
Underlying map from name strings to objects. [AI].
virtual ~LegoContainer()
Destructor.
Definition: legocontainer.h:52
T * Get(const char *p_name)
Retrieve the element mapped to the given name, or nullptr if missing.
Definition: legocontainer.h:92
LegoBool m_ownership
If TRUE, container owns objects and keys; else no cleanup on destruction. [AI].
void Add(const char *p_name, T *p_value)
Add an element mapped to the given name, replacing existing item if present.
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...
#define TRUE
Definition: d3drmdef.h:28
list< LegoCachedTexture > LegoCachedTextureList
List of cached textures, each with a pointer and a cache state.
pair< LegoTextureInfo *, BOOL > LegoCachedTexture
Pair associating a LegoTextureInfo pointer with a cache state (BOOL).
[AI] Defines basic fixed-width data types and platform-neutral constants for LEGO Island codebase.
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
LegoU8 LegoBool
[AI] Boolean value used throughout the codebase.
Definition: legotypes.h:89
#define map
[AI] Macro alias for Map<K, T, Pr>, replacing std::map<T>.
Definition: mxstl.h:411
[AI] STL compatibility layer header to provide consistent STL (Standard Template Library) types and a...
Comparator used to order keys in LegoContainerInfo maps; compares C-strings lexicographically.
Definition: legocontainer.h:19
LegoBool operator()(const char *const &p_key0, const char *const &p_key1) const
Definition: legocontainer.h:20