public HttpResponseMessage Edit(ListUpdate obj)
 {
     _processor.Send(obj);
     if (_notifications.HasNotifications())
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, _notifications.GetNotifications()));
     }
     return(Request.CreateResponse(HttpStatusCode.OK, obj));
 }
示例#2
0
        internal bool AddUpdate(int index, BlockID block, PhysicsArgs data, bool overRide = false)
        {
            try {
                int x = index % Width;
                int y = (index / Width) / Length;
                int z = (index / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }

                if (overRide)
                {
                    // Is the Ext flag just an indicator for the block update?
                    if (data.ExtBlock != 0 && (data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        data.Raw &= ~PhysicsArgs.ExtBits;
                    }
                    AddCheck(index, true, data); //Dont need to check physics here....AddCheck will do that
                    Blockchange((ushort)x, (ushort)y, (ushort)z, block, true, data);
                    return(true);
                }

                if (listUpdateExists.TrySetOn(x, y, z))
                {
                }
                else if (block == Block.Sand || block == Block.Gravel)
                {
                    RemoveUpdatesAtPos(index);
                }
                else
                {
                    return(false);
                }

                if ((byte)block != block)
                {
                    data.Data = Block.Obsidian;
                }
                else
                {
                    data.Data = (byte)block;
                }
                Update update; update.Index = index; update.data = data;
                ListUpdate.Add(update);

                if (!physThreadStarted && physics > 0)
                {
                    StartPhysics();
                }
                return(true);
            } catch {
                //s.Log("Warning-PhysicsUpdate");
                //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
                return(false);
            }
        }
示例#3
0
 public void ClearPhysics()
 {
     for (int i = 0; i < ListCheck.Count; i++)
     {
         RevertPhysics(ListCheck.Items[i]);
     }
     ListCheck.Clear(); listCheckExists.Clear();
     ListUpdate.Clear(); listUpdateExists.Clear();
 }
示例#4
0
        internal bool AddUpdate(int b, byte type, bool overRide, PhysicsArgs data)
        {
            try {
                int x = b % Width;
                int y = (b / Width) / Length;
                int z = (b / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }

                if (overRide)
                {
                    ExtBlock block;
                    block.BlockID = type;
                    block.ExtID   = 0;

                    // Is the Ext flag just an indicator for the block update?
                    if (data.ExtBlock && (data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        block.ExtID   = block.BlockID;
                        block.BlockID = Block.custom_block;
                        data.ExtBlock = false;
                    }
                    AddCheck(b, true, data); //Dont need to check physics here....AddCheck will do that
                    Blockchange((ushort)x, (ushort)y, (ushort)z, block, true, data);
                    return(true);
                }

                if (!listUpdateExists.Get(x, y, z))
                {
                    listUpdateExists.Set(x, y, z, true);
                }
                else if (type == Block.Sand || type == Block.Gravel)
                {
                    RemoveUpdatesAtPos(b);
                }
                else
                {
                    return(false);
                }
                ListUpdate.Add(new Update(b, (byte)type, data));

                if (!physThreadStarted && physics > 0)
                {
                    StartPhysics();
                }
                return(true);
            } catch {
                //s.Log("Warning-PhysicsUpdate");
                //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
                return(false);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateListOnlineRequest"/> class.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="listId">The list Id.</param>
 /// <param name="listUpdate">List object.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public UpdateListOnlineRequest(System.IO.Stream document, int listId, ListUpdate listUpdate, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Document         = document;
     this.ListId           = listId;
     this.ListUpdate       = listUpdate;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
示例#6
0
 public Ksdevice()
 {
     InitializeComponent();
     this.Width  = 198;
     this.Height = 275;
     _queuecount = 0;
     ViewInit();
     this.AllowDrop  = true;
     myinvoke        = new ListUpdate(myinvokefun);
     textinvoke      = new TextUpdate(textinvokefun);
     queueaddinvoke1 = new QueueADDInvoke(queueaddinvoke1fun);
     clearInvoke1    = new ClearInvoke(clearInvokefun);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateListRequest"/> class.
 /// </summary>
 /// <param name="name">The filename of the input document.</param>
 /// <param name="listId">The list Id.</param>
 /// <param name="listUpdate">List object.</param>
 /// <param name="folder">Original document folder.</param>
 /// <param name="storage">Original document storage.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public UpdateListRequest(string name, int listId, ListUpdate listUpdate, string folder = null, string storage = null, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Name             = name;
     this.ListId           = listId;
     this.ListUpdate       = listUpdate;
     this.Folder           = folder;
     this.Storage          = storage;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
示例#8
0
文件: Level.cs 项目: 8cta/MCGalaxy
        public void Dispose()
        {
            Extras.Clear();
            ListCheck.Clear(); listCheckExists.Clear();
            ListUpdate.Clear(); listUpdateExists.Clear();
            UndoBuffer.Clear();
            BlockDB.Cache.Clear();
            Zones.Clear();

            blockqueue.ClearAll();
            lock (saveLock) {
                blocks       = null;
                CustomBlocks = null;
            }
        }
示例#9
0
        public async Task <ActionResult <ListsView> > UpdateTask(ListUpdate updatedtask, Guid id)
        {
            var query = await lists.GetTodoById(id);

            if (query != null)
            {
                var updatetask = mapper.Map <TodoList>(updatedtask);
                var task       = await lists.Update(updatetask, id);

                await lists.Saves();

                var newtask = mapper.Map <ListsView>(task);
                return(Ok(newtask));
            }
            return(NotFound());
        }
示例#10
0
        internal bool AddUpdate(int b, int type, bool overRide, PhysicsArgs data)
        {
            try {
                int x = b % Width;
                int y = (b / Width) / Length;
                int z = (b / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }

                if (overRide)
                {
                    AddCheck(b, true, data); //Dont need to check physics here....AddCheck will do that
                    Blockchange((ushort)x, (ushort)y, (ushort)z, (byte)type, true, data);
                    return(true);
                }

                if (!listUpdateExists.Get(x, y, z))
                {
                    listUpdateExists.Set(x, y, z, true);
                }
                else if (type == Block.sand || type == Block.gravel)
                {
                    RemoveUpdatesAtPos(b);
                }
                else
                {
                    return(false);
                }

                ListUpdate.Add(new Update(b, (byte)type, data));
                if (!physicssate && physics > 0)
                {
                    StartPhysics();
                }
                return(true);
            } catch {
                //s.Log("Warning-PhysicsUpdate");
                //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
                return(false);
            }
        }
示例#11
0
        delegate void ListUpdate(int startindex, int endindex, string percent, string warning, string error);         //线程刷新UI代理:更新进度

        private void UpdateListView(int startindex, int endindex, string percent, string warning, string error)
        {
            if (this.lv_SelectedCalcuList.InvokeRequired)
            {
                ListUpdate d = new ListUpdate(UpdateListView);
                this.lv_SelectedCalcuList.Invoke(d, startindex, endindex, percent, warning, error);
            }
            else
            {
                //特别注意,这里用currentItemd的fid,来找lV_DataList.Items,
                //这里以假定fid是从0开始的连续整数,因此fid与listview的item序号有对应关系。
                //fid和listview.item的关系是fid对应listview.item[fid-1]
                //这里的对应关系,极大的提高了计算主引擎刷新界面的效率。避免了在listview中的搜索过程。
                //lV_DataList.Items[currentItem.fid - 1].BackColor = Color.LightSkyBlue;
                for (int i = startindex; i <= endindex; i++)
                {
                    lv_SelectedCalcuList.Items[i].SubItems[19].Text = percent + " %";       //更新进度信息
                    lv_SelectedCalcuList.Items[i].SubItems[20].Text = warning;              //更新报警总数信息
                    lv_SelectedCalcuList.Items[i].SubItems[21].Text = error;                //更新错误总数信息
                }
            }
        }
示例#12
0
 private void AddUpdate(int b, int type)
 {
     try
     {
         if (!ListUpdate.Exists(Update => Update.b == b))  //Checks to see if block is already due for an update
         {
             ListUpdate.Add(new Update(b, (byte)type));
         }
         else
         {
             if (type == 12 || type == 13)   //Sand and gravel overide
             {
                 ListUpdate.RemoveAll(Update => Update.b == b);
                 ListUpdate.Add(new Update(b, (byte)type));
             }
         }
     }
     catch
     {
         //s.Log("Warning-PhysicsUpdate");
         //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
     }
 }
        public async Task <IActionResult> put([FromBody] ListUpdate list)
        {
            if (list == null)
            {
                return(TempRes.result(400, Request.GetDisplayUrl(), list, "Data List Tidak Boleh Kosong"));
            }

            // MODELSTATE BASED VALIDATION
            ModelState.Clear();
            TryValidateModel(list);
            if (!ModelState.IsValid)
            {
                return(TempRes.result(400, Request.GetDisplayUrl(), list, ModelState.Values.SelectMany(ms => ms.Errors).FirstOrDefault().ErrorMessage));
            }

            var listupdate = await _listQ.update(list);

            if (listupdate == null)
            {
                return(TempRes.result(404, Request.GetDisplayUrl(), list, "Data List Tidak Ditemukan"));
            }

            return(TempRes.result(200, Request.GetDisplayUrl(), listupdate));
        }
示例#14
0
        void PhysicsTick()
        {
            lastCheck = ListCheck.Count;
            const uint mask = PhysicsArgs.TypeMask;

            HandlePhysics[]  handlers     = PhysicsHandlers;
            ExtraInfoHandler extraHandler = ExtraInfoPhysics.normalHandler;

            if (physics == 5)
            {
                handlers     = physicsDoorsHandlers;
                extraHandler = ExtraInfoPhysics.doorsHandler;
            }

            PhysInfo C;

            for (int i = 0; i < ListCheck.Count; i++)
            {
                Check chk = ListCheck.Items[i];
                IntToPos(chk.Index, out C.X, out C.Y, out C.Z);
                C.Index = chk.Index; C.Data = chk.data;

                try {
                    if (OnPhysicsUpdateEvent.handlers.Count > 0)
                    {
                        OnPhysicsUpdateEvent.Call(C.X, C.Y, C.Z, C.Data, this);
                    }

                    C.Block = blocks[chk.Index];
                    #if TEN_BIT_BLOCKS
                    BlockID extended = Block.ExtendedBase[C.Block];
                    if (extended > 0)
                    {
                        C.Block = (BlockID)(extended | FastGetExtTile(C.X, C.Y, C.Z));
                    }
                    #else
                    if (C.Block == Block.custom_block)
                    {
                        C.Block = (BlockID)(Block.Extended | FastGetExtTile(C.X, C.Y, C.Z));
                    }
                    #endif

                    if ((C.Data.Raw & mask) == 0 || C.Data.Type1 == PhysicsArgs.Custom || extraHandler(this, ref C))
                    {
                        HandlePhysics handler = handlers[C.Block];
                        if (handler != null)
                        {
                            handler(this, ref C);
                        }
                        else if ((C.Data.Raw & mask) == 0 || !C.Data.HasWait)
                        {
                            C.Data.Data = PhysicsArgs.RemoveFromChecks;
                        }
                    }

                    ListCheck.Items[i].data = C.Data;
                } catch {
                    listCheckExists.Set(C.X, C.Y, C.Z, false);
                    ListCheck.RemoveAt(i);
                }
            }
            RemoveExpiredChecks();

            lastUpdate = ListUpdate.Count;
            if (ListUpdate.Count > 0 && bulkSender == null)
            {
                bulkSender = new BufferedBlockSender(this);
            }

            for (int i = 0; i < ListUpdate.Count; i++)
            {
                Update U = ListUpdate.Items[i];
                try {
                    BlockID block = U.data.Data;
                    U.data.Data = 0;

                    // Is the Ext flag just an indicator for the block update?
                    byte extBits = U.data.ExtBlock;
                    if (extBits != 0 && (U.data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        block      |= (BlockID)(extBits << Block.ExtendedShift);
                        U.data.Raw &= ~PhysicsArgs.ExtBits;
                    }

                    if (DoPhysicsBlockchange(U.Index, block, false, U.data, true))
                    {
                        bulkSender.Add(U.Index, block);
                    }
                } catch {
                    Logger.Log(LogType.Warning, "Phys update issue");
                }
            }

            if (bulkSender != null)
            {
                bulkSender.Flush();
            }
            ListUpdate.Clear(); listUpdateExists.Clear();
        }
示例#15
0
        public void CalcPhysics()
        {
            ushort x, y, z;

            lastCheck = ListCheck.Count;
            const uint mask = PhysicsArgs.TypeMask;

            HandlePhysics[]  handlers     = BlockBehaviour.physicsHandlers;
            ExtraInfoHandler extraHandler = ExtraInfoPhysics.DoNormal;

            if (physics == 5)
            {
                handlers     = BlockBehaviour.physicsDoorsHandlers;
                extraHandler = ExtraInfoPhysics.DoDoorsOnly;
            }

            for (int i = 0; i < ListCheck.Count; i++)
            {
                Check C = ListCheck.Items[i];
                IntToPos(C.b, out x, out y, out z);
                try {
                    if (PhysicsUpdate != null)
                    {
                        PhysicsUpdate(x, y, z, C.data, this);
                    }
                    OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
                    if ((C.data.Raw & mask) == 0 || extraHandler(this, ref C))
                    {
                        HandlePhysics handler = handlers[blocks[C.b]];
                        if (handler != null)
                        {
                            handler(this, ref C);
                        }
                        else if ((C.data.Raw & mask) == 0 || !C.data.HasWait)
                        {
                            C.data.Data = PhysicsArgs.RemoveFromChecks;
                        }
                    }
                    ListCheck.Items[i] = C;
                } catch {
                    listCheckExists.Set(x, y, z, false);
                    ListCheck.RemoveAt(i);
                }
            }
            RemoveExpiredChecks();

            lastUpdate = ListUpdate.Count;
            if (ListUpdate.Count > 0 && bulkSender == null)
            {
                bulkSender = new BufferedBlockSender(this);
            }

            for (int i = 0; i < ListUpdate.Count; i++)
            {
                Update C = ListUpdate.Items[i];
                try {
                    byte block = C.data.Data, extBlock = 0;
                    C.data.Data = 0;
                    // Is the Ext flag just an indicator for the block update?
                    if (C.data.ExtBlock && (C.data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        extBlock        = block; block = Block.custom_block;
                        C.data.ExtBlock = false;
                    }

                    if (DoPhysicsBlockchange(C.b, block, false, C.data, extBlock, true))
                    {
                        bulkSender.Add(C.b, block, extBlock);
                    }
                } catch {
                    Server.s.Log("Phys update issue");
                }
            }

            if (bulkSender != null)
            {
                bulkSender.Send(true);
            }
            ListUpdate.Clear(); listUpdateExists.Clear();
        }
示例#16
0
        public void CalcPhysics()
        {
            if (physics == 0)
            {
                return;
            }
            try {
                ushort x, y, z;
                lastCheck = ListCheck.Count;
                if (physics == 5)
                {
                    for (int i = 0; i < ListCheck.Count; i++)
                    {
                        Check C = ListCheck.Items[i];
                        IntToPos(C.b, out x, out y, out z);
                        try {
                            if (PhysicsUpdate != null)
                            {
                                PhysicsUpdate(x, y, z, C.data, this);
                            }

                            if ((C.data.Raw & 0x3F) == 0 || ExtraInfoPhysics.DoDoorsOnly(this, ref C, null))
                            {
                                Block.HandlePhysics handler = Block.physicsDoorsHandlers[blocks[C.b]];
                                if (handler != null)
                                {
                                    handler(this, ref C);
                                }
                                else if ((C.data.Raw & 0x3F) == 0 || !C.data.HasWait)
                                {
                                    C.data.Data = 255;
                                }
                            }
                            ListCheck.Items[i] = C;
                        } catch {
                            listCheckExists.Set(x, y, z, false);
                            ListCheck.RemoveAt(i);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < ListCheck.Count; i++)
                    {
                        Check C = ListCheck.Items[i];
                        IntToPos(C.b, out x, out y, out z);
                        try {
                            if (PhysicsUpdate != null)
                            {
                                PhysicsUpdate(x, y, z, C.data, this);
                            }
                            if (OnPhysicsUpdateEvent.events.Count > 0)
                            {
                                OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
                            }

                            if ((C.data.Raw & 0x3F) == 0 || ExtraInfoPhysics.DoComplex(this, ref C))
                            {
                                Block.HandlePhysics handler = Block.physicsHandlers[blocks[C.b]];
                                if (handler != null)
                                {
                                    handler(this, ref C);
                                }
                                else if ((C.data.Raw & 0x3F) == 0 || !C.data.HasWait)
                                {
                                    C.data.Data = 255;
                                }
                            }
                            ListCheck.Items[i] = C;
                        } catch {
                            listCheckExists.Set(x, y, z, false);
                            ListCheck.RemoveAt(i);
                        }
                    }
                }
                RemoveExpiredChecks();

                lastUpdate = ListUpdate.Count;
                if (ListUpdate.Count > 0 && bulkSender == null)
                {
                    bulkSender = new BufferedBlockSender(this);
                }

                for (int i = 0; i < ListUpdate.Count; i++)
                {
                    Update C = ListUpdate.Items[i];
                    try {
                        byte type = C.data.Data;
                        C.data.Data = 0;
                        if (DoPhysicsBlockchange(C.b, type, false, C.data, 0, true))
                        {
                            bulkSender.Add(C.b, type, 0);
                        }
                    } catch {
                        Server.s.Log("Phys update issue");
                    }
                    bulkSender.CheckIfSend(false);
                }
                if (bulkSender != null)
                {
                    bulkSender.CheckIfSend(true);
                }
                ListUpdate.Clear(); listUpdateExists.Clear();
            } catch (Exception e) {
                Server.s.Log("Level physics error");
                Server.ErrorLog(e);
            }
        }
示例#17
0
        public void ClearPhysics()
        {
            ushort x, y, z;

            ListCheck.ForEach(delegate(Check C)    //checks though each block
            {
                IntToPos(C.b, out x, out y, out z);
                //attempts on shutdown to change blocks back into normal selves that are active, hopefully without needing to send into to clients.
                switch (blocks[C.b])
                {
                case 200:
                case 202:
                case 203:
                    blocks[C.b] = 0;
                    break;

                case 201:
                    //blocks[C.b] = 111;
                    Blockchange(x, y, z, 111);
                    break;

                case 205:
                    //blocks[C.b] = 113;
                    Blockchange(x, y, z, 113);
                    break;

                case 206:
                    //blocks[C.b] = 114;
                    Blockchange(x, y, z, 114);
                    break;

                case 208:     //doorair_white
                    Blockchange(x, y, z, 207);
                    break;

                case 209:
                    Blockchange(x, y, z, 50);
                    break;

                case 210:
                    Blockchange(x, y, z, 51);
                    break;

                case 211:
                    Blockchange(x, y, z, 52);
                    break;

                case 213:
                    Blockchange(x, y, z, 54);
                    break;

                case 214:
                    Blockchange(x, y, z, 55);
                    break;

                case 215:
                    Blockchange(x, y, z, 56);
                    break;

                case 216:
                    Blockchange(x, y, z, 57);
                    break;

                case 217:
                    Blockchange(x, y, z, 58);
                    break;

                case 218:
                    Blockchange(x, y, z, 59);
                    break;

                case 219:
                    Blockchange(x, y, z, 60);
                    break;

                case 220:
                    Blockchange(x, y, z, 61);
                    break;

                case 221:
                    Blockchange(x, y, z, 62);
                    break;

                case 222:
                    Blockchange(x, y, z, 63);
                    break;

                case 223:
                    Blockchange(x, y, z, 64);
                    break;

                case 224:
                    Blockchange(x, y, z, 65);
                    break;

                case 225:
                    Blockchange(x, y, z, 66);
                    break;

                case 226:
                    Blockchange(x, y, z, 67);
                    break;

                case 227:
                    Blockchange(x, y, z, 68);
                    break;

                case 228:
                    Blockchange(x, y, z, 69);
                    break;

                case 229:
                    Blockchange(x, y, z, 70);
                    break;

                case 230:
                    Blockchange(x, y, z, 71);
                    break;

                case 231:
                    Blockchange(x, y, z, 72);
                    break;

                case 232:
                    Blockchange(x, y, z, 73);
                    break;

                case 233:
                    Blockchange(x, y, z, 74);
                    break;

                case 234:
                    Blockchange(x, y, z, 75);
                    break;

                case 235:
                    Blockchange(x, y, z, 76);
                    break;

                case 236:
                    Blockchange(x, y, z, 77);
                    break;

                case 237:
                    Blockchange(x, y, z, 78);
                    break;

                case 238:
                    Blockchange(x, y, z, 79);
                    break;

                case 239:
                    Blockchange(x, y, z, 80);
                    break;

                case 240:
                    Blockchange(x, y, z, 81);
                    break;

                case 241:
                    Blockchange(x, y, z, 82);
                    break;

                case 242:
                    Blockchange(x, y, z, 83);
                    break;

                case 243:
                    Blockchange(x, y, z, 84);
                    break;

                case 244:
                    Blockchange(x, y, z, 85);
                    break;

                case 245:
                    Blockchange(x, y, z, 87);
                    break;

                case 246:
                    Blockchange(x, y, z, 86);
                    break;

                case 247:
                    Blockchange(x, y, z, 88);
                    break;

                case 248:
                    Blockchange(x, y, z, 89);
                    break;

                case 249:
                    Blockchange(x, y, z, 90);
                    break;
                }
            });

            ListCheck.Clear();
            ListUpdate.Clear();
        }
示例#18
0
        public void CalcPhysics()
        {
            try
            {
                if (Physics > 0)
                {
                    bool   extraPhysicsCheck = false;
                    ushort x, y, z;

                    ListCheck.ForEach(delegate(Check C)    //checks though each block to be updated
                    {
                        try
                        {
                            IntToPos(C.b, out x, out y, out z);
                            //Player.GlobalMessage("Found Block! = " + Block.Name(blocks[C.b]) + " : Ctime = " + C.time.ToString());
                            switch (blocks[C.b])
                            {
                            case Block.air:             //Placed air
                                //initialy checks if block is valid
                                PhysAir(PosToInt((ushort)(x + 1), y, z));
                                PhysAir(PosToInt((ushort)(x - 1), y, z));
                                PhysAir(PosToInt(x, y, (ushort)(z + 1)));
                                PhysAir(PosToInt(x, y, (ushort)(z - 1)));
                                PhysAir(PosToInt(x, (ushort)(y + 1), z));       //Check block above the air

                                //Edge of map water
                                if (y < depth / 2 && y >= (depth / 2) - 2)
                                {
                                    if (x == 0 || x == width - 1 || z == 0 || z == height - 1)
                                    {
                                        AddUpdate(C.b, Block.water);
                                    }
                                }

                                C.time = 255;
                                break;


                            case Block.dirt:         //Dirt
                                if (C.time > 80)     //To grass
                                {
                                    if (Block.LightPass(GetTile(x, (ushort)(y + 1), z)))
                                    {
                                        AddUpdate(C.b, Block.grass);
                                    }
                                    C.time = 255;
                                }
                                else
                                {
                                    C.time++;
                                }
                                break;

                            case Block.water:             //Active_water
                                //initialy checks if block is valid
                                if (!PhysSpongeCheck(C.b))
                                {
                                    if (GetTile(x, (ushort)(y + 1), z) != Block.Zero)
                                    {
                                        PhysSandCheck(PosToInt(x, (ushort)(y + 1), z));
                                    }
                                    PhysWater(PosToInt((ushort)(x + 1), y, z));
                                    PhysWater(PosToInt((ushort)(x - 1), y, z));
                                    PhysWater(PosToInt(x, y, (ushort)(z + 1)));
                                    PhysWater(PosToInt(x, y, (ushort)(z - 1)));
                                    PhysWater(PosToInt(x, (ushort)(y - 1), z));
                                }
                                else
                                {
                                    AddUpdate(C.b, Block.air);      //was placed near sponge
                                }
                                C.time = 255;
                                break;

                            case Block.lava:             //Active_lava
                                //initialy checks if block is valid
                                if (C.time >= 4)
                                {
                                    PhysLava(PosToInt((ushort)(x + 1), y, z), Block.lava);
                                    PhysLava(PosToInt((ushort)(x - 1), y, z), Block.lava);
                                    PhysLava(PosToInt(x, y, (ushort)(z + 1)), Block.lava);
                                    PhysLava(PosToInt(x, y, (ushort)(z - 1)), Block.lava);
                                    PhysLava(PosToInt(x, (ushort)(y - 1), z), Block.lava);
                                    C.time = 255;
                                }
                                else
                                {
                                    C.time++;
                                }
                                break;

                            case Block.sand:        //Sand
                                if (PhysSand(C.b, Block.sand))
                                {
                                    PhysAir(PosToInt((ushort)(x + 1), y, z));
                                    PhysAir(PosToInt((ushort)(x - 1), y, z));
                                    PhysAir(PosToInt(x, y, (ushort)(z + 1)));
                                    PhysAir(PosToInt(x, y, (ushort)(z - 1)));
                                    PhysAir(PosToInt(x, (ushort)(y + 1), z));        //Check block above
                                }
                                C.time = 255;
                                break;

                            case Block.gravel:        //Gravel
                                if (PhysSand(C.b, Block.gravel))
                                {
                                    PhysAir(PosToInt((ushort)(x + 1), y, z));
                                    PhysAir(PosToInt((ushort)(x - 1), y, z));
                                    PhysAir(PosToInt(x, y, (ushort)(z + 1)));
                                    PhysAir(PosToInt(x, y, (ushort)(z - 1)));
                                    PhysAir(PosToInt(x, (ushort)(y + 1), z));        //Check block above
                                }
                                C.time = 255;
                                break;

                            case Block.sponge:        //SPONGE
                                PhysSponge(C.b);
                                C.time = 255;
                                break;

                            //Adv physics updating anything placed next to water or lava
                            case Block.wood:        //Wood to die in lava
                            case Block.shrub:       //Tree and plants follow
                            case Block.trunk:       //Wood to die in lava
                            case Block.leaf:        //Bushes die in lava
                            case Block.yellowflower:
                            case Block.redflower:
                            case Block.mushroom:
                            case Block.redmushroom:
                            case Block.bookcase:                 //bookcase
                                if (Physics == Physics.Advanced) //Adv physics kills flowers and mushroos in water/lava
                                {
                                    PhysAir(PosToInt((ushort)(x + 1), y, z));
                                    PhysAir(PosToInt((ushort)(x - 1), y, z));
                                    PhysAir(PosToInt(x, y, (ushort)(z + 1)));
                                    PhysAir(PosToInt(x, y, (ushort)(z - 1)));
                                    PhysAir(PosToInt(x, (ushort)(y + 1), z));        //Check block above
                                }
                                C.time = 255;
                                break;

                            case Block.staircasestep:
                                PhysStair(C.b);
                                C.time = 255;
                                break;

                            case Block.wood_float:       //wood_float
                                PhysFloatwood(C.b);
                                C.time = 255;
                                break;

                            case Block.lava_fast:             //lava_fast
                                //initialy checks if block is valid
                                PhysLava(PosToInt((ushort)(x + 1), y, z), Block.lava_fast);
                                PhysLava(PosToInt((ushort)(x - 1), y, z), Block.lava_fast);
                                PhysLava(PosToInt(x, y, (ushort)(z + 1)), Block.lava_fast);
                                PhysLava(PosToInt(x, y, (ushort)(z - 1)), Block.lava_fast);
                                PhysLava(PosToInt(x, (ushort)(y - 1), z), Block.lava_fast);
                                C.time = 255;
                                break;

                            //Special blocks that are not saved
                            case Block.air_flood:       //air_flood
                                if (C.time < 1)
                                {
                                    PhysAirFlood(PosToInt((ushort)(x + 1), y, z), Block.air_flood);
                                    PhysAirFlood(PosToInt((ushort)(x - 1), y, z), Block.air_flood);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z + 1)), Block.air_flood);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z - 1)), Block.air_flood);
                                    PhysAirFlood(PosToInt(x, (ushort)(y - 1), z), Block.air_flood);
                                    PhysAirFlood(PosToInt(x, (ushort)(y + 1), z), Block.air_flood);

                                    C.time++;
                                }
                                else
                                {
                                    AddUpdate(C.b, 0);        //Turn back into normal air
                                    C.time = 255;
                                }
                                break;

                            case Block.air_flood_layer:       //air_flood_layer
                                if (C.time < 1)
                                {
                                    PhysAirFlood(PosToInt((ushort)(x + 1), y, z), Block.air_flood_layer);
                                    PhysAirFlood(PosToInt((ushort)(x - 1), y, z), Block.air_flood_layer);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z + 1)), Block.air_flood_layer);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z - 1)), Block.air_flood_layer);

                                    C.time++;
                                }
                                else
                                {
                                    AddUpdate(C.b, 0);        //Turn back into normal air
                                    C.time = 255;
                                }
                                break;

                            case Block.air_flood_down:       //air_flood_down
                                if (C.time < 1)
                                {
                                    PhysAirFlood(PosToInt((ushort)(x + 1), y, z), Block.air_flood_down);
                                    PhysAirFlood(PosToInt((ushort)(x - 1), y, z), Block.air_flood_down);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z + 1)), Block.air_flood_down);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z - 1)), Block.air_flood_down);
                                    PhysAirFlood(PosToInt(x, (ushort)(y - 1), z), Block.air_flood_down);

                                    C.time++;
                                }
                                else
                                {
                                    AddUpdate(C.b, 0);        //Turn back into normal air
                                    C.time = 255;
                                }
                                break;

                            case Block.air_flood_up:       //air_flood_up
                                if (C.time < 1)
                                {
                                    PhysAirFlood(PosToInt((ushort)(x + 1), y, z), Block.air_flood_up);
                                    PhysAirFlood(PosToInt((ushort)(x - 1), y, z), Block.air_flood_up);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z + 1)), Block.air_flood_up);
                                    PhysAirFlood(PosToInt(x, y, (ushort)(z - 1)), Block.air_flood_up);
                                    PhysAirFlood(PosToInt(x, (ushort)(y + 1), z), Block.air_flood_up);

                                    C.time++;
                                }
                                else
                                {
                                    AddUpdate(C.b, 0);        //Turn back into normal air
                                    C.time = 255;
                                }
                                break;

                            default:        //non special blocks are then ignored, maybe it would be better to avoid getting here and cutting down the list
                                //C.time = 255;
                                extraPhysicsCheck = true;
                                // HANDLE DOORS - Otherwise, this would require ~50 case statements

                                if (extraPhysicsCheck)
                                {
                                    for (int i = 0; i < doors.doorBlocks.Length; i++)
                                    {
                                        extraPhysicsCheck = false;
                                        if (blocks[C.b] == doors.doorAirBlocks[i])
                                        {
                                            if (C.time == 0)
                                            {
                                                PhysReplace(PosToInt((ushort)(x + 1), y, z), doors.doorBlocks[i], doors.doorAirBlocks[i]);
                                                PhysReplace(PosToInt((ushort)(x - 1), y, z), doors.doorBlocks[i], doors.doorAirBlocks[i]);
                                                PhysReplace(PosToInt(x, y, (ushort)(z + 1)), doors.doorBlocks[i], doors.doorAirBlocks[i]);
                                                PhysReplace(PosToInt(x, y, (ushort)(z - 1)), doors.doorBlocks[i], doors.doorAirBlocks[i]);
                                                PhysReplace(PosToInt(x, (ushort)(y - 1), z), doors.doorBlocks[i], doors.doorAirBlocks[i]);
                                                PhysReplace(PosToInt(x, (ushort)(y + 1), z), doors.doorBlocks[i], doors.doorAirBlocks[i]);
                                            }
                                            if (C.time < 16)
                                            {
                                                C.time++;
                                            }
                                            else
                                            {
                                                AddUpdate(C.b, doors.doorBlocks[i]);        //turn back into door
                                                C.time = 255;
                                            }
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    C.time = 255;
                                }                          // Ignore the block, no physics required
                                break;
                            }
                        }
                        catch
                        {
                            ListCheck.Remove(C);
                            Player.GlobalMessage("Phys check issue");
                        }
                    });

                    ListCheck.RemoveAll(Check => Check.time == 255); //Remove all that are finished with 255 time

                    ListUpdate.ForEach(delegate(Update C)            //checks though each block to be updated and does so
                    {
                        try
                        {
                            IntToPos(C.b, out x, out y, out z);
                            Blockchange(x, y, z, C.type);
                        }
                        catch
                        {
                            Logger.Log("Phys update issue", LogType.Error);
                        }
                        System.Threading.Thread.Sleep(1); // Attempt to slow down physics just a tad
                    });

                    ListUpdate.Clear();
                }
            }
            catch
            {
                Logger.Log("Map physics error", LogType.Error);
            }
        }
示例#19
0
        public void CalcPhysics()
        {
            ushort x, y, z;

            lastCheck = ListCheck.Count;
            const uint mask = PhysicsArgs.TypeMask;

            HandlePhysics[]  handlers     = physicsHandlers;
            ExtraInfoHandler extraHandler = ExtraInfoPhysics.DoNormal;

            if (physics == 5)
            {
                handlers     = physicsDoorsHandlers;
                extraHandler = ExtraInfoPhysics.DoDoorsOnly;
            }

            for (int i = 0; i < ListCheck.Count; i++)
            {
                Check C = ListCheck.Items[i];
                IntToPos(C.b, out x, out y, out z);
                try {
                    if (OnPhysicsUpdateEvent.handlers.Count > 0)
                    {
                        OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
                    }

                    if ((C.data.Raw & mask) == 0 || extraHandler(this, ref C))
                    {
                        int idx = blocks[C.b];
                        if (idx == Block.custom_block)
                        {
                            idx = Block.Count + GetExtTileNoCheck(x, y, z);
                        }

                        HandlePhysics handler = handlers[idx];
                        if (handler != null)
                        {
                            handler(this, ref C);
                        }
                        else if ((C.data.Raw & mask) == 0 || !C.data.HasWait)
                        {
                            C.data.Data = PhysicsArgs.RemoveFromChecks;
                        }
                    }
                    ListCheck.Items[i] = C;
                } catch {
                    listCheckExists.Set(x, y, z, false);
                    ListCheck.RemoveAt(i);
                }
            }
            RemoveExpiredChecks();

            lastUpdate = ListUpdate.Count;
            if (ListUpdate.Count > 0 && bulkSender == null)
            {
                bulkSender = new BufferedBlockSender(this);
            }

            ExtBlock block;

            for (int i = 0; i < ListUpdate.Count; i++)
            {
                Update C = ListUpdate.Items[i];
                try {
                    block.BlockID = C.data.Data;
                    block.ExtID   = 0;
                    C.data.Data   = 0;
                    // Is the Ext flag just an indicator for the block update?
                    if (C.data.ExtBlock && (C.data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        block.ExtID     = block.BlockID;
                        block.BlockID   = Block.custom_block;
                        C.data.ExtBlock = false;
                    }

                    if (DoPhysicsBlockchange(C.b, block, false, C.data, true))
                    {
                        bulkSender.Add(C.b, block.BlockID, block.ExtID);
                    }
                } catch {
                    Logger.Log(LogType.Warning, "Phys update issue");
                }
            }

            if (bulkSender != null)
            {
                bulkSender.Send(true);
            }
            ListUpdate.Clear(); listUpdateExists.Clear();
        }