示例#1
0
        public static void ConsumerFinished(string sequenceFile, Guid id)
        {
            SequenceEntry entry = null;

            if (ActiveSequences.TryGetValue(sequenceFile, out entry))
            {
                lock (entry)
                {
                    entry.RemoveConsumer(id);
                    if (!entry.HasConsumers())
                    {
                        SequenceEntry junk = null;
                        ActiveSequences.TryRemove(sequenceFile, out junk);
                        DisposeSequence(entry.Sequence);
                    }
                }
            }
            else if (RetiredSequences.TryGetValue(sequenceFile, out entry))
            {
                lock (entry)
                {
                    entry.RemoveConsumer(id);
                    if (!entry.HasConsumers())
                    {
                        SequenceEntry junk = null;
                        RetiredSequences.TryRemove(sequenceFile, out junk);
                        DisposeSequence(entry.Sequence);
                    }
                }
            }
        }
示例#2
0
        private static async Task <SequenceEntry> LoadSequenceAsync(string sequenceFile)
        {
            var entry = new SequenceEntry()
            {
                SequenceLoading = true
            };

            if (ActiveSequences.TryAdd(sequenceFile, entry))
            {
                try
                {
                    var sequence = await Task.Run(() => SequenceService.Instance.Load(sequenceFile));

                    entry.Sequence        = sequence;
                    entry.SequenceLoading = false;
                    return(entry);
                }
                catch (Exception e)
                {
                    Logging.Error("Error loading sequence!", e);
                }
            }

            return(null);
        }
示例#3
0
    /// <summary>
    /// Stops the recording.
    /// </summary>
    /// <returns><c>true</c>, if recording was stoped, <c>false</c> otherwise.</returns>
    public bool StopRecording()
    {
        // We weren't recording to begin with
        if (recording == false)
        {
            return(false);
        }

        // Inject a NULL entry so that we can ensure that the sequence time is maintained
        SequenceEntry e = new SequenceEntry(0);

        e.timestamp = Time.time - startTime;
        recordingSequence.entries.Add(e);

        // Go through the list of sequences to see if it exists, and replace
        // look for loaded sequence already in array
        for (int i = 0; i < sequences.Count; i++)
        {
            Sequence s = (Sequence)sequences[i];
            if (s.name == recordingSequence.name)
            {
                sequences.RemoveAt(i);
            }
        }

        // Add to the list
        sequences.Add(recordingSequence.Clone());

        recording = false;

        return(true);
    }
示例#4
0
        // Clone
        public SequenceEntry Clone()
        {
            SequenceEntry r = new SequenceEntry(0);

            r.timestamp = timestamp;
            r.action    = action;
            r.data1     = data1;
            r.data2     = data2;
            r.data3     = data3;

            return(r);
        }
示例#5
0
        // Clone
        public Sequence Clone()
        {
            Sequence r = new Sequence(0);

            r.name       = name;
            r.info       = info;
            r.numEntries = numEntries;

            for (int i = 0; i < entries.Count; i++)
            {
                SequenceEntry e = (SequenceEntry)entries[i];
                r.entries.Add(e.Clone());
            }
            return(r);
        }
示例#6
0
    /// <summary>
    /// Updates the playback.
    /// </summary>
    /// <returns><c>true</c>, if playback was updated, <c>false</c> otherwise.</returns>
    /// <param name="entries">Entries.</param>
    public bool UpdatePlayback(ref ArrayList entries)
    {
        // We are not playing any more
        if (IsPlaying() != true)
        {
            return(false);
        }

        Sequence seq = (Sequence)sequences[currentSequence];

        // Make sure to stop playing current sequence when we have hit the end
        if (currentSequenceEntry >= seq.entries.Count)
        {
            currentSequence      = ovrLipSyncContextSequencerValues.CurrentSequenceNotSet;
            currentSequenceEntry = 0;
            return(false);
        }

        float currentTime = Time.time - startTime;

        SequenceEntry e         = (SequenceEntry)seq.entries[currentSequenceEntry];
        float         entryTime = e.timestamp;

        while (currentTime > entryTime)
        {
            // Do not add a null action, this is to inject 'NOP' values into the
            // stream
            if (e.action != ovrLipSyncContextSequencerValues.NullEntry)
            {
                entries.Add(e.Clone());
            }

            currentSequenceEntry++;

            if (currentSequenceEntry >= seq.entries.Count)
            {
                currentSequence = -1;
                return(false);
            }

            // Keep filling entries with valid entries
            e         = (SequenceEntry)seq.entries[currentSequenceEntry];
            entryTime = e.timestamp;
        }

        return(true);
    }
示例#7
0
    /// <summary>
    /// Adds the entry to recording.
    /// </summary>
    /// <returns><c>true</c>, if entry to recording was added, <c>false</c> otherwise.</returns>
    /// <param name="entry">Entry.</param>
    public bool AddEntryToRecording(ref SequenceEntry entry)
    {
        if (recording == false)
        {
            return(false);
        }

        SequenceEntry newEntry = entry.Clone();

        // set the timestamp
        newEntry.timestamp = Time.time - startTime;

        recordingSequence.entries.Add(newEntry);
        recordingSequence.numEntries++;

        return(true);
    }
示例#8
0
        public static async Task <SequenceEntry> GetSequenceAsync(string sequenceFile)
        {
            //Returning the entry with a placeholder to the sequence facilitates parallel loading
            SequenceEntry entry = null;

            if (ActiveSequences.TryGetValue(sequenceFile, out entry))
            {
                lock (entry)
                {
                    entry.AddConsumer();
                    return(entry);
                }
            }

            entry = await LoadSequenceAsync(sequenceFile);

            if (entry != null)
            {
                entry.AddConsumer();
            }
            return(entry);
        }
示例#9
0
		private static async Task<SequenceEntry> LoadSequenceAsync(string sequenceFile)
		{
			var entry = new SequenceEntry()
			{
				SequenceLoading = true
			};
			
			if (ActiveSequences.TryAdd(sequenceFile, entry))
			{
				try
				{
					var sequence = await Task.Run(() => SequenceService.Instance.Load(sequenceFile));
					entry.Sequence = sequence;
					entry.SequenceLoading = false;
					return entry;
				}
				catch (Exception e)
				{
					Logging.Error("Error loading sequence!", e);
				}
			}
			
			return null;
		}
示例#10
0
    /// <summary>
    /// Saves the sequence.
    /// </summary>
    /// <param name="SequenceName">Sequence name.</param>
    public bool SaveSequence(string sequenceName)
    {
        int sIndex = ovrLipSyncContextSequencerValues.NullEntry;

        // A sequence will need to be in the sequence list to save out
        // look for loaded sequence already in array
        for (int i = 0; i < sequences.Count; i++)
        {
            Sequence s = (Sequence)sequences[i];
            if (s.name == sequenceName)
            {
                sIndex = i;
                break;
            }
        }

        if (sIndex == ovrLipSyncContextSequencerValues.NullEntry)
        {
            Debug.Log("OVRPhonemeContextSequencer WARNING: " + sequenceName + " does not exist, cannot save.");
            return(false);
        }

        Sequence saveSeq = (Sequence)sequences[sIndex];

        // We can save out each entry in this sequence

        // Use sequenceKey to collect sequence data
        string sequenceKey = sequenceName;

        PlayerPrefs.SetString(sequenceKey, saveSeq.name);

        sequenceKey = sequenceName + "_INFO";
        PlayerPrefs.SetString(sequenceKey, saveSeq.info);

        sequenceKey = sequenceName + "_NE";
        PlayerPrefs.SetInt(sequenceKey, saveSeq.numEntries);

        for (int i = 0; i < saveSeq.entries.Count; i++)
        {
            SequenceEntry e = (SequenceEntry)saveSeq.entries[i];
            sequenceKey  = sequenceName;
            sequenceKey += "_E_";
            sequenceKey += i;

            // for each field in entry
            string sequenceKeyField = "";

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_TIMESTAMP";
            PlayerPrefs.SetFloat(sequenceKeyField, e.timestamp);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_ACTION";
            PlayerPrefs.SetInt(sequenceKeyField, e.action);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_DATA1";
            PlayerPrefs.SetInt(sequenceKeyField, e.data1);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_DATA2";
            PlayerPrefs.SetInt(sequenceKeyField, e.data2);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_DATA3";
            PlayerPrefs.SetInt(sequenceKeyField, e.data3);
        }

        return(true);
    }
示例#11
0
    /// <summary>
    /// Loads a sequence block. Name provided by caller.
    /// </summary>
    /// <returns><c>true</c>, if sequence block was loaded, <c>false</c> otherwise.</returns>
    /// <param name="blockName">Block name.</param>
    public bool LoadSequence(string sequenceName)
    {
        // look for loaded sequence already in array
        for (int i = 0; i < sequences.Count; i++)
        {
            Sequence s = (Sequence)sequences[i];
            if (s.name == sequenceName)
            {
                currentSequence = i;
                return(true);
            }
        }

        // We will load up a stored sequence if it has been previously recorded
        if (PlayerPrefs.GetString(sequenceName, "") == "")
        {
            Debug.Log("OVRLipSyncContextSequencer WARNING: Cannot load sequence " + sequenceName);
            return(false);
        }

        // Create a new sequence
        Sequence seq = new Sequence(0);

        seq.name = sequenceName;

        // Use sequenceKey to collect sequence data
        string sequenceKey = "";

        // INFO (Used for string to show on-screen)
        sequenceKey  = sequenceName;
        sequenceKey += "_INFO";

        seq.info = PlayerPrefs.GetString(sequenceKey, "NO INFO");

        // Number of entries
        sequenceKey    = sequenceName;
        sequenceKey   += "_NE";
        seq.numEntries = PlayerPrefs.GetInt(sequenceKey, 0);

        // Get entries
        for (int i = 0; i < seq.numEntries; i++)
        {
            SequenceEntry e = new SequenceEntry(0);

            // Name of entry
            sequenceKey  = sequenceName;
            sequenceKey += "_E_";
            sequenceKey += i;

            // for each field in entry
            string sequenceKeyField = "";

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_TIMESTAMP";
            e.timestamp       = PlayerPrefs.GetFloat(sequenceKeyField, 0.0f);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_ACTION";
            e.action          = PlayerPrefs.GetInt(sequenceKeyField, -1);     // NULL action if does not exist

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_DATA1";
            e.data1           = PlayerPrefs.GetInt(sequenceKeyField, 0);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_DATA2";
            e.data2           = PlayerPrefs.GetInt(sequenceKeyField, 0);

            sequenceKeyField  = sequenceKey;
            sequenceKeyField += "_DATA3";
            e.data3           = PlayerPrefs.GetInt(sequenceKeyField, 0);

            // Add entry
            seq.entries.Add(e);
        }

        // SANITY CHECK: Make sure that number of entries is the same as what was
        // added
        if (seq.numEntries != seq.entries.Count)
        {
            Debug.Log("OVRLipSyncContextSequencer WARNING: " + sequenceName + " might be corrupted.");
            return(false);
        }

        // Add to sequence list
        sequences.Add(seq);

        return(true);
    }