Exemplo n.º 1
0
 public override Matrix Lerp(Matrix a, Matrix b, float t)
 {
     return(MyMath.Lerp(ref a, ref b, t));
 }
        /// <summary>
        /// Delete a level from the local system.  Returns false if not yet initialized.
        /// </summary>
        /// <param name="worldId"></param>
        /// <param name="callback"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool StartDeletingLevel(
            Guid worldId,
            Genres bucket,
            BokuAsyncCallback callback,
            object param)
        {
            bool deleted = false;

            bucket &= Genres.SharableBins;

            // Verify exactly one bucket is specified
            Debug.Assert(bucket != 0);
            Debug.Assert((int)bucket == int.MinValue || MyMath.IsPowerOfTwo((int)bucket));

            string worldFilename = null;
            string stuffFilename = null;
            string thumbFilename = null;

            LevelMetadata record = null;

            string stuffPath = String.Empty;
            string worldPath = String.Empty;

            if (0 != (bucket & Genres.MyWorlds))
            {
                stuffPath = BokuGame.MyWorldsStuffPath;
                worldPath = BokuGame.MyWorldsPath;
            }
            else if (0 != (bucket & Genres.Downloads))
            {
                stuffPath = BokuGame.DownloadsStuffPath;
                worldPath = BokuGame.DownloadsPath;
            }


            lock (Synch)
            {
                for (int i = 0; i < allLevels.Count; ++i)
                {
                    record = allLevels[i];

                    if (record.WorldId == worldId && (record.Genres & bucket) == bucket)
                    {
                        worldFilename = Path.Combine(BokuGame.Settings.MediaPath, worldPath + worldId.ToString() + @".Xml");
                        stuffFilename = Path.Combine(BokuGame.Settings.MediaPath, stuffPath + worldId.ToString() + @".Xml");
                        thumbFilename = Path.Combine(BokuGame.Settings.MediaPath, worldPath + worldId.ToString());

                        // Need to get the terrain file before we delete the main file.  BUT the terrain should be
                        // deleted after, otherwise the usage test will find the main file and always thing that
                        // the terrain file is in use.
                        string terrainFilename = null;
                        try
                        {
                            // Only delete terrain file if no longer referenced.
                            XmlWorldData xmlWorldData = XmlWorldData.Load(worldFilename, XnaStorageHelper.Instance);
                            terrainFilename = xmlWorldData.xmlTerrainData2.virtualMapFile;
                        }
                        catch { }

                        // Note : Delete() handles non-existent files just fine.
                        Storage4.Delete(worldFilename);
                        Storage4.Delete(stuffFilename);
                        Storage4.Delete(thumbFilename + @".dds");
                        Storage4.Delete(thumbFilename + @".jpg");
                        Storage4.Delete(thumbFilename + @".png");

                        // Only deletes terrain file if no other world is using it.  (including autosaves)
                        DeleteTerrainFile(terrainFilename);

                        LevelMetadata level = allLevels[i];
                        allLevels.RemoveAt(i);

                        LevelRemoved_Synched(level);

                        deleted = true;

                        break;
                    }
                }
            }

            AsyncResult result = new AsyncResult();

            result.Success = deleted;
            result.Param   = param;
            result.Seconds = 0;

            if (callback != null)
            {
                callback(result);
            }

            return(deleted);
        }
Exemplo n.º 3
0
 public override float Lerp(float a, float b, float t)
 {
     return(MyMath.Lerp(a, b, t));
 }
Exemplo n.º 4
0
 public override Vector4 Lerp(Vector4 a, Vector4 b, float t)
 {
     return(MyMath.Lerp(a, b, t));
 }
Exemplo n.º 5
0
        }   // end of c'tor

        // Cut and pasted from BaseSpriteEmitter, just to override
        // how the position is computed. Might like to refactor the
        // Update into common particle tasks (spawn, kill, move, etc.)
        public override void Update(Camera camera)
        {
            if (Active)
            {
                // Emit new particles if needed.
                float dt = Time.GameTimeFrameSeconds;
                dt = MathHelper.Clamp(dt, 0.0f, 1.0f);  // Limit to reasonable values.

                Position += Velocity * dt;

                if (Emitting)
                {
                    if (LinearEmission)
                    {
                        Vector3 deltaPosition = Position - PreviousPosition;
                        float   dist          = deltaPosition.Length();

                        partial += dist * EmissionRate;
                    }
                    else
                    {
                        partial += dt * EmissionRate;
                    }

                    // Emit as many particles as needed this
                    // frame to keep up with the emission rate.
                    while (partial >= 1.0f)
                    {
                        if (particleList.Count < MaxSprites)
                        {
                            // Pick a random position on the sphere.
                            Vector3 rndVec = new Vector3((float)(rnd.NextDouble() - rnd.NextDouble()),
                                                         (float)(rnd.NextDouble() - rnd.NextDouble()),
                                                         (float)(rnd.NextDouble() - rnd.NextDouble()));
                            rndVec.Normalize();
                            rndVec *= targetRadius;
                            Vector3 pos = Position + rndVec;

                            // Pick a random position somewhere along the path covered this frame.
                            if (PositionJitter > 0.0f)
                            {
                                pos += PositionJitter * new Vector3((float)rnd.NextDouble() - (float)rnd.NextDouble(), (float)rnd.NextDouble() - (float)rnd.NextDouble(), (float)rnd.NextDouble() - (float)rnd.NextDouble());
                            }
                            float lifetime = MinLifetime + (float)rnd.NextDouble() * (MaxLifetime - MinLifetime);
                            BaseSpriteParticle particle = new BaseSpriteParticle(pos, lifetime, Color, MaxRotationRate, NumTiles);
                            particleList.Add(particle);
                        }

                        partial -= 1.0f;
                    }
                }

                // Update the previous position to match the current one for the next frame.
                ResetPreviousPosition();

                // Update any existing particles.  For more heavyweight particles we could
                // have an Update call per particle.  These are lightweight enough that we
                // can just update them directly.
                for (int i = 0; i < particleList.Count;)
                {
                    BaseSpriteParticle particle = (BaseSpriteParticle)particleList[i];

                    particle.age += dt;

                    Debug.Assert(particle.age >= 0.0f);

                    float t = particle.age / particle.lifetime;
                    if (t > 1.0f)
                    {
                        // Dead particle.
                        particleList.RemoveAt(i);
                    }
                    else
                    {
                        particle.radius    = MyMath.Lerp(StartRadius, EndRadius, t);
                        particle.alpha     = MyMath.Lerp(StartAlpha, EndAlpha, t);
                        particle.rotation += particle.deltaRotation * dt;

                        // Change the linear fade to a curve.
                        particle.alpha *= particle.alpha;

                        // Add in gravity effect.
                        if (NonZeroGravity)
                        {
                            particle.velocity += Gravity * dt;
                            float speed2 = particle.velocity.LengthSquared();
                            if (speed2 > MaxSpeed * MaxSpeed)
                            {
                                particle.velocity.Normalize();
                                particle.velocity *= MaxSpeed;
                            }
                        }
                        particle.position += particle.velocity * dt;

                        i++;
                    }
                }   // end loop update particles.
                // Now that we've updated all the particles, create/update the vertex buffer.
                UpdateVerts();

                // See if we've died.
                if (Dying && particleList.Count == 0)
                {
                    Active = false;
                    RemoveFromManager();
                }
            }   // end of if active
        } // end Update
Exemplo n.º 6
0
        private static void UpdateFlyingEffects(Camera camera)
        {
            double currTime = Time.GameTimeTotalSeconds;

            for (int i = 0; i < flyingEffects.Count; ++i)
            {
                ScoreEffect scoreEffect = flyingEffects[i];

                float timeElapsed = (float)(currTime - scoreEffect.spawnTime);
                if (timeElapsed > kFlyingEffectSeconds)
                {
                    flyingEffects.RemoveAt(--i + 1);
                    ReleaseScoreEffect(scoreEffect);
                    continue;
                }

                Score score;
                scores.TryGetValue((int)scoreEffect.color, out score);

                Viewport viewport = BokuGame.bokuGame.GraphicsDevice.Viewport;

                float pct = timeElapsed / kFlyingEffectSeconds;

                // If the thing went to the recycle bin, remove our reference to it.
                if (scoreEffect.thing != null && scoreEffect.thing.CurrentState == GameThing.State.Inactive)
                {
                    scoreEffect.thing = null;
                }

                // If we still have a reference to the thing, update the source position of the flying score's path.
                if (scoreEffect.thing != null)
                {
                    scoreEffect.thingPosition = scoreEffect.thing.Movement.Position;
                }

                Vector3 pt0 = scoreEffect.thingPosition + new Vector3(0, 0, scoreEffect.thingBoundingRadius * 2);

                Vector3 pt1 = new Vector3(
                    (float)viewport.Width * 0.5f,
                    (float)viewport.Height * 0.3f,
                    0.75f);
                pt1 = viewport.Unproject(
                    pt1,
                    camera.ProjectionMatrix,
                    camera.ViewMatrix,
                    Matrix.Identity);

                Vector3 pt2 = new Vector3(
                    (float)viewport.Width * 0.6f,
                    (float)viewport.Height * 0.1f,
                    0.5f);
                pt2 = viewport.Unproject(
                    pt1,
                    camera.ProjectionMatrix,
                    camera.ViewMatrix,
                    Matrix.Identity);

                Vector3 pt3 = new Vector3(
                    (float)viewport.Width * 0.9f,
                    y_margin + ScoreBoardFont().LineSpacing *score.order,
                    0.5f);
                pt3 = viewport.Unproject(
                    pt3,
                    camera.ProjectionMatrix,
                    camera.ViewMatrix,
                    Matrix.Identity);

                scoreEffect.curr = MyMath.CubicBezier(pt0, pt1, pt2, pt3, pct);

                scoreEffect.alpha = MyMath.Clamp((1f - pct) * 5, 0, 1);
            }
        }
Exemplo n.º 7
0
            private void CreateRenderTargets(GraphicsDevice device)
            {
                int shadowOffset = Scoreboard.ShadowOffset;

                int surfaceWidth  = MyMath.GetNextPowerOfTwo(charWidth);
                int surfaceHeight = MyMath.GetNextPowerOfTwo(charHeight);

                string str = String.Format("{0}", ch);

                if (surface == null || surface.IsDisposed || surface.GraphicsDevice.IsDisposed)
                {
                    surface = new RenderTarget2D(
                        BokuGame.bokuGame.GraphicsDevice,
                        surfaceWidth,
                        surfaceHeight,
                        false,
                        SurfaceFormat.Color,
                        DepthFormat.None);
                    InGame.GetRT("Scoreboard", surface);
                }

                InGame.SetRenderTarget(surface);
                InGame.Clear(Color.Transparent);

                SpriteBatch batch = UI2D.Shared.SpriteBatch;

                try
                {
                    try
                    {
                        batch.Begin();

                        TextHelper.DrawString(
                            ScoreBoardFont,
                            str,
                            new Vector2(shadowOffset + (surfaceWidth - charWidth) / 2, shadowOffset + (surfaceHeight - charHeight) / 2),
                            Color.Black);
                        TextHelper.DrawString(
                            ScoreBoardFont,
                            str,
                            new Vector2((surfaceWidth - charWidth) / 2, (surfaceHeight - charHeight) / 2),
                            Color.White);
                    }
                    catch (Exception e)
                    {
                        if (e != null)
                        {
                        }
                    }
                    finally
                    {
                        batch.End();
                    }
                }
                catch
                {
                }
                finally
                {
                    InGame.RestoreRenderTarget();
                }
            }
Exemplo n.º 8
0
        }   // end of PixelsToCameraSpaceScreenCoords()

        /// <summary>
        /// A helper function which smoothly changes the heightOffset of the camera.
        /// This takes the desired offset as a paramter, rather than the absolute height.
        /// </summary>
        /// <param name="height">The height we want the camera at point to be.</param>
        public void ChangeHeightOffsetNotHeight(float desiredOffset)
        {
            targetHeight = Terrain.GetTerrainHeightFlat(At) + desiredOffset;
            HeightOffset = MyMath.Lerp(HeightOffset, desiredOffset, Time.WallClockFrameSeconds);
        }   // end of Camera MoveHeightOffset()
Exemplo n.º 9
0
        }   // end of TwitchCurve c'tor

        /// <summary>
        /// Applies the curve to the paramter t.  Assumes that t is
        /// in the range [0, 1].
        /// </summary>
        public static float Apply(float t, Shape shape)
        {
            const float overshootAmplitutde = 0.1f;
            float       result = t;

            switch (shape)
            {
            case Shape.Linear:
                result = t;
                break;

            case Shape.EaseIn:
                result = 2.0f * MyMath.SmoothStep(0.0f, 2.0f, t);
                break;

            case Shape.EaseOut:
                result = 2.0f * MyMath.SmoothStep(-1.0f, 1.0f, t) - 1.0f;
                break;

            case Shape.EaseInOut:
                result = MyMath.SmoothStep(0.0f, 1.0f, t);
                break;

            case Shape.OvershootIn:
            {
                t *= 0.5f;
                float smooth = MyMath.SmoothStep(0.0f, 1.0f, t);
                result = smooth - overshootAmplitutde * (float)Math.Cos((t - 0.25f) * MathHelper.TwoPi);
                // Blend toward smooth at tail.
                if (t < 0.1f)
                {
                    result = MyMath.Lerp(smooth, result, t * 10.0f);
                }
                result *= 2.0f;
            }
            break;

            case Shape.OvershootOut:
            {
                t = 0.5f + t * 0.5f;
                float smooth = MyMath.SmoothStep(0.0f, 1.0f, t);
                result = smooth - overshootAmplitutde * (float)Math.Cos((t - 0.25f) * MathHelper.TwoPi);
                // Blend toward smooth at tail.
                if (t > 0.9f)
                {
                    result = MyMath.Lerp(smooth, result, (1.0f - t) * 10.0f);
                }
                result = (result - 0.5f) * 2.0f;
            }
            break;

            case Shape.OvershootInOut:
            {
                float smooth = MyMath.SmoothStep(0.0f, 1.0f, t);
                result = smooth - overshootAmplitutde * (float)Math.Cos((t - 0.25f) * MathHelper.TwoPi);
                // Blend toward smooth at tails.
                if (t < 0.1f)
                {
                    result = MyMath.Lerp(smooth, result, t * 10.0f);
                }
                else if (t > 0.9f)
                {
                    result = MyMath.Lerp(smooth, result, (1.0f - t) * 10.0f);
                }
            }
            break;
            }

            return(result);
        } // TwitchCurve Apply()