this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

moved some stuff around

Altagos f5de010c 512b5c91

+115 -105
+92 -84
src/interval.zig
··· 22 22 23 23 pub fn Interval(comptime T: type) type { 24 24 if (@typeInfo(T) == .Int) { 25 - return struct { 26 - const Self = @This(); 27 - 28 - pub const empty: Self = .{ .min = std.math.inf(T), .max = -std.math.inf(T) }; 29 - pub const universe: Self = .{ .min = -std.math.inf(T), .max = std.math.inf(T) }; 30 - 31 - pub const Iterator = struct { 32 - interval: Self, 33 - current: T, 34 - 35 - lower_boundry: IntervalIteratorType = .inclusive, 36 - upper_boundry: IntervalIteratorType = .exclusive, 37 - 38 - pub fn init( 39 - interval: Self, 40 - lower_boundry: IntervalIteratorType, 41 - upper_boundry: IntervalIteratorType, 42 - ) Iterator { 43 - return .{ 44 - .interval = interval, 45 - .current = if (lower_boundry == .inclusive) interval.min else interval.min + 1, 46 - .lower_boundry = lower_boundry, 47 - .upper_boundry = upper_boundry, 48 - }; 49 - } 50 - 51 - pub fn next(self: *Iterator) ?T { 52 - self.current += 1; 53 - if (self.current < self.interval.max or (self.current == self.interval.max and self.upper_boundry == .inclusive)) { 54 - return self.current; 55 - } else return null; 56 - } 25 + return IntInterval(T); 26 + } else if (@typeInfo(T) == .Float) { 27 + return FloatInterval(T); 28 + } else { 29 + @compileError("Interval only supports Int and Float Types!"); 30 + } 31 + } 57 32 58 - pub fn nextInc(self: *Iterator) ?T { 59 - self.current += 1; 60 - return if (self.current <= self.interval.max) self.current else null; 61 - } 33 + fn IntInterval(comptime T: type) type { 34 + return struct { 35 + const Self = @This(); 62 36 63 - pub fn nextExc(self: *Iterator) ?T { 64 - self.current += 1; 65 - return if (self.current < self.interval.max) self.current else null; 66 - } 67 - }; 37 + pub const empty: Self = .{ .min = std.math.inf(T), .max = -std.math.inf(T) }; 38 + pub const universe: Self = .{ .min = -std.math.inf(T), .max = std.math.inf(T) }; 68 39 69 - min: T, 70 - max: T, 40 + pub const Iterator = struct { 41 + interval: Self, 42 + current: T, 71 43 72 - pub fn init(min: T, max: T) Interval { 73 - return .{ .min = min, .max = max }; 74 - } 44 + lower_boundry: IntervalIteratorType = .inclusive, 45 + upper_boundry: IntervalIteratorType = .exclusive, 75 46 76 - pub fn contains(self: *const Self, x: T) bool { 77 - return self.min <= x and x <= self.max; 47 + pub fn init( 48 + interval: Self, 49 + lower_boundry: IntervalIteratorType, 50 + upper_boundry: IntervalIteratorType, 51 + ) Iterator { 52 + return .{ 53 + .interval = interval, 54 + .current = if (lower_boundry == .inclusive) interval.min else interval.min + 1, 55 + .lower_boundry = lower_boundry, 56 + .upper_boundry = upper_boundry, 57 + }; 78 58 } 79 59 80 - pub fn surrounds(self: *const Self, x: T) bool { 81 - return self.min < x and x < self.max; 60 + pub fn next(self: *Iterator) ?T { 61 + self.current += 1; 62 + if (self.current < self.interval.max or (self.current == self.interval.max and self.upper_boundry == .inclusive)) { 63 + return self.current; 64 + } else return null; 82 65 } 83 66 84 - pub fn clamp(self: *const Self, x: T) T { 85 - if (x < self.min) return self.min; 86 - if (x > self.max) return self.max; 87 - return x; 67 + pub fn nextInc(self: *Iterator) ?T { 68 + self.current += 1; 69 + return if (self.current <= self.interval.max) self.current else null; 88 70 } 89 71 90 - pub fn iter(self: *const Self) Iterator { 91 - return Iterator{ 92 - .interval = self.*, 93 - .current = self.min, 94 - }; 72 + pub fn nextExc(self: *Iterator) ?T { 73 + self.current += 1; 74 + return if (self.current < self.interval.max) self.current else null; 95 75 } 96 76 }; 97 - } else if (@typeInfo(T) == .Float) { 98 - return struct { 99 - pub const empty: @This() = .{ .min = std.math.inf(T), .max = -std.math.inf(T) }; 100 - pub const universe: @This() = .{ .min = -std.math.inf(T), .max = std.math.inf(T) }; 101 77 102 - const Self = @This(); 78 + min: T, 79 + max: T, 103 80 104 - min: T, 105 - max: T, 81 + pub fn init(min: T, max: T) Interval { 82 + return .{ .min = min, .max = max }; 83 + } 106 84 107 - pub fn init(min: T, max: T) Self { 108 - return .{ .min = min, .max = max }; 109 - } 85 + pub fn contains(self: *const Self, x: T) bool { 86 + return self.min <= x and x <= self.max; 87 + } 110 88 111 - pub fn contains(self: *const Self, x: T) bool { 112 - return self.min <= x and x <= self.max; 113 - } 89 + pub fn surrounds(self: *const Self, x: T) bool { 90 + return self.min < x and x < self.max; 91 + } 114 92 115 - pub fn surrounds(self: *const Self, x: T) bool { 116 - return self.min < x and x < self.max; 117 - } 93 + pub fn clamp(self: *const Self, x: T) T { 94 + if (x < self.min) return self.min; 95 + if (x > self.max) return self.max; 96 + return x; 97 + } 118 98 119 - pub fn clamp(self: *const Self, x: T) T { 120 - if (x < self.min) return self.min; 121 - if (x > self.max) return self.max; 122 - return x; 123 - } 124 - }; 125 - } else { 126 - @compileError("Interval only supports Int and Float Types!"); 127 - } 99 + pub fn iter(self: *const Self) Iterator { 100 + return Iterator{ 101 + .interval = self.*, 102 + .current = self.min, 103 + }; 104 + } 105 + }; 106 + } 107 + 108 + fn FloatInterval(comptime T: type) type { 109 + return struct { 110 + pub const empty: @This() = .{ .min = std.math.inf(T), .max = -std.math.inf(T) }; 111 + pub const universe: @This() = .{ .min = -std.math.inf(T), .max = std.math.inf(T) }; 112 + 113 + const Self = @This(); 114 + 115 + min: T, 116 + max: T, 117 + 118 + pub fn init(min: T, max: T) Self { 119 + return .{ .min = min, .max = max }; 120 + } 121 + 122 + pub fn contains(self: *const Self, x: T) bool { 123 + return self.min <= x and x <= self.max; 124 + } 125 + 126 + pub fn surrounds(self: *const Self, x: T) bool { 127 + return self.min < x and x < self.max; 128 + } 129 + 130 + pub fn clamp(self: *const Self, x: T) T { 131 + if (x < self.min) return self.min; 132 + if (x > self.max) return self.max; 133 + return x; 134 + } 135 + }; 128 136 }
+23 -4
src/rayray.zig
··· 10 10 pub const material = @import("material.zig"); 11 11 pub const renderer = @import("renderer.zig"); 12 12 13 + const IntervalUsize = @import("interval.zig").IntervalUsize; 14 + 13 15 const log = std.log.scoped(.rayray); 14 16 15 17 const ThreadTracker = struct { ··· 62 64 63 65 for (0..num_threads) |row| { 64 66 const ctx = renderer.Context{ .cam = &self.camera, .world = &self.world }; 65 - const t = try std.Thread.spawn(.{}, renderer.renderThread, .{ ctx, &threads[row].done, row, row_height }); 67 + const t = try std.Thread.spawn(.{}, renderThread, .{ ctx, &threads[row].done, row, row_height }); 66 68 threads[row].thread = t; 67 69 } 68 70 ··· 72 74 .terminal = stderr, 73 75 .supports_ansi_escape_codes = true, 74 76 }; 75 - var node = progress.start("Rendering Completed", num_threads); 77 + var node = progress.start("Rendering", num_threads); 76 78 node.activate(); 77 79 78 80 while (true) { ··· 83 85 threads[id].thread.join(); 84 86 threads[id].marked_as_done = true; 85 87 finished_threads[id] = true; 86 - // node.completeOne(); 88 + node.completeOne(); 87 89 } else if (!threads[id].done.load(.Acquire)) { 88 90 done = false; 89 91 } 90 92 } 91 93 92 - // node.context.refresh(); 94 + node.context.refresh(); 93 95 94 96 if (done) break; 95 97 } ··· 99 101 return self.camera.image; 100 102 } 101 103 }; 104 + 105 + pub fn renderThread(ctx: renderer.Context, done: *std.atomic.Value(bool), row: usize, row_height: usize) void { 106 + spall.init_thread(); 107 + defer spall.deinit_thread(); 108 + 109 + const height = IntervalUsize{ .min = row_height * row, .max = row_height * row + row_height }; 110 + const width = IntervalUsize{ .min = 0, .max = ctx.cam.image_width }; 111 + 112 + // log.debug("Started Render Thread {}", .{row}); 113 + 114 + const s = spall.trace(@src(), "Render Thread {}", .{row}); 115 + defer s.end(); 116 + 117 + renderer.run(ctx, height, width); 118 + 119 + done.store(true, .Release); 120 + }
-17
src/renderer.zig
··· 56 56 } 57 57 } 58 58 59 - pub fn renderThread(ctx: Context, done: *std.atomic.Value(bool), row: usize, row_height: usize) void { 60 - spall.init_thread(); 61 - defer spall.deinit_thread(); 62 - 63 - const height = IntervalUsize{ .min = row_height * row, .max = row_height * row + row_height }; 64 - const width = IntervalUsize{ .min = 0, .max = ctx.cam.image_width }; 65 - 66 - log.debug("Started Render Thread {}", .{row}); 67 - 68 - const s = spall.trace(@src(), "Render Thread {}", .{row}); 69 - defer s.end(); 70 - 71 - run(ctx, height, width); 72 - 73 - done.store(true, .Release); 74 - } 75 - 76 59 fn vecToRgba(v: zm.Vec, samples_per_pixel: usize) zigimg.color.Rgba32 { 77 60 const scale: f32 = 1.0 / @as(f32, @floatFromInt(samples_per_pixel)); 78 61 const intensity = IntervalF32.init(0.0, 0.999);