Ejemplo n.º 1
0
 public void RegenerateDepthBounds()
 {
     if (Heightmap == null)
     {
         if (physicsHeight == 0)
         {
             depthBounds = default(DepthBounds);
         }
         else
         {
             physicsEndZ = physicsStartZ + DepthBounds.CalculateFlatPhysicsDepth(physicsEndX - physicsStartX, flatDirection);
             depthBounds = DepthBounds.CreateForFlat(this);
         }
     }
     else
     {
         depthBounds = DepthBounds.CreateForHeightmap(Heightmap);
     }
 }
Ejemplo n.º 2
0
        public AnimationSet(AnimationDeserializeContext context)
        {
            friendlyName = context.br.ReadNullableString();
            importOrigin = context.br.ReadPoint();
            behaviour    = context.br.ReadNullableString();

            if (context.br.ReadBoolean())
            {
                Heightmap = new Heightmap(context);
            }

            if (Heightmap != null)
            {
                physicsStartX = Heightmap.StartX;
                physicsEndX   = Heightmap.EndX;
                physicsStartZ = Heightmap.StartZ;
                physicsEndZ   = Heightmap.EndZ;
                // Assume that reading is faster than walking the heightmap:
                physicsHeight = context.br.ReadInt32();
                if (physicsHeight > 0)
                {
                    depthBounds = new DepthBounds(context);
                }
                flatDirection = context.br.ReadOblique(); // <- for the sake of editing, keep this value around
            }
            else
            {
                physicsStartX = context.br.ReadInt32();
                physicsEndX   = context.br.ReadInt32();
                physicsStartZ = context.br.ReadInt32();
                physicsHeight = context.br.ReadInt32();
                flatDirection = context.br.ReadOblique();

                if (physicsHeight == 0)
                {
                    physicsEndZ = context.br.ReadInt32(); // physicsEndZ gets auto-set during regen, except for carpets
                }
                RegenerateDepthBounds();                  // <- Know this is reasonably fast to generate
            }

            if (context.Version >= 38)
            {
                coplanarPriority = context.br.ReadInt32();
            }

            if (context.Version >= 36)
            {
                doAboveCheck = context.br.ReadBoolean();
            }

            if (context.br.ReadBoolean())
            {
                Ceiling = new Heightmap(context);
            }

            animations = new TagLookup <Animation>(context, () => new Animation(context));


            // Unused Animations
            {
                int count = context.br.ReadInt32();
                if (count > 0) // unusedAnimations is lazy-initialized
                {
                    unusedAnimations = new List <Animation>(count);
                    for (int i = 0; i < count; i++)
                    {
                        unusedAnimations.Add(new Animation(context));
                    }
                }
            }

            cue = context.br.ReadNullableString();


            // Shadow layers
            {
                int shadowLayerCount = context.br.ReadInt32();
                if (shadowLayerCount <= 0)
                {
                    shadowLayers = null;
                }
                else
                {
                    shadowLayers = new List <ShadowLayer>();
                    for (int i = 0; i < shadowLayerCount; i++)
                    {
                        shadowLayers.Add(new ShadowLayer(
                                             context.br.ReadInt32(),
                                             new SpriteRef(context)));
                    }

                    cachedShadowBounds = context.br.ReadBounds();
                }
            }


            //
            // FIX-UPS:
            //

            // TODO: Commenting this out and seeing if anything breaks (remove it eventually) -AR 7/7/16
            //if(physicsStartX == physicsEndX) // <- Why do we have zero width?
            //{
            //    Debug.WriteLine("WARNING: AnimationSet \"" + friendlyName + "\" has zero physics width");
            //    AutoGeneratePhysicsAndDepthBounds();
            //}
        }
Ejemplo n.º 3
0
        public AnimationSet(AnimationDeserializeContext context)
        {
            friendlyName = context.br.ReadNullableString();
            importOrigin = context.br.ReadPoint();
            behaviour    = context.br.ReadNullableString();

            if (context.br.ReadBoolean())
            {
                Heightmap = new Heightmap(context);
            }

            if (Heightmap != null)
            {
                physicsStartX = Heightmap.StartX;
                physicsEndX   = Heightmap.EndX;
                physicsStartZ = Heightmap.StartZ;
                physicsEndZ   = Heightmap.EndZ;

                // Assume that reading is faster than walking the heightmap:
                physicsHeight = context.br.ReadInt32();
                if (physicsHeight > 0)
                {
                    depthBounds = new DepthBounds(context);
                }
                flatDirection =
                    context.br.ReadOblique(); // <- for the sake of editing, keep this value around
            }
            else
            {
                physicsStartX = context.br.ReadInt32();
                physicsEndX   = context.br.ReadInt32();
                physicsStartZ = context.br.ReadInt32();
                physicsHeight = context.br.ReadInt32();
                flatDirection = context.br.ReadOblique();

                if (physicsHeight == 0)
                {
                    physicsEndZ =
                        context.br.ReadInt32(); // physicsEndZ gets auto-set during regen, except for carpets
                }
                RegenerateDepthBounds();        // <- Know this is reasonably fast to generate
            }

            if (context.Version >= 38)
            {
                coplanarPriority = context.br.ReadInt32();
            }

            if (context.Version >= 36)
            {
                doAboveCheck = context.br.ReadBoolean();
            }

            if (context.br.ReadBoolean())
            {
                Ceiling = new Heightmap(context);
            }

            animations = context.DeserializeTagLookup(() => new Animation(context));

            // Unused Animations
            {
                int count = context.br.ReadInt32();
                if (count > 0) // unusedAnimations is lazy-initialized
                {
                    unusedAnimations = new List <Animation>(count);
                    for (var i = 0; i < count; i++)
                    {
                        unusedAnimations.Add(new Animation(context));
                    }
                }
            }

            cue = context.br.ReadNullableString();

            // Shadow layers
            {
                int shadowLayerCount = context.br.ReadInt32();
                if (shadowLayerCount <= 0)
                {
                    shadowLayers = null;
                }
                else
                {
                    shadowLayers = new List <ShadowLayer>();
                    for (var i = 0; i < shadowLayerCount; i++)
                    {
                        shadowLayers.Add(new ShadowLayer(context.br.ReadInt32(), new SpriteRef(context)));
                    }

                    cachedShadowBounds = context.br.ReadBounds();
                }
            }

            // Properties:
            if (context.Version >= 40)
            {
                int count = context.br.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    properties.Add(context.br.ReadString(), context.br.ReadString());
                }
            }
        }