summary refs log tree commit diff
path: root/src/World/Chunk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/World/Chunk.cpp')
-rw-r--r--src/World/Chunk.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index 08f08bc..1874950 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -3,8 +3,12 @@
 
 namespace MC::World {
 
-void Chunk::set(uint32_t x, uint32_t y, uint32_t z, BlockType type) {
-    m_blocks[x][y][z].type = type;
+void Chunk::set(uint32_t x, uint32_t y, uint32_t z, BlockData data) {
+    m_blocks[pos(x, y, z)] = data;
+}
+
+Chunk::BlockData Chunk::get(uint32_t x, uint32_t y, uint32_t z) {
+    return m_blocks[pos(x, y, z)];
 }
 
 GFX::Mesh Chunk::mesh() {
@@ -16,7 +20,7 @@ GFX::Mesh Chunk::mesh() {
     for (int x = 0; x < Chunk::Width; x++) {
         for (int y = 0; y < Chunk::Height; y++) {
             for (int z = 0; z < Chunk::Width; z++) {
-                auto type = m_blocks[x][y][z].type;
+                auto type = get(x, y, z).type;
                 if (type == BlockType::Air) {
                     continue;
                 }
@@ -90,7 +94,7 @@ bool Chunk::is_face_visible(uint32_t x, uint32_t y, uint32_t z, BlockSide side)
         return true;
     }
 
-    auto neighbor = m_blocks[neighbor_pos.x()][neighbor_pos.y()][neighbor_pos.z()];
+    auto neighbor = get(neighbor_pos.x(), neighbor_pos.y(), neighbor_pos.z());
     if (neighbor.type == BlockType::Air) {
         return true;
     }
@@ -154,4 +158,8 @@ std::array<Vector<3>, 4> Chunk::face_normals(BlockSide side) {
     return {normal, normal, normal, normal};
 }
 
+uint64_t Chunk::pos(uint32_t x, uint32_t y, uint32_t z) {
+    return x + Chunk::Width * y + Chunk::Width * Chunk::Height * z;
+}
+
 }
{ color: #F00 } /* Operator.Word */ .highlight .pm { color: #DDD } /* Punctuation.Marker */ .highlight .w { color: #DDD } /* Text.Whitespace */ .highlight .mb { color: #F0F } /* Literal.Number.Bin */ .highlight .mf { color: #F0F } /* Literal.Number.Float */ .highlight .mh { color: #F0F } /* Literal.Number.Hex */ .highlight .mi { color: #F0F } /* Literal.Number.Integer */ .highlight .mo { color: #F0F } /* Literal.Number.Oct */ .highlight .sa { color: #87CEEB } /* Literal.String.Affix */ .highlight .sb { color: #87CEEB } /* Literal.String.Backtick */ .highlight .sc { color: #87CEEB } /* Literal.String.Char */ .highlight .dl { color: #87CEEB } /* Literal.String.Delimiter */ .highlight .sd { color: #87CEEB } /* Literal.String.Doc */ .highlight .s2 { color: #87CEEB } /* Literal.String.Double */ .highlight .se { color: #87CEEB } /* Literal.String.Escape */ .highlight .sh { color: #87CEEB } /* Literal.String.Heredoc */ .highlight .si { color: #87CEEB } /* Literal.String.Interpol */ .highlight .sx { color: #87CEEB } /* Literal.String.Other */ .highlight .sr { color: #87CEEB } /* Literal.String.Regex */ .highlight .s1 { color: #87CEEB } /* Literal.String.Single */ .highlight .ss { color: #87CEEB } /* Literal.String.Symbol */ .highlight .bp { color: #DDD } /* Name.Builtin.Pseudo */ .highlight .fm { color: #FF0 } /* Name.Function.Magic */ .highlight .vc { color: #EEDD82 } /* Name.Variable.Class */ .highlight .vg { color: #EEDD82 } /* Name.Variable.Global */ .highlight .vi { color: #EEDD82 } /* Name.Variable.Instance */ .highlight .vm { color: #EEDD82 } /* Name.Variable.Magic */ .highlight .il { color: #F0F } /* Literal.Number.Integer.Long */
{
  lib,
  ghidra,
  openjdk21,
  nixpkgs,
  makeWrapper,
  runCommand,
  callPackage,
  ...
}:

let
  ghidra-copy = let
    copy = runCommand "ghidra-patched" {
      nativeBuildInputs = [ makeWrapper ];
    } ''
      mkdir -p $out $out/lib/ghidra/support

      # dont let `cp` overwrite this later
      ln -s \
        $out/lib/ghidra/support/.launch.sh-wrapped \
        $out/lib/ghidra/support/launch.sh

      patch \
        ${ghidra}/lib/ghidra/support/launch.properties \
        -i ${./ui-scale.patch} \
        -o $out/lib/ghidra/support/launch.properties

      cp --update=none -r ${ghidra}/bin ${ghidra}/lib ${ghidra}/share $out/

      # the original has references to the old ghidra package
      wrapProgram "$out/lib/ghidra/support/.launch.sh-wrapped" \
        --set-default NIX_GHIDRAHOME "$out/lib/ghidra/Ghidra" \
        --prefix PATH : ${lib.makeBinPath [ openjdk21 ]}
    '';
  in
  copy
  // { inherit (ghidra) pname version meta releaseName distroPrefix; };

  members =
    let
      # a bit spooky, no? :3
      nixGhidraPath = "${nixpkgs}/pkgs/tools/security/ghidra";

      buildExtensionAndScripts = callPackage "${nixGhidraPath}/build-extension.nix" {
        ghidra = ghidra-patched;
      };

      withExtensions = callPackage "${nixGhidraPath}/with-extensions.nix" {
        ghidra = ghidra-patched;
      };

      extensions = callPackage "${nixGhidraPath}/extensions.nix" {
        inherit ghidra;
      };
    in
    {
      inherit withExtensions extensions;
      inherit (buildExtensionAndScripts) buildExtension buildGhidraScripts;
    };

    ghidra-patched = ghidra-copy // members;
in
ghidra-patched.withExtensions (
  # extensions passed by function are not built correctly,
  # use extensions build with "normal" ghidra.
  extensions: with members.extensions; [
    gnudisassembler
    machinelearning
    # swift 5.10.2 currently fails build on nixos 25.11
    # see: https://github.com/nixos/nixpkgs/issues/462451
    #ghidraninja-ghidra-scripts
    wasm
    lightkeeper
    kaiju
    ret-sync
    ghidra-delinker-extension
    ghidra-golanganalyzerextension
  ]
)