[luavsq] BPList周りの処理を移植
@@ -0,0 +1,80 @@ | ||
1 | +--[[ | |
2 | + BPList.KeyClockIterator.lua | |
3 | + Copyright © 2011 kbinani | |
4 | + | |
5 | + This file is part of luavsq. | |
6 | + | |
7 | + luavsq is free software; you can redistribute it and/or | |
8 | + modify it under the terms of the GPLv3 License. | |
9 | + | |
10 | + luavsq is distributed in the hope that it will be useful, | |
11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
13 | +]] | |
14 | + | |
15 | +if( nil == luavsq )then | |
16 | + luavsq = {}; | |
17 | +end | |
18 | + | |
19 | +if( nil == luavsq.BPList )then | |
20 | + luavsq.BPList = {}; | |
21 | +end | |
22 | + | |
23 | +if( nil == luavsq.BPList.KeyClockIterator )then | |
24 | + | |
25 | + luavsq.BPList.KeyClockIterator = {}; | |
26 | + | |
27 | + function luavsq.BPList.KeyClockIterator.new( ... ) | |
28 | + local this = {}; | |
29 | + local arguments = { ... }; | |
30 | + this._list = nil; | |
31 | + this._pos = 0; | |
32 | + | |
33 | + --- | |
34 | + -- @param list [VsqBPList] | |
35 | + -- @return [void] | |
36 | + function this:_init_1( list ) | |
37 | + self._list = list; | |
38 | + self._pos = 0; | |
39 | + end | |
40 | + | |
41 | + --- | |
42 | + -- @return [bool] | |
43 | + function this:hasNext() | |
44 | + if( self._pos + 1 <= self._list._length )then | |
45 | + return true; | |
46 | + else | |
47 | + return false; | |
48 | + end | |
49 | + end | |
50 | + | |
51 | + --- | |
52 | + -- @return [int] | |
53 | + function this:next() | |
54 | + self._pos = self._pos + 1; | |
55 | + return self._list.clocks[self._pos]; | |
56 | + end | |
57 | + | |
58 | + --- | |
59 | + -- @return [void] | |
60 | + function this:remove() | |
61 | + if( 0 < self._pos and self._pos <= self._list._length )then | |
62 | + local key = self._list.clocks[self._pos]; | |
63 | + local i; | |
64 | + for i = self._pos, self._list._length - 1, 1 do | |
65 | + self._list.clocks[i] = self._list.clocks[i + 1]; | |
66 | + self._list.items[i].value = self._list.items[i + 1].value; | |
67 | + self._list.items[i].id = self._list.items[i + 1].id; | |
68 | + end | |
69 | + self._list._length = self._list._length - 1; | |
70 | + end | |
71 | + end | |
72 | + | |
73 | + if( #arguments == 1 )then | |
74 | + this:_init_1( arguments[1] ); | |
75 | + end | |
76 | + | |
77 | + return this; | |
78 | + end | |
79 | + | |
80 | +end |
@@ -65,7 +65,7 @@ | ||
65 | 65 | local spl; |
66 | 66 | local buffer = ""; |
67 | 67 | last_line.value = stream:readLine(); |
68 | - while ( last_line.value:sub( 1, 1 ) ~= "[" )do | |
68 | + while( last_line.value:sub( 1, 1 ) ~= "[" )do | |
69 | 69 | spl = luavsq.Util.split( last_line.value, "=" ); |
70 | 70 | if( spl[1] == "MasterFeder" )then |
71 | 71 | self.masterFeder = tonumber( spl[2], 10 ); |
@@ -0,0 +1,673 @@ | ||
1 | +--[[ | |
2 | + BPList.js | |
3 | + Copyright © 2011 kbinani | |
4 | + | |
5 | + This file is part of luavsq. | |
6 | + | |
7 | + luavsq is free software; you can redistribute it and/or | |
8 | + modify it under the terms of the GPLv3 License. | |
9 | + | |
10 | + luavsq is distributed in the hope that it will be useful, | |
11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
13 | +]] | |
14 | + | |
15 | +if( nil == luavsq )then | |
16 | + luavsq = {}; | |
17 | +end | |
18 | + | |
19 | +if( nil == luavsq.BPList )then | |
20 | + | |
21 | + --- | |
22 | + --- コントロールカーブのデータ点リスト | |
23 | + luavsq.BPList = {}; | |
24 | + | |
25 | + function luavsq.BPList.new( ... ) | |
26 | + local this = {}; | |
27 | + local arguments = { ... }; | |
28 | + this.clocks = nil; | |
29 | + this.items = nil; | |
30 | + this._length = 0; -- clocks, itemsに入っているアイテムの個数 | |
31 | + this.defaultValue = 0; | |
32 | + this.maxValue = 127; | |
33 | + this.minValue = 0; | |
34 | + this.maxId = 0; | |
35 | + this.name = ""; | |
36 | + | |
37 | + --- | |
38 | + -- initializer | |
39 | + -- @return [void] | |
40 | + function this:_init_4( name, defaultValue, minimum, maximum ) | |
41 | + self.name = name; | |
42 | + self.defaultValue = defaultValue; | |
43 | + self.maxValue = maximum; | |
44 | + self.minValue = minimum; | |
45 | + self.maxId = 0; | |
46 | + end | |
47 | + | |
48 | + --- | |
49 | + -- @param length [int] | |
50 | + -- @return [void] | |
51 | + function this:_ensureBufferLength( length ) | |
52 | + if( self.clocks == nil )then | |
53 | + self.clocks = {}; | |
54 | + end | |
55 | + if( self.items == nil )then | |
56 | + self.items = {}; | |
57 | + end | |
58 | + if( length > #self.clocks )then | |
59 | + local newLength = length; | |
60 | + if( #self.clocks <= 0 )then | |
61 | + newLength = math.floor( length * 1.2 ); | |
62 | + else | |
63 | + local order = math.floor( length / #self.clocks ); | |
64 | + if( order <= 1 )then | |
65 | + order = 2; | |
66 | + end | |
67 | + newLength = #self.clocks * order; | |
68 | + end | |
69 | + local delta = newLength - #self.clocks; | |
70 | + local i; | |
71 | + for i = 1, delta, 1 do | |
72 | + table.insert( self.clocks, 0 ); | |
73 | + table.insert( self.items, luavsq.BP.new() ); | |
74 | + end | |
75 | + end | |
76 | + end | |
77 | + | |
78 | + --- | |
79 | + -- @return [string] | |
80 | + function this:getName() | |
81 | + if( self.name == nil )then | |
82 | + self.name = ""; | |
83 | + end | |
84 | + return self.name; | |
85 | + end | |
86 | + | |
87 | + --- | |
88 | + -- @param _value [string] | |
89 | + -- @return [void] | |
90 | + function this:setName( value ) | |
91 | + if( value == nil )then | |
92 | + self.name = ""; | |
93 | + else | |
94 | + self.name = value; | |
95 | + end | |
96 | + end | |
97 | + | |
98 | + --- | |
99 | + -- @return [long] | |
100 | + function this:getMaxId() | |
101 | + return self.maxId; | |
102 | + end | |
103 | + | |
104 | + --- | |
105 | + -- このBPListのデフォルト値を取得します | |
106 | + -- @return [int] | |
107 | + function this:getDefault() | |
108 | + return self.defaultValue; | |
109 | + end | |
110 | + | |
111 | + --- | |
112 | + -- @param _value [int] | |
113 | + -- @return [void] | |
114 | + function this:setDefault( _value ) | |
115 | + self.defaultValue = _value; | |
116 | + end | |
117 | + | |
118 | + --[[ | |
119 | + -- データ点のIDを一度クリアし,新たに番号付けを行います. | |
120 | + -- IDは,Redo,Undo用コマンドが使用するため,このメソッドを呼ぶとRedo,Undo操作が破綻する.XMLからのデシリアライズ直後のみ使用するべき. | |
121 | + -- @return [void] | |
122 | + function this:renumberIDs() | |
123 | + self.maxId = 0; | |
124 | + local i; | |
125 | + for i = 1, self._length, 1 do | |
126 | + self.maxId = self.maxId + 1; | |
127 | + self.items[i].id = self.maxId; | |
128 | + end | |
129 | + end]] | |
130 | + | |
131 | + --[[ | |
132 | + -- @return [string] | |
133 | + function this:getData() | |
134 | + local ret = ""; | |
135 | + local i; | |
136 | + for i = 1, self._length, 1 do | |
137 | + if( i > 1 )then | |
138 | + ret = ret .. ","; | |
139 | + end | |
140 | + ret = ret .. self.clocks[i] .. "=" + self.items[i].value; | |
141 | + end | |
142 | + return ret; | |
143 | + end | |
144 | + | |
145 | + --- | |
146 | + -- @param value [string] | |
147 | + -- @return [void] | |
148 | + function this:setData( value ) | |
149 | + self._length = 0; | |
150 | + self.maxId = 0; | |
151 | + var spl = value.split( ',' ); | |
152 | + for ( var i = 0; i < spl.length; i++ ) { | |
153 | + var spl2 = spl[i].split( '=' ); | |
154 | + if ( spl2.length < 2 ) { | |
155 | + continue; | |
156 | + } | |
157 | + var clock = parseInt( spl2[0], 10 ); | |
158 | + if( !isNaN( clock ) ){ | |
159 | + self._ensureBufferLength( self._length + 1 ); | |
160 | + self.clocks[self._length] = clock; | |
161 | + self.items[self._length] = new org.kbinani.vsq.VsqBPPair( parseInt( spl2[1], 10 ), self.maxId + 1 ); | |
162 | + self.maxId++; | |
163 | + self._length++; | |
164 | + } | |
165 | + } | |
166 | + end]] | |
167 | + | |
168 | + --- | |
169 | + -- このVsqBPListの同一コピーを作成します | |
170 | + -- @return [object] | |
171 | + function this:clone() | |
172 | + local res = luavsq.BPList.new( self.name, self.defaultValue, self.minValue, self.maxValue ); | |
173 | + res:_ensureBufferLength( self._length ); | |
174 | + local i; | |
175 | + for i = 1, self._length, 1 do | |
176 | + res.clocks[i] = self.clocks[i]; | |
177 | + res.items[i] = self.items[i]:clone(); | |
178 | + end | |
179 | + res._length = self._length; | |
180 | + res.maxId = self.maxId; | |
181 | + return res; | |
182 | + end | |
183 | + | |
184 | + --- | |
185 | + -- このリストに設定された最大値を取得します。 | |
186 | + -- @return [int] | |
187 | + function this:getMaximum() | |
188 | + return self.maxValue; | |
189 | + end | |
190 | + | |
191 | + --- | |
192 | + -- @param value[ int] | |
193 | + -- @return [void] | |
194 | + function this:setMaximum( value ) | |
195 | + self.maxValue = value; | |
196 | + end | |
197 | + | |
198 | + --- | |
199 | + -- このリストに設定された最小値を取得します | |
200 | + -- @return [int] | |
201 | + function this:getMinimum() | |
202 | + return self.minValue; | |
203 | + end | |
204 | + | |
205 | + --- | |
206 | + -- @param vlaue [int] | |
207 | + -- @return [void] | |
208 | + function this:setMinimum( value ) | |
209 | + self.minValue = value; | |
210 | + end | |
211 | + | |
212 | + --[[ | |
213 | + -- @param clock [int] | |
214 | + -- @return [void] | |
215 | + function this:remove( clock ) | |
216 | + self:_ensureBufferLength( self._length ); | |
217 | + local index = self:_find( clock ); | |
218 | + self:removeElementAt( index ); | |
219 | + end]] | |
220 | + | |
221 | + --[[ | |
222 | + -- @param index [int] | |
223 | + -- @return [void] | |
224 | + function this:removeElementAt( index ) | |
225 | + index = index + 1; | |
226 | + if( index >= 1 )then | |
227 | + local i; | |
228 | + for i = index + 1, self._length - 1, 1 do | |
229 | + self.clocks[i] = self.clocks[i + 1]; | |
230 | + self.items[i].value = self.items[i + 1].value; | |
231 | + self.items[i].id = self.items[i + 1].id; | |
232 | + end | |
233 | + self._length = self._length - 1; | |
234 | + end | |
235 | + end]] | |
236 | + | |
237 | + --- | |
238 | + -- @param clock [int] | |
239 | + -- @return [bool] | |
240 | + function this:isContainsKey( clock ) | |
241 | + self:_ensureBufferLength( self._length ); | |
242 | + return (self:_find( clock ) >= 0); | |
243 | + end | |
244 | + | |
245 | + --[[ | |
246 | + -- 時刻clockのデータを時刻new_clockに移動します。 | |
247 | + -- 時刻clockにデータがなければ何もしない。 | |
248 | + -- 時刻new_clockに既にデータがある場合、既存のデータは削除される。 | |
249 | + -- | |
250 | + -- @param clock [int] | |
251 | + -- @param new_clock [int] | |
252 | + -- @param new_value [int] | |
253 | + -- @return [void] | |
254 | + function this:move( clock, new_clock, new_value ) | |
255 | + self:_ensureBufferLength( self._length ); | |
256 | + local index = self:_find( clock ); | |
257 | + if( index < 0 )then | |
258 | + return; | |
259 | + end | |
260 | + local item = self.items[index + 1]; | |
261 | + local i; | |
262 | + for i = index + 1, self._length - 2, 1 do | |
263 | + self.clocks[i] = self.clocks[i + 1]; | |
264 | + self.items[i].value = self.items[i + 1].value; | |
265 | + self.items[i].id = self.items[i + 1].id; | |
266 | + end | |
267 | + self._length = self._length - 1; | |
268 | + local index_new = self:_find( new_clock ); | |
269 | + if( index_new >= 0 )then | |
270 | + self.items[index_new + 1].value = new_value; | |
271 | + self.items[index_new + 1].id = item.id; | |
272 | + return; | |
273 | + else | |
274 | + self._length = self._length + 1; | |
275 | + self:_ensureBufferLength( self._length ); | |
276 | + self.clocks[self._length] = new_clock; | |
277 | + luavsq.Util.sort( self.clocks, 0, self._length ); | |
278 | + index_new = self:_find( new_clock ); | |
279 | + --item.value = new_value; | |
280 | + local i; | |
281 | + for i = self._length, index_new + 2, -1 do | |
282 | + self.items[i].value = self.items[i - 1].value; | |
283 | + self.items[i].id = self.items[i - 1].id; | |
284 | + end | |
285 | + self.items[index_new + 1].value = new_value; | |
286 | + self.items[index_new + 1].id = item.id; | |
287 | + end | |
288 | + end]] | |
289 | + | |
290 | + --- | |
291 | + -- @return [void] | |
292 | + function this:clear() | |
293 | + self._length = 0; | |
294 | + end | |
295 | + | |
296 | + --- | |
297 | + -- @param index [int] | |
298 | + -- @return [int] | |
299 | + function this:getElement( index ) | |
300 | + return self:getElementA( index ); | |
301 | + end | |
302 | + | |
303 | + --- | |
304 | + -- @param index [int] | |
305 | + -- @return [int] | |
306 | + function this:getElementA( index ) | |
307 | + return self.items[index + 1].value; | |
308 | + end | |
309 | + | |
310 | + --- | |
311 | + -- @param index [int] | |
312 | + -- @return [VsqBPPair] | |
313 | + function this:getElementB( index ) | |
314 | + return self.items[index + 1]:clone(); | |
315 | + end | |
316 | + | |
317 | + --- | |
318 | + -- @param index [int] | |
319 | + -- @return [int] | |
320 | + function this:getKeyClock( index ) | |
321 | + return self.clocks[index + 1]; | |
322 | + end | |
323 | + | |
324 | + --- | |
325 | + -- @param id [long] | |
326 | + -- @return [int] | |
327 | + function this:findValueFromId( id ) | |
328 | + local i; | |
329 | + for i = 1, self._length, 1 do | |
330 | + local item = self.items[i]; | |
331 | + if( item.id == id )then | |
332 | + return item.value; | |
333 | + end | |
334 | + end | |
335 | + return self.defaultValue; | |
336 | + end | |
337 | + | |
338 | + --- | |
339 | + -- 指定したid値を持つVsqBPPairを検索し、その結果を返します。 | |
340 | + -- @param id (number) | |
341 | + -- @return (luavsq.BPListSearchResult) | |
342 | + function this:findElement( id ) | |
343 | + local context = luavsq.BPListSearchResult.new(); | |
344 | + local i; | |
345 | + for i = 1, self._length, 1 do | |
346 | + local item = self.items[i]; | |
347 | + if( item.id == id )then | |
348 | + context.clock = self.clocks[i]; | |
349 | + context.index = i - 1; | |
350 | + context.point = item:clone(); | |
351 | + return context; | |
352 | + end | |
353 | + end | |
354 | + context.clock = -1; | |
355 | + context.index = -1; | |
356 | + context.point = luavsq.BP.new( self.defaultValue, -1 ); | |
357 | + return context; | |
358 | + end | |
359 | + | |
360 | + --- | |
361 | + -- @param id [long] | |
362 | + -- @param value [int] | |
363 | + -- @return [void] | |
364 | + function this:setValueForId( id, value ) | |
365 | + local i; | |
366 | + for i = 1, self._length, 1 do | |
367 | + if( self.items[i].id == id )then | |
368 | + self.items[i].value = value; | |
369 | + break; | |
370 | + end | |
371 | + end | |
372 | + end | |
373 | + | |
374 | + --- | |
375 | + -- このBPListの内容をテキストファイルに書き出します | |
376 | + -- @param writer [ITextWriter] | |
377 | + -- @param start_clock [int] | |
378 | + -- @param header [string] | |
379 | + -- @return [void] | |
380 | + function this:print( writer, start_clock, header ) | |
381 | + writer:writeLine( header ); | |
382 | + local lastvalue = self.defaultValue; | |
383 | + local value_at_start_written = false; | |
384 | + local i; | |
385 | + for i = 1, self._length, 1 do | |
386 | + local key = self.clocks[i]; | |
387 | + if( start_clock == key )then | |
388 | + writer:writeLine( key .. "=" .. self.items[i].value ); | |
389 | + value_at_start_written = true; | |
390 | + elseif( start_clock < key )then | |
391 | + if( (not value_at_start_written) and (lastvalue ~= self.defaultValue) )then | |
392 | + writer:writeLine( start_clock .. "=" .. lastvalue ); | |
393 | + value_at_start_written = true; | |
394 | + end | |
395 | + local val = self.items[i].value; | |
396 | + writer:writeLine( key .. "=" .. val ); | |
397 | + else | |
398 | + lastvalue = self.items[i].value; | |
399 | + end | |
400 | + end | |
401 | + if( (not value_at_start_written) and (lastvalue ~= self.defaultValue) )then | |
402 | + writer:writeLine( start_clock .. "=" .. lastvalue ); | |
403 | + end | |
404 | + end | |
405 | + | |
406 | + --[[ | |
407 | + -- テキストファイルからデータ点を読込み、現在のリストに追加します | |
408 | + -- @param reader [TextStream] | |
409 | + -- @return [string] | |
410 | + function this:appendFromText( reader ) | |
411 | + local clock = 0; | |
412 | + local value = 0; | |
413 | + local minus = 1; | |
414 | + local mode = 0; -- 0: clockを読んでいる, 1: valueを読んでいる | |
415 | + while( reader:ready() )do | |
416 | + local ch = reader:get(); | |
417 | + if( ch == '\n' )then | |
418 | + if( mode == 1 )then | |
419 | + self:_addWithoutSort( clock, value * minus ); | |
420 | + mode = 0; | |
421 | + clock = 0; | |
422 | + value = 0; | |
423 | + minus = 1; | |
424 | + end | |
425 | + else | |
426 | + if( ch == '[' )then | |
427 | + if( mode == 1 )then | |
428 | + self:_addWithoutSort( clock, value * minus ); | |
429 | + mode = 0; | |
430 | + clock = 0; | |
431 | + value = 0; | |
432 | + minus = 1; | |
433 | + end | |
434 | + reader:setPointer( reader:getPointer() - 1 ); | |
435 | + break; | |
436 | + end | |
437 | + if( ch == '=' )then | |
438 | + mode = 1; | |
439 | + elseif( ch == '-' )then | |
440 | + minus = -1; | |
441 | + else | |
442 | + local num = -1; | |
443 | + if( ch == '0' )then | |
444 | + num = 0; | |
445 | + elseif( ch == '1' )then | |
446 | + num = 1; | |
447 | + elseif( ch == '2' )then | |
448 | + num = 2; | |
449 | + elseif( ch == '3' )then | |
450 | + num = 3; | |
451 | + elseif( ch == '4' )then | |
452 | + num = 4; | |
453 | + elseif( ch == '5' )then | |
454 | + num = 5; | |
455 | + elseif( ch == '6' )then | |
456 | + num = 6; | |
457 | + elseif( ch == '7' )then | |
458 | + num = 7; | |
459 | + elseif( ch == '8' )then | |
460 | + num = 8; | |
461 | + elseif( ch == '9' )then | |
462 | + num = 9; | |
463 | + end | |
464 | + if( num >= 0 )then | |
465 | + if( mode == 0 )then | |
466 | + clock = clock * 10 + num; | |
467 | + else | |
468 | + value = value * 10 + num; | |
469 | + end | |
470 | + end | |
471 | + end | |
472 | + end | |
473 | + end | |
474 | + return reader:readLine(); | |
475 | + end]] | |
476 | + | |
477 | + --- | |
478 | + -- @return [int] | |
479 | + function this:size() | |
480 | + return self._length; | |
481 | + end | |
482 | + | |
483 | + --- | |
484 | + -- @return [Iterator<int>] | |
485 | + function this:keyClockIterator() | |
486 | + return luavsq.BPList.KeyClockIterator.new( self ); | |
487 | + end | |
488 | + | |
489 | + --- | |
490 | + -- @param value (integer) | |
491 | + -- @return (integer) 0から始まるインデックス | |
492 | + function this:_find( value ) | |
493 | + local i; | |
494 | + for i = 1, self._length, 1 do | |
495 | + if( self.clocks[i] == value )then | |
496 | + return i - 1; | |
497 | + end | |
498 | + end | |
499 | + return -1; | |
500 | + end | |
501 | + | |
502 | + --- | |
503 | + -- 並べ替え,既存の値との重複チェックを行わず,リストの末尾にデータ点を追加する | |
504 | + -- | |
505 | + -- @param _clock [int] | |
506 | + -- @param value [int] | |
507 | + -- @return [void] | |
508 | + function this:_addWithoutSort( _clock, value ) | |
509 | + self:_ensureBufferLength( self._length + 1 ); | |
510 | + self.clocks[self._length + 1] = _clock; | |
511 | + self.maxId = self.maxId + 1; | |
512 | + self.items[self._length + 1].value = value; | |
513 | + self.items[self._length + 1].id = self.maxId; | |
514 | + self._length = self._length + 1; | |
515 | + end | |
516 | + | |
517 | + --- | |
518 | + -- @param clock [int] | |
519 | + -- @param value [int] | |
520 | + -- @return [long] | |
521 | + function this:add( clock, value ) | |
522 | + self:_ensureBufferLength( self._length ); | |
523 | + local index = self:_find( clock ); | |
524 | + if( index >= 0 )then | |
525 | + self.items[index + 1].value = value; | |
526 | + return self.items[index + 1].id; | |
527 | + else | |
528 | + self._length = self._length + 1; | |
529 | + self:_ensureBufferLength( self._length ); | |
530 | + self.clocks[self._length] = clock; | |
531 | + luavsq.Util.sort( self.clocks, 0, self._length ); | |
532 | + index = self:_find( clock ); | |
533 | + self.maxId = self.maxId + 1; | |
534 | + local i; | |
535 | + for i = self._length, index + 2, -1 do | |
536 | + self.items[i].value = self.items[i - 1].value; | |
537 | + self.items[i].id = self.items[i - 1].id; | |
538 | + end | |
539 | + self.items[index + 1].value = value; | |
540 | + self.items[index + 1].id = self.maxId; | |
541 | + return self.maxId; | |
542 | + end | |
543 | + end | |
544 | + | |
545 | + --- | |
546 | + -- @param clock [int] | |
547 | + -- @param value [int] | |
548 | + -- @param id [long] | |
549 | + -- @return [void] | |
550 | + function this:addWithId( clock, value, id ) | |
551 | + self:_ensureBufferLength( self._length ); | |
552 | + local index = self:_find( clock ); | |
553 | + if( index >= 0 )then | |
554 | + self.items[index + 1].value = value; | |
555 | + self.items[index + 1].id = id; | |
556 | + else | |
557 | + self._length = self._length + 1; | |
558 | + self:_ensureBufferLength( self._length ); | |
559 | + self.clocks[self._length] = clock; | |
560 | + luavsq.Util.sort( self.clocks, 0, self._length ); | |
561 | + index = self:_find( clock ); | |
562 | + local i; | |
563 | + for i = self._length, index + 2, -1 do | |
564 | + self.items[i].value = self.items[i - 1].value; | |
565 | + self.items[i].id = self.items[i - 1].id; | |
566 | + end | |
567 | + self.items[index + 1].value = value; | |
568 | + self.items[index + 1].id = id; | |
569 | + end | |
570 | + self.maxId = math.max( self.maxId, id ); | |
571 | + return id; | |
572 | + end | |
573 | + | |
574 | + --[[ | |
575 | + -- @param id [long] | |
576 | + -- @return [void] | |
577 | + function this:removeWithID( id ) | |
578 | + local i; | |
579 | + for i = 1, self._length, 1 do | |
580 | + if( self.items[i].id == id )then | |
581 | + local j; | |
582 | + for j = i, self._length - 1, 1 do | |
583 | + self.items[j].value = self.items[j + 1].value; | |
584 | + self.items[j].id = self.items[j + 1].id; | |
585 | + self.clocks[j] = self.clocks[j + 1]; | |
586 | + end | |
587 | + self._length = self._length - 1; | |
588 | + break; | |
589 | + end | |
590 | + end | |
591 | + end]] | |
592 | + | |
593 | + function this:getValue( ... ) | |
594 | + local arguments = { ... }; | |
595 | + if( #arguments == 2 )then | |
596 | + return self:_getValue_2( arguments[1], arguments[2] ); | |
597 | + elseif( #arguments == 1 )then | |
598 | + return self:_getValue_1( arguments[1] ); | |
599 | + end | |
600 | + end | |
601 | + | |
602 | + --- | |
603 | + -- @param clock [int] | |
604 | + -- @param index [ByRef<int>] | |
605 | + -- @return [int] | |
606 | + function this:_getValue_2( clock, index ) | |
607 | + if( self._length == 0 )then | |
608 | + return self.defaultValue; | |
609 | + else | |
610 | + if( index.value < 0 )then | |
611 | + index.value = 0; | |
612 | + end | |
613 | + if( index.value > 0 and clock < self.clocks[index.value + 1] )then | |
614 | + index.value = 0; | |
615 | + end | |
616 | + local i; | |
617 | + for i = index.value + 1, self._length, 1 do | |
618 | + local keyclock = self.clocks[i]; | |
619 | + if( clock < keyclock )then | |
620 | + if( i > 1 )then | |
621 | + index.value = i - 2; | |
622 | + return self.items[i - 1].value; | |
623 | + else | |
624 | + index.value = 0; | |
625 | + return self.defaultValue; | |
626 | + end | |
627 | + end | |
628 | + end | |
629 | + index.value = self._length - 1; | |
630 | + return self.items[self._length].value; | |
631 | + end | |
632 | + end | |
633 | + | |
634 | + --- | |
635 | + -- @param clock [int] | |
636 | + -- @return [int] | |
637 | + function this:_getValue_1( clock ) | |
638 | + self:_ensureBufferLength( self._length ); | |
639 | + local index = self:_find( clock ); | |
640 | + if( index >= 0 )then | |
641 | + return self.items[index + 1].value; | |
642 | + else | |
643 | + if( self._length <= 0 )then | |
644 | + return self.defaultValue; | |
645 | + else | |
646 | + local draft = 0; | |
647 | + local i; | |
648 | + for i = 1, self._length, 1 do | |
649 | + local c = self.clocks[i]; | |
650 | + if( clock < c )then | |
651 | + break; | |
652 | + end | |
653 | + draft = i; | |
654 | + end | |
655 | + if( draft == 0 )then | |
656 | + return self.defaultValue; | |
657 | + else | |
658 | + return self.items[draft].value; | |
659 | + end | |
660 | + end | |
661 | + end | |
662 | + end | |
663 | + | |
664 | + if( #arguments == 4 )then | |
665 | + this:_init_4( arguments[1], arguments[2], arguments[3], arguments[4] ); | |
666 | + end | |
667 | + | |
668 | + return this; | |
669 | + end | |
670 | + | |
671 | + luavsq.BPList.INIT_BUFLEN = 512; | |
672 | + | |
673 | +end |
@@ -0,0 +1,24 @@ | ||
1 | +dofile( "./test_bootstrap.lua" ); | |
2 | +module( "enhanced", package.seeall, lunit.testcase ); | |
3 | + | |
4 | +function test() | |
5 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
6 | + local iterator = luavsq.BPList.KeyClockIterator.new( list ); | |
7 | + assert_false( iterator:hasNext() ); | |
8 | + list:add( 480, 1 ); | |
9 | + list:add( 1920, 2 ); | |
10 | + | |
11 | + iterator = luavsq.BPList.KeyClockIterator.new( list ); | |
12 | + assert_true( iterator:hasNext() ); | |
13 | + assert_equal( 480, iterator:next() ); | |
14 | + assert_true( iterator:hasNext() ); | |
15 | + assert_equal( 1920, iterator:next() ); | |
16 | + assert_false( iterator:hasNext() ); | |
17 | + | |
18 | + iterator = luavsq.BPList.KeyClockIterator.new( list ); | |
19 | + assert_true( iterator:hasNext() ); | |
20 | + assert_equal( 480, iterator:next() ); | |
21 | + iterator:remove(); | |
22 | + assert_equal( 1920, iterator:next() ); | |
23 | + assert_false( iterator:hasNext() ); | |
24 | +end |
@@ -43,3 +43,13 @@ | ||
43 | 43 | local bytes = { 0x12, 0x34, 0x56, 0x78 }; |
44 | 44 | assert_equal( 0x12345678, luavsq.Util.makeUInt32BE( bytes ) ); |
45 | 45 | end |
46 | + | |
47 | +function testSort() | |
48 | + local array = { 1, 2, 3, 8, 7, 6, 5, 4, 9 }; | |
49 | + luavsq.Util.sort( array, 3, 5 ); | |
50 | + local expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
51 | + local i; | |
52 | + for i = 1, #expected, 1 do | |
53 | + assert_equal( expected[i], array[i] ); | |
54 | + end | |
55 | +end |
@@ -12,7 +12,6 @@ | ||
12 | 12 | |
13 | 13 | function testConstructFromStream() |
14 | 14 | local stream = luavsq.TextStream.new(); |
15 | - stream:writeLine( "[Mixer]" ); | |
16 | 15 | stream:writeLine( "MasterFeder=1" ); |
17 | 16 | stream:writeLine( "MasterPanpot=2" ); |
18 | 17 | stream:writeLine( "MasterMute=3" ); |
@@ -28,13 +27,59 @@ | ||
28 | 27 | local mixer = luavsq.Mixer.new( stream, lastLine ); |
29 | 28 | |
30 | 29 | assert_equal( 1, #mixer.slave ); |
31 | - fail(); | |
30 | + assert_equal( 1, mixer.masterFeder ); | |
31 | + assert_equal( 2, mixer.masterPanpot ); | |
32 | + assert_equal( 3, mixer.masterMute ); | |
33 | + assert_equal( 4, mixer.outputMode ); | |
34 | + assert_equal( 5, mixer.slave[1].feder ); | |
35 | + assert_equal( 6, mixer.slave[1].panpot ); | |
36 | + assert_equal( 7, mixer.slave[1].mute ); | |
37 | + assert_equal( 8, mixer.slave[1].solo ); | |
32 | 38 | end |
33 | 39 | |
34 | 40 | function testClone() |
35 | - fail(); | |
41 | + local mixer = luavsq.Mixer.new( 1, 2, 3, 4 ); | |
42 | + mixer.slave = {}; | |
43 | + mixer.slave[1] = luavsq.MixerEntry.new( 5, 6, 7, 8 ); | |
44 | + mixer.slave[2] = luavsq.MixerEntry.new( 9, 10, 11, 12 ); | |
45 | + | |
46 | + local copy = mixer:clone(); | |
47 | + assert_equal( 2, #copy.slave ); | |
48 | + assert_equal( 1, copy.masterFeder ); | |
49 | + assert_equal( 2, copy.masterPanpot ); | |
50 | + assert_equal( 3, copy.masterMute ); | |
51 | + assert_equal( 4, copy.outputMode ); | |
52 | + assert_equal( 5, copy.slave[1].feder ); | |
53 | + assert_equal( 6, copy.slave[1].panpot ); | |
54 | + assert_equal( 7, copy.slave[1].mute ); | |
55 | + assert_equal( 8, copy.slave[1].solo ); | |
56 | + assert_equal( 9, copy.slave[2].feder ); | |
57 | + assert_equal( 10, copy.slave[2].panpot ); | |
58 | + assert_equal( 11, copy.slave[2].mute ); | |
59 | + assert_equal( 12, copy.slave[2].solo ); | |
36 | 60 | end |
37 | 61 | |
38 | 62 | function testWrite() |
39 | - fail(); | |
63 | + local mixer = luavsq.Mixer.new( 1, 2, 3, 4 ); | |
64 | + mixer.slave = {}; | |
65 | + mixer.slave[1] = luavsq.MixerEntry.new( 5, 6, 7, 8 ); | |
66 | + mixer.slave[2] = luavsq.MixerEntry.new( 9, 10, 11, 12 ); | |
67 | + local stream = luavsq.TextStream.new(); | |
68 | + mixer:write( stream ); | |
69 | + local expected = | |
70 | + "[Mixer]\n" .. | |
71 | + "MasterFeder=1\n" .. | |
72 | + "MasterPanpot=2\n" .. | |
73 | + "MasterMute=3\n" .. | |
74 | + "OutputMode=4\n" .. | |
75 | + "Tracks=2\n" .. | |
76 | + "Feder0=5\n" .. | |
77 | + "Panpot0=6\n" .. | |
78 | + "Mute0=7\n" .. | |
79 | + "Solo0=8\n" .. | |
80 | + "Feder1=9\n" .. | |
81 | + "Panpot1=10\n" .. | |
82 | + "Mute1=11\n" .. | |
83 | + "Solo1=12\n"; | |
84 | + assert_equal( expected, stream:toString() ); | |
40 | 85 | end |
@@ -0,0 +1,286 @@ | ||
1 | +dofile( "./test_bootstrap.lua" ); | |
2 | +module( "enhanced", package.seeall, lunit.testcase ); | |
3 | + | |
4 | +function testConstruct() | |
5 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
6 | + assert_equal( "foo", list:getName() ); | |
7 | + assert_equal( 63, list:getDefault() ); | |
8 | + assert_equal( -10, list:getMinimum() ); | |
9 | + assert_equal( 1000, list:getMaximum() ); | |
10 | + assert_equal( 0, list:getMaxId() ); | |
11 | +end | |
12 | + | |
13 | +function testGetterAndSetterName() | |
14 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
15 | + assert_equal( "foo", list:getName() ); | |
16 | + list:setName( "bar" ); | |
17 | + assert_equal( "bar", list:getName() ); | |
18 | +end | |
19 | + | |
20 | +function testGetMaxId() | |
21 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
22 | + list:add( 0, 1 ); | |
23 | + assert_equal( 1, list:getMaxId() ); | |
24 | +end | |
25 | + | |
26 | +function testGetterAndSetterDefaultValue() | |
27 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
28 | + assert_equal( 63, list:getDefault() ); | |
29 | + list:setDefault( 62 ); | |
30 | + assert_equal( 62, list:getDefault() ); | |
31 | +end | |
32 | + | |
33 | +function testRenumberIDs() | |
34 | +-- fail(); | |
35 | +end | |
36 | + | |
37 | +function testGetData() | |
38 | +-- fail(); | |
39 | +end | |
40 | + | |
41 | +function testSetData() | |
42 | +-- fail(); | |
43 | +end | |
44 | + | |
45 | +function testClone() | |
46 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
47 | + list:add( 480, 1 ); | |
48 | + list:add( 1920, 2 ); | |
49 | + local copy = list:clone(); | |
50 | + assert_equal( "foo", copy:getName() ); | |
51 | + assert_equal( 63, copy:getDefault() ); | |
52 | + assert_equal( -10, copy:getMinimum() ); | |
53 | + assert_equal( 1000, copy:getMaximum() ); | |
54 | + assert_equal( 2, copy:size() ); | |
55 | + assert_equal( 1, copy:getElementB( 0 ).id ); | |
56 | + assert_equal( 1, copy:getElementB( 0 ).value ); | |
57 | + assert_equal( 480, copy:getKeyClock( 0 ) ); | |
58 | + assert_equal( 2, copy:getElementB( 1 ).id ); | |
59 | + assert_equal( 2, copy:getElementB( 1 ).value ); | |
60 | + assert_equal( 1920, copy:getKeyClock( 1 ) ); | |
61 | +end | |
62 | + | |
63 | +function testGetterAndSetterMaximum() | |
64 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
65 | + assert_equal( 1000, list:getMaximum() ); | |
66 | + list:setMaximum( 1001 ); | |
67 | + assert_equal( 1001, list:getMaximum() ); | |
68 | +end | |
69 | + | |
70 | +function testGetterAndSetterMinimum() | |
71 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
72 | + assert_equal( -10, list:getMinimum() ); | |
73 | + list:setMinimum( 1 ); | |
74 | + assert_equal( 1, list:getMinimum() ); | |
75 | +end | |
76 | + | |
77 | +function testRemove() | |
78 | +-- fail(); | |
79 | +end | |
80 | + | |
81 | +function testRemoveElementAt() | |
82 | +-- fail(); | |
83 | +end | |
84 | + | |
85 | +function testIsContainsKey() | |
86 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
87 | + assert_false( list:isContainsKey( 480 ) ); | |
88 | + list:add( 480, 1 ); | |
89 | + assert_true( list:isContainsKey( 480 ) ); | |
90 | +end | |
91 | + | |
92 | +function testMove() | |
93 | +-- fail(); | |
94 | +end | |
95 | + | |
96 | +function testGetElement() | |
97 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
98 | + list:add( 480, 1 ); | |
99 | + list:add( 1920, 2 ); | |
100 | + assert_equal( 1, list:getElement( 0 ) ); | |
101 | + assert_equal( 2, list:getElement( 1 ) ); | |
102 | +end | |
103 | + | |
104 | +function testGetElementA() | |
105 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
106 | + list:add( 480, 1 ); | |
107 | + list:add( 1920, 2 ); | |
108 | + assert_equal( 1, list:getElementA( 0 ) ); | |
109 | + assert_equal( 2, list:getElementA( 1 ) ); | |
110 | +end | |
111 | + | |
112 | +function testGetElementB() | |
113 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
114 | + list:add( 480, 11 ); | |
115 | + list:add( 1920, 12 ); | |
116 | + assert_equal( 1, list:getElementB( 0 ).id ); | |
117 | + assert_equal( 11, list:getElementB( 0 ).value ); | |
118 | + assert_equal( 2, list:getElementB( 1 ).id ); | |
119 | + assert_equal( 12, list:getElementB( 1 ).value ); | |
120 | +end | |
121 | + | |
122 | +function testGetKeyClock() | |
123 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
124 | + list:add( 480, 11 ); | |
125 | + list:add( 1920, 12 ); | |
126 | + assert_equal( 480, list:getKeyClock( 0 ) ); | |
127 | + assert_equal( 1920, list:getKeyClock( 1 ) ); | |
128 | +end | |
129 | + | |
130 | +function testFindValueFromId() | |
131 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
132 | + local idA = list:add( 480, 11 ); | |
133 | + local idB = list:add( 1920, 12 ); | |
134 | + assert_equal( 11, list:findValueFromId( idA ) ); | |
135 | + assert_equal( 12, list:findValueFromId( idB ) ); | |
136 | +end | |
137 | + | |
138 | +function testFindElement() | |
139 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
140 | + local idA = list:add( 480, 11 ); | |
141 | + local idB = list:add( 1920, 12 ); | |
142 | + local resultA = list:findElement( idA ); | |
143 | + local resultB = list:findElement( idB ); | |
144 | + assert_equal( 480, resultA.clock ); | |
145 | + assert_equal( 0, resultA.index ); | |
146 | + assert_equal( idA, resultA.point.id ); | |
147 | + assert_equal( 11, resultA.point.value ); | |
148 | + assert_equal( 1920, resultB.clock ); | |
149 | + assert_equal( 1, resultB.index ); | |
150 | + assert_equal( idB, resultB.point.id ); | |
151 | + assert_equal( 12, resultB.point.value ); | |
152 | +end | |
153 | + | |
154 | +function testSetValueForId() | |
155 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
156 | + local idA = list:add( 480, 11 ); | |
157 | + local idB = list:add( 1920, 12 ); | |
158 | + list:setValueForId( idA, 13 ); | |
159 | + assert_equal( 13, list:findValueFromId( idA ) ); | |
160 | +end | |
161 | + | |
162 | +function testPrint() | |
163 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
164 | + local header = "[BPList]"; | |
165 | + | |
166 | + local stream = luavsq.TextStream.new(); | |
167 | + list:print( stream, 0, header ); | |
168 | + local expected = | |
169 | + "[BPList]\n" | |
170 | + assert_equal( expected, stream:toString() ); | |
171 | + | |
172 | + stream = luavsq.TextStream.new(); | |
173 | + list:add( 480, 11 ); | |
174 | + list:add( 1920, 12 ); | |
175 | + list:print( stream, 0, header ); | |
176 | + expected = | |
177 | + "[BPList]\n" .. | |
178 | + "480=11\n" .. | |
179 | + "1920=12\n"; | |
180 | + assert_equal( expected, stream:toString() ); | |
181 | + | |
182 | + stream = luavsq.TextStream.new(); | |
183 | + list:print( stream, 1921, header ); | |
184 | + expected = | |
185 | + "[BPList]\n" .. | |
186 | + "1921=12\n"; | |
187 | + assert_equal( expected, stream:toString() ); | |
188 | +end | |
189 | + | |
190 | +function testAppendFromText() | |
191 | +-- fail(); | |
192 | +end | |
193 | + | |
194 | +function testSize() | |
195 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
196 | + assert_equal( 0, list:size() ); | |
197 | + list:add( 480, 11 ); | |
198 | + assert_equal( 1, list:size() ); | |
199 | +end | |
200 | + | |
201 | +function testKeyClockIterator() | |
202 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
203 | + list:add( 480, 11 ); | |
204 | + list:add( 1920, 12 ); | |
205 | + local iterator = list:keyClockIterator(); | |
206 | + assert_true( iterator:hasNext() ); | |
207 | + assert_equal( 480, iterator:next() ); | |
208 | + assert_true( iterator:hasNext() ); | |
209 | + assert_equal( 1920, iterator:next() ); | |
210 | + assert_false( iterator:hasNext() ); | |
211 | +end | |
212 | + | |
213 | +function testAdd() | |
214 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
215 | + local idA = list:add( 480, 11 ); | |
216 | + assert_equal( 1, idA ); | |
217 | + assert_equal( 11, list:getElement( 0 ) ); | |
218 | + | |
219 | + --同じclockに値をaddすると、データ点は増えずに値が上書きされる | |
220 | + idA = list:add( 480, 12 ); | |
221 | + assert_equal( 1, idA ); | |
222 | + assert_equal( 12, list:getElement( 0 ) ); | |
223 | + | |
224 | + --既存の点より小さいclockに値をaddすると、並び替えが起こる | |
225 | + local idB = list:add( 240, 99 ); | |
226 | + assert_not_equal( idA, idB ); | |
227 | + assert_equal( 240, list:getKeyClock( 0 ) ); | |
228 | + assert_equal( idB, list:getElementB( 0 ).id ); | |
229 | + assert_equal( 99, list:getElementB( 0 ).value ); | |
230 | + assert_equal( 480, list:getKeyClock( 1 ) ); | |
231 | + assert_equal( idA, list:getElementB( 1 ).id ); | |
232 | + assert_equal( 12, list:getElementB( 1 ).value ); | |
233 | +end | |
234 | + | |
235 | +function testAddWithID() | |
236 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
237 | + local idA = list:addWithId( 480, 11, 3 ); | |
238 | + assert_equal( 3, idA ); | |
239 | + assert_equal( 11, list:getElement( 0 ) ); | |
240 | + assert_equal( 3, list:getMaxId() ); | |
241 | + | |
242 | + --同じclockに値をaddすると、データ点は増えずに値が上書きされる | |
243 | + idA = list:addWithId( 480, 12, 4 ); | |
244 | + assert_equal( 4, idA ); | |
245 | + assert_equal( 12, list:getElement( 0 ) ); | |
246 | + assert_equal( 4, list:getMaxId() ); | |
247 | + | |
248 | + --既存の点より小さいclockに値をaddすると、並び替えが起こる | |
249 | + local idB = list:addWithId( 240, 99, 5 ); | |
250 | + assert_equal( 5, idB ); | |
251 | + assert_equal( 5, list:getMaxId() ); | |
252 | + assert_equal( 240, list:getKeyClock( 0 ) ); | |
253 | + assert_equal( 5, list:getElementB( 0 ).id ); | |
254 | + assert_equal( 99, list:getElementB( 0 ).value ); | |
255 | + assert_equal( 480, list:getKeyClock( 1 ) ); | |
256 | + assert_equal( 4, list:getElementB( 1 ).id ); | |
257 | + assert_equal( 12, list:getElementB( 1 ).value ); | |
258 | +end | |
259 | + | |
260 | +function testRemoveWithID() | |
261 | +-- fail(); | |
262 | +end | |
263 | + | |
264 | +function testGetValueWithoutLastIndex() | |
265 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
266 | + list:add( 480, 11 ); | |
267 | + list:add( 1920, 12 ); | |
268 | + assert_equal( 63, list:getValue( 479 ) ); | |
269 | + assert_equal( 11, list:getValue( 480 ) ); | |
270 | + assert_equal( 12, list:getValue( 2000 ) ); | |
271 | +end | |
272 | + | |
273 | +function testGetValueWithLastIndex() | |
274 | + local list = luavsq.BPList.new( "foo", 63, -10, 1000 ); | |
275 | + list:add( 480, 11 ); | |
276 | + list:add( 1920, 12 ); | |
277 | + local index = { value = 0 }; | |
278 | + assert_equal( 63, list:getValue( 479, index ) ); | |
279 | + assert_equal( 0, index.value ); | |
280 | + assert_equal( 11, list:getValue( 480, index ) ); | |
281 | + assert_equal( 0, index.value ); | |
282 | + assert_equal( 12, list:getValue( 2000, index ) ); | |
283 | + assert_equal( 1, index.value ); | |
284 | + assert_equal( 63, list:getValue( 479, index ) ); | |
285 | + assert_equal( 0, index.value ); | |
286 | +end |
@@ -85,4 +85,20 @@ | ||
85 | 85 | function luavsq.Util.makeUInt32BE( bytes ) |
86 | 86 | return bytes[1] * 0x1000000 + bytes[2] * 0x10000 + bytes[3] * 0x100 + bytes[4]; |
87 | 87 | end |
88 | + | |
89 | + --- | |
90 | + -- @param array (table) 並び替えるテーブル | |
91 | + -- @param startIndex (number) 並び替える範囲の開始位置(先頭が0) | |
92 | + -- @param length (number) 並び替える範囲の長さ | |
93 | + function luavsq.Util.sort( array, startIndex, length ) | |
94 | + local spliced = {}; | |
95 | + local i; | |
96 | + for i = startIndex + 1, startIndex + 1 + length, 1 do | |
97 | + table.insert( spliced, array[i] ); | |
98 | + end | |
99 | + table.sort( spliced ); | |
100 | + for i = startIndex + 1, startIndex + 1 + length, 1 do | |
101 | + array[i] = spliced[i - startIndex]; | |
102 | + end | |
103 | + end | |
88 | 104 | end |