0
\$\begingroup\$

I'm transitioning over to an ECS architecture for a small C++ graphics engine I'm working on and I'm a bit stumped on how to tackle events. One solution I came across was from this Reddit post basically if I'm understanding it correctly you create an entity whenever an event occurs and then add a component which would be the event type and have data specific to the event.

while (SDL_PollEvent(&event)) {
    if (sdlEvent.type == SDL_KEYDOWN || sdlEvent.type == SDL_KEYUP) {
        Entity keyEventEntity = entityManager.createEntity();
        keyEventEntity.addComponent<KeyEventComponent>(sdlEvent.key.keysym.sym, sdlEvent.type == SDL_KEYDOWN);
    }
}

I really like this solution (that's probably the best way to write it though), however, when I inevitably add non ECS systems this probably won't work so would I just create a second more typical event system or would I just use a typical event system to begin with and then perhaps ECS systems could inherit from a event handler interface?

\$\endgroup\$
1

0

You must log in to answer this question.