refactor: reduce Window references

This commit is contained in:
MihailRis
2025-04-02 14:55:53 +03:00
parent 896ab3597a
commit 74a94f869c
19 changed files with 151 additions and 155 deletions
+4
View File
@@ -16,4 +16,8 @@ public:
glm::ivec2 size() const {
return glm::ivec2(width, height);
}
float getRatio() const {
return width / static_cast<float>(height);
}
};
@@ -11,7 +11,6 @@
#include "objects/Player.hpp"
#include "voxels/Block.hpp"
#include "voxels/Chunks.hpp"
#include "window/Window.hpp"
#include "world/Level.hpp"
BlockWrapsRenderer::BlockWrapsRenderer(
-1
View File
@@ -6,7 +6,6 @@
#include "graphics/core/Atlas.hpp"
#include "graphics/core/Texture.hpp"
#include "assets/Assets.hpp"
#include "window/Window.hpp"
#include "voxels/Chunks.hpp"
#include "lighting/Lightmap.hpp"
#include "settings.hpp"
+7 -6
View File
@@ -4,11 +4,11 @@
#include "maths/util.hpp"
#include "assets/Assets.hpp"
#include "window/Camera.hpp"
#include "window/Window.hpp"
#include "maths/FrustumCulling.hpp"
#include "graphics/core/Font.hpp"
#include "graphics/core/Batch3D.hpp"
#include "graphics/core/Shader.hpp"
#include "graphics/core/DrawContext.hpp"
#include "presets/NotePreset.hpp"
#include "constants.hpp"
@@ -66,6 +66,7 @@ void TextsRenderer::renderNote(
xvec *= 1.0f + scale;
yvec *= 1.0f + scale;
}
const auto& viewport = context.getViewport();
if (preset.displayMode == NoteDisplayMode::PROJECTED) {
float scale = 1.0f;
if (glm::abs(preset.perspective) > 0.0001f) {
@@ -84,14 +85,14 @@ void TextsRenderer::renderNote(
}
pos /= projpos.w;
pos.z = 0;
xvec = {2.0f/Window::width*scale, 0, 0};
yvec = {0, 2.0f/Window::height*scale, 0};
xvec = {2.0f / viewport.getWidth() * scale, 0, 0};
yvec = {0, 2.0f / viewport.getHeight() * scale, 0};
} else {
auto matrix = camera.getProjView();
auto screenPos = matrix * glm::vec4(pos, 1.0f);
xvec = glm::vec3(2.0f/Window::width*scale, 0, 0);
yvec = glm::vec3(0, 2.0f/Window::height*scale, 0);
xvec = glm::vec3(2.0f / viewport.getWidth() * scale, 0, 0);
yvec = glm::vec3(0, 2.0f / viewport.getHeight() * scale, 0);
pos = screenPos / screenPos.w;
}
+2 -2
View File
@@ -338,8 +338,8 @@ void WorldRenderer::draw(
auto world = level.getWorld();
const Viewport& vp = pctx.getViewport();
camera.aspect = vp.getWidth() / static_cast<float>(vp.getHeight());
const auto& vp = pctx.getViewport();
camera.setAspectRatio(vp.getRatio());
const auto& settings = engine.getSettings();
const auto& worldInfo = world->getInfo();
+5 -2
View File
@@ -115,8 +115,10 @@ void GUI::actMouse(float delta) {
}
if (hover) {
hover->setHover(true);
if (Events::scroll) {
hover->scrolled(Events::scroll);
int scroll = Events::getScroll();
if (scroll) {
hover->scrolled(scroll);
}
}
this->hover = hover;
@@ -229,6 +231,7 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
}
menu->setPos((wsize - menu->getSize()) / 2.0f);
uicamera->setFov(wsize.y);
uicamera->setAspectRatio(viewport.getRatio());
auto uishader = assets.get<Shader>("ui");
uishader->use();
+4 -4
View File
@@ -68,11 +68,11 @@ void guiutil::alert(
));
panel->refresh();
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([on_hidden_final](){
panel->keepAlive(Events::addKeyCallback(keycode::ENTER, [on_hidden_final](){
on_hidden_final();
return true;
}));
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([on_hidden_final](){
panel->keepAlive(Events::addKeyCallback(keycode::ESCAPE, [on_hidden_final](){
on_hidden_final();
return true;
}));
@@ -130,11 +130,11 @@ void guiutil::confirm(
}));
panel->add(subpanel);
panel->keepAlive(Events::keyCallbacks[keycode::ENTER].add([=](){
panel->keepAlive(Events::addKeyCallback(keycode::ENTER, [=](){
on_confirm_final();
return true;
}));
panel->keepAlive(Events::keyCallbacks[keycode::ESCAPE].add([=](){
panel->keepAlive(Events::addKeyCallback(keycode::ESCAPE, [=](){
on_deny_final();
return true;
}));