Skip to content

Commit

Permalink
feat: support new packet types
Browse files Browse the repository at this point in the history
entity serial and frametime packets
also output error when unknown packet

Fixes #7
Fixes #4
  • Loading branch information
ThisAMJ committed May 2, 2024
1 parent c230b73 commit 919a265
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,27 @@ static int _parse_sar_data(struct sar_data *out, FILE *f, size_t len) {

break;

case SAR_DATA_ENTITY_SERIAL:
if (len != 8) {
out->type = SAR_DATA_INVALID;
break;
}

out->entity_serial.slot = _read_f32(data);
out->entity_serial.serial = _read_f32(data);

break;

case SAR_DATA_FRAMETIME:
if (len != 5) {
out->type = SAR_DATA_INVALID;
break;
}

out->frametime = _read_f32(data);

break;

case SAR_DATA_SPEEDRUN_TIME:
if (len < 5) {
out->type = SAR_DATA_INVALID;
Expand Down Expand Up @@ -307,6 +328,7 @@ static int _parse_sar_data(struct sar_data *out, FILE *f, size_t len) {
break;

default:
fprintf(g_errfile, "[SAR] Unhandled message type %02X\n", out->type);
out->type = SAR_DATA_INVALID;
break;
}
Expand Down
10 changes: 9 additions & 1 deletion src/demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ struct sar_data {
SAR_DATA_TIMESTAMP = 0x0B,
SAR_DATA_FILE_CHECKSUM = 0x0C,
SAR_DATA_HWAIT_RUN = 0x0D,
SAR_DATA_ENTITY_SERIAL = 0x0E,
SAR_DATA_FRAMETIME = 0x0F,
SAR_DATA_CHECKSUM = 0xFF,
SAR_DATA_CHECKSUM_V2 = 0xFE,

SAR_DATA_INVALID,
SAR_DATA_INVALID = 0x00,
} type;

int slot;

union {
float timescale;
uint32_t pause_ticks;
float frametime;

struct {
char *cvar;
Expand Down Expand Up @@ -78,6 +81,11 @@ struct sar_data {
char *cmd;
} hwait_run;

struct {
int slot;
int serial;
} entity_serial;

struct {
size_t nsplits;
struct {
Expand Down
6 changes: 6 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ static void _output_sar_data(uint32_t tick, struct sar_data data) {
case SAR_DATA_HWAIT_RUN:
if (g_config.show_wait) fprintf(g_outfile, "\t\t[%5u] [SAR] hwait %d ticks for '%s'\n", tick, data.hwait_run.ticks, data.hwait_run.cmd);
break;
case SAR_DATA_ENTITY_SERIAL:
fprintf(g_outfile, "\t\t[%5u] [SAR] Entity slot %d serial changed to %d\n", tick, data.entity_serial.slot, data.entity_serial.serial);
break;
case SAR_DATA_FRAMETIME:
fprintf(g_outfile, "\t\t[%5u] [SAR] Frame took %fms\n", tick, data.frametime * 1000.0f);
break;
case SAR_DATA_SPEEDRUN_TIME:
fprintf(g_outfile, "\t\t[%5u] [SAR] Speedrun finished with %zu splits!\n", tick, data.speedrun_time.nsplits);
{
Expand Down
1 change: 1 addition & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "util.h"

void util_strip_whitespace(char *str) {
if (strlen(str) == 0) return;
size_t i = 0;
while (isspace(str[i])) ++i;

Expand Down

0 comments on commit 919a265

Please sign in to comment.