Skip to content

Commit

Permalink
Version 0.4.0 Release
Browse files Browse the repository at this point in the history
Feature release for Entities [0.17.0]
  • Loading branch information
Dreaming381 committed Aug 9, 2021
1 parent 769b1da commit e98dc08
Show file tree
Hide file tree
Showing 105 changed files with 3,980 additions and 457 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## [0.4.0] – 2021-8-9

Officially supports Entities [0.17.0]

### Changed

- Updated Core to v0.4.0
- Updated Psyshock to v0.4.0
- Updated Myri to v0.4.0
- Updated Optimization Adventure Samples

## [0.3.3] – 2021-6-19

Officially supports Entities [0.17.0]
Expand Down
4 changes: 2 additions & 2 deletions Core/Core/Framework/BlackboardEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public DynamicBuffer<T> GetBuffer<T>() where T : struct, IBufferElementData
return em.GetBuffer<T>(entity);
}

public void AddCollectionComponent<T>(T value) where T : struct, ICollectionComponent
public void AddCollectionComponent<T>(T value, bool isInitialized = true) where T : struct, ICollectionComponent
{
em.AddCollectionComponent(entity, value);
em.AddCollectionComponent(entity, value, isInitialized);
}

public T GetCollectionComponent<T>(bool readOnly, out JobHandle handle) where T : struct, ICollectionComponent
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Framework/ILatiosSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface ILatiosSystem
BlackboardEntity sceneBlackboardEntity { get; }

bool ShouldUpdateSystem();
void OnNewScene();

EntityQuery GetEntityQuery(EntityQueryDesc desc);

Expand Down
34 changes: 31 additions & 3 deletions Core/Core/Framework/LatiosWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,25 @@ namespace Latios
public class LatiosWorld : World
{
public BlackboardEntity worldBlackboardEntity { get; private set; }
#if ENABLE_UNITY_COLLECTIONS_CHECKS
private BlackboardEntity m_sceneBlackboardEntity;
private bool m_sceneBlackboardSafetyOverride;
public BlackboardEntity sceneBlackboardEntity
{
get
{
if (m_sceneBlackboardEntity == Entity.Null && !m_sceneBlackboardSafetyOverride)
{
throw new InvalidOperationException(
"The sceneBlackboard Entity has not been initialized yet. If you are trying to access this entity in OnCreate(), please use OnNewScene() or another callback instead.");
}
return m_sceneBlackboardEntity;
}
private set => m_sceneBlackboardEntity = value;
}
#else
public BlackboardEntity sceneBlackboardEntity { get; private set; }
#endif

public SyncPointPlaybackSystem syncPoint
{
Expand Down Expand Up @@ -56,13 +74,10 @@ public LatiosWorld(string name) : base(name)
BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentSystemStateTag<>), typeof(ICollectionComponent));

worldBlackboardEntity = new BlackboardEntity(EntityManager.CreateEntity(), EntityManager);
sceneBlackboardEntity = new BlackboardEntity(EntityManager.CreateEntity(), EntityManager);
worldBlackboardEntity.AddComponentData(new WorldBlackboardTag());
sceneBlackboardEntity.AddComponentData(new SceneBlackboardTag());

#if UNITY_EDITOR
EntityManager.SetName(worldBlackboardEntity, "World Blackboard Entity");
EntityManager.SetName(sceneBlackboardEntity, "Scene Blackboard Entity");
#endif

useExplicitSystemOrdering = true;
Expand Down Expand Up @@ -90,14 +105,27 @@ internal void FrameStart()

internal void CreateNewSceneBlackboardEntity()
{
#if ENABLE_UNITY_COLLECTIONS_CHECKS
m_sceneBlackboardSafetyOverride = true;
#endif
if (!EntityManager.Exists(sceneBlackboardEntity) || !sceneBlackboardEntity.HasComponent<SceneBlackboardTag>())
{
sceneBlackboardEntity = new BlackboardEntity(EntityManager.CreateEntity(), EntityManager);
sceneBlackboardEntity.AddComponentData(new SceneBlackboardTag());
#if UNITY_EDITOR
EntityManager.SetName(sceneBlackboardEntity, "Scene Blackboard Entity");
#endif
foreach (var system in Systems)
{
if (system is ILatiosSystem latiosSystem)
{
latiosSystem.OnNewScene();
}
}
}
#if ENABLE_UNITY_COLLECTIONS_CHECKS
m_sceneBlackboardSafetyOverride = false;
#endif
}

#region AutoDependencies
Expand Down
6 changes: 6 additions & 0 deletions Core/Core/Framework/SubSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ protected sealed override void OnDestroy()

public EntityQuery GetEntityQuery(EntityQueryDesc desc) => GetEntityQuery(new EntityQueryDesc[] { desc });

public abstract void OnNewScene();

internal JobHandle SystemBaseDependency
{
get => Dependency;
Expand All @@ -74,6 +76,10 @@ public abstract class SubSystem : SubSystemBase

protected new abstract void OnUpdate();

public override void OnNewScene()
{
}

internal override void OnCreateInternal()
{
OnCreate();
Expand Down
4 changes: 4 additions & 0 deletions Core/Core/Framework/SuperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ internal static void UpdateManagedSystem(ComponentSystemBase system)
UnityEngine.Debug.LogException(e);
}
}

public virtual void OnNewScene()
{
}
}
}

8 changes: 8 additions & 0 deletions Core/Core/GameplayToolkit.meta

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

49 changes: 49 additions & 0 deletions Core/Core/GameplayToolkit/EntityWith.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Unity.Entities;

namespace Latios
{
public struct EntityWith<T> where T : struct, IComponentData
{
public Entity entity;

public EntityWith(Entity entity)
{
this.entity = entity;
}

public T this[ComponentDataFromEntity<T> cdfe]
{
get => cdfe[entity];
set => cdfe[entity] = value;
}

public bool IsValid(ComponentDataFromEntity<T> cdfe) => cdfe.HasComponent(entity);

public bool DidChange(ComponentDataFromEntity<T> cdfe, uint version) => cdfe.DidChange(entity, version);

public static implicit operator Entity(EntityWith<T> entityWith) => entityWith.entity;

public static implicit operator EntityWith<T>(Entity entity) => new EntityWith<T>(entity);
}

public struct EntityWithBuffer<T> where T : struct, IBufferElementData
{
public Entity entity;

public EntityWithBuffer(Entity entity)
{
this.entity = entity;
}

public DynamicBuffer<T> this[BufferFromEntity<T> bfe] => bfe[entity];

public bool IsValid(BufferFromEntity<T> bfe) => bfe.HasComponent(entity);

public bool DidChange(BufferFromEntity<T> bfe, uint version) => bfe.DidChange(entity, version);

public static implicit operator Entity(EntityWithBuffer<T> entityWithBuffer) => entityWithBuffer.entity;

public static implicit operator EntityWithBuffer<T>(Entity entity) => new EntityWithBuffer<T>(entity);
}
}

11 changes: 11 additions & 0 deletions Core/Core/GameplayToolkit/EntityWith.cs.meta

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

5 changes: 5 additions & 0 deletions Core/Core/Math/LatiosMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public static float3 RotateExtents(float3 extents, float3x3 rotationMatrix)
return RotateExtents(extents, rotationMatrix.c0, rotationMatrix.c1, rotationMatrix.c2);
}

public static float2 ComplexMul(float2 a, float2 b)
{
return new float2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}

#endregion Transformations

#region NumberTricks
Expand Down
99 changes: 99 additions & 0 deletions Core/Core/Math/Rng.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Unity.Mathematics;

namespace Latios
{
public struct Rng
{
uint m_state;

public Rng(uint seed)
{
m_state = seed;
}

public Rng(string seedString)
{
m_state = math.asuint(seedString.GetHashCode());
}

public Rng Shuffle()
{
var sequence = new RngSequence(new uint2(m_state, math.asuint(int.MinValue)));
m_state = sequence.NextUInt();
return this;
}

public RngSequence GetSequence(int index)
{
return new RngSequence(new uint2(math.asuint(index), m_state));
}

public struct RngSequence
{
uint2 m_state;

public RngSequence(uint2 initialState)
{
m_state = initialState;
}

uint NextState()
{
//From https://www.youtube.com/watch?v=LWFzPP8ZbdU
//This version is SquirrelNoise5, which was posted on the author's Twitter: https://twitter.com/SquirrelTweets/status/1421251894274625536.
// This is a Unity C# adaptation of SquirrelNoise5 - Squirrel's Raw Noise utilities (version 5).
// The following code within this scope is licensed by Squirrel Eiserloh under the Creative Commons Attribution 3.0 license (CC-BY-3.0 US).
var val = m_state.x * 0xd2a80a3f;
val += m_state.y;
val ^= (val >> 9);
val += 0xa884f197;
val ^= (val >> 11);
val *= 0x6c736f4b;
val ^= (val >> 13);
val += 0xb79f3abb;
val ^= (val >> 15);
val += 0x1b56c4f5;
val ^= (val >> 17);
m_state.x = val;
return val;
}

public bool NextBool() => RngToolkit.AsBool(NextState());
public bool2 NextBool2() => RngToolkit.AsBool2(NextState());
public bool3 NextBool3() => RngToolkit.AsBool3(NextState());
public bool4 NextBool4() => RngToolkit.AsBool4(NextState());

public uint NextUInt() => NextState();
public uint2 NextUInt2() => new uint2(NextState(), NextState());
public uint3 NextUInt3() => new uint3(NextState(), NextState(), NextState());
public uint4 NextUInt4() => new uint4(NextState(), NextState(), NextState(), NextState());
public uint NextUInt (uint min, uint max) => RngToolkit.AsUInt(NextState(), min, max);
public uint2 NextUInt2(uint2 min, uint2 max) => RngToolkit.AsUInt2(NextUInt2(), min, max);
public uint3 NextUInt3(uint3 min, uint3 max) => RngToolkit.AsUInt3(NextUInt3(), min, max);
public uint4 NextUInt4(uint4 min, uint4 max) => RngToolkit.AsUInt4(NextUInt4(), min, max);

public int NextInt() => RngToolkit.AsInt(NextState());
public int2 NextInt2() => RngToolkit.AsInt2(NextUInt2());
public int3 NextInt3() => RngToolkit.AsInt3(NextUInt3());
public int4 NextInt4() => RngToolkit.AsInt4(NextUInt4());
public int NextInt(int min, int max) => RngToolkit.AsInt(NextState(), min, max);
public int2 NextInt2(int2 min, int2 max) => RngToolkit.AsInt2(NextUInt2(), min, max);
public int3 NextInt3(int3 min, int3 max) => RngToolkit.AsInt3(NextUInt3(), min, max);
public int4 NextInt4(int4 min, int4 max) => RngToolkit.AsInt4(NextUInt4(), min, max);

public float NextFloat() => RngToolkit.AsFloat(NextState());
public float2 NextFloat2() => RngToolkit.AsFloat2(NextUInt2());
public float3 NextFloat3() => RngToolkit.AsFloat3(NextUInt3());
public float4 NextFloat4() => RngToolkit.AsFloat4(NextUInt4());
public float NextFloat(float min, float max) => RngToolkit.AsFloat(NextState(), min, max);
public float2 NextFloat2(float2 min, float2 max) => RngToolkit.AsFloat2(NextUInt2(), min, max);
public float3 NextFloat3(float3 min, float3 max) => RngToolkit.AsFloat3(NextUInt3(), min, max);
public float4 NextFloat4(float4 min, float4 max) => RngToolkit.AsFloat4(NextUInt4(), min, max);

public float2 NextFloat2Direction() => RngToolkit.AsFloat2Direction(NextState());
public float3 NextFloat3Direction() => RngToolkit.AsFloat3Direction(NextUInt2());
public quaternion NextQuaternionRotation() => RngToolkit.AsQuaternionRotation(NextUInt3());
}
}
}

11 changes: 11 additions & 0 deletions Core/Core/Math/Rng.cs.meta

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

Loading

0 comments on commit e98dc08

Please sign in to comment.