From a21adc532b26d55db5636cd37f9fe8a319f2b22f Mon Sep 17 00:00:00 2001 From: jeickhoff Date: Wed, 19 Jul 2023 18:41:05 +0200 Subject: [PATCH] Add terrain noise layers, global vars, begin terrain structures --- Assets/Config/TerrainLayers.meta | 8 + .../TerrainLayers/AbsoluteDirtLayer.asset | 24 + .../AbsoluteDirtLayer.asset.meta | 8 + .../TerrainLayers/AbsoluteStoneLayer.asset | 24 + .../AbsoluteStoneLayer.asset.meta | 8 + .../AbsoluteStoneMountainLayer.asset | 24 + .../AbsoluteStoneMountainLayer.asset.meta | 8 + .../TerrainLayers/AdditiveDirtLayer.asset | 24 + .../AdditiveDirtLayer.asset.meta | 8 + .../TerrainLayers/AdditiveStoneLayer.asset | 24 + .../AdditiveStoneLayer.asset.meta | 8 + .../TerrainLayers/StructureTreeLayer.asset | 24 + .../StructureTreeLayer.asset.meta | 8 + .../TerrainLayers/SurfaceGrassLayer.asset | 24 + .../SurfaceGrassLayer.asset.meta | 8 + .../TerrainLayerCollection.asset | 22 + .../TerrainLayerCollection.asset.meta | 8 + Assets/Materials/Shaders/VoxelShader.shader | 6 +- Assets/Materials/TerrainMaterial.mat | 2 +- Assets/Materials/Textures/BlockTextures.png | Bin 5616 -> 0 bytes Assets/Materials/Textures/SpriteSheet.png | Bin 0 -> 7315 bytes ...Textures.png.meta => SpriteSheet.png.meta} | 4 +- Assets/Prefabs/MultiplayPlayer.prefab | 2 +- Assets/Prefabs/TerrainArea.prefab | 7 +- ...f85a123bb39070d0d89.sceneWithBuildSettings | Bin 48 -> 48 bytes .../AuthoringScene/AuthoringScene.unity | 19 +- Assets/Scenes/MainScene.unity | 2 +- Assets/Scripts/Config.cs | 40 ++ Assets/Scripts/Config.cs.meta | 3 + Assets/Scripts/DrawIfAttribute.cs | 40 ++ Assets/Scripts/DrawIfAttribute.cs.meta | 3 + Assets/Scripts/Editor.meta | 3 + Assets/Scripts/Editor/DrawIfProperty.cs | 97 ++++ Assets/Scripts/Editor/DrawIfProperty.cs.meta | 3 + .../Player/Authoring/PlayerAuthoring.cs | 2 + Assets/Scripts/Player/Multiplay/Multiplay.cs | 2 +- Assets/Scripts/Player/PlayerActionSystem.cs | 7 +- Assets/Scripts/Player/PlayerManagerSystem.cs | 2 +- Assets/Scripts/Player/PlayerMovementSystem.cs | 7 +- Assets/Scripts/Rendering/DebugRenderSystem.cs | 7 +- .../Scripts/Rendering/TerrainMeshingSystem.cs | 65 ++- .../Rendering/TerrainRenderInitSystem.cs | 12 +- .../Terrain/Authoring/TerrainAreaAuthoring.cs | 23 +- .../Authoring/TerrainSpawnerAuthoring.cs | 90 ++-- Assets/Scripts/Terrain/Blocks/BlockType.cs | 6 +- Assets/Scripts/Terrain/Layers.meta | 3 + .../Scripts/Terrain/Layers/LayerCollection.cs | 40 ++ .../Terrain/Layers/LayerCollection.cs.meta | 3 + Assets/Scripts/Terrain/Layers/LayerConfig.cs | 78 +++ .../Terrain/Layers/LayerConfig.cs.meta | 3 + Assets/Scripts/Terrain/Structures.meta | 3 + .../Terrain/Structures/StructureTypes.cs | 9 + .../Terrain/Structures/StructureTypes.cs.meta | 3 + .../Terrain/TerrainGenerationSystem.cs | 448 ++++++++++++++---- .../Scripts/Terrain/TerrainNeighborSystem.cs | 20 +- .../Terrain/TerrainStructuresSystem.cs | 248 ++++++++++ .../Terrain/TerrainStructuresSystem.cs.meta | 3 + .../Scripts/Terrain/TerrainToSpawnSystem.cs | 34 +- .../Terrain/Utilities/NoiseUtilities.cs | 224 +++++++++ .../Terrain/Utilities/NoiseUtilities.cs.meta | 3 + .../Terrain/Utilities/TerrainUtilities.cs | 67 ++- Assets/Scripts/ThirdParty/CustomFastPerlin.cs | 182 ------- Assets/Scripts/ThirdParty/FastNoise.cs | 390 +++++++++++++++ ...omFastPerlin.cs.meta => FastNoise.cs.meta} | 0 ProjectSettings/ProjectSettings.asset | 2 +- 65 files changed, 2050 insertions(+), 429 deletions(-) create mode 100644 Assets/Config/TerrainLayers.meta create mode 100644 Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset create mode 100644 Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset create mode 100644 Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset create mode 100644 Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/AdditiveDirtLayer.asset create mode 100644 Assets/Config/TerrainLayers/AdditiveDirtLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/AdditiveStoneLayer.asset create mode 100644 Assets/Config/TerrainLayers/AdditiveStoneLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/StructureTreeLayer.asset create mode 100644 Assets/Config/TerrainLayers/StructureTreeLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/SurfaceGrassLayer.asset create mode 100644 Assets/Config/TerrainLayers/SurfaceGrassLayer.asset.meta create mode 100644 Assets/Config/TerrainLayers/TerrainLayerCollection.asset create mode 100644 Assets/Config/TerrainLayers/TerrainLayerCollection.asset.meta delete mode 100644 Assets/Materials/Textures/BlockTextures.png create mode 100644 Assets/Materials/Textures/SpriteSheet.png rename Assets/Materials/Textures/{BlockTextures.png.meta => SpriteSheet.png.meta} (97%) create mode 100644 Assets/Scripts/Config.cs create mode 100644 Assets/Scripts/Config.cs.meta create mode 100644 Assets/Scripts/DrawIfAttribute.cs create mode 100644 Assets/Scripts/DrawIfAttribute.cs.meta create mode 100644 Assets/Scripts/Editor.meta create mode 100644 Assets/Scripts/Editor/DrawIfProperty.cs create mode 100644 Assets/Scripts/Editor/DrawIfProperty.cs.meta create mode 100644 Assets/Scripts/Terrain/Layers.meta create mode 100644 Assets/Scripts/Terrain/Layers/LayerCollection.cs create mode 100644 Assets/Scripts/Terrain/Layers/LayerCollection.cs.meta create mode 100644 Assets/Scripts/Terrain/Layers/LayerConfig.cs create mode 100644 Assets/Scripts/Terrain/Layers/LayerConfig.cs.meta create mode 100644 Assets/Scripts/Terrain/Structures.meta create mode 100644 Assets/Scripts/Terrain/Structures/StructureTypes.cs create mode 100644 Assets/Scripts/Terrain/Structures/StructureTypes.cs.meta create mode 100644 Assets/Scripts/Terrain/TerrainStructuresSystem.cs create mode 100644 Assets/Scripts/Terrain/TerrainStructuresSystem.cs.meta create mode 100644 Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs create mode 100644 Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs.meta delete mode 100644 Assets/Scripts/ThirdParty/CustomFastPerlin.cs create mode 100644 Assets/Scripts/ThirdParty/FastNoise.cs rename Assets/Scripts/ThirdParty/{CustomFastPerlin.cs.meta => FastNoise.cs.meta} (100%) diff --git a/Assets/Config/TerrainLayers.meta b/Assets/Config/TerrainLayers.meta new file mode 100644 index 00000000..e76a1062 --- /dev/null +++ b/Assets/Config/TerrainLayers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 67ff42c4df16ec24794416729f1c23df +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset b/Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset new file mode 100644 index 00000000..fa713882 --- /dev/null +++ b/Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: AbsoluteDirtLayer + m_EditorClassIdentifier: + layerType: 0 + layerName: Dirt base layer + index: 300 + blockType: 2 + frequency: 50 + exponent: 1 + minHeight: 20 + maxHeight: 25 + chance: 0 + structureType: 0 diff --git a/Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset.meta b/Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset.meta new file mode 100644 index 00000000..7b83c968 --- /dev/null +++ b/Assets/Config/TerrainLayers/AbsoluteDirtLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a7f2d008399aab1458b1b760cf85ff0a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset b/Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset new file mode 100644 index 00000000..11ebf664 --- /dev/null +++ b/Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: AbsoluteStoneLayer + m_EditorClassIdentifier: + layerType: 0 + layerName: Stone base layer + index: 100 + blockType: 1 + frequency: 32 + exponent: 1 + minHeight: 10 + maxHeight: 26 + chance: 0 + structureType: 0 diff --git a/Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset.meta b/Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset.meta new file mode 100644 index 00000000..28b38818 --- /dev/null +++ b/Assets/Config/TerrainLayers/AbsoluteStoneLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b294ba7c0c4a08144916c18d0f467747 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset b/Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset new file mode 100644 index 00000000..b2fcb2a1 --- /dev/null +++ b/Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: AbsoluteStoneMountainLayer + m_EditorClassIdentifier: + layerType: 0 + layerName: Stone mountains layer + index: 150 + blockType: 1 + frequency: 110 + exponent: 1.1 + minHeight: 0 + maxHeight: 26 + chance: 0 + structureType: 0 diff --git a/Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset.meta b/Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset.meta new file mode 100644 index 00000000..61e3a32c --- /dev/null +++ b/Assets/Config/TerrainLayers/AbsoluteStoneMountainLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0bc928c0fbae2694a9c4c010f4687eb4 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/AdditiveDirtLayer.asset b/Assets/Config/TerrainLayers/AdditiveDirtLayer.asset new file mode 100644 index 00000000..3cb6d675 --- /dev/null +++ b/Assets/Config/TerrainLayers/AdditiveDirtLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: AdditiveDirtLayer + m_EditorClassIdentifier: + layerType: 4 + layerName: Dirt noise layer + index: 400 + blockType: 2 + frequency: 20 + exponent: 1 + minHeight: 2 + maxHeight: 5 + chance: 0 + structureType: 0 diff --git a/Assets/Config/TerrainLayers/AdditiveDirtLayer.asset.meta b/Assets/Config/TerrainLayers/AdditiveDirtLayer.asset.meta new file mode 100644 index 00000000..d4f233d5 --- /dev/null +++ b/Assets/Config/TerrainLayers/AdditiveDirtLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a676bee5116cc047acabfa4f7d19241 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/AdditiveStoneLayer.asset b/Assets/Config/TerrainLayers/AdditiveStoneLayer.asset new file mode 100644 index 00000000..92605a60 --- /dev/null +++ b/Assets/Config/TerrainLayers/AdditiveStoneLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: AdditiveStoneLayer + m_EditorClassIdentifier: + layerType: 4 + layerName: Stone noise layer + index: 200 + blockType: 1 + frequency: 7 + exponent: 1 + minHeight: 1 + maxHeight: 4 + chance: 0 + structureType: 0 diff --git a/Assets/Config/TerrainLayers/AdditiveStoneLayer.asset.meta b/Assets/Config/TerrainLayers/AdditiveStoneLayer.asset.meta new file mode 100644 index 00000000..3295579a --- /dev/null +++ b/Assets/Config/TerrainLayers/AdditiveStoneLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a5626c3ee64bec348a6e50deb3b467d1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/StructureTreeLayer.asset b/Assets/Config/TerrainLayers/StructureTreeLayer.asset new file mode 100644 index 00000000..2857bcc8 --- /dev/null +++ b/Assets/Config/TerrainLayers/StructureTreeLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: StructureTreeLayer + m_EditorClassIdentifier: + layerType: 2 + layerName: Structure tree layer + index: 1500 + blockType: 0 + frequency: 0 + exponent: 0 + minHeight: 0 + maxHeight: 0 + chance: 0.01 + structureType: 1 diff --git a/Assets/Config/TerrainLayers/StructureTreeLayer.asset.meta b/Assets/Config/TerrainLayers/StructureTreeLayer.asset.meta new file mode 100644 index 00000000..19424513 --- /dev/null +++ b/Assets/Config/TerrainLayers/StructureTreeLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 73e6007e32e2599449c029eab6a24533 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/SurfaceGrassLayer.asset b/Assets/Config/TerrainLayers/SurfaceGrassLayer.asset new file mode 100644 index 00000000..cd9c9291 --- /dev/null +++ b/Assets/Config/TerrainLayers/SurfaceGrassLayer.asset @@ -0,0 +1,24 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8dc7565f1544ab096b804d358a1a4e4, type: 3} + m_Name: SurfaceGrassLayer + m_EditorClassIdentifier: + layerType: 3 + layerName: Surface grass layer + index: 1000 + blockType: 5 + frequency: 0 + exponent: 0 + minHeight: 0 + maxHeight: 0 + chance: 0 + structureType: 0 diff --git a/Assets/Config/TerrainLayers/SurfaceGrassLayer.asset.meta b/Assets/Config/TerrainLayers/SurfaceGrassLayer.asset.meta new file mode 100644 index 00000000..eb6a2cb9 --- /dev/null +++ b/Assets/Config/TerrainLayers/SurfaceGrassLayer.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 04e8d21d759b887479e8717cf913597d +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Config/TerrainLayers/TerrainLayerCollection.asset b/Assets/Config/TerrainLayers/TerrainLayerCollection.asset new file mode 100644 index 00000000..0e5b0290 --- /dev/null +++ b/Assets/Config/TerrainLayers/TerrainLayerCollection.asset @@ -0,0 +1,22 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ac255652e50945d8a4e0ec00804a4230, type: 3} + m_Name: TerrainLayerCollection + m_EditorClassIdentifier: + layers: + - {fileID: 11400000, guid: b294ba7c0c4a08144916c18d0f467747, type: 2} + - {fileID: 11400000, guid: 0bc928c0fbae2694a9c4c010f4687eb4, type: 2} + - {fileID: 11400000, guid: a5626c3ee64bec348a6e50deb3b467d1, type: 2} + - {fileID: 11400000, guid: a7f2d008399aab1458b1b760cf85ff0a, type: 2} + - {fileID: 11400000, guid: 5a676bee5116cc047acabfa4f7d19241, type: 2} + - {fileID: 11400000, guid: 04e8d21d759b887479e8717cf913597d, type: 2} + - {fileID: 11400000, guid: 73e6007e32e2599449c029eab6a24533, type: 2} diff --git a/Assets/Config/TerrainLayers/TerrainLayerCollection.asset.meta b/Assets/Config/TerrainLayers/TerrainLayerCollection.asset.meta new file mode 100644 index 00000000..68b34fba --- /dev/null +++ b/Assets/Config/TerrainLayers/TerrainLayerCollection.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bf78fd0d717835f4ebfb0ab97738fcc3 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Materials/Shaders/VoxelShader.shader b/Assets/Materials/Shaders/VoxelShader.shader index ede7d2ab..a06635be 100644 --- a/Assets/Materials/Shaders/VoxelShader.shader +++ b/Assets/Materials/Shaders/VoxelShader.shader @@ -94,7 +94,7 @@ Shader "Custom/VoxelShader" #define BUMP_SCALE_NOT_SUPPORTED 1 UNITY_DECLARE_TEX2DARRAY(_ColourTextures); - uniform float _uvSizes[2 * 5]; // Needs to be set from C# + uniform float _uvSizes[2 * 6]; // Needs to be set from C# #include "Assets/Materials/Shaders/VoxelShaderInput.hlsl" #include "Assets/Materials/Shaders/VoxelForwardPass.hlsl" ENDHLSL @@ -130,7 +130,7 @@ Shader "Custom/VoxelShader" #include UNITY_DECLARE_TEX2DARRAY(_ColourTextures); - uniform float _uvSizes[2 * 5]; // Needs to be set from C# + uniform float _uvSizes[2 * 6]; // Needs to be set from C# #include "Assets/Materials/Shaders/VoxelShaderInput.hlsl" // vertex shader inputs @@ -200,7 +200,7 @@ Shader "Custom/VoxelShader" #include UNITY_DECLARE_TEX2DARRAY(_ColourTextures); - uniform float _uvSizes[2 * 5]; // Needs to be set from C# + uniform float _uvSizes[2 * 6]; // Needs to be set from C# #include "Assets/Materials/Shaders/VoxelShaderInput.hlsl" // vertex shader inputs diff --git a/Assets/Materials/TerrainMaterial.mat b/Assets/Materials/TerrainMaterial.mat index 75a0fe7b..bfc0cfc8 100644 --- a/Assets/Materials/TerrainMaterial.mat +++ b/Assets/Materials/TerrainMaterial.mat @@ -32,7 +32,7 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _ColourTextures: - m_Texture: {fileID: 18700000, guid: 137571eea8ad30344b78e5a940d7e002, type: 3} + m_Texture: {fileID: 18700000, guid: 58639cefbc9f1ba4ba221f75bd9a0573, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _DetailAlbedoMap: diff --git a/Assets/Materials/Textures/BlockTextures.png b/Assets/Materials/Textures/BlockTextures.png deleted file mode 100644 index 85d3815203fe618fb8939cffbb1c4e99166d7075..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5616 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 E7q|IKFaQ7m literal 0 HcmV?d00001 diff --git a/Assets/Materials/Textures/BlockTextures.png.meta b/Assets/Materials/Textures/SpriteSheet.png.meta similarity index 97% rename from Assets/Materials/Textures/BlockTextures.png.meta rename to Assets/Materials/Textures/SpriteSheet.png.meta index ebc3366e..351860d1 100644 --- a/Assets/Materials/Textures/BlockTextures.png.meta +++ b/Assets/Materials/Textures/SpriteSheet.png.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 137571eea8ad30344b78e5a940d7e002 +guid: 58639cefbc9f1ba4ba221f75bd9a0573 TextureImporter: internalIDToNameTable: [] externalObjects: {} @@ -58,7 +58,7 @@ TextureImporter: textureShape: 4 singleChannelComponent: 0 flipbookRows: 1 - flipbookColumns: 5 + flipbookColumns: 6 maxTextureSizeSet: 0 compressionQualitySet: 0 textureFormatSet: 0 diff --git a/Assets/Prefabs/MultiplayPlayer.prefab b/Assets/Prefabs/MultiplayPlayer.prefab index 09e6fa4c..34bf1749 100644 --- a/Assets/Prefabs/MultiplayPlayer.prefab +++ b/Assets/Prefabs/MultiplayPlayer.prefab @@ -317,7 +317,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: playerInput: {fileID: -3399718007712543476} - Username: 0 + username: 0 inputMovement: {x: 0, y: 0} inputLook: {x: 0, y: 0} inputJump: 0 diff --git a/Assets/Prefabs/TerrainArea.prefab b/Assets/Prefabs/TerrainArea.prefab index a0169c1a..7bedb3c1 100644 --- a/Assets/Prefabs/TerrainArea.prefab +++ b/Assets/Prefabs/TerrainArea.prefab @@ -93,4 +93,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bfdaa6c06fe64fbda2b16e07a4ee0b25, type: 3} m_Name: m_EditorClassIdentifier: - ComponentOverrides: [] + ComponentOverrides: + - FullTypeName: Unity.Transforms.LocalTransform + EntityIndex: 0 + PrefabType: -1 + SendTypeOptimization: -1 + VariantHash: 18225908329647095764 diff --git a/Assets/SceneDependencyCache/cf5ffb81d8efbf85a123bb39070d0d89.sceneWithBuildSettings b/Assets/SceneDependencyCache/cf5ffb81d8efbf85a123bb39070d0d89.sceneWithBuildSettings index 16a38fcb6e555a0748282ea8ee7a3e29cd5aadea..b58d334ae60face87d777c7b236fd01e82a02e37 100644 GIT binary patch delta 13 UcmXpon4rNiKfN<*PTOq`03SvL4*&oF delta 13 OcmXpon4rPI00jUH#Q`Az diff --git a/Assets/Scenes/AuthoringScene/AuthoringScene.unity b/Assets/Scenes/AuthoringScene/AuthoringScene.unity index 4c4dfd19..418612af 100644 --- a/Assets/Scenes/AuthoringScene/AuthoringScene.unity +++ b/Assets/Scenes/AuthoringScene/AuthoringScene.unity @@ -180,18 +180,15 @@ MonoBehaviour: - 1 - 1 - 1 - seed: 44 - initialAreas: - x: 4 - y: 2 - z: 4 - playerViewRange: 2 + - 1 + - 1 + layerCollection: {fileID: 11400000, guid: bf78fd0d717835f4ebfb0ab97738fcc3, type: 2} + seed: 42 + initialColumnsX: 2 + initialColumnsZ: 2 + playerViewRange: 0 terrainSpawnRange: 2 - maxChunkSpawnsPerTick: 50 - blocksPerAreaSide: 16 - YBounds: - x: 0 - y: 8 + maxColumnSpawnsPerTick: 8 --- !u!114 &176225512 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 02a338db..79b433f4 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -898,7 +898,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8bf58c69bf424fe194d229f05ce07072, type: 3} m_Name: m_EditorClassIdentifier: - editorArgs: -streaming_type host -emulation disabled + editorArgs: -streaming_type host -emulation disabled -debug --- !u!1 &2101193216 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs new file mode 100644 index 00000000..7306be4e --- /dev/null +++ b/Assets/Scripts/Config.cs @@ -0,0 +1,40 @@ +using Unity.Mathematics; + +namespace Opencraft +{ + public static class Env + { + //! Size of chunk's side + public const int AREA_POW = 4; + + //! How many terrain areas from world bottom to world top + public const int AREA_COLUMN_HEIGHT = 8; + public const int HALF_AREA_COLUMN_HEIGHT = 4; + + #region DO NOT CHANGE THESE! + + + public const int AREA_POW_2 = AREA_POW << 1; + public const int AREA_MASK = (1 << AREA_POW_2) - 1; + + public const int AREA_PADDING = 1; + public const int AREA_PADDING_2 = AREA_PADDING * 2; + + //! Visible chunk size + public const int AREA_SIZE = 1 << AREA_POW; + public const int AREA_SIZE_1 = AREA_SIZE - 1; + public const int AREA_SIZE_POW_2 = AREA_SIZE * AREA_SIZE; + public const int AREA_SIZE_POW_3 = AREA_SIZE * AREA_SIZE_POW_2; + public const int AREA_SIZE_SHIFTED = (AREA_SIZE & 255) << 8; + + //! Internal chunk size (visible size + padding) + public const int AREA_SIZE_PLUS_PADDING = AREA_SIZE + AREA_PADDING; + public const int AREA_SIZE_WITH_PADDING = AREA_SIZE + AREA_PADDING * 2; + public const int AREA_SIZE_WITH_PADDING_POW_2 = AREA_SIZE_WITH_PADDING * AREA_SIZE_WITH_PADDING; + public const int AREA_SIZE_WITH_PADDING_POW_3 = AREA_SIZE_WITH_PADDING * AREA_SIZE_WITH_PADDING_POW_2; + + public const int WORLD_HEIGHT = AREA_COLUMN_HEIGHT * AREA_SIZE; + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Scripts/Config.cs.meta b/Assets/Scripts/Config.cs.meta new file mode 100644 index 00000000..b6648ad1 --- /dev/null +++ b/Assets/Scripts/Config.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 82517950861345159410bf381e483c98 +timeCreated: 1689689914 \ No newline at end of file diff --git a/Assets/Scripts/DrawIfAttribute.cs b/Assets/Scripts/DrawIfAttribute.cs new file mode 100644 index 00000000..6e491e52 --- /dev/null +++ b/Assets/Scripts/DrawIfAttribute.cs @@ -0,0 +1,40 @@ +using UnityEngine; +using System; + +/// +/// Draws the field/property ONLY if the compared property compared by the comparison type with the value of comparedValue returns true. +/// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/ +/// +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)] +public class DrawIfAttribute : PropertyAttribute +{ + #region Fields + + public string comparedPropertyName { get; private set; } + public object comparedValues { get; private set; } + public DisablingType disablingType { get; private set; } + + /// + /// Types of comperisons. + /// + public enum DisablingType + { + ReadOnly = 2, + DontDraw = 3 + } + + #endregion + + /// + /// Only draws the field only if a condition is met. Supports enum and bools. + /// + /// The name of the property that is being compared (case sensitive). + /// The set of values the property is being compared to. + /// The type of disabling that should happen if the condition is NOT met. Defaulted to DisablingType.DontDraw. + public DrawIfAttribute(string comparedPropertyName, object comparedValues, DisablingType disablingType = DisablingType.DontDraw) + { + this.comparedPropertyName = comparedPropertyName; + this.comparedValues = comparedValues; + this.disablingType = disablingType; + } +} \ No newline at end of file diff --git a/Assets/Scripts/DrawIfAttribute.cs.meta b/Assets/Scripts/DrawIfAttribute.cs.meta new file mode 100644 index 00000000..7973861f --- /dev/null +++ b/Assets/Scripts/DrawIfAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e6de541c93c743de933c5a162fcb066a +timeCreated: 1689595193 \ No newline at end of file diff --git a/Assets/Scripts/Editor.meta b/Assets/Scripts/Editor.meta new file mode 100644 index 00000000..1f29ee50 --- /dev/null +++ b/Assets/Scripts/Editor.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6086a0bd3f414d5aa1d959ca2ff62068 +timeCreated: 1689595135 \ No newline at end of file diff --git a/Assets/Scripts/Editor/DrawIfProperty.cs b/Assets/Scripts/Editor/DrawIfProperty.cs new file mode 100644 index 00000000..070835b0 --- /dev/null +++ b/Assets/Scripts/Editor/DrawIfProperty.cs @@ -0,0 +1,97 @@ +using System.Collections; +using System.Linq; +using UnityEditor; +using UnityEngine; + +/// +/// Editor utility to show/hide attributes based on a condition +/// Based on: https://forum.unity.com/threads/draw-a-field-only-if-a-condition-is-met.448855/ +/// +[CustomPropertyDrawer(typeof(DrawIfAttribute))] +public class DrawIfPropertyDrawer : PropertyDrawer +{ + #region Fields + + // Reference to the attribute on the property. + DrawIfAttribute drawIf; + + // Field that is being compared. + SerializedProperty comparedField; + + #endregion + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + if (!ShowMe(property) && drawIf.disablingType == DrawIfAttribute.DisablingType.DontDraw) + return 0f; + + // The height of the property should be defaulted to the default height. + return base.GetPropertyHeight(property, label); + } + + /// + /// Errors default to showing the property. + /// + private bool ShowMe(SerializedProperty property) + { + drawIf = attribute as DrawIfAttribute; + // Replace propertyname to the value from the parameter + string path = property.propertyPath.Contains(".") ? System.IO.Path.ChangeExtension(property.propertyPath, drawIf.comparedPropertyName) : drawIf.comparedPropertyName; + + comparedField = property.serializedObject.FindProperty(path); + + if (comparedField == null) + { + Debug.LogError("Cannot find property with name: " + path); + return true; + } + + // get the value & compare based on types + switch (comparedField.type) + { // Possible extend cases to support your own type + case "bool": + if(drawIf.comparedValues is IEnumerable boolValues) + { + foreach(var val in boolValues) + { + if (comparedField.boolValue.Equals(val)) + return true; + } + + return false; + } + return comparedField.boolValue.Equals(drawIf.comparedValues); + case "Enum": + if(drawIf.comparedValues is IEnumerable enumValues) + { + foreach(var val in enumValues) + { + if (comparedField.intValue == (int)val) + return true; + } + + return false; + } + return comparedField.intValue == (int)drawIf.comparedValues; + default: + Debug.LogError("Error: " + comparedField.type + " is not supported of " + path); + return true; + } + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + // If the condition is met, simply draw the field. + if (ShowMe(property)) + { + EditorGUI.PropertyField(position, property); + } //...check if the disabling type is read only. If it is, draw it disabled + else if (drawIf.disablingType == DrawIfAttribute.DisablingType.ReadOnly) + { + GUI.enabled = false; + EditorGUI.PropertyField(position, property); + GUI.enabled = true; + } + } + +} \ No newline at end of file diff --git a/Assets/Scripts/Editor/DrawIfProperty.cs.meta b/Assets/Scripts/Editor/DrawIfProperty.cs.meta new file mode 100644 index 00000000..1856e6d9 --- /dev/null +++ b/Assets/Scripts/Editor/DrawIfProperty.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f5a28c99fdf14c51beb6e9925bcd10a8 +timeCreated: 1689595159 \ No newline at end of file diff --git a/Assets/Scripts/Player/Authoring/PlayerAuthoring.cs b/Assets/Scripts/Player/Authoring/PlayerAuthoring.cs index 4cb762ac..61ffeb48 100644 --- a/Assets/Scripts/Player/Authoring/PlayerAuthoring.cs +++ b/Assets/Scripts/Player/Authoring/PlayerAuthoring.cs @@ -15,6 +15,8 @@ public struct Player : IComponentData { // Link to an associated configuration entity public Entity PlayerConfig; + // Link to containing area + public Entity ContainingArea; // Movement variables [GhostField(Quantization = 1000)] public float3 Velocity; [GhostField] public byte OnGround; diff --git a/Assets/Scripts/Player/Multiplay/Multiplay.cs b/Assets/Scripts/Player/Multiplay/Multiplay.cs index 3633ac2c..76c1ebff 100644 --- a/Assets/Scripts/Player/Multiplay/Multiplay.cs +++ b/Assets/Scripts/Player/Multiplay/Multiplay.cs @@ -28,7 +28,7 @@ public class Multiplay : SignalingHandlerBase, private MultiplaySettings settings; - private Vector3 initialPosition = new Vector3(0, 3, -4); + private Vector3 initialPosition = new Vector3(0, 40, -4); void Awake() { diff --git a/Assets/Scripts/Player/PlayerActionSystem.cs b/Assets/Scripts/Player/PlayerActionSystem.cs index c2b7df04..0edc6c9a 100644 --- a/Assets/Scripts/Player/PlayerActionSystem.cs +++ b/Assets/Scripts/Player/PlayerActionSystem.cs @@ -63,12 +63,11 @@ public void OnUpdate(ref SystemState state) var colMaxes = _terrainColumnMaxBufferLookup[terrainAreaEntity].Reinterpret(); int minY = colMins[colIndex]; int maxY = colMaxes[colIndex]; - int bps = Constants.BlocksPerSide.Data; // If removed block is top or bottom of a column, search for new top or bottom and update heightmaps if (blockLoc.y == minY) { // Search upwards for new min y - for (int y = 1; y < bps - blockLoc.y; y++) + for (int y = 1; y < Env.AREA_SIZE - blockLoc.y; y++) { if (blocks[blockIndex + y] != BlockType.Air) { @@ -77,10 +76,10 @@ public void OnUpdate(ref SystemState state) break; } - if (y == (bps - blockLoc.y) - 1) + if (y == (Env.AREA_SIZE - blockLoc.y) - 1) { // no non-empty blocks found, set min to a max value - colMins[colIndex] = (byte)bps; + colMins[colIndex] = (byte)Env.AREA_SIZE; } } } diff --git a/Assets/Scripts/Player/PlayerManagerSystem.cs b/Assets/Scripts/Player/PlayerManagerSystem.cs index 2491f1b6..3dbf63f6 100644 --- a/Assets/Scripts/Player/PlayerManagerSystem.cs +++ b/Assets/Scripts/Player/PlayerManagerSystem.cs @@ -61,7 +61,7 @@ protected override void OnUpdate() networkId.Value * math.@select(halfCharacterWidthPlusHalfPadding, -halfCharacterWidthPlusHalfPadding, isEven) + math.@select(-spawnStaggeredOffset, spawnStaggeredOffset, isEven); - var preventZFighting = 2.5f + -0.01f * networkId.Value; + var preventZFighting = 30f + -0.01f * networkId.Value; commandBuffer.SetComponent(player, LocalTransform.FromPosition(new float3(staggeredXPos, preventZFighting, -1))); diff --git a/Assets/Scripts/Player/PlayerMovementSystem.cs b/Assets/Scripts/Player/PlayerMovementSystem.cs index 6c7e4984..6d8d96a5 100644 --- a/Assets/Scripts/Player/PlayerMovementSystem.cs +++ b/Assets/Scripts/Player/PlayerMovementSystem.cs @@ -39,7 +39,6 @@ partial struct PlayerMovementSystem : ISystem private BufferLookup _terrainBlockLookup; private NativeArray terrainAreasEntities; private NativeArray terrainAreaTransforms; - private int blocksPerChunkSide; public void OnCreate(ref SystemState state) { @@ -69,7 +68,6 @@ public void OnUpdate(ref SystemState state) var terrainAreasQuery = SystemAPI.QueryBuilder().WithAll().Build(); terrainAreasEntities = terrainAreasQuery.ToEntityArray(state.WorldUpdateAllocator); terrainAreaTransforms = terrainAreasQuery.ToComponentDataArray(state.WorldUpdateAllocator); - blocksPerChunkSide = SystemAPI.GetSingleton().blocksPerSide; foreach (var player in SystemAPI.Query().WithAll()) { @@ -202,7 +200,7 @@ private PlayerUtilities.PlayerSupportState CheckPlayerSupported(RigidTransform t transform.pos.x - offset, transform.pos.y - 1.1f, transform.pos.z + offset)); - + foreach (var pos in set) { if (TerrainUtilities.GetBlockAtPosition(pos, @@ -213,6 +211,9 @@ private PlayerUtilities.PlayerSupportState CheckPlayerSupported(RigidTransform t { return PlayerUtilities.PlayerSupportState.Supported; } + + + } return PlayerUtilities.PlayerSupportState.Unsupported; diff --git a/Assets/Scripts/Rendering/DebugRenderSystem.cs b/Assets/Scripts/Rendering/DebugRenderSystem.cs index 758bd816..ef873203 100644 --- a/Assets/Scripts/Rendering/DebugRenderSystem.cs +++ b/Assets/Scripts/Rendering/DebugRenderSystem.cs @@ -20,9 +20,7 @@ public partial struct DebugRenderSystem : ISystem //[BurstCompile] public void OnCreate(ref SystemState state) { - state.RequireForUpdate(); state.RequireForUpdate(); - _terrainSpawnerQuery = state.GetEntityQuery(ComponentType.ReadOnly()); if (!CmdArgs.DebugEnabled) { state.Enabled = false; @@ -32,16 +30,13 @@ public void OnCreate(ref SystemState state) [BurstCompile] public void OnUpdate(ref SystemState state) { - TerrainSpawner terrainSpawner = _terrainSpawnerQuery.GetSingleton(); - - new DebugDrawTerrain { blocksPerSide = terrainSpawner.blocksPerSide }.ScheduleParallel(); + new DebugDrawTerrain().ScheduleParallel(); } } [BurstCompile] public partial struct DebugDrawTerrain : IJobEntity { - public int blocksPerSide; public void Execute(in TerrainArea terrainChunk, in LocalTransform t) { diff --git a/Assets/Scripts/Rendering/TerrainMeshingSystem.cs b/Assets/Scripts/Rendering/TerrainMeshingSystem.cs index 51f82629..46c587ec 100644 --- a/Assets/Scripts/Rendering/TerrainMeshingSystem.cs +++ b/Assets/Scripts/Rendering/TerrainMeshingSystem.cs @@ -74,12 +74,6 @@ protected override void OnUpdate() MeshTerrainChunkJob meshJob = new MeshTerrainChunkJob { vertexLayout = _vertexLayout, - blocksPerSide = terrainSpawner.blocksPerSide, - blocksPerSideSquared = terrainSpawner.blocksPerSide * terrainSpawner.blocksPerSide, - blocksPerSideCubed = terrainSpawner.blocksPerSide * terrainSpawner.blocksPerSide * - terrainSpawner.blocksPerSide, - blocksPerSideMinusOne = terrainSpawner.blocksPerSide - 1, - blocksPerSideShifted = (terrainSpawner.blocksPerSide& 255) << 8, meshDataArray = meshDataArray, areasToUpdate = chunksToUpdate, terrainAreas = terrainAreas, @@ -122,11 +116,6 @@ protected override void OnUpdate() public partial struct MeshTerrainChunkJob : IJobParallelFor { [ReadOnly] public NativeArray vertexLayout; - public int blocksPerSide; - public int blocksPerSideSquared; - public int blocksPerSideCubed; - public int blocksPerSideMinusOne; - public int blocksPerSideShifted; public Mesh.MeshDataArray meshDataArray; [ReadOnly] public NativeArray areasToUpdate; [ReadOnly] public NativeArray terrainAreas; @@ -141,7 +130,7 @@ public void Execute(int index) TerrainNeighbors terrainNeighbor = terrainNeighbors[index]; TerrainArea terrainArea = terrainAreas[index]; // When area is remeshed, outline it in red - float3 terrainAreaLocation = terrainArea.location * blocksPerSide; + float3 terrainAreaLocation = terrainArea.location * Env.AREA_SIZE; TerrainUtilities.DebugDrawTerrainArea(ref terrainAreaLocation, Color.red, 0.5f); // Mesh object vertex data @@ -174,12 +163,12 @@ public void Execute(int index) neighborZN = terrainBufferLookup[terrainNeighbor.neighborZN]; // Bitmasks that mark a terrain block as visited - NativeArray visitedXN = new NativeArray(blocksPerSideCubed, Allocator.Temp); - NativeArray visitedXP = new NativeArray(blocksPerSideCubed, Allocator.Temp); - NativeArray visitedZN = new NativeArray(blocksPerSideCubed, Allocator.Temp); - NativeArray visitedZP = new NativeArray(blocksPerSideCubed, Allocator.Temp); - NativeArray visitedYN = new NativeArray(blocksPerSideCubed, Allocator.Temp); - NativeArray visitedYP = new NativeArray(blocksPerSideCubed, Allocator.Temp); + NativeArray visitedXN = new NativeArray(Env.AREA_SIZE_POW_3, Allocator.Temp); + NativeArray visitedXP = new NativeArray(Env.AREA_SIZE_POW_3, Allocator.Temp); + NativeArray visitedZN = new NativeArray(Env.AREA_SIZE_POW_3, Allocator.Temp); + NativeArray visitedZP = new NativeArray(Env.AREA_SIZE_POW_3, Allocator.Temp); + NativeArray visitedYN = new NativeArray(Env.AREA_SIZE_POW_3, Allocator.Temp); + NativeArray visitedYP = new NativeArray(Env.AREA_SIZE_POW_3, Allocator.Temp); // Setup mesh data arrays int currentVertexBufferSize = 6144; @@ -190,7 +179,7 @@ public void Execute(int index) NativeArray indices = meshData.GetIndexData(); // Precalculate the map-relative Y position of the chunk in the map - int chunkY = (int)terrainAreaLocation.y * blocksPerSide; + int chunkY = (int)terrainAreaLocation.y * Env.AREA_SIZE; // Allocate variables on the stack // iBPS is i * bps, kBPS2 is k*bps*bps. S means shifted, x1 means x + 1 int access, heightMapAccess, iBPS, kBPS2, i1, k1, j, j1, jS, jS1, topJ, @@ -200,37 +189,39 @@ public void Execute(int index) int numFaces = 0; // Z axis - for (int k = 0; k < blocksPerSide; k++, k1++) + for (int k = 0; k < Env.AREA_SIZE; k++, k1++) { - kBPS2 = k * blocksPerSideSquared; + kBPS2 = k * Env.AREA_SIZE_POW_2; i1 = 1; - heightMapAccess = k * blocksPerSide; + heightMapAccess = k * Env.AREA_SIZE; // Is the current run on the Z- or Z+ edge of the chunk minZ = k == 0; - maxZ = k == blocksPerSideMinusOne; + maxZ = k == Env.AREA_SIZE_1; // X axis - for (int i = 0; i < blocksPerSide; i++, i1++) + for (int i = 0; i < Env.AREA_SIZE; i++, i1++) { j = colMin[heightMapAccess]; topJ = colMax[heightMapAccess]; heightMapAccess++; // Calculate this once, rather than multiple times in the inner loop - iBPS = i * blocksPerSide; + iBPS = i * Env.AREA_SIZE; // Calculate access here and increment it each time in the innermost loop access = kBPS2 + iBPS + j; minX = i == 0; - maxX = i == blocksPerSideMinusOne; + maxX = i == Env.AREA_SIZE_1; // Y axis for (; j < topJ; j++, access++) { + if(access >= Env.AREA_SIZE_POW_3) + Debug.Log($"Access {access} OOB for {i} {j} {k} with col max height {topJ}"); BlockType b = blocks[access].type; if (b == BlockType.Air) continue; // Calculate length of run and make quads accordingly minY = j == 0; - maxY = j== blocksPerSideMinusOne; + maxY = j== Env.AREA_SIZE_1; kS = (k&255) << 16; // pre bit shift for packing in AppendQuad functions kS1 = (k1&255) << 16; y = j + chunkY; @@ -245,7 +236,7 @@ public void Execute(int index) visitedXN[access] = true; chunkAccess = accessIncremented; - for (length = jS1; length < blocksPerSideShifted; length += (1 << 8)) + for (length = jS1; length < Env.AREA_SIZE_SHIFTED; length += (1 << 8)) { if (blocks[chunkAccess].type != b) break; @@ -263,7 +254,7 @@ public void Execute(int index) chunkAccess = accessIncremented; - for (length = jS1; length < blocksPerSideShifted; length += (1 << 8)) + for (length = jS1; length < Env.AREA_SIZE_SHIFTED; length += (1 << 8)) { if (blocks[chunkAccess].type != b) break; @@ -280,7 +271,7 @@ public void Execute(int index) chunkAccess = accessIncremented; - for (length = jS1; length < blocksPerSideShifted; length += (1 << 8)) + for (length = jS1; length < Env.AREA_SIZE_SHIFTED; length += (1 << 8)) { if (blocks[chunkAccess].type != b) break; @@ -298,7 +289,7 @@ public void Execute(int index) chunkAccess = accessIncremented; - for (length = jS1; length < blocksPerSideShifted; length += (1 << 8)) + for (length = jS1; length < Env.AREA_SIZE_SHIFTED; length += (1 << 8)) { if (blocks[chunkAccess].type != b) break; @@ -313,16 +304,16 @@ public void Execute(int index) { visitedYN[access] = true; - chunkAccess = access + blocksPerSide; + chunkAccess = access + Env.AREA_SIZE; - for (length = i1; length < blocksPerSide; length++) + for (length = i1; length < Env.AREA_SIZE; length++) { if (blocks[chunkAccess].type != b) break; visitedYN[chunkAccess] = true; - chunkAccess += blocksPerSide; + chunkAccess += Env.AREA_SIZE; } AppendQuadY(ref vertexBuffer, ref indices, ref numFaces, i, length, jS, kS1, kS, (int)FaceDirectionShifted.yn, texture); } @@ -332,16 +323,16 @@ public void Execute(int index) { visitedYP[access] = true; - chunkAccess = access + blocksPerSide; + chunkAccess = access + Env.AREA_SIZE; - for (length = i1; length < blocksPerSide; length++) + for (length = i1; length < Env.AREA_SIZE; length++) { if (blocks[chunkAccess].type != b) break; visitedYP[chunkAccess] = true; - chunkAccess += blocksPerSide; + chunkAccess += Env.AREA_SIZE; } AppendQuadY(ref vertexBuffer, ref indices, ref numFaces, i, length, jS1, kS, kS1, (int)FaceDirectionShifted.yp, texture); } diff --git a/Assets/Scripts/Rendering/TerrainRenderInitSystem.cs b/Assets/Scripts/Rendering/TerrainRenderInitSystem.cs index bf946a08..73c3097b 100644 --- a/Assets/Scripts/Rendering/TerrainRenderInitSystem.cs +++ b/Assets/Scripts/Rendering/TerrainRenderInitSystem.cs @@ -15,16 +15,15 @@ namespace Opencraft.Rendering [UpdateAfter(typeof(TerrainNeighborSystem))] public partial class TerrainRenderInitSystem : SystemBase { - private EntityQuery _terrainSpawnerQuery; + private EntityQuery _materialQuery; private EntityQuery _newSpawnQuery; protected override void OnCreate() { - RequireForUpdate(); RequireForUpdate(); + RequireForUpdate(); RequireForUpdate(); - _terrainSpawnerQuery = GetEntityQuery(ComponentType.ReadOnly(), - ComponentType.ReadOnly()); + _materialQuery = GetEntityQuery(ComponentType.ReadOnly()); _newSpawnQuery = GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly()); } @@ -32,11 +31,10 @@ protected override void OnUpdate() { if (_newSpawnQuery.IsEmpty) return; - var terrainSpawner = _terrainSpawnerQuery.GetSingleton(); // On each new terrain area, add a new Mesh managed object EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp); - float3 boundsExtents = new float3(0.5 * terrainSpawner.blocksPerSide); - MaterialBank materialBank = _terrainSpawnerQuery.GetSingleton(); + float3 boundsExtents = new float3(0.5 * Env.AREA_SIZE); + MaterialBank materialBank = _materialQuery.GetSingleton(); foreach (var (terrainArea, terrainNeighbors, entity) in SystemAPI.Query,RefRO>().WithAll() .WithEntityAccess()) { diff --git a/Assets/Scripts/Terrain/Authoring/TerrainAreaAuthoring.cs b/Assets/Scripts/Terrain/Authoring/TerrainAreaAuthoring.cs index 2085fa5a..4160810d 100644 --- a/Assets/Scripts/Terrain/Authoring/TerrainAreaAuthoring.cs +++ b/Assets/Scripts/Terrain/Authoring/TerrainAreaAuthoring.cs @@ -1,4 +1,5 @@ using Opencraft.Terrain.Blocks; +using Opencraft.Terrain.Structures; using Unity.Entities; using Unity.Mathematics; using Unity.NetCode; @@ -12,7 +13,7 @@ public class TerrainBlockBaker : Baker { public override void Bake(TerrainAreaAuthoring authoring) { - var entity = GetEntity(TransformUsageFlags.Renderable); + var entity = GetEntity(TransformUsageFlags.Dynamic); // Initialize with no neighbors var terrainNeighbors = new TerrainNeighbors() { @@ -27,9 +28,14 @@ public override void Bake(TerrainAreaAuthoring authoring) AddComponent(entity); AddComponent(entity); AddComponent(entity); + + AddComponent(entity); + SetComponentEnabled(entity, false); + AddBuffer(entity); AddBuffer(entity); AddBuffer(entity); + AddBuffer(entity); } } @@ -62,6 +68,12 @@ public struct NewSpawn : IComponentData, IEnableableComponent public struct Remesh : IComponentData, IEnableableComponent { } + + // Remesh component marks an entity as having structures to be generated + public struct GenStructures : IComponentData, IEnableableComponent + { + } + [InternalBufferCapacity(4096)] // The buffer component to store terrain blocks @@ -84,6 +96,15 @@ public struct TerrainColMaxY : IBufferElementData [GhostField] public byte maxY; } + [InternalBufferCapacity(32)] + // Buffer of terrain area columns we need to spawn but haven't yet + public struct TerrainStructuresToSpawn : IBufferElementData + { + public int3 localPos; + public StructureType structureType; + public int3 extents; + } + } diff --git a/Assets/Scripts/Terrain/Authoring/TerrainSpawnerAuthoring.cs b/Assets/Scripts/Terrain/Authoring/TerrainSpawnerAuthoring.cs index 00d7306e..7ec4a0ff 100644 --- a/Assets/Scripts/Terrain/Authoring/TerrainSpawnerAuthoring.cs +++ b/Assets/Scripts/Terrain/Authoring/TerrainSpawnerAuthoring.cs @@ -1,3 +1,6 @@ +using Opencraft.Terrain.Blocks; +using Opencraft.Terrain.Layers; +using Opencraft.Terrain.Structures; using Opencraft.Terrain.Utilities; using Unity.Entities; using Unity.Mathematics; @@ -7,20 +10,22 @@ namespace Opencraft.Terrain.Authoring { [InternalBufferCapacity(64)] - // Buffer of terrain areas we need to spawn but haven't yet - public struct TerrainAreasToSpawn : IBufferElementData, ISingleton + // Buffer of terrain area columns we need to spawn but haven't yet + public struct TerrainColumnsToSpawn : IBufferElementData, ISingleton { - public int3 Value; + public int2 ColumnPos; } + + + // Singleton holding the TerrainArea prefab entity we instantiate, and some world settings public struct TerrainSpawner : IComponentData, ISingleton { public Entity TerrainArea; public int seed; - public int blocksPerSide; - public int maxChunkSpawnsPerTick; - public int2 YBounds; + public int maxColumnSpawnsPerTick; + public int2 worldLimitsHeight; public int playerViewRange; public int terrainSpawnRange; } @@ -30,6 +35,21 @@ public class MaterialBank : IComponentData, ISingleton { public Material TerrainMaterial; } + + public struct TerrainGenerationLayer : IComponentData + { + public LayerType layerType; + public int index; + public BlockType blockType; + public StructureType structureType; + public float frequency; + public float exponent; + //public int baseHeight; + public int minHeight; + public int maxHeight; + public int amplitude; + public float chance; + } [DisallowMultipleComponent] public class TerrainSpawnerAuthoring : MonoBehaviour @@ -37,15 +57,13 @@ public class TerrainSpawnerAuthoring : MonoBehaviour public GameObject TerrainArea; public Material TerrainMaterial; public float[] TerrainMaterialUVSizing= new float[] { 1.0f,1.0f, 1.0f,1.0f, 1.0f,1.0f, 1.0f,1.0f,1.0f,1.0f}; + public LayerCollection layerCollection = null; public int seed = 42; - public int3 initialAreas = new int3(3, 3, 3); + public int initialColumnsX = 3; + public int initialColumnsZ = 3; public int playerViewRange = 5; public int terrainSpawnRange = 5; - public int maxChunkSpawnsPerTick = 25; - public int blocksPerAreaSide = 4; - - [Tooltip("x is sea level, y is sky level")] - public int2 YBounds; + public int maxColumnSpawnsPerTick = 10; class Baker : Baker { @@ -56,9 +74,7 @@ public override void Bake(TerrainSpawnerAuthoring authoring) TerrainSpawner terrainSpawner = new TerrainSpawner { TerrainArea = GetEntity(authoring.TerrainArea, TransformUsageFlags.Dynamic), - blocksPerSide = authoring.blocksPerAreaSide, - YBounds = authoring.YBounds, - maxChunkSpawnsPerTick = authoring.maxChunkSpawnsPerTick, + maxColumnSpawnsPerTick = authoring.maxColumnSpawnsPerTick, seed = CmdArgs.seed != -1 ? CmdArgs.seed : authoring.seed, playerViewRange = authoring.playerViewRange, terrainSpawnRange = authoring.terrainSpawnRange @@ -67,25 +83,39 @@ public override void Bake(TerrainSpawnerAuthoring authoring) MaterialBank materialBank = new MaterialBank() { TerrainMaterial = authoring.TerrainMaterial }; // Add to the TerrainSpawner entity a buffer of terrain areas to spawn - var toSpawnBuffer = AddBuffer(entity); - DynamicBuffer intBuffer = toSpawnBuffer.Reinterpret(); - for (int x = -(int)math.floor(authoring.initialAreas.x / 2.0f); - x < math.ceil(authoring.initialAreas.x / 2.0f); + var columnsToSpawnBuffer = AddBuffer(entity); + DynamicBuffer intBuffer = columnsToSpawnBuffer.Reinterpret(); + for (int x = -(int)math.floor(authoring.initialColumnsX / 2.0f); + x < math.ceil(authoring.initialColumnsX / 2.0f); x++) - for (int y = -(int)math.floor(authoring.initialAreas.y / 2.0f); - y < math.ceil(authoring.initialAreas.y / 2.0f); - y++) - for (int z = -(int)math.floor(authoring.initialAreas.z / 2.0f); - z < math.ceil(authoring.initialAreas.z / 2.0f); - z++) - intBuffer.Add(new int3(x, y, z)); + for (int z = -(int)math.floor(authoring.initialColumnsZ / 2.0f); + z < math.ceil(authoring.initialColumnsZ / 2.0f); + z++) + intBuffer.Add(new int2(x, z)); AddComponent(entity, terrainSpawner); AddComponentObject(entity, materialBank); - int bps = authoring.blocksPerAreaSide; - Constants.BlocksPerSide.Data = bps; - Constants.BlocksPerLayer.Data = bps*bps; - Constants.BlocksPerArea.Data = bps*bps*bps; + + authoring.layerCollection.SortLayers(); + foreach(var layer in authoring.layerCollection.Layers) + { + Entity layerEntity = CreateAdditionalEntity(TransformUsageFlags.None, entityName:layer.LayerName); + AddComponent(layerEntity, new TerrainGenerationLayer + { + layerType=layer.LayerType, + index=layer.Index, + blockType=layer.BlockType, + structureType = layer.StructureType, + frequency = layer.Frequency, + exponent =layer.Exponent, + //baseHeight = layer.BaseHeight, + minHeight = layer.MinHeight, + maxHeight= layer.MaxHeight, + amplitude = layer.MaxHeight - layer.MinHeight, + chance = layer.Chance + }); + } + } } } diff --git a/Assets/Scripts/Terrain/Blocks/BlockType.cs b/Assets/Scripts/Terrain/Blocks/BlockType.cs index 279d4577..a7a63e02 100644 --- a/Assets/Scripts/Terrain/Blocks/BlockType.cs +++ b/Assets/Scripts/Terrain/Blocks/BlockType.cs @@ -7,7 +7,8 @@ public enum BlockType : byte Stone, Dirt, Tin, - Gem + Gem, + Grass } public static class BlockData { @@ -18,7 +19,8 @@ public static class BlockData (1 & 31) << 24, (2 & 31) << 24, (3 & 31) << 24, - (4 & 31) << 24 + (4 & 31) << 24, + (5 & 31) << 24 }; } diff --git a/Assets/Scripts/Terrain/Layers.meta b/Assets/Scripts/Terrain/Layers.meta new file mode 100644 index 00000000..3b3e9a21 --- /dev/null +++ b/Assets/Scripts/Terrain/Layers.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 630185c80e814021b17a24d60cd8d2c4 +timeCreated: 1689593638 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Layers/LayerCollection.cs b/Assets/Scripts/Terrain/Layers/LayerCollection.cs new file mode 100644 index 00000000..de58f586 --- /dev/null +++ b/Assets/Scripts/Terrain/Layers/LayerCollection.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using Unity.Mathematics; +using UnityEngine; + +namespace Opencraft.Terrain.Layers +{ + [CreateAssetMenu(fileName = "New Layer Collection", menuName = "OpenCraft/Layer Collection", order = -100)] + public class LayerCollection : ScriptableObject + { + [SerializeField] + private LayerConfig[] layers = null; + + public LayerConfig[] Layers { get { return layers; } } + + public void SortLayers() + { + Array.Sort(layers, new LayerConfigComparer()); + } + } + + // Comparer for sorting locations by distance from zero + struct LayerConfigComparer: IComparer + { + public int Compare(LayerConfig a, LayerConfig b) + { + if (a is null && b is not null) + return -1; + if (a is not null && b is null) + return 1; + if (a is null) + return 0; + if (a.Index > b.Index) + return 1; + if (a.Index < b.Index ) + return -1; + return 0; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Layers/LayerCollection.cs.meta b/Assets/Scripts/Terrain/Layers/LayerCollection.cs.meta new file mode 100644 index 00000000..0db5ae34 --- /dev/null +++ b/Assets/Scripts/Terrain/Layers/LayerCollection.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ac255652e50945d8a4e0ec00804a4230 +timeCreated: 1689594701 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Layers/LayerConfig.cs b/Assets/Scripts/Terrain/Layers/LayerConfig.cs new file mode 100644 index 00000000..dc47934e --- /dev/null +++ b/Assets/Scripts/Terrain/Layers/LayerConfig.cs @@ -0,0 +1,78 @@ +//using Opencraft.Editor; +using Opencraft.Terrain.Blocks; +using Opencraft.Terrain.Structures; +using UnityEngine; + +namespace Opencraft.Terrain.Layers +{ + [CreateAssetMenu(fileName = "New Layer", menuName = "OpenCraft/New Layer")] + public class LayerConfig : ScriptableObject + { + [SerializeField] + [Tooltip("What kind of terrain layer this object creates.")] + private LayerType layerType = LayerType.Absolute; + [SerializeField] + [Tooltip("The name of the created layer.")] + private string layerName = "New Layer"; + [SerializeField] + [Tooltip("Lower index layers are applied before higher indices.")] + private int index = 0; + [SerializeField] + [Tooltip("The block this layer will create.")] + [DrawIf("layerType", new[]{LayerType.Absolute, LayerType.Additive, LayerType.Random, LayerType.Surface})] + private BlockType blockType; + + [SerializeField] + [Tooltip("Noise parameter.")] + [DrawIf("layerType", new[]{LayerType.Absolute, LayerType.Additive})] + private float frequency = 0f; + [SerializeField] + [Tooltip("Noise parameter.")] + [DrawIf("layerType", new[]{LayerType.Absolute, LayerType.Additive})] + private float exponent = 0f; + + /*[SerializeField] + [Tooltip("Level to start randomly sampling at. (MinHeight to MinHeight+BaseHeight gets filled)")] + [DrawIf("layerType", new[]{LayerType.Absolute, LayerType.Additive})] + private int baseHeight = 0;*/ + [SerializeField] + [Tooltip("Lowest possible column floor.")] + [DrawIf("layerType", new[]{LayerType.Absolute, LayerType.Additive})] + private int minHeight = 0; + [SerializeField] + [Tooltip("Highest possible column ceiling.")] + [DrawIf("layerType", new[]{LayerType.Absolute, LayerType.Additive})] + private int maxHeight = 0; + + [SerializeField] + [Tooltip("Likelihood of spawning.")] + [DrawIf("layerType", new[]{LayerType.Structure, LayerType.Random})] + private float chance = 0; + [SerializeField] + [Tooltip("Structure to spawn.")] + [DrawIf("layerType", LayerType.Structure)] + private StructureType structureType = StructureType.None; + + + public LayerType LayerType => layerType; + public string LayerName => layerName; + public int Index => index; + public BlockType BlockType => blockType; + public float Frequency => frequency; + public float Exponent => exponent; + //public int BaseHeight => baseHeight; + public int MinHeight => minHeight; + public int MaxHeight => maxHeight; + public float Chance => chance; + public StructureType StructureType => structureType; + } + + public enum LayerType + { + Absolute, + Random, + Structure, + Surface, + Additive + } +} \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Layers/LayerConfig.cs.meta b/Assets/Scripts/Terrain/Layers/LayerConfig.cs.meta new file mode 100644 index 00000000..6901beb5 --- /dev/null +++ b/Assets/Scripts/Terrain/Layers/LayerConfig.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c8dc7565f1544ab096b804d358a1a4e4 +timeCreated: 1689593721 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Structures.meta b/Assets/Scripts/Terrain/Structures.meta new file mode 100644 index 00000000..87e6aab4 --- /dev/null +++ b/Assets/Scripts/Terrain/Structures.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dbad4c91d9a24dd886d69d2fad789c1c +timeCreated: 1689594458 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Structures/StructureTypes.cs b/Assets/Scripts/Terrain/Structures/StructureTypes.cs new file mode 100644 index 00000000..9eac8aca --- /dev/null +++ b/Assets/Scripts/Terrain/Structures/StructureTypes.cs @@ -0,0 +1,9 @@ +namespace Opencraft.Terrain.Structures +{ + public enum StructureType + { + None, + Tree + } + +} \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Structures/StructureTypes.cs.meta b/Assets/Scripts/Terrain/Structures/StructureTypes.cs.meta new file mode 100644 index 00000000..6b9025df --- /dev/null +++ b/Assets/Scripts/Terrain/Structures/StructureTypes.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 88fb4d57462c46d48fb342c980d22e93 +timeCreated: 1689594465 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/TerrainGenerationSystem.cs b/Assets/Scripts/Terrain/TerrainGenerationSystem.cs index b3645f43..6f614fb3 100644 --- a/Assets/Scripts/Terrain/TerrainGenerationSystem.cs +++ b/Assets/Scripts/Terrain/TerrainGenerationSystem.cs @@ -2,8 +2,10 @@ using Opencraft.Terrain; using Opencraft.Terrain.Authoring; using Opencraft.Terrain.Blocks; +using Opencraft.Terrain.Layers; using Opencraft.Terrain.Utilities; using Opencraft.ThirdParty; +using Packages.procgen.Runtime.Terrain.Approach2; using Unity.Entities; using Unity.Jobs; using Unity.Mathematics; @@ -11,13 +13,14 @@ using Unity.Transforms; using Unity.Burst; using Unity.Collections; +using Unity.Collections.LowLevel.Unsafe; using Unity.Physics; using Unity.Profiling; using Unity.Rendering; using UnityEngine; // Annoyingly this assembly directive must be outside the namespace. So we have to import Opencraft.Terrain namespace to itself... -[assembly: RegisterGenericJobType(typeof(SortJob))] +[assembly: RegisterGenericJobType(typeof(SortJob))] namespace Opencraft.Terrain { [WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)] @@ -28,21 +31,45 @@ namespace Opencraft.Terrain public partial struct TerrainGenerationSystem : ISystem { private EntityQuery _newSpawnQuery; - private ProfilerMarker markerTerrainGen; + private NativeArray _terrainGenLayers; + private ProfilerMarker _markerTerrainGen; + private ComponentLookup _terrainAreaLookup; + private ComponentLookup _localTransformLookup; + private BufferLookup _terrainBlocksLookup; + private BufferLookup _terrainColMinLookup; + private BufferLookup _terrainColMaxLookup; + private BufferLookup _structuresToSpawnLookup; //private double lastUpdate; public void OnCreate(ref SystemState state) { // Wait for scene load/baking to occur before updates. state.RequireForUpdate(); - state.RequireForUpdate(); - _newSpawnQuery = SystemAPI.QueryBuilder().WithAll().Build(); - markerTerrainGen = new ProfilerMarker("TerrainGeneration"); + state.RequireForUpdate(); + state.RequireForUpdate(); + _newSpawnQuery = SystemAPI.QueryBuilder().WithAll().Build(); + //_terrainGenLayers= SystemAPI.QueryBuilder().WithAll().Build().ToComponentDataArray(Allocator.Persistent); + _markerTerrainGen = new ProfilerMarker("TerrainGeneration"); //lastUpdate = -1.0; + _terrainAreaLookup = state.GetComponentLookup(isReadOnly: false); + _localTransformLookup = state.GetComponentLookup(isReadOnly: false); + _terrainBlocksLookup = state.GetBufferLookup(isReadOnly: false); + _terrainColMinLookup = state.GetBufferLookup(isReadOnly: false); + _terrainColMaxLookup = state.GetBufferLookup(isReadOnly: false); + _structuresToSpawnLookup = state.GetBufferLookup(isReadOnly: false); + } + + public void OnDestroy(ref SystemState state) + { + _terrainGenLayers.Dispose(); } public void OnUpdate(ref SystemState state) { + if (!_terrainGenLayers.IsCreated) + { + _terrainGenLayers= SystemAPI.QueryBuilder().WithAll().Build().ToComponentDataArray(Allocator.Persistent); + } /*if (state.World.Time.ElapsedTime - lastUpdate < 1.0) { return; @@ -57,52 +84,80 @@ public void OnUpdate(ref SystemState state) Entity terrainSpawnerEntity = SystemAPI.GetSingletonEntity(); // Fetch what chunks to spawn this tick - var toSpawnbuffer = SystemAPI.GetBuffer(terrainSpawnerEntity); - DynamicBuffer chunksToSpawnBuffer = toSpawnbuffer.Reinterpret(); + var toSpawnbuffer = SystemAPI.GetBuffer(terrainSpawnerEntity); + DynamicBuffer chunksColumnsSpawnBuffer = toSpawnbuffer.Reinterpret(); // If there is nothing to spawn, don't :) - if (chunksToSpawnBuffer.Length == 0) + if (chunksColumnsSpawnBuffer.Length == 0) { return; } - markerTerrainGen.Begin(); - NativeArray chunksToSpawn = chunksToSpawnBuffer.AsNativeArray(); - // Sort the chunks to spawn so ones closer to 0,0 are first - SortJob sortJob = chunksToSpawn.SortJob(new Int3DistanceComparer { }); + _markerTerrainGen.Begin(); + NativeArray columnsToSpawn = chunksColumnsSpawnBuffer.AsNativeArray(); + // Sort the columns to spawn so ones closer to 0,0 are first + SortJob sortJob = columnsToSpawn.SortJob(new Int2DistanceComparer { }); JobHandle sortHandle = sortJob.Schedule(); // Spawn the terrain area entities - state.EntityManager.Instantiate(terrainSpawner.TerrainArea, - chunksToSpawn.Length > terrainSpawner.maxChunkSpawnsPerTick - ? terrainSpawner.maxChunkSpawnsPerTick - : chunksToSpawn.Length, - Allocator.Temp); - // Then populate them on worker threads - JobHandle populateHandle = new PopulateTerrainAreas + int numColumnsToSpawn = columnsToSpawn.Length > terrainSpawner.maxColumnSpawnsPerTick + ? terrainSpawner.maxColumnSpawnsPerTick + : columnsToSpawn.Length; + NativeArray terrainAreaEntities = state.EntityManager.Instantiate(terrainSpawner.TerrainArea, + numColumnsToSpawn * Env.AREA_COLUMN_HEIGHT, + Allocator.TempJob); + //NativeArray terrainAreaEntities = _newSpawnQuery.ToEntityArray(Allocator.TempJob); + //NativeArray terrainAreas = _newSpawnQuery.ToComponentDataArray(Allocator.TempJob); + //NativeArray localTransforms = _newSpawnQuery.ToComponentDataArray(Allocator.TempJob); + //_terrainAreaLookup.Update(ref state); + //_localTransformLookup.Update(ref state); + _terrainBlocksLookup.Update(ref state); + _terrainColMinLookup.Update(ref state); + _terrainColMaxLookup.Update(ref state); + _structuresToSpawnLookup.Update(ref state); + EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob); + EntityCommandBuffer.ParallelWriter parallelEcb = ecb.AsParallelWriter(); + + // Populate new terrain areas on worker threads + JobHandle populateHandle = new PopulateTerrainColumns { - chunksToSpawn = chunksToSpawn, + terrainAreaEntities = terrainAreaEntities, + ecb = parallelEcb, + terrainSpawnerEntity = terrainSpawnerEntity, + //terrainAreaLookup = _terrainAreaLookup, + //localTransformLookup = _localTransformLookup, + //terrainAreas = terrainAreas, + //localTransforms = localTransforms, + terrainBlocksLookup = _terrainBlocksLookup, + terrainColMinLookup = _terrainColMinLookup, + terrainColMaxLookup = _terrainColMaxLookup, + _structuresToSpawnLookup = _structuresToSpawnLookup, + columnsToSpawn = columnsToSpawn, noiseSeed = terrainSpawner.seed, - blocksPerSide = terrainSpawner.blocksPerSide, - YBounds = terrainSpawner.YBounds, - }.ScheduleParallel(sortHandle); + terrainGenLayers = _terrainGenLayers + }.Schedule(numColumnsToSpawn, 1, sortHandle); // Each thread gets 1 column populateHandle.Complete(); + terrainAreaEntities.Dispose(); + //terrainAreas.Dispose(); + //localTransforms.Dispose(); // Remove spawned areas from the toSpawn buffer - if (chunksToSpawnBuffer.Length > terrainSpawner.maxChunkSpawnsPerTick) - chunksToSpawnBuffer.RemoveRange(0, terrainSpawner.maxChunkSpawnsPerTick); + if (chunksColumnsSpawnBuffer.Length > terrainSpawner.maxColumnSpawnsPerTick) + chunksColumnsSpawnBuffer.RemoveRange(0, terrainSpawner.maxColumnSpawnsPerTick); else - chunksToSpawnBuffer.Clear(); - markerTerrainGen.End(); + chunksColumnsSpawnBuffer.Clear(); + ecb.Playback(state.EntityManager); + ecb.Dispose(); + _markerTerrainGen.End(); } } // Comparer for sorting locations by distance from zero - public struct Int3DistanceComparer : IComparer + public struct Int2DistanceComparer : IComparer { - public int Compare(int3 a, int3 b) + public int Compare(int2 a, int2 b) { - int lSum = math.abs(a.x) + math.abs(a.y) + math.abs(a.z); - int rSum = math.abs(b.x) + math.abs(b.y) + math.abs(b.z); + int lSum = math.abs(a.x) + math.abs(a.y); + int rSum = math.abs(b.x) + math.abs(b.y); if (lSum > rSum) return 1; if (lSum < rSum) @@ -111,74 +166,303 @@ public int Compare(int3 a, int3 b) } } - [WithAll(typeof(NewSpawn))] [BurstCompile] - // Job that fills the terrain area block buffer - partial struct PopulateTerrainAreas : IJobEntity + partial struct PopulateTerrainColumns : IJobParallelFor { - public NativeArray chunksToSpawn; - public int blocksPerSide; + [ReadOnly] public NativeArray terrainAreaEntities; + [ReadOnly] public NativeArray columnsToSpawn; + public Entity terrainSpawnerEntity; + + public EntityCommandBuffer.ParallelWriter ecb; + //[NativeDisableParallelForRestriction] public ComponentLookup terrainAreaLookup; + //[NativeDisableParallelForRestriction] public ComponentLookup localTransformLookup; + //[NativeDisableParallelForRestriction] public NativeArray terrainAreas; + //[NativeDisableParallelForRestriction] public NativeArray localTransforms; + [NativeDisableParallelForRestriction] public BufferLookup terrainBlocksLookup; + [NativeDisableParallelForRestriction] public BufferLookup terrainColMinLookup; + [NativeDisableParallelForRestriction] public BufferLookup terrainColMaxLookup; + [NativeDisableParallelForRestriction] public BufferLookup _structuresToSpawnLookup; public int noiseSeed; - public int2 YBounds; // x is sea level, y is sky level + [ReadOnly] public NativeArray terrainGenLayers; - public void Execute([EntityIndexInQuery] int index, ref DynamicBuffer terrainBlocksBuffer, - ref DynamicBuffer colMinBuffer,ref DynamicBuffer colMaxBuffer, ref LocalTransform localTransform, ref TerrainArea terrainArea) + public void Execute(int jobIndex) { - int3 chunk = chunksToSpawn[index]; - terrainArea.location = chunk; // terrain area grid position - int areaX = chunk.x * blocksPerSide; - int areaY = chunk.y * blocksPerSide; - int areaZ = chunk.z * blocksPerSide; - localTransform.Position = new float3(areaX, areaY, areaZ); // world space position - - var perLayer = blocksPerSide * blocksPerSide; - var perArea = perLayer * blocksPerSide; - terrainBlocksBuffer.Resize(perArea, NativeArrayOptions.UninitializedMemory); - colMinBuffer.Resize(perLayer, NativeArrayOptions.UninitializedMemory); - colMaxBuffer.Resize(perLayer, NativeArrayOptions.UninitializedMemory); - DynamicBuffer terrainBlocks = terrainBlocksBuffer.Reinterpret(); - DynamicBuffer colMin = colMinBuffer.Reinterpret(); - DynamicBuffer colMax = colMaxBuffer.Reinterpret(); - int globalX, globalY, globalZ, block, column; - float noise, cutoff; - for (int z = 0; z < blocksPerSide; z++) + int index = jobIndex * Env.AREA_COLUMN_HEIGHT; + int2 columnToSpawn = columnsToSpawn[jobIndex]; + int columnX = columnToSpawn.x * Env.AREA_SIZE; + int columnZ = columnToSpawn.y * Env.AREA_SIZE; + + // Preprocess terrain generation layers to create noise lookup tables + NativeArray> terrainLayerLookupTables = + new NativeArray>(terrainGenLayers.Length, Allocator.Temp); + NativeArray terrainLayerInterpolateSettings = + new NativeArray(terrainGenLayers.Length, Allocator.Temp); + for (int i = 0; i < terrainGenLayers.Length; i++) { - globalZ = areaZ + z; - for (int x = 0; x < blocksPerSide; x++) + TerrainGenerationLayer terrainGenLayer = terrainGenLayers[i]; + switch (terrainGenLayer.layerType) { - globalX = areaX + x; - int minY = blocksPerSide; - int maxY = 0; - column = x + z * blocksPerSide; - for (int y = 0; y < blocksPerSide; y++) - { - globalY = areaY + y; - noise = FastPerlin.PerlinGetNoise(globalX, globalZ, noiseSeed); - cutoff = YBounds.x + noise * (YBounds.y - YBounds.x); - block = y + x * blocksPerSide + z * perLayer; - if (globalY > cutoff) + case LayerType.Absolute: + case LayerType.Additive: + NoiseUtilities.NoiseInterpolatorSettings nis = + NoiseUtilities.GetNoiseInterpolatorSettings(Env.AREA_SIZE_WITH_PADDING, downsamplingFactor:2); + terrainLayerInterpolateSettings[i] = nis; + NativeArray lut = new NativeArray((nis.size + 1) * (nis.size + 1), Allocator.Temp); + terrainLayerLookupTables[i] = lut; + // Generate a lookup table for this column of areas + int j = 0; + for (int z = 0; z < nis.size; z++) { - terrainBlocks[block] = BlockType.Air; - continue; + float zf = (z << nis.step) + columnZ; + for (int x = 0; x < nis.size; x++) + { + float xf = (x << nis.step) + columnX; + lut[j++] = NoiseUtilities.GetNoise(xf, 0.0f, zf, noiseSeed,1f, + terrainGenLayer.amplitude,terrainGenLayer.exponent, terrainGenLayer.frequency, + FastNoise.NoiseType.Simplex); + } } + break; + case LayerType.Surface: + // No noise sampling is performed for a surface layer + break; + case LayerType.Structure: + // Since probabilities are low for structure creation, we use individual random calls + break; + } + } + // Arrays of relevant components for entire terrain area column + //NativeArray columnTerrainAreas = + // new NativeArray(Env.AREA_COLUMN_HEIGHT, Allocator.Temp); + NativeArray> terrainBlockBuffers = + new NativeArray>(Env.AREA_COLUMN_HEIGHT, Allocator.Temp); + NativeArray> colMinBuffers = + new NativeArray>(Env.AREA_COLUMN_HEIGHT, Allocator.Temp); + NativeArray> colMaxBuffers = + new NativeArray>(Env.AREA_COLUMN_HEIGHT, Allocator.Temp); + NativeArray> terrainStructureBuffers = + new NativeArray>(Env.AREA_COLUMN_HEIGHT, Allocator.Temp); + //Preprocess terrain area column + for (int columnAreaY = 0; + columnAreaY < Env.AREA_COLUMN_HEIGHT; + columnAreaY++) + { + //Entity + Entity terrainEntity = terrainAreaEntities[index + columnAreaY]; + + //TerrainArea + //TerrainArea terrainArea = terrainAreas[index + columnAreaY]; + //columnTerrainAreas[columnAreaY] = terrainArea; + int3 chunk = new int3(columnToSpawn.x, columnAreaY, columnToSpawn.y); + //terrainArea.location = chunk; // terrain area grid position + ecb.SetComponent(index + columnAreaY, terrainEntity, new TerrainArea{location = chunk}); - if (y < minY) - minY = y; - if (y + 1 > maxY) - maxY = y + 1; - - // todo generate biomes, trees, etc - terrainBlocks[block] = (BlockType) ((math.abs(globalX) % 4) + 1); + //LocalTransform + int areaY = columnAreaY * Env.AREA_SIZE; + //LocalTransform localTransform = localTransforms[index + columnAreaY]; + //localTransform.Position = new float3(columnX, areaY, columnZ); // world space position + ecb.SetComponent(index + columnAreaY, terrainEntity, new LocalTransform{Position = new float3(columnX, areaY, columnZ) }); + // Block buffer + DynamicBuffer terrainBlocksBuffer = terrainBlocksLookup[terrainEntity]; + terrainBlocksBuffer.Resize(Env.AREA_SIZE_POW_3, NativeArrayOptions.ClearMemory); + DynamicBuffer terrainBlocks = terrainBlocksBuffer.Reinterpret(); + terrainBlockBuffers[columnAreaY] = terrainBlocks; + // Terrain area column min buffer + DynamicBuffer colMinBuffer = terrainColMinLookup[terrainEntity]; + colMinBuffer.Resize(Env.AREA_SIZE_POW_3, NativeArrayOptions.UninitializedMemory); + unsafe + { + // Initialize array to a max value for column height + UnsafeUtility.MemSet(colMinBuffer.GetUnsafePtr(), (byte)Env.AREA_SIZE, Env.AREA_SIZE_POW_3); + } + DynamicBuffer colMin = colMinBuffer.Reinterpret(); + colMinBuffers[columnAreaY] = colMin; + //Terrain area column max buffer + DynamicBuffer colMaxBuffer = terrainColMaxLookup[terrainEntity]; + colMaxBuffer.Resize(Env.AREA_SIZE_POW_3, NativeArrayOptions.ClearMemory); + DynamicBuffer colMax = colMaxBuffer.Reinterpret(); + colMaxBuffers[columnAreaY] = colMax; + // terrain Structures + DynamicBuffer structuresToSpawnBuffer = _structuresToSpawnLookup[terrainEntity]; + terrainStructureBuffers[columnAreaY] = structuresToSpawnBuffer; + } + + // iterate up each block column in this area column + int globalX, globalZ; + for (int z = 0; z < Env.AREA_SIZE; z++) + { + globalZ = columnZ + z; + for (int x = 0; x < Env.AREA_SIZE; x++) + { + globalX = columnX + x; + // For each block column in area column, iterate upwards + int columnAccess = x + z * Env.AREA_SIZE; + int heightSoFar = 0; // Start at y = 0 + int startIndex = TerrainUtilities.BlockLocationToIndex(x, 0, z); + for (int i = 0; i < terrainGenLayers.Length; i++) + { + TerrainGenerationLayer terrainGenerationLayer = terrainGenLayers[i]; + NativeArray lookupTable = terrainLayerLookupTables[i]; + NoiseUtilities.NoiseInterpolatorSettings nis = terrainLayerInterpolateSettings[i]; + switch (terrainGenerationLayer.layerType) + { + case LayerType.Absolute: + heightSoFar = GenerateAbsoluteLayer(ref terrainBlockBuffers, + ref colMinBuffers, ref colMaxBuffers, nis,ref lookupTable, x, z, startIndex, + heightSoFar, ref terrainGenerationLayer, columnAccess); + break; + case LayerType.Additive: + heightSoFar = GenerateAdditiveLayer(ref terrainBlockBuffers, + ref colMinBuffers, ref colMaxBuffers, nis,ref lookupTable, x, z, startIndex, + heightSoFar, ref terrainGenerationLayer, columnAccess); + break; + case LayerType.Surface: + heightSoFar = GenerateSurfaceLayer(ref terrainBlockBuffers, + ref colMinBuffers, ref colMaxBuffers, startIndex, + heightSoFar, ref terrainGenerationLayer, columnAccess); + break; + case LayerType.Structure: + // Structure layers do not immediately change blocks or height. Instead, + // they mark that a structure should be generated at a given position + GenerateStructureLayer(ref terrainGenerationLayer, ref terrainStructureBuffers,index, x,z, globalX, heightSoFar, globalZ ); + break; + } + + //startIndex += currentChunkY; } // Set column heights in heightmap buffers - colMin[column] = (byte)minY; - colMax[column] = (byte)maxY; - + //colMin[columnAccess] = (byte)minY; + //colMax[columnAccess] = (byte)(heightSoFar); + + + } + } + + } + + private void GenerateStructureLayer(ref TerrainGenerationLayer terrainGenLayer, ref NativeArray> structuresToSpawnBuffers, + int index, int localX, int localZ, int globalX, int globalY, int globalZ) + { + float chanceAtPos = NoiseUtilities.RandomPrecise(TerrainUtilities.BlockLocationHash(globalX, globalY, globalZ), (byte)noiseSeed); + int colY = globalY / Env.AREA_SIZE; + DynamicBuffer structuresToSpawn = structuresToSpawnBuffers[colY]; + int localY = globalY - (colY * Env.AREA_SIZE); + if (terrainGenLayer.chance > chanceAtPos) + { + if (NoiseUtilities.RandomPrecise(TerrainUtilities.BlockLocationHash(globalX+1, globalY, globalZ), (byte)noiseSeed) > chanceAtPos && + NoiseUtilities.RandomPrecise(TerrainUtilities.BlockLocationHash(globalX-1, globalY, globalZ), (byte)noiseSeed) > chanceAtPos && + NoiseUtilities.RandomPrecise(TerrainUtilities.BlockLocationHash(globalX, globalY, globalZ+1), (byte)noiseSeed) > chanceAtPos && + NoiseUtilities.RandomPrecise(TerrainUtilities.BlockLocationHash(globalX, globalY, globalZ-1), (byte)noiseSeed) > chanceAtPos) + { + // Mark that we need to spawn a structure here + structuresToSpawn.Add(new TerrainStructuresToSpawn + { + localPos = new int3(localX, localY, localZ), + structureType = terrainGenLayer.structureType, + extents = new int3(3,3,5) + }); + ecb.SetComponentEnabled(index, terrainAreaEntities[index + colY], true); } } } + + private int GenerateAbsoluteLayer(ref NativeArray> terrainBlockBuffers, + ref NativeArray> colMinBuffers, + ref NativeArray> colMaxBuffers, + NoiseUtilities.NoiseInterpolatorSettings nis, ref NativeArray lut, int x, int z, + int blockIndex, int heightSoFar, ref TerrainGenerationLayer terrainGenLayer, int columnAccess) + { + // Calculate height to add and sum it with the min height (because the height of this + // layer should fluctuate between minHeight and minHeight+the max noise) + int columnTop = terrainGenLayer.minHeight + (int)(NoiseUtilities.Interpolate(nis, x, z, lut)); + + // Absolute layers add from the minY and up but if the layer height is lower than + // the existing terrain there's nothing to add so just return the initial value + if (columnTop > heightSoFar) + { + // set blocks from + int start = terrainGenLayer.minHeight > 0 ? terrainGenLayer.minHeight : 0; + int end = columnTop < Env.WORLD_HEIGHT ? columnTop : Env.WORLD_HEIGHT; + SetBlocks(ref terrainBlockBuffers, ref colMinBuffers, ref colMaxBuffers, start, end, + terrainGenLayer.blockType, blockIndex, columnAccess); + + //Return the new global height of this column + return end; + } + + return heightSoFar; + } + + private int GenerateAdditiveLayer(ref NativeArray> terrainBlockBuffers, + ref NativeArray> colMinBuffers, + ref NativeArray> colMaxBuffers, + NoiseUtilities.NoiseInterpolatorSettings nis, ref NativeArray lut, int x, int z, + int blockIndex, int heightSoFar, ref TerrainGenerationLayer terrainGenLayer, int columnAccess) + { + int heightToAdd= terrainGenLayer.minHeight + (int)(NoiseUtilities.Interpolate(nis, x, z, lut)); + + + int end = heightSoFar + heightToAdd < Env.WORLD_HEIGHT ? heightSoFar + heightToAdd: Env.WORLD_HEIGHT; + SetBlocks(ref terrainBlockBuffers, ref colMinBuffers, ref colMaxBuffers, heightSoFar, end, + terrainGenLayer.blockType, blockIndex, columnAccess); + + //Return the new global height of this column + return end; + } + + private int GenerateSurfaceLayer(ref NativeArray> terrainBlockBuffers, + ref NativeArray> colMinBuffers, + ref NativeArray> colMaxBuffers, + int blockIndex, int heightSoFar, ref TerrainGenerationLayer terrainGenLayer, int columnAccess) + { + int heightToAdd= 1; + + int end = heightSoFar + heightToAdd < Env.WORLD_HEIGHT ? heightSoFar + heightToAdd: Env.WORLD_HEIGHT; + SetBlocks(ref terrainBlockBuffers, ref colMinBuffers, ref colMaxBuffers, heightSoFar, end, + terrainGenLayer.blockType, blockIndex, columnAccess); + + //Return the new global height of this column + return end; + } + + private void SetBlocks(ref NativeArray> terrainBlockBuffers, + ref NativeArray> colMinBuffers, + ref NativeArray> colMaxBuffers, + int start, int end, BlockType blockType, int blockIndex, int columnAccess) + { + DynamicBuffer terrainBlockBuffer = terrainBlockBuffers[0]; + DynamicBuffer colMinBuffer; + DynamicBuffer colMaxBuffer; + int prevColY = -1; + for (int globalY = start; globalY < end; globalY++) + { + int colY = globalY / Env.AREA_SIZE; + int chunkYMin = colY * Env.AREA_SIZE; + int chunkYMax = chunkYMin + Env.AREA_SIZE - 1; + int localY = globalY - chunkYMin; + // Check if we have entered a new terrain area + if (colY != prevColY) + { + // Get buffers for new terrain area + terrainBlockBuffer = terrainBlockBuffers[colY]; + colMinBuffer = colMinBuffers[colY]; + colMaxBuffer = colMaxBuffers[colY]; + // Set column heightmap + if(localY < colMinBuffer[columnAccess]) + colMinBuffer[columnAccess] = (byte)localY; + if (end > colY + chunkYMax) + colMaxBuffer[columnAccess] = (byte)(Env.AREA_SIZE); + else + colMaxBuffer[columnAccess] = (byte)(end - chunkYMin); + } + terrainBlockBuffer[blockIndex + localY] = blockType; + + prevColY = colY; + + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Terrain/TerrainNeighborSystem.cs b/Assets/Scripts/Terrain/TerrainNeighborSystem.cs index 400e1c5a..b582c544 100644 --- a/Assets/Scripts/Terrain/TerrainNeighborSystem.cs +++ b/Assets/Scripts/Terrain/TerrainNeighborSystem.cs @@ -43,16 +43,16 @@ protected override void OnUpdate() NativeArray terrainAreas = _terrainChunkQuery.ToComponentDataArray(Allocator.TempJob); - JobHandle handle = new SetAreaNeighborsJob() + new SetAreaNeighborsJob() { terrainAreas = terrainAreas, terrainAreaEntities = terrainAreaEntities, terrainNeighborsLookup = _terrainNeighborsLookup - }.ScheduleParallel(Dependency); - handle.Complete(); - - terrainAreas.Dispose(); - terrainAreaEntities.Dispose(); + }.ScheduleParallel(); + //handle.Complete(); + + //terrainAreas.Dispose(); + //terrainAreaEntities.Dispose(); } } @@ -64,8 +64,12 @@ protected override void OnUpdate() public partial struct SetAreaNeighborsJob : IJobEntity { // thread safe as long as no terrain areas have the same location! - [NativeDisableParallelForRestriction] public NativeArray terrainAreaEntities; - [NativeDisableParallelForRestriction] public NativeArray terrainAreas; + [NativeDisableParallelForRestriction] + [DeallocateOnJobCompletion] + public NativeArray terrainAreaEntities; + [NativeDisableParallelForRestriction] + [DeallocateOnJobCompletion] + public NativeArray terrainAreas; [NativeDisableParallelForRestriction] public ComponentLookup terrainNeighborsLookup; public void Execute(Entity entity, ref TerrainArea terrainArea) diff --git a/Assets/Scripts/Terrain/TerrainStructuresSystem.cs b/Assets/Scripts/Terrain/TerrainStructuresSystem.cs new file mode 100644 index 00000000..acf26617 --- /dev/null +++ b/Assets/Scripts/Terrain/TerrainStructuresSystem.cs @@ -0,0 +1,248 @@ +using System; +using Opencraft.Terrain.Authoring; +using Opencraft.Terrain.Blocks; +using Opencraft.Terrain.Structures; +using Opencraft.Terrain.Utilities; +using Unity.Burst; +using Unity.Collections; +using Unity.Entities; +using Unity.Jobs; +using Unity.Mathematics; +using Unity.Profiling; +using Unity.Transforms; + +namespace Opencraft.Terrain +{ + [WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)] + [UpdateInGroup(typeof(SimulationSystemGroup))] + [UpdateAfter(typeof(TerrainNeighborSystem))] + [BurstCompile] + // System that generates new terrain areas based on basic perlin noise + public partial struct TerrainStructuresSystem : ISystem + { + private EntityQuery _structuresToSpawnQuery; + private ProfilerMarker _markerStructureGen; + private BufferLookup _terrainBlocksLookup; + private BufferLookup _terrainColMinLookup; + private BufferLookup _terrainColMaxLookup; + public void OnCreate(ref SystemState state) + { + // Wait for scene load/baking to occur before updates. + state.RequireForUpdate(); + state.RequireForUpdate(); + state.RequireForUpdate(); + state.RequireForUpdate(); + _structuresToSpawnQuery = SystemAPI.QueryBuilder().WithAll().Build(); + //_terrainGenLayers= SystemAPI.QueryBuilder().WithAll().Build().ToComponentDataArray(Allocator.Persistent); + _markerStructureGen = new ProfilerMarker("StructureGeneration"); + _terrainBlocksLookup = state.GetBufferLookup(isReadOnly: false); + _terrainColMinLookup = state.GetBufferLookup(isReadOnly: false); + _terrainColMaxLookup = state.GetBufferLookup(isReadOnly: false); + state.Enabled = false; + } + + + + public void OnUpdate(ref SystemState state) + { + if (_structuresToSpawnQuery.IsEmpty) + { + return; + } + + _markerStructureGen.Begin(); + EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob); + EntityCommandBuffer.ParallelWriter parallelEcb = ecb.AsParallelWriter(); + new GenerateStructuresJob() + { + ecb = parallelEcb + }.ScheduleParallel(); + + ecb.Playback(state.EntityManager); + _markerStructureGen.End(); + } + } + + [BurstCompile] + [WithAll(typeof(GenStructures))] + public partial struct GenerateStructuresJob : IJobEntity + { + public EntityCommandBuffer.ParallelWriter ecb; + [ReadOnly] public BufferLookup terrainBufferLookup; + [ReadOnly] public BufferLookup terrainColMinLookup; + [ReadOnly] public BufferLookup terrainColMaxLookup; + + public void Execute(Entity entity, [EntityIndexInQuery]int index, in TerrainNeighbors terrainNeighbor, + ref DynamicBuffer structuresToSpawnBuffer, + ref DynamicBuffer terrainBlocksBuffer, + ref DynamicBuffer colMinBuffer, + ref DynamicBuffer colMaxBuffer) + { + if (structuresToSpawnBuffer.IsEmpty) + { + return; + } + + DynamicBuffer terrainBlocks = terrainBlocksBuffer.Reinterpret(); + DynamicBuffer colMax = colMaxBuffer.Reinterpret(); + DynamicBuffer colMin = colMinBuffer.Reinterpret(); + // References to neighbor areas + /*DynamicBuffer neighborXP = default; + if (terrainNeighbor.neighborXP != Entity.Null) + neighborXP = terrainBufferLookup[terrainNeighbor.neighborXP].Reinterpret(); + DynamicBuffer neighborXN = default; + if (terrainNeighbor.neighborXN != Entity.Null) + neighborXN = terrainBufferLookup[terrainNeighbor.neighborXN].Reinterpret();*/ + DynamicBuffer neighborYP = default; + DynamicBuffer neighborYPColMin = default; + DynamicBuffer neighborYPColMax = default; + if (terrainNeighbor.neighborYP != Entity.Null) + { + neighborYP = terrainBufferLookup[terrainNeighbor.neighborYP].Reinterpret(); + neighborYPColMin = terrainColMinLookup[terrainNeighbor.neighborYP].Reinterpret(); + neighborYPColMax = terrainColMaxLookup[terrainNeighbor.neighborYP].Reinterpret(); + } + + /*DynamicBuffer neighborYN = default; + if (terrainNeighbor.neighborYN != Entity.Null) + neighborYN = terrainBufferLookup[terrainNeighbor.neighborYN].Reinterpret(); + DynamicBuffer neighborZP = default; + if (terrainNeighbor.neighborZP != Entity.Null) + neighborZP = terrainBufferLookup[terrainNeighbor.neighborZP].Reinterpret(); + DynamicBuffer neighborZN = default; + if (terrainNeighbor.neighborZN != Entity.Null) + neighborZN = terrainBufferLookup[terrainNeighbor.neighborZN].Reinterpret();*/ + + + + DynamicBuffer delaySpawning = new DynamicBuffer(); + bool hasChanged = false; + // Loop through structures + AreasUpdated areasUpdated = AreasUpdated.NONE; + foreach (var structure in structuresToSpawnBuffer) + { + switch (structure.structureType) + { + case StructureType.Tree: + if (!CheckBoundsTree(structure.localPos, structure.extents, terrainNeighbor)) + { + // This structure overlaps with an area that has not been created yet + delaySpawning.Add(structure); + break; + } + + areasUpdated = GenerateTreeStructure(structure, ref terrainBlocks, ref colMin, ref colMax,ref neighborYP, ref neighborYPColMin, ref neighborYPColMax + /*ref neighborXP, ref neighborXN, ref neighborYP, ref neighborYN, ref neighborZN, ref neighborZP*/); + hasChanged = true; + + break; + } + } + + structuresToSpawnBuffer.Clear(); + if (!delaySpawning.IsEmpty) + { + structuresToSpawnBuffer.CopyFrom(delaySpawning); + } + else + { + // Disable GenStructures flag on this area + ecb.SetComponentEnabled(index, entity, false); + } + + // Set remeshing flag on this and neighbor areas if necessary + if (hasChanged) + ecb.SetComponentEnabled(index, entity, false); + if ((areasUpdated & AreasUpdated.XP) == AreasUpdated.XP) + ecb.SetComponentEnabled(index, terrainNeighbor.neighborXP, false); + if ((areasUpdated & AreasUpdated.XN) == AreasUpdated.XN) + ecb.SetComponentEnabled(index, terrainNeighbor.neighborXN, false); + if ((areasUpdated & AreasUpdated.YP) == AreasUpdated.YP) + ecb.SetComponentEnabled(index, terrainNeighbor.neighborYP, false); + if ((areasUpdated & AreasUpdated.YN) == AreasUpdated.YN) + ecb.SetComponentEnabled(index, terrainNeighbor.neighborYN, false); + if ((areasUpdated & AreasUpdated.ZP) == AreasUpdated.ZP) + ecb.SetComponentEnabled(index, terrainNeighbor.neighborZP, false); + if ((areasUpdated & AreasUpdated.ZN) == AreasUpdated.ZN) + ecb.SetComponentEnabled(index, terrainNeighbor.neighborZN, false); + + } + + [Flags] + private enum AreasUpdated + { + NONE = 0, + XP = 1, + XN = 2, + YP = 4, + YN = 8, + ZP = 16, + ZN = 32 + } + + private bool CheckBoundsTree(int3 baseLoc, int3 extent, TerrainNeighbors terrainNeighbors ) + { + if (baseLoc.x - extent.x < 0 && terrainNeighbors.neighborXN == Entity.Null) + { + return false; + } + if (baseLoc.x + extent.x >= Env.AREA_SIZE && terrainNeighbors.neighborXP == Entity.Null) + { + return false; + } + if (baseLoc.z - extent.z < 0 && terrainNeighbors.neighborZN == Entity.Null) + { + return false; + } + if (baseLoc.z + extent.z >= Env.AREA_SIZE && terrainNeighbors.neighborZP == Entity.Null) + { + return false; + } + if (baseLoc.y + extent.y >= Env.AREA_SIZE && terrainNeighbors.neighborYP == Entity.Null) + { + return false; + } + + return true; + } + + private AreasUpdated GenerateTreeStructure(TerrainStructuresToSpawn structure, + ref DynamicBuffer terrainBlocks, ref DynamicBuffer colMin, ref DynamicBuffer colMax, + ref DynamicBuffer neighborYP, ref DynamicBuffer neighborYPColMin, ref DynamicBuffer neighborYPColMax + /*ref DynamicBuffer neighborXP,ref DynamicBuffer neighborXN, + ref DynamicBuffer neighborYP, ref DynamicBuffer neighborYN, + ref DynamicBuffer neighborZP, ref DynamicBuffer neighborZN*/) + { + AreasUpdated aU = AreasUpdated.NONE; + //structure.localPos; + int blockAccess = TerrainUtilities.BlockLocationToIndex(ref structure.localPos); + int colAccess = TerrainUtilities.BlockLocationToColIndex(ref structure.localPos); + for (int y = 0; y < structure.extents.y; y++) + { + int localY = structure.localPos.y + y; + if (localY >= Env.AREA_SIZE) + { + aU &= AreasUpdated.YP; + int neighborY = localY - Env.AREA_SIZE; + neighborYP[neighborY] = BlockType.Tin; + if (neighborYPColMin[colAccess] > neighborY) + neighborYPColMin[colAccess] = (byte)neighborY; + if (neighborYPColMax[colAccess] < neighborY) + neighborYPColMax[colAccess] = (byte)neighborY; + + } + else + { + terrainBlocks[blockAccess + y] = BlockType.Tin; + if (colMin[colAccess] > localY) + colMin[colAccess] = (byte)localY; + if (colMax[colAccess] < localY) + colMax[colAccess] = (byte)localY; + } + } + return aU; + } + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Terrain/TerrainStructuresSystem.cs.meta b/Assets/Scripts/Terrain/TerrainStructuresSystem.cs.meta new file mode 100644 index 00000000..6cfc9625 --- /dev/null +++ b/Assets/Scripts/Terrain/TerrainStructuresSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 216b8214783e4f77920e7c86ea1fe7ca +timeCreated: 1689774393 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/TerrainToSpawnSystem.cs b/Assets/Scripts/Terrain/TerrainToSpawnSystem.cs index 21609336..6284e7dd 100644 --- a/Assets/Scripts/Terrain/TerrainToSpawnSystem.cs +++ b/Assets/Scripts/Terrain/TerrainToSpawnSystem.cs @@ -30,7 +30,7 @@ public void OnCreate(ref SystemState state) { // Wait for scene load/baking to occur before updates. state.RequireForUpdate(); - state.RequireForUpdate(); + state.RequireForUpdate(); _terrainAreasQuery = SystemAPI.QueryBuilder().WithAll().Build(); markerPlayerTerrainGenCheck = new ProfilerMarker("PlayerTerrainGenCheck"); } @@ -45,44 +45,42 @@ public void OnUpdate(ref SystemState state) terrainAreas = _terrainAreasQuery.ToComponentDataArray(state.WorldUpdateAllocator); // Determine what chunks need to be spawned - var toSpawnbuffer = SystemAPI.GetBuffer(terrainSpawnerEntity); - DynamicBuffer chunksToSpawnBuffer = toSpawnbuffer.Reinterpret(); + var toSpawnbuffer = SystemAPI.GetBuffer(terrainSpawnerEntity); + DynamicBuffer chunksToSpawnBuffer = toSpawnbuffer.Reinterpret(); markerPlayerTerrainGenCheck.Begin(); // todo - make this parallel - var areasPlayersCloseTo = new NativeHashSet(32, Allocator.TempJob); - int blocksPerSide = terrainSpawner.blocksPerSide; + var areasPlayersCloseTo = new NativeHashSet(32, Allocator.TempJob); int viewRange = terrainSpawner.terrainSpawnRange; foreach (var transform in SystemAPI.Query().WithAll()) { var pos = transform.Position; - int3 playerChunk =new int3( - (int) (math.floor(pos.x / blocksPerSide )), - (int) (math.floor(pos.y / blocksPerSide )), - (int) (math.floor(pos.z / blocksPerSide ))); + int2 playerColumn =new int2( + (int) (math.floor(pos.x / Env.AREA_SIZE )), + (int) (math.floor(pos.z / Env.AREA_SIZE ))); var viewRangeSide = (viewRange +1+ viewRange); // Set of areas forming cube around players current area - NativeHashSet nearbyAreas = new NativeHashSet(viewRangeSide * viewRangeSide * viewRangeSide, Allocator.Temp); + NativeHashSet nearbyColumns = new NativeHashSet(viewRangeSide * viewRangeSide, Allocator.Temp); for (int i = -viewRange; i < viewRange; i++) { - for (int j = -viewRange; j < viewRange; j++) + //for (int j = -viewRange; j < viewRange; j++) + //{ + for (int k = -viewRange; k < viewRange; k++) { - for (int k = -viewRange; k < viewRange; k++) - { - nearbyAreas.Add(playerChunk + new int3(i,j,k)); - } + nearbyColumns.Add(playerColumn + new int2(i,k)); } + //} } // O(n) in number of areas, may be further improvement by partitioning around players in advance foreach (var terrainArea in terrainAreas) { - if (nearbyAreas.Contains(terrainArea.location)) + if (nearbyColumns.Contains(terrainArea.location.xz)) { - nearbyAreas.Remove(terrainArea.location); + nearbyColumns.Remove(terrainArea.location.xz); } } // Copy the nearby areas of this player that aren't yet spawned to the global hashset - areasPlayersCloseTo.UnionWith(nearbyAreas); + areasPlayersCloseTo.UnionWith(nearbyColumns); } // Mark areas that need to be spawned chunksToSpawnBuffer.AddRange(areasPlayersCloseTo.ToNativeArray(Allocator.Temp)); diff --git a/Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs b/Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs new file mode 100644 index 00000000..04f17e77 --- /dev/null +++ b/Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs @@ -0,0 +1,224 @@ +using System.Runtime.CompilerServices; +using Opencraft.ThirdParty; +using Unity.Burst; +using Unity.Collections; +using Unity.Mathematics; +using UnityEngine; + +namespace Opencraft.Terrain.Utilities +{ + [BurstCompile] + public static class NoiseUtilities + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [BurstCompile] + public static float GetNoise(float x, float y, float z, int seed, float scale, int max, float power, float frequency = 0.01f, FastNoise.NoiseType noiseType = FastNoise.NoiseType.Simplex) + { + float scaleInv = 1f / scale; + float n = FastNoise.GetNoise(x * scaleInv, y * scaleInv, z * scaleInv, seed, frequency, noiseType) + 1f; + n *= (max >> 1); + + if (math.abs(power - 1f) > float.Epsilon) + { + n = math.pow(n, power); + } + + return n; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [BurstCompile] + public static NoiseInterpolatorSettings GetNoiseInterpolatorSettings(int areaSize, int downsamplingFactor) + { + int step = downsamplingFactor; + int size = (areaSize >> step) + 1; + int size2 = size * size; + return new NoiseInterpolatorSettings + { + size = size, + sizePow2 = size2, + sizePow2plusSize = size2 + size, + step = downsamplingFactor, + scale = 1f / (1 << step) + }; + } + + public struct NoiseInterpolatorSettings + { + public int size; + public int sizePow2; + + public int sizePow2plusSize; + //! +1 interpolated into downsampled state + public int step; + //! Interpolation scale + public float scale; + } + + + /// + /// Interpolates the given coordinate into a downsampled coordinate and returns a value from the lookup table on that position + /// + /// Position on the x axis + /// Lookup table to be used to interpolate + public static float Interpolate(NoiseInterpolatorSettings settings, int x, NativeArray lookupTable) + { + float xs = (x + 0.5f) * settings.scale; + + int x0 = FastFloor(xs); + + xs = (xs - x0); + + return Interpolate(lookupTable[x0], lookupTable[x0 + 1], xs); + } + + /// + /// Interpolates given coordinates into downsampled coordinates and returns a value from the lookup table on that position + /// + /// Position on the x axis + /// Position on the z axis + /// Lookup table to be used to interpolate + public static float Interpolate(NoiseInterpolatorSettings settings, int x, int z, NativeArray lookupTable) + { + float xs = (x + 0.5f) * settings.scale; + float zs = (z + 0.5f) * settings.scale; + + int x0 = FastFloor(xs); + int z0 = FastFloor(zs); + + xs = (xs - x0); + zs = (zs - z0); + + int lookupIndex = GetIndex1DFrom2D(x0, z0, settings.size); + int lookupIndex2 = lookupIndex + settings.size; // x0,z0+1 + + return Interpolate( + Interpolate(lookupTable[lookupIndex], lookupTable[lookupIndex + 1], xs), + Interpolate(lookupTable[lookupIndex2], lookupTable[lookupIndex2 + 1], xs), + zs); + } + + /// + /// Interpolates given coordinates into downsampled coordinates and returns a value from the lookup table on that position + /// + /// Position on the x axis + /// Position on the y axis + /// Position on the z axis + /// Lookup table to be used to interpolate + public static float Interpolate(NoiseInterpolatorSettings settings, int x, int y, int z, NativeArray lookupTable) + { + float xs = (x + 0.5f) * settings.scale; + float ys = (y + 0.5f) * settings.scale; + float zs = (z + 0.5f) * settings.scale; + + int x0 = FastFloor(xs); + int y0 = FastFloor(ys); + int z0 = FastFloor(zs); + + xs = (xs - x0); + ys = (ys - y0); + zs = (zs - z0); + + //int lookupIndex = Helpers.GetIndex1DFrom3D(x0, y0, z0, size, size); + int lookupIndex = GetIndex1DFrom3D(x0, y0, z0, settings.size, settings.size); + int lookupIndexY = lookupIndex + settings.sizePow2; // x0, y0+1, z0 + int lookupIndexZ = lookupIndex + settings.size; // x0, y0, z0+1 + int lookupIndexYZ = lookupIndex + settings.sizePow2plusSize; // x0, y0+1, z0+1 + + return Interpolate( + Interpolate( + Interpolate(lookupTable[lookupIndex], lookupTable[lookupIndex + 1], xs), + Interpolate(lookupTable[lookupIndexY], lookupTable[lookupIndexY + 1], xs), + ys), + Interpolate( + Interpolate(lookupTable[lookupIndexZ], lookupTable[lookupIndexZ + 1], xs), + Interpolate(lookupTable[lookupIndexYZ], lookupTable[lookupIndexYZ + 1], xs), + ys), + zs); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Interpolate(float x0, float x1, float alpha) + { + return x0 + (x1 - x0) * alpha; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int FastFloor(float val) + { + return (val > 0) ? (int)val : (int)val - 1; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetIndex1DFrom2D(int x, int z, int sizeX) + { + return x + z * sizeX; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int GetIndex1DFrom3D(int x, int y, int z, int sizeX, int sizeZ) + { + return x + sizeX * (z + y * sizeZ); + } + + private const float MULTIPLIER = 1f / 10000f; + //! First 255 prime numbers and 1. Used for randomizing a number in the RandomPercent function. + private static readonly int[] primeNumbers = + { + 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, + 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, + 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, + 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, + 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, + 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, + 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, + 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, + 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, + 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, + 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, + 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, + 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, + 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, + 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, + 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, + 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, + 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619 + }; + [BurstCompile] + public static float Random(int h, byte seed) + { + int hash = h; + unchecked + { + hash *= primeNumbers[seed]; + + if (hash < 0) + { + hash *= -1; + } + + return (hash % 10000) * MULTIPLIER; + } + } + [BurstCompile] + public static float RandomPrecise(int h, byte seed) + { + int hash = h; + unchecked + { + hash *= primeNumbers[seed]; + hash *= primeNumbers[++seed] * h; + + if (hash < 0) + { + hash *= -1; + } + + return (hash % 10000) * MULTIPLIER; + } + } + + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs.meta b/Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs.meta new file mode 100644 index 00000000..180e758b --- /dev/null +++ b/Assets/Scripts/Terrain/Utilities/NoiseUtilities.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8ebf50d6fdcc425f871d1bd04a4a2bb5 +timeCreated: 1689676263 \ No newline at end of file diff --git a/Assets/Scripts/Terrain/Utilities/TerrainUtilities.cs b/Assets/Scripts/Terrain/Utilities/TerrainUtilities.cs index 56a788b5..fd8957de 100644 --- a/Assets/Scripts/Terrain/Utilities/TerrainUtilities.cs +++ b/Assets/Scripts/Terrain/Utilities/TerrainUtilities.cs @@ -12,25 +12,13 @@ namespace Opencraft.Terrain.Utilities { - // Helper class for shared static BlocksPerAreaSide parameter, initialized in TerrainSpawnerAuthoring - public abstract class Constants - { - public static readonly SharedStatic BlocksPerSide = SharedStatic.GetOrCreate(); - public static readonly SharedStatic BlocksPerLayer = SharedStatic.GetOrCreate(); - public static readonly SharedStatic BlocksPerArea = SharedStatic.GetOrCreate(); - - private class BlocksPerSideKey {} - private class BlocksPerLayerKey {} - private class BlocksPerAreaKey {} - } - [BurstCompile] public static class TerrainUtilities { // Draws outline of an area public static void DebugDrawTerrainArea(ref float3 terrainAreaPos, Color color, float duration = 0.0f) { - var d = Constants.BlocksPerSide.Data; + var d = Env.AREA_SIZE; // Draw a bounding box Debug.DrawLine(terrainAreaPos, terrainAreaPos + new float3(d, 0, 0),color,duration ); Debug.DrawLine(terrainAreaPos, terrainAreaPos + new float3(0, d, 0),color,duration ); @@ -68,7 +56,7 @@ public static void DebugDrawTerrainBlock(ref float3 terrainBlockPos, Color color // Converts a continuous world location to a discrete area location public static int3 GetContainingAreaLocation(ref float3 pos) { - int bps = Constants.BlocksPerSide.Data; + int bps = Env.AREA_SIZE; // Terrain Areas are placed in cube grid with intervals of blocksPerAreaSide //Debug.Log($"before{pos}"); return new int3( @@ -90,24 +78,51 @@ public static int3 GetBlockLocationInArea(ref float3 blockPos, ref int3 terrainA // Converts a block position in an area to that block's index public static int BlockLocationToIndex(ref int3 blockPos) { - int bps = Constants.BlocksPerSide.Data; - return blockPos.y + blockPos.x * bps + blockPos.z * bps * bps ; + int bps = Env.AREA_SIZE; + int bpl = Env.AREA_SIZE_POW_2; + return blockPos.y + blockPos.x * bps + blockPos.z * bpl; } + + // Converts a block position in an area to that block's index + public static int BlockLocationToIndex(int x, int y, int z) + { + int bps = Env.AREA_SIZE; + int bpl = Env.AREA_SIZE_POW_2; + return y + x * bps + z * bpl; + } + + public static int BlockLocationHash(int x, int y, int z) + { + unchecked + { + int hashCode = x; + hashCode = (hashCode * 397) ^ y; + hashCode = (hashCode * 397) ^ z; + return hashCode; + } + } + // Converts a block position in an area to it's column index public static int BlockLocationToColIndex(ref int3 blockPos) { - int bps = Constants.BlocksPerSide.Data; + int bps = Env.AREA_SIZE; return blockPos.x + blockPos.z * bps ; } + + public static int BlockLocationToColIndex(int x, int z) + { + int bps = Env.AREA_SIZE; + return x + z * bps ; + } [BurstCompile] - // Given an int3 position and an array of are transforms, return the containing area index if it exists. + // Given an int3 position and an array of area transforms, return the containing area index if it exists. public static bool GetTerrainAreaByPosition(ref int3 pos, ref NativeArray terrainAreaTransforms, out int containingAreaIndex) { - int bps = Constants.BlocksPerSide.Data; + //int bps = Env.AREA_SIZE; for (int i = 0; i < terrainAreaTransforms.Length; i++) { if (terrainAreaTransforms[i].Position.Equals(pos)) @@ -134,7 +149,7 @@ public static bool GetBlockLocationAtPosition(ref float3 pos, if (GetTerrainAreaByPosition(ref containingAreaLocation, ref terrainAreaTransforms, out int containingAreaIndex)) { - int bps = Constants.BlocksPerSide.Data; + int bps = Env.AREA_SIZE; int3 localPos = GetBlockLocationInArea(ref pos, ref containingAreaLocation); int index = BlockLocationToIndex(ref localPos); if (index < 0 || index >= bps * bps * bps ) @@ -197,7 +212,7 @@ public static bool GetBlockAtPosition(float3 pos, public static bool VisibleFaceXN(int j, int access, bool min, int kBPS2, ref DynamicBuffer blocks, ref DynamicBuffer neighborXN) { - int bps = Constants.BlocksPerSide.Data; + int bps = Env.AREA_SIZE; if (min) { //if (chunkPosX == 0) @@ -217,7 +232,7 @@ public static bool VisibleFaceXN(int j, int access, bool min, int kBPS2, ref Dyn public static bool VisibleFaceXP(int j, int access, bool max, int kBPS2, ref DynamicBuffer blocks, ref DynamicBuffer neighborXP) { - int bps = Constants.BlocksPerSide.Data; + int bps = Env.AREA_SIZE; if (max) { //if (chunkPosX == Constants.ChunkXAmount - 1) @@ -237,7 +252,7 @@ public static bool VisibleFaceXP(int j, int access, bool max, int kBPS2, ref Dyn public static bool VisibleFaceYN(int access, bool min, int iBPS, int kBPS2, ref DynamicBuffer blocks, ref DynamicBuffer neighborYN) { - int bps = Constants.BlocksPerSide.Data; + int bps = Env.AREA_SIZE; if (min) { @@ -270,8 +285,8 @@ public static bool VisibleFaceYP(int access, bool max, int iBPS, int kBPS2, ref public static bool VisibleFaceZN(int j, int access, bool min, int iBPS, ref DynamicBuffer blocks, ref DynamicBuffer neighborZN) { - int bps = Constants.BlocksPerSide.Data; - int bpl = Constants.BlocksPerLayer.Data; + int bps = Env.AREA_SIZE; + int bpl = Env.AREA_SIZE_POW_2; if (min) { @@ -288,7 +303,7 @@ public static bool VisibleFaceZN(int j, int access, bool min, int iBPS, ref Dyna public static bool VisibleFaceZP(int j, int access, bool max, int iBPS, ref DynamicBuffer blocks, ref DynamicBuffer neighborZP) { - int bpl = Constants.BlocksPerLayer.Data; + int bpl = Env.AREA_SIZE_POW_2; if (max) { diff --git a/Assets/Scripts/ThirdParty/CustomFastPerlin.cs b/Assets/Scripts/ThirdParty/CustomFastPerlin.cs deleted file mode 100644 index f7db33df..00000000 --- a/Assets/Scripts/ThirdParty/CustomFastPerlin.cs +++ /dev/null @@ -1,182 +0,0 @@ -using Unity.Burst; -using FNLfloat = System.Single; - -namespace Opencraft.ThirdParty -{ - // Static version of managed FastNoise for Perlin noise, so it can be burst compiled. - // https://github.com/Auburn/FastNoise - [BurstCompile] - public static class FastPerlin - { - private const int PrimeX = 501125321; - private const int PrimeY = 1136930381; - - [BurstCompile] - public static float PerlinGetNoise(FNLfloat x, FNLfloat y, int seed) - { - // Transform coordinate - float mFrequency = 0.01f; - x *= mFrequency; - y *= mFrequency; - - FNLfloat SQRT3_1 = (FNLfloat)1.7320508075688772935274463415059; - FNLfloat F2 = 0.5f * (SQRT3_1 - 1); - FNLfloat t_1 = (x + y) * F2; - x += t_1; - y += t_1; - - // 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex. - - const float SQRT3 = 1.7320508075688772935274463415059f; - const float G2 = (3 - SQRT3) / 6; - - int i = FastFloor(x); - int j = FastFloor(y); - float xi = (float)(x - i); - float yi = (float)(y - j); - - float t = (xi + yi) * G2; - float x0 = (float)(xi - t); - float y0 = (float)(yi - t); - - i *= PrimeX; - j *= PrimeY; - - float n0, n1, n2; - - float a = 0.5f - x0 * x0 - y0 * y0; - if (a <= 0) n0 = 0; - else - { - n0 = (a * a) * (a * a) * GradCoord(seed, i, j, x0, y0); - } - - float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a); - if (c <= 0) n2 = 0; - else - { - float x2 = x0 + (2 * (float)G2 - 1); - float y2 = y0 + (2 * (float)G2 - 1); - n2 = (c * c) * (c * c) * GradCoord(seed, i + PrimeX, j + PrimeY, x2, y2); - } - - if (y0 > x0) - { - float x1 = x0 + (float)G2; - float y1 = y0 + ((float)G2 - 1); - float b = 0.5f - x1 * x1 - y1 * y1; - if (b <= 0) n1 = 0; - else - { - n1 = (b * b) * (b * b) * GradCoord(seed, i, j + PrimeY, x1, y1); - } - } - else - { - float x1 = x0 + ((float)G2 - 1); - float y1 = y0 + (float)G2; - float b = 0.5f - x1 * x1 - y1 * y1; - if (b <= 0) n1 = 0; - else - { - n1 = (b * b) * (b * b) * GradCoord(seed, i + PrimeX, j, x1, y1); - } - } - - return (n0 + n1 + n2) * 99.83685446303647f; - } - - private static int FastFloor(FNLfloat f) - { - return f >= 0 ? (int)f : (int)f - 1; - } - - private static float GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd) - { - int hash = Hash(seed, xPrimed, yPrimed); - hash ^= hash >> 15; - hash &= 127 << 1; - - float xg = Gradients2D[hash]; - float yg = Gradients2D[hash | 1]; - - return xd * xg + yd * yg; - } - - private static int Hash(int seed, int xPrimed, int yPrimed) - { - int hash = seed ^ xPrimed ^ yPrimed; - - hash *= 0x27d4eb2d; - return hash; - } - - static readonly float[] Gradients2D = - { - 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, - 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, - 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, - -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, - 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, - -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, - -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, - -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, - -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, - 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, - -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, - 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, - 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, - 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, - 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, - -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, - 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, - -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, - -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, - -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, - -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, - 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, - -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, - 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, - 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, - 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, - 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, - -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, - 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, - -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, - -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, - -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, - -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, - 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, - -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, - 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, - 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, - 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, - 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, - -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, - 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, - -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, - -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, - -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, - -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, - 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, - -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, - 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, - 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, - 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, - 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, - -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, - 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, - -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, - -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, - -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, - -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, - 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, - -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, - 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, - 0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, - -0.38268343236509f, 0.38268343236509f, -0.923879532511287f, - -0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, - 0.38268343236509f, -0.38268343236509f, 0.923879532511287f, - }; - } -} \ No newline at end of file diff --git a/Assets/Scripts/ThirdParty/FastNoise.cs b/Assets/Scripts/ThirdParty/FastNoise.cs new file mode 100644 index 00000000..88a20cf4 --- /dev/null +++ b/Assets/Scripts/ThirdParty/FastNoise.cs @@ -0,0 +1,390 @@ +using Unity.Burst; + +// COMPILE SETTINGS + +// Uncomment the line below to swap all the inputs/outputs of FastNoise to doubles instead of floats +//#define FN_USE_DOUBLES + +// Uncomment the line below to disable the method aggressive inlining attribute, do this if it is unsupported, ie Unity +//#define FN_DISABLE_AGGRESSIVE_INLINING + +// ---------------- + +#if FN_USE_DOUBLES +using FN_DECIMAL = System.Double; +#else +using FN_DECIMAL = System.Single; +#endif + +using System; +#if! FN_DISABLE_AGGRESSIVE_INLINING +using System.Runtime.CompilerServices; +#endif + + +namespace Opencraft.ThirdParty +{ + // Static version of managed FastNoise for Perlin noise, so it can be burst compiled. + // See https://github.com/Auburn/FastNoise and https://github.com/Hertzole/Voxelmetric + [BurstCompile] + public static class FastNoise + { + public enum Interp { Linear, Hermite, Quintic }; + public enum NoiseType { Perlin, Simplex }; + + private const Interp interp = Interp.Quintic; + private const int PrimeX = 501125321; + private const int PrimeY = 1136930381; + private const int PrimeZ = 6971; + private const int PrimeW = 1013; + private const FN_DECIMAL F3 = (FN_DECIMAL)(1.0 / 3.0); + private const FN_DECIMAL G3 = (FN_DECIMAL)(1.0 / 6.0); + private const FN_DECIMAL SQRT3 = 1.7320508075688772935274463415059f; + private const FN_DECIMAL G2 = (3 - SQRT3) / 6; + private const FN_DECIMAL F2 = 0.5f * (SQRT3 - 1); + + [BurstCompile] + public static FN_DECIMAL GetNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, int seed, FN_DECIMAL frequency = 0.01f, NoiseType noiseType = NoiseType.Simplex) + { + x *= frequency; + y *= frequency; + z *= frequency; + + switch (noiseType) + { + case NoiseType.Perlin: + return PerlinGetNoise(x, y, z, seed); + case NoiseType.Simplex: + return SimplexGetNoise(x, y, z, seed); + default: + return 0.0f; + } + } + + [BurstCompile] + public static FN_DECIMAL PerlinGetNoise(FN_DECIMAL x, FN_DECIMAL y,FN_DECIMAL z, int seed) + { + int x0 = FastFloor(x); + int y0 = FastFloor(y); + int z0 = FastFloor(z); + int x1 = x0 + 1; + int y1 = y0 + 1; + int z1 = z0 + 1; + + FN_DECIMAL xs, ys, zs; + switch (interp) + { + default: + /*case Interp.Linear: + xs = x - x0; + ys = y - y0; + zs = z - z0; + break; + case Interp.Hermite: + xs = InterpHermiteFunc(x - x0); + ys = InterpHermiteFunc(y - y0); + zs = InterpHermiteFunc(z - z0); + break;*/ + case Interp.Quintic: + xs = InterpQuinticFunc(x - x0); + ys = InterpQuinticFunc(y - y0); + zs = InterpQuinticFunc(z - z0); + break; + } + + FN_DECIMAL xd0 = x - x0; + FN_DECIMAL yd0 = y - y0; + FN_DECIMAL zd0 = z - z0; + FN_DECIMAL xd1 = xd0 - 1.0f; + FN_DECIMAL yd1 = yd0 - 1.0f; + FN_DECIMAL zd1 = zd0 - 1.0f; + + FN_DECIMAL xf00 = Lerp(GradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), GradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs); + FN_DECIMAL xf10 = Lerp(GradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), GradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs); + FN_DECIMAL xf01 = Lerp(GradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), GradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs); + FN_DECIMAL xf11 = Lerp(GradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), GradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs); + + FN_DECIMAL yf0 = Lerp(xf00, xf10, ys); + FN_DECIMAL yf1 = Lerp(xf01, xf11, ys); + + return Lerp(yf0, yf1, zs); + } + + [BurstCompile] + public static FN_DECIMAL SimplexGetNoise(FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, int seed) + { + FN_DECIMAL t = (x + y + z) * F3; + int i = FastFloor(x + t); + int j = FastFloor(y + t); + int k = FastFloor(z + t); + + t = (i + j + k) * G3; + FN_DECIMAL X0 = i - t; + FN_DECIMAL Y0 = j - t; + FN_DECIMAL Z0 = k - t; + + FN_DECIMAL x0 = x - X0; + FN_DECIMAL y0 = y - Y0; + FN_DECIMAL z0 = z - Z0; + + int i1, j1, k1; + int i2, j2, k2; + + if (x0 >= y0) + { + if (y0 >= z0) + { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } + else if (x0 >= z0) + { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 0; + k2 = 1; + } + else // x0 < z0 + { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 1; + j2 = 0; + k2 = 1; + } + } + else // x0 < y0 + { + if (y0 < z0) + { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 0; + j2 = 1; + k2 = 1; + } + else if (x0 < z0) + { + i1 = 0; + j1 = 1; + k1 = 0; + i2 = 0; + j2 = 1; + k2 = 1; + } + else // x0 >= z0 + { + i1 = 0; + j1 = 1; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } + } + + FN_DECIMAL x1 = x0 - i1 + G3; + FN_DECIMAL y1 = y0 - j1 + G3; + FN_DECIMAL z1 = z0 - k1 + G3; + FN_DECIMAL x2 = x0 - i2 + 2.0f * G3; + FN_DECIMAL y2 = y0 - j2 + 2.0f * G3; + FN_DECIMAL z2 = z0 - k2 + 2.0f * G3; + FN_DECIMAL x3 = x0 - 1.0f + 3.0f * G3; + FN_DECIMAL y3 = y0 - 1.0f + 3.0f * G3; + FN_DECIMAL z3 = z0 - 1.0f + 3.0f * G3; + + FN_DECIMAL n0, n1, n2, n3; + + t = 0.6f - x0 * x0 - y0 * y0 - z0 * z0; + if (t < 0.0f) + { + n0 = 0.0f; + } + else + { + t *= t; + n0 = t * t * GradCoord3D(seed, i, j, k, x0, y0, z0); + } + + t = 0.6f - x1 * x1 - y1 * y1 - z1 * z1; + if (t < 0.0f) + { + n1 = 0.0f; + } + else + { + t *= t; + n1 = t * t * GradCoord3D(seed, i + i1, j + j1, k + k1, x1, y1, z1); + } + + t = 0.6f - x2 * x2 - y2 * y2 - z2 * z2; + if (t < 0.0f) + { + n2 = 0.0f; + } + else + { + t *= t; + n2 = t * t * GradCoord3D(seed, i + i2, j + j2, k + k2, x2, y2, z2); + } + + t = 0.6f - x3 * x3 - y3 * y3 - z3 * z3; + if (t < 0.0f) + { + n3 = 0.0f; + } + else + { + t *= t; + n3 = t * t * GradCoord3D(seed, i + 1, j + 1, k + 1, x3, y3, z3); + } + + return 32.0f * (n0 + n1 + n2 + n3); + } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static int FastFloor(FN_DECIMAL f) + { + return f >= 0 ? (int)f : (int)f - 1; + } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static FN_DECIMAL GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd) + { + int hash = Hash(seed, xPrimed, yPrimed); + hash ^= hash >> 15; + hash &= 127 << 1; + + float xg = Gradients2D[hash]; + float yg = Gradients2D[hash | 1]; + + return xd * xg + yd * yg; + } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static FN_DECIMAL GradCoord3D(int seed, int x, int y, int z, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd) + { + int hash = seed; + hash ^= PrimeX * x; + hash ^= PrimeY * y; + hash ^= PrimeZ * z; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + hash &= 15; + FN_DECIMAL u = hash < 8 ? xd : yd; // gradient directions, and compute dot product. + FN_DECIMAL v = hash < 4 ? yd : hash == 12 || hash == 14 ? xd : zd; // Fix repeats at h = 12 to 15 + return ((hash & 1) != 0 ? -u : u) + ((hash & 2) != 0 ? -v : v); + } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static int Hash(int seed, int xPrimed, int yPrimed) + { + int hash = seed ^ xPrimed ^ yPrimed; + + hash *= 0x27d4eb2d; + return hash; + } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static FN_DECIMAL Lerp(FN_DECIMAL a, FN_DECIMAL b, FN_DECIMAL t) { return a + t * (b - a); } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static FN_DECIMAL InterpHermiteFunc(FN_DECIMAL t) { return t * t * (3 - 2 * t); } + +#if !FN_DISABLE_AGGRESSIVE_INLINING + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + private static FN_DECIMAL InterpQuinticFunc(FN_DECIMAL t) { return t * t * t * (t * (t * 6 - 15) + 10); } + + + static readonly FN_DECIMAL[] Gradients2D = + { + 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, + 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, + 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, + -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, + 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, + -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, + -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, + -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, + -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, + 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, + -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, + 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, + 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, + 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, + 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, + -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, + 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, + -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, + -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, + -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, + -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, + 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, + -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, + 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, + 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, + 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, + 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, + -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, + 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, + -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, + -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, + -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, + -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, + 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, + -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, + 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, + 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, + 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, + 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, + -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, + 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, + -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, + -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, + -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, + -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, + 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, + -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, + 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, + 0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, + 0.793353340291235f, 0.793353340291235f, 0.608761429008721f, + 0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, + -0.130526192220051f, 0.923879532511287f, -0.38268343236509f, + 0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, + -0.923879532511287f, 0.130526192220052f, -0.99144486137381f, + -0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, + -0.793353340291235f, -0.793353340291235f, -0.608761429008721f, + -0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, + 0.130526192220051f, -0.923879532511287f, 0.38268343236509f, + -0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, + 0.923879532511287f, -0.130526192220052f, 0.99144486137381f, + 0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, + -0.38268343236509f, 0.38268343236509f, -0.923879532511287f, + -0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, + 0.38268343236509f, -0.38268343236509f, 0.923879532511287f, + }; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ThirdParty/CustomFastPerlin.cs.meta b/Assets/Scripts/ThirdParty/FastNoise.cs.meta similarity index 100% rename from Assets/Scripts/ThirdParty/CustomFastPerlin.cs.meta rename to Assets/Scripts/ThirdParty/FastNoise.cs.meta diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 333b4b7f..fb5ea04f 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -823,7 +823,7 @@ PlayerSettings: tvOS: 1 incrementalIl2cppBuild: {} suppressCommonWarnings: 1 - allowUnsafeCode: 0 + allowUnsafeCode: 1 useDeterministicCompilation: 1 additionalIl2CppArgs: scriptingRuntimeVersion: 1