summaryrefslogtreecommitdiff
path: root/soundsystem/snd_io.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /soundsystem/snd_io.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'soundsystem/snd_io.cpp')
-rw-r--r--soundsystem/snd_io.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/soundsystem/snd_io.cpp b/soundsystem/snd_io.cpp
new file mode 100644
index 0000000..887e1a8
--- /dev/null
+++ b/soundsystem/snd_io.cpp
@@ -0,0 +1,93 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//===========================================================================//
+
+#include "soundsystem.h"
+#include "tier2/riff.h"
+#include "filesystem.h"
+#include "tier1/strtools.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+//-----------------------------------------------------------------------------
+// Purpose: Implements Audio IO on the engine's COMMON filesystem
+//-----------------------------------------------------------------------------
+class COM_IOReadBinary : public IFileReadBinary
+{
+public:
+ int open( const char *pFileName );
+ int read( void *pOutput, int size, int file );
+ void seek( int file, int pos );
+ unsigned int tell( int file );
+ unsigned int size( int file );
+ void close( int file );
+};
+
+
+// prepend sound/ to the filename -- all sounds are loaded from the sound/ directory
+int COM_IOReadBinary::open( const char *pFileName )
+{
+ char namebuffer[512];
+ FileHandle_t hFile;
+
+ Q_strncpy(namebuffer, "sound", sizeof( namebuffer ) );
+
+ //HACK HACK HACK the server is sending back sound names with slashes in front...
+ if (pFileName[0]!='/')
+ {
+ Q_strncat(namebuffer,"/", sizeof( namebuffer ), COPY_ALL_CHARACTERS );
+ }
+
+ Q_strncat( namebuffer, pFileName, sizeof( namebuffer ), COPY_ALL_CHARACTERS );
+
+ hFile = g_pFullFileSystem->Open( namebuffer, "rb", "GAME" );
+
+ return (int)hFile;
+}
+
+int COM_IOReadBinary::read( void *pOutput, int size, int file )
+{
+ if ( !file )
+ return 0;
+
+ return g_pFullFileSystem->Read( pOutput, size, (FileHandle_t)file );
+}
+
+void COM_IOReadBinary::seek( int file, int pos )
+{
+ if ( !file )
+ return;
+
+ g_pFullFileSystem->Seek( (FileHandle_t)file, pos, FILESYSTEM_SEEK_HEAD );
+}
+
+unsigned int COM_IOReadBinary::tell( int file )
+{
+ if ( !file )
+ return 0;
+ return g_pFullFileSystem->Tell( (FileHandle_t)file );
+}
+
+unsigned int COM_IOReadBinary::size( int file )
+{
+ if (!file)
+ return 0;
+ return g_pFullFileSystem->Size( (FileHandle_t)file );
+}
+
+void COM_IOReadBinary::close( int file )
+{
+ if (!file)
+ return;
+
+ g_pFullFileSystem->Close( (FileHandle_t)file );
+}
+
+static COM_IOReadBinary io;
+IFileReadBinary *g_pSndIO = &io;
+