ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 네네의 디버깅
    일상/잡담/애니메이션 2021. 2. 5. 23:56
    반응형

    뉴게임

    뉴게임에서 잠깐 나오는 네네의 디버깅 장면.

    여기서 잠깐 코드가 나오는데
    보자마자 정말 깔끔한 코드로 보여서 관심이 갔고, 버그가 난 상황까지 꽤 디테일하고 생각했다.

    코드는 C++로 쓰여졌으며 이는 auto, 래퍼런스(&), 포인터 변수의 p 접두 네이밍에서 알 수 있다.

    네네가 하고 싶었던 건 데미지를 받으면 걸린 캐릭터에 걸린 디버프를 반영해 데미지를 가하고, 체력이 0 이하가 되면 캐릭터가 죽는 코드이다.

    void DestructibleActor::ReceiveDamage(float sourceDamage)
    {
      auto resolvedDamage = sourceDamage;
      for(const auto& debuf : m_debufs)
      {
        resolvedDamage = debuf->ApplyToDamage(resolvedDamage);
        m_currentHealth -= resolvedDamage;
        if (m_currentHealth <= 0.f)
        {
          m_currentHealth = 0.f;
          DestroyMe();
        }
      }
    }
    
    void DestructibleActor::DestroyMe()
    {
      if (m_pDeathMotion)
      {
        PlayMotion(m_pDeathMotion);
      }
      
      // ...
    }

    버그가 있을 거 같은 부분은 아래 주석과 같다.

    void DestructibleActor::ReceiveDamage(float sourceDamage)
    {
      auto resolvedDamage = sourceDamage;
      
      // Actor에 Debuf가 없으면 데미지 처리를 못 함.
      // 단, debuf가 비어졌을 때 null 인스턴스를 집어넣는 방식의 처리를 했을 수도 있음.
      for(const auto& debuf : m_debufs)
      {
        resolvedDamage = debuf->ApplyToDamage(resolvedDamage);
        m_currentHealth -= resolvedDamage;
        
        // DestroyMe가 여러번 호출될 수 있음.
        // Dead 플래그 같은 것이 없고,
        // m_debufs의 엘리먼트 개수 만큼 여러번 될 여지가 있다.
        if (m_currentHealth <= 0.f) 
        {
          m_currentHealth = 0.f;
          DestroyMe();
        }
      }
    }
    
    void DestructibleActor::DestroyMe()
    {
      if (m_pDeathMotion)
      {
        PlayMotion(m_pDeathMotion);
      }
      
      // ...
    }

     

    이 애니메이션을 위해 만들어진 코드가 아니라 어딘가에 실제로 쓰이고 있던 코드의 특정 리비전을 가져온 거 같다.

    반응형

    '일상/잡담 > 애니메이션' 카테고리의 다른 글

    시로바코 극장판 2주차  (0) 2020.08.29
    ANILOG  (0) 2019.03.06
Designed by Tistory.