示例#1
0
        public static void Apply(int tickNum)
        {
            //RimLog.Message("Applied frame " + tickNum);
#if FILE_TRANSFER
            foreach (string s in tickFileNames(tickNum))
            {
                if (System.IO.File.Exists(s))
                {
                    //Rand.pushstate(0);
                    BinaryFormatter ser = new BinaryFormatter();
                    var             fs  = System.IO.File.OpenRead(s);
                    SyncTickData    sd  = ser.Deserialize(fs) as SyncTickData;

                    /*
                     * foreach (Designation des in sd.designations)
                     * {
                     *  AvoidLoop = true;
                     *  Find.CurrentMap.designationManager.AddDesignation(des);
                     *  AvoidLoop = false;
                     * }*/
                    //Rand.PopState();
                }
            }
#else
#endif
        }
示例#2
0
        public static bool FlushSyncTickData(int tickNum)
        {
            /*if (new System.Collections.ICollection[]
             * {
             *  singleton.jobsToSerialize,
             *  singleton.jobPriorities,
             *  singleton.designations,
             *  singleton.designatorCellCalls,
             *  singleton.designatorMultiCellCalls,
             *  singleton.ForbiddenCallDataCall
             * }.Any(u => { return u.Count > 0; }))*/
            {
                try
                {
#if FILE_TRANSFER
                    string s = @"D:\CoopReplays\_" + tickNum + "client_" + cliendID + ".xml";

                    //RimLog.Message("Written : " + s);
                    BinaryFormatter ser      = new BinaryFormatter();
                    var             fs       = System.IO.File.OpenWrite(s);
                    SyncTickData    buffered = singleton;
                    singleton = new SyncTickData();
                    ser.Serialize(fs, buffered);
                    fs.Flush();
                    fs.Close();
                    System.IO.File.WriteAllText(s + ".sync", "");
#else
                    if (cliendID > -1)
                    {
                        singleton.randomToVerify = new int[] { Verse.Rand.Int };
                        var colonists = Find.ColonistBar.GetColonistsInOrder();
                        singleton.colonistJobsToVerify     = colonists == null ? new List <string> {
                        } : colonists.ConvertAll <string>(u => u.CurJobDef == null ? u.ThingID + "::" + "<null>" : u.ThingID + "::" + u.CurJobDef.defName);
                        singleton.serializationServiceData = SerializationService.Flush();
                        BinaryFormatter ser = new BinaryFormatter()
                        {
                            TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.TypesWhenNeeded
                        };
                        SyncTickData buffered = singleton;
                        MemoryStream fs       = new MemoryStream();
                        singleton = new SyncTickData();
                        //RimLog.Message("sending data for tick " + tickNum);
                        NetDemo.PushStateToDirectory(cliendID, tickNum, buffered, 0);
                        fs.Close();
                        return(true);
                    }
                    return(false);
#endif
                }
                catch (Exception ee)
                {
                    RimLog.Error(ee.ToString());
                    return(false);
                }
            }
        }
示例#3
0
        public static bool Prefix(ref int ___ticksGameInt, ref TickManager __instance)
        {
            Rand.PushState(___ticksGameInt);
            getValuePatch.SendDiagDataToServer();
            getValuePatch.diagData.Clear();
            CooperateRimming.dumpRand = true;

            if (sw == null)
            {
                sw    = new Stopwatch();
                ACKSW = new Stopwatch();
                sw.Start();
                ACKSW.Start();

                /*fix for newly loaded game*/
                TickManagerPatch.nextCommunicationTick = Verse.Find.TickManager.TicksGame;
                TickManagerPatch.nextProcessionTick    = Verse.Find.TickManager.TicksGame;

                if (!imInSync)
                {
                    if (nextCommunicationTick == Verse.Find.TickManager.TicksGame)
                    {
                        imInSync = SyncTickData.FlushSyncTickData(nextProcessionTick + syncRoundLength * syncTickRoundOffset);
                    }
                }

                if (cachedData == null)
                {
                    return(false);
                }
                //for (; cachedData == null;)
                {
                }
            }
            shouldReallyTick = false;

            if (NetDemo.HasAllDataForFrame(Verse.Find.TickManager.TicksGame))
            {
                NetDemo.Receive();
            }

            if (sw.ElapsedMilliseconds > (1000 / ticksPerSecond) && !__instance.Paused)
            {
                sw.Reset();
                sw.Start();
                bool canNormallyTick = nextProcessionTick > Verse.Find.TickManager.TicksGame;

                //RimLog.Message("Tick " + ___ticksGameInt + " canNormallyTick " + canNormallyTick + "| comm " + nextCommunicationTick + " | " + nextProcessionTick);

                if (canNormallyTick)
                {
                    //Utilities.RimLog.Message("normal tick at " + Verse.Find.TickManager.TicksGame + " nsync " + nextSyncTickValue);
                    ulong i = 0;
                    foreach (var act in RandContextCounter.replacement_seed)
                    {
                        act((ulong)___ticksGameInt + (i++));
                    }
                    __instance.DoSingleTick();
                }

                if (SyncTickData.cliendID > -1 && ACKSW.ElapsedMilliseconds > 50)
                {
                    ACKSW.Reset();
                    ACKSW.Start();
                    //RimLog.Message("Sending state request for " + nextSyncTickValue);
                    //NetDemo.SendStateRequest(nextSyncTickValue, SyncTickData.cliendID);
                }


                if (!imInSync)
                {
                    if (nextCommunicationTick == Verse.Find.TickManager.TicksGame)
                    {
                        imInSync = SyncTickData.FlushSyncTickData(nextProcessionTick + syncRoundLength * syncTickRoundOffset);
                    }
                }

                {
                    if (nextProcessionTick == Verse.Find.TickManager.TicksGame)
                    {
#if FILE_TRANSFER
                        bool allSyncDataAvailable = SyncTickData.tickFileNames(___ticksGameInt).All(u => System.IO.File.Exists(u + ".sync"));
#else
#endif

                        //RimLog.Message("Frame " + ___ticksGameInt + " : " + " ::: " + allSyncDataAvailable + "[" + ___ticksGameInt + "] :: " + nextSyncTickValue + " [is synced : ] " + imInSync);

                        Action onA = LocalDB.OnApply;

                        if (cachedData != null)
                        {
                            IsSyncTick = true;

                            //RimLog.Message("Synctick happened at " + ___ticksGameInt);

                            SyncTickData.IsDeserializing = true;
                            //JobTrackerPatch.FlushCData();
                            shouldReallyTick = true;
                            streamholder.WriteLine("pre-deserialize tick at " + Verse.Find.TickManager.TicksGame, "tickstate");
                            streamholder.WriteLine("data applied at " + Verse.Find.TickManager.TicksGame, "tickstate");

                            //lock (LocalDB.OnApply)
                            {
                                Rand.PushState(___ticksGameInt);
                                try
                                {
                                    //RimLog.Message("applying at tick " + Verse.Find.TickManager.TicksGame);

                                    var cd = cachedData;
                                    cachedData = null;

                                    ulong i = 0;
                                    foreach (var act in RandContextCounter.replacement_seed)
                                    {
                                        act((ulong)___ticksGameInt + (i++));
                                    }

                                    foreach (var a in cd)
                                    {
                                        a.AcceptResult();
                                    }

                                    TickManagerPatch.SetSyncTickValue(nextProcessionTick + syncRoundLength);
                                    nextCommunicationTick += syncRoundLength;
                                    //Interlocked.Exchange(ref LocalDB.OnApply, null);
                                    //LocalDB.clientLocalStorage.ForEach(u => u.Value.AcceptResult());

                                    //nextSyncTickValue = Verse.Find.TickManager.TicksGame + syncRoundLength;
                                }
                                catch (Exception ee)
                                {
                                    RimLog.Message(ee.ToString());
                                }
                                Rand.PopState();

                                LocalDB.clientLocalStorage.Clear();
                            }
                            //SyncTickData.Apply(___ticksGameInt);
                            //__instance.DoSingleTick();

                            imInSync = false;
                        }
                    }
                }
            }

            //ReferenceTranspilerMethod(ref ___ticksGameInt);
            Rand.PopState();
            return(false);
        }