public void RegisterToTickManager(ThingWithComps thing) { TickerType tickerType = thing.def.tickerType; if (tickerType == TickerType.Rare) { return; // already done } if (tickerType == TickerType.Normal) { return; // faster than what we like, but we'll manage } if (tickerType == TickerType.Long) // not supported // If we get anything like this, we might want to know about it eventually. We could force in // CompTickLong support via Harmony patch. { Log.Error( "Unable to register " + thing + " to TickManager. Using this kind of LootAffixModifier is " + "(currently) unsupported for ThingDefs with tickerType=Long (like " + thing.def + ")." ); return; } // Manipulating TickLists outside of ThingDef.tickerType requires private list access // [Reflection] TickManager.tickListRare.RegisterThing(thing) FieldInfo tickListRareField = AccessTools.Field(typeof(TickManager), "tickListRare"); TickList tickListRare = (TickList)tickListRareField.GetValue(Find.TickManager); tickListRare.RegisterThing(thing); }
public static void TickPostfix(TickList __instance) { int currentTickInterval = __instance.TickInterval; TickerType currentTickType = __instance.tickType; switch (currentTickType) { case TickerType.Normal: RimThreaded.thingListNormal = __instance.thingLists[Find.TickManager.TicksGame % currentTickInterval]; RimThreaded.thingListNormalTicks = RimThreaded.thingListNormal.Count; break; case TickerType.Rare: RimThreaded.thingListRare = __instance.thingLists[Find.TickManager.TicksGame % currentTickInterval]; RimThreaded.thingListRareTicks = RimThreaded.thingListRare.Count; break; case TickerType.Long: RimThreaded.thingListLong = __instance.thingLists[Find.TickManager.TicksGame % currentTickInterval]; RimThreaded.thingListLongTicks = RimThreaded.thingListLong.Count; break; case TickerType.Never: break; default: throw new ArgumentOutOfRangeException(); } }
public static bool RegisterThing(TickList __instance, Thing t) { lock (thingsToRegister(__instance)) { thingsToRegister(__instance).Add(t); } return(false); }
public static void NormalThingPrepare() { TickList tickList = RimThreaded.callingTickManager.tickListNormal; tickList.Tick(); int currentTickInterval = tickList.TickInterval; normalThingList = tickList.thingLists[RimThreaded.callingTickManager.TicksGame % currentTickInterval]; normalThingListTicks = normalThingList.Count; }
private static List <Thing> BucketOf2(TickList __instance, Thing t, int currentTickInterval) { int hashCode = t.GetHashCode(); if (hashCode < 0) { hashCode *= -1; } return(thingLists(__instance)[hashCode % currentTickInterval]); }
public static void Postfix(bool __state, Thing thing) { if (__state) { TickList tickList = _tickListFor.Invoke(Find.TickManager, new[] { thing }) as TickList; if (tickList != null) { (_bucketOf.Invoke(tickList, new[] { thing }) as List <Thing>).Remove(thing); } } }
private void GoForward(Object o, EventArgs e) { _Sim.TimeSize = 100000; _Sim.Advance(); if (_Sim.Changers.ContainsKey(_Symbol)) { // define price here Price = (this.Ask + this.Bid) / 2.0; TickList.Add(Price); OnInstrumentUpdate(this); } }
public static bool Tick(TickList __instance) { currentTickType = tickType(__instance); currentTickInterval = get_TickInterval(__instance); List <Thing> tr = thingsToRegister(__instance); for (int index = 0; index < tr.Count; ++index) { Thing i = tr[index]; List <Thing> b = BucketOf(__instance, i); b.Add(i); } tr.Clear(); List <Thing> td = thingsToDeregister(__instance); for (int index = 0; index < td.Count; ++index) { Thing i = td[index]; List <Thing> b = BucketOf(__instance, i); b.Remove(i); } td.Clear(); if (DebugSettings.fastEcology) { Find.World.tileTemperatures.ClearCaches(); for (int index1 = 0; index1 < thingLists(__instance).Count; ++index1) { List <Thing> thingList = thingLists(__instance)[index1]; for (int index2 = 0; index2 < thingList.Count; ++index2) { if (thingList[index2].def.category == ThingCategory.Plant) { thingList[index2].TickLong(); } } } } thingList1 = thingLists(__instance)[Find.TickManager.TicksGame % currentTickInterval]; thingQueue = new ConcurrentQueue <Thing>(thingList1); CreateTickThreads(); foreach (EventWaitHandle eventWaitHandle in eventWaitStarts.Values) { eventWaitHandle.Set(); } monitorThreadWaitHandle.Set(); MainThreadWaitLoop(); return(false); }
public void DeregisterFromTickManager(ThingWithComps thing) { if (thing.def.tickerType != TickerType.Never) { return; // already done or complained about } // [Reflection] TickManager.tickListRare.DeregisterThing(thing) FieldInfo tickListRareField = AccessTools.Field(typeof(TickManager), "tickListRare"); TickList tickListRare = (TickList)tickListRareField.GetValue(Find.TickManager); tickListRare.DeregisterThing(thing); }
public static void Postfix(TickManager __instance) { FieldInfo tln = AccessTools.Field(typeof(TickManager), "tickListNormal"); TickList tickListNormal = tln.GetValue(__instance) as TickList; FieldInfo tlr = AccessTools.Field(typeof(TickManager), "tickListRare"); TickList tickListRare = tlr.GetValue(__instance) as TickList; FieldInfo tll = AccessTools.Field(typeof(TickManager), "tickListLong"); TickList tickListLong = tll.GetValue(__instance) as TickList; tln.SetValue(__instance, new TCTickList(tickListNormal)); tlr.SetValue(__instance, new TCTickList(tickListRare)); tll.SetValue(__instance, new TCTickList(tickListLong)); }
private static int get_TickInterval2(TickList __instance) { switch (tickType(__instance)) { case TickerType.Normal: return(1); case TickerType.Rare: return(250); case TickerType.Long: return(2000); default: return(-1); } }
private static void mainUpdateLoop(Object workSet) { WorkSet set = (WorkSet)workSet; List <Thing> list2 = set.list2; FieldInfo tickt = set.tickt; TickList __instance = set.__instance; Parallel.For(0, list2.Count, new ParallelOptions { MaxDegreeOfParallelism = ThreadingMod.NUM_THREADS_PER_MAP }, m => { if (!list2[m].Destroyed) { try { switch (((TickerType)tickt.GetValue(__instance))) { case TickerType.Normal: list2[m].Tick(); break; case TickerType.Rare: list2[m].TickRare(); break; case TickerType.Long: list2[m].TickLong(); break; } } catch (Exception ex) { if (Prefs.DevMode) { Log.Error("Exception ticking " + list2[m].ToString() + ": " + ex.ToString()); } } } }); loopDone = true; loopPauser.Set(); }
public TCTickList(TickList old) : base(GetTickType(old)) { tickType = GetTickType(old); FieldInfo tl = AccessTools.Field(typeof(TickList), "thingLists"); thingLists = tl.GetValue(this) as List <List <Thing> >; FieldInfo ttr = AccessTools.Field(typeof(TickList), "thingsToRegister"); thingsToRegister = ttr.GetValue(this) as List <Thing>; FieldInfo ttd = AccessTools.Field(typeof(TickList), "thingsToDeregister"); thingsToDeregister = ttd.GetValue(this) as List <Thing>; for (int i = 0; i < this.TickInterval; i++) { this.normalThingList.Add(new List <Thing>()); this.adjustedthingList.Add(new List <Thing>()); } }
public void Worker() { long t = 0; while (true) { t++; if (t % 1 == 0) { TickList?.Invoke(t); } if (t % 10 == 0) { ALarmList?.Invoke(t); } Thread.Sleep(1000); } }
public static bool Tick(TickList __instance) { TickDetour(__instance); return(false); }
public void MainThreadFunc(float delta_time) { // called every frame ProtoData proto_data = receiveBuffer.DequeueProtoData(); while (proto_data != null) { //Debug.Log("收到消息包 id : " + proto_data.id); switch (proto_data.id) { case ResponseId.JoinRoomResult: { JoinRoomResult result = proto_data.proto as JoinRoomResult; // 逻辑层更新 BL.BLTimelineController.Instance().OnJoinRoom(result.team_id); // 表现层更新 BattleField.battle_field.OnJoinRoom(result.team_id, result.team_id); } break; case ResponseId.BattleStart: { BattleStart result = proto_data.proto as BattleStart; BL.BLTimelineController.Instance().Start(); BattleFieldInputHandle.Instance().enabled = true; } break; case ResponseId.Tick: { TickList tick_list = proto_data.proto as TickList; //Debug.Log("收到同步帧 " + tick_list.frame); // 先把指令放入队列 for (int i = 0; i < tick_list.list.Count; ++i) { Tick tick = tick_list.list[i]; switch (tick.command_type) { case BL.TickCommandType.Move: { BL.BLIntVector3 dest_position; dest_position.x = tick.x; dest_position.y = 0; dest_position.z = tick.y; BL.BLCommandBase command = BL.BLCommandManager.Instance().CreateMove2PositionCommand(tick.cast_id, tick_list.frame, dest_position); BL.BLCommandManager.Instance().AddCommand(command.cast_frame, command); } break; case BL.TickCommandType.PUT_HERO: { BL.BLCommandBase command = BL.BLCommandManager.Instance().CreatePutHeroCommand(tick.team_id, tick_list.frame, tick.hero_index); BL.BLCommandManager.Instance().AddCommand(command.cast_frame, command); } break; case BL.TickCommandType.PURSUE_TARGET: { } break; } ; } // 时间轴控制进行一帧, 分发指令 BL.BLTimelineController.Instance().frame_received++; } break; default: break; } ; proto_data = receiveBuffer.DequeueProtoData(); } }
public static TickerType GetTickType(TickList tick) { FieldInfo tt = AccessTools.Field(typeof(TickList), "tickType"); return((TickerType)tt.GetValue(tick)); }
public static void TickDetour(TickList __instance) { try { FieldInfo registerThings = typeof(TickList).GetField("thingsToRegister", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo deregisterThings = typeof(TickList).GetField("thingsToDeregister", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo listsThings = typeof(TickList).GetField("thingLists", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo tickt = typeof(TickList).GetField("tickType", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo bucket = typeof(TickList).GetMethod("BucketOf", BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < ((List <Thing>)registerThings.GetValue(__instance)).Count; i++) { ((List <Thing>)bucket.Invoke(__instance, new object[] { ((List <Thing>)registerThings.GetValue(__instance))[i] })) .Add(((List <Thing>)registerThings.GetValue(__instance))[i]); } ((List <Thing>)registerThings.GetValue(__instance)).Clear(); for (int j = 0; j < ((List <Thing>)deregisterThings.GetValue(__instance)).Count; j++) { ((List <Thing>)bucket.Invoke(__instance, new object[] { ((List <Thing>)deregisterThings.GetValue(__instance))[j] })) .Remove(((List <Thing>)deregisterThings.GetValue(__instance))[j]); } ((List <Thing>)deregisterThings.GetValue(__instance)).Clear(); if (DebugSettings.fastEcology) { Find.World.tileTemperatures.ClearCaches(); for (int k = 0; k < ((List <List <Thing> >)listsThings.GetValue(__instance)).Count; k++) { List <Thing> list = ((List <List <Thing> >)listsThings.GetValue(__instance))[k]; for (int l = 0; l < list.Count; l++) { if (list[l].def.category == ThingCategory.Plant) { list[l].TickLong(); } } } } List <Thing> list2 = ((List <List <Thing> >)listsThings.GetValue(__instance))[Find.TickManager.TicksGame % TickInterval(((TickerType)tickt.GetValue(__instance)))]; //ThreadPool.QueueUserWorkItem(new WaitCallback(mainUpdateLoop), new WorkSet(list2, tickt, __instance)); //var t2 = new Thread(() => mainUpdateLoop(new WorkSet(list2, tickt, __instance))); //t2.Start(); Thread t = new Thread(new ParameterizedThreadStart(mainUpdateLoop)); t.Start(new WorkSet(list2, tickt, __instance)); TimeSpan timeout = TimeSpan.FromSeconds(30); DateTime start_time = DateTime.Now; while (!loopDone) { if (mainThreadJobs.Count != 0) { Job job; job = mainThreadJobs.Dequeue(); if (job != null) { job.doJob(); } } else { loopPauser.WaitOne(); loopPauser.Reset(); } //Debug Only Code if ((DateTime.Now - start_time) > timeout) { t.Abort(); throw new Exception("Threads needed to be aborted"); } } loopDone = false; } catch (Exception e) { Log.Error(e.ToString()); } }
public static bool Tick(TickList __instance) { TickerType currentTickType = tickType(__instance); int currentTickInterval = get_TickInterval2(__instance); Thing i; List <Thing> tr = thingsToRegister(__instance); for (int index = 0; index < tr.Count; ++index) { try { i = tr[index]; } catch (ArgumentOutOfRangeException) { break; } List <Thing> b = BucketOf2(__instance, i, currentTickInterval); b.Add(i); } lock (tr) { tr.Clear(); } List <Thing> td = thingsToDeregister(__instance); for (int index = 0; index < td.Count; ++index) { try { i = td[index]; } catch (ArgumentOutOfRangeException) { break; } List <Thing> b = BucketOf2(__instance, i, currentTickInterval); b.Remove(i); } lock (td) { td.Clear(); } if (DebugSettings.fastEcology) { Find.World.tileTemperatures.ClearCaches(); for (int index1 = 0; index1 < thingLists(__instance).Count; ++index1) { List <Thing> thingList = thingLists(__instance)[index1]; for (int index2 = 0; index2 < thingList.Count; ++index2) { if (thingList[index2].def.category == ThingCategory.Plant) { thingList[index2].TickLong(); } } } } switch (currentTickType) { case TickerType.Normal: RimThreaded.thingListNormal = thingLists(__instance)[Find.TickManager.TicksGame % currentTickInterval]; RimThreaded.thingListNormalTicks = RimThreaded.thingListNormal.Count; break; case TickerType.Rare: RimThreaded.thingListRare = thingLists(__instance)[Find.TickManager.TicksGame % currentTickInterval]; RimThreaded.thingListRareTicks = RimThreaded.thingListRare.Count; break; case TickerType.Long: RimThreaded.thingListLong = thingLists(__instance)[Find.TickManager.TicksGame % currentTickInterval]; RimThreaded.thingListLongTicks = RimThreaded.thingListLong.Count; break; } return(false); }
public void HandleReceive() { lock (mutex) { do { if (offset < DataSizeOffset + DataSize) { break; } // 先读取包的size int packet_size = ByteOrderConverter.NetworkToHostOrder(BitConverter.ToInt32(buffer, DataSizeOffset)); int proto_total_len = packet_size + WrapperLen; if (offset < proto_total_len) { break; } // 读取包id int id = ByteOrderConverter.NetworkToHostOrder(BitConverter.ToInt16(buffer, HandlerIdOfffset)); // 处理具体的包协议 object proto_data = null; int proto_data_deserialize_offset = DataOffset; switch (id) { case ResponseId.JoinRoomResult: { proto_data = JoinRoomResult.Deserialize(buffer, ref proto_data_deserialize_offset); } break; case ResponseId.BattleStart: { proto_data = BattleStart.Deserialize(buffer, ref proto_data_deserialize_offset); } break; case ResponseId.Tick: { proto_data = TickList.Deserialize(buffer, ref proto_data_deserialize_offset); } break; default: break; } ; if (proto_data != null) { ProtoData data = new ProtoData(); data.id = id; data.proto = proto_data; proto_data_queue.Enqueue(data); } // 包体读取完毕 Array.Copy(buffer, proto_total_len, buffer, 0, offset - proto_total_len); offset = offset - proto_total_len; }while(true); } }
private void btnSendMessage_Click(object sender, EventArgs e) { tlist = new TickList(); stProgress.Minimum = 0; stProgress.Maximum = users.Count(x => x.Notified == false); stProgress.Style = ProgressBarStyle.Continuous; stProgress.Visible = true; btnTakeUsers.Enabled = false; btnSendMessage.Enabled = false; btnPause.Enabled = true; btnStop.Enabled = true; parseTimer.Start(); OpenPostBox(); }
/// <summary> /// Init process of taking users /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTakeUsers_Click(object sender, EventArgs e) { tlist = new TickList(); stProgress.Style = ProgressBarStyle.Marquee; stProgress.Visible = true; mode = ParseMode.TakePeople; btnTakeUsers.Enabled = false; btnSendMessage.Enabled = false; btnPause.Enabled = true; btnStop.Enabled = true; parseTimer.Start(); TakePeople(); }
static bool Prefix(ref TickList __instance) { for (int index = 0; index < __instance.thingsToRegister.Count; ++index) { __instance.BucketOf(__instance.thingsToRegister[index]).Add(__instance.thingsToRegister[index]); } __instance.thingsToRegister.Clear(); for (int index = 0; index < __instance.thingsToDeregister.Count; ++index) { __instance.BucketOf(__instance.thingsToDeregister[index]).Remove(__instance.thingsToDeregister[index]); } __instance.thingsToDeregister.Clear(); if (DebugSettings.fastEcology) { Find.World.tileTemperatures.ClearCaches(); for (int index1 = 0; index1 < __instance.thingLists.Count; ++index1) { List <Thing> thingList = __instance.thingLists[index1]; for (int index2 = 0; index2 < thingList.Count; ++index2) { if (thingList[index2].def.category == ThingCategory.Plant) { thingList[index2].TickLong(); } } } } int tickValue = Find.TickManager.TicksGame == 0 ? 0 : Find.TickManager.TicksGame / RefcellRespeedConfig.currentTimeMultiplier; List <Thing> thingList1 = __instance.thingLists[tickValue % __instance.TickInterval]; for (int index = 0; index < thingList1.Count; ++index) { if (!thingList1[index].Destroyed) { try { switch (__instance.tickType) { case TickerType.Normal: thingList1[index].Tick(); continue; case TickerType.Rare: thingList1[index].TickRare(); continue; case TickerType.Long: thingList1[index].TickLong(); continue; default: continue; } } catch (Exception ex) { string str = thingList1[index].Spawned ? " (at " + (object)thingList1[index].Position + ")" : ""; if (Prefs.DevMode) { Log.Error("Exception ticking " + thingList1[index].ToStringSafe <Thing>() + str + ": " + (object)ex); } else { Log.ErrorOnce("Exception ticking " + thingList1[index].ToStringSafe <Thing>() + str + ". Suppressing further errors. Exception: " + (object)ex, thingList1[index].thingIDNumber ^ 576876901); } } } } return(false); }
public WorkSet(List <Thing> list2, FieldInfo tickt, TickList instance) { this.list2 = list2; this.tickt = tickt; __instance = instance; }
private static bool Prefix(TickList __instance) { if (!Active && !H_TickSelection.Active && !H_TickDef.Active) { return(true); } for (var i = 0; i < __instance.thingsToRegister.Count; i++) { __instance.BucketOf(__instance.thingsToRegister[i]).Add(__instance.thingsToRegister[i]); } __instance.thingsToRegister.Clear(); for (var j = 0; j < __instance.thingsToDeregister.Count; j++) { __instance.BucketOf(__instance.thingsToDeregister[j]).Remove(__instance.thingsToDeregister[j]); } __instance.thingsToDeregister.Clear(); if (DebugSettings.fastEcology) { Find.World.tileTemperatures.ClearCaches(); for (var k = 0; k < __instance.thingLists.Count; k++) { var list = __instance.thingLists[k]; for (var l = 0; l < list.Count; l++) { if (list[l].def.category == ThingCategory.Plant) { list[l].TickLong(); } } } } var list2 = __instance.thingLists[Find.TickManager.TicksGame % __instance.TickInterval]; for (var m = 0; m < list2.Count; m++) { var sam = list2[m]; if (!sam.Destroyed) { try { var tickerType = __instance.tickType; if (tickerType != TickerType.Normal) { if (tickerType != TickerType.Rare) { if (tickerType == TickerType.Long) { LogMe(sam, sam.TickLong, "TickLong"); } } else { LogMe(sam, sam.TickRare, "TickRare"); } } else { LogMe(sam, sam.Tick, "Tick"); } } catch (Exception ex) { var text = !list2[m].Spawned ? string.Empty : " (at " + list2[m].Position + ")"; if (Prefs.DevMode) { Log.Error(string.Concat("Exception ticking ", list2[m].ToStringSafe(), text, ": ", ex)); } else { Log.ErrorOnce( string.Concat("Exception ticking ", list2[m].ToStringSafe(), text, ". Suppressing further errors. Exception: ", ex), list2[m].thingIDNumber ^ 576876901); } } } } return(false); }