├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── CHANGELOG.md ├── CHANGELOG.md.meta ├── Documentation ├── ClusterLayers.png ├── ClusterMazeLayer.png ├── ClusterRevealedArtefactArea.gif ├── ClusterRoadSigns.png ├── ClusterTopDownMazeLayer.png ├── ClusterTopDownRegionLayer.png ├── ContextualGeneration.md ├── ContextualLayers.png ├── ContextualTransition.gif ├── DAG.png ├── Doxyfile ├── EffectDistance.md ├── EffectDistanceChunkAndRadius.png ├── Functional.png ├── FunctionalChunkWithoutContext.png ├── FunctionalLimitationCaves.png ├── FunctionalLimitationTooWideGap.png ├── GettingStarted.md ├── ImageSources │ ├── PaddingBlur.afphoto │ ├── PaddingBlurIterations.afphoto │ ├── PaddingPathfinding.afphoto │ ├── PaddingRelaxation.afphoto │ ├── UserAndProviderChunks.afphoto │ ├── _InternalLayerLevels.png │ ├── _MultipleTopLayerDependencies.png │ ├── _NotUsed_ContextualPaths.png │ └── _NotUsed_ContextualPathsAcrossChunks.png ├── InternalLayerLevels.md ├── InternalLayerLevels.png ├── LayerDependencies.md ├── LayerProcGenLogo.png ├── LayerProcGenLogoSmall.png ├── LayersAndChunks.md ├── MultipleTopLayerDependencies.png ├── PaddingBlur.png ├── PaddingBlurIterations.png ├── PaddingPathfinding.png ├── Patterns.md ├── Planning.png ├── PlanningAtScale.md ├── PlanningRoguelike.png ├── ProviderChunks.png ├── README.md ├── RunevisionAssemblies.png ├── ScriptTemplates.md ├── UserChunk.png ├── UsingWithoutUnity.md ├── Utilities.md └── doxygen-awesome-css │ ├── LICENSE │ ├── doxygen-awesome-sidebar-only.css │ └── doxygen-awesome.css ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── Samples ├── SimpleSamples │ ├── PointsScene.unity │ ├── PointsScene.unity.meta │ ├── PointsSpawningScene.unity │ ├── PointsSpawningScene.unity.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── PointsLayer.cs │ │ ├── PointsLayer.cs.meta │ │ ├── PointsSpawningLayer.cs │ │ └── PointsSpawningLayer.cs.meta └── TerrainSample │ ├── Data.meta │ ├── Data │ ├── InputControls.inputactions │ ├── InputControls.inputactions.meta │ ├── LightingSettings.lighting │ ├── LightingSettings.lighting.meta │ ├── Resources.meta │ ├── Resources │ │ ├── TerrainResources.asset │ │ └── TerrainResources.asset.meta │ ├── TerrainDummy.asset │ ├── TerrainDummy.asset.meta │ ├── TerrainDummy.prefab │ ├── TerrainDummy.prefab.meta │ ├── TerrainDummy.unity │ └── TerrainDummy.unity.meta │ ├── FirstPersonController.prefab │ ├── FirstPersonController.prefab.meta │ ├── Materials.meta │ ├── Materials │ ├── Cliff.png │ ├── Cliff.png.meta │ ├── Grass.png │ ├── Grass.png.meta │ ├── GrassDetail.png │ ├── GrassDetail.png.meta │ ├── Path.png │ ├── Path.png.meta │ ├── Skybox.mat │ ├── Skybox.mat.meta │ ├── TerrainMaterial.mat │ └── TerrainMaterial.mat.meta │ ├── Scripts.meta │ ├── Scripts │ ├── Behaviors.meta │ ├── Behaviors │ │ ├── FirstPersonController.cs │ │ ├── FirstPersonController.cs.meta │ │ ├── MouseLook.cs │ │ ├── MouseLook.cs.meta │ │ ├── WaitForGround.cs │ │ └── WaitForGround.cs.meta │ ├── Generation.meta │ ├── Generation │ │ ├── Layers.meta │ │ ├── Layers │ │ │ ├── CultivationLayer.cs │ │ │ ├── CultivationLayer.cs.meta │ │ │ ├── GeoGridLayer.cs │ │ │ ├── GeoGridLayer.cs.meta │ │ │ ├── LandscapeLayer.cs │ │ │ ├── LandscapeLayer.cs.meta │ │ │ ├── LocationLayer.cs │ │ │ ├── LocationLayer.cs.meta │ │ │ ├── PlayLayer.cs │ │ │ └── PlayLayer.cs.meta │ │ ├── PriorityQueue.cs │ │ ├── PriorityQueue.cs.meta │ │ ├── TerrainLODManager.cs │ │ ├── TerrainLODManager.cs.meta │ │ ├── TerrainObjects.meta │ │ ├── TerrainObjects │ │ │ ├── DeformationSpec.cs │ │ │ ├── DeformationSpec.cs.meta │ │ │ ├── LocationSpec.cs │ │ │ ├── LocationSpec.cs.meta │ │ │ ├── PathSpec.cs │ │ │ ├── PathSpec.cs.meta │ │ │ ├── TerrainDeformation.cs │ │ │ ├── TerrainDeformation.cs.meta │ │ │ ├── TerrainDeformationMethod.cs │ │ │ ├── TerrainDeformationMethod.cs.meta │ │ │ ├── TerrainNoise.cs │ │ │ ├── TerrainNoise.cs.meta │ │ │ ├── TerrainPathFinder.cs │ │ │ └── TerrainPathFinder.cs.meta │ │ ├── TerrainResources.cs │ │ └── TerrainResources.cs.meta │ ├── Utilities.meta │ └── Utilities │ │ ├── DebugGUI.cs │ │ ├── DebugGUI.cs.meta │ │ ├── Maths.cs │ │ ├── Maths.cs.meta │ │ ├── NativeArrayCopyExtensions.cs │ │ ├── NativeArrayCopyExtensions.cs.meta │ │ ├── PointerArray.cs │ │ ├── PointerArray.cs.meta │ │ ├── SingletonAsset.cs │ │ └── SingletonAsset.cs.meta │ ├── TerrainScene.unity │ └── TerrainScene.unity.meta ├── Src ├── Common.meta ├── Common │ ├── CollectionExtensions.cs │ ├── CollectionExtensions.cs.meta │ ├── Crd.cs │ ├── Crd.cs.meta │ ├── Debugging.meta │ ├── Debugging │ │ ├── DebugOption.cs │ │ ├── DebugOption.cs.meta │ │ ├── Logg.cs │ │ ├── Logg.cs.meta │ │ ├── SimpleProfiler.cs │ │ └── SimpleProfiler.cs.meta │ ├── GridBounds.cs │ ├── GridBounds.cs.meta │ ├── GridBounds3.cs │ ├── GridBounds3.cs.meta │ ├── Pools.meta │ ├── Pools │ │ ├── ArrayPool.cs │ │ ├── ArrayPool.cs.meta │ │ ├── IPool.cs │ │ ├── IPool.cs.meta │ │ ├── IPoolable.cs │ │ ├── IPoolable.cs.meta │ │ ├── ListPool.cs │ │ ├── ListPool.cs.meta │ │ ├── ObjectPool.cs │ │ ├── ObjectPool.cs.meta │ │ ├── PoolManager.cs │ │ └── PoolManager.cs.meta │ ├── RandomHash.cs │ ├── RandomHash.cs.meta │ ├── Runevision.Common.asmdef │ ├── Runevision.Common.asmdef.meta │ ├── TypeExtensions.cs │ └── TypeExtensions.cs.meta ├── Interop.meta ├── Interop │ ├── Independent.meta │ ├── Independent │ │ ├── DFloat.cs │ │ ├── DFloat.cs.meta │ │ ├── DPoint.cs │ │ ├── DPoint.cs.meta │ │ ├── DPoint3.cs │ │ ├── DPoint3.cs.meta │ │ ├── IBinarySerializable.cs │ │ ├── IBinarySerializable.cs.meta │ │ ├── Point.cs │ │ ├── Point.cs.meta │ │ ├── Point3.cs │ │ └── Point3.cs.meta │ ├── Runevision.Interop.asmdef │ ├── Runevision.Interop.asmdef.meta │ ├── UnitySpecific.meta │ └── UnitySpecific │ │ ├── DPoint3Unity.cs │ │ ├── DPoint3Unity.cs.meta │ │ ├── DPointUnity.cs │ │ ├── DPointUnity.cs.meta │ │ ├── Point3Unity.cs │ │ ├── Point3Unity.cs.meta │ │ ├── PointUnity.cs │ │ └── PointUnity.cs.meta ├── LayerProcGen.meta ├── LayerProcGen │ ├── AbstractDataLayer.cs │ ├── AbstractDataLayer.cs.meta │ ├── ChunkBasedDataLayer.cs │ ├── ChunkBasedDataLayer.cs.meta │ ├── LayerChunk.cs │ ├── LayerChunk.cs.meta │ ├── LayerDependency.cs │ ├── LayerDependency.cs.meta │ ├── LayerManager.cs │ ├── LayerManager.cs.meta │ ├── LayerNamedReference.cs │ ├── LayerNamedReference.cs.meta │ ├── MainThreadActionQueue.cs │ ├── MainThreadActionQueue.cs.meta │ ├── RollingGrid.cs │ ├── RollingGrid.cs.meta │ ├── Runevision.LayerProcGen.asmdef │ ├── Runevision.LayerProcGen.asmdef.meta │ ├── TopLayerDependency.cs │ ├── TopLayerDependency.cs.meta │ ├── WorkTracker.cs │ └── WorkTracker.cs.meta ├── SaveState.meta ├── SaveState │ ├── Runevision.SaveState.asmdef │ ├── Runevision.SaveState.asmdef.meta │ ├── StateObject.cs │ ├── StateObject.cs.meta │ ├── StateWrapper.cs │ ├── StateWrapper.cs.meta │ ├── WorldState.cs │ ├── WorldState.cs.meta │ ├── WorldStateBinary.cs │ ├── WorldStateBinary.cs.meta │ ├── WorldStateLocal.cs │ └── WorldStateLocal.cs.meta ├── Unity.meta └── Unity │ ├── Common.meta │ ├── Common │ ├── CallbackHub.cs │ ├── CallbackHub.cs.meta │ ├── DebugDrawer.cs │ ├── DebugDrawer.cs.meta │ ├── DebugOptions.cs │ ├── DebugOptions.cs.meta │ ├── ForwardingUnityWrapper.cs │ ├── ForwardingUnityWrapper.cs.meta │ ├── GLlineZOff.shader │ ├── GLlineZOff.shader.meta │ ├── GLlineZOn.shader │ ├── GLlineZOn.shader.meta │ ├── RunevisionUnityExtensions.cs │ └── RunevisionUnityExtensions.cs.meta │ ├── Editor.meta │ ├── Editor │ ├── DebugOptionsWindow.cs │ ├── DebugOptionsWindow.cs.meta │ ├── GenerationSourceEditor.cs │ ├── GenerationSourceEditor.cs.meta │ ├── GridBounds3Drawer.cs │ ├── GridBounds3Drawer.cs.meta │ ├── GridBoundsDrawer.cs │ ├── GridBoundsDrawer.cs.meta │ ├── LayerNamedReferenceDrawer.cs │ ├── LayerNamedReferenceDrawer.cs.meta │ ├── LayerSpecDrawer.cs │ ├── LayerSpecDrawer.cs.meta │ ├── Point3Drawer.cs │ ├── Point3Drawer.cs.meta │ ├── PointDrawer.cs │ ├── PointDrawer.cs.meta │ ├── UnitTests.meta │ ├── UnitTests │ │ ├── MathTests.cs │ │ └── MathTests.cs.meta │ ├── _Editor.asmdef │ └── _Editor.asmdef.meta │ ├── LayerProcGen.meta │ ├── LayerProcGen │ ├── GameObjectDestruction.cs │ ├── GameObjectDestruction.cs.meta │ ├── GenerationSource.cs │ ├── GenerationSource.cs.meta │ ├── LayerManagerBehavior.cs │ ├── LayerManagerBehavior.cs.meta │ ├── TransformWrapper.cs │ ├── TransformWrapper.cs.meta │ ├── VisualizationManager.cs │ └── VisualizationManager.cs.meta │ ├── Runevision.Unity.asmdef │ ├── Runevision.Unity.asmdef.meta │ ├── SaveState.meta │ └── SaveState │ ├── FBPPChooser.cs │ ├── FBPPChooser.cs.meta │ ├── FileBasedPlayerPrefs.meta │ ├── FileBasedPlayerPrefs │ ├── LICENSE.md │ ├── LICENSE.md.meta │ ├── README.md │ ├── README.md.meta │ ├── Runtime.meta │ └── Runtime │ │ ├── FBPP.cs │ │ ├── FBPP.cs.meta │ │ ├── FBPPConfig.cs │ │ ├── FBPPConfig.cs.meta │ │ ├── FBPPSaveFileModel.cs │ │ └── FBPPSaveFileModel.cs.meta │ ├── WorldStateFBPP.cs │ └── WorldStateFBPP.cs.meta ├── Third Party Notices.md ├── Third Party Notices.md.meta └── upm_release.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # GitHub action to publish Doxygen-based documentation 2 | 3 | name: Generate and deploy Doxygen documentation 4 | 5 | # Controls when the action will run. Triggers the workflow on push or pull request 6 | # events but only for the master branch 7 | on: 8 | push: 9 | branches: [ main ] 10 | 11 | permissions: 12 | contents: write 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | # This workflow contains a single job called "build" 17 | build: 18 | # The type of runner that the job will run on 19 | runs-on: ubuntu-latest 20 | 21 | # Steps represent a sequence of tasks that will be executed as part of the job 22 | steps: 23 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 24 | - uses: actions/checkout@v3 25 | 26 | - name: Generate Doxygen documentation 27 | uses: mattnotmitt/doxygen-action@v1.1.0 28 | with: 29 | # Working directory 30 | working-directory: "Documentation/" # default is . 31 | # Path to Doxyfile 32 | doxyfile-path: "./Doxyfile" # default is ./Doxyfile 33 | 34 | - name: Deploy documentation to gh-pages 35 | uses: peaceiris/actions-gh-pages@v3 36 | with: 37 | github_token: ${{ secrets.GITHUB_TOKEN }} 38 | # Default Doxyfile build documentation to html directory. 39 | # Change the directory if changes in Doxyfile. Original was ./html 40 | publish_dir: ./docs 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mercurial version control data 2 | .hg* 3 | 4 | # Visual Studio cache directory 5 | .vs/ 6 | 7 | # Gradle cache directory 8 | .gradle/ 9 | 10 | # Generated docs 11 | docs/ 12 | 13 | # Autogenerated VS/MD/Consulo solution and project files 14 | ExportedObj/ 15 | .consulo/ 16 | *.csproj 17 | *.unityproj 18 | *.sln 19 | *.suo 20 | *.tmp 21 | *.user 22 | *.userprefs 23 | *.pidb 24 | *.booproj 25 | *.svd 26 | *.pdb 27 | *.mdb 28 | *.opendb 29 | *.VC.db 30 | obj/ 31 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 4 | ## 0.3.0 - 2024-12-07 5 | 6 | ### Fixed 7 | 8 | - Fixed bug that chunk level parameter passed to ChunkBasedDataLayer.IsLoadedAtPosition was not being used. 9 | - Fixed regression bug introduced in 0.2.0 which caused the GenerationSource component to not start generating until moved, if initially at position (0,0). 10 | 11 | 12 | ## 0.2.0 - 2024-07-08 13 | 14 | ### Added 15 | 16 | - Made TransformWrapper setting child to same layer as parent optional. 17 | - Made Point and Point3 implement IBinarySerializable. 18 | - Added doc note to SimpleProfiler. 19 | 20 | ### Changed 21 | 22 | - Implemented WorldState system overhaul. 23 | - Made StateObject be more generic by taking hash value instead of point and type. 24 | - Made saving and loading global values avoid allocations. 25 | - Made WorldState store state as dictionaries of raw structs instead of as StateWrappers. 26 | 27 | ### Fixed 28 | 29 | - Fixed bug that the chunk Reset method didn't clear saved state objects. 30 | - Removed erroneous script asset default references added by Unity which Unity logged errors about. 31 | - Made layer visualization animated transitions update unaffected by time-scale. 32 | - Made GenerationSource not set TopLayerDependency position and size unless changed. 33 | 34 | 35 | ## 0.1.1 - 2024-05-27 36 | 37 | ### Changed 38 | 39 | - Rename assembly definition files to match their specified names. 40 | 41 | ### Fixed 42 | 43 | - Fix terrain sample splat handling accessing heights array out of bounds. 44 | 45 | 46 | ## 0.1.0 - 2024-05-23 47 | 48 | - Initial public pre-release. 49 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce1e11743db344da5857e8726a5faa11 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Documentation/ClusterLayers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ClusterLayers.png -------------------------------------------------------------------------------- /Documentation/ClusterMazeLayer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ClusterMazeLayer.png -------------------------------------------------------------------------------- /Documentation/ClusterRevealedArtefactArea.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ClusterRevealedArtefactArea.gif -------------------------------------------------------------------------------- /Documentation/ClusterRoadSigns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ClusterRoadSigns.png -------------------------------------------------------------------------------- /Documentation/ClusterTopDownMazeLayer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ClusterTopDownMazeLayer.png -------------------------------------------------------------------------------- /Documentation/ClusterTopDownRegionLayer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ClusterTopDownRegionLayer.png -------------------------------------------------------------------------------- /Documentation/ContextualLayers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ContextualLayers.png -------------------------------------------------------------------------------- /Documentation/ContextualTransition.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ContextualTransition.gif -------------------------------------------------------------------------------- /Documentation/DAG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/DAG.png -------------------------------------------------------------------------------- /Documentation/EffectDistanceChunkAndRadius.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/EffectDistanceChunkAndRadius.png -------------------------------------------------------------------------------- /Documentation/Functional.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/Functional.png -------------------------------------------------------------------------------- /Documentation/FunctionalChunkWithoutContext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/FunctionalChunkWithoutContext.png -------------------------------------------------------------------------------- /Documentation/FunctionalLimitationCaves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/FunctionalLimitationCaves.png -------------------------------------------------------------------------------- /Documentation/FunctionalLimitationTooWideGap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/FunctionalLimitationTooWideGap.png -------------------------------------------------------------------------------- /Documentation/ImageSources/PaddingBlur.afphoto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/PaddingBlur.afphoto -------------------------------------------------------------------------------- /Documentation/ImageSources/PaddingBlurIterations.afphoto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/PaddingBlurIterations.afphoto -------------------------------------------------------------------------------- /Documentation/ImageSources/PaddingPathfinding.afphoto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/PaddingPathfinding.afphoto -------------------------------------------------------------------------------- /Documentation/ImageSources/PaddingRelaxation.afphoto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/PaddingRelaxation.afphoto -------------------------------------------------------------------------------- /Documentation/ImageSources/UserAndProviderChunks.afphoto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/UserAndProviderChunks.afphoto -------------------------------------------------------------------------------- /Documentation/ImageSources/_InternalLayerLevels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/_InternalLayerLevels.png -------------------------------------------------------------------------------- /Documentation/ImageSources/_MultipleTopLayerDependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/_MultipleTopLayerDependencies.png -------------------------------------------------------------------------------- /Documentation/ImageSources/_NotUsed_ContextualPaths.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/_NotUsed_ContextualPaths.png -------------------------------------------------------------------------------- /Documentation/ImageSources/_NotUsed_ContextualPathsAcrossChunks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ImageSources/_NotUsed_ContextualPathsAcrossChunks.png -------------------------------------------------------------------------------- /Documentation/InternalLayerLevels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/InternalLayerLevels.png -------------------------------------------------------------------------------- /Documentation/LayerProcGenLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/LayerProcGenLogo.png -------------------------------------------------------------------------------- /Documentation/LayerProcGenLogoSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/LayerProcGenLogoSmall.png -------------------------------------------------------------------------------- /Documentation/LayersAndChunks.md: -------------------------------------------------------------------------------- 1 | # Layers and Chunks 2 | 3 | You implement pairs of layers and chunks, e.g. ExampleLayer and ExampleChunk. A layer contains chunks of the corresponding type. 4 | 5 | ## Layer and chunk classes 6 | 7 | A layer class must inherit from `ChunkBasedDataLayer` and a chunk class must inherit from `LayerChunk`. Both of those base classes must be used with generic type parameters of the layer and chunk themselves, e.g. ``. 8 | 9 | Here is a simplified example. See the [Script Templates](ScriptTemplates.md) page for more complete templates or the [Getting Started](GettingStarted.md) page for a simple working example. 10 | 11 | ```cs 12 | public class ExampleChunk : LayerChunk { 13 | // Data for this chunk goes here. 14 | 15 | public override void Create(int level, bool destroy) { 16 | // Generate or destroy data here. 17 | } 18 | } 19 | 20 | public class ExampleLayer : ChunkBasedDataLayer { 21 | // Specify the world space dimensions of the chunks. 22 | public override int chunkW { get { return 256; } } 23 | public override int chunkH { get { return 256; } } 24 | 25 | public ExampleLayer() { 26 | // Dependencies on other layers are set up here. 27 | } 28 | 29 | // APIs for requesting data from this layer go here. 30 | } 31 | ``` 32 | 33 | Each layer stores a [RollingGrid](#Runevision.LayerProcGen.RollingGrid) of corresponding chunks. This is automatically handled by the layer base class, though you can optionally specify the size of the grid in the base class constructor. 34 | 35 | ## Chunk size 36 | 37 | Chunks are always rectangular and all chunks in a given layer have the same world space size. This size is specified in the layer by overriding the two properties `chunkW` and `chunkH`. 38 | 39 | The size is specified in integers, meaning the smallest possible size is one unit, but apart from that, chunks can have any size. 40 | 41 | ```cs 42 | // Specify the world space dimensions of the chunks. 43 | public override int chunkW { get { return 256; } } 44 | public override int chunkH { get { return 256; } } 45 | ``` 46 | 47 | There is also a convenience property `chunkSize` of type [Point](#Runevision.Common.Point) which combines the width and height. 48 | 49 | ## Chunk lifetime 50 | 51 | A chunk is generated (invoking its generation code) when it’s depended on, and it's destroyed (recycled) when it’s no longer depended on. 52 | 53 | ```cs 54 | // Chunk Create method where the generation happens. 55 | public override void Create(int level, bool destroy) { 56 | if (destroy) { 57 | // Destroy data for this chunk here. 58 | } 59 | else { 60 | // Create data for this chunk here. 61 | } 62 | } 63 | ``` 64 | 65 | The following pages will cover how to setup layer dependencies that allow chunks to request data from other layers, as well as the concept of internal layer levels, which is a special and optional concept where a single class can implement multiple layers at once. 66 | -------------------------------------------------------------------------------- /Documentation/MultipleTopLayerDependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/MultipleTopLayerDependencies.png -------------------------------------------------------------------------------- /Documentation/PaddingBlur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/PaddingBlur.png -------------------------------------------------------------------------------- /Documentation/PaddingBlurIterations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/PaddingBlurIterations.png -------------------------------------------------------------------------------- /Documentation/PaddingPathfinding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/PaddingPathfinding.png -------------------------------------------------------------------------------- /Documentation/Planning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/Planning.png -------------------------------------------------------------------------------- /Documentation/PlanningRoguelike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/PlanningRoguelike.png -------------------------------------------------------------------------------- /Documentation/ProviderChunks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/ProviderChunks.png -------------------------------------------------------------------------------- /Documentation/RunevisionAssemblies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/RunevisionAssemblies.png -------------------------------------------------------------------------------- /Documentation/UserChunk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Documentation/UserChunk.png -------------------------------------------------------------------------------- /Documentation/UsingWithoutUnity.md: -------------------------------------------------------------------------------- 1 | ## Using Without Unity 2 | 3 | Although only tested in Unity, LayerProcGen is designed to run in any C#-compatible engine by having the core framework not depend on any Unity assemblies or API. 4 | 5 | The contents of these folders depend on Unity API and can be removed: 6 | 7 | * Unity 8 | * Interop/UnitySpecific 9 | 10 | Here is a diagram of the assemblies and the dependencies between them: 11 | 12 | ![Diagram of Runevision assemblies.](RunevisionAssemblies.png) 13 | 14 | The Interop/UnitySpecific folder is just conversions between LayerProcGen types and Unity types like Vector2 and Vector3. Even without removing it, the code should still compile outside of Unity since Unity-dependent parts are wrapped in #if UNITY_2019_4_OR_NEWER. 15 | 16 | The Unity folder contains Unity engine hooks and utilities in a variety of classes as noted below. Some of these may be useful as reference points if you wish to implement equivalent functionality in another engine. 17 | 18 | ## Unity-specific classes 19 | 20 | There are Unity components serving as wrapper classes which ensure central objects are created. 21 | 22 | * `GenerationSource`: A Unity component that sets up a TopLayerDependency. In other engines, TopLayerDependency objects must be setup by other means. 23 | * `LayerManagerBehavior`: A Unity component that wraps the central LayerManager class. In other engines, a LayerManager object must be created by other means. 24 | * `ForwardingUnityWrapper`: A static class that forwards log messages from the framework's Logg class to Unity's Debug.Log API and forwards certain calls from the framework's SimpleProfiler class to Unity's Profiler API. 25 | 26 | There are a few classes that assist with handling lifetime of Unity Objects across the boundary between generation threads and the main thread. No equivalent may be needed in other engines if they allow engine object manipulation outside of the main thread. 27 | 28 | * `TransformWrapper`: This class assists with scheduling object instantiations on the main thread under a given parent Transform. 29 | * `QueuedGameObjectDestruction`: A struct that implements IQueuedAction and can be scheduled on the MainThreadActionQueue to destroy all GameObjects under a specific TransformWrapper. 30 | 31 | Furthermore there are some non-critical but still useful utilities that have fully or partially Unity-dependent implementations. See the [Utilities](Utilities.md) page for details on which ones. 32 | -------------------------------------------------------------------------------- /Documentation/Utilities.md: -------------------------------------------------------------------------------- 1 | # Utilities 2 | 3 | LayerProcGen comes with a handful of utilities. The ones in the Runevision.LayerProcGen namespace relate to layer based generation specifically, while those in the Runevision.Common namespace are more general-purpose. 4 | 5 | ## LayerProcGen-specific utilities 6 | 7 | ### Visualization Manager 8 | 9 | (Unity-only for now) [VisualizationManager](#Runevision.LayerProcGen.VisualizationManager) is a manager for displaying various visualizations of the data layers. 10 | 11 | ## General-purpose utilities 12 | 13 | ### Debug Options 14 | 15 | The [DebugOption](#Runevision.Common.DebugOption) class and related classes is a system for quickly specifying debug options. Most of it is Unity-independent (specification and usage in code, and how the options self-assemble into a hierarchy), while the simple code that displays the controls is Unity-specific. 16 | 17 | ### Object Pools 18 | 19 | The [IPool](#Runevision.Common.IPool) interface represents an object pool that poolable objects can be retrieved from and returned to. It's implemented by [ObjectPool](#Runevision.Common.ObjectPool), [ArrayPool](#Runevision.Common.ArrayPool), [Array2DPool](#Runevision.Common.Array2DPool), [Array3DPool](#Runevision.Common.Array3DPool) and [ListPool](#Runevision.Common.ListPool). 20 | 21 | ### Simple Profiler 22 | 23 | [SimpleProfiler](#Runevision.Common.SimpleProfiler) is a simple tool for measuring execution time of generation processes. It's used by the LayerManager. 24 | 25 | ### Logg 26 | 27 | [Logg](#Runevision.Common.Logg) is a simple Unity-independent wrapper for logging messages, warnings and errors. 28 | 29 | ### Debug Drawer 30 | 31 | (Unity-only for now) [DebugDrawer](#Runevision.Common.DebugDrawer) is a utility for drawing lines for debug visualizations. 32 | -------------------------------------------------------------------------------- /Documentation/doxygen-awesome-css/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 - 2023 jothepro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Documentation/doxygen-awesome-css/doxygen-awesome-sidebar-only.css: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Doxygen Awesome 4 | https://github.com/jothepro/doxygen-awesome-css 5 | 6 | MIT License 7 | 8 | Copyright (c) 2021 - 2023 jothepro 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | */ 29 | 30 | html { 31 | /* side nav width. MUST be = `TREEVIEW_WIDTH`. 32 | * Make sure it is wide enough to contain the page title (logo + title + version) 33 | */ 34 | --side-nav-fixed-width: 340px; 35 | --menu-display: none; 36 | 37 | --top-height: 120px; 38 | --toc-sticky-top: -25px; 39 | --toc-max-height: calc(100vh - 2 * var(--spacing-medium) - 25px); 40 | } 41 | 42 | #projectname { 43 | white-space: nowrap; 44 | } 45 | 46 | 47 | @media screen and (min-width: 768px) { 48 | html { 49 | --searchbar-background: var(--page-background-color); 50 | } 51 | 52 | #side-nav { 53 | min-width: var(--side-nav-fixed-width); 54 | max-width: var(--side-nav-fixed-width); 55 | top: var(--top-height); 56 | overflow: visible; 57 | } 58 | 59 | #nav-tree, #side-nav { 60 | height: calc(100vh - var(--top-height)) !important; 61 | } 62 | 63 | #nav-tree { 64 | padding: 0; 65 | } 66 | 67 | #top { 68 | display: block; 69 | border-bottom: none; 70 | height: var(--top-height); 71 | margin-bottom: calc(0px - var(--top-height)); 72 | max-width: var(--side-nav-fixed-width); 73 | overflow: hidden; 74 | background: var(--side-nav-background); 75 | } 76 | #main-nav { 77 | float: left; 78 | padding-right: 0; 79 | } 80 | 81 | .ui-resizable-handle { 82 | cursor: default; 83 | width: 1px !important; 84 | background: var(--separator-color); 85 | box-shadow: 0 calc(-2 * var(--top-height)) 0 0 var(--separator-color); 86 | } 87 | 88 | #nav-path { 89 | position: fixed; 90 | right: 0; 91 | left: var(--side-nav-fixed-width); 92 | bottom: 0; 93 | width: auto; 94 | } 95 | 96 | #doc-content { 97 | height: calc(100vh - 31px) !important; 98 | padding-bottom: calc(3 * var(--spacing-large)); 99 | padding-top: calc(var(--top-height) - 80px); 100 | box-sizing: border-box; 101 | margin-left: var(--side-nav-fixed-width) !important; 102 | } 103 | 104 | #MSearchBox { 105 | width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium))); 106 | } 107 | 108 | #MSearchField { 109 | width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - 65px); 110 | } 111 | 112 | #MSearchResultsWindow { 113 | left: var(--spacing-medium) !important; 114 | right: auto; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14d92e9b014dd4445a5dc546f01bd132 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27afcacea37914d4d92635961fb410ec 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/PointsScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d5951da1c392540cabc819156a13accc 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/PointsSpawningScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1d13af568bdd47abb2bfd325f2e1778 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d3f65fa901a9b403aac18d3bc66c04f6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/Scripts/PointsLayer.cs: -------------------------------------------------------------------------------- 1 | using Runevision.Common; 2 | using Runevision.LayerProcGen; 3 | using System.Collections.Generic; 4 | 5 | public class PointsChunk : LayerChunk { 6 | // Data for this chunk goes here. 7 | // This could be any data structure, a List of points is just an example. 8 | public List pointList = new List(); 9 | 10 | public override void Create(int level, bool destroy) { 11 | if (destroy) { 12 | // Destroy data for this chunk here. 13 | // Chunk objects are reused so keep data structures if possible 14 | // in order to avoid continuous memory allocations. 15 | pointList.Clear(); 16 | } 17 | else { 18 | // Create data for this chunk here. 19 | for (int i = 0; i < 3; i++) { 20 | // bounds and index are useful properties of the base LayerChunk class. 21 | Point point = new Point( 22 | // The first two Range arguments specify the range. 23 | // The remaining arguments are input for the hash function. 24 | layer.rand.Range(bounds.min.x, bounds.max.x, index.x, index.y, i * 2), 25 | layer.rand.Range(bounds.min.y, bounds.max.y, index.x, index.y, i * 2 + 1)); 26 | pointList.Add(point); 27 | } 28 | } 29 | } 30 | } 31 | 32 | public class PointsLayer : ChunkBasedDataLayer { 33 | // Specify the world space dimensions of the chunks. 34 | public override int chunkW { get { return 256; } } 35 | public override int chunkH { get { return 256; } } 36 | 37 | // Data common for all chunks of this layer goes here. 38 | public RandomHash rand = new RandomHash(1234); 39 | 40 | public PointsLayer() { 41 | // Dependencies on other layers are set up here with appropriate padding. 42 | //AddLayerDependency(new LayerDependency(OtherLayer.instance, new Point(16, 16))); 43 | 44 | // Register to get a call per frame (Unity-specific). 45 | LayerManagerBehavior.OnUpdate -= Update; 46 | LayerManagerBehavior.OnUpdate += Update; 47 | } 48 | 49 | // This method is called every frame on the main thread (Unity-specific). 50 | void Update() { 51 | // Draw the points in all chunks. 52 | HandleAllChunks(0, c => { 53 | foreach (Point p in c.pointList) 54 | DebugDrawer.DrawCross(p, 16f, UnityEngine.Color.green); 55 | }); 56 | } 57 | 58 | // APIs for other layers to query data from this layer goes here. 59 | public void GetPointsInBounds(ILC q, List outPoints, GridBounds bounds) { 60 | // Add data within bounds. 61 | HandleChunksInBounds(q, bounds, 0, chunk => { 62 | foreach (var point in chunk.pointList) 63 | if (bounds.Contains(point)) 64 | outPoints.Add(point); 65 | }); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/Scripts/PointsLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46bf20a02e9534163b793da1150c4e16 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/Scripts/PointsSpawningLayer.cs: -------------------------------------------------------------------------------- 1 | using Runevision.Common; 2 | using Runevision.LayerProcGen; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | public class PointsSpawningChunk : LayerChunk { 7 | 8 | // A pool of List that all have the specified capacity. 9 | static ListPool pointsListPool = new ListPool(12); 10 | 11 | // Data for this chunk goes here. 12 | TransformWrapper chunkParent; 13 | 14 | public override void Create(int level, bool destroy) { 15 | if (destroy) { 16 | QueuedGameObjectDestruction.Enqueue(chunkParent, false); 17 | } 18 | else { 19 | // Get a List from the list pool. 20 | List points = pointsListPool.Get(); 21 | 22 | // Fill it with the points from the PointsLayer that are within the chunk bounds. 23 | PointsLayer.instance.GetPointsInBounds(this, points, bounds); 24 | 25 | // Instantiate a sphere for each point. 26 | // We need to capture the current value of relevant outer variables by copying them. 27 | // Otherwise the action executing delayed on the main thread may use incorrect 28 | // newer values stored in the same outer variables, which may even reference a 29 | // newer incarnation of a chunk that has been recycled and reused in the mean time. 30 | chunkParent = new TransformWrapper(PointsSpawningLayer.instance.layerParent, index); 31 | TransformWrapper currentChunkParent = chunkParent; // Capture current chunk parent. 32 | foreach (Point point in points) { 33 | Point currentPoint = point; // Capture current point in foreach loop. 34 | MainThreadActionQueue.Enqueue(() => { 35 | Transform tr = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; 36 | tr.position = new Vector3(currentPoint.x, 0f, currentPoint.y); 37 | tr.localScale = Vector3.one * 50f; 38 | currentChunkParent.AddChild(tr); 39 | }); 40 | } 41 | 42 | // Return the List to the list pool. 43 | pointsListPool.Return(ref points); 44 | } 45 | } 46 | } 47 | 48 | public class PointsSpawningLayer : ChunkBasedDataLayer { 49 | // Specify the world space dimensions of the chunks. 50 | public override int chunkW { get { return 100; } } 51 | public override int chunkH { get { return 100; } } 52 | 53 | // A Transform parent for all objects spawned by this layer. 54 | public Transform layerParent; 55 | 56 | public PointsSpawningLayer() { 57 | // Create the layer parent Transform. We're on the main thread, so it's ok. 58 | layerParent = new GameObject("PointsSpawnLayer").transform; 59 | 60 | // Dependencies on other layers are set up here with appropriate padding. 61 | AddLayerDependency(new LayerDependency(PointsLayer.instance, new Point(0, 0))); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Samples/SimpleSamples/Scripts/PointsSpawningLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70d58e1cb2500440d9a4227da08a0824 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5bb6a2d420994f4d8e74c61553a33ca 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/InputControls.inputactions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 329647f4d1b71443fbfc4b9d06eb73c0 3 | ScriptedImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 2 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} 11 | generateWrapperCode: 0 12 | wrapperCodePath: 13 | wrapperClassName: 14 | wrapperCodeNamespace: 15 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/LightingSettings.lighting: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!850595691 &4890085278179872738 4 | LightingSettings: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_Name: LightingSettings 10 | serializedVersion: 6 11 | m_GIWorkflowMode: 0 12 | m_EnableBakedLightmaps: 0 13 | m_EnableRealtimeLightmaps: 0 14 | m_RealtimeEnvironmentLighting: 0 15 | m_BounceScale: 1 16 | m_AlbedoBoost: 1 17 | m_IndirectOutputScale: 1 18 | m_UsingShadowmask: 0 19 | m_BakeBackend: 0 20 | m_LightmapMaxSize: 1024 21 | m_BakeResolution: 40 22 | m_Padding: 2 23 | m_LightmapCompression: 3 24 | m_AO: 0 25 | m_AOMaxDistance: 1 26 | m_CompAOExponent: 0 27 | m_CompAOExponentDirect: 0 28 | m_ExtractAO: 0 29 | m_MixedBakeMode: 1 30 | m_LightmapsBakeMode: 1 31 | m_FilterMode: 1 32 | m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0} 33 | m_ExportTrainingData: 0 34 | m_TrainingDataDestination: TrainingData 35 | m_RealtimeResolution: 2 36 | m_ForceWhiteAlbedo: 0 37 | m_ForceUpdates: 0 38 | m_FinalGather: 0 39 | m_FinalGatherRayCount: 1024 40 | m_FinalGatherFiltering: 1 41 | m_PVRCulling: 1 42 | m_PVRSampling: 1 43 | m_PVRDirectSampleCount: 32 44 | m_PVRSampleCount: 512 45 | m_PVREnvironmentSampleCount: 512 46 | m_PVREnvironmentReferencePointCount: 2048 47 | m_LightProbeSampleCountMultiplier: 4 48 | m_PVRBounces: 2 49 | m_PVRMinBounces: 2 50 | m_PVREnvironmentImportanceSampling: 0 51 | m_PVRFilteringMode: 0 52 | m_PVRDenoiserTypeDirect: 0 53 | m_PVRDenoiserTypeIndirect: 0 54 | m_PVRDenoiserTypeAO: 0 55 | m_PVRFilterTypeDirect: 0 56 | m_PVRFilterTypeIndirect: 0 57 | m_PVRFilterTypeAO: 0 58 | m_PVRFilteringGaussRadiusDirect: 1 59 | m_PVRFilteringGaussRadiusIndirect: 5 60 | m_PVRFilteringGaussRadiusAO: 2 61 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 62 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 63 | m_PVRFilteringAtrousPositionSigmaAO: 1 64 | m_PVRTiledBaking: 0 65 | m_NumRaysToShootPerTexel: -1 66 | m_RespectSceneVisibilityWhenBakingGI: 0 67 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/LightingSettings.lighting.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a983e11a2a344b0c86fc5f5d27e2e20 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 4890085278179872738 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5511cc565f8ae41fa86d682045c7949d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/Resources/TerrainResources.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: f94cfa842f4f94d6b8d2b3de415ccfff, type: 3} 13 | m_Name: TerrainResources 14 | m_EditorClassIdentifier: 15 | grassTex: {fileID: 2800000, guid: abc486c4404abec45bf6bbc84f5e6724, type: 3} 16 | cliffTex: {fileID: 2800000, guid: b0473df2c9578da47bd8219760f3a64e, type: 3} 17 | pathTex: {fileID: 2800000, guid: 8c22f1e696aec40ca996d60b571cfdcc, type: 3} 18 | grassDetail: {fileID: 2800000, guid: 61a6951af2e4b4827ae865aa1ea82346, type: 3} 19 | material: {fileID: 2100000, guid: 94fbe753cb405074dab0f9c7ed68248d, type: 2} 20 | terrainData: {fileID: 15600000, guid: f9650cbb629fd44068c8d627d767447f, type: 2} 21 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/Resources/TerrainResources.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dcf8c51c9f0de46278493d61861a6fbf 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/TerrainDummy.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Samples/TerrainSample/Data/TerrainDummy.asset -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/TerrainDummy.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9650cbb629fd44068c8d627d767447f 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 15600000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/TerrainDummy.prefab: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1 &3036771559365954352 4 | GameObject: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | serializedVersion: 6 10 | m_Component: 11 | - component: {fileID: 7347077795061113138} 12 | - component: {fileID: 8309915959743830040} 13 | - component: {fileID: 5206362927716155892} 14 | m_Layer: 0 15 | m_Name: TerrainDummy 16 | m_TagString: Untagged 17 | m_Icon: {fileID: 0} 18 | m_NavMeshLayer: 0 19 | m_StaticEditorFlags: 4294967295 20 | m_IsActive: 1 21 | --- !u!4 &7347077795061113138 22 | Transform: 23 | m_ObjectHideFlags: 0 24 | m_CorrespondingSourceObject: {fileID: 0} 25 | m_PrefabInstance: {fileID: 0} 26 | m_PrefabAsset: {fileID: 0} 27 | m_GameObject: {fileID: 3036771559365954352} 28 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 29 | m_LocalPosition: {x: 0, y: 0, z: 0} 30 | m_LocalScale: {x: 1, y: 1, z: 1} 31 | m_Children: [] 32 | m_Father: {fileID: 0} 33 | m_RootOrder: 0 34 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 35 | --- !u!218 &8309915959743830040 36 | Terrain: 37 | m_ObjectHideFlags: 0 38 | m_CorrespondingSourceObject: {fileID: 0} 39 | m_PrefabInstance: {fileID: 0} 40 | m_PrefabAsset: {fileID: 0} 41 | m_GameObject: {fileID: 3036771559365954352} 42 | m_Enabled: 1 43 | serializedVersion: 6 44 | m_TerrainData: {fileID: 15600000, guid: f9650cbb629fd44068c8d627d767447f, type: 2} 45 | m_TreeDistance: 5000 46 | m_TreeBillboardDistance: 50 47 | m_TreeCrossFadeLength: 5 48 | m_TreeMaximumFullLODCount: 50 49 | m_DetailObjectDistance: 80 50 | m_DetailObjectDensity: 1 51 | m_HeightmapPixelError: 5 52 | m_SplatMapDistance: 1000 53 | m_HeightmapMaximumLOD: 0 54 | m_ShadowCastingMode: 2 55 | m_DrawHeightmap: 1 56 | m_DrawInstanced: 0 57 | m_DrawTreesAndFoliage: 1 58 | m_ReflectionProbeUsage: 1 59 | m_MaterialTemplate: {fileID: 10652, guid: 0000000000000000f000000000000000, type: 0} 60 | m_BakeLightProbesForTrees: 1 61 | m_PreserveTreePrototypeLayers: 0 62 | m_DeringLightProbesForTrees: 1 63 | m_ScaleInLightmap: 0.0256 64 | m_LightmapParameters: {fileID: 15203, guid: 0000000000000000f000000000000000, type: 0} 65 | m_GroupingID: 0 66 | m_RenderingLayerMask: 1 67 | m_AllowAutoConnect: 1 68 | --- !u!154 &5206362927716155892 69 | TerrainCollider: 70 | m_ObjectHideFlags: 0 71 | m_CorrespondingSourceObject: {fileID: 0} 72 | m_PrefabInstance: {fileID: 0} 73 | m_PrefabAsset: {fileID: 0} 74 | m_GameObject: {fileID: 3036771559365954352} 75 | m_Material: {fileID: 0} 76 | m_Enabled: 1 77 | m_TerrainData: {fileID: 15600000, guid: f9650cbb629fd44068c8d627d767447f, type: 2} 78 | m_EnableTreeColliders: 1 79 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/TerrainDummy.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2f61f1c33475436881e85020a5406ce 3 | PrefabImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Data/TerrainDummy.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ae706ff2a6c547aba5c99bae6493558 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples/TerrainSample/FirstPersonController.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e9e851c0e142814dac026a256ba2ac0 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e842daad2e2646edab057e07bcc8e4c 3 | folderAsset: yes 4 | timeCreated: 1456613581 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Cliff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Samples/TerrainSample/Materials/Cliff.png -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Cliff.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0473df2c9578da47bd8219760f3a64e 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: -1 34 | maxTextureSize: 1024 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 1 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 1 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 1 67 | swizzle: 50462976 68 | cookieLightType: 1 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 2048 73 | resizeAlgorithm: 0 74 | textureFormat: -1 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | ignorePlatformSupport: 0 81 | androidETC2FallbackOverride: 0 82 | forceMaximumCompressionQuality_BC6H_BC7: 0 83 | - serializedVersion: 3 84 | buildTarget: Standalone 85 | maxTextureSize: 1024 86 | resizeAlgorithm: 0 87 | textureFormat: -1 88 | textureCompression: 1 89 | compressionQuality: 50 90 | crunchedCompression: 0 91 | allowsAlphaSplitting: 0 92 | overridden: 0 93 | ignorePlatformSupport: 0 94 | androidETC2FallbackOverride: 0 95 | forceMaximumCompressionQuality_BC6H_BC7: 0 96 | - serializedVersion: 3 97 | buildTarget: Android 98 | maxTextureSize: 1024 99 | resizeAlgorithm: 0 100 | textureFormat: 47 101 | textureCompression: 1 102 | compressionQuality: 50 103 | crunchedCompression: 0 104 | allowsAlphaSplitting: 0 105 | overridden: 0 106 | ignorePlatformSupport: 0 107 | androidETC2FallbackOverride: 0 108 | forceMaximumCompressionQuality_BC6H_BC7: 0 109 | - serializedVersion: 3 110 | buildTarget: WebGL 111 | maxTextureSize: 1024 112 | resizeAlgorithm: 0 113 | textureFormat: -1 114 | textureCompression: 1 115 | compressionQuality: 50 116 | crunchedCompression: 0 117 | allowsAlphaSplitting: 0 118 | overridden: 0 119 | ignorePlatformSupport: 0 120 | androidETC2FallbackOverride: 0 121 | forceMaximumCompressionQuality_BC6H_BC7: 0 122 | spriteSheet: 123 | serializedVersion: 2 124 | sprites: [] 125 | outline: [] 126 | physicsShape: [] 127 | bones: [] 128 | spriteID: 129 | internalID: 0 130 | vertices: [] 131 | indices: 132 | edges: [] 133 | weights: [] 134 | secondaryTextures: [] 135 | nameFileIdTable: {} 136 | mipmapLimitGroupName: 137 | pSDRemoveMatte: 0 138 | userData: 139 | assetBundleName: 140 | assetBundleVariant: 141 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Samples/TerrainSample/Materials/Grass.png -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Grass.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abc486c4404abec45bf6bbc84f5e6724 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 1 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 1 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 2048 73 | resizeAlgorithm: 0 74 | textureFormat: -1 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | ignorePlatformSupport: 0 81 | androidETC2FallbackOverride: 0 82 | forceMaximumCompressionQuality_BC6H_BC7: 0 83 | - serializedVersion: 3 84 | buildTarget: Standalone 85 | maxTextureSize: 2048 86 | resizeAlgorithm: 0 87 | textureFormat: -1 88 | textureCompression: 1 89 | compressionQuality: 50 90 | crunchedCompression: 0 91 | allowsAlphaSplitting: 0 92 | overridden: 0 93 | ignorePlatformSupport: 0 94 | androidETC2FallbackOverride: 0 95 | forceMaximumCompressionQuality_BC6H_BC7: 0 96 | spriteSheet: 97 | serializedVersion: 2 98 | sprites: [] 99 | outline: [] 100 | physicsShape: [] 101 | bones: [] 102 | spriteID: 103 | internalID: 0 104 | vertices: [] 105 | indices: 106 | edges: [] 107 | weights: [] 108 | secondaryTextures: [] 109 | nameFileIdTable: {} 110 | mipmapLimitGroupName: 111 | pSDRemoveMatte: 0 112 | userData: 113 | assetBundleName: 114 | assetBundleVariant: 115 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/GrassDetail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Samples/TerrainSample/Materials/GrassDetail.png -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/GrassDetail.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61a6951af2e4b4827ae865aa1ea82346 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 1 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 1 55 | alphaIsTransparency: 1 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 2048 73 | resizeAlgorithm: 0 74 | textureFormat: -1 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | ignorePlatformSupport: 0 81 | androidETC2FallbackOverride: 0 82 | forceMaximumCompressionQuality_BC6H_BC7: 0 83 | - serializedVersion: 3 84 | buildTarget: Standalone 85 | maxTextureSize: 2048 86 | resizeAlgorithm: 0 87 | textureFormat: -1 88 | textureCompression: 1 89 | compressionQuality: 50 90 | crunchedCompression: 0 91 | allowsAlphaSplitting: 0 92 | overridden: 0 93 | ignorePlatformSupport: 0 94 | androidETC2FallbackOverride: 0 95 | forceMaximumCompressionQuality_BC6H_BC7: 0 96 | spriteSheet: 97 | serializedVersion: 2 98 | sprites: [] 99 | outline: [] 100 | physicsShape: [] 101 | bones: [] 102 | spriteID: 103 | internalID: 0 104 | vertices: [] 105 | indices: 106 | edges: [] 107 | weights: [] 108 | secondaryTextures: [] 109 | nameFileIdTable: {} 110 | mipmapLimitGroupName: 111 | pSDRemoveMatte: 0 112 | userData: 113 | assetBundleName: 114 | assetBundleVariant: 115 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/runevision/LayerProcGen/87fb06b6e96482bd564030ecfd4e3403c167667d/Samples/TerrainSample/Materials/Path.png -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Path.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c22f1e696aec40ca996d60b571cfdcc 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 1 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 1 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 2048 73 | resizeAlgorithm: 0 74 | textureFormat: -1 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | ignorePlatformSupport: 0 81 | androidETC2FallbackOverride: 0 82 | forceMaximumCompressionQuality_BC6H_BC7: 0 83 | - serializedVersion: 3 84 | buildTarget: Standalone 85 | maxTextureSize: 2048 86 | resizeAlgorithm: 0 87 | textureFormat: -1 88 | textureCompression: 1 89 | compressionQuality: 50 90 | crunchedCompression: 0 91 | allowsAlphaSplitting: 0 92 | overridden: 0 93 | ignorePlatformSupport: 0 94 | androidETC2FallbackOverride: 0 95 | forceMaximumCompressionQuality_BC6H_BC7: 0 96 | spriteSheet: 97 | serializedVersion: 2 98 | sprites: [] 99 | outline: [] 100 | physicsShape: [] 101 | bones: [] 102 | spriteID: 103 | internalID: 0 104 | vertices: [] 105 | indices: 106 | edges: [] 107 | weights: [] 108 | secondaryTextures: [] 109 | nameFileIdTable: {} 110 | mipmapLimitGroupName: 111 | pSDRemoveMatte: 0 112 | userData: 113 | assetBundleName: 114 | assetBundleVariant: 115 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Skybox.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 8 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: Skybox 11 | m_Shader: {fileID: 106, guid: 0000000000000000f000000000000000, type: 0} 12 | m_Parent: {fileID: 0} 13 | m_ModifiedSerializedProperties: 0 14 | m_ValidKeywords: 15 | - _SUNDISK_HIGH_QUALITY 16 | m_InvalidKeywords: [] 17 | m_LightmapFlags: 5 18 | m_EnableInstancingVariants: 0 19 | m_DoubleSidedGI: 0 20 | m_CustomRenderQueue: 1000 21 | stringTagMap: {} 22 | disabledShaderPasses: [] 23 | m_LockedProperties: 24 | m_SavedProperties: 25 | serializedVersion: 3 26 | m_TexEnvs: 27 | - _BumpMap: 28 | m_Texture: {fileID: 0} 29 | m_Scale: {x: 1, y: 1} 30 | m_Offset: {x: 0, y: 0} 31 | - _DetailAlbedoMap: 32 | m_Texture: {fileID: 0} 33 | m_Scale: {x: 1, y: 1} 34 | m_Offset: {x: 0, y: 0} 35 | - _DetailMask: 36 | m_Texture: {fileID: 0} 37 | m_Scale: {x: 1, y: 1} 38 | m_Offset: {x: 0, y: 0} 39 | - _DetailNormalMap: 40 | m_Texture: {fileID: 0} 41 | m_Scale: {x: 1, y: 1} 42 | m_Offset: {x: 0, y: 0} 43 | - _EmissionMap: 44 | m_Texture: {fileID: 0} 45 | m_Scale: {x: 1, y: 1} 46 | m_Offset: {x: 0, y: 0} 47 | - _MainTex: 48 | m_Texture: {fileID: 0} 49 | m_Scale: {x: 1, y: 1} 50 | m_Offset: {x: 0, y: 0} 51 | - _MetallicGlossMap: 52 | m_Texture: {fileID: 0} 53 | m_Scale: {x: 1, y: 1} 54 | m_Offset: {x: 0, y: 0} 55 | - _OcclusionMap: 56 | m_Texture: {fileID: 0} 57 | m_Scale: {x: 1, y: 1} 58 | m_Offset: {x: 0, y: 0} 59 | - _ParallaxMap: 60 | m_Texture: {fileID: 0} 61 | m_Scale: {x: 1, y: 1} 62 | m_Offset: {x: 0, y: 0} 63 | m_Ints: [] 64 | m_Floats: 65 | - _AtmosphereThickness: 1 66 | - _BumpScale: 1 67 | - _Cutoff: 0.5 68 | - _DetailNormalMapScale: 1 69 | - _DstBlend: 0 70 | - _Exposure: 2 71 | - _Glossiness: 0.5 72 | - _Metallic: 0 73 | - _Mode: 0 74 | - _OcclusionStrength: 1 75 | - _Parallax: 0.02 76 | - _SrcBlend: 1 77 | - _SunDisk: 2 78 | - _SunSize: 0.025 79 | - _SunSizeConvergence: 5 80 | - _UVSec: 0 81 | - _ZWrite: 1 82 | m_Colors: 83 | - _Color: {r: 1, g: 1, b: 1, a: 1} 84 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} 85 | - _GroundColor: {r: 0.35607842, g: 0.5868173, b: 0.8901961, a: 1} 86 | - _SkyTint: {r: 0.25, g: 0.375, b: 0.5, a: 1} 87 | m_BuildTextureStacks: [] 88 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/Skybox.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87a429a934dea449db5755e49f2f4bcf 3 | timeCreated: 1456530284 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Materials/TerrainMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94fbe753cb405074dab0f9c7ed68248d 3 | timeCreated: 1437293759 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc9f5fb83de1a474e930ebe4c0abe14f 3 | folderAsset: yes 4 | timeCreated: 1436813598 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Behaviors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bef6f15ce8437483c97a2dbc4407aa6b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Behaviors/FirstPersonController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 05ec5cf00ca181d45a42ba1870e148c3 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Behaviors/MouseLook.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.InputSystem; 4 | 5 | [Serializable] 6 | public class MouseLook { 7 | public float sensitivityGamepad = 8f; 8 | public float sensitivityMouse = 0.4f; 9 | public bool clampVerticalRotation = true; 10 | public float MinimumX = -90F; 11 | public float MaximumX = 90F; 12 | public bool smooth; 13 | public float smoothTime = 5f; 14 | 15 | const float gamepadSensitivityExp = 20; 16 | 17 | Vector3 lookEuler; 18 | Vector3 lookEulerTarget; 19 | bool mouseWasUnlocked; 20 | 21 | public void Init(Transform character, Transform camera) { 22 | lookEuler = new Vector3( 23 | Mathf.Repeat(camera.localEulerAngles.x + 180, 360) - 180, 24 | character.eulerAngles.y, 0); 25 | lookEulerTarget = lookEuler; 26 | } 27 | 28 | public void LookRotation(Transform character, Transform camera, InputAction lookAction) { 29 | Vector2 look = lookAction.ReadValue(); 30 | 31 | InputDevice device = lookAction.activeControl?.device; 32 | if (device is Gamepad) { 33 | float mag = Mathf.Min(look.magnitude, 1f); 34 | look = mag == 0 ? Vector2.zero : look / mag; 35 | mag = (Mathf.Pow(gamepadSensitivityExp, mag) - 1) / (gamepadSensitivityExp - 1); 36 | look *= mag * sensitivityGamepad * Time.smoothDeltaTime; 37 | } 38 | if (device is Mouse) { 39 | look *= sensitivityMouse; 40 | if (Cursor.lockState != CursorLockMode.Locked) { 41 | look = Vector2.zero; 42 | mouseWasUnlocked = true; 43 | } 44 | else if (mouseWasUnlocked) { 45 | // First mouse delta after locking can be large (bug in Unity) so ignore it. 46 | look = Vector2.zero; 47 | mouseWasUnlocked = false; 48 | } 49 | } 50 | 51 | lookEulerTarget += new Vector3(-look.y, look.x, 0); 52 | if (smooth) { 53 | lookEuler = Vector3.Lerp(lookEuler, lookEulerTarget, smoothTime * Time.smoothDeltaTime); 54 | } 55 | else { 56 | lookEuler = lookEulerTarget; 57 | } 58 | 59 | if (clampVerticalRotation) { 60 | lookEuler.x = Mathf.Clamp(lookEuler.x, -90f, 90f); 61 | lookEulerTarget.x = Mathf.Clamp(lookEulerTarget.x, -90f, 90f); 62 | } 63 | character.eulerAngles = Vector3.up * lookEuler.y; 64 | camera.localEulerAngles = Vector3.right * lookEuler.x; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Behaviors/MouseLook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37e60a97f2c87ae41b6cdc1055d78cb9 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Behaviors/WaitForGround.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class WaitForGround : MonoBehaviour { 4 | public MonoBehaviour moveBehavior; 5 | public bool moveOntoGround = false; 6 | public float distAboveGround = 1; 7 | 8 | public void Update() { 9 | if (moveBehavior == null) 10 | return; 11 | 12 | Vector3 pos = moveBehavior.transform.position; 13 | Vector3 raycastOrigin = pos; 14 | if (!moveBehavior.enabled) 15 | raycastOrigin.y = 10000; 16 | 17 | RaycastHit hit; 18 | if (Physics.Raycast(raycastOrigin, -Vector3.up, out hit)) { 19 | if (!moveBehavior.enabled) { 20 | if (moveOntoGround) 21 | moveBehavior.transform.position = hit.point + Vector3.up * distAboveGround; 22 | moveBehavior.enabled = true; 23 | } 24 | } 25 | else { 26 | moveBehavior.enabled = false; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Behaviors/WaitForGround.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f458b5a97b374fe9a4e7957bbacda44 3 | timeCreated: 1472488287 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 300 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7e70d03e3e244af3b1d5be823e503e2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dbbbb3802a26444de9c01cd4c8fec617 3 | folderAsset: yes 4 | timeCreated: 1456945838 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers/CultivationLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e066ea6d1ca784147bd525fe561ed4de 3 | timeCreated: 1457803702 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: 8 | - m_ExtensionPtr: {instanceID: 0} 9 | - m_Script: {fileID: 11500000, guid: c6a5362adc5c442638ad222da2bb7031, type: 3} 10 | executionOrder: 0 11 | icon: {instanceID: 0} 12 | userData: 13 | assetBundleName: 14 | assetBundleVariant: 15 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers/GeoGridLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 584347a351f9a44dea2e24fd0dd855c2 3 | timeCreated: 1457803702 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: 8 | - m_ExtensionPtr: {instanceID: 0} 9 | - m_Script: {fileID: 11500000, guid: c6a5362adc5c442638ad222da2bb7031, type: 3} 10 | executionOrder: 0 11 | icon: {instanceID: 0} 12 | userData: 13 | assetBundleName: 14 | assetBundleVariant: 15 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers/LandscapeLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c1dd0ff8b3db4196845ef7a1ef97d53 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: 6 | - m_ExtensionPtr: {instanceID: 0} 7 | - m_Script: {fileID: 11500000, guid: c6a5362adc5c442638ad222da2bb7031, type: 3} 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers/LocationLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 295185c8577f848b58548b3a72417846 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers/PlayLayer.cs: -------------------------------------------------------------------------------- 1 | using Runevision.LayerProcGen; 2 | 3 | public class PlayChunk : LayerChunk { 4 | public PlayChunk() {} 5 | } 6 | 7 | public class PlayLayer : ChunkBasedDataLayer { 8 | public override int chunkW { get { return 8; } } 9 | public override int chunkH { get { return 8; } } 10 | 11 | public PlayLayer() { 12 | AddLayerDependency(new LayerDependency(LandscapeLayerA.instance, 256, 256)); 13 | AddLayerDependency(new LayerDependency(LandscapeLayerB.instance, 512, 512)); 14 | AddLayerDependency(new LayerDependency(LandscapeLayerC.instance, 1024, 1024)); 15 | AddLayerDependency(new LayerDependency(LandscapeLayerD.instance, 2048, 2048)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/Layers/PlayLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fcd7c22121cf842b9856c7e05e6451ae 3 | timeCreated: 1462464189 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/PriorityQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class PriorityQueue { 5 | 6 | struct PriorityElement : IComparable> { 7 | public E element; 8 | public float priority; 9 | 10 | public PriorityElement(E element, float priority) { 11 | this.element = element; 12 | this.priority = priority; 13 | } 14 | 15 | public int CompareTo(PriorityElement other) { 16 | return -priority.CompareTo(other.priority); 17 | } 18 | } 19 | 20 | List> set = new List>(); 21 | 22 | public int Count { get { return set.Count; } } 23 | 24 | public void Enqueue(T element, float priority) { 25 | var value = new PriorityElement(element, priority); 26 | int index = set.BinarySearch(value); 27 | if (index < 0) 28 | set.Insert(~index, value); 29 | else 30 | set.Insert(index, value); 31 | } 32 | 33 | public T Dequeue() { 34 | var result = set[set.Count - 1]; 35 | set.RemoveAt(set.Count - 1); 36 | return result.element; 37 | } 38 | 39 | public void Clear() { 40 | set.Clear(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/PriorityQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a36819775dffe4323a9daf868bc1f8f5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainLODManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a348ce4d7b044bcfb3e557f6c84016d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed9dbcc869094564a9ac7bf27ef381ad 3 | folderAsset: yes 4 | timeCreated: 1437243263 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/DeformationSpec.cs: -------------------------------------------------------------------------------- 1 | using Runevision.Common; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public abstract class DeformationSpec { 6 | public Vector4 splat; 7 | 8 | public List points = new List(); 9 | public GridBounds bounds; 10 | 11 | public GridBounds GetBounds() { return bounds; } 12 | 13 | public void CalculateBounds() { 14 | bounds = GridBounds.Empty(); 15 | for (int i = 0; i < points.Count; i++) { 16 | Vector2 point = points[i].pos.xz(); 17 | Vector2 padding = Vector2.one * points[i].outerWidth; 18 | bounds.Encapsulate((Point)(point - padding)); 19 | bounds.Encapsulate((Point)(point + padding + Vector2.one)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/DeformationSpec.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18047faa9ad604fd2bf2d79b1f13bba2 3 | timeCreated: 1456669892 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/LocationSpec.cs: -------------------------------------------------------------------------------- 1 | using Runevision.Common; 2 | using UnityEngine; 3 | 4 | public class LocationSpec : DeformationSpec, IPoolable { 5 | 6 | public void Reset() { 7 | splat = default; 8 | bounds = default; 9 | points.Clear(); 10 | } 11 | 12 | public LocationSpec Init(Vector3 point, int type, float width, float slopeWidth, float splatWidth, float centerElevation) { 13 | splat = ( 14 | type == 0 ? 15 | new Vector4(0, 0, 1, 0) : 16 | new Vector4(0, 0.7f, 0.3f, 0) 17 | ); 18 | 19 | float halfInnerWidth = width * 0.5f; 20 | float halfOuterWidth = width * 0.5f + slopeWidth; 21 | float halfSplatWidth = splatWidth * 0.5f; 22 | points.Add(new SpecPoint() { 23 | pos = point - Vector3.right * 0.01f, 24 | innerWidth = halfInnerWidth, 25 | outerWidth = halfOuterWidth, 26 | splatWidth = halfSplatWidth, 27 | centerElevation = centerElevation 28 | }); 29 | points.Add(new SpecPoint() { 30 | pos = point + Vector3.right * 0.01f, 31 | innerWidth = halfInnerWidth, 32 | outerWidth = halfOuterWidth, 33 | splatWidth = halfSplatWidth, 34 | centerElevation = centerElevation 35 | }); 36 | return this; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/LocationSpec.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b26cfd256a924533865d7208c705cc6 3 | timeCreated: 1456669892 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/PathSpec.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e15e9ebf14b1e45fd8992d05d488a528 3 | timeCreated: 1456669892 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/TerrainDeformation.cs: -------------------------------------------------------------------------------- 1 | using Runevision.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using Unity.Collections; 6 | using Unity.Mathematics; 7 | using UnityEngine; 8 | 9 | public struct SpecData { 10 | public int pointCount; 11 | public float4 splat; 12 | public float4 bounds; 13 | }; 14 | 15 | public struct SpecPoint { 16 | public Vector3 pos; 17 | public float innerWidth; 18 | public float outerWidth; 19 | public float splatWidth; 20 | public float centerElevation; 21 | }; 22 | 23 | public struct SpecPointB { 24 | public float3 pos; 25 | public float4 props; // innerWidth, outerWidth, splatWidth, centerElevation 26 | 27 | public static explicit operator SpecPointB(SpecPoint p) { 28 | return new SpecPointB() { 29 | pos = p.pos, 30 | props = new float4(p.innerWidth, p.outerWidth, p.splatWidth, p.centerElevation) 31 | }; 32 | } 33 | }; 34 | 35 | public static class TerrainDeformation { 36 | 37 | static ListPool specPointListPool = new ListPool(4096); 38 | static ListPool specDataListPool = new ListPool(128); 39 | 40 | public static void ApplySpecs( 41 | NativeArray heights, 42 | NativeArray dists, 43 | NativeArray splats, 44 | Point gridOffset, 45 | Point gridSize, 46 | float2 cellSize, 47 | IReadOnlyList specs, 48 | Func postprocess = null, 49 | Func postprocessSpecs = null 50 | ) { 51 | if (specs.Count == 0) 52 | return; 53 | 54 | List specDatas = specDataListPool.Get(); 55 | for (int i = 0; i < specs.Count; i++) { 56 | DeformationSpec spec = specs[i]; 57 | int specPointCount = spec.points.Count; 58 | specDatas.Add(new SpecData() { 59 | pointCount = specPointCount, 60 | splat = spec.splat, 61 | bounds = new float4( 62 | spec.bounds.min.x - cellSize.x, spec.bounds.min.y - cellSize.y, 63 | spec.bounds.max.x + cellSize.x, spec.bounds.max.y + cellSize.y) 64 | }); 65 | } 66 | 67 | List specPoints = specPointListPool.Get(); 68 | for (int i = 0; i < specs.Count; i++) { 69 | DeformationSpec spec = specs[i]; 70 | for (int j = 0; j < spec.points.Count; j++) { 71 | specPoints.Add(spec.points[j]); 72 | } 73 | } 74 | 75 | if (postprocess != null) { 76 | for (int i = specPoints.Count - 1; i >= 0; i--) { 77 | specPoints[i] = postprocess(specPoints[i]); 78 | } 79 | } 80 | 81 | if (postprocessSpecs != null) { 82 | for (int i = specDatas.Count - 1; i >= 0; i--) { 83 | specDatas[i] = postprocessSpecs(specDatas[i]); 84 | } 85 | } 86 | 87 | NativeArray specPointsArray = new NativeArray(specPoints.Count, Allocator.Persistent); 88 | NativeArray specDatasArray = new NativeArray(specDatas.Count, Allocator.Persistent); 89 | 90 | UnityEngine.Profiling.Profiler.BeginSample("SetupSpecData"); 91 | for (int i = 0; i < specPoints.Count; i++) 92 | specPointsArray[i] = (SpecPointB)specPoints[i]; 93 | for (int i = 0; i < specDatas.Count; i++) 94 | specDatasArray[i] = specDatas[i]; 95 | UnityEngine.Profiling.Profiler.EndSample(); 96 | 97 | UnityEngine.Profiling.Profiler.BeginSample("Dispatch"); 98 | PointerArray heightsPointerArray = heights; 99 | PointerArray distsPointerArray = dists; 100 | PointerArray splatsPointerArray = splats; 101 | TerrainDeformationMethod.ApplySpecs( 102 | specDatasArray, 103 | specPointsArray, 104 | (uint)specDatas.Count, 105 | gridOffset.x, 106 | gridOffset.y, 107 | (uint)gridSize.x, 108 | (uint)gridSize.y, 109 | cellSize, 110 | ref heightsPointerArray, 111 | ref distsPointerArray, 112 | ref splatsPointerArray); 113 | UnityEngine.Profiling.Profiler.EndSample(); 114 | 115 | specPointsArray.Dispose(); 116 | specDatasArray.Dispose(); 117 | 118 | specPointListPool.Return(ref specPoints); 119 | specDataListPool.Return(ref specDatas); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/TerrainDeformation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 380838a1fe3b44e5ab159d0b9aa84df1 3 | timeCreated: 1456669892 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/TerrainDeformationMethod.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2990c5cdf6e884eb09269d22875dd1dd 3 | ComputeShaderImporter: 4 | externalObjects: {} 5 | currentAPIMask: 65536 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/TerrainNoise.cs: -------------------------------------------------------------------------------- 1 | using Runevision.Common; 2 | using Unity.Mathematics; 3 | 4 | public class TerrainNoise { 5 | public static float GetHeight(DPoint p) { 6 | float freq = 0.002f; 7 | float amplitude = 0.5f; 8 | float result = 0; 9 | float scalar = 1f; 10 | // Add a few octaves of noise. 11 | // Scale higher frequencies by output of lower frequencies 12 | // to make terrain more bumpy at higher altitudes. 13 | for (int i = 0; i < 6; i++) { 14 | float noiseVal = noise.snoise(new float2((float)p.x, (float)p.y) * freq); 15 | result += noiseVal * scalar * amplitude; 16 | scalar *= noiseVal * 0.5f + 1.0f; 17 | freq *= 2f; 18 | amplitude *= 0.45f; 19 | } 20 | return result * 100; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/TerrainNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09683473c471d41798e76a86fc8ebc6e 3 | timeCreated: 1457810694 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainObjects/TerrainPathFinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64f61a5eb5c5d49d183e34fc247d0faa 3 | timeCreated: 1456684556 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainResources.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [CreateAssetMenu] 4 | public class TerrainResources : SingletonAsset { 5 | public Texture2D grassTex; 6 | public Texture2D cliffTex; 7 | public Texture2D pathTex; 8 | public Texture2D grassDetail; 9 | 10 | [Space] 11 | public Material material; 12 | public TerrainData terrainData; 13 | } 14 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Generation/TerrainResources.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f94cfa842f4f94d6b8d2b3de415ccfff 3 | timeCreated: 1472488287 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 300 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45b76cef1aeed44ba9d2c191eb06d812 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/DebugGUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class DebugGUI : MonoBehaviour { 4 | public static bool on { get; private set; } 5 | 6 | public GameObject debugOverlay; 7 | 8 | void Update() { 9 | // Toggle debug GUI when pressing 1. 10 | if (Input.GetKeyDown(KeyCode.Alpha1)) { 11 | on = !on; 12 | debugOverlay.SetActive(on); 13 | Cursor.lockState = CursorLockMode.None; 14 | } 15 | // Take screenshot when pressing 2. 16 | if (Input.GetKeyDown(KeyCode.Alpha2)) { 17 | ScreenCapture.CaptureScreenshot(System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "_Screenshot.png"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/DebugGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 647c97265fe624ca4a72aba3b3f4a73d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/Maths.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6342c4107022c43ab852b45b0db0027a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/NativeArrayCopyExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using Unity.Collections; 4 | using Unity.Collections.LowLevel.Unsafe; 5 | 6 | public static class NativeArrayCopyExtensions { 7 | 8 | [WriteAccessRequired] 9 | public static unsafe void CopyFrom(this NativeArray dst, arrT[] src) 10 | where natT : struct 11 | where arrT : struct 12 | { 13 | SanityCheck(dst, src, src.Length); 14 | GCHandle gCHandle = GCHandle.Alloc(src, GCHandleType.Pinned); 15 | IntPtr intPtr = gCHandle.AddrOfPinnedObject(); 16 | UnsafeUtility.MemCpy( 17 | (byte*)dst.GetUnsafePtr(), 18 | (byte*)(void*)intPtr, 19 | dst.Length * UnsafeUtility.SizeOf()); 20 | gCHandle.Free(); 21 | } 22 | 23 | [WriteAccessRequired] 24 | public static unsafe void CopyFrom(this NativeArray dst, arrT[,] src) 25 | where natT : struct 26 | where arrT : struct 27 | { 28 | SanityCheck(dst, src, src.Length); 29 | GCHandle gCHandle = GCHandle.Alloc(src, GCHandleType.Pinned); 30 | IntPtr intPtr = gCHandle.AddrOfPinnedObject(); 31 | UnsafeUtility.MemCpy( 32 | (byte*)dst.GetUnsafePtr(), 33 | (byte*)(void*)intPtr, 34 | dst.Length * UnsafeUtility.SizeOf()); 35 | gCHandle.Free(); 36 | } 37 | 38 | [WriteAccessRequired] 39 | public static unsafe void CopyTo(this NativeArray src, arrT[] dst) 40 | where natT : struct 41 | where arrT : struct 42 | { 43 | SanityCheck(src, dst, dst.Length); 44 | GCHandle gCHandle = GCHandle.Alloc(dst, GCHandleType.Pinned); 45 | IntPtr intPtr = gCHandle.AddrOfPinnedObject(); 46 | UnsafeUtility.MemCpy( 47 | (byte*)(void*)intPtr, 48 | (byte*)src.GetUnsafePtr(), 49 | src.Length * UnsafeUtility.SizeOf()); 50 | gCHandle.Free(); 51 | } 52 | 53 | [WriteAccessRequired] 54 | public static unsafe void CopyTo(this NativeArray src, arrT[,] dst) 55 | where natT : struct 56 | where arrT : struct 57 | { 58 | SanityCheck(src, dst, dst.Length); 59 | GCHandle gCHandle = GCHandle.Alloc(dst, GCHandleType.Pinned); 60 | IntPtr intPtr = gCHandle.AddrOfPinnedObject(); 61 | UnsafeUtility.MemCpy( 62 | (byte*)(void*)intPtr, 63 | (byte*)src.GetUnsafePtr(), 64 | src.Length * UnsafeUtility.SizeOf()); 65 | gCHandle.Free(); 66 | } 67 | 68 | // Common 69 | static void SanityCheck(NativeArray nat, object array, int arrayLength) 70 | where natT : struct 71 | where arrT : struct 72 | { 73 | if (array == null) { 74 | throw new ArgumentNullException(nameof(array)); 75 | } 76 | 77 | if (arrayLength < 0) { 78 | throw new ArgumentOutOfRangeException(nameof(arrayLength), "length must be equal or greater than zero."); 79 | } 80 | 81 | if (arrayLength != nat.Length) { 82 | throw new Exception("Array length and NativeArray length do not match."); 83 | } 84 | 85 | if (UnsafeUtility.SizeOf() != UnsafeUtility.SizeOf()) { 86 | throw new Exception("Element types of array and NativeArray are not of same size."); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/NativeArrayCopyExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 135a12a108e0845f59773dce861120b1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/PointerArray.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 128ad1eeec835442cb8707d596004336 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/SingletonAsset.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | // ScriptableObject which can be called as a singleton. 4 | // Loaded on demand. If called first time from a non-main-thread, it waits for the main thread. 5 | public abstract class SingletonAsset : ScriptableObject where T : ScriptableObject, new() { 6 | static T s_Instance = null; 7 | static object loadLock = new object(); 8 | public static T instance { 9 | get { 10 | if (s_Instance == null) { 11 | CallbackHub.ExecuteOnMainThread(() => { 12 | lock (loadLock) { 13 | if (s_Instance == null) { 14 | s_Instance = Resources.Load(typeof(T).Name); 15 | (s_Instance as SingletonAsset).OnInitialize(); 16 | } 17 | } 18 | }); 19 | while (s_Instance == null) 20 | System.Threading.Thread.Sleep(1); 21 | } 22 | return s_Instance; 23 | } 24 | } 25 | 26 | protected virtual void OnInitialize() { } 27 | } 28 | -------------------------------------------------------------------------------- /Samples/TerrainSample/Scripts/Utilities/SingletonAsset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b352bb87371784427838bce0db633c58 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Samples/TerrainSample/TerrainScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6179a949add5450398b336f5ba7ad3a 3 | timeCreated: 1456869393 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69b372e2fd42947e395d9e819fa4685f 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Src/Common/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | 12 | namespace Runevision.Common { 13 | 14 | public static class CollectionExtensions { 15 | 16 | public static void Clear(this Array array) { 17 | Array.Clear(array, 0, array.Length); 18 | } 19 | 20 | public static T GetRandom(this IList list, RandomHash rng, int seed) { 21 | int n = rng.Range(0, list.Count, seed); 22 | return list[n]; 23 | } 24 | 25 | public static void Shuffle(this IList list, RandomHash rng, int seed) { 26 | int n = list.Count; 27 | while (n > 1) { 28 | n--; 29 | int k = rng.Range(0, n + 1, n, seed); 30 | (list[n], list[k]) = (list[k], list[n]); 31 | } 32 | } 33 | 34 | public static int MaxIndex(this IEnumerable sequence) where T : IComparable { 35 | int maxIndex = -1; 36 | T maxValue = default; // Immediately overwritten anyway 37 | int index = 0; 38 | foreach (T value in sequence) { 39 | if (value.CompareTo(maxValue) > 0 || maxIndex == -1) { 40 | maxIndex = index; 41 | maxValue = value; 42 | } 43 | index++; 44 | } 45 | return maxIndex; 46 | } 47 | 48 | public static int MinIndex(this IEnumerable sequence) where T : IComparable { 49 | int minIndex = -1; 50 | T minValue = default; // Immediately overwritten anyway 51 | int index = 0; 52 | foreach (T value in sequence) { 53 | if (value.CompareTo(minValue) < 0 || minIndex == -1) { 54 | minIndex = index; 55 | minValue = value; 56 | } 57 | index++; 58 | } 59 | return minIndex; 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Src/Common/CollectionExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e0e7bfbcdb494de29e96e2d526c0364 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Common/Crd.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | namespace Runevision.Common { 10 | 11 | // These are methods useful for processing integer coordinates. 12 | // Unlike built-in '/' and '%' operators, the methods here work the same for 13 | // the entire number range, no matter if the input is positive or negative. 14 | public static class Crd { 15 | 16 | // Div is like the division operator '/' except it rounds down instead of towards zero, 17 | // meaning the remainder is always zero or positive, never negative. 18 | // 19 | // Example with a positive dividend (division operator versus Div): 20 | // 9 / 4 = 2 (remainder 1) 21 | // Div(9, 4) = 2 (remainder 1) 22 | // 23 | // Example with a negative dividend (division operator versus Div): 24 | // -9 / 4 = -2 (remainder -1) 25 | // Div(-9, 4) = -3 (remainder 3) 26 | public static int Div(int x, int divisor) { 27 | return (x - (((x % divisor) + divisor) % divisor)) / divisor; 28 | } 29 | 30 | public static Point Div(Point p, int divisor) { 31 | return new Point(Div(p.x, divisor), Div(p.y, divisor)); 32 | } 33 | 34 | public static Point Div(Point p, Point divisor) { 35 | return new Point(Div(p.x, divisor.x), Div(p.y, divisor.y)); 36 | } 37 | 38 | // DivUp is like the division operator '/' except it rounds up instead of towards zero, 39 | // meaning the remainder is always zero or negative, never positive. 40 | // 41 | // Example with a positive dividend (division operator versus Div): 42 | // 9 / 4 = 2 (remainder 1) 43 | // DivUp(9, 4) = 3 (remainder -3) 44 | // 45 | // Example with a negative dividend (division operator versus Div): 46 | // -9 / 4 = -2 (remainder -1) 47 | // DivUp(-9, 4) = -2 (remainder -1) 48 | public static int DivUp(int x, int divisor) { 49 | return (x - (((x % divisor) - divisor) % divisor)) / divisor; 50 | } 51 | 52 | public static Point DivUp(Point p, int divisor) { 53 | return new Point(DivUp(p.x, divisor), DivUp(p.y, divisor)); 54 | } 55 | 56 | public static Point DivUp(Point p, Point divisor) { 57 | return new Point(DivUp(p.x, divisor.x), DivUp(p.y, divisor.y)); 58 | } 59 | 60 | // Mod (modulo) is like the remainder operator '%' except it's always zero or positive, 61 | // due to being the remainder of the Div method, which rounds down instead of towards zero. 62 | // 63 | // Example with a positive input (remainder operator versus Mod): 64 | // 9 % 4 = 1 65 | // Mod(9, 4) = 1 66 | // 67 | // Example with a negative input (remainder operator versus Mod): 68 | // -9 % 4 = -1 69 | // Mod(-9, 4) = 3 70 | public static int Mod(int x, int period) { 71 | return ((x % period) + period) % period; 72 | } 73 | 74 | public static Point Mod(Point p, int period) { 75 | return new Point(Mod(p.x, period), Mod(p.y, period)); 76 | } 77 | 78 | public static Point Mod(Point p, Point period) { 79 | return new Point(Mod(p.x, period.x), Mod(p.y, period.y)); 80 | } 81 | 82 | // RoundToPeriod rounds towards the nearest multiple of period; up if half-way in between. 83 | // 84 | // Example with a positive input: 85 | // RoundToPeriod(9, 4) = 8 86 | // 87 | // Example with a negative input: 88 | // RoundToPeriod(-9, 4) = -8 89 | public static int RoundToPeriod(int x, int period) { 90 | x += period / 2; 91 | return x - (((x % period) + period) % period); 92 | } 93 | 94 | public static Point RoundToPeriod(Point p, int period) { 95 | return new Point (RoundToPeriod(p.x, period), RoundToPeriod(p.y, period)); 96 | } 97 | 98 | public static Point RoundToPeriod(Point p, Point period) { 99 | return new Point (RoundToPeriod(p.x, period.x), RoundToPeriod(p.y, period.y)); 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /Src/Common/Crd.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e59744df961244a43b6190a83599dcb5 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Common/Debugging.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b17ce050b1e145a6b4e64483c1e2007 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Common/Debugging/DebugOption.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9880888d4ce64728bc120771c41a1d1 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Common/Debugging/Logg.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System; 10 | 11 | namespace Runevision.Common { 12 | 13 | /// 14 | /// A simple wrapper for logging messages, warnings and errors. 15 | /// 16 | /// 17 | /// Logs are output to the OS console and can be forwarded elsewhere too. 18 | /// In Unity it's forwarded to Unity's console window. 19 | /// 20 | public static class Logg { 21 | public static event Action ForwardMessage; 22 | public static event Action ForwardWarning; 23 | public static event Action ForwardError; 24 | 25 | static DateTime s_StartTime; 26 | 27 | static Logg() { 28 | s_StartTime = DateTime.Now; 29 | } 30 | 31 | public static void Log(string str, bool showInConsole = true) { 32 | Console.WriteLine((DateTime.Now - s_StartTime) + " " + str); 33 | if (showInConsole) 34 | ForwardMessage?.Invoke((DateTime.Now - s_StartTime) + " " + str); 35 | } 36 | 37 | public static void LogWarning(string str) { 38 | Console.WriteLine((DateTime.Now - s_StartTime) + " Warning: " + str); 39 | ForwardWarning?.Invoke((DateTime.Now - s_StartTime) + " " + str); 40 | } 41 | 42 | public static void LogError(string str) { 43 | Console.WriteLine((DateTime.Now - s_StartTime) + " Error: " + str); 44 | ForwardError?.Invoke((DateTime.Now - s_StartTime) + " " + str); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Src/Common/Debugging/Logg.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ef8f8d90c43f403d8430d2349c3e1a3 3 | timeCreated: 1453312079 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Src/Common/Debugging/SimpleProfiler.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 746c357b760894c3eacfde29278ec434 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Common/GridBounds.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0739920e800474977a3c01de47c0cd9a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Common/GridBounds3.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99c7afe74cbc94affa9fe0dee0bb7443 3 | timeCreated: 1460293176 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Src/Common/Pools.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36b23e95947414b0ba098fa73140cbfe 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Common/Pools/ArrayPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2cf0081762e974d00b79c6e5ebd648ad 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/Common/Pools/IPool.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.Collections.Generic; 10 | 11 | namespace Runevision.Common { 12 | 13 | public interface IPool { 14 | int CountAll { get; } 15 | int CountActive { get; } 16 | int CountInactive { get; } 17 | } 18 | 19 | /// 20 | /// Represents an object pool that poolable objects can be retrieved from and returned to. 21 | /// 22 | /// 23 | /// Used by creating a long-lived pool instance of a given type and, when needed, 24 | /// calling Get to retrieve an object from the pool and Return 25 | /// to return it to the pool. The following classes implement the interface: 26 | /// 27 | /// can be used to pool objects that implement the 28 | /// interface and support an empty constructor. 29 | /// Unlike the other pool types, ObjectPool also has static GlobalGet and 30 | /// GlobalReturn functions that can be used without creating a pool instance. 31 | /// 32 | /// can be used to pool arrays of a specific length specified 33 | /// in the pool constructor. and 34 | /// can be used for arrays of two and three dimensions. 35 | /// 36 | /// can be used to pool Lists of a specific capacity specified 37 | /// in the pool constructor. 38 | /// 39 | /// The background for these classes is that, as many Unity developers know, it's best to 40 | /// avoid generating "garbage" to be collected by the .Net garbage collector. 41 | /// A common way to avoid this is to pool and reuse resources rather than creating new ones 42 | /// every time one is needed. 43 | /// 44 | public interface IPool : IPool { 45 | /// 46 | /// Returns the object to the pool and sets the reference to null. 47 | /// 48 | void Return(ref T obj); 49 | 50 | /// 51 | /// Gets an existing object from the pool, or creates one if none are available. 52 | /// 53 | T Get(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Src/Common/Pools/IPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad11aeda6890a4077b59c39037cd434e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Common/Pools/IPoolable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | namespace Runevision.Common { 10 | 11 | /// 12 | /// Represents a poolable object that can be used with the class. 13 | /// 14 | public interface IPoolable { 15 | /// 16 | /// Called by the pool when this IPoolable object is returned to the pool. 17 | /// 18 | void Reset(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Src/Common/Pools/IPoolable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32b85a802a7aa43eb8ec2b259a79a2d3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Common/Pools/ListPool.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.Collections.Generic; 10 | 11 | namespace Runevision.Common { 12 | 13 | // T is the type of the elements in the list, not the lists themselves. 14 | public class ListPool : IPool> { 15 | 16 | public int CountAll { get; private set; } 17 | public int CountActive { get { return CountAll - CountInactive; } } 18 | public int CountInactive { get { 19 | lock (stack) { 20 | return stack.Count; 21 | } 22 | } } 23 | 24 | int capacity; 25 | Stack> stack = new Stack>(); 26 | string name; 27 | 28 | public ListPool(int capacity) { 29 | this.capacity = capacity; 30 | name = GetType().PrettyName() + " cap " + this.capacity; 31 | lock (PoolManager.allPools) { 32 | PoolManager.allPools.Add(this); 33 | } 34 | } 35 | 36 | public List Get() { 37 | lock (stack) { 38 | if (stack.Count > 0) 39 | return stack.Pop(); 40 | else 41 | CountAll++; 42 | } 43 | List list = new List(capacity); 44 | PoolManager.TrackSourcePool(list, this); 45 | return list; 46 | } 47 | 48 | public void Return(ref List list) { 49 | lock (stack) { 50 | if (stack.Contains(list)) 51 | throw new System.Exception("Trying to return list that was already returned to the pool."); 52 | } 53 | list.Clear(); 54 | if (list.Capacity > capacity) { 55 | Logg.LogWarning(list.GetType().PrettyName() + " capacity was increased from " + capacity + " to " + list.Capacity); 56 | capacity = list.Capacity; 57 | } 58 | lock (stack) { 59 | stack.Push(list); 60 | if (stack.Count > CountAll) 61 | Logg.LogWarning(list.GetType().PrettyName() + " has " + stack.Count + " in stack but only " + CountAll + " total."); 62 | } 63 | list = null; 64 | } 65 | 66 | public void Return(ref object obj) { 67 | List list = (List)obj; 68 | Return(ref list); 69 | obj = null; 70 | } 71 | 72 | public override string ToString() { return name; } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Src/Common/Pools/ListPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c726ba70c757b4f62b65490d2ab86d6f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Common/Pools/ObjectPool.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.Collections.Generic; 10 | 11 | namespace Runevision.Common { 12 | 13 | public class ObjectPool : IPool where T : IPoolable, new() { 14 | 15 | // Singleton 16 | static ObjectPool s_Instance; 17 | 18 | public static ObjectPool instance { 19 | get { 20 | lock (PoolManager.allPools) { 21 | if (s_Instance == null) 22 | s_Instance = new ObjectPool(); 23 | return s_Instance; 24 | } 25 | } 26 | } 27 | 28 | /// 29 | /// Gets an existing object from the singleton pool of type T, or creates one if none are available. 30 | /// 31 | public static T GlobalGet() { 32 | return instance.Get(); 33 | } 34 | 35 | /// 36 | /// Returns the object to the singleton pool of type T and sets the reference to null. 37 | /// 38 | public static void GlobalReturn(ref T element) { 39 | instance.Return(ref element); 40 | } 41 | 42 | /// 43 | /// Returns all the elements to the singleton pool of type T and calls Clear on the collection. 44 | /// 45 | public static void GlobalReturnAll(ICollection elements) { 46 | instance.ReturnAll(elements); 47 | } 48 | 49 | // Member data 50 | 51 | public int CountAll { get; private set; } 52 | public int CountActive { get { return CountAll - CountInactive; } } 53 | public int CountInactive { get { 54 | lock (stack) { 55 | return stack.Count; 56 | } 57 | } } 58 | 59 | Stack stack = new Stack(); 60 | string name; 61 | 62 | public ObjectPool() { 63 | name = GetType().PrettyName(); 64 | lock (PoolManager.allPools) { 65 | PoolManager.allPools.Add(this); 66 | } 67 | } 68 | 69 | public T Get() { 70 | lock (stack) { 71 | if (stack.Count > 0) 72 | return stack.Pop(); 73 | else 74 | CountAll++; 75 | } 76 | T element = new T(); 77 | PoolManager.TrackSourcePool(element, this); 78 | return element; 79 | } 80 | 81 | public void Return(ref T element) { 82 | lock (stack) { 83 | if (stack.Count > 0 && ReferenceEquals(stack.Peek(), element)) 84 | throw new System.Exception("Trying to return object that was already returned to the pool."); 85 | element.Reset(); 86 | stack.Push(element); 87 | element = default; 88 | } 89 | } 90 | 91 | public void Return(ref object obj) { 92 | T typedObject = (T)obj; 93 | Return(ref typedObject); 94 | obj = null; 95 | } 96 | 97 | /// 98 | /// Returns all the elements to the pool and calls Clear on the collection. 99 | /// 100 | /// 101 | public void ReturnAll(ICollection elements) { 102 | foreach (T element in elements) { 103 | T copy = element; 104 | Return(ref copy); 105 | } 106 | elements.Clear(); 107 | } 108 | 109 | public override string ToString() { return name; } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /Src/Common/Pools/ObjectPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cfdd8d3e0eec41e98fb4be49ee2a50d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/Common/Pools/PoolManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.Collections.Generic; 10 | 11 | namespace Runevision.Common { 12 | 13 | public static class PoolManager { 14 | public static List allPools = new List(); 15 | //static Dictionary sourcePools = new(); 16 | 17 | public static void TrackSourcePool(object element, IPool pool) { 18 | /*lock (sourcePools) { 19 | sourcePools[element] = pool; 20 | }*/ 21 | } 22 | 23 | /*public static void Return (object obj) { 24 | lock (sourcePools) { 25 | if (sourcePools.TryGetValue (obj, out IPool pool)) { 26 | pool.Return (obj); 27 | } 28 | else { 29 | Logg.LogError ("Could not return " + obj + " to pool as it's not tracked."); 30 | } 31 | } 32 | } 33 | 34 | public static void ReturnAllAndClear (this IEnumerable list) { 35 | foreach (var element in list) 36 | Return (element); 37 | var iList = list as IList; 38 | if (iList != null) 39 | iList.Clear (); 40 | } 41 | 42 | public static void ReturnToPool (this IPoolable element) { 43 | Return (element); 44 | }*/ 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Src/Common/Pools/PoolManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c81ff53580a6844c7944ba2c9833f4bb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Common/RandomHash.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d9ce5bd50c084471a0483e7042385bf 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Common/Runevision.Common.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Runevision.Common", 3 | "references": [ 4 | "GUID:bdf51211cba1541cca26870e4d9c763d" 5 | ], 6 | "includePlatforms": [], 7 | "excludePlatforms": [], 8 | "allowUnsafeCode": false, 9 | "overrideReferences": false, 10 | "precompiledReferences": [], 11 | "autoReferenced": true, 12 | "defineConstraints": [], 13 | "versionDefines": [], 14 | "noEngineReferences": true 15 | } -------------------------------------------------------------------------------- /Src/Common/Runevision.Common.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af01629e909984b56b6ddac3cc8fe766 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/Common/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System; 10 | using System.Linq; 11 | 12 | namespace Runevision.Common { 13 | 14 | public static class TypeExtensions { 15 | 16 | public static string PrettyName(this Type t) { 17 | if (t.IsArray) { 18 | return PrettyName(t.GetElementType()) + "[]"; 19 | } 20 | 21 | if (t.IsGenericType) { 22 | return string.Format( 23 | "{0}<{1}>", 24 | t.Name.Substring(0, t.Name.LastIndexOf("`", StringComparison.InvariantCulture)), 25 | string.Join(", ", t.GetGenericArguments().Select(PrettyName))); 26 | } 27 | 28 | return t.Name; 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Src/Common/TypeExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1878e5eb38733478e82e1a1c19b68eef 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Interop.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e08e55b7c75304c0e8a4366b599597ca 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 226511d66250d421cbf4936431173c36 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent/DFloat.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 989d8bee2d2e948099e602f3d58a26d6 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent/DPoint.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System; 10 | 11 | namespace Runevision.Common { 12 | 13 | [Serializable] 14 | public partial struct DPoint : IEquatable { 15 | public DFloat x, y; 16 | 17 | public DPoint(DFloat x, DFloat y) { 18 | this.x = x; 19 | this.y = y; 20 | } 21 | 22 | public DFloat this[int index] { 23 | get { 24 | switch (index) { 25 | case 0: return x; 26 | case 1: return y; 27 | default: throw new IndexOutOfRangeException(); 28 | } 29 | } 30 | set { 31 | switch (index) { 32 | case 0: x = value; break; 33 | case 1: y = value; break; 34 | default: throw new IndexOutOfRangeException(); 35 | } 36 | } 37 | } 38 | 39 | public DFloat[] array { get { return new[] { x, y }; } } 40 | 41 | public static DPoint zero = new DPoint(0f, 0f); 42 | public static DPoint right = new DPoint(1f, 0f); 43 | public static DPoint up = new DPoint(0f, 1f); 44 | public static DPoint one = new DPoint(1f, 1f); 45 | 46 | // User-defined conversion from DPoint to Point 47 | public static explicit operator Point(DPoint p) { 48 | return new Point((int)p.x, (int)p.y); 49 | } 50 | // User-defined conversion from Point to DPoint 51 | public static implicit operator DPoint(Point p) { 52 | return new DPoint(p.x, p.y); 53 | } 54 | 55 | public static DPoint operator +(DPoint a, DPoint b) { 56 | return new DPoint(a.x + b.x, a.y + b.y); 57 | } 58 | 59 | public static DPoint operator -(DPoint a, DPoint b) { 60 | return new DPoint(a.x - b.x, a.y - b.y); 61 | } 62 | 63 | public static DPoint operator -(DPoint a) { 64 | return new DPoint(-a.x, -a.y); 65 | } 66 | 67 | public static DPoint operator *(DPoint a, int f) { 68 | return new DPoint(a.x * f, a.y * f); 69 | } 70 | 71 | public static DPoint operator *(DPoint a, Point b) { 72 | return new DPoint(a.x * b.x, a.y * b.y); 73 | } 74 | 75 | public static DPoint operator *(Point a, DPoint b) { 76 | return new DPoint(a.x * b.x, a.y * b.y); 77 | } 78 | 79 | public static DPoint operator /(DPoint a, int f) { 80 | return new DPoint(a.x / f, a.y / f); 81 | } 82 | 83 | public static bool operator ==(DPoint a, DPoint b) { 84 | return (a.x.value == b.x.value) && (a.y.value == b.y.value); 85 | } 86 | 87 | public static bool operator !=(DPoint a, DPoint b) { 88 | return (a.x.value != b.x.value) || (a.y.value != b.y.value); 89 | } 90 | 91 | public override bool Equals(object obj) { 92 | if (!(obj is DPoint other)) 93 | return false; 94 | return (x == other.x) && (y == other.y); 95 | } 96 | 97 | public bool Equals(DPoint other) { 98 | return (x == other.x) && (y == other.y); 99 | } 100 | 101 | public DPoint3 xyo { get { return new DPoint3(x, y, 0); } } 102 | public DPoint3 xoy { get { return new DPoint3(x, 0, y); } } 103 | public DPoint3 oxy { get { return new DPoint3(0, x, y); } } 104 | 105 | public override string ToString() { 106 | return $"({x},{y})"; 107 | } 108 | 109 | public override int GetHashCode() { 110 | int result = 373; 111 | result = 37 * result + x.value; 112 | result = 37 * result + y.value; 113 | return result; 114 | } 115 | 116 | public static DPoint Min(DPoint a, DPoint b) { 117 | return new DPoint(DFloat.Min(a.x, b.x), DFloat.Min(a.y, b.y)); 118 | } 119 | 120 | public static DPoint Max(DPoint a, DPoint b) { 121 | return new DPoint(DFloat.Max(a.x, b.x), DFloat.Max(a.y, b.y)); 122 | } 123 | 124 | public DFloat sqrMagnitude { 125 | get { 126 | return x * x + y * y; 127 | } 128 | } 129 | 130 | public float magnitude { get { return (float)Math.Sqrt(sqrMagnitude); } } 131 | 132 | public static float Distance(DPoint a, DPoint b) { 133 | return (b - a).magnitude; 134 | } 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /Src/Interop/Independent/DPoint.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d44dfab19bd346c1811c78a3457745d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent/DPoint3.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 595183d85f043488689b78d20d3bcfe8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent/IBinarySerializable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.IO; 10 | 11 | namespace Runevision.Common { 12 | 13 | public interface IBinarySerializable { 14 | void Serialize(BinaryWriter writer); 15 | void Deserialize(BinaryReader reader); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/Independent/IBinarySerializable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a2ef97067101a45ee96b06adc8817b0f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent/Point.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4802ab29a225142cb8712792ea13911c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Interop/Independent/Point3.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a260c47d731dd44519c455fc3e6f5adb 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Interop/Runevision.Interop.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Runevision.Interop", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:d8b63aba1907145bea998dd612889d6b" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [ 15 | { 16 | "name": "com.unity.mathematics", 17 | "expression": "", 18 | "define": "PACKAGE_UNITY_MATHEMATICS" 19 | } 20 | ], 21 | "noEngineReferences": false 22 | } -------------------------------------------------------------------------------- /Src/Interop/Runevision.Interop.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bdf51211cba1541cca26870e4d9c763d 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82145f921cb3948eba877f6ce76e1167 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/DPoint3Unity.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | #if UNITY_2019_4_OR_NEWER 10 | #if PACKAGE_UNITY_MATHEMATICS 11 | using Unity.Mathematics; 12 | #endif 13 | using UnityEngine; 14 | 15 | namespace Runevision.Common { 16 | 17 | public partial struct DPoint3 { 18 | 19 | // User-defined conversion from DPoint3 to Vector3 20 | public static explicit operator Vector3(DPoint3 p) { 21 | return new Vector3((float)p.x, (float)p.y, (float)p.z); 22 | } 23 | 24 | // User-defined conversion from Vector3 to DPoint3 25 | public static implicit operator DPoint3(Vector3 p) { 26 | return new DPoint3(p.x, p.y, p.z); 27 | } 28 | 29 | #if PACKAGE_UNITY_MATHEMATICS 30 | // User-defined conversion from DPoint3 to float3 31 | public static explicit operator float3(DPoint3 p) { 32 | return new float3((float)p.x, (float)p.y, (float)p.z); 33 | } 34 | 35 | // User-defined conversion from float3 to DPoint3 36 | public static implicit operator DPoint3(float3 p) { 37 | return new DPoint3(p.x, p.y, p.z); 38 | } 39 | #endif 40 | } 41 | 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/DPoint3Unity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36f8b5749e525432cbb2427a8838989d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/DPointUnity.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | #if UNITY_2019_4_OR_NEWER 10 | #if PACKAGE_UNITY_MATHEMATICS 11 | using Unity.Mathematics; 12 | #endif 13 | using UnityEngine; 14 | 15 | namespace Runevision.Common { 16 | 17 | public partial struct DPoint { 18 | 19 | // User-defined conversion from DPoint to Vector3 20 | public static explicit operator Vector3(DPoint p) { 21 | return new Vector3((float)p.x, (float)p.y, 0); 22 | } 23 | 24 | // User-defined conversion from Vector3 to DPoint 25 | public static explicit operator DPoint(Vector3 p) { 26 | return new DPoint(p.x, p.y); 27 | } 28 | 29 | // User-defined conversion from DPoint to Vector2 30 | public static explicit operator Vector2(DPoint p) { 31 | return new Vector2((float)p.x, (float)p.y); 32 | } 33 | 34 | // User-defined conversion from Vector2 to DPoint 35 | public static implicit operator DPoint(Vector2 p) { 36 | return new DPoint(p.x, p.y); 37 | } 38 | 39 | #if PACKAGE_UNITY_MATHEMATICS 40 | // User-defined conversion from DPoint to float3 41 | public static explicit operator float3(DPoint p) { 42 | return new float3((float)p.x, (float)p.y, 0); 43 | } 44 | 45 | // User-defined conversion from float3 to DPoint 46 | public static explicit operator DPoint(float3 p) { 47 | return new DPoint(p.x, p.y); 48 | } 49 | 50 | // User-defined conversion from DPoint to float2 51 | public static explicit operator float2(DPoint p) { 52 | return new float2((float)p.x, (float)p.y); 53 | } 54 | 55 | // User-defined conversion from float2 to DPoint 56 | public static implicit operator DPoint(float2 p) { 57 | return new DPoint(p.x, p.y); 58 | } 59 | #endif 60 | } 61 | 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/DPointUnity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64ebf52cf38f548dfb9c01f2b42d6b16 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/Point3Unity.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | #if UNITY_2019_4_OR_NEWER 10 | #if PACKAGE_UNITY_MATHEMATICS 11 | using Unity.Mathematics; 12 | #endif 13 | using UnityEngine; 14 | 15 | namespace Runevision.Common { 16 | 17 | public partial struct Point3 { 18 | 19 | // User-defined conversion from Point to Vector3 20 | public static implicit operator Vector3(Point3 p) { 21 | return new Vector3(p.x, p.y, p.z); 22 | } 23 | 24 | // User-defined conversion from Vector3 to Point 25 | public static explicit operator Point3(Vector3 p) { 26 | return new Point3(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); 27 | } 28 | 29 | #if PACKAGE_UNITY_MATHEMATICS 30 | // User-defined conversion from Point to float3 31 | public static implicit operator float3(Point3 p) { 32 | return new float3(p.x, p.y, p.z); 33 | } 34 | 35 | // User-defined conversion from float3 to Point 36 | public static explicit operator Point3(float3 p) { 37 | return new Point3(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); 38 | } 39 | #endif 40 | } 41 | 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/Point3Unity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62b0d71f63b714bcaa1ddfd734132c59 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/PointUnity.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | #if UNITY_2019_4_OR_NEWER 10 | #if PACKAGE_UNITY_MATHEMATICS 11 | using Unity.Mathematics; 12 | #endif 13 | using UnityEngine; 14 | 15 | namespace Runevision.Common { 16 | 17 | public partial struct Point { 18 | 19 | // User-defined conversion from Point to Vector3 20 | public static explicit operator Vector3(Point p) { 21 | return new Vector3(p.x, p.y, 0); 22 | } 23 | 24 | // User-defined conversion from Vector3 to Point 25 | public static explicit operator Point(Vector3 p) { 26 | return new Point(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y)); 27 | } 28 | 29 | // User-defined conversion from Point to Vector2 30 | public static implicit operator Vector2(Point p) { 31 | return new Vector2(p.x, p.y); 32 | } 33 | 34 | // User-defined conversion from Vector2 to Point 35 | public static explicit operator Point(Vector2 p) { 36 | return new Point(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y)); 37 | } 38 | 39 | public static Point GetRoundedPoint(Vector2 p) { 40 | return new Point(Mathf.RoundToInt(p.x), Mathf.RoundToInt(p.y)); 41 | } 42 | 43 | #if PACKAGE_UNITY_MATHEMATICS 44 | // User-defined conversion from Point to float3 45 | public static explicit operator float3(Point p) { 46 | return new float3(p.x, p.y, 0); 47 | } 48 | 49 | // User-defined conversion from float3 to Point 50 | public static explicit operator Point(float3 p) { 51 | return new Point(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y)); 52 | } 53 | 54 | // User-defined conversion from Point to float2 55 | public static implicit operator float2(Point p) { 56 | return new float2(p.x, p.y); 57 | } 58 | 59 | // User-defined conversion from float2 to Point 60 | public static explicit operator Point(float2 p) { 61 | return new Point(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y)); 62 | } 63 | 64 | public static Point GetRoundedPoint(float2 p) { 65 | return new Point(Mathf.RoundToInt(p.x), Mathf.RoundToInt(p.y)); 66 | } 67 | #endif 68 | } 69 | 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /Src/Interop/UnitySpecific/PointUnity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8440da878e3f34ec8bfbad804d17b51f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/LayerProcGen.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f329712c3459f4809b0f9710781c0468 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Src/LayerProcGen/AbstractDataLayer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using System; 11 | using System.Collections.Generic; 12 | 13 | namespace Runevision.LayerProcGen { 14 | 15 | /// 16 | /// Internal. Non-generic base class for all layers. 17 | /// 18 | public abstract class AbstractDataLayer { 19 | 20 | // Pertaining to all the different layers. 21 | 22 | static Dictionary s_LayerDict = new Dictionary(); 23 | 24 | /// 25 | /// Check if a layer of the specified type exists without creating it as a side effect. 26 | /// 27 | public static bool HasLayer() where T : AbstractDataLayer { return s_LayerDict.ContainsKey(typeof(T)); } 28 | 29 | /// 30 | /// An enumeration of all current layers. 31 | /// 32 | public static IEnumerable layers { get { return s_LayerDict.Values; } } 33 | 34 | internal static void ResetInstances() { 35 | foreach (var instance in s_LayerDict.Values) 36 | instance.ResetInstance(); 37 | s_LayerDict.Clear(); 38 | } 39 | 40 | // Pertaining to one layer. 41 | 42 | internal abstract void ResetInstance(); 43 | 44 | internal AbstractDataLayer() { 45 | if (s_LayerDict.ContainsKey(GetType())) 46 | Logg.LogError($"Layer {GetType().Name} already created!"); 47 | 48 | s_LayerDict.Add(GetType(), this); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Src/LayerProcGen/AbstractDataLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e40483d8b4745436384c443b9cdb81e7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/LayerProcGen/ChunkBasedDataLayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df91e787f9e914922a53a0b64bd23ae5 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/LayerProcGen/LayerChunk.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36b5262245e2b4f98a23812b9308afff 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/LayerProcGen/LayerDependency.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | 11 | namespace Runevision.LayerProcGen { 12 | 13 | /// 14 | /// A layer's dependency on another with a specified level and padding. 15 | /// 16 | public class LayerDependency { 17 | 18 | public AbstractChunkBasedDataLayer layer; 19 | public int level; 20 | public int vPadding; 21 | public int hPadding; 22 | 23 | public LayerDependency(AbstractChunkBasedDataLayer layer, int padding) 24 | : this(layer, padding, padding) { } 25 | public LayerDependency(AbstractChunkBasedDataLayer layer, int hPadding, int vPadding) 26 | : this(layer, hPadding, vPadding, layer.GetLevelCount() - 1) { } 27 | public LayerDependency(AbstractChunkBasedDataLayer layer, Point padding) 28 | : this(layer, padding.x, padding.y, layer.GetLevelCount() - 1) { } 29 | public LayerDependency(AbstractChunkBasedDataLayer layer, Point padding, int level) 30 | : this(layer, padding.x, padding.y, level) { } 31 | public LayerDependency(AbstractChunkBasedDataLayer layer, int hPadding, int vPadding, int level) { 32 | this.layer = layer; 33 | this.hPadding = hPadding; 34 | this.vPadding = vPadding; 35 | this.level = level; 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Src/LayerProcGen/LayerDependency.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 955351e8793fd4b2f8c451f6a62e9289 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/LayerProcGen/LayerManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 65a64f3415cd9432fa67784dec05bf4f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/LayerProcGen/LayerNamedReference.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using System; 11 | using System.Linq; 12 | using System.Reflection; 13 | 14 | namespace Runevision.LayerProcGen { 15 | 16 | [Serializable] 17 | public class LayerNamedReference { 18 | public string className; 19 | 20 | Type cachedLayerType; 21 | AbstractChunkBasedDataLayer cachedLayerInstance; 22 | string cachedClassName; 23 | 24 | public Type GetLayerType() { 25 | if (string.IsNullOrEmpty(className)) { 26 | cachedLayerType = null; 27 | cachedClassName = className; 28 | } 29 | else if (cachedLayerType == null || className != cachedClassName) { 30 | cachedLayerType = AppDomain.CurrentDomain.GetAssemblies() 31 | .Select(domainAssembly => domainAssembly.GetType(className)) 32 | .FirstOrDefault(type => type != null); 33 | if (cachedLayerType == null) 34 | Logg.LogError("Could not find layer type " + className + "."); 35 | cachedClassName = className; 36 | } 37 | return cachedLayerType; 38 | } 39 | 40 | public AbstractChunkBasedDataLayer GetLayerInstance() { 41 | if (cachedLayerInstance == null || className != cachedClassName) { 42 | Type t = GetLayerType(); 43 | if (t == null) 44 | return null; 45 | PropertyInfo propInfo = t.GetProperty("instance", 46 | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); 47 | cachedLayerInstance = (AbstractChunkBasedDataLayer)propInfo?.GetValue(null); 48 | } 49 | return cachedLayerInstance; 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Src/LayerProcGen/LayerNamedReference.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff434b31d6ecb41c9ae8be7c086bd10d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/LayerProcGen/MainThreadActionQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3ffd755ddf5647e487063f92ba3fc3f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/LayerProcGen/RollingGrid.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using System.Collections; 11 | using System.Collections.Generic; 12 | 13 | namespace Runevision.LayerProcGen { 14 | 15 | /// 16 | /// Represents an infinite 2D array, used by layers to store chunks in. 17 | /// 18 | public class RollingGrid : IEnumerable where T : class { 19 | 20 | struct Cell { 21 | public Point[] points; 22 | public T[] values; 23 | public int count; 24 | } 25 | 26 | int sizeX, sizeY; 27 | Cell[,] grid; 28 | HashSet set = new HashSet(); 29 | 30 | public RollingGrid(int sizeX, int sizeY, int maxOverlap = 3) { 31 | this.sizeX = sizeX; 32 | this.sizeY = sizeY; 33 | grid = new Cell[sizeX, sizeY]; 34 | for (int i = 0; i < sizeX; i++) { 35 | for (int j = 0; j < sizeY; j++) { 36 | grid[i, j].points = new Point[maxOverlap]; 37 | grid[i, j].values = new T[maxOverlap]; 38 | } 39 | } 40 | } 41 | 42 | public T this[int x, int y] { 43 | get { 44 | int modX = Crd.Mod(x, sizeX); 45 | int modY = Crd.Mod(y, sizeY); 46 | Cell cell = grid[modX, modY]; 47 | for (int i = 0; i < cell.count; i++) { 48 | if (cell.points[i].x == x && cell.points[i].y == y) 49 | return cell.values[i]; 50 | } 51 | return null; 52 | } 53 | set { 54 | int modX = Crd.Mod(x, sizeX); 55 | int modY = Crd.Mod(y, sizeY); 56 | Cell cell = grid[modX, modY]; 57 | 58 | if (value == null) { 59 | for (int i = 0; i < cell.count; i++) { 60 | if (cell.points[i].x == x && cell.points[i].y == y) { 61 | set.Remove(cell.values[i]); 62 | if (cell.count > 1) { 63 | // When removing value, move last value into removed value's place. 64 | cell.points[i] = cell.points[cell.count - 1]; 65 | cell.values[i] = cell.values[cell.count - 1]; 66 | cell.values[cell.count - 1] = null; 67 | } 68 | else { 69 | cell.values[i] = null; 70 | } 71 | cell.count--; 72 | grid[modX, modY] = cell; 73 | return; 74 | } 75 | } 76 | } 77 | else { 78 | // Check if we already contain point 79 | for (int i = 0; i < cell.count; i++) { 80 | if (cell.points[i].x == x && cell.points[i].y == y) 81 | return; 82 | } 83 | 84 | // Point is new. 85 | // Check if there's no room. 86 | if (cell.count == cell.points.Length) 87 | throw new System.Exception($"Max overlap exceeded in {GetType()}."); 88 | 89 | // Store point and value 90 | set.Add(value); 91 | cell.points[cell.count] = new Point(x, y); 92 | cell.values[cell.count] = value; 93 | cell.count++; 94 | grid[modX, modY] = cell; 95 | } 96 | } 97 | } 98 | 99 | public T this[Point p] { 100 | get { return this[p.x, p.y]; } 101 | set { this[p.x, p.y] = value; } 102 | } 103 | 104 | public IEnumerator GetEnumerator() { 105 | return set.GetEnumerator(); 106 | } 107 | IEnumerator IEnumerable.GetEnumerator() { 108 | return set.GetEnumerator(); 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /Src/LayerProcGen/RollingGrid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd76bb9ddca704ff686aecacd8f9c688 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/LayerProcGen/Runevision.LayerProcGen.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Runevision.LayerProcGen", 3 | "references": [ 4 | "GUID:af01629e909984b56b6ddac3cc8fe766", 5 | "GUID:bdf51211cba1541cca26870e4d9c763d", 6 | "GUID:97462eeaf6ea341848ff6b8b6119c1f0" 7 | ], 8 | "includePlatforms": [], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false, 11 | "overrideReferences": false, 12 | "precompiledReferences": [], 13 | "autoReferenced": true, 14 | "defineConstraints": [], 15 | "versionDefines": [], 16 | "noEngineReferences": true 17 | } -------------------------------------------------------------------------------- /Src/LayerProcGen/Runevision.LayerProcGen.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eedf2b075ec794c139fc663e635ee0bb 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/LayerProcGen/TopLayerDependency.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | 11 | namespace Runevision.LayerProcGen { 12 | 13 | /// 14 | /// All generation starts with one or more top level dependencies at the root. 15 | /// 16 | public class TopLayerDependency { 17 | 18 | public IChunkBasedDataLayer layer { get { return (IChunkBasedDataLayer)abstractLayer; } } 19 | public AbstractChunkBasedDataLayer abstractLayer { get; private set; } 20 | public int level { get; private set; } 21 | public Point focus { get; private set; } 22 | public Point size { get; private set; } 23 | public GridBounds chunkIndices { get; private set; } 24 | public bool changed { get; private set; } 25 | 26 | internal ChunkLevelData currentRootUsage; 27 | 28 | bool active; 29 | 30 | public bool isActive { 31 | get { return active; } 32 | set { 33 | if (active != value) { 34 | active = value; 35 | changed = true; 36 | if (active) 37 | LayerManager.instance.AddTopDependency(this); 38 | } 39 | } 40 | } 41 | 42 | public TopLayerDependency(AbstractChunkBasedDataLayer layer, Point size, int level) { 43 | abstractLayer = layer; 44 | this.size = size; 45 | this.level = level; 46 | } 47 | 48 | public TopLayerDependency(AbstractChunkBasedDataLayer layer, Point size) 49 | : this(layer, size, layer.GetLevelCount() - 1) { } 50 | 51 | public void SetFocus(Point focus) { 52 | if (isActive && focus == this.focus) 53 | return; 54 | this.focus = focus; 55 | UpdateLayerIndices(); 56 | } 57 | 58 | public void SetSize(Point size) { 59 | if (isActive && size == this.size) 60 | return; 61 | this.size = size; 62 | UpdateLayerIndices(); 63 | } 64 | 65 | public void SetPadding(Point padding) { 66 | if (isActive && padding * 2 == size) 67 | return; 68 | size = padding * 2; 69 | UpdateLayerIndices(); 70 | } 71 | 72 | void UpdateLayerIndices() { 73 | GridBounds oldIndices = chunkIndices; 74 | GridBounds bounds = new GridBounds(focus - size / 2, size); 75 | chunkIndices = bounds.GetDivided(layer.chunkSize); 76 | if (chunkIndices != oldIndices || !isActive) 77 | changed = true; 78 | isActive = true; 79 | } 80 | 81 | internal void GetPendingBounds(out GridBounds bounds, out int level) { 82 | changed = false; 83 | bounds = new GridBounds(focus - size / 2, size); 84 | level = this.level; 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Src/LayerProcGen/TopLayerDependency.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f02fe9d5611c48e095831784b8e36f1 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/LayerProcGen/WorkTracker.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using System; 11 | using System.Collections.Generic; 12 | 13 | namespace Runevision.LayerProcGen { 14 | 15 | public static class WorkTracker { 16 | static bool trackingWork; 17 | static object workLock = new object(); 18 | static Dictionary workEstimated = new Dictionary(); 19 | static Dictionary workNeeded = new Dictionary(); 20 | static Dictionary workDone = new Dictionary(); 21 | 22 | public static void AddWorkEstimated(float work, object key) { 23 | if (!trackingWork) 24 | return; 25 | lock (workLock) { 26 | workEstimated.TryGetValue(key, out float val); 27 | workEstimated[key] = val + work; 28 | } 29 | } 30 | 31 | public static void AddWorkNeeded(float work, object key) { 32 | if (!trackingWork) 33 | return; 34 | lock (workLock) { 35 | workNeeded.TryGetValue(key, out float val); 36 | workNeeded[key] = val + work; 37 | } 38 | } 39 | 40 | public static void AddWorkDone(float work, object key) { 41 | if (!trackingWork) 42 | return; 43 | lock (workLock) { 44 | workDone.TryGetValue(key, out float val); 45 | workDone[key] = val + work; 46 | } 47 | } 48 | 49 | public static void WorkIsKnown(object key) { 50 | if (!trackingWork) 51 | return; 52 | lock (workLock) { 53 | workNeeded.TryGetValue(key, out float val); 54 | workEstimated[key] = val; 55 | } 56 | } 57 | 58 | public static void StartTracking() { 59 | lock (workLock) { 60 | workEstimated.Clear(); 61 | workNeeded.Clear(); 62 | workDone.Clear(); 63 | trackingWork = true; 64 | } 65 | } 66 | 67 | public static void StopTracking() { 68 | lock (workLock) { 69 | trackingWork = false; 70 | Logg.Log(GetResults(), false); 71 | } 72 | } 73 | 74 | public static float CalculateProgress() { 75 | float workNeededTotal = 0; 76 | float workDoneTotal = 0; 77 | lock (workLock) { 78 | foreach (var kvp in workEstimated) { 79 | workNeeded.TryGetValue(kvp.Key, out float needed); 80 | workNeededTotal += Math.Max(kvp.Value, needed); 81 | workDone.TryGetValue(kvp.Key, out float done); 82 | workDoneTotal += done; 83 | } 84 | } 85 | return workNeededTotal == 0 ? 0 : (workDoneTotal / workNeededTotal); 86 | } 87 | 88 | public static string GetResults() { 89 | string str = "WorkTracker results\n"; 90 | foreach (var kvp in workEstimated) { 91 | workNeeded.TryGetValue(kvp.Key, out float needed); 92 | workDone.TryGetValue(kvp.Key, out float done); 93 | str += $" {kvp.Key} : estimated: {kvp.Value} need: {needed} done: {done}\n"; 94 | } 95 | return str; 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /Src/LayerProcGen/WorkTracker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 43c3f74bd55b2427bbf4e18b9edbcb6f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/SaveState.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b04f6db16c344c74a5cf8a6ad82fd65 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/SaveState/Runevision.SaveState.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Runevision.SaveState", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:af01629e909984b56b6ddac3cc8fe766", 6 | "GUID:bdf51211cba1541cca26870e4d9c763d" 7 | ], 8 | "includePlatforms": [], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false, 11 | "overrideReferences": false, 12 | "precompiledReferences": [], 13 | "autoReferenced": true, 14 | "defineConstraints": [], 15 | "versionDefines": [], 16 | "noEngineReferences": true 17 | } -------------------------------------------------------------------------------- /Src/SaveState/Runevision.SaveState.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97462eeaf6ea341848ff6b8b6119c1f0 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/SaveState/StateObject.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.Collections.Generic; 10 | using System.Text; 11 | 12 | namespace Runevision.SaveState { 13 | 14 | public class StateObject { 15 | public List state { get; private set; } = new List(); 16 | 17 | int hash; 18 | 19 | public static StateObject Get(int hash, StateWrapper stateObj) { 20 | return new StateObject(hash, new StateWrapper[] { stateObj }); 21 | } 22 | 23 | static StateObject temporary = new StateObject(); 24 | static StateObject GetTemporary(int hash) { 25 | temporary.hash = hash; 26 | temporary.state = StateWrapper.GetTemporary(); 27 | return temporary; 28 | } 29 | private StateObject() { } 30 | 31 | public StateObject(int hash, params StateWrapper[][] stateLists) { 32 | this.hash = hash; 33 | foreach (StateWrapper[] stateList in stateLists) 34 | state.Add(stateList); 35 | Load(); 36 | WorldState.saveCallbacks += Save; 37 | WorldState.loadCallbacks += Load; 38 | WorldState.cleanupCallbacks += Cleanup; 39 | } 40 | 41 | public void SetDontCleanup() { 42 | WorldState.cleanupCallbacks -= Cleanup; 43 | } 44 | 45 | public static T GetGlobal(int hash) { 46 | StateObject savedState = GetTemporary(hash); 47 | savedState.Load(); 48 | T value = ((StateWrapper)savedState.state[0][0]).Value; 49 | return value; 50 | } 51 | 52 | public static void SetGlobal(int hash, T value) { 53 | StateObject savedState = GetTemporary(hash); 54 | ((StateWrapper)savedState.state[0][0]).Value = value; 55 | savedState.Save(); 56 | } 57 | 58 | public void Unload() { 59 | Save(); 60 | WorldState.saveCallbacks -= Save; 61 | WorldState.loadCallbacks -= Load; 62 | WorldState.cleanupCallbacks -= Cleanup; 63 | } 64 | 65 | public void Cleanup() { 66 | WorldState.saveCallbacks -= Save; 67 | WorldState.loadCallbacks -= Load; 68 | WorldState.cleanupCallbacks -= Cleanup; 69 | } 70 | 71 | public override int GetHashCode() { 72 | return hash; 73 | } 74 | 75 | public override string ToString() { 76 | StringBuilder sb = new StringBuilder(); 77 | sb.AppendLine(string.Format("[StateObject {0}]", 78 | hash.ToString("X4"))); 79 | foreach (var w in state) { 80 | sb.Append(w.GetType().Name); 81 | sb.Append(": "); 82 | foreach (var s in w) { 83 | sb.Append(s); 84 | sb.Append(", "); 85 | } 86 | sb.Append("\n"); 87 | } 88 | return sb.ToString(); 89 | } 90 | 91 | void Load() { 92 | WorldState.instance.GetState(this); 93 | } 94 | 95 | void Save() { 96 | WorldState.instance.SetState(this); 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /Src/SaveState/StateObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2e990a4b13504d2abde42d14f00e4b8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/SaveState/StateWrapper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.Collections.Generic; 10 | 11 | namespace Runevision.SaveState { 12 | 13 | public abstract class StateWrapper { 14 | public delegate void ValueChanged(); 15 | public ValueChanged valueChanged; 16 | public abstract void SetDefault(); 17 | public abstract object objectValue { get; set; } 18 | } 19 | 20 | public class StateWrapper : StateWrapper { 21 | T value; 22 | T defaultValue; 23 | 24 | public T Value { 25 | get { return value; } 26 | set { 27 | if (this.value.Equals(value)) 28 | return; 29 | this.value = value; 30 | if (valueChanged != null) 31 | valueChanged.Invoke(); 32 | } 33 | } 34 | 35 | public StateWrapper() { } 36 | public StateWrapper(T value) { this.Value = value; defaultValue = value; } 37 | public override string ToString() { return Value.ToString(); } 38 | public override void SetDefault() { Value = defaultValue; } 39 | public override object objectValue { get { return (object)Value; } set { this.Value = (T)value; } } 40 | 41 | static List temporary = 42 | new List() { new StateWrapper[] { new StateWrapper() }}; 43 | internal static List GetTemporary() { 44 | StateWrapper temp = (StateWrapper)temporary[0][0]; 45 | temp.value = default; 46 | temp.defaultValue = default; 47 | return temporary; 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Src/SaveState/StateWrapper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2cb4e6500eb70423ca7fc6d179fdb502 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/SaveState/WorldState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bbc74565d3fa4728873f4ec244e0746 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/SaveState/WorldStateBinary.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f8d7dfe5dd9d9406f9ecd6d09f1245fb 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/SaveState/WorldStateLocal.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.IO; 10 | 11 | namespace Runevision.SaveState { 12 | 13 | public class WorldStateLocal : WorldStateBinary { 14 | public override void Save(string saveName) { 15 | using (BinaryWriter writer = new BinaryWriter(File.Open(saveName + ".bin", FileMode.Create))) 16 | Save(writer); 17 | } 18 | 19 | public override void Load(string saveName) { 20 | using (BinaryReader reader = new BinaryReader(File.Open(saveName + ".bin", FileMode.Open))) 21 | Load(reader); 22 | } 23 | 24 | public override bool HasSave(string saveName) { 25 | return File.Exists(saveName + ".bin"); 26 | } 27 | 28 | public override void DeleteSave(string saveName) { 29 | File.Delete(saveName + ".bin"); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Src/SaveState/WorldStateLocal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c20e0da2f0c304e7ea480a9b1e4e3192 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/Unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f35396f8a30f24268aadf66f5bbc1811 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Unity/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8220a68b0435544fda8ab7a52e58362c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Unity/Common/CallbackHub.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System; 10 | using UnityEngine; 11 | 12 | public class CallbackHub : MonoBehaviour { 13 | 14 | public static event Action update; 15 | public static event Action lateUpdate; 16 | public static event Action fixedUpdate; 17 | 18 | static CallbackHub instance; 19 | 20 | static int mainThreadID; 21 | public static bool isMainThread { 22 | get { return System.Threading.Thread.CurrentThread.ManagedThreadId == mainThreadID; } 23 | } 24 | 25 | void Awake() { 26 | mainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; 27 | if (instance == null) 28 | instance = this; 29 | } 30 | 31 | void Update() { 32 | update?.Invoke(); 33 | } 34 | 35 | void LateUpdate() { 36 | lateUpdate?.Invoke(); 37 | } 38 | 39 | void FixedUpdate() { 40 | fixedUpdate?.Invoke(); 41 | } 42 | 43 | public static void GuaranteeInstance() { 44 | if (instance != null) 45 | return; 46 | GameObject go = new GameObject("CallbackHub"); 47 | go.hideFlags = HideFlags.HideAndDontSave; 48 | Application.quitting += () => Destroy(go); 49 | go.AddComponent(); 50 | } 51 | 52 | public static void ExecuteOnMainThread(Action action) { 53 | if (action == null) 54 | return; 55 | if (isMainThread) { 56 | // If already on main thread, call action right away. 57 | action(); 58 | return; 59 | } 60 | 61 | // Otherwise add a callback that calls action and then removes itself. 62 | Action handler = null; 63 | handler = () => { 64 | action(); 65 | update -= handler; 66 | }; 67 | update += handler; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Src/Unity/Common/CallbackHub.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e380d9effe0f4f918a57b5a10bbf003 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Common/DebugDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d1371bf6245f347d9b232d50000656d6 3 | timeCreated: 1437745133 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: 8 | - shaderZOn: {fileID: 4800000, guid: 4b0723e29d1cc43868429c70134e2868, type: 3} 9 | - shaderZOff: {fileID: 4800000, guid: 4a4437c127aa14f04a75f51916cfe09d, type: 3} 10 | executionOrder: -200 11 | icon: {instanceID: 0} 12 | userData: 13 | assetBundleName: 14 | assetBundleVariant: 15 | -------------------------------------------------------------------------------- /Src/Unity/Common/DebugOptions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 548bf3ec60e4a4e2aa4924bcf557ddd4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/Unity/Common/ForwardingUnityWrapper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using UnityEngine; 10 | using UnityEngine.Profiling; 11 | 12 | namespace Runevision.Common { 13 | 14 | public static class ForwardingUnityWrapper { 15 | 16 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] 17 | static void Register() { 18 | Logg.ForwardMessage += Debug.Log; 19 | Logg.ForwardWarning += str => Debug.LogWarning(str + "\n\n" + StackTraceUtility.ExtractStackTrace()); 20 | Logg.ForwardError += str => Debug.LogError(str + "\n\n" + StackTraceUtility.ExtractStackTrace()); 21 | 22 | SimpleProfiler.ForwardBeginThread += (threadGroupName, threadName) => 23 | Profiler.BeginThreadProfiling(threadGroupName, threadName); 24 | SimpleProfiler.ForwardEndThread += () => Profiler.EndThreadProfiling(); 25 | SimpleProfiler.ForwardBeginSample += str => Profiler.BeginSample(str); 26 | SimpleProfiler.ForwardEndSample += () => Profiler.EndSample(); 27 | } 28 | 29 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] 30 | static void RegisterAfterSceneLoad() { 31 | CallbackHub.GuaranteeInstance(); 32 | CallbackHub.update += () => DebugOption.UpdateAnimValues(Time.unscaledDeltaTime); 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Src/Unity/Common/ForwardingUnityWrapper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84c64500fba9848edb23b947ca1f50fe 3 | timeCreated: 1453312079 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Src/Unity/Common/GLlineZOff.shader: -------------------------------------------------------------------------------- 1 | Shader "Debug/GLlineZOff" { 2 | SubShader { 3 | Pass { 4 | Blend SrcAlpha OneMinusSrcAlpha 5 | ZWrite Off 6 | ZTest Always 7 | Cull Off 8 | BindChannels { 9 | Bind "vertex", vertex 10 | Bind "color", color 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Src/Unity/Common/GLlineZOff.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a4437c127aa14f04a75f51916cfe09d 3 | timeCreated: 1437745048 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Src/Unity/Common/GLlineZOn.shader: -------------------------------------------------------------------------------- 1 | Shader "Debug/GLlineZOn" { 2 | SubShader { 3 | Pass { 4 | Blend SrcAlpha OneMinusSrcAlpha 5 | ZWrite Off 6 | Cull Off 7 | BindChannels { 8 | Bind "vertex", vertex 9 | Bind "color", color 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Src/Unity/Common/GLlineZOn.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b0723e29d1cc43868429c70134e2868 3 | timeCreated: 1437744866 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Src/Unity/Common/RunevisionUnityExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using UnityEngine; 10 | 11 | namespace Runevision.Common { 12 | 13 | public static class RunevisionUnityExtensions { 14 | 15 | // Select 2 components out of 3. 16 | public static Vector2 xy(this Vector3 v) { return new Vector2(v.x, v.y); } 17 | public static Vector2 xz(this Vector3 v) { return new Vector2(v.x, v.z); } 18 | public static Vector2 yz(this Vector3 v) { return new Vector2(v.y, v.z); } 19 | 20 | // Flatten one component out of 3. 21 | public static Vector3 oyz(this Vector3 v) { return new Vector3(0f, v.y, v.z); } 22 | public static Vector3 xoz(this Vector3 v) { return new Vector3(v.x, 0f, v.z); } 23 | public static Vector3 xyo(this Vector3 v) { return new Vector3(v.x, v.y, 0f); } 24 | 25 | // Expand 2 components to 3. 26 | public static Vector3 xyo(this Vector2 v) { return new Vector3(v.x, v.y, 0f); } 27 | public static Vector3 xoy(this Vector2 v) { return new Vector3(v.x, 0f, v.y); } 28 | public static Vector3 oxy(this Vector2 v) { return new Vector3(0f, v.x, v.y); } 29 | 30 | public static Vector3 Clamped(this Vector3 v, float length) { 31 | float l = v.magnitude; 32 | if (l > length) 33 | return v / l * length; 34 | return v; 35 | } 36 | 37 | public static void Destroy(this Object obj) { 38 | Object.Destroy(obj); 39 | } 40 | 41 | public static void DestroyIncludingMeshes(this GameObject go) { 42 | if (go == null) 43 | return; 44 | MeshFilter[] filters = go.GetComponentsInChildren(); 45 | foreach (var filter in filters) { 46 | // Only destroy meshes with negative instance IDs, 47 | // which means they were not loaded from disk. 48 | if (filter.sharedMesh.GetInstanceID() < 0) 49 | Object.Destroy(filter.sharedMesh); 50 | } 51 | Object.Destroy(go); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Src/Unity/Common/RunevisionUnityExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec215b4c20f1649b4aaa2252c9779a8c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/Unity/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 648c72f3c7ff74a8cbb0a535c08bfecc 3 | folderAsset: yes 4 | timeCreated: 1464532543 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Src/Unity/Editor/DebugOptionsWindow.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEngine; 11 | using UnityEditor; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | public class DebugOptionsWindow : EditorWindow { 16 | Vector2 scroll; 17 | GUIStyle foldoutStyle; 18 | 19 | [MenuItem("Window/Debug Options")] 20 | static void Init() { 21 | DebugOptionsWindow window = GetWindow(); 22 | window.titleContent = new GUIContent("Debug Options"); 23 | window.Show(); 24 | } 25 | 26 | void OnEnable() { 27 | DebugOption.UIChanged += Repaint; 28 | } 29 | 30 | void OnDisable() { 31 | DebugOption.UIChanged -= Repaint; 32 | } 33 | 34 | void OnGUI() { 35 | if (foldoutStyle == null || foldoutStyle.padding.left == 0) { 36 | foldoutStyle = new GUIStyle(EditorStyles.foldout); 37 | foldoutStyle.padding.left += 2; 38 | } 39 | 40 | EditorGUIUtility.hierarchyMode = true; 41 | scroll = EditorGUILayout.BeginScrollView(scroll); 42 | GUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins); 43 | foreach (DebugOption option in DebugOption.root.children) 44 | DrawOption(option, 0); 45 | GUILayout.EndVertical(); 46 | EditorGUILayout.EndScrollView(); 47 | } 48 | 49 | void DrawOption(DebugOption option, int level) { 50 | if (level > 10) 51 | return; 52 | if (option.hidden) 53 | return; 54 | 55 | if (option is DebugButton) { 56 | if (GUILayout.Button(option.name)) 57 | option.HandleClick(); 58 | } 59 | else if (option is DebugToggle) { 60 | EditorGUI.indentLevel--; 61 | bool newOn = EditorGUILayout.ToggleLeft(option.name, ((DebugToggle)option).enabledSelf); 62 | if (newOn != ((DebugToggle)option).enabledSelf) 63 | option.HandleClick(); 64 | EditorGUI.indentLevel++; 65 | } 66 | else if (option is DebugFoldout) { 67 | bool newOn = EditorGUILayout.Foldout(((DebugFoldout)option).enabledSelf, option.name, foldoutStyle); 68 | if (newOn != ((DebugFoldout)option).enabledSelf) 69 | option.HandleClick(); 70 | } 71 | 72 | DebugFoldout parent = option as DebugFoldout; 73 | if (parent != null && parent.enabledSelf) { 74 | EditorGUI.indentLevel++; 75 | foreach (DebugOption child in parent.children) 76 | DrawOption(child, level + 1); 77 | EditorGUI.indentLevel--; 78 | } 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /Src/Unity/Editor/DebugOptionsWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0893cf2b77dbb44e3a77a3965a6e7ce8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/GenerationSourceEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.LayerProcGen; 10 | using UnityEditor; 11 | using UnityEngine; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | [CustomEditor(typeof(GenerationSource))] 16 | [CanEditMultipleObjects] 17 | public class GenerationSourceEditor : Editor { 18 | public bool HasFrameBounds() { 19 | return true; 20 | } 21 | 22 | public Bounds OnGetFrameBounds() { 23 | GenerationSource source = target as GenerationSource; 24 | Vector3 size = new Vector3(source.size.x, source.size.y, source.size.y); 25 | return new Bounds(source.transform.position, size); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Src/Unity/Editor/GenerationSourceEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0412e9ee63c714d6a9bdbceff32b4cb9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/GridBounds3Drawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEditor; 11 | using UnityEngine; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | [CustomPropertyDrawer(typeof(GridBounds3))] 16 | public class GridBounds3Drawer : PropertyDrawer { 17 | GUIContent[] posLabels = { 18 | new GUIContent("X"), 19 | new GUIContent("Y"), 20 | new GUIContent("Z"), 21 | }; 22 | GUIStyle labelRight = "RightLabel"; 23 | 24 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 25 | position.height = EditorGUIUtility.singleLineHeight; 26 | Rect orig = position; 27 | position = EditorGUI.PrefixLabel(position, label); 28 | position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 29 | 30 | GUI.Label(new Rect(orig.x, position.y, orig.width - position.width - 5, position.height), "Min", labelRight); 31 | EditorGUI.MultiPropertyField(position, posLabels, property.FindPropertyRelative("min.x")); 32 | position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 33 | 34 | GUI.Label(new Rect(orig.x, position.y, orig.width - position.width - 5, position.height), "Max", labelRight); 35 | EditorGUI.MultiPropertyField(position, posLabels, property.FindPropertyRelative("max.x")); 36 | } 37 | 38 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { 39 | return EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing * 2; 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Src/Unity/Editor/GridBounds3Drawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db7701c382e144583b1bef921d42afc5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/GridBoundsDrawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEditor; 11 | using UnityEngine; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | [CustomPropertyDrawer(typeof(GridBounds))] 16 | public class GridBoundsDrawer : PropertyDrawer { 17 | GUIContent[] posLabels = { 18 | new GUIContent("X"), 19 | new GUIContent("Y") 20 | }; 21 | GUIStyle labelRight = "RightLabel"; 22 | 23 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 24 | position.height = EditorGUIUtility.singleLineHeight; 25 | Rect orig = position; 26 | position = EditorGUI.PrefixLabel(position, label); 27 | position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 28 | 29 | GUI.Label(new Rect(orig.x, position.y, orig.width - position.width - 5, position.height), "Min", labelRight); 30 | EditorGUI.MultiPropertyField(position, posLabels, property.FindPropertyRelative("min.x")); 31 | position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; 32 | 33 | GUI.Label(new Rect(orig.x, position.y, orig.width - position.width - 5, position.height), "Max", labelRight); 34 | EditorGUI.MultiPropertyField(position, posLabels, property.FindPropertyRelative("max.x")); 35 | } 36 | 37 | public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { 38 | return EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing * 2; 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Src/Unity/Editor/GridBoundsDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4677dab8d0a674bf49ae9a103b2e9b92 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/LayerNamedReferenceDrawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.LayerProcGen; 10 | using System; 11 | using System.Linq; 12 | using UnityEditor; 13 | using UnityEngine; 14 | 15 | namespace Runevision.UnityEditor { 16 | 17 | [CustomPropertyDrawer(typeof(LayerNamedReference))] 18 | public class LayerNamedReferenceDrawer : PropertyDrawer { 19 | 20 | static string[] layerTypeStrings; 21 | static GUIContent[] layerTypeContents; 22 | 23 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 24 | if (layerTypeStrings == null) { 25 | Type layerBaseType = typeof(AbstractChunkBasedDataLayer); 26 | layerTypeStrings = AppDomain.CurrentDomain.GetAssemblies() 27 | .SelectMany(assembly => assembly.GetTypes()) 28 | .Where(t => t != layerBaseType && layerBaseType.IsAssignableFrom(t) && !t.IsGenericType) 29 | .Select(t => t.FullName) 30 | .ToArray(); 31 | layerTypeContents = layerTypeStrings.Select( 32 | s => new GUIContent(s.Substring(s.LastIndexOf('.') + 1))).ToArray(); 33 | } 34 | 35 | var nameProp = property.FindPropertyRelative("className"); 36 | string currentString = nameProp.stringValue; 37 | int currentValue = Array.IndexOf(layerTypeStrings, currentString); 38 | EditorGUI.BeginChangeCheck(); 39 | int newValue = EditorGUI.Popup(position, label, currentValue, layerTypeContents); 40 | if (EditorGUI.EndChangeCheck()) 41 | nameProp.stringValue = layerTypeStrings[newValue]; 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Src/Unity/Editor/LayerNamedReferenceDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 617c4efb61f3344dca56541bab2d234c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/LayerSpecDrawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.LayerProcGen; 10 | using UnityEditor; 11 | using UnityEngine; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | [CustomPropertyDrawer(typeof(VisualizationManager.LayerSpec))] 16 | public class LayerSpecDrawer : PropertyDrawer { 17 | 18 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 19 | position.width -= 36 + EditorGUIUtility.standardVerticalSpacing; 20 | EditorGUI.PropertyField(position, property.FindPropertyRelative("layerClassName"), GUIContent.none); 21 | position.x += position.width + EditorGUIUtility.standardVerticalSpacing; 22 | position.width = 36; 23 | int oldIndent = EditorGUI.indentLevel; 24 | EditorGUI.indentLevel = 0; 25 | EditorGUI.PropertyField(position, property.FindPropertyRelative("color"), GUIContent.none); 26 | EditorGUI.indentLevel = oldIndent; 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Src/Unity/Editor/LayerSpecDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d66d8580e226a40aaa507f1601ff8fc0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/Point3Drawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEditor; 11 | using UnityEngine; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | [CustomPropertyDrawer(typeof(Point3))] 16 | public class Point3Drawer : PropertyDrawer { 17 | GUIContent[] subLabels = { 18 | new GUIContent("X"), 19 | new GUIContent("Y"), 20 | new GUIContent("Z") 21 | }; 22 | 23 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 24 | position = EditorGUI.PrefixLabel(position, label); 25 | EditorGUI.MultiPropertyField(position, subLabels, property.FindPropertyRelative("x")); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Src/Unity/Editor/Point3Drawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a56629a94e8424086b639df661e7945e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/PointDrawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEditor; 11 | using UnityEngine; 12 | 13 | namespace Runevision.UnityEditor { 14 | 15 | [CustomPropertyDrawer(typeof(Point))] 16 | public class PointDrawer : PropertyDrawer { 17 | GUIContent[] subLabels = { 18 | new GUIContent("X"), 19 | new GUIContent("Y") 20 | }; 21 | 22 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 23 | position = EditorGUI.PrefixLabel(position, label); 24 | EditorGUI.MultiPropertyField(position, subLabels, property.FindPropertyRelative("x")); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Src/Unity/Editor/PointDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a6c5e40bff1e41eaac6f29b59c8d2d6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Editor/UnitTests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 47a39fc95e0534632817b78b2d4418f0 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Src/Unity/Editor/UnitTests/MathTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using NUnit.Framework; 10 | using Runevision.Common; 11 | using UnityEngine; 12 | 13 | namespace Runevision.Testing { 14 | 15 | public class MathTests { 16 | 17 | // DFloat 18 | 19 | [Test] 20 | public void DFloatEqualsInt() { 21 | Assert.IsTrue(new DFloat(5) == 5); 22 | Assert.IsTrue(new DFloat(5) != 4); 23 | } 24 | 25 | [Test] 26 | public void DFloatEqualsFloat() { 27 | Assert.IsTrue(new DFloat(5.5f) == 5.5f); 28 | Assert.IsTrue(new DFloat(5.5f) != 5.4f); 29 | } 30 | 31 | [Test] 32 | public void DFloatMuliplyInt() { 33 | Assert.AreEqual(new DFloat(5) * 2, new DFloat(10)); 34 | Assert.AreEqual(new DFloat(0.5f) * 6, new DFloat(3)); 35 | } 36 | 37 | [Test] 38 | public void DFloatDivideInt() { 39 | Assert.AreEqual(new DFloat(5) / 2, new DFloat(2.5f)); 40 | Assert.AreEqual(new DFloat(10) / 5, new DFloat(2)); 41 | } 42 | 43 | [Test] 44 | public void DFloatLerp() { 45 | Assert.AreEqual(DFloat.Lerp(2, 10, 0.25f), new DFloat(4)); 46 | } 47 | 48 | // DPoint 49 | 50 | [Test] 51 | public void DPointEqualsVector2() { 52 | Assert.IsTrue(new DPoint(5, 4.5f) == new Vector2(5, 4.5f)); 53 | Assert.IsTrue(new DPoint(5, 4.5f) != new Vector2(5, 3)); 54 | } 55 | 56 | [Test] 57 | public void DPointEqualsPoint() { 58 | Assert.IsTrue(new DPoint(5, 4) == new Point(5, 4)); 59 | Assert.IsTrue(new DPoint(5, 4) != new Point(5, 3)); 60 | } 61 | 62 | [Test] 63 | public void DPointMagnitude() { 64 | Assert.IsTrue(new DPoint(3, 4).magnitude == 5); 65 | Assert.IsTrue(new DPoint(3, 4).magnitude != 6); 66 | } 67 | } 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Src/Unity/Editor/UnitTests/MathTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1ce6d808a75a4752863f3d6b7a51b5f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Unity/Editor/_Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "_Editor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:af01629e909984b56b6ddac3cc8fe766", 6 | "GUID:bdf51211cba1541cca26870e4d9c763d", 7 | "GUID:eedf2b075ec794c139fc663e635ee0bb", 8 | "GUID:97462eeaf6ea341848ff6b8b6119c1f0", 9 | "GUID:8ef0670089409406a939f610fb518ff4" 10 | ], 11 | "includePlatforms": [ 12 | "Editor" 13 | ], 14 | "excludePlatforms": [], 15 | "allowUnsafeCode": false, 16 | "overrideReferences": false, 17 | "precompiledReferences": [], 18 | "autoReferenced": true, 19 | "defineConstraints": [], 20 | "versionDefines": [], 21 | "noEngineReferences": false 22 | } -------------------------------------------------------------------------------- /Src/Unity/Editor/_Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdbc8a51514654ca2a6d7bdc17b1066e 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 49a6707ec081a43d6980970b7a15b5a8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/GameObjectDestruction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | 11 | namespace Runevision.LayerProcGen { 12 | 13 | /// 14 | /// A GameObject destruction to enqueue to be performed on the main thread. 15 | /// 16 | public struct QueuedGameObjectDestruction : IQueuedAction { 17 | 18 | TransformWrapper transform; 19 | bool destroyMeshes; 20 | 21 | /// 22 | /// Called by MainThreadActionQueue. 23 | /// 24 | public void Process() { 25 | if (transform.transform != null) { 26 | if (destroyMeshes) 27 | transform.transform.gameObject.DestroyIncludingMeshes(); 28 | else 29 | transform.transform.gameObject.Destroy(); 30 | } 31 | } 32 | 33 | /// 34 | /// Enqueue destruction on the main thread of the GameObject wrapped in the TransformWrapper. 35 | /// 36 | /// The TransformWrapper wrapping the Transform of the GameObject. 37 | /// If true, MeshFilter components are searched for non-persistent meshes, and these will be destroyed too. 38 | public static void Enqueue(TransformWrapper tr, bool destroyMeshes) { 39 | MainThreadActionQueue.Enqueue(new QueuedGameObjectDestruction { transform = tr, destroyMeshes = destroyMeshes }); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/GameObjectDestruction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97d3584c43c2a451ea410e67f923f250 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/GenerationSource.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEngine; 11 | 12 | namespace Runevision.LayerProcGen { 13 | 14 | /// 15 | /// Unity component that creates a . 16 | /// 17 | public class GenerationSource : MonoBehaviour { 18 | 19 | public LayerNamedReference layer; 20 | public Point size = Point.one; 21 | 22 | public TopLayerDependency dep { get; private set; } 23 | 24 | void OnEnable() { 25 | UpdateState(); 26 | } 27 | 28 | void OnDisable() { 29 | if (dep != null) 30 | dep.isActive = false; 31 | } 32 | 33 | void UpdateState() { 34 | if (layer == null) 35 | return; 36 | 37 | // Get layer instance. 38 | AbstractChunkBasedDataLayer instance = layer.GetLayerInstance(); 39 | 40 | // Create top layer dependency based on layer. 41 | if (instance != null && (dep == null || dep.layer != instance)) { 42 | if (dep != null) 43 | dep.isActive = false; 44 | dep = new TopLayerDependency(instance, size); 45 | } 46 | } 47 | 48 | void Update() { 49 | UpdateState(); 50 | if (dep == null) 51 | return; 52 | 53 | Vector3 focusPos = transform.position; 54 | Point focus; 55 | if (LayerManagerBehavior.instance.generationPlane == LayerManagerBehavior.GenerationPlane.XZ) 56 | focus = (Point)(focusPos.xz()); 57 | else 58 | focus = (Point)(focusPos.xy()); 59 | if (!dep.isActive || focus != dep.focus) 60 | dep.SetFocus(focus); 61 | 62 | Point safeSize = Point.Max(Point.one, size); 63 | if (!dep.isActive || dep.size != safeSize) 64 | dep.SetSize(safeSize); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/GenerationSource.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c4cf5e19ddc8e4a0eab971574202728a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/LayerManagerBehavior.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using System; 11 | using UnityEngine; 12 | #if PACKAGE_UNITY_UI 13 | using UnityEngine.UI; 14 | #endif 15 | 16 | namespace Runevision.LayerProcGen { 17 | 18 | /// 19 | /// Unity component that wraps the LayerManager class. 20 | /// 21 | public class LayerManagerBehavior : MonoBehaviour { 22 | 23 | public enum GenerationPlane { XY, XZ } 24 | 25 | public static LayerManagerBehavior instance { get; private set; } 26 | 27 | public static event Action OnUpdate; 28 | 29 | public LayerManager manager { get; private set; } 30 | 31 | public bool useParallelThreads = true; 32 | public GenerationPlane generationPlane; 33 | #if PACKAGE_UNITY_UI 34 | public Text debugQueueText; 35 | public Text debugStatusText; 36 | #endif 37 | 38 | void Awake() { 39 | manager = new LayerManager(useParallelThreads); 40 | instance = this; 41 | } 42 | 43 | void OnDestroy() { 44 | manager.OnDestroy(); 45 | } 46 | 47 | protected virtual void Update() { 48 | MainThreadActionQueue.ProcessQueue(); 49 | DebugDrawer.xzMode = (generationPlane == GenerationPlane.XZ); 50 | OnUpdate?.Invoke(); 51 | 52 | #if PACKAGE_UNITY_UI 53 | if (debugQueueText && debugQueueText.enabled) 54 | debugQueueText.text = MainThreadActionQueue.idle ? string.Empty 55 | : "Action Queue: " + MainThreadActionQueue.queueCount; 56 | if (debugStatusText && debugStatusText.enabled) 57 | debugStatusText.text = SimpleProfiler.GetStatus(); 58 | #endif 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/LayerManagerBehavior.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 63f788e7d356b4a5cafd9dc42d4b15e2 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/TransformWrapper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using Runevision.Common; 10 | using UnityEngine; 11 | 12 | namespace Runevision.LayerProcGen { 13 | 14 | /// 15 | /// Transform stand-in that chunks can create outside of the main thread. 16 | /// 17 | public class TransformWrapper { 18 | 19 | public Transform transform { get; private set; } 20 | 21 | Transform layerParent; 22 | Point chunkIndex; 23 | 24 | public TransformWrapper(Transform layerParent, Point chunkIndex) { 25 | this.layerParent = layerParent; 26 | this.chunkIndex = chunkIndex; 27 | } 28 | 29 | /// 30 | /// Creates the wrapper's own Transform if it doesn't exist, then adds the child. 31 | /// 32 | public void AddChild(Transform child, bool matchParentLayer = false) { 33 | // Ignore if layerParent is null. This can sometimes happen while unloading a scene. 34 | if (layerParent == null) 35 | return; 36 | if (transform == null) { 37 | transform = new GameObject("Chunk" + chunkIndex).transform; 38 | transform.SetParent(layerParent, false); 39 | transform.gameObject.layer = layerParent.gameObject.layer; 40 | } 41 | child.SetParent(transform, false); 42 | if (matchParentLayer) 43 | child.gameObject.layer = transform.gameObject.layer; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/TransformWrapper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04257feb29c3c43fa969526ab946d1ee 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Src/Unity/LayerProcGen/VisualizationManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 85ca4b91f6f7b43e99055b67c253781f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/Runevision.Unity.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Runevision.Unity", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:af01629e909984b56b6ddac3cc8fe766", 6 | "GUID:eedf2b075ec794c139fc663e635ee0bb", 7 | "GUID:97462eeaf6ea341848ff6b8b6119c1f0", 8 | "GUID:bdf51211cba1541cca26870e4d9c763d", 9 | "GUID:2bafac87e7f4b9b418d9448d219b01ab" 10 | ], 11 | "includePlatforms": [], 12 | "excludePlatforms": [], 13 | "allowUnsafeCode": false, 14 | "overrideReferences": false, 15 | "precompiledReferences": [], 16 | "autoReferenced": true, 17 | "defineConstraints": [], 18 | "versionDefines": [ 19 | { 20 | "name": "com.unity.ugui", 21 | "expression": "", 22 | "define": "PACKAGE_UNITY_UI" 23 | } 24 | ], 25 | "noEngineReferences": false 26 | } -------------------------------------------------------------------------------- /Src/Unity/Runevision.Unity.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ef0670089409406a939f610fb518ff4 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/Unity/SaveState.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9d779ab92e1d47268968749b11c2691 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FBPPChooser.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using UnityEngine; 10 | 11 | namespace Runevision.SaveState { 12 | 13 | public static class FBPPChooser { 14 | 15 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] 16 | static void Register() { 17 | WorldState.instance = new WorldStateFBPP(); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FBPPChooser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37099d6596ecd482d9bc52b6fb1606a7 3 | timeCreated: 1453312079 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e2c18e7de7c3541348334ab81b5bf75c 3 | folderAsset: yes 4 | timeCreated: 1638361071 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Richard Elms 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1bf9d2aa345b34249ad8dd7b673c3125 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d96598735a5849279947af5a51a9593 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68f4d3b9737104fbab944117cada614a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/Runtime/FBPP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d90b86305cb1b4e70a96970526afed26 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/Runtime/FBPPConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | public class FBPPConfig { 5 | private const string DEFAULT_SAVE_FILE_NAME = "saveData.txt"; 6 | private const string DEFAULT_ENCRYPTION_SECRET = "encryption-secret-default"; 7 | 8 | public string SaveFileName = DEFAULT_SAVE_FILE_NAME; 9 | 10 | public bool AutoSaveData = true; 11 | 12 | public bool ScrambleSaveData = true; 13 | 14 | public string EncryptionSecret = DEFAULT_ENCRYPTION_SECRET; 15 | 16 | public string SaveFilePath = null; 17 | 18 | public Action OnLoadError; 19 | 20 | internal string GetSaveFilePath() { 21 | return string.IsNullOrEmpty(SaveFilePath) ? Application.persistentDataPath : SaveFilePath; 22 | } 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/Runtime/FBPPConfig.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26ccb3b1d6bfd4e3e9c042f31a39db70 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/FileBasedPlayerPrefs/Runtime/FBPPSaveFileModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a12b345fefbb4570b29565e59a59bad 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/WorldStateFBPP.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Rune Skovbo Johansen 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | using System.IO; 10 | 11 | namespace Runevision.SaveState { 12 | 13 | public class WorldStateFBPP : WorldStateBinary { 14 | public override void Save(string saveName) { 15 | using (MemoryStream stream = new MemoryStream()) { 16 | using (BinaryWriter writer = new BinaryWriter(stream)) { 17 | Save(writer); 18 | } 19 | stream.Flush(); 20 | FBPP.SetString(saveName, System.Convert.ToBase64String(stream.ToArray())); 21 | FBPP.Save(); 22 | } 23 | } 24 | 25 | public override void Load(string saveName) { 26 | string tmp = FBPP.GetString(saveName, string.Empty); 27 | using (MemoryStream stream = new MemoryStream(System.Convert.FromBase64String(tmp))) 28 | using (BinaryReader reader = new BinaryReader(stream)) 29 | Load(reader); 30 | } 31 | 32 | public override bool HasSave(string saveName) { 33 | return FBPP.HasKey(saveName); 34 | } 35 | 36 | public override void DeleteSave(string saveName) { 37 | FBPP.DeleteKey(saveName); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Src/Unity/SaveState/WorldStateFBPP.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bb3f89e62e56463baa79ec85cc8aad7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | -------------------------------------------------------------------------------- /Third Party Notices.md: -------------------------------------------------------------------------------- 1 | This package contains third-party software components governed by the licenses indicated below: 2 | 3 | FBPP (File Based Player Prefs) 4 | ------------------------------ 5 | License type: MIT License 6 | () 7 | 8 | Copyright (c) 2017 Richard Elms 9 | 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | 29 | 30 | RandomHash class 31 | ---------------- 32 | License type: BSD 2-Clause License 33 | () 34 | 35 | C# implementation of xxHash optimized for producing random numbers 36 | from one or more input integers. 37 | Copyright (C) 2024 Rune Skovbo Johansen. 38 | 39 | Based on: 40 | xxHashSharp - A pure C# implementation of xxhash 41 | Copyright (C) 2014 Seok-Ju, Yun. 42 | 43 | 44 | Based on: 45 | xxHash - Extremely Fast Hash algorithm 46 | Copyright (C) 2012-2014 Yann Collet 47 | 48 | 49 | Redistribution and use in source and binary forms, with or without 50 | modification, are permitted provided that the following conditions are 51 | met: 52 | 53 | - Redistributions of source code must retain the above copyright 54 | notice, this list of conditions and the following disclaimer. 55 | - Redistributions in binary form must reproduce the above 56 | copyright notice, this list of conditions and the following 57 | disclaimer in the documentation and/or other materials provided 58 | with the distribution. 59 | 60 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 61 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 62 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 63 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 64 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 65 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 66 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 67 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 68 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 69 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 70 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 71 | -------------------------------------------------------------------------------- /Third Party Notices.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce73f9cb0b86145c383f4bad71370d02 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------