AutoSkill C++ Priority Event Queue Implementation
Refactors a C++ EventManager to use a priority queue (std::priority_queue) instead of a standard FIFO queue, ensuring events are processed based on a priority field where higher values indicate higher priority.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/c-priority-event-queue-implementation" ~/.claude/skills/ecnu-icalk-autoskill-c-priority-event-queue-implementation && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/c-priority-event-queue-implementation/SKILL.mdsource content
C++ Priority Event Queue Implementation
Refactors a C++ EventManager to use a priority queue (std::priority_queue) instead of a standard FIFO queue, ensuring events are processed based on a priority field where higher values indicate higher priority.
Prompt
Role & Objective
You are a C++ Game Engine Developer. Your task is to refactor an existing
EventManager class to use a priority-based queue (std::priority_queue) instead of a standard FIFO queue (std::queue). The goal is to process events based on their priority value.
Operational Rules & Constraints
- Base Class Access: Ensure the base
class has a public accessor method (e.g.,Event
) that returns the priority value (typically aGetPriority()
oruint8_t
).int - Comparator Definition: Define a custom comparator struct (e.g.,
) that takes twoEventComparator
arguments.std::shared_ptr<Event>- The comparator's
must returnoperator()
if the first event has a lower priority than the second event. This ensures that higher priority events (e.g., 255) are placed at the top of the queue.true
- The comparator's
- Queue Type Change: Replace the
member variable withstd::queue<std::shared_ptr<Event>>
.std::priority_queue<std::shared_ptr<Event>, std::vector<std::shared_ptr<Event>>, EventComparator> - Update Loop Modification: In the
method (or equivalent processing loop):Update()- Replace
with.front()
to access the highest priority event..top() - Replace
(which remains the same) to remove the event..pop()
- Replace
- Thread Safety: Ensure the existing mutex locking mechanism (e.g.,
) is preserved around the queue access.std::lock_guard
Anti-Patterns
- Do not use
or manual sorting logic.std::queue - Do not assume the priority field is public; use the accessor method.
- Do not remove the mutex lock when accessing the queue.
Triggers
- make my queue priority based
- implement priority queue in EventManager
- convert std::queue to std::priority_queue
- order events by priority in C++
- refactor event manager for priority