Beispiel #1
0
        private static void AssertEqualRelativePaths(
            BuildXLContext context,
            string objPath,
            Remapper remapper,
            RelativePath expectedPath,
            RelativePath actualPath)
        {
            if (remapper?.PathAtomStringRemapper != null)
            {
                var expectedAtoms = expectedPath.GetAtoms();
                var actualAtoms   = actualPath.GetAtoms();

                XAssert.AreEqual(
                    expectedAtoms.Length,
                    actualAtoms.Length,
                    $"{nameof(AbsolutePath)} values don't match for objPath: {objPath}");

                for (int i = 0; i < expectedAtoms.Length; ++i)
                {
                    AssertEqualPathAtoms(context, objPath, remapper, expectedAtoms[i], actualAtoms[i]);
                }
            }
            else
            {
                XAssert.AreEqual(expectedPath, actualPath, $"{nameof(RelativePath)} values don't match for objPath: {objPath}");
            }
        }
Beispiel #2
0
    void Update()
    {
        float mappedValue = Remapper.Remap(player.currentSpeed, speedLimit.x, speedLimit.y, tachoGrenze.x, tachoGrenze.y);

        tachoNadel.localRotation = Quaternion.Euler(0f, 0f, -mappedValue);
        speedText.text           = player.currentSpeed.ToString("0");
    }
Beispiel #3
0
        /* Constructor */
        public MainForm()
        {
            InitializeComponent();

            // Setup global keyboard hook
            m_GlobalKeyboardHook = new GlobalKeyboardHook();
            m_GlobalKeyboardHook.KeyboardPressed += OnKeyPressed;

            // Setup global mouse hook
            m_GlobalMouseHook             = new GlobalMouseHook();
            m_GlobalMouseHook.MouseEvent += OnMouseEvent;

            // Create macro player
            m_MacroPlayer                  = new MacroPlayer();
            m_MacroPlayer.Loop             = true;
            m_MacroPlayer.RecordShortcut   = true;
            m_MacroPlayer.PropertyChanged += MacroPlayer_PropertyChanged;

            // Create remapper
            m_Remapper = new Remapper();

            // Create status checker
            m_StatusChecker = new StatusChecker();

            // Set control mode
            SetControlMode(ControlMode.Macro);

            // Create save/load helper
            m_SaveLoadHelper = new SaveLoadHelper(this, m_MacroPlayer);
            m_SaveLoadHelper.PropertyChanged += SaveLoadHelper_PropertyChanged;

            // Initialize interceptor
            InitInterceptor();
        }
        private void SetInfluences(params InfluenceDef[] influences)
        {
            Remapper remap = new Remapper();

            remap.Remap(influences);
            for (int i = 0; i < remap.RemapTable.Length; ++i)
            {
                _facePoints[i].InfluenceIndex = remap.RemapTable[i];
            }
            _influences = new InfluenceDef[remap.ImplementationLength];
            for (int i = 0; i < remap.ImplementationLength; ++i)
            {
                _influences[i] = influences[remap.ImplementationTable[i]];
            }

            HashSet <string> utilized = new HashSet <string>();

            foreach (InfluenceDef inf in _influences)
            {
                if (inf != null)
                {
                    for (int i = 0; i < inf.WeightCount; ++i)
                    {
                        utilized.Add(inf.Weights[i].Bone);
                    }
                }
            }
            _utilizedBones = utilized.ToArray();
        }
Beispiel #5
0
        /// <summary>
        /// Constructor for this class, defines the individual controller.
        /// </summary>
        public DInputController(SharpDX.DirectInput.DirectInput directInput, Guid deviceGuid) : base(directInput, deviceGuid)
        {
            // Instantiate the remapper.
            Remapper = new Remapper(Remapper.InputDeviceType.DirectInput, this);

            // Get the controller key binding.
            Remapper.GetMappings();
        }
Beispiel #6
0
        private void Evaluate()
        {
            //Colors will almost always need remapping
            _remapData = new Remapper();
            _remapData.Remap(new MemoryList <RGBAPixel>(_pData, _srcCount), null); //Don't bother sorting

            int[] imp    = _remapData._impTable;
            int   impLen = imp.Length;

            _dstCount = impLen;

            //Do we have alpha?
            int i = 0;

            while (i < _dstCount && _pData[imp[i]].A == 255)
            {
                i++;
            }

            _hasAlpha = i < _srcCount;

            //Determine format
            if (_hasAlpha)
            {
                _outType = WiiColorComponentType.RGBA8;
            }
            else
            {
                _outType = WiiColorComponentType.RGB8;
            }

            switch (_outType)
            {
            case WiiColorComponentType.RGB565:
            case WiiColorComponentType.RGBA4:
                _dstStride = 2;
                break;

            case WiiColorComponentType.RGB8:
            case WiiColorComponentType.RGBA6:
                _dstStride = 3;
                break;

            case WiiColorComponentType.RGBA8:
            case WiiColorComponentType.RGBX8:
                _dstStride = 4;
                break;
            }

            _dataLen = _dstStride * _dstCount;

            GetEncoder();
        }
        /// <summary>
        /// Constructor for this class, defines the individual controller.
        /// </summary>
        /// <param name="controllerId">Specifies the XInput controller port for the controller to be created.</param>
        public XInputController(int controllerId)
        {
            // Create controller instance and assign controller port.
            Controller   = new Controller((UserIndex)controllerId);
            ControllerId = controllerId;

            // Instantiate the remapper.
            Remapper = new Remapper(Remapper.InputDeviceType.XInput, this);

            // Get the controller key binding.
            Remapper.GetMappings();
        }
Beispiel #8
0
    private void Update()
    {
        float t = Remapper.Remap(player.currentSpeed, player.minSpeed, player.maxSpeed, 0, 1);

        //Camera FoV
        cameraComponent.fieldOfView = Mathf.Lerp(minFOV, maxFOV, fovCurve.Evaluate(t));

        //Camera MotionBlur
        motionBlur.shutterAngle.value = Mathf.Lerp(minShutterAngle, maxShutterAngle, motionBlurCurve.Evaluate(t));

        //Camera Shake
        transform.localPosition = localStartPos + Random.insideUnitSphere * Mathf.Lerp(minShake, maxShake, shakeCurve.Evaluate(t));
    }
Beispiel #9
0
    public IEnumerator SetProgressBar()
    {
        _currentPos = Player.Instance.transform.position.x;
        Vector3 pos = Vector3.one;

        CurrentLevelText.text = StageManager.Instance.getCurrentLevel().ToString();
        NextLevelText.text    = (StageManager.Instance.getCurrentLevel() + 1).ToString();
        while (true)
        {
            pos.x = Remapper.Remap(_currentPos, startPosition, _endPosition, 0, 1);
            Bar.transform.localScale = pos;
            yield return(new WaitForFixedUpdate());
        }
    }
Beispiel #10
0
        /// <summary>
        /// Apply brightness and any other things to the image
        /// Ok to modify image
        /// </summary>
        /// <param name="image"></param>
        /// <param name="gamma"></param>
        /// <param name="useGamma"></param>
        /// <returns></returns>
        private void PostProcessImage(uint[] image, byte[] gamma, bool useGamma)
        {
            if (image == null)
            {
                return;
            }

            ApplyBrightness(image);
            imageFilter(image); // any external filtering

            if (device.IsConnected)
            {
                device.WriteImage(Remapper.MapImage(image, useGamma ? gamma : null));
            }
        }
Beispiel #11
0
 private static void AssertEqualLocationData(
     BuildXLContext context,
     string objPath,
     Remapper remapper,
     LocationData expectedLocationData,
     LocationData actualLocationData)
 {
     if (remapper?.PathStringRemapper != null)
     {
         AssertEqualAbsolutePaths(context, objPath, remapper, expectedLocationData.Path, actualLocationData.Path);
         XAssert.AreEqual(expectedLocationData.Line, actualLocationData.Line, $"{nameof(LocationData)} values don't match for objPath: {objPath}");
         XAssert.AreEqual(expectedLocationData.Position, actualLocationData.Position, $"{nameof(LocationData)} values don't match for objPath: {objPath}");
     }
     else
     {
         XAssert.AreEqual(expectedLocationData, actualLocationData, $"{nameof(LocationData)} values don't match for objPath: {objPath}");
     }
 }
Beispiel #12
0
    void Update()
    {
        float playerDistance = Vector3.Distance(player.transform.position, trackStart.position);

        //Prewarm Phase
        if (playerDistance < 0.5f && !isStarted)
        {
            isStarted = true;
        }

        if (isStarted)
        {
            playerDistance /= trackDistance;
            playerDistance  = Mathf.Clamp01(playerDistance);
            float progess = Remapper.Remap(playerDistance, 0, 1, startPos.position.x + startPos.rect.width / 2, endPos.position.x - endPos.rect.width / 2);
            playerIcon.position = new Vector3(progess, playerIcon.position.y, playerIcon.position.z);
        }
    }
Beispiel #13
0
        private static void ValidateConfigurationCopyConstructor(bool booleanDefault)
        {
            var context         = BuildXLContext.CreateInstanceForTesting();
            var initialInstance = (CommandLineConfiguration)CreateInstance(context, typeof(CommandLineConfiguration), booleanDefault);

            string from = A("x");
            string to   = A("y");

            var remapper     = new Remapper(new PathTable(), p => p.Replace(from, to), a => a + "_");
            var pathRemapper = new PathRemapper(
                context.PathTable,
                remapper.PathTable,
                pathStringRemapper: remapper.PathStringRemapper,
                pathAtomStringRemapper: remapper.PathAtomStringRemapper);
            var clone = new CommandLineConfiguration(initialInstance, pathRemapper);

            ValidateEqual(context, typeof(CommandLineConfiguration), initialInstance, clone, "configuration", remapper);
        }
Beispiel #14
0
 private static void AssertEqualFileArtifacts(
     BuildXLContext context,
     string objPath,
     Remapper remapper,
     FileArtifact expectedFile,
     FileArtifact actualFile)
 {
     if (remapper != null)
     {
         AssertEqualAbsolutePaths(context, objPath, remapper, expectedFile.Path, actualFile.Path);
         XAssert.AreEqual(
             expectedFile.RewriteCount,
             actualFile.RewriteCount,
             $"{nameof(FileArtifact)} values don't match for objPath: {objPath}");
     }
     else
     {
         XAssert.AreEqual(expectedFile, actualFile, $"{nameof(FileArtifact)} values don't match for objPath: {objPath}");
     }
 }
Beispiel #15
0
    public void Reset()
    {
        this.enabled     = true;
        meshRend.enabled = true;

        currentSpeed = 0;
        manager.SwitchGameplay(GameState.PLAY);
        rigid.useGravity   = true;
        isFinished         = false;
        transform.rotation = Quaternion.identity;
        transform.position = startPoint.position;
        startRoutine       = StartCoroutine(StartSpeedUp());
        metalBarRessource  = 1f;
        rigid.constraints  = RigidbodyConstraints.FreezeRotationY & RigidbodyConstraints.FreezeRotationZ;
        float value = Remapper.Remap(metalBarRessource, 0, 1, 0, 0.8f);

        crowbarMat.SetFloat("_OpacityEmission", value);
        timer = 0;
        metalbarText.SetActive(false);
        metalbar.SetActive(true);
    }
        private void Evaluate()
        {
            //Colors will almost always need remapping
            _remapData = new Remapper();
            _remapData.Remap<RGBAPixel>(new MemoryList<RGBAPixel>(_pData, _srcCount), null); //Don't bother sorting

            int[] imp = _remapData._impTable;
            int impLen = imp.Length;

            _dstCount = impLen;

            //Do we have alpha?
            int i = 0;
            while ((i < _dstCount) && (_pData[imp[i]].A == 255)) i++;

            _hasAlpha = i < _srcCount;

            //Determine format
            if (_hasAlpha)
                _outType = WiiColorComponentType.RGBA8;
            else
                _outType = WiiColorComponentType.RGB8;

            switch (_outType)
            {
                case WiiColorComponentType.RGB565:
                case WiiColorComponentType.RGBA4:
                    _dstStride = 2; break;
                case WiiColorComponentType.RGB8:
                case WiiColorComponentType.RGBA6:
                    _dstStride = 3; break;
                case WiiColorComponentType.RGBA8:
                case WiiColorComponentType.RGBX8:
                    _dstStride = 4; break;
            }

            _dataLen = _dstStride * _dstCount;

            GetEncoder();
        }
Beispiel #17
0
 private static void AssertEqualAbsolutePaths(BuildXLContext context, string objPath, Remapper remapper, AbsolutePath expectedPath, AbsolutePath actualPath)
 {
     if (remapper?.PathStringRemapper != null)
     {
         var expectedPathString = remapper.PathStringRemapper(expectedPath.ToString(context.PathTable));
         XAssert.AreEqual(
             expectedPathString,
             actualPath.ToString(remapper.PathTable),
             $"{nameof(AbsolutePath)} values don't match for objPath: {objPath}");
     }
     else
     {
         XAssert.AreEqual(expectedPath, actualPath, $"{nameof(AbsolutePath)} values don't match for objPath: {objPath}");
     }
 }
Beispiel #18
0
 private static void AssertEqualPathAtoms(BuildXLContext context, string objPath, Remapper remapper, PathAtom expectedAtom, PathAtom actualAtom)
 {
     if (remapper?.PathAtomStringRemapper != null)
     {
         var expectedAtomString = remapper.PathAtomStringRemapper(expectedAtom.ToString(context.StringTable));
         XAssert.AreEqual(
             expectedAtomString,
             actualAtom.ToString(remapper.PathTable.StringTable),
             $"{nameof(PathAtom)} values don't match for objPath: {objPath}");
     }
     else
     {
         XAssert.AreEqual(expectedAtom, actualAtom, $"{nameof(PathAtom)} values don't match for objPath: {objPath}");
     }
 }
Beispiel #19
0
        public static void ValidateEqual(BuildXLContext context, Type type, object expected, object actual, string objPath, Remapper remapper)
        {
            type = GetNonNullableType(type);

            if (type == typeof(bool))
            {
                XAssert.AreEqual((bool)expected, (bool)actual, $"{nameof(Boolean)} values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(int) || type == typeof(short) || type == typeof(sbyte) || type == typeof(long))
            {
                XAssert.AreEqual(
                    Convert.ToInt64(expected),
                    Convert.ToInt64(actual),
                    $"Numeric values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(uint) || type == typeof(ushort) || type == typeof(byte) || type == typeof(ulong))
            {
                XAssert.AreEqual(
                    Convert.ToUInt64(expected),
                    Convert.ToUInt64(actual),
                    $"Numeric values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(double))
            {
                XAssert.AreEqual(
                    Convert.ToDouble(expected),
                    Convert.ToDouble(actual),
                    $"Numeric values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(string))
            {
                XAssert.AreEqual((string)expected, (string)actual, $"{nameof(String)} values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(ModuleId))
            {
                XAssert.AreEqual(
                    (ModuleId)expected,
                    (ModuleId)actual,
                    $"{nameof(ModuleId)} id values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(LocationData))
            {
                AssertEqualLocationData(context, objPath, remapper, (LocationData)expected, (LocationData)actual);
                return;
            }

            if (type == typeof(RelativePath))
            {
                AssertEqualRelativePaths(context, objPath, remapper, (RelativePath)expected, (RelativePath)actual);
                return;
            }

            if (type == typeof(AbsolutePath))
            {
                AssertEqualAbsolutePaths(context, objPath, remapper, (AbsolutePath)expected, (AbsolutePath)actual);
                return;
            }

            if (type == typeof(FileArtifact))
            {
                AssertEqualFileArtifacts(context, objPath, remapper, (FileArtifact)expected, (FileArtifact)actual);
                return;
            }

            if (type == typeof(PathAtom))
            {
                AssertEqualPathAtoms(context, objPath, remapper, (PathAtom)expected, (PathAtom)actual);
                return;
            }

            if (type == typeof(SymbolAtom))
            {
                XAssert.AreEqual((SymbolAtom)expected, (SymbolAtom)actual, $"{nameof(SymbolAtom)} values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(global::BuildXL.Utilities.LineInfo))
            {
                XAssert.AreEqual(
                    (global::BuildXL.Utilities.LineInfo)expected,
                    (global::BuildXL.Utilities.LineInfo)actual,
                    $"{nameof(global::BuildXL.Utilities.LineInfo)} values don't match for objPath: {objPath}");
                return;
            }

            if (type == typeof(LineInfo))
            {
                XAssert.AreEqual(
                    (LineInfo)expected,
                    (LineInfo)actual,
                    $"{nameof(LineInfo)} values don't match for objPath: {objPath}");
                return;
            }

            if (type.GetTypeInfo().IsEnum)
            {
                XAssert.AreEqual((Enum)expected, (Enum)actual, $"Enum values don't match for objPath: {objPath}");
                return;
            }

            if (type.GetTypeInfo().IsGenericType)
            {
                var generic = type.GetGenericTypeDefinition();
                if (generic == typeof(List <>) || generic == typeof(IReadOnlyList <>))
                {
                    XAssert.IsTrue((expected == null) == (actual == null));

                    var expectedList = expected as IList;
                    var actualList   = actual as IList;

                    XAssert.IsTrue(
                        (expectedList == null) == (actualList == null),
                        "One of the lists is null, the other isnt for objPath: {0}",
                        objPath);
                    if (expectedList != null)
                    {
                        XAssert.AreEqual(expectedList.Count, actualList.Count, $"Counts of lists don't match for objPath: {objPath}");
                        for (int i = 0; i < expectedList.Count; i++)
                        {
                            ValidateEqual(
                                context,
                                type.GenericTypeArguments[0],
                                expectedList[i],
                                actualList[i],
                                objPath + "[" + i.ToString(CultureInfo.InvariantCulture) + "]",
                                remapper);
                        }
                    }

                    return;
                }

                if (generic == typeof(Dictionary <,>) || generic == typeof(IReadOnlyDictionary <,>) || generic == typeof(ConcurrentDictionary <,>))
                {
                    XAssert.IsTrue((expected == null) == (actual == null));

                    var expectedDictionary = expected as IDictionary;
                    var actualDictionary   = actual as IDictionary;

                    XAssert.IsTrue(
                        (expectedDictionary == null) == (actualDictionary == null),
                        $"One of the dictionaries is null, the other isnt for objPath: {objPath}");
                    if (expectedDictionary != null)
                    {
                        XAssert.AreEqual(
                            expectedDictionary.Count,
                            expectedDictionary.Count,
                            $"Counts of dictionaries don't match for objPath: {objPath}");
                        foreach (var kv in expectedDictionary)
                        {
                            var key         = kv.GetType().GetProperty("Key").GetValue(kv);
                            var value       = kv.GetType().GetTypeInfo().GetProperty("Value").GetValue(kv);
                            var actualValue = actualDictionary[key];

                            ValidateEqual(context, type.GenericTypeArguments[1], value, actualValue, objPath + "[" + key + "]", remapper);
                        }
                    }

                    return;
                }
            }

            if (type.GetTypeInfo().IsInterface)
            {
                var actualType = ConfigurationConverter.FindImplementationType(
                    type,
                    ObjectLiteral.Create(new List <Binding>(), default(LineInfo), AbsolutePath.Invalid),

                    // Note we only create a sourceresolver, so no need to fiddle, just compare with SourceResolver.
                    () => "SourceResolver");
                ValidateEqualMembers(context, actualType, expected, actual, objPath, remapper);
                return;
            }

            if (type.GetTypeInfo().IsClass)
            {
                ValidateEqualMembers(context, type, expected, actual, objPath, remapper);
                return;
            }

            XAssert.Fail($"Don't know how to compare objects of this type '{type}' for objPath: {objPath}");
        }
Beispiel #20
0
        private static void ValidateEqualMembers(BuildXLContext context, Type type, object expected, object actual, string objPath, Remapper remapper)
        {
            XAssert.IsTrue(type.GetTypeInfo().IsClass);

            foreach (var property in type.GetTypeInfo().GetProperties(BindingFlags.Instance))
            {
                var expectedProperty = property.GetValue(expected);
                var actualProperty   = property.GetValue(actual);
                ValidateEqual(context, property.PropertyType, expectedProperty, actualProperty, objPath + "." + property.Name, remapper);
            }
        }
Beispiel #21
0
        public RemapperForm(Remapper remapper)
        {
            InitializeComponent();

            Remapper = remapper;
        }
Beispiel #22
0
        private void Evaluate(bool removeZ)
        {
            float *fPtr;
            int    bestScale = 0;
            bool   sign;

            Vector3 min = new Vector3(float.MaxValue), max = new Vector3(float.MinValue);
            float * pMin = (float *)&min, pMax = (float *)&max;
            float   vMin = float.MaxValue, vMax = float.MinValue, vDist;
            float   val;

            //Currently, remapping provides to benefit for vertices/normals
            //Maybe when merging is supported this will change

            _remap = new Remapper();
            //if (_srcElements == 3)
            //    _remap.Remap<Vector3>(new MemoryList<Vector3>(_pData, _srcCount), null);
            //if (_srcElements == 2)
            //    _remap.Remap<Vector2>(new MemoryList<Vector2>(_pData, _srcCount), null);

            int[] imp    = null;
            int   impLen = _srcCount;

            //Remapping is useless if there is no savings
            if (_remap._impTable != null && _remap._impTable.Length < _srcCount)
            {
                imp    = _remap._impTable;
                impLen = imp.Length;
            }

            _min      = new Vector3(float.MaxValue);
            _max      = new Vector3(float.MinValue);
            _dstCount = impLen;
            _type     = 0;

            //Get extents
            fPtr = _pData;
            for (int i = 0; i < impLen; i++)
            {
                if (imp != null)
                {
                    fPtr = &_pData[imp[i] * _srcElements];
                }
                for (int x = 0; x < _srcElements; x++)
                {
                    val = *fPtr++;
                    if (val < pMin[x])
                    {
                        pMin[x] = val;
                    }
                    if (val > pMax[x])
                    {
                        pMax[x] = val;
                    }
                    if (val < vMin)
                    {
                        vMin = val;
                    }
                    if (val > vMax)
                    {
                        vMax = val;
                    }
                }
            }

            _min = min;
            _max = max;
            if (removeZ && (_srcElements == 3) && (min._z == 0) && (max._z == 0))
            {
                _dstElements = 2;
            }
            else
            {
                _dstElements = _srcElements;
            }

            _hasZ = _dstElements > 2;

            vDist = Math.Max(Math.Abs(vMin), Math.Abs(vMax));

            if (!_forceFloat)
            {
                //Is signed? If so, increase type
                if (sign = (vMin < 0))
                {
                    _type++;
                }

                int   divisor = 0;
                float rMin = 0.0f, rMax;
                for (int i = 0; i < 2; i++)
                {
                    float bestError = _maxError;
                    float scale, maxVal;

                    if (i == 0)
                    {
                        if (sign)
                        {
                            rMax = 127.0f; rMin = -128.0f;
                        }
                        else
                        {
                            rMax = 255.0f;
                        }
                    }
                    else
                    if (sign)
                    {
                        rMax = 32767.0f; rMin = -32768.0f;
                    }
                    else
                    {
                        rMax = 65535.0f;
                    }

                    maxVal = rMax / vDist;
                    while ((divisor < 32) && ((scale = VQuant.QuantTable[divisor]) <= maxVal))
                    {
                        float worstError = float.MinValue;

                        fPtr = _pData;
                        for (int y = 0; y < impLen; y++)
                        {
                            if (imp != null)
                            {
                                fPtr = &_pData[imp[i] * _srcElements];
                            }
                            for (int z = 0; z < _srcElements; z++)
                            {
                                if ((val = *fPtr++) == 0)
                                {
                                    continue;
                                }

                                val *= scale;
                                if (val > rMax)
                                {
                                    val = rMax;
                                }
                                else if (val < rMin)
                                {
                                    val = rMin;
                                }

                                int step = (int)((val * scale));
                                //int step = (int)((val * scale) + (val > 0 ? 0.5f : -0.5f));
                                float error = Math.Abs((step / scale) - val);

                                if (error > worstError)
                                {
                                    worstError = error;
                                }

                                if (error > bestError)
                                {
                                    goto Check;
                                }
                            }
                        }

                        //for (fPtr = sPtr; fPtr < fCeil; )
                        //{
                        //    if ((val = *fPtr++) == 0)
                        //        continue;

                        //    val *= scale;
                        //    if (val > rMax) val = rMax;
                        //    else if (val < rMin) val = rMin;

                        //    int step = (int)((val * scale);// + (val > 0 ? 0.5f : -0.5f));
                        //    float error = Math.Abs((step / scale) - val);

                        //    if (error > worstError)
                        //        worstError = error;

                        //    if (error > bestError)
                        //        break;
                        //}

Check:

                        if (worstError < bestError)
                        {
                            bestScale = divisor;
                            bestError = worstError;
                            if (bestError == 0)
                            {
                                goto Next;
                            }
                        }

                        divisor++;
                    }

                    if (bestError < _maxError)
                    {
                        goto Next;
                    }

                    _type += 2;
                }
            }

            _type  = WiiVertexComponentType.Float;
            _scale = 0;

Next:

            _scale     = bestScale;
            _dstStride = _dstElements << ((int)_type >> 1);
            _dataLen   = _dstCount * _dstStride;

            _quantScale = VQuant.QuantTable[_scale];
            GetEncoder();
        }
Beispiel #23
0
        public void Start(HypnoLsdController device, Remapper remapper, int mbaud, Action <uint[]> imageFilterIn = null)
        {
            this.device = device;

            Remapper = remapper;
            Width    = remapper.Width;
            Height   = remapper.Height;

            if (imageFilterIn != null)
            {
                this.imageFilter = imageFilterIn;
            }
            else
            {
                this.imageFilter = b => { }
            };                               // identity

            AddDemos();

            // get attention
            device.WriteString("\r\n");
            Thread.Sleep(250);

            //device.ConnectionSpeed = 1000000; // 1 Mbaud for testing
            //Thread.Sleep(100);

            //Thread.Sleep(1000);
            //device.Drawing = true;
            //Thread.Sleep(1000);
            //device.Drawing = false;
            //Thread.Sleep(1000);

            device.WriteString("\r\n");


            device.ConnectionSpeed = mbaud; // 12000000;// 3000000;// 12000000; // 12 Mbaud for testing
            Thread.Sleep(500);

            const int delay = 200;

            device.Drawing = false;
            Thread.Sleep(delay);

            device.Drawing = true;
            Thread.Sleep(delay);
            device.Drawing = false;
            Thread.Sleep(delay);

            if (remapper.SupportedStrands.Contains(remapper.Strands))
            {
                device.SetSize(remapper.Strands, remapper.Width * remapper.Height / remapper.Strands);
            }
            else
            {
                throw new NotImplementedException("Remapper does not support " + remapper.Strands + " strands");
            }

            // some context switches to ensure we're at the top in case we disconnected early last time.
            device.Drawing = true;
            Thread.Sleep(delay);
        }
Beispiel #24
0
        public PrimitiveData(VertexShaderDesc info, IEnumerable <Vertex> points, EPrimitiveType type)
        {
            _bufferInfo = info;
            _type       = type;
            _influences = null;

            List <Vertex> vertices = points.ToList();
            Remapper      remapper = null;

            switch (_type)
            {
            case EPrimitiveType.Triangles:
                remapper = SetTriangleIndices(vertices);
                break;

            case EPrimitiveType.Lines:
                remapper = SetLineIndices(vertices);
                break;

            default:
                //case EPrimitiveType.Points:
                remapper = SetPointIndices(vertices);
                break;
            }

            int[] firstAppearanceArray = null;
            if (remapper == null)
            {
                firstAppearanceArray = new int[vertices.Count];
                for (int i = 0; i < vertices.Count; ++i)
                {
                    firstAppearanceArray[i] = i;
                }
            }
            else
            {
                firstAppearanceArray = remapper.ImplementationTable;
            }

            CreateFacePoints(firstAppearanceArray.Length);

            if (info.HasSkinning)
            {
                SetInfluences(firstAppearanceArray.Select(x => vertices[x].Influence).ToArray());
            }

            for (int i = 0; i < info.MorphCount + 1; ++i)
            {
                var data = firstAppearanceArray.Select(x => vertices[x].Position).ToList();
                AddBuffer(data, EBufferType.Position);
            }
            if (info.HasNormals)
            {
                for (int i = 0; i < info.MorphCount + 1; ++i)
                {
                    var data = firstAppearanceArray.Select(x => vertices[x].Normal).ToList();
                    AddBuffer(data, EBufferType.Normal);
                }
            }
            if (info.HasBinormals)
            {
                for (int i = 0; i < info.MorphCount + 1; ++i)
                {
                    var data = firstAppearanceArray.Select(x => vertices[x].Binormal).ToList();
                    AddBuffer(data, EBufferType.Binormal);
                }
            }
            if (info.HasTangents)
            {
                for (int i = 0; i < info.MorphCount + 1; ++i)
                {
                    var data = firstAppearanceArray.Select(x => vertices[x].Tangent).ToList();
                    AddBuffer(data, EBufferType.Tangent);
                }
            }
            for (int i = 0; i < info.ColorCount; ++i)
            {
                var data = firstAppearanceArray.Select(x => vertices[x].Color).ToList();
                AddBuffer(data, EBufferType.Color);
            }
            for (int i = 0; i < info.TexcoordCount; ++i)
            {
                var data = firstAppearanceArray.Select(x => vertices[x].TexCoord).ToList();
                AddBuffer(data, EBufferType.TexCoord);
            }
        }
        private void Evaluate(bool removeZ)
        {
            float* fPtr;
            int bestScale = 0;
            bool sign;

            Vector3 min = new Vector3(float.MaxValue), max = new Vector3(float.MinValue);
            float* pMin = (float*)&min, pMax = (float*)&max;
            float vMin = float.MaxValue, vMax = float.MinValue, vDist;
            float val;

            //Currently, remapping provides to benefit for vertices/normals
            //Maybe when merging is supported this will change

            _remap = new Remapper();
            //if (_srcElements == 3)
            //    _remap.Remap<Vector3>(new MemoryList<Vector3>(_pData, _srcCount), null);
            //if (_srcElements == 2)
            //    _remap.Remap<Vector2>(new MemoryList<Vector2>(_pData, _srcCount), null);

            int[] imp = null;
            int impLen = _srcCount;

            //Remapping is useless if there is no savings
            if (_remap._impTable != null && _remap._impTable.Length < _srcCount)
            {
                imp = _remap._impTable;
                impLen = imp.Length;
            }

            _min = new Vector3(float.MaxValue);
            _max = new Vector3(float.MinValue);
            _dstCount = impLen;
            _type = 0;

            //Get extents
            fPtr = _pData;
            for (int i = 0; i < impLen; i++)
            {
                if (imp != null)
                    fPtr = &_pData[imp[i] * _srcElements];
                for (int x = 0; x < _srcElements; x++)
                {
                    val = *fPtr++;
                    if (val < pMin[x]) pMin[x] = val;
                    if (val > pMax[x]) pMax[x] = val;
                    if (val < vMin) vMin = val;
                    if (val > vMax) vMax = val;
                }
            }

            _min = min;
            _max = max;
            if (removeZ && (_srcElements == 3) && (min._z == 0) && (max._z == 0))
                _dstElements = 2;
            else
                _dstElements = _srcElements;

            _hasZ = _dstElements > 2;

            vDist = Math.Max(Math.Abs(vMin), Math.Abs(vMax));

            if (!_forceFloat)
            {
                //Is signed? If so, increase type
                if (sign = (vMin < 0))
                    _type++;

                int divisor = 0;
                float rMin = 0.0f, rMax;
                for (int i = 0; i < 2; i++)
                {
                    float bestError = _maxError;
                    float scale, maxVal;

                    if (i == 0)
                        if (sign)
                        { rMax = 127.0f; rMin = -128.0f; }
                        else
                            rMax = 255.0f;
                    else
                        if (sign)
                        { rMax = 32767.0f; rMin = -32768.0f; }
                        else
                            rMax = 65535.0f;

                    maxVal = rMax / vDist;
                    while ((divisor < 32) && ((scale = VQuant.QuantTable[divisor]) <= maxVal))
                    {
                        float worstError = float.MinValue;

                        fPtr = _pData;
                        for (int y = 0; y < impLen; y++)
                        {
                            if (imp != null)
                                fPtr = &_pData[imp[i] * _srcElements];
                            for (int z = 0; z < _srcElements; z++)
                            {
                                if ((val = *fPtr++) == 0)
                                    continue;

                                val *= scale;
                                if (val > rMax) val = rMax;
                                else if (val < rMin) val = rMin;

                                int step = (int)((val * scale));
                                //int step = (int)((val * scale) + (val > 0 ? 0.5f : -0.5f));
                                float error = Math.Abs((step / scale) - val);

                                if (error > worstError)
                                    worstError = error;

                                if (error > bestError)
                                    goto Check;
                            }
                        }

                        //for (fPtr = sPtr; fPtr < fCeil; )
                    //{
                    //    if ((val = *fPtr++) == 0)
                    //        continue;

                        //    val *= scale;
                    //    if (val > rMax) val = rMax;
                    //    else if (val < rMin) val = rMin;

                        //    int step = (int)((val * scale);// + (val > 0 ? 0.5f : -0.5f));
                    //    float error = Math.Abs((step / scale) - val);

                        //    if (error > worstError)
                    //        worstError = error;

                        //    if (error > bestError)
                    //        break;
                    //}

                    Check:

                        if (worstError < bestError)
                        {
                            bestScale = divisor;
                            bestError = worstError;
                            if (bestError == 0)
                                goto Next;
                        }

                        divisor++;
                    }

                    if (bestError < _maxError)
                        goto Next;

                    _type += 2;
                }
            }

            _type = WiiVertexComponentType.Float;
            _scale = 0;

            Next:

            _scale = bestScale;
            _dstStride = _dstElements << ((int)_type >> 1);
            _dataLen = _dstCount * _dstStride;

            _quantScale = VQuant.QuantTable[_scale];
            GetEncoder();
        }
Beispiel #26
0
        public List <PrimitiveGroup> GroupPrimitives(Facepoint[] points, out int pointCount, out int faceCount)
        {
            pointCount = 0;
            faceCount  = 0;
            List <PrimitiveClass> fpPrimitives = new List <PrimitiveClass>();

            if (_useStrips)
            {
                //Remap points so there is only one id per individual point
                Remapper remapData = new Remapper();
                remapData.Remap <Facepoint>(points, null);

                //Set up tristripper with remapped point ids
                TriStripper stripper = new TriStripper(
                    remapData._remapTable.Select(x => (uint)x).ToArray(),
                    points.Select(x => x.NodeID).ToArray(),
                    remapData._impTable);
                stripper.SetCacheSize(_cacheSize);
                stripper.SetMinStripSize(_minStripLen);
                stripper.SetPushCacheHits(_pushCacheHits);

                //Backward search doesn't work,
                //but generally won't improve the optimization with the cache on anyway
                //stripper.SetBackwardSearch(_backwardSearch);

                //Create strips using ids
                List <Primitive> primArray = stripper.Strip();

                //Recollect facepoints with new indices and get point/face count
                for (int i = 0; i < primArray.Count; i++)
                {
                    Primitive p = primArray[i];
                    if (p.Type == PrimType.TriangleList)
                    {
                        int count = p.Indices.Count / 3;
                        faceCount += count;
                        for (int r = 0; r < count; r++)
                        {
                            fpPrimitives.Add(new PointTriangle(
                                                 points[remapData._impTable[p.Indices[r * 3 + 0]]],
                                                 points[remapData._impTable[p.Indices[r * 3 + 1]]],
                                                 points[remapData._impTable[p.Indices[r * 3 + 2]]]));
                        }
                    }
                    else
                    {
                        faceCount += p.Indices.Count - 2;
                        fpPrimitives.Add(new PointTriangleStrip()
                        {
                            _points = p.Indices.Select(x => points[remapData._impTable[x]]).ToList()
                        });
                    }
                    pointCount += p.Indices.Count;
                }
            }
            else
            {
                faceCount = (pointCount = points.Length) / 3;
                for (int r = 0; r < faceCount; r++)
                {
                    fpPrimitives.Add(new PointTriangle(
                                         points[r * 3 + 0],
                                         points[r * 3 + 1],
                                         points[r * 3 + 2]));
                }
            }

            //Group primitives by each point's influence id
            fpPrimitives.Sort(PrimitiveClass.Compare);
            List <PrimitiveGroup> groups = new List <PrimitiveGroup>();

            foreach (PrimitiveClass p in fpPrimitives)
            {
                bool added = false;
                foreach (PrimitiveGroup g in groups)
                {
                    if (added = g.TryAdd(p))
                    {
                        break;
                    }
                }
                if (!added)
                {
                    PrimitiveGroup g = new PrimitiveGroup();
                    g.TryAdd(p);
                    groups.Add(g);
                }
            }

            return(groups);
        }
Beispiel #27
0
    private void Update()
    {
        if (startRoutine != null)
        {
            return;
        }

        if (IsJumping || isFinished)
        {
            return;
        }

        if (currentSpeed > killSpeed)
        {
            manager.SwitchGameplay(GameState.LOST);
            rigid.velocity   = Vector3.zero;
            rigid.useGravity = false;
            return;
        }

        frameInput = Vector3.zero;

        float t        = Remapper.Remap(currentSpeed, minSpeed, maxSpeed, 0, 1);
        float handling = Mathf.Lerp(minHandling, maxHandling, handlingCurve.Evaluate(t));

        //Button Down Timer
        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            lastLeftDownTime = Time.time;
        }

        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            lastRightDownTime = Time.time;
        }

        //Left Right Movement
        if (metalBarRessource > 0.0f && (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)))
        {
            frameInput += Vector3.left * handling * Mathf.Lerp(1, 0, lastLeftDownTime / (Time.time * decreaseFactor));

            metalBarRessource -= Time.deltaTime * movementDecreaseFactor;

            currentCrowbarRot += Time.deltaTime * crowbarRotSpeed;
            currentCrowbarRot  = Mathf.Clamp(currentCrowbarRot, -30f, 30f);

            crowbar.localRotation = Quaternion.Euler(0f, 0f, currentCrowbarRot);
            playerVFX.crowbarSparksLeft.Play();
            playerVFX.crowbarSparksLeft.transform.rotation = Quaternion.Euler(0f, -90f, 0f);

            if (!steeringAudio.isPlaying)
            {
                Debug.Log("Audio");
                steeringAudio.Play();
            }
        }
        else if (metalBarRessource > 0.0f && (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)))
        {
            frameInput += Vector3.right * handling * Mathf.Lerp(1, 0, lastRightDownTime / (Time.time * decreaseFactor));

            metalBarRessource -= Time.deltaTime * movementDecreaseFactor;

            currentCrowbarRot -= Time.deltaTime * crowbarRotSpeed;
            currentCrowbarRot  = Mathf.Clamp(currentCrowbarRot, -30f, 30f);

            crowbar.localRotation = Quaternion.Euler(0f, 0f, currentCrowbarRot);
            playerVFX.crowbarSparksRight.Play();
            playerVFX.crowbarSparksRight.transform.rotation = Quaternion.Euler(0f, -270f, 0f);

            if (!steeringAudio.isPlaying)
            {
                Debug.Log("Audio");
                steeringAudio.Play();
            }
        }
        else
        {
            steeringAudio.Stop();

            if (currentCrowbarRot > 0)
            {
                currentCrowbarRot -= Time.deltaTime * crowbarRotSpeed * 2;
                currentCrowbarRot  = Mathf.Clamp(currentCrowbarRot, 0, 30f);

                crowbar.localRotation = Quaternion.Euler(0f, 0f, currentCrowbarRot);
            }
            else
            {
                currentCrowbarRot += Time.deltaTime * crowbarRotSpeed * 2;
                currentCrowbarRot  = Mathf.Clamp(currentCrowbarRot, -30f, 0);

                crowbar.localRotation = Quaternion.Euler(0f, 0f, currentCrowbarRot);
            }
        }

        //Speedbooster
        if (isOnSpeedbooster)
        {
            currentSpeed += Time.deltaTime / boostDiv;
        }


        //Braking or Acceleration
        if (metalBarRessource > 0.0f && (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)))
        {
            OnBrakeKey();
            lastBrakeTime = Time.time;

            currentSpeed      -= Time.deltaTime * breakMultiplier;
            metalBarRessource -= Time.deltaTime * breakDecreaseFactor;

            playerVFX.breakSparks.Play();
        }
        else
        {
            //When braking the acceleration is slowed for brakeGraceDuration
            if (lastBrakeTime + brakeGraceDuration > Time.time)
            {
                if (!breakAudio.isPlaying)
                {
                    breakAudio.Play();
                }

                currentSpeed += Time.deltaTime * brakeGraceModifier;
            }
            //Normal acceleration
            else
            {
                currentSpeed += Time.deltaTime / accelDiv;

                breakAudio.Stop();
            }
        }

        if (metalBarRessource > 0)
        {
            timer = 0;
            if (metalbarText.activeSelf)
            {
                metalbarText.SetActive(false);
            }
            float value = Remapper.Remap(metalBarRessource, 0, 1, 0, 0.8f);
            crowbarMat.SetFloat("_OpacityEmission", value);
        }
        else
        {
            timer += Time.deltaTime;
            if (timer % 1f < 0.5f)
            {
                metalbarText.SetActive(true);
            }
            else
            {
                metalbarText.SetActive(false);
            }
        }

        currentSpeed = Mathf.Clamp(currentSpeed, minSpeed, maxSpeed);

        rigid.velocity += frameInput;


        rigid.velocity = new Vector3(rigid.velocity.x, rigid.velocity.y, currentSpeed);

        //Press player down
        if (isOnSpeedbooster)
        {
            rigid.velocity += transform.up * -2f;
        }

        if (Vector3.Dot(Vector3.up, rigid.velocity.normalized) > 0f)
        {
            Debug.Log("Pushing Down");
            rigid.AddForce(transform.up * -1000f, ForceMode.Acceleration);
        }
    }