update map gen

This commit is contained in:
2026-06-09 22:46:32 +07:00
parent 9048435ac4
commit 1c8544d383
28 changed files with 834 additions and 442 deletions

View File

@@ -0,0 +1,64 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace Hallucinate.GameSetup.Maze.Native
{
public class NativeNoiseProvider : IDisposable
{
private const string DLL_NAME = "BackroomsNoise";
[DllImport(DLL_NAME)]
private static extern IntPtr CreateNoiseGenerator(int seed, float frequency, int noiseType);
[DllImport(DLL_NAME)]
private static extern float GetNoiseValue(IntPtr handle, float x, float z);
[DllImport(DLL_NAME)]
private static extern void GetNoiseBuffer(IntPtr handle, float startX, float startZ, int width, int depth, float[] buffer);
[DllImport(DLL_NAME)]
private static extern void DestroyNoiseGenerator(IntPtr handle);
private IntPtr _handle;
public bool IsInitialized => _handle != IntPtr.Zero;
public NativeNoiseProvider(int seed, float frequency = 0.01f, int noiseType = 0)
{
try
{
_handle = CreateNoiseGenerator(seed, frequency, noiseType);
}
catch (DllNotFoundException)
{
Debug.LogWarning($"Native library '{DLL_NAME}' not found. Ensure it is compiled and placed in Plugins folder.");
}
}
public float GetNoise(float x, float z)
{
if (!IsInitialized) return 0f;
return GetNoiseValue(_handle, x, z);
}
public void FillBuffer(float startX, float startZ, int width, int depth, float[] buffer)
{
if (!IsInitialized || buffer == null) return;
GetNoiseBuffer(_handle, startX, startZ, width, depth, buffer);
}
public void Dispose()
{
if (IsInitialized)
{
DestroyNoiseGenerator(_handle);
_handle = IntPtr.Zero;
}
}
~NativeNoiseProvider()
{
Dispose();
}
}
}