예제 #1
0
        internal void Say(
            string who,
            string what,
            Vector3 where,
            AssignedVoice v,
            bool doRotate,
            BeepType beep)
        {
            if (queue == null)
            {
                return;
            }

            QueuedSpeech e = new QueuedSpeech(
                subs.FixExpressions(who),
                subs.FixExpressions(what),
                where, v, false, doRotate, beep);

            // Put that on the queue and wake up the background thread.
            lock (queue)
            {
                queue.Enqueue(e);
                Monitor.Pulse(queue);
            }
        }
        /// <summary>
        /// Initialize everything that needs to be initialized once we're logged in.
        /// </summary>
        /// <param name="login">The status of the login</param>
        /// <param name="message">Error message on failure, MOTD on success.</param>
        public void RegisterCommand(string name, Cogbot.Actions.Command live)
        {
            string orginalName = name;

            name = name.Replace(" ", "").ToLower();
            while (name.EndsWith("."))
            {
                name = name.Substring(0, name.Length - 1);
            }
            Monitor.Enter(Commands);
            live.TheBotClient = this;
            CommandInstance prev;

            if (!Commands.TryGetValue(name, out prev))
            {
                CommandInstance command = new CommandInstance(live);
                Commands.Add(name, command);
                command.Name = orginalName;
                if (command.IsStateFul)
                {
                    live.TheBotClient     = this;
                    command.WithBotClient = live;
                }
            }
            else
            {
                if (prev.CmdType != live.GetType())
                {
                    RegisterCommand("!" + orginalName, live);
                }
            }
            Monitor.Exit(Commands);
        }
예제 #3
0
        /// <summary>
        /// Say something as a named person or object at a location.
        /// </summary>
        /// <param name="who">Name of person speaking</param>
        /// <param name="what">What they said</param>
        /// <param name="where">Where they were standing when they said it</param>
        /// <param name="v">The voice they use</param>
        internal void Say(
            string who,
            string what,
            Vector3 where,
            AssignedVoice v)
        {
            if (queue == null)
            {
                return;
            }

            // Create queue entry from the information.
            QueuedSpeech e = new QueuedSpeech(
                subs.FixExpressions(who),
                subs.FixExpressions(what),
                where,
                v,
                false);

            // Put that on the queue and wake up the background thread.
            lock (queue)
            {
                queue.Enqueue(e);
                Monitor.Pulse(queue);
            }
        }
예제 #4
0
 /// <summary>
 /// Adds an object to the end of the Queue
 /// </summary>
 /// <param name="obj">Object to put in queue</param>
 public new void Enqueue(T obj)
 {
     lock (SyncRoot)
     {
         base.Enqueue(obj);
         Monitor.Pulse(SyncRoot);
     }
 }
예제 #5
0
 /// <summary>
 /// Remove all objects from the Queue, resume all dequeue threads.
 /// </summary>
 public void Close()
 {
     lock (SyncRoot)
     {
         open = false;
         base.Clear();
         Monitor.PulseAll(SyncRoot); // resume any waiting threads
     }
 }
예제 #6
0
        /// <summary>
        /// The speaking thread body.
        /// </summary>
        /// <remarks>This loops on the queue of things to say, and speaks them
        /// one at a time.</remarks>
        private void SpeakLoop()
        {
            QueuedSpeech utterance;

            try
            {
                while (running)
                {
                    // Wait for something to show up in the queue.
                    lock (queue)
                    {
                        while (queue.Count == 0)
                        {
                            Monitor.Wait(queue);
                        }

                        utterance = queue.Dequeue();
                    }

                    // Watch for the special "shutdown" message.
                    if (utterance.message == null &&
                        utterance.speaker == null)
                    {
                        running = false;
                        continue;
                    }

                    string thisfile = AUDIOFILE + string.Format("{0}", seq++) + ".wav";
                    if (seq > 4)
                    {
                        seq = 0;
                    }

                    // Synthesize it into a file.
                    syn.Speak(utterance, thisfile);

                    // TODO Get FMOD working on Mac
                    if (System.Environment.OSVersion.Platform != PlatformID.MacOSX)
                    {
                        // Play back the file
                        control.sound.Play(
                            thisfile,              // Name of the file
                            16000,                 // Same rate
                            utterance.position,    // Location
                            true,                  // Delete the file when done
                            utterance.isSpatial);  // Whether it is inworld or moves with listener
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Synth shutdown " + e.Message);
            }
        }
        /// <summary>
        /// Thread that processes FMOD calls.
        /// </summary>
        private void CommandLoop()
        {
            // Initialze a bunch of static values
            UpVector.x   = 0.0f;
            UpVector.y   = 1.0f;
            UpVector.z   = 0.0f;
            ZeroVector.x = 0.0f;
            ZeroVector.y = 0.0f;
            ZeroVector.z = 0.0f;

            allSounds   = new Dictionary <IntPtr, MediaObject>();
            allChannels = new Dictionary <IntPtr, MediaObject>();

            // Initialize the command queue.
            queue = new Queue <SoundDelegate>();

            // Initialize the FMOD sound package
            InitFMOD();
            initDone.Set();
            if (!SoundSystemAvailable)
            {
                return;
            }

            SoundDelegate action = null;

            while (true)
            {
                // Wait for something to show up in the queue.
                lock (queue)
                {
                    while (queue.Count == 0)
                    {
                        Monitor.Wait(queue);
                    }
                    action = queue.Dequeue();
                }

                // We have an action, so call it.
                try
                {
                    action();
                    action = null;
                }
                catch (Exception e)
                {
                    Logger.Log("Error in sound action:\n    " + e.Message + "\n" + e.StackTrace,
                               Helpers.LogLevel.Error);
                }
            }
        }
예제 #8
0
        private void CleanupThreadCallback(object state)
        {
            if (_disposed)
            {
                return;
            }

            if (Monitor.TryEnter(_timerLock) == false)
            {
                return;
            }

            try
            {
                lock (_syncRoot)
                {
                    // If we're below, or at, or minimum segment count threshold,
                    // there's no point in going any further.
                    if (_segments.Count <= _minimumSegmentCount)
                    {
                        return;
                    }

                    for (int i = _activeSegment; i > 0; i--)
                    {
                        ObjectPoolSegment <T> segment;
                        if (_segments.TryGetValue(i, out segment) == true)
                        {
                            // For the "old" segments that were allocated at startup, this will
                            // always be false, as their expiration dates are set at infinity.
                            if (segment.CanBeCleanedUp())
                            {
                                _segments.Remove(i);
                                segment.Dispose();
                            }
                        }
                    }
                }
            }
            finally
            {
                Monitor.Exit(_timerLock);
            }
        }
예제 #9
0
 /// <summary>
 /// Removes and returns the object at the beginning of the Queue.
 /// </summary>
 /// <param name="timeout">time to wait before returning (in milliseconds)</param>
 /// <returns>Object in queue.</returns>
 public T Dequeue(int timeout)
 {
     lock (SyncRoot)
     {
         while (open && (base.Count == 0))
         {
             if (!Monitor.Wait(SyncRoot, timeout))
             {
                 throw new InvalidOperationException("Timeout");
             }
         }
         if (open)
         {
             return(base.Dequeue());
         }
         else
         {
             throw new InvalidOperationException("Queue Closed");
         }
     }
 }
예제 #10
0
        internal void _listener_404(IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            HttpJob httpJob = new HttpJob(this, context, request, response);

            lock (HttpJobs)
            {
                HttpJobs.Add(httpJob);
            }
            // 5 second wait
            if (Monitor.TryEnter(HttpLock, waitForEachTime))
            {
                DoJob(httpJob);
                Monitor.Exit(HttpLock);
            }
            else
            {
                LogInfo("ERROR Waiting for prevoius request more than " +
                        TaskQueueHandler.GetTimeString(waitForEachTime));
                httpJob.OutOfLock = true;
                DoJob(httpJob);
            }
        }
 public void EnsureSimulator(Simulator simulator)
 {
     if (simulator == null || simulator.Handle == 0)
     {
         return;
     }
     if (!Monitor.TryEnter(_AllSimulators, 10000))
     {
         WriteLine("Cant lock _AllSimulators");
         return;
     }
     lock (SimMaster)
     {
         if (!SimMaster.ContainsKey(simulator.Handle))
         {
             SimMaster[simulator.Handle] = this;
             MasteringRegions.AddTo(simulator.Handle);
         }
     }
     try
     {
         {
             foreach (Simulator set in _AllSimulators)
             {
                 if (set.Handle == simulator.Handle && set.Client == simulator.Client)
                 {
                     return;
                 }
             }
             _AllSimulators.Add(simulator);
         }
         SimRegion.GetRegion(simulator);
     }
     finally
     {
         Monitor.Exit(_AllSimulators);
     }
 }
예제 #12
0
        /// <summary>
        /// Queue up an action to say.
        /// </summary>
        /// <param name="who"></param>
        /// <param name="what"></param>
        /// <param name="where"></param>
        /// <param name="v"></param>
        internal void SayAction(
            string who,
            string what,
            Vector3 where,
            AssignedVoice v,
            bool spatial)
        {
            if (queue == null)
            {
                return;
            }

            QueuedSpeech e = new QueuedSpeech(
                subs.FixExpressions(who),
                subs.FixExpressions(what),
                where, v, true, spatial, BeepType.None);

            lock (queue)
            {
                queue.Enqueue(e);
                Monitor.Pulse(queue);
            }
        }
예제 #13
0
 public bool Dequeue(int timeout, ref T obj)
 {
     lock (SyncRoot)
     {
         while (open && (base.Count == 0))
         {
             if (!Monitor.Wait(SyncRoot, timeout))
             {
                 return(false);
             }
         }
         if (open)
         {
             obj = base.Dequeue();
             return(true);
         }
         else
         {
             obj = default(T);
             return(false);
         }
     }
 }
예제 #14
0
        private void InitializeFriendsList()
        {
            if (!Monitor.TryEnter(lockOneAtaTime))
            {
                return;
            }
            List <FriendInfo> friends = client.Friends.FriendList.FindAll((FriendInfo f) => true);

            friends.Sort((fi1, fi2) =>
            {
                if (fi1.IsOnline && !fi2.IsOnline)
                {
                    return(-1);
                }
                else if (!fi1.IsOnline && fi2.IsOnline)
                {
                    return(1);
                }
                else
                {
                    return(String.CompareOrdinal(fi1.Name, fi2.Name));
                }
            }
                         );

            listFriends.BeginUpdate();

            listFriends.Items.Clear();
            foreach (FriendInfo friend in friends)
            {
                listFriends.Items.Add(friend);
            }

            listFriends.EndUpdate();
            Monitor.Exit(lockOneAtaTime);
        }