Beispiel #1
0
 public string[] DoSplit(string file, string path, long size)
 {
     SplitEventArgs arg = new SplitEventArgs();
     //以文件的全路对应的字符串和文件打开模式来初始化FileStream文件流实例
     string[] files;
     using (FileStream splitFileStream = new FileStream(file, FileMode.Open))
     {
         long length = 0;
         using (BinaryReader splitFileReader = new BinaryReader(splitFileStream))
         {
             //获得分割后文件的个数
             int fileCount = (int)(splitFileStream.Length / size);
             if (splitFileStream.Length % size != 0) fileCount++;
             files = new string[fileCount];
             //循环将大文件分割成多个小文件
             for (int i = 1; i <= fileCount; i++)
             {
                 //小文件名
                 string filename = Path.GetFileName(file);
                 //确定小文件的文件名称
                 string tempFileName = Path.Combine(path, String.Concat(filename, ".fsp", i));
                 files[i - 1] = tempFileName;
                 //根据文件名称和文件打开模式来初始化FileStream文件流实例
                 FileStream tempStream = new FileStream(tempFileName, FileMode.OpenOrCreate);
                 //以FileStream实例来创建、初始化BinaryWriter书写器实例
                 BinaryWriter tempWriter = new BinaryWriter(tempStream);
                 //如果读取的数据大于限定的最大缓冲值 强制设置缓冲大小
                 int readLength = (int) (size > _maxReadSize ? _maxReadSize : size);
                 //如果尺寸大于限定 分段写入
                 int readCount = (int) (size > _maxReadSize ? size / _maxReadSize : 1);
                 //获得分段数
                 readCount = size > _maxReadSize && size % _maxReadSize != 0 ? readCount + 1 : readCount;
                 //写入分段
                 for (int j = 0; j < readCount;j++)
                 {
                     readLength = (int) (size - tempStream.Length > _maxReadSize ? readLength :size - tempStream.Length);
                     //从大文件中读取指定大小数据
                     byte[] tempBytes = splitFileReader.ReadBytes(readLength);
                     //把此数据写入小文件
                     tempWriter.Write(tempBytes);
                     //关闭书写器,形成小文件
                     arg.FileName = tempFileName;
                     arg.Length = tempStream.Length;
                     arg.Percent = (int) (((double) (tempStream.Length + length)/splitFileStream.Length)*100);
                     OnSplitStateChange(arg);
                 }
                 length += tempStream.Length;
                 tempWriter.Close();
                 //关闭文件流
                 tempStream.Close();
             }
             splitFileReader.Close();
         }
         //关闭大文件阅读器
         splitFileStream.Close();
     }
     return files;
 }
Beispiel #2
0
        public void OnSplitStateChange(SplitEventArgs e)
        {
            EventHandler <SplitEventArgs> handler = SplitStateChange;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #3
0
        private void _gameMemory_OnSplit(object sender, SplitEventArgs e)
        {
            if (_state.CurrentPhase != TimerPhase.Running)
            {
                e.AutoSplit.Triggered = false;
                return;
            }

            Trace.WriteLine($"[NoLoads] {e.AutoSplit.Name} Split");
            _timer.Split();
        }
        private void OnSplitGoalCompletedEvent(SplitEventArgs e)
        {
            EventHandler <SplitEventArgs> handler = SplitGoalCompletedEvent;

            if (handler != null)
            {
                try
                {
                    handler(this, e);
                }
                catch (Exception ex)
                {
                    // Don't let downstream exceptions bubble up
                    Logger.LogWarning(ex, ex.ToString());
                }
            }
        }
        public void SplitEventHandler(string name, string value)
        {
            if ((currentSplit.name == name && currentSplit.value == value) ||
                (this.autoReset && !this.timerRunning &&
                 sSplits.Length > 0 &&
                 sSplits[0].name == name && sSplits[0].value == value))
            {
                LogWriter.WriteLine("Trigger Function Called.");
                if (OnSplit != null && currentSplit.doSplit)
                {
                    SplitEventArgs e = new SplitEventArgs();
                    e.name  = name;
                    e.value = value;

                    OnSplit(this, e);
                }
                GoToNextSplit();
            }
        }
Beispiel #6
0
        static public void OnSplitTriggered(object sender, SplitEventArgs e)
        {
            // If we have received a Start event trigger, then we want to start our timer Model causing
            // LiveSplit to begin counting. We then want to immediatly pause the in-game time tracking
            // as we will be setting this absolutely based on reading the actual in-game time from
            // the process memory. Pausing the in-game timer stops LiveSplit from getting in our way.
            if (e.name == "Start")
            {
                Console.WriteLine("Start");
            }

            // Escape Goat 2 only has one other condition for splitting, the end of a room. This event is
            // called when: a door is entered, a soul shard is collected, or a glass fragment is obtained.
            // Due to the differences in IGT and RTA timings for Escape Goat 2, we do not want to split
            // if we are on the final split, we want to instead pause the timer. A more detailed explanation
            // for this is in the comments for `goatState_OnIGTFixed()`.
            else
            {
                Room room = (Room)e.value;
                Console.WriteLine("Split {0}", room);
            }
        }
Beispiel #7
0
 public void OnSplitChange(object obj, SplitEventArgs splits)
 {
     Splits = splits.SplitList;
 }
        /// <summary>
        /// Handle player state changes.
        /// Event distance is given in meters.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RiderStateEventHandler(object sender, RiderStateEventArgs e)
        {
            if (!m_started || !m_splits.ShowSplits)
            {
                return;
            }

            SplitV2 split = null;

            if (m_splits.CalculateGoal)
            {
                if (m_splitCount >= m_splits.Splits.Count)
                {
                    return;
                }

                // get the in-progress split
                split = m_splits.Splits[m_splitCount];
            }

            DateTime now = DateTime.Now;

            TimeSpan runningTime = (now - m_startTime);
            TimeSpan splitTime   = (now - m_splitStartTime);

            if (m_eventCount++ == 0)
            {
                // Capture the current distance traveled value to use as an offset to each successive distance value.
                m_distanceSeedValue = e.Distance;
            }

            // Calculate total distance travelled
            int totalMeters = e.Distance - m_distanceSeedValue;

            double kmsTravelled   = totalMeters / 1000.0;
            double milesTravelled = kmsTravelled / 1.609;

            double totalDistance = Math.Round(m_splits.SplitsInKm ? kmsTravelled : milesTravelled, 1);

            // Calculate how deep into the current split the rider is.
            int splitMetersTravelled = totalMeters - m_lastSplitMeters;

            // How long is current split?
            int splitLengthMeters = split == null ? m_splits.SplitDistanceAsMeters : split.SplitDistanceAsMeters;

            // How much of the split is completed (expressed as percentage)
            double splitCompletedPct = splitMetersTravelled / (double)splitLengthMeters;

            // Compute distance, leave unrounded
            double splitKmTravelled = splitMetersTravelled / 1000.0;
            double splitMiTravelled = splitKmTravelled / 1.609;

            double splitDistance = m_splits.SplitsInKm ? splitKmTravelled : splitMiTravelled;
            double splitSpeed    = Math.Round((splitDistance / splitTime.TotalSeconds) * 3600, 1);

            // Now round the distance
            splitDistance = Math.Round(splitDistance, 1);

            if (split != null)
            {
                if (splitMetersTravelled >= splitLengthMeters)
                {
                    // Calculate the deltaTime, positive number is bad, negative good.
                    TimeSpan deltaTime = new TimeSpan(0, 0, (int)Math.Round(runningTime.Subtract(split.TotalTime).TotalSeconds, 0));

                    // This completes the split.  TotalDistance travelled and Delta is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, totalDistance, runningTime, m_splits.SplitsInKm, deltaTime);
                    OnSplitGoalCompletedEvent(args);

                    // Reset time and begin next split
                    m_splitStartTime = now;
                    m_splitCount++;

                    m_lastSplitMeters = split.TotalDistanceAsMeters;
                }
                else
                {
                    // Goal time of split start
                    TimeSpan splitStartTime = split.TotalTime.Subtract(split.SplitTime);

                    // Goal time to get to this point in the split
                    TimeSpan splitWaypointTime = splitStartTime.Add(split.SplitTime.Multiply(splitCompletedPct));

                    // Calculate the deltaTime, positive number is bad, negative good.
                    TimeSpan deltaTime = new TimeSpan(0, 0, (int)Math.Round(runningTime.Subtract(splitWaypointTime).TotalSeconds, 0));

                    // This is an update to the split in-progress.  SplitDistance travelled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm, deltaTime);
                    OnSplitUpdatedEvent(args);

                    Logger.LogInformation($"%Complete: {splitCompletedPct} Start: {splitStartTime.ToString("m'm 's's'")} Waypoint: {splitWaypointTime.ToString("m'm 's's'")} Delta: {deltaTime.ToString("m'm 's's'")}");
                }
            }
            else
            {
                if (splitMetersTravelled >= splitLengthMeters)
                {
                    // This completes the split.  TotalDistance traveled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, totalDistance, runningTime, m_splits.SplitsInKm);
                    OnSplitCompletedEvent(args);

                    // Reset time and begin next split
                    m_splitStartTime = now;
                    m_splitCount++;

                    m_lastSplitMeters = totalMeters;
                }
                else
                {
                    // This is an update to the split in-progress.  SplitDistance traveled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm);
                    OnSplitUpdatedEvent(args);
                }
            }
        }
Beispiel #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="splits"></param>
 public void OnSplitChange(object obj, SplitEventArgs splits)
 {
     SplitList = new ObservableCollection <Split>(splits.SplitList);
 }
        public void SplitEventHandler(string name, string value) {
            if ((currentSplit.name == name && currentSplit.value == value) ||
                    (this.autoReset && !this.timerRunning &&
                    sSplits.Length > 0 &&
                    sSplits[0].name == name && sSplits[0].value == value)) {
                LogWriter.WriteLine("Trigger Function Called.");
                if (OnSplit != null && currentSplit.doSplit) {
                    SplitEventArgs e = new SplitEventArgs();
                    e.name = name;
                    e.value = value;

                    OnSplit(this, e);
                }
                GoToNextSplit();
            }
        }
Beispiel #11
0
 public void OnSplitStateChange(SplitEventArgs e)
 {
     EventHandler<SplitEventArgs> handler = SplitStateChange;
     if (handler != null) handler(this, e);
 }
Beispiel #12
0
        public string[] DoSplit(string file, string path, long size)
        {
            SplitEventArgs arg = new SplitEventArgs();

            //以文件的全路对应的字符串和文件打开模式来初始化FileStream文件流实例
            string[] files;
            using (FileStream splitFileStream = new FileStream(file, FileMode.Open))
            {
                long length = 0;
                using (BinaryReader splitFileReader = new BinaryReader(splitFileStream))
                {
                    //获得分割后文件的个数
                    int fileCount = (int)(splitFileStream.Length / size);
                    if (splitFileStream.Length % size != 0)
                    {
                        fileCount++;
                    }
                    files = new string[fileCount];
                    //循环将大文件分割成多个小文件
                    for (int i = 1; i <= fileCount; i++)
                    {
                        //小文件名
                        string filename = Path.GetFileName(file);
                        //确定小文件的文件名称
                        string tempFileName = Path.Combine(path, String.Concat(filename, ".fsp", i));
                        files[i - 1] = tempFileName;
                        //根据文件名称和文件打开模式来初始化FileStream文件流实例
                        FileStream tempStream = new FileStream(tempFileName, FileMode.OpenOrCreate);
                        //以FileStream实例来创建、初始化BinaryWriter书写器实例
                        BinaryWriter tempWriter = new BinaryWriter(tempStream);
                        //如果读取的数据大于限定的最大缓冲值 强制设置缓冲大小
                        int readLength = (int)(size > _maxReadSize ? _maxReadSize : size);
                        //如果尺寸大于限定 分段写入
                        int readCount = (int)(size > _maxReadSize ? size / _maxReadSize : 1);
                        //获得分段数
                        readCount = size > _maxReadSize && size % _maxReadSize != 0 ? readCount + 1 : readCount;
                        //写入分段
                        for (int j = 0; j < readCount; j++)
                        {
                            readLength = (int)(size - tempStream.Length > _maxReadSize ? readLength :size - tempStream.Length);
                            //从大文件中读取指定大小数据
                            byte[] tempBytes = splitFileReader.ReadBytes(readLength);
                            //把此数据写入小文件
                            tempWriter.Write(tempBytes);
                            //关闭书写器,形成小文件
                            arg.FileName = tempFileName;
                            arg.Length   = tempStream.Length;
                            arg.Percent  = (int)(((double)(tempStream.Length + length) / splitFileStream.Length) * 100);
                            OnSplitStateChange(arg);
                        }
                        length += tempStream.Length;
                        tempWriter.Close();
                        //关闭文件流
                        tempStream.Close();
                    }
                    splitFileReader.Close();
                }
                //关闭大文件阅读器
                splitFileStream.Close();
            }
            return(files);
        }
        /// <summary>
        /// Handle player state changes.
        /// Event distance is given in meters.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RiderStateEventHandler(object sender, RiderStateEventArgs e)
        {
            if (!m_started || !m_splits.ShowSplits)
            {
                return;
            }

            SplitGoal goal = null;

            if (m_splitGoals != null)
            {
                if (m_splitCount >= m_splitGoals.Goals.Count)
                {
                    return;
                }

                // get the in-progress goal
                goal = m_splitGoals.Goals[m_splitCount];
            }

            DateTime now = DateTime.Now;

            TimeSpan runningTime = (now - m_startTime);
            TimeSpan splitTime   = (now - m_splitStartTime);

            if (m_eventCount++ == 0)
            {
                // Capture the current distance traveled value to use as an offset to each successive distance value.
                m_distanceSeedValue = e.Distance;
            }

            // Calculate total distance travelled
            int totalMeters = e.Distance - m_distanceSeedValue;


            double kmsTravelled   = totalMeters / 1000.0;
            double milesTravelled = kmsTravelled / 1.609;

            double totalDistance = Math.Round(m_splits.SplitsInKm ? kmsTravelled : milesTravelled, 1);

            //double averageKph = Math.Round((kmsTravelled / runningTime.TotalSeconds) * 3600, 1);
            //double averageMph = Math.Round((milesTravelled / runningTime.TotalSeconds) * 3600, 1);

            // Calculate how deep into the split distance the rider is.
            int splitMeters = totalMeters - (m_splits.SplitDistanceAsMeters * m_splitCount);

            double splitKmTravelled = Math.Round(splitMeters / 1000.0, 1);
            double splitMiTravelled = Math.Round(splitKmTravelled / 1.609, 1);

            double splitDistance = m_splits.SplitsInKm ? splitKmTravelled : splitMiTravelled;
            double splitSpeed    = Math.Round((splitDistance / splitTime.TotalSeconds) * 3600, 1);

            //double splitAverageKph = Math.Round((splitKmTravelled / splitTime.TotalSeconds) * 3600, 1);
            //double splitAverageMph = Math.Round((splitMiTravelled / splitTime.TotalSeconds) * 3600, 1);

            if (goal != null)
            {
                if (splitKmTravelled >= goal.SplitDistanceKm)
                {
                    // Calculate the deltaTime, positive number is good, negative bad.
                    TimeSpan deltaTime = goal.TotalTime.Subtract(runningTime);

                    // This completes the split.  TotalDistance travelled and Delta is included.
                    SplitGoalCompletedEventArgs args = new SplitGoalCompletedEventArgs(m_splitCount + 1, splitTime, splitSpeed, totalDistance, runningTime, m_splits.SplitsInKm, deltaTime);
                    OnSplitGoalCompletedEvent(args);

                    // Reset time and begin next split
                    m_splitStartTime = now;
                    m_splitCount++;

                    m_lastSplitMeters = 0;
                }
                else
                {
                    if (splitMeters - m_lastSplitMeters >= 100) // only raise update event every 100 meters or so
                    {
                        // This is an update to the split in-progress.  SplitDistance travelled is included.
                        SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm);
                        OnSplitUpdatedEvent(args);

                        m_lastSplitMeters = splitMeters;
                    }
                }
            }
            else
            {
                if (splitKmTravelled >= m_splits.SplitDistanceAsKm)
                {
                    // This completes the split.  TotalDistance traveled is included.
                    SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, totalDistance, runningTime, m_splits.SplitsInKm);
                    OnSplitCompletedEvent(args);

                    // Reset time and begin next split
                    m_splitStartTime = now;
                    m_splitCount++;

                    m_lastSplitMeters = 0;
                }
                else
                {
                    if (splitMeters - m_lastSplitMeters >= 100) // only raise update event every 100 meters or so
                    {
                        // This is an update to the split in-progress.  SplitDistance traveled is included.
                        SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm);
                        OnSplitUpdatedEvent(args);

                        m_lastSplitMeters = splitMeters;
                    }
                }
            }
        }
Beispiel #14
0
        static LocalVehicle()
        {
            Screen = new Screen();
            HUD    = new HUD();

            Events.Car.PreExplode.SubscribeAll((sender, data) =>
            {
                BeforeExploded?.Invoke(null, System.EventArgs.Empty);
            });

            Events.Car.PreSplit.SubscribeAll((sender, data) =>
            {
                BeforeSplit?.Invoke(null, System.EventArgs.Empty);
            });

            Events.Car.CheckpointHit.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new CheckpointHitEventArgs(data.checkpointIndex_, data.trackT_);
                    CheckpointPassed?.Invoke(null, eventArgs);
                }
            });

            Events.Car.Death.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new DestroyedEventArgs((DestructionCause)data.causeOfDeath);
                    Destroyed?.Invoke(null, eventArgs);
                }
            });

            Events.Car.Explode.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new DestroyedEventArgs((DestructionCause)data.causeOfDeath);
                    Exploded?.Invoke(null, eventArgs);
                }
            });

            Events.RaceEnd.LocalCarHitFinish.Subscribe(data =>
            {
                BeforeFinished?.Invoke(null, System.EventArgs.Empty);
            });

            Events.Player.Finished.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>() != null)
                {
                    var eventArgs = new FinishedEventArgs((RaceEndType)data.finishType_, data.finishData_);
                    Finished?.Invoke(null, eventArgs);
                }
            });

            Events.Car.Horn.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new HonkEventArgs(data.hornPercent_, new Position(data.position_.x, data.position_.y, data.position_.z));
                    Honked?.Invoke(null, eventArgs);
                }
            });

            Events.Car.Impact.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new ImpactEventArgs(data.speed_, new Position(data.pos_.x, data.pos_.y, data.pos_.z), data.impactedCollider_.name);
                    Collided?.Invoke(null, eventArgs);
                }
            });

            Events.Car.Jump.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    Jumped?.Invoke(null, System.EventArgs.Empty);
                }
            });

            Events.Car.ModeSpecial.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    SpecialModeEvent?.Invoke(null, System.EventArgs.Empty);
                }
            });

            Events.Player.CarRespawn.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>() != null)
                {
                    var pos       = new Position(data.position_.x, data.position_.y, data.position_.z);
                    var rot       = new Rotation(data.rotation_.x, data.rotation_.y, data.rotation_.z);
                    var eventArgs = new RespawnEventArgs(pos, rot, data.fastRespawn_);

                    Respawned?.Invoke(null, eventArgs);
                }
            });

            Events.Car.Split.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new SplitEventArgs(data.penetration, data.separationSpeed);
                    Split?.Invoke(null, eventArgs);
                }
            });

            Events.Car.TrickComplete.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    var eventArgs = new TrickCompleteEventArgs(data.cooldownAmount_, data.points_, data.wallRideMeters_, data.ceilingRideMeters_, data.grindMeters_);
                    TrickCompleted?.Invoke(null, eventArgs);
                }
            });

            Events.Car.WingsStateChange.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    if (data.open_)
                    {
                        WingsOpened?.Invoke(null, System.EventArgs.Empty);
                    }
                    else
                    {
                        WingsClosed?.Invoke(null, System.EventArgs.Empty);
                    }
                }
            });

            Events.Car.WingsAbilityStateChanged.SubscribeAll((sender, data) =>
            {
                if (sender.GetComponent <PlayerDataLocal>())
                {
                    if (data.enabled_)
                    {
                        WingsEnabled?.Invoke(null, System.EventArgs.Empty);
                    }
                    else
                    {
                        WingsDisabled?.Invoke(null, System.EventArgs.Empty);
                    }
                }
            });
        }