// external function to initiate the copying of data objects from one memory address to a destination. public void copyBytes(uint source, uint destination, memory destinationRegion, int count, Vector3 vertex, Color color, bool noFly) { //Debug.Log ("copyBytes from " + source.ToString ("x") + " to " + destination.ToString ("x") + " count "+count); /* * if(!inRange(source) || !destinationRegion.inRange(destination)){ * Debug.Log ("memory copyBytes address out of range "+source.ToString("x")+" to "+destination.ToString("x")); * //Debug.Break (); * return; * } */ if (!noFly) { startup.pauseLabel("Memory Copy"); startup.pause(false); } this.currentSource = source; this.currentDestination = destination; this.vertex = vertex; this.recentCubeScript = null; this.currentCount = count; this.origCount = count; this.currentColor = color; this.noFly = noFly; this.destinationRegion = destinationRegion; //Debug.Log ("copyBytes "+count+" to " + currentDestination.ToString ("x") + " of " + destinationRegion.name); //Debug.Log ("copyBytes currentCount " + this.currentCount); // If a quick copy, don't wait until next frame because we may be skipping animation. if (noFly) { Update(); } }
public void toXML(ref XmlDocument xmlDoc, ref XmlNode parent) { XmlNode memoryNode = xmlDoc.CreateElement("memory"); XmlNode nameNode = xmlDoc.CreateElement("name"); nameNode.InnerText = gameObject.name; memoryNode.AppendChild(nameNode); XmlNode protectedNode = xmlDoc.CreateElement("read_protected_data"); protectedNode.InnerText = readProtectedData.ToString(); memoryNode.AppendChild(protectedNode); XmlNode session1Color = xmlDoc.CreateElement("session1_color"); session1Color.InnerText = pipeBehavior.session1Color.ToString(); XmlNode session2Color = xmlDoc.CreateElement("session2_color"); session2Color.InnerText = pipeBehavior.session2Color.ToString(); memoryNode.AppendChild(session1Color); memoryNode.AppendChild(session2Color); for (int i = 0; i < cubes.Length; i++) { if (cubes[i] != null) { dataBehaviorNew script = (dataBehaviorNew)cubes[i].GetComponent(typeof(dataBehaviorNew)); script.toXML(ref xmlDoc, ref memoryNode, i); //Debug.Log ("memory toXML saved cube "+i); } } parent.AppendChild(memoryNode); }
private static void prebuildData(int count) { for (int i = 0; i < count; i++) { GameObject myData = Instantiate(Resources.Load("dataPrefab")) as GameObject; myData.SetActive(false); //myData.renderer.collider.enabled = false; dataBehaviorNew script = (dataBehaviorNew)myData.GetComponent(typeof(dataBehaviorNew)); script.enabled = false; availableData.Add(myData); } }
public static void freeData(GameObject data) { Destroy(data); return; data.SetActive(false); //data.renderer.collider.enabled = false; dataBehaviorNew script = (dataBehaviorNew)data.GetComponent(typeof(dataBehaviorNew)); script.reset(); script.enabled = false; availableData.Add(data); }
public int fromXML(XmlNode cubeNode) { XmlNode addressNode = cubeNode.SelectSingleNode("address"); address = uint.Parse(addressNode.InnerText, System.Globalization.NumberStyles.HexNumber); XmlNode colorNode = cubeNode.SelectSingleNode("color"); gameObject.renderer.material.color = myUtils.colorFromRGBA(colorNode.InnerText); XmlNode indexNode = cubeNode.SelectSingleNode("index"); int index = int.Parse(indexNode.InnerText); dataBehaviorNew thisScript = (dataBehaviorNew)gameObject.GetComponent(typeof(dataBehaviorNew)); thisScript.enabled = false; return(index); }
public void quickCopy(Vector3 destination, uint address) { if (destination == Vector3.zero) { memory.freeData(gameObject); } else { transform.position = destination; doneMoving = true; this.address = address; dataBehaviorNew thisScript = (dataBehaviorNew)gameObject.GetComponent(typeof(dataBehaviorNew)); thisScript.enabled = false; } }
public void fromXml(XmlDocument xmlDoc) { clearCubes(); XmlNode memoryNode = xmlDoc.SelectSingleNode("//bookmark/memory"); XmlNode nameNode = memoryNode.SelectSingleNode("name"); gameObject.name = nameNode.InnerText; XmlNode protectedNode = memoryNode.SelectSingleNode("read_protected_data"); if (protectedNode != null) { readProtectedData = bool.Parse(protectedNode.InnerText); } Color s1 = pipeBehavior.session1Color; Color s2 = pipeBehavior.session2Color; XmlNode session1Color = memoryNode.SelectSingleNode("session1_color"); if (session1Color != null) { s1 = myUtils.colorFromRGBA(session1Color.InnerText); XmlNode session2Color = memoryNode.SelectSingleNode("session2_color"); s2 = myUtils.colorFromRGBA(session2Color.InnerText); } XmlNodeList cubeNodes = memoryNode.SelectNodes("cube"); //Debug.Log ("memory fromXML # cubes is " + cubeNodes.Count); for (int i = 0; i < cubeNodes.Count; i++) { GameObject myData = getFreeData(); //GameObject myData = Instantiate (Resources.Load ("dataPrefab")) as GameObject; dataBehaviorNew script = (dataBehaviorNew)myData.GetComponent(typeof(dataBehaviorNew)); int index = script.fromXML(cubeNodes[i]); script.enabled = false; //myData.collider.enabled = false; //myData.collider2D.enabled = false; Vector3 pos = this.getAddressLocation(script.address); myData.transform.position = pos; //Debug.Log ("memory fromXML loaded cube "+index); cubes[index] = myData; } if (session1Color != null) { setCubeColor(s1, pipeBehavior.session1Color); setCubeColor(s2, pipeBehavior.session2Color); } }
public static GameObject getFreeData() { if (availableData.Count == 0) { //prebuildData(10000); GameObject myData = Instantiate(Resources.Load("dataPrefab")) as GameObject; return(myData); } GameObject go = availableData[availableData.Count - 1]; availableData.RemoveAt(availableData.Count - 1); go.SetActive(true); //go.renderer.collider.enabled = false; dataBehaviorNew script = (dataBehaviorNew)go.GetComponent(typeof(dataBehaviorNew)); script.enabled = true; return(go); }
// look for keyboard shortcuts and clicking of objects bool checkKeys() { bool retval = true; if (menus.clicked != "") { return(true); } if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftAlt)) { // User clicked button (but not while naviaging via alt key //Debug.Log("clicked in checkKyes"); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (Input.GetKey(KeyCode.LeftShift)) { // user seeks information about an object functionBehaive funScript = (functionBehaive)hit.transform.gameObject.GetComponent(typeof(functionBehaive)); if (funScript != null) { funScript.showSummary(false, false); } else { Debug.Log("perhaps hit data? " + hit.transform.gameObject.name); dataBehaviorNew dataScript = (dataBehaviorNew)hit.transform.gameObject.GetComponent(typeof(dataBehaviorNew)); if (dataScript != null) { dataScript.showSummary(); addressLabel = "address: 0x" + dataScript.address.ToString("x"); } } } else { // if function is clicked, zoom to it. Debug.Log("HIT SOMETHING " + hit.transform.gameObject.name); functionBehaive funScript = (functionBehaive)hit.transform.gameObject.GetComponent(typeof(functionBehaive)); if (funScript != null) { cameraScript.setObject(funScript.function.getPosition()); } } } } else if (Input.GetMouseButtonUp(0)) { addressLabel = ""; } else if (Input.GetKeyDown("space")) { doUserPause(); //print("space key was pressed"); //}else if (Input.GetKeyDown("escape")){ // //print("escape key was pressed"); // helpString = null; // //cameraScript.restore(); // setCamera(); } else if (Input.GetKeyDown("w") && Input.GetKey(KeyCode.LeftShift)) { cameraScript.moveZ(1); } else if (Input.GetKeyDown("s") && Input.GetKey(KeyCode.LeftShift)) { cameraScript.moveZ(-1); } else if (Input.GetKeyDown("w")) { cameraScript.moveY(1); } else if (Input.GetKeyDown("s")) { cameraScript.moveY(-1); } else if (Input.GetKeyDown("a")) { cameraScript.moveX(1); } else if (Input.GetKeyDown("d")) { cameraScript.moveX(-1); // }else if (Input.GetKeyDown("r") && (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift))){ } else if (Input.GetKeyDown("r") && (Input.GetKey(KeyCode.LeftShift))) { if (!justShowData) { justShowData = true; skipToData = true; pauseLabelString = "skipping"; } else { justShowData = false; } } else if (Input.GetKeyDown("f")) { manageControl.follow(!manageControl.following()); } else if (Input.GetKeyDown("r")) { if (isPlaying) { skipToData = true; pauseLabelString = "skipping"; //Debug.Log("Skip to data at clock "+currentClock); } } else if (Input.GetKeyDown("h")) { setCamera(); } else if (Input.GetKeyDown("i")) { if (!skipToNetwork) { justShowData = true; skipToData = true; pauseLabelString = "skipping"; } else { justShowData = false; skipToData = false; if (!userPause) { pauseLabelString = "play"; } } skipToNetwork = !skipToNetwork; } else if (Input.GetKeyDown("b")) { pause(true); userStackFrame = manageControl.callStack.Count - 1; functionDatabase.functionItem fi = manageControl.currentFunction; cameraScript.setObject(fi.getPosition()); if (functionLabels) { fi.script.showSummary(true, true); } } else if (Input.GetKeyDown("n") && (Input.GetKey(KeyCode.LeftShift))) { if (userStackFrame < manageControl.callStack.Count - 1) { functionDatabase.functionItem fi = manageControl.callStack[userStackFrame]; cameraScript.setObject(fi.getPosition()); userStackFrame++; if (functionLabels) { fi.script.showSummary(true, true); } } } else if (Input.GetKeyDown("n")) { if (userStackFrame >= 0) { functionDatabase.functionItem fi = manageControl.callStack[userStackFrame]; cameraScript.setObject(fi.getPosition()); if (userStackFrame > 0) { userStackFrame--; } if (functionLabels) { fi.script.showSummary(true, true); } } } else if (Input.GetKeyDown("m")) { pause(true); menus.clicked = "create bookmark"; //createBookmark(); } else if (Input.GetKeyDown("l")) { pause(true); menus.clicked = "goto bookmark"; } else { retval = false; } return(retval); }
// Animate the fllight of this data object void Update() { //Debug.Log ("moving"); if (doneMoving) { return; } float now = Time.time; float distCovered = (now - startTime) * this.markers[startMark].speed; float fracJourney = distCovered / journeyLength; if (fracJourney < 1.0) { //Debug.Log ("speed "+speed+" dist covered is "+distCovered+" len is "+journeyLength+" now is " + Time.time + " frac is " + fracJourney); transform.position = Vector3.Lerp(this.markers[startMark].point, this.markers[endMark].point, fracJourney); } else if (this.endMark < this.markers.Length - 1) { this.startMark++; this.endMark++; if (this.markers[startMark].doScale) { Vector3 scale = origScale; scale.x = scale.x * this.markers[startMark].scale.x; scale.y = scale.y * this.markers[startMark].scale.y; scale.z = scale.z * this.markers[startMark].scale.z; transform.localScale = scale; } float randOffset = Random.Range(0, 0.1F); this.journeyLength = Vector3.Distance(this.markers[startMark].point, this.markers[endMark].point); this.startTime = Time.time; if (startMark == changeAt) { renderer.material.color = changeTo; } //Debug.Log ("data, my 3rd pt is "+this.thirdMarker); } else { doneMoving = true; transform.position = this.markers[this.markers.Length - 1].point; transform.localScale = origScale; if (this.caboose) { //Debug.Log ("CABOOOOOOOOOSE"); startup.resume(); } if (this.destroy) { //Destroy(gameObject, 0.1F); memory.freeData(gameObject); } if (this.replace) { memory.freeData(this.replace); this.replace = null; } dataBehaviorNew thisScript = (dataBehaviorNew)gameObject.GetComponent(typeof(dataBehaviorNew)); thisScript.enabled = false; } }
// 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++; } }