ECSTASY
All in the name
Loading...
Searching...
No Matches
main.cpp File Reference
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

static void addEventListeners (ecstasy::Registry &registry)
 
int main (int argc, char **argv)
 

Detailed Description

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Version
1.0.0
Date
2022-11-15

Definition in file main.cpp.

Function Documentation

◆ addEventListeners()

static void addEventListeners ( ecstasy::Registry registry)
static

Definition at line 27 of file main.cpp.

28{
29 registry.entityBuilder()
32 (void)r;
33 (void)entity;
34 std::cout << "Mouse button " << static_cast<int>(e.button) << " event, pressed = " << e.pressed
35 << std::endl;
36 })
37 .with<event::MouseWheelScrollListener>(
39 (void)r;
40 (void)entity;
41 std::cout << "Mouse wheel " << static_cast<int>(e.wheel) << " event, delta = " << e.delta << std::endl;
42 })
43 .with<event::MouseMoveListener>(
45 (void)r;
46 (void)entity;
47 std::cout << "Mouse move to (" << e.x << ", " << e.y << ")" << std::endl;
48 })
49 .with<event::KeyListener>([](ecstasy::Registry &r, ecstasy::Entity entity, const event::KeyEvent &e) {
50 (void)r;
51 (void)entity;
52 std::cout << "Keyboard key " << e.key << " event, pressed = " << e.pressed << std::endl;
53 })
54 .with<event::TextEnteredListener>(
56 (void)r;
57 (void)entity;
58 std::cout << "Text entered: " << esf::Encoding::utf32CharToUtf8String(e.unicode) << std::endl;
59 })
60 .with<event::GamepadButtonListener>([](ecstasy::Registry &r, ecstasy::Entity entity,
62 (void)r;
63 (void)entity;
64 std::cout << "Gamepad " << e.id << " button " << e.button << " event, pressed = " << e.pressed << std::endl;
65 })
66 .with<event::GamepadConnectedListener>(
68 (void)r;
69 (void)entity;
70 std::cout << "Gamepad " << e.id << " " << ((e.connected) ? "connected" : "disconnected") << std::endl;
71 })
72 .with<event::GamepadAxisListener>(
74 (void)r;
75 (void)entity;
76 std::cout << "Gamepad " << e.id << " axis " << e.axis << " changed to " << e.value << std::endl;
77 })
78 .with<event::KeySequenceListener>(std::initializer_list<event::Keyboard::Key>{event::Keyboard::Key::A,
79 event::Keyboard::Key::Z, event::Keyboard::Key::E},
81 (void)r;
82 (void)entity;
83 (void)e;
84 std::cout << "Key Sequence AZE completed" << std::endl;
85 })
86 .with<event::KeyCombinationListener>(std::initializer_list<event::Keyboard::Key>{event::Keyboard::Key::Q,
87 event::Keyboard::Key::S, event::Keyboard::Key::D},
89 (void)r;
90 (void)entity;
91 (void)e;
92 std::cout << "Key Combination QSD completed" << std::endl;
93 })
94 .build();
95}
Encapsulate an index to an entity.
Definition Entity.hpp:35
EntityBuilder & with(Args &&...args)
Add a component to the builder target entity.
Definition Registry.hpp:566
Base of an ECS architecture.
Definition Registry.hpp:82
EntityBuilder entityBuilder() noexcept
Create a new entity builder.
Definition Registry.cpp:33
T endl(T... args)
Event describing a gamepad axis value change.
Event describing a gamepad button pressed or released.
bool pressed
Whether the button is pressed (down) or not (up).
Event describing a gamepad connection or disconnection.
bool connected
Whether the gamepad has been connected or disconnected.
Event describing a key pressed or released.
Definition KeyEvent.hpp:25
bool pressed
Whether the key is pressed (down) or not (up).
Definition KeyEvent.hpp:29
Keyboard::Key key
Target key.
Definition KeyEvent.hpp:27
Event describing when a mouse button is pressed or released.
Event describing when the mouse move.
Event describing when a mouse wheel is scrolled.
float delta
Wheel offset (positive is up/left and negative is down/right)
Event describing a text (character) entered.
std::uint32_t unicode
Unicode of character entered.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 97 of file main.cpp.

98{
99 ecstasy::Registry registry;
100 esf::RenderWindow &window =
101 registry.addResource<esf::RenderWindow>(sf::VideoMode(1280, 720), "ECSTASY SFML integration: events");
102 window.setEventListener([](const sf::Event &event) {
103 std::cout << "Event " << event.type << std::endl;
104 return false;
105 });
106 registry.addSystem<esf::PollEvents>();
107 (void)argv;
108 (void)argc;
109
110 addEventListeners(registry);
111
112 while (window.get().isOpen()) {
113 window.get().clear(sf::Color::White);
114 registry.runSystems();
115 window.get().display();
116 }
117 return 0;
118}
static void addEventListeners(ecstasy::Registry &registry)
Definition main.cpp:27
constexpr T & get() noexcept
Get a reference to the object.
void runSystems()
Run all systems present in the registry.
Definition Registry.cpp:92
R & addResource(Args &&...args)
Add a new resource in the registry.
Definition Registry.hpp:884
S & addSystem(Args &&...args)
Add a new system in the registry.
Definition Registry.hpp:839
Poll events system, polling the events from the RenderWindow resource if present.
void setEventListener(EventListener listener) noexcept
Set the event listener.
Event integration.
Definition Event.hpp:25