Exemplo n.º 1
0
    public void Activate()
    {
        StateInformation i = _currStateInfo;

        i.inactive     = false;
        _currStateInfo = i;
    }
Exemplo n.º 2
0
    public void Deactivate()
    {
        StateInformation i = _currStateInfo;

        i.inactive     = true;
        _currStateInfo = i;
    }
Exemplo n.º 3
0
        public void Create_With_WorkGroup()
        {
            var group = Substitute.For <IWorkGroup>();
            var test  = new StateInformation(group);

            Assert.Equal(group, test.Group);
        }
    public void OnMouseButton(Vector3 mousePosition, StateInformation stateInformation)
    {
        IPlacedObject    selectedObject       = stateInformation.selectedObject;
        MouseButtonState leftMouseButtonState = leftMouseButton.GetState();

        // moving the Object
        if (leftMouseButtonState == MouseButtonState.DOWN)
        {
            selectedObject.SetAllCollidersStatus(false);
        }
        else if (leftMouseButtonState == MouseButtonState.PRESSED)
        {
            selectedObject.RemoveWeaponFromPerson();
            //selectedObject.SetAllCollidersStatus(false);
            objectEditingModule.MoveObject(selectedObject, mousePosition);
        }
        else if (leftMouseButtonState == MouseButtonState.UP)
        {
            selectedObject.SetAllCollidersStatus(true);
        }

        // Giving an Enemy a Weapon
        if (leftMouseButtonState == MouseButtonState.UP && lastLeftMouseButtonState == MouseButtonState.PRESSED)
        {
            IPlacedObject hoveredObject    = stateInformation.hoveredObject;
            bool          objectCanBeGiven = objectInformationModule.CheckIfWeaponCanBeGivenToPerson(selectedObject, hoveredObject);
            if (objectCanBeGiven)
            {
                // give selectedObject to hoveredObject
                objectEditingModule.GiveWeaponToPerson(selectedObject, hoveredObject);
            }
        }
        lastLeftMouseButtonState = leftMouseButtonState;
    }
    void Start()
    {
        stateInformation = new StateInformation();
        interfaceManager = InterfaceManager.GetInstance();
        prefabsManager   = PrefabsManager.GetInstance();
        levelController  = LevelController.instance;
        levelDataManager = LevelDataManager.GetInstance();

        startupModule           = (IStartupModule)StartupModule.GetInstance();
        objectDeletionModule    = (IObjectDeletionModule)ObjectDeletionModule.GetInstance();
        objectPlacementModule   = (IObjectPlacementModule)ObjectPlacementModule.GetInstance();
        objectEditingModule     = (IObjectEditingModule)ObjectEditingModule.GetInstance();
        objectInformationModule = (IObjectInformationModule)ObjectInformationModule.GetInstance();


        GameObject leftMouseButtonObject = Instantiate(mouseButtonPrefab, transform);

        leftMouseButton = leftMouseButtonObject.GetComponent <MouseButton>();
        GameObject rightMouseButtonObject = Instantiate(mouseButtonPrefab, transform);

        rightMouseButton = rightMouseButtonObject.GetComponent <MouseButton>();

        leftMouseButton.Setup(0, mouseButtonLeftPressedTime);
        rightMouseButton.Setup(1, cameraDragTime);

        prefabsManager.AddPrefabs();
        interfaceManager.SetupUI(prefabsManager.GetPrefabTable());

        InitializeLevel(initialLevelWidth, initialLevelHeight);
        SetupLevel();
    }
Exemplo n.º 6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty infoProperty  = property.FindPropertyRelative("Info");
            SerializedProperty valueProperty = property.FindPropertyRelative("_value");

            StateInformation stateInfo = (StateInformation)infoProperty.objectReferenceValue;

            if (stateInfo != null)
            {
                label.tooltip = stateInfo.Description;

                if (stateInfo.accuracy != AttributeInformation.Accuracy.Float)
                {
                    EditorGUI.BeginChangeCheck();
                    float newValue = EditorGUI.IntField(position, label, Mathf.RoundToInt(valueProperty.floatValue));
                    if (EditorGUI.EndChangeCheck())
                    {
                        valueProperty.floatValue = newValue;
                    }
                }
                else
                {
                    valueProperty.floatValue = EditorGUI.FloatField(position, label, valueProperty.floatValue);
                }

                GUI.tooltip = null;
            }
            else
            {
                EditorGUI.LabelField(position, label);
            }

            property.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 7
0
 ////////////////////////////////////////////////////////////////////////////
 public EqualityAnalyzer extract(StateInformation si)
 {
     if (si.equalityAnalyzer == null)
     {
         si.equalityAnalyzer = new EqualityAnalyzer(procedure);
     }
     return(si.equalityAnalyzer);
 }
 public void OnMouseButton(Vector3 mousePosition, StateInformation stateInformation)
 {
     if (leftMouseButton.GetState() == MouseButtonState.PRESSED || leftMouseButton.GetState() == MouseButtonState.DOWN)
     {
         objectDeletionModule.DeleteObject(stateInformation.hoveredObject);
         stateInformation.hoveredObject = null;
     }
 }
Exemplo n.º 9
0
 public FunctionInliner extract(StateInformation si)
 {
     if (si.functionInliner == null)
     {
         si.functionInliner = new FunctionInliner(procedure);
     }
     return(si.functionInliner);
 }
 public void OnMouseButton(Vector3 mousePosition, StateInformation stateInformation)
 {
     if (leftMouseButton.GetState() == MouseButtonState.DOWN)
     {
         objectEditingModule.AddPatrolPoint(stateInformation.selectedObject, mousePosition);
         interfaceManager.SetupObjectEditorPanel(stateInformation.selectedObject);
     }
 }
Exemplo n.º 11
0
 /////////////////////////////////////////////////////
 public MapCollector extract(StateInformation si)
 {
     if (si.mapCollector == null)
     {
         si.mapCollector = new MapCollector();
     }
     return(si.mapCollector);
 }
        public SubexpressionCounter extract(StateInformation si)
        {
            if (si.subexpressionCounter == null)
            {
                si.subexpressionCounter = new SubexpressionCounter(procedure);
            }

            return(si.subexpressionCounter);
        }
Exemplo n.º 13
0
 public BasicBlock()
 {
     label            = null;
     cfg              = null;
     statements       = new List <StatementInfo>();
     controlStatement = null;
     myPredecessors   = new List <BasicEdge>();
     preState         = new StateInformation();
     postState        = preState;
 }
Exemplo n.º 14
0
        ////////////////////////////////////////////////////////////////////////
        public void mergeNextBlock()
        {
            Debug.Assert(controlStatement != null);
            Debug.Assert(controlStatement is UnconditionalBranch);
            BasicBlock next = controlStatement.successors.First().target;


            Debug.Assert(next.controlStatement != null);
            Debug.Assert(next.predecessors.Count() == 1);
            Debug.Assert(next != this);

            statements.RemoveAt(statements.Count - 1); //collect control statement

            int preNumStatements = statements.Count;

            next.removePredecessor(successors.First());

            StateInformation insertionPrestate = (statements.Count > 0) ? statements.Last().postState : preState;
            int i = 0;

            foreach (var nsi in next.statements)
            {
                nsi.preState   = (i == 0) ? insertionPrestate : statements.Last().postState;
                nsi.basicBlock = this;
                nsi.index      = statements.Count;
                statements.Add(nsi);
                i++;
            }

            postState        = statements.Last().postState;
            controlStatement = statements.Last().statement as ControlStatement;
            foreach (var e in controlStatement.successors)
            {
                e.setSource(this);
            }

            assertLocalInvariant();

            next.controlStatement = null;
            next.statements       = new List <StatementInfo>();
            next.postState        = next.preState;
            next.setControlStatement(new Block(next));
            if (cfg.endNode.label == next.label)
            {
                cfg.endNode = this;
            }
            next.delete();

            foreach (var e in controlStatement.successors)
            {
                e.target.assertLocalInvariant();
            }

            assertLocalInvariant();
        }
Exemplo n.º 15
0
        public DeadCodeEliminator extract(StateInformation si)
        {
            if (si.deadCodeEliminator == null)
            {
                si.deadCodeEliminator = new DeadCodeEliminator();
            }

            si.deadCodeEliminator.initializedVariables = si.initializedVariables;

            return(si.deadCodeEliminator);
        }
 public void AddTask_WorkGroup(string value)
 {
     using (var test = Create())
     {
         test.Start();
         var group = test.AddWorkGroup(value, 1);
         var state = new StateInformation(group);
         var t     = new Task(state1 => { Thread.Sleep(100); }, state);
         test.AddTask(t);
     }
 }
 public void OnMouseButton(Vector3 mousePosition, StateInformation stateInformation)
 {
     if (leftMouseButton.GetState() == MouseButtonState.PRESSED && stateInformation.objectToPlace.Type == PrefabType.LEVELELEMENT)
     {
         objectPlacementModule.PlaceObject(stateInformation.objectToPlace, mousePosition);
     }
     else if (leftMouseButton.GetState() == MouseButtonState.DOWN)
     {
         objectPlacementModule.PlaceObject(stateInformation.objectToPlace, mousePosition);
     }
 }
Exemplo n.º 18
0
        public DeadCodeEliminator extract(StateInformation si)
        {
            if (si.deadCodeEliminator == null)
            {
                si.deadCodeEliminator = new DeadCodeEliminator(procedure);
            }

            si.deadCodeEliminator.initializedVariables = si.initializedVariables;
            Debug.Assert(si.deadCodeEliminator.initializedVariables != null);
            return(si.deadCodeEliminator);
        }
Exemplo n.º 19
0
        ///////////////////////////////////////////////////////////////////
        protected PredicateStatement(Expression expression)
        {
            Debug.Assert(expression != null);
            Debug.Assert(expression.isGround);

            this.expression = expression;
//            this.myPredecessors = new ExpressionList<Predicate>();
            //           this.successors   = new ExpressionList<Predicate>();
            preStates  = new StateInformation();
            postStates = new StateInformation();
        }
Exemplo n.º 20
0
        private StateInformation GetOrCreateStateInformation(TState state)
        {
            if (!states.ContainsKey(state))
            {
                states[state] = new StateInformation()
                {
                    state = state
                };
            }

            return(GetStateInformation(state));
        }
Exemplo n.º 21
0
    private void UpdateListeners(bool isCondutctorDied)
    {
        StateInformation info = new StateInformation();

        info.Hares           = _haresPercent;
        info.RemainKilled    = _maxKilledPassengers;
        info.StationNumber   = _currentStationNumber;
        info.TicketCount     = _ticketCount;
        info.IsConductorDied = isCondutctorDied;
        foreach (var gameStateNotificationListener in _listeners)
        {
            gameStateNotificationListener.UpdateInfo(info);
        }
    }
Exemplo n.º 22
0
 ////////////////////////////////////////////////////////////////////////
 public void appendStatement(Statement s)
 {
     Debug.Assert(s != null);
     if (controlStatement == null)
     {
         // Debug.Assert(controlStatement == null);
         var si = new StatementInfo(s, postState, new StateInformation(), this, statements.Count);
         statements.Add(si);
         postState = si.postState;
     }
     else
     {
         insertStatementAt(statements.Count - 1, s);
     }
 }
Exemplo n.º 23
0
    private void Victory()
    {
        StateInformation info = new StateInformation();

        info.Hares           = _haresPercent;
        info.RemainKilled    = _maxKilledPassengers;
        info.StationNumber   = _currentStationNumber;
        info.TicketCount     = _ticketCount;
        info.IsConductorDied = false;
        info.IsLevelFinished = true;
        foreach (var gameStateNotificationListener in _listeners)
        {
            gameStateNotificationListener.UpdateInfo(info);
            gameStateNotificationListener.GameOver();
        }
    }
Exemplo n.º 24
0
        ////////////////////////////////////////////////////////////////////////
        public void setControlStatement(ControlStatement tc)
        {
            Debug.Assert(tc != null);
            if (controlStatement != null)
            {
                Debug.Assert(!ReferenceEquals(controlStatement, tc));

                var os = new List <BasicEdge>(successors);

                foreach (var e in successors)
                {
                    e.target.removePredecessor(e);
                }
                controlStatement = tc;
                statements[statements.Count - 1].statement = tc;
                foreach (var e in tc.successors)
                {
                    Debug.Assert(e.source == this);
                }
                foreach (var e in tc.successors)
                {
                    Debug.Assert(e.target.predecessors.Contains(e));
                }

                foreach (var se in os)
                {
                    if (se.target.predecessors.Count == 0)
                    {
                        se.target.delete();
                    }
                }
            }
            else
            {
                Debug.Assert(controlStatement == null);
                foreach (var e in tc.successors)
                {
                    Debug.Assert(e.source == this);
                }
                controlStatement = tc;
                var cs = new StatementInfo(tc, postState, new StateInformation(), this, statements.Count);
                statements.Add(cs);
                postState = cs.postState;
            }
            assertLocalInvariant();
        }
Exemplo n.º 25
0
        ////////////////////////////////////////////////////////////////////////
        public void delete()
        {
//            Console.WriteLine("\tDeleting block {0}", label);
            Debug.Assert(predecessors.Count() == 0);
            if (successors.Count > 0)
            {
                setControlStatement(new Block(this));
            }
            Debug.Assert(successors.Count() == 0);
            cfg.removeNode(label);
            preState         = null;
            postState        = null;
            cfg              = null;
            controlStatement = null;
            label            = null;
            statements       = null;
        }
Exemplo n.º 26
0
 public InitializedVariables extract(StateInformation si)
 {
     if (si.initializedVariables == null)
     {
         si.initializedVariables = new InitializedVariables(procedure);
     }
     else
     {
         Debug.Assert(si.initializedVariables.procedure != null);
     }
     if (si.equalityAnalyzer == null || si.equalityAnalyzer.pathCondition == null)
     {
         si.initializedVariables.pathCondition = new PropositionalFormula(true);
     }
     else
     {
         si.initializedVariables.pathCondition = si.equalityAnalyzer.pathCondition;
     }
     return(si.initializedVariables);
 }
Exemplo n.º 27
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        public StatementId insertStatementAt(int index, Statement statement)
        {
            Debug.Assert(controlStatement != null);
            Debug.Assert(statement != null);
            Debug.Assert(index >= 0 && index < statements.Count);
            StateInformation pre = statements[index].preState;
            var post             = new StateInformation(); //(index == statements.Count) ?  : statements[index].preState;

            statements[index].preState = post;
            var si = new StatementInfo(statement, pre, post, this, index);

            statements.Insert(index, si);
            assertLocalInvariant();

            for (int i = index + 1; i < statements.Count; i++)
            {
                statements[i].index++;
            }
            return(statements[index].statementId);
        }
Exemplo n.º 28
0
            public StatementInfo(
                Statement statement,
                StateInformation preState,
                StateInformation postState,
                BasicBlock basicBlock,
                int index
                )
            {
                Debug.Assert(statement != null);
                Debug.Assert(preState != null);
                Debug.Assert(postState != null);
                Debug.Assert(preState != postState);
                Debug.Assert(basicBlock != null);

                this.statement  = statement;
                this.preState   = preState;
                this.postState  = postState;
                this.basicBlock = basicBlock;
                this.index      = index;
            }
Exemplo n.º 29
0
        ////////////////////////////////////
        private void dumpState(StateInformation si)
        {
            if (si.initializedVariables == null || si.deadCodeEliminator == null)
            {
                return;
            }

            writeTabs();
            cfgFile.Write("I = {");

            foreach (var v in si.initializedVariables.firstOccurence.Keys)
            {
                if (si.deadCodeEliminator.liveVariables.Contains(v))
                {
                    cfgFile.Write(" " + v);
                }
            }

            cfgFile.WriteLine(" } <BR ALIGN=\"LEFT\"/>");
        }
Exemplo n.º 30
0
        ////////////////////////////////////////////////////////////////////////
        internal void deleteStatement(int index)
        {
            Debug.Assert(index >= 0 && index < statements.Count - 1);
//            Console.WriteLine("Deleting statement {0}", label + "_" + index.ToString());

            statements.RemoveAt(index);
            if (index == 0)
            {
                preState = statements[index].preState;
            }
            else
            {
                statements[index - 1].postState = statements[index].preState;
            }

            for (int i = index; i < statements.Count; i++)
            {
                statements[i].index--;
            }

            assertLocalInvariant();
        }
Exemplo n.º 31
0
 private void Victory()
 {
     StateInformation info = new StateInformation();
     info.Hares = _haresPercent;
     info.RemainKilled = _maxKilledPassengers;
     info.StationNumber = _currentStationNumber;
     info.TicketCount = _ticketCount;
     info.IsConductorDied = false;
     info.IsLevelFinished = true;
     foreach (var gameStateNotificationListener in _listeners)
     {
         gameStateNotificationListener.UpdateInfo(info);
         gameStateNotificationListener.GameOver();
     }
 }
Exemplo n.º 32
0
 private void UpdateListeners(bool isCondutctorDied)
 {
     StateInformation info = new StateInformation();
     info.Hares = _haresPercent;
     info.RemainKilled = _maxKilledPassengers;
     info.StationNumber = _currentStationNumber;
     info.TicketCount = _ticketCount;
     info.IsConductorDied = isCondutctorDied;
     foreach (var gameStateNotificationListener in _listeners)
     {
         gameStateNotificationListener.UpdateInfo(info);
     }
 }