<commit_before>#include "Runtime/World/CGameArea.hpp"

#include "Runtime/CGameState.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/World/CScriptAreaAttributes.hpp"

#include "DataSpec/DNAMP1/MREA.hpp"

#include "TCastTo.hpp" // Generated file, do not modify include path

namespace urde {

static logvisor::Module Log("CGameArea");

CAreaRenderOctTree::CAreaRenderOctTree(const u8* buf) : x0_buf(buf) {
  CMemoryInStream r(x0_buf + 8, INT32_MAX);
  x8_bitmapCount = r.readUint32Big();
  xc_meshCount = r.readUint32Big();
  x10_nodeCount = r.readUint32Big();
  x14_bitmapWordCount = (xc_meshCount + 31) / 32;
  x18_aabb.readBoundingBoxBig(r);

  x30_bitmaps = reinterpret_cast<const u32*>(x0_buf + 64);
  u32 wc = x14_bitmapWordCount * x8_bitmapCount;
  for (u32 i = 0; i < wc; ++i)
    const_cast<u32*>(x30_bitmaps)[i] = hecl::SBig(x30_bitmaps[i]);

  x34_indirectionTable = x30_bitmaps + wc;
  x38_entries = reinterpret_cast<const u8*>(x34_indirectionTable + x10_nodeCount);
  for (u32 i = 0; i < x10_nodeCount; ++i) {
    const_cast<u32*>(x34_indirectionTable)[i] = hecl::SBig(x34_indirectionTable[i]);
    Node* n = reinterpret_cast<Node*>(const_cast<u8*>(x38_entries) + x34_indirectionTable[i]);
    n->x0_bitmapIdx = hecl::SBig(n->x0_bitmapIdx);
    n->x2_flags = hecl::SBig(n->x2_flags);
    if (n->x2_flags) {
      u32 childCount = n->GetChildCount();
      for (u32 c = 0; c < childCount; ++c)
        n->x4_children[c] = hecl::SBig(n->x4_children[c]);
    }
  }
}

static const u32 ChildCounts[] = {0, 2, 2, 4, 2, 4, 4, 8};
u32 CAreaRenderOctTree::Node::GetChildCount() const { return ChildCounts[x2_flags]; }

zeus::CAABox CAreaRenderOctTree::Node::GetNodeBounds(const zeus::CAABox& curAABB, int idx) const {
  zeus::CVector3f center = curAABB.center();
  switch (x2_flags) {
  case 0:
  default:
    return curAABB;
  case 1:
    if (idx == 0)
      return {curAABB.min.x(), curAABB.min.y(), curAABB.min.z(), center.x(), curAABB.max.y(), curAABB.max.z()};
    else
      return {center.x(), curAABB.min.y(), curAABB.min.z(), curAABB.max.x(), curAABB.max.y(), curAABB.max.z()};
  case 2:<commit_msg>CGameArea: Make use of std::array where applicable<commit_after>#include "Runtime/World/CGameArea.hpp"

#include <array>

#include "Runtime/CGameState.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/World/CScriptAreaAttributes.hpp"

#include "DataSpec/DNAMP1/MREA.hpp"

#include "TCastTo.hpp" // Generated file, do not modify include path

namespace urde {

static logvisor::Module Log("CGameArea");

CAreaRenderOctTree::CAreaRenderOctTree(const u8* buf) : x0_buf(buf) {
  CMemoryInStream r(x0_buf + 8, INT32_MAX);
  x8_bitmapCount = r.readUint32Big();
  xc_meshCount = r.readUint32Big();
  x10_nodeCount = r.readUint32Big();
  x14_bitmapWordCount = (xc_meshCount + 31) / 32;
  x18_aabb.readBoundingBoxBig(r);

  x30_bitmaps = reinterpret_cast<const u32*>(x0_buf + 64);
  u32 wc = x14_bitmapWordCount * x8_bitmapCount;
  for (u32 i = 0; i < wc; ++i)
    const_cast<u32*>(x30_bitmaps)[i] = hecl::SBig(x30_bitmaps[i]);

  x34_indirectionTable = x30_bitmaps + wc;
  x38_entries = reinterpret_cast<const u8*>(x34_indirectionTable + x10_nodeCount);
  for (u32 i = 0; i < x10_nodeCount; ++i) {
    const_cast<u32*>(x34_indirectionTable)[i] = hecl::SBig(x34_indirectionTable[i]);
    Node* n = reinterpret_cast<Node*>(const_cast<u8*>(x38_entries) + x34_indirectionTable[i]);
    n->x0_bitmapIdx = hecl::SBig(n->x0_bitmapIdx);
    n->x2_flags = hecl::SBig(n->x2_flags);
    if (n->x2_flags) {
      u32 childCount = n->GetChildCount();
      for (u32 c = 0; c < childCount; ++c)
        n->x4_children[c] = hecl::SBig(n->x4_children[c]);
    }
  }
}

u32 CAreaRenderOctTree::Node::GetChildCount() const {
  static constexpr std::array<u32, 8> ChildCounts{0, 2, 2, 4, 2, 4, 4, 8};
  return ChildCounts[x2_flags];
}

zeus::CAABox CAreaRenderOctTree::Node::GetNodeBounds(const zeus::CAABox& curAABB, int idx) const {
  zeus::CVector3f center = curAABB.center();
  switch (x2_flags) {
  case 0:
  default:
    return curAABB;
  case 1:
    if (idx == 0)
      return {curAABB.min.x(), curAABB.min.y(), curAABB.min.z(), center.x(), curAABB.max.y(), curAABB.max.z()};
    else
      return {center.x(), curAABB.min.y(), curAABB.min.z(), curAABB.max.x(), curAABB.max.y(), curAABB.max.z()};
  case 2:
{'fraction_non_alphanumeric': 0.15961411971058978, 'fraction_numerical': 0.045384784038588026, 'mean_word_length': 4.85622593068036, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5143345', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1833, 'n_words': 327}