diff --git a/sjplayer/src/sjplayer/ActorController.d b/sjplayer/src/sjplayer/ActorController.d index 2cba4e1..c62f59b 100644 --- a/sjplayer/src/sjplayer/ActorController.d +++ b/sjplayer/src/sjplayer/ActorController.d @@ -79,7 +79,7 @@ struct ActorControllerFactory { } /// - @property ActorController product() { + @property ActorController product() out (r; r) { return product_; } diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d index 43d7030..16578a6 100644 --- a/sjplayer/src/sjplayer/Context.d +++ b/sjplayer/src/sjplayer/Context.d @@ -17,6 +17,8 @@ import sjplayer.Actor, sjplayer.ElementDrawerInterface, sjplayer.ElementInterface, sjplayer.PostEffect, + sjplayer.PostEffectController, + sjplayer.PostEffectControllerInterface, sjplayer.ProgramSet, sjplayer.ScheduledControllerInterface, sjplayer.VarStore; @@ -40,6 +42,11 @@ class Context { "actor", ActorControllerFactory(varstore, actor_), ), + tuple( + "posteffect", + PostEffectControllerFactory(varstore, posteffect_), + ), + tuple( "background", BackgroundScheduledControllerFactory(varstore, background_), @@ -58,12 +65,11 @@ class Context { drawers_ = builder.drawers[]; controllers_ = builder.controllers[]; - actor_controller_ = factories[0][1].product; + actor_controller_ = factories[0][1].product; + posteffect_controller_ = factories[1][1].product; } /// ~this() { - actor_controller_.destroy(); - controllers_.each!destroy; drawers_.each!destroy; elements_.each!destroy; @@ -109,6 +115,10 @@ class Context { @property inout(ActorControllerInterface) actor() inout { return actor_controller_; } + /// + @property inout(PostEffectControllerInterface) posteffect() inout { + return posteffect_controller_; + } private: class Builder : ContextBuilderInterface { @@ -135,5 +145,6 @@ class Context { ElementDrawerInterface[] drawers_; ScheduledControllerInterface[] controllers_; - ActorControllerInterface actor_controller_; + ActorControllerInterface actor_controller_; + PostEffectControllerInterface posteffect_controller_; } diff --git a/sjplayer/src/sjplayer/PostEffect.d b/sjplayer/src/sjplayer/PostEffect.d index e02e541..ad218ed 100644 --- a/sjplayer/src/sjplayer/PostEffect.d +++ b/sjplayer/src/sjplayer/PostEffect.d @@ -14,7 +14,7 @@ class PostEffect { /// align(1) vec2 clip_lefttop = vec2(1, 1); /// - align(1) vec2 clip_righttop = vec2(1, 1); + align(1) vec2 clip_rightbottom = vec2(1, 1); } /// @@ -62,7 +62,9 @@ class PostEffect { program_.Draw(tex_, sampler_, instance, size_); } + /// Instance instance; + alias instance this; private: const vec2i size_; diff --git a/sjplayer/src/sjplayer/PostEffectController.d b/sjplayer/src/sjplayer/PostEffectController.d new file mode 100644 index 0000000..a3499cf --- /dev/null +++ b/sjplayer/src/sjplayer/PostEffectController.d @@ -0,0 +1,74 @@ +/// License: MIT +module sjplayer.PostEffectController; + +import std.range.primitives; + +import sjscript; + +import sjplayer.AbstractScheduledController, + sjplayer.ContextBuilderInterface, + sjplayer.PostEffect, + sjplayer.PostEffectControllerInterface, + sjplayer.ScheduledController, + sjplayer.VarStoreInterface; + +/// +class PostEffectController : PostEffectScheduledController, PostEffectControllerInterface { + public: + /// + this( + PostEffect posteffect, + in VarStoreInterface varstore, + in ParametersBlock[] operations) { + super(posteffect, varstore, operations); + posteffect_ = posteffect; + } + + override void CauseDamagedEffect() { + } + override void Update() { + } + + private: + PostEffect posteffect_; +} + +private alias PostEffectScheduledController = ScheduledController!( + PostEffect, + [ + "clip_left": "clip_lefttop.x", + "clip_top": "clip_lefttop.y", + "clip_right": "clip_rightbottom.x", + "clip_bottom": "clip_rightbottom.y", + ] + ); + +/// +struct PostEffectControllerFactory { + public: + /// + this(in VarStoreInterface varstore, PostEffect posteffect) { + varstore_ = varstore; + posteffect_ = posteffect; + } + + /// + void Create(R)(R params, ContextBuilderInterface builder) + if (isInputRange!R && is(ElementType!R == ParametersBlock)) { + product_ = new PostEffectController( + posteffect_, varstore_, SortParametersBlock(params)); + builder.AddScheduledController(product_); + } + + /// + @property PostEffectController product() out (r; r) { + return product_; + } + + private: + const VarStoreInterface varstore_; + + PostEffect posteffect_; + + PostEffectController product_; +} diff --git a/sjplayer/src/sjplayer/PostEffectControllerInterface.d b/sjplayer/src/sjplayer/PostEffectControllerInterface.d new file mode 100644 index 0000000..ed245f5 --- /dev/null +++ b/sjplayer/src/sjplayer/PostEffectControllerInterface.d @@ -0,0 +1,11 @@ +/// License: MIT +module sjplayer.PostEffectControllerInterface; + +/// +interface PostEffectControllerInterface { + public: + /// + void CauseDamagedEffect(); + /// + void Update(); +} diff --git a/sjplayer/standalone/main.d b/sjplayer/standalone/main.d index 3911513..ac124f2 100644 --- a/sjplayer/standalone/main.d +++ b/sjplayer/standalone/main.d @@ -39,6 +39,7 @@ int main(string[] args) { context.OperateScheduledControllers(beat); context.actor.Update(); + context.posteffect.Update(); context.StartDrawing();