MCPcopy Create free account
hub / github.com/doldecomp/mkdd / createMaterial

Method createMaterial

libs/JSystem/J2DGraph/J2DScreen.cpp:343–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343bool J2DScreen::createMaterial(JSURandomInputStream* input, u32 flags, JKRArchive* archive)
344{
345 int initialPosition = input->getPosition();
346 u32 blank[2];
347 input->read(blank, 8);
348 mMaterialCount = input->readU16();
349 input->skip(2);
350
351 if (flags & 0x1f0000) {
352 mMaterials = new J2DMaterial[mMaterialCount];
353 } else {
354 mMaterials = new (-4) J2DMaterial[mMaterialCount];
355 }
356
357 u8* blockbuf = new (-4) u8[blank[1]];
358 if (mMaterials && blockbuf) {
359 J2DMaterialBlock* blocks = (J2DMaterialBlock*)blockbuf;
360 input->seek(initialPosition, SEEK_SET);
361 input->read(blockbuf, blank[1]);
362
363 J2DMaterialFactory factory(blocks[0]);
364 for (u16 i = 0; i < mMaterialCount; i++) {
365 factory.create(&mMaterials[i], i, flags, mTexRes, mFontRes, archive);
366 }
367 if (flags & 0x1f0000) {
368 u32 nameTabIdx = READU32_BE(blockbuf, 0x14);
369 ResNTAB* nameTab = (ResNTAB*)(blockbuf + nameTabIdx);
370 u16 entry = nameTab->mEntryNum;
371 u16 offset = nameTab->mEntries[entry-1].mOffs;
372 const char *strTable = (const char *)nameTab;
373 u16 strSize = offset;
374 for (; strTable[strSize] != 0; strSize++) {}
375
376 strSize++;
377 u8* tab = new u8[strSize];
378 if (!tab)
379 goto ret_fail;
380
381 for (u16 i = 0; i < strSize; i++) {
382 tab[i] = blockbuf[nameTabIdx+i];
383 }
384
385 mNameTab = new JUTNameTab((ResNTAB*)tab);
386 if (!mNameTab) {
387 delete[] tab;
388 goto ret_fail;
389 }
390 }
391
392 delete[] blockbuf;
393 return true;
394 }
395
396ret_fail:
397 delete[] blockbuf;
398 clean();
399 return false;
400}

Callers

nothing calls this directly

Calls 6

readU16Method · 0.80
skipMethod · 0.80
seekMethod · 0.80
getPositionMethod · 0.45
readMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected