mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
9f89b0ef24
* Temp * temp * move ui core * Arrange ui and terrain * Fix import path for all modules except core * Move primitives into core * Fix debug.getError * Move audio-downloader to audio module * export game from game.ts * Migrate load-pipeline to ts * Fix core modules and cleanup * Move animation into core * Fix module exports * Fix director issue * Remove most cc.director usage * Fix ts issues * Fix issues for unit test and editor running * Revert removing deprecated import * tweaks * tweaks * Fix ci * Fix ci * Add modules in module division * Upgrade coordinates-converts-utils
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
export class BufferBlob {
|
|
private _arrayBufferOrPaddings: Array<ArrayBuffer | number> = [];
|
|
private _length = 0;
|
|
|
|
public setNextAlignment (align: number) {
|
|
if (align !== 0) {
|
|
const remainder = this._length % align;
|
|
if (remainder !== 0) {
|
|
const padding = align - remainder;
|
|
this._arrayBufferOrPaddings.push(padding);
|
|
this._length += padding;
|
|
}
|
|
}
|
|
}
|
|
|
|
public addBuffer (arrayBuffer: ArrayBuffer) {
|
|
const result = this._length;
|
|
this._arrayBufferOrPaddings.push(arrayBuffer);
|
|
this._length += arrayBuffer.byteLength;
|
|
return result;
|
|
}
|
|
|
|
public getLength () {
|
|
return this._length;
|
|
}
|
|
|
|
public getCombined () {
|
|
const result = new Uint8Array(this._length);
|
|
let counter = 0;
|
|
this._arrayBufferOrPaddings.forEach((arrayBufferOrPadding) => {
|
|
if (typeof arrayBufferOrPadding === 'number') {
|
|
counter += arrayBufferOrPadding;
|
|
} else {
|
|
result.set(new Uint8Array(arrayBufferOrPadding), counter);
|
|
counter += arrayBufferOrPadding.byteLength;
|
|
}
|
|
});
|
|
return result.buffer;
|
|
}
|
|
}
|