Releases: PixeyeHQ/actors.unity
Actors Framework
ENG
Breaking changes & Improvements:
- The boilerplate code for components transferred from
static partial class Components
{
public const string Health = "Pixeye.Source.ComponentHealth";
[RuntimeInitializeOnLoadMethod]
static void ComponentHealthInit() => new SComponentHealth();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentHealth ComponentHealth(in this ent entity)
=> ref Storage<ComponentHealth>.components[entity.id];
internal class SComponentHealth : Storage<ComponentHealth>.Setup
{
public override ComponentHealth Create() => new ComponentHealth();
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.val = 0;
component.valMax = 0;
}
}
}
}
to
static partial class component
{
public const string health = "Pixeye.Source.ComponentHealth";
public static ref ComponentHealth ComponentHealth(in this ent entity)
=> ref StorageComponentHealth.components[entity.id];
}
sealed class StorageComponentHealth : Storage<ComponentHealth>
{
public override ComponentHealth Create() => new ComponentHealth();
public override void Dispose()
{
for (int i = 0; i < disposedLen; i++)
{
ref var component = ref components[disposed[i]];
component.val = 0;
component.valMax = 0;
}
}
}
-
[GroupWantEvent]
attribute changed to[WantEvent]
-
[GroupExclude]
attribute changed to[Exclude]
-
You can gain slightly better performance at project initialization by defining a namespace you use for your components in the framework settings file. ```SettingsFramework.json````
{
"SizeEntities": 1024, // initial size of entity arrays
"SizeComponents": 256, // how many components can be registered
"SizeGenerations": 4, // you don't need to change anything
"SizeProcessors": 64, // how many processors you want
"DataNamespace": "Pixeye.Source" // define namespace that you use in your components.
}
RU
Изменения и улучшения
- Настроечный код изменен с
static partial class Components
{
public const string Health = "Pixeye.Source.ComponentHealth";
[RuntimeInitializeOnLoadMethod]
static void ComponentHealthInit() => new SComponentHealth();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentHealth ComponentHealth(in this ent entity)
=> ref Storage<ComponentHealth>.components[entity.id];
internal class SComponentHealth : Storage<ComponentHealth>.Setup
{
public override ComponentHealth Create() => new ComponentHealth();
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.val = 0;
component.valMax = 0;
}
}
}
}
на
static partial class component
{
public const string health = "Pixeye.Source.ComponentHealth";
public static ref ComponentHealth ComponentHealth(in this ent entity)
=> ref StorageComponentHealth.components[entity.id];
}
sealed class StorageComponentHealth : Storage<ComponentHealth>
{
public override ComponentHealth Create() => new ComponentHealth();
public override void Dispose()
{
for (int i = 0; i < disposedLen; i++)
{
ref var component = ref components[disposed[i]];
component.val = 0;
component.valMax = 0;
}
}
}
-
[GroupWantEvent]
атрибут изменен на[WantEvent]
-
[GroupExclude]
атрибут изменен на[Exclude]
-
Инициализацию проекта на старте можно ускорить настроив файл ```SettingsFramework.json````
( находится в ресурсах, если нет то создайте вручную )
{
"SizeEntities": 1024, // стартовое кол-во сущностей
"SizeComponents": 256, // кол-во компонентов
"SizeGenerations": 4, // кол-во поколений компонентов ( скорее все вам непонадобится это менять )
"SizeProcessors": 64, // кол-во процессоров
"DataNamespace": "Pixeye.Source" // какой namespace используется для компонентов.
}
Actors Framework
Fixes:
- Op.All in group events works correctly
- Adding entities from Add/Remove group events works correctly
Breaking changes :
- Processors can work as groups. It's useful when you want to have only one group in the processor.
// Add OnAdd, OnRemove events for group.
[GroupWantEvent(Op.Add | Op.Remove)]
sealed class ProcessorObserver : Processor<ComponentObserver>, ITick
{
public void Tick(float delta)
{
for (int i = 0; i < source.length; i++)
{
ref var cObserver = ref source.entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
public override void OnAdd(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].FirstTime();
}
}
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
}
- OnAdd / OnRemove delegates for entities groups were changed with event class. Also the event method holds all entities that were added/removed to the group at the current frame.
sealed class ProcessorUI : Processor, ITick
{
Group<ComponentUI> groupUI;
public ProcessorUI()
{
// Add Events to the group and choose event type.
groupUI.Set<Events>(Op.Remove);
// You can choose both events as well.
// groupUI.Set<Events>(Op.Add|Op.Remove);
}
// Make a special class for events.
class Events : GroupEvents
{
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var entity = ref entities[i];
var cUI = entity.ComponentUI();
cUI.view.Release();
}
}
}
}
- Components boilerplate code have changed.
sealed class ComponentFSM
{
public IFSM source;
public int stateNext = -1;
public int stateCurrent = -1;
}
#region HELPERS
static partial class Components
{
[RuntimeInitializeOnLoadMethod]
static void ComponentFSMInit() => new SComponentFSM();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentFSM ComponentFSM(in this ent entity)
=> ref Storage<ComponentFSM>.components[entity.id];
internal class SComponentFSM : Storage<ComponentFSM>.Setup
{
// Component create method.
public override ComponentFSM Create() => new ComponentFSM();
// Optional dispose method for all components that must be removed on the current frame.
// Use this method to revert component to default setup or clean links.
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.source = null;
component.stateCurrent = -1;
component.stateNext = -1;
}
}
}
}
Actors Framework
Fixes:
- Op.All in group events works correctly
- Adding entities from Add/Remove group events works correctly
Breaking changes :
- Processors can work as groups. It's useful when you want to have only one group in the processor.
// Add OnAdd, OnRemove events for group.
[GroupWantEvent(Op.Add | Op.Remove)]
sealed class ProcessorObserver : Processor<ComponentObserver>, ITick
{
public void Tick(float delta)
{
for (int i = 0; i < source.length; i++)
{
ref var cObserver = ref source.entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
public override void OnAdd(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].FirstTime();
}
}
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
}
- OnAdd / OnRemove delegates for entities groups were changed with event class. Also the event method holds all entities that were added/removed to the group at the current frame.
sealed class ProcessorUI : Processor, ITick
{
Group<ComponentUI> groupUI;
public ProcessorUI()
{
// Add Events to the group and choose event type.
groupUI.Set<Events>(Op.Remove);
// You can choose both events as well.
// groupUI.Set<Events>(Op.Add|Op.Remove);
}
// Make a special class for events.
class Events : GroupEvents
{
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var entity = ref entities[i];
var cUI = entity.ComponentUI();
cUI.view.Release();
}
}
}
}
- Components boilerplate code have changed.
sealed class ComponentFSM
{
public IFSM source;
public int stateNext = -1;
public int stateCurrent = -1;
}
#region HELPERS
static partial class Components
{
[RuntimeInitializeOnLoadMethod]
static void ComponentFSMInit() => new SComponentFSM();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentFSM ComponentFSM(in this ent entity)
=> ref Storage<ComponentFSM>.components[entity.id];
internal class SComponentFSM : Storage<ComponentFSM>.Setup
{
// Component create method.
public override ComponentFSM Create() => new ComponentFSM();
// Optional dispose method for all components that must be removed on the current frame.
// Use this method to revert component to default setup or clean links.
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.source = null;
component.stateCurrent = -1;
component.stateNext = -1;
}
}
}
}
Actors Framework
Fixes:
- Component boilerplate initialization.
Breaking changes :
- Processors can work as groups. It's useful when you want to have only one group in the processor.
// Add OnAdd, OnRemove events for group.
[GroupWantEvent(Op.Add | Op.Remove)]
sealed class ProcessorObserver : Processor<ComponentObserver>, ITick
{
public void Tick(float delta)
{
for (int i = 0; i < source.length; i++)
{
ref var cObserver = ref source.entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
public override void OnAdd(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].FirstTime();
}
}
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
}
- OnAdd / OnRemove delegates for entities groups were changed with event class. Also the event method holds all entities that were added/removed to the group at the current frame.
sealed class ProcessorUI : Processor, ITick
{
Group<ComponentUI> groupUI;
public ProcessorUI()
{
// Add Events to the group and choose event type.
groupUI.Set<Events>(Op.Remove);
// You can choose both events as well.
// groupUI.Set<Events>(Op.Add|Op.Remove);
}
// Make a special class for events.
class Events : GroupEvents
{
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var entity = ref entities[i];
var cUI = entity.ComponentUI();
cUI.view.Release();
}
}
}
}
- Components boilerplate code have changed.
sealed class ComponentFSM
{
public IFSM source;
public int stateNext = -1;
public int stateCurrent = -1;
}
#region HELPERS
static partial class Components
{
[RuntimeInitializeOnLoadMethod]
static void ComponentFSMInit() => new SComponentFSM();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentFSM ComponentFSM(in this ent entity)
=> ref Storage<ComponentFSM>.components[entity.id];
internal class SComponentFSM : Storage<ComponentFSM>.Setup
{
// Component create method.
public override ComponentFSM Create() => new ComponentFSM();
// Optional dispose method for all components that must be removed on the current frame.
// Use this method to revert component to default setup or clean links.
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.source = null;
component.stateCurrent = -1;
component.stateNext = -1;
}
}
}
}
Actors Framework
Breaking changes :
- Processors can work as groups. It's useful when you want to have only one group in the processor.
// Add OnAdd, OnRemove events for group.
[GroupWantEvent(Op.Add | Op.Remove)]
sealed class ProcessorObserver : Processor<ComponentObserver>, ITick
{
public void Tick(float delta)
{
for (int i = 0; i < source.length; i++)
{
ref var cObserver = ref source.entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
public override void OnAdd(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].FirstTime();
}
}
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
}
- OnAdd / OnRemove delegates for entities groups were changed with event class. Also the event method holds all entities that were added/removed to the group at the current frame.
sealed class ProcessorUI : Processor, ITick
{
Group<ComponentUI> groupUI;
public ProcessorUI()
{
// Add Events to the group and choose event type.
groupUI.Set<Events>(Op.Remove);
// You can choose both events as well.
// groupUI.Set<Events>(Op.Add|Op.Remove);
}
// Make a special class for events.
class Events : GroupEvents
{
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var entity = ref entities[i];
var cUI = entity.ComponentUI();
cUI.view.Release();
}
}
}
}
- Components boilerplate code have changed.
sealed class ComponentFSM
{
public IFSM source;
public int stateNext = -1;
public int stateCurrent = -1;
}
#region HELPERS
static partial class Components
{
static SComponentFSM sComponentFSM = new SComponentFSM();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentFSM ComponentFSM(in this ent entity)
=> ref Storage<ComponentFSM>.components[entity.id];
internal class SComponentFSM : Storage<ComponentFSM>.Setup
{
// Component create method.
public override ComponentFSM Create() => new ComponentFSM();
// Optional dispose method for all components that must be removed on the current frame.
// Use this method to revert component to default setup or clean links.
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.source = null;
component.stateCurrent = -1;
component.stateNext = -1;
}
}
}
}
Actors Framework
Breaking changes :
- Processors can work as groups. It's useful when you want to have only one group in the processor.
// Add OnAdd, OnRemove events for group.
[GroupWantEvent(Op.Add | Op.Remove)]
sealed class ProcessorObserver : Processor<ComponentObserver>, ITick
{
public void Tick(float delta)
{
for (int i = 0; i < source.length; i++)
{
ref var cObserver = ref source.entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
public override void OnAdd(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].FirstTime();
}
}
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var cObserver = ref entities[i].ComponentObserver();
for (int j = 0; j < cObserver.length; j++)
cObserver.wrappers[j].Check();
}
}
}
- OnAdd / OnRemove delegates for entities groups were changed with event class. Also the event method holds all entities that were added/removed to the group at the current frame.
sealed class ProcessorUI : Processor, ITick
{
Group<ComponentUI> groupUI;
public ProcessorUI()
{
// Add Events to the group and choose event type.
groupUI.Set<Events>(Op.Remove);
// You can choose both events as well.
// groupUI.Set<Events>(Op.Add|Op.Remove);
}
// Make a special class for events.
class Events : GroupEvents
{
public override void OnRemove(ent[] entities, int length)
{
for (int i = 0; i < length; i++)
{
ref var entity = ref entities[i];
var cUI = entity.ComponentUI();
cUI.view.Release();
}
}
}
}
- Components boilerplate code have changed.
sealed class ComponentFSM
{
public IFSM source;
public int stateNext = -1;
public int stateCurrent = -1;
}
#region HELPERS
static partial class Components
{
static SComponentFSM sComponentFSM = new SComponentFSM();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref ComponentFSM ComponentFSM(in this ent entity)
=> ref Storage<ComponentFSM>.components[entity.id];
internal class SComponentFSM : Storage<ComponentFSM>.Setup
{
// Component create method.
public override ComponentFSM Create() => new ComponentFSM();
// Optional dispose method for all components that must be removed on the current frame.
// Use this method to revert component to default setup or clean links.
public override void Dispose(int[] id, int len)
{
for (int i = 0; i < len; i++)
{
ref var component = ref components[id[i]];
component.source = null;
component.stateCurrent = -1;
component.stateNext = -1;
}
}
}
}
Actors Framework
2019.8.16 Merge branch 'master' of https://github.com/dimmpixeye/ecs
Actors Framework
Changes:
- If you use tags group filter, please set Tools->Actors->Tags->Set Tags Check
- If you want to write components on structs, please set Tools->Actors-> Set Struct Components
Added:
- Multithread groups. An example of how to use them
Actors Framework
Bug fixes
Changes:
You don't need to use deploy(); method after Set methods.
Actors Framework
Changes:
-
The framework can use structs for components. To enable this feature to define ACTORS_COMPONENTS_STRUCTS in the scripting define symbols.
Don't use this feature with projects you already work with. -
BufferStruct doesn't expand anymore. If you use BufferStruct make sure you allocate enough spaced to run everything.
-
DiposeAction of components changed. It passes the entity instead of the component. Make sure to refactor all components dispose of action.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void DisposeComponentHealth(in ent entity)
{
ref var component = ref Storage<ComponentHealth>.Instance.components[entity.id];
}
Изменения:
-
Для компонентов можно использовать структуры. Подключите ACTORS_COMPONENTS_STRUCTS в scripting define symbols проекта.
Не используйте на проекте над которым уже работаете. -
BufferStruct не расширяются. Заранее определите нужный размер BufferStruct для работы.
-
DiposeAction компонентов поменялись. Пример как оформлять выше.