[add] Added ActorControllerInterface.
This commit is contained in:
parent
4c480abb75
commit
2fd5736587
@ -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);
|
||||
|
||||
|
14
sjplayer/src/sjplayer/ActorControllerInterface.d
Normal file
14
sjplayer/src/sjplayer/ActorControllerInterface.d
Normal file
@ -0,0 +1,14 @@
|
||||
/// License: MIT
|
||||
module sjplayer.ActorControllerInterface;
|
||||
|
||||
import gl4d;
|
||||
|
||||
///
|
||||
interface ActorControllerInterface {
|
||||
public:
|
||||
///
|
||||
void Accelarate(vec2 accel);
|
||||
|
||||
///
|
||||
void Update();
|
||||
}
|
@ -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_;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user