From fc81f9dcc7514dbf48ea9d682c3e904b909efaf0 Mon Sep 17 00:00:00 2001 From: falsycat Date: Thu, 17 Oct 2019 00:00:00 +0000 Subject: [PATCH] [fix] Fixed an issue that playing with offset might not work properly. --- .bin/music/test-60bpm.sj | 20 ++++---- .../sjplayer/AbstractScheduledController.d | 46 +++++++------------ sjplayer/src/sjplayer/Context.d | 13 +++--- .../sjplayer/VarStoreScheduledController.d | 1 + 4 files changed, 34 insertions(+), 46 deletions(-) diff --git a/.bin/music/test-60bpm.sj b/.bin/music/test-60bpm.sj index ed55e79..57a5b3e 100644 --- a/.bin/music/test-60bpm.sj +++ b/.bin/music/test-60bpm.sj @@ -4,22 +4,22 @@ actor [0..1] { clip_left := 0.1; } background [0..1] { - inner_r = 0.8; - inner_g = 0.8; - inner_b = 0.8; - inner_a = 1; + inner_r := 0.8; + inner_g := 0.8; + inner_b := 0.8; + inner_a := 1; - outer_r = 0; - outer_g = 0; - outer_b = 0; - outer_a = 1; + outer_r := 0; + outer_g := 0; + outer_b := 0; + outer_a := 1; } posteffect [0..1] { clip_left := 0.1; clip_right := 0.1; } -variable [0..3.5] { - hoge = 1-time; +variable [0..1] { + hoge = 1; } $repeat i 2 { diff --git a/sjplayer/src/sjplayer/AbstractScheduledController.d b/sjplayer/src/sjplayer/AbstractScheduledController.d index d3f4f66..66053ab 100644 --- a/sjplayer/src/sjplayer/AbstractScheduledController.d +++ b/sjplayer/src/sjplayer/AbstractScheduledController.d @@ -26,9 +26,22 @@ abstract class AbstractScheduledController : ScheduledControllerInterface { } override void Operate(float time) { - FinalizeCurrentOperationIfEnded(time); - PrepareNextOperationIfStarted(time); - ProcessCurrentOperationIfAvailable(time); + while (true) { + if (next_operation_index_ >= 1) { + const current = &operations_[next_operation_index_-1]; + ProcessOperation( + current.period.ConvertToRelativeTime(time), *current); + if (current.period.end > time) return; + FinalizeOperation(*current); + } + + if (next_operation_index_ >= operations_.length) return; + + const next = &operations_[next_operation_index_]; + if (next.period.start > time) return; + ++next_operation_index_; + PrepareOperation(*next); + } } protected: @@ -87,33 +100,6 @@ abstract class AbstractScheduledController : ScheduledControllerInterface { } private: - void FinalizeCurrentOperationIfEnded(float time) { - if (next_operation_index_ < 1) return; - - const current = &operations_[next_operation_index_-1]; - if (current.period.end > time) return; - - FinalizeOperation(*current); - } - void PrepareNextOperationIfStarted(float time) { - if (next_operation_index_ >= operations_.length) return; - - const next = &operations_[next_operation_index_]; - if (next.period.start > time) return; - - ++next_operation_index_; - PrepareOperation(*next); - } - void ProcessCurrentOperationIfAvailable(float time) { - if (next_operation_index_ < 1) return; - - const current = &operations_[next_operation_index_-1]; - if (current.period.end <= time) return; - - ProcessOperation( - current.period.ConvertToRelativeTime(time), *current); - } - const VarStoreInterface varstore_; const ParametersBlock[] operations_; diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d index 94b3e88..090e404 100644 --- a/sjplayer/src/sjplayer/Context.d +++ b/sjplayer/src/sjplayer/Context.d @@ -39,7 +39,12 @@ class Context { sjplayer.CircleElement, sjplayer.SquareElement, sjplayer.TriangleElement; + // FIXME: fucking solution auto factories = tuple( + tuple( + "variable", + VarStoreScheduledControllerFactory(varstore), + ), tuple( "actor", ActorControllerFactory(varstore, actor_), @@ -65,10 +70,6 @@ class Context { "triangle", TriangleElementScheduledControllerFactory(programs, varstore), ), - tuple( - "variable", - VarStoreScheduledControllerFactory(varstore), - ), ); foreach (ref factory; factories) { factory[1]. @@ -84,8 +85,8 @@ class Context { drawers_ = builder.drawers[]; controllers_ = builder.controllers[]; - actor_controller_ = factories[0][1].product; - posteffect_controller_ = factories[1][1].product; + actor_controller_ = factories[1][1].product; + posteffect_controller_ = factories[2][1].product; } /// ~this() { diff --git a/sjplayer/src/sjplayer/VarStoreScheduledController.d b/sjplayer/src/sjplayer/VarStoreScheduledController.d index fe0dcc5..07a9a5a 100644 --- a/sjplayer/src/sjplayer/VarStoreScheduledController.d +++ b/sjplayer/src/sjplayer/VarStoreScheduledController.d @@ -22,6 +22,7 @@ class VarStoreScheduledController : AbstractScheduledController { varstore_ = varstore; } + protected: override void SetParameter( ref in Parameter param, ref in AbstractScheduledController.VarStore vars) {