From 2fd5736587b1a196e288bc06f6aca1ea0aefdd4a Mon Sep 17 00:00:00 2001 From: falsycat Date: Wed, 9 Oct 2019 00:00:00 +0000 Subject: [PATCH] [add] Added ActorControllerInterface. --- sjplayer/src/sjplayer/ActorController.d | 9 ++-- .../src/sjplayer/ActorControllerInterface.d | 14 ++++++ sjplayer/src/sjplayer/Context.d | 45 ++++++++----------- sjplayer/standalone/main.d | 2 +- 4 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 sjplayer/src/sjplayer/ActorControllerInterface.d diff --git a/sjplayer/src/sjplayer/ActorController.d b/sjplayer/src/sjplayer/ActorController.d index 173a944..2cba4e1 100644 --- a/sjplayer/src/sjplayer/ActorController.d +++ b/sjplayer/src/sjplayer/ActorController.d @@ -10,12 +10,13 @@ import sjscript; import sjplayer.AbstractScheduledController, sjplayer.Actor, + sjplayer.ActorControllerInterface, sjplayer.ContextBuilderInterface, sjplayer.ScheduledController, sjplayer.VarStoreInterface; /// -class ActorController : ActorScheduledController { +class ActorController : ActorScheduledController, ActorControllerInterface { public: /// enum MaxAccel = 1e-1; @@ -31,10 +32,10 @@ class ActorController : ActorScheduledController { operations_ = operations; } - /// - void Update(vec2 accel) { + override void Accelarate(vec2 accel) { actor_.accel += accel; - + } + override void Update() { actor_.accel.x = actor_.accel.x.clamp(-MaxAccel, MaxAccel); actor_.accel.y = actor_.accel.y.clamp(-MaxAccel, MaxAccel); diff --git a/sjplayer/src/sjplayer/ActorControllerInterface.d b/sjplayer/src/sjplayer/ActorControllerInterface.d new file mode 100644 index 0000000..4876612 --- /dev/null +++ b/sjplayer/src/sjplayer/ActorControllerInterface.d @@ -0,0 +1,14 @@ +/// License: MIT +module sjplayer.ActorControllerInterface; + +import gl4d; + +/// +interface ActorControllerInterface { + public: + /// + void Accelarate(vec2 accel); + + /// + void Update(); +} diff --git a/sjplayer/src/sjplayer/Context.d b/sjplayer/src/sjplayer/Context.d index e2a6863..43d7030 100644 --- a/sjplayer/src/sjplayer/Context.d +++ b/sjplayer/src/sjplayer/Context.d @@ -11,6 +11,7 @@ import sjscript; import sjplayer.Actor, sjplayer.ActorController, + sjplayer.ActorControllerInterface, sjplayer.Background, sjplayer.ContextBuilderInterface, sjplayer.ElementDrawerInterface, @@ -61,15 +62,15 @@ class Context { } /// ~this() { - controllers_.each!destroy; actor_controller_.destroy(); + controllers_.each!destroy; drawers_.each!destroy; elements_.each!destroy; - actor_.destroy(); - background_.destroy(); posteffect_.destroy(); + background_.destroy(); + actor_.destroy(); } /// @@ -77,10 +78,6 @@ class Context { assert(false); // TODO: } - /// - void UpdateActor(vec2 accel) { - actor_controller_.Update(accel); - } /// void OperateScheduledControllers(float time) { controllers_.each!(x => x.Operate(time)); @@ -90,12 +87,6 @@ class Context { void StartDrawing() { posteffect_.BindFramebuffer(); } - /// - void EndDrawing() { - posteffect_.UnbindFramebuffer(); - posteffect_.DrawFramebuffer(); - } - /// void DrawBackground() { background_.Draw(); @@ -108,6 +99,16 @@ class Context { void DrawActor() { actor_.Draw(); } + /// + void EndDrawing() { + posteffect_.UnbindFramebuffer(); + posteffect_.DrawFramebuffer(); + } + + /// + @property inout(ActorControllerInterface) actor() inout { + return actor_controller_; + } private: class Builder : ContextBuilderInterface { @@ -126,21 +127,13 @@ class Context { Appender!(ScheduledControllerInterface[]) controllers; } - Actor actor_; - invariant(actor_); - - ActorController actor_controller_; - invariant(actor_controller_); - + Actor actor_; Background background_; - invariant(background_); - PostEffect posteffect_; - invariant(posteffect_); - - ElementInterface[] elements_; - - ElementDrawerInterface[] drawers_; + ElementInterface[] elements_; + ElementDrawerInterface[] drawers_; ScheduledControllerInterface[] controllers_; + + ActorControllerInterface actor_controller_; } diff --git a/sjplayer/standalone/main.d b/sjplayer/standalone/main.d index 3fd3fe2..3911513 100644 --- a/sjplayer/standalone/main.d +++ b/sjplayer/standalone/main.d @@ -38,7 +38,7 @@ int main(string[] args) { const beat = msecs/60f * bpm; context.OperateScheduledControllers(beat); - context.UpdateActor(vec2(0, 0)); + context.actor.Update(); context.StartDrawing();