[update] Added SortParametersBlock function.

This commit is contained in:
falsycat 2019-10-08 00:00:00 +00:00
parent ea55a66247
commit 9d55655c92
2 changed files with 18 additions and 10 deletions

View File

@ -2,7 +2,9 @@
module sjplayer.AbstractScheduledController; module sjplayer.AbstractScheduledController;
import std.algorithm, import std.algorithm,
std.array,
std.exception, std.exception,
std.range.primitives,
std.typecons; std.typecons;
import sjscript; import sjscript;
@ -103,3 +105,16 @@ abstract class AbstractScheduledController : ScheduledControllerInterface {
float[string] user_vars_; float[string] user_vars_;
} }
///
ParametersBlock[] SortParametersBlock(R)(R params)
if (isInputRange!R && is(ElementType!R == ParametersBlock)) {
auto result = params.array;
result.sort!"a.period.start < b.period.start";
auto before = Period(-1, 0);
foreach (param; result) {
(!param.period.IsPeriodIntersectedToPeriod(before)).enforce();
}
return result;
}

View File

@ -8,7 +8,8 @@ import std.algorithm,
import sjscript; import sjscript;
import sjplayer.Background, import sjplayer.AbstractScheduledController,
sjplayer.Background,
sjplayer.ContextBuilderInterface, sjplayer.ContextBuilderInterface,
sjplayer.ScheduledController, sjplayer.ScheduledController,
sjplayer.VarStoreInterface, sjplayer.VarStoreInterface,
@ -45,16 +46,8 @@ struct BackgroundScheduledControllerFactory {
/// ///
void Create(R)(R params, ContextBuilderInterface builder) void Create(R)(R params, ContextBuilderInterface builder)
if (isInputRange!R && is(ElementType!R == ParametersBlock)) { if (isInputRange!R && is(ElementType!R == ParametersBlock)) {
auto params_array = params.array;
params_array.sort!"a.period.start < b.period.start";
auto before = Period(-1, 0);
foreach (param; params_array) {
(!param.period.IsPeriodIntersectedToPeriod(before)).enforce();
}
auto ctrl = new BackgroundScheduledController( auto ctrl = new BackgroundScheduledController(
background_, varstore_, params_array); background_, varstore_, SortParametersBlock(params));
builder.AddScheduledController(ctrl); builder.AddScheduledController(ctrl);
} }