Skip to content

Commit

Permalink
Added support for subtitles of TAS videos.
Browse files Browse the repository at this point in the history
They will appear in the info bar with center alignment.
  • Loading branch information
punesemu committed Sep 21, 2021
1 parent 2ada90f commit f42c1fa
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 78 deletions.
13 changes: 10 additions & 3 deletions src/gui/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ static struct _qt {
objCheat *objch;
QImage qimage;

// widget dell'overlay
wdgOverlayUi *overlay;

// dialog del settaggio
dlgSettings *dset;

Expand Down Expand Up @@ -185,7 +188,7 @@ BYTE gui_create(void) {
qt.mwin->show();

qt.dset = new dlgSettings(qt.mwin);
overlay.widget = new wdgOverlayUi();
qt.overlay = new wdgOverlayUi();

memset(&ext_win, 0x00, sizeof(ext_win));
qt.vssystem = new dlgVsSystem(qt.mwin);
Expand All @@ -205,7 +208,7 @@ BYTE gui_create(void) {

QApplication::sendEvent(qt.mwin, &event);
QApplication::sendEvent(qt.dset, &event);
QApplication::sendEvent(overlay.widget, &event);
QApplication::sendEvent(qt.overlay, &event);

return (EXIT_OK);
}
Expand Down Expand Up @@ -303,7 +306,7 @@ void gui_update(void) {
qt.mwin->setWindowTitle(uQString(title));
qt.mwin->update_window();
qt.dset->update_dialog();
overlay.widget->update_widget();
qt.overlay->update_widget();

gui.in_update = FALSE;
}
Expand Down Expand Up @@ -592,6 +595,10 @@ void gui_screen_update(void) {
qt.dset->widget_Settings_Video->widget_Palette_Editor->widget_Palette_PPU->update();
}

void *gui_wdgoverlayui_get_ptr(void) {
return ((void *)qt.overlay);
}

void *gui_dlgsettings_get_ptr(void) {
return ((void *)qt.dset);
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ EXTERNC void gui_overlay_enable_save_slot(BYTE mode);
EXTERNC void gui_overlay_set_size(int w, int h);
EXTERNC void gui_overlay_info_init(void);
EXTERNC void gui_overlay_info_emulator(void);
EXTERNC void gui_overlay_info_append_subtitle(uTCHAR *msg);
EXTERNC void gui_overlay_info_append_msg_precompiled(int index, void *arg1);
EXTERNC void gui_overlay_blit(void);
EXTERNC void gui_overlay_slot_preview(int slot, void *buffer, uTCHAR *file);
Expand Down
89 changes: 72 additions & 17 deletions src/gui/tas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include <QtCore/QFileInfo>
#include <QtCore/QRegularExpression>
#include "tas.h"
#include "emu.h"
#include "info.h"
Expand All @@ -26,17 +27,26 @@

#define tas_set_data_port_ctrlstd(prt, dt)\
prt.data[dt] = tas.il[tas.index].prt[dt]
#define tas_increment_index()\
if (++tas.index == tas.count) {\
tas_read();\
}

static _port tas_port_bck[PORT_MAX];
INLINE static void tas_increment_index(void);

typedef struct _tas_subtitle {
int frame;
uTCHAR *string;
} _tas_subtitle;
typedef struct _tas_subtitles {
int nsubtitle;
_tas_subtitle *list;
} _tas_subtitles;

struct _tas_internal {
unsigned int count;
QList<size_t> file_byte_il;
uint32_t index;
QList<size_t> file_byte_il;
QString comment_author;
_tas_subtitles subtitles;
} tsint;
static _port tas_port_bck[PORT_MAX];

BYTE tas_file(uTCHAR *ext, uTCHAR *file) {
QString extension = uQString(ext);
Expand All @@ -51,14 +61,10 @@ BYTE tas_file(uTCHAR *ext, uTCHAR *file) {
}

if (tas.type != NOTAS) {
BYTE found = FALSE;
BYTE i, found = FALSE;

{
BYTE i;

for (i = PORT1; i < PORT_MAX; i++) {
memcpy(&tas_port_bck[i], &port[i], sizeof(_port));
}
for (i = PORT1; i < PORT_MAX; i++) {
memcpy(&tas_port_bck[i], &port[i], sizeof(_port));
}

umemset(tas.file, 0x00, usizeof(tas.file));
Expand All @@ -73,7 +79,6 @@ BYTE tas_file(uTCHAR *ext, uTCHAR *file) {
tas_header(file);

{
BYTE i;
const QString rom_ext[4] = { ".nes", ".NES", ".fds", ".FDS" };

for (i = 0; i < LENGTH(rom_ext); i++) {
Expand Down Expand Up @@ -102,7 +107,7 @@ BYTE tas_file(uTCHAR *ext, uTCHAR *file) {
return (EXIT_OK);
}
void tas_quit(void) {
BYTE i;
int i;

tas.type = NOTAS;

Expand All @@ -122,6 +127,21 @@ void tas_quit(void) {
input_init(NO_SET_CURSOR);

tsint.file_byte_il.clear();

// commenti
for (i = 0; i < tsint.subtitles.nsubtitle; i++) {
_tas_subtitle *ts = &tsint.subtitles.list[i];

if (ts->string) {
free(ts->string);
ts->string = NULL;
}
}
if (tsint.subtitles.list) {
free(tsint.subtitles.list);
tsint.subtitles.list = NULL;
}
tsint.subtitles.nsubtitle = 0;
}

void tas_header_FM2(uTCHAR *file) {
Expand Down Expand Up @@ -189,8 +209,25 @@ void tas_header_FM2(uTCHAR *file) {
if (port[PORT2].type == CTRL_ZAPPER) {
info.zapper_is_present = TRUE;
}
} else if (key.compare("comment author", Qt::CaseInsensitive) == 0) {
tsint.comment_author = value;
} else if (key.compare("subtitle", Qt::CaseInsensitive) == 0) {
QRegularExpression re("^\\s*(\\d+)\\s+(.*)$");
QRegularExpressionMatch match = re.match(value);

if (match.hasMatch()) {
_tas_subtitle *ts = NULL, *list = NULL;

if ((list = (_tas_subtitle *)realloc(tsint.subtitles.list, (tsint.subtitles.nsubtitle + 1) * sizeof(_tas_subtitle)))) {
tsint.subtitles.list = list;
ts = &tsint.subtitles.list[tsint.subtitles.nsubtitle];
memset(ts, 0x00, sizeof(_tas_subtitle));
ts->frame = match.captured(1).toInt();
ts->string = emu_ustrncpy(ts->string, uQStringCD(match.captured(2)));
tsint.subtitles.nsubtitle++;
};
}
}

pos = ftell(tas.fp);
}

Expand Down Expand Up @@ -266,6 +303,8 @@ void tas_read_FM2(void) {
tsint.index++;
}
void tas_frame_FM2(void) {
int i;

// il primo frame
if (!tas.frame) {
gui_overlay_info_append_msg_precompiled(20, NULL);
Expand All @@ -286,7 +325,17 @@ void tas_frame_FM2(void) {
return;
}

tas_increment_index()
// commenti
for (i = 0; i < tsint.subtitles.nsubtitle; i++) {
_tas_subtitle *ts = &tsint.subtitles.list[i];

if ((ts->frame == tas.frame) && ts->string) {
gui_overlay_info_append_subtitle(ts->string);
}
}

// il resto
tas_increment_index();

if (tas.il[tas.index].state > 0) {
if (tas.il[tas.index].state == 1) {
Expand Down Expand Up @@ -354,3 +403,9 @@ void tas_restart_from_begin_FM2(void) {
tas.frame = -1;
}
}

INLINE static void tas_increment_index(void) {
if (++tas.index == tas.count) {
tas_read();
}
}

0 comments on commit f42c1fa

Please sign in to comment.