mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2026-01-30 19:42:51 +03:00
feat(sound): add SI2 Log methods
This commit is contained in:
parent
e7a11be6aa
commit
91e29bbf52
@ -13,4 +13,6 @@ target_link_libraries(sound
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
ui
|
ui
|
||||||
util
|
util
|
||||||
|
PUBLIC
|
||||||
|
fmod
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2,10 +2,13 @@
|
|||||||
#include "ui/FrameScript.hpp"
|
#include "ui/FrameScript.hpp"
|
||||||
|
|
||||||
void SI2::RegisterScriptFunctions() {
|
void SI2::RegisterScriptFunctions() {
|
||||||
for (int32_t i = 0; i < NUM_SCRIPT_FUNCTIONS_SI2; ++i) {
|
FrameScript_Method* item = s_ScriptFunctions;
|
||||||
FrameScript_RegisterFunction(
|
while (item->name) {
|
||||||
SI2::s_ScriptFunctions[i].name,
|
FrameScript_RegisterFunction(item->name, item->method);
|
||||||
SI2::s_ScriptFunctions[i].method
|
item++;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t SI2::Init(int32_t flag) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,17 +1,26 @@
|
|||||||
#ifndef SOUND_SI2_HPP
|
#ifndef SOUND_SI2_HPP
|
||||||
#define SOUND_SI2_HPP
|
#define SOUND_SI2_HPP
|
||||||
|
|
||||||
#include "sound/SI2Script.hpp"
|
|
||||||
#include "ui/Types.hpp"
|
#include "ui/Types.hpp"
|
||||||
|
#include <storm/Log.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <fmod.h>
|
||||||
|
#include <fmod_errors.h>
|
||||||
|
|
||||||
class SI2 {
|
class SI2 {
|
||||||
public:
|
public:
|
||||||
// Static variables
|
// Static variables
|
||||||
static FrameScript_Method s_ScriptFunctions[NUM_SCRIPT_FUNCTIONS_SI2];
|
static FrameScript_Method s_ScriptFunctions[];
|
||||||
|
static uint32_t sm_logFlags;
|
||||||
|
static HSLOG sm_log;
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
static void RegisterScriptFunctions();
|
static void RegisterScriptFunctions();
|
||||||
|
static int32_t Log_Init();
|
||||||
|
static void Log_Write(const char* format, ...);
|
||||||
|
static void Log_Write(uint32_t line, const char* filename, FMOD_RESULT errcode, const char* format, ...);
|
||||||
|
static int32_t Init(int32_t flag);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
71
src/sound/SI2Log.cpp
Normal file
71
src/sound/SI2Log.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include "sound/SI2.hpp"
|
||||||
|
#include <storm/Error.hpp>
|
||||||
|
#include <bc/os/File.hpp>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
uint32_t SI2::sm_logFlags = SLOG_FLAG_DEFAULT;
|
||||||
|
HSLOG SI2::sm_log = nullptr;
|
||||||
|
|
||||||
|
int32_t SI2::Log_Init() {
|
||||||
|
OsCreateDirectory("Logs", 0);
|
||||||
|
SLogCreate("Logs\\Sound.log", sm_logFlags, &sm_log);
|
||||||
|
sm_logFlags |= SLOG_FLAG_APPEND;
|
||||||
|
// return OsDeleteFile((Blizzard::File*)"Logs\\SESound.log");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SI2::Log_Write(const char* format, ...) {
|
||||||
|
STORM_ASSERT(format);
|
||||||
|
|
||||||
|
char output[512] = { 0 };
|
||||||
|
if (format[0]) {
|
||||||
|
va_list va;
|
||||||
|
va_start(va, format);
|
||||||
|
vsnprintf(output, sizeof(output), format, va);
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log_Write(__LINE__, __FILE__, FMOD_OK, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SI2::Log_Write(uint32_t line, const char* filename, FMOD_RESULT errcode, const char* format, ...) {
|
||||||
|
static uint32_t s_nNumErrors = 0;
|
||||||
|
|
||||||
|
if (s_nNumErrors > 200) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s_nNumErrors == 200) {
|
||||||
|
SLogWrite(sm_log, " -######## TOO MANY ERRORS. NO FURTHER ERRORS WILL BE LOGGED.");
|
||||||
|
SLogFlush(sm_log);
|
||||||
|
s_nNumErrors++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
STORM_ASSERT(format);
|
||||||
|
|
||||||
|
char output[512] = { 0 };
|
||||||
|
if (format[0]) {
|
||||||
|
va_list va;
|
||||||
|
va_start(va, format);
|
||||||
|
vsnprintf(output, sizeof(output), format, va);
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errcode == FMOD_OK) {
|
||||||
|
SLogWrite(sm_log, output);
|
||||||
|
SLogFlush(sm_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errcode == FMOD_ERR_HTTP_PROXY_AUTH) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SLogWrite(sm_log, " -######## FMOD ERROR! (err %d) %s", errcode, FMOD_ErrorString(errcode));
|
||||||
|
if (format[0]) {
|
||||||
|
SLogWrite(sm_log, output);
|
||||||
|
}
|
||||||
|
SLogWrite(sm_log, "%s(%d)", filename, line);
|
||||||
|
SLogFlush(sm_log);
|
||||||
|
s_nNumErrors++;
|
||||||
|
}
|
||||||
@ -1,4 +1,3 @@
|
|||||||
#include "sound/SI2Script.hpp"
|
|
||||||
#include "sound/SI2.hpp"
|
#include "sound/SI2.hpp"
|
||||||
#include "ui/Types.hpp"
|
#include "ui/Types.hpp"
|
||||||
#include "util/Lua.hpp"
|
#include "util/Lua.hpp"
|
||||||
@ -100,7 +99,7 @@ int32_t Script_VoiceChat_ActivatePrimaryCaptureCallback(lua_State* L) {
|
|||||||
WHOA_UNIMPLEMENTED(0);
|
WHOA_UNIMPLEMENTED(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameScript_Method SI2::s_ScriptFunctions[NUM_SCRIPT_FUNCTIONS_SI2] = {
|
FrameScript_Method SI2::s_ScriptFunctions[] = {
|
||||||
{ "PlaySound", &Script_PlaySound },
|
{ "PlaySound", &Script_PlaySound },
|
||||||
{ "PlayMusic", &Script_PlayMusic },
|
{ "PlayMusic", &Script_PlayMusic },
|
||||||
{ "PlaySoundFile", &Script_PlaySoundFile },
|
{ "PlaySoundFile", &Script_PlaySoundFile },
|
||||||
@ -123,5 +122,6 @@ FrameScript_Method SI2::s_ScriptFunctions[NUM_SCRIPT_FUNCTIONS_SI2] = {
|
|||||||
{ "VoiceChat_IsRecordingLoopbackSound", &Script_VoiceChat_IsRecordingLoopbackSound },
|
{ "VoiceChat_IsRecordingLoopbackSound", &Script_VoiceChat_IsRecordingLoopbackSound },
|
||||||
{ "VoiceChat_IsPlayingLoopbackSound", &Script_VoiceChat_IsPlayingLoopbackSound },
|
{ "VoiceChat_IsPlayingLoopbackSound", &Script_VoiceChat_IsPlayingLoopbackSound },
|
||||||
{ "VoiceChat_GetCurrentMicrophoneSignalLevel", &Script_VoiceChat_GetCurrentMicrophoneSignalLevel },
|
{ "VoiceChat_GetCurrentMicrophoneSignalLevel", &Script_VoiceChat_GetCurrentMicrophoneSignalLevel },
|
||||||
{ "VoiceChat_ActivatePrimaryCaptureCallback", &Script_VoiceChat_ActivatePrimaryCaptureCallback }
|
{ "VoiceChat_ActivatePrimaryCaptureCallback", &Script_VoiceChat_ActivatePrimaryCaptureCallback },
|
||||||
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
#ifndef SOUND_SI2_SCRIPT_HPP
|
|
||||||
#define SOUND_SI2_SCRIPT_HPP
|
|
||||||
|
|
||||||
#define NUM_SCRIPT_FUNCTIONS_SI2 23
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Reference in New Issue
Block a user