private Node GetNodeFromNodeClusterAndLocation(Vector3 newLocation, NodeCluster newCluster, bool onlyAvailableNodes = false) { Vector3 startLocation = newCluster.gridCoordinates; Vector3 endLocation = newCluster.gridCoordinates + new Vector3(newCluster.clusterSize, newCluster.clusterSize, newCluster.clusterSize); Node closestNode = null; Grid newGrid = newCluster.mainAbstractGrid.mainGrid; float closestDist = 100000000; for (int i = (int)startLocation.x; i < endLocation.x; i++) { for (int j = (int)startLocation.z; j < endLocation.z; j++) { Node tempNode = newGrid.LookUpNode(i, j); if (onlyAvailableNodes) { if (!tempNode.available) { continue; } } float tempDist = Vector3.Distance(newLocation, tempNode.sphereCoordinates); if (tempDist < closestDist) { closestDist = tempDist; closestNode = tempNode; } } } return(closestNode); }
public void RemoveNode(Node newNode) { //Only Remove if Node is NOT ABSTRACT if (newNode.IsTemporary()) { NodeCluster newCluster = newNode.clusterParent; ManageAbstractNodeList(newNode, false); for (int i = 0; i < newCluster.nodeList.Count; i++) { Node removeNode = null; for (int j = 0; j < newCluster.nodeList[i].neighbors.Count; j++) { if (newCluster.nodeList[i].neighbors[j] == newNode) { removeNode = newNode; } } if (removeNode != null) { newCluster.nodeList[i].neighbors.Remove(removeNode); } } newCluster.ManageAbstractNodes(newNode, false); newCluster.SetAbstractConnections(); } }
public Node GetClosestNode(Vector3 newLocation, bool onlyAvailableNodes = false) { Grid newGrid = GetGridFromLocation(newLocation);//GetGridFrontLocationOnSphere(newLocation); NodeCluster newCluster = GetNodeClusterFromGridAndLocation(newLocation, newGrid); Node newNode = GetNodeFromNodeClusterAndLocation(newLocation, newCluster, onlyAvailableNodes); return(newNode); }
private void SpawnZ(int newX, int newZ) { NodeCluster newNodeCluster = new NodeCluster(this, clusterSize, newX, newZ); int nodeClusterKey = GetNodeClusterKey(newNodeCluster.xVal, newNodeCluster.zVal); nodeClusterDictionary.Add(nodeClusterKey, newNodeCluster); nodeClusterCounter++; }
private void SpawnZ(int newX, int newZ) { Vector3 newLocation = new Vector3(newX, 0, newZ); Node newNode = mainGrid.nodeDictionary[newLocation]; NodeCluster newNodeCluster = new NodeCluster(this, clusterSize, newNode.gridCoordinates, newNode.cubeCoordinates, newNode.sphereCoordinates); nodeClusterDictionary.Add(newLocation, newNodeCluster); nodeClusterCounter++; }
/* * ============================================================= * Manages Inserted Nodes * ============================================================= */ public Node InsertNode(Node refNode) { NodeCluster newCluster = refNode.clusterParent != null ? refNode.clusterParent : GetNodeClusterFromLocation((int)refNode.xVal, (int)refNode.zVal); Node newNode = new Node(this.mainGrid, refNode.gridCoordinates, NodeType.Temporary, -1); newNode.SetClusterParent(newCluster); ManageAbstractNodeList(newNode); newCluster.ManageAbstractNodes(newNode); newCluster.SetAbstractConnections(); return(newNode); }
static async Task Main(string[] args) { string url = "chains/main/blocks/head/header"; List <string> urls = new List <string>() { "https://rpc.tzkt.io/mainnet/", "https://mainnet-tezos.giganode.io/", "https://mainnet.smartpy.io/" }; string i = null; while (Convert.ToInt16(i) != 2) { Console.WriteLine("Добавить url?"); i = Console.ReadLine(); if (Convert.ToInt16(i) != 2) { string new_base_url = Console.ReadLine(); urls.Add(new_base_url); } else { break; } } NodeCluster nodeCluster = new NodeCluster(urls); Head LatestHead = new Head(); Task task = Task.Factory.StartNew(async() => LatestHead = await nodeCluster.GetLatestHead(url)); task.Wait(); // LatestHead = await Task.Run<Head>(() => nodeCluster.GetLatestHead(url)); Thread.Sleep(5000); Task task_return = Task.Factory.StartNew(() => { Console.WriteLine($"Head.Url: {LatestHead.Url}"); Console.WriteLine($"Head.ChainId: {LatestHead.Chain_id}"); Console.WriteLine($"Head.Hash: {LatestHead.Hash}"); Console.WriteLine($"Head.Predecessor: {LatestHead.Predecessor}"); Console.WriteLine($"Head.Level: {LatestHead.Level}"); Console.WriteLine($"Head.Timestamp: {LatestHead.Timestamp}"); }); task_return.Wait(); // await Task.WhenAll(new[] { task, task_return }); }
private NodeCluster GetNodeClusterFromGridAndLocation(Vector3 newLocation, Grid newGrid) { NodeCluster closestCluster = null; float closestDist = 1000000; foreach (NodeCluster newCluster in newGrid.abstractGrid.nodeClusterDictionary.Values) { float tempDist = Vector3.Distance(newLocation, newCluster.centerSphereCoordinates); if (tempDist < closestDist) { closestDist = tempDist; closestCluster = newCluster; } } return(closestCluster); }
private void SpawnX(int newX) { int tempZ = (int)mainGrid.transform.position.z; NodeCluster newNodeCluster = new NodeCluster(this, clusterSize, newX, tempZ); int nodeClusterKey = GetNodeClusterKey(newNodeCluster.xVal, newNodeCluster.zVal); nodeClusterDictionary.Add(nodeClusterKey, newNodeCluster); nodeClusterCounter++; int newZ = tempZ + clusterSize; for (int i = 0; i < abstractGridSize - 1; ++i) { SpawnZ(newX, newZ); newZ += clusterSize; } }
private void SpawnX(int newX) { int tempZ = 0;// (int)mainGrid.transform.position.z; Vector3 newLocation = new Vector3(newX, 0, tempZ); Node newNode = mainGrid.nodeDictionary[newLocation]; NodeCluster newNodeCluster = new NodeCluster(this, clusterSize, newNode.gridCoordinates, newNode.cubeCoordinates, newNode.sphereCoordinates); nodeClusterDictionary.Add(newLocation, newNodeCluster); nodeClusterCounter++; int newZ = tempZ + clusterSize; for (int i = 0; i < abstractGridSize - 1; ++i) { SpawnZ(newX, newZ); newZ += clusterSize; } }
private void BeginLevel() { //Create Player Base Node newNode = mainGrid.gridDictionary[Orientation.Front].LookUpNode(25, 25); NodeCluster newCluster = newNode.clusterParent; Building p1Base = SpawnBuilding(newCluster, BuildingType.Base); p1Base.Initialize(player01, BuildingType.Base); p1BaseHealth = p1Base.gameObject.GetComponent <Health>(); player01.Initialize(newNode); //Create Enemy Base newNode = mainGrid.gridDictionary[Orientation.Back].LookUpNode(25, 25); newCluster = newNode.clusterParent; Building p2Base = SpawnBuilding(newCluster, BuildingType.Base); p2Base.Initialize(player02, BuildingType.Base); p2BaseHealth = p2Base.gameObject.GetComponent <Health>(); player02.Initialize(newNode); }
private void MoveTemporaryBuilding() { //Placing Building NodeCluster newCluster = mainGrid.GetClosestNode(targetPoint).clusterParent; if (newCluster.centerNode.available) { placingBuilding.transform.position = newCluster.centerNode.GetLocation(); Vector3 upVector = targetPoint - LevelManager.PLANET_CENTER; placingBuilding.transform.up = upVector; if (Input.GetMouseButtonDown(0)) { Building newBuilding = mainLevelManager.SpawnBuilding(newCluster, BuildingType.Shield); newBuilding.Initialize(this, BuildingType.Shield); Destroy(placingBuilding); placingBuilding = null; } } }
public Building SpawnBuilding(NodeCluster newCluster, BuildingType type) { Node newNode = newCluster.centerNode; int range = 3; for (int j = (int)newNode.gridCoordinates.x - range; j <= newNode.gridCoordinates.x + range; j++) { for (int k = (int)newNode.gridCoordinates.z - range; k <= newNode.gridCoordinates.z + range; k++) { Node currentNode = newNode.gridParent.LookUpNode(j, k); currentNode.ToggleAvailable(false); newCluster.RefreshPaths(); } } GameObject buildingPrefab = (type == BuildingType.Base) ? basePrefab : shieldPrefab; GameObject newBuildingPrefab = Instantiate(buildingPrefab, newNode.sphereCoordinates, Quaternion.identity) as GameObject; Vector3 lookVector = (newNode.GetLocation()-PLANET_CENTER); newBuildingPrefab.transform.up = lookVector; Building buildingComponent = newBuildingPrefab.GetComponent<Building>(); return buildingComponent; }
public void SetClusterParents(Dictionary <Vector3, Node> nodeDictionary) { foreach (Node newNode in nodeDictionary.Values) { int minX = 0; // (int)mainGrid.transform.position.x; int minZ = 0; // (int)mainGrid.transform.position.z; Vector2 currentMin = new Vector2(minX, minZ); Vector2 currentMax = new Vector2(minX + (clusterSize - 1), minZ + (clusterSize - 1)); bool clusterFound = false; for (int i = 0; i < mainGrid.gridSize / clusterSize; i++) { currentMin.x = minX + (clusterSize * i); currentMax.x = currentMin.x + (clusterSize - 1); for (int j = 0; j < mainGrid.gridSize / clusterSize; j++) { currentMin.y = minZ + (clusterSize * j); currentMax.y = currentMin.y + (clusterSize - 1); if (newNode.xVal >= currentMin.x && newNode.xVal <= currentMax.x && newNode.zVal >= currentMin.y && newNode.zVal <= currentMax.y) { clusterFound = true; break; } } if (clusterFound) { break; } } if (clusterFound) { NodeCluster newCluster = LookUpNodeCluster((int)currentMin.x, (int)currentMin.y); newNode.SetClusterParent(newCluster); } } }
public Building SpawnBuilding(NodeCluster newCluster, BuildingType type) { Node newNode = newCluster.centerNode; int range = 3; for (int j = (int)newNode.gridCoordinates.x - range; j <= newNode.gridCoordinates.x + range; j++) { for (int k = (int)newNode.gridCoordinates.z - range; k <= newNode.gridCoordinates.z + range; k++) { Node currentNode = newNode.gridParent.LookUpNode(j, k); currentNode.ToggleAvailable(false); newCluster.RefreshPaths(); } } GameObject buildingPrefab = (type == BuildingType.Base) ? basePrefab : shieldPrefab; GameObject newBuildingPrefab = Instantiate(buildingPrefab, newNode.sphereCoordinates, Quaternion.identity) as GameObject; Vector3 lookVector = (newNode.GetLocation() - PLANET_CENTER); newBuildingPrefab.transform.up = lookVector; Building buildingComponent = newBuildingPrefab.GetComponent <Building>(); return(buildingComponent); }
private Node GetNodeFromNodeClusterAndLocation(Vector3 newLocation, NodeCluster newCluster) { Vector3 startLocation = newCluster.gridCoordinates; Vector3 endLocation = newCluster.gridCoordinates + new Vector3(newCluster.clusterSize, newCluster.clusterSize, newCluster.clusterSize); Node closestNode = null; Grid newGrid = newCluster.mainAbstractGrid.mainGrid; float closestDist = 100000000; for (int i = (int)startLocation.x; i < endLocation.x; i++) { for (int j = (int)startLocation.z; j < endLocation.z; j++) { Node tempNode = newGrid.LookUpNode(i, j); float tempDist = Vector3.Distance(newLocation, tempNode.sphereCoordinates); if (tempDist < closestDist) { closestDist = tempDist; closestNode = tempNode; } } } return closestNode; }
static void Main(string[] args) { Console.Title = "Node"; var configBuilder = new ClusterConfigBuilder(); var seeds = "0.0.0.0:7001,0.0.0.0:7002"; var clusterEvents = new Subject <Shared.Messages.ClusterEvent>(); var cache = new AssetsCache(); clusterEvents.Subscribe((m) => { Console.WriteLine($"1\t{m.Type.ToString()}\t{m.NodeId}"); if (m.Type == ClusterEventType.Up) { cache.SetNodeId(m.NodeId); } else if (m.Type == ClusterEventType.MemberUp) { cache.AddNode(m.NodeId); } else if (m.Type == ClusterEventType.MemberDown) { cache.RemoveNode(m.NodeId); } else if (m.Type == ClusterEventType.SeedDown) { cache.Stop(); } }); var cluster = new NodeCluster(clusterEvents, configBuilder.Build(Roles.Node, 6001, seeds)); var clusterEvents2 = new Subject <Shared.Messages.ClusterEvent>(); var cache2 = new AssetsCache(); clusterEvents2.Subscribe((m) => { Console.WriteLine($"2\t{m.Type.ToString()}\t{m.NodeId}"); if (m.Type == ClusterEventType.Up) { cache2.SetNodeId(m.NodeId); } else if (m.Type == ClusterEventType.MemberUp) { cache2.AddNode(m.NodeId); } else if (m.Type == ClusterEventType.MemberDown) { cache2.RemoveNode(m.NodeId); } else if (m.Type == ClusterEventType.SeedDown) { cache2.Stop(); } }); var cluster2 = new NodeCluster(clusterEvents2, configBuilder.Build(Roles.Node, 6002, seeds)); cluster.Start(); var firstStarted = true; cluster2.Start(); var secondStarted = true; Console.WriteLine("Press 0 to exit"); Console.WriteLine("Press 1 to start\\stop first node"); Console.WriteLine("Press 2 to start\\stop first node"); Console.WriteLine("Press a to print first cache"); Console.WriteLine("Press b to print second cache"); while (true) { var num = Console.ReadKey(); var exit = false; switch (num.KeyChar) { case '1': if (firstStarted) { cluster.Stop(); firstStarted = false; Console.WriteLine("\tEND"); cache.Stop(); } else { cache.Stop(); cluster.Start(); firstStarted = true; Console.WriteLine("\tSTART"); } break; case '2': if (secondStarted) { cluster2.Stop(); secondStarted = false; Console.WriteLine("\tEND"); cache2.Stop(); } else { cache2.Stop(); cluster2.Start(); secondStarted = true; Console.WriteLine("\tSTART"); } break; case '0': exit = true; break; case 'a': cache.Print(); break; case 'b': cache2.Print(); break; default: Console.WriteLine("\tNoop"); break; } if (exit) { break; } } cluster.Stop(); cluster2.Stop(); }
//Used for Nodes in the ConnectionGrid public void SetClusterParent(NodeCluster newNodeCluster) { clusterParent = newNodeCluster; }
public List <Node> FindComplexPath(Node startNode, Node endNode) { if (startNode.available != true || endNode.available != true) { return(null); } List <Node> newAbstractPath; if (startNode.gridParent != endNode.gridParent) { newAbstractPath = startNode.gridParent.abstractGrid.FindMultiAbstractGridPath(startNode, endNode); } else { newAbstractPath = startNode.gridParent.abstractGrid.FindAbstractPath(startNode, endNode); } List <Node> tempList = new List <Node>(); List <Node> outList = new List <Node>(); if (newAbstractPath == null) { //Debug.Log("Abstract Path is Null"); return(null); } for (int i = 0; i < newAbstractPath.Count - 1; i++) { Node sNode = newAbstractPath[i]; Node eNode = newAbstractPath[i + 1]; if (sNode.clusterParent == eNode.clusterParent) { NodeCluster newCluster = sNode.clusterParent; //Nodes are NOT Temporary, Use Precomputed Path if (!sNode.IsTemporary() && !eNode.IsTemporary()) { List <Node> storedPath = sNode.clusterParent.GetStoredPath(sNode, eNode); if (storedPath == null) { Debug.Log("Stored Path is NULL"); Debug.Log("Start Node:(" + sNode.xVal + "," + sNode.zVal + ") End Node:(" + eNode.xVal + "," + eNode.zVal + ")"); return(null); } bool direction = (sNode.xVal == storedPath[0].xVal && sNode.zVal == storedPath[0].zVal); if (!direction) { storedPath.Reverse(); } if (outList.Count > 0) { if (outList[outList.Count - 1] == sNode) { outList.RemoveAt(outList.Count - 1); } } outList.AddRange(storedPath); } //At least one of the Nodes have been Inserted. Compute a new path else { Node s = sNode.gridParent.LookUpNode(sNode.xVal, sNode.zVal); Node e = eNode.gridParent.LookUpNode(eNode.xVal, eNode.zVal); tempList = sNode.gridParent.FindPath(s, e); outList.AddRange(tempList); tempList.Clear(); } } else { if ((i + 2) < newAbstractPath.Count) { if (newAbstractPath[i + 2].IsAbstract()) { outList.Add(eNode); } } } } return(outList); }
private void SpawnX(int newX) { int tempZ = 0;// (int)mainGrid.transform.position.z; Vector3 newLocation = new Vector3(newX, 0, tempZ); Node newNode = mainGrid.nodeDictionary[newLocation]; NodeCluster newNodeCluster = new NodeCluster(this, clusterSize, newNode.gridCoordinates,newNode.cubeCoordinates,newNode.sphereCoordinates); nodeClusterDictionary.Add(newLocation, newNodeCluster); nodeClusterCounter++; int newZ = tempZ + clusterSize; for (int i = 0; i < abstractGridSize - 1; ++i) { SpawnZ(newX, newZ); newZ += clusterSize; } }
private void Initialize() { int x_01 = (int)connection_01.position.x; int z_01 = (int)connection_01.position.z; Node tempNode = abstractGrid_01.mainGrid.LookUpNode(x_01, z_01); NodeCluster tempCluster = tempNode.clusterParent; Node closestNode = tempCluster.nodeList[0]; float closestDist = 1000000; for (int i = 0; i < tempCluster.nodeList.Count; i++) { float tempDist = Vector3.Distance(tempNode.GetLocation(), tempCluster.nodeList[i].GetLocation()); if (tempDist < closestDist) { closestDist = tempDist; closestNode = tempCluster.nodeList[i]; } } node_01 = closestNode; /*NodeCluster nc_01 = abstractGrid_01.GetNodeClusterFromLocation(x_01, z_01); * Node closestNode = nc_01.nodeList[0]; * float closestDistance = 100000000; * for (int i = 0; i < nc_01.nodeList.Count; i++) * { * float tempDist = Vector3.Distance(connection_01.position, nc_01.nodeList[i].GetLocation()); * if (tempDist < closestDistance) * { * closestDistance = tempDist; * closestNode = nc_01.nodeList[i]; * } * } * node_01 = closestNode;*/ int x_02 = (int)connection_02.position.x; int z_02 = (int)connection_02.position.z; Node tempNode2 = abstractGrid_02.mainGrid.LookUpNode(x_02, z_02); NodeCluster tempCluster2 = tempNode2.clusterParent; Node closestNode2 = tempCluster2.nodeList[0]; float closestDist2 = 1000000; for (int i = 0; i < tempCluster2.nodeList.Count; i++) { float tempDist = Vector3.Distance(tempNode2.GetLocation(), tempCluster2.nodeList[i].GetLocation()); if (tempDist < closestDist2) { closestDist2 = tempDist; closestNode2 = tempCluster2.nodeList[i]; } } node_02 = closestNode2; /*NodeCluster nc_02 = abstractGrid_02.GetNodeClusterFromLocation(x_02, z_02); * closestNode = nc_02.nodeList[0]; * closestDistance = 100000000; * for (int i = 0; i < nc_02.nodeList.Count; i++) * { * float tempDist = Vector3.Distance(connection_02.position, nc_02.nodeList[i].GetLocation()); * if (tempDist < closestDistance) * { * closestDistance = tempDist; * closestNode = nc_02.nodeList[i]; * } * } * node_02 = closestNode;*/ node_01.SetConnection(node_02); node_02.SetConnection(node_01); node_01.gridParent.ManageConnectionNodes(node_01); node_02.gridParent.ManageConnectionNodes(node_02); connectionGrid.ManageNodeList(node_01); connectionGrid.ManageNodeList(node_02); }