refactor
This commit is contained in:
@@ -96,7 +96,7 @@ assetload::postfunc assetload::atlas(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::set<std::string> names = builder.getNames();
|
std::set<std::string> names = builder.getNames();
|
||||||
Atlas* atlas = builder.build(2, false);
|
Atlas* atlas = builder.build(2, false).release();
|
||||||
return [=](auto assets) {
|
return [=](auto assets) {
|
||||||
atlas->prepare();
|
atlas->prepare();
|
||||||
assets->store(atlas, name);
|
assets->store(atlas, name);
|
||||||
@@ -247,7 +247,7 @@ static bool animation(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Atlas> srcAtlas (builder.build(2));
|
auto srcAtlas = builder.build(2);
|
||||||
srcAtlas->prepare();
|
srcAtlas->prepare();
|
||||||
|
|
||||||
Texture* srcTex = srcAtlas->getTexture();
|
Texture* srcTex = srcAtlas->getTexture();
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
|
|
||||||
batch->setColor(glm::vec4(1.0f));
|
batch->setColor(glm::vec4(1.0f));
|
||||||
|
|
||||||
auto previews = frontend->getBlocksAtlas();
|
auto previews = assets->getAtlas("block-previews");
|
||||||
auto indices = content->getIndices();
|
auto indices = content->getIndices();
|
||||||
|
|
||||||
ItemDef* item = indices->getItemDef(stack.getItemId());
|
ItemDef* item = indices->getItemDef(stack.getItemId());
|
||||||
@@ -181,7 +181,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
int x = pos.x+slotSize-text.length()*8;
|
int x = pos.x+slotSize-text.length()*8;
|
||||||
int y = pos.y+slotSize-16;
|
int y = pos.y+slotSize-16;
|
||||||
|
|
||||||
batch->setColor(glm::vec4(0, 0, 0, 1.0f));
|
batch->setColor({0, 0, 0, 1.0f});
|
||||||
font->draw(batch, text, x+1, y+1);
|
font->draw(batch, text, x+1, y+1);
|
||||||
batch->setColor(glm::vec4(1.0f));
|
batch->setColor(glm::vec4(1.0f));
|
||||||
font->draw(batch, text, x, y);
|
font->draw(batch, text, x, y);
|
||||||
@@ -266,13 +266,12 @@ void SlotView::onFocus(gui::GUI* gui) {
|
|||||||
void SlotView::bind(
|
void SlotView::bind(
|
||||||
int64_t inventoryid,
|
int64_t inventoryid,
|
||||||
ItemStack& stack,
|
ItemStack& stack,
|
||||||
LevelFrontend* frontend,
|
const Content* content,
|
||||||
InventoryInteraction* interaction
|
InventoryInteraction* interaction
|
||||||
) {
|
) {
|
||||||
this->inventoryid = inventoryid;
|
this->inventoryid = inventoryid;
|
||||||
bound = &stack;
|
bound = &stack;
|
||||||
content = frontend->getLevel()->content;
|
this->content = content;
|
||||||
this->frontend = frontend;
|
|
||||||
this->interaction = interaction;
|
this->interaction = interaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,21 +331,18 @@ void InventoryView::bind(
|
|||||||
slot->bind(
|
slot->bind(
|
||||||
inventory->getId(),
|
inventory->getId(),
|
||||||
inventory->getSlot(slot->getLayout().index),
|
inventory->getSlot(slot->getLayout().index),
|
||||||
frontend, interaction
|
content, interaction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::unbind() {
|
void InventoryView::unbind() {
|
||||||
if (inventory && inventory->isVirtual()) {
|
inventory = nullptr;
|
||||||
frontend->getLevel()->inventories->remove(inventory->getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::setSelected(int index) {
|
void InventoryView::setSelected(int index) {
|
||||||
for (int i = 0; i < int(slots.size()); i++) {
|
for (size_t i = 0; i < slots.size(); i++) {
|
||||||
auto slot = slots[i];
|
slots[i]->setHighlighted(static_cast<int>(i) == index);
|
||||||
slot->setHighlighted(i == index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ struct SlotLayout {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class SlotView : public gui::UINode {
|
class SlotView : public gui::UINode {
|
||||||
LevelFrontend* frontend = nullptr;
|
|
||||||
InventoryInteraction* interaction = nullptr;
|
InventoryInteraction* interaction = nullptr;
|
||||||
const Content* content;
|
const Content* content;
|
||||||
SlotLayout layout;
|
SlotLayout layout;
|
||||||
@@ -81,7 +80,7 @@ public:
|
|||||||
void bind(
|
void bind(
|
||||||
int64_t inventoryid,
|
int64_t inventoryid,
|
||||||
ItemStack& stack,
|
ItemStack& stack,
|
||||||
LevelFrontend* frontend,
|
const Content* content,
|
||||||
InventoryInteraction* interaction
|
InventoryInteraction* interaction
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ LevelFrontend::LevelFrontend(LevelController* controller, Assets* assets)
|
|||||||
: level(controller->getLevel()),
|
: level(controller->getLevel()),
|
||||||
controller(controller),
|
controller(controller),
|
||||||
assets(assets),
|
assets(assets),
|
||||||
contentCache(std::make_unique<ContentGfxCache>(level->content, assets)),
|
contentCache(std::make_unique<ContentGfxCache>(level->content, assets))
|
||||||
blocksAtlas(BlocksPreview::build(contentCache.get(), assets, level->content))
|
|
||||||
{
|
{
|
||||||
|
assets->store(
|
||||||
|
BlocksPreview::build(contentCache.get(), assets, level->content).release(),
|
||||||
|
"block-previews"
|
||||||
|
);
|
||||||
controller->getPlayerController()->listenBlockInteraction(
|
controller->getPlayerController()->listenBlockInteraction(
|
||||||
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
|
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
|
||||||
auto material = level->content->findBlockMaterial(def->material);
|
auto material = level->content->findBlockMaterial(def->material);
|
||||||
@@ -79,10 +82,6 @@ ContentGfxCache* LevelFrontend::getContentGfxCache() const {
|
|||||||
return contentCache.get();
|
return contentCache.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas* LevelFrontend::getBlocksAtlas() const {
|
|
||||||
return blocksAtlas.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
LevelController* LevelFrontend::getController() const {
|
LevelController* LevelFrontend::getController() const {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class Atlas;
|
|
||||||
class Level;
|
class Level;
|
||||||
class Assets;
|
class Assets;
|
||||||
class BlocksPreview;
|
|
||||||
class ContentGfxCache;
|
class ContentGfxCache;
|
||||||
class LevelController;
|
class LevelController;
|
||||||
|
|
||||||
@@ -15,7 +13,6 @@ class LevelFrontend {
|
|||||||
LevelController* controller;
|
LevelController* controller;
|
||||||
Assets* assets;
|
Assets* assets;
|
||||||
std::unique_ptr<ContentGfxCache> contentCache;
|
std::unique_ptr<ContentGfxCache> contentCache;
|
||||||
std::unique_ptr<Atlas> blocksAtlas;
|
|
||||||
public:
|
public:
|
||||||
LevelFrontend(LevelController* controller, Assets* assets);
|
LevelFrontend(LevelController* controller, Assets* assets);
|
||||||
~LevelFrontend();
|
~LevelFrontend();
|
||||||
@@ -23,8 +20,6 @@ public:
|
|||||||
Level* getLevel() const;
|
Level* getLevel() const;
|
||||||
Assets* getAssets() const;
|
Assets* getAssets() const;
|
||||||
ContentGfxCache* getContentGfxCache() const;
|
ContentGfxCache* getContentGfxCache() const;
|
||||||
Atlas* getBlocksAtlas() const;
|
|
||||||
|
|
||||||
LevelController* getController() const;
|
LevelController* getController() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
|
|||||||
grabbedItemView->bind(
|
grabbedItemView->bind(
|
||||||
0,
|
0,
|
||||||
interaction->getGrabbedItem(),
|
interaction->getGrabbedItem(),
|
||||||
frontend,
|
frontend->getLevel()->content,
|
||||||
interaction.get()
|
interaction.get()
|
||||||
);
|
);
|
||||||
grabbedItemView->setColor(glm::vec4());
|
grabbedItemView->setColor(glm::vec4());
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ bool AtlasBuilder::has(const std::string& name) const {
|
|||||||
return names.find(name) != names.end();
|
return names.find(name) != names.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas* AtlasBuilder::build(uint extrusion, bool prepare, uint maxResolution) {
|
std::unique_ptr<Atlas> AtlasBuilder::build(uint extrusion, bool prepare, uint maxResolution) {
|
||||||
if (maxResolution == 0) {
|
if (maxResolution == 0) {
|
||||||
maxResolution = Texture::MAX_RESOLUTION;
|
maxResolution = Texture::MAX_RESOLUTION;
|
||||||
}
|
}
|
||||||
@@ -99,5 +99,5 @@ Atlas* AtlasBuilder::build(uint extrusion, bool prepare, uint maxResolution) {
|
|||||||
unitX * x, unitY * y, unitX * (x + w), unitY * (y + h)
|
unitX * x, unitY * y, unitX * (x + w), unitY * (y + h)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return new Atlas(std::move(canvas), regions, prepare);
|
return std::make_unique<Atlas>(std::move(canvas), regions, prepare);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
/// (greather is less mip-mapping artifacts)
|
/// (greather is less mip-mapping artifacts)
|
||||||
/// @param prepare generate atlas texture (calls .prepare())
|
/// @param prepare generate atlas texture (calls .prepare())
|
||||||
/// @param maxResolution max atlas resolution
|
/// @param maxResolution max atlas resolution
|
||||||
Atlas* build(uint extrusion, bool prepare=true, uint maxResolution=0);
|
std::unique_ptr<Atlas> build(uint extrusion, bool prepare=true, uint maxResolution=0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRAPHICS_CORE_ATLAS_HPP_
|
#endif // GRAPHICS_CORE_ATLAS_HPP_
|
||||||
|
|||||||
@@ -55,9 +55,11 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
|||||||
break;
|
break;
|
||||||
case BlockModel::custom:
|
case BlockModel::custom:
|
||||||
{
|
{
|
||||||
|
glm::vec3 pmul = glm::vec3(size * 0.63f);
|
||||||
glm::vec3 hitbox = glm::vec3();
|
glm::vec3 hitbox = glm::vec3();
|
||||||
for (const auto& box : def->modelBoxes)
|
for (const auto& box : def->modelBoxes) {
|
||||||
hitbox = glm::max(hitbox, box.size());
|
hitbox = glm::max(hitbox, box.size());
|
||||||
|
}
|
||||||
offset.y += (1.0f - hitbox).y * 0.5f;
|
offset.y += (1.0f - hitbox).y * 0.5f;
|
||||||
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
||||||
for (size_t i = 0; i < def->modelBoxes.size(); i++) {
|
for (size_t i = 0; i < def->modelBoxes.size(); i++) {
|
||||||
@@ -69,28 +71,39 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
|||||||
def->modelUVs[i * 6 + 4],
|
def->modelUVs[i * 6 + 4],
|
||||||
def->modelUVs[i * 6 + 5]
|
def->modelUVs[i * 6 + 5]
|
||||||
};
|
};
|
||||||
batch->cube(def->modelBoxes[i].a * glm::vec3(1.0f, 1.0f, -1.0f) * glm::vec3(size * 0.63f), def->modelBoxes[i].size() * glm::vec3(size * 0.63f), texfaces, glm::vec4(1.0f), !def->rt.emissive);
|
batch->cube(
|
||||||
|
def->modelBoxes[i].a * glm::vec3(1.0f, 1.0f, -1.0f) * pmul,
|
||||||
|
def->modelBoxes[i].size() * pmul,
|
||||||
|
texfaces, glm::vec4(1.0f), !def->rt.emissive
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& points = def->modelExtraPoints;
|
||||||
|
glm::vec3 poff = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
for (size_t i = 0; i < def->modelExtraPoints.size() / 4; i++) {
|
for (size_t i = 0; i < def->modelExtraPoints.size() / 4; i++) {
|
||||||
const UVRegion& reg = def->modelUVs[def->modelBoxes.size() * 6 + i];
|
const UVRegion& reg = def->modelUVs[def->modelBoxes.size() * 6 + i];
|
||||||
batch->point((def->modelExtraPoints[i * 4 + 0] - glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec3(size * 0.63f), glm::vec2(reg.u1, reg.v1), glm::vec4(1.0));
|
|
||||||
batch->point((def->modelExtraPoints[i * 4 + 1] - glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec3(size * 0.63f), glm::vec2(reg.u2, reg.v1), glm::vec4(1.0));
|
batch->point((points[i * 4 + 0] - poff) * pmul, glm::vec2(reg.u1, reg.v1), glm::vec4(1.0));
|
||||||
batch->point((def->modelExtraPoints[i * 4 + 2] - glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec3(size * 0.63f), glm::vec2(reg.u2, reg.v2), glm::vec4(1.0));
|
batch->point((points[i * 4 + 1] - poff) * pmul, glm::vec2(reg.u2, reg.v1), glm::vec4(1.0));
|
||||||
batch->point((def->modelExtraPoints[i * 4 + 0] - glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec3(size * 0.63f), glm::vec2(reg.u1, reg.v1), glm::vec4(1.0));
|
batch->point((points[i * 4 + 2] - poff) * pmul, glm::vec2(reg.u2, reg.v2), glm::vec4(1.0));
|
||||||
batch->point((def->modelExtraPoints[i * 4 + 2] - glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec3(size * 0.63f), glm::vec2(reg.u2, reg.v2), glm::vec4(1.0));
|
batch->point((points[i * 4 + 0] - poff) * pmul, glm::vec2(reg.u1, reg.v1), glm::vec4(1.0));
|
||||||
batch->point((def->modelExtraPoints[i * 4 + 3] - glm::vec3(0.0f, 0.0f, 1.0f)) * glm::vec3(size * 0.63f), glm::vec2(reg.u1, reg.v2), glm::vec4(1.0));
|
batch->point((points[i * 4 + 2] - poff) * pmul, glm::vec2(reg.u2, reg.v2), glm::vec4(1.0));
|
||||||
|
batch->point((points[i * 4 + 3] - poff) * pmul, glm::vec2(reg.u1, reg.v2), glm::vec4(1.0));
|
||||||
}
|
}
|
||||||
batch->flush();
|
batch->flush();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BlockModel::xsprite: {
|
case BlockModel::xsprite: {
|
||||||
glm::vec3 right = glm::normalize(glm::vec3(1.f, 0.f, -1.f));
|
glm::vec3 right = glm::normalize(glm::vec3(1.f, 0.f, -1.f));
|
||||||
batch->sprite(right*float(size)*0.43f+glm::vec3(0, size*0.4f, 0),
|
batch->sprite(
|
||||||
glm::vec3(0.f, 1.f, 0.f),
|
right*float(size)*0.43f+glm::vec3(0, size*0.4f, 0),
|
||||||
right,
|
glm::vec3(0.f, 1.f, 0.f),
|
||||||
size*0.5f, size*0.6f,
|
right,
|
||||||
texfaces[0],
|
size*0.5f, size*0.6f,
|
||||||
glm::vec4(1.0f));
|
texfaces[0],
|
||||||
|
glm::vec4(1.0f)
|
||||||
|
);
|
||||||
batch->flush();
|
batch->flush();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -141,6 +154,5 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
|||||||
fbo.unbind();
|
fbo.unbind();
|
||||||
|
|
||||||
Window::viewport(0, 0, Window::width, Window::height);
|
Window::viewport(0, 0, Window::width, Window::height);
|
||||||
auto newAtlas = std::unique_ptr<Atlas>(builder.build(2));
|
return builder.build(2);
|
||||||
return newAtlas;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ std::shared_ptr<Inventory> Inventories::createVirtual(size_t size) {
|
|||||||
|
|
||||||
auto inv = std::make_shared<Inventory>(id, size);
|
auto inv = std::make_shared<Inventory>(id, size);
|
||||||
store(inv);
|
store(inv);
|
||||||
return inv;
|
return std::shared_ptr<Inventory>(inv.get(), [this](Inventory* ptr) {
|
||||||
|
remove(ptr->getId());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inventories::store(std::shared_ptr<Inventory> inv) {
|
void Inventories::store(std::shared_ptr<Inventory> inv) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
Camera::Camera(glm::vec3 position, float fov) : fov(fov), position(position), zoom(1.0f), rotation(1.0f) {
|
Camera::Camera(glm::vec3 position, float fov) : fov(fov), position(position) {
|
||||||
updateVectors();
|
updateVectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -14,8 +14,8 @@ public:
|
|||||||
|
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
|
|
||||||
float zoom;
|
float zoom = 1.0f;
|
||||||
glm::mat4 rotation;
|
glm::mat4 rotation {1.0f};
|
||||||
bool perspective = true;
|
bool perspective = true;
|
||||||
bool flipped = false;
|
bool flipped = false;
|
||||||
float aspect = 0.0f;
|
float aspect = 0.0f;
|
||||||
|
|||||||
Reference in New Issue
Block a user