From afde681ce9eb35463474ee6124fbc2bc3d9b048d Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Fri, 13 Oct 2023 19:50:30 +0200 Subject: [PATCH] Added top side to grass and improved worldgen a tiny bit --- code/source-c/blocks.c | 10 +++-- code/source-c/cube_premeshing.c | 46 +++++++++++------------ code/source-c/default_terrain_generator.c | 20 ++++++++-- code/source-c/initialization.c | 7 +++- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/code/source-c/blocks.c b/code/source-c/blocks.c index 117b5a9..2ddb587 100644 --- a/code/source-c/blocks.c +++ b/code/source-c/blocks.c @@ -162,13 +162,15 @@ tc_cube_info_s tc_gen_unitexture_cube_info void tc_create_blocks() { - tc_image_s *dirt_texture = tc_resolve_name_to_image("dirt"); - tc_image_s *grass_texture = tc_resolve_name_to_image("grass"); - tc_image_s *stone_texture = tc_resolve_name_to_image("stone"); + tc_image_s *dirt_texture = tc_resolve_name_to_image("dirt"); + tc_image_s *grass_texture = tc_resolve_name_to_image("grass-side"); + tc_image_s *grass_top_texture = tc_resolve_name_to_image("grass-top"); + tc_image_s *stone_texture = tc_resolve_name_to_image("stone"); tc_cube_info_s dirt = tc_gen_unitexture_cube_info("Dirt", 1 | TC_BLOCK_OPAQUE_BIT, dirt_texture->image_id); - tc_cube_info_s grass = tc_gen_unitexture_cube_info("Grass", 2 | TC_BLOCK_OPAQUE_BIT, grass_texture->image_id); tc_cube_info_s stone = tc_gen_unitexture_cube_info("Stone", 3 | TC_BLOCK_OPAQUE_BIT, stone_texture->image_id); + tc_cube_info_s grass = tc_gen_unitexture_cube_info("Grass", 2 | TC_BLOCK_OPAQUE_BIT, grass_texture->image_id); + grass.texture_top = grass_top_texture->image_id; tc_new_cube_block(dirt); tc_new_cube_block(grass); diff --git a/code/source-c/cube_premeshing.c b/code/source-c/cube_premeshing.c index 9a8881d..2d4866f 100644 --- a/code/source-c/cube_premeshing.c +++ b/code/source-c/cube_premeshing.c @@ -51,14 +51,13 @@ float tc_cube_back_xyz[18] = float tc_cube_west_uv[12] = { - // Left - 1.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 1.0f, + 1.0f, 0.0f, - 0.0f, 1.0f, + 1.0f, 0.0f, 1.0f, 1.0f, - 1.0f, 0.0f + 0.0f, 1.0f }; float tc_cube_west_xyz[18] = @@ -76,14 +75,13 @@ float tc_cube_west_xyz[18] = float tc_cube_east_uv[12] = { - // Right - 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 0.0f, + 0.0f, 1.0f, - 1.0f, 0.0f, + 0.0f, 1.0f, 1.0f, 1.0f, - 0.0f, 1.0f + 1.0f, 0.0f }; float tc_cube_east_xyz[18] = @@ -101,7 +99,6 @@ float tc_cube_east_xyz[18] = float tc_cube_top_uv[12] = { - // Top 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, @@ -126,7 +123,6 @@ float tc_cube_top_xyz[18] = float tc_cube_bottom_uv[12] = { - // Bottom 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -151,21 +147,25 @@ float tc_cube_bottom_xyz[18] = void tc_adjust_cube_uvs_for_image(tc_image_s *image, float *face_uvs) { - float lower_x = ((float) image->x) / ((float) image->width); - float lower_y = ((float) image->y) / ((float) image->height); - float higher_x; - float higher_y; + float uv_per_pixel_w = 1.0f / image->width; + float uv_per_pixel_h = 1.0f / image->height; if(image->superimage != NULL) { - higher_x = (((float) (image->x + image->width)) / ((float) image->superimage->width)); - higher_y = (((float) (image->y + image->height)) / ((float) image->superimage->height)); - } - else - { - higher_x = 1.0f; - higher_y = 1.0f; + uv_per_pixel_w = 1.0f / image->superimage->width; + uv_per_pixel_h = 1.0f / image->superimage->height; } + printf("UV Per Pixel: %f|%f\n", uv_per_pixel_w, uv_per_pixel_h); + + float lower_x = uv_per_pixel_w * ((float) image->x); + float lower_y = uv_per_pixel_h * ((float) image->y); + float higher_x = 1.0f; + float higher_y = 1.0f; + + higher_x = lower_x + uv_per_pixel_w * 8; // image->width; + higher_y = lower_y + uv_per_pixel_h * 8; // image->height; + + printf("Lower Coordinates: %f|%f, Higher Coordinates: %f %f\n", lower_x, lower_y, higher_x, higher_y); uint32_t num_floats = 2 * 6; uint32_t index = 0; diff --git a/code/source-c/default_terrain_generator.c b/code/source-c/default_terrain_generator.c index 282b173..fc39f2e 100644 --- a/code/source-c/default_terrain_generator.c +++ b/code/source-c/default_terrain_generator.c @@ -8,6 +8,9 @@ bool tc_generate_default_terrain_chunk(tc_worldgen_s *gen, tc_chunk_s *chunk) block.position.y = 0.0f; block.position.z = 0.0f; + tc_block_s grass; + grass.type_identifier = 2 | TC_BLOCK_OPAQUE_BIT; + if(chunk->position.y > 0) return true; uint32_t x_in_chunk = 0; @@ -28,9 +31,20 @@ bool tc_generate_default_terrain_chunk(tc_worldgen_s *gen, tc_chunk_s *chunk) } ++x_in_chunk; } - tc_block_s air; - block.type_identifier = 0; - tc_set_block_in_chunk(chunk, 6, 8, 14, air); + if(chunk->position.y == 0) + { + x_in_chunk = 0; + while(x_in_chunk < 32) + { + z_in_chunk = 0; + while(z_in_chunk < 32) + { + tc_set_block_in_chunk(chunk, x_in_chunk, 31, z_in_chunk, grass); + ++z_in_chunk; + } + ++x_in_chunk; + } + } return true; } diff --git a/code/source-c/initialization.c b/code/source-c/initialization.c index 014105b..f0dfc27 100644 --- a/code/source-c/initialization.c +++ b/code/source-c/initialization.c @@ -43,9 +43,14 @@ void tc_load_textures() tc_image_s *dirt = tc_create_subimage(tc_game_state_g.block_texture_atlas, 0, 0, 8, 8); dirt->name = "dirt"; + tc_image_s *grass = tc_create_subimage(tc_game_state_g.block_texture_atlas, 8, 0, 8, 8); - grass->name = "grass"; + grass->name = "grass-side"; + + tc_image_s *grass_top = + tc_create_subimage(tc_game_state_g.block_texture_atlas, 8, 8, 8, 8); + grass_top->name = "grass-top"; tc_image_s *stone = tc_create_subimage(tc_game_state_g.block_texture_atlas, 16, 0, 8, 8);