[add] Added PostEffectController.

This commit is contained in:
falsycat 2019-10-09 00:00:00 +00:00
parent 2fd5736587
commit 1e6ebe97ce
6 changed files with 105 additions and 6 deletions

View File

@ -79,7 +79,7 @@ struct ActorControllerFactory {
}
///
@property ActorController product() {
@property ActorController product() out (r; r) {
return product_;
}

View File

@ -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_;
}

View File

@ -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_;

View File

@ -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_;
}

View File

@ -0,0 +1,11 @@
/// License: MIT
module sjplayer.PostEffectControllerInterface;
///
interface PostEffectControllerInterface {
public:
///
void CauseDamagedEffect();
///
void Update();
}

View File

@ -39,6 +39,7 @@ int main(string[] args) {
context.OperateScheduledControllers(beat);
context.actor.Update();
context.posteffect.Update();
context.StartDrawing();