refactor: add Window interface
This commit is contained in:
@@ -12,27 +12,33 @@
|
||||
#include "objects/Player.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
LevelFrontend::LevelFrontend(
|
||||
Engine& engine,
|
||||
Player* currentPlayer,
|
||||
LevelController* controller,
|
||||
Assets& assets,
|
||||
const EngineSettings& settings
|
||||
)
|
||||
: level(*controller->getLevel()),
|
||||
controller(controller),
|
||||
assets(assets),
|
||||
assets(*engine.getAssets()),
|
||||
contentCache(std::make_unique<ContentGfxCache>(
|
||||
level.content, assets, settings.graphics
|
||||
)) {
|
||||
assets.store(
|
||||
BlocksPreview::build(
|
||||
*contentCache, assets, *level.content.getIndices()
|
||||
engine.getWindow(),
|
||||
*contentCache,
|
||||
*engine.getAssets(),
|
||||
*level.content.getIndices()
|
||||
),
|
||||
"block-previews"
|
||||
);
|
||||
|
||||
auto& rassets = assets;
|
||||
controller->getBlocksController()->listenBlockInteraction(
|
||||
[currentPlayer, controller, &assets](auto player, const auto& pos, const auto& def, BlockInteraction type) {
|
||||
[currentPlayer, controller, &rassets](auto player, const auto& pos, const auto& def, BlockInteraction type) {
|
||||
const auto& level = *controller->getLevel();
|
||||
auto material = level.content.findBlockMaterial(def.material);
|
||||
if (material == nullptr) {
|
||||
@@ -40,7 +46,7 @@ LevelFrontend::LevelFrontend(
|
||||
}
|
||||
|
||||
if (type == BlockInteraction::step) {
|
||||
auto sound = assets.get<audio::Sound>(material->stepsSound);
|
||||
auto sound = rassets.get<audio::Sound>(material->stepsSound);
|
||||
glm::vec3 pos {};
|
||||
auto soundsCamera = currentPlayer->currentCamera.get();
|
||||
if (soundsCamera == currentPlayer->spCamera.get() ||
|
||||
@@ -66,10 +72,10 @@ LevelFrontend::LevelFrontend(
|
||||
audio::Sound* sound = nullptr;
|
||||
switch (type) {
|
||||
case BlockInteraction::placing:
|
||||
sound = assets.get<audio::Sound>(material->placeSound);
|
||||
sound = rassets.get<audio::Sound>(material->placeSound);
|
||||
break;
|
||||
case BlockInteraction::destruction:
|
||||
sound = assets.get<audio::Sound>(material->breakSound);
|
||||
sound = rassets.get<audio::Sound>(material->breakSound);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
class Level;
|
||||
class Assets;
|
||||
class Player;
|
||||
class Engine;
|
||||
class ContentGfxCache;
|
||||
class LevelController;
|
||||
struct EngineSettings;
|
||||
@@ -12,13 +13,13 @@ struct EngineSettings;
|
||||
class LevelFrontend {
|
||||
Level& level;
|
||||
LevelController* controller;
|
||||
const Assets& assets;
|
||||
Assets& assets;
|
||||
std::unique_ptr<ContentGfxCache> contentCache;
|
||||
public:
|
||||
LevelFrontend(
|
||||
Engine& engine,
|
||||
Player* currentPlayer,
|
||||
LevelController* controller,
|
||||
Assets& assets,
|
||||
const EngineSettings& settings
|
||||
);
|
||||
~LevelFrontend();
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "voxels/GlobalChunks.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
#include "window/Events.hpp"
|
||||
#include "window/input.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "world/Level.hpp"
|
||||
@@ -225,7 +224,8 @@ void Hud::cleanup() {
|
||||
}
|
||||
|
||||
void Hud::processInput(bool visible) {
|
||||
if (!Window::isFocused() && !menu.hasOpenPage() && !isInventoryOpen()) {
|
||||
const auto& window = engine.getWindow();
|
||||
if (!window.isFocused() && !menu.hasOpenPage() && !isInventoryOpen()) {
|
||||
setPause(true);
|
||||
}
|
||||
const auto& bindings = input.getBindings();
|
||||
@@ -343,10 +343,11 @@ void Hud::update(bool visible) {
|
||||
element.getNode()->setVisible(visible);
|
||||
}
|
||||
|
||||
const auto& windowSize = engine.getWindow().getSize();
|
||||
glm::vec2 caSize = contentAccessPanel->getSize();
|
||||
contentAccessPanel->setVisible(inventoryView != nullptr && showContentPanel);
|
||||
contentAccessPanel->setSize(glm::vec2(caSize.x, Window::height));
|
||||
contentAccess->setMinSize(glm::vec2(1, Window::height));
|
||||
contentAccessPanel->setSize(glm::vec2(caSize.x, windowSize.y));
|
||||
contentAccess->setMinSize(glm::vec2(1, windowSize.y));
|
||||
hotbarView->setVisible(visible && !(secondUI && !inventoryView));
|
||||
|
||||
if (visible) {
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "util/stringutil.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
#include "window/Events.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "world/World.hpp"
|
||||
@@ -64,7 +63,7 @@ LevelScreen::LevelScreen(
|
||||
);
|
||||
|
||||
frontend = std::make_unique<LevelFrontend>(
|
||||
player, controller.get(), assets, settings
|
||||
engine, player, controller.get(), settings
|
||||
);
|
||||
renderer = std::make_unique<WorldRenderer>(
|
||||
engine, *frontend, *player
|
||||
@@ -162,11 +161,14 @@ void LevelScreen::saveWorldPreview() {
|
||||
Camera camera = *player->fpCamera;
|
||||
camera.setFov(glm::radians(70.0f));
|
||||
|
||||
DrawContext pctx(nullptr, {Window::width, Window::height}, batch.get());
|
||||
DrawContext pctx(nullptr, engine.getWindow(), batch.get());
|
||||
|
||||
DrawContext ctx(&pctx, engine.getWindow(), batch.get());
|
||||
ctx.setViewport(
|
||||
{static_cast<uint>(previewSize * 1.5),
|
||||
static_cast<uint>(previewSize)}
|
||||
);
|
||||
|
||||
Viewport viewport(previewSize * 1.5, previewSize);
|
||||
DrawContext ctx(&pctx, viewport, batch.get());
|
||||
|
||||
renderer->draw(ctx, camera, false, true, 0.0f, *postProcessing);
|
||||
auto image = postProcessing->toImage();
|
||||
image->flipY();
|
||||
@@ -226,7 +228,12 @@ void LevelScreen::update(float delta) {
|
||||
playerController->update(delta, inputLocked ? nullptr : &engine.getInput());
|
||||
}
|
||||
controller->update(glm::min(delta, 0.2f), paused);
|
||||
playerController->postUpdate(delta, inputLocked ? nullptr : &engine.getInput(), paused);
|
||||
playerController->postUpdate(
|
||||
delta,
|
||||
engine.getWindow().getSize().y,
|
||||
inputLocked ? nullptr : &engine.getInput(),
|
||||
paused
|
||||
);
|
||||
|
||||
hud->update(hudVisible);
|
||||
|
||||
@@ -239,8 +246,7 @@ void LevelScreen::update(float delta) {
|
||||
void LevelScreen::draw(float delta) {
|
||||
auto camera = playerController->getPlayer()->currentCamera;
|
||||
|
||||
Viewport viewport(Window::width, Window::height);
|
||||
DrawContext ctx(nullptr, viewport, batch.get());
|
||||
DrawContext ctx(nullptr, engine.getWindow(), batch.get());
|
||||
|
||||
if (!hud->isPause()) {
|
||||
scripting::on_entities_render(engine.getTime().getDelta());
|
||||
|
||||
@@ -18,7 +18,8 @@ MenuScreen::MenuScreen(Engine& engine) : Screen(engine) {
|
||||
menu->reset();
|
||||
menu->setPage("main");
|
||||
|
||||
uicamera = std::make_unique<Camera>(glm::vec3(), Window::height);
|
||||
uicamera =
|
||||
std::make_unique<Camera>(glm::vec3(), engine.getWindow().getSize().y);
|
||||
uicamera->perspective = false;
|
||||
uicamera->flipped = true;
|
||||
}
|
||||
@@ -31,13 +32,14 @@ void MenuScreen::update(float delta) {
|
||||
void MenuScreen::draw(float delta) {
|
||||
auto assets = engine.getAssets();
|
||||
|
||||
Window::clear();
|
||||
Window::setBgColor(glm::vec3(0.2f));
|
||||
display::clear();
|
||||
display::setBgColor(glm::vec3(0.2f));
|
||||
|
||||
uint width = Window::width;
|
||||
uint height = Window::height;
|
||||
const auto& size = engine.getWindow().getSize();
|
||||
uint width = size.x;
|
||||
uint height = size.y;
|
||||
|
||||
uicamera->setFov(Window::height);
|
||||
uicamera->setFov(height);
|
||||
uicamera->setAspectRatio(width / static_cast<float>(height));
|
||||
auto uishader = assets->get<Shader>("ui");
|
||||
uishader->use();
|
||||
@@ -49,7 +51,7 @@ void MenuScreen::draw(float delta) {
|
||||
batch->rect(
|
||||
0, 0,
|
||||
width, height, 0, 0, 0,
|
||||
UVRegion(0, 0, width/bg->getWidth(), height/bg->getHeight()),
|
||||
UVRegion(0, 0, width / bg->getWidth(), height / bg->getHeight()),
|
||||
false, false, glm::vec4(1.0f)
|
||||
);
|
||||
batch->flush();
|
||||
|
||||
Reference in New Issue
Block a user