Skip to content

Instantly share code, notes, and snippets.

View jeffvella's full-sized avatar
🏠
Working from home

Jeffrey Vella jeffvella

🏠
Working from home
  • Montréal, Canada
View GitHub Profile
using NUnit.Framework;
using System;
using System.Diagnostics;
using System.Linq;
using Unity.Collections;
using Unity.Entities;
using Unity.PerformanceTesting;
namespace Packages.com.vella.events.Tests
{
using NUnit.Framework;
using System;
using System.Diagnostics;
using System.Linq;
using Unity.Collections;
using Unity.Entities;
using Unity.PerformanceTesting;
namespace Packages.com.vella.events.Tests
{
[Test, Performance, TestCategory(TestCategory.Performance)]
public void CompareToDefaultApproaches([Values(1, 25, 100, 250, 1000, 5000)] int eventsPerArchetype)
{
var system = World.GetOrCreateSystem<EntityEventSystem>();
var components = new[]
{
ComponentType.ReadWrite<EntityEvent>(),
ComponentType.ReadWrite<EcsTestData>(),
};
var archetype = Manager.CreateArchetype(components);
static unsafe class EntityComponentID
{
internal static uint NextID() => ++EntityComponentIDCounter.Ref.Data.Id; // first id = 1
}
public struct SomeGenericParam { }
public struct MyStaticData
{
public uint Id;
using System;
using Unity.Entities;
namespace Vella.Events
{
/// <summary>
/// System that is responsible for creating the EntityEventSystem.
/// It allows a package user to control where the <see cref="EntityEventSystem"/> is located.
/// </summary>
[UpdateInGroup(typeof(InitializationSystemGroup))]
public struct C1 : IComponentData { }
public struct C2 : IComponentData { }
public struct C3 : IComponentData { }
[Test]
unsafe public void HasTest()
{
Manager.CreateEntity(new[]
public struct MyComponent : IComponentData
{
public Entity Reference;
public int Value;
}
public struct MyElement : IBufferElementData
{
public Entity Reference;
public int Value;
public struct MyComponent : IComponentData
{
public Entity Reference;
public int Value;
}
public class MySystem : SystemBase
{
protected override void OnUpdate()
{
public class ScoreSystem : SystemBase
{
public const int BaseScoreMultiplier = 10;
private EventQueue<ScoreAddedEvent> _addScoreQueue;
protected override void OnCreate()
{
_addScoreQueue = World.GetOrCreateSystem<EntityEventSystem>().GetQueue<ScoreAddedEvent>();
}
int count;
int* countPtr = &count;
NativeKeyValueArrays<int, UnsafeEventBatch> pairsMaster = default;
NativeArray<Entity> entitiesMaster = default;
var pairsPtr = UnsafeUtility.AddressOf(ref pairsMaster);
var entitiesPtr = UnsafeUtility.AddressOf(ref entitiesMaster);
var sw = Stopwatch.StartNew();