This commit is contained in:
Jay Robson 2024-02-16 18:09:00 +11:00
parent 8ca1b9affd
commit 0df855ad8c
98 changed files with 428 additions and 428 deletions

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::conversions::pressure namespace Sim::Conversions::Pressure
{ {
constexpr double torr_to_pa(double t) { return t * 133.322; } constexpr double torr_to_pa(double t) { return t * 133.322; }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::conversions::temperature namespace Sim::Conversions::Temperature
{ {
constexpr double k_to_c(double k) { return k - 273.15; } constexpr double k_to_c(double k) { return k - 273.15; }

View File

@ -4,7 +4,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace sim::coolant; using namespace Sim::Coolant;
constexpr static double calc_cylinder(double h, double d) constexpr static double calc_cylinder(double h, double d)
{ {

View File

@ -3,7 +3,7 @@
#include "fluid_holder.hpp" #include "fluid_holder.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
class Condenser : public FluidHolder class Condenser : public FluidHolder

View File

@ -4,7 +4,7 @@
#include "../util/constants.hpp" #include "../util/constants.hpp"
#include "../system.hpp" #include "../system.hpp"
using namespace sim::coolant; using namespace Sim::Coolant;
CondenserSecondary::CondenserSecondary(Condenser* primary, Evaporator* source, double volume) : CondenserSecondary::CondenserSecondary(Condenser* primary, Evaporator* source, double volume) :
primary(primary), source(source), FluidHolder(primary->fluid, volume, 0) primary(primary), source(source), FluidHolder(primary->fluid, volume, 0)

View File

@ -5,7 +5,7 @@
#include "evaporator.hpp" #include "evaporator.hpp"
#include "condenser.hpp" #include "condenser.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
class CondenserSecondary : public FluidHolder class CondenserSecondary : public FluidHolder

View File

@ -5,7 +5,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace sim::coolant; using namespace Sim::Coolant;
constexpr static double calc_cylinder(double h, double d) constexpr static double calc_cylinder(double h, double d)
{ {
@ -41,15 +41,15 @@ void Evaporator::update(double dt)
steam = 0; steam = 0;
double P = 10000; // Pa double P = 10000; // Pa
double K = conversions::temperature::c_to_k(heat); // K double K = Conversions::Temperature::c_to_k(heat); // K
double R = util::constants::R; // J/K/mol double R = Util::Constants::R; // J/K/mol
double n_g = air / util::constants::M_air; // mol double n_g = air / Util::Constants::M_air; // mol
double V_g = (volume - level) * 0.001; // m^3 double V_g = (volume - level) * 0.001; // m^3
double n = (P * V_g) / (R * K); // mol double n = (P * V_g) / (R * K); // mol
air = n * util::constants::M_air; air = n * Util::Constants::M_air;
update_base(dt); update_base(dt);
} }

View File

@ -3,7 +3,7 @@
#include "fluid_holder.hpp" #include "fluid_holder.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
class Evaporator : public FluidHolder class Evaporator : public FluidHolder

View File

@ -5,7 +5,7 @@
#include "vapor_pressure.hpp" #include "vapor_pressure.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
struct Fluid struct Fluid
@ -14,9 +14,9 @@ struct Fluid
const double gPmol; // g/mol const double gPmol; // g/mol
const double jPg; // J/g latent heat of vaporisation const double jPg; // J/g latent heat of vaporisation
const coolant::VaporPressure vapor_pressure; const Coolant::VaporPressure vapor_pressure;
constexpr Fluid(double gPl, double gPmol, double jPg, coolant::VaporPressure vapor_pressure) : constexpr Fluid(double gPl, double gPmol, double jPg, Coolant::VaporPressure vapor_pressure) :
gPl(gPl), gPmol(gPmol), jPg(jPg), gPl(gPl), gPmol(gPmol), jPg(jPg),
vapor_pressure(vapor_pressure) vapor_pressure(vapor_pressure)
{ {

View File

@ -7,7 +7,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace sim::coolant; using namespace Sim::Coolant;
FluidHolder::FluidHolder(Fluid fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass) FluidHolder::FluidHolder(Fluid fluid, double volume, double extra_mass) : fluid(fluid), volume(volume), extra_mass(extra_mass)
{ {
@ -98,19 +98,19 @@ double FluidHolder::calc_pressure(double heat, double volume, double mol)
{ {
double V = volume * 0.001; double V = volume * 0.001;
return V == 0 ? 0 : (mol * heat * util::constants::R) / V; return V == 0 ? 0 : (mol * heat * Util::Constants::R) / V;
} }
double FluidHolder::calc_pressure_mol(double heat, double volume, double pressure) double FluidHolder::calc_pressure_mol(double heat, double volume, double pressure)
{ {
double V = volume * 0.001; double V = volume * 0.001;
return (pressure * V) / (util::constants::R * heat); return (pressure * V) / (Util::Constants::R * heat);
} }
double FluidHolder::get_pressure() const double FluidHolder::get_pressure() const
{ {
return calc_pressure(conversions::temperature::c_to_k(heat), get_gas_volume(), fluid.g_to_mol(steam) + air / util::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 FluidHolder::get_gas_density() const double FluidHolder::get_gas_density() const
@ -141,12 +141,12 @@ void FluidHolder::update_base(double secs)
if(mass > 0) if(mass > 0)
{ {
double K = conversions::temperature::c_to_k(heat); // K double K = Conversions::Temperature::c_to_k(heat); // K
double P = fluid.vapor_pressure.calc_p(K); // Pa double P = fluid.vapor_pressure.calc_p(K); // Pa
double R = util::constants::R; // J/K/mol double R = Util::Constants::R; // J/K/mol
double J_m = fluid.jPg * fluid.gPmol; // J/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 n_g = fluid.g_to_mol(steam) + air / Util::Constants::M_air; // mol
double V_g = (volume - level) * 0.001; // m^3 double V_g = (volume - level) * 0.001; // m^3
double n = (P * V_g) / (R * K) - n_g; // mol double n = (P * V_g) / (R * K) - n_g; // mol

View File

@ -6,7 +6,7 @@
#include "fluid.hpp" #include "fluid.hpp"
#include "../conversions/temperature.hpp" #include "../conversions/temperature.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
class FluidHolder class FluidHolder
@ -36,7 +36,7 @@ public:
virtual double get_volume() const { return volume; } // litres virtual double get_volume() const { return volume; } // litres
virtual double get_level() const { return level; } // litres virtual double get_level() const { return level; } // litres
virtual double get_heat() const { return heat; } // celsius virtual double get_heat() const { return heat; } // celsius
virtual double get_heat_k() const { return conversions::temperature::c_to_k(get_heat()); } // kelvin virtual double get_heat_k() const { return Conversions::Temperature::c_to_k(get_heat()); } // kelvin
virtual double get_steam() const { return steam; } // grams virtual double get_steam() const { return steam; } // grams
virtual double get_gas() const { return steam + air; } // grams virtual double get_gas() const { return steam + air; } // grams
virtual double get_air() const { return air; } // grams virtual double get_air() const { return air; } // grams

View File

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using namespace sim::coolant; using namespace Sim::Coolant;
Pump::Pump(FluidHolder* src, FluidHolder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target) : Pump::Pump(FluidHolder* src, FluidHolder* dst, double mass, double radius, double power, double l_per_rev, double friction, mode_t mode, double target) :
src(src), src(src),
@ -71,7 +71,7 @@ void Pump::update(double dt)
break; break;
} }
velocity += util::calc_work(dt * power * max_power, mass); velocity += Util::calc_work(dt * power * max_power, mass);
} }
else else
@ -90,7 +90,7 @@ void Pump::update(double dt)
double p_diff = (p_diff_1 + p_diff_2) / 2; double p_diff = (p_diff_1 + p_diff_2) / 2;
double work = p_diff * dst_volume * 0.001 + get_rpm() / 60 * dt * friction; double work = p_diff * dst_volume * 0.001 + get_rpm() / 60 * dt * friction;
velocity = std::max(velocity - util::calc_work(work, mass), 0.0); velocity = std::max(velocity - Util::calc_work(work, mass), 0.0);
flow = dst_volume / dt; flow = dst_volume / dt;
} }

View File

@ -4,7 +4,7 @@
#include "fluid_holder.hpp" #include "fluid_holder.hpp"
#include "../util/pid.hpp" #include "../util/pid.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
class Pump class Pump
@ -12,7 +12,7 @@ class Pump
FluidHolder* const src; FluidHolder* const src;
FluidHolder* const dst; FluidHolder* const dst;
util::PID pid {1, 0, 100, 0, 0}; Util::PID pid {1, 0, 100, 0, 0};
double flow = 0; // L/s double flow = 0; // L/s
double velocity = 0; // m/s double velocity = 0; // m/s

View File

@ -1,7 +1,7 @@
#include "sink.hpp" #include "sink.hpp"
using namespace sim::coolant; using namespace Sim::Coolant;
Sink::Sink(Fluid type, double heat, double pressure, double steam_density) : Sink::Sink(Fluid type, double heat, double pressure, double steam_density) :
heat(heat), heat(heat),

View File

@ -7,7 +7,7 @@
// can kinda just do anything. for example, get rid of steam to the "outside", // can kinda just do anything. for example, get rid of steam to the "outside",
// or pump in new coolant. // or pump in new coolant.
namespace sim::coolant namespace Sim::Coolant
{ {
class Sink : public FluidHolder class Sink : public FluidHolder

View File

@ -6,7 +6,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace sim::coolant; using namespace Sim::Coolant;
Valve::Valve(FluidHolder* src, FluidHolder* dst, double state, double max) : src(src), dst(dst), max(max) Valve::Valve(FluidHolder* src, FluidHolder* dst, double state, double max) : src(src), dst(dst), max(max)
{ {
@ -84,7 +84,7 @@ void Valve::update(double dt)
mol = FluidHolder::calc_pressure_mol(src->get_heat_k(), src->get_gas_volume(), pressure1 - remove); mol = FluidHolder::calc_pressure_mol(src->get_heat_k(), src->get_gas_volume(), pressure1 - remove);
mass_a = src->get_air() - mol / util::constants::M_air; mass_a = src->get_air() - mol / Util::Constants::M_air;
mass_s = src->get_steam() - src->fluid.mol_to_g(mol); mass_s = src->get_steam() - src->fluid.mol_to_g(mol);
} }
@ -95,7 +95,7 @@ void Valve::update(double dt)
mol = FluidHolder::calc_pressure_mol(dst->get_heat_k(), dst->get_gas_volume(), pressure2 - remove); mol = FluidHolder::calc_pressure_mol(dst->get_heat_k(), dst->get_gas_volume(), pressure2 - remove);
mass_a = dst->get_air() - mol / util::constants::M_air; mass_a = dst->get_air() - mol / Util::Constants::M_air;
mass_s = dst->get_steam() - dst->fluid.mol_to_g(mol); mass_s = dst->get_steam() - dst->fluid.mol_to_g(mol);
} }

View File

@ -4,7 +4,7 @@
#include "fluid_holder.hpp" #include "fluid_holder.hpp"
#include "../util/pid.hpp" #include "../util/pid.hpp"
namespace sim::coolant namespace Sim::Coolant
{ {
class Valve class Valve
@ -21,7 +21,7 @@ class Valve
bool auto_on = false; bool auto_on = false;
double auto_th = 0; // C double auto_th = 0; // C
util::PID pid {1e-3, -1e-3, 100, 0, 0}; Util::PID pid {1e-3, -1e-3, 100, 0, 0};
public: public:

View File

@ -3,7 +3,7 @@
#include <cmath> #include <cmath>
using namespace sim::coolant; using namespace Sim::Coolant;
double VaporPressure::calc_p(double t) const double VaporPressure::calc_p(double t) const
{ {

View File

@ -3,7 +3,7 @@
#include <json/json.h> #include <json/json.h>
namespace sim::coolant namespace Sim::Coolant
{ {
struct VaporPressure struct VaporPressure

View File

@ -6,7 +6,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace sim::electric; using namespace Sim::Electric;
constexpr static double calc_cylinder(double h, double d) constexpr static double calc_cylinder(double h, double d)
{ {
@ -15,19 +15,19 @@ constexpr static double calc_cylinder(double h, double d)
return M_PI * r * r * h * 1000; return M_PI * r * r * h * 1000;
} }
Turbine::Turbine(coolant::Fluid type, coolant::Condenser* condenser, double length, double diameter, double mass) : Turbine::Turbine(Coolant::Fluid type, Coolant::Condenser* condenser, double length, double diameter, double mass) :
length(length), diameter(diameter), condenser(condenser), length(length), diameter(diameter), condenser(condenser),
sim::coolant::FluidHolder(type, calc_cylinder(length, diameter), mass) Sim::Coolant::FluidHolder(type, calc_cylinder(length, diameter), mass)
{ {
} }
Turbine::Turbine(const Json::Value& node, coolant::Condenser* condenser) : Turbine::Turbine(const Json::Value& node, Coolant::Condenser* condenser) :
condenser(condenser), condenser(condenser),
length(node["length"].asDouble()), length(node["length"].asDouble()),
diameter(node["diameter"].asDouble()), diameter(node["diameter"].asDouble()),
friction(node["friction"].asDouble()), friction(node["friction"].asDouble()),
sim::coolant::FluidHolder(node) Sim::Coolant::FluidHolder(node)
{ {
velocity = node["velocity"].asDouble(); velocity = node["velocity"].asDouble();
phase = node["phase"].asDouble(); phase = node["phase"].asDouble();
@ -37,15 +37,15 @@ Turbine::Turbine(const Json::Value& node, coolant::Condenser* condenser) :
void Turbine::update(double dt) void Turbine::update(double dt)
{ {
double work = get_rpm() / 60 * dt * friction; double work = get_rpm() / 60 * dt * friction;
phase = std::fmod(phase + util::map( get_rpm(), 0, 60, 0, 2 * M_PI ) * dt, 2 * M_PI); phase = std::fmod(phase + Util::map( get_rpm(), 0, 60, 0, 2 * M_PI ) * dt, 2 * M_PI);
// do energy transfer stuff here // do energy transfer stuff here
if(breaker_closed) if(breaker_closed)
{ {
double r_diff = util::map(get_phase_diff(), -M_PI, M_PI, -30, 30); double r_diff = Util::map(get_phase_diff(), -M_PI, M_PI, -30, 30);
double w = r_diff * 1e6; double w = r_diff * 1e6;
double v2 = util::mod((velocity - 3600) / 60 + 30, 60) - 30; double v2 = Util::mod((velocity - 3600) / 60 + 30, 60) - 30;
double w2 = w * w * v2; double w2 = w * w * v2;
energy_generated = w2 * extra_mass; energy_generated = w2 * extra_mass;
@ -69,13 +69,13 @@ double Turbine::get_rpm() const
double Turbine::get_phase_diff() const double Turbine::get_phase_diff() const
{ {
double phase_g = std::fmod(System::active.clock * 60, 1) * 2 * M_PI; double phase_g = std::fmod(System::active.clock * 60, 1) * 2 * M_PI;
return util::mod(phase - phase_g + M_PI, 2*M_PI) - M_PI; return Util::mod(phase - phase_g + M_PI, 2*M_PI) - M_PI;
} }
void Turbine::add_gas(double steam, double air, double t) void Turbine::add_gas(double steam, double air, double t)
{ {
double joules = (steam + air) * fluid.jPg; double joules = (steam + air) * fluid.jPg;
velocity = std::max(velocity + util::calc_work(joules, extra_mass), 0.0); velocity = std::max(velocity + Util::calc_work(joules, extra_mass), 0.0);
condenser->add_gas(steam, air, t); condenser->add_gas(steam, air, t);
} }

View File

@ -4,12 +4,12 @@
#include "../coolant/fluid_holder.hpp" #include "../coolant/fluid_holder.hpp"
#include "../coolant/condenser.hpp" #include "../coolant/condenser.hpp"
namespace sim::electric namespace Sim::Electric
{ {
class Turbine : public sim::coolant::FluidHolder class Turbine : public Sim::Coolant::FluidHolder
{ {
coolant::Condenser* const condenser; Coolant::Condenser* const condenser;
const double length; const double length;
const double diameter; const double diameter;
@ -23,8 +23,8 @@ public:
bool breaker_closed = false; bool breaker_closed = false;
Turbine(coolant::Fluid type, coolant::Condenser* condenser, double length, double diameter, double mass); Turbine(Coolant::Fluid type, Coolant::Condenser* condenser, double length, double diameter, double mass);
Turbine(const Json::Value& node, coolant::Condenser* condenser); Turbine(const Json::Value& node, Coolant::Condenser* condenser);
void update(double dt); void update(double dt);
double get_rpm() const; double get_rpm() const;

View File

@ -13,7 +13,7 @@
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
using namespace sim::graphics; using namespace Sim::Graphics;
static bool on_ground = false; static bool on_ground = false;
static double yaw = 0, pitch = 0; static double yaw = 0, pitch = 0;
@ -22,7 +22,7 @@ static glm::vec<3, double> velocity(0);
static Mesh collision_scene; static Mesh collision_scene;
static glm::mat4 camera_mat; static glm::mat4 camera_mat;
Json::Value camera::serialize() Json::Value Camera::serialize()
{ {
Json::Value node; Json::Value node;
@ -39,7 +39,7 @@ Json::Value camera::serialize()
return node; return node;
} }
void camera::load(const Json::Value& node) void Camera::load(const Json::Value& node)
{ {
on_ground = node["on_ground"].asBool(); on_ground = node["on_ground"].asBool();
yaw = node["yaw"].asDouble(); yaw = node["yaw"].asDouble();
@ -52,7 +52,7 @@ void camera::load(const Json::Value& node)
velocity[2] = node["velocity"]["z"].asDouble(); velocity[2] = node["velocity"]["z"].asDouble();
} }
void camera::rotate(double y, double p) void Camera::rotate(double y, double p)
{ {
yaw += y * 0.05; yaw += y * 0.05;
pitch -= p * 0.05; pitch -= p * 0.05;
@ -61,43 +61,43 @@ void camera::rotate(double y, double p)
if(pitch > 180) pitch = 180; if(pitch > 180) pitch = 180;
} }
void camera::move(double xoff, double yoff, double zoff) void Camera::move(double xoff, double yoff, double zoff)
{ {
pos.x += xoff; pos.x += xoff;
pos.y += yoff; pos.y += yoff;
pos.z += zoff; pos.z += zoff;
} }
glm::vec<3, double> camera::get_normal() glm::vec<3, double> Camera::get_normal()
{ {
glm::mat<3, 3, double> mat(camera_mat); glm::mat<3, 3, double> mat(camera_mat);
return glm::vec<3, double>(0, 0, -1) * mat; return glm::vec<3, double>(0, 0, -1) * mat;
} }
glm::vec<3, double> camera::get_pos() glm::vec<3, double> Camera::get_pos()
{ {
return pos; return pos;
} }
void camera::init() void Camera::init()
{ {
collision_scene.load_model("../assets/model", "scene_collisions.stl"); collision_scene.load_model("../assets/model", "scene_collisions.stl");
} }
void camera::update(double dt) void Camera::update(double dt)
{ {
glm::vec<2, double> off(0, 0); glm::vec<2, double> off(0, 0);
double m = 30; double m = 30;
if(keyboard::is_pressed(GLFW_KEY_W)) if(Keyboard::is_pressed(GLFW_KEY_W))
off.y += 1; off.y += 1;
if(keyboard::is_pressed(GLFW_KEY_S)) if(Keyboard::is_pressed(GLFW_KEY_S))
off.y -= 1; off.y -= 1;
if(keyboard::is_pressed(GLFW_KEY_A)) if(Keyboard::is_pressed(GLFW_KEY_A))
off.x -= 1; off.x -= 1;
if(keyboard::is_pressed(GLFW_KEY_D)) if(Keyboard::is_pressed(GLFW_KEY_D))
off.x += 1; off.x += 1;
if(keyboard::is_pressed(GLFW_KEY_LEFT_SHIFT)) if(Keyboard::is_pressed(GLFW_KEY_LEFT_SHIFT))
m *= 1.5; m *= 1.5;
if(off.x != 0 || off.y != 0) if(off.x != 0 || off.y != 0)
off = glm::normalize(off); off = glm::normalize(off);
@ -118,7 +118,7 @@ void camera::update(double dt)
velocity.y += rotated.y * m * dt; velocity.y += rotated.y * m * dt;
} }
if(on_ground && keyboard::is_pressed(GLFW_KEY_SPACE)) if(on_ground && Keyboard::is_pressed(GLFW_KEY_SPACE))
{ {
velocity.z += 3.5; velocity.z += 3.5;
} }
@ -139,7 +139,7 @@ void camera::update(double dt)
camera_mat = glm::translate(camera_mat, glm::vec3(-pos.x, -pos.y, -pos.z)); camera_mat = glm::translate(camera_mat, glm::vec3(-pos.x, -pos.y, -pos.z));
} }
glm::mat4 camera::get_matrix() glm::mat4 Camera::get_matrix()
{ {
return camera_mat; return camera_mat;
} }

View File

@ -6,7 +6,7 @@
#include "../system.hpp" #include "../system.hpp"
namespace sim::graphics::camera namespace Sim::Graphics::Camera
{ {
glm::mat4 get_matrix(); glm::mat4 get_matrix();

View File

@ -14,18 +14,18 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
using namespace sim::graphics; using namespace Sim::Graphics;
static glm::vec<3, double> trigger_near; static glm::vec<3, double> trigger_near;
static glm::vec<3, double> trigger_far; static glm::vec<3, double> trigger_far;
static std::vector<std::unique_ptr<focus::Focus>> stack; static std::vector<std::unique_ptr<Focus::Focus>> stack;
static std::unique_ptr<focus::Focus> state = nullptr; static std::unique_ptr<Focus::Focus> state = nullptr;
static bool mouse_visible = false; static bool mouse_visible = false;
static bool mouse_locked = false; static bool mouse_locked = false;
static bool triggered = false; static bool triggered = false;
void focus::on_keypress(int key, int sc, int action, int mods) void Focus::on_keypress(int key, int sc, int action, int mods)
{ {
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{ {
@ -46,7 +46,7 @@ void focus::on_keypress(int key, int sc, int action, int mods)
} }
} }
void focus::on_mouse_button(int button, int action, int mods) void Focus::on_mouse_button(int button, int action, int mods)
{ {
if(state) if(state)
{ {
@ -58,27 +58,27 @@ void focus::on_mouse_button(int button, int action, int mods)
if(is_mouse_locked() && mouse_visible) if(is_mouse_locked() && mouse_visible)
{ {
double mx, my; double mx, my;
mouse::get(mx, my); Mouse::get(mx, my);
glm::vec2 wsize = resize::get_size(); glm::vec2 wsize = Resize::get_size();
glm::vec4 viewport = glm::vec4(0, 0, wsize); glm::vec4 viewport = glm::vec4(0, 0, wsize);
glm::vec2 mouse(mx, wsize.y - my); glm::vec2 mouse(mx, wsize.y - my);
trigger_near = glm::unProject(glm::vec3(mouse, -1), camera::get_matrix(), window::projection_matrix, viewport); trigger_near = glm::unProject(glm::vec3(mouse, -1), Camera::get_matrix(), Window::projection_matrix, viewport);
trigger_far = glm::unProject(glm::vec3(mouse, 1), camera::get_matrix(), window::projection_matrix, viewport); trigger_far = glm::unProject(glm::vec3(mouse, 1), Camera::get_matrix(), Window::projection_matrix, viewport);
triggered = true; triggered = true;
} }
else if(!mouse_visible) else if(!mouse_visible)
{ {
trigger_near = camera::get_pos(); trigger_near = Camera::get_pos();
trigger_far = trigger_near + camera::get_normal(); trigger_far = trigger_near + Camera::get_normal();
triggered = true; triggered = true;
} }
} }
} }
void focus::on_cursor_pos(double x, double y) void Focus::on_cursor_pos(double x, double y)
{ {
if(state) if(state)
{ {
@ -86,7 +86,7 @@ void focus::on_cursor_pos(double x, double y)
} }
} }
void focus::on_charcode(unsigned int c) void Focus::on_charcode(unsigned int c)
{ {
if(state) if(state)
{ {
@ -94,17 +94,17 @@ void focus::on_charcode(unsigned int c)
} }
} }
glm::vec<3, double> focus::get_trigger_near() glm::vec<3, double> Focus::get_trigger_near()
{ {
return trigger_near; return trigger_near;
} }
glm::vec<3, double> focus::get_trigger_far() glm::vec<3, double> Focus::get_trigger_far()
{ {
return trigger_far; return trigger_far;
} }
void focus::update(double dt) void Focus::update(double dt)
{ {
triggered = false; triggered = false;
@ -119,12 +119,12 @@ void focus::update(double dt)
{ {
if(c) if(c)
{ {
mouse::show_cursor(); Mouse::show_cursor();
} }
else else
{ {
mouse::hide_cursor(); Mouse::hide_cursor();
} }
mouse_visible = c; mouse_visible = c;
@ -136,7 +136,7 @@ void focus::update(double dt)
} }
} }
void focus::render_ui() void Focus::render_ui()
{ {
if(state) if(state)
{ {
@ -144,7 +144,7 @@ void focus::render_ui()
} }
} }
void focus::render() void Focus::render()
{ {
if(state) if(state)
{ {
@ -152,12 +152,12 @@ void focus::render()
} }
} }
bool focus::is_focused() bool Focus::is_focused()
{ {
return (state != nullptr); return (state != nullptr);
} }
void focus::clear_focus() void Focus::clear_focus()
{ {
state = nullptr; state = nullptr;
@ -168,18 +168,18 @@ void focus::clear_focus()
} }
} }
bool focus::is_mouse_locked() bool Focus::is_mouse_locked()
{ {
return is_focused() || mouse_locked; return is_focused() || mouse_locked;
} }
void focus::clear_mouse_locked() void Focus::clear_mouse_locked()
{ {
mouse_locked = false; mouse_locked = false;
clear_focus(); clear_focus();
} }
void focus::set(std::unique_ptr<Focus> f) void Focus::set(std::unique_ptr<Focus> f)
{ {
if(state != nullptr) if(state != nullptr)
{ {
@ -189,7 +189,7 @@ void focus::set(std::unique_ptr<Focus> f)
state = std::move(f); state = std::move(f);
} }
bool focus::is_triggered() bool Focus::is_triggered()
{ {
return triggered; return triggered;
} }

View File

@ -5,7 +5,7 @@
#include <memory> #include <memory>
namespace sim::graphics::focus namespace Sim::Graphics::Focus
{ {
struct Focus struct Focus

View File

@ -11,7 +11,7 @@
#include "../camera.hpp" #include "../camera.hpp"
#include "../../system.hpp" #include "../../system.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static std::unordered_map<int, bool> pressed; static std::unordered_map<int, bool> pressed;
@ -19,7 +19,7 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
{ {
if(key == GLFW_KEY_F11 && action == GLFW_RELEASE) if(key == GLFW_KEY_F11 && action == GLFW_RELEASE)
{ {
resize::toggle_fullscreen(); Resize::toggle_fullscreen();
} }
if(action == GLFW_PRESS) if(action == GLFW_PRESS)
@ -29,28 +29,28 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
switch(key) switch(key)
{ {
case GLFW_KEY_1: case GLFW_KEY_1:
sim::System::active.speed = 1; // 1 s/s Sim::System::active.speed = 1; // 1 s/s
break; break;
case GLFW_KEY_2: case GLFW_KEY_2:
sim::System::active.speed = 10; // 10 s/s Sim::System::active.speed = 10; // 10 s/s
break; break;
case GLFW_KEY_3: case GLFW_KEY_3:
sim::System::active.speed = 60; // 1 min/s Sim::System::active.speed = 60; // 1 min/s
break; break;
case GLFW_KEY_4: case GLFW_KEY_4:
sim::System::active.speed = 600; // 10 min/s Sim::System::active.speed = 600; // 10 min/s
break; break;
case GLFW_KEY_5: case GLFW_KEY_5:
sim::System::active.speed = 3600; // 1 h/s Sim::System::active.speed = 3600; // 1 h/s
break; break;
case GLFW_KEY_6: case GLFW_KEY_6:
sim::System::active.speed = 43200; // 12 h/s Sim::System::active.speed = 43200; // 12 h/s
break; break;
case GLFW_KEY_O: case GLFW_KEY_O:
sim::System::save(); Sim::System::save();
break; break;
case GLFW_KEY_L: case GLFW_KEY_L:
sim::System::load(); Sim::System::load();
break; break;
} }
} }
@ -60,17 +60,17 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
pressed[key] = false; pressed[key] = false;
} }
focus::on_keypress(key, sc, action, mods); Focus::on_keypress(key, sc, action, mods);
} }
static void cb_charcode(GLFWwindow* win, unsigned int code) static void cb_charcode(GLFWwindow* win, unsigned int code)
{ {
focus::on_charcode(code); Focus::on_charcode(code);
} }
bool keyboard::is_pressed(int key) bool Keyboard::is_pressed(int key)
{ {
if(focus::is_mouse_locked()) if(Focus::is_mouse_locked())
{ {
return false; return false;
} }
@ -88,9 +88,9 @@ bool keyboard::is_pressed(int key)
} }
} }
void keyboard::init() void Keyboard::init()
{ {
GLFWwindow* win = window::get_window(); GLFWwindow* win = Window::get_window();
glfwSetKeyCallback(win, cb_keypress); glfwSetKeyCallback(win, cb_keypress);
glfwSetCharCallback(win, cb_charcode); glfwSetCharCallback(win, cb_charcode);
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::graphics::keyboard namespace Sim::Graphics::Keyboard
{ {
void init(); void init();

View File

@ -7,20 +7,20 @@
#include "../window.hpp" #include "../window.hpp"
#include "../camera.hpp" #include "../camera.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static double xpos = 0, ypos = 0; static double xpos = 0, ypos = 0;
static void cb_cursor_pos(GLFWwindow* win, double x, double y) static void cb_cursor_pos(GLFWwindow* win, double x, double y)
{ {
if(focus::is_mouse_locked()) if(Focus::is_mouse_locked())
{ {
focus::on_cursor_pos(x - xpos, y - ypos); Focus::on_cursor_pos(x - xpos, y - ypos);
} }
else else
{ {
camera::rotate(x - xpos, y - ypos); Camera::rotate(x - xpos, y - ypos);
} }
xpos = x; xpos = x;
@ -29,41 +29,41 @@ static void cb_cursor_pos(GLFWwindow* win, double x, double y)
void cb_mouse_button(GLFWwindow* window, int button, int action, int mods) void cb_mouse_button(GLFWwindow* window, int button, int action, int mods)
{ {
focus::on_mouse_button(button, action, mods); Focus::on_mouse_button(button, action, mods);
} }
void mouse::get(double& x, double& y) void Mouse::get(double& x, double& y)
{ {
x = xpos; x = xpos;
y = ypos; y = ypos;
} }
glm::vec2 mouse::get() glm::vec2 Mouse::get()
{ {
return {xpos, ypos}; return {xpos, ypos};
} }
void mouse::show_cursor() void Mouse::show_cursor()
{ {
double x, y; double x, y;
GLFWwindow* win = window::get_window(); GLFWwindow* win = Window::get_window();
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
glfwGetCursorPos(win, &x, &y); glfwGetCursorPos(win, &x, &y);
cb_cursor_pos(win, x, y); cb_cursor_pos(win, x, y);
} }
void mouse::hide_cursor() void Mouse::hide_cursor()
{ {
double x, y; double x, y;
GLFWwindow* win = window::get_window(); GLFWwindow* win = Window::get_window();
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwGetCursorPos(win, &x, &y); glfwGetCursorPos(win, &x, &y);
cb_cursor_pos(win, x, y); cb_cursor_pos(win, x, y);
} }
void mouse::init() void Mouse::init()
{ {
GLFWwindow* win = window::get_window(); GLFWwindow* win = Window::get_window();
glfwSetCursorPosCallback(win, cb_cursor_pos); glfwSetCursorPosCallback(win, cb_cursor_pos);
glfwSetMouseButtonCallback(win, cb_mouse_button); glfwSetMouseButtonCallback(win, cb_mouse_button);
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

View File

@ -3,7 +3,7 @@
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
namespace sim::graphics::mouse namespace Sim::Graphics::Mouse
{ {
void init(); void init();

View File

@ -2,9 +2,9 @@
#include "locations.hpp" #include "locations.hpp"
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
using namespace sim::graphics; using namespace Sim::Graphics;
const glm::mat4 locations::monitors[7] = { const glm::mat4 Locations::monitors[7] = {
( (
glm::translate(glm::mat4(1), glm::vec3(-2.949, -1.7778 + 0.05, 3 - 0.05)) * glm::translate(glm::mat4(1), glm::vec3(-2.949, -1.7778 + 0.05, 3 - 0.05)) *
glm::rotate(glm::mat4(1), glm::radians<float>(-90), glm::vec3(1, 0, 0)) * glm::rotate(glm::mat4(1), glm::radians<float>(-90), glm::vec3(1, 0, 0)) *

View File

@ -3,7 +3,7 @@
#include <glm/matrix.hpp> #include <glm/matrix.hpp>
namespace sim::graphics::locations namespace Sim::Graphics::Locations
{ {
extern const glm::mat4 monitors[7]; extern const glm::mat4 monitors[7];

View File

@ -8,7 +8,7 @@
#include "arrays.hpp" #include "arrays.hpp"
#include "font.hpp" #include "font.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static unsigned int vao, vbo, ebo; static unsigned int vao, vbo, ebo;
@ -17,7 +17,7 @@ static void* ptr_diff(void* a, void* b)
return (void*)((size_t)a - (size_t)b); return (void*)((size_t)a - (size_t)b);
} }
void arrays::vertex_attrib_pointers() void Arrays::vertex_attrib_pointers()
{ {
vertex v; vertex v;
@ -34,7 +34,7 @@ void arrays::vertex_attrib_pointers()
glEnableVertexAttribArray(3); glEnableVertexAttribArray(3);
} }
glm::mat4 arrays::colour(glm::vec4 c) glm::mat4 Arrays::colour(glm::vec4 c)
{ {
return glm::mat4({ return glm::mat4({
c.r, c.g, c.b, c.a, c.r, c.g, c.b, c.a,

View File

@ -3,7 +3,7 @@
#include <glm/matrix.hpp> #include <glm/matrix.hpp>
namespace sim::graphics::arrays namespace Sim::Graphics::Arrays
{ {
struct vertex struct vertex

View File

@ -13,7 +13,7 @@
#include "arrays.hpp" #include "arrays.hpp"
#include "font.hpp" #include "font.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
struct character struct character
{ {
@ -25,7 +25,7 @@ struct character
static character chars[128]; static character chars[128];
void font::init() void Font::init()
{ {
FT_Library ft; FT_Library ft;
FT_Face face; FT_Face face;
@ -95,7 +95,7 @@ void font::init()
void Mesh::load_text(const char* text, double size) void Mesh::load_text(const char* text, double size)
{ {
std::vector<arrays::vertex> vertices; std::vector<Arrays::vertex> vertices;
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
float x = 0, y = size; float x = 0, y = size;
@ -136,10 +136,10 @@ void Mesh::load_text(const char* text, double size)
float ex = sx + ch.size.x * size; float ex = sx + ch.size.x * size;
float ey = sy + ch.size.y * size; float ey = sy + ch.size.y * size;
vertices.push_back(arrays::vertex(ch.handle, {0, 0}, {sx, sy, 0, 1}, {0, 0, -1})); vertices.push_back(Arrays::vertex(ch.handle, {0, 0}, {sx, sy, 0, 1}, {0, 0, -1}));
vertices.push_back(arrays::vertex(ch.handle, {0, 1}, {sx, ey, 0, 1}, {0, 0, -1})); vertices.push_back(Arrays::vertex(ch.handle, {0, 1}, {sx, ey, 0, 1}, {0, 0, -1}));
vertices.push_back(arrays::vertex(ch.handle, {1, 0}, {ex, sy, 0, 1}, {0, 0, -1})); vertices.push_back(Arrays::vertex(ch.handle, {1, 0}, {ex, sy, 0, 1}, {0, 0, -1}));
vertices.push_back(arrays::vertex(ch.handle, {1, 1}, {ex, ey, 0, 1}, {0, 0, -1})); vertices.push_back(Arrays::vertex(ch.handle, {1, 1}, {ex, ey, 0, 1}, {0, 0, -1}));
indices.insert(indices.end(), &index[0], &index[6]); indices.insert(indices.end(), &index[0], &index[6]);
at += 4; at += 4;

View File

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
namespace sim::graphics::font namespace Sim::Graphics::Font
{ {
void init(); void init();

View File

@ -7,7 +7,7 @@
#include "../shader.hpp" #include "../shader.hpp"
#include "../camera.hpp" #include "../camera.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
constexpr static void init(GLMesh* m) constexpr static void init(GLMesh* m)
{ {
@ -24,7 +24,7 @@ constexpr static void init(GLMesh* m)
glBindBuffer(GL_ARRAY_BUFFER, m->vbo); glBindBuffer(GL_ARRAY_BUFFER, m->vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->ebo);
arrays::vertex_attrib_pointers(); Arrays::vertex_attrib_pointers();
} }
GLMesh::GLMesh(GLMesh&& o) GLMesh::GLMesh(GLMesh&& o)
@ -59,8 +59,8 @@ void GLMesh::bind()
void GLMesh::uniform() void GLMesh::uniform()
{ {
glUniformMatrix4fv(shader::gl_model, 1, false, &model_matrix[0][0]); glUniformMatrix4fv(Shader::gl_model, 1, false, &model_matrix[0][0]);
glUniformMatrix4fv(shader::gl_tex_mat, 1, false, &colour_matrix[0][0]); glUniformMatrix4fv(Shader::gl_tex_mat, 1, false, &colour_matrix[0][0]);
} }
void GLMesh::set(const Mesh& m, int mode) void GLMesh::set(const Mesh& m, int mode)

View File

@ -8,7 +8,7 @@
#include <glm/matrix.hpp> #include <glm/matrix.hpp>
namespace sim::graphics namespace Sim::Graphics
{ {
struct GLMesh struct GLMesh

View File

@ -8,7 +8,7 @@
#include <iostream> #include <iostream>
using namespace sim::graphics; using namespace Sim::Graphics;
void Mesh::add(const Mesh& o, glm::mat4 mat) void Mesh::add(const Mesh& o, glm::mat4 mat)
{ {
@ -20,7 +20,7 @@ void Mesh::add(const Mesh& o, glm::mat4 mat)
for(unsigned int i = 0; i < o.vertices.size(); i++) for(unsigned int i = 0; i < o.vertices.size(); i++)
{ {
arrays::vertex v = o.vertices[i]; Arrays::vertex v = o.vertices[i];
v.normal = mat3 * v.normal; v.normal = mat3 * v.normal;
v.pos = mat * v.pos; v.pos = mat * v.pos;
vertices.push_back(v); vertices.push_back(v);
@ -32,7 +32,7 @@ void Mesh::add(const Mesh& o, glm::mat4 mat)
} }
} }
void Mesh::set_vertices(const arrays::vertex* data, size_t size) void Mesh::set_vertices(const Arrays::vertex* data, size_t size)
{ {
vertices.clear(); vertices.clear();
vertices.reserve(size); vertices.reserve(size);
@ -98,10 +98,10 @@ bool ray_intersects_triangle(vec3 ray_origin,
bool Mesh::check_focus(double len) const bool Mesh::check_focus(double len) const
{ {
auto near = focus::get_trigger_near(); auto near = Focus::get_trigger_near();
auto far = focus::get_trigger_far(); auto far = Focus::get_trigger_far();
return focus::is_triggered() && check_intersect(near, glm::normalize(far - near) * len); return Focus::is_triggered() && check_intersect(near, glm::normalize(far - near) * len);
} }
bool Mesh::check_focus() const bool Mesh::check_focus() const

View File

@ -10,17 +10,17 @@
#include "arrays.hpp" #include "arrays.hpp"
namespace sim::graphics namespace Sim::Graphics
{ {
struct Mesh struct Mesh
{ {
std::vector<arrays::vertex> vertices; std::vector<Arrays::vertex> vertices;
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
constexpr Mesh() { } constexpr Mesh() { }
void set_vertices(const arrays::vertex* data, size_t size); void set_vertices(const Arrays::vertex* data, size_t size);
void set_indices(const unsigned int* data, size_t size); void set_indices(const unsigned int* data, size_t size);
void load_model(std::string base, std::string path); void load_model(std::string base, std::string path);
void load_model(std::string path) { load_model(".", path); } void load_model(std::string path) { load_model(".", path); }

View File

@ -15,14 +15,14 @@
#include "arrays.hpp" #include "arrays.hpp"
#include "texture.hpp" #include "texture.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
struct proc_state struct proc_state
{ {
unsigned int offset = 0; unsigned int offset = 0;
std::string base; std::string base;
std::vector<arrays::vertex> vertices; std::vector<Arrays::vertex> vertices;
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
std::unordered_map<const aiTexture*, unsigned int> handles; std::unordered_map<const aiTexture*, unsigned int> handles;
}; };
@ -53,10 +53,10 @@ static unsigned int proc_texture(const proc_state& state, aiMaterial* mat, const
std::string filename(str.C_Str()); std::string filename(str.C_Str());
std::replace(filename.begin(), filename.end(), '\\', '/'); std::replace(filename.begin(), filename.end(), '\\', '/');
return texture::load(state.base + "/" + filename); return Texture::load(state.base + "/" + filename);
} }
return texture::handle_white; return Texture::handle_white;
} }
static void proc_mesh(proc_state& state, glm::mat4 mat, aiMesh* mesh, const aiScene* scene) static void proc_mesh(proc_state& state, glm::mat4 mat, aiMesh* mesh, const aiScene* scene)
@ -68,7 +68,7 @@ static void proc_mesh(proc_state& state, glm::mat4 mat, aiMesh* mesh, const aiSc
for(unsigned int i = 0; i < mesh->mNumVertices; i++) for(unsigned int i = 0; i < mesh->mNumVertices; i++)
{ {
arrays::vertex vertex; Arrays::vertex vertex;
auto [x, y, z] = mesh->mVertices[i]; auto [x, y, z] = mesh->mVertices[i];
vertex.pos = glm::vec4(x, y, z, 1) * mat; vertex.pos = glm::vec4(x, y, z, 1) * mat;
@ -130,7 +130,7 @@ static unsigned int proc_embedded_texture(aiTexture* tex)
if(tex->mHeight == 0) if(tex->mHeight == 0)
{ {
return texture::load_mem((unsigned char*)tex->pcData, tex->mWidth); return Texture::load_mem((unsigned char*)tex->pcData, tex->mWidth);
} }
// swizzle each pixel to get RGBA // swizzle each pixel to get RGBA
@ -140,7 +140,7 @@ static unsigned int proc_embedded_texture(aiTexture* tex)
tex->pcData[i] = {t.r, t.g, t.b, t.a}; tex->pcData[i] = {t.r, t.g, t.b, t.a};
} }
return texture::load_mem((unsigned char*)tex->pcData, tex->mWidth, tex->mHeight, 4); return Texture::load_mem((unsigned char*)tex->pcData, tex->mWidth, tex->mHeight, 4);
} }
void Mesh::load_model(std::string base, std::string filename) void Mesh::load_model(std::string base, std::string filename)

View File

@ -8,18 +8,18 @@
#include "texture.hpp" #include "texture.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static std::unordered_map<std::string, unsigned int> loaded; static std::unordered_map<std::string, unsigned int> loaded;
unsigned int texture::handle_white; unsigned int Texture::handle_white;
void texture::init() void Texture::init()
{ {
unsigned char pixels[] = {255, 255, 255, 255}; unsigned char pixels[] = {255, 255, 255, 255};
handle_white = load_mem(pixels, 1, 1, 4); handle_white = load_mem(pixels, 1, 1, 4);
} }
unsigned int texture::load_mem(const unsigned char* data, int width, int height, int channels) unsigned int Texture::load_mem(const unsigned char* data, int width, int height, int channels)
{ {
if(!data) if(!data)
{ {
@ -64,7 +64,7 @@ unsigned int texture::load_mem(const unsigned char* data, int width, int height,
return handle; return handle;
} }
unsigned int texture::load_mem(const unsigned char* filedata, size_t len) unsigned int Texture::load_mem(const unsigned char* filedata, size_t len)
{ {
int width, height, channels; int width, height, channels;
unsigned char* data = stbi_load_from_memory(filedata, len, &width, &height, &channels, 0); unsigned char* data = stbi_load_from_memory(filedata, len, &width, &height, &channels, 0);
@ -73,7 +73,7 @@ unsigned int texture::load_mem(const unsigned char* filedata, size_t len)
return handle; return handle;
} }
unsigned int texture::load(std::string path) unsigned int Texture::load(std::string path)
{ {
const auto it = loaded.find(path); const auto it = loaded.find(path);

View File

@ -3,7 +3,7 @@
#include <string> #include <string>
namespace sim::graphics::texture namespace Sim::Graphics::Texture
{ {
extern unsigned int handle_white; extern unsigned int handle_white;

View File

@ -15,14 +15,14 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
using namespace sim::graphics; using namespace Sim::Graphics;
using namespace sim::graphics::monitor; using namespace Sim::Graphics::Monitor;
static void set_all(bool state) static void set_all(bool state)
{ {
for(int i = 0; i < sim::System::active.reactor->rods.size(); i++) for(int i = 0; i < Sim::System::active.reactor->rods.size(); i++)
{ {
sim::reactor::Rod* r = sim::System::active.reactor->rods[i].get(); Sim::Reactor::Rod* r = Sim::System::active.reactor->rods[i].get();
if(r->should_select()) if(r->should_select())
{ {
@ -31,7 +31,7 @@ static void set_all(bool state)
} }
} }
struct core_monitor : public focus::Focus struct core_monitor : public Focus::Focus
{ {
virtual void on_keypress(int key, int sc, int action, int mods) virtual void on_keypress(int key, int sc, int action, int mods)
{ {
@ -40,7 +40,7 @@ struct core_monitor : public focus::Focus
return; return;
} }
sim::System& sys = sim::System::active; Sim::System& sys = Sim::System::active;
switch(key) switch(key)
{ {
@ -72,23 +72,23 @@ struct core_monitor : public focus::Focus
} }
}; };
struct core_joystick : public focus::Focus struct core_joystick : public Focus::Focus
{ {
virtual void on_cursor_pos(double x, double y) virtual void on_cursor_pos(double x, double y)
{ {
sim::System::active.reactor->add_rod_speed(y * 1e-6); Sim::System::active.reactor->add_rod_speed(y * 1e-6);
} }
virtual ~core_joystick() virtual ~core_joystick()
{ {
sim::System::active.reactor->reset_rod_speed(); Sim::System::active.reactor->reset_rod_speed();
} }
virtual void on_mouse_button(int button, int action, int mods) virtual void on_mouse_button(int button, int action, int mods)
{ {
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE)
{ {
focus::clear_focus(); Focus::clear_focus();
} }
} }
@ -104,21 +104,21 @@ Core::Core()
void Core::init() void Core::init()
{ {
mesh1.model_matrix = locations::monitors[2]; mesh1.model_matrix = Locations::monitors[2];
mesh1.colour_matrix = arrays::colour({1, 1, 1, 1}); mesh1.colour_matrix = Arrays::colour({1, 1, 1, 1});
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
rmesh.load_text("Reactor Core", 0.04); rmesh.load_text("Reactor Core", 0.04);
mesh1.bind(); mesh1.bind();
mesh1.set(rmesh, GL_STATIC_DRAW); mesh1.set(rmesh, GL_STATIC_DRAW);
unsigned int indices[] = {0, 1, 3, 0, 3, 2}; unsigned int indices[] = {0, 1, 3, 0, 3, 2};
arrays::vertex vertices[] = { Arrays::vertex vertices[] = {
{texture::handle_white, {0, 0}, {-0.75, -0.75, 0, 1}, {0, 0, -1}}, {Texture::handle_white, {0, 0}, {-0.75, -0.75, 0, 1}, {0, 0, -1}},
{texture::handle_white, {0, 1}, {-0.75, 0.75, 0, 1}, {0, 0, -1}}, {Texture::handle_white, {0, 1}, {-0.75, 0.75, 0, 1}, {0, 0, -1}},
{texture::handle_white, {1, 0}, { 0.75, -0.75, 0, 1}, {0, 0, -1}}, {Texture::handle_white, {1, 0}, { 0.75, -0.75, 0, 1}, {0, 0, -1}},
{texture::handle_white, {1, 1}, { 0.75, 0.75, 0, 1}, {0, 0, -1}}, {Texture::handle_white, {1, 1}, { 0.75, 0.75, 0, 1}, {0, 0, -1}},
}; };
rmesh.set_indices(indices, 6); rmesh.set_indices(indices, 6);
@ -142,12 +142,12 @@ void Core::init()
void Core::update(double dt) void Core::update(double dt)
{ {
sim::System& sys = sim::System::active; Sim::System& sys = Sim::System::active;
if(m_monitor.check_focus()) if(m_monitor.check_focus())
focus::set(std::make_unique<core_monitor>()); Focus::set(std::make_unique<core_monitor>());
if(m_joystick.check_focus()) if(m_joystick.check_focus())
focus::set(std::make_unique<core_joystick>()); Focus::set(std::make_unique<core_joystick>());
if(m_scram.check_focus()) if(m_scram.check_focus())
sys.reactor->scram(); sys.reactor->scram();
if(m_buttons[0].check_focus()) if(m_buttons[0].check_focus())
@ -170,7 +170,7 @@ void Core::update(double dt)
void Core::render() void Core::render()
{ {
sim::System& sys = sim::System::active; Sim::System& sys = Sim::System::active;
double step = 1 / (sys.vessel->diameter / sys.reactor->cell_width * 0.8); double step = 1 / (sys.vessel->diameter / sys.reactor->cell_width * 0.8);
double sx = 0.5 - (sys.reactor->width - 1) * step / 2.0; double sx = 0.5 - (sys.reactor->width - 1) * step / 2.0;
@ -195,7 +195,7 @@ void Core::render()
double ox = sx + x * step; double ox = sx + x * step;
double oy = sy + y * step; double oy = sy + y * step;
reactor::Rod* r = sys.reactor->rods[i].get(); Reactor::Rod* r = sys.reactor->rods[i].get();
if(!r->should_display()) if(!r->should_display())
{ {
@ -213,14 +213,14 @@ void Core::render()
glm::mat4 mat = mesh1.model_matrix * glm::translate(glm::mat4(1), glm::vec3(ox, oy, 0)) * mat_scale; glm::mat4 mat = mesh1.model_matrix * glm::translate(glm::mat4(1), glm::vec3(ox, oy, 0)) * mat_scale;
mesh2.model_matrix = mat; mesh2.model_matrix = mat;
mesh2.colour_matrix = arrays::colour(colour_heat); mesh2.colour_matrix = Arrays::colour(colour_heat);
mesh2.uniform(); mesh2.uniform();
mesh2.render(); mesh2.render();
if(sys.reactor->cursor == i) if(sys.reactor->cursor == i)
{ {
mesh2.model_matrix = mat * mat_cursor; mesh2.model_matrix = mat * mat_cursor;
mesh2.colour_matrix = arrays::colour({1, 0, 0, 1}); mesh2.colour_matrix = Arrays::colour({1, 0, 0, 1});
mesh2.uniform(); mesh2.uniform();
mesh2.render(); mesh2.render();
} }
@ -228,7 +228,7 @@ void Core::render()
if(r->selected) if(r->selected)
{ {
mesh2.model_matrix = mat * mat_select; mesh2.model_matrix = mat * mat_select;
mesh2.colour_matrix = arrays::colour({1, 1, 0, 1}); mesh2.colour_matrix = Arrays::colour({1, 1, 0, 1});
mesh2.uniform(); mesh2.uniform();
mesh2.render(); mesh2.render();
} }
@ -236,7 +236,7 @@ void Core::render()
if(colour_spec[3] != 0) if(colour_spec[3] != 0)
{ {
mesh2.model_matrix = mat * mat_spec; mesh2.model_matrix = mat * mat_spec;
mesh2.colour_matrix = arrays::colour(colour_spec); mesh2.colour_matrix = Arrays::colour(colour_spec);
mesh2.uniform(); mesh2.uniform();
mesh2.render(); mesh2.render();
} }

View File

@ -3,17 +3,17 @@
#include "../mesh/glmesh.hpp" #include "../mesh/glmesh.hpp"
namespace sim::graphics::monitor namespace Sim::Graphics::monitor
{ {
class Core class Core
{ {
sim::graphics::GLMesh mesh1, mesh2; Sim::Graphics::GLMesh mesh1, mesh2;
sim::graphics::Mesh m_monitor; Sim::Graphics::Mesh m_monitor;
sim::graphics::Mesh m_buttons[9]; Sim::Graphics::Mesh m_buttons[9];
sim::graphics::Mesh m_joystick; Sim::Graphics::Mesh m_joystick;
sim::graphics::Mesh m_scram; Sim::Graphics::Mesh m_scram;
public: public:

View File

@ -12,14 +12,14 @@
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <iostream> #include <iostream>
using namespace sim::graphics; using namespace Sim::Graphics;
using namespace sim::graphics::monitor; using namespace Sim::Graphics::Monitor;
struct valve_joystick : public focus::Focus struct valve_joystick : public Focus::Focus
{ {
sim::coolant::Valve* active; Sim::Coolant::Valve* active;
valve_joystick(sim::coolant::Valve* v) : active(v) valve_joystick(Sim::Coolant::Valve* v) : active(v)
{ {
} }
@ -38,7 +38,7 @@ struct valve_joystick : public focus::Focus
{ {
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE)
{ {
focus::clear_focus(); Focus::clear_focus();
} }
} }
@ -56,7 +56,7 @@ PrimaryLoop::PrimaryLoop()
void PrimaryLoop::init() void PrimaryLoop::init()
{ {
mesh1.model_matrix = locations::monitors[3]; mesh1.model_matrix = Locations::monitors[3];
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0)); mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
mesh1.colour_matrix = mesh2.colour_matrix = { mesh1.colour_matrix = mesh2.colour_matrix = {
@ -67,7 +67,7 @@ void PrimaryLoop::init()
}; };
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
ss << "Turbine Bypass Valve\n\n"; ss << "Turbine Bypass Valve\n\n";
ss << "Opened\nFlow\nSetpoint\n\n"; ss << "Opened\nFlow\nSetpoint\n\n";
@ -106,13 +106,13 @@ void PrimaryLoop::init()
void PrimaryLoop::update(double dt) void PrimaryLoop::update(double dt)
{ {
System& sys = sim::System::active; System& sys = Sim::System::active;
clock_now += dt; clock_now += dt;
if(clock_at + 1.0/30.0 < clock_now) if(clock_at + 1.0/30.0 < clock_now)
{ {
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
clock_at += 1.0/30.0; clock_at += 1.0/30.0;
ss << "\n\n"; ss << "\n\n";
@ -159,9 +159,9 @@ void PrimaryLoop::update(double dt)
} }
if(m_joystick_turbine_bypass.check_focus()) if(m_joystick_turbine_bypass.check_focus())
focus::set(std::make_unique<valve_joystick>(sys.turbine_bypass_valve.get())); Focus::set(std::make_unique<valve_joystick>(sys.turbine_bypass_valve.get()));
if(m_joystick_turbine_inlet.check_focus()) if(m_joystick_turbine_inlet.check_focus())
focus::set(std::make_unique<valve_joystick>(sys.turbine_inlet_valve.get())); Focus::set(std::make_unique<valve_joystick>(sys.turbine_inlet_valve.get()));
if(m_switch_pump.check_focus()) if(m_switch_pump.check_focus())
sys.primary_pump->powered = !sys.primary_pump->powered; sys.primary_pump->powered = !sys.primary_pump->powered;
if(m_switch_inlet.check_focus()) if(m_switch_inlet.check_focus())

View File

@ -3,7 +3,7 @@
#include "../mesh/glmesh.hpp" #include "../mesh/glmesh.hpp"
namespace sim::graphics::monitor namespace Sim::Graphics::monitor
{ {
class PrimaryLoop class PrimaryLoop

View File

@ -12,8 +12,8 @@
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <iostream> #include <iostream>
using namespace sim::graphics; using namespace Sim::Graphics;
using namespace sim::graphics::monitor; using namespace Sim::Graphics::Monitor;
SecondaryLoop::SecondaryLoop() SecondaryLoop::SecondaryLoop()
{ {
@ -22,7 +22,7 @@ SecondaryLoop::SecondaryLoop()
void SecondaryLoop::init() void SecondaryLoop::init()
{ {
mesh1.model_matrix = locations::monitors[5]; mesh1.model_matrix = Locations::monitors[5];
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0)); mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
mesh1.colour_matrix = mesh2.colour_matrix = { mesh1.colour_matrix = mesh2.colour_matrix = {
@ -33,7 +33,7 @@ void SecondaryLoop::init()
}; };
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
ss << "Cooling Tower\n\n"; ss << "Cooling Tower\n\n";
ss << "Heat\nSteam\nPressure\nLevel\n\n"; ss << "Heat\nSteam\nPressure\nLevel\n\n";
@ -62,13 +62,13 @@ void SecondaryLoop::init()
void SecondaryLoop::update(double dt) void SecondaryLoop::update(double dt)
{ {
System& sys = sim::System::active; System& sys = Sim::System::active;
clock_now += dt; clock_now += dt;
if(clock_at + 1.0/30.0 < clock_now) if(clock_at + 1.0/30.0 < clock_now)
{ {
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
clock_at += 1.0/30.0; clock_at += 1.0/30.0;
ss << "\n\n"; ss << "\n\n";

View File

@ -3,21 +3,21 @@
#include "../mesh/glmesh.hpp" #include "../mesh/glmesh.hpp"
namespace sim::graphics::monitor namespace Sim::Graphics::monitor
{ {
class SecondaryLoop class SecondaryLoop
{ {
sim::graphics::GLMesh mesh1, mesh2; Sim::Graphics::GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0; double clock_at = 0, clock_now = 0;
sim::graphics::GLMesh gm_switch_2; Sim::Graphics::GLMesh gm_switch_2;
sim::graphics::GLMesh gm_switch_3; Sim::Graphics::GLMesh gm_switch_3;
sim::graphics::Mesh m_joystick_turbine_bypass; Sim::Graphics::Mesh m_joystick_turbine_bypass;
sim::graphics::Mesh m_joystick_turbine_inlet; Sim::Graphics::Mesh m_joystick_turbine_inlet;
sim::graphics::Mesh m_switch_2; Sim::Graphics::Mesh m_switch_2;
sim::graphics::Mesh m_switch_3; Sim::Graphics::Mesh m_switch_3;
public: public:

View File

@ -12,8 +12,8 @@
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <iostream> #include <iostream>
using namespace sim::graphics; using namespace Sim::Graphics;
using namespace sim::graphics::monitor; using namespace Sim::Graphics::Monitor;
Turbine::Turbine() Turbine::Turbine()
{ {
@ -22,7 +22,7 @@ Turbine::Turbine()
void Turbine::init() void Turbine::init()
{ {
mesh1.model_matrix = mesh2.model_matrix = locations::monitors[4]; mesh1.model_matrix = mesh2.model_matrix = Locations::monitors[4];
mesh1.colour_matrix = mesh2.colour_matrix = { mesh1.colour_matrix = mesh2.colour_matrix = {
1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0,
@ -31,7 +31,7 @@ void Turbine::init()
}; };
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh, rmesh2; Sim::Graphics::Mesh rmesh, rmesh2;
ss << "Turbine\n\n"; ss << "Turbine\n\n";
ss << "Heat\nPressure\nSpeed\n\n"; ss << "Heat\nPressure\nSpeed\n\n";
@ -56,13 +56,13 @@ void Turbine::init()
void Turbine::update(double dt) void Turbine::update(double dt)
{ {
System& sys = sim::System::active; System& sys = Sim::System::active;
clock_now += dt; clock_now += dt;
if(clock_at + 1.0/30.0 < clock_now) if(clock_at + 1.0/30.0 < clock_now)
{ {
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh, rmesh2; Sim::Graphics::Mesh rmesh, rmesh2;
clock_at += 1.0/30.0; clock_at += 1.0/30.0;
ss << "\n\n"; ss << "\n\n";

View File

@ -3,17 +3,17 @@
#include "../mesh/glmesh.hpp" #include "../mesh/glmesh.hpp"
namespace sim::graphics::monitor namespace Sim::Graphics::monitor
{ {
class Turbine class Turbine
{ {
sim::graphics::GLMesh mesh1, mesh2; Sim::Graphics::GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0; double clock_at = 0, clock_now = 0;
sim::graphics::GLMesh gm_synchroscope_dial; Sim::Graphics::GLMesh gm_synchroscope_dial;
sim::graphics::GLMesh gm_switch_breaker; Sim::Graphics::GLMesh gm_switch_breaker;
sim::graphics::Mesh m_switch_breaker; Sim::Graphics::Mesh m_switch_breaker;
public: public:

View File

@ -12,7 +12,7 @@
#include <glm/ext/matrix_transform.hpp> #include <glm/ext/matrix_transform.hpp>
#include <sstream> #include <sstream>
using namespace sim::graphics::monitor; using namespace Sim::Graphics::Monitor;
Vessel::Vessel() Vessel::Vessel()
{ {
@ -21,7 +21,7 @@ Vessel::Vessel()
void Vessel::init() void Vessel::init()
{ {
mesh1.model_matrix = locations::monitors[1]; mesh1.model_matrix = Locations::monitors[1];
mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0)); mesh2.model_matrix = glm::translate(mesh1.model_matrix, glm::vec3(0.5, 0, 0));
mesh1.colour_matrix = mesh2.colour_matrix = { mesh1.colour_matrix = mesh2.colour_matrix = {
@ -32,7 +32,7 @@ void Vessel::init()
}; };
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
ss << "Reactor Vessel\n\n"; ss << "Reactor Vessel\n\n";
ss << "Heat\n"; ss << "Heat\n";
@ -54,8 +54,8 @@ void Vessel::init()
void Vessel::update(double dt) void Vessel::update(double dt)
{ {
std::stringstream ss; std::stringstream ss;
sim::graphics::Mesh rmesh; Sim::Graphics::Mesh rmesh;
sim::System& sys = sim::System::active; Sim::System& sys = Sim::System::active;
clock_now += dt; clock_now += dt;
if(clock_at + 1.0/30.0 > clock_now) if(clock_at + 1.0/30.0 > clock_now)
@ -67,18 +67,18 @@ void Vessel::update(double dt)
double crod_min = INFINITY, crod_max = -INFINITY; double crod_min = INFINITY, crod_max = -INFINITY;
clock_at += 1.0/30.0; clock_at += 1.0/30.0;
sys.reactor->get_stats(sim::reactor::Rod::val_t::HEAT, temp_min, temp_max); sys.reactor->get_stats(Sim::Reactor::Rod::val_t::HEAT, temp_min, temp_max);
for(int i = 0; i < sys.reactor->size; i++) for(int i = 0; i < sys.reactor->size; i++)
{ {
sim::reactor::Rod* r = sys.reactor->rods[i].get(); Sim::Reactor::Rod* r = sys.reactor->rods[i].get();
if(r->get_id() != 5) if(r->get_id() != 5)
{ {
continue; continue;
} }
auto br = (sim::reactor::control::BoronRod*)r; auto br = (Sim::Reactor::control::BoronRod*)r;
double v = br->get_inserted(); double v = br->get_inserted();
if(v > crod_max) if(v > crod_max)

View File

@ -3,12 +3,12 @@
#include "../mesh/glmesh.hpp" #include "../mesh/glmesh.hpp"
namespace sim::graphics::monitor namespace Sim::Graphics::monitor
{ {
class Vessel class Vessel
{ {
sim::graphics::GLMesh mesh1, mesh2; Sim::Graphics::GLMesh mesh1, mesh2;
double clock_at = 0, clock_now = 0; double clock_at = 0, clock_now = 0;
public: public:

View File

@ -5,7 +5,7 @@
#include "resize.hpp" #include "resize.hpp"
#include "window.hpp" #include "window.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static bool is_fullscreen = false; static bool is_fullscreen = false;
@ -17,19 +17,19 @@ static int win_restore_h;
static int win_restore_x; static int win_restore_x;
static int win_restore_y; static int win_restore_y;
glm::vec<2, int> resize::get_size() glm::vec<2, int> Resize::get_size()
{ {
return {win_w, win_h}; return {win_w, win_h};
} }
float resize::get_aspect() float Resize::get_aspect()
{ {
return (float)win_w / (float)win_h; return (float)win_w / (float)win_h;
} }
void resize::toggle_fullscreen() void Resize::toggle_fullscreen()
{ {
GLFWwindow* win = window::get_window(); GLFWwindow* win = Window::get_window();
is_fullscreen = !is_fullscreen; is_fullscreen = !is_fullscreen;
if(is_fullscreen) if(is_fullscreen)
@ -57,9 +57,9 @@ static void cb_framebuffer_size(GLFWwindow* win, int w, int h)
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
} }
void resize::init() void Resize::init()
{ {
GLFWwindow* win = window::get_window(); GLFWwindow* win = Window::get_window();
glfwSetFramebufferSizeCallback(win, cb_framebuffer_size); glfwSetFramebufferSizeCallback(win, cb_framebuffer_size);
} }

View File

@ -3,7 +3,7 @@
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
namespace sim::graphics::resize namespace Sim::Graphics::Resize
{ {
void init(); void init();

View File

@ -9,14 +9,14 @@
#include "shader.hpp" #include "shader.hpp"
#include "window.hpp" #include "window.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static unsigned int prog_id; static unsigned int prog_id;
int shader::gl_tex_mat; int Shader::gl_tex_mat;
int shader::gl_model; int Shader::gl_model;
int shader::gl_camera; int Shader::gl_camera;
int shader::gl_projection; int Shader::gl_projection;
static int load_shader(const char* src, int type) static int load_shader(const char* src, int type)
{ {
@ -43,7 +43,7 @@ static std::string read_shader(const char* path)
return ss.str(); return ss.str();
} }
unsigned int shader::init_program() unsigned int Shader::init_program()
{ {
std::string shader_vsh = read_shader("../assets/shader/main.vsh"); std::string shader_vsh = read_shader("../assets/shader/main.vsh");
std::string shader_fsh = read_shader("../assets/shader/main.fsh"); std::string shader_fsh = read_shader("../assets/shader/main.fsh");
@ -63,7 +63,7 @@ unsigned int shader::init_program()
char infoLog[512]; char infoLog[512];
glGetProgramInfoLog(prog_id, 512, NULL, infoLog); glGetProgramInfoLog(prog_id, 512, NULL, infoLog);
std::cout << "Shader Link Error: " << infoLog << std::endl; std::cout << "Shader Link Error: " << infoLog << std::endl;
window::close(); Window::close();
return 0; return 0;
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::graphics::shader namespace Sim::Graphics::Shader
{ {
extern int gl_tex_mat; extern int gl_tex_mat;

View File

@ -16,22 +16,22 @@
#include "widget/clock.hpp" #include "widget/clock.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static GLMesh StaticMeshData; static GLMesh StaticMeshData;
static widget::Clock WidgetClock; static widget::Clock WidgetClock;
void ui::init() void UI::init()
{ {
Mesh m; Mesh m;
unsigned int handle = texture::handle_white; unsigned int handle = Texture::handle_white;
const unsigned int indices[] = {0, 1, 3, 0, 3, 2}; const unsigned int indices[] = {0, 1, 3, 0, 3, 2};
const arrays::vertex vertices[] = { const Arrays::vertex vertices[] = {
arrays::vertex(handle, {0, 0}, {-1, -1, 0, 1}, {0, 0, -1}), Arrays::vertex(handle, {0, 0}, {-1, -1, 0, 1}, {0, 0, -1}),
arrays::vertex(handle, {0, 1}, {-1, 1, 0, 1}, {0, 0, -1}), Arrays::vertex(handle, {0, 1}, {-1, 1, 0, 1}, {0, 0, -1}),
arrays::vertex(handle, {1, 0}, { 1, -1, 0, 1}, {0, 0, -1}), Arrays::vertex(handle, {1, 0}, { 1, -1, 0, 1}, {0, 0, -1}),
arrays::vertex(handle, {1, 1}, { 1, 1, 0, 1}, {0, 0, -1}), Arrays::vertex(handle, {1, 1}, { 1, 1, 0, 1}, {0, 0, -1}),
}; };
m.set_indices(indices, 6); m.set_indices(indices, 6);
@ -42,21 +42,21 @@ void ui::init()
StaticMeshData.colour_matrix = glm::scale(glm::mat4(1), glm::vec3(1) * 0.75f); StaticMeshData.colour_matrix = glm::scale(glm::mat4(1), glm::vec3(1) * 0.75f);
} }
void ui::update(double dt) void UI::update(double dt)
{ {
WidgetClock.update(dt); WidgetClock.update(dt);
} }
void ui::render() void UI::render()
{ {
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
glm::vec2 wsize(resize::get_size() / 2); glm::vec2 wsize(Resize::get_size() / 2);
glm::mat4 mat_projection = glm::mat4(1); glm::mat4 mat_projection = glm::mat4(1);
glm::mat4 mat_camera = glm::scale(glm::mat4(1), glm::vec3(1.0f / wsize * glm::vec2(1, -1), -1)); glm::mat4 mat_camera = glm::scale(glm::mat4(1), glm::vec3(1.0f / wsize * glm::vec2(1, -1), -1));
glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]); glUniformMatrix4fv(Shader::gl_projection, 1, false, &mat_projection[0][0]);
glUniformMatrix4fv(shader::gl_camera, 1, false, &mat_camera[0][0]); glUniformMatrix4fv(Shader::gl_camera, 1, false, &mat_camera[0][0]);
StaticMeshData.bind(); StaticMeshData.bind();
StaticMeshData.uniform(); StaticMeshData.uniform();

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::graphics::ui namespace Sim::Graphics::UI
{ {
void init(); void init();

View File

@ -16,13 +16,13 @@
#include "../resize.hpp" #include "../resize.hpp"
#include "../../system.hpp" #include "../../system.hpp"
using namespace sim::graphics::widget; using namespace Sim::Graphics::Widget;
void Clock::update(double dt) void Clock::update(double dt)
{ {
Mesh m; Mesh m;
double at = System::active.clock; double at = System::active.clock;
glm::vec2 wsize(resize::get_size() / 2); glm::vec2 wsize(Resize::get_size() / 2);
std::stringstream ss; std::stringstream ss;
int t_s = std::fmod(at, 60); int t_s = std::fmod(at, 60);
@ -38,7 +38,7 @@ void Clock::update(double dt)
data.bind(); data.bind();
data.model_matrix = glm::translate(glm::mat4(1), glm::vec3(-wsize + glm::vec2(2, 2), 0)); data.model_matrix = glm::translate(glm::mat4(1), glm::vec3(-wsize + glm::vec2(2, 2), 0));
data.colour_matrix = arrays::colour({1, 1, 1, 1}); data.colour_matrix = Arrays::colour({1, 1, 1, 1});
data.set(m, GL_DYNAMIC_DRAW); data.set(m, GL_DYNAMIC_DRAW);
} }

View File

@ -3,7 +3,7 @@
#include "../mesh/glmesh.hpp" #include "../mesh/glmesh.hpp"
namespace sim::graphics::widget namespace Sim::Graphics::widget
{ {
struct Clock struct Clock

View File

@ -27,7 +27,7 @@
#include "mesh/texture.hpp" #include "mesh/texture.hpp"
#include "ui.hpp" #include "ui.hpp"
using namespace sim::graphics; using namespace Sim::Graphics;
static GLFWwindow* win; static GLFWwindow* win;
static bool win_should_close = false; static bool win_should_close = false;
@ -39,7 +39,7 @@ static monitor::PrimaryLoop monitor_primary_loop;
static monitor::SecondaryLoop monitor_secondary_loop; static monitor::SecondaryLoop monitor_secondary_loop;
static monitor::Turbine monitor_turbine; static monitor::Turbine monitor_turbine;
glm::mat4 window::projection_matrix; glm::mat4 Window::projection_matrix;
void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{ {
@ -49,7 +49,7 @@ void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum s
} }
} }
void window::create() void Window::create()
{ {
glfwInit(); glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
@ -98,17 +98,17 @@ void window::create()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDebugMessageCallback(cb_debug_message, nullptr); glDebugMessageCallback(cb_debug_message, nullptr);
keyboard::init(); Keyboard::init();
mouse::init(); Mouse::init();
resize::init(); Resize::init();
texture::init(); Texture::init();
camera::init(); Camera::init();
font::init(); Font::init();
ui::init(); UI::init();
shader::init_program(); Shader::init_program();
sim::System& sys = sim::System::active; Sim::System& sys = Sim::System::active;
Mesh m, m2; Mesh m, m2;
m.load_model("../assets", "scene-baked.glb"); m.load_model("../assets", "scene-baked.glb");
@ -128,7 +128,7 @@ void window::create()
glViewport(0, 0, 800, 600); glViewport(0, 0, 800, 600);
} }
void window::update(double dt) void Window::update(double dt)
{ {
glfwPollEvents(); glfwPollEvents();
@ -138,15 +138,15 @@ void window::update(double dt)
monitor_secondary_loop.update(dt); monitor_secondary_loop.update(dt);
monitor_turbine.update(dt); monitor_turbine.update(dt);
ui::update(dt); UI::update(dt);
} }
void window::render() void Window::render()
{ {
glm::mat4 mat_camera = camera::get_matrix(); glm::mat4 mat_camera = Camera::get_matrix();
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), resize::get_aspect(), 0.01f, 20.f); glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), Resize::get_aspect(), 0.01f, 20.f);
glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]); glUniformMatrix4fv(Shader::gl_projection, 1, false, &mat_projection[0][0]);
glUniformMatrix4fv(shader::gl_camera, 1, false, &mat_camera[0][0]); glUniformMatrix4fv(Shader::gl_camera, 1, false, &mat_camera[0][0]);
projection_matrix = mat_projection; projection_matrix = mat_projection;
glClearColor(0, 0, 0, 1.0f); glClearColor(0, 0, 0, 1.0f);
@ -162,30 +162,30 @@ void window::render()
monitor_secondary_loop.render(); monitor_secondary_loop.render();
monitor_turbine.render(); monitor_turbine.render();
focus::render(); Focus::render();
ui::render(); UI::render();
focus::render_ui(); Focus::render_ui();
glfwSwapBuffers(win); glfwSwapBuffers(win);
} }
bool window::should_close() bool Window::should_close()
{ {
return win_should_close || glfwWindowShouldClose(win); return win_should_close || glfwWindowShouldClose(win);
} }
void window::close() void Window::close()
{ {
win_should_close = true; win_should_close = true;
} }
void window::destroy() void Window::destroy()
{ {
glfwDestroyWindow(win); glfwDestroyWindow(win);
glfwTerminate(); glfwTerminate();
} }
GLFWwindow* window::get_window() GLFWwindow* Window::get_window()
{ {
return win; return win;
} }

View File

@ -6,7 +6,7 @@
#include "../system.hpp" #include "../system.hpp"
namespace sim::graphics::window namespace Sim::Graphics::Window
{ {
extern glm::mat4 projection_matrix; extern glm::mat4 projection_matrix;

View File

@ -20,7 +20,7 @@
#include "system.hpp" #include "system.hpp"
#include "tests.hpp" #include "tests.hpp"
using namespace sim; using namespace Sim;
int main() int main()
{ {
@ -31,27 +31,27 @@ int main()
// tests::run(); // tests::run();
// return 0; // return 0;
graphics::window::create(); Graphics::Window::create();
long clock = util::time::get_now(); long clock = Util::Time::get_now();
double at = 0; double at = 0;
while(!graphics::window::should_close()) while(!Graphics::Window::should_close())
{ {
long now = util::time::get_now(); long now = Util::Time::get_now();
long passed = now - clock; long passed = now - clock;
double dt = (double)passed / 1e6; double dt = (double)passed / 1e6;
clock += passed; clock += passed;
at += dt * sim::System::active.speed; at += dt * Sim::System::active.speed;
sim::System::active.update(dt); Sim::System::active.update(dt);
graphics::camera::update(dt); Graphics::Camera::update(dt);
graphics::window::update(dt); Graphics::Window::update(dt);
graphics::focus::update(dt); Graphics::Focus::update(dt);
graphics::window::render(); Graphics::Window::render();
} }
graphics::window::destroy(); Graphics::Window::destroy();
} }

View File

@ -9,9 +9,9 @@
#include <vector> #include <vector>
#include <cstdlib> #include <cstdlib>
using namespace sim::reactor; using namespace Sim::Reactor;
sim::reactor::Reactor sim::reactor::builder(const int W, const int H, const double CW, const double CH, fuel::FuelRod fr, coolant::Vessel* v, const char** lines) Sim::Reactor::Reactor Sim::Reactor::Builder(const int W, const int H, const double CW, const double CH, fuel::FuelRod fr, coolant::Vessel* v, const char** lines)
{ {
std::vector<std::unique_ptr<Rod>> arr(W * H); std::vector<std::unique_ptr<Rod>> arr(W * H);
@ -49,7 +49,7 @@ sim::reactor::Reactor sim::reactor::builder(const int W, const int H, const doub
return Reactor(&arr[0], W, H, CW, CH); return Reactor(&arr[0], W, H, CW, CH);
} }
std::unique_ptr<Rod> sim::reactor::load_rod(const Json::Value& node, coolant::Vessel* v) std::unique_ptr<Rod> Sim::Reactor::load_rod(const Json::Value& node, coolant::Vessel* v)
{ {
int id = node["id"].asInt(); int id = node["id"].asInt();

View File

@ -8,10 +8,10 @@
#include <json/json.h> #include <json/json.h>
namespace sim::reactor namespace Sim::Reactor
{ {
Reactor builder(const int W, const int H, const double CW, const double CH, fuel::FuelRod fr, coolant::Vessel* v, const char** lines); Reactor Builder(const int W, const int H, const double CW, const double CH, fuel::FuelRod fr, coolant::Vessel* v, const char** lines);
std::unique_ptr<Rod> load_rod(const Json::Value& node, coolant::Vessel* v); std::unique_ptr<Rod> load_rod(const Json::Value& node, coolant::Vessel* v);
}; };

View File

@ -3,7 +3,7 @@
#include <cmath> #include <cmath>
using namespace sim::reactor::control; using namespace Sim::Reactor::Control;
constexpr double boron_density = 2340000; // g/m^3 constexpr double boron_density = 2340000; // g/m^3
constexpr double boron_molar_mass = 10; // g/mol constexpr double boron_molar_mass = 10; // g/mol

View File

@ -3,7 +3,7 @@
#include "../coolant/pipe.hpp" #include "../coolant/pipe.hpp"
namespace sim::reactor::control namespace Sim::Reactor::control
{ {
class BoronRod : public coolant::Pipe class BoronRod : public coolant::Pipe

View File

@ -3,7 +3,7 @@
#include <cmath> #include <cmath>
using namespace sim::reactor::control; using namespace Sim::Reactor::Control;
GraphiteRod::GraphiteRod(const Json::Value& node) : Rod(node) GraphiteRod::GraphiteRod(const Json::Value& node) : Rod(node)
{ {

View File

@ -3,10 +3,10 @@
#include "../rod.hpp" #include "../rod.hpp"
namespace sim::reactor::control namespace Sim::Reactor::control
{ {
class GraphiteRod : public sim::reactor::Rod class GraphiteRod : public Sim::Reactor::Rod
{ {
double inserted = 0; double inserted = 0;

View File

@ -1,7 +1,7 @@
#include "heater.hpp" #include "heater.hpp"
using namespace sim::reactor::coolant; using namespace Sim::Reactor::Coolant;
Heater::Heater(const Json::Value& node) : Rod(node) Heater::Heater(const Json::Value& node) : Rod(node)
{ {

View File

@ -3,10 +3,10 @@
#include "../rod.hpp" #include "../rod.hpp"
namespace sim::reactor::coolant namespace Sim::Reactor::coolant
{ {
class Heater : public sim::reactor::Rod class Heater : public Sim::Reactor::Rod
{ {
double rate = 0; double rate = 0;

View File

@ -2,7 +2,7 @@
#include "pipe.hpp" #include "pipe.hpp"
#include "../reactor.hpp" #include "../reactor.hpp"
using namespace sim::reactor::coolant; using namespace Sim::Reactor::Coolant;
Pipe::Pipe(coolant::Vessel* v) Pipe::Pipe(coolant::Vessel* v)
{ {
@ -35,7 +35,7 @@ void Pipe::update(double secs)
void Pipe::update_pipe(double secs) void Pipe::update_pipe(double secs)
{ {
sim::reactor::Reactor* r = (sim::reactor::Reactor*)reactor; Sim::Reactor::Reactor* r = (Sim::Reactor::Reactor*)reactor;
double m_heat = r->cell_width * r->cell_width * r->cell_height * 1e6; double m_heat = r->cell_width * r->cell_width * r->cell_height * 1e6;
vals[val_t::HEAT] = vessel->add_heat(m_heat, vals[val_t::HEAT]); vals[val_t::HEAT] = vessel->add_heat(m_heat, vals[val_t::HEAT]);

View File

@ -4,17 +4,17 @@
#include "vessel.hpp" #include "vessel.hpp"
#include "../rod.hpp" #include "../rod.hpp"
namespace sim::reactor::coolant namespace Sim::Reactor::coolant
{ {
class Pipe : public sim::reactor::Rod class Pipe : public Sim::Reactor::Rod
{ {
protected: protected:
coolant::Vessel* vessel; coolant::Vessel* vessel;
double steam; double steam;
virtual double get_k(sim::reactor::Rod::val_t type) const; virtual double get_k(Sim::Reactor::Rod::val_t type) const;
virtual const char* get_name() const { return "Coolant"; } virtual const char* get_name() const { return "Coolant"; }
virtual int get_id() const { return 2; } virtual int get_id() const { return 2; }

View File

@ -7,7 +7,7 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
using namespace sim::reactor::coolant; using namespace Sim::Reactor::Coolant;
constexpr static double calc_cylinder(double h, double d) constexpr static double calc_cylinder(double h, double d)
{ {
@ -16,15 +16,15 @@ constexpr static double calc_cylinder(double h, double d)
return M_PI * r * r * h * 1000; return M_PI * r * r * h * 1000;
} }
Vessel::Vessel(sim::coolant::Fluid fluid, double height, double diameter, double mass, double level, double bubble_hl) : Vessel::Vessel(Sim::Coolant::Fluid fluid, double height, double diameter, double mass, double level, double bubble_hl) :
sim::coolant::FluidHolder(fluid, calc_cylinder(height, diameter), mass), Sim::Coolant::FluidHolder(fluid, calc_cylinder(height, diameter), mass),
height(height), diameter(diameter), bubble_hl(bubble_hl) height(height), diameter(diameter), bubble_hl(bubble_hl)
{ {
this->level = level; this->level = level;
} }
Vessel::Vessel(const Json::Value& node) : Vessel::Vessel(const Json::Value& node) :
sim::coolant::FluidHolder(node), Sim::Coolant::FluidHolder(node),
height(node["height"].asDouble()), height(node["height"].asDouble()),
diameter(node["diameter"].asDouble()), diameter(node["diameter"].asDouble()),
bubble_hl(node["bubble_hl"].asDouble()) bubble_hl(node["bubble_hl"].asDouble())
@ -67,7 +67,7 @@ void Vessel::update(double secs)
steam_last = steam; steam_last = steam;
steam_suspended += diff; steam_suspended += diff;
steam_suspended *= reactor::fuel::half_life::get(secs, bubble_hl); steam_suspended *= Reactor::fuel::half_life::get(secs, bubble_hl);
if(steam_suspended < 0) if(steam_suspended < 0)
{ {

View File

@ -5,10 +5,10 @@
#include "../../coolant/fluid_holder.hpp" #include "../../coolant/fluid_holder.hpp"
namespace sim::reactor::coolant namespace Sim::Reactor::coolant
{ {
class Vessel : public sim::coolant::FluidHolder class Vessel : public Sim::Coolant::FluidHolder
{ {
public: public:
@ -18,7 +18,7 @@ public:
double steam_suspended = 0; // grams double steam_suspended = 0; // grams
Vessel(sim::coolant::Fluid fluid, double height, double diameter, double mass, double level, double bubble_hl); Vessel(Sim::Coolant::Fluid fluid, double height, double diameter, double mass, double level, double bubble_hl);
Vessel(const Json::Value& node); Vessel(const Json::Value& node);
double get_steam_suspended() const; // grams double get_steam_suspended() const; // grams

View File

@ -3,7 +3,7 @@
#include <cmath> #include <cmath>
using namespace sim::reactor::fuel; using namespace Sim::Reactor::Fuel;
constexpr double fuel_density = 19100000; // g/m^3 constexpr double fuel_density = 19100000; // g/m^3
constexpr double fuel_molar_mass = 238.029; // g/mol constexpr double fuel_molar_mass = 238.029; // g/mol

View File

@ -4,10 +4,10 @@
#include "sample.hpp" #include "sample.hpp"
#include "../rod.hpp" #include "../rod.hpp"
namespace sim::reactor::fuel namespace Sim::Reactor::fuel
{ {
class FuelRod : public sim::reactor::Rod class FuelRod : public Sim::Reactor::Rod
{ {
Sample s; Sample s;

View File

@ -3,7 +3,7 @@
#include <cmath> #include <cmath>
namespace sim::reactor::fuel::half_life namespace Sim::Reactor::fuel::half_life
{ {
const double Te_135 = 19; const double Te_135 = 19;

View File

@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
using namespace sim::reactor::fuel; using namespace Sim::Reactor::Fuel;
constexpr double NEUTRON_BG = 1e-30; constexpr double NEUTRON_BG = 1e-30;

View File

@ -5,14 +5,14 @@
#include <ostream> #include <ostream>
namespace sim::reactor::fuel namespace Sim::Reactor::fuel
{ {
class Sample class Sample
{ {
constexpr static const double Xe_135_M = 1e6; constexpr static const double Xe_135_M = 1e6;
sim::reactor::fuel::Waste waste; Sim::Reactor::fuel::Waste waste;
// mol // mol
double fuel = 0; double fuel = 0;

View File

@ -2,7 +2,7 @@
#include "waste.hpp" #include "waste.hpp"
#include "half_life.hpp" #include "half_life.hpp"
using namespace sim::reactor::fuel; using namespace Sim::Reactor::Fuel;
Waste::Waste(const Json::Value& node) Waste::Waste(const Json::Value& node)
{ {

View File

@ -3,7 +3,7 @@
#include <json/json.h> #include <json/json.h>
namespace sim::reactor::fuel namespace Sim::Reactor::fuel
{ {
class Waste class Waste

View File

@ -5,7 +5,7 @@
#include <algorithm> #include <algorithm>
using namespace sim::reactor; using namespace Sim::Reactor;
Reactor::Reactor(std::unique_ptr<Rod>* rods, int w, int h, double cw, double ch) : cell_width(cw), cell_height(ch), width(w), height(h), size(w * h) Reactor::Reactor(std::unique_ptr<Rod>* rods, int w, int h, double cw, double ch) : cell_width(cw), cell_height(ch), width(w), height(h), size(w * h)
{ {
@ -155,7 +155,7 @@ void Reactor::toggle_selected()
void Reactor::update_tile(double secs, int i, int x, int y) 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}}; int nb_lookup[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
std::shuffle(nb_lookup, &nb_lookup[3], util::random::gen); std::shuffle(nb_lookup, &nb_lookup[3], Util::Random::gen);
for(int j = 0; j < 4; j++) for(int j = 0; j < 4; j++)
{ {
@ -171,7 +171,7 @@ void Reactor::update_tile(double secs, int i, int x, int y)
void Reactor::update_interactions(int* rods_lookup, double secs) void Reactor::update_interactions(int* rods_lookup, double secs)
{ {
std::shuffle(rods_lookup, &rods_lookup[size - 1], util::random::gen); std::shuffle(rods_lookup, &rods_lookup[size - 1], Util::Random::gen);
for(int id = 0; id < size; id++) for(int id = 0; id < size; id++)
{ {

View File

@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
namespace sim::reactor namespace Sim::Reactor
{ {
struct Reactor struct Reactor

View File

@ -5,7 +5,7 @@
#include <cmath> #include <cmath>
using namespace sim::reactor; using namespace Sim::Reactor;
// Avogadro's Number // Avogadro's Number
static double N_a = 6.02214076e23; static double N_a = 6.02214076e23;
@ -69,22 +69,22 @@ glm::vec4 Rod::get_heat_colour() const
if(temp < 120) if(temp < 120)
{ {
return {0, util::map(temp, 0, 120, 0, 1), 1, 1}; return {0, Util::map(temp, 0, 120, 0, 1), 1, 1};
} }
if(temp < 240) if(temp < 240)
{ {
return {0, 1, util::map(temp, 120, 240, 1, 0), 1}; return {0, 1, Util::map(temp, 120, 240, 1, 0), 1};
} }
if(temp < 280) if(temp < 280)
{ {
return {util::map(temp, 240, 280, 0, 1), 1, 0, 1}; return {Util::map(temp, 240, 280, 0, 1), 1, 0, 1};
} }
if(temp < 320) if(temp < 320)
{ {
return {1, util::map(temp, 280, 320, 1, 0), 0, 1}; return {1, Util::map(temp, 280, 320, 1, 0), 0, 1};
} }
return {1, 0, 0, 1}; return {1, 0, 0, 1};
@ -97,13 +97,13 @@ double Rod::get_flux() const
double Rod::get_volume() const double Rod::get_volume() const
{ {
auto r = (sim::reactor::Reactor*)reactor; auto r = (Sim::Reactor::Reactor*)reactor;
return r->cell_width * r->cell_width * r->cell_height; return r->cell_width * r->cell_width * r->cell_height;
} }
double Rod::get_side_area() const double Rod::get_side_area() const
{ {
auto r = (sim::reactor::Reactor*)reactor; auto r = (Sim::Reactor::Reactor*)reactor;
return r->cell_width * r->cell_height; return r->cell_width * r->cell_height;
} }

View File

@ -7,7 +7,7 @@
#include <glm/vec4.hpp> #include <glm/vec4.hpp>
#include <memory> #include <memory>
namespace sim::reactor namespace Sim::Reactor
{ {
class Rod class Rod

View File

@ -10,9 +10,9 @@
#include "reactor/coolant/heater.hpp" #include "reactor/coolant/heater.hpp"
#include "graphics/camera.hpp" #include "graphics/camera.hpp"
using namespace sim; using namespace Sim;
sim::System System::active; Sim::System System::active;
System::System() System::System()
{ {
@ -38,42 +38,42 @@ System::System()
" C C C C " " C C C C "
}; };
vessel = std::make_unique<reactor::coolant::Vessel>(sim::coolant::WATER, 8, 10, 6e6, 5e5, 10); vessel = std::make_unique<Reactor::coolant::Vessel>(Sim::Coolant::WATER, 8, 10, 6e6, 5e5, 10);
reactor = std::make_unique<reactor::Reactor>(sim::reactor::builder(19, 19, 1.0 / 4.0, 4, reactor::fuel::FuelRod(0.2), vessel.get(), layout)); reactor = std::make_unique<Reactor::Reactor>(Sim::Reactor::Builder(19, 19, 1.0 / 4.0, 4, Reactor::fuel::FuelRod(0.2), vessel.get(), layout));
condenser = std::make_unique<coolant::Condenser>(sim::coolant::WATER, 6, 4, 3e6, 30000); condenser = std::make_unique<Coolant::Condenser>(Sim::Coolant::WATER, 6, 4, 3e6, 30000);
turbine = std::make_unique<electric::Turbine>(sim::coolant::WATER, condenser.get(), 6, 3, 2e6); turbine = std::make_unique<Electric::Turbine>(Sim::Coolant::WATER, condenser.get(), 6, 3, 2e6);
sink = std::make_unique<coolant::Sink>(sim::coolant::WATER, 11, 0, 0); sink = std::make_unique<Coolant::Sink>(Sim::Coolant::WATER, 11, 0, 0);
evaporator = std::make_unique<coolant::Evaporator>(sim::coolant::WATER, 2, 30, 0, 1000); evaporator = std::make_unique<Coolant::Evaporator>(Sim::Coolant::WATER, 2, 30, 0, 1000);
condenser_secondary = std::make_unique<coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000); condenser_secondary = std::make_unique<Coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000);
turbine_inlet_valve = std::make_unique<coolant::Valve>(vessel.get(), turbine.get(), 0, 0.5); turbine_inlet_valve = std::make_unique<Coolant::Valve>(vessel.get(), turbine.get(), 0, 0.5);
turbine_bypass_valve = std::make_unique<coolant::Valve>(vessel.get(), condenser.get(), 0, 0.5); turbine_bypass_valve = std::make_unique<Coolant::Valve>(vessel.get(), condenser.get(), 0, 0.5);
primary_pump = std::make_unique<coolant::Pump>(condenser.get(), vessel.get(), 1e5, 1, 1e5, 0.1, 10, coolant::Pump::mode_t::SRC, 35000); primary_pump = std::make_unique<Coolant::Pump>(condenser.get(), vessel.get(), 1e5, 1, 1e5, 0.1, 10, Coolant::Pump::mode_t::SRC, 35000);
secondary_pump = std::make_unique<coolant::Pump>(evaporator.get(), condenser_secondary.get(), 1e5, 1, 1e4, 0.1, 1, coolant::Pump::mode_t::NONE, 0); secondary_pump = std::make_unique<Coolant::Pump>(evaporator.get(), condenser_secondary.get(), 1e5, 1, 1e4, 0.1, 1, Coolant::Pump::mode_t::NONE, 0);
freight_pump = std::make_unique<coolant::Pump>(sink.get(), evaporator.get(), 1e5, 1, 1e4, 0.1, 10, coolant::Pump::mode_t::DST, 1e6); freight_pump = std::make_unique<Coolant::Pump>(sink.get(), evaporator.get(), 1e5, 1, 1e4, 0.1, 10, Coolant::Pump::mode_t::DST, 1e6);
} }
System::System(const Json::Value& node) System::System(const Json::Value& node)
{ {
clock = node["clock"].asDouble(); clock = node["clock"].asDouble();
vessel = std::make_unique<reactor::coolant::Vessel>(node["vessel"]); vessel = std::make_unique<Reactor::coolant::Vessel>(node["vessel"]);
reactor = std::make_unique<reactor::Reactor>(node["reactor"], vessel.get()); reactor = std::make_unique<Reactor::Reactor>(node["reactor"], vessel.get());
condenser = std::make_unique<coolant::Condenser>(node["condenser"]); condenser = std::make_unique<Coolant::Condenser>(node["condenser"]);
turbine = std::make_unique<electric::Turbine>(node["turbine"], condenser.get()); turbine = std::make_unique<Electric::Turbine>(node["turbine"], condenser.get());
evaporator = std::make_unique<coolant::Evaporator>(node["evaporator"]); evaporator = std::make_unique<Coolant::Evaporator>(node["evaporator"]);
sink = std::make_unique<coolant::Sink>(evaporator->fluid, 11, 0, 0); sink = std::make_unique<Coolant::Sink>(evaporator->fluid, 11, 0, 0);
condenser_secondary = std::make_unique<coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000); condenser_secondary = std::make_unique<Coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000);
turbine_inlet_valve = std::make_unique<coolant::Valve>(node["valve"]["turbine"]["inlet"], vessel.get(), turbine.get()); turbine_inlet_valve = std::make_unique<Coolant::Valve>(node["valve"]["turbine"]["inlet"], vessel.get(), turbine.get());
turbine_bypass_valve = std::make_unique<coolant::Valve>(node["valve"]["turbine"]["bypass"], vessel.get(), condenser.get()); turbine_bypass_valve = std::make_unique<Coolant::Valve>(node["valve"]["turbine"]["bypass"], vessel.get(), condenser.get());
primary_pump = std::make_unique<coolant::Pump>(node["pump"]["primary"], condenser.get(), vessel.get()); primary_pump = std::make_unique<Coolant::Pump>(node["pump"]["primary"], condenser.get(), vessel.get());
secondary_pump = std::make_unique<coolant::Pump>(node["pump"]["secondary"], evaporator.get(), condenser_secondary.get()); secondary_pump = std::make_unique<Coolant::Pump>(node["pump"]["secondary"], evaporator.get(), condenser_secondary.get());
freight_pump = std::make_unique<coolant::Pump>(node["pump"]["freight"], sink.get(), evaporator.get()); freight_pump = std::make_unique<Coolant::Pump>(node["pump"]["freight"], sink.get(), evaporator.get());
} }
void System::update(double dt) void System::update(double dt)
@ -117,7 +117,7 @@ System::operator Json::Value() const
void System::save() void System::save()
{ {
Json::Value root(active); Json::Value root(active);
root["camera"] = graphics::camera::serialize(); root["camera"] = Graphics::Camera::serialize();
Json::StreamWriterBuilder builder; Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None"; builder["commentStyle"] = "None";
@ -137,7 +137,7 @@ void System::load()
savefile.close(); savefile.close();
System sys(root); System sys(root);
graphics::camera::load(root["camera"]); Graphics::Camera::load(root["camera"]);
active = std::move(sys); active = std::move(sys);
} }

View File

@ -14,28 +14,28 @@
#include "coolant/sink.hpp" #include "coolant/sink.hpp"
#include "electric/turbine.hpp" #include "electric/turbine.hpp"
namespace sim namespace Sim
{ {
struct System struct System
{ {
static System active; static System active;
std::unique_ptr<sim::reactor::Reactor> reactor; std::unique_ptr<Sim::Reactor::Reactor> reactor;
std::unique_ptr<sim::reactor::coolant::Vessel> vessel; std::unique_ptr<Sim::Reactor::coolant::Vessel> vessel;
std::unique_ptr<sim::coolant::Sink> sink; std::unique_ptr<Sim::Coolant::Sink> sink;
std::unique_ptr<sim::coolant::Condenser> condenser; std::unique_ptr<Sim::Coolant::Condenser> condenser;
std::unique_ptr<sim::coolant::CondenserSecondary> condenser_secondary; std::unique_ptr<Sim::Coolant::CondenserSecondary> condenser_secondary;
std::unique_ptr<sim::coolant::Evaporator> evaporator; std::unique_ptr<Sim::Coolant::Evaporator> evaporator;
std::unique_ptr<sim::electric::Turbine> turbine; std::unique_ptr<Sim::Electric::Turbine> turbine;
std::unique_ptr<sim::coolant::Pump> primary_pump; std::unique_ptr<Sim::Coolant::Pump> primary_pump;
std::unique_ptr<sim::coolant::Pump> secondary_pump; std::unique_ptr<Sim::Coolant::Pump> secondary_pump;
std::unique_ptr<sim::coolant::Pump> freight_pump; std::unique_ptr<Sim::Coolant::Pump> freight_pump;
std::unique_ptr<sim::coolant::Valve> turbine_bypass_valve; std::unique_ptr<Sim::Coolant::Valve> turbine_bypass_valve;
std::unique_ptr<sim::coolant::Valve> turbine_inlet_valve; std::unique_ptr<Sim::Coolant::Valve> turbine_inlet_valve;
double speed = 1; double speed = 1;
double clock = 3600 * 12; double clock = 3600 * 12;

View File

@ -4,9 +4,9 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
using namespace sim; using namespace Sim;
void tests::run() void Tests::run()
{ {
// fluid_system fs(WATER, 1000, 10); // fluid_system fs(WATER, 1000, 10);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::tests namespace Sim::Tests
{ {
void run(); void run();

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::util::constants namespace Sim::Util::Constants
{ {
constexpr double R = 8.31446261815324; // molar gas constant, J/mol/K 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 constexpr double R_air = 0.2870500676; // specific gas constant of dry air, J/g/K

View File

@ -19,7 +19,7 @@ std::ostream& operator<<(std::ostream& o, const glm::vec<N, T>& v)
return o; return o;
} }
namespace sim::util namespace Sim::Util
{ {
constexpr double calc_work(double j, double mass) constexpr double calc_work(double j, double mass)

View File

@ -25,7 +25,7 @@
#include "pid.hpp" #include "pid.hpp"
using namespace std; using namespace std;
using namespace sim::util; using namespace Sim::Util;
PID::PID(const Json::Value& node) : PID::PID(const Json::Value& node) :
_max(node["max"].asDouble()), _max(node["max"].asDouble()),

View File

@ -24,7 +24,7 @@
#include <json/json.h> #include <json/json.h>
namespace sim::util namespace Sim::Util
{ {
class PID class PID

View File

@ -1,11 +1,11 @@
#include "random.hpp" #include "random.hpp"
using namespace sim::util; using namespace Sim::Util;
std::mt19937 random::gen; std::mt19937 Random::gen;
void random::init() void Random::init()
{ {
std::random_device rd; std::random_device rd;
gen = std::mt19937(rd()); gen = std::mt19937(rd());

View File

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

View File

@ -8,10 +8,10 @@
#include "time.hpp" #include "time.hpp"
using namespace sim::util; using namespace Sim::Util;
unsigned long time::get_now() unsigned long Time::get_now()
{ {
#ifdef _WIN32 #ifdef _WIN32
FILETIME ft; FILETIME ft;
@ -27,7 +27,7 @@ unsigned long time::get_now()
#endif #endif
} }
void time::sleep(unsigned long usec) void Time::sleep(unsigned long usec)
{ {
#ifdef _WIN32 #ifdef _WIN32
Sleep(usec / 1000); Sleep(usec / 1000);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace sim::util::time namespace Sim::Util::Time
{ {
unsigned long get_now(); unsigned long get_now();