Skip to content

Commit

Permalink
Add terrain structure generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeickhoff committed Jul 27, 2023
1 parent a21adc5 commit f14acce
Show file tree
Hide file tree
Showing 29 changed files with 467 additions and 310 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
/[Pp]rofile[Aa]nalyzer/

# output dir
/Bin/
Expand Down
Binary file modified Assets/Materials/Textures/SpriteSheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Assets/Materials/Textures/SpriteSheet.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8bf58c69bf424fe194d229f05ce07072, type: 3}
m_Name:
m_EditorClassIdentifier:
editorArgs: -streaming_type host -emulation disabled -debug
editorArgs: -streaming_type host -emulation disabled
--- !u!1 &2101193216
GameObject:
m_ObjectHideFlags: 0
Expand Down
9 changes: 3 additions & 6 deletions Assets/Scripts/CmdArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public static ClientServerBootstrap.PlayType getPlayType()
}

private static StreamingRole DefaultStreamingRole = StreamingRole.Disabled;
#else
// All clients are assumed hosts, a command line argument is necessary to start as a streaming Guest
private const StreamingRole DefaultStreamingRole = StreamingRole.Host;

#endif
#if UNITY_EDITOR
public static StreamingRole ClientStreamingRole
{
get
Expand All @@ -40,8 +34,11 @@ public static StreamingRole ClientStreamingRole
set => DefaultStreamingRole = value;
}
#else
// All clients are assumed hosts, a command line argument is necessary to start as a streaming Guest
private const StreamingRole DefaultStreamingRole = StreamingRole.Host;
public static StreamingRole ClientStreamingRole { get; set; } = DefaultStreamingRole;
#endif

public static bool DebugEnabled = false;
public static bool EmulationEnabled = false;
public static EmulationType emulationType = EmulationType.None;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/CmdArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void OnEnable()
break;
}
}
#if UNITY_EDITOR
#if UNITY_EDITOR && !UNITY_SERVER
Debug.Log($"Client streaming role is {CmdArgs.ClientStreamingRole} {CmdArgs.getPlayType()}");
#endif
// Debug flag, used for rendering outlines
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class Env
public const int AREA_POW = 4;

//! How many terrain areas from world bottom to world top
public const int AREA_COLUMN_HEIGHT = 8;
public const int AREA_COLUMN_HEIGHT = 4;
public const int HALF_AREA_COLUMN_HEIGHT = 4;

#region DO NOT CHANGE THESE!
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Networking/NetCodeBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public static World CreateClientWorld(string name, WorldFlags flags, IReadOnlyLi
DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);

ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(world);
#endif

if (World.DefaultGameObjectInjectionWorld == null)
World.DefaultGameObjectInjectionWorld = world;

return world;
#endif
}


Expand Down
9 changes: 6 additions & 3 deletions Assets/Scripts/Terrain/Authoring/TerrainAreaAuthoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ public struct TerrainColMaxY : IBufferElementData
}

[InternalBufferCapacity(32)]
// Buffer of terrain area columns we need to spawn but haven't yet
// Buffer of terrain area structures we need to spawn but haven't yet
public struct TerrainStructuresToSpawn : IBufferElementData
{
public int3 localPos;
public int3 basePos;
public StructureType structureType;
public int3 extents;
public int3 extentsPos;
public int3 extentsNeg;
public int noise;
public int3 offset;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public override void Bake(TerrainSpawnerAuthoring authoring)
minHeight = layer.MinHeight,
maxHeight= layer.MaxHeight,
amplitude = layer.MaxHeight - layer.MinHeight,
chance = layer.Chance
chance = layer.Chance,
});
}

Expand Down
8 changes: 6 additions & 2 deletions Assets/Scripts/Terrain/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public enum BlockType : byte
Dirt,
Tin,
Gem,
Grass
Grass,
Leaf,
Wood
}
public static class BlockData
{
Expand All @@ -20,7 +22,9 @@ public static class BlockData
(2 & 31) << 24,
(3 & 31) << 24,
(4 & 31) << 24,
(5 & 31) << 24
(5 & 31) << 24,
(6 & 31) << 24,
(7 & 31) << 24,
};
}

Expand Down
51 changes: 50 additions & 1 deletion Assets/Scripts/Terrain/Structures/StructureTypes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
namespace Opencraft.Terrain.Structures
using System.Runtime.CompilerServices;
using Unity.Mathematics;

namespace Opencraft.Terrain.Structures
{
public static class Structure
{
// Tree structure vars
public const int MIN_TRUNK_HEIGHT = 3;
public const int TREE_NOISE_RANGE = 2;
public const int MIN_CROWN_RADIUS = 1;
public const int MAX_CROWN_RADIUS = MIN_CROWN_RADIUS + TREE_NOISE_RANGE;

// Encodes the sizes of various structures
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int3 StructureToExtents(StructureType structureType, bool negativeBounds = false)
{
int3 ret = new int3(0);
switch (structureType)
{
case StructureType.Tree:
if (negativeBounds)
ret = new int3(MAX_CROWN_RADIUS,
0,
MAX_CROWN_RADIUS);
else
ret = new int3(MAX_CROWN_RADIUS,
MIN_TRUNK_HEIGHT + TREE_NOISE_RANGE + 1,
MAX_CROWN_RADIUS);
break;
}

return ret;
}

// Encodes the noise variation
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int StructureToNoiseRange(StructureType structureType)
{
int ret = 0;
switch (structureType)
{
case StructureType.Tree:
ret = TREE_NOISE_RANGE;
break;
}

return ret;
}
}

public enum StructureType
{
None,
Expand Down
Loading

0 comments on commit f14acce

Please sign in to comment.