#include <cereal/cereal.hpp>
#include <cereal/archives/json.hpp>
+#include <filesystem>
#include <fstream>
-std::map<std::string, std::variant<int, double, std::string>> Config::values;
+std::map<std::string, std::variant<int, double, std::string>> Config::values = {
+ { "title", "gamedev2" },
+ { "screenWidth", 640 },
+ { "screenHeight", 480 }
+};
void Config::save(void)
{
public:
template<typename T>
- static std::optional<T> get(const std::string& name)
+ static T get(const std::string& name)
{
if (values.count(name) != 0) {
if (auto value = std::get_if<T>(&values[name]); value != nullptr)
return *value;
}
- return {};
+ return T();
}
template<typename T>
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include "config.hpp"
#include "engine.hpp"
#include "gamestate.hpp"
#include "gamerun.hpp"
int Engine::init(void)
{
+ Config::load();
+
systems.add<GameRunSystem>();
systems.add<InputSystem>();
systems.add<PlayerSystem>(entities);
physicsThread.join();
debugThread.join();
- // Save the entities' data
+ // Save the entities' data, and settings data
GameState::save("save.json", entities);
+ Config::save();
// Remove all Lua references from entities
entities.each<Scripted>([](entityx::Entity, Scripted &f) {
#define GLEW_STATIC
#define SOL_ALL_SAFETIES_ON = 1
-#include "config.hpp"
#include "engine.hpp"
#include <SDL2/SDL.h>
Engine engine;
engine.init();
- //Config config;
- //config.add<int>("screenWidth");
- //config.add<int>("screenHeight");
- //config.add<std::string>("title");
- //config.load();
- //std::cout << *config.get<int>("screenWidth") << std::endl;
-
// Go go go!
engine.run();
- //config.set("screenWidth", 10000);
- //config.set("screenHeight", 481);
- //config.set("title", "gamEdevvv2");
- //config.save();
-
return 0;
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.hpp>
#include <render.hpp>
#include <components/Render.hpp>
#include <components/Position.hpp>
events.subscribe<WorldMeshUpdateEvent>(*this);
events.subscribe<entityx::ComponentAddedEvent<Player>>(*this);
+ title = Config::get<std::string>("title");
+ width = Config::get<int>("screenWidth");
+ height = Config::get<int>("screenHeight");
+
init();
}
// 0.01f,
// 2048.0f);
- float scale = 40.0f;
- float scaleWidth = static_cast<float>(width) / scale;
- float scaleHeight = static_cast<float>(height) / scale;
+ //float scale = 40.0f;
+ //float scaleWidth = static_cast<float>(width) / scale;
+ //float scaleHeight = static_cast<float>(height) / scale;
//glm::mat4 projection = glm::ortho(-(scaleWidth/2), // Left
// (scaleWidth/2), // Right
glm::vec3(0.0f, 0.0f, 1.0f), // Facing
glm::vec3(0.0f, 1.0f, 0.0f)); // Up
- scale = 1.0f;
- scaleWidth = static_cast<float>(width) / scale;
- scaleHeight = static_cast<float>(height) / scale;
-
- projection = glm::ortho(-scaleWidth/2.0f, // Left
- scaleWidth/2, // Right
- -scaleHeight/2, // Bottom
- scaleHeight/2, // Top
- 100.0f, // zFar
- -100.0f); // zNear
+ projection = glm::ortho(0.0f, // Left
+ static_cast<float>(width), // Right
+ -static_cast<float>(height), // Top
+ 0.0f,
+ 100.0f, // zFar
+ -100.0f); // zNear
model = glm::mat4(1.0f);
}
// Create window, managed by the unique_ptr
- window.reset(SDL_CreateWindow(title,
- SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
- width, height,
- SDL_WINDOW_OPENGL));
+ window.reset(SDL_CreateWindow(title.c_str(),
+ SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ width, height,
+ SDL_WINDOW_OPENGL));
if (window.get() == nullptr) {
std::cerr << "SDL window creation failed: "
public entityx::Receiver<RenderSystem>
{
private:
- constexpr static const char *title = "gamedev2";
- constexpr static int width = 1280;
- constexpr static int height = 720;
+ std::string title;
+ int width;
+ int height;
std::unique_ptr<SDL_Window, void (*)(SDL_Window *)> window;
SDL_GLContext context;
auto& face = fonts[file];
FT_Set_Pixel_Sizes(face, 0, size);
fontData.try_emplace(name);
+ fontData[name].fontSize = size;
// Calculate dimensions of final texture
//
if (fontData.find(font) == fontData.end())
return;
+ y -= fontData[font].fontSize;
+
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()) {
// Stores texture and placement data for a font at a size.
struct Font {
+ int fontSize;
+
GLuint tex;
GLuint vbo;