void main(){
texCoord = tex_coord;
- color = vec4(0.0f, 0.0f, 0.0f, 1.0f);
+ color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
//color = tex_color;
//gl_Position = ortho * vec4(coord2d.xyz, 1.0f);
gl_Position = projection * view * model * vec4(coord2d.xyz, 1.0f);
#include <cereal/archives/json.hpp>
#include <fstream>
-void Config::save(void) const
+std::map<std::string, std::variant<int, double, std::string>> Config::values;
+
+void Config::save(void)
{
if (std::ofstream file (fileName); file.good()) {
cereal::JSONOutputArchive archive (file);
{
private:
static constexpr const char *fileName = "settings.json";
- std::map<std::string, std::variant<int, double, std::string>> values;
+ static std::map<std::string, std::variant<int, double, std::string>> values;
public:
template<typename T>
- std::optional<T> get(const std::string& name)
+ static std::optional<T> get(const std::string& name)
{
if (values.count(name) != 0) {
if (auto value = std::get_if<T>(&values[name]); value != nullptr)
}
template<typename T>
- void set(const std::string& name, T val)
+ static void set(const std::string& name, T val)
{
values[name] = val;
}
template<typename T>
- void add(const std::string& name)
+ static void require(const std::string& name, T defaultValue = T())
{
- values[name] = T();
+ if (values.count(name) == 0)
+ values[name] = defaultValue();
}
- void save(void) const;
- void load(void);
+ static void save(void);
+ static void load(void);
};
#endif // CONFIG_HPP_
#include <fstream>
+using namespace std::literals::string_literals;
using namespace std::chrono_literals;
namespace cr = std::chrono;
typedef std::chrono::high_resolution_clock mc;
}
}
-void Engine::renderLoop(void)
+void Engine::renderLoop(int& fpsCounter)
{
entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */
while (shouldRun()) {
systems.update<TextSystem>(dt);
systems.update<RenderSystem>(dt);
+ fpsCounter++;
}
}
void Engine::run(void)
{
+ int fpsCounter = 0;
+
// Start logic thread
logicThread = std::thread([this](void) {
logicLoop();
physicsLoop();
});
+ debugThread = std::thread([this, &fpsCounter](void) {
+ while (shouldRun()) {
+ std::this_thread::sleep_for(1s);
+ fps = fpsCounter;
+ fpsCounter = 0;
+ systems.system<TextSystem>()->put("default", 0, 0, "fps: "s + std::to_string(fps));
+ }
+ });
+
// Keep render loop on main thread
- renderLoop();
+ renderLoop(fpsCounter);
// Done, bring logic thread back
logicThread.join();
physicsThread.join();
+ debugThread.join();
// Save the entities' data
GameState::save("save.json", entities);
entityx::EntityManager entities;
entityx::SystemManager systems;
+ int fps;
+
std::thread logicThread;
std::thread physicsThread;
+ std::thread debugThread;
void logicLoop(void);
void physicsLoop(void);
- void renderLoop(void);
+ void renderLoop(int& fpsCounter);
bool shouldRun(void);
public:
Engine(void) :
entities(events),
- systems(entities, events) {}
+ systems(entities, events),
+ fps(0) {}
/**
* Initializes the game engine.
if (d.text.size() == 0)
continue;
- // TODO make normal
events.emit<NewRenderEvent>(d.vbo, d.tex, 0, d.buffer.size());
}
}
if (fontData.find(font) == fontData.end())
return;
+ auto& vector = fontData[font].text;
+ if (auto i = std::find_if(vector.begin(), vector.end(), [&x, &y](const Text& t) {
+ return t.x == x && t.y == y; }); i != vector.end()) {
+ vector.erase(i);
+ }
+
fontData[font].text.emplace_back(text, x, y, -9.0f);
shouldUpdateVBOs = true;
}