0
|
1 module renderer;
|
|
2
|
|
3 import dsfml.window.all;
|
|
4 import dsfml.system.all;
|
|
5 import dsfml.graphics.all;
|
|
6
|
|
7 import consumer;
|
|
8 import imagecache;
|
|
9
|
|
10 class Renderer {
|
|
11 public RenderWindow app;
|
|
12 public Cache cache;
|
|
13 private Consumer[] consumers;
|
|
14
|
|
15 this(char[] title, int width, int height, int depth=32) {
|
|
16 this.app = new RenderWindow(VideoMode(width, height, depth), title);
|
|
17 this.app.setFramerateLimit(40);
|
|
18
|
|
19 this.cache = new Cache("."); // TODO
|
|
20 }
|
|
21
|
|
22 void add_consumer(Consumer consumer) {
|
|
23 this.consumers ~= consumer;
|
|
24 }
|
|
25
|
|
26 /* start the mainloop */
|
|
27 void mainloop() {
|
|
28 Event evt;
|
|
29
|
|
30 while(this.app.isOpened()) {
|
|
31 // handle all events
|
|
32 while(this.app.getEvent(evt)) {
|
|
33 if (evt.Type == Event.EventType.CLOSED) {
|
|
34 this.app.close();
|
|
35 }
|
|
36 }
|
|
37 // draw all
|
|
38 foreach(Consumer consumer; this.consumers) {
|
|
39 consumer.draw();
|
|
40 }
|
|
41 // display all
|
|
42 this.app.display();
|
|
43 }
|
|
44 }
|
|
45 }
|