Example #1
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();
        }
Example #2
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();
        }
Example #3
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);
            }
        }
Example #4
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();
        }