Skip to content

Commit

Permalink
Merge pull request #18 from LAGonauta/fix-msising-voices
Browse files Browse the repository at this point in the history
Hopefully fixed missing voices issue on Release mode.
  • Loading branch information
LAGonauta committed Jan 17, 2020
2 parents 86d6cd3 + e16d6ed commit 92b7efb
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 57 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -45,12 +45,14 @@ set(ALSOFT_TESTS OFF)
set(ALSOFT_UTILS OFF)
add_subdirectory(externals/openal-soft)

set(OPENAL_INCLUDE_DIR "../openal-soft/include/AL")
set(ALURE_INSTALL OFF)
set(ALURE_BUILD_STATIC OFF)
set(ALURE_ENABLE_WAVE OFF)
set(ALURE_ENABLE_VORBIS OFF)
set(ALURE_ENABLE_FLAC OFF)
set(ALURE_ENABLE_SNDFILE ON)
set(SNDFILE_LIBRARY "C:\\Program Files (x86)\\Mega-Nerd\\libsndfile\\lib\\libsndfile-1.lib")
set(SNDFILE_INCLUDE_DIR "C:\\Program Files (x86)\\Mega-Nerd\\libsndfile\\include")
set(ALURE_BUILD_EXAMPLES OFF)
add_subdirectory(externals/alure)

Expand Down
4 changes: 2 additions & 2 deletions CMakeSettings.json
Expand Up @@ -9,7 +9,7 @@
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\MetaAudio\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\MetaAudio\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DOPENAL_LIBRARY=${env.USERPROFILE}\\CMakeBuilds\\MetaAudio\\${workspaceHash}\\build\\${name}\\externals\\openal-soft\\OpenAL32.lib",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
Expand All @@ -22,7 +22,7 @@
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\MetaAudio\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\MetaAudio\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DOPENAL_LIBRARY=${env.USERPROFILE}\\CMakeBuilds\\MetaAudio\\${workspaceHash}\\build\\${name}\\externals\\openal-soft\\OpenAL32.lib",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/snd_dma.cpp
Expand Up @@ -4,7 +4,7 @@
#include "snd_fx.hpp"
#include "snd_voice.hpp"
#include "snd_vox.hpp"
#include "snd_loader.h"
#include "snd_loader.hpp"
#include "zone.h"

//sfx struct
Expand Down
57 changes: 46 additions & 11 deletions src/snd_loader.cpp
@@ -1,8 +1,9 @@
#include <iostream>
#include <fstream>

#include "FileSystem.h"
#include "alure2.h"
#include "snd_loader.h"
#include "snd_loader.hpp"

// Based on Alure's Stream class
class GoldSrcFileBuf final : public std::streambuf {
Expand Down Expand Up @@ -90,19 +91,16 @@ class GoldSrcFileBuf final : public std::streambuf {
{
return traits_type::eof();
}
auto curPosition = g_pFileSystem->Tell(mFile);

setg(nullptr, nullptr, nullptr);
return pos;
return curPosition;
}

public:
bool open(const char *filename) noexcept
{
mFile = g_pFileSystem->OpenFromCacheForRead(filename, "rb");
if (!mFile)
{
mFile = g_pFileSystem->Open(filename, "rb");
}
mFile = g_pFileSystem->Open(filename, "rb");
if (!mFile)
{
return false;
Expand Down Expand Up @@ -135,10 +133,47 @@ class GoldSrcFileStream final : public std::istream {

alure::UniquePtr<std::istream> GoldSrcFileFactory::openFile(const alure::String &name) noexcept
{
auto stream = alure::MakeUnique<GoldSrcFileStream>(name.c_str());
if (stream->fail())
alure::String namebuffer = "sound";

if (name[0] != '/')
{
stream = nullptr;
namebuffer.append("/");
}
return std::move(stream);

namebuffer.append(name);

auto fileExists = g_pFileSystem->FileExists(namebuffer.c_str());
if (!fileExists)
{
namebuffer.clear();
if (name[0] != '/')
{
namebuffer.append("/");
}
namebuffer.append(name);

fileExists = g_pFileSystem->FileExists(namebuffer.c_str());
}

alure::UniquePtr<std::istream> file;
if (fileExists)
{
char final_file_path[260]; // MAX_PATH
g_pFileSystem->GetLocalPath(namebuffer.c_str(), final_file_path, sizeof(final_file_path));
file = alure::MakeUnique<std::ifstream>(final_file_path, std::ios::binary);
if (file->fail())
{
file = alure::MakeUnique<GoldSrcFileStream>(namebuffer.c_str());
if (file->fail())
{
file = nullptr;
}
else
{
*file >> std::noskipws;
}
}
}

return std::move(file);
}
58 changes: 16 additions & 42 deletions src/snd_mem.cpp
Expand Up @@ -10,81 +10,55 @@
static auto local_decoder = alure::MakeShared<LocalAudioDecoder>();

// Check if file exists. Order: original, .wav, .flac, .ogg, .mp3
static std::optional<alure::String> S_GetFilePath(alure::String sfx_name, bool is_stream)
static std::optional<alure::String> S_GetFilePath(const alure::String& sfx_name, bool is_stream)
{
alure::String original_name = sfx_name;
alure::String new_name(sfx_name);
alure::String m_function_name;
if (is_stream)
{
m_function_name = "S_LoadStreamSound";
sfx_name.erase(sfx_name.begin());
new_name.erase(new_name.begin());
}
else
{
m_function_name = "S_LoadSound";
}
bool valid_file = false;
alure::String namebuffer;

int char_index = sfx_name.rfind('.', sfx_name.length());
int char_index = new_name.rfind('.', new_name.length());

if (char_index != sfx_name.npos)
if (char_index != new_name.npos)
{
auto context = alure::Context::GetCurrent();
for (const alure::String& extension : LocalAudioDecoder::SupportedExtensions)
{
sfx_name.replace(char_index, sfx_name.npos, extension);

namebuffer = "sound";
if (sfx_name[0] != '/')
new_name.replace(char_index, new_name.npos, extension);
try
{
namebuffer.append("/");
auto dec = context.createDecoder(new_name);
valid_file = true;
break;
}

namebuffer.append(sfx_name);

auto fileExists = g_pFileSystem->FileExists(namebuffer.c_str());
if (!fileExists)
{
namebuffer.clear();
if (sfx_name[0] != '/')
{
namebuffer.append("/");
}
namebuffer.append(sfx_name);

fileExists = g_pFileSystem->FileExists(namebuffer.c_str());
}

if (fileExists)
catch (const std::runtime_error& error)
{
try
{
auto dec = context.createDecoder(namebuffer);
valid_file = true;
break;
}
catch (const std::runtime_error& error)
{
gEngfuncs.Con_DPrintf("%s: Couldn't load %s. %s.\n", m_function_name.c_str(), namebuffer.c_str(), error.what());
valid_file = false;
}
gEngfuncs.Con_DPrintf("%s: Couldn't load %s. %s.\n", m_function_name.c_str(), new_name.c_str(), error.what());
valid_file = false;
}
}
}
else
{
gEngfuncs.Con_DPrintf("%s: Couldn't load %s. Invalid file name.\n", m_function_name.c_str(), namebuffer.c_str());
gEngfuncs.Con_DPrintf("%s: Couldn't load %s. Invalid file name.\n", m_function_name.c_str(), sfx_name.c_str());
return std::optional<alure::String>{};
}

if (valid_file)
{
return namebuffer;
return new_name;
}
else
{
gEngfuncs.Con_DPrintf("%s: Couldn't load %s.\n", m_function_name.c_str(), original_name.c_str());
gEngfuncs.Con_DPrintf("%s: Couldn't load %s.\n", m_function_name.c_str(), sfx_name.c_str());
return std::nullopt;
}
}
Expand Down

0 comments on commit 92b7efb

Please sign in to comment.