Example #1
0
    public void LoadTrack(string trackName)
    {
        var trackSerializer = new TrackSerializer(track);
        var mapDTO          = trackSerializer.LoadWorld(trackName);

        track.SkidMarks.Init();

        //MAP METADATA
        Mapper.Map(mapDTO, track.Metadata);

        //Init track objects
        InstantiateMapObjects(mapDTO);

        //Init checkpoints
        InstantiateCheckpoints(mapDTO);

        //Init waypoints
        InstantiateWaypoints(mapDTO);
    }
Example #2
0
    public void SaveTrack()
    {
        var WorldSerialization = new TrackSerializer(track);

        WorldSerialization.SaveWorld(track.Metadata.Name);
    }
Example #3
0
        public void Evaluate(int SpreadMax)
        {
            double currentposition = this.GetCurrentPosition();

            bool clear = false;

            for (int i = 0; i < this.FPinInReset.SliceCount; i++)
            {
                double dblreset;//,dblseek;
                this.FPinInReset.GetValue(i, out dblreset);
                //this.FPinInDoSeek.GetValue(i, out dblseek);
                if (dblreset >= 0.5)// || dblseek >= 0.5)
                {
                    clear = true;
                }
            }

            double dblload;

            this.FPinInLoad.GetValue(0, out dblload);

            #region Track Data
            //First we update our tracks data
            if (this.FPinInTrackId.PinIsChanged ||
                this.FPinInPlay.PinIsChanged ||
                this.FPinInRecord.PinIsChanged ||
                this.FPinInBufferLength.PinIsChanged ||
                this.FPinInReset.PinIsChanged ||
                clear ||
                dblload >= 0.5)
            {
                if (dblload >= 0.5)
                {
                    this.FActiveTracks.Clear();
                    this.FTracks.Clear();

                    string path;
                    this.FpinInSavePath.GetString(0, out path);
                    path = path == null ? String.Empty : path;

                    if (Directory.Exists(path))
                    {
                        foreach (string f in Directory.GetFiles(path))
                        {
                            SeqTrack s = TrackSerializer.LoadTrack(f, 1.0);
                            if (s != null)
                            {
                                this.FTracks.Add(s.Id, s);
                            }
                        }
                    }
                }


                this.FActiveTracks.Clear();

                for (int i = 0; i < this.FPinInTrackId.SliceCount; i++)
                {
                    string id;
                    this.FPinInTrackId.GetString(i, out id);


                    //Keep a record of active tracks
                    this.FActiveTracks.Add(id);

                    SeqTrack track;
                    if (!this.FTracks.ContainsKey(id))
                    {
                        //Create new track
                        track    = new SeqTrack();
                        track.Id = id;
                        this.FTracks.Add(id, track);
                    }
                    else
                    {
                        track = this.FTracks[id];
                    }
                    //Update slice index if it has changed;
                    track.TrackIndex = i;


                    //Update Play/Record/Buffer
                    double dblplay, dblrecord, dblbuffer, dblclear, dblkeep;

                    this.FPinInPlay.GetValue(i, out dblplay);
                    this.FPinInRecord.GetValue(i, out dblrecord);
                    this.FPinInBufferLength.GetValue(i, out dblbuffer);
                    this.FPinInReset.GetValue(i, out dblclear);
                    this.FPinInKeepPosition.GetValue(i, out dblkeep);

                    dblbuffer = Math.Max(dblbuffer, 0.1);

                    if (dblclear >= 0.5)
                    {
                        track.Clear();
                    }


                    bool resettime = false;
                    if (dblrecord >= 0.5 && track.Play)
                    {
                        track.StartRecording(currentposition);
                    }
                    else
                    {
                        resettime = track.StopRecording(currentposition, dblkeep > 0.5);
                    }

                    if (dblplay >= 0.5)
                    {
                        track.StartPlay(currentposition, resettime);
                    }



                    track.Play         = dblplay >= 0.5;
                    track.BufferLength = dblbuffer;
                }
            }
            #endregion

            #region Save
            double dblsave;
            this.FPinInSave.GetValue(0, out dblsave);
            if (dblsave >= 0.5)
            {
                string path;
                this.FpinInSavePath.GetString(0, out path);
                path = path == null ? String.Empty : path;

                if (Directory.Exists(path))
                {
                    foreach (SeqTrack track in this.FTracks.Values)
                    {
                        try
                        {
                            TrackSerializer.SaveTrack(path, track);
                        }
                        catch (Exception ex)
                        {
                            this.FHost.Log(TLogType.Error, ex.Message);
                        }
                    }
                }
            }
            #endregion

            #region Output Results
            this.FPinOutput.SliceCount       = this.FActiveTracks.Count;
            this.FPinOutTrackId.SliceCount   = this.FActiveTracks.Count;
            this.FPinOutBufferLen.SliceCount = this.FActiveTracks.Count;
            this.FPinOutPosition.SliceCount  = this.FActiveTracks.Count;

            for (int i = 0; i < this.FActiveTracks.Count; i++)
            {
                SeqTrack track = this.FTracks[this.FActiveTracks[i]];
                this.FPinOutTrackId.SetString(i, this.FActiveTracks[i]);

                double dblinput;
                this.FPinInInput.GetValue(track.TrackIndex, out dblinput);

                double dblinter;
                this.FPinInInterpolate.GetValue(track.TrackIndex, out dblinter);

                double dblloop;
                this.FPinInInterMode.GetValue(track.TrackIndex, out dblloop);

                if (track.Record)
                {
                    double pos = track.RecordValue(currentposition, dblinput);
                    this.FPinOutput.SetValue(i, dblinput);
                    this.FPinOutPosition.SetValue(i, pos);
                }
                else
                {
                    double seekpos, dbldoseek;

                    this.FPinInDoSeek.GetValue(track.TrackIndex, out dbldoseek);
                    this.FPinInSeekPos.GetValue(track.TrackIndex, out seekpos);

                    if (dbldoseek >= 0.5)
                    {
                        track.DoSeek(currentposition - seekpos);
                    }

                    double pos = track.BufferPosition;
                    if (track.Play)
                    {
                        if (!track.IsEmpty)
                        {
                            double val = track.Getvalue(currentposition, dblinter >= 0.5, dblloop >= 0.5, out pos);
                            this.FPinOutput.SetValue(i, val);
                        }
                        else
                        {
                            this.FPinOutput.SetValue(i, dblinput);
                        }
                    }
                    else
                    {
                        //this.FPinOutput.SetValue(i, dblinput);

                        /*
                         * if (track.TrackIndex < this.FPrevious.Count)
                         * {
                         *  if (this.FPrevious[track.TrackIndex] != dblinput)
                         *  {
                         *      this.FPinOutput.SetValue(i, dblinput);
                         *  }
                         * }*/

                        if (FirstFrame)
                        {
                            this.FPinOutput.SetValue(i, dblinput);
                        }
                    }

                    if (track.TrackIndex < this.FPrevious.Count)
                    {
                        if (this.FPrevious[track.TrackIndex] != dblinput)
                        {
                            this.FPinOutput.SetValue(i, dblinput);
                        }
                    }

                    this.FPinOutPosition.SetValue(i, pos);
                }
                this.FPinOutBufferLen.SetValue(i, track.RealBufferLength);
            }

            List <string> unused = new List <string>();
            foreach (string id in this.FTracks.Keys)
            {
                if (!this.FActiveTracks.Contains(id))
                {
                    unused.Add(id);
                }
            }

            this.FPinOutUnusedTracks.SliceCount = unused.Count;
            for (int i = 0; i < unused.Count; i++)
            {
                this.FPinOutUnusedTracks.SetString(i, unused[i]);
            }

            this.FPinOutTicks.SetValue(0, currentposition);
            #endregion

            this.SavePreviousData();

            this.FirstFrame = false;
        }