diff --git a/common/Util.ts b/common/Util.ts deleted file mode 100644 index f6020577..00000000 --- a/common/Util.ts +++ /dev/null @@ -1,97 +0,0 @@ -import type { AjaxOptionImpl } from "./interface/AjaxOptionImpl"; - -/** - * @param {number} value - * @param {number} min - * @param {number} max - * @param {number} [default_value=null] - * @return {number} - * @method - * @static - */ -export const $clamp = ( - value: number, - min: number, - max: number, - default_value: number | null = null -): number => { - - const number: number = +value; - - return isNaN(number) && default_value !== null - ? default_value - : Math.min(Math.max(min, isNaN(number) ? 0 : number), max); -}; - -/** - * @param {object} option - * @return {void} - * @method - * @public - */ -export const $ajax = (option: AjaxOptionImpl): void => -{ - // get or post - let postData: string | null = null; - switch (option.method.toUpperCase()) { - - case "GET": - if (option.data) { - const urls = option.url.split("?"); - - urls[1] = urls.length === 1 - ? option.data.toString() - : `${urls[1]}&${option.data.toString()}`; - - option.url = urls.join("?"); - } - break; - - case "PUT": - case "POST": - if (option.data) { - postData = option.data.toString(); - } - break; - - default: - break; - - } - - // start - const xmlHttpRequest = new XMLHttpRequest(); - - // init - xmlHttpRequest.open(option.method, option.url, true); - - // set mimeType - xmlHttpRequest.responseType = option.format; - - // use cookie - xmlHttpRequest.withCredentials = option.withCredentials; - - // add event - if (option.event) { - const keys: string[] = Object.keys(option.event); - for (let idx = 0; idx < keys.length; ++idx) { - - const name: string = keys[idx]; - - // @ts-ignore - xmlHttpRequest.addEventListener(name, option.event[name]); - } - } - - // set request header - for (let idx: number = 0; idx < option.headers.length; ++idx) { - const header = option.headers[idx]; - if (!header) { - continue; - } - xmlHttpRequest.setRequestHeader(header.name, header.value); - } - - xmlHttpRequest.send(postData); -}; - diff --git a/packages/geom/src/ColorTransform.ts b/packages/geom/src/ColorTransform.ts index 9a65d296..5c6ce2ef 100644 --- a/packages/geom/src/ColorTransform.ts +++ b/packages/geom/src/ColorTransform.ts @@ -1,60 +1,8 @@ import { execute as colorTransformConcatService } from "../src/ColorTransform/service/ColorTransformConcatService"; - -/** - * @type {Float32Array[]} - * @private - */ -const $objectPool: Float32Array[] = []; - -/** - * @description オブジェクトプールから Float32Array オブジェクトを取得します。 - * Get a Float32Array object from the object pool. - * - * @param {number} [f0=0] - * @param {number} [f1=0] - * @param {number} [f2=0] - * @param {number} [f3=0] - * @param {number} [f4=0] - * @param {number} [f5=0] - * @param {number} [f6=0] - * @param {number} [f7=0] - * @return {Float32Array} - * @method - * @private - */ -const $getFloat32Array = ( - f0: number = 1, f1: number = 1, - f2: number = 1, f3: number = 1, - f4: number = 0, f5: number = 0, - f6: number = 0, f7: number = 0 -): Float32Array => { - - const array: Float32Array = $objectPool.pop() || new Float32Array(8); - - array[0] = f0; - array[1] = f1; - array[2] = f2; - array[3] = f3; - array[4] = f4; - array[5] = f5; - array[6] = f6; - array[7] = f7; - - return array; -}; - -/** - * @description 再利用する為に、オブジェクトプールに Float32Array オブジェクトを追加します。 - * Add a Float32Array object to the object pool for reuse. - * - * @param {Float32Array} array - * @method - * @private - */ -const $poolFloat32Array = (array: Float32Array): void => -{ - $objectPool.push(array); -}; +import { + $getFloat32Array8, + $poolFloat32Array8 +} from "./GeomUtil"; /** * @description ColorTransform クラスを使用すると、表示オブジェクトのカラー値を調整することができます。 @@ -110,7 +58,7 @@ export class ColorTransform * @type {Float32Array} * @private */ - this._$colorTransform = $getFloat32Array( + this._$colorTransform = $getFloat32Array8( red_multiplier, green_multiplier, blue_multiplier, alpha_multiplier, red_offset, green_offset, blue_offset, alpha_offset ); @@ -350,7 +298,7 @@ export class ColorTransform */ _$multiplication (a: Float32Array, b: Float32Array): Float32Array { - return $getFloat32Array( + return $getFloat32Array8( a[0] * b[0], a[1] * b[1], a[2] * b[2], @@ -373,15 +321,12 @@ export class ColorTransform } /** - * @param {Float32Array} buffer + * @param {Float32Array} array * @method * @private */ - _$poolBuffer (buffer: Float32Array): void + _$poolBuffer (array: Float32Array): void { - if ($objectPool.length > 10) { - return ; - } - $poolFloat32Array(buffer); + $poolFloat32Array8(array); } } diff --git a/packages/geom/src/GeomUtil.ts b/packages/geom/src/GeomUtil.ts new file mode 100644 index 00000000..ddad581a --- /dev/null +++ b/packages/geom/src/GeomUtil.ts @@ -0,0 +1,106 @@ +/** + * @type {Float32Array[]} + * @private + */ +const $objectPool6: Float32Array[] = []; + +/** + * @description オブジェクトプールから Float32Array オブジェクトを取得します。 + * Get a Float32Array object from the object pool. + * + * @param {number} [f0=0] + * @param {number} [f1=0] + * @param {number} [f2=0] + * @param {number} [f3=0] + * @param {number} [f4=0] + * @param {number} [f5=0] + * @return {Float32Array} + * @method + * @private + */ +export const $getFloat32Array6 = ( + f0: number = 1, f1: number = 0, + f2: number = 0, f3: number = 1, + f4: number = 0, f5: number = 0 +): Float32Array => { + + const array: Float32Array = $objectPool6.pop() || new Float32Array(6); + + array[0] = f0; + array[1] = f1; + array[2] = f2; + array[3] = f3; + array[4] = f4; + array[5] = f5; + + return array; +}; + +/** + * @description 再利用する為に、オブジェクトプールに Float32Array オブジェクトを追加します。 + * Add a Float32Array object to the object pool for reuse. + * + * @param {Float32Array} array + * @method + * @private + */ +export const $poolFloat32Array6 = (array: Float32Array): void => +{ + $objectPool6.push(array); +}; + +/** + * @type {Float32Array[]} + * @private + */ +const $objectPool8: Float32Array[] = []; + +/** + * @description オブジェクトプールから Float32Array オブジェクトを取得します。 + * Get a Float32Array object from the object pool. + * + * @param {number} [f0=0] + * @param {number} [f1=0] + * @param {number} [f2=0] + * @param {number} [f3=0] + * @param {number} [f4=0] + * @param {number} [f5=0] + * @param {number} [f6=0] + * @param {number} [f7=0] + * @return {Float32Array} + * @method + * @private + */ +export const $getFloat32Array8 = ( + f0: number = 1, f1: number = 1, + f2: number = 1, f3: number = 1, + f4: number = 0, f5: number = 0, + f6: number = 0, f7: number = 0 +): Float32Array => { + + const array: Float32Array = $objectPool8.pop() || new Float32Array(8); + + array[0] = f0; + array[1] = f1; + array[2] = f2; + array[3] = f3; + array[4] = f4; + array[5] = f5; + array[6] = f6; + array[7] = f7; + + return array; +}; + +/** + * @description 再利用する為に、オブジェクトプールに Float32Array オブジェクトを追加します。 + * Add a Float32Array object to the object pool for reuse. + * + * @param {Float32Array} array + * @method + * @private + */ +export const $poolFloat32Array8 = (array: Float32Array): void => +{ + $objectPool8.push(array); +}; \ No newline at end of file diff --git a/packages/geom/src/Matrix.ts b/packages/geom/src/Matrix.ts index ae49e5cc..6a5b8ef6 100644 --- a/packages/geom/src/Matrix.ts +++ b/packages/geom/src/Matrix.ts @@ -12,57 +12,10 @@ import { execute as matrixScaleService } from "../src/Matrix/service/MatrixScale import { execute as matrixSetToService } from "../src/Matrix/service/MatrixSetToService"; import { execute as matrixTransformPointService } from "../src/Matrix/service/MatrixTransformPointService"; import { execute as matrixTranslateService } from "../src/Matrix/service/MatrixTranslateService"; - -/** - * @type {Float32Array[]} - * @private - */ -const $objectPool: Float32Array[] = []; - -/** - * @description オブジェクトプールから Float32Array オブジェクトを取得します。 - * Get a Float32Array object from the object pool. - * - * @param {number} [f0=0] - * @param {number} [f1=0] - * @param {number} [f2=0] - * @param {number} [f3=0] - * @param {number} [f4=0] - * @param {number} [f5=0] - * @return {Float32Array} - * @method - * @private - */ -const $getFloat32Array = ( - f0: number = 1, f1: number = 0, - f2: number = 0, f3: number = 1, - f4: number = 0, f5: number = 0 -): Float32Array => { - - const array: Float32Array = $objectPool.pop() || new Float32Array(6); - - array[0] = f0; - array[1] = f1; - array[2] = f2; - array[3] = f3; - array[4] = f4; - array[5] = f5; - - return array; -}; - -/** - * @description 再利用する為に、オブジェクトプールに Float32Array オブジェクトを追加します。 - * Add a Float32Array object to the object pool for reuse. - * - * @param {Float32Array} array - * @method - * @private - */ -const $poolFloat32Array = (array: Float32Array): void => -{ - $objectPool.push(array); -}; +import { + $getFloat32Array6, + $poolFloat32Array6 +} from "./GeomUtil"; /** * @description Matrix クラスは、2 つの座標空間の間におけるポイントのマッピング方法を決定する変換マトリックスを表します。 @@ -103,7 +56,7 @@ export class Matrix * @type {Float32Array} * @private */ - this._$matrix = $getFloat32Array(a, b, c, d, tx, ty); + this._$matrix = $getFloat32Array6(a, b, c, d, tx, ty); } /** @@ -497,7 +450,7 @@ export class Matrix */ _$multiplication (a: Float32Array, b: Float32Array): Float32Array { - return $getFloat32Array( + return $getFloat32Array6( a[0] * b[0] + a[2] * b[1], a[1] * b[0] + a[3] * b[1], a[0] * b[2] + a[2] * b[3], @@ -506,16 +459,14 @@ export class Matrix a[1] * b[4] + a[3] * b[5] + a[5] ); } + /** - * @param {Float32Array} buffer + * @param {Float32Array} array * @method * @private */ - _$poolBuffer (buffer: Float32Array): void + _$poolBuffer (array: Float32Array): void { - if ($objectPool.length > 10) { - return ; - } - $poolFloat32Array(buffer); + $poolFloat32Array6(array); } } diff --git a/packages/geom/src/Transform.ts b/packages/geom/src/Transform.ts index 39428dab..a8357fa3 100644 --- a/packages/geom/src/Transform.ts +++ b/packages/geom/src/Transform.ts @@ -354,8 +354,10 @@ export class Transform } /** - * matrix プロパティから取得される Matrix の Matrix._$matrix と同じ値を返しますが、matrix プロパティと異なり Matrix を複製しません。 - * 返される値は一時的に使用することのみできます。返される値の要素を直接更新してはいけません。返される値をプール(Util.$poolFloat32Array)してはいけません。 + * @description matrix プロパティから取得される Matrix の Matrix._$matrix と同じ値を返しますが、matrix プロパティと異なり Matrix を複製しません。 + * 返される値は一時的に使用することのみできます。返される値の要素を直接更新してはいけません。 + * Returns the same value as Matrix._$matrix of Matrix obtained from the matrix property, but unlike the matrix property, does not duplicate Matrix. + * The returned value may only be used temporarily. Elements of the returned value must not be updated directly. * * @return {Float32Array} * @method diff --git a/packages/media/src/MediaUtil.ts b/packages/media/src/MediaUtil.ts index 0daeacf7..f3943132 100644 --- a/packages/media/src/MediaUtil.ts +++ b/packages/media/src/MediaUtil.ts @@ -1,5 +1,6 @@ import type { Sound } from "./Sound"; import type { Video } from "./Video"; +import type { AjaxOptionImpl } from "./interface/AjaxOptionImpl"; /** * @type {AudioContext} @@ -7,6 +8,101 @@ import type { Video } from "./Video"; */ export const $audioContext: AudioContext | null = "AudioContext" in window ? new AudioContext() : null; +/** + * @param {object} option + * @return {void} + * @method + * @public + */ +export const $ajax = (option: AjaxOptionImpl): void => +{ + // get or post + let postData: string | null = null; + switch (option.method.toUpperCase()) { + + case "GET": + if (option.data) { + const urls = option.url.split("?"); + + urls[1] = urls.length === 1 + ? option.data.toString() + : `${urls[1]}&${option.data.toString()}`; + + option.url = urls.join("?"); + } + break; + + case "PUT": + case "POST": + if (option.data) { + postData = option.data.toString(); + } + break; + + default: + break; + + } + + // start + const xmlHttpRequest = new XMLHttpRequest(); + + // init + xmlHttpRequest.open(option.method, option.url, true); + + // set mimeType + xmlHttpRequest.responseType = option.format; + + // use cookie + xmlHttpRequest.withCredentials = option.withCredentials; + + // add event + if (option.event) { + const keys: string[] = Object.keys(option.event); + for (let idx = 0; idx < keys.length; ++idx) { + + const name: string = keys[idx]; + + // @ts-ignore + xmlHttpRequest.addEventListener(name, option.event[name]); + } + } + + // set request header + for (let idx: number = 0; idx < option.headers.length; ++idx) { + const header = option.headers[idx]; + if (!header) { + continue; + } + xmlHttpRequest.setRequestHeader(header.name, header.value); + } + + xmlHttpRequest.send(postData); +}; + +/** + * @param {number} value + * @param {number} min + * @param {number} max + * @param {number} [default_value=null] + * @return {number} + * @method + * @static + */ +export const $clamp = ( + value: number, + min: number, + max: number, + default_value: number | null = null +): number => { + + const number: number = +value; + + return isNaN(number) && default_value !== null + ? default_value + : Math.min(Math.max(min, isNaN(number) ? 0 : number), max); +}; + /** * @type {number} * @private diff --git a/packages/media/src/Sound.ts b/packages/media/src/Sound.ts index 05ddf4bf..30011da1 100644 --- a/packages/media/src/Sound.ts +++ b/packages/media/src/Sound.ts @@ -6,15 +6,13 @@ import { execute as soundProgressEventService } from "./Sound/SoundProgressEvent import { execute as soundLoadendEventService } from "./Sound/SoundLoadendEventService"; import { execute as soundEndedEventService } from "./Sound/SoundEndedEventService"; import { execute as soundDecodeService } from "./Sound/SoundDecodeService"; -import { - $clamp, - $ajax -} from "../../../common/Util"; import { Event, EventDispatcher } from "@next2d/events"; import { + $clamp, + $ajax, $audioContext, $getSounds } from "./MediaUtil"; diff --git a/packages/media/src/SoundMixer/SoundMixerUpdateVolumeService.ts b/packages/media/src/SoundMixer/SoundMixerUpdateVolumeService.ts index dda384e2..25cafe76 100644 --- a/packages/media/src/SoundMixer/SoundMixerUpdateVolumeService.ts +++ b/packages/media/src/SoundMixer/SoundMixerUpdateVolumeService.ts @@ -1,7 +1,7 @@ import type { Sound } from "../Sound"; import type { Video } from "../Video"; -import { $clamp } from "../../../../common/Util"; import { + $clamp, $setVolume, $getSounds, $getVideos diff --git a/packages/media/src/SoundTransform.ts b/packages/media/src/SoundTransform.ts index a77ee4e4..ee4319de 100644 --- a/packages/media/src/SoundTransform.ts +++ b/packages/media/src/SoundTransform.ts @@ -1,4 +1,4 @@ -import { $clamp } from "../../../common/Util"; +import { $clamp } from "./MediaUtil"; /** * @description SoundTransform クラスにはボリュームとループのプロパティが含まれます。 diff --git a/packages/media/src/Video.ts b/packages/media/src/Video.ts index 52468415..c137bd95 100644 --- a/packages/media/src/Video.ts +++ b/packages/media/src/Video.ts @@ -2,10 +2,12 @@ import { SoundMixer } from "./SoundMixer"; import { DisplayObject } from "@next2d/display"; import { VideoEvent } from "@next2d/events"; import type { BoundsImpl } from "./interface/BoundsImpl"; -import { $clamp } from "../../../common/Util"; import { execute as videoCreateElementService } from "./Video/VideoCreateElementService"; import { execute as videoPlayEventService } from "./Video/VideoPlayEventService"; -import { $getVideos } from "./MediaUtil"; +import { + $clamp, + $getVideos +} from "./MediaUtil"; /** * @description サーバーまたはローカルに保存された録画済みビデオファイルを再生する Video オブジェクトです。 diff --git a/common/interface/AjaxEventImpl.ts b/packages/media/src/interface/AjaxEventImpl.ts similarity index 100% rename from common/interface/AjaxEventImpl.ts rename to packages/media/src/interface/AjaxEventImpl.ts diff --git a/common/interface/AjaxOptionImpl.ts b/packages/media/src/interface/AjaxOptionImpl.ts similarity index 100% rename from common/interface/AjaxOptionImpl.ts rename to packages/media/src/interface/AjaxOptionImpl.ts diff --git a/common/interface/URLLoaderDataFormatImpl.ts b/packages/media/src/interface/URLLoaderDataFormatImpl.ts similarity index 100% rename from common/interface/URLLoaderDataFormatImpl.ts rename to packages/media/src/interface/URLLoaderDataFormatImpl.ts diff --git a/common/interface/URLRequestHeaderImpl.ts b/packages/media/src/interface/URLRequestHeaderImpl.ts similarity index 100% rename from common/interface/URLRequestHeaderImpl.ts rename to packages/media/src/interface/URLRequestHeaderImpl.ts diff --git a/common/interface/URLRequestMethodImpl.ts b/packages/media/src/interface/URLRequestMethodImpl.ts similarity index 100% rename from common/interface/URLRequestMethodImpl.ts rename to packages/media/src/interface/URLRequestMethodImpl.ts