Example #1
0
        public override void Update(IUpdateArgs args)
        {
            if (CanRender)
            {
                var offset = new Vector3(0.5f, 0.5f, 0.5f);

                if (DoRotation)
                {
                    ItemRenderer.Update(args, Matrix.Identity * Matrix.CreateScale(Scale) * Matrix.CreateTranslation(-offset)
                                        * Matrix.CreateRotationY(MathHelper.ToRadians(_rotation)) * Matrix.CreateTranslation(offset)
                                        * Matrix.CreateTranslation((KnownPosition.ToVector3())), Color.White.ToVector3(), KnownPosition);
                }
                else
                {
                    ItemRenderer.Update(args, Matrix.Identity * Matrix.CreateScale(Scale)
                                        * Matrix.CreateRotationY(MathHelper.ToRadians(KnownPosition.Yaw))
                                        * Matrix.CreateTranslation(KnownPosition.ToVector3()), Color.White.ToVector3(), KnownPosition);
                }

                ItemRenderer?.Update(args.GraphicsDevice, args.Camera);
            }

            if (DoRotation)
            {
                _rotation += 45f * (float)args.GameTime.ElapsedGameTime.TotalSeconds;
            }
        }
Example #2
0
        public override void Update(IUpdateArgs args)
        {
            if (CanRender)
            {
                var knownPos = KnownPosition.ToVector3();
                //    var bb       = base.BoundingBox;
                // var knownPos = bb.GetCenter();

                if (DoRotation)
                {
                    //var offset = new Vector3((float) Width, (float) Height, (float) Width) / 2f;
                    var offset = new Vector3(0.5f, 0f, 0.5f);
                    ItemRenderer.Update(args, MCMatrix.CreateScale(0.25f)
                                        * MCMatrix.CreateTranslation(-offset)
                                        * MCMatrix.CreateRotationY(MathHelper.ToRadians(_rotation))
                                        * MCMatrix.CreateTranslation(offset)
                                        * MCMatrix.CreateTranslation(knownPos));
                }
                else
                {
                    ItemRenderer.Update(args, MCMatrix.CreateScale(0.25f)
                                        * MCMatrix.CreateRotationY(MathHelper.ToRadians(KnownPosition.Yaw))
                                        * MCMatrix.CreateTranslation(knownPos));
                }
            }

            if (DoRotation)
            {
                _rotation += 45f * (float)args.GameTime.ElapsedGameTime.TotalSeconds;
            }
        }
Example #3
0
        public void Update(IUpdateArgs args)
        {
            var moonPhase = (int)(World.WorldInfo.Time / 24000L % 8L + 8L) % 8;

            if (CurrentMoonPhase != moonPhase)
            {
                CurrentMoonPhase = moonPhase;

                var w = (1f / MoonTexture.Width) * (MoonTexture.Width / 4f);
                var h = (1f / MoonTexture.Height) * (MoonTexture.Height / 2f);

                int x = moonPhase % 4;
                int y = moonPhase % 2;

                float textureX = (w * x);
                float textureY = (h * y);

                float textureXMax = (w * x) + w;
                float textureYMax = (h * y) + h;

                _moonPlaneVertices[0].TextureCoordinate = new Vector2(textureX, textureY);
                _moonPlaneVertices[1].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[2].TextureCoordinate = new Vector2(textureX, textureYMax);

                _moonPlaneVertices[3].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[4].TextureCoordinate = new Vector2(textureXMax, textureYMax);
                _moonPlaneVertices[5].TextureCoordinate = new Vector2(textureX, textureYMax);

                var modified = _moonPlaneVertices.Select(x => x.TextureCoordinate).ToArray();
                MoonPlane.SetData(12, modified, 0, modified.Length, MoonPlane.VertexDeclaration.VertexStride);
            }
        }
Example #4
0
        public bool Update(IUpdateArgs args)
        {
            if ((args.GameTime.TotalGameTime.TotalMilliseconds - _lastTickTime) >= 50)
            {
                _lastTickTime = args.GameTime.TotalGameTime.TotalMilliseconds;
                var ticks = _scheduledTicks.Where(x => x.Value <= _tick).ToArray();

                foreach (var tick in ticks)
                {
                    _scheduledTicks.TryRemove(tick.Key, out long _);
                }

                //Executed scheduled ticks
                foreach (var tick in ticks)
                {
                    try
                    {
                        tick.Key.Invoke();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, $"An exception occureced while executing a scheduled tick!");
                    }
                }

                _tick++;
                return(true);
            }

            return(false);
        }
Example #5
0
            public void Update(IUpdateArgs args, Matrix characterMatrix, Vector3 diffuseColor)
            {
                CharacterMatrix = characterMatrix;
                foreach (var part in Parts)
                {
                    if (part.Effect != null)
                    {
                        part.Effect.DiffuseColor = diffuseColor;
                    }

                    if (!part.IsDirty)
                    {
                        continue;
                    }

                    _isDirty = true;
                    part.Update(args);
                }

                foreach (var attachable in Attachables.ToArray())
                {
                    attachable.Update(RotationMatrix);
                }

                if (_isDirty)
                {
                    UpdateVertexBuffer(args.GraphicsDevice);
                }
            }
Example #6
0
        // selects type-dependent args validation
        private static void ValidateArgs(IUpdateArgs args)
        {
            ValidateUpdateArgs(args);

            var contentArgs = args as IUpdateContentArgs;

            if (contentArgs != null)
            {
                ValidateUpdateContentArgs(contentArgs);
            }

            var captionArgs = args as IUpdateCaptionArgs;

            if (captionArgs != null)
            {
                ValidateUpdateCaptionArgs(captionArgs);
            }

            var iconArgs = args as IUpdateIconArgs;

            if (iconArgs != null)
            {
                ValidateUpdateIconArgs(iconArgs);
            }
        }
Example #7
0
        public virtual void Update(IUpdateArgs args)
        {
            var now = DateTime.UtcNow;

            if (RenderEntity || ShowItemInHand)
            {
                ModelRenderer.Update(args, KnownPosition);
            }

            if (ShowItemInHand)
            {
                //ItemRenderer?.World =
                ItemRenderer?.Update(args.GraphicsDevice, args.Camera);
            }

            if (now.Subtract(LastUpdatedTime).TotalMilliseconds >= 50)
            {
                LastUpdatedTime = now;
                try
                {
                    OnTick();
                }
                catch (Exception e)
                {
                    Log.Warn($"Exception while trying to tick entity!", e);
                }
            }
        }
Example #8
0
        public override void Update(IUpdateArgs args)
        {
            if (CanRender)
            {
                var bb       = base.BoundingBox;
                var knownPos = bb.GetCenter();

                if (DoRotation)
                {
                    var offset = new Vector3((float)Width, (float)Height, (float)Width) / 2f;

                    ItemRenderer.Update(args, Matrix.Identity
                                        * Matrix.CreateScale(Scale)
                                        * Matrix.CreateTranslation(-offset)
                                        * Matrix.CreateRotationY(MathHelper.ToRadians(_rotation))
                                        * Matrix.CreateTranslation(offset)
                                        * Matrix.CreateTranslation((knownPos)), Color.White.ToVector3(), KnownPosition);
                }
                else
                {
                    ItemRenderer.Update(args, Matrix.Identity
                                        * Matrix.CreateScale(Scale)
                                        * Matrix.CreateRotationY(MathHelper.ToRadians(KnownPosition.Yaw))
                                        * Matrix.CreateTranslation(knownPos), Color.White.ToVector3(), KnownPosition);
                }

                ItemRenderer?.Update(args.GraphicsDevice, args.Camera);
            }

            if (DoRotation)
            {
                _rotation += 45f * (float)args.GameTime.ElapsedGameTime.TotalSeconds;
            }
        }
Example #9
0
 private static void ValidateUpdateArgs(IUpdateArgs args)
 {
     // output screensaver file should not exist
     if (File.Exists(args.OutputPath))
     {
         var message = string.Format(Localization.ValidateArgsOutputFile, args.OutputPath);
         throw new IOException(message);
     }
 }
Example #10
0
        public void Update(IUpdateArgs args)
        {
            if (!RenderSkybox)
            {
                return;
            }

            var moonPhase = (int)(World.Time / 24000L % 8L + 8L) % 8;

            if (CurrentMoonPhase != moonPhase)
            {
                CurrentMoonPhase = moonPhase;

                var w = (1f / MoonTexture.Width) * (MoonTexture.Width / 4f);
                var h = (1f / MoonTexture.Height) * (MoonTexture.Height / 2f);

                int x = moonPhase % 4;
                int y = moonPhase % 2;

                float textureX = (w * x);
                float textureY = (h * y);

                float textureXMax = (w * x) + w;
                float textureYMax = (h * y) + h;

                _moonPlaneVertices[0].TextureCoordinate = new Vector2(textureX, textureY);
                _moonPlaneVertices[1].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[2].TextureCoordinate = new Vector2(textureX, textureYMax);

                _moonPlaneVertices[3].TextureCoordinate = new Vector2(textureXMax, textureY);
                _moonPlaneVertices[4].TextureCoordinate = new Vector2(textureXMax, textureYMax);
                _moonPlaneVertices[5].TextureCoordinate = new Vector2(textureX, textureYMax);

                var modified = _moonPlaneVertices.Select(xx => xx.TextureCoordinate).ToArray();
                MoonPlane.SetData(12, modified, 0, modified.Length, MoonPlane.VertexDeclaration.VertexStride);
            }

            var camera = args.Camera;

            SkyPlaneEffect.View       = camera.ViewMatrix;
            SkyPlaneEffect.Projection = camera.ProjectionMatrix;

            CelestialPlaneEffect.View       = camera.ViewMatrix;
            CelestialPlaneEffect.Projection = camera.ProjectionMatrix;

            var position = camera.Position;

            if (EnableClouds)
            {
                CloudsPlaneEffect.View       = camera.ViewMatrix;
                CloudsPlaneEffect.Projection = camera.ProjectionMatrix;

                CloudsPlaneEffect.World = Matrix.CreateTranslation(position.X, 127, position.Z);
            }
        }
Example #11
0
        public override void Update(IUpdateArgs args)
        {
            if (CanRender)
            {
                ItemRenderer?.Update(
                    Matrix.Identity * Matrix.CreateScale(Scale)
                    * Matrix.CreateRotationY(MathHelper.ToRadians(KnownPosition.Yaw))
                    * Matrix.CreateTranslation(KnownPosition.ToVector3()), KnownPosition);

                ItemRenderer?.Update(args.GraphicsDevice, args.Camera);
            }
        }
Example #12
0
        public void Update(IUpdateArgs args, SkyBox skyRenderer)
        {
            var entities = Entities.Values.ToArray();

            foreach (var entity in entities)
            {
                if (entity is Entity e)
                {
                    e.ModelRenderer.DiffuseColor = Color.White.ToVector3() * World.BrightnessModifier;
                }
                entity.Update(args);
            }
        }
Example #13
0
        public void Update(IUpdateArgs args)
        {
            Shaders.Update(args.Camera);

            _timer += (float)args.GameTime.ElapsedGameTime.TotalSeconds;
            if (_timer >= (1.0f / _framerate))
            {
                _timer       -= 1.0f / _framerate;
                _currentFrame = (_currentFrame + 1) % Resources.Atlas.GetFrameCount();

                Shaders.SetAnimatedTextures(Resources.Atlas.GetAtlas(_currentFrame));
            }
        }
Example #14
0
            public void Update(IUpdateArgs args)
            {
                if (!IsDirty)
                {
                    return;
                }
                var device = args.GraphicsDevice;

                if (Effect == null)
                {
                    Effect         = new AlphaTestEffect(device);
                    Effect.Texture = Texture;
                }

                IsDirty = false;
            }
Example #15
0
            public void Update(IUpdateArgs args, Matrix characterMatrix, Vector3 diffuseColor)
            {
                if (CurrentAnim == null && Animations.TryDequeue(out var animation))
                {
                    animation.Setup();
                    CurrentAnim = animation;
                }

                if (CurrentAnim != null)
                {
                    CurrentAnim.Update(args.GameTime);

                    if (CurrentAnim.IsFinished())
                    {
                        CurrentAnim.Reset();
                        CurrentAnim = null;
                    }
                }

                CharacterMatrix = characterMatrix;
                foreach (var part in Parts)
                {
                    if (part.Effect != null)
                    {
                        part.Effect.DiffuseColor = diffuseColor;
                    }

                    if (!part.IsDirty)
                    {
                        continue;
                    }

                    _isDirty = true;
                    part.Update(args);
                }

                foreach (var attachable in Attachables.ToArray())
                {
                    //attachable.R
                    //attachable.Update(RotationMatrix);
                }

                if (_isDirty)
                {
                    UpdateVertexBuffer(args.GraphicsDevice);
                }
            }
Example #16
0
        public void Update(IUpdateArgs args, SkyBox skyRenderer)
        {
            var lightColor = new Color(245, 245, 225).ToVector3();

            var entities = Entities.Values.ToArray();

            foreach (var entity in entities)
            {
                if (entity.ModelRenderer != null)
                {
                    entity.ModelRenderer.DiffuseColor = (new Color(245, 245, 225).ToVector3() * ((1f / 16f) * entity.SurroundingLightValue))
                                                        * World.BrightnessModifier;
                }

                entity.Update(args);
            }
        }
Example #17
0
        public override void Update(IUpdateArgs args)
        {
            var entityLocation         = TrackingEntity.RenderLocation.ToVector3();
            var entityPhysicalLocation = TrackingEntity.KnownPosition;

            if (_mode == EntityCameraMode.FirstPerson)
            {
                MoveTo(
                    entityLocation + new Vector3(0, (float)(TrackingEntity.Height - 0.175f), 0),
                    entityPhysicalLocation.GetDirection(true, true));
            }
            else
            {
                MoveTo(entityLocation,
                       entityPhysicalLocation.GetDirection(true, true));
            }
        }
Example #18
0
        public virtual void Update(IUpdateArgs args)
        {
            var now = DateTime.UtcNow;

            if (RenderEntity || ShowItemInHand)
            {
                ModelRenderer.Update(args, KnownPosition);

                CalculateLegMovement(args);

                if (ShowItemInHand)
                {
                    //CheckHeldItem();

                    //Matrix.CreateRotationY(MathUtils.ToRadians((-KnownPosition.HeadYaw)))
                    //			ItemRenderer?.Update(Matrix.CreateRotationY(MathUtils.ToRadians(180f - KnownPosition.HeadYaw)) * Matrix.CreateTranslation(KnownPosition));
                    //   ItemRenderer?.Update(null, new PlayerLocation(KnownPosition.X, KnownPosition.Y, KnownPosition.Z, 180f - KnownPosition.HeadYaw, 180f - KnownPosition.Yaw, KnownPosition.Pitch));

                    if (_rightArmModel != null && ItemRenderer != null)
                    {
                        //ItemRenderer.Rotation = _rightArmModel.Rotation;
                    }

                    ItemRenderer?.Update(Matrix.Identity *
                                         Matrix.CreateScale(Scale) *
                                         Matrix.CreateRotationY(MathHelper.ToRadians(180f - KnownPosition.HeadYaw)) *
                                         Matrix.CreateTranslation(KnownPosition.X, KnownPosition.Y, KnownPosition.Z), new PlayerLocation(KnownPosition.X, KnownPosition.Y, KnownPosition.Z, 180f - KnownPosition.HeadYaw, 180f - KnownPosition.Yaw, KnownPosition.Pitch));
                    //ItemRenderer?.World =
                    ItemRenderer?.Update(args.GraphicsDevice, args.Camera);
                }
            }

            /*      if (now.Subtract(LastUpdatedTime).TotalMilliseconds >= 50)
             *    {
             *        LastUpdatedTime = now;
             *        try
             *        {
             *            OnTick();
             *        }
             *        catch (Exception e)
             *        {
             *            Log.Warn(e, $"Exception while trying to tick entity!");
             *        }
             *    }*/
        }
Example #19
0
        public void Update(IUpdateArgs args)
        {
            var entities      = Entities.Values.ToArray();
            var blockEntities = BlockEntities.Values.ToArray();

            foreach (var entity in entities.Concat(blockEntities))
            {
                /*if (entity.ModelRenderer != null)
                 *      entity.ModelRenderer.DiffuseColor =
                 *              (new Color(245, 245, 225).ToVector3() * ((1f / 16f) * entity.SurroundingLightValue))
                 * World.BrightnessModifier;*/

                if (entity.IsRendered)
                {
                    entity.Update(args);
                }
            }
        }
Example #20
0
        public void Update(IUpdateArgs args)
        {
            _timer += (float)args.GameTime.ElapsedGameTime.TotalSeconds;
            if (_timer >= (1.0f / _framerate))
            {
                _timer       -= 1.0f / _framerate;
                _currentFrame = (_currentFrame + 1) % FrameCount;

                _currentFrameTexture   = Game.Resources.Atlas.GetAtlas(_currentFrame);
                AnimatedEffect.Texture = _currentFrameTexture;
                // OpaqueEffect.Texture = frame;
                // TransparentEffect.Texture = frame;
            }

            var camera = args.Camera;

            _cameraBoundingFrustum = camera.BoundingFrustum;
            _cameraPosition        = camera.Position;
        }
Example #21
0
        public void Update(IUpdateArgs args)
        {
            //var entities      = Entities.Values.ToArray();
            //var blockEntities = BlockEntities.Values.ToArray();

            foreach (var entity in _rendered)
            {
                _updateWatch.Restart();
                //if (entity.IsRendered)
                entity.Update(args);

                var elapsed = _updateWatch.ElapsedMilliseconds;

                if (elapsed > 13)
                {
                    Log.Warn($"Entity update took to long! Spent {elapsed}ms on entity of type {entity} (EntityId={entity.EntityId})");
                }
            }
        }
Example #22
0
        public override void Update(IUpdateArgs args)
        {
            var entityLocation = TrackingEntity.RenderLocation;

            if (_mode == EntityCameraMode.FirstPerson)
            {
                MoveTo(
                    entityLocation + new Vector3(0, Player.EyeLevel, 0),
                    new Vector3(
                        MathHelper.ToRadians(entityLocation.HeadYaw),
                        MathHelper.ToRadians(entityLocation.HeadYaw),
                        MathHelper.ToRadians(entityLocation.Pitch)));
            }
            else
            {
                MoveTo(entityLocation.ToVector3(),
                       new Vector3(MathHelper.ToRadians(entityLocation.HeadYaw), MathHelper.ToRadians(entityLocation.HeadYaw), MathHelper.ToRadians(entityLocation.Pitch)));
            }
        }
Example #23
0
        /// <inheritdoc />
        public override void UpdateContext3D(IUpdateArgs args, IGuiRenderer guiRenderer)
        {
            _rot += (float)args.GameTime.ElapsedGameTime.TotalSeconds;

            if (_basicEffect == null)
            {
                _basicEffect = new BasicEffect(Alex.GraphicsDevice);
                _basicEffect.VertexColorEnabled = true;
                _basicEffect.TextureEnabled     = true;
                _basicEffect.LightingEnabled    = false;
                _basicEffect.FogEnabled         = false;
            }

            var offset = new Vector3(0.5f, 0.5f, 0.5f);

            _basicEffect.Projection = args.Camera.ProjectionMatrix;
            _basicEffect.View       = args.Camera.ViewMatrix;

            _basicEffect.World = Matrix.CreateScale(1f / 16f)
                                 * Matrix.CreateRotationY(MathUtils.ToRadians(18f * _rot % 360f))
                                 * Matrix.CreateRotationX(MathUtils.ToRadians(8f * _rot % 360f));

            var block = _blockStates[_index];

            if (_index != _previousIndex)
            {
                if (block.Block.Animated)
                {
                    //	_alphaEffect.Texture = Alex.Resources.Atlas.GetAtlas(0);
                    _basicEffect.Texture = Alex.Resources.Atlas.GetAtlas(0);
                }
                else
                {
                    //	_alphaEffect.Texture = Alex.Resources.Atlas.GetStillAtlas();
                    _basicEffect.Texture = Alex.Resources.Atlas.GetStillAtlas();
                }

                _previousIndex = _index;
            }

            _currentEffect = _basicEffect;
        }
Example #24
0
 public override void Update(IUpdateArgs args, IEntity entity)
 {
     MoveTo(entity.KnownPosition + new Vector3(0, Player.EyeLevel, 0),
            new Vector3(MathHelper.ToRadians(entity.KnownPosition.HeadYaw), MathHelper.ToRadians(entity.KnownPosition.HeadYaw), MathHelper.ToRadians(entity.KnownPosition.Pitch)));
 }
Example #25
0
        public override void Update(IUpdateArgs args)
        {
            if (WaitingOnChunk && Age % 4 == 0)
            {
                NoAi = true;

                if (Level.GetChunk(KnownPosition.GetCoordinates3D(), true) != null)
                {
                    Velocity       = Vector3.Zero;
                    WaitingOnChunk = false;
                    NoAi           = false;
                }
            }

            ChunkCoordinates oldChunkCoordinates = new ChunkCoordinates(base.KnownPosition);
            bool             sprint = IsSprinting;
            bool             sneak  = IsSneaking;

            if (!CanFly && IsFlying)
            {
                IsFlying = false;
            }

            if (IsSprinting && !CanSprint)
            {
                IsSprinting = false;
            }

            Controller.Update(args.GameTime);
            //KnownPosition.HeadYaw = KnownPosition.Yaw;

            if (IsSprinting && !sprint)
            {
                FOVModifier = 10;

                Network.EntityAction((int)EntityId, EntityAction.StartSprinting);
            }
            else if (!IsSprinting && sprint)
            {
                FOVModifier = 0;

                Network.EntityAction((int)EntityId, EntityAction.StopSprinting);
            }

            if (IsSneaking != sneak)
            {
                if (IsSneaking)
                {
                    Network.EntityAction((int)EntityId, EntityAction.StartSneaking);
                    Camera.UpdateOffset(new Vector3(0f, -0.15f, 0.35f));
                }
                else
                {
                    Network.EntityAction((int)EntityId, EntityAction.StopSneaking);
                    Camera.UpdateOffset(Vector3.Zero);
                }
            }

            //	DoHealthAndExhaustion();

            var previousCheckedInput = _prevCheckedInput;

            if ((Controller.CheckInput && Controller.CheckMovementInput))
            {
                _prevCheckedInput = true;
                if (!previousCheckedInput || World.FormManager.IsShowingForm)
                {
                    return;
                }

                UpdateRayTracer();

                //if (Controller.InputManager.IsDown(InputCommand.LeftClick) && DateTime.UtcNow - _lastAnimate >= TimeSpan.FromMilliseconds(500))
                //{
                //	SwingArm(true);
                //}

                var hitEntity = HitEntity;
                if (hitEntity != null && Controller.InputManager.IsPressed(InputCommand.LeftClick) && hitEntity is LivingEntity)
                {
                    if (_destroyingBlock)
                    {
                        StopBreakingBlock(forceCanceled: true);
                    }

                    InteractWithEntity(hitEntity, true);
                }
                else if (hitEntity != null && Controller.InputManager.IsPressed(InputCommand.RightClick) && hitEntity is LivingEntity)
                {
                    if (_destroyingBlock)
                    {
                        StopBreakingBlock(forceCanceled: true);
                    }

                    InteractWithEntity(hitEntity, false);
                }
                else if (hitEntity == null && !_destroyingBlock &&
                         Controller.InputManager.IsPressed(InputCommand.LeftClick) &&
                         !HasRaytraceResult)
                {
                    HandleLeftClick(Inventory[Inventory.SelectedSlot], Inventory.SelectedSlot);
                }
                else if (hitEntity == null && !_destroyingBlock && Controller.InputManager.IsDown(InputCommand.LeftClick) && !IsWorldImmutable && HasRaytraceResult)                 //Destroying block.
                {
                    StartBreakingBlock();
                }
                else if (_destroyingBlock && Controller.InputManager.IsUp(InputCommand.LeftClick))
                {
                    StopBreakingBlock();
                }
                else if (_destroyingBlock && Controller.InputManager.IsDown(InputCommand.LeftClick))
                {
                    if (_destroyingTarget != new BlockCoordinates(Vector3.Floor(Raytraced)))
                    {
                        StopBreakingBlock(true, true);

                        if (Gamemode != Gamemode.Creative)
                        {
                            StartBreakingBlock();
                        }
                    }
                    else
                    {
                        if ((DateTime.UtcNow - _lastAnimate).TotalMilliseconds > 500)
                        {
                            _lastAnimate = DateTime.UtcNow;
                            SwingArm(true);
                        }

                        var timeRan = (DateTime.UtcNow - _destroyingTick).TotalMilliseconds / 50d;
                        if (timeRan >= _destroyTimeNeeded)
                        {
                            StopBreakingBlock(true);
                        }
                    }
                }
                else if (Controller.InputManager.IsPressed(InputCommand.RightClick))
                {
                    bool handledClick = false;
                    var  item         = Inventory[Inventory.SelectedSlot];
                    // Log.Debug($"Right click!");
                    if (item != null)
                    {
                        handledClick = HandleClick(item, Inventory.SelectedSlot);
                    }

                    /*if (!handledClick && Inventory.OffHand != null && !(Inventory.OffHand is ItemAir))
                     * {
                     *      handledClick = HandleRightClick(Inventory.OffHand, 1);
                     * }*/
                }

                if (hitEntity != null && HasCollision)
                {
                    if (IsColliding(hitEntity))
                    {
                        //var distance = DistanceToHorizontal(hitEntity);
                        //	Velocity += (KnownPosition.ToVector3() - hitEntity.KnownPosition.ToVector3());
                    }
                }
            }
            else
            {
                if (_destroyingBlock)
                {
                    StopBreakingBlock();
                }

                _prevCheckedInput     = false;
                _lastTimeWithoutInput = DateTime.UtcNow;
            }

            if (PreviousSlot != Inventory.SelectedSlot)
            {
                var slot = Inventory.SelectedSlot;
                Network?.HeldItemChanged(Inventory[Inventory.SelectedSlot], (short)slot);
                PreviousSlot = slot;
            }

            base.Update(args);
        }
Example #26
0
        public override void Update(IUpdateArgs args)
        {
            bool hasActiveDialog = Alex.Instance.GuiManager.ActiveDialog != null;

            Controller.CheckMovementInput = !hasActiveDialog;

            if (WaitingOnChunk && Age % 4 == 0)
            {
                NoAi = true;

                if (Level.GetChunk(KnownPosition.GetCoordinates3D(), true) != null)
                {
                    WaitingOnChunk = false;
                }
            }

            if (!IsSpawned)
            {
                base.Update(args);
                return;
            }

            bool sprint = IsSprinting;
            bool sneak  = IsSneaking;

            if (!CanFly && IsFlying)
            {
                IsFlying = false;
            }

            if (IsSprinting && !CanSprint)
            {
                IsSprinting = false;
            }

            Controller.Update(args.GameTime);
            //KnownPosition.HeadYaw = KnownPosition.Yaw;

            if (IsSprinting && !sprint)
            {
                FOVModifier = 10;
                Network.EntityAction((int)EntityId, EntityAction.StartSprinting);
            }
            else if (!IsSprinting && sprint)
            {
                FOVModifier = 0;
                Network.EntityAction((int)EntityId, EntityAction.StopSprinting);
            }

            if (IsSneaking != sneak)
            {
                if (IsSneaking)
                {
                    Network.EntityAction((int)EntityId, EntityAction.StartSneaking);
                    Level.Camera.UpdateOffset(new Vector3(0f, -0.15f, 0.35f));
                }
                else
                {
                    Network.EntityAction((int)EntityId, EntityAction.StopSneaking);
                    Level.Camera.UpdateOffset(Vector3.Zero);
                }
            }

            //	DoHealthAndExhaustion();

            //var previousCheckedInput = _prevCheckedInput;

            if (_skipUpdate)
            {
                _skipUpdate = false;
            }
            else if ((Controller.CheckInput && Controller.CheckMovementInput && !hasActiveDialog))
            {
                UpdateBlockRayTracer();
                UpdateRayTracer();

                //if (Controller.InputManager.IsDown(InputCommand.LeftClick) && DateTime.UtcNow - _lastAnimate >= TimeSpan.FromMilliseconds(500))
                //{
                //	SwingArm(true);
                //}

                bool didLeftClick     = Controller.InputManager.IsPressed(InputCommand.LeftClick);
                bool didRightClick    = Controller.InputManager.IsPressed(InputCommand.RightClick);
                bool leftMouseBtnDown = Controller.InputManager.IsDown(InputCommand.LeftClick);

                var hitEntity = HitEntity;

                if (hitEntity != null && didLeftClick && hitEntity is LivingEntity)
                {
                    if (_destroyingBlock)
                    {
                        StopBreakingBlock(forceCanceled: true);
                    }

                    InteractWithEntity(hitEntity, true, IsLeftHanded ? 1 : 0);
                }
                else if (hitEntity != null && didRightClick && hitEntity is LivingEntity)
                {
                    if (_destroyingBlock)
                    {
                        StopBreakingBlock(forceCanceled: true);
                    }

                    InteractWithEntity(hitEntity, false, IsLeftHanded ? 1 : 0);
                }
                else if (hitEntity == null && !_destroyingBlock && didLeftClick && !HasRaytraceResult)
                {
                    HandleLeftClick(IsLeftHanded ? Inventory.OffHand : Inventory.MainHand, IsLeftHanded ? 1 : 0);
                }
                else if (hitEntity == null && !_destroyingBlock &&
                         Controller.InputManager.IsBeginPress(InputCommand.LeftClick) &&
                         !IsWorldImmutable && HasRaytraceResult)                                  //Destroying block.
                {
                    StartBreakingBlock();
                }
                else if (_destroyingBlock)
                {
                    if (!leftMouseBtnDown)
                    {
                        StopBreakingBlock();
                    }
                    else if (_destroyingTarget != new BlockCoordinates(Vector3.Floor(Raytraced)))
                    {
                        StopBreakingBlock(true, true);

                        if (Gamemode != Gamemode.Creative)
                        {
                            //	StartBreakingBlock();
                        }
                    }
                }
                else if (didRightClick)
                {
                    bool handledClick = false;
                    var  item         = IsLeftHanded ? Inventory.OffHand : Inventory.MainHand;         // [Inventory.SelectedSlot];

                    // Log.Debug($"Right click!");
                    if (item != null)
                    {
                        handledClick = HandleClick(
                            item, IsLeftHanded ? 1 : 0, Inventory.HotbarOffset + Inventory.SelectedSlot);
                    }

                    /*if (!handledClick && Inventory.OffHand != null && !(Inventory.OffHand is ItemAir))
                     * {
                     *      handledClick = HandleRightClick(Inventory.OffHand, 1);
                     * }*/
                }

                if (hitEntity != null && HasCollision)
                {
                    if (IsColliding(hitEntity))
                    {
                        //var distance = DistanceToHorizontal(hitEntity);
                        //	Velocity += (KnownPosition.ToVector3() - hitEntity.KnownPosition.ToVector3());
                    }
                }
            }
            else
            {
                if (_destroyingBlock)
                {
                    StopBreakingBlock();
                }
            }

            if (PreviousSlot != Inventory.SelectedSlot)
            {
                var slot = Inventory.SelectedSlot;
                Network?.HeldItemChanged(Inventory[Inventory.SelectedSlot], (short)slot);
                PreviousSlot = slot;
            }

            if (hasActiveDialog)
            {
                _skipUpdate = true;
            }

            base.Update(args);
        }
Example #27
0
        public override void Update(IUpdateArgs args)
        {
            base.Update(args);

            var dt = (float)args.GameTime.ElapsedGameTime.TotalSeconds;

            if (IsSneaking)
            {
                _body.Rotation = new Vector3(-35f, _body.Rotation.Y, _body.Rotation.Z);
                _body.Position = Vector3.Forward * 7.5f;
                //_head.Position = new Vector3(_body.Position.X, 0.25f, 0f);

                _leftArmModel.Rotation  = new Vector3(72f, 0f, 0f);
                _rightArmModel.Rotation = new Vector3(72f, 0f, 0f);
            }
            else
            {
                _body.Position = Vector3.Zero;
                _body.Rotation = new Vector3(0f);


                var moveSpeed = MovementSpeed;
                var tcos0     = (float)(Math.Cos(DistanceMoved * 38.17) * moveSpeed) * 57.3f;
                var tcos1     = -tcos0;

                var   pos    = KnownPosition.ToVector3();
                float deltaX = pos.X - _prevUpdatePosition.X;
                float deltaZ = pos.Z - _prevUpdatePosition.Z;
                float distSQ = deltaX * deltaX + deltaZ * deltaZ;

                //_armRotation = _armRotation;

                // Test arm rotations
                if (_leftArmModel != null && _rightArmModel != null)
                {
                    //var lArmRot = new Vector3((0.5f + MathF.Sin(_armRotation)) * 7.5f, 0f,
                    //	0.1f + (MathF.Cos(_armRotation) * 1.5f));
                    Vector3 rArmRot = Vector3.Zero;
                    var     lArmRot = new Vector3(tcos0, 0, 0);
                    if (distSQ > 0f)
                    {
                        _armRotation += (float)((new Vector3(Velocity.X, 0, Velocity.Z).Length()) + distSQ) * dt;

                        rArmRot = new Vector3((0.5f + MathF.Cos(_armRotation)) * 24.5f, 0, 0);
                    }
                    else
                    {
                        _armRotation += dt;
                        rArmRot       = new Vector3((0.5f + MathF.Cos(_armRotation)) * -7.5f, 0f,
                                                    0.1f + (MathF.Sin(_armRotation) * -1.5f));
                    }

                    _leftArmModel.Rotation     = rArmRot;
                    _rightArmModel.Rotation    = -rArmRot;
                    _rightSleeveModel.Rotation = -rArmRot;
                    _leftSleeveModel.Rotation  = rArmRot;
                }


                if (_leftLegModel != null && _rightLegModel != null)
                {
                    Vector3 lLegRot = Vector3.Zero;
                    Vector3 rLegRot = Vector3.Zero;

                    if (distSQ > 0f)
                    {
                        _legRotation += (float)((new Vector3(Velocity.X, 0, Velocity.Z).Length()) + distSQ) * dt;

                        lLegRot = new Vector3(MathF.Sin(_legRotation) * 34.5f, 0f, 0f);
                        rLegRot = new Vector3(-MathF.Sin(_legRotation) * 34.5f, 0f, 0f);

                        _prevUpdatePosition = pos;
                    }
                    else
                    {
                        _legRotation = 0f;
                    }

                    _leftLegModel.Rotation    = lLegRot;
                    _rightLegModel.Rotation   = rLegRot;
                    _leftPantsModel.Rotation  = lLegRot;
                    _rightPantsModel.Rotation = rLegRot;
                }
            }
        }
Example #28
0
        // selects type-dependent args validation
        private static void ValidateArgs(IUpdateArgs args)
        {
            ValidateUpdateArgs(args);

            var contentArgs = args as IUpdateContentArgs;
            if (contentArgs != null)
                ValidateUpdateContentArgs(contentArgs);

            var captionArgs = args as IUpdateCaptionArgs;
            if (captionArgs != null)
                ValidateUpdateCaptionArgs(captionArgs);

            var iconArgs = args as IUpdateIconArgs;
            if (iconArgs != null)
                ValidateUpdateIconArgs(iconArgs);
        }
Example #29
0
            public void Update(IUpdateArgs args,
                               Matrix characterMatrix,
                               Vector3 diffuseColor,
                               PlayerLocation modelLocation)
            {
                var device = args.GraphicsDevice;

                if (Effect == null)
                {
                    Effect         = new AlphaTestEffect(device);
                    Effect.Texture = Texture;
                }
                else
                {
                    if (CurrentAnim == null && Animations.TryDequeue(out var animation))
                    {
                        animation.Setup();
                        animation.Start();

                        CurrentAnim = animation;
                    }

                    if (CurrentAnim != null)
                    {
                        CurrentAnim.Update(args.GameTime);

                        if (CurrentAnim.IsFinished())
                        {
                            CurrentAnim.Reset();
                            CurrentAnim = null;
                        }
                    }



                    Matrix yawPitchMatrix = Matrix.Identity;

                    if (ApplyHeadYaw || ApplyPitch)
                    {
                        var headYaw = ApplyHeadYaw ?
                                      MathUtils.ToRadians(-(modelLocation.HeadYaw - modelLocation.Yaw)) : 0f;

                        var pitch = ApplyPitch ? MathUtils.ToRadians(modelLocation.Pitch) : 0f;

                        yawPitchMatrix = Matrix.CreateTranslation(-EntityModelBone.Pivot)
                                         * Matrix.CreateFromYawPitchRoll(headYaw, pitch, 0f)
                                         * Matrix.CreateTranslation(EntityModelBone.Pivot);
                    }

                    var userRotationMatrix = Matrix.CreateTranslation(-EntityModelBone.Pivot)
                                             * Matrix.CreateRotationX(MathUtils.ToRadians(Rotation.X))
                                             * Matrix.CreateRotationY(MathUtils.ToRadians(Rotation.Y))
                                             * Matrix.CreateRotationZ(MathUtils.ToRadians(Rotation.Z))
                                             * Matrix.CreateTranslation(EntityModelBone.Pivot);

                    Effect.World = yawPitchMatrix * userRotationMatrix * DefaultMatrix
                                   * Matrix.CreateTranslation(_position) * characterMatrix;

                    Effect.DiffuseColor = diffuseColor;
                    var children = Children;

                    if (children.Length > 0)
                    {
                        foreach (var child in children)
                        {
                            child.Update(args, userRotationMatrix * characterMatrix, diffuseColor, modelLocation);
                        }
                    }

                    if (_isDirty)
                    {
                        UpdateVertexBuffer(args.GraphicsDevice);
                    }
                }
            }
Example #30
0
 public override void Update(IUpdateArgs args)
 {
     base.Update(args);
     //	DistanceMoved = 0f;
 }
Example #31
0
 private static void ValidateUpdateArgs(IUpdateArgs args)
 {
     // output screensaver file should not exist
     if (File.Exists(args.OutputPath))
     {
         var message = string.Format(Localization.ValidateArgsOutputFile, args.OutputPath);
         throw new IOException(message);
     }
 }
Example #32
0
        private void CalculateLegMovement(IUpdateArgs args)
        {
            var   pos    = KnownPosition.ToVector3();
            float distSQ = Vector3.DistanceSquared(_prevUpdatePosition, pos);

            var distance = DistanceMoved;

            distSQ = distance;

            if (!IsMoving)
            {
                //DistanceMoved = 0f;
            }

            var dt = (float)args.GameTime.ElapsedGameTime.TotalSeconds;

            if (!ServerEntity)
            {
                var distanceMoved = DistanceMoved;
                DistanceMoved = 0;

                _mvSpeed = (float)(distanceMoved * (TimeSpan.FromSeconds(1) / args.GameTime.ElapsedGameTime));
            }

            if (IsSneaking && _body != null)
            {
                var posOffset = new Vector3(0f, -1.5f, -4.5f);
                _body.Rotation = new Vector3(-25f, _body.Rotation.Y, _body.Rotation.Z);
                _body.Position = posOffset;

                //_head.Position = new Vector3(_body.Position.X, 0.25f, 0f);
                if (_rightArmModel != null && _leftArmModel != null)
                {
                    _leftArmModel.Rotation = new Vector3(-20f, 0f, 0f);
                    _leftArmModel.Position = posOffset;


                    if (!_rightArmModel.IsAnimating)
                    {
                        _rightArmModel.Rotation = new Vector3(-20f, 0f, 0f);
                    }

                    _rightArmModel.Position = posOffset;

                    if (_rightSleeveModel != null && _leftSleeveModel != null)
                    {
                        _rightSleeveModel.Rotation = _rightArmModel.Rotation;
                        _rightSleeveModel.Position = posOffset;

                        _leftSleeveModel.Rotation = _leftArmModel.Rotation;
                        _leftSleeveModel.Position = posOffset;
                    }
                }

                if (_head != null)
                {
                    _head.Position = posOffset;
                }
            }
            else if (_body != null && !IsSneaking)
            {
                _body.Position = Vector3.Zero;
                _body.Rotation = new Vector3(0f);

                if (_rightArmModel != null && _leftArmModel != null)
                {
                    _rightArmModel.Position = _leftArmModel.Position = Vector3.Zero;

                    if (_rightSleeveModel != null && _leftSleeveModel != null)
                    {
                        _rightSleeveModel.Rotation = _rightArmModel.Rotation;
                        _rightSleeveModel.Position = Vector3.Zero;

                        _leftSleeveModel.Rotation = _leftArmModel.Rotation;
                        _leftSleeveModel.Position = Vector3.Zero;
                    }
                }

                if (_head != null)
                {
                    _head.Position = Vector3.Zero;
                }
            }

            var moveSpeed = MovementSpeed * 20f;
            var tcos0     = (float)(Math.Cos(distance * (38.17 * 20f)) * moveSpeed) * (57.3f * 20f);
            var tcos1     = -tcos0;

            //_armRotation = _armRotation;

            // Test arm rotations
            if (!IsSneaking && _leftArmModel != null && _rightArmModel != null)
            {
                //var lArmRot = new Vector3((0.5f + MathF.Sin(_armRotation)) * 7.5f, 0f,
                //	0.1f + (MathF.Cos(_armRotation) * 1.5f));
                Vector3 rArmRot = Vector3.Zero;
                var     lArmRot = new Vector3(tcos0, 0, 0);

                if (distSQ > 0f)
                {
                    if (!IsMoving)
                    {
                        _armRotation = 0f;
                        IsMoving     = true;
                    }

                    _armRotation += (float)(_mvSpeed) * dt;
                    //rArmRot = new Vector3(tcos0, 0, 0);
                    rArmRot = new Vector3((0.5f + MathF.Cos(_armRotation)) * 24.5f, 0, 0);
                }
                else
                {
                    IsMoving      = false;
                    _armRotation += dt;

                    rArmRot = new Vector3(
                        (0.5f + MathF.Cos(_armRotation)) * -7.5f, 0f, 0.1f + (MathF.Sin(_armRotation) * -1.5f));
                }


                _leftArmModel.Rotation = rArmRot;

                if (!_rightArmModel.IsAnimating)
                {
                    _rightArmModel.Rotation = -rArmRot;
                }

                if (_rightSleeveModel != null && _leftSleeveModel != null)
                {
                    _rightSleeveModel.Rotation = -rArmRot;
                    _leftSleeveModel.Rotation  = rArmRot;
                }
            }


            if (_leftLegModel != null && _rightLegModel != null)
            {
                Vector3 lLegRot = Vector3.Zero;
                Vector3 rLegRot = Vector3.Zero;

                if (distSQ > 0f)
                {
                    _legRotation += (float)(_mvSpeed) * dt;
                    ;

                    lLegRot = new Vector3(MathF.Sin(_legRotation) * 34.5f, 0f, 0f);
                    rLegRot = new Vector3(-MathF.Sin(_legRotation) * 34.5f, 0f, 0f);
                    //lLegRot = new Vector3(tcos0, 0f, 0f);
                    //rLegRot = new Vector3(tcos1, 0f, 0f);
                }
                else
                {
                    _legRotation = 0f;
                }

                _leftLegModel.Rotation  = lLegRot;
                _rightLegModel.Rotation = rLegRot;

                if (_leftPantsModel != null && _rightPantsModel != null)
                {
                    _leftPantsModel.Rotation  = lLegRot;
                    _rightPantsModel.Rotation = rLegRot;
                }
            }


            var itemRender = ItemRenderer;
            var rightArm   = _rightArmModel;

            if (itemRender != null && rightArm != null)
            {
            }

            _prevUpdatePosition = pos;
        }