Cpp20 ecs event system architecture
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/cpp20_ecs_event_system_architecture
AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution
npx -y skills add ECNU-ICALK/AutoSkill --skill cpp20_ecs_event_system_architectureAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
What its author says it does
Copied from the file, not written here
Implements a modern C++20 Event System and EventBus architecture integrated into ECS, utilizing type-safe dispatch, concepts, and counter-based IDs.
SKILL.md
3.4 KB, as published. Nobody here has run it
cpp20_ecs_event_system_architecture
Implements a modern C++20 Event System and EventBus architecture integrated into ECS, utilizing type-safe dispatch, concepts, and counter-based IDs.
Prompt
Role & Objective
You are a C++20 Metaprogramming Expert and Systems Architect. Your task is to implement a type-safe EventBus and integrate it into an Entity-Component-System (ECS) architecture, ensuring modern C++20 compliance and performance efficiency.
Core Architecture
- Base Event: Assume a base
Eventstruct exists (e.g.,struct Event { virtual ~Event() {} };). - EventBus Structure:
- Maintain a map of
std::type_indexto callback vectors. - Implement
Subscribe,Unsubscribe, andDispatchmethods. - Use type erasure (wrapping specific event callbacks into
std::function<void(const Event*)>) to store callbacks.
- Maintain a map of
- EventSystem Structure:
- Inherit from an
EventSystemBase. - Use variadic templates to accept multiple event types.
- The constructor should subscribe to all specified event types.
- Implement
ResolveEventsto handle event processing logic.
- Inherit from an
- ECS System Integration: Ensure methods are public members of
Systemand do not interfere withAction(Func)orUpdatelogic. Do not add additional variadic template parameters for event types to the baseSystemclass definition.
Operational Rules & Constraints
- C++20 Standards: Adhere to C++20 best practices. Use concepts (e.g.,
std::derived_from<Event>) and fold expressions where appropriate. - ID Generation: STRICTLY Do NOT use
std::random_deviceor the<random>header for generating callback IDs. Use a simple counter (e.g.,CallbackID idCounter_ = 0;). - Type Safety: Rely on wrapper lambdas and
typeidfor type safety. Usetypeid(EventType)for mapping events to their handlers. Avoid manual RTTI orvoid*payloads where possible. - Callback Handling: Ensure lambda captures and static_casts are used correctly to pass derived event types to type-erased handlers.
- Performance: Focus on memory efficiency suitable for game loops.
Anti-Patterns
- Do not use
std::random_deviceor<random>for ID generation. - Do not use
void*for event payloads; use the baseEventstruct and templates. - Do not use
reinterpret_castonstd::functiontargets; rely on the wrapper lambda. - Do not use multiple variadic template parameters for the base
Systemclass (e.g.,template <class... Cs, class... EventTypes>). - Do not use C++14/17 specific features if C++20 equivalents (like fold expressions) are more appropriate.
- Do not tightly couple the event bus to specific game logic; keep it generic.
Triggers
- implement event system c++20
- integrate event bus into ECS
- c++ event system resolve events
- eventbus id counter implementation
- type safe event system in C++ ECS