hud refactor (part II)
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
|
#include "../assets/Assets.h"
|
||||||
#include "../graphics/Viewport.h"
|
#include "../graphics/Viewport.h"
|
||||||
#include "../graphics/Shader.h"
|
#include "../graphics/Shader.h"
|
||||||
#include "../graphics/Texture.h"
|
#include "../graphics/Texture.h"
|
||||||
@@ -11,10 +12,10 @@
|
|||||||
#include "../voxels/Block.h"
|
#include "../voxels/Block.h"
|
||||||
#include "ContentGfxCache.h"
|
#include "ContentGfxCache.h"
|
||||||
|
|
||||||
BlocksPreview::BlocksPreview(Shader* shader,
|
BlocksPreview::BlocksPreview(Assets* assets, const ContentGfxCache* cache)
|
||||||
Atlas* atlas,
|
: shader(assets->getShader("ui3d")),
|
||||||
const ContentGfxCache* cache)
|
atlas(assets->getAtlas("blocks")),
|
||||||
: shader(shader), atlas(atlas), cache(cache) {
|
cache(cache) {
|
||||||
batch = std::make_unique<Batch3D>(1024);
|
batch = std::make_unique<Batch3D>(1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +38,8 @@ void BlocksPreview::draw(const Block* def, int x, int y, int size, glm::vec4 tin
|
|||||||
uint width = viewport->getWidth();
|
uint width = viewport->getWidth();
|
||||||
uint height = viewport->getHeight();
|
uint height = viewport->getHeight();
|
||||||
|
|
||||||
y = height - y - 1;
|
y = height - y - 1 - 35 /* magic garbage */;
|
||||||
x += 2;
|
x += 2;
|
||||||
y -= 35;
|
|
||||||
|
|
||||||
glm::vec3 offset (x/float(width) * 2, y/float(height) * 2, 0.0f);
|
glm::vec3 offset (x/float(width) * 2, y/float(height) * 2, 0.0f);
|
||||||
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class Assets;
|
||||||
class Viewport;
|
class Viewport;
|
||||||
class Shader;
|
class Shader;
|
||||||
class Atlas;
|
class Atlas;
|
||||||
@@ -19,11 +20,11 @@ class BlocksPreview {
|
|||||||
const ContentGfxCache* const cache;
|
const ContentGfxCache* const cache;
|
||||||
const Viewport* viewport;
|
const Viewport* viewport;
|
||||||
public:
|
public:
|
||||||
BlocksPreview(Shader* shader, Atlas* atlas, const ContentGfxCache* cache);
|
BlocksPreview(Assets* assets, const ContentGfxCache* cache);
|
||||||
~BlocksPreview();
|
~BlocksPreview();
|
||||||
|
|
||||||
void begin(const Viewport* viewport);
|
void begin(const Viewport* viewport);
|
||||||
void draw(const Block* block, int x, int y, int size, glm::vec4 tint);
|
void draw(const Block* block, int x, int y, int size, glm::vec4 tint);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRONTEND_BLOCKS_PREVIEW_H_
|
#endif // FRONTEND_BLOCKS_PREVIEW_H_
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRONTEND_BLOCKS_GFX_CACHE_H_
|
#endif // FRONTEND_BLOCKS_GFX_CACHE_H_
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "BlocksPreview.h"
|
#include "BlocksPreview.h"
|
||||||
|
#include "LevelFrontend.h"
|
||||||
#include "../window/Events.h"
|
#include "../window/Events.h"
|
||||||
#include "../assets/Assets.h"
|
#include "../assets/Assets.h"
|
||||||
#include "../graphics/Shader.h"
|
#include "../graphics/Shader.h"
|
||||||
@@ -15,18 +16,16 @@
|
|||||||
|
|
||||||
InventoryView::InventoryView(
|
InventoryView::InventoryView(
|
||||||
int columns,
|
int columns,
|
||||||
const Assets* assets,
|
|
||||||
const ContentIndices* indices,
|
const ContentIndices* indices,
|
||||||
const ContentGfxCache* cache,
|
LevelFrontend* frontend,
|
||||||
std::vector<blockid_t> blocks)
|
std::vector<blockid_t> blocks)
|
||||||
: assets(assets),
|
: indices(indices),
|
||||||
indices(indices),
|
|
||||||
cache(cache),
|
|
||||||
blocks(blocks),
|
blocks(blocks),
|
||||||
|
frontend(frontend),
|
||||||
columns(columns) {
|
columns(columns) {
|
||||||
blocksPreview = new BlocksPreview(assets->getShader("ui3d"),
|
}
|
||||||
assets->getAtlas("blocks"),
|
|
||||||
cache);
|
InventoryView::~InventoryView() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::setPosition(int x, int y) {
|
void InventoryView::setPosition(int x, int y) {
|
||||||
@@ -48,6 +47,7 @@ void InventoryView::setSlotConsumer(slotconsumer consumer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::actAndDraw(const GfxContext* ctx) {
|
void InventoryView::actAndDraw(const GfxContext* ctx) {
|
||||||
|
Assets* assets = frontend->getAssets();
|
||||||
Shader* uiShader = assets->getShader("ui");
|
Shader* uiShader = assets->getShader("ui");
|
||||||
|
|
||||||
auto viewport = ctx->getViewport();
|
auto viewport = ctx->getViewport();
|
||||||
@@ -73,6 +73,8 @@ void InventoryView::actAndDraw(const GfxContext* ctx) {
|
|||||||
}
|
}
|
||||||
scroll = std::min(scroll, int(inv_h-viewport.getHeight()));
|
scroll = std::min(scroll, int(inv_h-viewport.getHeight()));
|
||||||
scroll = std::max(scroll, 0);
|
scroll = std::max(scroll, 0);
|
||||||
|
|
||||||
|
auto blocksPreview = frontend->getBlocksPreview();
|
||||||
blocksPreview->begin(&ctx->getViewport());
|
blocksPreview->begin(&ctx->getViewport());
|
||||||
{
|
{
|
||||||
Window::clearDepth();
|
Window::clearDepth();
|
||||||
|
|||||||
@@ -10,18 +10,15 @@
|
|||||||
class Assets;
|
class Assets;
|
||||||
class GfxContext;
|
class GfxContext;
|
||||||
class ContentIndices;
|
class ContentIndices;
|
||||||
class BlocksPreview;
|
class LevelFrontend;
|
||||||
class ContentGfxCache;
|
|
||||||
|
|
||||||
typedef std::function<void(blockid_t)> slotconsumer;
|
typedef std::function<void(blockid_t)> slotconsumer;
|
||||||
|
|
||||||
class InventoryView {
|
class InventoryView {
|
||||||
const Assets* assets;
|
|
||||||
const ContentIndices* indices;
|
const ContentIndices* indices;
|
||||||
const ContentGfxCache* const cache;
|
|
||||||
std::vector<blockid_t> blocks;
|
std::vector<blockid_t> blocks;
|
||||||
BlocksPreview* blocksPreview;
|
|
||||||
slotconsumer consumer = nullptr;
|
slotconsumer consumer = nullptr;
|
||||||
|
LevelFrontend* frontend;
|
||||||
|
|
||||||
int scroll = 0;
|
int scroll = 0;
|
||||||
int columns;
|
int columns;
|
||||||
@@ -32,13 +29,15 @@ class InventoryView {
|
|||||||
public:
|
public:
|
||||||
InventoryView(
|
InventoryView(
|
||||||
int columns,
|
int columns,
|
||||||
const Assets* assets,
|
|
||||||
const ContentIndices* indices,
|
const ContentIndices* indices,
|
||||||
const ContentGfxCache* cache,
|
LevelFrontend* frontend,
|
||||||
std::vector<blockid_t> blocks);
|
std::vector<blockid_t> blocks);
|
||||||
|
|
||||||
|
virtual ~InventoryView();
|
||||||
|
|
||||||
|
virtual void actAndDraw(const GfxContext* ctx);
|
||||||
|
|
||||||
void setPosition(int x, int y);
|
void setPosition(int x, int y);
|
||||||
void actAndDraw(const GfxContext* ctx);
|
|
||||||
int getWidth() const;
|
int getWidth() const;
|
||||||
int getHeight() const;
|
int getHeight() const;
|
||||||
void setSlotConsumer(slotconsumer consumer);
|
void setSlotConsumer(slotconsumer consumer);
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include "LevelFrontend.h"
|
||||||
|
|
||||||
|
#include "../world/Level.h"
|
||||||
|
#include "../assets/Assets.h"
|
||||||
|
#include "BlocksPreview.h"
|
||||||
|
#include "ContentGfxCache.h"
|
||||||
|
|
||||||
|
LevelFrontend::LevelFrontend(Level* level, Assets* assets)
|
||||||
|
: level(level),
|
||||||
|
assets(assets),
|
||||||
|
contentCache(std::make_unique<ContentGfxCache>(level->content, assets)),
|
||||||
|
blocksPreview(std::make_unique<BlocksPreview>(assets, contentCache.get())) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
LevelFrontend::~LevelFrontend() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Level* LevelFrontend::getLevel() const {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assets* LevelFrontend::getAssets() const {
|
||||||
|
return assets;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlocksPreview* LevelFrontend::getBlocksPreview() const {
|
||||||
|
return blocksPreview.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
ContentGfxCache* LevelFrontend::getContentGfxCache() const {
|
||||||
|
return contentCache.get();
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef FRONTEND_LEVEL_FRONTEND_H_
|
||||||
|
#define FRONTEND_LEVEL_FRONTEND_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class Level;
|
||||||
|
class Assets;
|
||||||
|
class BlocksPreview;
|
||||||
|
class ContentGfxCache;
|
||||||
|
|
||||||
|
class LevelFrontend {
|
||||||
|
Level* level;
|
||||||
|
Assets* assets;
|
||||||
|
std::unique_ptr<ContentGfxCache> contentCache;
|
||||||
|
std::unique_ptr<BlocksPreview> blocksPreview;
|
||||||
|
public:
|
||||||
|
LevelFrontend(Level* level, Assets* assets);
|
||||||
|
~LevelFrontend();
|
||||||
|
|
||||||
|
Level* getLevel() const;
|
||||||
|
Assets* getAssets() const;
|
||||||
|
BlocksPreview* getBlocksPreview() const;
|
||||||
|
ContentGfxCache* getContentGfxCache() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FRONTEND_LEVEL_FRONTEND_H_
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
#include "../maths/voxmaths.h"
|
#include "../maths/voxmaths.h"
|
||||||
#include "../settings.h"
|
#include "../settings.h"
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
#include "ContentGfxCache.h"
|
#include "LevelFrontend.h"
|
||||||
#include "graphics/Skybox.h"
|
#include "graphics/Skybox.h"
|
||||||
|
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
@@ -38,12 +38,14 @@ using std::shared_ptr;
|
|||||||
|
|
||||||
WorldRenderer::WorldRenderer(Engine* engine,
|
WorldRenderer::WorldRenderer(Engine* engine,
|
||||||
Level* level,
|
Level* level,
|
||||||
const ContentGfxCache* cache)
|
LevelFrontend* frontend)
|
||||||
: engine(engine),
|
: engine(engine),
|
||||||
level(level),
|
level(level),
|
||||||
frustumCulling(new Frustum()),
|
frustumCulling(new Frustum()),
|
||||||
lineBatch(new LineBatch()),
|
lineBatch(new LineBatch()),
|
||||||
renderer( new ChunksRenderer(level, cache, engine->getSettings())) {
|
renderer(new ChunksRenderer(level,
|
||||||
|
frontend->getContentGfxCache(),
|
||||||
|
engine->getSettings())) {
|
||||||
|
|
||||||
auto& settings = engine->getSettings();
|
auto& settings = engine->getSettings();
|
||||||
level->events->listen(EVT_CHUNK_HIDDEN,
|
level->events->listen(EVT_CHUNK_HIDDEN,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Texture;
|
|||||||
class Frustum;
|
class Frustum;
|
||||||
class Engine;
|
class Engine;
|
||||||
class Chunks;
|
class Chunks;
|
||||||
class ContentGfxCache;
|
class LevelFrontend;
|
||||||
class Skybox;
|
class Skybox;
|
||||||
|
|
||||||
class WorldRenderer {
|
class WorldRenderer {
|
||||||
@@ -34,7 +34,7 @@ class WorldRenderer {
|
|||||||
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool culling);
|
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool culling);
|
||||||
void drawChunks(Chunks* chunks, Camera* camera, Shader* shader);
|
void drawChunks(Chunks* chunks, Camera* camera, Shader* shader);
|
||||||
public:
|
public:
|
||||||
WorldRenderer(Engine* engine, Level* level, const ContentGfxCache* cache);
|
WorldRenderer(Engine* engine, Level* level, LevelFrontend* frontend);
|
||||||
~WorldRenderer();
|
~WorldRenderer();
|
||||||
|
|
||||||
void draw(const GfxContext& context, Camera* camera);
|
void draw(const GfxContext& context, Camera* camera);
|
||||||
|
|||||||
+29
-35
@@ -39,47 +39,44 @@
|
|||||||
#include "WorldRenderer.h"
|
#include "WorldRenderer.h"
|
||||||
#include "BlocksPreview.h"
|
#include "BlocksPreview.h"
|
||||||
#include "InventoryView.h"
|
#include "InventoryView.h"
|
||||||
|
#include "LevelFrontend.h"
|
||||||
#include "../engine.h"
|
#include "../engine.h"
|
||||||
#include "../core_defs.h"
|
#include "../core_defs.h"
|
||||||
|
|
||||||
using std::wstring;
|
|
||||||
using std::shared_ptr;
|
|
||||||
using glm::vec2;
|
using glm::vec2;
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
using glm::vec4;
|
using glm::vec4;
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
inline Label* create_label(gui::wstringsupplier supplier) {
|
inline std::shared_ptr<Label> create_label(gui::wstringsupplier supplier) {
|
||||||
Label* label = new Label(L"-");
|
auto label = std::make_shared<Label>(L"-");
|
||||||
label->textSupplier(supplier);
|
label->textSupplier(supplier);
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HudRenderer::createDebugPanel(Engine* engine) {
|
void HudRenderer::createDebugPanel(Engine* engine) {
|
||||||
Panel* panel = new Panel(vec2(250, 200), vec4(5.0f), 1.0f);
|
Panel* panel = new Panel(vec2(250, 200), vec4(5.0f), 1.0f);
|
||||||
debugPanel = shared_ptr<UINode>(panel);
|
debugPanel = std::shared_ptr<UINode>(panel);
|
||||||
panel->listenInterval(1.0f, [this]() {
|
panel->listenInterval(1.0f, [this]() {
|
||||||
fpsString = std::to_wstring(fpsMax)+L" / "+std::to_wstring(fpsMin);
|
fpsString = std::to_wstring(fpsMax)+L" / "+std::to_wstring(fpsMin);
|
||||||
fpsMin = fps;
|
fpsMin = fps;
|
||||||
fpsMax = fps;
|
fpsMax = fps;
|
||||||
});
|
});
|
||||||
panel->setCoord(vec2(10, 10));
|
panel->setCoord(vec2(10, 10));
|
||||||
panel->add(shared_ptr<Label>(create_label([this](){
|
panel->add(create_label([this](){ return L"fps: "+this->fpsString;}));
|
||||||
return L"fps: "+this->fpsString;
|
panel->add(create_label([this](){
|
||||||
})));
|
|
||||||
panel->add(shared_ptr<Label>(create_label([this](){
|
|
||||||
return L"meshes: " + std::to_wstring(Mesh::meshesCount);
|
return L"meshes: " + std::to_wstring(Mesh::meshesCount);
|
||||||
})));
|
}));
|
||||||
panel->add(shared_ptr<Label>(create_label([=](){
|
panel->add(create_label([=](){
|
||||||
auto& settings = engine->getSettings();
|
auto& settings = engine->getSettings();
|
||||||
bool culling = settings.graphics.frustumCulling;
|
bool culling = settings.graphics.frustumCulling;
|
||||||
return L"frustum-culling: "+wstring(culling ? L"on" : L"off");
|
return L"frustum-culling: "+std::wstring(culling ? L"on" : L"off");
|
||||||
})));
|
}));
|
||||||
panel->add(shared_ptr<Label>(create_label([this]() {
|
panel->add(create_label([this]() {
|
||||||
return L"chunks: "+std::to_wstring(level->chunks->chunksCount)+
|
return L"chunks: "+std::to_wstring(level->chunks->chunksCount)+
|
||||||
L" visible: "+std::to_wstring(level->chunks->visible);
|
L" visible: "+std::to_wstring(level->chunks->visible);
|
||||||
})));
|
}));
|
||||||
panel->add(shared_ptr<Label>(create_label([this](){
|
panel->add(create_label([this](){
|
||||||
auto player = level->player;
|
auto player = level->player;
|
||||||
auto indices = level->content->indices;
|
auto indices = level->content->indices;
|
||||||
auto def = indices->getBlockDef(player->selectedVoxel.id);
|
auto def = indices->getBlockDef(player->selectedVoxel.id);
|
||||||
@@ -90,16 +87,16 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
}
|
}
|
||||||
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
||||||
L" "+stream.str();
|
L" "+stream.str();
|
||||||
})));
|
}));
|
||||||
panel->add(shared_ptr<Label>(create_label([this](){
|
panel->add(create_label([this](){
|
||||||
return L"seed: "+std::to_wstring(level->world->seed);
|
return L"seed: "+std::to_wstring(level->world->seed);
|
||||||
})));
|
}));
|
||||||
|
|
||||||
for (int ax = 0; ax < 3; ax++){
|
for (int ax = 0; ax < 3; ax++){
|
||||||
Panel* sub = new Panel(vec2(10, 27), vec4(0.0f));
|
Panel* sub = new Panel(vec2(10, 27), vec4(0.0f));
|
||||||
sub->orientation(Orientation::horizontal);
|
sub->orientation(Orientation::horizontal);
|
||||||
|
|
||||||
wstring str = L"x: ";
|
std::wstring str = L"x: ";
|
||||||
str[0] += ax;
|
str[0] += ax;
|
||||||
Label* label = new Label(str);
|
Label* label = new Label(str);
|
||||||
label->margin(vec4(2, 3, 2, 3));
|
label->margin(vec4(2, 3, 2, 3));
|
||||||
@@ -112,7 +109,7 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
Hitbox* hitbox = this->level->player->hitbox;
|
Hitbox* hitbox = this->level->player->hitbox;
|
||||||
return std::to_wstring(hitbox->position[ax]);
|
return std::to_wstring(hitbox->position[ax]);
|
||||||
});
|
});
|
||||||
box->textConsumer([this, ax](wstring text) {
|
box->textConsumer([this, ax](std::wstring text) {
|
||||||
try {
|
try {
|
||||||
vec3 position = this->level->player->hitbox->position;
|
vec3 position = this->level->player->hitbox->position;
|
||||||
position[ax] = std::stoi(text);
|
position[ax] = std::stoi(text);
|
||||||
@@ -124,7 +121,7 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
sub->add(box);
|
sub->add(box);
|
||||||
panel->add(sub);
|
panel->add(sub);
|
||||||
}
|
}
|
||||||
panel->add(shared_ptr<Label>(create_label([this](){
|
panel->add(create_label([this](){
|
||||||
int hour, minute, second;
|
int hour, minute, second;
|
||||||
timeutil::from_value(this->level->world->daytime, hour, minute, second);
|
timeutil::from_value(this->level->world->daytime, hour, minute, second);
|
||||||
|
|
||||||
@@ -132,7 +129,7 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
|
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
|
||||||
util::lfill(std::to_wstring(minute), 2, L'0');
|
util::lfill(std::to_wstring(minute), 2, L'0');
|
||||||
return L"time: "+timeString;
|
return L"time: "+timeString;
|
||||||
})));
|
}));
|
||||||
{
|
{
|
||||||
TrackBar* bar = new TrackBar(0.0f, 1.0f, 1.0f, 0.005f, 8);
|
TrackBar* bar = new TrackBar(0.0f, 1.0f, 1.0f, 0.005f, 8);
|
||||||
bar->supplier([=]() {
|
bar->supplier([=]() {
|
||||||
@@ -176,15 +173,13 @@ void HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
|
|
||||||
HudRenderer::HudRenderer(Engine* engine,
|
HudRenderer::HudRenderer(Engine* engine,
|
||||||
Level* level,
|
Level* level,
|
||||||
const ContentGfxCache* cache)
|
LevelFrontend* frontend)
|
||||||
: level(level),
|
: level(level),
|
||||||
assets(engine->getAssets()),
|
assets(engine->getAssets()),
|
||||||
gui(engine->getGUI()),
|
gui(engine->getGUI()),
|
||||||
cache(cache) {
|
frontend(frontend) {
|
||||||
|
|
||||||
auto menu = gui->getMenu();
|
auto menu = gui->getMenu();
|
||||||
blocksPreview = new BlocksPreview(assets->getShader("ui3d"),
|
|
||||||
assets->getAtlas("blocks"),
|
|
||||||
cache);
|
|
||||||
auto content = level->content;
|
auto content = level->content;
|
||||||
auto indices = content->indices;
|
auto indices = content->indices;
|
||||||
std::vector<blockid_t> blocks;
|
std::vector<blockid_t> blocks;
|
||||||
@@ -194,7 +189,7 @@ HudRenderer::HudRenderer(Engine* engine,
|
|||||||
continue;
|
continue;
|
||||||
blocks.push_back(id);
|
blocks.push_back(id);
|
||||||
}
|
}
|
||||||
contentAccess.reset(new InventoryView(8, assets, indices, cache, blocks));
|
contentAccess.reset(new InventoryView(8, indices, frontend, blocks));
|
||||||
contentAccess->setSlotConsumer([=](blockid_t id) {
|
contentAccess->setSlotConsumer([=](blockid_t id) {
|
||||||
level->player->chosenBlock = id;
|
level->player->chosenBlock = id;
|
||||||
});
|
});
|
||||||
@@ -211,7 +206,6 @@ HudRenderer::HudRenderer(Engine* engine,
|
|||||||
|
|
||||||
HudRenderer::~HudRenderer() {
|
HudRenderer::~HudRenderer() {
|
||||||
gui->remove(debugPanel);
|
gui->remove(debugPanel);
|
||||||
delete blocksPreview;
|
|
||||||
delete uicamera;
|
delete uicamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,14 +269,14 @@ void HudRenderer::draw(const GfxContext& ctx){
|
|||||||
batch->line(width/2-5, height/2-5, width/2+5, height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
|
batch->line(width/2-5, height/2-5, width/2+5, height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
|
||||||
batch->line(width/2+5, height/2-5, width/2-5, height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
|
batch->line(width/2+5, height/2-5, width/2-5, height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* player = level->player;
|
Player* player = level->player;
|
||||||
|
|
||||||
|
|
||||||
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.75f);
|
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.75f);
|
||||||
batch->rect(width - 68, height - 68, 68, 68);
|
batch->rect(width - 68, height - 68, 68, 68);
|
||||||
batch->color = vec4(1.0f);
|
batch->color = vec4(1.0f);
|
||||||
batch->render();
|
batch->render();
|
||||||
|
|
||||||
|
auto blocksPreview = frontend->getBlocksPreview();
|
||||||
blocksPreview->begin(&ctx.getViewport());
|
blocksPreview->begin(&ctx.getViewport());
|
||||||
{
|
{
|
||||||
Window::clearDepth();
|
Window::clearDepth();
|
||||||
|
|||||||
+3
-5
@@ -15,9 +15,8 @@ class Assets;
|
|||||||
class Player;
|
class Player;
|
||||||
class Level;
|
class Level;
|
||||||
class Engine;
|
class Engine;
|
||||||
class ContentGfxCache;
|
|
||||||
class BlocksPreview;
|
|
||||||
class InventoryView;
|
class InventoryView;
|
||||||
|
class LevelFrontend;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class GUI;
|
class GUI;
|
||||||
@@ -28,7 +27,6 @@ class HudRenderer {
|
|||||||
Level* level;
|
Level* level;
|
||||||
Assets* assets;
|
Assets* assets;
|
||||||
Camera* uicamera;
|
Camera* uicamera;
|
||||||
BlocksPreview* blocksPreview;
|
|
||||||
|
|
||||||
int fps = 60;
|
int fps = 60;
|
||||||
int fpsMin = 60;
|
int fpsMin = 60;
|
||||||
@@ -40,13 +38,13 @@ class HudRenderer {
|
|||||||
std::unique_ptr<InventoryView> contentAccess;
|
std::unique_ptr<InventoryView> contentAccess;
|
||||||
std::shared_ptr<gui::UINode> debugPanel;
|
std::shared_ptr<gui::UINode> debugPanel;
|
||||||
gui::GUI* gui;
|
gui::GUI* gui;
|
||||||
const ContentGfxCache* const cache;
|
LevelFrontend* frontend;
|
||||||
|
|
||||||
void createDebugPanel(Engine* engine);
|
void createDebugPanel(Engine* engine);
|
||||||
public:
|
public:
|
||||||
HudRenderer(Engine* engine,
|
HudRenderer(Engine* engine,
|
||||||
Level* level,
|
Level* level,
|
||||||
const ContentGfxCache* cache);
|
LevelFrontend* frontend);
|
||||||
~HudRenderer();
|
~HudRenderer();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "WorldRenderer.h"
|
#include "WorldRenderer.h"
|
||||||
#include "hud.h"
|
#include "hud.h"
|
||||||
#include "ContentGfxCache.h"
|
#include "ContentGfxCache.h"
|
||||||
|
#include "LevelFrontend.h"
|
||||||
#include "gui/GUI.h"
|
#include "gui/GUI.h"
|
||||||
#include "gui/panels.h"
|
#include "gui/panels.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
@@ -84,26 +85,20 @@ static bool backlight;
|
|||||||
|
|
||||||
LevelScreen::LevelScreen(Engine* engine, Level* level)
|
LevelScreen::LevelScreen(Engine* engine, Level* level)
|
||||||
: Screen(engine),
|
: Screen(engine),
|
||||||
level(level) {
|
level(level),
|
||||||
|
frontend(std::make_unique<LevelFrontend>(level, engine->getAssets())),
|
||||||
|
hud(std::make_unique<HudRenderer>(engine, level, frontend.get())),
|
||||||
|
worldRenderer(std::make_unique<WorldRenderer>(engine, level, frontend.get())),
|
||||||
|
controller(std::make_unique<LevelController>(engine->getSettings(), level)) {
|
||||||
|
|
||||||
auto& settings = engine->getSettings();
|
auto& settings = engine->getSettings();
|
||||||
controller = new LevelController(settings, level);
|
|
||||||
cache = new ContentGfxCache(level->content, engine->getAssets());
|
|
||||||
worldRenderer = new WorldRenderer(engine, level, cache);
|
|
||||||
hud = new HudRenderer(engine, level, cache);
|
|
||||||
backlight = settings.graphics.backlight;
|
backlight = settings.graphics.backlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelScreen::~LevelScreen() {
|
LevelScreen::~LevelScreen() {
|
||||||
delete controller;
|
|
||||||
delete hud;
|
|
||||||
delete worldRenderer;
|
|
||||||
delete cache;
|
|
||||||
|
|
||||||
std::cout << "-- writing world" << std::endl;
|
std::cout << "-- writing world" << std::endl;
|
||||||
World* world = level->world;
|
World* world = level->world;
|
||||||
world->write(level);
|
world->write(level.get());
|
||||||
|
|
||||||
delete level;
|
|
||||||
delete world;
|
delete world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class HudRenderer;
|
|||||||
class Engine;
|
class Engine;
|
||||||
class Camera;
|
class Camera;
|
||||||
class Batch2D;
|
class Batch2D;
|
||||||
class ContentGfxCache;
|
class LevelFrontend;
|
||||||
class LevelController;
|
class LevelController;
|
||||||
|
|
||||||
/* Screen is a mainloop state */
|
/* Screen is a mainloop state */
|
||||||
@@ -37,11 +37,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class LevelScreen : public Screen {
|
class LevelScreen : public Screen {
|
||||||
Level* level;
|
std::unique_ptr<Level> level;
|
||||||
LevelController* controller;
|
std::unique_ptr<LevelFrontend> frontend;
|
||||||
WorldRenderer* worldRenderer;
|
std::unique_ptr<HudRenderer> hud;
|
||||||
HudRenderer* hud;
|
std::unique_ptr<WorldRenderer> worldRenderer;
|
||||||
ContentGfxCache* cache;
|
std::unique_ptr<LevelController> controller;
|
||||||
|
|
||||||
bool hudVisible = true;
|
bool hudVisible = true;
|
||||||
void updateHotkeys();
|
void updateHotkeys();
|
||||||
@@ -53,4 +53,4 @@ public:
|
|||||||
void draw(float delta) override;
|
void draw(float delta) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRONTEND_SCREENS_H_
|
#endif // FRONTEND_SCREENS_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user