SectrPrototype/code/grime/queue.odin
Ed_ b698f5166b Base input pass updated for sokol possibly done (untested)
Still need to figure out input event consumption, I don't want to do it with the event ring.

I would like to setup input binding layers and then have the push/pop input contextes with a set of bindings.
If the bindings are detected it should "consume" that binding from further use for the buffered time period.

This will be really important with how heavily model this app will be.I
2024-06-18 01:33:50 -04:00

62 lines
1.4 KiB
Odin

package grime
import "core:container/queue"
make_queue :: proc( $QueueType : typeid/Queue($Type), capacity := queue.DEFAULT_CAPACITY, allocator := context.allocator ) -> (result : Queue(Type), error : AllocatorError)
{
queue.init( & result, capacity, allocator )
return
}
push_back_slice_queue :: proc( self : ^$QueueType / Queue($Type), slice : []Type ) -> ( error : AllocatorError )
{
num := cast(uint) len(slice)
if uint( space_left( self^ )) < num {
error = queue._grow( self, self.len + num )
if error != .None do return
}
size := uint(len(self.data))
insert_from := (self.offset + self.len) % size
insert_to := num
if insert_from + insert_to > size {
insert_to = size - insert_from
}
copy( self.data[ insert_from : ], slice[ : insert_to ])
copy( self.data[ : insert_from ], slice[ insert_to : ])
return
}
QueueIterator :: struct( $Type : typeid ) {
data : []Type,
length : uint,
offset : uint,
index : uint,
}
iterator_queue :: proc( queue : $QueueType / Queue($Type) ) -> QueueIterator(Type)
{
iter := QueueIterator(Type) {
data = queue.data[:],
length = queue.len,
offset = queue.offset,
index = 0,
}
return iter
}
next_queue_iterator :: proc( iter : ^QueueIterator($Type) ) -> ^Type
{
using iter
front_id := (length + offset ) % len(data)
elem_id := (length + offset - index) % len(data)
if elem_id == front_id do return nil
elem := & data[ elem_id ]
index += 1
return elem
}