Skip to content

Commit 043f298

Browse files
committed
impl: Use buffers in region code functions
1 parent 5d95073 commit 043f298

2 files changed

Lines changed: 81 additions & 38 deletions

File tree

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,67 @@
11
function region_code_get(argument0, argument1, argument2, argument3) {
22
// region_code_get(x1, y1, x2, y2)
3-
// Fetches the code of the specified region.
3+
// Fetches the code of the specified region.z
4+
//show_debug_message("region_code_get")
45
var x1, y1, x2, y2, str, a, b, ca, cb, am;
56
x1 = argument0
67
y1 = argument1
78
x2 = argument2
89
y2 = argument3
9-
str = ""
10+
11+
var _colamount = colamount
12+
var _colfirst = colfirst
13+
var _collast = collast
14+
var _song_exists = song_exists
15+
var _song_ins = song_ins
16+
var _song_key = song_key
17+
var _song_vel = song_vel
18+
var _song_pan = song_pan
19+
var _song_pit = song_pit
20+
1021
ca = 0
1122
am = 0
23+
var str_buffer = buffer_create(16, buffer_grow, 1);
1224
for (a = x1; a < x2; a += 1) {
1325
if (a <= enda) {
14-
if (colamount[a] > 0) {
15-
str += string(ca) + "|"
26+
if (_colamount[a] > 0) {
27+
buffer_write(str_buffer, buffer_text, string(ca))
28+
buffer_write(str_buffer, buffer_text, "|")
1629
ca = 0
1730
cb = 0
1831
for (b = y1; b < y2; b += 1) {
19-
if (b >= colfirst[a] && b <= collast[a]) {
20-
if (song_exists[a, b]) {
21-
str += string(cb) + "|"
32+
if (b >= _colfirst[a] && b <= _collast[a]) {
33+
if (_song_exists[a, b]) {
34+
buffer_write(str_buffer, buffer_text, string(cb))
35+
buffer_write(str_buffer, buffer_text, "|")
2236
cb = 0
23-
str += string(ds_list_find_index(instrument_list, song_ins[a, b])) + "|"
24-
str += string(song_key[a, b]) + "|"
25-
str += string(song_vel[a, b]) + "|"
26-
str += string(song_pan[a, b]) + "|"
27-
str += string(song_pit[a, b]) + "|"
37+
buffer_write(str_buffer, buffer_text, string(ds_list_find_index(instrument_list, _song_ins[a, b])))
38+
buffer_write(str_buffer, buffer_text, "|")
39+
buffer_write(str_buffer, buffer_text, string(_song_key[a, b]))
40+
buffer_write(str_buffer, buffer_text, "|")
41+
buffer_write(str_buffer, buffer_text, string(_song_vel[a, b]))
42+
buffer_write(str_buffer, buffer_text, "|")
43+
buffer_write(str_buffer, buffer_text, string(_song_pan[a, b]))
44+
buffer_write(str_buffer, buffer_text, "|")
45+
buffer_write(str_buffer, buffer_text, string(_song_pit[a, b]))
46+
buffer_write(str_buffer, buffer_text, "|")
2847
am += 1
2948
}
3049
}
3150
cb += 1
3251
}
33-
str += "-1|"
52+
buffer_write(str_buffer, buffer_text, "-1|")
3453
}
3554
}
3655
ca += 1
3756
}
38-
if (am = 0) str = ""
57+
if (am == 0) {
58+
str = ""
59+
} else {
60+
buffer_seek(str_buffer, buffer_seek_start, 0)
61+
str = try_compress_selection(buffer_read(str_buffer, buffer_string))
62+
}
63+
buffer_delete(str_buffer)
64+
//show_debug_message(str)
3965
return str
4066

41-
42-
4367
}
Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,55 @@
11
function region_code_load(argument0, argument1, argument2) {
22
// region_code_load(x, y, code)
3-
// Loads the specified code into the x, y position.
3+
// Loads the specified code into the x, y position.z
4+
//show_debug_message("region_code_load " + argument2)
45
var xx, yy, str, ca, cb, val, ins, key, vel, pan, pit;
56
xx = argument0
67
yy = argument1
7-
str = argument2
8+
str = try_decompress_selection(argument2)
89
if (str = "") return 0
910
ca = 0
10-
while (str != "") {
11-
val = real(string_copy(str, 1, string_pos("|", str) - 1))
12-
str = string_delete(str, 1, string_pos("|", str))
11+
var str_len = string_length(str)
12+
var str_buffer = string_buffer_create(str)
13+
var val_buffer = buffer_create(1, buffer_grow, 1)
14+
15+
var pipe_pos = buffer_pos_char(str_buffer, str_len, "|")
16+
var prev_pipe_pos = -1
17+
do {
18+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
19+
prev_pipe_pos = pipe_pos
1320
ca += val
1421
cb = 0
1522
while (1) {
16-
val = real(string_copy(str, 1, string_pos("|", str) - 1))
17-
str = string_delete(str, 1, string_pos("|", str))
18-
if (val = -1) break
23+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
24+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
25+
prev_pipe_pos = pipe_pos
26+
if (val == -1) break
1927
cb += val
20-
ins = instrument_list[| real(string_copy(str, 1, string_pos("|", str) - 1))]
21-
str = string_delete(str, 1, string_pos("|", str))
22-
key = real(string_copy(str, 1, string_pos("|", str) - 1))
23-
str = string_delete(str, 1, string_pos("|", str))
24-
vel = real(string_copy(str, 1, string_pos("|", str) - 1))
25-
str = string_delete(str, 1, string_pos("|", str))
26-
pan = real(string_copy(str, 1, string_pos("|", str) - 1))
27-
str = string_delete(str, 1, string_pos("|", str))
28-
pit = real(string_copy(str, 1, string_pos("|", str) - 1))
29-
str = string_delete(str, 1, string_pos("|", str))
28+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
29+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
30+
prev_pipe_pos = pipe_pos
31+
var ins = instrument_list[| val]
32+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
33+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
34+
prev_pipe_pos = pipe_pos
35+
var key = val
36+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
37+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
38+
prev_pipe_pos = pipe_pos
39+
var vel = val
40+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
41+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
42+
prev_pipe_pos = pipe_pos
43+
var pan = val
44+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
45+
val = real(buffer_substr_copy(str_buffer, prev_pipe_pos + 1, pipe_pos - prev_pipe_pos - 1, val_buffer))
46+
prev_pipe_pos = pipe_pos
47+
var pit = val
3048
add_block(xx + ca, yy + cb, ins, key, vel, pan, pit)
3149
}
32-
}
33-
34-
35-
50+
pipe_pos = buffer_pos_char(str_buffer, str_len, "|", pipe_pos + 1)
51+
} until (pipe_pos >= str_len)
52+
buffer_delete(str_buffer)
53+
buffer_delete(val_buffer)
54+
3655
}

0 commit comments

Comments
 (0)