loading savefiles now works :)

This commit is contained in:
Jay Robson 2024-02-14 12:19:19 +11:00
parent 19a7802823
commit 1d797bcc4d
5 changed files with 37 additions and 31 deletions

View File

@ -3,6 +3,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "camera.hpp" #include "camera.hpp"
#include "mesh/mesh.hpp"
#include "input/keyboard.hpp" #include "input/keyboard.hpp"
#include "../util/math.hpp" #include "../util/math.hpp"
@ -18,6 +19,7 @@ static bool on_ground = false;
static double yaw = 0, pitch = 0; static double yaw = 0, pitch = 0;
static glm::vec<3, double> pos(0, 0, 2); static glm::vec<3, double> pos(0, 0, 2);
static glm::vec<3, double> velocity(0); static glm::vec<3, double> velocity(0);
static mesh collision_scene;
static glm::mat4 camera_mat; static glm::mat4 camera_mat;
Json::Value camera::serialize() Json::Value camera::serialize()
@ -77,6 +79,11 @@ glm::vec<3, double> camera::get_pos()
return pos; return pos;
} }
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); glm::vec<2, double> off(0, 0);
@ -119,8 +126,8 @@ void camera::update(double dt)
glm::vec<3, double> normal_last(0); glm::vec<3, double> normal_last(0);
glm::vec<3, double> velocity2; glm::vec<3, double> velocity2;
velocity2 = system::active.scene.calc_intersect(pos, velocity * dt, normal_last); velocity2 = collision_scene.calc_intersect(pos, velocity * dt, normal_last);
velocity2 = system::active.scene.calc_intersect(pos + glm::vec<3, double>(0, 0, -1.5), velocity2, normal_last) / dt; velocity2 = collision_scene.calc_intersect(pos + glm::vec<3, double>(0, 0, -1.5), velocity2, normal_last) / dt;
pos += velocity2 * dt; pos += velocity2 * dt;
on_ground = ((velocity * dt / dt).z != velocity2.z); on_ground = ((velocity * dt / dt).z != velocity2.z);

View File

@ -16,6 +16,7 @@ glm::vec<3, double> get_pos();
Json::Value serialize(); Json::Value serialize();
void load(const Json::Value& node); void load(const Json::Value& node);
void init();
void rotate(double pitch, double yaw); void rotate(double pitch, double yaw);
void move(double x, double y, double z); void move(double x, double y, double z);
void update(double dt); void update(double dt);

View File

@ -30,11 +30,11 @@ using namespace sim::graphics;
static GLFWwindow* win; static GLFWwindow* win;
static bool win_should_close = false; static bool win_should_close = false;
static glmesh MeshScene; static glmesh mesh_scene;
static monitor::vessel MonitorVessel; static monitor::vessel monitor_vessel;
static monitor::core MonitorCore; static monitor::core monitor_core;
static monitor::primary_loop MonitorPrimaryLoop; static monitor::primary_loop monitor_primary_loop;
static monitor::secondary_loop MonitorSecondaryLoop; static monitor::secondary_loop monitor_secondary_loop;
glm::mat4 window::projection_matrix; glm::mat4 window::projection_matrix;
@ -99,6 +99,7 @@ void window::create()
mouse::init(); mouse::init();
resize::init(); resize::init();
texture::init(); texture::init();
camera::init();
font::init(); font::init();
ui::init(); ui::init();
@ -108,17 +109,13 @@ void window::create()
mesh m; mesh m;
m.load_model("../assets", "scene-baked.glb"); m.load_model("../assets", "scene-baked.glb");
MeshScene.bind(); mesh_scene.bind();
MeshScene.set(m, GL_STATIC_DRAW); mesh_scene.set(m, GL_STATIC_DRAW);
sys.scene.load_model("../assets/model", "scene_collisions.stl"); monitor_core.init();
// MeshCollisionScene.bind(); monitor_vessel.init();
// MeshCollisionScene.set(sys.scene.to_lines(), GL_STATIC_DRAW); monitor_primary_loop.init();
monitor_secondary_loop.init();
MonitorCore.init();
MonitorVessel.init();
MonitorPrimaryLoop.init();
MonitorSecondaryLoop.init();
glfwShowWindow(win); glfwShowWindow(win);
glViewport(0, 0, 800, 600); glViewport(0, 0, 800, 600);
@ -128,10 +125,10 @@ void window::update(double dt)
{ {
glfwPollEvents(); glfwPollEvents();
MonitorCore.update(dt); monitor_core.update(dt);
MonitorVessel.update(dt); monitor_vessel.update(dt);
MonitorPrimaryLoop.update(dt); monitor_primary_loop.update(dt);
MonitorSecondaryLoop.update(dt); monitor_secondary_loop.update(dt);
ui::update(dt); ui::update(dt);
} }
@ -147,14 +144,14 @@ void window::render()
glClearColor(0, 0, 0, 1.0f); glClearColor(0, 0, 0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
MeshScene.bind(); mesh_scene.bind();
MeshScene.uniform(); mesh_scene.uniform();
MeshScene.render(); mesh_scene.render();
MonitorCore.render(); monitor_core.render();
MonitorVessel.render(); monitor_vessel.render();
MonitorPrimaryLoop.render(); monitor_primary_loop.render();
MonitorSecondaryLoop.render(); monitor_secondary_loop.render();
ui::render(); ui::render();

View File

@ -254,7 +254,10 @@ reactor::reactor(const Json::Value& node, coolant::vessel* v) :
for(int i = 0; i < size; i++) for(int i = 0; i < size; i++)
{ {
rods.push_back(load_rod(j_rods[i], v)); std::unique_ptr<rod> r = load_rod(j_rods[i], v);
r->reactor = this;
rods.push_back(std::move(r));
} }
} }

View File

@ -13,7 +13,6 @@
#include "coolant/evaporator.hpp" #include "coolant/evaporator.hpp"
#include "coolant/sink.hpp" #include "coolant/sink.hpp"
#include "electric/turbine.hpp" #include "electric/turbine.hpp"
#include "graphics/mesh/mesh.hpp"
namespace sim namespace sim
{ {
@ -38,7 +37,6 @@ struct system
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;
sim::graphics::mesh scene;
double speed = 1; double speed = 1;
double clock = 0; double clock = 0;