many little fixes

This commit is contained in:
lllzebralll 2022-11-08 14:49:10 +03:00
parent 815aa90489
commit b1e5a3c6fb
6 changed files with 48 additions and 42 deletions

View File

@ -417,43 +417,43 @@ inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const
{SETUP_UV(block->textureFaces[1]); {SETUP_UV(block->textureFaces[1]);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0); VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr1,lg1,lb1,ls1); VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2); VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr2,lg2,lb2,ls2);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0); VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2); VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr2,lg2,lb2,ls2);
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr3,lg3,lb3,ls3);} VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr3,lg3,lb3,ls3);}
{SETUP_UV(block->textureFaces[0]); {SETUP_UV(block->textureFaces[0]);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0); VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1); VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr2,lg2,lb2,ls2); VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr2,lg2,lb2,ls2);
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0); VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr3,lg3,lb3,ls3); VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr3,lg3,lb3,ls3);
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);} VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);}
{SETUP_UV(block->textureFaces[5]); {SETUP_UV(block->textureFaces[5]);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4); VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5); VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr5,lg5,lb5,ls5);
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr6,lg6,lb6,ls6); VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr6,lg6,lb6,ls6);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4); VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr7,lg7,lb7,ls7); VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr7,lg7,lb7,ls7);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);} VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr5,lg5,lb5,ls5);}
{SETUP_UV(block->textureFaces[4]); {SETUP_UV(block->textureFaces[4]);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4); VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr5,lg5,lb5,ls5); VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr5,lg5,lb5,ls5);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6); VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr6,lg6,lb6,ls6);
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4); VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr4,lg4,lb4,ls4);
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6); VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr6,lg6,lb6,ls6);
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr7,lg7,lb7,ls7);} VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr7,lg7,lb7,ls7);}
} }
const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& size){ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& size){
@ -509,7 +509,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x]; voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
if (vox.id == 0) if (vox.id == 0)
continue; continue;
if (Block::blocks[vox.id]->model != BLOCK_MODEL_GRASS) if (Block::blocks[vox.id]->model != BLOCK_MODEL_X_SPRITE)
continue; continue;
_renderXBlock(buffer, x, y, z, chunks, vox, index); _renderXBlock(buffer, x, y, z, chunks, vox, index);
} }

View File

@ -95,36 +95,42 @@ void HudRenderer::draw(Level* level, Assets* assets){
Block* cblock = Block::blocks[player->choosenBlock]; Block* cblock = Block::blocks[player->choosenBlock];
if (cblock->model == BLOCK_MODEL_CUBE){ if (cblock->model == BLOCK_MODEL_CUBE){
batch->blockSprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f)); batch->blockSprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
} else if (cblock->model == BLOCK_MODEL_GRASS){ } else if (cblock->model == BLOCK_MODEL_X_SPRITE){
batch->sprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f)); batch->sprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
} }
} }
if (!Events::_cursor_locked) { if (!Events::_cursor_locked) {
int size = 48;
int step = 70;
int y = uicamera->fov - 72 - 70;
int x = 0;
vec4 tint = vec4(1.0f);
int mx = Events::x;
int my = Events::y;
for (unsigned i = 1; i < 256; i++) { for (unsigned i = 1; i < 256; i++) {
Block* cblock = Block::blocks[i]; Block* cblock = Block::blocks[i];
if (cblock == nullptr) if (cblock == nullptr)
break; break;
int size = 48; x = 24 + (i-1) * step;
int step = 70;
int x = 24 + (i-1) * step;
int y = uicamera->fov - 72 - 70;
y -= 72 * (x / (Window::width - step)); y -= 72 * (x / (Window::width - step));
x %= (Window::width - step); x %= (Window::width - step);
vec4 tint(1.0f);
int mx = Events::x;
int my = Events::y;
if (mx > x && mx < x + size && my > y && my < y + size) { if (mx > x && mx < x + size && my > y && my < y + size) {
tint.r *= 2.0f; tint.r *= 1.3f;
tint.g *= 2.0f; tint.g *= 1.3f;
tint.b *= 2.0f; tint.b *= 1.3f;
if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) { if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) {
player->choosenBlock = i; player->choosenBlock = i;
} }
} else
{
tint = vec4(1.0f);
} }
if (cblock->model == BLOCK_MODEL_CUBE){ if (cblock->model == BLOCK_MODEL_CUBE){
batch->blockSprite(x, y, size, size, 16, cblock->textureFaces, tint); batch->blockSprite(x, y, size, size, 16, cblock->textureFaces, tint);
} else if (cblock->model == BLOCK_MODEL_GRASS){ } else if (cblock->model == BLOCK_MODEL_X_SPRITE){
batch->sprite(x, y, size, size, 16, cblock->textureFaces[3], tint); batch->sprite(x, y, size, size, 16, cblock->textureFaces[3], tint);
} }
} }

View File

@ -189,7 +189,7 @@ void PlayerController::update_interaction(){
int x = (int)(iend.x)+(int)(norm.x); int x = (int)(iend.x)+(int)(norm.x);
int y = (int)(iend.y)+(int)(norm.y); int y = (int)(iend.y)+(int)(norm.y);
int z = (int)(iend.z)+(int)(norm.z); int z = (int)(iend.z)+(int)(norm.z);
if (block->model == BLOCK_MODEL_GRASS){ if (block->model == BLOCK_MODEL_X_SPRITE){
x = (int)iend.x; x = (int)iend.x;
y = (int)iend.y; y = (int)iend.y;
z = (int)iend.z; z = (int)iend.z;

View File

@ -120,7 +120,7 @@ void mainloop(Level* level, Assets* assets) {
float delta = 0.0f; float delta = 0.0f;
bool occlusion = true; bool occlusion = true;
bool devdata = false; bool devdata = false;
Window::swapInterval(0); Window::swapInterval(1);
while (!Window::isShouldClose()){ while (!Window::isShouldClose()){
frame++; frame++;
float currentTime = glfwGetTime(); float currentTime = glfwGetTime();

View File

@ -2,7 +2,7 @@
#define VOXELS_BLOCK_H_ #define VOXELS_BLOCK_H_
#define BLOCK_MODEL_CUBE 1 #define BLOCK_MODEL_CUBE 1
#define BLOCK_MODEL_GRASS 2 #define BLOCK_MODEL_X_SPRITE 2
class Block { class Block {
public: public:

View File

@ -142,10 +142,10 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
} }
if (real_y <= 2) if (real_y <= 2)
id = BLOCK_BEDROCK; id = BLOCK_BEDROCK;
if ((id == 0) && (real_y > 55) && ((int)height + 1 == real_y) && ((unsigned short)random() > 56000)){ if ((id == 0) && (real_y > 55) && ((int)(height + 0.5f) == real_y) && ((unsigned short)random() > 56000)){
id = BLOCK_GRASS; id = BLOCK_GRASS;
} }
if ((id == 0) && (real_y > 55) && ((int)height + 1 == real_y) && ((unsigned short)random() > 64000)){ if ((id == 0) && (real_y > 55) && ((int)(height + 0.5f) == real_y) && ((unsigned short)random() > 64000)){
id = BLOCK_FLOWER; id = BLOCK_FLOWER;
} }
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id; voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;