forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneCache.cpp
132 lines (110 loc) · 2.86 KB
/
SceneCache.cpp
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#include "SceneCache.h"
#include "choreoscene.h"
#include "choreoevent.h"
extern ISoundEmitterSystemBase *soundemitterbase;
CChoreoScene *BlockingLoadScene( const char *filename );
CSceneCache::CSceneCache()
{
msecs = 0;
}
CSceneCache::CSceneCache( const CSceneCache& src )
{
msecs = src.msecs;
sounds = src.sounds;
}
int CSceneCache::GetSoundCount() const
{
return sounds.Count();
}
char const *CSceneCache::GetSoundName( int index )
{
return soundemitterbase->GetSoundName( sounds[ index ] );
}
void CSceneCache::Save( CUtlBuffer& buf )
{
buf.PutUnsignedInt( msecs );
unsigned short c = GetSoundCount();
buf.PutShort( c );
Assert( sounds.Count() <= 65536 );
for ( int i = 0; i < c; ++i )
{
buf.PutString( GetSoundName( i ) );
}
}
void CSceneCache::Restore( CUtlBuffer& buf )
{
MEM_ALLOC_CREDIT();
msecs = buf.GetUnsignedInt();
unsigned short c = (unsigned short)buf.GetShort();
for ( int i = 0; i < c; ++i )
{
char soundname[ 512 ];
buf.GetString( soundname );
int idx = soundemitterbase->GetSoundIndex( soundname );
if ( idx != -1 )
{
Assert( idx <= 65535 );
if ( sounds.Find( idx ) == sounds.InvalidIndex() )
{
sounds.AddToTail( (unsigned short)idx );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Static method
// Input : *event -
// soundlist -
//-----------------------------------------------------------------------------
void CSceneCache::PrecacheSceneEvent( CChoreoEvent *event, CUtlVector< unsigned short >& soundlist )
{
if ( !event || event->GetType() != CChoreoEvent::SPEAK )
return;
int idx = soundemitterbase->GetSoundIndex( event->GetParameters() );
if ( idx != -1 )
{
MEM_ALLOC_CREDIT();
Assert( idx <= 65535 );
soundlist.AddToTail( (unsigned short)idx );
}
if ( event->GetCloseCaptionType() == CChoreoEvent::CC_MASTER )
{
char tok[ CChoreoEvent::MAX_CCTOKEN_STRING ];
if ( event->GetPlaybackCloseCaptionToken( tok, sizeof( tok ) ) )
{
int idx = soundemitterbase->GetSoundIndex( tok );
if ( idx != -1 && soundlist.Find( idx ) == soundlist.InvalidIndex() )
{
MEM_ALLOC_CREDIT();
Assert( idx <= 65535 );
soundlist.AddToTail( (unsigned short)idx );
}
}
}
}
void CSceneCache::Rebuild( char const *filename )
{
msecs = 0;
sounds.RemoveAll();
CChoreoScene *scene = BlockingLoadScene( filename );
if ( scene )
{
// Walk all events looking for SPEAK events
CChoreoEvent *event;
int c = scene->GetNumEvents();
for ( int i = 0; i < c; ++i )
{
event = scene->GetEvent( i );
PrecacheSceneEvent( event, sounds );
}
// Update scene duration, too
msecs = (int)( scene->FindStopTime() * 1000.0f + 0.5f );
delete scene;
}
}