Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 15, 2023
1 parent aa88fcd commit be980b2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
5 changes: 4 additions & 1 deletion res/main.glslv
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ void main(){
vec2 pos2d = (u_model * vec4(v_position, 1.0)).xz-u_cameraPos.xz;
vec4 modelpos = u_model * vec4(v_position+vec3(0,pow(length(pos2d)*0.0, 3.0),0), 1.0);
vec4 viewmodelpos = u_view * modelpos;
vec3 light = v_light.rgb;
vec3 light = v_light.rgb * 1.6;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz)/u_torchlightDistance);
light += torchlight * u_torchlightColor;
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
a_texCoord = v_texCoord;
a_color.rgb += u_skyLightColor * v_light.a;
a_color.r = min(a_color.r, 1.1);
a_color.g = min(a_color.g, 1.1);
a_color.b = min(a_color.b, 1.1);
a_distance = length(viewmodelpos);
gl_Position = u_proj * viewmodelpos;
}
6 changes: 3 additions & 3 deletions src/definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void setup_definitions() {
block->skyLightPassing = true;
block->obstacle = false;
block->selectable = false;
block->model = 0;
block->model = BlockModel::none;
Block::blocks[block->id] = block;

block = new Block(BLOCK_DIRT, 2);
Expand Down Expand Up @@ -71,15 +71,15 @@ void setup_definitions() {
block->drawGroup = 5;
block->lightPassing = true;
block->obstacle = false;
block->model = 2;
block->model = BlockModel::xsprite;
block->hitboxScale = 0.5f;
Block::blocks[block->id] = block;

block = new Block(BLOCK_FLOWER, 16);
block->drawGroup = 5;
block->lightPassing = true;
block->obstacle = false;
block->model = 2;
block->model = BlockModel::xsprite;
Block::blocks[block->id] = block;

block = new Block(BLOCK_BRICK, 17);
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ void HudRenderer::drawInventory(Player* player) {
tint = vec4(1.0f);
}

if (cblock->model == BLOCK_MODEL_CUBE){
if (cblock->model == BlockModel::block){
batch->blockSprite(x, y, size, size, 16, cblock->textureFaces, tint);
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
} else if (cblock->model == BlockModel::xsprite){
batch->sprite(x, y, size, size, 16, cblock->textureFaces[3], tint);
}
}
Expand Down Expand Up @@ -265,9 +265,9 @@ void HudRenderer::draw(){

{
Block* cblock = Block::blocks[player->choosenBlock];
if (cblock->model == BLOCK_MODEL_CUBE){
if (cblock->model == BlockModel::block){
batch->blockSprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
} else if (cblock->model == BlockModel::xsprite){
batch->sprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/world_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
linesShader->use();
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
glLineWidth(2.0f);
if (selectedBlock->model == 1){
if (selectedBlock->model == BlockModel::block){
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f, 1.005f,1.005f,1.005f, 0,0,0,0.5f);
} else if (selectedBlock->model == 2){
} else if (selectedBlock->model == BlockModel::xsprite){
lineBatch->box(pos.x+0.5f, pos.y+0.35f, pos.z+0.5f, 0.805f,0.705f,0.805f, 0,0,0,0.5f);
}
lineBatch->render();
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/BlocksRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,15 @@ void BlocksRenderer::render(const voxel* voxels, int atlas_size) {
uvfor(def, 2, atlas_size), uvfor(def, 3, atlas_size),
uvfor(def, 4, atlas_size), uvfor(def, 5, atlas_size) };
switch (def.model) {
case BLOCK_MODEL_CUBE:
case BlockModel::block:
if (*((light_t*)&def.emission)) {
blockCube(x, y, z, vec3(1, 1, 1), texfaces, def.drawGroup);
}
else {
blockCubeShaded(x, y, z, vec3(1, 1, 1), texfaces, &def, vox.states);
}
break;
case BLOCK_MODEL_X_SPRITE: {
case BlockModel::xsprite: {
blockXSprite(x, y, z, vec3(1, 1, 1), texfaces[FACE_MX], texfaces[FACE_MZ], 1.0f);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/objects/player_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void PlayerController::updateInteraction(){
lighting->onBlockSet(x,y,z, 0);
}
if (Events::jclicked(mousecode::BUTTON_2)){
if (block->model != BLOCK_MODEL_X_SPRITE){
if (block->model != BlockModel::xsprite){
x = (int)(iend.x)+(int)(norm.x);
y = (int)(iend.y)+(int)(norm.y);
z = (int)(iend.z)+(int)(norm.z);
Expand Down
9 changes: 5 additions & 4 deletions src/voxels/Block.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef VOXELS_BLOCK_H_
#define VOXELS_BLOCK_H_

#define BLOCK_MODEL_CUBE 1
#define BLOCK_MODEL_X_SPRITE 2

#define FACE_MX 0
#define FACE_PX 1
#define FACE_MY 2
#define FACE_PY 3
#define FACE_MZ 4
#define FACE_PZ 5

enum class BlockModel {
none, block, xsprite
};

class Block {
public:
static Block* blocks[256];
Expand All @@ -20,7 +21,7 @@ class Block {
int textureFaces[6]; // -x,x, -y,y, -z,z
unsigned char emission[3];
unsigned char drawGroup = 0;
unsigned char model = 1; // 0:None 1:Block 2:XSprite
BlockModel model = BlockModel::block;
bool lightPassing = false;
bool skyLightPassing = false;
bool obstacle = true;
Expand Down

0 comments on commit be980b2

Please sign in to comment.