mirror of https://github.com/fairyglade/ly.git
added refresh interval in ms for animations
This commit is contained in:
parent
e125d8f1aa
commit
020f27b203
|
|
@ -35,6 +35,14 @@
|
||||||
# matrix -> CMatrix
|
# matrix -> CMatrix
|
||||||
animation = none
|
animation = none
|
||||||
|
|
||||||
|
# The minimum time between animation frames
|
||||||
|
# 32 -> ~30fps
|
||||||
|
# 16 -> ~60fps
|
||||||
|
# 8 -> ~120fps
|
||||||
|
# 6 -> ~144fps
|
||||||
|
# 4 -> ~240fps
|
||||||
|
animation_refresh_ms = 16
|
||||||
|
|
||||||
# Stop the animation after some time
|
# Stop the animation after some time
|
||||||
# 0 -> Run forever
|
# 0 -> Run forever
|
||||||
# 1..2e12 -> Stop the animation after this many seconds
|
# 1..2e12 -> Stop the animation after this many seconds
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ pub fn realloc(self: *Doom) !void {
|
||||||
self.buffer = buffer;
|
self.buffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: Doom) void {
|
pub fn draw_with_update(self: Doom) void {
|
||||||
for (0..self.terminal_buffer.width) |x| {
|
for (0..self.terminal_buffer.width) |x| {
|
||||||
for (1..self.terminal_buffer.height) |y| {
|
for (1..self.terminal_buffer.height) |y| {
|
||||||
const source = y * self.terminal_buffer.width + x;
|
const source = y * self.terminal_buffer.width + x;
|
||||||
|
|
@ -74,6 +74,18 @@ pub fn draw(self: Doom) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw(self: Doom) void {
|
||||||
|
for (0..self.terminal_buffer.width) |x| {
|
||||||
|
for (1..self.terminal_buffer.height) |y| {
|
||||||
|
const source = y * self.terminal_buffer.width + x;
|
||||||
|
|
||||||
|
const buffer_source = self.buffer[source];
|
||||||
|
|
||||||
|
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn initBuffer(buffer: []u8, width: usize) void {
|
fn initBuffer(buffer: []u8, width: usize) void {
|
||||||
const length = buffer.len - width;
|
const length = buffer.len - width;
|
||||||
const slice_start = buffer[0..length];
|
const slice_start = buffer[0..length];
|
||||||
|
|
|
||||||
|
|
@ -68,14 +68,12 @@ pub fn realloc(self: *Matrix) !void {
|
||||||
self.lines = lines;
|
self.lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: *Matrix) void {
|
pub fn draw_with_update(self: *Matrix) void {
|
||||||
const buf_height = self.terminal_buffer.height;
|
const buf_height = self.terminal_buffer.height;
|
||||||
const buf_width = self.terminal_buffer.width;
|
const buf_width = self.terminal_buffer.width;
|
||||||
self.count += 1;
|
|
||||||
if (self.count > FRAME_DELAY) {
|
|
||||||
self.frame += 1;
|
self.frame += 1;
|
||||||
if (self.frame > 4) self.frame = 1;
|
if (self.frame > 4) self.frame = 1;
|
||||||
self.count = 0;
|
|
||||||
|
|
||||||
var x: usize = 0;
|
var x: usize = 0;
|
||||||
while (x < self.terminal_buffer.width) : (x += 2) {
|
while (x < self.terminal_buffer.width) : (x += 2) {
|
||||||
|
|
@ -140,8 +138,13 @@ pub fn draw(self: *Matrix) void {
|
||||||
first_col = false;
|
first_col = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw(self: *Matrix) void {
|
||||||
|
const buf_width = self.terminal_buffer.width;
|
||||||
|
|
||||||
var x: usize = 0;
|
var x: usize = 0;
|
||||||
while (x < buf_width) : (x += 2) {
|
while (x < buf_width) : (x += 2) {
|
||||||
var y: usize = 1;
|
var y: usize = 1;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const Bigclock = enums.Bigclock;
|
||||||
|
|
||||||
animation: Animation = .none,
|
animation: Animation = .none,
|
||||||
animation_timeout_sec: u12 = 0,
|
animation_timeout_sec: u12 = 0,
|
||||||
|
animation_refresh_ms: u16 = 16,
|
||||||
asterisk: ?u8 = '*',
|
asterisk: ?u8 = '*',
|
||||||
auth_fails: u64 = 10,
|
auth_fails: u64 = 10,
|
||||||
bg: u16 = 0,
|
bg: u16 = 0,
|
||||||
|
|
|
||||||
24
src/main.zig
24
src/main.zig
|
|
@ -317,6 +317,11 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var animation_timer = switch(config.animation) {
|
||||||
|
.none => undefined,
|
||||||
|
else => try std.time.Timer.start()
|
||||||
|
};
|
||||||
|
|
||||||
const animate = config.animation != .none;
|
const animate = config.animation != .none;
|
||||||
const shutdown_key = try std.fmt.parseInt(u8, config.shutdown_key[1..], 10);
|
const shutdown_key = try std.fmt.parseInt(u8, config.shutdown_key[1..], 10);
|
||||||
const shutdown_len = try utils.strWidth(lang.shutdown);
|
const shutdown_len = try utils.strWidth(lang.shutdown);
|
||||||
|
|
@ -340,6 +345,7 @@ pub fn main() !void {
|
||||||
try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
|
try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
while (run) {
|
while (run) {
|
||||||
// If there's no input or there's an animation, a resolution change needs to be checked
|
// If there's no input or there's an animation, a resolution change needs to be checked
|
||||||
if (!update or config.animation != .none) {
|
if (!update or config.animation != .none) {
|
||||||
|
|
@ -380,8 +386,22 @@ pub fn main() !void {
|
||||||
if (!animation_timed_out) {
|
if (!animation_timed_out) {
|
||||||
switch (config.animation) {
|
switch (config.animation) {
|
||||||
.none => {},
|
.none => {},
|
||||||
.doom => doom.draw(),
|
.doom => {
|
||||||
.matrix => matrix.draw(),
|
if (animation_timer.read() / std.time.ns_per_ms > config.animation_refresh_ms) {
|
||||||
|
animation_timer.reset();
|
||||||
|
doom.draw_with_update();
|
||||||
|
} else {
|
||||||
|
doom.draw();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.matrix => {
|
||||||
|
if (animation_timer.read() / std.time.ns_per_ms > config.animation_refresh_ms) {
|
||||||
|
animation_timer.reset();
|
||||||
|
matrix.draw_with_update();
|
||||||
|
} else {
|
||||||
|
matrix.draw();
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue