示例#1
0
    // Update is called once per frame.  Manage memory copy operations.
    void Update()
    {
        if (waitForUnpause)
        {
            if (!startup.userPause)
            {
                waitForUnpause = false;
            }
            else
            {
                //Debug.Log ("wait for unpause, returing");
                return;
            }
        }
        Color color;
        int   bundle = 0;

        // bundle some number of data objects into a single frame
        while (this.currentCount > 0 && bundle < dataBehaviorNew.reduce)
        {
            bool done = false;
            while (!done)
            {
                GameObject cube = getCube(this.currentSource);
                if (cube != null)
                {
                    color = cube.renderer.material.color;
                    if (protectedReadBreak && color != pipeBehavior.getPipeColor() && !readProtectedData)
                    {
                        Debug.Log("Read of protected data");
                        startup.doUserPause();
                        startup.pauseLabelString     = "Protected Data Read";
                        readProtectedData            = true;
                        waitForUnpause               = true;
                        cube.renderer.material.color = Color.black;
                    }
                }
                else
                {
                    //Debug.Log ("move update no cube at currentSource "+this.currentSource.ToString("x"));
                    color = this.currentColor;
                    //done = true;
                }
                // is the data move's destination going to overwrite existing data?
                GameObject replace     = this.destinationRegion.getCube(this.currentDestination);
                Vector3    destination = this.destinationRegion.getAddressLocation(this.currentDestination);
                Vector3    source      = getAddressLocation(this.currentSource);
                float      randY       = Random.Range(0, 2);
                source.y = source.y + randY;
                GameObject myData = getFreeData();
                myData.renderer.material.color = color;
                myData.transform.position      = source;
                dataBehaviorNew           script    = (dataBehaviorNew)myData.GetComponent(typeof(dataBehaviorNew));
                dataBehaviorNew.FlyType[] flyPoints = new dataBehaviorNew.FlyType[3];
                float speed = 30f;
                flyPoints[0] = new dataBehaviorNew.FlyType(source, speed, false, Vector3.zero);
                flyPoints[1] = new dataBehaviorNew.FlyType(vertex, speed, false, Vector3.zero);
                flyPoints[2] = new dataBehaviorNew.FlyType(destination, speed, false, Vector3.zero);
                bool caboose = (this.currentCount <= bytesPerCube);
                // save time by instantly handling small moves.  TBD, move to configuration data
                if (origCount > 10 && !noFly)
                {
                    script.flyTo(flyPoints, caboose, false, false, replace, (uint)(this.currentDestination + bundle), -1, Color.clear, 3.0f);
                }
                else
                {
                    //Debug.Log ("small move, just put cube, destination "+destination);
                    if (replace != null)
                    {
                        freeData(replace);
                    }
                    script.quickCopy(destination, this.currentDestination);
                }
                if (!this.destinationRegion.putCube(this.currentDestination, myData))
                {
                    Debug.Log("failed putting cube to destination " + this.currentDestination.ToString("x"));
                    Debug.Break();
                    return;
                }
                //Debug.Log ("memory update put cube to "+this.currentDestination.ToString("x"));
                recentCubeScript = script;
                if (!noFly)
                {
                    done = true;
                }
                this.currentSource      = this.currentSource + (uint)bytesPerCube;
                this.currentDestination = this.currentDestination + (uint)bytesPerCube;
                this.currentCount       = this.currentCount - bytesPerCube;
                // if this is the last data object in a copy, set the caboose flag to unpause
                // upon completion of the copy.
                if (this.currentCount <= 0)
                {
                    if (!noFly)
                    {
                        if (recentCubeScript != null)
                        {
                            recentCubeScript.setCaboose();
                        }
                        else
                        {
                            startup.resume();
                        }
                    }
                    done = true;
                }
                bundle++;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (this.skipFrames > 0)
        {
            skipFrames--;
            return;
        }
        int bundle = 0;

        //if(this.currentCount > 0){
        while (this.currentCount > 0 && bundle < dataBehaviorNew.reduce)
        {
            Vector3    destination = Vector3.zero;
            GameObject replace     = null;
            if (memoryScript)
            {
                destination = memoryScript.getAddressLocation(this.currentAddr);
                replace     = memoryScript.getCube(this.currentAddr);
            }
            //Debug.Log("pipe destination for address "+currentAddr.ToString("x")+" is "+destination);
            // NOTE on writes, source is actually the distination pipe
            Vector3 source = pipe.transform.position;
            float   radius = 0.5F;
            float   left   = source.x - radius;
            float   right  = source.x + radius;
            float   newx   = Random.Range(left, right);
            float   top    = source.z - radius;
            float   bot    = source.z + radius;
            float   newz   = Random.Range(top, bot);
            float   starty = Random.Range(0, 2.0F);
            float   speed  = 30.0f;
            dataBehaviorNew.FlyType[] flyPoints = new dataBehaviorNew.FlyType[5];
            // randDsource is destination if a write
            Vector3    randSource = new Vector3(newx, source.y + starty, newz);
            GameObject myData;
            myData = memory.getFreeData();
            //myData = Instantiate (Resources.Load ("dataPrefab")) as GameObject;
            myData.renderer.material.color = getPipeColor();
            dataBehaviorNew script      = (dataBehaviorNew)myData.GetComponent(typeof(dataBehaviorNew));
            bool            destroyCube = false;
            bool            caboose     = false;
            if (memoryScript)
            {
                caboose = (this.currentCount <= memoryScript.bytesPerCube);
            }
            else
            {
                caboose     = (this.currentCount <= baseBytesPerCube);
                destroyCube = true;
            }
            bool    leader    = false;
            int     changeAt  = -1;
            Color   changeTo  = Color.black;
            Vector3 dataScale = new Vector3(4.0f, 4.0f, 4.0f);
            if (this.reading)
            {
                changeAt = 1;
                changeTo = getPipeColor();
                //myData.renderer.material.color = getPipeColor();
                myData.renderer.material.color = getRemoteColor();
                flyPoints[0] = new dataBehaviorNew.FlyType(getRemoteTeam(), speed * 1.2f, true, dataScale);
                flyPoints[1] = new dataBehaviorNew.FlyType(transform.position, speed * 1.8f, true, dataScale);
                flyPoints[2] = new dataBehaviorNew.FlyType(getLocalEndpoint(), speed, false, Vector3.zero);
                //flyPoints[0] = new dataBehaviorNew.FlyType(randSource, speed, false, Vector3.zero);
                flyPoints[3] = new dataBehaviorNew.FlyType(vertex, speed, false, Vector3.zero);
                flyPoints[4] = new dataBehaviorNew.FlyType(destination, speed, false, Vector3.zero);
                script.flyTo(flyPoints, caboose, false, destroyCube, replace, (uint)(this.currentAddr + bundle), changeAt, changeTo, 1.0f);
                if (memoryScript)
                {
                    if (!memoryScript.putCube(this.currentAddr, myData))
                    {
                        Debug.Log("pipeBehavior could not put cube in region for address " + this.currentAddr.ToString("x"));
                    }
                }
                else
                {
                    Debug.Log("pipeBehavior no memory region to put cube for " + this.currentAddr.ToString("x"));
                }
            }
            else
            {
                //Debug.Log ("writing to network in session "+sessionNumber);
                // writing AGAIN: source and destination are reversed
                Material m;
                m = myData.renderer.material;
                if (replace != null)
                {
                    //Debug.Log ("assigning write color to that of replace, which was "+replace.renderer.material.color);
                    m.color = replace.renderer.material.color;
                }
                else
                {
                    Debug.Log("Writing from empty memory!!");
                    m.color = getPipeColor();
                }
                //float randY = Random.Range (0, 2);
                //destination.y = destination.y + randY;
                myData.transform.position = destination;
                flyPoints[0] = new dataBehaviorNew.FlyType(destination, speed, true, dataScale);
                flyPoints[1] = new dataBehaviorNew.FlyType(vertex, speed, false, Vector3.zero);
                //flyPoints[2] = new dataBehaviorNew.FlyType(randSource, speed, false, Vector3.zero);
                flyPoints[2] = new dataBehaviorNew.FlyType(getLocalEndpoint(), speed, false, Vector3.zero);
                flyPoints[3] = new dataBehaviorNew.FlyType(transform.position, speed, false, Vector3.zero);
                flyPoints[4] = new dataBehaviorNew.FlyType(getRemoteTeam(), speed, false, Vector3.zero);
                script.flyTo(flyPoints, caboose, leader, true, null, (uint)(this.currentAddr + bundle), changeAt, changeTo, 1.0f);
            }
            if (memoryScript)
            {
                this.currentAddr  = this.currentAddr + (uint)memoryScript.bytesPerCube;
                this.currentCount = this.currentCount - memoryScript.bytesPerCube;
            }
            else
            {
                this.currentCount -= baseBytesPerCube;
            }
            bundle++;
        }
    }