Skip to content

Commit

Permalink
libtrx: pull Config_Read and Config_Write
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 26, 2024
1 parent bb3b7fc commit eabf568
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
45 changes: 14 additions & 31 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/config/config_file.h>
#include <libtrx/config/file.h>
#include <libtrx/filesystem.h>
#include <libtrx/game/console/common.h>
#include <libtrx/game/ui/events.h>
Expand All @@ -35,8 +35,6 @@ static void M_LoadLegacyOptions(JSON_OBJECT *const parent_obj);
static void M_DumpKeyboardLayout(JSON_OBJECT *parent_obj, INPUT_LAYOUT layout);
static void M_DumpControllerLayout(
JSON_OBJECT *parent_obj, INPUT_LAYOUT layout);
static void M_Load(JSON_OBJECT *root_obj);
static void M_Dump(JSON_OBJECT *root_obj);

static void M_LoadKeyboardLayout(
JSON_OBJECT *const parent_obj, const INPUT_LAYOUT layout)
Expand Down Expand Up @@ -241,7 +239,12 @@ static void M_DumpControllerLayout(
}
}

static void M_Load(JSON_OBJECT *root_obj)
const char *Config_GetPath(void)
{
return m_ConfigPath;
}

void Config_LoadFromJSON(JSON_OBJECT *root_obj)
{
ConfigFile_LoadOptions(root_obj, g_ConfigOptionMap);

Expand All @@ -252,11 +255,9 @@ static void M_Load(JSON_OBJECT *root_obj)
}

M_LoadLegacyOptions(root_obj);

Config_Sanitize();
}

static void M_Dump(JSON_OBJECT *root_obj)
void Config_DumpToJSON(JSON_OBJECT *root_obj)
{
ConfigFile_DumpOptions(root_obj, g_ConfigOptionMap);

Expand All @@ -271,30 +272,6 @@ static void M_Dump(JSON_OBJECT *root_obj)
}
}

bool Config_Read(void)
{
const bool result = ConfigFile_Read(m_ConfigPath, &M_Load);
Input_CheckConflicts(CM_KEYBOARD, g_Config.input.layout);
Input_CheckConflicts(CM_CONTROLLER, g_Config.input.cntlr_layout);
Music_SetVolume(g_Config.music_volume);
Sound_SetMasterVolume(g_Config.sound_volume);
Requester_Shutdown(&g_SavegameRequester);
Requester_Init(&g_SavegameRequester, g_Config.maximum_save_slots);
return result;
}

bool Config_Write(void)
{
const EVENT event = {
.name = "canvas_resize",
.sender = NULL,
.data = NULL,
};
UI_Events_Fire(&event);

return ConfigFile_Write(m_ConfigPath, &M_Dump);
}

void Config_Sanitize(void)
{
CLAMP(g_Config.start_lara_hitpoints, 1, LARA_MAX_HITPOINTS);
Expand All @@ -320,6 +297,12 @@ void Config_Sanitize(void)

void Config_ApplyChanges(void)
{
Input_CheckConflicts(CM_KEYBOARD, g_Config.input.layout);
Input_CheckConflicts(CM_CONTROLLER, g_Config.input.cntlr_layout);
Music_SetVolume(g_Config.music_volume);
Sound_SetMasterVolume(g_Config.sound_volume);
Requester_Shutdown(&g_SavegameRequester);
Requester_Init(&g_SavegameRequester, g_Config.maximum_save_slots);
Output_ApplyRenderSettings();
}

Expand Down
2 changes: 1 addition & 1 deletion src/config_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "config.h"

// import order guard
#include <libtrx/config/config_map.h>
#include <libtrx/config/map.h>
// import order guard

#include "global/enum_str.h"
Expand Down
2 changes: 1 addition & 1 deletion src/config_map.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include <libtrx/config/config_option.h>
#include <libtrx/config/option.h>

extern const CONFIG_OPTION g_ConfigOptionMap[];
5 changes: 5 additions & 0 deletions src/specific/s_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ void S_Output_DrawShadow(PHD_VBUF *vbufs, int clip, int vertex_count)

void S_Output_ApplyRenderSettings(void)
{
if (m_Renderer3D == NULL) {
return;
}

if (m_PictureSurface != NULL
&& (Screen_GetResWidth() != m_SurfaceWidth
|| Screen_GetResHeight() != m_SurfaceHeight)) {
Expand Down Expand Up @@ -855,6 +859,7 @@ void S_Output_Shutdown(void)
M_ReleaseTextures();
M_ReleaseSurfaces();
GFX_Context_Detach();
m_Renderer2D = NULL;
m_Renderer3D = NULL;
}

Expand Down

0 comments on commit eabf568

Please sign in to comment.