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