Start limiting scope of global->cheat to cheats.c

This commit is contained in:
twinaphex 2015-12-01 02:43:34 +01:00
parent 2c12ea6dd9
commit 43abd39f6a
5 changed files with 49 additions and 29 deletions

View File

@ -52,8 +52,10 @@ struct cheat_manager
unsigned buf_size;
};
unsigned cheat_manager_get_buf_size(cheat_manager_t *handle)
unsigned cheat_manager_get_buf_size(void)
{
global_t *global = global_get_ptr();
cheat_manager_t *handle = global->cheat;
if (!handle)
return 0;
return handle->buf_size;
@ -66,9 +68,11 @@ unsigned cheat_manager_get_size(cheat_manager_t *handle)
return handle->size;
}
void cheat_manager_apply_cheats(cheat_manager_t *handle)
void cheat_manager_apply_cheats(void)
{
unsigned i, idx = 0;
global_t *global = global_get_ptr();
cheat_manager_t *handle = global->cheat;
if (!handle)
return;
@ -328,7 +332,7 @@ void cheat_manager_toggle(cheat_manager_t *handle)
return;
handle->cheats[handle->ptr].state ^= true;
cheat_manager_apply_cheats(handle);
cheat_manager_apply_cheats();
cheat_manager_update(handle, handle->ptr);
}
@ -374,3 +378,28 @@ bool cheat_manager_get_code_state(cheat_manager_t *handle, unsigned i)
return false;
return handle->cheats[i].state;
}
void cheat_manager_state_checks(
bool cheat_index_plus_pressed,
bool cheat_index_minus_pressed,
bool cheat_toggle_pressed)
{
global_t *global = global_get_ptr();
if (!global || !global->cheat)
return;
if (cheat_index_plus_pressed)
cheat_manager_index_next(global->cheat);
else if (cheat_index_minus_pressed)
cheat_manager_index_prev(global->cheat);
else if (cheat_toggle_pressed)
cheat_manager_toggle(global->cheat);
}
void cheat_manager_state_free(void)
{
global_t *global = global_get_ptr();
if (global->cheat)
cheat_manager_free(global->cheat);
global->cheat = NULL;
}

View File

@ -53,13 +53,13 @@ void cheat_manager_index_prev(cheat_manager_t *handle);
void cheat_manager_toggle(cheat_manager_t *handle);
void cheat_manager_apply_cheats(cheat_manager_t *handle);
void cheat_manager_apply_cheats(void);
void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx);
void cheat_manager_toggle_index(cheat_manager_t *handle, unsigned i);
unsigned cheat_manager_get_buf_size(cheat_manager_t *handle);
unsigned cheat_manager_get_buf_size(void);
const char *cheat_manager_get_desc(cheat_manager_t *handle, unsigned i);
@ -67,6 +67,13 @@ const char *cheat_manager_get_code(cheat_manager_t *handle, unsigned i);
bool cheat_manager_get_code_state(cheat_manager_t *handle, unsigned i);
void cheat_manager_state_checks(
bool cheat_index_plus_pressed,
bool cheat_index_minus_pressed,
bool cheat_toggle_pressed);
void cheat_manager_state_free(void);
#ifdef __cplusplus
}
#endif

View File

@ -1095,22 +1095,14 @@ bool event_command(enum event_command cmd)
}
break;
case EVENT_CMD_CHEATS_DEINIT:
if (!global)
break;
if (global->cheat)
cheat_manager_free(global->cheat);
global->cheat = NULL;
cheat_manager_state_free();
break;
case EVENT_CMD_CHEATS_INIT:
event_command(EVENT_CMD_CHEATS_DEINIT);
event_init_cheats();
break;
case EVENT_CMD_CHEATS_APPLY:
if (!global->cheat)
break;
cheat_manager_apply_cheats(global->cheat);
cheat_manager_apply_cheats();
break;
case EVENT_CMD_REMAPPING_DEINIT:
break;

View File

@ -48,12 +48,9 @@ static void menu_action_setting_disp_set_label_cheat_num_passes(
const char *path,
char *s2, size_t len2)
{
global_t *global = global_get_ptr();
*w = 19;
strlcpy(s2, path, len2);
if (global && global->cheat)
snprintf(s, len, "%u", cheat_manager_get_buf_size(global->cheat));
snprintf(s, len, "%u", cheat_manager_get_buf_size());
}
static void menu_action_setting_disp_set_label_remap_file_load(
@ -414,7 +411,7 @@ static void menu_action_setting_disp_set_label_cheat(
if (!global)
return;
if (cheat_index < cheat_manager_get_buf_size(global->cheat))
if (cheat_index < cheat_manager_get_buf_size())
snprintf(s, len, "%s : (%s)",
(cheat_manager_get_code(global->cheat, cheat_index) != NULL)
? cheat_manager_get_code(global->cheat, cheat_index) :

View File

@ -505,15 +505,10 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
if (cmd->reset_pressed)
event_command(EVENT_CMD_RESET);
if (global->cheat)
{
if (cmd->cheat_index_plus_pressed)
cheat_manager_index_next(global->cheat);
else if (cmd->cheat_index_minus_pressed)
cheat_manager_index_prev(global->cheat);
else if (cmd->cheat_toggle_pressed)
cheat_manager_toggle(global->cheat);
}
cheat_manager_state_checks(
cmd->cheat_index_plus_pressed,
cmd->cheat_index_minus_pressed,
cmd->cheat_toggle_pressed);
}
break;
case RUNLOOP_CTL_CHECK_PAUSE_STATE: