Ejemplo n.º 1
0
 /// <summary>
 /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
 /// </summary>
 /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
 /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result" />.</param>
 /// <returns>
 /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)
 /// </returns>
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     if (RemoteEvents.Contains(binder.Name))
     {
         result = new AddRemoveMarker();
         return(true);
     }
     if (base.TryGetMember(binder, out result))
     {
         try
         {
             result = Agent.Execute(new RemoteInvocation(InvocationKind.Get, binder.Name));
         }
         catch (SerializationException)
         {
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
        private async Task EnqueueCollectRequestAsync(WebSocket websocket, RemoteEvents request)
        {
            // Ensure there is a collector.  Wait for one if necessary
            if (mCollectors.Count == 0)
            {
                await DequeueCollectRequestAndSendFrame(websocket);
            }

            var            collector      = mCollectors.Dequeue();
            CollectRequest collectRequest = new CollectRequest();

            collectRequest.Collector   = collector;
            collectRequest.DrawRequest = request.DrawRequest;

            // Copy the screen in a blocking background thread
            collectRequest.Task = Task.Run(() =>
            {
                CopyScreen(request, collector, collectRequest);
            });
            mCollectRequests.Enqueue(collectRequest);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copy the screen, block for up to 2 seconds if nothing changes.
        /// </summary>
        void CopyScreen(RemoteEvents request, FrameCollector collector, CollectRequest collectRequest)
        {
            if (mOptions.FullThrottle)
            {
                // Need the lock to wait for previous throttle (if any) to end
                mLastScreenHash = 0; // Ask CopyScreen blocking to end early
                lock (mLockScreenCopy)
                    mLastScreenHash = 0;

                collector.CopyScreen();
            }
            else
            {
                // Block until screen changes or timeout
                // NOTE: Holding this lock (even without the hash function
                //       in the while loop) incurs a time penalty.  This
                //       code is the big bottleneck causing a slow frame
                //       rate.  And most of the time is spent in CopyScreen.
                lock (mLockScreenCopy)
                {
                    long hash = 0;
                    var  screenCopyTimeout = DateTime.Now;
                    while ((DateTime.Now - screenCopyTimeout).TotalMilliseconds < WAIT_FOR_SCREEN_CHANGE_TIMEOUT_MS)
                    {
                        collector.CopyScreen();
                        using (var bm = new Bitmap32Bits(collector.Screen, System.Drawing.Imaging.ImageLockMode.ReadOnly))
                            hash = bm.HashLong(0, 0, bm.Width, bm.Height);
                        if (hash != mLastScreenHash)
                        {
                            break;
                        }
                        Thread.Sleep(20);
                    }
                    mLastScreenHash = hash;
                }
            }
            collector.ScaleScreen(mOptions.Width, mOptions.Height);
        }
        /// <summary>
        /// Called when [remote button press].
        /// </summary>
        /// <param name="remoteControlButton">The remote control button.</param>
        private void OnRemoteButtonPress(RemoteEvents.Buttons button)
        {
            switch (button)
            {
                case RemoteEvents.Buttons.Start:
                    GameRoundStart();
                    break;

                case RemoteEvents.Buttons.Stop:
                    if (_clockState == CountDownClockEvents.StateChangedArgs.Running)
                        GameRoundPause();
                    else
                        GameRoundReset();
                    break;

                case RemoteEvents.Buttons.Left:
                    _config.RequiredImpactLevel -= 5;
                    break;

                case RemoteEvents.Buttons.Right:
                    _config.RequiredImpactLevel += 5;
                    break;
            }
        }