Example #1
0
    public Controller(dzn.Locator locator, String name = "", dzn.Meta parent = null) : base(locator, name, parent)
    {
        this.dzn_runtime.infos[this].flushes = true;
        this.out_ia = null;
        this.ia     = new iCommand();
        this.ia.dzn_meta.provides.name      = "ia";
        this.ia.dzn_meta.provides.meta      = this.dzn_meta;
        this.ia.dzn_meta.provides.component = this;
        this.iu = new iUnity();
        this.iu.dzn_meta.requires.name      = "iu";
        this.iu.dzn_meta.requires.component = this;
        this.iu.dzn_meta.requires.meta      = this.dzn_meta;

        this.dzn_meta.requires = new List <dzn.port.Meta> {
            this.iu.dzn_meta,
        };
        this.dzn_meta.children        = new List <dzn.Meta> {
        };
        this.dzn_meta.ports_connected = new List <Action>
        {
            ia.check_bindings,
            iu.check_bindings,
        };

        this.ia.inport.start = () => { dzn.Runtime.callIn(this, () => { ia_start(); }, this.ia.dzn_meta, "start"); };

        this.iu.outport.wallHit = () => { dzn.Runtime.callOut(this, () => { iu_wallHit(); }, this.iu.dzn_meta, "wallHit"); };
    }
Example #2
0
        async Task DoCommand(iCommand command, iMsgData msgData)
        {
            if (command.Multithreaded)
            {
                Thread t = new Thread(async() =>
                {
                    var d = await command.Evaluate(msgData);
                    if (d)
                    {
                        await command.DoWork(msgData);
                    }
                }
                                      );
                t.Start();
            }
            else
            {
                var d = await command.Evaluate(msgData);

                if (d)
                {
                    await command.DoWork(msgData);
                }
            }
        }
Example #3
0
        private void undo_Click(object sender, EventArgs e)
        {
            if (_commandStack.Count > 0)
            {
                // Remove the last command
                iCommand lastCommand = _commandStack.Pop();

                //jika command adalah freehandcommand
                if (Convert.ToString(lastCommand).Contains("freehand"))
                {
                    while (Convert.ToString(lastCommand).Contains("freehand") && _commandStack.Count > 0)
                    {
                        lastCommand = _commandStack.Pop();
                        lastCommand.Undo();

                        //jika ternyata lastcommand tidak freehand lagi
                        if (!Convert.ToString(lastCommand).Contains("freehand"))
                        {
                            //kembalikan ke stack
                            _commandStack.Push(lastCommand);
                        }
                    }
                }
                else
                {
                    lastCommand.Undo();
                }
                panel1.Refresh();
            }
        }
Example #4
0
        private void bg_colorButton_Click(object sender, EventArgs e)
        {
            ColorDialog c = new ColorDialog();

            System.Windows.Forms.DialogResult myResult = new System.Windows.Forms.DialogResult();
            myResult = c.ShowDialog();
            if (myResult == System.Windows.Forms.DialogResult.OK)
            {
                objGraphic.Clear(c.Color);
                bg_colorButton.BackColor = c.Color;

                bg = c.Color;
                while (_commandStack.Count > 0)
                {
                    redrawer.Push(_commandStack.Pop());
                }
                while (redrawer.Count > 0)
                {
                    iCommand redraw = redrawer.Pop();
                    redraw.Do();
                    _commandStack.Push(redraw);
                }
                panel1.Refresh();
            }
        }
 public void sendCommand(iCommand command)
 {
     try
     {
         int waitingTime = command.waitingTime();
         if (command is Pcmd)
         {
             LOGGER.Debug(String.Format("putting Pcmd's into queue {0} for time {1}", command, waitingTime));
             while (waitingTime > 0)
             { // generate enough Pcmds for the expected waiting time
                 iCommand newCommand = ((Pcmd)command).clone((waitingTime > maxWaitingTime) ? maxWaitingTime : waitingTime);
                 commonCommandQueue.Add(newCommand);
                 waitingTime = waitingTime - maxWaitingTime;
             }
         }
         else
         {
             LOGGER.Debug(String.Format("putting command into queue {0}", command));
             if (command is iCommonCommand)
             {
                 //commonCommandQueue.offer(command);
                 commonCommandQueue.Add(command);
             }
             else
             {
                 commandQueue.Add(command);
                 //commandQueue.offer(command);
             }
         }
     }
     catch (Exception e)
     {
         LOGGER.Info("Could not add " + command + " to a queue. " + e.Message);
     }
 }
Example #6
0
 public static void connect(iCommand provided, iCommand required)
 {
     provided.outport           = required.outport;
     required.inport            = provided.inport;
     provided.dzn_meta.requires = required.dzn_meta.requires;
     required.dzn_meta.provides = provided.dzn_meta.provides;
 }
        private int getNextSequenceNumber(iCommand command)
        {
            byte packetTypeId       = (byte)command.getPacketType();
            byte nextSequenceNumber = nextSequenceNumbers[packetTypeId];

            nextSequenceNumbers[packetTypeId] = (byte)(nextSequenceNumber + 1);

            return(nextSequenceNumber);
        }
Example #8
0
 public void RunCommand(iCommand newCommand, CommandSettings commandSet)
 {
     try
     {
         newCommand.Execute(commandSet);
     }
     catch (Exception ex)
     {
         throw new Exception("RunCommand error: " + ex.Message);
     }
 }
Example #9
0
        private void erase_button_Click(object sender, EventArgs e)
        {
            if (_commandStack.Count > 0)
            {
                while (_commandStack.Count > 0)
                {
                    iCommand lastCommand = _commandStack.Pop();

                    lastCommand.Undo();
                }
                panel1.Refresh();
            }
        }
        private void runConsumer(BlockingCollection <iCommand> queue, bool heartbeat)
        {
            LOGGER.Info("Creating a specific command queue consumer...");

            new Thread(() =>
            {
                try
                {
                    using (var sumoSocket = new UdpClient())
                    {
                        while (sendCommands)
                        {
                            try
                            {
                                iCommand command = queue.Take();
                                if (command != null)
                                {
                                    int cnt       = getNextSequenceNumber(command);
                                    byte[] packet = command.getBytes(cnt);
                                    sumoSocket.Send(packet, packet.Length, SumoRemote);
                                    LOGGER.Info(String.Format("Sending command: {0}", command));
                                    Thread.Sleep(command.waitingTime());
                                }
                                else  // send "null" PCmd (0,0) =  ("go by 0 speed") when queue is empty
                                {
                                    if (heartbeat)
                                    {
                                        Pcmd nullCommand      = Pcmd.pcmd(0, 0, maxWaitingTime);
                                        byte[] nullMovePacket = nullCommand.getBytes(getNextSequenceNumber(nullCommand));
                                        //LOGGER.Debug("empty queue,  sending null command '{}' with packet {}", nullCommand, convertAndCutPacket(nullMovePacket, false));
                                        sumoSocket.Send(nullMovePacket, nullMovePacket.Length, SumoRemote);
                                    }
                                    Thread.Sleep(maxWaitingTime);
                                    //MILLISECONDS.sleep(maxWaitingTime);
                                }
                            }
                            catch (Exception e)
                            {
                                throw new CommandException("Got interrupted while taking a command", e);
                            }
                        }
                    }
                }
                catch (IOException)
                {
                    LOGGER.Warn("Error occurred while sending packets to the drone.");
                }
            }).Start();
        }
Example #11
0
        public static int waitingTime(this iCommand cmd)
        {
            var property = cmd.GetType().GetProperty("waitingTime");

            if (property != null)
            {
                if (cmd.waitingTime() == 0)
                {
                    return(100);
                }
                else
                {
                    return(cmd.waitingTime());
                }
            }
            else
            {
                return(100);
            }
        }
Example #12
0
        public void AutoRun()
        {
            try
            {
                if (_engineSettings.Commands != null)
                {
                    Assembly assem = System.Reflection.Assembly.GetExecutingAssembly();

                    foreach (CommandSettings commandSet in _engineSettings.Commands)
                    {
                        Type     type           = assem.GetType("DHI.Generic.NetCDF.MIKE.Commands." + commandSet.CommandName);
                        iCommand autoRunCommand = (iCommand)assem.CreateInstance(type.Namespace + "." + type.Name);
                        autoRunCommand.Execute(commandSet);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("AutoRun error: " + ex.Message);
            }
        }
Example #13
0
        public override async Task <List <iCommand> > RecieveCommands()
        {
            var StaticCommands       = new List <iCommand>();
            IEnumerable <Type> types = GetTypes(typeof(iCommand));

            foreach (Type t in types)
            {
                object[] exa = t.GetCustomAttributes(typeof(CmdAttribute), true);
                foreach (CmdAttribute at in exa)
                {
                    iCommand obj = (iCommand)Activator.CreateInstance(t);
                    obj.Command = at.command;
                    obj.Rating  = (CommandRatings)at.commandRatings;
                    obj.Type    = (CommandType)at.commandType;

                    StaticCommands.Add(obj);
                }
            }
            StaticCommands = StaticCommands.GroupBy(x => x.Command).Select(y => y.First()).ToList();
            return(await Task.FromResult(StaticCommands));
        }
Example #14
0
 public void SetCommand(int slot, iCommand onCommand, iCommand offCommand)
 {
     this.onCommands[slot]  = onCommand;
     this.offCommands[slot] = offCommand;
 }
Example #15
0
 public void DoCommand(iCommand command)
 {
     command.doCommand();
 }
Example #16
0
 public void AddCommand(iCommand command)
 {
     _commands.Add(command);
 }
Example #17
0
        public MainWindow()
        {
            playerlife = 2;
            InitializeComponent();
            Globals.playerMissiles = new List <PlayerMissile>();
            PlayerShip statekgracza = PlayerShip.Instance();
            Designs    designs      = new Designs();

            highscores = new Dictionary <string, int>();


            #region Adding Textures
            Uri uri = new Uri(@"/Cruiser.PNG", UriKind.Relative);
            designs.addDesign("Cruiser", uri);
            uri = new Uri(@"/Destroyer.PNG", UriKind.Relative);
            designs.addDesign("Destroyer", uri);
            uri = new Uri(@"/PlayerShip.PNG", UriKind.Relative);
            designs.addDesign("PlayerShip", uri);
            uri = new Uri(@"/bullet.PNG", UriKind.Relative);
            designs.addDesign("Missile1", uri);
            uri = new Uri(@"/bullet.PNG", UriKind.Relative);
            designs.addDesign("Missile2", uri);
            uri = new Uri(@"/Booster.PNG", UriKind.Relative);
            designs.addDesign("Booster", uri);
            #endregion



            #region Adding Commands
            moveLeft  = new MoveLeft(statekgracza);
            moveRight = new MoveRight(statekgracza);
            shoot     = new Shoot(statekgracza);
            exit      = new Exit(this);
            commands  = new PlayerCommands();
            #endregion

            #region Adding Scores
            highscores.Add("Kamil", 20);
            highscores.Add("Piotr", 30);
            highscores.Add("RafaƂ", 40);
            #endregion


            #region Initialize Window
            main            = this;
            LifePoints      = "5";
            mapa            = new Canvas();
            lifecounter     = LifeCounter;
            pointscounter   = PointCounter;
            mapa.Width      = 800;
            mapa.Height     = 600;
            mapa.Background = new SolidColorBrush(Colors.White);
            mapa.Focusable  = true;
            Grid.SetRow(mapa, 0);
            Grid.SetRow(mapa, 0);
            Grid.SetColumnSpan(mapa, 6);
            Root.Children.Add(mapa);
            statekgracza.CreateShipDynamically(mapa);
            GameMaster gameMaster = new GameMaster(mapa, statekgracza);
            Thread     t          = new Thread(new ThreadStart(gameMaster.RunGame));
            t.Start();
            #endregion
        }
Example #18
0
 public void SetCommand(iCommand command)
 {
     this.command = command;
 }
Example #19
0
 public void setCommand(int slot, iCommand cmd)
 {
     commands[slot] = cmd;
 }