void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _colliderComponentId = _world.GetComponentIndex <ColliderComponent> (); _snakeComponentId = _world.GetComponentIndex <SnakeComponent> (); _collisionObjects = _world.GetFilter <ColliderComponent, DestroyComponent> (); _snakeObjects = _world.GetFilter <ColliderComponent, SnakeComponent> (); }
public static void Inject(EcsWorld world, IEcsSystem system) { var systemType = system.GetType(); if (!Attribute.IsDefined(systemType, typeof(EcsInjectAttribute))) { return; } var worldType = world.GetType(); var filterType = typeof(EcsFilter); foreach (var f in systemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { // EcsWorld if (f.FieldType.IsAssignableFrom(worldType) && !f.IsStatic) { f.SetValue(system, world); } // EcsFilter #if DEBUG if (f.FieldType == filterType) { throw new Exception( string.Format("Cant use EcsFilter type at \"{0}\" system for dependency injection, use generic version instead", system)); } #endif if (f.FieldType.IsSubclassOf(filterType) && !f.IsStatic) { f.SetValue(system, world.GetFilter(f.FieldType)); } } }
private static void Command_GetBleedingListForAllWoundedPeds() { EcsWorld world = GunshotWound3.EcsWorld; var filter = world.GetFilter <EcsFilter <GswPedComponent, PedBleedingInfoComponent> >(); if (filter.IsEmpty()) { Game.Console.Print("There are no peds with bleedings!"); return; } Game.Console.Print("Wounded Ped List:"); foreach (int i in filter) { PedBleedingInfoComponent info = filter.Components2[i]; if (info.BleedingEntities.Count > 0) { EcsEntity pedEntity = filter.Entities[i]; Game.Console.Print($"Ped {pedEntity.GetEntityName()} has bleedings:"); foreach (EcsEntity bleedingEntity in info.BleedingEntities) { PrintInfoAboutBleeding(world, bleedingEntity, info); } } } }
private static void Command_HealPlayerBleedings() { EcsWorld world = GunshotWound3.EcsWorld; var filter = world.GetFilter <EcsFilter <GswPedComponent, PlayerMarkComponent> >(); if (filter.IsEmpty()) { Game.Console.Print("There is no player in GSW3!"); return; } EcsEntity playerEntity = filter.Entities[0]; var info = world.GetComponent <PedBleedingInfoComponent>(playerEntity); if (info == null || info.BleedingEntities.Count <= 0) { Game.Console.Print("Player doesn't have any bleedings!"); return; } int bleedingsCount = info.BleedingEntities.Count; foreach (EcsEntity bleedingEntity in info.BleedingEntities) { world.RemoveEntity(bleedingEntity); } info.BleedingEntities.Clear(); Game.Console.Print($"Healed {bleedingsCount.ToString()} bleedings of player!"); }
private static void Command_GetPlayerBleedingList() { EcsWorld world = GunshotWound3.EcsWorld; var filter = world.GetFilter <EcsFilter <GswPedComponent, PlayerMarkComponent> >(); if (filter.IsEmpty()) { Game.Console.Print("There is no player in GSW3!"); return; } EcsEntity playerEntity = filter.Entities[0]; var info = world.GetComponent <PedBleedingInfoComponent>(playerEntity); if (info == null || info.BleedingEntities.Count <= 0) { Game.Console.Print("Player doesn't have any bleedings!"); return; } Game.Console.Print("Player Bleedings:"); foreach (EcsEntity bleedingEntity in info.BleedingEntities) { PrintInfoAboutBleeding(world, bleedingEntity, info); } }
private static void Command_GetNaturalMotionMessageList() { EcsWorld world = GunshotWound3.EcsWorld; var filter = world.GetFilter <EcsFilter <NaturalMotionMessagesDictComponent> >(); if (filter.IsEmpty()) { Game.Console.Print("Natural Motion System was not init!"); return; } Dictionary <string, NaturalMotionMessage> dict = filter.Components1[0].MessageDict; if (dict.Count <= 0) { Game.Console.Print("Natural Motion System was not init!"); return; } Game.Console.Print("NaturalMotionMessageList:"); foreach (string key in dict.Keys) { Game.Console.Print(key); } }
private static void Command_PlayNaturalMotionMessage( [ConsoleCommandParameter("NM-name")] string name, [ConsoleCommandParameter("Ragdoll Type")] int ragdollType, [ConsoleCommandParameter("Ragdoll Length in ms")] int ragdollLength) { EcsWorld world = GunshotWound3.EcsWorld; var filter = world.GetFilter <EcsFilter <NaturalMotionMessagesDictComponent> >(); if (filter.IsEmpty()) { Game.Console.Print("Natural Motion System was not init!"); return; } Dictionary <string, NaturalMotionMessage> dict = filter.Components1[0].MessageDict; if (dict.Count <= 0 || !dict.ContainsKey(name)) { Game.Console.Print($"Message {name} not exists!"); return; } var ped = Game.LocalPlayer.Character; NativeFunction.Natives.SET_PED_TO_RAGDOLL(ped, ragdollLength, ragdollLength, ragdollType, 0, 0, 0); NaturalMotionMessage nmMessage = dict[name]; NaturalMotionSystem.PlayNaturalMotionMessage(nmMessage, ped, new Random()); }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _world.SubscribeToEvent <ControlEvent> (OnControlEntity); _controlObjects = _world.GetFilter <ControlComponent> (); _controlComponentId = _world.GetComponentIndex <ControlComponent> (); }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _destroyObjects = _world.GetFilter <DestroyComponent> (); _destroyComponentId = _world.GetComponentIndex <DestroyComponent> (); _world.OnComponentDetach += OnComponentDetach; _world.SubscribeToEvent <DestroyEvent> (OnDestroyEntity); }
void IEcsSystem.Initialize(EcsWorld world) { _world = world; Debug.LogFormat("{0} => initialize", GetType().Name); _goObjects = _world.GetFilter <GameObjectComponent, SnakeComponent> (); _controlComponentId = _world.GetComponentIndex <ControlComponent> (); _goComponentId = _world.GetComponentIndex <GameObjectComponent> (); _snakeComponentId = _world.GetComponentIndex <SnakeComponent> (); }
private void TriggerClearBoardEvents() { var wallsFilter = _world.GetFilter <EcsFilter <Wall> >(); foreach (var ids in wallsFilter) { var entity = wallsFilter.Entities[ids]; WallReactivitySystemOnRemove.CachedWalls[entity] = wallsFilter.Components1[ids]; _world.RemoveEntity(entity); } }
//get full world state from GenerationState or savefile public void setWorld(World world, EcsWorld ecsWorld) { this.world = world; _localMap = world.localMap; _ecsWorld = ecsWorld; // add units to container // TODO add generated wild animals EcsFilter filter = ecsWorld.GetFilter(typeof(EcsFilter <UnitJobsComponent>)); foreach (var i in filter) { unitContainer.addNewPlayerUnit(filter.GetEntity(i)); } }
private void GunshotWoundTick() { _debugStopwatch.Restart(); _updateSystems.Run(); _debugStopwatch.Stop(); CheckTime(_debugStopwatch.ElapsedMilliseconds); #if DEBUG string debugSubtitles = $"ActiveEntities: {_ecsWorld.GetStats().ActiveEntities}/{_mainConfig.TicksToRefresh}\n" + $"Peds: {_ecsWorld.GetFilter<EcsFilter<WoundedPedComponent>>().EntitiesCount}\n" + $"Ms: {_debugStopwatch.ElapsedMilliseconds}"; UI.ShowSubtitle(debugSubtitles); #endif }
public static void Inject(EcsWorld world, IEcsSystem system) { var worldType = world.GetType(); var systemType = system.GetType(); var ecsFilter = typeof(EcsFilter); var ecsIndex = typeof(int); var attrEcsWorld = typeof(EcsWorldAttribute); var attrEcsFilterInclude = typeof(EcsFilterIncludeAttribute); var attrEcsFilterExclude = typeof(EcsFilterExcludeAttribute); var attrEcsIndex = typeof(EcsIndexAttribute); foreach (var f in systemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { // [EcsWorld] if (f.FieldType.IsAssignableFrom(worldType) && !f.IsStatic && Attribute.IsDefined(f, attrEcsWorld)) { f.SetValue(system, world); } // [EcsFilterInclude] if (f.FieldType == ecsFilter && !f.IsStatic) { EcsComponentMask includeMask = null; var standardFilterIncDefined = Attribute.IsDefined(f, attrEcsFilterInclude); if (standardFilterIncDefined) { includeMask = new EcsComponentMask(); var components = ((EcsFilterIncludeAttribute)Attribute.GetCustomAttribute(f, attrEcsFilterInclude)).Components; for (var i = 0; i < components.Length; i++) { includeMask.SetBit(world.GetComponentIndex(components[i]), true); } } EcsComponentMask excludeMask = null; var standardFilterExcDefined = Attribute.IsDefined(f, attrEcsFilterExclude); if (standardFilterExcDefined) { excludeMask = new EcsComponentMask(); var components = ((EcsFilterExcludeAttribute)Attribute.GetCustomAttribute(f, attrEcsFilterExclude)).Components; for (var i = 0; i < components.Length; i++) { excludeMask.SetBit(world.GetComponentIndex(components[i]), true); } } #if DEBUG && !ECS_PERF_TEST if (standardFilterIncDefined && includeMask.IsEmpty()) { throw new Exception("Include filter cant be empty at system: " + systemType.Name); } if (standardFilterExcDefined && excludeMask.IsEmpty()) { throw new Exception("Exclude filter cant be empty at system: " + systemType.Name); } if (!standardFilterIncDefined && standardFilterExcDefined) { throw new Exception("EcsFilterExclude can be applied only as pair to EcsFilterInclude at system: " + systemType.Name); } if (includeMask != null && excludeMask != null && includeMask.IsIntersects(excludeMask)) { throw new Exception("Exclude and include filters are intersected at system: " + systemType.Name); } #endif if (standardFilterIncDefined) { f.SetValue(system, world.GetFilter(includeMask, excludeMask ?? new EcsComponentMask())); } } // [EcsIndex] if (f.FieldType == ecsIndex && !f.IsStatic && Attribute.IsDefined(f, attrEcsIndex)) { var component = ((EcsIndexAttribute)Attribute.GetCustomAttribute(f, attrEcsIndex)).Component; f.SetValue(system, world.GetComponentIndex(component)); } } }
public StoneSwapSystem(EcsWorld world, ICoreEventsReceiver eventsReceiver, Match3State state) : base(state) { _world = world; _eventsReceiver = eventsReceiver; _swappingStones = world.GetFilter <EcsFilter <Stone, Swapping> >(); }
public EcsUpdateReactiveSystem(EcsWorld world) { _world = world; _reactiveFilter = _world.GetFilter <EcsFilter <EcsUpdateReactiveFlag <Inc1> > > (); }
public TestUiInputEventSystem(EcsWorld world) { _inputChangeEvents = world.GetFilter <EcsFilter <EcsUiInputChangeEvent> > (); _inputEndEvents = world.GetFilter <EcsFilter <EcsUiInputEndEvent> > (); }
public TestUiClickEventSystem(EcsWorld world) { _clickEvents = world.GetFilter <EcsFilter <EcsUiClickEvent> > (); }
public EcsReactiveSystem(EcsWorld world) { _reactiveFilter = world.GetFilter <EcsFilter <Inc1> > (); }
protected override void SetupFilters(EcsWorld world) { dxfFileDefinitionFilter = world.GetFilter <EcsFilter <DxfFileDefinition> >(); }
public TestUiEnterExitEventSystem(EcsWorld world) { _enterEvents = world.GetFilter <EcsFilter <EcsUiEnterEvent> > (); _exitEvents = world.GetFilter <EcsFilter <EcsUiExitEvent> > (); }
protected override void SetupFilters(EcsWorld world) { ncParametersFilter = world.GetFilter <EcsFilter <NcParameters> >(); }
protected override void SetupFilters(EcsWorld world) { dxfFileContentFilter = world.GetFilter <EcsFilter <DxfFileContent> >(); }
public static EcsFilter <T1, T2, T3> GetFilter <T1, T2, T3>(this EcsWorld world) where T1 : struct where T2 : struct where T3 : struct { return((EcsFilter <T1, T2, T3>)world.GetFilter(typeof(EcsFilter <T1, T2, T3>))); }
public TestUiScrollViewEventSystem(EcsWorld world) { _scrollViewEvents = world.GetFilter <EcsFilter <EcsUiScrollViewEvent> > (); }
public TestUiDragEventSystem(EcsWorld world) { _beginDragEvents = world.GetFilter <EcsFilter <EcsUiBeginDragEvent> > (); _dragEvents = world.GetFilter <EcsFilter <EcsUiDragEvent> > (); _endDragEvents = world.GetFilter <EcsFilter <EcsUiEndDragEvent> > (); }
public static EcsFilter <T1> GetFilter <T1>(this EcsWorld world) where T1 : struct { return((EcsFilter <T1>)world.GetFilter(typeof(EcsFilter <T1>))); }
protected override void SetupFilters(EcsWorld world) { ncProgramFilter = world.GetFilter <EcsFilter <NcProgram> >(); }
public static T GetFilter <T>(this EcsWorld world) where T : EcsFilter { return((world.GetFilter(typeof(T)) as T) !); }
public DestroyStoneSystem(EcsWorld world, ICoreEventsReceiver eventsReceiver, Match3State state) : base(state) { _world = world; _eventsReceiver = eventsReceiver; _destroyed = world.GetFilter <EcsFilter <Stone, Destroyed> >(); }