Skip to content

Commit

Permalink
3rdParty: apply pending patches for mupen64plus-video-GLideN64
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed May 24, 2024
1 parent 5febea4 commit f306caa
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
50 changes: 50 additions & 0 deletions Source/3rdParty/mupen64plus-video-GLideN64/src/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <fstream>
#include <ctime>

#ifndef MUPENPLUSAPI // zilmar spec

std::mutex g_logMutex;
std::wofstream fileOutput;

Expand Down Expand Up @@ -113,6 +115,54 @@ void LogDebug(const char* _fileName, int _line, u16 _type, const char* _format,
fileOutput.flush();
}

#else // mupen64plus
#include "mupenplus/GLideN64_mupenplus.h"

void LogDebug(const char* _fileName, int _line, u16 _type, const char* _format, ...)
{
static const int logLevel[] = {
M64MSG_INFO,
M64MSG_ERROR,
M64MSG_INFO,
M64MSG_WARNING,
M64MSG_VERBOSE,
M64MSG_VERBOSE
};

if (CoreDebugCallback == nullptr ||
_type > LOG_LEVEL)
{
return;
}

// initialize use of the variable argument array
va_list vaArgs;
va_start(vaArgs, _format);

// reliably acquire the size from a copy of
// the variable argument array
// and a functionally reliable call
// to mock the formatting
va_list vaCopy;
va_copy(vaCopy, vaArgs);
const int iLen = std::vsnprintf(NULL, 0, _format, vaCopy);
va_end(vaCopy);

// return a formatted string without
// risking memory mismanagement
// and without assuming any compiler
// or platform specific behavior
std::vector<char> zc(iLen + 1);
std::vsnprintf(zc.data(), zc.size(), _format, vaArgs);
va_end(vaArgs);

std::stringstream formatString;
formatString << _fileName << ":" << _line << ", \"" << zc.data() << "\"";

CoreDebugCallback(CoreDebugCallbackContext, logLevel[_type], formatString.str().c_str());
}
#endif

#if defined(OS_WINDOWS) && !defined(MINGW)
#include "windows/GLideN64_windows.h"
void debugPrint(const char * format, ...) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ EXPORT m64p_error CALL PluginStartup(
void (*DebugCallback)(void *, int, const char *)
)
{
return api().PluginStartup(CoreLibHandle);
return api().PluginStartup(CoreLibHandle, Context, DebugCallback);
}

#ifdef M64P_GLIDENUI
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/mupen64plus-video-GLideN64/src/PluginAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PluginAPI
void ResizeVideoOutput(int _Width, int _Height);
void ReadScreen2(void * _dest, int * _width, int * _height, int _front);

m64p_error PluginStartup(m64p_dynlib_handle _CoreLibHandle);
m64p_error PluginStartup(m64p_dynlib_handle _CoreLibHandle, void * Context, void (*DebugCallback)(void *, int, const char *));
#ifdef M64P_GLIDENUI
m64p_error PluginConfig();
#endif // M64P_GLIDENUI
Expand Down
4 changes: 1 addition & 3 deletions Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,10 +1226,8 @@ bool TextureCache::_loadHiresTexture(u32 _tile, CachedTexture *_pTexture, u64 &
GHQTexInfo ghqTexInfo;
// TODO: fix problem with zero texture dimensions on GLideNHQ side.
auto hirestexFound = txfilter_hirestex(_pTexture->crc, _ricecrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo);
if (!hirestexFound) {
if (!hirestexFound && _strongcrc != 0U) {
// Texture with RiceCRC was not found. Try alternative CRC.
if (_strongcrc == 0U)
_strongcrc = txfilter_checksum_strong(addr, width, height, _pTexture->size, bpl, paladdr);
hirestexFound = txfilter_hirestex(_pTexture->crc, _strongcrc, palette, N64FormatSize(_pTexture->format, _pTexture->size), &ghqTexInfo);
}
if (hirestexFound && ghqTexInfo.width != 0 && ghqTexInfo.height != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "m64p_common.h"
#include "m64p_config.h"
#include "m64p_vidext.h"
#include "m64p_frontend.h"

#define PLUGIN_VERSION 0x020000
#define VIDEO_PLUGIN_API_VERSION 0x020200
Expand Down Expand Up @@ -53,6 +54,9 @@ extern ptr_VidExt_GL_GetDefaultFramebuffer CoreVideo_GL_GetDefaultFramebuffer;

extern ptr_PluginGetVersion CoreGetVersion;

extern void* CoreDebugCallbackContext;
extern ptr_DebugCallback CoreDebugCallback;

extern const unsigned int* rdram_size;

extern void(*renderCallback)(int);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ ptr_VidExt_GL_GetDefaultFramebuffer CoreVideo_GL_GetDefaultFramebuffer = nullptr

ptr_PluginGetVersion CoreGetVersion = nullptr;

void* CoreDebugCallbackContext = nullptr;
ptr_DebugCallback CoreDebugCallback = nullptr;

const unsigned int* rdram_size = nullptr;

void(*renderCallback)(int) = nullptr;
void (*renderCallback)(int) = nullptr;

m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle)
m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle, void* Context, void (*DebugCallback)(void *, int, const char *))
{
CoreDebugCallbackContext = Context;
CoreDebugCallback = DebugCallback;

ConfigGetSharedDataFilepath = (ptr_ConfigGetSharedDataFilepath) DLSYM(_CoreLibHandle, "ConfigGetSharedDataFilepath");
ConfigGetUserConfigPath = (ptr_ConfigGetUserConfigPath) DLSYM(_CoreLibHandle, "ConfigGetUserConfigPath");
ConfigGetUserCachePath = (ptr_ConfigGetUserCachePath)DLSYM(_CoreLibHandle, "ConfigGetUserCachePath");
Expand Down

0 comments on commit f306caa

Please sign in to comment.