riversong code showcase
This commit is contained in:
47
Source/Riversong/Game/World/EntityIdMap/EntityIdMap.cs
Normal file
47
Source/Riversong/Game/World/EntityIdMap/EntityIdMap.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class EntityIdMap : IDisposable
|
||||
{
|
||||
private NativeGrid<EntityIdMapValue> _data;
|
||||
|
||||
public EntityIdMap(int2 size)
|
||||
{
|
||||
_data = new NativeGrid<EntityIdMapValue>(size, Allocator.Persistent);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_data?.Dispose();
|
||||
_data = null;
|
||||
}
|
||||
|
||||
public void SetBuildingId(TileRect rect, int id)
|
||||
{
|
||||
foreach (var tile in TileRange.From(rect))
|
||||
{
|
||||
ref var value = ref _data.GetValueRW(tile);
|
||||
value.BuildingId = id;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetResourceNodeId(int2 tile, int id)
|
||||
{
|
||||
ref var value = ref _data.GetValueRW(tile);
|
||||
value.ResourceNodeId = id;
|
||||
}
|
||||
|
||||
public ref EntityIdMapValue GetValueRW(int2 tile)
|
||||
{
|
||||
return ref _data.GetValueRW(tile);
|
||||
}
|
||||
|
||||
public NativeArray<EntityIdMapValue> GetNativeArray()
|
||||
{
|
||||
return _data.GetNativeArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user