示例#1
0
        // Happens each time a progress is made
        public static void ProgressCallback()
        {
            PDAScanner.ScanTarget scanTarget = PDAScanner.scanTarget;
            if (scanTarget.techType == TechType.Player)
            {
                return;
            }

            if (scanTarget.isValid && scanTarget.progress > 0f && scanTarget.gameObject.TryGetComponent(out NitroxEntity nitroxEntity))
            {
                // Should always be the same for the same entity
                NitroxId       nitroxId = nitroxEntity.Id;
                DateTimeOffset Now      = DateTimeOffset.UtcNow;

                // Start a thread when a scanning period starts
                if (!ThrottlingEntries.TryGetValue(nitroxId, out ThrottledEntry throttledEntry))
                {
                    ThrottlingEntries.Add(nitroxId, throttledEntry = new ThrottledEntry(scanTarget.techType, nitroxId, new PDAScanner.Entry()
                    {
                        techType = scanTarget.techType, progress = scanTarget.progress
                    }));

                    throttledEntry.StartThrottler();
                }
                PDAScanner.Entry scannerEntry = throttledEntry.GetEntry();

                // Updating the progress throttling
                throttledEntry.Update(Now, null, scanTarget.progress);
                // Throttling the packet sending
                if (Now.ToUnixTimeMilliseconds() < throttledEntry.LatestPacketSendTime.ToUnixTimeMilliseconds() + PACKET_SENDING_RATE)
                {
                    return;
                }

                NitroxTechType nitroxTechType = new NitroxTechType(scanTarget.techType.ToString());
                // This should not occur all the time because it only takes effect one time per entity
                // Then it occurs when someone else already scanned the entity
                // Check if the entry is already in the partial list, and then, change the progress
                if (PDAManagerEntry.CachedEntries.TryGetValue(nitroxTechType, out PDAProgressEntry pdaProgressEntry))
                {
                    if (pdaProgressEntry.Entries.TryGetValue(nitroxId, out float progress))
                    {
                        pdaProgressEntry.Entries.Remove(nitroxId);
                        // We'd like the progress to not decrease when two people scan the same thing at the same time
                        if (scannerEntry.progress < progress)
                        {
                            PDAScanner.scanTarget.progress = progress;
                            scannerEntry.progress          = progress;
                        }
                        if (pdaProgressEntry.Entries.Count == 0)
                        {
                            PDAManagerEntry.CachedEntries.Remove(nitroxTechType);
                        }
                    }
                }

                throttledEntry.Update(Now, Now, scanTarget.progress);
                PDAManagerEntry.Progress(throttledEntry.GetEntry(), nitroxId);
            }
        }
示例#2
0
        // After 2 seconds without scanning, a packet will be sent with the latest progress
        static IEnumerator ThrottleLastProgress(ThrottledEntry throttledEntry)
        {
            do
            {
                yield return(new WaitForSeconds(LAST_PACKET_SEND_DELAY / 1000));
            }while (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() < throttledEntry.LatestProgressTime.ToUnixTimeMilliseconds() + LAST_PACKET_SEND_DELAY);

            throttledEntry.GetEntry();
            if (!throttledEntry.Unlocked && !PDAScanner.ContainsCompleteEntry(throttledEntry.EntryTechType))
            {
                PDAManagerEntry.Progress(throttledEntry.Entry, throttledEntry.Id);
            }

            // No need to keep this in memory
            ThrottlingEntries.Remove(throttledEntry.Id);
        }