diff --git a/CMakeLists.txt b/CMakeLists.txt index 2de17ea..7078029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,20 @@ cmake_minimum_required(VERSION 3.25) project(FastNuclearSim VERSION 1.0) set(CMAKE_CXX_STANDARD 26) -set(CMAKE_CXX_FLAGS "-g -O3 -I/usr/include/freetype2") + +if(WIN32) + set(CMAKE_CXX_FLAGS "-g -O3") +else() + set(CMAKE_CXX_FLAGS "-g -O3 -I/usr/include/freetype2") +endif() file(GLOB_RECURSE SOURCES src/*.cpp) add_executable(FastNuclearSim ${SOURCES}) -target_link_libraries(FastNuclearSim PUBLIC stdc++ m GLEW glfw GL freetype assimp jsoncpp) + +if(WIN32) + target_link_libraries(FastNuclearSim PUBLIC stdc++ m brotlidec assimp-5 glew32 opengl32 glfw3 freetype jsoncpp zlibstatic) +else() + target_link_libraries(FastNuclearSim PUBLIC stdc++ m GLEW glfw GL freetype assimp jsoncpp) +endif() diff --git a/src/coolant/evaporator.cpp b/src/coolant/evaporator.cpp index 1db4307..45f0008 100644 --- a/src/coolant/evaporator.cpp +++ b/src/coolant/evaporator.cpp @@ -42,14 +42,14 @@ void evaporator::update(double dt) double P = 10000; // Pa double K = conversions::temperature::c_to_k(heat); // K - double R = sim::constants::R; // J/K/mol + double R = util::constants::R; // J/K/mol - double n_g = air / constants::M_air; // mol - double V_g = (volume - level) * 0.001; // m^3 + double n_g = air / util::constants::M_air; // mol + double V_g = (volume - level) * 0.001; // m^3 double n = (P * V_g) / (R * K); // mol - air = n * constants::M_air; + air = n * util::constants::M_air; update_base(dt); } diff --git a/src/coolant/fluid_holder.cpp b/src/coolant/fluid_holder.cpp index b33f609..1a06809 100644 --- a/src/coolant/fluid_holder.cpp +++ b/src/coolant/fluid_holder.cpp @@ -98,19 +98,19 @@ double fluid_holder::calc_pressure(double heat, double volume, double mol) { double V = volume * 0.001; - return V == 0 ? 0 : (mol * heat * constants::R) / V; + return V == 0 ? 0 : (mol * heat * util::constants::R) / V; } double fluid_holder::calc_pressure_mol(double heat, double volume, double pressure) { double V = volume * 0.001; - return (pressure * V) / (constants::R * heat); + return (pressure * V) / (util::constants::R * heat); } double fluid_holder::get_pressure() const { - return calc_pressure(conversions::temperature::c_to_k(heat), get_gas_volume(), fluid.g_to_mol(steam) + air / constants::M_air); + return calc_pressure(conversions::temperature::c_to_k(heat), get_gas_volume(), fluid.g_to_mol(steam) + air / util::constants::M_air); } double fluid_holder::get_gas_density() const @@ -143,10 +143,10 @@ void fluid_holder::update_base(double secs) { double K = conversions::temperature::c_to_k(heat); // K double P = fluid.vapor_pressure.calc_p(K); // Pa - double R = sim::constants::R; // J/K/mol + double R = util::constants::R; // J/K/mol - double J_m = fluid.jPg * fluid.gPmol; // J/mol - double n_g = fluid.g_to_mol(steam) + air / constants::M_air; // mol + double J_m = fluid.jPg * fluid.gPmol; // J/mol + double n_g = fluid.g_to_mol(steam) + air / util::constants::M_air; // mol double V_g = (volume - level) * 0.001; // m^3 double n = (P * V_g) / (R * K) - n_g; // mol diff --git a/src/coolant/valve.cpp b/src/coolant/valve.cpp index 3ad2fdf..53a2d1b 100644 --- a/src/coolant/valve.cpp +++ b/src/coolant/valve.cpp @@ -54,7 +54,7 @@ void valve::update(double dt) mol = fluid_holder::calc_pressure_mol(src->get_heat_k(), src->get_gas_volume(), pressure1 - remove); - mass_a = src->get_air() - mol / constants::M_air; + mass_a = src->get_air() - mol / util::constants::M_air; mass_s = src->get_steam() - src->fluid.mol_to_g(mol); } @@ -65,7 +65,7 @@ void valve::update(double dt) mol = fluid_holder::calc_pressure_mol(dst->get_heat_k(), dst->get_gas_volume(), pressure2 - remove); - mass_a = dst->get_air() - mol / constants::M_air; + mass_a = dst->get_air() - mol / util::constants::M_air; mass_s = dst->get_steam() - dst->fluid.mol_to_g(mol); } diff --git a/src/main.cpp b/src/main.cpp index 26feabd..9f4cb13 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,4 @@ -#include - #include #include #include @@ -18,33 +16,29 @@ #include "graphics/window.hpp" #include "graphics/camera.hpp" +#include "util/time.hpp" #include "system.hpp" #include "tests.hpp" using namespace sim; -unsigned long get_now() -{ - struct timeval tv; - gettimeofday(&tv, nullptr); - return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec; -} - int main() { +#ifndef _WIN32 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +#endif // tests::run(); // return 0; graphics::window::create(); - long clock = get_now(); + long clock = util::time::get_now(); double at = 0; while(!graphics::window::should_close()) { - long now = get_now(); + long now = util::time::get_now(); long passed = now - clock; double dt = (double)passed / 1e6; clock += passed; diff --git a/src/reactor/reactor.cpp b/src/reactor/reactor.cpp index 4c711b7..a64af7b 100644 --- a/src/reactor/reactor.cpp +++ b/src/reactor/reactor.cpp @@ -149,7 +149,7 @@ void reactor::toggle_selected() void reactor::update_tile(double secs, int i, int x, int y) { int nb_lookup[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; - std::shuffle(nb_lookup, &nb_lookup[3], sim::random::gen); + std::shuffle(nb_lookup, &nb_lookup[3], util::random::gen); for(int j = 0; j < 4; j++) { @@ -165,7 +165,7 @@ void reactor::update_tile(double secs, int i, int x, int y) void reactor::update_interactions(int* rods_lookup, double secs) { - std::shuffle(rods_lookup, &rods_lookup[size - 1], sim::random::gen); + std::shuffle(rods_lookup, &rods_lookup[size - 1], util::random::gen); for(int id = 0; id < size; id++) { diff --git a/src/util/constants.hpp b/src/util/constants.hpp index 975c669..ed868bb 100644 --- a/src/util/constants.hpp +++ b/src/util/constants.hpp @@ -1,7 +1,7 @@ #pragma once -namespace sim::constants +namespace sim::util::constants { constexpr double R = 8.31446261815324; // molar gas constant, J/mol/K constexpr double R_air = 0.2870500676; // specific gas constant of dry air, J/g/K diff --git a/src/util/random.cpp b/src/util/random.cpp index f57f5e3..2f7ed98 100644 --- a/src/util/random.cpp +++ b/src/util/random.cpp @@ -1,7 +1,7 @@ #include "random.hpp" -using namespace sim; +using namespace sim::util; std::mt19937 random::gen; diff --git a/src/util/random.hpp b/src/util/random.hpp index 0b97b0a..caf1bc3 100644 --- a/src/util/random.hpp +++ b/src/util/random.hpp @@ -3,7 +3,7 @@ #include -namespace sim::random +namespace sim::util::random { extern std::mt19937 gen; diff --git a/src/util/time.cpp b/src/util/time.cpp new file mode 100644 index 0000000..6de245d --- /dev/null +++ b/src/util/time.cpp @@ -0,0 +1,38 @@ + +#ifdef _WIN32 +#include +#else +#include +#include +#endif + +#include "time.hpp" + +using namespace sim::util; + + +unsigned long time::get_now() +{ +#ifdef _WIN32 + FILETIME ft; + ULARGE_INTEGER ul; + GetSystemTimeAsFileTime(&ft); + ul.LowPart = ft.dwLowDateTime; + ul.HighPart = ft.dwHighDateTime; + return (unsigned long)(ul.QuadPart / 10 - 11644473600000000ULL); +#else + struct timeval tv; + gettimeofday(&tv, nullptr); + return (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec; +#endif +} + +void time::sleep(unsigned long usec) +{ +#ifdef _WIN32 + Sleep(usec / 1000); +#else + usleep(usec); +#endif +} + diff --git a/src/util/time.hpp b/src/util/time.hpp new file mode 100644 index 0000000..601f89d --- /dev/null +++ b/src/util/time.hpp @@ -0,0 +1,11 @@ + +#pragma once + +namespace sim::util::time +{ + +unsigned long get_now(); +void sleep(unsigned long usec); + +}; +