当前位置: 首页>>代码示例>>C#>>正文


C# Position.FitsIntoByte方法代码示例

本文整理汇总了C#中fCraft.Position.FitsIntoByte方法的典型用法代码示例。如果您正苦于以下问题:C# Position.FitsIntoByte方法的具体用法?C# Position.FitsIntoByte怎么用?C# Position.FitsIntoByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fCraft.Position的用法示例。


在下文中一共展示了Position.FitsIntoByte方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IoLoop


//.........这里部分代码省略.........
                                    player.ParseMessage( message, false );
                                }
                                break;

                            // Player movement
                            case InputCodes.MoveRotate:
                                reader.ReadByte();
                                Position newPos = new Position();
                                newPos.x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.h = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.r = reader.ReadByte();
                                newPos.l = reader.ReadByte();

                                if( newPos.h < 0 || newPos.x < -32 || newPos.x >= world.map.widthX * 32+32 || newPos.y < -32 || newPos.y > world.map.widthY * 32+32 ) {
                                    world.log.Log( player.name + " was kicked for moving out of map boundaries.", LogType.SuspiciousActivity );
                                    world.SendToAll( player.name + " was kicked for moving out of map boundaries.", null );
                                    KickNow( "Hacking detected: out of map boundaries." );
                                    return;
                                }

                                Position delta = new Position(), oldPos = player.pos;
                                bool posChanged, rotChanged;

                                if( !player.isHidden ) {
                                    delta.Set( newPos.x - oldPos.x, newPos.y - oldPos.y, newPos.h - oldPos.h, newPos.r, newPos.l );
                                    posChanged = delta.x != 0 || delta.y != 0 || delta.h != 0;
                                    rotChanged = newPos.r != oldPos.r || newPos.l != oldPos.l;

                                    if( player.isFrozen ) {
                                        if( rotChanged ) {
                                            world.SendToAll( PacketWriter.MakeRotate( player.id, newPos ), player );
                                            player.pos.r = newPos.r;
                                            player.pos.l = newPos.l;
                                        }
                                        if( posChanged ) {
                                            SendNow( PacketWriter.MakeTeleport( 255, player.pos ) );
                                        }

                                    } else {
                                        if( delta.FitsIntoByte() && fullPositionUpdateCounter < fullPositionUpdateInterval ) {
                                            if( posChanged && rotChanged ) {
                                                world.SendToAll( PacketWriter.MakeMoveRotate( player.id, delta ), player );
                                            } else if( posChanged ) {
                                                world.SendToAll( PacketWriter.MakeMove( player.id, delta ), player );
                                            } else if( rotChanged ) {
                                                world.SendToAll( PacketWriter.MakeRotate( player.id, newPos ), player );
                                            }
                                        } else if( !delta.IsZero() && !player.isFrozen ) {
                                            world.SendToAll( PacketWriter.MakeTeleport( player.id, newPos ), player );
                                        }
                                        player.pos = newPos;
                                        if( player.isDummySpamming ) {
                                            world.cmd.standardCommands.Dummy( player, new Command( "/dummy " + player.name ) );
                                        }
                                    }

                                    fullPositionUpdateCounter++;
                                    if( fullPositionUpdateCounter >= fullPositionUpdateInterval ) fullPositionUpdateCounter = 0;
                                }
                                break;

                            // Set tile
                            case InputCodes.SetTile:
                                x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                h = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                mode = reader.ReadByte();
                                type = reader.ReadByte();
                                if( type > 49 || x < 0 || x > world.map.widthX || y < 0 || y > world.map.widthY || h < 0 || h > world.map.height ) {
                                    world.log.Log( player.name + " was kicked for sending bad SetTile packets.", LogType.SuspiciousActivity );
                                    world.SendToAll( player.name + " was kicked for sending bad SetTile packets.", null );
                                    KickNow( "Hacking detected: illegal SetTile packet." );
                                    return;
                                } else {
                                    player.SetTile( x, y, h, mode == 1, (Block)type );
                                }
                                break;
                        }
                    }
                }

            } catch( ThreadAbortException ) {
                world.log.Log( "Session.IoLoop: Thread aborted!", LogType.Error );

            } catch( IOException ex ) {
                world.log.Log( "Session.IoLoop: {0}.", LogType.Warning, ex.Message );

            } catch( SocketException ex ) {
                world.log.Log( "Session.IoLoop: {0}.", LogType.Warning, ex.Message );

            } catch( Exception ex ) {
                world.log.Log( "Session.IoLoop: {0}: {1}.", LogType.Error, ex.ToString(), ex.Message );

            } finally {
                canQueue = false;
                canSend = false;
                canDispose = true;
            }
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:101,代码来源:Session.cs

示例2: MoveEntity

        void MoveEntity( VisibleEntity entity, Position newPos ) {
            Position oldPos = entity.LastKnownPosition;

            // calculate difference between old and new positions
            Position delta = new Position {
                X = (short)(newPos.X - oldPos.X),
                Y = (short)(newPos.Y - oldPos.Y),
                H = (short)(newPos.H - oldPos.H),
                R = (byte)Math.Abs( newPos.R - oldPos.R ),
                L = (byte)Math.Abs( newPos.L - oldPos.L )
            };

            bool posChanged = (delta.X != 0) || (delta.Y != 0) || (delta.H != 0);
            bool rotChanged = (delta.R != 0) || (delta.L != 0);

            if( skipUpdates ) {
                int distSquared = delta.X * delta.X + delta.Y * delta.Y + delta.H * delta.H;
                // movement optimization
                if( distSquared < SkipMovementThresholdSquared &&
                    (delta.R * delta.R + delta.L * delta.L) < SkipRotationThresholdSquared &&
                    !entity.SkippedLastMove ) {

                    entity.SkippedLastMove = true;
                    return;
                }
                entity.SkippedLastMove = false;
            }

            Packet packet;
            // create the movement packet
            if( partialUpdates && delta.FitsIntoByte() && fullUpdateCounter < FullPositionUpdateInterval ) {
                if( posChanged && rotChanged ) {
                    // incremental position + rotation update
                    packet = PacketWriter.MakeMoveRotate( entity.Id, new Position {
                        X = delta.X,
                        Y = delta.Y,
                        H = delta.H,
                        R = newPos.R,
                        L = newPos.L
                    } );

                } else if( posChanged ) {
                    // incremental position update
                    packet = PacketWriter.MakeMove( entity.Id, delta );

                } else if( rotChanged ) {
                    // absolute rotation update
                    packet = PacketWriter.MakeRotate( entity.Id, newPos );
                } else {
                    return;
                }

            } else {
                // full (absolute position + rotation) update
                packet = PacketWriter.MakeTeleport( entity.Id, newPos );
            }

            entity.LastKnownPosition = newPos;
            SendNow( packet );
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:60,代码来源:Session.cs


注:本文中的fCraft.Position.FitsIntoByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。