Skip to content

Commit

Permalink
fix: sections use BoundedArrayAligned
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Jun 15, 2024
1 parent 70cfae6 commit d320a50
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const Core = struct {
bg: u32,
width: i32,
height: i32,
width_g_arr: []const u32,
height_g_arr: []const u32,
width_g_arr: std.BoundedArrayAligned(u32, 4, 2000),
height_g_arr: std.BoundedArrayAligned(u32, 4, 2000),

fn setActive(self: *@This(), value: bool) void {
self.mutex.lock();
Expand All @@ -40,42 +40,21 @@ const Core = struct {

var array_w: std.BoundedArrayAligned(u32, 4, 2000) = undefined;

fn updateWidthSec(self: *@This(), adv_w: u32) !void {
fn updateWidthSec(self: *@This(), adv: u32) !void {
self.mutex.lock();
defer self.mutex.unlock();


array_w = try std.BoundedArrayAligned(u32, 4, 2000).init(0);
var w_val = adv_w;

while (w_val <= @as(u32, @intCast(self.width))) {
try array_w.append(w_val);
w_val += adv_w;
}

try array_w.resize(array_w.len);
self.width_g_arr = array_w.slice();
self.width_g_arr = try getNthValues(self.width, adv);
}

var array_h: std.BoundedArrayAligned(u32, 4, 1000) = undefined;

fn updateHeightSec(self: *@This(), adv_h: u32) !void {
fn updateHeightSec(self: *@This(), adv: u32) !void {
self.mutex.lock();
defer self.mutex.unlock();

array_h = try std.BoundedArrayAligned(u32, 4, 1000).init(0);

var h_val = adv_h;

while (h_val <= @as(u32, @intCast(self.height))) {
try array_h.append(h_val);
h_val += adv_h;
}

try array_h.resize(array_h.len);
self.height_g_arr = array_h.slice();
self.height_g_arr = try getNthValues(self.height, adv);
}

};

const Handler = struct {
Expand Down Expand Up @@ -217,8 +196,21 @@ fn animation(core: *Core, handler: *Handler) !void {
}
}

fn checkSec(arr: []const u32, value: usize) bool {
for (arr) |el| {
fn getNthValues(number: i32, adv: u32) !std.BoundedArrayAligned(u32, 4, 2000) {
var array = try std.BoundedArrayAligned(u32, 4, 2000).init(0);
var val = adv;

while (val <= @as(u32, @intCast(number))) {
try array.append(val);
val += adv;
}

try array.resize(array.len);
return array;
}

fn checkSec(arr: std.BoundedArrayAligned(u32, 4, 2000), value: usize) bool {
for (arr.slice()) |el| {
if (el == value) {
return true;
}
Expand Down Expand Up @@ -319,10 +311,6 @@ pub fn main() !void {
std.process.exit(0);
}

if (handler.style != Style.default) {
if (handler.style == Style.crypto) {} else if (handler.style == Style.columns) {}
}

{
const t_h = try std.Thread.spawn(.{}, Handler.run, .{ &handler, &core });
defer t_h.join();
Expand Down

0 comments on commit d320a50

Please sign in to comment.