Skip to content

Commit 32e17e7

Browse files
committed
impl: Further improve the speed of nontrivial macros
- Move `array_grow_then_set()` to a separate file; - Utilize `array_grow_then_set()` in `selection_to_array_ext()` function; - Introduce a new function `selection_load_from_array()` to load the selection directly from a selection code array, which is the opposite of `selection_to_array_ext()`; - Use `selection_to_array_ext()` in nonsimple macros.
1 parent 3968f3f commit 32e17e7

File tree

20 files changed

+116
-55
lines changed

20 files changed

+116
-55
lines changed

Minecraft Note Block Studio.yyp

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function array_grow_then_set(array, index, value) {
2+
// Set a value at the index of the array; also allows custom growth of the array
3+
4+
var length = array_length(array)
5+
if (index >= length) {
6+
var new_size = index + 1
7+
var new_length = new_size * 3 / 2; // 1.5x growth factor
8+
//var new_length = (new_size + (new_size >> 3) + 6) & ~3; // Python-style growth
9+
//show_debug_message(string(length) + " -> " + string(floor(new_length)))
10+
for (var i = new_length - 1; i >= length; --i) {
11+
array[@ i] = 0
12+
}
13+
}
14+
array[@ index] = value
15+
}

scripts/array_grow_then_set/array_grow_then_set.yy

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/draw_window_macro_arpeggio/draw_window_macro_arpeggio.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ function draw_window_macro_arpeggio() {
6363
}
6464
if val >= total_vals break
6565
}
66-
var new_str = array_to_selection(arr_data, total_vals)
67-
selection_load_ext(selection_x, selection_y, new_str)
66+
selection_load_from_array(selection_x, selection_y, arr_data)
6867
history_set(h_selectchange, selection_x, selection_y, selection_code, selection_x, selection_y, str)
6968
if(!keyboard_check(vk_alt)) selection_place(false)
7069
}

scripts/draw_window_macro_portamento/draw_window_macro_portamento.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ function draw_window_macro_portamento() {
5454
} else decr = decr + inc
5555
val ++
5656
}
57-
var new_str = array_to_selection(arr_data, total_vals)
58-
selection_load_ext(selection_x, selection_y, new_str)
57+
selection_load_from_array(selection_x, selection_y, arr_data)
5958
history_set(h_selectchange, selection_x, selection_y, selection_code, selection_x, selection_y, str)
6059
if(!keyboard_check(vk_alt)) selection_place(false)
6160
}

scripts/draw_window_macro_stagger/draw_window_macro_stagger.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ function draw_window_macro_stagger() {
8686
}
8787
if val >= total_vals break
8888
}
89-
var new_str = array_to_selection(arr_data, total_vals)
9089
var sel_x = selection_x
9190
var sel_y = selection_y
9291
selection_delete(true)
93-
selection_load_ext(sel_x, sel_y, new_str)
92+
selection_load_from_array(sel_x, sel_y, arr_data)
9493
history_set(h_selectchange, selection_x, selection_y, selection_code, selection_x, selection_y, str)
9594
if(!keyboard_check(vk_alt)) selection_place(false)
9695
}

scripts/draw_window_macro_stereo/draw_window_macro_stereo.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ function draw_window_macro_stereo() {
6767
}
6868
val ++
6969
}
70-
var new_str = array_to_selection(arr_data, total_vals)
71-
selection_load_ext(selection_x, selection_y, new_str)
70+
selection_load_from_array(selection_x, selection_y, arr_data)
7271
history_set(h_selectchange, selection_x, selection_y, selection_code, selection_x, selection_y, str)
7372
if(!keyboard_check(vk_alt)) selection_place(false)
7473
}

scripts/load_song/load_song.gml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,3 @@ function load_song() {
232232
io_clear()
233233

234234
}
235-
236-
function array_grow_then_set(array, index, value) {
237-
// Behave like array_set(), except it allows custom growth of the array
238-
239-
var length = array_length(array)
240-
if (index >= length) {
241-
var new_size = index + 1
242-
var new_length = new_size * 3 / 2; // 1.5x growth factor
243-
//var new_length = (new_size + (new_size >> 3) + 6) & ~3; // Python-style growth
244-
show_debug_message(string(length) + " -> " + string(floor(new_length)))
245-
for (var i = new_length - 1; i >= length; --i) {
246-
array[@ i] = 0
247-
}
248-
}
249-
array[@ index] = value
250-
}

scripts/macro_chorus/macro_chorus.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ function macro_chorus() {
4141
}
4242
}
4343
}
44-
var new_str = array_to_selection(arr_data, total_vals)
45-
selection_load_ext(selection_x, selection_y, new_str)
44+
selection_load_from_array(selection_x, selection_y, arr_data)
4645
history_set(h_selectchange, selection_x, selection_y, selection_code, selection_x, selection_y, str)
4746
if(!keyboard_check(vk_alt)) selection_place(false)
4847

scripts/macro_fadein/macro_fadein.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function macro_fadein() {
2626
decr = decr + inc
2727
val ++
2828
}
29-
var new_str = array_to_selection(arr_data, total_vals)
30-
selection_load_ext(selection_x, selection_y, new_str)
29+
selection_load_from_array(selection_x, selection_y, arr_data)
3130
history_set(h_selectchange, selection_x, selection_y, selection_code, selection_x, selection_y, str)
3231
if(!keyboard_check(vk_alt)) selection_place(false)
3332

0 commit comments

Comments
 (0)