Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98f56833a0 | ||
|
|
3cc4797a72 | ||
|
|
f295aedf04 | ||
|
|
ba0b25980c | ||
|
|
c97a17f85b | ||
|
|
fb63ee21f4 |
+72
-13
@@ -504,19 +504,78 @@ group_texture_runs :: proc(list: []Queued_Sprite) {
|
|||||||
end += 1
|
end += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stable insertion sort is sufficient while MAX_SPRITES is 128.
|
stable_group_by_texture(list[start:end])
|
||||||
for i in start + 1 ..< end {
|
|
||||||
item := list[i]
|
|
||||||
j := i
|
|
||||||
for j > start {
|
|
||||||
if uintptr(list[j - 1].texture) <= uintptr(item.texture) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
list[j] = list[j - 1]
|
|
||||||
j -= 1
|
|
||||||
}
|
|
||||||
list[j] = item
|
|
||||||
}
|
|
||||||
start = end
|
start = end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stably orders window by texture pointer. Fast path for 1–2 textures
|
||||||
|
// (common); insertion sort for 3+.
|
||||||
|
stable_group_by_texture :: proc(window: []Queued_Sprite) {
|
||||||
|
n := len(window)
|
||||||
|
if n <= 1 do return
|
||||||
|
|
||||||
|
already := true
|
||||||
|
for i in 1 ..< n {
|
||||||
|
if uintptr(window[i].texture) < uintptr(window[i - 1].texture) {
|
||||||
|
already = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if already do return
|
||||||
|
|
||||||
|
first := uintptr(window[0].texture)
|
||||||
|
second: uintptr
|
||||||
|
has_second := false
|
||||||
|
third := false
|
||||||
|
for i in 1 ..< n {
|
||||||
|
t := uintptr(window[i].texture)
|
||||||
|
if t == first do continue
|
||||||
|
if !has_second {
|
||||||
|
second = t
|
||||||
|
has_second = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if t != second {
|
||||||
|
third = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !has_second do return
|
||||||
|
|
||||||
|
if third {
|
||||||
|
for i in 1 ..< n {
|
||||||
|
item := window[i]
|
||||||
|
j := i
|
||||||
|
for j > 0 {
|
||||||
|
if uintptr(window[j - 1].texture) <= uintptr(item.texture) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
window[j] = window[j - 1]
|
||||||
|
j -= 1
|
||||||
|
}
|
||||||
|
window[j] = item
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lo, hi := first, second
|
||||||
|
if lo > hi do lo, hi = hi, lo
|
||||||
|
|
||||||
|
tmp: [MAX_SPRITES]Queued_Sprite
|
||||||
|
w := 0
|
||||||
|
for q in window {
|
||||||
|
if uintptr(q.texture) == lo {
|
||||||
|
tmp[w] = q
|
||||||
|
w += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for q in window {
|
||||||
|
if uintptr(q.texture) == hi {
|
||||||
|
tmp[w] = q
|
||||||
|
w += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
copy(window, tmp[:w])
|
||||||
|
}
|
||||||
|
|||||||
@@ -190,6 +190,51 @@ group_texture_runs_already_optimal :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, marker_of(list[3]), f32(40))
|
testing.expect_value(t, marker_of(list[3]), f32(40))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
group_texture_runs_alternating_many_stable :: proc(t: ^testing.T) {
|
||||||
|
// Characterization: large alternating group must collapse to two runs
|
||||||
|
// while preserving same-texture submission order (markers).
|
||||||
|
N :: 64
|
||||||
|
list := make([]Queued_Sprite, N)
|
||||||
|
defer delete(list)
|
||||||
|
for i in 0 ..< N {
|
||||||
|
tex: uintptr = 2 if (i % 2) == 0 else 1
|
||||||
|
list[i] = queued(tex, 1, f32(i + 1))
|
||||||
|
}
|
||||||
|
testing.expect_value(t, texture_run_count(list), N)
|
||||||
|
group_texture_runs(list)
|
||||||
|
testing.expect_value(t, texture_run_count(list), 2)
|
||||||
|
testing.expect(t, list[0].texture == fake_tex(1))
|
||||||
|
testing.expect(t, list[N / 2 - 1].texture == fake_tex(1))
|
||||||
|
testing.expect(t, list[N / 2].texture == fake_tex(2))
|
||||||
|
testing.expect(t, list[N - 1].texture == fake_tex(2))
|
||||||
|
for i in 0 ..< N / 2 {
|
||||||
|
testing.expect_value(t, marker_of(list[i]), f32(2 * i + 2)) // odd markers: 2,4,...,N
|
||||||
|
testing.expect_value(t, marker_of(list[N / 2 + i]), f32(2 * i + 1)) // even markers: 1,3,...,N-1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
group_texture_runs_three_textures_stable :: proc(t: ^testing.T) {
|
||||||
|
list := []Queued_Sprite {
|
||||||
|
queued(3, 1, 1),
|
||||||
|
queued(1, 1, 2),
|
||||||
|
queued(2, 1, 3),
|
||||||
|
queued(3, 1, 4),
|
||||||
|
queued(1, 1, 5),
|
||||||
|
queued(2, 1, 6),
|
||||||
|
}
|
||||||
|
testing.expect_value(t, texture_run_count(list), 6)
|
||||||
|
group_texture_runs(list)
|
||||||
|
testing.expect_value(t, texture_run_count(list), 3)
|
||||||
|
testing.expect_value(t, marker_of(list[0]), f32(2))
|
||||||
|
testing.expect_value(t, marker_of(list[1]), f32(5))
|
||||||
|
testing.expect_value(t, marker_of(list[2]), f32(3))
|
||||||
|
testing.expect_value(t, marker_of(list[3]), f32(6))
|
||||||
|
testing.expect_value(t, marker_of(list[4]), f32(1))
|
||||||
|
testing.expect_value(t, marker_of(list[5]), f32(4))
|
||||||
|
}
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
group_texture_runs_noncontiguous_same_group_id :: proc(t: ^testing.T) {
|
group_texture_runs_noncontiguous_same_group_id :: proc(t: ^testing.T) {
|
||||||
// Same nonzero id split by group 0: each window regroups alone.
|
// Same nonzero id split by group 0: each window regroups alone.
|
||||||
@@ -280,6 +325,24 @@ draw_sprite_stamps_batch_group_zero :: proc(t: ^testing.T) {
|
|||||||
testing.expect(t, app.draw_list[0].texture == data.texture)
|
testing.expect(t, app.draw_list[0].texture == data.texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
draw_sprite_at_max_sprites_does_not_append :: proc(t: ^testing.T) {
|
||||||
|
app := make_test_draw_app()
|
||||||
|
defer destroy_test_draw_app(&app)
|
||||||
|
data := make_test_draw_character()
|
||||||
|
defer destroy_test_draw_character(&data)
|
||||||
|
|
||||||
|
for _ in 0 ..< MAX_SPRITES {
|
||||||
|
append(&app.draw_list, Queued_Sprite{texture = data.texture})
|
||||||
|
}
|
||||||
|
testing.expect_value(t, len(app.draw_list), MAX_SPRITES)
|
||||||
|
|
||||||
|
sprite := spawn_sprite(&data, {100, 200}, "idle", 0)
|
||||||
|
draw_sprite(&app, &sprite)
|
||||||
|
|
||||||
|
testing.expect_value(t, len(app.draw_list), MAX_SPRITES)
|
||||||
|
}
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
draw_sprite_batched_stamps_batch_group :: proc(t: ^testing.T) {
|
draw_sprite_batched_stamps_batch_group :: proc(t: ^testing.T) {
|
||||||
app := make_test_draw_app()
|
app := make_test_draw_app()
|
||||||
|
|||||||
Reference in New Issue
Block a user