faster sort of command queue
This commit is contained in:
parent
89f19ccf2e
commit
884105a4e2
@ -59,6 +59,35 @@ fn int Cmd.compare_to(Cmd a, Cmd b)
|
|||||||
return a.z_index > b.z_index ? 1 : -1;
|
return a.z_index > b.z_index ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FIXME: This sorting method does not fully respect layer ordering for popups.
|
||||||
|
// Popups that start on the same layer but are enqueued at different times
|
||||||
|
// may still be rendered on top of each other, even if the first popup
|
||||||
|
// has elements in higher layers than the second. The current approach
|
||||||
|
// does not truly sort by layer; it only moves elements from higher layers
|
||||||
|
// to the end of the queue as they are encountered.
|
||||||
|
fn void? CmdQueue.sort(&queue)
|
||||||
|
{
|
||||||
|
CmdQueue stack;
|
||||||
|
stack.init(allocator::tmem);
|
||||||
|
|
||||||
|
for (isz i = queue.len()-1; i > 0; i--) {
|
||||||
|
Cmd cur = (*queue)[i];
|
||||||
|
Cmd next = (*queue)[i - 1];
|
||||||
|
// cur < next
|
||||||
|
if (cur.compare_to(next) < 0) {
|
||||||
|
stack.push(next);
|
||||||
|
queue.remove_at(i-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usz l = stack.len();
|
||||||
|
for (usz i; i < l; i++) {
|
||||||
|
queue.push(stack.pop())!;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// implement the Printable interface
|
// implement the Printable interface
|
||||||
fn usz? Cmd.to_format(Cmd* cmd, Formatter *f) @dynamic
|
fn usz? Cmd.to_format(Cmd* cmd, Formatter *f) @dynamic
|
||||||
{
|
{
|
||||||
|
@ -294,6 +294,12 @@ fn void? Ctx.frame_end(&ctx)
|
|||||||
ctx.sprite_atlas.should_update = false;
|
ctx.sprite_atlas.should_update = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort the command buffer by the z-index
|
||||||
|
// FIXME: sorting the buffer fucks with scissor commands that have to be kept in place
|
||||||
|
// TODO: instead of sorting at the end perform ordered inserts into the command buffer
|
||||||
|
//sort::countingsort(ctx.cmd_queue, fn uint(Cmd c) => c.z_index+1);
|
||||||
|
ctx.cmd_queue.sort()!;
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
$if $feature(DEBUG_POINTER):
|
$if $feature(DEBUG_POINTER):
|
||||||
// draw mouse position
|
// draw mouse position
|
||||||
@ -311,11 +317,6 @@ $if $feature(DEBUG_POINTER):
|
|||||||
ctx.cmd_queue.push(cmd);
|
ctx.cmd_queue.push(cmd);
|
||||||
$endif
|
$endif
|
||||||
|
|
||||||
// sort the command buffer by the z-index
|
|
||||||
// FIXME: sorting the buffer fucks with scissor commands that have to be kept in place
|
|
||||||
// TODO: instead of sorting at the end perform ordered inserts into the command buffer
|
|
||||||
sort::countingsort(ctx.cmd_queue, fn uint(Cmd c) => c.z_index+1);
|
|
||||||
|
|
||||||
// foreach (i, c: ctx.cmd_queue) {
|
// foreach (i, c: ctx.cmd_queue) {
|
||||||
// io::printf("[%d]: ", i);
|
// io::printf("[%d]: ", i);
|
||||||
// io::printn(c);
|
// io::printn(c);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user