Skip to content

Commit

Permalink
display-swap-interval setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 8, 2023
1 parent b0ccc5f commit d5dc134
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/voxel_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct EngineSettings {
int displayHeight;
/* Anti-aliasing samples */
int displaySamples;
/* GLFW swap interval value, 0 - unlimited fps, 1 - vsync*/
int displaySwapInterval;
/* Window title */
const char* displayTitle;
/* Max milliseconds that engine uses for chunks loading only */
Expand All @@ -68,8 +70,8 @@ class Engine {
EngineSettings settings;

uint64_t frame = 0;
float lastTime = 0.0f;
float delta = 0.0f;
double lastTime = 0.0;
double delta = 0.0;
bool occlusion = true;
public:
Engine(const EngineSettings& settings);
Expand All @@ -87,6 +89,7 @@ Engine::Engine(const EngineSettings& settings) {
settings.displayHeight,
settings.displayTitle,
settings.displaySamples);
Window::swapInterval(settings.displaySwapInterval);

assets = new Assets();
std::cout << "-- loading assets" << std::endl;
Expand Down Expand Up @@ -114,7 +117,7 @@ Engine::Engine(const EngineSettings& settings) {

void Engine::updateTimers() {
frame++;
float currentTime = Window::time();
double currentTime = Window::time();
delta = currentTime - lastTime;
lastTime = currentTime;
}
Expand Down Expand Up @@ -146,7 +149,6 @@ void Engine::mainloop() {
HudRenderer hud(assets);
lastTime = Window::time();

Window::swapInterval(1);
while (!Window::isShouldClose()){
updateTimers();
updateHotkeys();
Expand Down Expand Up @@ -187,6 +189,7 @@ void load_settings(EngineSettings& settings, std::string filename) {
obj->num("display-width", settings.displayWidth);
obj->num("display-height", settings.displayHeight);
obj->num("display-samples", settings.displaySamples);
obj->num("display-swap-interval", settings.displaySwapInterval);
obj->num("chunks-load-distance", settings.chunksLoadDistance);
obj->num("chunks-load-speed", settings.chunksLoadSpeed);
obj->num("chunks-padding", settings.chunksPadding);
Expand All @@ -197,6 +200,7 @@ void save_settings(EngineSettings& settings, std::string filename) {
obj.put("display-width", settings.displayWidth);
obj.put("display-height", settings.displayHeight);
obj.put("display-samples", settings.displaySamples);
obj.put("display-swap-interval", settings.displaySwapInterval);
obj.put("chunks-load-distance", settings.chunksLoadDistance);
obj.put("chunks-load-speed", settings.chunksLoadSpeed);
obj.put("chunks-padding", settings.chunksPadding);
Expand All @@ -214,6 +218,7 @@ int main() {
settings.chunksLoadSpeed = 10;
settings.chunksLoadDistance = 12;
settings.chunksPadding = 2;
settings.displaySwapInterval = 1;

if (std::filesystem::is_regular_file(SETTINGS_FILE)) {
std::cout << "-- loading settings" << std::endl;
Expand Down

0 comments on commit d5dc134

Please sign in to comment.