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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "cbase.h"
#include "c_slideshow_display.h"
#include "c_te_legacytempents.h"
#include "tempent.h"
#include "engine/IEngineSound.h"
#include "dlight.h"
#include "iefx.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "filesystem.h"
#include "KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define SLIDESHOW_LIST_BUFFER_MAX 8192
enum SlideshowCycleTypes
{
SLIDESHOW_CYCLE_RANDOM,
SLIDESHOW_CYCLE_FORWARD,
SLIDESHOW_CYCLE_BACKWARD,
SLIDESHOW_CYCLE_TOTAL
};
CUtlVector< C_SlideshowDisplay* > g_SlideshowDisplays;
IMPLEMENT_CLIENTCLASS_DT(C_SlideshowDisplay, DT_SlideshowDisplay, CSlideshowDisplay)
RecvPropBool( RECVINFO(m_bEnabled) ),
RecvPropString( RECVINFO( m_szDisplayText ) ),
RecvPropString( RECVINFO( m_szSlideshowDirectory ) ),
RecvPropArray3( RECVINFO_ARRAY(m_chCurrentSlideLists), RecvPropInt( RECVINFO(m_chCurrentSlideLists[0]) ) ),
RecvPropFloat( RECVINFO(m_fMinSlideTime) ),
RecvPropFloat( RECVINFO(m_fMaxSlideTime) ),
RecvPropInt( RECVINFO(m_iCycleType) ),
RecvPropBool( RECVINFO(m_bNoListRepeats) ),
END_RECV_TABLE()
C_SlideshowDisplay::C_SlideshowDisplay()
{
g_SlideshowDisplays.AddToTail( this );
}
C_SlideshowDisplay::~C_SlideshowDisplay()
{
g_SlideshowDisplays.FindAndRemove( this );
}
void C_SlideshowDisplay::Spawn( void )
{
BaseClass::Spawn();
m_NextSlideTime = 0;
SetNextClientThink( CLIENT_THINK_ALWAYS );
}
void C_SlideshowDisplay::OnDataChanged( DataUpdateType_t updateType )
{
BaseClass::OnDataChanged( updateType );
if ( updateType == DATA_UPDATE_CREATED )
{
BuildSlideShowImagesList();
}
else if ( updateType == DATA_UPDATE_DATATABLE_CHANGED )
{
m_iCurrentSlideList = 0;
m_iCurrentSlide = 0;
}
}
int C_SlideshowDisplay::GetMaterialIndex( int iSlideIndex )
{
if ( !m_SlideMaterialLists[ 0 ] )
return 0;
return m_SlideMaterialLists[ 0 ]->iSlideMaterials[ iSlideIndex ];
}
int C_SlideshowDisplay::NumMaterials( void )
{
if ( !m_SlideMaterialLists[ 0 ] )
return 0;
return m_SlideMaterialLists[ 0 ]->iSlideMaterials.Count();
}
void C_SlideshowDisplay::ClientThink( void )
{
BaseClass::ClientThink();
if ( !m_bEnabled )
return;
// Check if it's time for the next slide
if ( m_NextSlideTime > gpGlobals->curtime )
return;
// Set the time to cycle to the next slide
m_NextSlideTime = gpGlobals->curtime + RandomFloat( m_fMinSlideTime, m_fMaxSlideTime );
// Get the amount of items to pick from
int iNumCurrentSlideLists;
for ( iNumCurrentSlideLists = 0; iNumCurrentSlideLists < 16; ++iNumCurrentSlideLists )
{
if ( m_chCurrentSlideLists[ iNumCurrentSlideLists ] == (unsigned char)-1 )
break;
}
// Bail if no slide lists are selected
if ( iNumCurrentSlideLists == 0 )
return;
// Cycle the list
switch ( m_iCycleType )
{
case SLIDESHOW_CYCLE_RANDOM:
{
int iOldSlideList = m_iCurrentSlideList;
m_iCurrentSlideList = RandomInt( 0, iNumCurrentSlideLists - 1 );
// Prevent repeats if we don't want them
if ( m_bNoListRepeats && iNumCurrentSlideLists > 1 && m_iCurrentSlideList == iOldSlideList )
{
++m_iCurrentSlideList;
if ( m_iCurrentSlideList >= iNumCurrentSlideLists )
m_iCurrentSlideList = 0;
}
break;
}
case SLIDESHOW_CYCLE_FORWARD:
if ( m_iCurrentSlideList >= iNumCurrentSlideLists )
m_iCurrentSlideList = 0;
break;
case SLIDESHOW_CYCLE_BACKWARD:
if ( m_iCurrentSlideList < 0 )
m_iCurrentSlideList = iNumCurrentSlideLists - 1;
break;
}
SlideMaterialList_t *pSlideMaterialList = m_SlideMaterialLists[ m_chCurrentSlideLists[ m_iCurrentSlideList ] ];
// Cycle in the list
switch ( m_iCycleType )
{
case SLIDESHOW_CYCLE_RANDOM:
m_iCurrentSlide = RandomInt( 0, pSlideMaterialList->iSlideMaterials.Count() - 1 );
break;
case SLIDESHOW_CYCLE_FORWARD:
++m_iCurrentSlide;
if ( m_iCurrentSlide >= pSlideMaterialList->iSlideMaterials.Count() )
{
++m_iCurrentSlideList;
if ( m_iCurrentSlideList >= iNumCurrentSlideLists )
m_iCurrentSlideList = 0;
pSlideMaterialList = m_SlideMaterialLists[ m_chCurrentSlideLists[ m_iCurrentSlideList ] ];
m_iCurrentSlide = 0;
}
break;
case SLIDESHOW_CYCLE_BACKWARD:
--m_iCurrentSlide;
if ( m_iCurrentSlide < 0 )
{
--m_iCurrentSlideList;
if ( m_iCurrentSlideList < 0 )
m_iCurrentSlideList = iNumCurrentSlideLists - 1;
pSlideMaterialList = m_SlideMaterialLists[ m_chCurrentSlideLists[ m_iCurrentSlideList ] ];
m_iCurrentSlide = pSlideMaterialList->iSlideMaterials.Count() - 1;
}
break;
}
// Set the current material to what we've cycled to
m_iCurrentMaterialIndex = pSlideMaterialList->iSlideMaterials[ m_iCurrentSlide ];
m_iCurrentSlideIndex = pSlideMaterialList->iSlideIndex[ m_iCurrentSlide ];
}
void C_SlideshowDisplay::BuildSlideShowImagesList( void )
{
FileFindHandle_t matHandle;
char szDirectory[_MAX_PATH];
char szMatFileName[_MAX_PATH] = {'\0'};
char szFileBuffer[ SLIDESHOW_LIST_BUFFER_MAX ];
char *pchCurrentLine = NULL;
if ( IsX360() )
{
Q_snprintf( szDirectory, sizeof( szDirectory ), "materials/vgui/%s/slides.txt", m_szSlideshowDirectory );
FileHandle_t fh = g_pFullFileSystem->Open( szDirectory, "rt" );
if ( !fh )
{
DevWarning( "Couldn't read slideshow image file %s!", szDirectory );
return;
}
int iFileSize = MIN( g_pFullFileSystem->Size( fh ), SLIDESHOW_LIST_BUFFER_MAX );
int iBytesRead = g_pFullFileSystem->Read( szFileBuffer, iFileSize, fh );
g_pFullFileSystem->Close( fh );
// Ensure we don't write outside of our buffer
if ( iBytesRead > iFileSize )
iBytesRead = iFileSize;
szFileBuffer[ iBytesRead ] = '\0';
pchCurrentLine = szFileBuffer;
// Seek to end of first line
char *pchNextLine = pchCurrentLine;
while ( *pchNextLine != '\0' && *pchNextLine != '\n' && *pchNextLine != ' ' )
++pchNextLine;
if ( *pchNextLine != '\0' )
{
// Mark end of string
*pchNextLine = '\0';
// Seek to start of next string
++pchNextLine;
while ( *pchNextLine != '\0' && ( *pchNextLine == '\n' || *pchNextLine == ' ' ) )
++pchNextLine;
}
Q_strncpy( szMatFileName, pchCurrentLine, sizeof(szMatFileName) );
pchCurrentLine = pchNextLine;
}
else
{
Q_snprintf( szDirectory, sizeof( szDirectory ), "materials/vgui/%s/*.vmt", m_szSlideshowDirectory );
const char *pMatFileName = g_pFullFileSystem->FindFirst( szDirectory, &matHandle );
if ( pMatFileName )
Q_strncpy( szMatFileName, pMatFileName, sizeof(szMatFileName) );
}
int iSlideIndex = 0;
while ( szMatFileName[ 0 ] )
{
char szFileName[_MAX_PATH];
Q_snprintf( szFileName, sizeof( szFileName ), "vgui/%s/%s", m_szSlideshowDirectory, szMatFileName );
szFileName[ Q_strlen( szFileName ) - 4 ] = '\0';
int iMatIndex = ::GetMaterialIndex( szFileName );
// Get material keywords
char szFullFileName[_MAX_PATH];
Q_snprintf( szFullFileName, sizeof( szFullFileName ), "materials/vgui/%s/%s", m_szSlideshowDirectory, szMatFileName );
KeyValues *pMaterialKeys = new KeyValues( "material" );
bool bLoaded = pMaterialKeys->LoadFromFile( g_pFullFileSystem, szFullFileName, NULL );
if ( bLoaded )
{
char szKeywords[ 256 ];
Q_strcpy( szKeywords, pMaterialKeys->GetString( "%keywords", "" ) );
char *pchKeyword = szKeywords;
while ( pchKeyword[ 0 ] != '\0' )
{
char *pNextKeyword = pchKeyword;
// Skip commas and spaces
while ( pNextKeyword[ 0 ] != '\0' && pNextKeyword[ 0 ] != ',' )
++pNextKeyword;
if ( pNextKeyword[ 0 ] != '\0' )
{
pNextKeyword[ 0 ] = '\0';
++pNextKeyword;
while ( pNextKeyword[ 0 ] != '\0' && ( pNextKeyword[ 0 ] == ',' || pNextKeyword[ 0 ] == ' ' ) )
++pNextKeyword;
}
// Find the list with the current keyword
int iList;
for ( iList = 0; iList < m_SlideMaterialLists.Count(); ++iList )
{
if ( Q_strcmp( m_SlideMaterialLists[ iList ]->szSlideKeyword, pchKeyword ) == 0 )
break;
}
if ( iList >= m_SlideMaterialLists.Count() )
{
// Couldn't find the list, so create it
iList = m_SlideMaterialLists.AddToTail( new SlideMaterialList_t );
Q_strcpy( m_SlideMaterialLists[ iList ]->szSlideKeyword, pchKeyword );
}
// Add material index to this list
m_SlideMaterialLists[ iList ]->iSlideMaterials.AddToTail( iMatIndex );
m_SlideMaterialLists[ iList ]->iSlideIndex.AddToTail( iSlideIndex );
pchKeyword = pNextKeyword;
}
}
// Find the generic list
int iList;
for ( iList = 0; iList < m_SlideMaterialLists.Count(); ++iList )
{
if ( Q_strcmp( m_SlideMaterialLists[ iList ]->szSlideKeyword, "" ) == 0 )
break;
}
if ( iList >= m_SlideMaterialLists.Count() )
{
// Couldn't find the generic list, so create it
iList = m_SlideMaterialLists.AddToHead( new SlideMaterialList_t );
Q_strcpy( m_SlideMaterialLists[ iList ]->szSlideKeyword, "" );
}
// Add material index to this list
m_SlideMaterialLists[ iList ]->iSlideMaterials.AddToTail( iMatIndex );
m_SlideMaterialLists[ iList ]->iSlideIndex.AddToTail( iSlideIndex );
if ( IsX360() )
{
// Seek to end of first line
char *pchNextLine = pchCurrentLine;
while ( *pchNextLine != '\0' && *pchNextLine != '\n' && *pchNextLine != ' ' )
++pchNextLine;
if ( *pchNextLine != '\0' )
{
// Mark end of string
*pchNextLine = '\0';
// Seek to start of next string
++pchNextLine;
while ( *pchNextLine != '\0' && ( *pchNextLine == '\n' || *pchNextLine == ' ' ) )
++pchNextLine;
}
Q_strncpy( szMatFileName, pchCurrentLine, sizeof(szMatFileName) );
pchCurrentLine = pchNextLine;
}
else
{
const char *pMatFileName = g_pFullFileSystem->FindNext( matHandle );
if ( pMatFileName )
Q_strncpy( szMatFileName, pMatFileName, sizeof(szMatFileName) );
else
szMatFileName[ 0 ] = '\0';
}
++iSlideIndex;
}
if ( !IsX360() )
{
g_pFullFileSystem->FindClose( matHandle );
}
}
|