#ifndef _ENGINE_EVENT_H_
#define _ENGINE_EVENT_H_

#include <engine/utility.h>

DECLARE_COMPONENT(Event, {
  uint32_t id;
})

#define SPAWN_EVENT(...) SPAWN(( Event, .id = event_id() ), ## __VA_ARGS__)

#define QUERY_EVENT(...) \
  static uint32_t CAT(_leid, __LINE__) = 0; \
  uint32_t CAT(_neid, __LINE__) = CAT(_leid, __LINE__); \
  _QUERY( \
    if(_event->id <= CAT(_leid, __LINE__)) return; \
    if(_event->id > CAT(_neid, __LINE__)) CAT(_neid, __LINE__) = _event->id; \
  , \
    CAT(_leid, __LINE__) = CAT(_neid, __LINE__); \
  , ( read, Event, _event ), ## __VA_ARGS__)

uint32_t Engine_next_event_id(void);

#endif