Exemplo n.º 1
0
        public RandomlyInterspersedBitstream(ICsBitStream bitStream1, ICsBitStream bitStream2, float secondStreamProportion, int seed = 1745)
        {
            BitStream1             = bitStream1;
            BitStream2             = bitStream2;
            SecondStreamProportion = secondStreamProportion;

            ByteSwitcher = new System.Random(seed);
        }
Exemplo n.º 2
0
        public ChallengeSetVisualizer ConstructCsViewStep1(
            ICsBitStream significant,
            ICsBitStream insignificant,
            int fileSize,
            float sizeOffset)
        {
            var newCsView = VisualizerFactory.InstantiateChallengeSetVisualizer();

            newCsView.DetailMaterial = GameObject.Instantiate(newCsView.DetailMaterial);

            var nComponents = ComputeNumberOfComponents(significant, insignificant, fileSize);

            var outgoingComponentStack = new SortedList <float, Transform>(new DuplicateKeyComparer <float>());

            outgoingComponentStack.Add(1, newCsView.transform);

            float componentImpactMult = 1f;

            newCsView.Components = new List <CsViewComponent>();

            int i = 0;

            do
            {
                var parent = outgoingComponentStack.Values.Last();
                outgoingComponentStack.RemoveAt(outgoingComponentStack.Count - 1);

                // construct component
                var newComponent = GenerateComponent(significant, insignificant, parent, sizeOffset,
                                                     i > 0);

                // assign material
                foreach (var rend in newComponent.GetComponentsInChildren <Renderer>())
                {
                    rend.material = newCsView.DetailMaterial;
                }

                // iterate through other potential components using the stack
                GenerateOutgoingPriorities(significant, insignificant, newComponent,
                                           ref outgoingComponentStack, componentImpactMult);

                componentImpactMult *= .8f;

                newCsView.Components.Add(newComponent);

                newCsView.EncapsulatePoint(newComponent.transform.position);  //+Vector3.one/2f);
                //newCsView.ComponentBounds.Encapsulate( newComponent.transform.position );
                //new UnityEngine.Bounds(newComponent.transform.position, Vector3.one) );

                i++;
            } while (i < nComponents);

            newCsView.Components.First().transform.position -= (newCsView.ComponentBoundMax + newCsView.ComponentBoundMin) / 2f;

            //newCsView.Components.First().transform.localPosition -= .5f*(newCsView.ComponentBoundMax - newCsView.ComponentBoundMin);

            return(newCsView);
        }
Exemplo n.º 3
0
        public static float ReadFloat(this ICsBitStream bitstream)
        {
            float[] floatTarget = new float[1];

            var bitData = bitstream.ReadBits(32).ToArray();

            var byteData = new byte[4];

            for (int i = 0; i < 4; i++)
            {
                int byteValue = 0;
                for (int b = 0; b < 8; b++)
                {
                    byteValue = (byteValue << 1) + (bitData[i * 8 + b]?1:0);
                }
                byteData[i] = (byte)byteValue;
            }

            Buffer.BlockCopy(byteData, 0, floatTarget, 0, 4);

            return(floatTarget[0]);
        }
Exemplo n.º 4
0
        private CsViewComponent GenerateComponent(ICsBitStream significant, ICsBitStream insignificant, Transform parent, float sizeOffset,
                                                  bool generatePillar = true)
        {
            int componentTypeIndex = significant.ReadInt(8)
                                     % ViewComponents.Count;

            if (ViewComponents.Count < componentTypeIndex)
            {
                throw new Exception("Index " + componentTypeIndex + " is not covered by a cs view component!");
            }

            var newComponent = GameObject.Instantiate(ViewComponents[componentTypeIndex].gameObject);

            newComponent.transform.parent        = parent;
            newComponent.transform.localScale    = Vector3.one;
            newComponent.transform.localRotation = Quaternion.identity;
            newComponent.transform.localPosition = Vector3.zero + Vector3.up * sizeOffset;

            var csComponent = newComponent.GetComponent <CsViewComponent>();

            // rotate component
            var rotationMult = insignificant.ReadInt(3)
                               * 360f / 8f;

            newComponent.transform.Rotate(Vector3.up, rotationMult, Space.Self);

            if (generatePillar)
            {
                // construct pillar
                var pillar = GameObject.Instantiate(PillarPrefab);
                pillar.transform.parent        = parent;
                pillar.transform.localScale    = new Vector3(1, sizeOffset * 5f, 1f);
                pillar.transform.localRotation = Quaternion.identity;
                pillar.transform.localPosition = Vector3.up * sizeOffset / 2f;
            }

            return(csComponent);
        }
Exemplo n.º 5
0
        private void GenerateOutgoingPriorities(ICsBitStream significant, ICsBitStream insignificant,
                                                CsViewComponent component, ref SortedList <float, Transform> potentialSites,
                                                float componentImpactMultiplier = 1f)
        {
            var criticalData = significant.ReadBits(16).ToList();

            var bitSums = new int[3];

            bitSums[0] = SumNthBits(criticalData, 2, 1);
            bitSums[1] = SumNthBits(criticalData, 2, 0);
            bitSums[2] = SumNthBits(criticalData, 3, 1);

            var cosums = new float[3];

            cosums[0] = (bitSums[0] * .76f + 2.1f) * componentImpactMultiplier;
            cosums[1] = (bitSums[1] * .35f + .1f) * componentImpactMultiplier;
            cosums[2] = (bitSums[2] * .24f + .1f) * componentImpactMultiplier;

            for (int i = 0; i < 3; i++)
            {
                potentialSites.Add(cosums[i], component.ConnectionBones[i]);
            }
        }
Exemplo n.º 6
0
 private int ComputeNumberOfComponents(ICsBitStream significant, ICsBitStream insignificant, int filesize)
 {
     return(Mathf.Max(Mathf.FloorToInt(Mathf.Log(filesize - 6000, 1.7f)) - 10, 3));
 }
Exemplo n.º 7
0
 public static int ReadInt(this ICsBitStream bitstream, int bitsToRead = 32)
 {
     return(BoolListToInt(bitstream.ReadBits(bitsToRead)));
 }