MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / init

Method init

Source/Node/TIC80Node.cpp:296–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296bool TIC80Node::init() {
297 if (!Sprite::init()) return false;
298
299 if (!_codeFile.empty() && !_cartFile.empty()) {
300 auto resourceCartData = SharedContent.load(_cartFile);
301 if (!resourceCartData.first || resourceCartData.second == 0) {
302 Error("TIC80Node: failed to load resource cart file: {}", _cartFile);
303 return false;
304 }
305
306 auto resourceCart = New<tic_cartridge>();
307 tic_cart_load(resourceCart.get(), resourceCartData.first.get(), s_cast<s32>(resourceCartData.second));
308
309 auto mergedCart = New<tic_cartridge>();
310 memset(mergedCart.get(), 0, sizeof(tic_cartridge));
311 if (!mergeCartResources(mergedCart.get(), resourceCart.get())) {
312 Error("TIC80Node: failed to merge cart resources");
313 return false;
314 }
315
316 if (!mergeCartResources(mergedCart.get(), resourceCart.get())) {
317 Error("TIC80Node: failed to merge cart resources");
318 return false;
319 }
320
321 if (!loadCodeFromFile(_codeFile, mergedCart.get())) {
322 Error("TIC80Node: failed to load code file: {}", _codeFile);
323 return false;
324 }
325
326 const s32 estimatedSize = sizeof(tic_cartridge) * 2;
327 std::vector<u8> cartBuffer(estimatedSize);
328 s32 actualSize = tic_cart_save(mergedCart.get(), cartBuffer.data());
329 if (actualSize <= 0 || actualSize > estimatedSize) {
330 Error("TIC80Node: failed to save merged cart");
331 return false;
332 }
333
334 _tic80 = New<TIC80>();
335 auto ticData = s_cast<TIC80*>(_tic80.get());
336 auto tic = ticData->tic;
337 tic80_load(tic, cartBuffer.data(), actualSize);
338 } else if (!_cartFile.empty()) {
339 auto cartData = SharedContent.load(_cartFile);
340 if (!cartData.first || cartData.second == 0) {
341 Error("TIC80Node: failed to load cart file: {}", _cartFile);
342 return false;
343 }
344
345 _tic80 = New<TIC80>();
346 auto ticData = s_cast<TIC80*>(_tic80.get());
347 auto tic = ticData->tic;
348 tic80_load(tic, cartData.first.get(), s_cast<s32>(cartData.second));
349 } else {
350 Error("TIC80Node: cart file not provided");
351 return false;
352 }
353

Callers

nothing calls this directly

Calls 15

tic_cart_loadFunction · 0.85
mergeCartResourcesFunction · 0.85
loadCodeFromFileFunction · 0.85
tic_cart_saveFunction · 0.85
tic80_loadFunction · 0.85
createTexture2DFunction · 0.85
calcTextureSizeFunction · 0.85
setSizeFunction · 0.85
tic80_tickFunction · 0.85
getSoLoudMethod · 0.80
setProtectVoiceMethod · 0.80
setFixedFPSMethod · 0.80

Tested by

no test coverage detected