Skip to content

Commit d5b3e81

Browse files
authored
Merge pull request #63 from uvcat7/framerate-diagnostics
Framerate diagnostics QOL and bugfixes
2 parents c455277 + b9a6cbe commit d5b3e81

File tree

10 files changed

+158
-65
lines changed

10 files changed

+158
-65
lines changed

src/Core/Core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include <chrono>
45

56
namespace Vortex {
67

@@ -51,7 +52,7 @@ struct TimingData;
5152
typedef const String& StringRef;
5253
typedef uint64_t TextureHandle;
5354

54-
extern float deltaTime;
55+
extern std::chrono::duration<double> deltaTime;
5556

5657
extern void HudNote(const char* fmt, ...);
5758
extern void HudInfo(const char* fmt, ...);

src/Core/TextDraw.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ void Text::draw(vec2i textPos)
321321
}
322322
batch.flush();
323323
}
324-
325-
VortexCheckGlError();
326324
}
327325

328326
};

src/Editor/Editing.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ void onKeyRelease(KeyRelease& evt) override
271271
noteKeysHeld--;
272272
if (noteKeysHeld < 0) noteKeysHeld = 0;
273273
finishNotePlacement(col);
274-
// Don't advance when we're stepping jumps
275-
if (hasJumpToNextNote() && noteKeysHeld == 0 && gView->getSnapType() != ST_NONE)
274+
// Don't advance when we're stepping jumps or when music is playing
275+
if (hasJumpToNextNote() && gMusic->isPaused()
276+
&& noteKeysHeld == 0 && gView->getSnapType() != ST_NONE)
276277
{
277278
gView->setCursorRow(gView->snapRow(gView->getCursorRow(), gView->hasReverseScroll() ? View::SNAP_UP : View::SNAP_DOWN));
278279
}

src/Editor/Editor.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -888,46 +888,46 @@ void tick()
888888
notifyChanges();
889889

890890
vec2i windowSize = gSystem->getWindowSize();
891-
recti r = {0, 0, windowSize.x, windowSize.y};
891+
recti r = { 0, 0, windowSize.x, windowSize.y };
892892

893893
gTextOverlay->handleInputs(events);
894894

895895
GuiMain::setViewSize(r.w, r.h);
896-
GuiMain::frameStart(deltaTime, events);
896+
GuiMain::frameStart(deltaTime.count(), events);
897897

898898
vec2i view = gSystem->getWindowSize();
899899

900900
handleDialogs();
901901

902-
myGui->tick({0, 0, view.x, view.y}, deltaTime, events);
903-
904-
if(!GuiMain::isCapturingText())
902+
myGui->tick({ 0, 0, view.x, view.y }, deltaTime.count(), events);
903+
904+
if (!GuiMain::isCapturingText())
905905
{
906-
for(KeyPress* press = nullptr; events.next(press);)
906+
for (KeyPress* press = nullptr; events.next(press);)
907907
{
908908
Action::Type action = gShortcuts->getAction(press->keyflags, press->key);
909-
if(action)
909+
if (action)
910910
{
911911
Action::perform(action);
912912
press->handled = true;
913913
}
914914
}
915915
}
916916

917-
if(!GuiMain::isCapturingMouse())
917+
if (!GuiMain::isCapturingMouse())
918918
{
919-
for(MouseScroll* scroll = nullptr; events.next(scroll);)
919+
for (MouseScroll* scroll = nullptr; events.next(scroll);)
920920
{
921921
Action::Type action = gShortcuts->getAction(scroll->keyflags, scroll->up);
922-
if(action)
922+
if (action)
923923
{
924924
Action::perform(action);
925925
scroll->handled = true;
926926
}
927927
}
928928
}
929929

930-
if(GuiMain::isCapturingMouse())
930+
if (GuiMain::isCapturingMouse())
931931
{
932932
gSystem->setCursor(GuiMain::getCursorIcon());
933933
}
@@ -937,14 +937,14 @@ void tick()
937937
gMinimap->handleInputs(events);
938938
gEditing->handleInputs(events);
939939

940-
if(gSimfile->isOpen())
940+
if (gSimfile->isOpen())
941941
{
942942
gView->tick();
943943
}
944944

945945
gSelection->handleInputs(events);
946946

947-
if(gSimfile->isOpen())
947+
if (gSimfile->isOpen())
948948
{
949949
gMusic->tick();
950950
gMinimap->tick();
@@ -954,8 +954,8 @@ void tick()
954954

955955
updateTitle();
956956
notifyChanges();
957-
958-
if(gSimfile->isOpen())
957+
958+
if (gSimfile->isOpen())
959959
{
960960
gNotefield->draw();
961961
gMinimap->draw();

src/Editor/Music.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <limits.h>
44
#include <stdint.h>
55
#include <math.h>
6+
#include <chrono>
67

78
#include <Core/Vector.h>
89
#include <Core/Reference.h>
@@ -19,6 +20,7 @@
1920

2021
#include <Editor/ConvertToOgg.h>
2122
#include <Editor/Editor.h>
23+
#include <Editor/View.h>
2224
#include <Editor/Common.h>
2325
#include <Editor/TextOverlay.h>
2426

@@ -48,7 +50,7 @@ struct MusicImpl : public Music, public MixSource {
4850

4951
Mixer* myMixer;
5052
Sound mySamples;
51-
double myPlayTimer;
53+
std::chrono::steady_clock::time_point myPlayTimer;
5254
TickData myBeatTick, myNoteTick;
5355
String myTitle, myArtist;
5456
int myMusicSpeed;
@@ -673,7 +675,7 @@ void onChanges(int changes)
673675
| VCM_TEMPO_CHANGED
674676
| VCM_END_ROW_CHANGED;
675677

676-
if(changes & bits)
678+
if((changes & bits) && !gMusic->isPaused() && gView->hasChartPreview())
677679
{
678680
interruptStream();
679681
if(changes & (VCM_TEMPO_CHANGED | VCM_NOTES_CHANGED))

src/Editor/Sound.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <stdint.h>
1212
#include <limits.h>
13+
#include <chrono>
1314

1415
namespace Vortex {
1516

@@ -93,7 +94,7 @@ class Sound::Thread : public BackgroundThread
9394
int myCurrentFrame;
9495
int myReservedFrames;
9596
uchar myProgress;
96-
double myStartTime;
97+
std::chrono::steady_clock::time_point myStartTime;
9798
};
9899

99100
Sound::Thread::~Thread()

src/Editor/TextOverlay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void tickHud()
432432
{
433433
fade += 0.5f;
434434
}
435-
float delta = clamp(deltaTime * fade, 0.0f, 1.0f);
435+
auto delta = clamp(deltaTime.count() * fade, 0.0, 1.0);
436436

437437
myHud[i].timeLeft -= delta;
438438
if(myHud[i].timeLeft <= -0.5f) myHud.erase(i);
@@ -575,7 +575,7 @@ void drawAbout()
575575
Text::arrange(Text::BC, "ArrowVortex (beta)");
576576
Text::draw(vec2i{size.x / 2, size.y / 2 - 2});
577577

578-
Text::arrange(Text::TC, "(C) Bram 'Fietsemaker' van de Wetering");
578+
Text::arrange(Text::TC, "Bram 'Fietsemaker' van de Wetering");
579579
Text::draw(vec2i{size.x / 2, size.y / 2 + 2});
580580

581581
String buildDate = "Build :: " + System::getBuildData();
@@ -584,7 +584,7 @@ void drawAbout()
584584

585585
DrawTitleText("ABOUT", "[ESC] close", nullptr);
586586

587-
auto fps = Str::fmt("%1 FPS").arg(1.0f / max(deltaTime, 0.0001f), 0, 0);
587+
auto fps = Str::fmt("%1 FPS").arg(1.0f / max(deltaTime.count(), 0.0001), 0, 0);
588588
Text::arrange(Text::TR, fps);
589589
Text::draw(vec2i{size.x - 4, 4});
590590
}

src/System/Debug.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include <io.h>
66
#include <fcntl.h>
77
#include <stdio.h>
8-
#include <time.h>
8+
//#include <time.h>
9+
#include <chrono>
910

1011
#define WIN32_LEAN_AND_MEAN
1112
#include <windows.h>
@@ -17,28 +18,17 @@ namespace Debug {
1718

1819
// ================================================================================================
1920
// Debug :: timing functions.
20-
21-
static double GetTimeFreq()
22-
{
23-
LARGE_INTEGER i;
24-
if(QueryPerformanceFrequency(&i))
25-
{
26-
return 1.0 / (double)i.QuadPart;
27-
}
28-
return 1.0;
29-
}
30-
31-
double getElapsedTime()
21+
using namespace std::chrono;
22+
steady_clock::time_point getElapsedTime()
3223
{
33-
static double sTimerFreq = GetTimeFreq();
34-
LARGE_INTEGER i;
35-
QueryPerformanceCounter(&i);
36-
return (double)i.QuadPart * sTimerFreq;
24+
return std::chrono::steady_clock::now();
3725
}
3826

39-
double getElapsedTime(double startTime)
27+
double getElapsedTime(steady_clock::time_point startTime)
4028
{
41-
return getElapsedTime() - startTime;
29+
auto currentTime = steady_clock::now();
30+
const duration<double> deltaTime = currentTime - startTime;
31+
return deltaTime.count();
4232
}
4333

4434
// ================================================================================================

src/System/Debug.h

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

33
#include <Core/Core.h>
44
#include <assert.h>
5+
#include <chrono>
56

67
#ifndef _DEBUG
78
#define VORTEX_DISABLE_ASSERTS
@@ -15,10 +16,10 @@ namespace Debug
1516
enum Type { INFO, WARNING, ERROR };
1617

1718
/// Returns a timestamp of the current time.
18-
double getElapsedTime();
19+
std::chrono::steady_clock::time_point getElapsedTime();
1920

2021
/// Returns the number of seconds elapsed since the start time.
21-
double getElapsedTime(double startTime);
22+
double getElapsedTime(std::chrono::steady_clock::time_point startTime);
2223

2324
/// Creates a blank log file.
2425
void openLogFile();

0 commit comments

Comments
 (0)