diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp index 45b583cd..79e849af 100644 --- a/src/assets/AssetsLoader.cpp +++ b/src/assets/AssetsLoader.cpp @@ -68,7 +68,7 @@ bool _load_font(Assets* assets, const std::string& filename, const std::string& } pages.push_back(texture); } - Font* font = new Font(pages); + Font* font = new Font(pages, pages[0]->height / 16); assets->store(font, name); return true; } diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index 56dd8eef..c13681f6 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -2,7 +2,7 @@ #include "Texture.h" #include "Batch2D.h" -Font::Font(std::vector pages) : pages(pages) { +Font::Font(std::vector pages, int lineHeight) : lineHeight_(lineHeight), pages(pages) { } Font::~Font(){ @@ -26,6 +26,9 @@ Font::~Font(){ // return 7; // } +int Font::lineHeight() const { + return lineHeight_; +} bool Font::isPrintableChar(int c) { switch (c){ @@ -42,6 +45,10 @@ bool Font::isPrintableChar(int c) { #define RES 16 +int Font::calcWidth(std::wstring text) { + return text.length() * 8; +} + void Font::draw(Batch2D* batch, std::wstring text, int x, int y) { draw(batch, text, x, y, STYLE_NONE); } diff --git a/src/graphics/Font.h b/src/graphics/Font.h index e9418cbc..6df79e08 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -12,11 +12,14 @@ class Batch2D; #define STYLE_OUTLINE 2 class Font { + int lineHeight_; public: std::vector pages; - Font(std::vector pages); + Font(std::vector pages, int lineHeight); ~Font(); + int lineHeight() const; + int calcWidth(std::wstring text); // int getGlyphWidth(char c); bool isPrintableChar(int c); void draw(Batch2D* batch, std::wstring text, int x, int y); diff --git a/src/voxel_engine.cpp b/src/voxel_engine.cpp index f50cac49..d84e2425 100644 --- a/src/voxel_engine.cpp +++ b/src/voxel_engine.cpp @@ -2,10 +2,6 @@ #include #include -#define GLEW_STATIC -#include -#include - #include #include #include @@ -22,6 +18,7 @@ #include "window/Window.h" #include "window/Events.h" #include "window/Camera.h" +#include "window/input.h" #include "audio/Audio.h" #include "voxels/Chunk.h" #include "voxels/Chunks.h" @@ -117,25 +114,22 @@ Engine::Engine(const EngineSettings& settings) { void Engine::updateTimers() { frame++; - float currentTime = glfwGetTime(); + float currentTime = Window::time(); delta = currentTime - lastTime; lastTime = currentTime; } void Engine::updateHotkeys() { - if (Events::jpressed(GLFW_KEY_ESCAPE)) { - Window::setShouldClose(true); - } - if (Events::jpressed(GLFW_KEY_TAB) || Events::jpressed(GLFW_KEY_E)) { + if (Events::jpressed(keycode::TAB)) { Events::toggleCursor(); } - if (Events::jpressed(GLFW_KEY_O)) { + if (Events::jpressed(keycode::O)) { occlusion = !occlusion; } - if (Events::jpressed(GLFW_KEY_F3)) { + if (Events::jpressed(keycode::F3)) { level->player->debug = !level->player->debug; } - if (Events::jpressed(GLFW_KEY_F5)) { + if (Events::jpressed(keycode::F5)) { for (uint i = 0; i < level->chunks->volume; i++) { shared_ptr chunk = level->chunks->chunks[i]; if (chunk != nullptr && chunk->isReady()) { @@ -150,7 +144,7 @@ void Engine::mainloop() { std::cout << "-- preparing systems" << std::endl; WorldRenderer worldRenderer(level, assets); HudRenderer hud(assets); - lastTime = glfwGetTime(); + lastTime = Window::time(); Window::swapInterval(1); while (!Window::isShouldClose()){ diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 846287cf..53a5d8d5 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -1,6 +1,8 @@ #include #include "Window.h" #include "Events.h" + +#define GLEW_STATIC #include #include @@ -168,3 +170,7 @@ void Window::swapBuffers(){ glfwSwapBuffers(window); Window::resetScissor(); } + +double Window::time() { + return glfwGetTime(); +} \ No newline at end of file diff --git a/src/window/Window.h b/src/window/Window.h index bd5a6545..b826e0ed 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -29,6 +29,8 @@ public: static void pushScissor(glm::vec4 area); static void popScissor(); static void resetScissor(); + + static double time(); }; #endif /* WINDOW_WINDOW_H_ */