ArcdpsExtension
 
Loading...
Searching...
No Matches
EventSequencer.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <compare>
6#include <condition_variable>
7#include <cstdint>
8#include <functional>
9#include <mutex>
10#include <set>
11#include <string>
12#include <thread>
13
14namespace ArcdpsExtension {
16 public:
17 typedef std::function<uintptr_t(cbtevent* ev, ag* src, ag* dst, const char* skillname, uint64_t id, uint64_t revision)> CallbackSignature;
18
19 explicit EventSequencer(CallbackSignature pCallback);
20 virtual ~EventSequencer();
21
22 // delete copy and move
23 EventSequencer(const EventSequencer& pOther) = delete;
24 EventSequencer(EventSequencer&& pOther) noexcept = delete;
25 EventSequencer& operator=(const EventSequencer& pOther) = delete;
26 EventSequencer& operator=(EventSequencer&& pOther) noexcept = delete;
27
28 struct Event {
29 struct CbtEvent : cbtevent {
30 bool Present = false;
31 };
32
33 struct Agent : ag {
34 std::string NameStorage;
35 bool Present = false;
36 };
37
41
42 const char* Skillname; // Skill names are guaranteed to be valid for the lifetime of the process so copying pointer is fine
43 uint64_t Id;
44 uint64_t Revision;
45
46 std::strong_ordering operator<=>(const Event& pOther) const {
47 return Id <=> pOther.Id;
48 }
49
52 Id(pId),
54 if (pEv) {
55 *static_cast<cbtevent*>(&Ev) = *pEv;
56 Ev.Present = true;
57 }
58 if (pSrc) {
59 *static_cast<ag*>(&Source) = *pSrc;
60 Source.Present = true;
61 if (Source.name) {
62 Source.NameStorage = pSrc->name;
63 }
64 }
65 if (pDst) {
66 *static_cast<ag*>(&Destination) = *pDst;
67 Destination.Present = true;
68 if (Destination.name) {
70 }
71 }
72 }
73 };
74
75 void ProcessEvent(cbtevent* pEv, ag* pSrc, ag* pDst, const char* pSkillname, uint64_t pId, uint64_t pRevision);
76
77 [[nodiscard]] bool EventsPending() const;
78
83 void Reset();
84
85 void Shutdown();
86
87 private:
88 const CallbackSignature mCallback;
89 std::multiset<Event> mElements;
90 std::mutex mElementsMutex;
91 std::condition_variable_any mNewElement;
92 std::jthread mThread;
93 uint64_t mNextId = 2; // Events start with ID 2 for some reason (it is always like that and no plans to change)
94 bool mThreadRunning = false;
95
96 void EventInternal(Event& pElem) const;
97 };
98} // namespace ArcdpsExtension
Definition EventSequencer.h:15
void ProcessEvent(cbtevent *pEv, ag *pSrc, ag *pDst, const char *pSkillname, uint64_t pId, uint64_t pRevision)
Definition EventSequencer.cpp:7
virtual ~EventSequencer()
Definition EventSequencer.cpp:47
EventSequencer(EventSequencer &&pOther) noexcept=delete
bool EventsPending() const
Definition EventSequencer.cpp:13
EventSequencer & operator=(EventSequencer &&pOther) noexcept=delete
EventSequencer(const EventSequencer &pOther)=delete
void Shutdown()
Definition EventSequencer.cpp:76
std::function< uintptr_t(cbtevent *ev, ag *src, ag *dst, const char *skillname, uint64_t id, uint64_t revision)> CallbackSignature
Definition EventSequencer.h:17
void Reset()
Definition EventSequencer.cpp:17
EventSequencer & operator=(const EventSequencer &pOther)=delete
Definition ArcdpsExtension.h:10
Definition EventSequencer.h:33
std::string NameStorage
Definition EventSequencer.h:34
bool Present
Definition EventSequencer.h:35
bool Present
Definition EventSequencer.h:30
Definition EventSequencer.h:28
uint64_t Id
Definition EventSequencer.h:43
std::strong_ordering operator<=>(const Event &pOther) const
Definition EventSequencer.h:46
const char * Skillname
Definition EventSequencer.h:42
Event(cbtevent *pEv, ag *pSrc, ag *pDst, const char *pSkillname, uint64_t pId, uint64_t pRevision)
Definition EventSequencer.h:50
CbtEvent Ev
Definition EventSequencer.h:38
Agent Source
Definition EventSequencer.h:39
Agent Destination
Definition EventSequencer.h:40
uint64_t Revision
Definition EventSequencer.h:44
Definition arcdps_structs_slim.h:330
const char * name
Definition arcdps_structs_slim.h:331
Definition arcdps_structs_slim.h:299