コード例 #1
0
        internal override void Link(TrackingSpaceRoot ram, List <AbstractCompiler> compilers)
        {
            base.Link(ram, compilers);

            var typeAsType = Type2Connect == "" ? null : Find(Type2Connect);

            if (typeAsType != null)
            {
                var typeObjects = transform.GetComponentsInChildren(typeAsType);
                foreach (var to1 in typeObjects)
                {
                    foreach (var to2 in typeObjects)
                    {
                        if (to1 == to2)
                        {
                            continue;
                        }
                        var go = new GameObject();
                        go.transform.parent = transform;
                        var lineRenderer = go.AddComponent <LineRenderer>();
                        var positions    = new Vector3[2];
                        positions[0]               = to1.transform.position;
                        positions[1]               = to2.transform.position;
                        lineRenderer.endWidth      = 0.1f;
                        lineRenderer.startWidth    = 0.1f;
                        lineRenderer.startColor    = Color.blue;
                        lineRenderer.endColor      = Color.blue;
                        lineRenderer.positionCount = 2;
                        lineRenderer.SetPositions(positions);
                    }
                }
            }

            foreach (var c in compilers)
            {
                var door2Door = c.gameObject.GetComponent <SmallDoor2DoorTransitionCompiler>();
                if (door2Door == null)
                {
                    continue;
                }
                door2Door.HideStuff();
            }

            //colorize rooms
            var renderers = GetComponentsInChildren <Renderer>();

            foreach (var rend in renderers)
            {
                ProcessRenderer(rend);
            }
        }
コード例 #2
0
        //public override bool SpaceRequirement(
        //    List<HardwareRequirements> hardwareCluster,
        //    List<HardwareRequirements> hardwareExtra,
        //    int extraAmount,
        //    TrackingSpaceRoot ram)
        //{
        //    var totalTiles = ram.GetTilesAvailable();
        //    var tiles = hardwareCluster.Sum(rt => GetTileAmount(rt, ram.TileSize));
        //    var extra = hardwareExtra.Sum(rt => GetTileAmount(rt, ram.TileSize));
        //    Debug.Log("space needed " + tiles + "+" + extra + "*" + extraAmount + " ? " + totalTiles);
        //    return totalTiles >= tiles + extra * extraAmount;
        //}

        public override bool GetPacking(
            List <PackingRequest> requests,
            TrackingSpaceRoot ram,
            out Dictionary <PackingRequest, PackingResult> result)
        {
            //clone/copy hardware list
            var req = new List <PackingRequest>(requests);

            //  Debug.Log("availableTiles " + HardwareRequirementsEditor.Matrix2String(availableTiles));

            //create result list
            var res = new Dictionary <PackingRequest, PackingResult>();

            //for each room have assignment matrix
            var places = new List <int>();

            foreach (var r in requests)
            {
                places.AddRange(r.Places);
            }
            places = places.Distinct().ToList();
            var placeToAssignment = places.ToDictionary(p => p, p => (bool[, ])ram.TileAvailable.Clone());

            //iterate through, sort by biggest
            while (req.Any())
            {
                //get largest tile demand
                var nextIndex = GetNext2Place(req);
                var nextHw    = req[nextIndex];
                req.RemoveAt(nextIndex);

                //Debug.Log("try place ");// + nextReq.Key.gameObject.name);

                //get demand
                var tilesNeeded = GetTileAmountAsVector2Int(nextHw.Size, ram.TileSize);

                //check availability
                var availableTiles = MatrixCombine(nextHw.Places.Select(p => placeToAssignment[p]).ToList(), true);
                //    if (concurrentRequests.Any())
                //{
                //var assignedSpace = concurrentRequests.Select(cr => assignedMatrix[cr]).ToList();
                //var assignedSpace = reqsAlreadyPlacedToConsider.Select(req => req.GetAssignmentMatrix()).ToList();
                //var singleListOccupiedTiles = MatrixCombine(assignedSpace, false);
                //var inverseOccupied = InvertMatrix(singleListOccupiedTiles);
                // availableTiles = MatrixCombine(inverseOccupied, availableTiles, true);
                //}
                //Debug.Log(HardwareRequirementsEditor.Matrix2String(availableTiles) + " availableTiles ");

                //assign tiles
                bool[,] assignedTiles;
                Vector2Int pointer, allocation;
                bool       reverse;
                if (AssignTiles(availableTiles, ram.TileAvailable, tilesNeeded, nextHw.WallX, nextHw.WallY, out assignedTiles, out pointer, out allocation, out reverse))
                {
                    //Debug.Log(HardwareRequirementsEditor.Matrix2String(assignedTiles) + " assignedTiles ");
                    //TODO PAPER: talk about fragmentation! (optimization for better usage)
                    //place / allocate
                    res.Add(nextHw, new PackingResult {
                        Pointer = pointer, Allocation = allocation, Reverse = reverse
                    });
                    //add to assignment matrix
                    var inverseAssigned = InvertMatrix(assignedTiles);
                    foreach (var place in nextHw.Places)
                    {
                        placeToAssignment[place] = MatrixCombine(inverseAssigned, placeToAssignment[place], true);
                    }

                    //assignedMatrix.Add(nextHw, ram.GetAssignmentMatrix(pointer, allocation));
                    //nextReq.Key.Assign(ram, pointer, assignment);
                }
                else
                {
                    Debug.Log("Packing not possible: Not enough memory/space");
                    result = new Dictionary <PackingRequest, PackingResult>();
                    return(false);
                }
            }

            result = res;
            return(true);
        }
コード例 #3
0
        public override void Recompile(TrackingSpaceRoot ram)
        {
            var memoryPointer   = HardwareRequirements.MemoryPointer.Value;
            var allocatedMemory = HardwareRequirements.AllocatedMemory;
            var tilesAvailable  = ram.TileAvailable;
            var dimensions      = ram.GetTileAmountTotal();
            var reversed        = HardwareRequirements.Reversed;

            //check where there is first 2m wall, place there
            //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]);
                    }
                }
            }
            //set position and rotation
            var position2 = ram.GetSpaceFromPosition(memoryPointer);
            var position3 = new Vector3(position2.x, 0f, position2.y);

            transform.position = position3;
            switch (PlacementOfDoors)
            {
            case DoorPlacement.StraightBig:
                if (upperWall && !reversed)
                {
                    transform.position      = position3 + (allocatedMemory.y - 1) * Vector3.forward;
                    transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
                }
                else if (rightWall && reversed)
                {
                    transform.position      = position3 + Vector3.forward + (allocatedMemory.x - 1) * Vector3.right;
                    transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
                }
                else if (lowerWall && !reversed)
                {
                    transform.position      = position3 + Vector3.right;
                    transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
                }
                else
                {
                    if (!(leftWall && reversed))
                    {
                        Debug.LogError(gameObject.name + "/" + transform.parent.gameObject.name + " no fitting wall");
                    }
                    transform.position      = position3;
                    transform.localRotation = Quaternion.Euler(0f, -90f, 0f);
                }
                break;

            case DoorPlacement.CornerSmall:
                if (upperWall && rightWall)
                {
                    transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
                }
                else if (rightWall && lowerWall)
                {
                    transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
                }
                else if (lowerWall && leftWall)
                {
                    transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
                }
                else
                {
                    if (!leftWall || !upperWall)
                    {
                        Debug.LogError(gameObject.name + "/" + transform.parent.gameObject.name + " no wall");
                    }
                    transform.localRotation = Quaternion.Euler(0f, -90f, 0f);
                }
                break;

            case DoorPlacement.StraightSmall:
                if (leftWall || rightWall)
                {
                    transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
                }
                else
                {
                    if (!upperWall && !lowerWall)
                    {
                        Debug.LogError(gameObject.name + "/" + transform.parent.gameObject.name + " no wall");
                    }
                    transform.localRotation = Quaternion.Euler(0f, -90f, 0f);
                }
                break;
            }

            for (var i = 0; i < Transitions.Count; i++)
            {
                Colorize(Transitions[i], i == 0 ? Always1 : Always2);
            }

            SetVars();
        }
コード例 #4
0
        // todo show which reqs are fulfilled and which not
        public override bool GetPacking(List <PackingRequest> request, TrackingSpaceRoot ram, out Dictionary <PackingRequest, PackingResult> result)
        {
            var placeableObjects = new List <PlaceableObject>();

            foreach (var req in request)
            {
                var obj = new PlaceableObject((int)Math.Ceiling(req.Size.x), (int)Math.Ceiling(req.Size.y),
                                              req.Places,
                                              _convertToSideRequirement(req.WallY), _convertToSideRequirement(req.WallX),
                                              req.IsSemiWall,
                                              req.PlaceFarAway);
                obj.Request = req;

                placeableObjects.Add(obj);
            }

            var tilesAvailable = (bool[, ])ram.TileAvailable.Clone();

            DeterministicPacker packer = new DeterministicPacker(true);


            var bestWallScore = int.MaxValue;
            List <PlacedObject> bestPlacedObjs = null;

            for (int i = 0; i < InitialRunsPacker; i++)
            {
                float acceptProbability = (float)i / InitialRunsPacker;

                List <PlacedObject> placedObjs;

                var firstFitScore = packer.Pack(out placedObjs,
                                                placeableObjects, tilesAvailable,
                                                ExecutionMode == Modes.Performance ? PlacementScoreRequirement.OnlyBestWall : PlacementScoreRequirement.PreferBest,
                                                false,
                                                acceptProbability);

                if (placedObjs == null)
                {
                    continue;
                }

                var wallScore = DeterministicPacker.GetScore(placedObjs, true);

                if (wallScore <= bestWallScore)
                {
                    bestPlacedObjs = placedObjs;
                    bestWallScore  = wallScore;
                }
            }

            if (bestPlacedObjs == null)
            {
                result = null;
                return(false);
            }

            if (ExecutionMode == Modes.Quality)
            {
                List <PlacedObject> annealedPlacedObjs = null;
                var annealingScore = packer.ImprovePackingAccordingToPlacementScores(out annealedPlacedObjs, bestPlacedObjs);

                var wallScore = DeterministicPacker.GetScore(annealedPlacedObjs, true);

                if (wallScore > 0)
                {
                    result = null;
                    return(false);
                }

                bestPlacedObjs = annealedPlacedObjs;
            }

            // convert PackedObject to PackingResult
            result = new Dictionary <PackingRequest, PackingResult>();
            foreach (var placedObj in bestPlacedObjs)
            {
                var placeableObj = placedObj.PlaceableObject;
                var xDim         = placedObj.Flipped
                    ? placeableObj.Dimensions.Y
                    : placeableObj.Dimensions.X;
                var yDim = placedObj.Flipped
                    ? placeableObj.Dimensions.X
                    : placeableObj.Dimensions.Y;

                var res = new PackingResult()
                {
                    Allocation = new Vector2Int(xDim, yDim),
                    Pointer    = new Vector2Int(placedObj.Position.X, placedObj.Position.Y),
                    Reverse    = placedObj.Flipped
                };

                result[placeableObj.Request] = res;
            }

            return(true);
        }
コード例 #5
0
        public override void Recompile(TrackingSpaceRoot ram)
        {
            var memoryPointer   = HardwareRequirements.MemoryPointer.Value;
            var allocatedMemory = HardwareRequirements.AllocatedMemory;

            _readyToFire = new Dictionary <PetrinetTransition, bool>();


            var tilesAvailable = ram.TileAvailable;
            var dimensions     = ram.GetTileAmountTotal();

            //debug floor object
            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;
            //pos += ram.GetSpaceFromPosition(memoryPointer);
            if (FloorObject != null)
            {
                var go = CompileLibraryObject(FloorObject, pos, 0f, "floor_" + gameObject.name);
                go.transform.localScale = new Vector3(allocatedMemory.x, 1f, allocatedMemory.y);
            }

            //check where there is first 2m wall, place there
            //check all walls
            var upperWall = allocatedMemory.x > 1;
            var rightWall = allocatedMemory.y > 1;
            var lowerWall = allocatedMemory.x > 1;
            var leftWall  = allocatedMemory.y > 1;

            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]);
                    }
                }
            }
            //set position and rotation
            var position2 = ram.GetSpaceFromPosition(memoryPointer);
            var position3 = new Vector3(position2.x, 0f, position2.y);

            if (upperWall)
            {
                transform.position      = position3 + (allocatedMemory.y - 1) * Vector3.forward;
                transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
            }
            else if (rightWall)
            {
                transform.position      = position3 + Vector3.forward + (allocatedMemory.x - 1) * Vector3.right;
                transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
            }
            else if (lowerWall)
            {
                transform.position      = position3 + Vector3.right;
                transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
            }
            else
            {
                if (!leftWall)
                {
                    Debug.LogError(gameObject.name + "/" + transform.parent.gameObject.name + " no wall");
                }
                transform.position      = position3;
                transform.localRotation = Quaternion.Euler(0f, -90f, 0f);
            }


            //init vars
            _colliderToTransition = new Dictionary <Collider, PetrinetTransition>
            {
                { Collider1To2Trigger, Transitions[0] },
                { Collider2To1Trigger, Transitions[1] }
            };
            _transitionToViz = new Dictionary <PetrinetTransition, GameObject>
            {
                { Transitions[0], Viz1 },
                { Transitions[1], Viz2 }
            };

            _playerTransform = GameObject.Find(PlayerObject).transform;

            _compiled = true;
        }
コード例 #6
0
 public abstract bool GetPacking(
     List <PackingRequest> request,
     TrackingSpaceRoot ram,
     out Dictionary <PackingRequest, PackingResult> result);