add(continous): example which provides a fixed render schedule

The other examples did rendering based on events, which this renderer
does not. This makes these applications potentially not that efficient,
but allows for consistent frame times that make animations, etc.
possible. This example serves to show that you can use `zterm` for both
types of render scheduling and even change between them without much
efford.
This commit is contained in:
2025-05-30 23:02:56 +02:00
parent 0d2644f476
commit 76f708d9d7
3 changed files with 269 additions and 1 deletions

View File

@@ -90,6 +90,23 @@ pub fn Queue(comptime T: type, comptime size: usize) type {
assert(!this.isEmptyLH());
}
pub fn lock(this: *QueueType) void {
this.mutex.lock();
}
pub fn unlock(this: *QueueType) void {
this.mutex.unlock();
}
/// Used to efficiently drain the queue
pub fn drain(this: *QueueType) ?T {
if (this.isEmptyLH()) return null;
const result = this.buf[this.mask(this.read_index)];
this.read_index = this.mask2(this.read_index + 1);
return result;
}
fn isEmptyLH(this: QueueType) bool {
return this.write_index == this.read_index;
}
@@ -114,7 +131,7 @@ pub fn Queue(comptime T: type, comptime size: usize) type {
}
/// Returns the length
fn len(this: QueueType) usize {
pub fn len(this: QueueType) usize {
const wrap_offset = 2 * this.buf.len *
@intFromBool(this.write_index < this.read_index);
const adjusted_write_index = this.write_index + wrap_offset;