From 831b3410ede58b58063dabb7bf55e35ea14732e2 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Fri, 1 May 2015 15:20:51 +0600 Subject: [PATCH] Correct settings section creation for mupen64plus. --- src/mupenplus/Config_mupenplus.cpp | 98 ++++++++++++++++-------------- src/mupenplus/GLideN64_mupenplus.h | 1 + src/mupenplus/MupenPlusAPIImpl.cpp | 2 + 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/mupenplus/Config_mupenplus.cpp b/src/mupenplus/Config_mupenplus.cpp index 58a9d642..530ef472 100644 --- a/src/mupenplus/Config_mupenplus.cpp +++ b/src/mupenplus/Config_mupenplus.cpp @@ -29,114 +29,120 @@ bool Config_SetDefault() return false; } + config.resetToDefaults(); // Set default values for "Video-General" section, if they are not set yet. Taken from RiceVideo - m64p_error res = ConfigSetDefaultBool(g_configVideoGeneral, "Fullscreen", 0, "Use fullscreen mode if True, or windowed mode if False "); + m64p_error res = ConfigSetDefaultBool(g_configVideoGeneral, "Fullscreen", config.video.fullscreen, "Use fullscreen mode if True, or windowed mode if False "); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGeneral, "ScreenWidth", 640, "Width of output window or fullscreen width"); + res = ConfigSetDefaultInt(g_configVideoGeneral, "ScreenWidth", config.video.windowedWidth, "Width of output window or fullscreen width"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGeneral, "ScreenHeight", 480, "Height of output window or fullscreen height"); + res = ConfigSetDefaultInt(g_configVideoGeneral, "ScreenHeight", config.video.windowedHeight, "Height of output window or fullscreen height"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGeneral, "VerticalSync", 0, "If true, activate the SDL_GL_SWAP_CONTROL attribute"); + res = ConfigSetDefaultBool(g_configVideoGeneral, "VerticalSync", config.video.verticalSync, "If true, activate the SDL_GL_SWAP_CONTROL attribute"); assert(res == M64ERR_SUCCESS); res = ConfigSetDefaultInt(g_configVideoGliden64, "configVersion", CONFIG_VERSION_CURRENT, "Settings version. Don't touch it."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "MultiSampling", 0, "Enable/Disable MultiSampling (0=off, 2,4,8,16=quality)"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "MultiSampling", config.video.multisampling, "Enable/Disable MultiSampling (0=off, 2,4,8,16=quality)"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "AspectRatio", 0, "Screen aspect ratio (0=stretch, 1=force 4:3, 2=force 16:9, 3=adjust)"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "AspectRatio", config.frameBufferEmulation.aspect, "Screen aspect ratio (0=stretch, 1=force 4:3, 2=force 16:9, 3=adjust)"); assert(res == M64ERR_SUCCESS); //#Texture Settings - res = ConfigSetDefaultBool(g_configVideoGliden64, "bilinearMode", 0, "Bilinear filtering mode (0=N64 3point, 1=standard)"); + res = ConfigSetDefaultBool(g_configVideoGliden64, "bilinearMode", config.texture.bilinearMode, "Bilinear filtering mode (0=N64 3point, 1=standard)"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "MaxAnisotropy", 0, "Max level of Anisotropic Filtering, 0 for off"); + res = ConfigSetDefaultBool(g_configVideoGliden64, "MaxAnisotropy", config.texture.maxAnisotropy, "Max level of Anisotropic Filtering, 0 for off"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "CacheSize", 500, "Size of texture cache in megabytes. Good value is VRAM*3/4"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "CacheSize", config.texture.maxBytes / uMegabyte, "Size of texture cache in megabytes. Good value is VRAM*3/4"); assert(res == M64ERR_SUCCESS); //#Emulation Settings - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableFog", 1, "Enable fog emulation."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableFog", config.generalEmulation.enableFog, "Enable fog emulation."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableNoise", 1, "Enable color noise emulation."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableNoise", config.generalEmulation.enableNoise, "Enable color noise emulation."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableLOD", 1, "Enable LOD emulation."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableLOD", config.generalEmulation.enableLOD, "Enable LOD emulation."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableHWLighting", 1, "Enable hardware per-pixel lighting."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableHWLighting", config.generalEmulation.enableHWLighting, "Enable hardware per-pixel lighting."); assert(res == M64ERR_SUCCESS); //#Frame Buffer Settings:" - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableFBEmulation", 1, "Enable frame and|or depth buffer emulation."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableFBEmulation", config.frameBufferEmulation.enable, "Enable frame and|or depth buffer emulation."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableCopyColorToRDRAM", 0, "Enable color buffer copy to RDRAM."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableCopyColorToRDRAM", config.frameBufferEmulation.copyToRDRAM, "Enable color buffer copy to RDRAM."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableCopyDepthToRDRAM", 0, "Enable depth buffer copy to RDRAM."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableCopyDepthToRDRAM", config.frameBufferEmulation.copyDepthToRDRAM, "Enable depth buffer copy to RDRAM."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableCopyColorFromRDRAM", 0, "Enable color buffer copy from RDRAM."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableCopyColorFromRDRAM", config.frameBufferEmulation.copyFromRDRAM, "Enable color buffer copy from RDRAM."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableDetectCFB", 0, "Detect CPU writes to frame buffer."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableDetectCFB", config.frameBufferEmulation.detectCFB, "Detect CPU writes to frame buffer."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableN64DepthCompare", 0, "Enable N64 depth compare instead of OpenGL standard one. Experimental."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableN64DepthCompare", config.frameBufferEmulation.N64DepthCompare, "Enable N64 depth compare instead of OpenGL standard one. Experimental."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "ValidityCheckMethod", 0, "Method to check validity of auxiliary texture frame buffer (0=write fingerprint to the buffer, 1=fill whole buffer in RDRAM with test value)"); + res = ConfigSetDefaultBool(g_configVideoGliden64, "ValidityCheckMethod", config.frameBufferEmulation.validityCheckMethod, "Method to check validity of auxiliary texture frame buffer (0=write fingerprint to the buffer, 1=fill whole buffer in RDRAM with test value)"); assert(res == M64ERR_SUCCESS); //#Texture filter settings - res = ConfigSetDefaultInt(g_configVideoGliden64, "txFilterMode", 0, "Texture filter (0=none, 1=Smooth filtering 1, 2=Smooth filtering 2, 3=Smooth filtering 3, 4=Smooth filtering 4, 5=Sharp filtering 1, 6=Sharp filtering 2)"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "txFilterMode", config.textureFilter.txFilterMode, "Texture filter (0=none, 1=Smooth filtering 1, 2=Smooth filtering 2, 3=Smooth filtering 3, 4=Smooth filtering 4, 5=Sharp filtering 1, 6=Sharp filtering 2)"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "txEnhancementMode", 0, "Texture Enhancement (0=none, 1=store as is, 2=X2, 3=X2SAI, 4=HQ2X, 5=HQ2XS, 6=LQ2X, 7=LQ2XS, 8=HQ4X, 9=2xBRZ, 10=3xBRZ, 11=4xBRZ, 12=5xBRZ)"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "txEnhancementMode", config.textureFilter.txEnhancementMode, "Texture Enhancement (0=none, 1=store as is, 2=X2, 3=X2SAI, 4=HQ2X, 5=HQ2XS, 6=LQ2X, 7=LQ2XS, 8=HQ4X, 9=2xBRZ, 10=3xBRZ, 11=4xBRZ, 12=5xBRZ)"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txFilterIgnoreBG", 0, "Don't filter background textures."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txFilterIgnoreBG", config.textureFilter.txFilterIgnoreBG, "Don't filter background textures."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "txCacheSize", 128, "Size of filtered textures cache in megabytes."); + res = ConfigSetDefaultInt(g_configVideoGliden64, "txCacheSize", config.textureFilter.txCacheSize/uMegabyte, "Size of filtered textures cache in megabytes."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txHiresEnable", 0, "Use high-resolution texture packs if available."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txHiresEnable", config.textureFilter.txHiresEnable, "Use high-resolution texture packs if available."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txHiresFullAlphaChannel", 0, "Allow to use alpha channel of high-res texture fully."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txHiresFullAlphaChannel", config.textureFilter.txHiresFullAlphaChannel, "Allow to use alpha channel of high-res texture fully."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txHresAltCRC", 0, "Use alternative method of paletted textures CRC calculation."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txHresAltCRC", config.textureFilter.txHresAltCRC, "Use alternative method of paletted textures CRC calculation."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txDump", 0, "Enable dump of loaded N64 textures."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txDump", config.textureFilter.txDump, "Enable dump of loaded N64 textures."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txCacheCompression", 1, "Zip textures cache."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txCacheCompression", config.textureFilter.txCacheCompression, "Zip textures cache."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txForce16bpp", 0, "Force use 16bit texture formats for HD textures."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txForce16bpp", config.textureFilter.txForce16bpp, "Force use 16bit texture formats for HD textures."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultBool(g_configVideoGliden64, "txSaveCache", 1, "Save texture cache to hard disk."); + res = ConfigSetDefaultBool(g_configVideoGliden64, "txSaveCache", config.textureFilter.txSaveCache, "Save texture cache to hard disk."); assert(res == M64ERR_SUCCESS); -#ifdef OS_WINDOWS - res = ConfigSetDefaultString(g_configVideoGliden64, "fontName", "arial.ttf", "File name of True Type Font for text messages."); -#else - res = ConfigSetDefaultString(g_configVideoGliden64, "fontName", "FreeSans.ttf", "File name of True Type Font for text messages."); -#endif + res = ConfigSetDefaultString(g_configVideoGliden64, "fontName", config.font.name.c_str(), "File name of True Type Font for text messages."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "fontSize", 18, "Font size."); + res = ConfigSetDefaultInt(g_configVideoGliden64, "fontSize", config.font.size, "Font size."); assert(res == M64ERR_SUCCESS); res = ConfigSetDefaultString(g_configVideoGliden64, "fontColor", "B5E61D", "Font color in RGB format."); assert(res == M64ERR_SUCCESS); //#Bloom filter settings - res = ConfigSetDefaultInt(g_configVideoGliden64, "EnableBloom", 0, "Enable bloom filter"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "EnableBloom", config.bloomFilter.enable, "Enable bloom filter"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "bloomThresholdLevel", 4, "Brightness threshold level for bloom. Values [2, 6]"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "bloomThresholdLevel", config.bloomFilter.thresholdLevel, "Brightness threshold level for bloom. Values [2, 6]"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "bloomBlendMode", 0, "Bloom blend mode (0=Strong, 1=Mild, 2=Light)"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "bloomBlendMode", config.bloomFilter.blendMode, "Bloom blend mode (0=Strong, 1=Mild, 2=Light)"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "blurAmount", 10, "Blur radius. Values [2, 10]"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "blurAmount", config.bloomFilter.blurAmount, "Blur radius. Values [2, 10]"); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "blurStrength", 20, "Blur strength. Values [10, 100]"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "blurStrength", config.bloomFilter.blurStrength, "Blur strength. Values [10, 100]"); assert(res == M64ERR_SUCCESS); - return res == M64ERR_SUCCESS; + return ConfigSaveSection("Video-GLideN64") == M64ERR_SUCCESS; } void Config_LoadConfig() { - Config_SetDefault(); + const u32 hacks = config.generalEmulation.hacks; + + if (!Config_SetDefault()) { + config.generalEmulation.hacks = hacks; + return; + } + config.version = ConfigGetParamInt(g_configVideoGliden64, "configVersion"); if (config.version != CONFIG_VERSION_CURRENT) { m64p_error res = ConfigDeleteSection("Video-GLideN64"); assert(res == M64ERR_SUCCESS); ConfigSaveFile(); - Config_SetDefault(); + if (!Config_SetDefault()) { + config.generalEmulation.hacks = hacks; + return; + } } config.video.fullscreen = ConfigGetParamBool(g_configVideoGeneral, "Fullscreen"); @@ -202,4 +208,6 @@ void Config_LoadConfig() config.bloomFilter.blendMode = ConfigGetParamInt(g_configVideoGliden64, "bloomBlendMode"); config.bloomFilter.blurAmount = ConfigGetParamInt(g_configVideoGliden64, "blurAmount"); config.bloomFilter.blurStrength = ConfigGetParamInt(g_configVideoGliden64, "blurStrength"); + + config.generalEmulation.hacks = hacks; } diff --git a/src/mupenplus/GLideN64_mupenplus.h b/src/mupenplus/GLideN64_mupenplus.h index 6c14c287..a6b38737 100644 --- a/src/mupenplus/GLideN64_mupenplus.h +++ b/src/mupenplus/GLideN64_mupenplus.h @@ -12,6 +12,7 @@ /* definitions of pointers to Core config functions */ extern ptr_ConfigOpenSection ConfigOpenSection; extern ptr_ConfigDeleteSection ConfigDeleteSection; +extern ptr_ConfigSaveSection ConfigSaveSection; extern ptr_ConfigSaveFile ConfigSaveFile; extern ptr_ConfigSetParameter ConfigSetParameter; extern ptr_ConfigGetParameter ConfigGetParameter; diff --git a/src/mupenplus/MupenPlusAPIImpl.cpp b/src/mupenplus/MupenPlusAPIImpl.cpp index ef96eaf9..a4dd3292 100644 --- a/src/mupenplus/MupenPlusAPIImpl.cpp +++ b/src/mupenplus/MupenPlusAPIImpl.cpp @@ -13,6 +13,7 @@ ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = NULL; ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath = NULL; ptr_ConfigOpenSection ConfigOpenSection = NULL; ptr_ConfigDeleteSection ConfigDeleteSection = NULL; +ptr_ConfigSaveSection ConfigSaveSection = NULL; ptr_ConfigSaveFile ConfigSaveFile = NULL; ptr_ConfigSetDefaultInt ConfigSetDefaultInt = NULL; ptr_ConfigSetDefaultBool ConfigSetDefaultBool = NULL; @@ -42,6 +43,7 @@ m64p_error PluginAPI::PluginStartup(m64p_dynlib_handle _CoreLibHandle) ConfigGetUserConfigPath = (ptr_ConfigGetUserConfigPath) DLSYM(_CoreLibHandle, "ConfigGetUserConfigPath"); ConfigOpenSection = (ptr_ConfigOpenSection)DLSYM(_CoreLibHandle, "ConfigOpenSection"); ConfigDeleteSection = (ptr_ConfigDeleteSection)DLSYM(_CoreLibHandle, "ConfigDeleteSection"); + ConfigSaveSection = (ptr_ConfigSaveSection)DLSYM(_CoreLibHandle, "ConfigSaveSection"); ConfigSaveFile = (ptr_ConfigSaveFile)DLSYM(_CoreLibHandle, "ConfigSaveFile"); ConfigSetDefaultInt = (ptr_ConfigSetDefaultInt)DLSYM(_CoreLibHandle, "ConfigSetDefaultInt"); ConfigSetDefaultBool = (ptr_ConfigSetDefaultBool)DLSYM(_CoreLibHandle, "ConfigSetDefaultBool");