summaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-30 23:54:23 +1000
committerquou <quou@disroot.org>2024-07-30 23:54:35 +1000
commit2ddc36906c45e3abfda6154d6595d2db68a93b5c (patch)
tree97de8b880b26d95676272836c289fcd1a473a782 /render.c
parente4dc6fb9870e81679695f0ecf179bb2b58f03937 (diff)
floor and ceiling
Diffstat (limited to 'render.c')
-rw-r--r--render.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/render.c b/render.c
index a63dfe4..348263d 100644
--- a/render.c
+++ b/render.c
@@ -724,13 +724,40 @@ void ren_map(
const int* dir,
const int* left
) {
- int x, w, h, hh;
+ int x, y, w, h, hh, hhi, hci, ey;
const int* data = (const int*)&map[1];
/* temp */
const Texture* texture = get_texture(asset_id_brick_texture);
+ const Texture* ceiling = get_texture(asset_id_floorboardsbot_texture);
+ const Texture* floort = get_texture(asset_id_floorboards_texture);
w = r->vp[0] << fbits;
h = r->vp[1] << fbits;
hh = (h / 4) * r->asp;
+ hhi = r->vp[1] / 2;
+ ey = mini(hhi, r->clip[3]);
+ for (y = r->clip[1]; y < ey; y++) {
+ int rl[2], rr[2], floor[4];
+ int dist = (hh) / ((y - hhi) << fbits);
+ rl[0] = dir[0] + left[0];
+ rl[1] = dir[1] + left[1];
+ rr[0] = dir[0] - left[0];
+ rr[1] = dir[1] - left[1];
+ floor[0] = pos[0] - ((dist * rl[0]) >> fbits);
+ floor[1] = pos[1] - ((dist * rl[1]) >> fbits);
+ floor[2] = pos[0] - ((dist * rr[0]) >> fbits);
+ floor[3] = pos[1] - ((dist * rr[1]) >> fbits);
+ for (x = r->clip[0]; x < r->clip[2]; x++) {
+ int t = ((2 * x) << (fbits * 2)) / w - f1;
+ int coordc = x + y * r->vp[0];
+ int coordf = x + ((hhi - y) + hhi) * r->vp[0];
+ int ifloor[2];
+ t = (t + f1) / 2;
+ ifloor[0] = floor[0] + ((t * (floor[2] - floor[0])) >> fbits);
+ ifloor[1] = floor[1] + ((t * (floor[3] - floor[1])) >> fbits);
+ r->t[coordc] = sample_tex(ceiling, ifloor[0], ifloor[1]);
+ r->t[coordf] = sample_tex(floort, ifloor[0], ifloor[1]);
+ }
+ }
for (x = r->clip[0]; x < r->clip[2]; x++) {
int ray = ((2 * x) << (fbits * 2)) / w - f1;
int d[2];
@@ -740,8 +767,8 @@ void ren_map(
d[1] = dir[1] - ((left[1] * ray) >> fbits);
mp[0] = pos[0] >> fbits;
mp[1] = pos[1] >> fbits;
- delta[0] = !d[0]? f1*30: abs((f1 << fbits) / d[0]);
- delta[1] = !d[1]? f1*30: abs((f1 << fbits) / d[1]);
+ delta[0] = abs((f1 << fbits) / (d[0] + !d[0]));
+ delta[1] = abs((f1 << fbits) / (d[1] + !d[1]));
if (d[0] < 0) {
step[0] = -1;
dside[0] = ((pos[0] - (mp[0] << fbits)) * delta[0]) >> fbits;
@@ -781,12 +808,10 @@ void ren_map(
ey = mini(ey, r->clip[3]);
for (y = sy; y < ey; y++) {
int coord = x + y * r->vp[0];
- if (dist < r->d[coord]) {
- int v = ((y - sy) << fbits) / (ey - sy);
- Colour c = sample_tex(texture, u, v);
- r->d[coord] = dist;
- r->t[coord] = c;
- }
+ int v = ((y - sy) << fbits) / (ey - sy);
+ Colour c = sample_tex(texture, u, v);
+ r->d[coord] = dist;
+ r->t[coord] = c;
}
break;
}