tunnel-runner

Pseudo 3D tunnel effect.
git clone git://git.amin.space/tunnel-runner.git
Log | Files | Refs | README | LICENSE

commit d1442d486fd3a180c812671a1e22b581217164d6
parent 30e59a4d8d778f79955bd414058941d1561929f0
Author: amin <dev@aminmesbah.com>
Date:   Sun, 23 Sep 2018 18:37:28 +0000

Clean up texel fetching code

FossilOrigin-Name: 7e38f9d28c7a196bc7a8e35e4aec9e279d26a578ddadde1867f4bc793d54a710
Diffstat:
Mtunnel_runner.c | 27++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/tunnel_runner.c b/tunnel_runner.c @@ -175,24 +175,17 @@ render_tunnel( uint32_t *pixel = (uint32_t *)row; for (uint32_t x = 0; x < buffer.width; ++x) { - uint8_t color = texture[ - (uint32_t)( - transform.distance_table[y + transform.look_shift_y][x + transform.look_shift_x] - + translation_offset - ) - % TR_TEX_HEIGHT - ] - [ - (uint32_t)( - transform.angle_table[y + transform.look_shift_y][x + transform.look_shift_x] - + rotation_offset - ) - % TR_TEX_WIDTH - ]; + uint32_t texel_y = (uint32_t)(transform.distance_table[y + transform.look_shift_y][x + transform.look_shift_x] + translation_offset) % TR_TEX_HEIGHT; + uint32_t texel_x = (uint32_t)(transform.angle_table[y + transform.look_shift_y][x + transform.look_shift_x] + rotation_offset) % TR_TEX_WIDTH; - uint32_t red = color << 16; - uint32_t green = color << 8; - uint32_t blue = color; + assert(texel_x >= 0 && texel_x < TR_TEX_WIDTH); + assert(texel_y >= 0 && texel_y < TR_TEX_HEIGHT); + + uint8_t texel = texture[texel_y][texel_x]; + + uint32_t red = texel << 16; + uint32_t green = texel << 8; + uint32_t blue = texel; switch(color_choice) {