Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 7e452e5

Browse files
committed
update engine (inputs rewrite)
1 parent 9a993e5 commit 7e452e5

File tree

12 files changed

+35
-63
lines changed

12 files changed

+35
-63
lines changed

sources/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int argc, const char *args[])
2020
engineInitialize(EngineCreateConfig());
2121
controlThread().updatePeriod(1000000 / 30);
2222

23-
const auto closeListener = engineWindow()->events.listen(inputListener<InputClassEnum::WindowClose, InputWindow>([](auto) { engineStop(); }));
23+
const auto closeListener = engineWindow()->events.listen(inputFilter([](input::WindowClose) { engineStop(); }));
2424
engineWindow()->title("MazeTD");
2525
engineAssets()->add(HashString("mazetd/mazetd.pack"));
2626

sources/player/buildingsList.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace mazetd
99
{
1010
namespace
1111
{
12-
bool buildingSelectionClick(Entity *e)
12+
bool buildingSelectionClick(input::GuiValue in)
1313
{
14-
playerBuildingSelection = e;
14+
playerBuildingSelection = in.entity;
1515
engineGuiManager()->focus(0); // defocus to allow using keyboard shortcuts
1616
return true;
1717
}
@@ -76,9 +76,9 @@ namespace mazetd
7676
Entity *e = ents->create(++index);
7777
e->value<GuiButtonComponent>();
7878
e->value<GuiTextComponent>().value = String(name);
79-
e->value<GuiEventComponent>().event.bind<&buildingSelectionClick>();
79+
e->value<GuiEventComponent>().event = inputFilter(buildingSelectionClick);
8080
e->value<NameComponent>().name = name;
81-
e->value<GuiTooltipComponent>().tooltip.bind<&buildingTooltip>();
81+
e->value<GuiTooltipComponent>().tooltip.bind<buildingTooltip>();
8282
return e;
8383
}
8484

sources/player/buildingsPlacement.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ namespace mazetd
179179
updateAttacksMods();
180180
}
181181

182-
bool mouseEvent(InputMouse in)
182+
bool mouseEvent(auto in)
183183
{
184184
if (!gameReady || playerCursorTile == m || in.mods != ModifiersFlags::None)
185185
return false;
@@ -195,16 +195,7 @@ namespace mazetd
195195
return false;
196196
}
197197

198-
EventListener<bool(const GenericInput &)> mousePressListener;
199-
EventListener<bool(const GenericInput &)> mouseMoveListener;
200-
201-
const auto engineInitListener = controlThread().initialize.listen(
202-
[]()
203-
{
204-
mousePressListener.attach(engineWindow()->events);
205-
mousePressListener.bind(inputListener<InputClassEnum::MousePress, InputMouse>(&mouseEvent));
206-
mouseMoveListener.attach(engineWindow()->events);
207-
mouseMoveListener.bind(inputListener<InputClassEnum::MouseMove, InputMouse>(&mouseEvent));
208-
});
198+
EventListener<bool(const GenericInput &)> mousePressListener = engineEvents().listen(inputFilter(mouseEvent<input::MousePress>), 200);
199+
EventListener<bool(const GenericInput &)> mouseMoveListener = engineEvents().listen(inputFilter(mouseEvent<input::MouseMove>), 201);
209200
}
210201
}

sources/player/camera.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace mazetd
4444
return pos - cntr;
4545
}
4646

47-
bool mousePress(InputMouse in)
47+
bool mousePress(input::MousePress in)
4848
{
4949
if (in.buttons != MouseButtonsFlags::Right)
5050
return false;
@@ -63,14 +63,14 @@ namespace mazetd
6363
playerPanning = false;
6464
}
6565

66-
bool mouseRelease(InputMouse in)
66+
bool mouseRelease(input::MouseRelease in)
6767
{
6868
if (in.buttons == MouseButtonsFlags::Right)
6969
stop();
7070
return false;
7171
}
7272

73-
bool mouseMove(InputMouse)
73+
bool mouseMove(input::MouseMove)
7474
{
7575
if (!playerPanning)
7676
return false;
@@ -87,7 +87,7 @@ namespace mazetd
8787
return false;
8888
}
8989

90-
bool mouseWheel(InputMouseWheel in)
90+
bool mouseWheel(input::MouseWheel in)
9191
{
9292
switch (in.mods)
9393
{
@@ -108,13 +108,13 @@ namespace mazetd
108108
return false;
109109
}
110110

111-
bool focusLose(InputWindow)
111+
bool focusLose(input::WindowFocusLose)
112112
{
113113
stop();
114114
return false;
115115
}
116116

117-
bool keyRelease(InputKey in)
117+
bool keyRelease(input::KeyPress in)
118118
{
119119
if (in.key == 'C')
120120
{
@@ -125,29 +125,12 @@ namespace mazetd
125125
return false;
126126
}
127127

128-
EventListener<bool(const GenericInput &)> mousePressListener;
129-
EventListener<bool(const GenericInput &)> mouseReleaseListener;
130-
EventListener<bool(const GenericInput &)> mouseMoveListener;
131-
EventListener<bool(const GenericInput &)> mouseWheelListener;
132-
EventListener<bool(const GenericInput &)> focusloseListener;
133-
EventListener<bool(const GenericInput &)> keyReleaseListener;
134-
135-
const auto engineInitListener = controlThread().initialize.listen(
136-
[]()
137-
{
138-
mousePressListener.attach(engineWindow()->events, 100);
139-
mousePressListener.bind(inputListener<InputClassEnum::MousePress, InputMouse>(&mousePress));
140-
mouseReleaseListener.attach(engineWindow()->events, 101);
141-
mouseReleaseListener.bind(inputListener<InputClassEnum::MouseRelease, InputMouse>(&mouseRelease));
142-
mouseMoveListener.attach(engineWindow()->events, 102);
143-
mouseMoveListener.bind(inputListener<InputClassEnum::MouseMove, InputMouse>(&mouseMove));
144-
mouseWheelListener.attach(engineWindow()->events, 103);
145-
mouseWheelListener.bind(inputListener<InputClassEnum::MouseWheel, InputMouseWheel>(&mouseWheel));
146-
focusloseListener.attach(engineWindow()->events, 104);
147-
focusloseListener.bind(inputListener<InputClassEnum::FocusLose, InputWindow>(&focusLose));
148-
keyReleaseListener.attach(engineWindow()->events, 105);
149-
keyReleaseListener.bind(inputListener<InputClassEnum::KeyRelease, InputKey>(&keyRelease));
150-
});
128+
EventListener<bool(const GenericInput &)> mousePressListener = engineEvents().listen(inputFilter(mousePress), 100);
129+
EventListener<bool(const GenericInput &)> mouseReleaseListener = engineEvents().listen(inputFilter(mouseRelease), 101);
130+
EventListener<bool(const GenericInput &)> mouseMoveListener = engineEvents().listen(inputFilter(mouseMove), 102);
131+
EventListener<bool(const GenericInput &)> mouseWheelListener = engineEvents().listen(inputFilter(mouseWheel), 103);
132+
EventListener<bool(const GenericInput &)> focusloseListener = engineEvents().listen(inputFilter(focusLose), 104);
133+
EventListener<bool(const GenericInput &)> keyReleaseListener = engineEvents().listen(inputFilter(keyRelease), 105);
151134

152135
const auto engineUpdateListener = controlThread().update.listen(
153136
[]()

sources/player/gameSpeed.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace mazetd
1010
{
1111
namespace
1212
{
13-
bool keyPress(InputKey in)
13+
bool keyPress(input::KeyPress in)
1414
{
1515
if (!gameReady)
1616
return false;
@@ -35,6 +35,8 @@ namespace mazetd
3535
return false;
3636
}
3737

38+
EventListener<bool(const GenericInput &)> keyPressListener = engineEvents().listen(inputFilter(keyPress), 110);
39+
3840
void gameScheduleAction()
3941
{
4042
if (!gameReady || gamePaused)
@@ -43,15 +45,11 @@ namespace mazetd
4345
eventGameUpdate().dispatch();
4446
}
4547

46-
EventListener<bool(const GenericInput &)> keyPressListener;
4748
Holder<Schedule> gameUpdateSchedule;
4849

4950
const auto engineInitListener = controlThread().initialize.listen(
5051
[]()
5152
{
52-
keyPressListener.attach(engineWindow()->events, 110);
53-
keyPressListener.bind(inputListener<InputClassEnum::KeyPress, InputKey>(&keyPress));
54-
5553
ScheduleCreateConfig cfg;
5654
cfg.name = "game update";
5755
cfg.type = ScheduleTypeEnum::SteadyPeriodic;

sources/screens/about.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace mazetd
2626
}
2727
{
2828
auto _ = g->rightRow();
29-
g->button().text("Close").event<&setScreenMainmenu>();
29+
g->button().text("Close").event(setScreenMainmenu);
3030
}
3131
}
3232
}

sources/screens/game.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace mazetd
150150
{ // top bar
151151
auto _1 = g->alignment(Vec2(0.5, 0));
152152
auto _2 = g->row();
153-
g->button().image(HashString("mazetd/gui/menu.png")).event<&setScreenPaused>().size(Vec2(50, 0));
153+
g->button().image(HashString("mazetd/gui/menu.png")).event(setScreenPaused).size(Vec2(50, 0));
154154
{
155155
auto _1 = g->panel();
156156
auto _2 = g->row();

sources/screens/lost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ namespace mazetd
2222
auto _ = g->panel().text("Game Over");
2323
g->label().text(Stringizer() + "Waves: " + SpawningGroup::waveIndex);
2424
}
25-
g->button().text("Close").event<&buttonStop>();
25+
g->button().text("Close").event(buttonStop);
2626
}
2727
}

sources/screens/mainMenu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ namespace mazetd
1919
auto _1 = g->alignment(Vec2(0.8, 0.666));
2020
auto _2 = g->panel();
2121
auto _3 = g->column();
22-
g->button().text("Start").event<&setScreenGenerating>();
23-
g->button().text("About").event<&setScreenAbout>();
24-
g->button().text("Quit").event<&engineStop>();
22+
g->button().text("Start").event(setScreenGenerating);
23+
g->button().text("About").event(setScreenAbout);
24+
g->button().text("Quit").event(engineStop);
2525
}
2626
}
2727

2828
namespace
2929
{
30-
const auto engineInitListener = controlThread().initialize.listen(&setScreenMainmenu, 999);
30+
const auto engineInitListener = controlThread().initialize.listen(setScreenMainmenu, 999);
3131
}
3232
}

0 commit comments

Comments
 (0)