Skip to content

Commit

Permalink
Fix single-threading, minor change to glass pillar
Browse files Browse the repository at this point in the history
  • Loading branch information
bfeldpw committed Dec 24, 2023
1 parent c990061 commit 2bab5a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/config.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Globally enable/disable multithreading. Disabling
/// is mostly used for debugging, frequency targets
/// might not be met
pub const multithreading = true;
pub const multithreading = false;
/// Globally turn on the General Purpose Allocators (GPAs)
/// verbose output
pub const debug_allocator = false;
Expand Down
2 changes: 1 addition & 1 deletion src/map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const map_celltype_tmp = [map_size_y][map_size_x]u8{
[_]u8{ 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 2, 1, 0, 0, 0, 1 },
[_]u8{ 1, 0, 0, 0, 3, 0, 4, 0, 0, 4, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 2, 1, 0, 0, 0, 1 },
Expand Down
17 changes: 10 additions & 7 deletions src/raycaster.zig
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub fn processRays(comptime multithreading: bool) !void {
while (!thread_group_rays.isDone()) std.time.sleep(1000);
thread_group_rays.reset();
} else {
traceMultipleRays(0, rays.seg_i0.len, angle, inc_angle);
traceMultipleRays(0, rays.items.len, angle, inc_angle);
}
}

Expand Down Expand Up @@ -475,7 +475,7 @@ fn traceMultipleRays(i_0: usize, i_1: usize, angle_0: f32, inc: f32) void {
i += 1;
angle += inc;
}
thread_group_rays.finish();
if (cfg.multithreading) thread_group_rays.finish();
}

inline fn traceSingleSegment(angle: f32, s_i: usize, r_i: usize) void {
Expand Down Expand Up @@ -926,16 +926,19 @@ fn resolveContactPillarGlass(d_x: *f32, d_y: *f32, s_x: *f32, s_y: *f32,
segments.pos.items[s_i].x1 = s_x.* + d_x0 * d_p;
segments.pos.items[s_i].y1 = s_y.* + d_y0 * d_p;

const alpha = std.math.atan2(f32, d_y0, d_x0) -
std.math.atan2(f32, d_y0 * d_p - pillar.center_y,
d_x0 * d_p - pillar.center_x);
const norm = std.math.atan2(f32, d_y0 * d_p - pillar.center_y,
d_x0 * d_p - pillar.center_x);
const alpha = std.math.atan2(f32, d_y0, d_x0) - norm;

// std.math.atan2(f32, d_y0 * d_p - pillar.center_y,
// d_x0 * d_p - pillar.center_x);
// std.math.atan2(f32, d_y0 * d_p - @intToFloat(f32, m_y) + pillar.center_y,
// d_x0 * d_p - @intToFloat(f32, m_x) + pillar.center_x);
// if (alpha > std.math.pi) alpha -= 2.0 * std.math.pi;
// if (alpha < -std.math.pi) alpha += 2.0 * std.math.pi;
const beta = alpha / n;
d_y.* = @sin(beta);
d_x.* = @cos(beta);
d_y.* = @sin(beta + norm);
d_x.* = @cos(beta + norm);

// const r_x = (d_x0 * d_p - e_x) / r;
// const r_y = (d_y0 * d_p - e_y) / r;
Expand Down

0 comments on commit 2bab5a3

Please sign in to comment.