RhythmGame 1.4.3
Loading...
Searching...
No Matches
NoteState.h
Go to the documentation of this file.
1//
2// Created by PC on 06/02/2025.
3//
4
5#ifndef NOTESTATE_H
6#define NOTESTATE_H
7
8#include "BmsNotes.h"
9#include "HitEvent.h"
10
11#include <QAbstractProxyModel>
12#include <boost/icl/interval_map.hpp>
13
14#include <limits>
15#include <optional>
16#include <utility>
17
18namespace gameplay_logic {
20{
21 Q_GADGET
22 Q_PROPERTY(Note note MEMBER note)
23 Q_PROPERTY(qint64 index MEMBER index)
27 Q_PROPERTY(QVariant hitData MEMBER hitData)
32 Q_PROPERTY(QVariant otherEndHitData MEMBER otherEndHitData)
36 Q_PROPERTY(bool belowBottom MEMBER belowBottom)
37 public:
38 Note note;
39 qint64 index;
40 QVariant hitData = QVariant::fromValue(nullptr);
41 QVariant otherEndHitData = QVariant::fromValue(nullptr);
42 bool hit = false;
43 bool otherEndHit = false;
44 bool belowBottom = false;
45 double longNoteEndPosition = std::numeric_limits<double>::infinity();
46};
47
53class ColumnState final : public QAbstractListModel
54{
55 Q_OBJECT
56 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged)
57 Q_PROPERTY(
58 bool holdingLongNote READ isHoldingLongNote NOTIFY holdingLongNoteChanged)
59
60 QList<NoteState> notes;
61 QList<int> timeToPositionIndexMapping;
62 boost::icl::interval_map<double, std::set<qint64>> lnBodies;
63 int64_t elapsed{};
64 bool pressed = false;
65 bool holdingLongNote = false;
66 void setPressed(bool pressed);
67 void setHoldingLongNote(bool holdingLongNote);
68
69 public:
82
83 explicit ColumnState(QList<NoteState> notes, QObject* parent = nullptr);
84 auto rowCount(const QModelIndex& parent) const -> int override;
85 auto data(const QModelIndex& index, int role) const -> QVariant override;
86 auto roleNames() const -> QHash<int, QByteArray> override;
87 void onHitEvent(HitEvent hit);
88 auto isPressed() const -> bool;
89 auto isHoldingLongNote() const -> bool;
90 auto getNotes() const -> const QList<NoteState>& { return notes; }
91 auto getNotes() -> QList<NoteState>& { return notes; }
92 auto mapTimeIndexToPositionIndex(int64_t timeIndex) const -> int;
94 auto getLnBeginBounds(double position) const
95 -> std::optional<std::pair<int, int>>;
96
97 signals:
100};
101
103{
104 Q_GADGET
105 Q_PROPERTY(Time time MEMBER time)
106 Q_PROPERTY(qint64 index MEMBER index)
107
108 public:
109 Time time;
110 qint64 index;
111};
112
117class BarLinesState final : public QAbstractListModel
118{
119 Q_OBJECT
120 QList<BarLineState> barLines;
121
122 public:
123 explicit BarLinesState(QList<BarLineState> barLines,
124 QObject* parent = nullptr);
125 auto rowCount(const QModelIndex& parent) const -> int override;
126 auto data(const QModelIndex& index, int role) const -> QVariant override;
127 auto getBarlines() const -> const QList<BarLineState>&;
128};
129
135class Filter : public QAbstractProxyModel
136{
137 Q_OBJECT
141 Q_PROPERTY(double topPosition READ getTopPosition WRITE setTopPosition
142 NOTIFY topPositionChanged)
146 Q_PROPERTY(double bottomPosition READ getBottomPosition WRITE
147 setBottomPosition NOTIFY bottomPositionChanged)
148 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged)
149 Q_PROPERTY(
150 bool holdingLongNote READ isHoldingLongNote NOTIFY holdingLongNoteChanged)
151
152 double topPosition = 0.0;
153 double bottomPosition = 0.0;
154 int bottomRow = 0;
155 int firstRow = 0;
156 int endRow = 0;
157 bool pressed = false;
158 bool holdingLongNote = false;
159 void setPressed(bool pressed);
160 void setHoldingLongNote(bool holdingLongNote);
161 ColumnState* columnState;
162 void setRows(int first, int end);
163
164 public:
165 explicit Filter(ColumnState* columnState, QObject* parent = nullptr);
166
167 auto getTopPosition() const -> double { return topPosition; }
168 void setTopPosition(double value);
169 auto getBottomPosition() const -> double { return bottomPosition; }
170 void setBottomPosition(double value);
171 Q_INVOKABLE void setVisibleRange(double bottom, double top);
172 auto isPressed() const -> bool { return pressed; }
173 auto isHoldingLongNote() const -> bool { return holdingLongNote; }
174 auto index(int row,
175 int column = 0,
176 const QModelIndex& parent = QModelIndex()) const
177 -> QModelIndex override;
178 auto parent(const QModelIndex& child) const -> QModelIndex override;
179 auto rowCount(const QModelIndex& parent) const -> int override;
180 auto columnCount(const QModelIndex& parent) const -> int override;
181 auto mapToSource(const QModelIndex& proxyIndex) const
182 -> QModelIndex override;
183 auto mapFromSource(const QModelIndex& sourceIndex) const
184 -> QModelIndex override;
185 signals:
186 void topPositionChanged();
187 void bottomPositionChanged();
188 void pressedChanged();
189 void holdingLongNoteChanged();
190};
191
197class BarlineFilter : public QAbstractProxyModel
198{
199 Q_OBJECT
203 Q_PROPERTY(double topPosition READ getTopPosition WRITE setTopPosition
204 NOTIFY topPositionChanged)
208 Q_PROPERTY(double bottomPosition READ getBottomPosition WRITE
209 setBottomPosition NOTIFY bottomPositionChanged)
210
211 double topPosition = 0.0;
212 double bottomPosition = 0.0;
213 int bottomRow = 0;
214 int topRow = 0;
215
216 public:
217 explicit BarlineFilter(BarLinesState* barLinesState,
218 QObject* parent = nullptr);
219
220 auto getTopPosition() const -> double { return topPosition; }
221 void setTopPosition(double value);
222 auto getBottomPosition() const -> double { return bottomPosition; }
223 void setBottomPosition(double value);
224 Q_INVOKABLE void setVisibleRange(double bottom, double top);
225 signals:
228
229 public:
230 // QAbstractProxyModel overrides
231 auto mapToSource(const QModelIndex& proxyIndex) const
232 -> QModelIndex override;
233 auto mapFromSource(const QModelIndex& sourceIndex) const
234 -> QModelIndex override;
235 auto index(int row,
236 int column = 0,
237 const QModelIndex& parent = QModelIndex()) const
238 -> QModelIndex override;
239 auto parent(const QModelIndex& child) const -> QModelIndex override;
240 auto rowCount(const QModelIndex& parent) const -> int override;
241 auto columnCount(const QModelIndex& parent) const -> int override;
242 auto data(const QModelIndex& index, int role = Qt::DisplayRole) const
243 -> QVariant override;
244};
245
249class GameplayState final : public QObject
250{
251 Q_OBJECT
252 Q_PROPERTY(QList<Filter*> columnStates READ getColumnFilters CONSTANT)
253 Q_PROPERTY(BarlineFilter* barLinesState READ getBarLineFilter CONSTANT)
254
255 BarLinesState* barLinesState;
256 BarlineFilter* barLineFilter = nullptr;
257 QList<ColumnState*> columnStates;
258 QList<Filter*> columnFilters;
259 double position = 0.0;
260 std::optional<double> noteVisiblePositionSpan;
261 std::optional<double> barLineVisiblePositionSpan;
262
263 void updateVisibleRanges();
264
265 public:
266 GameplayState(QList<ColumnState*> columnStates,
267 BarLinesState* barLinesState,
268 QObject* parent = nullptr);
269 auto getColumnStates() -> QList<ColumnState*>;
270 auto getColumnFilters() -> QList<Filter*>;
271 auto getBarLinesState() const -> BarLinesState*;
272 auto getBarLineFilter() const -> BarlineFilter*;
273 Q_INVOKABLE int noteTypeAt(int column, int noteIndex) const;
274 void setPosition(double value);
279 Q_INVOKABLE void setVisiblePositionSpans(double noteSpan,
280 double barLineSpan);
281};
282
283} // namespace gameplay_logic
284
285#endif // NOTESTATE_H
bool pressed
Definition BeatorajaReplayImporter.cpp:65
double value
Definition BmsNotesData.cpp:35
int column
Definition BmsReplayData.cpp:41
std::optional< int > noteIndex
Definition BmsReplayData.cpp:40
QByteArray data
Definition Lr2FontCache.cpp:25
zip_uint64_t index
Definition SongAssetStore.cpp:436
Definition NoteState.h:103
The state of the barlines in the chart.
Definition NoteState.h:118
A filter model that only shows the barlines that are in the visible area.
Definition NoteState.h:198
auto getBottomPosition() const -> double
Definition NoteState.h:222
The state of a single column, including its notes and whether it is currently pressed.
Definition NoteState.h:54
Role
Definition NoteState.h:71
@ BelowBottomRole
Definition NoteState.h:76
@ NoteOtherEndHitRole
Definition NoteState.h:75
@ HeldLongNoteRole
Definition NoteState.h:79
@ NoteHitRole
Definition NoteState.h:74
@ NotePositionRole
Definition NoteState.h:73
@ LongNoteEndPositionRole
Definition NoteState.h:77
@ StaticLongNoteCandidateRole
Definition NoteState.h:80
@ VisibleNoteRole
Definition NoteState.h:78
auto getNotes() -> QList< NoteState > &
Definition NoteState.h:91
A filter model that only shows the notes that are in the visible area.
Definition NoteState.h:136
auto getBottomPosition() const -> double
Definition NoteState.h:169
auto isHoldingLongNote() const -> bool
Definition NoteState.h:173
auto isPressed() const -> bool
Definition NoteState.h:172
The state of gameplay columns and barlines.
Definition NoteState.h:250
A very generic event that happened during gameplay.
Definition HitEvent.h:19
Definition NoteState.h:20
Note note
Definition NoteState.h:22
double longNoteEndPosition
Definition NoteState.h:45
QVariant otherEndHitData
Definition NoteState.h:32
bool belowBottom
Definition NoteState.h:36
QVariant hitData
Definition NoteState.h:27
qint64 index
Definition NoteState.h:23
bool hit
Definition NoteState.h:42
bool otherEndHit
Definition NoteState.h:43
Definition BmsNotes.h:119
Definition BmsNotes.h:14
Classes and functions mostly related to gameplay.
Definition ArenaGameplaySource.h:10