From 9e3c4fb00c09eef63a2e7269640f3366eae8e5a3 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 21 Jan 2024 18:34:44 +0300 Subject: [PATCH 01/11] InventoryBuilder used for access panel and hotbar --- src/frontend/InventoryView.cpp | 7 +++-- src/frontend/hud.cpp | 50 ++++++++++++---------------------- src/items/Inventory.cpp | 2 +- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 723af338..c47f62ba 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -156,7 +156,7 @@ void SlotView::draw(Batch2D* batch, Assets* assets) { auto preview = frontend->getBlocksPreview(); auto indices = content->getIndices(); - ItemDef* item = indices->getItemDef(stack.getItemId()); + ItemDef* item = indices->getItemDef(stack.getItemId()); switch (item->iconType) { case item_icon_type::none: break; @@ -285,8 +285,11 @@ InventoryView::InventoryView( InventoryView::~InventoryView() {} void InventoryView::build() { - int index = 0; + size_t index = 0; for (auto& slot : layout->getSlots()) { + if (index >= inventory->size()) + break; + ItemStack& item = inventory->getSlot(index); auto view = std::make_shared( diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 8a4c3a0c..4b99a461 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -177,31 +177,21 @@ std::shared_ptr HudRenderer::createContentAccess() { accessInventory->getSlot(id-1).set(ItemStack(id, 1)); } - const int slotSize = InventoryView::SLOT_SIZE; - const int interval = InventoryView::SLOT_INTERVAL; - int padding = 8; + SlotLayout slotLayout(glm::vec2(), false, true, + [=](ItemStack& item) { + auto copy = ItemStack(item); + inventory->move(copy, indices); + }, + [=](ItemStack& item, ItemStack& grabbed) { + inventory->getSlot(player->getChosenSlot()).set(item); + }); int columns = 8; int rows = ceildiv(itemsCount-1, columns); - uint cawidth = columns * (slotSize + interval) - interval + padding; - uint caheight = rows * (slotSize + interval) - interval + padding*2; - auto layout = std::make_unique(glm::vec2(cawidth, caheight)); - for (int i = 0; i < itemsCount-1; i++) { - int row = i / columns; - int col = i % columns; - glm::vec2 position ( - col * slotSize + (col-1) * interval + padding, - row * slotSize + (row-1) * interval + padding - ); - layout->add(SlotLayout(position, false, true, - [=](ItemStack& item) { - auto copy = ItemStack(item); - inventory->move(copy, indices); - }, - [=](ItemStack& item, ItemStack& grabbed) { - inventory->getSlot(player->getChosenSlot()).set(item); - })); - } + InventoryBuilder builder; + builder.addGrid(columns, rows, glm::vec2(), 8, slotLayout); + auto layout = builder.build(); + auto contentAccess = std::make_shared( content, frontend, @@ -219,18 +209,12 @@ std::shared_ptr HudRenderer::createHotbar() { auto inventory = player->getInventory(); auto content = level->content; - const int slotSize = InventoryView::SLOT_SIZE; - const int interval = InventoryView::SLOT_INTERVAL; + SlotLayout slotLayout(glm::vec2(), false, false, nullptr, nullptr); + InventoryBuilder builder; + builder.addGrid(10, 1, glm::vec2(), 4, slotLayout); + auto layout = builder.build(); - int padding = 4; - uint width = 10 * (slotSize + interval) - interval + padding*2; - uint height = slotSize + padding * 2; - auto layout = std::make_unique(glm::vec2(width, height)); - for (int i = 0; i < 10; i++) { - glm::vec2 position (i * (slotSize + interval) + padding, padding); - layout->add(SlotLayout(position, false, false, nullptr, nullptr)); - } - layout->setOrigin(glm::vec2(width / 2, 0)); + layout->setOrigin(glm::vec2(layout->getSize().x/2, 0)); auto view = std::make_shared( content, frontend, diff --git a/src/items/Inventory.cpp b/src/items/Inventory.cpp index ba2025ad..cc4b1a2c 100644 --- a/src/items/Inventory.cpp +++ b/src/items/Inventory.cpp @@ -4,7 +4,7 @@ Inventory::Inventory(size_t size) : slots(size) { } ItemStack& Inventory::getSlot(size_t index) { - return slots[index]; + return slots.at(index); } size_t Inventory::findEmptySlot(size_t begin, size_t end) const { From aa93c2715920cbc887d543bb913558ef558cbc78 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 21 Jan 2024 19:21:18 +0300 Subject: [PATCH 02/11] InventoryView.addGrid semantics changed --- src/frontend/InventoryView.cpp | 4 +++- src/frontend/InventoryView.h | 2 +- src/frontend/hud.cpp | 14 ++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index c47f62ba..70966c06 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -72,7 +72,7 @@ InventoryBuilder::InventoryBuilder() {} void InventoryBuilder::addGrid( - int cols, int rows, + int cols, int count, glm::vec2 coord, int padding, SlotLayout slotLayout) @@ -80,6 +80,8 @@ void InventoryBuilder::addGrid( const int slotSize = InventoryView::SLOT_SIZE; const int interval = InventoryView::SLOT_INTERVAL; + int rows = ceildiv(count, cols); + uint width = cols * (slotSize + interval) - interval + padding*2; uint height = rows * (slotSize + interval) - interval + padding*2; diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index 1115428e..5c7df130 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -72,7 +72,7 @@ public: InventoryBuilder(); void addGrid( - int cols, int rows, + int cols, int count, glm::vec2 coord, int padding, SlotLayout slotLayout); diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 4b99a461..ea82473e 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -186,12 +186,10 @@ std::shared_ptr HudRenderer::createContentAccess() { inventory->getSlot(player->getChosenSlot()).set(item); }); - int columns = 8; - int rows = ceildiv(itemsCount-1, columns); InventoryBuilder builder; - builder.addGrid(columns, rows, glm::vec2(), 8, slotLayout); + builder.addGrid(8, itemsCount-1, glm::vec2(), 8, slotLayout); auto layout = builder.build(); - + auto contentAccess = std::make_shared( content, frontend, @@ -211,7 +209,7 @@ std::shared_ptr HudRenderer::createHotbar() { SlotLayout slotLayout(glm::vec2(), false, false, nullptr, nullptr); InventoryBuilder builder; - builder.addGrid(10, 1, glm::vec2(), 4, slotLayout); + builder.addGrid(10, 10, glm::vec2(), 4, slotLayout); auto layout = builder.build(); layout->setOrigin(glm::vec2(layout->getSize().x/2, 0)); @@ -236,13 +234,9 @@ std::shared_ptr HudRenderer::createInventory() { SlotLayout slotLayout(glm::vec2(), true, false, [=](ItemStack& stack) { stack.clear(); }, nullptr); - - int columns = 10; - int rows = ceildiv(inventory->size(), columns); - int padding = 4; InventoryBuilder builder; - builder.addGrid(columns, rows, glm::vec2(), padding, slotLayout); + builder.addGrid(10, inventory->size(), glm::vec2(), 4, slotLayout); auto layout = builder.build(); auto view = std::make_shared( From 6430121cf281d474aea60041a20d9385f6b76b80 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 21 Jan 2024 19:46:35 +0300 Subject: [PATCH 03/11] addGrid extra slots creation fix --- src/frontend/InventoryView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 70966c06..e10f2032 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -96,6 +96,8 @@ void InventoryBuilder::addGrid( for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { + if (row * cols + col >= count) + return; glm::vec2 position ( col * (slotSize + interval) + padding, row * (slotSize + interval) + padding From 714a49685f5d24b782708470dfb6a10103134d7b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 21 Jan 2024 22:29:14 +0300 Subject: [PATCH 04/11] Texture.readData --- src/graphics/Texture.cpp | 69 +++++++++++++++++++++++----------------- src/graphics/Texture.h | 2 ++ 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 0d5ae803..5531be1e 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -1,52 +1,61 @@ #include "Texture.h" #include #include +#include #include "ImageData.h" Texture::Texture(uint id, int width, int height) - : id(id), width(width), height(height) { + : id(id), width(width), height(height) { } Texture::Texture(ubyte* data, int width, int height, uint format) - : width(width), height(height) { - glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, id); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, - format, GL_UNSIGNED_BYTE, (GLvoid *) data); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glGenerateMipmap(GL_TEXTURE_2D); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2); - glBindTexture(GL_TEXTURE_2D, 0); + : width(width), height(height) { + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, + format, GL_UNSIGNED_BYTE, (GLvoid *) data); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2); + glBindTexture(GL_TEXTURE_2D, 0); } Texture::~Texture() { - glDeleteTextures(1, &id); + glDeleteTextures(1, &id); } void Texture::bind(){ - glBindTexture(GL_TEXTURE_2D, id); + glBindTexture(GL_TEXTURE_2D, id); } void Texture::reload(ubyte* data){ - glBindTexture(GL_TEXTURE_2D, id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data); - glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_2D, id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data); + glBindTexture(GL_TEXTURE_2D, 0); +} + +ImageData* Texture::readData() { + std::unique_ptr data (new ubyte[width * height * 4]); + glBindTexture(GL_TEXTURE_2D, id); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.get()); + glBindTexture(GL_TEXTURE_2D, 0); + return new ImageData(ImageFormat::rgba8888, width, height, data.release()); } Texture* Texture::from(const ImageData* image) { - uint width = image->getWidth(); - uint height = image->getHeight(); - uint format; - const void* data = image->getData(); - switch (image->getFormat()) { - case ImageFormat::rgb888: format = GL_RGB; break; - case ImageFormat::rgba8888: format = GL_RGBA; break; - default: - throw std::runtime_error("unsupported image data format"); - } - return new Texture((ubyte*)data, width, height, format); -} \ No newline at end of file + uint width = image->getWidth(); + uint height = image->getHeight(); + uint format; + const void* data = image->getData(); + switch (image->getFormat()) { + case ImageFormat::rgb888: format = GL_RGB; break; + case ImageFormat::rgba8888: format = GL_RGBA; break; + default: + throw std::runtime_error("unsupported image data format"); + } + return new Texture((ubyte*)data, width, height, format); +} diff --git a/src/graphics/Texture.h b/src/graphics/Texture.h index 4e85cb86..595ba411 100644 --- a/src/graphics/Texture.h +++ b/src/graphics/Texture.h @@ -18,6 +18,8 @@ public: void bind(); void reload(ubyte* data); + ImageData* readData(); + static Texture* from(const ImageData* image); }; From db2108171cc42175e8661184b1bb6558c8612ab5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 21 Jan 2024 23:35:41 +0300 Subject: [PATCH 05/11] inventory render optimized --- src/constants.h | 2 + src/frontend/BlocksPreview.cpp | 112 +++++++---- src/frontend/BlocksPreview.h | 24 +-- src/frontend/InventoryView.cpp | 29 +-- src/frontend/InventoryView.h | 3 +- src/frontend/LevelFrontend.cpp | 12 +- src/frontend/LevelFrontend.h | 5 +- src/frontend/hud.cpp | 340 ++++++++++++++++----------------- src/graphics/Framebuffer.cpp | 6 +- src/graphics/Framebuffer.h | 2 +- src/window/Window.cpp | 4 + src/window/Window.h | 1 + 12 files changed, 285 insertions(+), 255 deletions(-) diff --git a/src/constants.h b/src/constants.h index dd5e56e0..f9cc1d4b 100644 --- a/src/constants.h +++ b/src/constants.h @@ -17,6 +17,8 @@ const int CHUNK_D = 16; const uint VOXEL_USER_BITS = 8; constexpr uint VOXEL_USER_BITS_OFFSET = sizeof(blockstate_t)*8-VOXEL_USER_BITS; +const int ITEM_ICON_SIZE = 48; + /* Chunk volume (count of voxels per Chunk) */ constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D); diff --git a/src/frontend/BlocksPreview.cpp b/src/frontend/BlocksPreview.cpp index 846afc4a..723cdc10 100644 --- a/src/frontend/BlocksPreview.cpp +++ b/src/frontend/BlocksPreview.cpp @@ -8,47 +8,23 @@ #include "../graphics/Texture.h" #include "../graphics/Atlas.h" #include "../graphics/Batch3D.h" +#include "../graphics/Framebuffer.h" +#include "../graphics/GfxContext.h" +#include "../window/Window.h" #include "../window/Camera.h" #include "../voxels/Block.h" +#include "../content/Content.h" +#include "../constants.h" #include "ContentGfxCache.h" -BlocksPreview::BlocksPreview(Assets* assets, const ContentGfxCache* cache) - : shader(assets->getShader("ui3d")), - atlas(assets->getAtlas("blocks")), - cache(cache) { - batch = std::make_unique(1024); -} - -BlocksPreview::~BlocksPreview() { -} - -void BlocksPreview::begin(const Viewport* viewport) { - this->viewport = viewport; - shader->use(); - shader->uniformMatrix("u_projview", - glm::ortho(0.0f, float(viewport->getWidth()), - 0.0f, float(viewport->getHeight()), - -100.0f, 100.0f) * - glm::lookAt(glm::vec3(2, 2, 2), glm::vec3(0.0f), glm::vec3(0, 1, 0))); - atlas->getTexture()->bind(); -} - -/* Draw one block preview at given screen position */ -void BlocksPreview::draw(const Block* def, int x, int y, int size, glm::vec4 tint) { - uint width = viewport->getWidth(); - uint height = viewport->getHeight(); - - y = height - y - 1 - 35 /* magic garbage */; - x += 2; - - if (def->model == BlockModel::aabb) { - x += (1.0f - def->hitbox.size()).x * size * 0.5f; - y += (1.0f - def->hitbox.size()).y * size * 0.25f; - } - - glm::vec3 offset (x/float(width) * 2, y/float(height) * 2, 0.0f); - shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset)); - +ImageData* BlocksPreview::draw( + const ContentGfxCache* cache, + Framebuffer* fbo, + Batch3D* batch, + const Block* def, + int size +){ + Window::clear(); blockid_t id = def->rt.id; const UVRegion texfaces[6]{cache->getRegion(id, 0), cache->getRegion(id, 1), cache->getRegion(id, 2), cache->getRegion(id, 3), @@ -59,11 +35,11 @@ void BlocksPreview::draw(const Block* def, int x, int y, int size, glm::vec4 tin // something went wrong... break; case BlockModel::block: - batch->blockCube(glm::vec3(size * 0.63f), texfaces, tint, !def->rt.emissive); + batch->blockCube(glm::vec3(size * 0.63f), texfaces, glm::vec4(1.0f), !def->rt.emissive); break; case BlockModel::aabb: batch->blockCube(def->hitbox.size() * glm::vec3(size * 0.63f), - texfaces, tint, !def->rt.emissive); + texfaces, glm::vec4(1.0f), !def->rt.emissive); break; case BlockModel::custom: case BlockModel::xsprite: { @@ -73,10 +49,64 @@ void BlocksPreview::draw(const Block* def, int x, int y, int size, glm::vec4 tin right, size*0.5f, size*0.6f, texfaces[0], - tint); + glm::vec4(1.0f)); break; } } - batch->flush(); + return fbo->texture->readData(); +} + +std::unique_ptr BlocksPreview::build( + const ContentGfxCache* cache, + Assets* assets, + const Content* content +) { + auto indices = content->getIndices(); + size_t count = indices->countBlockDefs(); + size_t iconSize = ITEM_ICON_SIZE; + + Shader* shader = assets->getShader("ui3d"); + Atlas* atlas = assets->getAtlas("blocks"); + + Viewport viewport(iconSize, iconSize); + GfxContext pctx(nullptr, viewport, nullptr); + GfxContext ctx = pctx.sub(); + ctx.cullFace(true); + ctx.depthTest(true); + + Framebuffer fbo(iconSize, iconSize, true); + Batch3D batch(1024); + batch.begin(); + + shader->use(); + shader->uniformMatrix("u_projview", + + glm::ortho(0.0f, float(iconSize), 0.0f, float(iconSize), + -100.0f, 100.0f) * + glm::lookAt(glm::vec3(2, 2, 2), + glm::vec3(0.0f), + glm::vec3(0, 1, 0))); + + AtlasBuilder builder; + Window::viewport(0, 0, iconSize, iconSize); + Window::setBgColor(glm::vec4(0.0f)); + + fbo.bind(); + for (size_t i = 0; i < count; i++) { + auto def = indices->getBlockDef(i); + + glm::vec3 offset(0.1f, 0.5f, 0.1f); + if (def->model == BlockModel::aabb) { + offset.y += (1.0f - def->hitbox.size()).y * 0.5f; + } + atlas->getTexture()->bind(); + shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset)); + + builder.add(def->name, draw(cache, &fbo, &batch, def, iconSize)); + } + fbo.unbind(); + + Window::viewport(0, 0, Window::width, Window::height); + return std::unique_ptr(builder.build(2)); } diff --git a/src/frontend/BlocksPreview.h b/src/frontend/BlocksPreview.h index 0a1a03f3..5c4ab4c1 100644 --- a/src/frontend/BlocksPreview.h +++ b/src/frontend/BlocksPreview.h @@ -6,25 +6,27 @@ #include class Assets; -class Viewport; -class Shader; +class ImageData; class Atlas; +class Framebuffer; class Batch3D; class Block; +class Content; class ContentGfxCache; class BlocksPreview { - Shader* shader; - Atlas* atlas; - std::unique_ptr batch; - const ContentGfxCache* const cache; - const Viewport* viewport; public: - BlocksPreview(Assets* assets, const ContentGfxCache* cache); - ~BlocksPreview(); + static ImageData* draw( + const ContentGfxCache* cache, + Framebuffer* framebuffer, + Batch3D* batch, + const Block* block, + int size); - void begin(const Viewport* viewport); - void draw(const Block* block, int x, int y, int size, glm::vec4 tint); + static std::unique_ptr build( + const ContentGfxCache* cache, + Assets* assets, + const Content* content); }; #endif // FRONTEND_BLOCKS_PREVIEW_H_ diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index e10f2032..93c2f0bc 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -153,31 +153,26 @@ void SlotView::draw(Batch2D* batch, Assets* assets) { batch->color = glm::vec4(1.0f); - Shader* uiShader = assets->getShader("ui"); Viewport viewport(Window::width, Window::height); GfxContext ctx(nullptr, viewport, batch); - auto preview = frontend->getBlocksPreview(); + auto previews = frontend->getBlocksAtlas(); auto indices = content->getIndices(); ItemDef* item = indices->getItemDef(stack.getItemId()); switch (item->iconType) { case item_icon_type::none: break; - case item_icon_type::block: - batch->render(); - { - GfxContext subctx = ctx.sub(); - subctx.depthTest(true); - subctx.cullFace(true); + case item_icon_type::block: { + Block* cblock = content->requireBlock(item->icon); + batch->texture(previews->getTexture()); - Block* cblock = content->requireBlock(item->icon); - preview->begin(&subctx.getViewport()); - preview->draw(cblock, coord.x, coord.y, slotSize, tint); - } - uiShader->use(); - batch->begin(); + UVRegion region = previews->get(cblock->name); + batch->rect( + coord.x, coord.y, slotSize, slotSize, + 0, 0, 0, region, false, true, tint); break; + } case item_icon_type::sprite: { size_t index = item->icon.find(':'); std::string name = item->icon.substr(index+1); @@ -327,12 +322,6 @@ InventoryLayout* InventoryView::getLayout() const { return layout.get(); } -// performance disaster x2 -void InventoryView::draw(Batch2D* batch, Assets* assets) { - Container::draw(batch, assets); - Window::clearDepth(); -} - void InventoryView::drawBackground(Batch2D* batch, Assets* assets) { glm::vec2 coord = calcCoord(); batch->texture(nullptr); diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index 5c7df130..c8c4801d 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -126,7 +126,6 @@ public: void build(); - virtual void draw(Batch2D* batch, Assets* assets) override; virtual void drawBackground(Batch2D* batch, Assets* assets) override; void setInventory(std::shared_ptr inventory); @@ -138,7 +137,7 @@ public: void setSelected(int index); static const int SLOT_INTERVAL = 4; - static const int SLOT_SIZE = 48; + static const int SLOT_SIZE = ITEM_ICON_SIZE; }; class InventoryInteraction { diff --git a/src/frontend/LevelFrontend.cpp b/src/frontend/LevelFrontend.cpp index 4b1c6542..9561dfb2 100644 --- a/src/frontend/LevelFrontend.cpp +++ b/src/frontend/LevelFrontend.cpp @@ -2,6 +2,7 @@ #include "../world/Level.h" #include "../assets/Assets.h" +#include "../graphics/Atlas.h" #include "BlocksPreview.h" #include "ContentGfxCache.h" @@ -9,8 +10,7 @@ LevelFrontend::LevelFrontend(Level* level, Assets* assets) : level(level), assets(assets), contentCache(std::make_unique(level->content, assets)), - blocksPreview(std::make_unique(assets, contentCache.get())) { - + blocksAtlas(BlocksPreview::build(contentCache.get(), assets, level->content)) { } LevelFrontend::~LevelFrontend() { @@ -24,10 +24,10 @@ Assets* LevelFrontend::getAssets() const { return assets; } -BlocksPreview* LevelFrontend::getBlocksPreview() const { - return blocksPreview.get(); -} - ContentGfxCache* LevelFrontend::getContentGfxCache() const { return contentCache.get(); } + +Atlas* LevelFrontend::getBlocksAtlas() const { + return blocksAtlas.get(); +} diff --git a/src/frontend/LevelFrontend.h b/src/frontend/LevelFrontend.h index 095f5535..98a8a111 100644 --- a/src/frontend/LevelFrontend.h +++ b/src/frontend/LevelFrontend.h @@ -3,6 +3,7 @@ #include +class Atlas; class Level; class Assets; class BlocksPreview; @@ -12,15 +13,15 @@ class LevelFrontend { Level* level; Assets* assets; std::unique_ptr contentCache; - std::unique_ptr blocksPreview; + std::unique_ptr blocksAtlas; public: LevelFrontend(Level* level, Assets* assets); ~LevelFrontend(); Level* getLevel() const; Assets* getAssets() const; - BlocksPreview* getBlocksPreview() const; ContentGfxCache* getContentGfxCache() const; + Atlas* getBlocksAtlas() const; }; diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index ea82473e..4d0a5493 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -52,106 +52,106 @@ using glm::vec4; using namespace gui; inline std::shared_ptr