Skip to content

Commit

Permalink
fix: Code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Yushu2606 committed Dec 29, 2023
1 parent cfdcfe2 commit 3f05292
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 264 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on:
- push
- pull_request
- workflow_dispatch

env:
BUILD_TYPE: Release

jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3.5.3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Build
run: dotnet publish -c ${{env.BUILD_TYPE}}

- name: Upload Artifact
uses: actions/upload-artifact@v3.1.2
with:
path: src/bin
28 changes: 0 additions & 28 deletions .github/workflows/dotnet.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on:
workflow_dispatch:
inputs:
prerelease:
type: boolean
required: true
description: Prerelease or not

env:
BUILD_TYPE: Release
DOTNET_VERSION: 8
ASSEMBLY_NAME: Hosihikari.Minecraft.Foundation

jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3.5.3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{env.DOTNET_VERSION}}.0.x

- name: Build
run: dotnet publish -c ${{env.BUILD_TYPE}}

- name: Publish NuGet
id: publish-nuget
uses: alirezanet/publish-nuget@v3.1.0
with:
PROJECT_FILE_PATH: src/${{env.ASSEMBLY_NAME}}.csproj
VERSION_FILE_PATH: Directory.Build.props
TAG_COMMIT: false
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
NO_BUILD: true

- name: Upload Artifact
uses: actions/upload-artifact@v3.1.2
with:
path: src/bin/Release/net${{env.DOTNET_VERSION}}.0/publish/
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.0.0</Version>
</PropertyGroup>
</Project>
23 changes: 16 additions & 7 deletions src/AABB.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Hosihikari.NativeInterop.Generation;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using Hosihikari.NativeInterop.Generation;

namespace Hosihikari.Minecraft;

Expand All @@ -10,18 +10,27 @@ public unsafe struct AABB
internal Vec3 min;
internal Vec3 max;

public Vec3 Min { readonly get => min; set => min = value; }
public Vec3 Max { readonly get => max; set => max = value; }
public Vec3 Min
{
readonly get => min;
set => min = value;
}

public Vec3 Max
{
readonly get => max;
set => max = value;
}

public unsafe ref Vec3 this[int index]
public ref Vec3 this[int index]
{
get
{
fixed (AABB* ptr = &this)
{
long num = (nint)ptr;
return ref *(Vec3*)(index == 1 ? num + 12 : num);
return ref *(Vec3*)(index is 1 ? num + 12 : num);
}
}
}
}
}
7 changes: 3 additions & 4 deletions src/Bedrock/ErrorInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace Hosihikari.Minecraft.Foundation.Bedrock;

#pragma warning disable CS9084


public unsafe struct ErrorInfo<E>
where E : unmanaged
{
private E error;
private fixed byte filler[0x30];

#pragma warning disable CS9084
public ref E Error => ref error;
}
#pragma warning restore CS9084
}
17 changes: 10 additions & 7 deletions src/Bedrock/Result.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Hosihikari.NativeInterop.Generation;
using System.Text.RegularExpressions;
using Hosihikari.NativeInterop.Generation;
using Hosihikari.NativeInterop.Unmanaged;
using Hosihikari.NativeInterop.Unmanaged.STL;
using System.Text.RegularExpressions;

namespace Hosihikari.Minecraft.Foundation.Bedrock;

Expand All @@ -19,10 +19,13 @@ public struct Result<Err>

internal partial class ResultTypeReferencePrivider : ITypeReferenceProvider
{
[GeneratedRegex("^class Bedrock::Result<void, class std::error_code>")]
public static partial Regex ResultRegex();

public static Regex Regex => ResultRegex();

public static Type? Matched(Match match) => typeof(Result<StdErrorCode>);
}
public static Type Matched(Match match)
{
return typeof(Result<StdErrorCode>);
}

[GeneratedRegex("^class Bedrock::Result<void, class std::error_code>")]
public static partial Regex ResultRegex();
}
38 changes: 0 additions & 38 deletions src/BinaryStream.cs

This file was deleted.

94 changes: 57 additions & 37 deletions src/BlockPos.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
using Hosihikari.NativeInterop.Generation;
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Hosihikari.NativeInterop.Generation;

namespace Hosihikari.Minecraft;

[PredefinedType]
[StructLayout(LayoutKind.Sequential)]
public unsafe struct BlockPos
public unsafe struct BlockPos(int x, int y, int z)
{
internal int x;
internal int y;
internal int z;
internal int x = x;
internal int y = y;
internal int z = z;

public int X { readonly get => x; set => x = value; }
public int Y { readonly get => y; set => y = value; }
public int Z { readonly get => z; set => z = value; }
public int X
{
readonly get => x;
set => x = value;
}

public int Y
{
readonly get => y;
set => y = value;
}

public BlockPos(int x, int y, int z)
public int Z
{
this.x = x; this.y = y; this.z = z;
readonly get => z;
set => z = value;
}

private static BlockPos* MAX_ptr;
Expand All @@ -37,14 +46,29 @@ public BlockPos(int x, int y, int z)

public static BlockPos ZERO => *ZERO_ptr;

public override unsafe int GetHashCode()
public override int GetHashCode()
{
fixed (BlockPos* pos = &this)
{
ulong num = (ulong)((((*(byte*)pos ^ -3750763034362895579L) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 1uL)) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 2uL)) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 3uL));
ulong num =
(ulong)(((((((*(byte*)pos ^ -3750763034362895579L) * 1099511628211L) ^
*(byte*)((ulong)(nint)pos + 1uL)) * 1099511628211L) ^ *(byte*)((ulong)(nint)pos + 2uL)) *
1099511628211L) ^ *(byte*)((ulong)(nint)pos + 3uL));
ulong num2 = 2654435769L + num * 1099511628211L;
ulong num3 = (num2 >> 2) + (ulong)(172538324985L + (((((*(byte*)((ulong)(nint)pos + 4uL) ^ -3750763034362895579L) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 5uL)) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 6uL)) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 7uL)) + (long)(num * 64)) * 1099511628211L) ^ num2;
return (int)((num3 >> 2) + (ulong)(2654435769L + ((((*(byte*)((ulong)(nint)pos + 8uL) ^ -3750763034362895579L) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 9uL)) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 10uL)) * 1099511628211L ^ *(byte*)((ulong)(nint)pos + 11uL)) * 1099511628211L + (long)(num3 * 64)) ^ num3);
ulong num3 = ((num2 >> 2) + (ulong)(172538324985L +
((((((((*(byte*)((ulong)(nint)pos + 4uL) ^ -3750763034362895579L) *
1099511628211L) ^ *(byte*)((ulong)(nint)pos + 5uL)) *
1099511628211L) ^ *(byte*)((ulong)(nint)pos + 6uL)) *
1099511628211L) ^
*(byte*)((ulong)(nint)pos + 7uL)) + (long)(num * 64)) *
1099511628211L)) ^ num2;
return (int)(((num3 >> 2) + (ulong)(2654435769L +
(((((((*(byte*)((ulong)(nint)pos + 8uL) ^ -3750763034362895579L) *
1099511628211L) ^ *(byte*)((ulong)(nint)pos + 9uL)) *
1099511628211L) ^ *(byte*)((ulong)(nint)pos + 10uL)) *
1099511628211L) ^
*(byte*)((ulong)(nint)pos + 11uL)) * 1099511628211L +
(long)(num3 * 64))) ^ num3);
}
}

Expand All @@ -59,7 +83,7 @@ public readonly double Length
}
}

public unsafe ref int this[int index]
public ref int this[int index]
{
get
{
Expand All @@ -70,30 +94,26 @@ public unsafe ref int this[int index]
{
2 => (nint)(num + 8),
1 => (nint)(num + 4),
_ => (nint)num,
_ => (nint)num
});
}
}
}

public readonly BlockPos[] Neighbors
{
get
{
return new BlockPos[6]
{
new(x,y-1,z),
new(x,y+1,z),
new(x,y,z-1),
new(x,y,z+1),
new(x-1,y,z),
new(x+1,y,z),
};
}
}
public readonly BlockPos[] Neighbors =>
[
new(x, y - 1, z),
new(x, y + 1, z),
new(x, y, z - 1),
new(x, y, z + 1),
new(x - 1, y, z),
new(x + 1, y, z)
];

public BlockPos Add(int dx, int dy = 0, int dz = 0)
=> new(x + dx, y + dy, z + dz);
{
return new(x + dx, y + dy, z + dz);
}

public static bool operator ==(in BlockPos obj, in BlockPos b)
{
Expand Down Expand Up @@ -179,13 +199,13 @@ public BlockPos Add(int dx, int dy = 0, int dz = 0)
return result;
}

public override readonly bool Equals(object? obj)
public readonly override bool Equals(object? obj)
{
if (obj == null) return false;

if (obj is BlockPos bp)
{
return this == bp;
}

return false;
}
}
}
Loading

0 comments on commit 3f05292

Please sign in to comment.