better error handling, better font rendering; reactor copy
This commit is contained in:
parent
18e0cffa93
commit
18e541ba1c
|
@ -8,6 +8,7 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "mesh.hpp"
|
||||
#include "arrays.hpp"
|
||||
#include "font.hpp"
|
||||
|
||||
|
@ -89,7 +90,7 @@ void font::init()
|
|||
}
|
||||
}
|
||||
|
||||
void font::generate(mesh& m, const char* text, double size)
|
||||
void mesh::load_text(const char* text, double size)
|
||||
{
|
||||
std::vector<arrays::vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
@ -135,7 +136,7 @@ void font::generate(mesh& m, const char* text, double size)
|
|||
x += ch.advance * size;
|
||||
}
|
||||
|
||||
m.set_vertices(&vertices[0], vertices.size(), GL_DYNAMIC_DRAW);
|
||||
m.set_indices(&indices[0], indices.size(), GL_DYNAMIC_DRAW);
|
||||
set_vertices(&vertices[0], vertices.size(), GL_DYNAMIC_DRAW);
|
||||
set_indices(&indices[0], indices.size(), GL_DYNAMIC_DRAW);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,15 +10,6 @@ namespace sim::graphics::font
|
|||
{
|
||||
|
||||
void init();
|
||||
void generate(mesh& m, const char* text, double size);
|
||||
|
||||
template <class T>
|
||||
void generate(mesh& m, const char* header, T* item, double size)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << header << *item;
|
||||
generate(m, ss.str().c_str(), size);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#include <string>
|
||||
|
||||
#include "arrays.hpp"
|
||||
|
||||
#include <glm/matrix.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace sim::graphics
|
||||
{
|
||||
|
@ -26,7 +28,16 @@ struct mesh
|
|||
void set_vertices(const arrays::vertex* data, size_t size, int mode);
|
||||
void set_indices(const unsigned int* data, size_t size, int mode);
|
||||
void load_model(std::string base, std::string path);
|
||||
void load_text(const char* text, double size);
|
||||
void render();
|
||||
|
||||
template <class T>
|
||||
void load_text(const char* header, T* item, double size)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << header << *item;
|
||||
load_text(ss.str().c_str(), size);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -56,7 +56,20 @@ void window::create()
|
|||
|
||||
if(err != GLEW_OK)
|
||||
{
|
||||
std::cout << "GLEW Init Failed: " << glewGetErrorString(err) << "\n";
|
||||
std::cerr << "GLEW Init Failed: " << glewGetErrorString(err) << "\n";
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!glGetTextureHandleARB || !glMakeTextureHandleResidentARB)
|
||||
{
|
||||
std::cerr << "Fatal: Bindless textures not supported\n";
|
||||
|
||||
if(!glGetTextureHandleARB)
|
||||
std::cerr << " Missing: glGetTextureHandleARB\n";
|
||||
if(!glMakeTextureHandleResidentARB)
|
||||
std::cerr << " Missing: glMakeTextureHandleResidentARB\n";
|
||||
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
@ -130,14 +143,10 @@ void window::create()
|
|||
|
||||
void window::loop()
|
||||
{
|
||||
MeshText.bind();
|
||||
font::generate(MeshText, "Reactor Core\n\nTODO", 0.1);
|
||||
MeshMon1.bind();
|
||||
font::generate(MeshMon1, "Reactor Vessel\n\n", parts::vessel, 0.1);
|
||||
MeshMon2.bind();
|
||||
font::generate(MeshMon2, "Steam Valve\n\n", parts::valve, 0.1);
|
||||
MeshMon3.bind();
|
||||
font::generate(MeshMon3, "Coolant Pump\n\n", parts::pump, 0.1);
|
||||
MeshText.bind(); MeshText.load_text("Reactor Core\n\nTODO", 0.1);
|
||||
MeshMon1.bind(); MeshMon1.load_text("Reactor Vessel\n\n", parts::vessel, 0.1);
|
||||
MeshMon2.bind(); MeshMon2.load_text("Steam Valve\n\n", parts::valve, 0.1);
|
||||
MeshMon3.bind(); MeshMon3.load_text("Coolant Pump\n\n", parts::pump, 0.1);
|
||||
|
||||
glm::mat4 mat_projection = glm::perspective(glm::radians(80.0f), resize::get_aspect(), 0.01f, 20.f);
|
||||
glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]);
|
||||
|
@ -145,16 +154,11 @@ void window::loop()
|
|||
glClearColor(0, 0, 0, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
MeshScene.bind();
|
||||
MeshScene.render();
|
||||
MeshText.bind();
|
||||
MeshText.render();
|
||||
MeshMon1.bind();
|
||||
MeshMon1.render();
|
||||
MeshMon2.bind();
|
||||
MeshMon2.render();
|
||||
MeshMon3.bind();
|
||||
MeshMon3.render();
|
||||
MeshScene.bind(); MeshScene.render();
|
||||
MeshText.bind(); MeshText.render();
|
||||
MeshMon1.bind(); MeshMon1.render();
|
||||
MeshMon2.bind(); MeshMon2.render();
|
||||
MeshMon3.bind(); MeshMon3.render();
|
||||
|
||||
glfwSwapBuffers(win);
|
||||
glfwPollEvents();
|
||||
|
|
|
@ -17,6 +17,7 @@ class control_rod : public sim::reactor::coolant::pipe
|
|||
virtual void display(std::ostream& o) const;
|
||||
|
||||
virtual const char* get_name() const { return "Control Rod"; }
|
||||
virtual rod* clone() const { return new control_rod(*this); };
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class graphite_rod : public sim::reactor::rod
|
|||
virtual void display(std::ostream& o) const;
|
||||
|
||||
virtual const char* get_name() const { return "Graphite Rod"; }
|
||||
virtual rod* clone() const { return new graphite_rod(*this); };
|
||||
virtual double get_k(val_t type) const;
|
||||
|
||||
public:
|
||||
|
|
|
@ -14,6 +14,7 @@ class heater : public sim::reactor::rod
|
|||
|
||||
virtual const char* get_name() const { return "Heater"; }
|
||||
virtual double get_k(val_t type) const { return 0.5; }
|
||||
virtual rod* clone() const { return new heater(*this); };
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ protected:
|
|||
|
||||
virtual double get_k(sim::reactor::rod::val_t type) const;
|
||||
virtual const char* get_name() const { return "Coolant"; }
|
||||
virtual rod* clone() const { return new pipe(*this); };
|
||||
|
||||
void update_pipe(double secs);
|
||||
|
||||
public:
|
||||
|
|
|
@ -15,6 +15,7 @@ class fuel_rod : public sim::reactor::rod
|
|||
virtual void display(std::ostream& o) const;
|
||||
|
||||
virtual const char* get_name() const { return "Fuel"; }
|
||||
virtual rod* clone() const { return new fuel_rod(*this); };
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -22,6 +22,16 @@ reactor::reactor(reactor&& o) : width(o.width), height(o.height), size(o.size)
|
|||
o.rods = nullptr;
|
||||
}
|
||||
|
||||
reactor::reactor(const reactor& o) : width(o.width), height(o.height), size(o.size)
|
||||
{
|
||||
rods = new std::unique_ptr<rod>[width * height];
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
this->rods[i] = std::unique_ptr<rod>(o.rods[i]->clone());
|
||||
}
|
||||
}
|
||||
|
||||
reactor::~reactor()
|
||||
{
|
||||
if(rods != nullptr)
|
||||
|
|
|
@ -21,6 +21,7 @@ struct reactor
|
|||
int cursor = 0;
|
||||
|
||||
reactor(std::unique_ptr<rod>* rods, int width, int height);
|
||||
reactor(const reactor& r);
|
||||
reactor(reactor&& r);
|
||||
~reactor();
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
virtual void add(val_t type, double v);
|
||||
virtual double extract(val_t type, double s, double k, double o);
|
||||
virtual double get(val_t type) const;
|
||||
virtual rod* clone() const { return new rod(*this); };
|
||||
|
||||
virtual bool should_display() const { return false; }
|
||||
virtual bool should_select() const { return false; }
|
||||
|
|
Loading…
Reference in New Issue