-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add player terrain modification, refactor namespaces
- Loading branch information
jeickhoff
committed
Jul 2, 2023
1 parent
833db7e
commit 243b58c
Showing
36 changed files
with
759 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Opencraft.Terrain; | ||
using Opencraft.Terrain.Authoring; | ||
using Unity.Entities; | ||
|
||
namespace Opencraft | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Opencraft.Player.Authoring; | ||
using Opencraft.Terrain.Authoring; | ||
using Opencraft.Terrain.Utilities; | ||
using Unity.Burst; | ||
using Unity.Collections; | ||
using Unity.Entities; | ||
using Unity.Transforms; | ||
|
||
namespace Opencraft.Player | ||
{ | ||
// Handle the terrain modification events specifically | ||
[UpdateInGroup(typeof(SimulationSystemGroup))] | ||
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)] | ||
[BurstCompile] | ||
public partial struct PlayerActionSystem : ISystem | ||
{ | ||
private BufferLookup<TerrainBlocks> _terrainBlockLookup; | ||
private NativeArray<Entity> terrainAreasEntities; | ||
|
||
[BurstCompile] | ||
public void OnCreate(ref SystemState state) | ||
{ | ||
|
||
state.RequireForUpdate<Authoring.Player>(); | ||
state.RequireForUpdate<TerrainArea>(); | ||
state.RequireForUpdate<TerrainSpawner>(); | ||
_terrainBlockLookup = state.GetBufferLookup<TerrainBlocks>(false); | ||
|
||
} | ||
|
||
[BurstCompile] | ||
public void OnUpdate(ref SystemState state) | ||
{ | ||
state.CompleteDependency(); | ||
_terrainBlockLookup.Update(ref state); | ||
var terrainAreasQuery = SystemAPI.QueryBuilder().WithAll<TerrainArea, LocalTransform>().Build(); | ||
terrainAreasEntities = terrainAreasQuery.ToEntityArray(state.WorldUpdateAllocator); | ||
|
||
foreach (var player in SystemAPI.Query<PlayerAspect>().WithAll<Simulate>()) | ||
{ | ||
// Destroy block action | ||
if (player.Input.PrimaryAction.IsSet && player.SelectedBlock.terrainAreaIndex != -1) | ||
{ | ||
|
||
Entity terrainAreaEntity = terrainAreasEntities[player.SelectedBlock.terrainAreaIndex]; | ||
if(_terrainBlockLookup.TryGetBuffer(terrainAreaEntity, out DynamicBuffer<TerrainBlocks> terrainBlocks)) | ||
{ | ||
int blockIndex = TerrainUtilities.BlockLocationToIndex(ref player.SelectedBlock.blockLoc); | ||
DynamicBuffer<int> blocks = terrainBlocks.Reinterpret<int>(); | ||
if (blocks[blockIndex] != -1) | ||
{ | ||
blocks[blockIndex] = -1; | ||
} | ||
} | ||
|
||
} | ||
// Place block action, using the neighbor of selected block | ||
if (player.Input.SecondaryAction.IsSet && player.SelectedBlock.neighborTerrainAreaIndex != -1) | ||
{ | ||
Entity terrainAreaEntity = terrainAreasEntities[player.SelectedBlock.neighborTerrainAreaIndex]; | ||
if(_terrainBlockLookup.TryGetBuffer(terrainAreaEntity, out DynamicBuffer<TerrainBlocks> terrainBlocks)) | ||
{ | ||
int blockIndex = TerrainUtilities.BlockLocationToIndex(ref player.SelectedBlock.neighborBlockLoc); | ||
DynamicBuffer<int> blocks = terrainBlocks.Reinterpret<int>(); | ||
if (blocks[blockIndex] == -1) | ||
{ | ||
blocks[blockIndex] = 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.