forked from nba-emu/NanoBoyAdvance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
700 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2021 fleroviux | ||
* | ||
* Licensed under GPLv3 or any later version. | ||
* Refer to the included LICENSE file. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <functional> | ||
#include <thread> | ||
|
||
namespace nba { | ||
|
||
struct FrameLimiter { | ||
FrameLimiter(float fps = 60.0) { | ||
Reset(fps); | ||
} | ||
|
||
void Reset(); | ||
void Reset(float fps); | ||
void SetFastForward(bool value); | ||
|
||
void Run( | ||
std::function<void(void)> frame_advance, | ||
std::function<void(float)> update_fps | ||
); | ||
|
||
private: | ||
static constexpr int kMillisecondsPerSecond = 1000; | ||
static constexpr int kMicrosecondsPerSecond = 1000000; | ||
|
||
int frame_count = 0; | ||
int frame_duration; | ||
float frames_per_second; | ||
bool fast_forward = false; | ||
|
||
std::chrono::time_point<std::chrono::steady_clock> timestamp_target; | ||
std::chrono::time_point<std::chrono::steady_clock> timestamp_fps_update; | ||
}; | ||
|
||
} // namespace nba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2021 fleroviux | ||
* | ||
* Licensed under GPLv3 or any later version. | ||
* Refer to the included LICENSE file. | ||
*/ | ||
|
||
#include <platform/frame_limiter.hpp> | ||
|
||
namespace nba { | ||
|
||
void FrameLimiter::Reset() { | ||
Reset(frames_per_second); | ||
} | ||
|
||
void FrameLimiter::Reset(float fps) { | ||
frame_count = 0; | ||
frame_duration = int(kMicrosecondsPerSecond / fps); | ||
frames_per_second = fps; | ||
fast_forward = false; | ||
timestamp_target = std::chrono::steady_clock::now(); | ||
timestamp_fps_update = std::chrono::steady_clock::now(); | ||
} | ||
|
||
void FrameLimiter::SetFastForward(bool value) { | ||
if (fast_forward != value) { | ||
fast_forward = value; | ||
if (!fast_forward) { | ||
timestamp_target = std::chrono::steady_clock::now(); | ||
} | ||
} | ||
} | ||
|
||
void FrameLimiter::Run( | ||
std::function<void(void)> frame_advance, | ||
std::function<void(float)> update_fps | ||
) { | ||
timestamp_target += std::chrono::microseconds(frame_duration); | ||
|
||
frame_advance(); | ||
frame_count++; | ||
|
||
auto now = std::chrono::steady_clock::now(); | ||
auto fps_update_delta = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
now - timestamp_fps_update).count(); | ||
|
||
if (fps_update_delta >= kMillisecondsPerSecond) { | ||
update_fps(frame_count * float(kMillisecondsPerSecond) / fps_update_delta); | ||
frame_count = 0; | ||
timestamp_fps_update = std::chrono::steady_clock::now(); | ||
} | ||
|
||
if (!fast_forward) { | ||
std::this_thread::sleep_until(timestamp_target); | ||
} | ||
} | ||
|
||
} // namespace nba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
project(NanoBoyAdvance-Qt CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeModules) | ||
|
||
set(SOURCES | ||
main.cpp | ||
screen.cpp | ||
main_window.cpp | ||
) | ||
|
||
set(HEADERS | ||
screen.hpp | ||
main_window.hpp | ||
) | ||
|
||
# CHECKME: dunno, is this required? | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
# CHECKME: possibly we can get rid of all OpenGL dependencies here. | ||
find_package(OpenGL REQUIRED) | ||
find_package(Qt5Gui REQUIRED) | ||
find_package(Qt5Widgets REQUIRED) | ||
find_package(Qt5OpenGL REQUIRED) | ||
set(QT_DEPS Qt5::Gui Qt5::Widgets Qt5::OpenGL) | ||
|
||
include(FindSDL2 REQUIRED) | ||
find_package(SDL2 REQUIRED) | ||
include_directories(${SDL2_INCLUDE_DIR}) | ||
|
||
add_executable(NanoBoyAdvance-Qt ${SOURCES} ${HEADERS}) | ||
target_link_libraries(NanoBoyAdvance-Qt platform-core ${QT_DEPS} ${OPENGL_gl_LIBRARY} ${SDL2_LIBRARY}) | ||
set_target_properties(NanoBoyAdvance-Qt PROPERTIES OUTPUT_NAME "NanoBoyAdvance") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2021 fleroviux | ||
* | ||
* Licensed under GPLv3 or any later version. | ||
* Refer to the included LICENSE file. | ||
*/ | ||
|
||
#include <QApplication> | ||
|
||
#include "main_window.hpp" | ||
|
||
int main(int argc, char** argv) { | ||
QApplication app{ argc, argv }; | ||
MainWindow window{ &app }; | ||
|
||
QCoreApplication::setOrganizationName("fleroviux"); | ||
QCoreApplication::setApplicationName("NanoboyAdvance"); | ||
|
||
window.show(); | ||
return app.exec(); | ||
} |
Oops, something went wrong.