summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--render.c85
1 files changed, 52 insertions, 33 deletions
diff --git a/render.c b/render.c
index 86e61f7..7c4dd77 100644
--- a/render.c
+++ b/render.c
@@ -714,6 +714,9 @@ void ren_mesh(
}
}
+/* temp */
+#include "asset.h"
+
void ren_map(
Renderer* r,
const struct Map* map,
@@ -723,54 +726,70 @@ void ren_map(
) {
int x, w, h, hh;
const int* data = (const int*)&map[1];
+ /* temp */
+ const Texture* texture = get_texture(asset_id_gun_texture);
w = r->vp[0] << fbits;
h = r->vp[1] << fbits;
hh = h / 2;
for (x = r->clip[0]; x < r->clip[2]; x++) {
- Line l;
int ray = ((2 * x) << (fbits * 2)) / w - f1;
- int d[2], plane[2];
- d[0] = ((left[0] * ray) >> fbits);
- d[1] = ((left[1] * ray) >> fbits);
- plane[0] = pos[0] - d[0];
- plane[1] = pos[1] - d[1];
- d[0] = dir[0] - d[0];
- d[1] = dir[1] - d[1];
- d[0] = (pos[0] + d[0] * 4);
- d[1] = (pos[1] + d[1] * 4);
- init_line(&l, pos, d);
+ int d[2];
+ int delta[2], step[2], dside[2];
+ int mp[2];
+ d[0] = dir[0] - ((left[0] * ray) >> fbits);
+ 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]);
+ if (d[0] < 0) {
+ step[0] = -1;
+ dside[0] = ((pos[0] - (mp[0] << fbits)) * delta[0]) >> fbits;
+ } else {
+ step[0] = 1;
+ dside[0] = (((mp[0] << fbits) + f1 - pos[0]) * delta[0]) >> fbits;
+ }
+ if (d[1] < 0) {
+ step[1] = -1;
+ dside[1] = ((pos[1] - (mp[1] << fbits)) * delta[1]) >> fbits;
+ } else {
+ step[1] = 1;
+ dside[1] = (((mp[1] << fbits) + f1 - pos[1]) * delta[1]) >> fbits;
+ }
while (1) {
- int mp[2], tile;
- mp[0] = l.x >> fbits;
- mp[1] = l.y >> fbits;
- if (
- mp[0] < 0 ||
- mp[1] < 0 ||
- mp[0] >= map->w ||
- mp[1] >= map->h
- ) break;
- tile = data[mp[0] + mp[1] * map->w];
- if (tile) {
- int lp[2], sy, ey, d, y;
- lp[0] = l.x;
- lp[1] = l.y;
- d = vec_dist(lp, lp, plane, 2);
- sy = (r->vp[1] / 2) - (((hh << fbits) / d) >> fbits);
- ey = (r->vp[1] / 2) + (((hh << fbits) / d) >> fbits);
+ int dist, u;
+ if (dside[0] < dside[1]) {
+ dside[0] += delta[0];
+ mp[0] += step[0];
+ dist = dside[0] - delta[0];
+ u = pos[1] + ((dist * d[1]) >> fbits);
+ } else {
+ dside[1] += delta[1];
+ mp[1] += step[1];
+ dist = dside[1] - delta[1];
+ u = pos[0] + ((dist * d[0]) >> fbits);
+ }
+ if (mp[0] < 0) break;
+ if (mp[1] < 0) break;
+ if (mp[0] >= map->w) break;
+ if (mp[1] >= map->h) break;
+ if (data[mp[0] + mp[1] * map->w]) {
+ int y;
+ int sy = (r->vp[1] / 2) - (((hh << fbits) / dist) >> fbits);
+ int ey = (r->vp[1] / 2) + (((hh << fbits) / dist) >> fbits);
sy = maxi(sy, r->clip[1]);
ey = mini(ey, r->clip[3]);
for (y = sy; y < ey; y++) {
int coord = x + y * r->vp[0];
- Colour c = { 0, 0, 0, 255 };
- c.r = (((16 << fbits ) - d) / 16);
- if (d < r->d[coord]) {
- r->d[coord] = d;
+ 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;
}
}
break;
}
- step_line(&l);
}
}
}