RhythmGame 1.4.3
Loading...
Searching...
No Matches
HitEvent.h
Go to the documentation of this file.
1//
2// Created by bobini on 22.08.23.
3//
4
5#ifndef RHYTHMGAME_HITEVENT_H
6#define RHYTHMGAME_HITEVENT_H
7#include <QObject>
8#include <QVariant>
9#include "BmsPoints.h"
10#include "input/BmsKeys.h"
11namespace gameplay_logic {
12
19{
20 Q_GADGET
21 public:
22 enum class Action
23 {
24 None,
25 Press,
26 Release
27 };
28 Q_ENUM(Action)
29 private:
30 // nanoseconds
31 using DeltaTime = int64_t;
35 Q_PROPERTY(DeltaTime offsetFromStart READ getOffsetFromStart CONSTANT)
42 Q_PROPERTY(DeltaTime hitOffset READ getHitOffset CONSTANT)
44 Q_PROPERTY(int judgement READ getJudgement CONSTANT)
46 Q_PROPERTY(DeltaTime deviation READ getDeviation CONSTANT)
52 Q_PROPERTY(QVariant points READ getPoints CONSTANT)
56 Q_PROPERTY(int column READ getColumn CONSTANT)
62 Q_PROPERTY(int key READ getKey CONSTANT)
68 Q_PROPERTY(int noteIndex READ getNoteIndex CONSTANT)
72 Q_PROPERTY(Action action READ getAction CONSTANT)
77 Q_PROPERTY(bool noteRemoved READ getNoteRemoved CONSTANT)
78
79 DeltaTime offsetFromStart;
80 std::optional<BmsPoints> points;
81 std::optional<int> noteIndex;
82 int column;
83 std::optional<input::BmsKey> key;
85 bool noteRemoved;
86
87 public:
88 HitEvent(int column,
89 std::optional<input::BmsKey> key,
90 std::optional<int> noteIndex,
91 DeltaTime offsetFromStart,
92 std::optional<BmsPoints> points,
94 bool noteRemoved);
96 std::optional<int> noteIndex,
97 DeltaTime offsetFromStart,
98 std::optional<BmsPoints> points,
100 bool noteRemoved)
102 std::nullopt,
103 noteIndex,
105 points,
106 action,
108 {
109 }
110 HitEvent() = default;
111
112 auto getOffsetFromStart() const -> DeltaTime;
113 // if the tap did not hit a note, this returns null
114 auto getHitOffset() const -> DeltaTime;
115 auto getJudgement() const -> int;
116 auto getDeviation() const -> DeltaTime;
117 auto getPoints() const -> QVariant;
118 auto getPointsOptional() const -> std::optional<BmsPoints>;
119 auto getColumn() const -> int;
120 auto getKey() const -> int;
121 auto getKeyOptional() const -> std::optional<input::BmsKey>;
122 // if the tap did not hit a note, this returns -1
123 auto getNoteIndex() const -> int;
124 auto getAction() const -> Action;
125 auto getNoteRemoved() const -> bool;
126 void setAction(Action newAction);
127 void setPoints(std::optional<BmsPoints> newPoints);
128 void setNoteRemoved(bool newNoteRemoved);
129
130 auto operator>(const HitEvent& other) const
131 {
132 auto hitOffset = points.has_value() ? points->getDeviation() : 0;
133 auto otherHitOffset =
134 other.points.has_value() ? other.points->getDeviation() : 0;
135 return offsetFromStart + hitOffset >
136 other.offsetFromStart + otherHitOffset;
137 }
138 auto operator==(const HitEvent& other) const -> bool
139 {
140 return offsetFromStart == other.offsetFromStart &&
141 points == other.points && noteIndex == other.noteIndex &&
142 column == other.column && key == other.key &&
143 action == other.action &&
144 noteRemoved == other.noteRemoved;
145 }
146
147 friend auto operator<<(QDataStream& stream, const HitEvent& tap)
148 -> QDataStream&;
149 friend auto operator>>(QDataStream& stream, HitEvent& tap) -> QDataStream&;
150};
151} // namespace gameplay_logic
152
153#endif // RHYTHMGAME_HITEVENT_H
Definition BmsPoints.h:11
A very generic event that happened during gameplay.
Definition HitEvent.h:19
bool noteRemoved
Whether this event removed a note.
Definition HitEvent.h:77
int key
The physical key that caused this event or -1 if not applicable.
Definition HitEvent.h:62
friend auto operator>>(QDataStream &stream, HitEvent &tap) -> QDataStream &
Definition HitEvent.cpp:104
auto getColumn() const -> int
Definition HitEvent.cpp:29
DeltaTime deviation
Signed timing deviation in nanoseconds, or 0 when unavailable.
Definition HitEvent.h:46
void setNoteRemoved(bool newNoteRemoved)
Definition HitEvent.cpp:85
auto getJudgement() const -> int
Definition HitEvent.cpp:13
void setPoints(std::optional< BmsPoints > newPoints)
Definition HitEvent.cpp:80
friend auto operator<<(QDataStream &stream, const HitEvent &tap) -> QDataStream &
Definition HitEvent.cpp:95
auto getNoteRemoved() const -> bool
Definition HitEvent.cpp:70
auto getPoints() const -> QVariant
Definition HitEvent.cpp:23
auto getDeviation() const -> DeltaTime
Definition HitEvent.cpp:18
Action
Definition HitEvent.h:23
auto getOffsetFromStart() const -> DeltaTime
Definition HitEvent.cpp:8
void setAction(Action newAction)
Definition HitEvent.cpp:75
Action action
What the user did to cause this event to happen.
Definition HitEvent.h:72
int column
The column where this event happened.
Definition HitEvent.h:56
DeltaTime offsetFromStart
The offset from the start of the chart when this event happened.
Definition HitEvent.h:35
auto getHitOffset() const -> DeltaTime
Definition HitEvent.cpp:128
DeltaTime hitOffset
The offset from the note's perfect hit time when this event happened.
Definition HitEvent.h:42
auto getKeyOptional() const -> std::optional< input::BmsKey >
Definition HitEvent.cpp:55
int noteIndex
The index of the note that was hit or -1 if no note was hit.
Definition HitEvent.h:68
auto getKey() const -> int
Definition HitEvent.cpp:50
auto getPointsOptional() const -> std::optional< BmsPoints >
Definition HitEvent.cpp:90
auto operator==(const HitEvent &other) const -> bool
Definition HitEvent.h:138
QVariant points
The points awarded for this hit.
Definition HitEvent.h:52
auto getNoteIndex() const -> int
Definition HitEvent.cpp:60
int judgement
Judgement awarded for this event, or -1 when none was awarded.
Definition HitEvent.h:44
auto getAction() const -> Action
Definition HitEvent.cpp:65
Classes and functions mostly related to gameplay.
Definition ArenaGameplaySource.h:10
Various input-related classes and functions.
Definition BmsKeys.h:12