blob: 70b015398c49e03095fbc43e7aa486f0b27c71f6 (
plain) (
blame)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: This is a helper class for the situation where you want to build lists of
// things that fall into buckets, and effeciently keep up with which buckets have
// been used since flush.
//
//=============================================================================//
#ifndef MATERIALBUCKETS_H
#define MATERIALBUCKETS_H
#ifdef _WIN32
#pragma once
#endif
// FLASHLIGHTFIXME: Make all of the buckets share the same m_Elements (ie. make m_Elements static)
template <class Element_t>
class CMaterialsBuckets
{
public:
typedef unsigned short SortIDHandle_t;
typedef unsigned short ElementHandle_t;
CMaterialsBuckets()
{
m_FlushCount = -1;
}
// Set the number of buckets that are needed. This should get called every time
// a level is loaded.
void SetNumMaterialSortIDs( int n )
{
m_MaterialSortInfoArray.Purge();
m_MaterialSortInfoArray.SetCount( n );
m_Elements.Purge();
m_UsedSortIDs.Purge();
}
// Clear out all buckets. This should get called once a frame.
void Flush( void )
{
m_FlushCount++;
m_Elements.RemoveAll();
m_UsedSortIDs.RemoveAll();
}
//
// These functions are used to get at the list of used buckets.
//
SortIDHandle_t GetFirstUsedSortID()
{
return m_UsedSortIDs.Head();
}
SortIDHandle_t GetNextUsedSortID( SortIDHandle_t prevSortID )
{
return m_UsedSortIDs.Next( prevSortID );
}
int GetSortID( SortIDHandle_t handle )
{
return m_UsedSortIDs[handle];
}
SortIDHandle_t InvalidSortIDHandle()
{
return m_UsedSortIDs.InvalidIndex();
}
//
// These functions are used to get at the list of elements for each sortID.
//
ElementHandle_t GetElementListHead( int sortID )
{
return m_MaterialSortInfoArray[sortID].m_Head;
}
ElementHandle_t GetElementListNext( ElementHandle_t h )
{
return m_Elements.Next( h );
}
Element_t GetElement( ElementHandle_t h )
{
return m_Elements[h];
}
ElementHandle_t InvalidElementHandle()
{
return m_Elements.InvalidIndex();
}
// Add an element to the the bucket specified by sortID
void AddElement( int sortID, Element_t elem )
{
// Allocate an element to stick this in.
unsigned short elemID = m_Elements.Alloc( true );
m_Elements[elemID] = elem;
if( m_MaterialSortInfoArray[sortID].m_FlushCount != m_FlushCount )
{
// This is the first element that has used this sort id since flush.
// FLASHLIGHTFIXME: need to sort these by vertex format when shoving
// them into this list!
// Mark this sortID as having been used since the last flush.
m_MaterialSortInfoArray[sortID].m_FlushCount = m_FlushCount;
// Add this sortID to the list of sortIDs used since flush.
m_UsedSortIDs.AddToTail( sortID );
// Set the head pointer for this sort id to this element.
m_MaterialSortInfoArray[sortID].m_Head = elemID;
}
else
{
// We already have an element in this sort id since flush, so chain
// into thelist of elements for this sort id.
m_Elements.LinkBefore( m_MaterialSortInfoArray[sortID].m_Head, elemID );
m_MaterialSortInfoArray[sortID].m_Head = elemID;
}
}
private:
struct MaterialSortInfo_t
{
MaterialSortInfo_t() :
m_FlushCount( -1 ),
m_Head( (unsigned short)-1 ) // i.e., InvalidIndex()
{
}
int m_FlushCount;
unsigned short m_Head;
};
// This is a list of material sort info ids that have been used since flush.
CUtlLinkedList<unsigned short> m_UsedSortIDs;
// This is m_NumMaterialSortIDs big.
CUtlVector<MaterialSortInfo_t> m_MaterialSortInfoArray;
// This is used in multilist mode to make elements that belong in the multiple lists of
CUtlLinkedList<Element_t, unsigned short, true> m_Elements;
int m_FlushCount;
};
#endif // MATERIALBUCKETS_H
|