Skip to content

Commit f451dd8

Browse files
committed
videoservices init
1 parent 3f55ae9 commit f451dd8

124 files changed

Lines changed: 74754 additions & 130 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/game/client/swarm/vgui/nb_header_footer.cpp

Lines changed: 161 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "filesystem.h"
1111
#include "rd_workshop.h"
1212
#include "asw_util_shared.h"
13+
#include "video_services.h"
1314

1415
// memdbgon must be the last include file in a .cpp file!!!
1516
#include "tier0/memdbgon.h"
@@ -34,11 +35,8 @@ CASW_Background_Movie* ASWBackgroundMovie()
3435

3536
CASW_Background_Movie::CASW_Background_Movie()
3637
{
37-
#ifdef ASW_BINK_MOVIES
38+
m_nMaterialType = MATERIAL_INVALID;
3839
m_nBIKMaterial = BIKMATERIAL_INVALID;
39-
#else
40-
m_nAVIMaterial = AVIMATERIAL_INVALID;
41-
#endif
4240
m_nTextureID = -1;
4341
m_szCurrentMovie[0] = 0;
4442
m_nLastGameState = -1;
@@ -53,97 +51,152 @@ void CASW_Background_Movie::SetCurrentMovie( const char *szFilename )
5351
{
5452
// Safety check as we're possibly going to overwrite a file here!
5553
char szBaseName[MAX_PATH];
56-
V_FileBase( szFilename, szBaseName, sizeof( szBaseName ) );
57-
char szExpectedName[MAX_PATH];
58-
V_snprintf( szExpectedName, sizeof( szExpectedName ), "media/%s.bik", szBaseName );
59-
Assert( !V_strcmp( szFilename, szExpectedName ) );
60-
if ( V_strcmp( szFilename, szExpectedName ) )
54+
V_FileBase(szFilename, szBaseName, sizeof(szBaseName));
55+
const char* szAllowedExtensions[] = { "bik", "webm", nullptr };
56+
57+
bool bValidExtension = false;
58+
const char* szExt = V_GetFileExtension(szFilename);
59+
if (szExt)
6160
{
62-
// If we're trying to set the movie to something dangerous, use a known safe filename instead.
63-
szFilename = "media/BGFX_03.bik";
61+
for (int i = 0; szAllowedExtensions[i]; i++)
62+
{
63+
if (!Q_stricmp(szExt, szAllowedExtensions[i]))
64+
{
65+
bValidExtension = true;
66+
break;
67+
}
68+
}
6469
}
6570

66-
szFilename = g_ReactiveDropWorkshop.GetNativeFileSystemFile( szFilename );
71+
bool bValidPath = false;
72+
if (V_IsAbsolutePath(szFilename))
73+
{
74+
Warning("Absolute paths are not allowed for video files: %s\n", szFilename);
75+
}
76+
else
77+
{
78+
char szExpectedPrefix[] = "media/";
79+
if (!Q_strnicmp(szFilename, szExpectedPrefix, sizeof(szExpectedPrefix) - 1))
80+
{
81+
bValidPath = true;
82+
}
83+
}
6784

68-
if ( Q_strcmp( m_szCurrentMovie, szFilename ) )
85+
if (!bValidExtension || !bValidPath)
6986
{
70-
#ifdef ASW_BINK_MOVIES
71-
if ( m_nBIKMaterial != BIKMATERIAL_INVALID )
87+
Warning("Invalid video path: %s (must be in media/ folder with .bik or .webm extension)\n", szFilename);
88+
89+
const char* szDefaultFiles[] = {
90+
"media/BGFX_03.webm",
91+
"media/BGFX_03.bik",
92+
nullptr
93+
};
94+
95+
for (int i = 0; szDefaultFiles[i]; i++)
7296
{
73-
// FIXME: Make sure the m_pMaterial is actually destroyed at this point!
74-
g_pBIK->DestroyMaterial( m_nBIKMaterial );
75-
m_nBIKMaterial = BIKMATERIAL_INVALID;
76-
m_nTextureID = -1;
97+
if (g_pFullFileSystem->FileExists(szDefaultFiles[i], "GAME"))
98+
{
99+
szFilename = szDefaultFiles[i];
100+
break;
101+
}
77102
}
103+
}
78104

79-
char szMaterialName[ MAX_PATH ];
80-
Q_snprintf( szMaterialName, sizeof( szMaterialName ), "BackgroundBIKMaterial%i", g_pBIK->GetGlobalMaterialAllocationNumber() );
81-
m_nBIKMaterial = bik->CreateMaterial( szMaterialName, szFilename, "GAME", BIK_LOOP );
82-
#else
83-
if ( m_nAVIMaterial != AVIMATERIAL_INVALID )
105+
szFilename = g_ReactiveDropWorkshop.GetNativeFileSystemFile(szFilename);
106+
if (Q_strcmp(m_szCurrentMovie, szFilename))
107+
{
108+
if (m_nMaterialType != MATERIAL_INVALID)
84109
{
85-
// FIXME: Make sure the m_pMaterial is actually destroyed at this point!
86-
g_pAVI->DestroyAVIMaterial( m_nAVIMaterial );
87-
m_nAVIMaterial = AVIMATERIAL_INVALID;
110+
switch (m_nMaterialType)
111+
{
112+
case MATERIAL_WEBM:
113+
g_pWEBM->DestroyVideoMaterial( m_pWEBMMaterial );
114+
break;
115+
case MATERIAL_BIK:
116+
g_pBIK->DestroyMaterial(m_nBIKMaterial);
117+
break;
118+
}
119+
m_nMaterialType = MATERIAL_INVALID;
88120
m_nTextureID = -1;
89121
}
90122

91-
char szMaterialName[ MAX_PATH ];
92-
static int g_nGlobalAVIAllocationCount = 0;
93-
Q_snprintf( szMaterialName, sizeof( szMaterialName ), "BackgroundAVIMaterial%i", g_nGlobalAVIAllocationCount++ );
94-
m_nAVIMaterial = g_pAVI->CreateAVIMaterial( szMaterialName, szFilename, "GAME" );
95-
m_flStartTime = gpGlobals->realtime;
123+
const char* ext = Q_GetFileExtension(szFilename);
124+
if (ext && !Q_stricmp(ext, "webm"))
125+
{
126+
// Utwórz materia³ WebM
127+
char szMaterialName[MAX_PATH];
128+
Q_snprintf(szMaterialName, sizeof(szMaterialName), "BackgroundWebMMaterial%i", g_pWEBM->GetUniqueMaterialID());
96129

97-
IMaterial *pMaterial = avi->GetMaterial( m_nAVIMaterial );
98-
pMaterial->IncrementReferenceCount();
99-
#endif
130+
m_pWEBMMaterial = g_pWEBM->CreateVideoMaterial(
131+
szMaterialName, szFilename, "GAME",
132+
VideoPlaybackFlags::LOOP_VIDEO | VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS,
133+
VideoSystem::WEBM);
100134

101-
Q_snprintf( m_szCurrentMovie, sizeof( m_szCurrentMovie ), "%s", szFilename );
102-
s_bLastReduceMotion = false; // we need to render at least one frame before we can pause.
135+
if (m_pWEBMMaterial)
136+
{
137+
m_nMaterialType = MATERIAL_WEBM;
138+
m_pWEBMMaterial->StartVideo();
139+
}
140+
}
141+
else
142+
{
143+
char szMaterialName[MAX_PATH];
144+
Q_snprintf(szMaterialName, sizeof(szMaterialName), "BackgroundBIKMaterial%i", g_pBIK->GetGlobalMaterialAllocationNumber());
145+
146+
m_nBIKMaterial = bik->CreateMaterial(szMaterialName, szFilename, "GAME", BIK_LOOP);
147+
m_nMaterialType = MATERIAL_BIK;
148+
}
149+
150+
Q_snprintf(m_szCurrentMovie, sizeof(m_szCurrentMovie), "%s", szFilename);
151+
s_bLastReduceMotion = false;
103152
}
104153
}
105154

155+
106156
void CASW_Background_Movie::ClearCurrentMovie()
107157
{
108-
#ifdef ASW_BINK_MOVIES
109-
if ( m_nBIKMaterial != BIKMATERIAL_INVALID )
110-
{
111-
// FIXME: Make sure the m_pMaterial is actually destroyed at this point!
112-
g_pBIK->DestroyMaterial( m_nBIKMaterial );
113-
m_nBIKMaterial = BIKMATERIAL_INVALID;
114-
m_nTextureID = -1;
115-
}
116-
#else
117-
if ( m_nAVIMaterial != AVIMATERIAL_INVALID )
158+
if (m_nMaterialType != MATERIAL_INVALID)
118159
{
119-
// FIXME: Make sure the m_pMaterial is actually destroyed at this point!
120-
g_pAVI->DestroyAVIMaterial( m_nAVIMaterial );
121-
m_nAVIMaterial = AVIMATERIAL_INVALID;
160+
switch (m_nMaterialType)
161+
{
162+
case MATERIAL_WEBM:
163+
g_pWEBM->DestroyVideoMaterial( m_pWEBMMaterial );
164+
break;
165+
case MATERIAL_BIK:
166+
g_pBIK->DestroyMaterial(m_nBIKMaterial);
167+
break;
168+
}
169+
m_nMaterialType = MATERIAL_INVALID;
122170
m_nTextureID = -1;
123171
}
124-
#endif
125172
}
126173

127174
int CASW_Background_Movie::SetTextureMaterial()
128175
{
129-
#ifdef ASW_BINK_MOVIES
130-
if ( m_nBIKMaterial == BIKMATERIAL_INVALID )
131-
return -1;
132-
#else
133-
if ( m_nAVIMaterial == AVIMATERIAL_INVALID )
176+
if (m_nMaterialType == MATERIAL_INVALID)
134177
return -1;
135-
#endif
136178

137-
if ( m_nTextureID == -1 )
179+
if (m_nTextureID == -1)
138180
{
139-
m_nTextureID = g_pMatSystemSurface->CreateNewTextureID( true );
181+
m_nTextureID = g_pMatSystemSurface->CreateNewTextureID(true);
140182
}
141-
142-
#ifdef ASW_BINK_MOVIES
143-
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureID, g_pBIK->GetMaterial( m_nBIKMaterial ) );
144-
#else
145-
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureID, g_pAVI->GetMaterial( m_nAVIMaterial ) );
146-
#endif
183+
184+
switch (m_nMaterialType)
185+
{
186+
case MATERIAL_WEBM:
187+
{
188+
IMaterial *pMaterial = m_pWEBMMaterial->GetMaterial();
189+
if ( pMaterial )
190+
{
191+
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureID, pMaterial );
192+
}
193+
break;
194+
}
195+
case MATERIAL_BIK:
196+
g_pMatSystemSurface->DrawSetTextureMaterial(m_nTextureID, g_pBIK->GetMaterial(m_nBIKMaterial));
197+
break;
198+
}
199+
147200
return m_nTextureID;
148201
}
149202

@@ -159,7 +212,6 @@ void CASW_Background_Movie::Update( bool bForce )
159212
if ( ( nGameState != m_nLastGameState || bForce ) && !( nGameState == ASW_GS_LAUNCHING || nGameState == ASW_GS_INGAME ) )
160213
{
161214
const char *pFilename = NULL;
162-
#ifdef ASW_BINK_MOVIES
163215
const char *szMovieType = "briefing";
164216
if ( ASWGameRules()->GetGameState() >= ASW_GS_DEBRIEF )
165217
{
@@ -180,12 +232,8 @@ void CASW_Background_Movie::Update( bool bForce )
180232
pFilename = NULL;
181233
}
182234
}
183-
184235
if ( pFilename == NULL )
185236
pFilename = UTIL_RD_RandomBriefingMovie( engine->GetLevelNameShort(), ASWGameRules()->m_iCosmeticRandomSeed, szMovieType );
186-
#else
187-
pFilename = "media/test.avi";
188-
#endif
189237
if ( pFilename )
190238
{
191239
SetCurrentMovie( pFilename );
@@ -198,55 +246,65 @@ void CASW_Background_Movie::Update( bool bForce )
198246
int nGameState = 0;
199247
if ( nGameState != m_nLastGameState || bForce )
200248
{
201-
#ifdef ASW_BINK_MOVIES
202249
const char *szMainMenuImage, *szMainMenuVideo, *szMainMenuAudio;
203250
UTIL_RD_DecideMainMenuBackground( szMainMenuImage, szMainMenuVideo, szMainMenuAudio, false );
204251
SetCurrentMovie( szMainMenuVideo );
205-
#else
206-
SetCurrentMovie( "media/test.avi" );
207-
#endif
208252
m_nLastGameState = nGameState;
209253
}
210254
}
211255

212-
#ifdef ASW_BINK_MOVIES
213-
if ( m_nBIKMaterial == BIKMATERIAL_INVALID )
256+
if (m_nMaterialType == MATERIAL_INVALID)
214257
return;
215258

216-
if ( g_pBIK->ReadyForSwap( m_nBIKMaterial ) )
259+
switch (m_nMaterialType)
217260
{
218-
if ( g_pBIK->Update( m_nBIKMaterial ) == false )
261+
case MATERIAL_WEBM:
262+
if ( !s_bLastReduceMotion && rd_reduce_motion.GetBool() )
219263
{
220-
// FIXME: Make sure the m_pMaterial is actually destroyed at this point!
221-
g_pBIK->DestroyMaterial( m_nBIKMaterial );
222-
m_nBIKMaterial = BIKMATERIAL_INVALID;
264+
s_bLastReduceMotion = true;
265+
m_pWEBMMaterial->SetPaused( true );
223266
}
224-
else if ( !s_bLastReduceMotion && rd_reduce_motion.GetBool() )
267+
else if ( s_bLastReduceMotion && !rd_reduce_motion.GetBool() )
225268
{
226-
s_bLastReduceMotion = true;
227-
bik->Pause( m_nBIKMaterial );
269+
s_bLastReduceMotion = false;
270+
m_pWEBMMaterial->SetPaused( false );
228271
}
229-
}
230272

231-
if ( m_nBIKMaterial != BIKMATERIAL_INVALID && s_bLastReduceMotion && !rd_reduce_motion.GetBool() )
232-
{
233-
s_bLastReduceMotion = false;
234-
bik->Unpause( m_nBIKMaterial );
235-
}
236-
#else
237-
if ( m_nAVIMaterial == AVIMATERIAL_INVALID )
238-
return;
239-
240-
int nFrames = avi->GetFrameCount( m_nAVIMaterial );
241-
float flTimePerFrame = 1.0f / avi->GetFrameRate( m_nAVIMaterial );
242-
float flTimePassed = gpGlobals->realtime - m_flStartTime;
243-
int nFramesPassed = flTimePassed / flTimePerFrame;
244-
nFramesPassed = nFramesPassed % nFrames;
245-
avi->SetFrame( m_nAVIMaterial, nFramesPassed );
273+
if ( !m_pWEBMMaterial->Update() )
274+
{
275+
if ( m_pWEBMMaterial->IsLooping() )
276+
{
277+
m_pWEBMMaterial->SetTime( 0.0f );
278+
}
279+
else
280+
{
281+
g_pWEBM->DestroyVideoMaterial( m_pWEBMMaterial );
282+
m_nMaterialType = MATERIAL_INVALID;
283+
}
284+
}
285+
break;
286+
case MATERIAL_BIK:
287+
if (g_pBIK->ReadyForSwap(m_nBIKMaterial))
288+
{
289+
if (g_pBIK->Update(m_nBIKMaterial) == false)
290+
{
291+
g_pBIK->DestroyMaterial(m_nBIKMaterial);
292+
m_nMaterialType = MATERIAL_INVALID;
293+
}
294+
else if (!s_bLastReduceMotion && rd_reduce_motion.GetBool())
295+
{
296+
s_bLastReduceMotion = true;
297+
bik->Pause(m_nBIKMaterial);
298+
}
299+
}
246300

247-
// float flMaxU, flMaxV;
248-
// g_pAVI->GetTexCoordRange( m_nAVIMaterial, &flMaxU, &flMaxV );
249-
#endif
301+
if (m_nMaterialType != MATERIAL_INVALID && s_bLastReduceMotion && !rd_reduce_motion.GetBool())
302+
{
303+
s_bLastReduceMotion = false;
304+
bik->Unpause(m_nBIKMaterial);
305+
}
306+
break;
307+
}
250308
}
251309

252310
// ======================================

src/game/client/swarm/vgui/nb_header_footer.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
#include <vgui/VGUI.h>
88
#include <vgui_controls/EditablePanel.h>
99

10-
#define ASW_BINK_MOVIES
11-
12-
#ifdef ASW_BINK_MOVIES
1310
#include "avi/ibik.h"
14-
#else
15-
#include "avi/iavi.h"
16-
#endif
11+
#include "ivideoservices.h"
12+
13+
extern IVideoServices *g_pWEBM;
1714

1815
// == MANAGED_CLASS_DECLARATIONS_START: Do not edit by hand ==
1916
class vgui::Label;
@@ -48,13 +45,20 @@ class CASW_Background_Movie
4845
int SetTextureMaterial();
4946
void ClearCurrentMovie();
5047

48+
enum VideoMaterialType
49+
{
50+
MATERIAL_INVALID = -1,
51+
MATERIAL_BIK,
52+
MATERIAL_WEBM
53+
};
54+
5155
private:
52-
#ifdef ASW_BINK_MOVIES
53-
BIKMaterial_t m_nBIKMaterial;
54-
#else
55-
AVIMaterial_t m_nAVIMaterial;
56-
float m_flStartTime;
57-
#endif
56+
union {
57+
BIKMaterial_t m_nBIKMaterial;
58+
IVideoMaterial *m_pWEBMMaterial;
59+
};
60+
VideoMaterialType m_nMaterialType;
61+
5862
int m_nTextureID;
5963
char m_szCurrentMovie[ MAX_PATH ];
6064
int m_nLastGameState;

0 commit comments

Comments
 (0)