public static Entity CreateEntity(EntityManager entity_manager, UnityEngine.Vector3 localPos, UnityEngine.Quaternion localRot, ref AtomicFloat life, Entity parent_entity, ref RandomLocal random) { var entity = entity_manager.CreateEntity(archetype_); entity_manager.SetComponentData(entity, LockTarget.Create(ref life)); entity_manager.SetComponentData(entity, new Position { Value = localPos, }); entity_manager.SetComponentData(entity, new Rotation { Value = localRot, }); entity_manager.SetComponentData(entity, random.create()); var attach_entity = entity_manager.CreateEntity(typeof(Attach)); entity_manager.SetComponentData(attach_entity, new Attach { Parent = parent_entity, Child = entity, }); return(entity); }
public bool Exists(ref AtomicFloat afloat) { int index = get_index(ref afloat); var value = (m_Table + index)->m_Value; return((value & ALIVE_FLG) != 0 && (value & ~ALIVE_FLG) == afloat.Version); }
int get_index(ref AtomicFloat afloat) { long ptrdiff = (long)afloat.m_Data - (long)m_Data; long index = ptrdiff / GetUnitSize(); Assert.AreEqual(index * GetUnitSize(), ptrdiff); return((int)index); }
public static LockTarget Create(ref AtomicFloat parent_life, bool has_direction = false) { return(new LockTarget() { locked_time_ = CV.MaxValue, fired_time_ = CV.MaxValue, estimated_time_arrival_ = CV.MaxValue, parent_life_ = parent_life, has_direction_ = has_direction ? 1 : 0, }); }
public void Destroy(ref AtomicFloat afloat) { for (;;) { if (!Exists(ref afloat)) { return; } int index = get_index(ref afloat); var current = (m_Table + index)->m_Value; var next = (current & ~ALIVE_FLG) + 1; var prev = Interlocked.CompareExchange(ref (m_Table + index)->m_Value, next, current); if (prev == current) { return; } } }