<commit_before>﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna;
using Microsoft.Xna.Framework.Input;
using System.Reflection;

namespace CocosSharp
{
    public class CCAcceleration
    {
        public double X;
        public double Y;
        public double Z;
        public double TimeStamp;
    }

    public class CCAccelerometer
    {
        #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL
        // the accelerometer sensor on the device
        static Microsoft.Devices.Sensors.Accelerometer accelerometer = null;
        #endif

        const float TG3_GRAVITY_EARTH = 9.80665f;
        readonly CCAcceleration accelerationValue = new CCAcceleration();


        CCEventAccelerate accelerateEvent = new CCEventAccelerate();
        bool enabled = false;


        #region Properties

        public CCWindow Window { get; set; }

        bool Active { get; set; }
        bool Emulating { get; set; }

        public bool Enabled 
        {
            get { return enabled; }

            set 
            {
                enabled = value;
                if (enabled && !Active)
                {
                    #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL
                    try
                    {
                        if(Microsoft.Devices.Sensors.Accelerometer.IsSupported)
                        {
                            accelerometer.CurrentValueChanged += accelerometer_CurrentValueChanged;
                            accelerometer.Start();
                            Active = true;
                        }
                        else
                        {
                            Active = false;
                        }
                    }
                    catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                    {
                        Active = false;
                    }
                    #endif

                    if(!Active)
                    {
                        Active = true;
                        Emulating = true;
                    }
                    else
                    {
                        Emulating = false;
                    }
                }
                else
                {
                    if (Active && !Emulating)
                    {
                        #if !WINDOWS && !OUYA &&!NETFX_CORE && !MACOS && !WINDOWSGL
                        if (accelerometer != null)
                        {
                            accelerometer.CurrentValueChanged -= accelerometer_CurrentValueChanged;
                            accelerometer.Stop();
                        }
                        #endif
                    }

                    ResetAccelerometer();

                    Active = false;
                    Emulating = false;
                }
            }
        }

        #endregion Properties


        #region Constructors

        public CCAccelerometer(CCWindow window)
        {
            Window = window;

            #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL
            try
            {
                accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
            }
            catch (Exception ex)
            {
                CCLog.Log(ex.ToString());
                CCLog.Log("No accelerometer on platform. CCAccelerometer will default to emulation code.");
            }
            #endif
        }

        #endregion Constructors


        void ResetAccelerometer()
        {
            accelerationValue.X = 0;
            accelerationValue.Y = 0;
            accelerationValue.Z = 0;
        }

        #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL
        void accelerometer_CurrentValueChanged(object sender, Microsoft.Devices.Sensors.SensorReadingEventArgs<Microsoft.Devices.Sensors.AccelerometerReading> e)
        {
            // We have to use reflection to get the Vector3 value out of Acceleration
            // What happens is that the Sensor used XNA Vector3 and what we have done is replaced
            // the XNA with MonoGame which our Sensor does not compile against.
            //
            // Result is this ugly hack.
            object val = e.SensorReading.GetType()<commit_msg>WindowsDX: CCAccelerometer was attempting to reference Microsoft.Devices.Sensors<commit_after>﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna;
using Microsoft.Xna.Framework.Input;
using System.Reflection;

namespace CocosSharp
{
    public class CCAcceleration
    {
        public double X;
        public double Y;
        public double Z;
        public double TimeStamp;
    }

    public class CCAccelerometer
    {
        #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL && !WINDOWSDX
        // the accelerometer sensor on the device
        static Microsoft.Devices.Sensors.Accelerometer accelerometer = null;
        #endif

        const float TG3_GRAVITY_EARTH = 9.80665f;
        readonly CCAcceleration accelerationValue = new CCAcceleration();


        CCEventAccelerate accelerateEvent = new CCEventAccelerate();
        bool enabled = false;


        #region Properties

        public CCWindow Window { get; set; }

        bool Active { get; set; }
        bool Emulating { get; set; }

        public bool Enabled 
        {
            get { return enabled; }

            set 
            {
                enabled = value;
                if (enabled && !Active)
                {
                    #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL && !WINDOWSDX
                    try
                    {
                        if(Microsoft.Devices.Sensors.Accelerometer.IsSupported)
                        {
                            accelerometer.CurrentValueChanged += accelerometer_CurrentValueChanged;
                            accelerometer.Start();
                            Active = true;
                        }
                        else
                        {
                            Active = false;
                        }
                    }
                    catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                    {
                        Active = false;
                    }
                    #endif

                    if (!Active)
                    {
                        Active = true;
                        Emulating = true;
                    }
                    else
                    {
                        Emulating = false;
                    }
                }
                else
                {
                    if (Active && !Emulating)
                    {
                        #if !WINDOWS && !OUYA &&!NETFX_CORE && !MACOS && !WINDOWSGL && !WINDOWSDX
                        if (accelerometer != null)
                        {
                            accelerometer.CurrentValueChanged -= accelerometer_CurrentValueChanged;
                            accelerometer.Stop();
                        }
                        #endif
                    }

                    ResetAccelerometer();

                    Active = false;
                    Emulating = false;
                }
            }
        }

        #endregion Properties


        #region Constructors

        public CCAccelerometer(CCWindow window)
        {
            Window = window;

            #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL && !WINDOWSDX
            try
            {
                accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
            }
            catch (Exception ex)
            {
                CCLog.Log(ex.ToString());
                CCLog.Log("No accelerometer on platform. CCAccelerometer will default to emulation code.");
            }
            #endif
        }

        #endregion Constructors


        void ResetAccelerometer()
        {
            accelerationValue.X = 0;
            accelerationValue.Y = 0;
            accelerationValue.Z = 0;
        }

        #if !WINDOWS && !OUYA && !NETFX_CORE && !MACOS && !WINDOWSGL && !WINDOWSDX
        void accelerometer_CurrentValueChanged(object sender, Microsoft.Devices.Sensors.SensorReadingEventArgs<Microsoft.Devices.Sensors.AccelerometerReading> e)
        {
            // We have to use reflection to get the Vector3 value out of Acceleration
            // What happens is that the Sensor used XNA Vector3 and what we have done is replaced
            // the XNA with MonoGame which our Sensor does not compile against.
            //
            // Result is this ugly hack.
            object val = e.SensorReading.GetType()
{'fraction_non_alphanumeric': 0.0712812285124914, 'fraction_numerical': 0.0027504011001604402, 'mean_word_length': 1.1295754026354319, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2623999', 'n_tokens_mistral': 2160, 'n_tokens_neox': 1969, 'n_words': 499}