Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameLogicSystemGroup : ComponentSystemGroup
- {
- }
- [UpdateInGroup(typeof(GameLogicSystemGroup))]
- public class StatUpdateSystemGroup : ComponentSystemGroup
- {
- }
- [UpdateInGroup(typeof(GameLogicSystemGroup))]
- [UpdateAfter(typeof(StatUpdateSystemGroup))]
- public class SkillUpdateSystemGroup: ComponentSystemGroup
- {
- }
- [UpdateInGroup(typeof(GameLogicSystemGroup), OrderFirst = true)]
- public class GameLogicStartBuffer : EntityCommandBufferSystem
- {
- }
- [UpdateInGroup(typeof(GameLogicSystemGroup), OrderLast = true)]
- public class GameLogicEndBuffer : EntityCommandBufferSystem
- {
- }
- public struct StatBlock
- {
- public int Str;
- public int Dex;
- public int Int;
- public int Con;
- public static StatBlock operator +(StatBlock a, StatBlock b)
- {
- return new StatBlock()
- {
- Str = a.Str + b.Str,
- Dex = a.Dex + b.Dex,
- Int = a.Int + b.Int,
- Con = a.Con + b.Con
- };
- }
- }
- public struct TagBaseChanged : IComponentData
- {
- }
- public struct TagModsChanged : IComponentData
- {
- }
- public struct BaseStats : IComponentData
- {
- public StatBlock Value;
- }
- [InternalBufferCapacity(10)]
- public struct StatMods : IBufferElementData
- {
- public StatBlock Value;
- }
- public struct TotalStatMods : IComponentData
- {
- public StatBlock Value;
- }
- public struct TotalStats : IComponentData
- {
- public StatBlock Value;
- }
- public struct SomeSkillA : IComponentData
- {
- public int Value;
- }
- public struct SomeSkillB : IComponentData
- {
- public int Value;
- }
- [UpdateInGroup(typeof(StatUpdateSystemGroup))]
- public partial class SystemCalcMods : SystemBase
- {
- protected override void OnUpdate()
- {
- Entities.WithAll<TagModsChanged>().ForEach((ref TotalStatMods total, in DynamicBuffer<StatMods> mods) =>
- {
- total.Value = new StatBlock();
- for (int i = 0; i < mods.Length; i++)
- total.Value += mods[i].Value;
- }).ScheduleParallel(Dependency);
- }
- }
- [UpdateInGroup(typeof(StatUpdateSystemGroup))]
- [UpdateAfter(typeof(SystemCalcMods))]
- public partial class SystemCalcStats : SystemBase
- {
- private struct job_stats : IJobEntity
- {
- public void Execute(ref TotalStats total, in TotalStatMods mods, in BaseStats stats)
- {
- total.Value = stats.Value + mods.Value;
- }
- }
- private EntityQuery query_mod, query_base, query_both;
- protected override void OnCreate()
- {
- query_base = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<TagBaseChanged>(),
- ComponentType.Exclude<TagModsChanged>());
- query_mod = EntityManager.CreateEntityQuery(ComponentType.Exclude<TagBaseChanged>(),
- ComponentType.ReadOnly<TagModsChanged>());
- query_both = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<TagBaseChanged>(),
- ComponentType.ReadOnly<TagModsChanged>());
- }
- protected override void OnUpdate()
- {
- var job = new job_stats();
- job.ScheduleParallel(query_base);
- job.ScheduleParallel(query_mod);
- job.ScheduleParallel(query_both);
- }
- }
- [UpdateInGroup(typeof(SkillUpdateSystemGroup))]
- public partial class SystemCalcSkillA : SystemBase
- {
- protected override void OnUpdate()
- {
- Entities.ForEach((ref SomeSkillA skill, in TotalStats stats) =>
- {
- skill.Value = 50 + (stats.Value.Str + stats.Value.Int) / 2;
- }).ScheduleParallel(Dependency);
- }
- }
- [UpdateInGroup(typeof(SkillUpdateSystemGroup))]
- public partial class SystemCalcSkillB : SystemBase
- {
- protected override void OnUpdate()
- {
- Entities.ForEach((ref SomeSkillB skill, in TotalStats stats) =>
- {
- skill.Value = 25 + (stats.Value.Dex + stats.Value.Con + stats.Value.Str) / 3;
- }).ScheduleParallel(Dependency);
- }
- }
- [UpdateInGroup(typeof(GameLogicSystemGroup))]
- public partial class SystemClearTagModsChanged : SystemBase
- {
- private GameLogicEndBuffer ecbSystem;
- protected override void OnCreate()
- {
- ecbSystem = World.GetOrCreateSystem<GameLogicEndBuffer>();
- }
- protected override void OnUpdate()
- {
- var ecb = ecbSystem.CreateCommandBuffer().AsParallelWriter();
- Entities.WithAll<TagModsChanged>().ForEach((Entity e, int index) =>
- {
- ecb.RemoveComponent<TagModsChanged>(index, e);
- });
- ecbSystem.AddJobHandleForProducer(Dependency);
- }
- }
- [UpdateInGroup(typeof(GameLogicSystemGroup))]
- public partial class SystemClearTagBaseChanged : SystemBase
- {
- private GameLogicEndBuffer ecbSystem;
- protected override void OnCreate()
- {
- ecbSystem = World.GetOrCreateSystem<GameLogicEndBuffer>();
- }
- protected override void OnUpdate()
- {
- var ecb = ecbSystem.CreateCommandBuffer().AsParallelWriter();
- Entities.WithAll<TagBaseChanged>().ForEach((Entity e, int index) =>
- {
- ecb.RemoveComponent<TagBaseChanged>(index, e);
- });
- ecbSystem.AddJobHandleForProducer(Dependency);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement