[add] Added ElementProgramSet.
This commit is contained in:
parent
375dabf2ea
commit
669c908f94
36
sjplayer/src/sjplayer/ElementProgramSet.d
Normal file
36
sjplayer/src/sjplayer/ElementProgramSet.d
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/// License: MIT
|
||||||
|
module sjplayer.ElementProgramSet;
|
||||||
|
|
||||||
|
import std.meta,
|
||||||
|
std.typecons;
|
||||||
|
|
||||||
|
import sjplayer.CircleElement;
|
||||||
|
|
||||||
|
///
|
||||||
|
class ElementProgramSet {
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
alias ElementPrograms = Tuple!(CircleElementProgram);
|
||||||
|
|
||||||
|
///
|
||||||
|
this() {
|
||||||
|
foreach (ref program; programs_) {
|
||||||
|
program = new typeof(program);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~this() {
|
||||||
|
foreach (program; programs_) {
|
||||||
|
program.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
T Get(T)() out (r; r) {
|
||||||
|
enum index = staticIndexOf!(T, ElementPrograms.Types);
|
||||||
|
static assert(index >= 0);
|
||||||
|
return programs_[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ElementPrograms programs_;
|
||||||
|
}
|
@ -20,12 +20,14 @@ int main(string[] args) {
|
|||||||
scope(exit) sfMusic_destroy(music);
|
scope(exit) sfMusic_destroy(music);
|
||||||
sfMusic_play(music);
|
sfMusic_play(music);
|
||||||
|
|
||||||
|
import sjplayer.ElementProgramSet;
|
||||||
|
auto programs = new ElementProgramSet;
|
||||||
|
scope(exit) programs.destroy();
|
||||||
|
|
||||||
import sjplayer.CircleElement;
|
import sjplayer.CircleElement;
|
||||||
auto program = new CircleElementProgram;
|
|
||||||
scope(exit) program.destroy();
|
|
||||||
auto element = new CircleElement;
|
auto element = new CircleElement;
|
||||||
scope(exit) element.destroy();
|
scope(exit) element.destroy();
|
||||||
auto drawer = new CircleElementDrawer(program, [element]);
|
auto drawer = new CircleElementDrawer(programs.Get!CircleElementProgram, [element]);
|
||||||
scope(exit) drawer.destroy();
|
scope(exit) drawer.destroy();
|
||||||
|
|
||||||
with (element) {
|
with (element) {
|
||||||
|
Reference in New Issue
Block a user