Skip to content

Commit

Permalink
Make config saveable
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed May 2, 2024
1 parent c7557e7 commit 6cfd0f4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 46 deletions.
39 changes: 22 additions & 17 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ typedef struct{
uint32_t http_control_server_enable;
uint32_t avoid_overlaping_touchscreen;
float custom_font_scale;
uint32_t hardcore_mode;
uint32_t padding[228];
ra_config_t ra_config;
uint32_t padding[227];
}persistent_settings_t;
_Static_assert(sizeof(persistent_settings_t)==1024, "persistent_settings_t must be exactly 1024 bytes");
#define SE_STATS_GRAPH_DATA 256
Expand Down Expand Up @@ -1033,6 +1033,9 @@ se_core_rewind_buffer_t rewind_buffer;
se_save_state_t save_states[SE_NUM_SAVE_STATES];
se_cheat_t cheats[SE_NUM_CHEATS];
se_cloud_state_t cloud_state;
#ifdef ENABLE_RETRO_ACHIEVEMENTS
ra_config_t ra_config;
#endif

bool se_more_rewind_deltas(se_core_rewind_buffer_t* rewind, uint32_t index){
return (rewind->deltas[index%SE_REWIND_BUFFER_SIZE].offset&SE_LAST_DELTA_IN_TX)==0;
Expand Down Expand Up @@ -1694,6 +1697,9 @@ uint32_t retro_achievements_read_memory_callback(uint32_t address, uint8_t* buff
}
return 0;
}
ra_config_t* se_get_ra_config(){
return &gui_state.settings.ra_config;
}
#endif
void se_psg_debugger(){

Expand Down Expand Up @@ -2825,7 +2831,7 @@ void se_capture_state(se_core_state_t* core, se_save_state_t * save_state){
se_screenshot(save_state->screenshot, &save_state->screenshot_width, &save_state->screenshot_height);
}
void se_restore_state(se_core_state_t* core, se_save_state_t * save_state){
if(!save_state->valid || save_state->system != emu_state.system||gui_state.settings.hardcore_mode)return;
if(!save_state->valid || save_state->system != emu_state.system||gui_state.settings.ra_config.hardcore_mode)return;
*core=save_state->state;
emu_state.render_frame = true;
se_emulate_single_frame();
Expand Down Expand Up @@ -3077,7 +3083,7 @@ static float se_draw_debug_panels(float screen_x, float sidebar_w, float y, floa
igSetNextWindowPos((ImVec2){screen_x,y}, ImGuiCond_Always, (ImVec2){0,0});
igSetNextWindowSize((ImVec2){w, height}, ImGuiCond_Always);
igBegin(se_localize_and_cache(desc->label),&desc->visible, ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoResize);
if(gui_state.settings.hardcore_mode && desc->allow_hardcore == false){
if(gui_state.settings.ra_config.hardcore_mode && desc->allow_hardcore == false){
se_text("Disabled in Hardcore Mode");
}else desc->function();

Expand Down Expand Up @@ -4899,8 +4905,8 @@ void se_load_rom_overlay(bool visible){
w_size.y/=se_dpi_scale();
igSetNextWindowSize((ImVec2){w_size.x,w_size.y},ImGuiCond_Always);
igSetNextWindowPos((ImVec2){w_pos.x,w_pos.y},ImGuiCond_Always,(ImVec2){0,0});
igSetNextWindowBgAlpha(gui_state.settings.hardcore_mode? 1.0: SE_TRANSPARENT_BG_ALPHA);
igBegin(se_localize_and_cache(ICON_FK_FILE_O " Load Game"),gui_state.settings.hardcore_mode?NULL:&gui_state.overlay_open,ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoResize);
igSetNextWindowBgAlpha(gui_state.settings.ra_config.hardcore_mode? 1.0: SE_TRANSPARENT_BG_ALPHA);
igBegin(se_localize_and_cache(ICON_FK_FILE_O " Load Game"),gui_state.settings.ra_config.hardcore_mode?NULL:&gui_state.overlay_open,ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoResize);

float list_y_off = igGetWindowHeight();
int x, y, w, h;
Expand Down Expand Up @@ -5798,7 +5804,7 @@ void se_draw_menu_panel(){
ImGuiStyle *style = igGetStyle();
int win_w = igGetWindowContentRegionWidth();
se_section(ICON_FK_FLOPPY_O " Save States");
if(gui_state.settings.hardcore_mode)se_text("Disabled in Hardcore Mode");
if(gui_state.settings.ra_config.hardcore_mode)se_text("Disabled in Hardcore Mode");
else{
if (cloud_state.drive){
if (igBeginTabBar("Saves",ImGuiTabBarFlags_None)){
Expand Down Expand Up @@ -5869,7 +5875,7 @@ void se_draw_menu_panel(){

if(emu_state.system==SYSTEM_NDS || emu_state.system == SYSTEM_GBA || emu_state.system == SYSTEM_GB){
se_section(ICON_FK_KEY " Action Replay Codes");
if(gui_state.settings.hardcore_mode) se_text("Disabled in Hardcore Mode");
if(gui_state.settings.ra_config.hardcore_mode) se_text("Disabled in Hardcore Mode");
else{
int free_cheat_index = -1;
for(int i=0;i<SE_NUM_CHEATS;i++){
Expand Down Expand Up @@ -6161,10 +6167,9 @@ void se_draw_menu_panel(){
bool draw_debug_menu = gui_state.settings.draw_debug_menu;
se_checkbox("Show Debug Tools",&draw_debug_menu);
gui_state.settings.draw_debug_menu = draw_debug_menu;
bool hardcore_mode = gui_state.settings.hardcore_mode;
se_checkbox("Hardcore Mode",&hardcore_mode);
if(gui_state.settings.hardcore_mode!=hardcore_mode){
gui_state.settings.hardcore_mode = hardcore_mode;
bool hardcore_mode = gui_state.settings.ra_config.hardcore_mode;
if(gui_state.settings.ra_config.hardcore_mode!=hardcore_mode){
gui_state.settings.ra_config.hardcore_mode = hardcore_mode;
se_reset_core();
}

Expand Down Expand Up @@ -6819,7 +6824,7 @@ static void frame(void) {

if(!emu_state.rom_loaded)se_push_disabled();
for(int i=0;i<num_toggles;++i){
bool hardcore_disabled = gui_state.settings.hardcore_mode&& i<first_hardcore_toggle;
bool hardcore_disabled = gui_state.settings.ra_config.hardcore_mode&& i<first_hardcore_toggle;
if(hardcore_disabled)se_push_disabled();
bool active_button = i==curr_toggle;
if(active_button)igPushStyleColorVec4(ImGuiCol_Button, style->Colors[ImGuiCol_ButtonActive]);
Expand Down Expand Up @@ -6859,15 +6864,15 @@ static void frame(void) {
}
}

if(gui_state.settings.hardcore_mode){
if(gui_state.settings.ra_config.hardcore_mode){
if(emu_state.run_mode==SB_MODE_REWIND||emu_state.run_mode==SB_MODE_STEP){
emu_state.run_mode= SB_MODE_RUN;
emu_state.step_frames=1;
}
if(emu_state.step_frames<1&&emu_state.step_frames!=-1)emu_state.step_frames=1;
}

if(gui_state.settings.hardcore_mode){
if(gui_state.settings.ra_config.hardcore_mode){
if(emu_state.run_mode==SB_MODE_REWIND||emu_state.run_mode==SB_MODE_STEP)emu_state.run_mode= SB_MODE_RUN;
if(emu_state.step_frames<1&&emu_state.step_frames!=-1)emu_state.step_frames=1;
}
Expand Down Expand Up @@ -7182,7 +7187,7 @@ void se_load_settings(){
}
if(gui_state.settings.settings_file_version<3){
gui_state.settings.settings_file_version = 3;
gui_state.settings.hardcore_mode=0;
gui_state.settings.ra_config.hardcore_mode=0;
}
if(gui_state.settings.custom_font_scale<0.5)gui_state.settings.custom_font_scale=1.0;
if(gui_state.settings.custom_font_scale>2.0)gui_state.settings.custom_font_scale=1.0;
Expand Down Expand Up @@ -7666,7 +7671,7 @@ static void se_init(){
gui_state.settings.http_control_server_enable=true;
http_server_mode=true;
// HTTP Server mode only has frame stepping which is not allowed in hardcore mode.
gui_state.settings.hardcore_mode = false;
gui_state.settings.ra_config.hardcore_mode = false;
}
if(emu_state.cmd_line_arg_count>=2){
se_load_rom(emu_state.cmd_line_args[1]);
Expand Down
58 changes: 33 additions & 25 deletions src/retro_achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool se_button(const char* label, ImVec2 size);
const char* se_localize_and_cache(const char* input_str);
ImFont* se_get_mono_font();
#include "retro_achievements.h"
ra_config_t* se_get_ra_config();
}

#include "IconsForkAwesome.h"
Expand Down Expand Up @@ -59,11 +60,6 @@ const bool only_one_notification = false;
const int atlas_spacing = 4; // leaving some space between tiles to avoid bleeding
const float padding = 7;

static bool draw_notifications = true;
static bool draw_progress_indicators = true;
static bool draw_challenge_indicators = true;
static bool draw_trackers = true;

// atlases -> the currently existing atlases, each serving a different image
// width/height combo image_cache -> a mapping of image urls to their atlas and
// the coordinates within the atlas download_cache -> a cache of downloaded
Expand Down Expand Up @@ -958,8 +954,7 @@ void retro_achievements_initialize(void* state)
rc_client_enable_logging(ra_state->rc_client, RC_CLIENT_LOG_LEVEL_VERBOSE,
retro_achievements_log_callback);

// TODO: should probably be an option after we're finished testing
rc_client_set_hardcore_enabled(ra_state->rc_client, 0);
rc_client_set_hardcore_enabled(ra_state->rc_client, se_get_ra_config()->hardcore_mode);
rc_client_set_event_handler(ra_state->rc_client, retro_achievements_event_handler);

// RetroAchievements doesn't enable CORS, so we use a reverse proxy
Expand Down Expand Up @@ -1262,20 +1257,23 @@ void retro_achievements_draw_panel(int win_w)
std::string settings = ICON_FK_WRENCH " " + std::string(se_localize_and_cache("Settings"));
se_text(settings.c_str());

// TODO: make these saveable
igCheckbox(se_localize_and_cache("Enable Notifications"), &draw_notifications);
igCheckbox(se_localize_and_cache("Enable Progress Indicator"), &draw_progress_indicators);
igCheckbox(se_localize_and_cache("Enable Leaderboard Trackers"), &draw_trackers);
igCheckbox(se_localize_and_cache("Enable Challenges"), &draw_challenge_indicators);
// TODO: put hardcore mode checkbox here?
ra_config_t* config = se_get_ra_config();
if (igCheckbox(se_localize_and_cache("Enable Hardcore Mode"), &config->hardcore_mode)) {
rc_client_set_hardcore_enabled(ra_state->rc_client, se_get_ra_config()->hardcore_mode);
}

igCheckbox(se_localize_and_cache("Enable Notifications"), &config->draw_notifications);
igCheckbox(se_localize_and_cache("Enable Progress Indicators"), &config->draw_progress_indicators);
igCheckbox(se_localize_and_cache("Enable Leaderboard Trackers"), &config->draw_leaderboard_trackers);
igCheckbox(se_localize_and_cache("Enable Challenge Indicators"), &config->draw_challenge_indicators);

retro_achievements_draw_achievements();
}
}

void retro_achievements_draw_notifications(float left, float top)
{
if (!draw_notifications)
if (!se_get_ra_config()->draw_notifications)
return;

ra_game_state_ptr game_state = ra_state->game_state;
Expand Down Expand Up @@ -1327,21 +1325,31 @@ void retro_achievements_draw_notifications(float left, float top)
float placard_width = padding + 350 + padding; // notifications that have the same width are more appealing
float wrap_width = placard_width - padding * 2 - image_width;

float title_height = 0, submessage_height = 0, submessage2_height = 0;

ImVec2 out;
ImFont* font = igGetFont();
ImFont_CalcTextSizeA(&out, font, 22.0f, std::numeric_limits<float>::max(), wrap_width, notification.title.c_str(), NULL,
NULL);
float title_height = out.y;
title_height = out.y;

ImFont_CalcTextSizeA(&out, font, 18.0f, std::numeric_limits<float>::max(), wrap_width, notification.submessage.c_str(), NULL,
NULL);
float submessage_height = out.y;
float placard_height = padding + title_height + padding;

ImFont_CalcTextSizeA(&out, font, 18.0f, std::numeric_limits<float>::max(), wrap_width, notification.submessage2.c_str(), NULL,
NULL);
float submessage2_height = out.y;
if (!notification.submessage.empty())
{
ImFont_CalcTextSizeA(&out, font, 18.0f, std::numeric_limits<float>::max(), wrap_width, notification.submessage.c_str(), NULL,
NULL);
submessage_height = out.y;
placard_height += submessage_height + padding;
}

float placard_height = padding + title_height + padding + submessage_height + padding + submessage2_height + padding;
if (!notification.submessage2.empty())
{
ImFont_CalcTextSizeA(&out, font, 18.0f, std::numeric_limits<float>::max(), wrap_width, notification.submessage2.c_str(), NULL,
NULL);
submessage2_height = out.y;
placard_height += submessage2_height + padding;
}

ImDrawList_AddRectFilled(igGetWindowDrawList(), ImVec2{x, y},
ImVec2{x + placard_width, y + placard_height},
Expand Down Expand Up @@ -1388,7 +1396,7 @@ void retro_achievements_draw_notifications(float left, float top)

void retro_achievements_draw_progress_indicator(float right, float top)
{
if (!draw_progress_indicators)
if (!se_get_ra_config()->draw_progress_indicators)
return;

ra_game_state_ptr game_state = ra_state->game_state;
Expand Down Expand Up @@ -1460,7 +1468,7 @@ void retro_achievements_draw_progress_indicator(float right, float top)

void retro_achievements_draw_leaderboard_trackers(float left, float bottom)
{
if (!draw_trackers)
if (!se_get_ra_config()->draw_leaderboard_trackers)
return;

ra_game_state_ptr game_state = ra_state->game_state;
Expand Down Expand Up @@ -1518,7 +1526,7 @@ void retro_achievements_draw_leaderboard_trackers(float left, float bottom)

void retro_achievements_draw_challenge_indicators(float right, float bottom)
{
if (!draw_challenge_indicators)
if (!se_get_ra_config()->draw_challenge_indicators)
return;

ra_game_state_ptr game_state = ra_state->game_state;
Expand Down
18 changes: 14 additions & 4 deletions src/retro_achievements.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@

#ifndef RETRO_ACHIEVEMENTS
#define RETRO_ACHIEVEMENTS
#include "rc_client.h"
#include "mutex.h"
#include <stdint.h>
#include <stdbool.h>

typedef struct {
bool hardcore_mode;
bool draw_challenge_indicators;
bool draw_progress_indicators;
bool draw_leaderboard_trackers;
bool draw_notifications;
uint8_t padding[3];
} ra_config_t;

#ifdef ENABLE_RETRO_ACHIEVEMENTS

typedef struct {
uint32_t atlas_id;
Expand All @@ -18,8 +28,6 @@ typedef struct {
float x2, y2;
} atlas_tile_t;

typedef struct ra_state_t ra_state_t;

void retro_achievements_initialize(void* emu_state);

void retro_achievements_shutdown();
Expand All @@ -42,4 +50,6 @@ void retro_achievements_draw_leaderboard_trackers(float left, float bottom);

void retro_achievements_draw_challenge_indicators(float right, float bottom);

#endif

#endif

0 comments on commit 6cfd0f4

Please sign in to comment.