blob: d7de712237b06517cf1fb1a3f7eb5db190a32c18 (
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// Functionality common to wad and decal code in gl_draw.c and draw.c
//
//===========================================================================//
#include "render_pch.h"
#include "decal.h"
#include "decal_private.h"
#include "zone.h"
#include "sys.h"
#include "gl_matsysiface.h"
#include "filesystem.h"
#include "filesystem_engine.h"
#include "materialsystem/imaterial.h"
#include <malloc.h>
#include "utldict.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
struct DecalEntry
{
#ifdef _DEBUG
char *m_pDebugName; // only used in debug builds
#endif
IMaterial *material;
int index;
};
// This stores the list of all decals
CUtlMap< FileNameHandle_t, DecalEntry > g_DecalDictionary( 0, 0, DefLessFunc( FileNameHandle_t ) );
// This is a list of indices into the dictionary.
// This list is indexed by network id, so it maps network ids to decal dictionary entries
CUtlVector< int > g_DecalLookup;
//-----------------------------------------------------------------------------
// Purpose:
// Output : int
//-----------------------------------------------------------------------------
int Draw_DecalMax( void )
{
return g_nMaxDecals;
}
//-----------------------------------------------------------------------------
// Purpose:
// Sets the name of the bitmap from decals.wad to be used in a specific slot #
// called from cl_parse.cpp twice
// This sets the name of a decal prototype texture
// Input : decal -
// *name -
//-----------------------------------------------------------------------------
// called from gl_rsurf.cpp
IMaterial *Draw_DecalMaterial( int index )
{
if ( index < 0 || index >= g_DecalLookup.Count() )
return NULL;
int slot = g_DecalLookup[index];
if ( slot < 0 || slot >= (int)g_DecalDictionary.MaxElement() )
return NULL;
DecalEntry * entry = &g_DecalDictionary[slot];
if ( entry )
{
return entry->material;
}
else
{
return NULL;
}
}
#ifndef SWDS
void Draw_DecalSetName( int decal, char *name )
{
while ( decal >= g_DecalLookup.Count() )
{
MEM_ALLOC_CREDIT();
int idx = g_DecalLookup.AddToTail();
g_DecalLookup[idx] = g_DecalDictionary.InvalidIndex();
}
FileNameHandle_t fnHandle = g_pFileSystem->FindOrAddFileName( name );
int lookup = g_DecalDictionary.Find( fnHandle );
if ( lookup == g_DecalDictionary.InvalidIndex() )
{
DecalEntry entry;
#ifdef _DEBUG
int len = strlen(name) + 1;
entry.m_pDebugName = new char[len];
memcpy( entry.m_pDebugName, name, len );
#endif
entry.material = GL_LoadMaterial( name, TEXTURE_GROUP_DECAL );
entry.index = decal;
lookup = g_DecalDictionary.Insert( fnHandle, entry );
}
else
{
g_DecalDictionary[lookup].index = decal;
}
g_DecalLookup[decal] = lookup;
}
// called from cl_parse.cpp
// find the server side decal id given it's name.
// used for save/restore
int Draw_DecalIndexFromName( char *name, bool *found )
{
Assert( found );
FileNameHandle_t fnHandle = g_pFileSystem->FindOrAddFileName( name );
int lookup = g_DecalDictionary.Find( fnHandle );
if ( lookup == g_DecalDictionary.InvalidIndex() )
{
if ( found )
{
*found = false;
}
return 0;
}
if ( found )
{
*found = true;
}
return g_DecalDictionary[lookup].index;
}
#endif
const char *Draw_DecalNameFromIndex( int index )
{
#if !defined(SWDS)
return g_DecalDictionary[index].material ? g_DecalDictionary[index].material->GetName() : "";
#else
return "";
#endif
}
// This is called to reset all loaded decals
// called from cl_parse.cpp and host.cpp
void Decal_Init( void )
{
Decal_Shutdown();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void Decal_Shutdown( void )
{
for ( int index = g_DecalDictionary.FirstInorder(); index != g_DecalDictionary.InvalidIndex(); index = g_DecalDictionary.NextInorder(index) )
{
IMaterial *mat = g_DecalDictionary[index].material;
if ( mat )
{
GL_UnloadMaterial( mat );
}
#ifdef _DEBUG
delete[] g_DecalDictionary[index].m_pDebugName;
#endif
}
g_DecalLookup.Purge();
g_DecalDictionary.RemoveAll();
}
|