Merge branch 'main' into particles-first

This commit is contained in:
MihailRis
2024-11-04 20:16:49 +03:00
9 changed files with 57 additions and 12 deletions
+4
View File
@@ -70,6 +70,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie -lstdc++fs") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie -lstdc++fs")
endif() endif()
if (WIN32)
target_link_libraries(${PROJECT_NAME} VoxelEngineSrc winmm)
endif()
target_link_libraries(${PROJECT_NAME} VoxelEngineSrc ${CMAKE_DL_LIBS}) target_link_libraries(${PROJECT_NAME} VoxelEngineSrc ${CMAKE_DL_LIBS})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
@@ -60,4 +60,5 @@ function on_open()
create_checkbox("camera.shaking", "Camera Shaking") create_checkbox("camera.shaking", "Camera Shaking")
create_checkbox("camera.inertia", "Camera Inertia") create_checkbox("camera.inertia", "Camera Inertia")
create_checkbox("camera.fov-effects", "Camera FOV Effects") create_checkbox("camera.fov-effects", "Camera FOV Effects")
create_checkbox("display.limit-fps-iconified", "Limit Background FPS")
end end
+1
View File
@@ -76,6 +76,7 @@ settings.Regular Sounds=Обычные Звуки
settings.UI Sounds=Звуки Интерфейса settings.UI Sounds=Звуки Интерфейса
settings.V-Sync=Вертикальная Синхронизация settings.V-Sync=Вертикальная Синхронизация
settings.Key=Кнопка settings.Key=Кнопка
settings.Limit Background FPS=Ограничить фоновую частоту кадров
# Управление # Управление
chunks.reload=Перезагрузить Чанки chunks.reload=Перезагрузить Чанки
+5 -2
View File
@@ -185,8 +185,11 @@ void Engine::mainloop() {
if (!Window::isIconified()) { if (!Window::isIconified()) {
renderFrame(batch); renderFrame(batch);
} }
Window::setFramerate(Window::isIconified() ? 20 : Window::setFramerate(
settings.display.framerate.get()); Window::isIconified() && settings.display.limitFpsIconified.get()
? 20
: settings.display.framerate.get()
);
processPostRunnables(); processPostRunnables();
+1
View File
@@ -51,6 +51,7 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) {
builder.add("samples", &settings.display.samples); builder.add("samples", &settings.display.samples);
builder.add("framerate", &settings.display.framerate); builder.add("framerate", &settings.display.framerate);
builder.add("fullscreen", &settings.display.fullscreen); builder.add("fullscreen", &settings.display.fullscreen);
builder.add("limit-fps-iconified", &settings.display.limitFpsIconified);
builder.section("camera"); builder.section("camera");
builder.add("sensitivity", &settings.camera.sensitivity); builder.add("sensitivity", &settings.camera.sensitivity);
+2
View File
@@ -29,6 +29,8 @@ struct DisplaySettings {
IntegerSetting samples {0}; IntegerSetting samples {0};
/// @brief Framerate limit /// @brief Framerate limit
IntegerSetting framerate {-1, -1, 120}; IntegerSetting framerate {-1, -1, 120};
/// @brief Limit framerate when window is iconified
FlagSetting limitFpsIconified {false};
}; };
struct ChunksSettings { struct ChunksSettings {
+30 -4
View File
@@ -5,9 +5,10 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <thread>
#include "typedefs.hpp"
#include "stringutil.hpp" #include "stringutil.hpp"
#include "typedefs.hpp"
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
@@ -34,6 +35,27 @@ std::string platform::detect_locale() {
.replace(2, 1, "_") .replace(2, 1, "_")
.substr(0, 5); .substr(0, 5);
} }
void platform::sleep(size_t millis) {
// Uses implementation from the SFML library
// https://github.com/SFML/SFML/blob/master/src/SFML/System/Win32/SleepImpl.cpp
// Get the minimum supported timer resolution on this system
static const UINT periodMin = []{
TIMECAPS tc;
timeGetDevCaps(&tc, sizeof(TIMECAPS));
return tc.wPeriodMin;
}();
// Set the timer resolution to the minimum for the Sleep call
timeBeginPeriod(periodMin);
// Wait...
Sleep(static_cast<DWORD>(millis));
// Reset the timer resolution back to the system default
timeEndPeriod(periodMin);
}
#else #else
void platform::configure_encoding() { void platform::configure_encoding() {
@@ -47,6 +69,10 @@ std::string platform::detect_locale() {
return preferredLocaleName.substr(0, 5); return preferredLocaleName.substr(0, 5);
} }
void platform::sleep(size_t millis) {
std::this_thread::sleep_for(std::chrono::milliseconds(millis));
}
#endif #endif
void platform::open_folder(const std::filesystem::path& folder) { void platform::open_folder(const std::filesystem::path& folder) {
@@ -54,11 +80,11 @@ void platform::open_folder(const std::filesystem::path& folder) {
return; return;
} }
#ifdef __APPLE__ #ifdef __APPLE__
auto cmd = "open "+util::quote(folder.u8string()); auto cmd = "open " + util::quote(folder.u8string());
#elif defined(_WIN32) #elif defined(_WIN32)
auto cmd = "start explorer "+util::quote(folder.u8string()); auto cmd = "start explorer " + util::quote(folder.u8string());
#else #else
auto cmd = "xdg-open "+util::quote(folder.u8string()); auto cmd = "xdg-open " + util::quote(folder.u8string());
#endif #endif
system(cmd.c_str()); system(cmd.c_str());
} }
+2
View File
@@ -10,4 +10,6 @@ namespace platform {
/// @brief Open folder using system file manager asynchronously /// @brief Open folder using system file manager asynchronously
/// @param folder target folder /// @param folder target folder
void open_folder(const std::filesystem::path& folder); void open_folder(const std::filesystem::path& folder);
/// Makes the current thread sleep for the specified amount of milliseconds.
void sleep(size_t millis);
} }
+10 -5
View File
@@ -14,6 +14,8 @@
#include "util/ObjectsKeeper.hpp" #include "util/ObjectsKeeper.hpp"
#include "Events.hpp" #include "Events.hpp"
#include "util/platform.hpp"
static debug::Logger logger("window"); static debug::Logger logger("window");
GLFWwindow* Window::window = nullptr; GLFWwindow* Window::window = nullptr;
@@ -357,11 +359,14 @@ bool Window::isFullscreen() {
void Window::swapBuffers() { void Window::swapBuffers() {
glfwSwapBuffers(window); glfwSwapBuffers(window);
Window::resetScissor(); Window::resetScissor();
double currentTime = time(); if (framerate > 0) {
if (framerate > 0 && currentTime - prevSwap < (1.0 / framerate)) { auto elapsedTime = time() - prevSwap;
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>( auto frameTime = 1.0 / framerate;
(1.0 / framerate - (currentTime - prevSwap)) * 1000 if (elapsedTime < frameTime) {
))); platform::sleep(
static_cast<size_t>((frameTime - elapsedTime) * 1000)
);
}
} }
prevSwap = time(); prevSwap = time();
} }