diff --git a/apps/demos/scenery/scenes/ingame.c b/apps/demos/scenery/scenes/ingame.c index a78e635..2b8de99 100644 --- a/apps/demos/scenery/scenes/ingame.c +++ b/apps/demos/scenery/scenes/ingame.c @@ -17,6 +17,7 @@ #define TERRAIN_DISTANCE (TERRAIN_RADIUS * 2) #define HALF_TERRAIN_DISTANCE ((float)TERRAIN_DISTANCE / 2) #define PLAYER_HEIGHT 0.6f +#define TREE_DENSITY 0.02f /* TODO: pregenerate grid of levels of detail */ static float heightmap[TERRAIN_DISTANCE][TERRAIN_DISTANCE]; @@ -26,7 +27,7 @@ static void process_fly_mode(State *state) { SceneIngame *scn = (SceneIngame *)state->scene; DrawCameraFromPrincipalAxesResult dir_and_up = - draw_camera_from_principal_axes(scn->pos, scn->roll, scn->pitch, scn->yaw, (float)M_PI_2 * 0.8f, 1, TERRAIN_RADIUS * M_SQRT2f); + draw_camera_from_principal_axes(scn->pos, scn->roll, scn->pitch, scn->yaw, (float)M_PI_2 * 0.8f, 1, TERRAIN_RADIUS * sqrtf(3)); const Vec3 right = m_vec_norm(m_vec_cross(dir_and_up.direction, dir_and_up.up)); const float speed = 0.04f; /* TODO: put this in a better place */ @@ -83,7 +84,7 @@ static void process_ground_mode(State *state) { SceneIngame *scn = (SceneIngame *)state->scene; DrawCameraFromPrincipalAxesResult dir_and_up = - draw_camera_from_principal_axes(scn->pos, scn->roll, scn->pitch, scn->yaw, (float)M_PI_2 * 0.8f, 1, TERRAIN_RADIUS * M_SQRT2f); + draw_camera_from_principal_axes(scn->pos, scn->roll, scn->pitch, scn->yaw, (float)M_PI_2 * 0.8f, 1, TERRAIN_RADIUS * sqrtf(3)); dir_and_up.direction.y = 0; dir_and_up.direction = vec3_norm(dir_and_up.direction); @@ -153,6 +154,20 @@ static int32_t ceil_sqrt(int32_t const n) { } +static uint32_t adler32(const void *buf, size_t buflength) { + const uint8_t *buffer = (const uint8_t*)buf; + + uint32_t s1 = 1; + uint32_t s2 = 0; + + for (size_t n = 0; n < buflength; n++) { + s1 = (s1 + buffer[n]) % 65521; + s2 = (s2 + s1) % 65521; + } + return (s2 << 16) | s1; +} + + static void draw_terrain(SceneIngame *scn) { /* draw terrain in circle */ int32_t const rsi = (int32_t)TERRAIN_RADIUS * (int32_t)TERRAIN_RADIUS; @@ -177,7 +192,14 @@ static void draw_terrain(SceneIngame *scn) { (Vec3){ (float)x, d3, (float)y - 1 }, (Rect){ .w = 128, .h = 128 }, (Color){255, 255, 255, 255}); - } + + if (((float)(adler32(&((Vec2){x, y}), sizeof (Vec2)) % 100) / 100) <= TREE_DENSITY) + draw_billboard("/assets/trreez.png", + (Vec3){ (float)x, d0 + 2.f, (float)y }, + (Vec2){2.f, 2.f}, + (Rect){0}, + (Color){255, 255, 255, 255}, true); + } } int32_t const rsi_g = (int32_t)GRASS_RADIUS * (int32_t)GRASS_RADIUS; diff --git a/data/assets/trreez.png b/data/assets/trreez.png new file mode 100644 index 0000000..f1b37a4 --- /dev/null +++ b/data/assets/trreez.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7952339fa5ad130729a31380e86344136dcd5f31316b810cd107dbb832ad26cb +size 56030 diff --git a/src/rendering/twn_draw_c.h b/src/rendering/twn_draw_c.h index f2828f0..15c4220 100644 --- a/src/rendering/twn_draw_c.h +++ b/src/rendering/twn_draw_c.h @@ -24,7 +24,7 @@ extern float camera_2d_zoom; extern double depth_range_low, depth_range_high; -#define QUAD_ELEMENT_BUFFER_LENGTH ((65536 * 4) / 6) +#define QUAD_ELEMENT_BUFFER_LENGTH ((65536 * 8) / 6) #define CIRCLE_VERTICES_MAX 2048 /* TODO: limit to only most necessary */ diff --git a/src/twn_textures.c b/src/twn_textures.c index 9be2b72..814c1f0 100644 --- a/src/twn_textures.c +++ b/src/twn_textures.c @@ -242,7 +242,7 @@ static void add_new_atlas(TextureCache *cache) { /* TODO: create a PBO surface if possible, reducing duplication */ SDL_Surface *new_atlas = create_surface((int)ctx.texture_atlas_size, (int)ctx.texture_atlas_size); arrput(cache->atlas_surfaces, new_atlas); - arrput(cache->atlas_textures, create_gpu_texture(TEXTURE_FILTER_NEAREAST, true, 4, (int)ctx.texture_atlas_size, (int)ctx.texture_atlas_size)); + arrput(cache->atlas_textures, create_gpu_texture(TEXTURE_FILTER_NEAREAST, false, 4, (int)ctx.texture_atlas_size, (int)ctx.texture_atlas_size)); }