1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
11 // === Roguelike Input Mode Settings ===
12 // Milliseconds of button down before starting persistent input.
13 #define ROGUELIKE_PERSIST_DELAY_INIT 500
15 // Milliseconds between persistent input sends.
16 #define ROGUELIKE_PERSIST_DELAY_CONSECUTIVE 100
19 static GameWindow
* globalWindow
= NULL
;
21 GameWindow
* GameWindow::getWindow()
26 GameWindow::GameWindow(uint x
, uint y
, bool fullscreen
)
27 : Gosu::Window(x
, y
, fullscreen
)
32 GameWindow::~GameWindow()
38 bool GameWindow::init(const std::string descriptor
)
40 rc
= new Resourcer(this, descriptor
);
41 world
= new World(rc
, this);
42 return rc
->init() && world
->init();
45 void GameWindow::buttonDown(const Gosu::Button btn
)
47 if (btn
== Gosu::kbEscape
)
50 if (keystates
.find(btn
) == keystates
.end())
51 keystates
[btn
].second
= Gosu::milliseconds();
52 world
->buttonDown(btn
);
56 void GameWindow::buttonUp(const Gosu::Button btn
)
58 if (keystates
.find(btn
) != keystates
.end())
62 void GameWindow::draw()
67 bool GameWindow::needsRedraw() const
69 return world
->needsRedraw();
72 void GameWindow::update()
74 std::map
<Gosu::Button
, std::pair
<bool, unsigned long> >::iterator it
;
76 // Persistent input handling code
77 for (it
= keystates
.begin(); it
!= keystates
.end(); it
++) {
78 if ((*it
).second
.first
== false) {
79 if (Gosu::milliseconds() >=
80 (*it
).second
.second
+ROGUELIKE_PERSIST_DELAY_INIT
) {
81 (*it
).second
.second
= Gosu::milliseconds();
82 (*it
).second
.first
= true;
83 world
->buttonDown((*it
).first
);
89 if (Gosu::milliseconds() >=
90 (*it
).second
.second
+ROGUELIKE_PERSIST_DELAY_CONSECUTIVE
) {
91 (*it
).second
.second
= Gosu::milliseconds();
92 world
->buttonDown((*it
).first
);