got things compiling with mingw

This commit is contained in:
Jay Robson 2024-02-14 15:28:43 +11:00
parent 72e9047881
commit 18e05450b4
11 changed files with 83 additions and 30 deletions

View File

@ -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()

View File

@ -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 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);
}

View File

@ -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 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

View File

@ -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);
}

View File

@ -1,6 +1,4 @@
#include <sys/time.h>
#include <random>
#include <sstream>
#include <fstream>
@ -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;

View File

@ -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++)
{

View File

@ -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

View File

@ -1,7 +1,7 @@
#include "random.hpp"
using namespace sim;
using namespace sim::util;
std::mt19937 random::gen;

View File

@ -3,7 +3,7 @@
#include <random>
namespace sim::random
namespace sim::util::random
{
extern std::mt19937 gen;

38
src/util/time.cpp Normal file
View File

@ -0,0 +1,38 @@
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <unistd.h>
#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
}

11
src/util/time.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
namespace sim::util::time
{
unsigned long get_now();
void sleep(unsigned long usec);
};