Skip to content

Commit

Permalink
Use stringstream
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGonauta committed Dec 16, 2023
1 parent 76166f7 commit eb1bd25
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 217 deletions.
2 changes: 1 addition & 1 deletion include/AudioEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace MetaAudio
std::shared_ptr<SoundLoader> m_loader;

//Print buffer
std::string dprint_buffer;
std::stringstream dprint_buffer;

void S_FreeCache(sfx_t* sfx);
void S_FlushCaches(void);
Expand Down
21 changes: 12 additions & 9 deletions src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,13 @@ namespace MetaAudio
channel_manager->ClearLoopingRemovedEntities();

// Print buffer and clear it.
if (dprint_buffer.length())
{
gEngfuncs.Con_DPrintf(const_cast<char*>((dprint_buffer.c_str())));
dprint_buffer.clear();
auto str = dprint_buffer.str();
if (!str.empty())
{
gEngfuncs.Con_DPrintf(const_cast<char*>((str.c_str())));
dprint_buffer.clear();
}
}

AL_CopyVector(forward, orientation);
Expand Down Expand Up @@ -369,21 +372,21 @@ namespace MetaAudio

if (settings.SoundShow())
{
std::string output;
std::stringstream output;
size_t total = 0;
channel_manager->ForEachChannel([&](aud_channel_t& channel)
{
if (channel.sfx && channel.volume > 0)
{
output.append(std::to_string(static_cast<int>(channel.volume * 255.0f)) + " " + channel.sfx->name + "\n");
output << static_cast<int>(channel.volume * 255.0f) << " " << channel.sfx->name << std::endl;
++total;
}
});

if (!output.empty())
if (total > 0)
{
output.append("----(" + std::to_string(total) + ")----\n");
gEngfuncs.Con_Printf(const_cast<char*>(output.c_str()));
output << "----(" << total << ")----" << std::endl;
gEngfuncs.Con_Printf(const_cast<char*>(output.str().c_str()));
}
}
}
Expand Down Expand Up @@ -548,7 +551,7 @@ namespace MetaAudio
}
catch (const std::runtime_error& error)
{
dprint_buffer.append(_function_name).append(": ").append(error.what()).append("\n");
dprint_buffer << _function_name << ": " << error.what() << std::endl;
}
}

Expand Down
Loading

0 comments on commit eb1bd25

Please sign in to comment.