MCPcopy Create free account
hub / github.com/melonjs/melonJS / writeFrame

Function writeFrame

packages/melonjs/tests/aseprite-parser.spec.js:191–228  ·  view source on GitHub ↗
(w, { duration }, bodyFn)

Source from the content-addressed store, hash-verified

189// write a frame header with the given chunk-emitting body fn
190// bodyFn may be async (e.g. when emitting compressed cels via zlib)
191async function writeFrame(w, { duration }, bodyFn) {
192 const frameStart = w.length;
193 w.u32(0); // frame size — patched
194 w.u16(0xf1fa); // frame magic
195 w.u16(0xffff); // old chunks count: 0xFFFF means "use the 32-bit field below"
196 w.u16(duration);
197 w.zeros(2);
198 const chunkCountOffset = w.length;
199 w.u32(0); // new chunks count — patched
200
201 let chunkCount = 0;
202 await bodyFn({
203 layer: (name) => {
204 writeLayerChunk(w, name);
205 chunkCount++;
206 },
207 rawCel: (opts) => {
208 writeRawCelChunk(w, opts);
209 chunkCount++;
210 },
211 linkedCel: (opts) => {
212 writeLinkedCelChunk(w, opts);
213 chunkCount++;
214 },
215 compressedCel: async (opts) => {
216 await writeCompressedCelChunk(w, opts);
217 chunkCount++;
218 },
219 tags: (tags) => {
220 writeTagsChunk(w, tags);
221 chunkCount++;
222 },
223 });
224
225 const end = w.length;
226 patchU32WriterPart(w, frameStart, end - frameStart);
227 patchU32WriterPart(w, chunkCountOffset, chunkCount);
228}
229
230// the writer holds Uint8Array parts before we concat to a buffer, so an
231// in-place patch must walk the parts list and mutate the right one. We could

Callers 1

Calls 9

writeLayerChunkFunction · 0.85
writeRawCelChunkFunction · 0.85
writeLinkedCelChunkFunction · 0.85
writeCompressedCelChunkFunction · 0.85
writeTagsChunkFunction · 0.85
patchU32WriterPartFunction · 0.85
zerosMethod · 0.80
u32Method · 0.45
u16Method · 0.45

Tested by

no test coverage detected