|
13 | 13 | #define CELL_XSZ (TILE_XSZ << 1) |
14 | 14 | #define CELL_YSZ (TILE_YSZ << 1) |
15 | 15 |
|
16 | | -struct rect { |
17 | | - int x, y, w, h; |
18 | | -}; |
19 | | - |
20 | 16 | enum { DIR_N, DIR_W, DIR_S, DIR_E }; |
21 | 17 | enum { DIR8_N, DIR8_NW, DIR8_W, DIR8_SW, DIR8_S, DIR8_SE, DIR8_E, DIR8_NE }; |
22 | 18 |
|
@@ -91,6 +87,8 @@ int cell_remove_beamseg(struct level_cell *cell, struct beamseg *bs); |
91 | 87 | void cell_add_psys(struct level_cell *cell, struct psys *ps); |
92 | 88 | int cell_remove_psys(struct level_cell *cell, struct psys *ps); |
93 | 89 |
|
| 90 | +struct mob *raycast(struct level *lvl, int32_t x, int32_t y, int32_t dx, int32_t dy, struct mob *ignmob); |
| 91 | + |
94 | 92 | /* implicit in these conversions is the tile size: 64x32 */ |
95 | 93 | static INLINE void vscr_to_grid(int sx, int sy, int32_t *gridx, int32_t *gridy) |
96 | 94 | { |
@@ -127,4 +125,37 @@ static INLINE void grid_to_cell(int32_t gx, int32_t gy, int *cx, int *cy) |
127 | 125 | *cy = (gy + 0x80) >> 8; |
128 | 126 | } |
129 | 127 |
|
| 128 | +static INLINE int ray_step(struct level *lvl, int32_t x, int32_t y, int32_t dx, |
| 129 | + int32_t dy, int32_t hslope, int32_t vslope, int32_t *nx, int32_t *ny) |
| 130 | +{ |
| 131 | + int32_t x1, y1, offs; |
| 132 | + |
| 133 | + /* convert to origin at upper-left, rather than center of cells, to make |
| 134 | + * stepping simpler |
| 135 | + */ |
| 136 | + x += 128; |
| 137 | + y += 128; |
| 138 | + |
| 139 | + /* find next boundaries when stepping horizontally or vertically */ |
| 140 | + x1 = (dx > 0 ? x + 256 : x - 1) & ~0xff; |
| 141 | + /*hslope = (dy << 8) / dx;*/ |
| 142 | + y1 = y + ((hslope * (x1 - x)) >> 8); |
| 143 | + offs = y1 - (y & ~0xff); |
| 144 | + |
| 145 | + if(offs < 256 && offs >= 0) { |
| 146 | + *nx = x1 - 128; |
| 147 | + *ny = y1 - 128; |
| 148 | + return dx > 0 ? DIR_E : DIR_W; |
| 149 | + } |
| 150 | + |
| 151 | + y1 = (dy > 0 ? y + 256 : y - 1) & ~0xff; |
| 152 | + /*vslope = (dx << 8) / dy;*/ |
| 153 | + x1 = x + ((vslope * (y1 - y)) >> 8); |
| 154 | + |
| 155 | + *nx = x1 - 128; |
| 156 | + *ny = y1 - 128; |
| 157 | + return dy > 0 ? DIR_S : DIR_N; |
| 158 | +} |
| 159 | + |
| 160 | + |
130 | 161 | #endif /* LEVEL_H_ */ |
0 commit comments