Skip to content

Commit

Permalink
Merge pull request #29 from Im-Rises/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Im-Rises committed May 30, 2023
2 parents 9313f14 + bc12b15 commit 8808693
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 47 deletions.
62 changes: 18 additions & 44 deletions ParticleSimulator/ParticleSimulatorLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "InputManager.h"

#ifdef _WIN32
#include <Windows.h>
#endif

#include <imgui/imgui.h>
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_impl_opengl3.h>
Expand Down Expand Up @@ -165,51 +169,14 @@ ParticleSimulatorLauncher::~ParticleSimulatorLauncher() {
glfwTerminate();
}

// void ParticleSimulatorLauncher::start() {
// // Create the scene
// scene = std::make_unique<Scene>(displayWidth, displayHeight);
//
// // Variables for the main loop
// float deltaTime = NAN;
// float accumulator = 0.0F;
//
// #ifdef __EMSCRIPTEN__
// // For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
// // You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
// ImGuiIO& io = ImGui::GetIO();
// (void)io;
// io.IniFilename = nullptr;
// EMSCRIPTEN_MAINLOOP_BEGIN
// #else
// while (glfwWindowShouldClose(window) == 0)
// #endif
// {
// deltaTime = ImGui::GetIO().DeltaTime;
//
// handleInputs();
//
// handleUi(deltaTime);
//
// updateGame(deltaTime);
//
// while (accumulator >= fixedDeltaTime)
// {
// fixedUpdateGame(fixedDeltaTime);
// accumulator -= fixedDeltaTime;
// }
// accumulator += deltaTime;
//
// updateScreen();
// }
// #ifdef __EMSCRIPTEN__
// EMSCRIPTEN_MAINLOOP_END;
// #endif
// }

void ParticleSimulatorLauncher::start() {
// Create the scene
scene = std::make_unique<Scene>(displayWidth, displayHeight);

#ifdef _WIN32
timeBeginPeriod(1);
#endif

// Variables for the main loop
std::chrono::high_resolution_clock::time_point previousTime = std::chrono::high_resolution_clock::now();
float deltaTime = 0.0F;
Expand All @@ -229,6 +196,8 @@ void ParticleSimulatorLauncher::start() {

deltaTime = std::chrono::duration<float>(currentTime - previousTime).count();

auto startMs = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now());

handleInputs();

handleUi(deltaTime);
Expand All @@ -237,17 +206,22 @@ void ParticleSimulatorLauncher::start() {

updateScreen();

float const delay = fixedDeltaTime - deltaTime;
if (delay > 0.0F)
auto endMs = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now());
auto delayMs = fixedDeltaTime - std::chrono::duration_cast<std::chrono::duration<float>>(endMs - startMs).count();
if (delayMs > 0.0F)
{
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(delay * 1000.0F)));
std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<int>(delayMs * 1000.0F)));
}

previousTime = currentTime;
}
#ifdef __EMSCRIPTEN__
EMSCRIPTEN_MAINLOOP_END;
#endif

#ifdef _WIN32
timeEndPeriod(1);
#endif
}

void ParticleSimulatorLauncher::handleInputs() {
Expand Down
6 changes: 3 additions & 3 deletions ParticleSimulator/ParticleSimulatorLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ struct GLFWwindow;

class ParticleSimulatorLauncher {
public:
static constexpr std::string_view PROJECT_NAME = "Particle Simulator 3D";
static constexpr std::string_view PROJECT_VERSION = "2.1.1";
static constexpr std::string_view PROJECT_LINK = "https://github.com/Im-Rises/ParticleSimulator";
static constexpr std::string_view PROJECT_NAME = "Particle Simulator 3D (WebGL)";
static constexpr std::string_view PROJECT_VERSION = "2.2.0";
static constexpr std::string_view PROJECT_LINK = "https://github.com/Im-Rises/particle-simulator-webgl";
static constexpr std::string_view PROJECT_AUTHOR = "Im-Rises (Quentin Morel)";

private:
Expand Down

0 comments on commit 8808693

Please sign in to comment.