From ecbed62b80733d19a13304d174455747573c6317 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 6 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Added Context struct for `sjplayer`. --- sjplayer/src/sjplayer/Context.d | 42 +++++++++++++++++++++++++++++++++ sjplayer/src/sjplayer/package.d | 7 +++--- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 sjplayer/src/sjplayer/Context.d diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d new file mode 100644 index 0000000..7e4620f --- /dev/null +++ b/sjplayer/src/sjplayer/Context.d @@ -0,0 +1,42 @@ +/// License: MIT +module sjplayer.Context; + +import std.algorithm; + +import sjplayer.ElementInterface, + sjplayer.ScheduledControllerInterface; + +/// +struct Context { + public: + @disable this(); + @disable this(this); + + /// + ~this() { + controllers_.each!destroy; + drawers_.each!destroy; + elements_.each!destroy; + } + + /// + ElementInterface.DamageCalculationResult CalculateDamage() const { + assert(false); // TODO: + } + + /// + void DrawElements() { + drawers_.each!(x => x.Draw()); + } + /// + void OperateScheduledControllers(float time) { + controllers_.each!(x => x.Operate(time)); + } + + private: + ElementInterface[] elements_; + + ElementDrawerInterface[] drawers_; + + ScheduledControllerInterface[] controllers_; +} diff --git a/sjplayer/src/sjplayer/package.d b/sjplayer/src/sjplayer/package.d index 3264cb2..5a2cbf1 100644 --- a/sjplayer/src/sjplayer/package.d +++ b/sjplayer/src/sjplayer/package.d @@ -4,15 +4,16 @@ module sjplayer; import sjscript; public { - import sjplayer.ElementProgramSet; + import sjplayer.Context, + sjplayer.ElementProgramSet; } /// -auto CreateContextFromText(string src, ElementProgramSet programs) { +Context CreateContextFromText(string src, ElementProgramSet programs) { return src.CreateScriptAst().CreateContextFromScriptAst(programs); } /// -auto CreateContextFromScriptAst( +Context CreateContextFromScriptAst( ParametersBlock[] params, ElementProgramSet programs) { // TODO: assert(false);