MCPcopy Create free account
hub / github.com/ddnet/ddnet / Load

Method Load

src/game/client/components/ghost.cpp:455–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455int CGhost::Load(const char *pFilename)
456{
457 int Slot = GetSlot();
458 if(Slot == -1)
459 return -1;
460
461 if(!GhostLoader()->Load(pFilename, GameClient()->Map()->BaseName(), GameClient()->Map()->Sha256(), GameClient()->Map()->Crc()))
462 return -1;
463
464 const CGhostInfo *pInfo = GhostLoader()->GetInfo();
465
466 // select ghost
467 CGhostItem *pGhost = &m_aActiveGhosts[Slot];
468 pGhost->Reset();
469 pGhost->m_Path.SetSize(pInfo->m_NumTicks);
470
471 str_copy(pGhost->m_aPlayer, pInfo->m_aOwner);
472
473 int Index = 0;
474 bool FoundSkin = false;
475 bool NoTick = false;
476 bool Error = false;
477
478 int Type;
479 while(!Error && GhostLoader()->ReadNextType(&Type))
480 {
481 if(Index == pInfo->m_NumTicks && (Type == GHOSTDATA_TYPE_CHARACTER || Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK))
482 {
483 Error = true;
484 break;
485 }
486
487 if(Type == GHOSTDATA_TYPE_SKIN && !FoundSkin)
488 {
489 FoundSkin = true;
490 if(!GhostLoader()->ReadData(Type, &pGhost->m_Skin, sizeof(CGhostSkin)))
491 Error = true;
492 }
493 else if(Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK)
494 {
495 NoTick = true;
496 if(!GhostLoader()->ReadData(Type, pGhost->m_Path.Get(Index++), sizeof(CGhostCharacter_NoTick)))
497 Error = true;
498 }
499 else if(Type == GHOSTDATA_TYPE_CHARACTER)
500 {
501 if(!GhostLoader()->ReadData(Type, pGhost->m_Path.Get(Index++), sizeof(CGhostCharacter)))
502 Error = true;
503 }
504 else if(Type == GHOSTDATA_TYPE_START_TICK)
505 {
506 if(!GhostLoader()->ReadData(Type, &pGhost->m_StartTick, sizeof(int)))
507 Error = true;
508 }
509 }
510
511 GhostLoader()->Close();
512

Callers 8

InitializeLanguageMethod · 0.45
HandleLanguageChangedMethod · 0.45
OnMapLoadMethod · 0.45
OnInitMethod · 0.45
LoadBackgroundMethod · 0.45
LoadMenuBackgroundMethod · 0.45
GhostlistPopulateMethod · 0.45
RenderGhostMethod · 0.45

Calls 12

GetInfoMethod · 0.80
SetSizeMethod · 0.80
ReadNextTypeMethod · 0.80
ReadDataMethod · 0.80
str_copyFunction · 0.50
BaseNameMethod · 0.45
MapMethod · 0.45
Sha256Method · 0.45
CrcMethod · 0.45
ResetMethod · 0.45
GetMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected