refactor
This commit is contained in:
parent
e7f192e141
commit
106d9ce547
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::conversions::pressure
|
||||
namespace Sim::Conversions::Pressure
|
||||
{
|
||||
|
||||
constexpr double torr_to_pa(double t) { return t * 133.322; }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::conversions::temperature
|
||||
namespace Sim::Conversions::Temperature
|
||||
{
|
||||
|
||||
constexpr double k_to_c(double k) { return k - 273.15; }
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::coolant;
|
||||
using namespace Sim::Coolant;
|
||||
|
||||
constexpr static double calc_cylinder(double h, double d)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "fluid_holder.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class Condenser : public FluidHolder
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "../util/constants.hpp"
|
||||
#include "../system.hpp"
|
||||
|
||||
using namespace sim::coolant;
|
||||
using namespace Sim::Coolant;
|
||||
|
||||
CondenserSecondary::CondenserSecondary(Condenser* primary, Evaporator* source, double volume) :
|
||||
primary(primary), source(source), FluidHolder(primary->fluid, volume, 0)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "evaporator.hpp"
|
||||
#include "condenser.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class CondenserSecondary : public FluidHolder
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::coolant;
|
||||
using namespace Sim::Coolant;
|
||||
|
||||
constexpr static double calc_cylinder(double h, double d)
|
||||
{
|
||||
|
@ -41,15 +41,15 @@ void Evaporator::update(double dt)
|
|||
steam = 0;
|
||||
|
||||
double P = 10000; // Pa
|
||||
double K = conversions::temperature::c_to_k(heat); // K
|
||||
double R = util::constants::R; // J/K/mol
|
||||
double K = Conversions::Temperature::c_to_k(heat); // K
|
||||
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 n = (P * V_g) / (R * K); // mol
|
||||
|
||||
air = n * util::constants::M_air;
|
||||
air = n * Util::Constants::M_air;
|
||||
update_base(dt);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "fluid_holder.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class Evaporator : public FluidHolder
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "vapor_pressure.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
struct Fluid
|
||||
|
@ -14,9 +14,9 @@ struct Fluid
|
|||
const double gPmol; // g/mol
|
||||
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),
|
||||
vapor_pressure(vapor_pressure)
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <cmath>
|
||||
#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)
|
||||
{
|
||||
|
@ -98,19 +98,19 @@ double FluidHolder::calc_pressure(double heat, double volume, double mol)
|
|||
{
|
||||
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 V = volume * 0.001;
|
||||
|
||||
return (pressure * V) / (util::constants::R * heat);
|
||||
return (pressure * V) / (Util::Constants::R * heat);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -141,12 +141,12 @@ void FluidHolder::update_base(double secs)
|
|||
|
||||
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 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 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 n = (P * V_g) / (R * K) - n_g; // mol
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "fluid.hpp"
|
||||
#include "../conversions/temperature.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class FluidHolder
|
||||
|
@ -36,7 +36,7 @@ public:
|
|||
virtual double get_volume() const { return volume; } // litres
|
||||
virtual double get_level() const { return level; } // litres
|
||||
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_gas() const { return steam + air; } // grams
|
||||
virtual double get_air() const { return air; } // grams
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <iostream>
|
||||
#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) :
|
||||
src(src),
|
||||
|
@ -71,7 +71,7 @@ void Pump::update(double dt)
|
|||
break;
|
||||
}
|
||||
|
||||
velocity += util::calc_work(dt * power * max_power, mass);
|
||||
velocity += Util::calc_work(dt * power * max_power, mass);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -90,7 +90,7 @@ void Pump::update(double dt)
|
|||
double p_diff = (p_diff_1 + p_diff_2) / 2;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "fluid_holder.hpp"
|
||||
#include "../util/pid.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class Pump
|
||||
|
@ -12,7 +12,7 @@ class Pump
|
|||
FluidHolder* const src;
|
||||
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 velocity = 0; // m/s
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "sink.hpp"
|
||||
|
||||
using namespace sim::coolant;
|
||||
using namespace Sim::Coolant;
|
||||
|
||||
Sink::Sink(Fluid type, double heat, double pressure, double steam_density) :
|
||||
heat(heat),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// can kinda just do anything. for example, get rid of steam to the "outside",
|
||||
// or pump in new coolant.
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class Sink : public FluidHolder
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <cmath>
|
||||
#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)
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ void Valve::update(double dt)
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ void Valve::update(double dt)
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "fluid_holder.hpp"
|
||||
#include "../util/pid.hpp"
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
class Valve
|
||||
|
@ -21,7 +21,7 @@ class Valve
|
|||
bool auto_on = false;
|
||||
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:
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::coolant;
|
||||
using namespace Sim::Coolant;
|
||||
|
||||
double VaporPressure::calc_p(double t) const
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace sim::coolant
|
||||
namespace Sim::Coolant
|
||||
{
|
||||
|
||||
struct VaporPressure
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::electric;
|
||||
using namespace Sim::Electric;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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),
|
||||
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),
|
||||
length(node["length"].asDouble()),
|
||||
diameter(node["diameter"].asDouble()),
|
||||
friction(node["friction"].asDouble()),
|
||||
sim::coolant::FluidHolder(node)
|
||||
Sim::Coolant::FluidHolder(node)
|
||||
{
|
||||
velocity = node["velocity"].asDouble();
|
||||
phase = node["phase"].asDouble();
|
||||
|
@ -37,15 +37,15 @@ Turbine::Turbine(const Json::Value& node, coolant::Condenser* condenser) :
|
|||
void Turbine::update(double dt)
|
||||
{
|
||||
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
|
||||
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 v2 = util::mod((velocity - 3600) / 60 + 30, 60) - 30;
|
||||
double v2 = Util::mod((velocity - 3600) / 60 + 30, 60) - 30;
|
||||
double w2 = w * w * v2;
|
||||
|
||||
energy_generated = w2 * extra_mass;
|
||||
|
@ -69,13 +69,13 @@ double Turbine::get_rpm() const
|
|||
double Turbine::get_phase_diff() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
#include "../coolant/fluid_holder.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 diameter;
|
||||
|
@ -23,8 +23,8 @@ public:
|
|||
|
||||
bool breaker_closed = false;
|
||||
|
||||
Turbine(coolant::Fluid type, coolant::Condenser* condenser, double length, double diameter, double mass);
|
||||
Turbine(const Json::Value& node, coolant::Condenser* condenser);
|
||||
Turbine(Coolant::Fluid type, Coolant::Condenser* condenser, double length, double diameter, double mass);
|
||||
Turbine(const Json::Value& node, Coolant::Condenser* condenser);
|
||||
|
||||
void update(double dt);
|
||||
double get_rpm() const;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <glm/vec3.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static bool on_ground = false;
|
||||
static double yaw = 0, pitch = 0;
|
||||
|
@ -22,7 +22,7 @@ static glm::vec<3, double> velocity(0);
|
|||
static Mesh collision_scene;
|
||||
static glm::mat4 camera_mat;
|
||||
|
||||
Json::Value camera::serialize()
|
||||
Json::Value Camera::serialize()
|
||||
{
|
||||
Json::Value node;
|
||||
|
||||
|
@ -39,7 +39,7 @@ Json::Value camera::serialize()
|
|||
return node;
|
||||
}
|
||||
|
||||
void camera::load(const Json::Value& node)
|
||||
void Camera::load(const Json::Value& node)
|
||||
{
|
||||
on_ground = node["on_ground"].asBool();
|
||||
yaw = node["yaw"].asDouble();
|
||||
|
@ -52,7 +52,7 @@ void camera::load(const Json::Value& node)
|
|||
velocity[2] = node["velocity"]["z"].asDouble();
|
||||
}
|
||||
|
||||
void camera::rotate(double y, double p)
|
||||
void Camera::rotate(double y, double p)
|
||||
{
|
||||
yaw += y * 0.05;
|
||||
pitch -= p * 0.05;
|
||||
|
@ -61,43 +61,43 @@ void camera::rotate(double y, double p)
|
|||
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.y += yoff;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
void camera::init()
|
||||
void Camera::init()
|
||||
{
|
||||
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);
|
||||
double m = 30;
|
||||
|
||||
if(keyboard::is_pressed(GLFW_KEY_W))
|
||||
if(Keyboard::is_pressed(GLFW_KEY_W))
|
||||
off.y += 1;
|
||||
if(keyboard::is_pressed(GLFW_KEY_S))
|
||||
if(Keyboard::is_pressed(GLFW_KEY_S))
|
||||
off.y -= 1;
|
||||
if(keyboard::is_pressed(GLFW_KEY_A))
|
||||
if(Keyboard::is_pressed(GLFW_KEY_A))
|
||||
off.x -= 1;
|
||||
if(keyboard::is_pressed(GLFW_KEY_D))
|
||||
if(Keyboard::is_pressed(GLFW_KEY_D))
|
||||
off.x += 1;
|
||||
if(keyboard::is_pressed(GLFW_KEY_LEFT_SHIFT))
|
||||
if(Keyboard::is_pressed(GLFW_KEY_LEFT_SHIFT))
|
||||
m *= 1.5;
|
||||
if(off.x != 0 || off.y != 0)
|
||||
off = glm::normalize(off);
|
||||
|
@ -118,7 +118,7 @@ void camera::update(double 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;
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void camera::update(double dt)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "../system.hpp"
|
||||
|
||||
namespace sim::graphics::camera
|
||||
namespace Sim::Graphics::Camera
|
||||
{
|
||||
|
||||
glm::mat4 get_matrix();
|
||||
|
|
|
@ -14,18 +14,18 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static glm::vec<3, double> trigger_near;
|
||||
static glm::vec<3, double> trigger_far;
|
||||
|
||||
static std::vector<std::unique_ptr<focus::Focus>> stack;
|
||||
static std::unique_ptr<focus::Focus> state = nullptr;
|
||||
static std::vector<std::unique_ptr<Focus::Focus>> stack;
|
||||
static std::unique_ptr<Focus::Focus> state = nullptr;
|
||||
static bool mouse_visible = false;
|
||||
static bool mouse_locked = 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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -58,27 +58,27 @@ void focus::on_mouse_button(int button, int action, int mods)
|
|||
if(is_mouse_locked() && mouse_visible)
|
||||
{
|
||||
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::vec2 mouse(mx, wsize.y - my);
|
||||
|
||||
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_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);
|
||||
triggered = true;
|
||||
}
|
||||
|
||||
else if(!mouse_visible)
|
||||
{
|
||||
trigger_near = camera::get_pos();
|
||||
trigger_far = trigger_near + camera::get_normal();
|
||||
trigger_near = Camera::get_pos();
|
||||
trigger_far = trigger_near + Camera::get_normal();
|
||||
triggered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void focus::on_cursor_pos(double x, double y)
|
||||
void Focus::on_cursor_pos(double x, double y)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
glm::vec<3, double> focus::get_trigger_far()
|
||||
glm::vec<3, double> Focus::get_trigger_far()
|
||||
{
|
||||
return trigger_far;
|
||||
}
|
||||
|
||||
void focus::update(double dt)
|
||||
void Focus::update(double dt)
|
||||
{
|
||||
triggered = false;
|
||||
|
||||
|
@ -119,12 +119,12 @@ void focus::update(double dt)
|
|||
{
|
||||
if(c)
|
||||
{
|
||||
mouse::show_cursor();
|
||||
Mouse::show_cursor();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mouse::hide_cursor();
|
||||
Mouse::hide_cursor();
|
||||
}
|
||||
|
||||
mouse_visible = c;
|
||||
|
@ -136,7 +136,7 @@ void focus::update(double dt)
|
|||
}
|
||||
}
|
||||
|
||||
void focus::render_ui()
|
||||
void Focus::render_ui()
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ void focus::render_ui()
|
|||
}
|
||||
}
|
||||
|
||||
void focus::render()
|
||||
void Focus::render()
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
|
@ -152,12 +152,12 @@ void focus::render()
|
|||
}
|
||||
}
|
||||
|
||||
bool focus::is_focused()
|
||||
bool Focus::is_focused()
|
||||
{
|
||||
return (state != nullptr);
|
||||
}
|
||||
|
||||
void focus::clear_focus()
|
||||
void Focus::clear_focus()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void focus::clear_mouse_locked()
|
||||
void Focus::clear_mouse_locked()
|
||||
{
|
||||
mouse_locked = false;
|
||||
clear_focus();
|
||||
}
|
||||
|
||||
void focus::set(std::unique_ptr<Focus> f)
|
||||
void Focus::set(std::unique_ptr<Focus> f)
|
||||
{
|
||||
if(state != nullptr)
|
||||
{
|
||||
|
@ -189,7 +189,7 @@ void focus::set(std::unique_ptr<Focus> f)
|
|||
state = std::move(f);
|
||||
}
|
||||
|
||||
bool focus::is_triggered()
|
||||
bool Focus::is_triggered()
|
||||
{
|
||||
return triggered;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
namespace sim::graphics::focus
|
||||
namespace Sim::Graphics::Focus
|
||||
{
|
||||
|
||||
struct Focus
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "../camera.hpp"
|
||||
#include "../../system.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
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)
|
||||
{
|
||||
resize::toggle_fullscreen();
|
||||
Resize::toggle_fullscreen();
|
||||
}
|
||||
|
||||
if(action == GLFW_PRESS)
|
||||
|
@ -29,28 +29,28 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
|
|||
switch(key)
|
||||
{
|
||||
case GLFW_KEY_1:
|
||||
sim::System::active.speed = 1; // 1 s/s
|
||||
Sim::System::active.speed = 1; // 1 s/s
|
||||
break;
|
||||
case GLFW_KEY_2:
|
||||
sim::System::active.speed = 10; // 10 s/s
|
||||
Sim::System::active.speed = 10; // 10 s/s
|
||||
break;
|
||||
case GLFW_KEY_3:
|
||||
sim::System::active.speed = 60; // 1 min/s
|
||||
Sim::System::active.speed = 60; // 1 min/s
|
||||
break;
|
||||
case GLFW_KEY_4:
|
||||
sim::System::active.speed = 600; // 10 min/s
|
||||
Sim::System::active.speed = 600; // 10 min/s
|
||||
break;
|
||||
case GLFW_KEY_5:
|
||||
sim::System::active.speed = 3600; // 1 h/s
|
||||
Sim::System::active.speed = 3600; // 1 h/s
|
||||
break;
|
||||
case GLFW_KEY_6:
|
||||
sim::System::active.speed = 43200; // 12 h/s
|
||||
Sim::System::active.speed = 43200; // 12 h/s
|
||||
break;
|
||||
case GLFW_KEY_O:
|
||||
sim::System::save();
|
||||
Sim::System::save();
|
||||
break;
|
||||
case GLFW_KEY_L:
|
||||
sim::System::load();
|
||||
Sim::System::load();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -60,17 +60,17 @@ static void cb_keypress(GLFWwindow* win, int key, int sc, int action, int mods)
|
|||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
glfwSetCharCallback(win, cb_charcode);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::graphics::keyboard
|
||||
namespace Sim::Graphics::Keyboard
|
||||
{
|
||||
|
||||
void init();
|
||||
|
|
|
@ -7,20 +7,20 @@
|
|||
#include "../window.hpp"
|
||||
#include "../camera.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static double xpos = 0, ypos = 0;
|
||||
|
||||
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
|
||||
{
|
||||
camera::rotate(x - xpos, y - ypos);
|
||||
Camera::rotate(x - xpos, y - ypos);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
y = ypos;
|
||||
}
|
||||
|
||||
glm::vec2 mouse::get()
|
||||
glm::vec2 Mouse::get()
|
||||
{
|
||||
return {xpos, ypos};
|
||||
}
|
||||
|
||||
void mouse::show_cursor()
|
||||
void Mouse::show_cursor()
|
||||
{
|
||||
double x, y;
|
||||
GLFWwindow* win = window::get_window();
|
||||
GLFWwindow* win = Window::get_window();
|
||||
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
glfwGetCursorPos(win, &x, &y);
|
||||
cb_cursor_pos(win, x, y);
|
||||
}
|
||||
|
||||
void mouse::hide_cursor()
|
||||
void Mouse::hide_cursor()
|
||||
{
|
||||
double x, y;
|
||||
GLFWwindow* win = window::get_window();
|
||||
GLFWwindow* win = Window::get_window();
|
||||
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
glfwGetCursorPos(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);
|
||||
glfwSetMouseButtonCallback(win, cb_mouse_button);
|
||||
glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace sim::graphics::mouse
|
||||
namespace Sim::Graphics::Mouse
|
||||
{
|
||||
|
||||
void init();
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#include "locations.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::rotate(glm::mat4(1), glm::radians<float>(-90), glm::vec3(1, 0, 0)) *
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
namespace sim::graphics::locations
|
||||
namespace Sim::Graphics::Locations
|
||||
{
|
||||
|
||||
extern const glm::mat4 monitors[7];
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "arrays.hpp"
|
||||
#include "font.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void arrays::vertex_attrib_pointers()
|
||||
void Arrays::vertex_attrib_pointers()
|
||||
{
|
||||
vertex v;
|
||||
|
||||
|
@ -34,7 +34,7 @@ void arrays::vertex_attrib_pointers()
|
|||
glEnableVertexAttribArray(3);
|
||||
}
|
||||
|
||||
glm::mat4 arrays::colour(glm::vec4 c)
|
||||
glm::mat4 Arrays::colour(glm::vec4 c)
|
||||
{
|
||||
return glm::mat4({
|
||||
c.r, c.g, c.b, c.a,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
namespace sim::graphics::arrays
|
||||
namespace Sim::Graphics::Arrays
|
||||
{
|
||||
|
||||
struct vertex
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "arrays.hpp"
|
||||
#include "font.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
struct character
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ struct character
|
|||
|
||||
static character chars[128];
|
||||
|
||||
void font::init()
|
||||
void Font::init()
|
||||
{
|
||||
FT_Library ft;
|
||||
FT_Face face;
|
||||
|
@ -95,7 +95,7 @@ void font::init()
|
|||
|
||||
void Mesh::load_text(const char* text, double size)
|
||||
{
|
||||
std::vector<arrays::vertex> vertices;
|
||||
std::vector<Arrays::vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
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 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, 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, 1}, {ex, ey, 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, {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}));
|
||||
indices.insert(indices.end(), &index[0], &index[6]);
|
||||
|
||||
at += 4;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace sim::graphics::font
|
||||
namespace Sim::Graphics::Font
|
||||
{
|
||||
|
||||
void init();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "../shader.hpp"
|
||||
#include "../camera.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
constexpr static void init(GLMesh* m)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ constexpr static void init(GLMesh* m)
|
|||
glBindBuffer(GL_ARRAY_BUFFER, m->vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->ebo);
|
||||
|
||||
arrays::vertex_attrib_pointers();
|
||||
Arrays::vertex_attrib_pointers();
|
||||
}
|
||||
|
||||
GLMesh::GLMesh(GLMesh&& o)
|
||||
|
@ -59,8 +59,8 @@ void GLMesh::bind()
|
|||
|
||||
void GLMesh::uniform()
|
||||
{
|
||||
glUniformMatrix4fv(shader::gl_model, 1, false, &model_matrix[0][0]);
|
||||
glUniformMatrix4fv(shader::gl_tex_mat, 1, false, &colour_matrix[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_model, 1, false, &model_matrix[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_tex_mat, 1, false, &colour_matrix[0][0]);
|
||||
}
|
||||
|
||||
void GLMesh::set(const Mesh& m, int mode)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
namespace sim::graphics
|
||||
namespace Sim::Graphics
|
||||
{
|
||||
|
||||
struct GLMesh
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
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++)
|
||||
{
|
||||
arrays::vertex v = o.vertices[i];
|
||||
Arrays::vertex v = o.vertices[i];
|
||||
v.normal = mat3 * v.normal;
|
||||
v.pos = mat * v.pos;
|
||||
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.reserve(size);
|
||||
|
@ -98,10 +98,10 @@ bool ray_intersects_triangle(vec3 ray_origin,
|
|||
|
||||
bool Mesh::check_focus(double len) const
|
||||
{
|
||||
auto near = focus::get_trigger_near();
|
||||
auto far = focus::get_trigger_far();
|
||||
auto near = Focus::get_trigger_near();
|
||||
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
|
||||
|
|
|
@ -10,17 +10,17 @@
|
|||
#include "arrays.hpp"
|
||||
|
||||
|
||||
namespace sim::graphics
|
||||
namespace Sim::Graphics
|
||||
{
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
std::vector<arrays::vertex> vertices;
|
||||
std::vector<Arrays::vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
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 load_model(std::string base, std::string path);
|
||||
void load_model(std::string path) { load_model(".", path); }
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
#include "arrays.hpp"
|
||||
#include "texture.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
struct proc_state
|
||||
{
|
||||
unsigned int offset = 0;
|
||||
|
||||
std::string base;
|
||||
std::vector<arrays::vertex> vertices;
|
||||
std::vector<Arrays::vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
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::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)
|
||||
|
@ -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++)
|
||||
{
|
||||
arrays::vertex vertex;
|
||||
Arrays::vertex vertex;
|
||||
|
||||
auto [x, y, z] = mesh->mVertices[i];
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
@ -140,7 +140,7 @@ static unsigned int proc_embedded_texture(aiTexture* tex)
|
|||
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)
|
||||
|
|
|
@ -8,18 +8,18 @@
|
|||
|
||||
#include "texture.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
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};
|
||||
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)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ unsigned int texture::load_mem(const unsigned char* data, int width, int height,
|
|||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
unsigned int texture::load(std::string path)
|
||||
unsigned int Texture::load(std::string path)
|
||||
{
|
||||
const auto it = loaded.find(path);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace sim::graphics::texture
|
||||
namespace Sim::Graphics::Texture
|
||||
{
|
||||
|
||||
extern unsigned int handle_white;
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace sim::graphics::monitor;
|
||||
using namespace Sim::Graphics;
|
||||
using namespace Sim::Graphics::Monitor;
|
||||
|
||||
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())
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ struct core_monitor : public focus::Focus
|
|||
return;
|
||||
}
|
||||
|
||||
sim::System& sys = sim::System::active;
|
||||
Sim::System& sys = Sim::System::active;
|
||||
|
||||
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)
|
||||
{
|
||||
sim::System::active.reactor->add_rod_speed(y * 1e-6);
|
||||
Sim::System::active.reactor->add_rod_speed(y * 1e-6);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE)
|
||||
{
|
||||
focus::clear_focus();
|
||||
Focus::clear_focus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,21 +104,21 @@ Core::Core()
|
|||
|
||||
void Core::init()
|
||||
{
|
||||
mesh1.model_matrix = locations::monitors[2];
|
||||
mesh1.colour_matrix = arrays::colour({1, 1, 1, 1});
|
||||
mesh1.model_matrix = Locations::monitors[2];
|
||||
mesh1.colour_matrix = Arrays::colour({1, 1, 1, 1});
|
||||
|
||||
sim::graphics::Mesh rmesh;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
|
||||
rmesh.load_text("Reactor Core", 0.04);
|
||||
mesh1.bind();
|
||||
mesh1.set(rmesh, GL_STATIC_DRAW);
|
||||
|
||||
unsigned int indices[] = {0, 1, 3, 0, 3, 2};
|
||||
arrays::vertex vertices[] = {
|
||||
{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, {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}},
|
||||
Arrays::vertex vertices[] = {
|
||||
{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, {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}},
|
||||
};
|
||||
|
||||
rmesh.set_indices(indices, 6);
|
||||
|
@ -142,12 +142,12 @@ void Core::init()
|
|||
|
||||
void Core::update(double dt)
|
||||
{
|
||||
sim::System& sys = sim::System::active;
|
||||
Sim::System& sys = Sim::System::active;
|
||||
|
||||
if(m_monitor.check_focus())
|
||||
focus::set(std::make_unique<core_monitor>());
|
||||
Focus::set(std::make_unique<core_monitor>());
|
||||
if(m_joystick.check_focus())
|
||||
focus::set(std::make_unique<core_joystick>());
|
||||
Focus::set(std::make_unique<core_joystick>());
|
||||
if(m_scram.check_focus())
|
||||
sys.reactor->scram();
|
||||
if(m_buttons[0].check_focus())
|
||||
|
@ -170,7 +170,7 @@ void Core::update(double dt)
|
|||
|
||||
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 sx = 0.5 - (sys.reactor->width - 1) * step / 2.0;
|
||||
|
@ -195,7 +195,7 @@ void Core::render()
|
|||
double ox = sx + x * 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())
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
mesh2.model_matrix = mat;
|
||||
mesh2.colour_matrix = arrays::colour(colour_heat);
|
||||
mesh2.colour_matrix = Arrays::colour(colour_heat);
|
||||
mesh2.uniform();
|
||||
mesh2.render();
|
||||
|
||||
if(sys.reactor->cursor == i)
|
||||
{
|
||||
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.render();
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ void Core::render()
|
|||
if(r->selected)
|
||||
{
|
||||
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.render();
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ void Core::render()
|
|||
if(colour_spec[3] != 0)
|
||||
{
|
||||
mesh2.model_matrix = mat * mat_spec;
|
||||
mesh2.colour_matrix = arrays::colour(colour_spec);
|
||||
mesh2.colour_matrix = Arrays::colour(colour_spec);
|
||||
mesh2.uniform();
|
||||
mesh2.render();
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::monitor
|
||||
namespace Sim::Graphics::monitor
|
||||
{
|
||||
|
||||
class Core
|
||||
{
|
||||
sim::graphics::GLMesh mesh1, mesh2;
|
||||
Sim::Graphics::GLMesh mesh1, mesh2;
|
||||
|
||||
sim::graphics::Mesh m_monitor;
|
||||
sim::graphics::Mesh m_buttons[9];
|
||||
sim::graphics::Mesh m_joystick;
|
||||
sim::graphics::Mesh m_scram;
|
||||
Sim::Graphics::Mesh m_monitor;
|
||||
Sim::Graphics::Mesh m_buttons[9];
|
||||
Sim::Graphics::Mesh m_joystick;
|
||||
Sim::Graphics::Mesh m_scram;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace sim::graphics::monitor;
|
||||
using namespace Sim::Graphics;
|
||||
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)
|
||||
{
|
||||
focus::clear_focus();
|
||||
Focus::clear_focus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ PrimaryLoop::PrimaryLoop()
|
|||
|
||||
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));
|
||||
|
||||
mesh1.colour_matrix = mesh2.colour_matrix = {
|
||||
|
@ -67,7 +67,7 @@ void PrimaryLoop::init()
|
|||
};
|
||||
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
|
||||
ss << "Turbine Bypass Valve\n\n";
|
||||
ss << "Opened\nFlow\nSetpoint\n\n";
|
||||
|
@ -106,13 +106,13 @@ void PrimaryLoop::init()
|
|||
|
||||
void PrimaryLoop::update(double dt)
|
||||
{
|
||||
System& sys = sim::System::active;
|
||||
System& sys = Sim::System::active;
|
||||
clock_now += dt;
|
||||
|
||||
if(clock_at + 1.0/30.0 < clock_now)
|
||||
{
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
clock_at += 1.0/30.0;
|
||||
|
||||
ss << "\n\n";
|
||||
|
@ -159,9 +159,9 @@ void PrimaryLoop::update(double dt)
|
|||
}
|
||||
|
||||
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())
|
||||
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())
|
||||
sys.primary_pump->powered = !sys.primary_pump->powered;
|
||||
if(m_switch_inlet.check_focus())
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::monitor
|
||||
namespace Sim::Graphics::monitor
|
||||
{
|
||||
|
||||
class PrimaryLoop
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace sim::graphics::monitor;
|
||||
using namespace Sim::Graphics;
|
||||
using namespace Sim::Graphics::Monitor;
|
||||
|
||||
SecondaryLoop::SecondaryLoop()
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ SecondaryLoop::SecondaryLoop()
|
|||
|
||||
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));
|
||||
|
||||
mesh1.colour_matrix = mesh2.colour_matrix = {
|
||||
|
@ -33,7 +33,7 @@ void SecondaryLoop::init()
|
|||
};
|
||||
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
|
||||
ss << "Cooling Tower\n\n";
|
||||
ss << "Heat\nSteam\nPressure\nLevel\n\n";
|
||||
|
@ -62,13 +62,13 @@ void SecondaryLoop::init()
|
|||
|
||||
void SecondaryLoop::update(double dt)
|
||||
{
|
||||
System& sys = sim::System::active;
|
||||
System& sys = Sim::System::active;
|
||||
clock_now += dt;
|
||||
|
||||
if(clock_at + 1.0/30.0 < clock_now)
|
||||
{
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
clock_at += 1.0/30.0;
|
||||
|
||||
ss << "\n\n";
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::monitor
|
||||
namespace Sim::Graphics::monitor
|
||||
{
|
||||
|
||||
class SecondaryLoop
|
||||
{
|
||||
sim::graphics::GLMesh mesh1, mesh2;
|
||||
Sim::Graphics::GLMesh mesh1, mesh2;
|
||||
double clock_at = 0, clock_now = 0;
|
||||
|
||||
sim::graphics::GLMesh gm_switch_2;
|
||||
sim::graphics::GLMesh gm_switch_3;
|
||||
Sim::Graphics::GLMesh gm_switch_2;
|
||||
Sim::Graphics::GLMesh gm_switch_3;
|
||||
|
||||
sim::graphics::Mesh m_joystick_turbine_bypass;
|
||||
sim::graphics::Mesh m_joystick_turbine_inlet;
|
||||
sim::graphics::Mesh m_switch_2;
|
||||
sim::graphics::Mesh m_switch_3;
|
||||
Sim::Graphics::Mesh m_joystick_turbine_bypass;
|
||||
Sim::Graphics::Mesh m_joystick_turbine_inlet;
|
||||
Sim::Graphics::Mesh m_switch_2;
|
||||
Sim::Graphics::Mesh m_switch_3;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace sim::graphics::monitor;
|
||||
using namespace Sim::Graphics;
|
||||
using namespace Sim::Graphics::Monitor;
|
||||
|
||||
Turbine::Turbine()
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ Turbine::Turbine()
|
|||
|
||||
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 = {
|
||||
1, 1, 1, 1,
|
||||
0, 0, 0, 0,
|
||||
|
@ -31,7 +31,7 @@ void Turbine::init()
|
|||
};
|
||||
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh, rmesh2;
|
||||
Sim::Graphics::Mesh rmesh, rmesh2;
|
||||
|
||||
ss << "Turbine\n\n";
|
||||
ss << "Heat\nPressure\nSpeed\n\n";
|
||||
|
@ -56,13 +56,13 @@ void Turbine::init()
|
|||
|
||||
void Turbine::update(double dt)
|
||||
{
|
||||
System& sys = sim::System::active;
|
||||
System& sys = Sim::System::active;
|
||||
clock_now += dt;
|
||||
|
||||
if(clock_at + 1.0/30.0 < clock_now)
|
||||
{
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh, rmesh2;
|
||||
Sim::Graphics::Mesh rmesh, rmesh2;
|
||||
clock_at += 1.0/30.0;
|
||||
|
||||
ss << "\n\n";
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::monitor
|
||||
namespace Sim::Graphics::monitor
|
||||
{
|
||||
|
||||
class Turbine
|
||||
{
|
||||
sim::graphics::GLMesh mesh1, mesh2;
|
||||
Sim::Graphics::GLMesh mesh1, mesh2;
|
||||
double clock_at = 0, clock_now = 0;
|
||||
|
||||
sim::graphics::GLMesh gm_synchroscope_dial;
|
||||
sim::graphics::GLMesh gm_switch_breaker;
|
||||
sim::graphics::Mesh m_switch_breaker;
|
||||
Sim::Graphics::GLMesh gm_synchroscope_dial;
|
||||
Sim::Graphics::GLMesh gm_switch_breaker;
|
||||
Sim::Graphics::Mesh m_switch_breaker;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using namespace sim::graphics::monitor;
|
||||
using namespace Sim::Graphics::Monitor;
|
||||
|
||||
Vessel::Vessel()
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ Vessel::Vessel()
|
|||
|
||||
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));
|
||||
|
||||
mesh1.colour_matrix = mesh2.colour_matrix = {
|
||||
|
@ -32,7 +32,7 @@ void Vessel::init()
|
|||
};
|
||||
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
|
||||
ss << "Reactor Vessel\n\n";
|
||||
ss << "Heat\n";
|
||||
|
@ -54,8 +54,8 @@ void Vessel::init()
|
|||
void Vessel::update(double dt)
|
||||
{
|
||||
std::stringstream ss;
|
||||
sim::graphics::Mesh rmesh;
|
||||
sim::System& sys = sim::System::active;
|
||||
Sim::Graphics::Mesh rmesh;
|
||||
Sim::System& sys = Sim::System::active;
|
||||
clock_now += dt;
|
||||
|
||||
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;
|
||||
|
||||
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++)
|
||||
{
|
||||
sim::reactor::Rod* r = sys.reactor->rods[i].get();
|
||||
Sim::Reactor::Rod* r = sys.reactor->rods[i].get();
|
||||
|
||||
if(r->get_id() != 5)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto br = (sim::reactor::control::BoronRod*)r;
|
||||
auto br = (Sim::Reactor::control::BoronRod*)r;
|
||||
double v = br->get_inserted();
|
||||
|
||||
if(v > crod_max)
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::monitor
|
||||
namespace Sim::Graphics::monitor
|
||||
{
|
||||
|
||||
class Vessel
|
||||
{
|
||||
sim::graphics::GLMesh mesh1, mesh2;
|
||||
Sim::Graphics::GLMesh mesh1, mesh2;
|
||||
double clock_at = 0, clock_now = 0;
|
||||
|
||||
public:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "resize.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static bool is_fullscreen = false;
|
||||
|
||||
|
@ -17,19 +17,19 @@ static int win_restore_h;
|
|||
static int win_restore_x;
|
||||
static int win_restore_y;
|
||||
|
||||
glm::vec<2, int> resize::get_size()
|
||||
glm::vec<2, int> Resize::get_size()
|
||||
{
|
||||
return {win_w, win_h};
|
||||
}
|
||||
|
||||
float resize::get_aspect()
|
||||
float Resize::get_aspect()
|
||||
{
|
||||
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;
|
||||
|
||||
if(is_fullscreen)
|
||||
|
@ -57,9 +57,9 @@ static void cb_framebuffer_size(GLFWwindow* win, int w, int 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
namespace sim::graphics::resize
|
||||
namespace Sim::Graphics::Resize
|
||||
{
|
||||
|
||||
void init();
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
#include "shader.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static unsigned int prog_id;
|
||||
|
||||
int shader::gl_tex_mat;
|
||||
int shader::gl_model;
|
||||
int shader::gl_camera;
|
||||
int shader::gl_projection;
|
||||
int Shader::gl_tex_mat;
|
||||
int Shader::gl_model;
|
||||
int Shader::gl_camera;
|
||||
int Shader::gl_projection;
|
||||
|
||||
static int load_shader(const char* src, int type)
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ static std::string read_shader(const char* path)
|
|||
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_fsh = read_shader("../assets/shader/main.fsh");
|
||||
|
@ -63,7 +63,7 @@ unsigned int shader::init_program()
|
|||
char infoLog[512];
|
||||
glGetProgramInfoLog(prog_id, 512, NULL, infoLog);
|
||||
std::cout << "Shader Link Error: " << infoLog << std::endl;
|
||||
window::close();
|
||||
Window::close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::graphics::shader
|
||||
namespace Sim::Graphics::Shader
|
||||
{
|
||||
|
||||
extern int gl_tex_mat;
|
||||
|
|
|
@ -16,22 +16,22 @@
|
|||
|
||||
#include "widget/clock.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static GLMesh StaticMeshData;
|
||||
static widget::Clock WidgetClock;
|
||||
|
||||
void ui::init()
|
||||
void UI::init()
|
||||
{
|
||||
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 arrays::vertex vertices[] = {
|
||||
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, {1, 0}, { 1, -1, 0, 1}, {0, 0, -1}),
|
||||
arrays::vertex(handle, {1, 1}, { 1, 1, 0, 1}, {0, 0, -1}),
|
||||
const Arrays::vertex vertices[] = {
|
||||
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, {1, 0}, { 1, -1, 0, 1}, {0, 0, -1}),
|
||||
Arrays::vertex(handle, {1, 1}, { 1, 1, 0, 1}, {0, 0, -1}),
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void ui::update(double dt)
|
||||
void UI::update(double dt)
|
||||
{
|
||||
WidgetClock.update(dt);
|
||||
}
|
||||
|
||||
void ui::render()
|
||||
void UI::render()
|
||||
{
|
||||
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_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_camera, 1, false, &mat_camera[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_projection, 1, false, &mat_projection[0][0]);
|
||||
glUniformMatrix4fv(Shader::gl_camera, 1, false, &mat_camera[0][0]);
|
||||
|
||||
StaticMeshData.bind();
|
||||
StaticMeshData.uniform();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::graphics::ui
|
||||
namespace Sim::Graphics::UI
|
||||
{
|
||||
|
||||
void init();
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
#include "../resize.hpp"
|
||||
#include "../../system.hpp"
|
||||
|
||||
using namespace sim::graphics::widget;
|
||||
using namespace Sim::Graphics::Widget;
|
||||
|
||||
void Clock::update(double dt)
|
||||
{
|
||||
Mesh m;
|
||||
double at = System::active.clock;
|
||||
glm::vec2 wsize(resize::get_size() / 2);
|
||||
glm::vec2 wsize(Resize::get_size() / 2);
|
||||
std::stringstream ss;
|
||||
|
||||
int t_s = std::fmod(at, 60);
|
||||
|
@ -38,7 +38,7 @@ void Clock::update(double dt)
|
|||
|
||||
data.bind();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace sim::graphics::widget
|
||||
namespace Sim::Graphics::widget
|
||||
{
|
||||
|
||||
struct Clock
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "mesh/texture.hpp"
|
||||
#include "ui.hpp"
|
||||
|
||||
using namespace sim::graphics;
|
||||
using namespace Sim::Graphics;
|
||||
|
||||
static GLFWwindow* win;
|
||||
static bool win_should_close = false;
|
||||
|
@ -39,7 +39,7 @@ static monitor::PrimaryLoop monitor_primary_loop;
|
|||
static monitor::SecondaryLoop monitor_secondary_loop;
|
||||
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)
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ void GLAPIENTRY cb_debug_message(GLenum source, GLenum type, GLuint id, GLenum s
|
|||
}
|
||||
}
|
||||
|
||||
void window::create()
|
||||
void Window::create()
|
||||
{
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
|
@ -98,17 +98,17 @@ void window::create()
|
|||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDebugMessageCallback(cb_debug_message, nullptr);
|
||||
|
||||
keyboard::init();
|
||||
mouse::init();
|
||||
resize::init();
|
||||
texture::init();
|
||||
camera::init();
|
||||
font::init();
|
||||
ui::init();
|
||||
Keyboard::init();
|
||||
Mouse::init();
|
||||
Resize::init();
|
||||
Texture::init();
|
||||
Camera::init();
|
||||
Font::init();
|
||||
UI::init();
|
||||
|
||||
shader::init_program();
|
||||
Shader::init_program();
|
||||
|
||||
sim::System& sys = sim::System::active;
|
||||
Sim::System& sys = Sim::System::active;
|
||||
Mesh m, m2;
|
||||
|
||||
m.load_model("../assets", "scene-baked.glb");
|
||||
|
@ -128,7 +128,7 @@ void window::create()
|
|||
glViewport(0, 0, 800, 600);
|
||||
}
|
||||
|
||||
void window::update(double dt)
|
||||
void Window::update(double dt)
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
|
@ -138,15 +138,15 @@ void window::update(double dt)
|
|||
monitor_secondary_loop.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_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_camera, 1, false, &mat_camera[0][0]);
|
||||
glm::mat4 mat_camera = Camera::get_matrix();
|
||||
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_camera, 1, false, &mat_camera[0][0]);
|
||||
projection_matrix = mat_projection;
|
||||
|
||||
glClearColor(0, 0, 0, 1.0f);
|
||||
|
@ -162,30 +162,30 @@ void window::render()
|
|||
monitor_secondary_loop.render();
|
||||
monitor_turbine.render();
|
||||
|
||||
focus::render();
|
||||
ui::render();
|
||||
focus::render_ui();
|
||||
Focus::render();
|
||||
UI::render();
|
||||
Focus::render_ui();
|
||||
|
||||
glfwSwapBuffers(win);
|
||||
}
|
||||
|
||||
bool window::should_close()
|
||||
bool Window::should_close()
|
||||
{
|
||||
return win_should_close || glfwWindowShouldClose(win);
|
||||
}
|
||||
|
||||
void window::close()
|
||||
void Window::close()
|
||||
{
|
||||
win_should_close = true;
|
||||
}
|
||||
|
||||
void window::destroy()
|
||||
void Window::destroy()
|
||||
{
|
||||
glfwDestroyWindow(win);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
GLFWwindow* window::get_window()
|
||||
GLFWwindow* Window::get_window()
|
||||
{
|
||||
return win;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "../system.hpp"
|
||||
|
||||
namespace sim::graphics::window
|
||||
namespace Sim::Graphics::Window
|
||||
{
|
||||
|
||||
extern glm::mat4 projection_matrix;
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -20,7 +20,7 @@
|
|||
#include "system.hpp"
|
||||
#include "tests.hpp"
|
||||
|
||||
using namespace sim;
|
||||
using namespace Sim;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -31,27 +31,27 @@ int main()
|
|||
// tests::run();
|
||||
// return 0;
|
||||
|
||||
graphics::window::create();
|
||||
Graphics::Window::create();
|
||||
|
||||
long clock = util::time::get_now();
|
||||
long clock = Util::Time::get_now();
|
||||
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;
|
||||
double dt = (double)passed / 1e6;
|
||||
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::window::update(dt);
|
||||
graphics::focus::update(dt);
|
||||
graphics::window::render();
|
||||
Graphics::Camera::update(dt);
|
||||
Graphics::Window::update(dt);
|
||||
Graphics::Focus::update(dt);
|
||||
Graphics::Window::render();
|
||||
}
|
||||
|
||||
graphics::window::destroy();
|
||||
Graphics::Window::destroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
#include <vector>
|
||||
#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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
#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);
|
||||
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::reactor::control;
|
||||
using namespace Sim::Reactor::Control;
|
||||
|
||||
constexpr double boron_density = 2340000; // g/m^3
|
||||
constexpr double boron_molar_mass = 10; // g/mol
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "../coolant/pipe.hpp"
|
||||
|
||||
namespace sim::reactor::control
|
||||
namespace Sim::Reactor::control
|
||||
{
|
||||
|
||||
class BoronRod : public coolant::Pipe
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::reactor::control;
|
||||
using namespace Sim::Reactor::Control;
|
||||
|
||||
GraphiteRod::GraphiteRod(const Json::Value& node) : Rod(node)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#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;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "heater.hpp"
|
||||
|
||||
using namespace sim::reactor::coolant;
|
||||
using namespace Sim::Reactor::Coolant;
|
||||
|
||||
Heater::Heater(const Json::Value& node) : Rod(node)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#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;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "pipe.hpp"
|
||||
#include "../reactor.hpp"
|
||||
|
||||
using namespace sim::reactor::coolant;
|
||||
using namespace Sim::Reactor::Coolant;
|
||||
|
||||
Pipe::Pipe(coolant::Vessel* v)
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ void Pipe::update(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;
|
||||
|
||||
vals[val_t::HEAT] = vessel->add_heat(m_heat, vals[val_t::HEAT]);
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
#include "vessel.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:
|
||||
|
||||
coolant::Vessel* vessel;
|
||||
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 int get_id() const { return 2; }
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::reactor::coolant;
|
||||
using namespace Sim::Reactor::Coolant;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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),
|
||||
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),
|
||||
height(height), diameter(diameter), bubble_hl(bubble_hl)
|
||||
{
|
||||
this->level = level;
|
||||
}
|
||||
|
||||
Vessel::Vessel(const Json::Value& node) :
|
||||
sim::coolant::FluidHolder(node),
|
||||
Sim::Coolant::FluidHolder(node),
|
||||
height(node["height"].asDouble()),
|
||||
diameter(node["diameter"].asDouble()),
|
||||
bubble_hl(node["bubble_hl"].asDouble())
|
||||
|
@ -67,7 +67,7 @@ void Vessel::update(double secs)
|
|||
|
||||
steam_last = steam;
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
#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:
|
||||
|
||||
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
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);
|
||||
|
||||
double get_steam_suspended() const; // grams
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::reactor::fuel;
|
||||
using namespace Sim::Reactor::Fuel;
|
||||
|
||||
constexpr double fuel_density = 19100000; // g/m^3
|
||||
constexpr double fuel_molar_mass = 238.029; // g/mol
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#include "sample.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;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
namespace sim::reactor::fuel::half_life
|
||||
namespace Sim::Reactor::fuel::half_life
|
||||
{
|
||||
|
||||
const double Te_135 = 19;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim::reactor::fuel;
|
||||
using namespace Sim::Reactor::Fuel;
|
||||
|
||||
constexpr double NEUTRON_BG = 1e-30;
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
#include <ostream>
|
||||
|
||||
namespace sim::reactor::fuel
|
||||
namespace Sim::Reactor::fuel
|
||||
{
|
||||
|
||||
class Sample
|
||||
{
|
||||
constexpr static const double Xe_135_M = 1e6;
|
||||
|
||||
sim::reactor::fuel::Waste waste;
|
||||
Sim::Reactor::fuel::Waste waste;
|
||||
|
||||
// mol
|
||||
double fuel = 0;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "waste.hpp"
|
||||
#include "half_life.hpp"
|
||||
|
||||
using namespace sim::reactor::fuel;
|
||||
using namespace Sim::Reactor::Fuel;
|
||||
|
||||
Waste::Waste(const Json::Value& node)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace sim::reactor::fuel
|
||||
namespace Sim::Reactor::fuel
|
||||
{
|
||||
|
||||
class Waste
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#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)
|
||||
{
|
||||
|
@ -155,7 +155,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], util::random::gen);
|
||||
std::shuffle(nb_lookup, &nb_lookup[3], Util::Random::gen);
|
||||
|
||||
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)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace sim::reactor
|
||||
namespace Sim::Reactor
|
||||
{
|
||||
|
||||
struct Reactor
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
using namespace sim::reactor;
|
||||
using namespace Sim::Reactor;
|
||||
|
||||
// Avogadro's Number
|
||||
static double N_a = 6.02214076e23;
|
||||
|
@ -69,22 +69,22 @@ glm::vec4 Rod::get_heat_colour() const
|
|||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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};
|
||||
|
@ -97,13 +97,13 @@ double Rod::get_flux() 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <glm/vec4.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace sim::reactor
|
||||
namespace Sim::Reactor
|
||||
{
|
||||
|
||||
class Rod
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include "reactor/coolant/heater.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
|
||||
using namespace sim;
|
||||
using namespace Sim;
|
||||
|
||||
sim::System System::active;
|
||||
Sim::System System::active;
|
||||
|
||||
System::System()
|
||||
{
|
||||
|
@ -38,42 +38,42 @@ System::System()
|
|||
" C C C C "
|
||||
};
|
||||
|
||||
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));
|
||||
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);
|
||||
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));
|
||||
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);
|
||||
|
||||
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);
|
||||
condenser_secondary = std::make_unique<coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000);
|
||||
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);
|
||||
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_bypass_valve = std::make_unique<coolant::Valve>(vessel.get(), condenser.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);
|
||||
|
||||
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);
|
||||
freight_pump = std::make_unique<coolant::Pump>(sink.get(), evaporator.get(), 1e5, 1, 1e4, 0.1, 10, coolant::Pump::mode_t::DST, 1e6);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
clock = node["clock"].asDouble();
|
||||
|
||||
vessel = std::make_unique<reactor::coolant::Vessel>(node["vessel"]);
|
||||
reactor = std::make_unique<reactor::Reactor>(node["reactor"], vessel.get());
|
||||
condenser = std::make_unique<coolant::Condenser>(node["condenser"]);
|
||||
turbine = std::make_unique<electric::Turbine>(node["turbine"], condenser.get());
|
||||
vessel = std::make_unique<Reactor::coolant::Vessel>(node["vessel"]);
|
||||
reactor = std::make_unique<Reactor::Reactor>(node["reactor"], vessel.get());
|
||||
condenser = std::make_unique<Coolant::Condenser>(node["condenser"]);
|
||||
turbine = std::make_unique<Electric::Turbine>(node["turbine"], condenser.get());
|
||||
|
||||
evaporator = std::make_unique<coolant::Evaporator>(node["evaporator"]);
|
||||
sink = std::make_unique<coolant::Sink>(evaporator->fluid, 11, 0, 0);
|
||||
condenser_secondary = std::make_unique<coolant::CondenserSecondary>(condenser.get(), evaporator.get(), 1000);
|
||||
evaporator = std::make_unique<Coolant::Evaporator>(node["evaporator"]);
|
||||
sink = std::make_unique<Coolant::Sink>(evaporator->fluid, 11, 0, 0);
|
||||
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_bypass_valve = std::make_unique<coolant::Valve>(node["valve"]["turbine"]["bypass"], vessel.get(), condenser.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());
|
||||
|
||||
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());
|
||||
freight_pump = std::make_unique<coolant::Pump>(node["pump"]["freight"], sink.get(), evaporator.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());
|
||||
freight_pump = std::make_unique<Coolant::Pump>(node["pump"]["freight"], sink.get(), evaporator.get());
|
||||
}
|
||||
|
||||
void System::update(double dt)
|
||||
|
@ -117,7 +117,7 @@ System::operator Json::Value() const
|
|||
void System::save()
|
||||
{
|
||||
Json::Value root(active);
|
||||
root["camera"] = graphics::camera::serialize();
|
||||
root["camera"] = Graphics::Camera::serialize();
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
|
@ -137,7 +137,7 @@ void System::load()
|
|||
savefile.close();
|
||||
|
||||
System sys(root);
|
||||
graphics::camera::load(root["camera"]);
|
||||
Graphics::Camera::load(root["camera"]);
|
||||
active = std::move(sys);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,28 +14,28 @@
|
|||
#include "coolant/sink.hpp"
|
||||
#include "electric/turbine.hpp"
|
||||
|
||||
namespace sim
|
||||
namespace Sim
|
||||
{
|
||||
|
||||
struct System
|
||||
{
|
||||
static System active;
|
||||
|
||||
std::unique_ptr<sim::reactor::Reactor> reactor;
|
||||
std::unique_ptr<sim::reactor::coolant::Vessel> vessel;
|
||||
std::unique_ptr<Sim::Reactor::Reactor> reactor;
|
||||
std::unique_ptr<Sim::Reactor::coolant::Vessel> vessel;
|
||||
|
||||
std::unique_ptr<sim::coolant::Sink> sink;
|
||||
std::unique_ptr<sim::coolant::Condenser> condenser;
|
||||
std::unique_ptr<sim::coolant::CondenserSecondary> condenser_secondary;
|
||||
std::unique_ptr<sim::coolant::Evaporator> evaporator;
|
||||
std::unique_ptr<sim::electric::Turbine> turbine;
|
||||
std::unique_ptr<Sim::Coolant::Sink> sink;
|
||||
std::unique_ptr<Sim::Coolant::Condenser> condenser;
|
||||
std::unique_ptr<Sim::Coolant::CondenserSecondary> condenser_secondary;
|
||||
std::unique_ptr<Sim::Coolant::Evaporator> evaporator;
|
||||
std::unique_ptr<Sim::Electric::Turbine> turbine;
|
||||
|
||||
std::unique_ptr<sim::coolant::Pump> primary_pump;
|
||||
std::unique_ptr<sim::coolant::Pump> secondary_pump;
|
||||
std::unique_ptr<sim::coolant::Pump> freight_pump;
|
||||
std::unique_ptr<Sim::Coolant::Pump> primary_pump;
|
||||
std::unique_ptr<Sim::Coolant::Pump> secondary_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_inlet_valve;
|
||||
std::unique_ptr<Sim::Coolant::Valve> turbine_bypass_valve;
|
||||
std::unique_ptr<Sim::Coolant::Valve> turbine_inlet_valve;
|
||||
|
||||
double speed = 1;
|
||||
double clock = 3600 * 12;
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace sim;
|
||||
using namespace Sim;
|
||||
|
||||
void tests::run()
|
||||
void Tests::run()
|
||||
{
|
||||
// fluid_system fs(WATER, 1000, 10);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::tests
|
||||
namespace Sim::Tests
|
||||
{
|
||||
|
||||
void run();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::util::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
|
||||
|
|
|
@ -19,7 +19,7 @@ std::ostream& operator<<(std::ostream& o, const glm::vec<N, T>& v)
|
|||
return o;
|
||||
}
|
||||
|
||||
namespace sim::util
|
||||
namespace Sim::Util
|
||||
{
|
||||
|
||||
constexpr double calc_work(double j, double mass)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "pid.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace sim::util;
|
||||
using namespace Sim::Util;
|
||||
|
||||
PID::PID(const Json::Value& node) :
|
||||
_max(node["max"].asDouble()),
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace sim::util
|
||||
namespace Sim::Util
|
||||
{
|
||||
|
||||
class PID
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
#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;
|
||||
gen = std::mt19937(rd());
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <random>
|
||||
|
||||
namespace sim::util::random
|
||||
namespace Sim::Util::Random
|
||||
{
|
||||
|
||||
extern std::mt19937 gen;
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
#include "time.hpp"
|
||||
|
||||
using namespace sim::util;
|
||||
using namespace Sim::Util;
|
||||
|
||||
|
||||
unsigned long time::get_now()
|
||||
unsigned long Time::get_now()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILETIME ft;
|
||||
|
@ -27,7 +27,7 @@ unsigned long time::get_now()
|
|||
#endif
|
||||
}
|
||||
|
||||
void time::sleep(unsigned long usec)
|
||||
void Time::sleep(unsigned long usec)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(usec / 1000);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace sim::util::time
|
||||
namespace Sim::Util::Time
|
||||
{
|
||||
|
||||
unsigned long get_now();
|
||||
|
|
Loading…
Reference in New Issue