Decreased GL,GLFW presence out of Window module

This commit is contained in:
MihailRis 2023-11-09 01:19:44 +03:00
parent 086f04af39
commit 1d9fc44482
6 changed files with 28 additions and 16 deletions

View File

@ -68,7 +68,7 @@ bool _load_font(Assets* assets, const std::string& filename, const std::string&
} }
pages.push_back(texture); pages.push_back(texture);
} }
Font* font = new Font(pages); Font* font = new Font(pages, pages[0]->height / 16);
assets->store(font, name); assets->store(font, name);
return true; return true;
} }

View File

@ -2,7 +2,7 @@
#include "Texture.h" #include "Texture.h"
#include "Batch2D.h" #include "Batch2D.h"
Font::Font(std::vector<Texture*> pages) : pages(pages) { Font::Font(std::vector<Texture*> pages, int lineHeight) : lineHeight_(lineHeight), pages(pages) {
} }
Font::~Font(){ Font::~Font(){
@ -26,6 +26,9 @@ Font::~Font(){
// return 7; // return 7;
// } // }
int Font::lineHeight() const {
return lineHeight_;
}
bool Font::isPrintableChar(int c) { bool Font::isPrintableChar(int c) {
switch (c){ switch (c){
@ -42,6 +45,10 @@ bool Font::isPrintableChar(int c) {
#define RES 16 #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) { void Font::draw(Batch2D* batch, std::wstring text, int x, int y) {
draw(batch, text, x, y, STYLE_NONE); draw(batch, text, x, y, STYLE_NONE);
} }

View File

@ -12,11 +12,14 @@ class Batch2D;
#define STYLE_OUTLINE 2 #define STYLE_OUTLINE 2
class Font { class Font {
int lineHeight_;
public: public:
std::vector<Texture*> pages; std::vector<Texture*> pages;
Font(std::vector<Texture*> pages); Font(std::vector<Texture*> pages, int lineHeight);
~Font(); ~Font();
int lineHeight() const;
int calcWidth(std::wstring text);
// int getGlyphWidth(char c); // int getGlyphWidth(char c);
bool isPrintableChar(int c); bool isPrintableChar(int c);
void draw(Batch2D* batch, std::wstring text, int x, int y); void draw(Batch2D* batch, std::wstring text, int x, int y);

View File

@ -2,10 +2,6 @@
#include <cmath> #include <cmath>
#include <stdint.h> #include <stdint.h>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <ctime> #include <ctime>
@ -22,6 +18,7 @@
#include "window/Window.h" #include "window/Window.h"
#include "window/Events.h" #include "window/Events.h"
#include "window/Camera.h" #include "window/Camera.h"
#include "window/input.h"
#include "audio/Audio.h" #include "audio/Audio.h"
#include "voxels/Chunk.h" #include "voxels/Chunk.h"
#include "voxels/Chunks.h" #include "voxels/Chunks.h"
@ -117,25 +114,22 @@ Engine::Engine(const EngineSettings& settings) {
void Engine::updateTimers() { void Engine::updateTimers() {
frame++; frame++;
float currentTime = glfwGetTime(); float currentTime = Window::time();
delta = currentTime - lastTime; delta = currentTime - lastTime;
lastTime = currentTime; lastTime = currentTime;
} }
void Engine::updateHotkeys() { void Engine::updateHotkeys() {
if (Events::jpressed(GLFW_KEY_ESCAPE)) { if (Events::jpressed(keycode::TAB)) {
Window::setShouldClose(true);
}
if (Events::jpressed(GLFW_KEY_TAB) || Events::jpressed(GLFW_KEY_E)) {
Events::toggleCursor(); Events::toggleCursor();
} }
if (Events::jpressed(GLFW_KEY_O)) { if (Events::jpressed(keycode::O)) {
occlusion = !occlusion; occlusion = !occlusion;
} }
if (Events::jpressed(GLFW_KEY_F3)) { if (Events::jpressed(keycode::F3)) {
level->player->debug = !level->player->debug; 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++) { for (uint i = 0; i < level->chunks->volume; i++) {
shared_ptr<Chunk> chunk = level->chunks->chunks[i]; shared_ptr<Chunk> chunk = level->chunks->chunks[i];
if (chunk != nullptr && chunk->isReady()) { if (chunk != nullptr && chunk->isReady()) {
@ -150,7 +144,7 @@ void Engine::mainloop() {
std::cout << "-- preparing systems" << std::endl; std::cout << "-- preparing systems" << std::endl;
WorldRenderer worldRenderer(level, assets); WorldRenderer worldRenderer(level, assets);
HudRenderer hud(assets); HudRenderer hud(assets);
lastTime = glfwGetTime(); lastTime = Window::time();
Window::swapInterval(1); Window::swapInterval(1);
while (!Window::isShouldClose()){ while (!Window::isShouldClose()){

View File

@ -1,6 +1,8 @@
#include <iostream> #include <iostream>
#include "Window.h" #include "Window.h"
#include "Events.h" #include "Events.h"
#define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@ -168,3 +170,7 @@ void Window::swapBuffers(){
glfwSwapBuffers(window); glfwSwapBuffers(window);
Window::resetScissor(); Window::resetScissor();
} }
double Window::time() {
return glfwGetTime();
}

View File

@ -29,6 +29,8 @@ public:
static void pushScissor(glm::vec4 area); static void pushScissor(glm::vec4 area);
static void popScissor(); static void popScissor();
static void resetScissor(); static void resetScissor();
static double time();
}; };
#endif /* WINDOW_WINDOW_H_ */ #endif /* WINDOW_WINDOW_H_ */