[add] Added ActorControllerInterface.

This commit is contained in:
falsycat 2019-10-09 00:00:00 +00:00
parent 4c480abb75
commit 2fd5736587
4 changed files with 39 additions and 31 deletions

View File

@ -10,12 +10,13 @@ import sjscript;
import sjplayer.AbstractScheduledController, import sjplayer.AbstractScheduledController,
sjplayer.Actor, sjplayer.Actor,
sjplayer.ActorControllerInterface,
sjplayer.ContextBuilderInterface, sjplayer.ContextBuilderInterface,
sjplayer.ScheduledController, sjplayer.ScheduledController,
sjplayer.VarStoreInterface; sjplayer.VarStoreInterface;
/// ///
class ActorController : ActorScheduledController { class ActorController : ActorScheduledController, ActorControllerInterface {
public: public:
/// ///
enum MaxAccel = 1e-1; enum MaxAccel = 1e-1;
@ -31,10 +32,10 @@ class ActorController : ActorScheduledController {
operations_ = operations; operations_ = operations;
} }
/// override void Accelarate(vec2 accel) {
void Update(vec2 accel) {
actor_.accel += accel; actor_.accel += accel;
}
override void Update() {
actor_.accel.x = actor_.accel.x.clamp(-MaxAccel, MaxAccel); actor_.accel.x = actor_.accel.x.clamp(-MaxAccel, MaxAccel);
actor_.accel.y = actor_.accel.y.clamp(-MaxAccel, MaxAccel); actor_.accel.y = actor_.accel.y.clamp(-MaxAccel, MaxAccel);

View File

@ -0,0 +1,14 @@
/// License: MIT
module sjplayer.ActorControllerInterface;
import gl4d;
///
interface ActorControllerInterface {
public:
///
void Accelarate(vec2 accel);
///
void Update();
}

View File

@ -11,6 +11,7 @@ import sjscript;
import sjplayer.Actor, import sjplayer.Actor,
sjplayer.ActorController, sjplayer.ActorController,
sjplayer.ActorControllerInterface,
sjplayer.Background, sjplayer.Background,
sjplayer.ContextBuilderInterface, sjplayer.ContextBuilderInterface,
sjplayer.ElementDrawerInterface, sjplayer.ElementDrawerInterface,
@ -61,15 +62,15 @@ class Context {
} }
/// ///
~this() { ~this() {
controllers_.each!destroy;
actor_controller_.destroy(); actor_controller_.destroy();
controllers_.each!destroy;
drawers_.each!destroy; drawers_.each!destroy;
elements_.each!destroy; elements_.each!destroy;
actor_.destroy();
background_.destroy();
posteffect_.destroy(); posteffect_.destroy();
background_.destroy();
actor_.destroy();
} }
/// ///
@ -77,10 +78,6 @@ class Context {
assert(false); // TODO: assert(false); // TODO:
} }
///
void UpdateActor(vec2 accel) {
actor_controller_.Update(accel);
}
/// ///
void OperateScheduledControllers(float time) { void OperateScheduledControllers(float time) {
controllers_.each!(x => x.Operate(time)); controllers_.each!(x => x.Operate(time));
@ -90,12 +87,6 @@ class Context {
void StartDrawing() { void StartDrawing() {
posteffect_.BindFramebuffer(); posteffect_.BindFramebuffer();
} }
///
void EndDrawing() {
posteffect_.UnbindFramebuffer();
posteffect_.DrawFramebuffer();
}
/// ///
void DrawBackground() { void DrawBackground() {
background_.Draw(); background_.Draw();
@ -108,6 +99,16 @@ class Context {
void DrawActor() { void DrawActor() {
actor_.Draw(); actor_.Draw();
} }
///
void EndDrawing() {
posteffect_.UnbindFramebuffer();
posteffect_.DrawFramebuffer();
}
///
@property inout(ActorControllerInterface) actor() inout {
return actor_controller_;
}
private: private:
class Builder : ContextBuilderInterface { class Builder : ContextBuilderInterface {
@ -127,20 +128,12 @@ class Context {
} }
Actor actor_; Actor actor_;
invariant(actor_);
ActorController actor_controller_;
invariant(actor_controller_);
Background background_; Background background_;
invariant(background_);
PostEffect posteffect_; PostEffect posteffect_;
invariant(posteffect_);
ElementInterface[] elements_; ElementInterface[] elements_;
ElementDrawerInterface[] drawers_; ElementDrawerInterface[] drawers_;
ScheduledControllerInterface[] controllers_; ScheduledControllerInterface[] controllers_;
ActorControllerInterface actor_controller_;
} }

View File

@ -38,7 +38,7 @@ int main(string[] args) {
const beat = msecs/60f * bpm; const beat = msecs/60f * bpm;
context.OperateScheduledControllers(beat); context.OperateScheduledControllers(beat);
context.UpdateActor(vec2(0, 0)); context.actor.Update();
context.StartDrawing(); context.StartDrawing();