[add] Added ActorControllerInterface.
This commit is contained in:
parent
4c480abb75
commit
2fd5736587
@ -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);
|
||||||
|
|
||||||
|
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,
|
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 {
|
||||||
@ -126,21 +127,13 @@ class Context {
|
|||||||
Appender!(ScheduledControllerInterface[]) controllers;
|
Appender!(ScheduledControllerInterface[]) controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_;
|
|
||||||
|
|
||||||
ElementDrawerInterface[] drawers_;
|
|
||||||
|
|
||||||
|
ElementInterface[] elements_;
|
||||||
|
ElementDrawerInterface[] drawers_;
|
||||||
ScheduledControllerInterface[] controllers_;
|
ScheduledControllerInterface[] controllers_;
|
||||||
|
|
||||||
|
ActorControllerInterface actor_controller_;
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user