internal void ActivateLinker(TrackingSpaceRoot ram, List <AbstractCompiler> compilers) { Link(ram, compilers); if (Linked != null) { Linked.Invoke(); } }
internal void StartCompile(TrackingSpaceRoot ram) { HardwareRequirements = gameObject.GetComponentInParent <HardwareRequirements>(); Transitions = HardwareRequirements.gameObject.GetComponents <PetrinetTransition>().ToList(); RemoveListeners(); AddListeners(); Recompile(ram); _compiledPosition = transform.position; CheckVisualization(); }
internal override void Link(TrackingSpaceRoot ram, List <AbstractCompiler> compilers) { //delete old game objects first DeleteKids(); //build environment from library objects PlacePrimitives(ram, compilers, PlaceStraightWallObjects, WallLibrary, WallOccupiedLibrary, CornerLibrary, FloorLibraryOccupied, FloorLibraryUnoccupied, UnavailableLibrary, UnavailableTilesBorder); TokenUpdate(Condition); }
//[HideInInspector] //public Vector2[,] MemorySpacePointer; //[HideInInspector] //public Vector2 MemoryFragmentSpaceTileSize; public void Assign(TrackingSpaceRoot ram, AbstractPacker.PackingResult assignment)//, Vector2[,] memorySpacePointer, Vector2 memoryFragmentSpaceTileSize) { MemoryPointer = assignment.Pointer; Ram = ram; AllocatedMemory = assignment.Allocation; Reversed = assignment.Reverse; if (ReAssigned != null) { ReAssigned.Invoke(); } }
public abstract void Recompile(TrackingSpaceRoot ram);
public override void Recompile(TrackingSpaceRoot ram) { var memoryPointer = new Vector2Int(); var allocatedMemory = HardwareRequirements.AllocatedMemory; var reversed = HardwareRequirements.Reversed; if (HardwareRequirements.MemoryPointer != null) { memoryPointer = HardwareRequirements.MemoryPointer.Value; } else { Debug.LogError("pointer should not be zero"); } var tilesAvailable = ram.TileAvailable; var dimensions = ram.GetTileAmountTotal(); //if (PositionAtPointerElseMeanAllocated) //{ // var pos = ram.GetSpaceFromPosition(memoryPointer); // position = new Vector3(pos.x, 0f, pos.y); //} //else //{ var pos = Vector2.zero; for (var i = 0; i < allocatedMemory.x; i++) { for (var j = 0; j < allocatedMemory.y; j++) { pos += ram.GetSpaceFromPosition(memoryPointer.x + i, memoryPointer.y + j); } } pos /= allocatedMemory.x * allocatedMemory.y; var position = new Vector3(pos.x, 0, pos.y); //} transform.position = position; //check rotation //check all walls var upperWall = true; var rightWall = true; var lowerWall = true; var leftWall = true; for (var x = memoryPointer.x; x < memoryPointer.x + allocatedMemory.x; x++) { for (var z = memoryPointer.y; z < memoryPointer.y + allocatedMemory.y; z++) { if (x == memoryPointer.x) { leftWall = leftWall && (x == 0 || !tilesAvailable[x - 1, z]); } if (z == memoryPointer.y) { lowerWall = lowerWall && (z == 0 || !tilesAvailable[x, z - 1]); } if (z == memoryPointer.y + allocatedMemory.y - 1) { upperWall = upperWall && (z + 1 == dimensions.y || !tilesAvailable[x, z + 1]); } if (x == memoryPointer.x + allocatedMemory.x - 1) { rightWall = rightWall && (x + 1 == dimensions.x || !tilesAvailable[x + 1, z]); } } } if (upperWall && !reversed) { transform.localRotation = Quaternion.Euler(0f, 0f, 0f); } else if (rightWall && reversed) { transform.localRotation = Quaternion.Euler(0f, 90f, 0f); } else if (lowerWall && !reversed) { transform.localRotation = Quaternion.Euler(0f, 180f, 0f); } else if (leftWall && reversed) { transform.localRotation = Quaternion.Euler(0f, -90f, 0f); } else if (upperWall) { transform.localRotation = Quaternion.Euler(0f, 90f, 0f); } else if (rightWall) { transform.localRotation = Quaternion.Euler(0f, 0f, 0f); } else if (lowerWall) { transform.localRotation = Quaternion.Euler(0f, 90f, 0f); } else if (leftWall) { transform.localRotation = Quaternion.Euler(0f, 0f, 0f); } SetVars(); }
protected void PlacePrimitives(TrackingSpaceRoot ram, List <AbstractCompiler> compilers, bool placeStraightWallCorners, List <GameObject> wall, List <GameObject> wallOccupied, List <GameObject> corner, List <GameObject> floorOccupied, List <GameObject> floorUnoccupied, List <GameObject> unavailable, int unavailableTilesBorder) { var total = ram.GetTileAmountTotal(); var tileAvailable = (bool[, ])ram.TileAvailable.Clone(); var tileSize = ram.TileSize; var compilerLinkInfos = compilers.Select(c => c.GetLinkInformation()).ToList(); var compilerPlacements = compilers.Select(c => c.HardwareRequirements.GetAssignmentMatrix()).ToList(); var compilerPlacedLinkedInfo = new AbstractCompiler.LinkInformation[total.x, total.y]; for (var x = 0; x < total.x; x++) { for (var z = 0; z < total.y; z++) { var first = compilerPlacements.FindIndex(cp => cp[x, z]); var info = first < 0 ? AbstractCompiler.LinkInformation.Default : compilerLinkInfos[first]; compilerPlacedLinkedInfo[x, z] = info; } } //iterate through corners for (var x = 0 - unavailableTilesBorder; x <= total.x + unavailableTilesBorder; x++) { for (var z = 0 - unavailableTilesBorder; z <= total.y + unavailableTilesBorder; z++) { if ((x < 0 || x >= total.x || z < 0 || z >= total.y) && x < total.x + unavailableTilesBorder && z < total.y + unavailableTilesBorder) { if (unavailable.Any()) { CompileLibraryObject(unavailable[Random.Range(0, unavailable.Count)], ram.GetSpaceFromPosition(x, z), 0f, "floor_" + x + "_" + z); } } if (x < 0 || x > total.x || z < 0 || z > total.y) { continue; } //get assigned tiles in quadrants var upLeft = x - 1 >= 0 && z < total.y && tileAvailable[x - 1, z]; var lowerLeft = x - 1 >= 0 && z - 1 >= 0 && tileAvailable[x - 1, z - 1]; var upRight = x < total.x && z < total.y && tileAvailable[x, z]; var lowerRight = x < total.x && z - 1 >= 0 && tileAvailable[x, z - 1]; var upLeftOccupied = upLeft && compilerPlacements.Any(cp => cp[x - 1, z]) && compilerPlacedLinkedInfo[x - 1, z] != AbstractCompiler.LinkInformation.ShowAsUnoccupied; //var lowerLeftOccupied = lowerLeft && compilerPlacements.Any(cp => cp[x - 1, z-1]) && compilerPlacedLinkedInfo[x - 1, z - 1] != AbstractCompiler.LinkInformation.ShowAsUnoccupied; var upRightOccupied = upRight && compilerPlacements.Any(cp => cp[x, z]) && compilerPlacedLinkedInfo[x, z] != AbstractCompiler.LinkInformation.ShowAsUnoccupied; var lowerRightOccupied = lowerRight && compilerPlacements.Any(cp => cp[x, z - 1]) && compilerPlacedLinkedInfo[x, z - 1] != AbstractCompiler.LinkInformation.ShowAsUnoccupied; var upLeftIgnore = upLeft && compilerPlacedLinkedInfo[x - 1, z] == AbstractCompiler.LinkInformation.ShowNoWalls; var lowerLeftIgnore = lowerLeft && compilerPlacedLinkedInfo[x - 1, z - 1] == AbstractCompiler.LinkInformation.ShowNoWalls; var upRightIgnore = upRight && compilerPlacedLinkedInfo[x, z] == AbstractCompiler.LinkInformation.ShowNoWalls; var lowerRightIgnore = lowerRight && compilerPlacedLinkedInfo[x, z - 1] == AbstractCompiler.LinkInformation.ShowNoWalls; //create floor objects if (upRight && !upRightIgnore) { if (upRightOccupied && floorOccupied.Any()) { CompileLibraryObject(floorOccupied[Random.Range(0, floorOccupied.Count)], ram.GetSpaceFromPosition(x, z), 0f, "floor_" + x + "_" + z); } else if (!upRightOccupied && floorUnoccupied.Any()) { CompileLibraryObject(floorUnoccupied[Random.Range(0, floorUnoccupied.Count)], ram.GetSpaceFromPosition(x, z), 0f, "floor_" + x + "_" + z); } } else if (!upRight && x < total.x && z < total.y) { if (unavailable.Any()) { var unav = unavailable[Random.Range(0, unavailable.Count)]; if (LeaveOutWallsLeftLowerWallsAndCornersForView && SeeThroughUnavailable != null) { var av = false; for (var xx = x + 1; xx < total.x; xx++) { for (var zz = z + 1; zz < total.y; zz++) { av = tileAvailable[xx, zz]; if (av) { break; } } if (av) { break; } } if (av) { unav = SeeThroughUnavailable; } } CompileLibraryObject(unav, ram.GetSpaceFromPosition(x, z), 0f, "floor_" + x + "_" + z); } } //check for walls var leftWall = upLeft != lowerLeft && !upLeftIgnore && !lowerLeftIgnore; var lowerWall = lowerRight != lowerLeft && !lowerRightIgnore && !lowerLeftIgnore; var rightWall = lowerRight != upRight && !lowerRightIgnore && !upRightIgnore; var upperWall = upLeft != upRight && !upLeftIgnore && !upRightIgnore; //do not build if iso view is on and upper left or lower right are not available var rightSeeThrough = false; var upSeeThrough = false; var cornerSeeThrough = false; if (LeaveOutWallsLeftLowerWallsAndCornersForView) { rightSeeThrough = rightWall && !lowerRight; upSeeThrough = upperWall && !upLeft; //lowerWall = lowerWall && lowerLeft; //leftWall = leftWall && lowerLeft; //rightSeeThrough = !rightWall && oldRight; //upSeeThrough = !upperWall && oldUpper; cornerSeeThrough = rightSeeThrough || upSeeThrough; } //do not build, if no adjacent edge is a wall if (!upperWall && !lowerWall && !rightWall && !leftWall) { continue; } //create ref point for wall and corner placement Vector2 refPoint; if (x == total.x && z == total.y) { refPoint = ram.GetSpaceFromPosition(x - 1, z - 1) + 0.5f * tileSize; } else if (x == total.x) { refPoint = ram.GetSpaceFromPosition(x - 1, z); refPoint.x += 0.5f * tileSize.x; refPoint.y -= 0.5f * tileSize.y; } else if (z == total.y) { refPoint = ram.GetSpaceFromPosition(x, z - 1); refPoint.x -= 0.5f * tileSize.x; refPoint.y += 0.5f * tileSize.y; } else { refPoint = ram.GetSpaceFromPosition(x, z) - 0.5f * tileSize; } //create corner if not straight wall var count = 0; if (leftWall) { count++; } if (rightWall) { count++; } if (lowerWall) { count++; } if (upperWall) { count++; } var obj = corner[Random.Range(0, corner.Count)]; var buildSeeThrough = cornerSeeThrough && SeeThroughCorner != null; if (buildSeeThrough) { obj = SeeThroughCorner; } if (corner.Any() && !(!placeStraightWallCorners && count == 2 && leftWall == rightWall)) { CompileLibraryObject(obj, refPoint, 0f, "corner_" + x + "_" + z); } //create walls if (wall != null) { if (upperWall) { var occupied = upLeftOccupied || upRightOccupied; var list = occupied ? wallOccupied : wall; var objWall = list[Random.Range(0, list.Count)]; if (upSeeThrough && SeeThroughWall != null) { objWall = SeeThroughWall; } CompileLibraryObject(objWall, new Vector2(0f, 0.5f * tileSize.y) + refPoint, upLeft ? 90f : -90f, "upperWall_" + x + "_" + z); } if (rightWall) { var occupied = lowerRightOccupied || upRightOccupied; occupied = occupied || lowerRight && !lowerRightOccupied; var list = occupied ? wallOccupied : wall; var objWall = list[Random.Range(0, list.Count)]; if (rightSeeThrough && SeeThroughWall != null) { objWall = SeeThroughWall; } CompileLibraryObject(objWall, new Vector2(0.5f * tileSize.x, 0f) + refPoint, upRight ? 180f : 0f, "rightWall_" + x + "_" + z); } } } } }
internal abstract void Link(TrackingSpaceRoot ram, List <AbstractCompiler> compilers);