From 2fb754a83a82e9c6a7a0d1181431bbcaf2cb3abb Mon Sep 17 00:00:00 2001 From: superp00t Date: Tue, 5 Mar 2024 16:24:33 -0500 Subject: [PATCH] refactor(thunderbrew): use static size members instead of null-termination to delimit FrameScript_Method arrays --- src/gx/CGVideoOptions.cpp | 10 +++++----- src/gx/CGVideoOptions.hpp | 9 +++++---- src/gx/glsdl/CGxDeviceGLSDL.cpp | 2 -- src/gx/glsdl/GLMipmap.cpp | 6 +++--- src/sound/SI2.cpp | 7 ++----- src/sound/SI2.hpp | 1 + src/sound/SI2Script.cpp | 5 +++-- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/gx/CGVideoOptions.cpp b/src/gx/CGVideoOptions.cpp index c779e76..8551b9b 100644 --- a/src/gx/CGVideoOptions.cpp +++ b/src/gx/CGVideoOptions.cpp @@ -32,14 +32,14 @@ FrameScript_Method CGVideoOptions::s_ScriptFunctions[] = { { "GetRefreshRates", &Script_GetRefreshRates }, { "GetCurrentMultisampleFormat", &Script_GetCurrentMultisampleFormat }, { "GetMultisampleFormats", &Script_GetMultisampleFormats }, - { "IsStereoVideoAvailable", &Script_IsStereoVideoAvailable }, - { nullptr, nullptr } + { "IsStereoVideoAvailable", &Script_IsStereoVideoAvailable } }; +size_t CGVideoOptions::s_NumScriptFunctions = sizeof(CGVideoOptions::s_ScriptFunctions) / sizeof(FrameScript_Method); + void CGVideoOptions::RegisterScriptFunctions() { - FrameScript_Method* item = s_ScriptFunctions; - while (item->name) { + for (int32_t i = 0; i < CGVideoOptions::s_NumScriptFunctions; i++) { + auto item = &s_ScriptFunctions[i]; FrameScript_RegisterFunction(item->name, item->method); - item++; } } diff --git a/src/gx/CGVideoOptions.hpp b/src/gx/CGVideoOptions.hpp index 048e10f..84da0e0 100644 --- a/src/gx/CGVideoOptions.hpp +++ b/src/gx/CGVideoOptions.hpp @@ -6,11 +6,12 @@ class CGVideoOptions { public: - // Static variables - static FrameScript_Method s_ScriptFunctions[]; + // Static variables + static FrameScript_Method s_ScriptFunctions[]; + static size_t CGVideoOptions::s_NumScriptFunctions; - // Static functions - static void RegisterScriptFunctions(); + // Static functions + static void RegisterScriptFunctions(); }; #endif diff --git a/src/gx/glsdl/CGxDeviceGLSDL.cpp b/src/gx/glsdl/CGxDeviceGLSDL.cpp index 89f7444..16eba2c 100644 --- a/src/gx/glsdl/CGxDeviceGLSDL.cpp +++ b/src/gx/glsdl/CGxDeviceGLSDL.cpp @@ -1268,8 +1268,6 @@ void CGxDeviceGLSDL::SceneClear(uint32_t mask, CImVector color) { } void CGxDeviceGLSDL::ScenePresent() { - this->m_GLSDLWindow.DispatchEvents(); - if (this->m_context) { // TODO diff --git a/src/gx/glsdl/GLMipmap.cpp b/src/gx/glsdl/GLMipmap.cpp index e913ed8..e66440e 100644 --- a/src/gx/glsdl/GLMipmap.cpp +++ b/src/gx/glsdl/GLMipmap.cpp @@ -7,7 +7,7 @@ int32_t GLMipmap::GetDepthBits() { return this->m_DepthBits; } -void GLMipmap::Attach(GLFramebuffer* framebuffer, GLenum attachPoint, int32_t a4) { +void GLMipmap::Attach(GLFramebuffer* framebuffer, GLenum attachPoint, int32_t level) { if (!this->m_AttachPoints) { this->m_AttachPoints = new std::vector(); } @@ -44,7 +44,7 @@ void GLMipmap::Attach(GLFramebuffer* framebuffer, GLenum attachPoint, int32_t a4 GL_TEXTURE_3D, this->m_Texture->m_TextureID, this->m_Level, - a4 + level ); } else { glFramebufferTexture2DEXT( @@ -67,7 +67,7 @@ void GLMipmap::Attach(GLFramebuffer* framebuffer, GLenum attachPoint, int32_t a4 auto& attach = attachPoints[framebufferID]; attach.framebuffer = framebuffer; - attach.zOffset = a4; + attach.zOffset = level; if ( (attach.point != GL_DEPTH_ATTACHMENT || attachPoint != GL_STENCIL_ATTACHMENT) diff --git a/src/sound/SI2.cpp b/src/sound/SI2.cpp index eef2cca..389d855 100644 --- a/src/sound/SI2.cpp +++ b/src/sound/SI2.cpp @@ -18,17 +18,14 @@ void F_CALL FMOD_Free(void* ptr, FMOD_MEMORY_TYPE type, const char* sourcestr) { SMemFree(ptr, sourcestr, 0, 0); } - void SI2::RegisterScriptFunctions() { - FrameScript_Method* item = s_ScriptFunctions; - while (item->name) { + for (int32_t i = 0; i < s_NumScriptFunctions; i++) { + auto item = &s_ScriptFunctions[i]; FrameScript_RegisterFunction(item->name, item->method); - item++; } } int32_t SI2::Init(int32_t flag) { - Log_Init(); SI2_LOG("=> Version %s (%s) %s", "1.0.0", "00000", "Feb 25 2024"); SI2_LOG(" "); diff --git a/src/sound/SI2.hpp b/src/sound/SI2.hpp index bd8a881..7b434d5 100644 --- a/src/sound/SI2.hpp +++ b/src/sound/SI2.hpp @@ -16,6 +16,7 @@ class SI2 { public: // Static variables static FrameScript_Method s_ScriptFunctions[]; + static size_t s_NumScriptFunctions; static uint32_t sm_logFlags; static HSLOG sm_log; static FMOD::System* sm_pGameSystem; diff --git a/src/sound/SI2Script.cpp b/src/sound/SI2Script.cpp index 138b994..40d77f2 100644 --- a/src/sound/SI2Script.cpp +++ b/src/sound/SI2Script.cpp @@ -122,6 +122,7 @@ FrameScript_Method SI2::s_ScriptFunctions[] = { { "VoiceChat_IsRecordingLoopbackSound", &Script_VoiceChat_IsRecordingLoopbackSound }, { "VoiceChat_IsPlayingLoopbackSound", &Script_VoiceChat_IsPlayingLoopbackSound }, { "VoiceChat_GetCurrentMicrophoneSignalLevel", &Script_VoiceChat_GetCurrentMicrophoneSignalLevel }, - { "VoiceChat_ActivatePrimaryCaptureCallback", &Script_VoiceChat_ActivatePrimaryCaptureCallback }, - { nullptr, nullptr } + { "VoiceChat_ActivatePrimaryCaptureCallback", &Script_VoiceChat_ActivatePrimaryCaptureCallback } }; + +size_t SI2::s_NumScriptFunctions = sizeof(SI2::s_ScriptFunctions) / sizeof(FrameScript_Method);