Isle
Loading...
Searching...
No Matches
viewlodlist.cpp
Go to the documentation of this file.
1#include "viewlodlist.h"
2
3#include "decomp.h"
4#include "viewlod.h"
5
6#include <stdio.h>
7
12
13// GLOBAL: LEGO1 0x10101064
14// GLOBAL: BETA10 0x10205d08
15int ViewLODListManager::g_ROINameUID = 0;
16
17#ifdef _DEBUG
18// FUNCTION: BETA10 0x10178310
19inline void ViewLODList::Dump(void (*pTracer)(const char*, ...)) const
20{
21 pTracer(" ViewLODList<0x%x>: Capacity=%d, Size=%d, RefCount=%d\n", this, Capacity(), Size(), m_refCount);
22
23 for (int i = 0; i < (int) Size(); i++) {
24 ViewLOD* lod = const_cast<ViewLOD*>(this->operator[](i));
25 pTracer(" [%d]: ViewLOD<0x%x>: Vertices=%d\n", i, lod, lod->NVerts());
26 }
27}
28#endif
29
30// FUNCTION: LEGO1 0x100a6fd0
31// FUNCTION: BETA10 0x101783a3
33{
34}
35
36// FUNCTION: LEGO1 0x100a7130
37// FUNCTION: BETA10 0x1017841c
38// FUNCTION: ALPHA 0x100e3402
40{
41 ViewLODListMap::iterator iterator;
42
43 // delete all ViewLODLists
44 for (iterator = m_map.begin(); !(iterator == m_map.end()); ++iterator) {
45 const ROIName& rROIName = (*iterator).first;
46 ViewLODList* pLODList = (*iterator).second;
47
48 // ???who pops and deletes LODObjects
49 while (pLODList->Size() > 0) {
50 delete const_cast<ViewLOD*>(pLODList->PopBack());
51 }
52
53 delete pLODList;
54 // ??? for now
55 delete[] const_cast<char*>(rROIName);
56 }
57
58 // ??? correct way of "emptying" map
59 m_map.erase(m_map.begin(), m_map.end());
60
61 assert(m_map.begin() == m_map.end());
62}
63
64// FUNCTION: LEGO1 0x100a72c0
65// FUNCTION: BETA10 0x101785ef
66// FUNCTION: ALPHA 0x100e35d2
67ViewLODList* ViewLODListManager::Create(const ROIName& rROIName, int lodCount)
68{
69 // returned ViewLODList has a refCount of 1, i.e. caller must call Release()
70 // when it no longer holds on to the list
71
72 ViewLODList* pLODList;
73 int refCount;
74 char* pROIName;
75
76 // assert(!Lookup(rROIName)); // alpha only
77
78 pLODList = new ViewLODList(lodCount, this);
79 refCount = pLODList->AddRef();
80 assert(refCount == 1);
81
82 ViewLODList* list = Lookup(rROIName);
83 if (list != NULL) {
84 list->Release();
85
86 char num[12];
87 sprintf(num, "%d", g_ROINameUID);
88 pROIName = new char[strlen(rROIName) + strlen(num) + 1];
89 strcpy(pROIName, rROIName);
90 strcat(pROIName, num);
91 g_ROINameUID++;
92 }
93 else {
94 pROIName = new char[strlen(rROIName) + 1];
95 strcpy(pROIName, rROIName);
96 }
97
98 m_map[pROIName] = pLODList;
99
100 // NOTE: Lookup() adds a refCount
101 assert((Lookup(pROIName) == pLODList) && (pLODList->Release() == 1));
102
103 return pLODList;
104}
105
106// FUNCTION: LEGO1 0x100a75b0
107// FUNCTION: BETA10 0x101787d8
109{
110 // returned ViewLODList's refCount is increased, i.e. caller must call Release()
111 // when it no longer holds on to the list
112
113 ViewLODListMap::const_iterator iterator = m_map.find(p_roiName);
114 ViewLODList* pLODList = 0;
115
116 if (!(iterator == m_map.end())) {
117 pLODList = (*iterator).second;
118
119 assert(pLODList);
120 pLODList->AddRef();
121 }
122
123 return pLODList;
124}
125
126// FUNCTION: LEGO1 0x100a7680
127// FUNCTION: BETA10 0x1017886b
129{
130 ViewLODListMap::iterator iterator;
131 char deleted = FALSE;
132
133 for (iterator = m_map.begin(); !(iterator == m_map.end()); ++iterator) {
134 const ROIName& rROIName = (*iterator).first;
135 ViewLODList* pLODList = (*iterator).second;
136
137 if (lodList == pLODList) {
138 while (pLODList->Size() > 0) {
139 delete const_cast<ViewLOD*>(pLODList->PopBack());
140 }
141
142 delete pLODList;
143 delete[] const_cast<char*>(rROIName);
144 m_map.erase(iterator);
145
146 deleted = TRUE;
147 break;
148 }
149 }
150
151 return deleted;
152}
[AI] Abstract base class for an ordered list of LODObject pointers, where each entry represents an in...
Definition: lodlist.h:31
size_t Size() const
[AI] Returns the current number of LODObject pointers contained.
Definition: lodlist.h:165
size_t Capacity() const
[AI] Returns the maximum number of LODObject pointers the list can hold.
Definition: lodlist.h:171
[AI] Type-safe extension of LODListBase, templated for any LODObject-derived type.
Definition: lodlist.h:110
const T * PopBack()
[AI] Typed remove.
Definition: lodlist.h:249
const ViewLOD * operator[](int) const
[AI] Typed access to the LODObject at position i.
Definition: lodlist.h:237
[AI] Manages the lifecycle, lookup, and sharing of ViewLODList instances for different ROI names.
Definition: viewlodlist.h:111
ViewLODList * Create(const ROIName &rROIName, int lodCount)
[AI] Creates and registers a new ViewLODList for a named ROI, with space for the specified number of ...
Definition: viewlodlist.cpp:67
ViewLODListManager()
[AI] Constructs a ViewLODListManager; initializes internal structures.
Definition: viewlodlist.cpp:32
virtual ~ViewLODListManager()
[AI] Destroys the manager and all ViewLODLists it owns, ensuring proper cleanup of all managed instan...
Definition: viewlodlist.cpp:39
ViewLODList * Lookup(const ROIName &) const
[AI] Looks up an existing ViewLODList by ROI name, incrementing its reference count.
unsigned char Destroy(ViewLODList *lodList)
[AI] Destroys (removes and deletes) the given ViewLODList from the manager.
[AI] Reference-counted list of Level-of-Detail (LOD) objects associated with a single ROI (Realtime O...
Definition: viewlodlist.h:30
int Release()
[AI] Decrements the reference count.
int AddRef()
[AI] Increments the reference count.
[AI] Represents a Level of Detail (LOD) object for rendering, implemented with a mesh builder and sup...
Definition: viewlod.h:20
int NVerts() const override
[AI] Returns the estimated number of vertices in this LOD.
Definition: viewlod.h:49
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define list
[AI] Macro alias for List<T>, replacing std::list<T>.
Definition: mxstl.h:410
const char * ROIName
[AI] String type used as a key to identify uniquely-named ROI (Realtime Object Instance) classes.
Definition: viewlodlist.h:79