From 88834b805565b4761f904827ad32b9ba2a4d2265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Tue, 4 Apr 2023 22:46:28 +0200 Subject: [PATCH] Make sync track compress better (#67) * Delta encoding for sync track frames. * Fix non-monotonic track frames --- intro/data/intro.sync | 4 ++-- lib/libmisc/sync.c | 13 +++++++++++++ tools/sync2c/main.go | 18 +++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/intro/data/intro.sync b/intro/data/intro.sync index 4b42b398..878009cd 100644 --- a/intro/data/intro.sync +++ b/intro/data/intro.sync @@ -171,8 +171,8 @@ $293A 5 $2A00 2 $2A02 9 # lifeforms $2A0E 2 -$2912 2 -$2916 2 +$2A12 2 +$2A16 2 $2A18 5 $2A1A 2 $2A1C 5 diff --git a/lib/libmisc/sync.c b/lib/libmisc/sync.c index 06c3cc7e..2a4ae770 100644 --- a/lib/libmisc/sync.c +++ b/lib/libmisc/sync.c @@ -28,6 +28,19 @@ void TrackInit(TrackT *track) { track->type = TRACK_LINEAR; track->pending = true; + { + short prevFrame = -1; + TrackKeyT *curr; + + for (curr = track->data; curr->frame != END_KEY; curr++) { + if (curr->frame < 0) + continue; + if (prevFrame >= 0) + curr->frame += prevFrame; + prevFrame = curr->frame; + } + } + TrackAdvance(track, track->data); } diff --git a/tools/sync2c/main.go b/tools/sync2c/main.go index cecf3b4e..0590b29e 100644 --- a/tools/sync2c/main.go +++ b/tools/sync2c/main.go @@ -94,6 +94,18 @@ func parseFrame(token string) (frame int64, err error) { } } + if prevFrame >= 0 { + delta := frame - prevFrame + if delta < 0 { + return 0, &parseError{ + "frame numbers must be specified in ascending order"} + } + prevFrame = frame + frame = delta + } else { + prevFrame = frame + } + return frame, err } @@ -101,6 +113,8 @@ func parseValue(token string) (value int64, err error) { return strconv.ParseInt(token, 0, 16) } +var prevFrame int64 + func parseTrack(tokens []string, track *Track) (err error) { var frame, value int64 @@ -117,9 +131,6 @@ func parseTrack(tokens []string, track *Track) (err error) { if value, err = parseValue(tokens[1]); err != nil { return err } - if track.First != nil && track.First.Key > int(frame) { - return &parseError{"frame numbers must be specified in ascending order"} - } if len(tokens) == 3 && tokens[2][0] == '!' { typ := tokens[2][1:] @@ -179,6 +190,7 @@ func parseSyncFile(path string) []Track { // Create new track if tokens[0] == "@track" { + prevFrame = -1 track = &Track{RawName: tokens[1]} continue }