public void SendToChildren() { AddAllListeners(); A.SendEventToChildren(UnitTestEventType.TestEventType, EventPool.New <AEventData>()); AreNotEqual(A.Triggered, 1); AreEqual(A1.Triggered, 1); AreEqual(A11a.Triggered, 1); AreEqual(A11b.Triggered, 1); AreEqual(A12.Triggered, 1); AreEqual(A2.Triggered, 1); AreEqual(A21.Triggered, 1); AreEqual(A22.Triggered, 1); AreNotEqual(B.Triggered, 1); AreNotEqual(B1.Triggered, 1); AreNotEqual(B11.Triggered, 1); AreNotEqual(B12.Triggered, 1); AreNotEqual(B2.Triggered, 1); AreNotEqual(B21.Triggered, 1); AreNotEqual(B22.Triggered, 1); RemoveAllListeners(); Reset(); }
public void DontSendToOneMultipleTimes() { AddAllListeners(); var targets = new List <GameObject> { A.gameObject, A1.gameObject, A11a.gameObject, A12.gameObject }; this.SendEventWithChildren(UnitTestEventType.TestEventType, EventPool.New <AEventData>(), targets); AreEqual(A.Triggered, 1); AreEqual(A1.Triggered, 1); AreEqual(A11a.Triggered, 1); AreEqual(A11b.Triggered, 1); AreEqual(A12.Triggered, 1); AreEqual(A2.Triggered, 1); AreEqual(A21.Triggered, 1); AreEqual(A22.Triggered, 1); AreNotEqual(B.Triggered, 1); AreNotEqual(B1.Triggered, 1); AreNotEqual(B11.Triggered, 1); AreNotEqual(B12.Triggered, 1); AreNotEqual(B2.Triggered, 1); AreNotEqual(B21.Triggered, 1); AreNotEqual(B22.Triggered, 1); RemoveAllListeners(); Reset(); }
private void OnMouseDown() { EventPool.Trigger(EventTypes.Cancel); GetComponent <SpriteRenderer>().enabled = false; GetComponent <Collider2D>().enabled = false; transform.GetChild(0).gameObject.SetActive(false); }
public EventPool Wait(Predicate cancelPoller) { IsCancel = cancelPoller; EventPool result; lock (Events) { if (Events.Count == 0) { Log.Info("Waiting for changes..."); OnWait(); Monitor.Wait(Events); FirstChangeInSeries = true; } if (IsCancel()) { return(null); } result = Events; Events = new EventPool(); } return(result); }
/// <summary> /// 初始化网络频道基类的新实例。 /// </summary> /// <param name="name">网络频道名称。</param> /// <param name="networkChannelHelper">网络频道辅助器。</param> public NetworkChannelBase(string name, INetworkChannelHelper networkChannelHelper) { m_Name = name ?? string.Empty; m_SendPacketPool = new Queue <Packet>(); m_ReceivePacketPool = new EventPool <Packet>(EventPoolMode.Default); m_NetworkChannelHelper = networkChannelHelper; m_AddressFamily = AddressFamily.Unknown; m_ResetHeartBeatElapseSecondsWhenReceivePacket = false; m_HeartBeatInterval = DefaultHeartBeatInterval; m_Socket = null; m_SendState = new SendState(); m_ReceiveState = new ReceiveState(); m_HeartBeatState = new HeartBeatState(); m_SentPacketCount = 0; m_ReceivedPacketCount = 0; m_Active = false; m_Disposed = false; NetworkChannelConnected = null; NetworkChannelClosed = null; NetworkChannelMissHeartBeat = null; NetworkChannelError = null; NetworkChannelCustomError = null; networkChannelHelper.Initialize(this); }
private bool TryBatchTransfer(EventPool changes) { // TODO: tune threshold for optimal speed if (true || changes.Count < 100) { // TODO: run batch sync on the end: measure speed of changes return(false); } Log.Info("To many changes. Need to fallback to batch method"); foreach (var root in GetChangedRoots(changes)) { if (IsCancel()) { return(true); } if (!RunBatchTransfer(root)) { return(false); } } return(true); }
public void Remove(UnitController unit) { BattlefieldUnit battlefieldUnit = (from placeUnit in PlaceUnitList where placeUnit.Unit == unit select placeUnit).First(); battlefieldUnit.Unit = null; #region Check if end of battle bool playersArmy = battlefieldUnit.Place.PlayersArmy; bool end = true; foreach (BattlefieldUnit placeUnit in PlaceUnitList) { if (placeUnit.Place.PlayersArmy == playersArmy && placeUnit.Unit != null) { end = false; } } if (end) { EventPool.Trigger(EventTypes.EndBattle, !playersArmy); } #endregion }
public void SendToListWhithoutChildren() { AddAllListeners(); var targets = new List <GameObject> { A1.gameObject, A12.gameObject, B.gameObject, B22.gameObject }; this.SendEvent(UnitTestEventType.TestEventType, EventPool.New <AEventData>(), targets); AreNotEqual(A.Triggered, 1); AreEqual(A1.Triggered, 1); AreNotEqual(A11a.Triggered, 1); AreNotEqual(A11b.Triggered, 1); AreEqual(A12.Triggered, 1); AreNotEqual(A2.Triggered, 1); AreNotEqual(A21.Triggered, 1); AreNotEqual(A22.Triggered, 1); AreEqual(B.Triggered, 1); AreNotEqual(B1.Triggered, 1); AreNotEqual(B11.Triggered, 1); AreNotEqual(B12.Triggered, 1); AreNotEqual(B2.Triggered, 1); AreNotEqual(B21.Triggered, 1); AreEqual(B22.Triggered, 1); RemoveAllListeners(); Reset(); }
public void SendToAll() { AddAllListeners(); this.SendEvent(UnitTestEventType.TestEventType, EventPool.New <AEventData>()); AreEqual(A.Triggered, 1); AreEqual(A1.Triggered, 1); AreEqual(A11a.Triggered, 1); AreEqual(A11b.Triggered, 1); AreEqual(A12.Triggered, 1); AreEqual(A2.Triggered, 1); AreEqual(A21.Triggered, 1); AreEqual(A22.Triggered, 1); AreEqual(B.Triggered, 1); AreEqual(B1.Triggered, 1); AreEqual(B11.Triggered, 1); AreEqual(B12.Triggered, 1); AreEqual(B2.Triggered, 1); AreEqual(B21.Triggered, 1); AreEqual(B22.Triggered, 1); RemoveAllListeners(); AreEqual(EventDispatcher.GetListernerNumber(), 0); Reset(); }
// Use this for initialization void Awake() { editor = GetComponent <ChartEditor>(); GameObject groupMovePool = new GameObject("Main Song Object Pool"); noteParent = new GameObject("Notes"); starpowerParent = new GameObject("Starpowers"); bpmParent = new GameObject("BPMs"); timesignatureParent = new GameObject("Time Signatures"); sectionParent = new GameObject("Sections"); songEventParent = new GameObject("Global Events"); chartEventParent = new GameObject("Chart Events"); notePool = new NotePool(noteParent, editor.notePrefab, NOTE_POOL_SIZE); noteParent.transform.SetParent(groupMovePool.transform); spPool = new StarpowerPool(starpowerParent, editor.starpowerPrefab, POOL_SIZE); starpowerParent.transform.SetParent(groupMovePool.transform); bpmPool = new BPMPool(bpmParent, editor.bpmPrefab, POOL_SIZE); bpmParent.transform.SetParent(groupMovePool.transform); tsPool = new TimesignaturePool(timesignatureParent, editor.tsPrefab, POOL_SIZE); timesignatureParent.transform.SetParent(groupMovePool.transform); sectionPool = new SectionPool(sectionParent, editor.sectionPrefab, POOL_SIZE); sectionParent.transform.SetParent(groupMovePool.transform); songEventPool = new EventPool(songEventParent, editor.songEventPrefab, POOL_SIZE); songEventParent.transform.SetParent(groupMovePool.transform); chartEventPool = new ChartEventPool(chartEventParent, editor.chartEventPrefab, POOL_SIZE); chartEventParent.transform.SetParent(groupMovePool.transform); }
public void OnAwake() { This = this; m_EventPool = new EventPool <CGEventArgs>(EventPoolMode.AllowNoHandler | EventPoolMode.AllowMultiHandler); UploadEvent(); }
private void Update() { if (Input.GetKeyDown(KeyCode.S)) { // Triggering an event can be done from anywhere in your code. EventPool.Trigger <string, int, float>("MousePos", Input.mousePosition.x.ToString(), Mathf.RoundToInt(Input.mousePosition.y), Input.mousePosition.z); } }
public void CharacterDamage(EntityRefCharacter Character, FP Damage) { var ev = EventPool <EventCharacterDamage> .Alloc(); ev._Character = Character; ev._Damage = Damage; _f.AddEvent(ev); }
private void OnMouseDown() { if (!Targetable) { return; } EventPool.Trigger(EventTypes.Targeted, this); }
/// <summary> /// Releases acquired resources. /// </summary> public void Dispose() { lock (this) { EventPool.RecycleEvent(this.IsReceivedEvent); this.IsReceivedEvent = EventPool.GlobalStubEvent; } }
public override void Dispose() { if (_audioSourceList != null) { AudioSourceList.Clear(); AudioTypeList.Clear(); } EventPool.Remove(GetInstanceID(), EventNames.ON_AUDIO_VOLUME_CTRL, OnAudioMute); }
protected override void DefaultAction() { _unitController.Defense += Increase; _unitController.StatusEffects.Add(new StatusEffect { Type = StatusEffectType.DefUp, OwnTurns = Duration, GlobalTurns = -1, RemoveEffect = delegate { _unitController.Defense -= Increase; } }); EventPool.Trigger(EventTypes.ActionNoTarget, _unitController.PlayersArmy); }
/// <summary> /// 释放事件缓存中的事件数据包并清空事件缓存。 /// </summary> /// <param name="eventDic">事件缓存。</param> private void ClearCache(Dictionary <string, List <EventData> > eventDic) { foreach (List <EventData> events in eventDic.Values) { foreach (EventData e in events) { EventPool.Delete(e); } events.Clear(); } }
public Event() { apes = new EventPool(); forest = new EventPool(); personal = new EventPool(); word = new EventPool(); block = new EventPool(); Add_Apes_Event(); Add_Forest_Event(); Add_Personal_Event(); Add_Word_Event(); }
protected override void DefaultAction() { BattlefieldUnits battlefieldUnits = InfoPool.Request <BattlefieldUnits>("Battlefield units"); foreach (UnitController unit in battlefieldUnits.Units) { unit.Health -= 1; } EventPool.Trigger(EventTypes.ActionNoTarget, _avatarController.Player); gameObject.SetActive(false); }
public NetworkChannel(string name, INetworkChannel networkChannelHelper) { m_Name = name ?? string.Empty; m_EventPool = new EventPool<Packet>(EventPoolMode.Defalut); m_NetworkChannelHelper = networkChannelHelper; m_Socket = null; m_ReceiveState = new ReceiveState(); m_Disposed = false; NetworkChannelConnected = null; networkChannelHelper.Initialize(this); }
/// <summary> /// 初始化网络管理器的新实例。 /// </summary> public NetworkManager() { m_NetworkChannels = new Dictionary <string, NetworkChannel>(); m_EventPool = new EventPool <Packet>(EventPoolMode.Default); m_NetworkHelper = null; m_NetworkConnectedEventHandler = null; m_NetworkClosedEventHandler = null; m_NetworkSendPacketEventHandler = null; m_NetworkMissHeartBeatEventHandler = null; m_NetworkErrorEventHandler = null; m_NetworkCustomErrorEventHandler = null; }
private EventPool RetrieveChanges(ChangesMonitor source) { if (LostLifeChanges.Count == 0) { return(source.Wait(IsCancel)); } // we failed last time and there are unprocessed changes var changes = new EventPool(LostLifeChanges); LostLifeChanges.Clear(); return(changes); }
private void OnDisable() { EventPool.StopListening(EventTypes.Move, Move); EventPool.StopListening <Transform>(EventTypes.MoveTo, MoveTo); EventPool.StopListening <bool>(EventTypes.ActionNoTarget, NoTargetAction); EventPool.StopListening <ActionType, UnitController>(EventTypes.ActionEnemyTarget, TargetEnemy); EventPool.StopListening <ActionType, UnitController>(EventTypes.ActionFriendlyTarget, TargetFriend); EventPool.StopListening <ActionType, AvatarController>(EventTypes.ActionFriendlyTargetAvatar, TargetFriend); EventPool.StopListening(EventTypes.Cancel, CancelAction); EventPool.StopListening <UnitController>(EventTypes.Targeted, ExecuteTargetingAction); EventPool.StopListening <UnitController>(EventTypes.UnitDeath, RemoveUnit); InfoPool.Unprovide("Battlefield units", GetBattlefieldUnits); }
public void PlaySetting(AudioSource audioSource, AudioType audioType) { int findIndex = AudioSourceList.BinarySearch(audioSource, new AudioSourceComparer()); if (findIndex < 0) { AudioSourceList.Add(audioSource); AudioTypeList.Add(audioType); } else { AudioTypeList[findIndex] = audioType; } EventPool.Listen(GetInstanceID(), EventNames.ON_AUDIO_VOLUME_CTRL, OnAudioMute); }
public static T GetEvent <T>() where T : IInputEventBase, new() { string cmdKey = typeof(T).Name; if (!m_eventPool.ContainsKey(cmdKey)) { EventPool pool = new EventPool(); pool.Init <T>(3); m_eventPool.Add(cmdKey, pool); } return((T)m_eventPool[cmdKey].GetEvent()); }
public void UpdateTest() { sum = 0; EventPool <int> eventPool = new EventPool <int>(); var t = eventPool.CreateChannel("a"); t.Events += Ac; for (int i = 0; i < 100; i++) { int k = i; Task.Run(() => t.Fire(this, k)); } Thread.Sleep(100); eventPool.Update(); Assert.AreEqual(5050, sum); }
protected override void Start() { base.Start(); UnityAction oldAction = Action; Action = delegate { oldAction(); EventPool.StartListening <UnitController>(EventTypes.Targeted, Target); }; Target = delegate(UnitController unitController) { DefaultTarget(unitController); EventPool.StopListening <UnitController>(EventTypes.Targeted, Target); }; }
public void Functions_OnOnDutyStateChanged(bool onDuty) { if (onDuty) { Common.RegisterCallouts(); if (Settings.AmbientEvents.EnableAmbientEvents) { EventPool.EventsController(); } Globals.HeliCamera.ManagerFiber.Start(); // set up integration with PoliceSmartRadio if (IsLSPDFRPluginRunning("PoliceSmartRadio")) { PoliceSmartRadioAvailable = true; PoliceSmartRadioFunctions = new PoliceSmartRadioFunctions(); } GameFiber.StartNew(delegate { Logger.LogTrivial("Functions fiber started"); while (true) { GameFiber.Yield(); if (Controls.ToggleBinoculars.IsJustPressed() && !Game.LocalPlayer.Character.IsInAnyVehicle(false) && !Binoculars.IsActive && Settings.General.IsBinocularEnable) { Binoculars.EnableBinoculars(); } if (Controls.ToggleInteractionMenu.IsJustPressed() && !Binoculars.IsActive) { InteractionMenu.DisEnable(); } } }); Game.DisplayNotification("~g~<font size=\"14\"><b>WILDERNESS CALLOUTS</b></font>~s~~n~Version: ~b~" + WildernessCallouts.Common.GetVersion( @"Plugins\LSPDFR\Wilderness Callouts.dll") + "~s~~n~Loaded!"); } }
public static void MainMenuOnItemSelected(UIMenu sender, UIMenuItem selectedItem, int index) { GameFiber.StartNew(delegate { if (selectedItem == AskFishingLicenseItem || selectedItem == AskHuntingLicenseItem) { Ped closestPed = World.GetAllPeds().Where(x => x.IsAlive && x != Game.LocalPlayer.Character && x.IsHuman && !x.IsInAnyVehicle(false) && Vector3.Distance(x.Position, Game.LocalPlayer.Character.Position) < 12.5f).OrderBy(x => x.Position.DistanceTo(Game.LocalPlayer.Character.Position)).FirstOrDefault(); if (closestPed.Exists()) { closestPed.Tasks.AchieveHeading(closestPed.GetHeadingTowards(Game.LocalPlayer.Character)).WaitForCompletion(2000); Object id = new Object("hei_prop_hei_id_bank", Vector3.Zero); closestPed.Tasks.PlayAnimation("mp_common", "givetake1_a", 2.5f, AnimationFlags.None); id.AttachToEntity(closestPed, closestPed.GetBoneIndex(PedBoneId.RightPhHand), Vector3.Zero, new Rotator(0.0f, 180.0f, 0.0f)); GameFiber.Sleep(1200); if (selectedItem == AskFishingLicenseItem) { WildernessCallouts.Common.FishingLicense(closestPed); } else if (selectedItem == AskHuntingLicenseItem) { WildernessCallouts.Common.HuntingLicense(closestPed); } id.Delete(); StaticPeds.Add(closestPed); } } else if (selectedItem == CallAirAmbulanceItem) { Ped pedToRescue = WildernessCallouts.Common.GetPedToRescue(); AirParamedic airpara = new AirParamedic(pedToRescue, "You can leave, we will take care of him, thanks", "You can leave, we will take care of her, thanks"); airpara.Start(); } else if (selectedItem == CallVetItem) { Ped animal = WildernessCallouts.Common.GetValidAnimalForVetPickup(); Vet vet = new Vet(animal); vet.Start(); } #if DEBUG else if (selectedItem == CreateEventItem) { EventPool.CreateEvent(); } #endif }); }