[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,
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);

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,
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 {
@ -127,20 +128,12 @@ class Context {
}
Actor actor_;
invariant(actor_);
ActorController actor_controller_;
invariant(actor_controller_);
Background background_;
invariant(background_);
PostEffect posteffect_;
invariant(posteffect_);
ElementInterface[] elements_;
ElementDrawerInterface[] drawers_;
ScheduledControllerInterface[] controllers_;
ActorControllerInterface actor_controller_;
}

View File

@ -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();