update map gen
This commit is contained in:
8
Assets/Scripts/GameSetup/Maze/Native.meta
Normal file
8
Assets/Scripts/GameSetup/Maze/Native.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05fdc25279e7ac148a44fde646c93546
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
64
Assets/Scripts/GameSetup/Maze/Native/NativeNoiseProvider.cs
Normal file
64
Assets/Scripts/GameSetup/Maze/Native/NativeNoiseProvider.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fd030227a1b87a4f8826f9b317fbf87
|
||||
Reference in New Issue
Block a user