Blocks atlas is auto-assembling now

This commit is contained in:
MihailRis
2023-11-22 01:53:48 +03:00
parent ea5c117652
commit fb8d220cca
41 changed files with 622 additions and 75 deletions
+1 -2
View File
@@ -162,8 +162,7 @@ InputBindBox::InputBindBox(Binding& binding, vec4 padding)
: Panel(vec2(100,32), padding, 0, false),
binding(binding) {
label = new Label(L"");
//label->align(Align::center);
add(shared_ptr<UINode>(label));
add(label);
}
shared_ptr<UINode> InputBindBox::getAt(vec2 pos, shared_ptr<UINode> self) {
+14 -9
View File
@@ -15,6 +15,7 @@
#include "../graphics/Shader.h"
#include "../graphics/Batch2D.h"
#include "../graphics/Font.h"
#include "../graphics/Atlas.h"
#include "../graphics/Mesh.h"
#include "../window/Camera.h"
#include "../window/Window.h"
@@ -146,6 +147,7 @@ void HudRenderer::drawContentAccess(const GfxContext& ctx, Player* player) {
const Viewport& viewport = ctx.getViewport();
const uint width = viewport.getWidth();
Atlas* atlas = assets->getAtlas("blocks");
uint count = contentIds->countBlockDefs();
uint icon_size = 48;
@@ -171,7 +173,7 @@ void HudRenderer::drawContentAccess(const GfxContext& ctx, Player* player) {
batch->rect(inv_x, inv_y, inv_w, inv_h);
// blocks & items
batch->texture(assets->getTexture("block_tex"));
batch->texture(atlas->getTexture());
for (uint i = 0; i < count-1; i++) {
Block* cblock = contentIds->getBlockDef(i+1);
if (cblock == nullptr)
@@ -190,9 +192,10 @@ void HudRenderer::drawContentAccess(const GfxContext& ctx, Player* player) {
}
if (cblock->model == BlockModel::block){
batch->blockSprite(x, y, icon_size, icon_size, 16, cblock->textureFaces, tint);
batch->blockSprite(x, y, icon_size, icon_size, (const UVRegion*)cblock->uvdata, tint);
} else if (cblock->model == BlockModel::xsprite){
batch->sprite(x, y, icon_size, icon_size, 16, cblock->textureFaces[3], tint);
const UVRegion& region = (reinterpret_cast<UVRegion*>(cblock->uvdata))[3];
batch->sprite(x, y, icon_size, icon_size, region, tint);
}
}
}
@@ -231,6 +234,8 @@ void HudRenderer::draw(const GfxContext& ctx){
const uint width = viewport.getWidth();
const uint height = viewport.getHeight();
Atlas* atlas = assets->getAtlas("blocks");
debugPanel->visible(level->player->debug);
uicamera->fov = height;
@@ -239,10 +244,9 @@ void HudRenderer::draw(const GfxContext& ctx){
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjection()*uicamera->getView());
// Chosen block preview
Texture* blocks = assets->getTexture("block_tex");
batch->begin();
batch->texture(nullptr);
// Chosen block preview
batch->color = vec4(1.0f);
if (Events::_cursor_locked && !level->player->debug) {
batch->lineWidth(2);
@@ -258,14 +262,15 @@ void HudRenderer::draw(const GfxContext& ctx){
batch->rect(width - 68, height - 68, 68, 68);
batch->color = vec4(1.0f);
batch->texture(blocks);
batch->texture(atlas->getTexture());
{
Block* cblock = contentIds->getBlockDef(player->choosenBlock);
assert(cblock != nullptr);
if (cblock->model == BlockModel::block){
batch->blockSprite(width-56, uicamera->fov - 56, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
batch->blockSprite(width-56, uicamera->fov - 56, 48, 48, (const UVRegion*)cblock->uvdata, vec4(1.0f));
} else if (cblock->model == BlockModel::xsprite){
batch->sprite(width-56, uicamera->fov - 56, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
const UVRegion& region = (reinterpret_cast<UVRegion*>(cblock->uvdata))[3];
batch->sprite(width-56, uicamera->fov - 56, 48, 48, region, vec4(1.0f));
}
}
+24 -2
View File
@@ -10,6 +10,7 @@
#include "../window/Window.h"
#include "../window/Camera.h"
#include "../graphics/Mesh.h"
#include "../graphics/Atlas.h"
#include "../graphics/Shader.h"
#include "../graphics/Texture.h"
#include "../graphics/LineBatch.h"
@@ -27,6 +28,7 @@
#include "../engine.h"
using glm::vec3;
using std::string;
using std::shared_ptr;
WorldRenderer::WorldRenderer(Engine* engine, Level* level)
@@ -37,6 +39,26 @@ WorldRenderer::WorldRenderer(Engine* engine, Level* level)
level->events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
renderer->unload(chunk);
});
// TODO: move to some proper place
// otrefactoryu dnem
Assets* assets = engine->getAssets();
Atlas* atlas = assets->getAtlas("blocks");
const Content* content = level->content;
const ContentIndices* contentIds = content->indices;
for (uint i = 0; i < contentIds->countBlockDefs(); i++) {
Block* def = contentIds->getBlockDef(i);
for (uint side = 0; side < 6; side++) {
string tex = def->textureFaces[side];
if (atlas->has(tex)) {
UVRegion region = atlas->get(tex);
float* data = reinterpret_cast<float*>(&region);
for (uint j = 0; j < 4; j++) {
def->uvdata[side * 4 + j] = data[j];
}
}
}
}
}
WorldRenderer::~WorldRenderer() {
@@ -99,7 +121,7 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera, bool occlusion)
const Content* content = level->content;
const ContentIndices* contentIds = content->indices;
Assets* assets = engine->getAssets();
Texture* texture = assets->getTexture("block");
Atlas* atlas = assets->getAtlas("blocks");
Shader* shader = assets->getShader("main");
Shader* linesShader = assets->getShader("lines");
@@ -139,7 +161,7 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera, bool occlusion)
cblock->emission[1] / 15.0f * multiplier,
cblock->emission[2] / 15.0f * multiplier);
shader->uniform1f("u_torchlightDistance", 6.0f);
texture->bind();
atlas->getTexture()->bind();
Chunks* chunks = level->chunks;
drawChunks(chunks, camera, shader, occlusion);