Skip to content

Commit 13cc68e

Browse files
committed
test commit for timers
1 parent 4d6301f commit 13cc68e

File tree

7 files changed

+86
-20
lines changed

7 files changed

+86
-20
lines changed

Encore/src/RhythmEngine/Engine/BaseEngine.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
#ifndef BASEENGINE_H
66
#define BASEENGINE_H
77
#include "BaseStats.h"
8+
#include "RhythmTimer.h"
89
#include "timingvalues.h"
910
#include "RhythmEngine/NoteVector.h"
1011

1112
#include <memory>
1213
#include <span>
14+
#include <unordered_map>
1315

1416
namespace Encore::RhythmEngine {
17+
18+
1519
enum HitState {
1620
HitNote = 0,
1721
OverhitNote = 1,
@@ -20,7 +24,7 @@ namespace Encore::RhythmEngine {
2024

2125
class BaseEngine {
2226
public:
23-
BaseEngine(auto _chart, auto _stats) : chart(_chart), stats(_stats) {};
27+
BaseEngine(auto _chart, auto _stats) : chart(_chart), stats(_stats), Timers() {};
2428
virtual ~BaseEngine() {};
2529
virtual void SetStatsInputState(InputChannel channel, Action action) {};
2630
bool EarlyStrike(double noteStartTime, double inputTime, double inputOffset) {
@@ -46,7 +50,7 @@ namespace Encore::RhythmEngine {
4650
*/
4751
std::shared_ptr<BaseChart<EncNote, 5> > chart;
4852
std::shared_ptr<BaseStats<5> > stats;
49-
53+
std::unordered_map<std::string, RhythmTimer> Timers;
5054
virtual void UpdateOnFrame(double CurrentTime) {
5155

5256
};

Encore/src/RhythmEngine/Engine/GuitarEngine.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ bool Encore::RhythmEngine::GuitarEngine::ActivateOverdrive(
5454
void Encore::RhythmEngine::GuitarEngine::UpdateOnFrame(double CurrentTime) {
5555
CheckMissedNotes(0, TheSongTime.GetElapsedTime());
5656
stats->OverdriveFill += chart->overdrive.CheckOverdrive(CurrentTime);
57-
if (stats->OverdriveFill > 1.0) stats->OverdriveFill = 1.0;
57+
if (stats->OverdriveFill > 1.0)
58+
stats->OverdriveFill = 1.0;
5859
// there is ONLY lane 0 for guitar
5960
}
6061
void Encore::RhythmEngine::GuitarEngine::SetStatsInputState(
6162
InputChannel channel, Action action
6263
) {
6364
stats->InputTime = TheSongTime.GetElapsedTime(); // todo: REPLACE WITH ACTUAL SONG
6465
// TIME
65-
// (IN SECONDS)
66+
// (IN SECONDS)
6667
if (action == Action::PRESS) {
6768
switch (channel) {
6869
case InputChannel::LANE_1:
@@ -128,36 +129,38 @@ int Encore::RhythmEngine::GuitarEngine::RunHitStateCheck(
128129
if (StrumInput) {
129130
// miss should be managed by current frame
130131
// overhit is managed here
132+
if (Timers["SAH"].CanBeUsedUp(stats->InputTime)) {
133+
Timers["SAH"].ResetTimer();
134+
return CheckNextInput;
135+
}
131136
if (EarlyStrike(CurrentNote.StartSeconds, stats->InputTime, stats->InputOffset)) {
137+
132138
chart->overdrive.UpdateEventViaNote(false, CurrentNote.StartTicks);
133139
return OverhitNote;
134140
}
135141
// if frets match, continue and try to hit
136142
if (InHitwindow(CurrentNote.StartSeconds, stats->InputTime, stats->InputOffset)) {
137143
if (!MaskMatch(CurrentNote.Lane, stats->HeldFretsArrayToMask())) {
138-
stats->FretAfterStrum = true;
139-
stats->FretAfterStrumTime = stats->InputTime;
144+
Timers["FAS"].ActivateTimer(stats->InputTime);
140145
return CheckNextInput;
141146
}
142147
}
143148
}
144149
// if FAS is active, or if there was a strum
145150
// really couldve just put it up there LMFAO
146-
bool strum = HittableAsStrum(
147-
CurrentNote.NoteType,
148-
stats->FretAfterStrum,
149-
stats->InputTime,
150-
stats->FretAfterStrumTime
151-
)
152-
|| StrumInput;
151+
bool strum = Timers["FAS"].CanBeUsedUp(stats->InputTime) || StrumInput;
153152

154153
if (MaskMatch(CurrentNote.Lane, stats->HeldFretsArrayToMask())
155154
&& InHitwindow(CurrentNote.StartSeconds, stats->InputTime, stats->InputOffset)
156155
&& (HittableAsHopo(CurrentNote.NoteType, stats->Combo)
157156
|| HittableAsTap(CurrentNote.NoteType) || strum)) {
158157
stats->HitNote(std::popcount(CurrentNote.Lane));
159158
chart->overdrive.UpdateEventViaNote(true, CurrentNote.StartTicks);
160-
stats->FretAfterStrum = false;
159+
if (CurrentNote.NoteType == 1 && !StrumInput && !Timers["FAS"].CanBeUsedUp(stats->InputTime)) {
160+
Timers["SAH"].ActivateTimer(stats->InputTime);
161+
}
162+
Timers["FAS"].ResetTimer();
163+
161164
chart->at(0).erase(curNoteItr);
162165
return HitState::HitNote;
163166
}

Encore/src/RhythmEngine/Engine/GuitarEngine.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Encore::RhythmEngine {
1111
class GuitarEngine : public BaseEngine {
12-
1312
bool ActivateOverdrive(InputChannel channel, Action action) override;
1413

1514
/*
@@ -38,16 +37,21 @@ namespace Encore::RhythmEngine {
3837
bool PlayerIsPaused() override { return stats->Paused; };
3938
void TogglePause() override { stats->Paused = !stats->Paused; };
4039

41-
4240
public:
41+
std::unordered_map<std::string, RhythmTimer> Timers;
4342
void UpdateOnFrame(double CurrentTime) override;
4443
void SetStatsInputState(InputChannel channel, Action action) override;
4544
void HitNote() override;
4645
void Overhit() override;
4746
std::shared_ptr<GuitarChart> chart;
4847
std::shared_ptr<GuitarStats> stats;
4948
GuitarEngine(auto _chart, auto _stats)
50-
: BaseEngine(_chart, _stats), chart(_chart), stats(_stats) {};
49+
: BaseEngine(_chart, _stats),
50+
Timers{
51+
std::pair<std::string, RhythmTimer>("FAS", 0.025),
52+
std::pair<std::string, RhythmTimer>("SAH", 0.05)
53+
},
54+
chart(_chart), stats(_stats) {};
5155
~GuitarEngine() override {};
5256
};
5357
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Created by maria on 20/06/2025.
3+
//
4+
5+
#ifndef RHYTHMTIMER_H
6+
#define RHYTHMTIMER_H
7+
8+
namespace Encore::RhythmEngine {
9+
struct RhythmTimer {
10+
RhythmTimer() : Duration(0.05), Time(-1), Active(false) {};
11+
explicit RhythmTimer(double dur) {
12+
Duration = dur;
13+
Time = -1;
14+
Active = false;
15+
};
16+
[[nodiscard]] bool CanBeUsedUp(double time) const {
17+
if (time < Time + Duration && Active)
18+
return true;
19+
return false;
20+
}
21+
void ActivateTimer(double time) {
22+
Time = time;
23+
Active = true;
24+
}
25+
void ResetTimer() {
26+
Time = -1;
27+
Active = false;
28+
}
29+
private:
30+
double Duration;
31+
double Time;
32+
bool Active;
33+
};
34+
}
35+
#endif //RHYTHMTIMER_H

Encore/src/gameplay/enctime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void SongTime::BeatmapFromMidiTrack(
1919
// << events[i].getTempoBPM() << std::endl;
2020
} else if (track[i].isMeta() && track[i][1] == 0x58) {
2121
int numer = (int)track[i][3];
22-
int denom = pow(2, (int)track[i][4]);
22+
int denom = pow(2, track[i][4]);
2323
TimeSigChanges.emplace_back(
2424
midiFile.getTimeInSeconds(0, i), numer, denom, track[i].tick
2525
);

Encore/src/gameplay/inputCallbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <cstring>
1111

1212
void keyCallback(GLFWwindow *wind, int key, int scancode, int action, int mods) {
13-
Encore::EncoreLog(LOG_DEBUG, TextFormat("Keyboard key %01i inputted on menu %s", key, ToString(TheMenuManager.currentScreen)) );
13+
// Encore::EncoreLog(LOG_DEBUG, TextFormat("Keyboard key %01i inputted on menu %s", key, ToString(TheMenuManager.currentScreen)) );
1414
switch (TheMenuManager.currentScreen) { // NOTE: when adding a new Menu
1515
// derivative, you
1616
// must put its enum value in Screens, and its

Encore/src/menus/GameplayMenu.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void GameplayMenu::Draw() {
451451
ClearBackground(BLACK);
452452
unsigned char BackgroundColor = 0;
453453
// if (ThePlayerManager.BandStats->PlayersInOverdrive > 0) {
454-
BackgroundColor = BeatToCharViaTickThing(TheSongTime.GetCurrentTick(), 0, 8, 960);
454+
// BackgroundColor = BeatToCharViaTickThing(TheSongTime.GetCurrentTick(), 0, 8, 960);
455455
//}
456456
if (!songPlaying) {
457457
TheSongTime.Reset();
@@ -505,6 +505,26 @@ void GameplayMenu::Draw() {
505505
assets.sdfShader,
506506
0
507507
);
508+
std::string FASState = player.engine->Timers["FAS"].CanBeUsedUp(curTime) ? "FAS Active" : "";
509+
GameMenu::mhDrawText(
510+
assets.rubik,
511+
FASState,
512+
{ MiddleOfScreen + (NoteXWidth * 5.0f), float(FakeStrikeline)},
513+
u.hinpct(0.05),
514+
GREEN,
515+
assets.sdfShader,
516+
0
517+
);
518+
std::string SAHState = player.engine->Timers["SAH"].CanBeUsedUp(curTime) ? "SAH Active" : "";
519+
GameMenu::mhDrawText(
520+
assets.rubik,
521+
SAHState,
522+
{ MiddleOfScreen + (NoteXWidth * 5.0f), float(FakeStrikeline) + u.hinpct(0.5)},
523+
u.hinpct(0.05),
524+
GREEN,
525+
assets.sdfShader,
526+
0
527+
);
508528

509529
/* 0 is the top of the screen, and is earlier/negative in time
510530
*

0 commit comments

Comments
 (0)