[update] Added ActorControllerFactory.
This commit is contained in:
parent
9d55655c92
commit
8b4e4535a1
@ -1,13 +1,16 @@
|
|||||||
/// License: MIT
|
/// License: MIT
|
||||||
module sjplayer.ActorController;
|
module sjplayer.ActorController;
|
||||||
|
|
||||||
import std.algorithm;
|
import std.algorithm,
|
||||||
|
std.range.primitives;
|
||||||
|
|
||||||
import gl4d;
|
import gl4d;
|
||||||
|
|
||||||
import sjscript;
|
import sjscript;
|
||||||
|
|
||||||
import sjplayer.Actor,
|
import sjplayer.AbstractScheduledController,
|
||||||
|
sjplayer.Actor,
|
||||||
|
sjplayer.ContextBuilderInterface,
|
||||||
sjplayer.ScheduledController,
|
sjplayer.ScheduledController,
|
||||||
sjplayer.VarStoreInterface;
|
sjplayer.VarStoreInterface;
|
||||||
|
|
||||||
@ -29,7 +32,7 @@ class ActorController : ActorScheduledController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
void Manipulate(vec2 accel) {
|
void Update(vec2 accel) {
|
||||||
actor_.accel += accel;
|
actor_.accel += accel;
|
||||||
|
|
||||||
actor_.accel.x = actor_.accel.x.clamp(-MaxAccel, MaxAccel);
|
actor_.accel.x = actor_.accel.x.clamp(-MaxAccel, MaxAccel);
|
||||||
@ -56,3 +59,33 @@ private alias ActorScheduledController = ScheduledController!(
|
|||||||
"color_a": "color.a",
|
"color_a": "color.a",
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
///
|
||||||
|
struct ActorControllerFactory {
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
this(in VarStoreInterface varstore, Actor actor) {
|
||||||
|
varstore_ = varstore;
|
||||||
|
actor_ = actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
void Create(R)(R params, ContextBuilderInterface builder)
|
||||||
|
if (isInputRange!R && is(ElementType!R == ParametersBlock)) {
|
||||||
|
product_ = new ActorController(
|
||||||
|
actor_, varstore_, SortParametersBlock(params));
|
||||||
|
builder.AddScheduledController(product_);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@property ActorController product() {
|
||||||
|
return product_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const VarStoreInterface varstore_;
|
||||||
|
|
||||||
|
Actor actor_;
|
||||||
|
|
||||||
|
ActorController product_;
|
||||||
|
}
|
||||||
|
@ -5,9 +5,13 @@ import std.algorithm,
|
|||||||
std.array,
|
std.array,
|
||||||
std.typecons;
|
std.typecons;
|
||||||
|
|
||||||
|
import gl4d;
|
||||||
|
|
||||||
import sjscript;
|
import sjscript;
|
||||||
|
|
||||||
import sjplayer.Background,
|
import sjplayer.Actor,
|
||||||
|
sjplayer.ActorController,
|
||||||
|
sjplayer.Background,
|
||||||
sjplayer.ContextBuilderInterface,
|
sjplayer.ContextBuilderInterface,
|
||||||
sjplayer.ElementDrawerInterface,
|
sjplayer.ElementDrawerInterface,
|
||||||
sjplayer.ElementInterface,
|
sjplayer.ElementInterface,
|
||||||
@ -23,11 +27,16 @@ class Context {
|
|||||||
auto builder = new Builder;
|
auto builder = new Builder;
|
||||||
auto varstore = new BlackHole!VarStoreInterface;
|
auto varstore = new BlackHole!VarStoreInterface;
|
||||||
|
|
||||||
|
actor_ = new Actor(programs.Get!ActorProgram);
|
||||||
background_ = new Background(programs.Get!BackgroundProgram);
|
background_ = new Background(programs.Get!BackgroundProgram);
|
||||||
|
|
||||||
import sjplayer.BackgroundScheduledController,
|
import sjplayer.BackgroundScheduledController,
|
||||||
sjplayer.CircleElementScheduledController;
|
sjplayer.CircleElementScheduledController;
|
||||||
auto factories = tuple(
|
auto factories = tuple(
|
||||||
|
tuple(
|
||||||
|
"actor",
|
||||||
|
ActorControllerFactory(varstore, actor_),
|
||||||
|
),
|
||||||
tuple(
|
tuple(
|
||||||
"background",
|
"background",
|
||||||
BackgroundScheduledControllerFactory(varstore, background_),
|
BackgroundScheduledControllerFactory(varstore, background_),
|
||||||
@ -37,7 +46,7 @@ class Context {
|
|||||||
CircleElementScheduledControllerFactory(programs, varstore),
|
CircleElementScheduledControllerFactory(programs, varstore),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
foreach (factory; factories) {
|
foreach (ref factory; factories) {
|
||||||
factory[1].
|
factory[1].
|
||||||
Create(params.filter!(x => x.name == factory[0]), builder);
|
Create(params.filter!(x => x.name == factory[0]), builder);
|
||||||
}
|
}
|
||||||
@ -45,6 +54,8 @@ class Context {
|
|||||||
elements_ = builder.elements[];
|
elements_ = builder.elements[];
|
||||||
drawers_ = builder.drawers[];
|
drawers_ = builder.drawers[];
|
||||||
controllers_ = builder.controllers[];
|
controllers_ = builder.controllers[];
|
||||||
|
|
||||||
|
actor_controller_ = factories[0][1].product;
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
~this() {
|
~this() {
|
||||||
@ -59,6 +70,16 @@ class Context {
|
|||||||
ElementInterface.DamageCalculationResult CalculateDamage() const {
|
ElementInterface.DamageCalculationResult CalculateDamage() const {
|
||||||
assert(false); // TODO:
|
assert(false); // TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
void UpdateActor(vec2 accel) {
|
||||||
|
actor_controller_.Update(accel);
|
||||||
|
}
|
||||||
|
///
|
||||||
|
void OperateScheduledControllers(float time) {
|
||||||
|
controllers_.each!(x => x.Operate(time));
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
void DrawBackground() {
|
void DrawBackground() {
|
||||||
background_.Draw();
|
background_.Draw();
|
||||||
@ -68,8 +89,8 @@ class Context {
|
|||||||
drawers_.each!(x => x.Draw());
|
drawers_.each!(x => x.Draw());
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
void OperateScheduledControllers(float time) {
|
void DrawActor() {
|
||||||
controllers_.each!(x => x.Operate(time));
|
actor_.Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -89,7 +110,14 @@ class Context {
|
|||||||
Appender!(ScheduledControllerInterface[]) controllers;
|
Appender!(ScheduledControllerInterface[]) controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Actor actor_;
|
||||||
|
invariant(actor_);
|
||||||
|
|
||||||
|
ActorController actor_controller_;
|
||||||
|
invariant(actor_controller_);
|
||||||
|
|
||||||
Background background_;
|
Background background_;
|
||||||
|
invariant(background_);
|
||||||
|
|
||||||
ElementInterface[] elements_;
|
ElementInterface[] elements_;
|
||||||
|
|
||||||
|
@ -37,10 +37,12 @@ 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));
|
||||||
|
|
||||||
gl.Clear(GL_COLOR_BUFFER_BIT);
|
gl.Clear(GL_COLOR_BUFFER_BIT);
|
||||||
context.DrawBackground();
|
context.DrawBackground();
|
||||||
context.DrawElements();
|
context.DrawElements();
|
||||||
|
context.DrawActor();
|
||||||
sfWindow_display(win);
|
sfWindow_display(win);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user