Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Display streaming FPS" option #167

Closed
wants to merge 14 commits into from
21 changes: 21 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ static int ini_handle(void *out, const char *section, const char *name,
config->enable_frame_pacer = BOOL(value);
} else if (strcmp(name, "disable_powersave") == 0) {
config->disable_powersave = BOOL(value);
} else if (strcmp(name, "jp_layout") == 0) {
config->jp_layout = BOOL(value);
} else if (strcmp(name, "show_fps") == 0) {
config->show_fps = BOOL(value);
} else if (strcmp(name, "save_debug_log") == 0) {
config->save_debug_log = BOOL(value);
} else if (strcmp(name, "mapping") == 0) {
Expand Down Expand Up @@ -151,6 +155,8 @@ void config_save(const char* filename, PCONFIGURATION config) {

write_config_bool(fd, "enable_frame_pacer", config->enable_frame_pacer);
write_config_bool(fd, "disable_powersave", config->disable_powersave);
write_config_bool(fd, "jp_layout", config->jp_layout);
write_config_bool(fd, "show_fps", config->show_fps);
write_config_bool(fd, "save_debug_log", config->save_debug_log);

write_config_int(fd, "mouse_acceleration", config->mouse_acceleration);
Expand All @@ -174,6 +180,17 @@ void config_save(const char* filename, PCONFIGURATION config) {
fclose(fd);
}

void update_layout() {
if (config.jp_layout) {
config.btn_confirm = SCE_CTRL_CIRCLE;
config.btn_cancel = SCE_CTRL_CROSS;
}
else {
config.btn_confirm = SCE_CTRL_CROSS;
config.btn_cancel = SCE_CTRL_CIRCLE;
}
}

void config_parse(int argc, char* argv[], PCONFIGURATION config) {
LiInitializeStreamConfiguration(&config->stream);

Expand All @@ -198,6 +215,8 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->unsupported_version = false;
config->save_debug_log = false;
config->disable_powersave = true;
config->jp_layout = false;
config->show_fps = false;
config->enable_frame_pacer = true;

config->special_keys.nw = INPUT_SPECIAL_KEY_PAUSE | INPUT_TYPE_SPECIAL;
Expand All @@ -218,6 +237,8 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config_file_parse(config_file, config);
}

update_layout();

if (config->config_file != NULL)
config_save(config->config_file, config);

Expand Down
9 changes: 9 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <stdint.h>
#include <stdbool.h>

#include <psp2/ctrl.h>

#define MAX_INPUTS 6

struct input_config {
Expand All @@ -40,6 +42,7 @@ struct special_keys {
};

typedef struct _CONFIGURATION {
// static configuration, value will be saved to config file
STREAM_CONFIGURATION stream;
char* app;
char* action;
Expand All @@ -57,13 +60,18 @@ typedef struct _CONFIGURATION {
struct touchscreen_deadzone back_deadzone;
struct special_keys special_keys;
bool disable_powersave;
bool jp_layout;
bool show_fps;
bool enable_frame_pacer;
bool save_debug_log;
struct input_config inputs[MAX_INPUTS];
int inputsCount;
int mouse_acceleration;
bool enable_ref_frame_invalidation;
FILE *log_file;
// runtime configuration, value will be recreated at launch
SceCtrlButtons btn_confirm;
SceCtrlButtons btn_cancel;
} CONFIGURATION, *PCONFIGURATION;

extern CONFIGURATION config;
Expand All @@ -74,3 +82,4 @@ bool inputAdded;
bool config_file_parse(char* filename, PCONFIGURATION config);
void config_parse(int argc, char* argv[], PCONFIGURATION config);
void config_save(const char* filename, PCONFIGURATION config);
void update_layout();
11 changes: 7 additions & 4 deletions src/gui/guilib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "guilib.h"

#include "../config.h"
#include "../platform.h"

#include <stdarg.h>
Expand Down Expand Up @@ -259,7 +260,9 @@ void draw_alert(char *message, menu_geom geom, char *buttons_captions[], int but
char caption[256];
strcpy(caption, "");

char *icons[4] = {"x", "◯", "△", "□"};
char *o_layout[4] = {"o", "x", "△", "□"};
char *x_layout[4] = {"x", "o", "△", "□"};
char **icons = config.jp_layout ? o_layout : x_layout;
char *default_captions[4] = {"Ok", "Cancel", "Options", "Delete"};
for (int i = 0; i < buttons_count; i++) {
char single_button_caption[64];
Expand Down Expand Up @@ -400,7 +403,7 @@ int display_menu(menu_entry menu[], int total_elements, menu_geom *geom_ptr,
gui_global_loop_callback(menu[real_cursor].id, context, &input);
}

if (input.buttons & SCE_CTRL_CIRCLE && (input.buttons & SCE_CTRL_HOLD) == 0) {
if (input.buttons & config.btn_cancel && (input.buttons & SCE_CTRL_HOLD) == 0) {
if (!back_cb || back_cb(context) == 0) {
exit_code = 1;
goto error;
Expand Down Expand Up @@ -439,9 +442,9 @@ void display_alert(char *message, char *button_captions[], int buttons_count,
continue;
}

if (input.buttons & SCE_CTRL_CROSS) {
if (input.buttons & config.btn_confirm) {
result = 0;
} else if (input.buttons & SCE_CTRL_CIRCLE) {
} else if (input.buttons & config.btn_cancel) {
result = 1;
} else if (input.buttons & SCE_CTRL_TRIANGLE) {
result = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum {
};

int ui_main_menu_loop(int cursor, void *context, const input_data *input) {
if ((input->buttons & SCE_CTRL_CROSS) == 0 || (input->buttons & SCE_CTRL_HOLD) != 0) {
if ((input->buttons & config.btn_confirm) == 0 || (input->buttons & SCE_CTRL_HOLD) != 0) {
return 0;
}
if (cursor >= MAIN_MENU_CONNECT_PAIRED && cursor < MAIN_MENU_QUIT) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/ui_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int ui_connect_loop(int id, void *context, const input_data *input) {
menu[i].disabled = (server.currentGame != 0);
}

if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/ui_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int end_search_thread(SceUID thid) {
}

static int ui_search_device_callback(int id, void *context, const input_data *input) {
if ((input->buttons & SCE_CTRL_CROSS) == 0 || (input->buttons & SCE_CTRL_HOLD) != 0) {
if ((input->buttons & config.btn_confirm) == 0 || (input->buttons & SCE_CTRL_HOLD) != 0) {
// if remain slot, reload discovered devices
if (!DEVICE_ENTRY_IDX[DEVICE_VIEW_ITEM + found_device - 1]) {
return 2;
Expand Down
51 changes: 39 additions & 12 deletions src/gui/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ enum {
static int select_special_key_loop(int id, void *context, const input_data *input) {
int *code = context;

if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
return 0;
}
if (id != SETTINGS_SELECT_SPECIAL_KEY_MANUAL) {
Expand Down Expand Up @@ -274,7 +274,7 @@ static int special_keys_loop(int id, void *context, const input_data *input) {
config.special_keys.size += delta;
break;
default:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
select_special_key_menu(&selected_ord);
Expand Down Expand Up @@ -381,6 +381,8 @@ enum {
SETTINGS_ENABLE_STREAM_OPTIMIZE,
SETTINGS_SAVE_DEBUG_LOG,
SETTINGS_DISABLE_POWERSAVE,
SETTINGS_JP_LAYOUT,
SETTINGS_SHOW_FPS,
SETTINGS_ENABLE_FRAME_PACER,
SETTINGS_ENABLE_MAPPING,
SETTINGS_BACK_DEADZONE,
Expand All @@ -397,6 +399,8 @@ enum {
SETTINGS_VIEW_ENABLE_STREAM_OPTIMIZE,
SETTINGS_VIEW_SAVE_DEBUG_LOG,
SETTINGS_VIEW_DISABLE_POWERSAVE,
SETTINGS_VIEW_JP_LAYOUT,
SETTINGS_VIEW_SHOW_FPS,
SETTINGS_VIEW_ENABLE_FRAME_PACER,
SETTINGS_VIEW_ENABLE_MAPPING,
SETTINGS_VIEW_BACK_DEADZONE,
Expand Down Expand Up @@ -468,7 +472,7 @@ static int settings_loop(int id, void *context, const input_data *input) {
did_change = 1;
break;
case SETTINGS_BITRATE:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
char value[512];
Expand All @@ -484,49 +488,63 @@ static int settings_loop(int id, void *context, const input_data *input) {
}
break;
case SETTINGS_SOPS:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.sops = !config.sops;
break;
case SETTINGS_ENABLE_FRAME_INVAL:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.enable_ref_frame_invalidation = !config.enable_ref_frame_invalidation;
break;
case SETTINGS_ENABLE_STREAM_OPTIMIZE:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.stream.streamingRemotely = config.stream.streamingRemotely ? 0 : 1;
break;
case SETTINGS_SAVE_DEBUG_LOG:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.save_debug_log = !config.save_debug_log;
break;
case SETTINGS_DISABLE_POWERSAVE:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.disable_powersave = !config.disable_powersave;
break;
case SETTINGS_JP_LAYOUT:
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.jp_layout = !config.jp_layout;
break;
case SETTINGS_SHOW_FPS:
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.show_fps = !config.show_fps;
break;
case SETTINGS_ENABLE_FRAME_PACER:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
config.enable_frame_pacer = !config.enable_frame_pacer;
break;
case SETTINGS_ENABLE_MAPPING:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
did_change = 1;
Expand All @@ -538,14 +556,14 @@ static int settings_loop(int id, void *context, const input_data *input) {
}
break;
case SETTINGS_BACK_DEADZONE:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
deadzone_settings_menu();
did_change = 1;
break;
case SETTINGS_SPECIAL_KEYS:
if ((input->buttons & SCE_CTRL_CROSS) == 0 || input->buttons & SCE_CTRL_HOLD) {
if ((input->buttons & config.btn_confirm) == 0 || input->buttons & SCE_CTRL_HOLD) {
break;
}
special_keys_menu();
Expand Down Expand Up @@ -602,6 +620,12 @@ static int settings_loop(int id, void *context, const input_data *input) {
sprintf(current, "%s", config.disable_powersave ? "yes" : "no");
MENU_REPLACE(SETTINGS_VIEW_DISABLE_POWERSAVE, current);

sprintf(current, "%s", config.jp_layout ? "yes" : "no");
MENU_REPLACE(SETTINGS_VIEW_JP_LAYOUT, current);

sprintf(current, "%s", config.show_fps ? "yes" : "no");
MENU_REPLACE(SETTINGS_VIEW_SHOW_FPS, current);

sprintf(current, "%s", config.enable_frame_pacer ? "yes" : "no");
MENU_REPLACE(SETTINGS_VIEW_ENABLE_FRAME_PACER, current);

Expand All @@ -625,6 +649,7 @@ static int settings_loop(int id, void *context, const input_data *input) {

static int settings_back(void *context) {
ui_settings_save_config();
update_layout();
return 0;
}

Expand Down Expand Up @@ -660,6 +685,8 @@ int ui_settings_menu() {
MENU_CATEGORY("System");
MENU_ENTRY(SETTINGS_SAVE_DEBUG_LOG, SETTINGS_VIEW_SAVE_DEBUG_LOG, "Enable debug log", "");
MENU_ENTRY(SETTINGS_DISABLE_POWERSAVE, SETTINGS_VIEW_DISABLE_POWERSAVE, "Disable power save", "");
MENU_ENTRY(SETTINGS_JP_LAYOUT, SETTINGS_VIEW_JP_LAYOUT, "Swap X & O for Moonlight", "");
MENU_ENTRY(SETTINGS_SHOW_FPS, SETTINGS_VIEW_SHOW_FPS, "Display streaming FPS", "");

MENU_CATEGORY("Input");
MENU_ENTRY(SETTINGS_MOUSE_ACCEL, SETTINGS_VIEW_MOUSE_ACCEL, "Mouse acceleration", ICON_LEFT_RIGHT_ARROWS);
Expand Down
7 changes: 3 additions & 4 deletions src/video/vita.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

#if 0
#define printf vita_debug_log
#define DRAW_FPS 1
#endif

void draw_indicators();
Expand Down Expand Up @@ -409,9 +408,9 @@ static int vita_submit_decode_unit(PDECODE_UNIT decodeUnit) {
vita2d_start_drawing();
void *tex_buf = vita2d_texture_get_datap(frame_texture);
vita2d_draw_texture(frame_texture, 0, 0);
#ifdef DRAW_FPS
vita2d_font_draw_textf(font, 20, 40, RGBA8(0xFF, 0xFF, 0xFF, 0xFF), 12, "fps: %u / %u", curr_fps[0], curr_fps[1]);
#endif
if (config.show_fps) {
vita2d_font_draw_textf(font, 20, 40, RGBA8(0xFF, 0xFF, 0xFF, 0xFF), 14, "fps: %u / %u", curr_fps[0], curr_fps[1]);
}
draw_indicators();
vita2d_end_drawing();
vita2d_wait_rendering_done();
Expand Down