示例#1
0
        public void Serialize(AnimationSerializeContext context)
        {
            context.bw.Write(isLooped);
            context.bw.WriteNullableString(friendlyName);

            context.bw.Write(Frames.Count);
            for (var i = 0; i < Frames.Count; i++)
            {
                Frames[i].Serialize(context);
            }


            if (!context.monitor)
            {
                cachedBounds = new Bounds(CalculateGraphicsBounds());
            }
            if (context.Version >= 35)
            {
                context.bw.Write(cachedBounds);
            }


            context.bw.Write(isShared);
            context.bw.WriteNullableString(cue);
            context.bw.WriteBoolean(preventDropMotion);
        }
示例#2
0
        public void Serialize(AnimationSerializeContext context)
        {
            Debug.Assert(slices != null); // <- should never serialize an empty depth bound (check in caller)

            if (heights == null)
            {
                context.bw.Write((int)0);
            }
            else
            {
                context.bw.Write(heights.Length);
                context.bw.Write(heights);
            }

            // NOTE: slices.Length is implicit
            for (int i = 0; i < slices.Length; i++)
            {
                context.bw.Write(slices[i].xOffset);
                context.bw.Write(slices[i].zOffset);

                context.bw.Write(slices[i].depths.Length);
                for (int j = 0; j < slices[i].depths.Length; j++)
                {
                    context.bw.Write(slices[i].depths[j].front);
                    context.bw.Write(slices[i].depths[j].back);
                }
            }
        }
示例#3
0
	    public void Serialize(AnimationSerializeContext context)
	    {
		    context.bw.Write(position);
			targetAnimationContext.Serialize(context.bw);
		    targetAttachmentContext.Serialize(context.bw);
		    attachRange.Serialize(context.bw);
		    context.bw.Write((int)facing);
	    }
示例#4
0
        /// <summary>Check that an AnimationSet round-trips through serialization cleanly</summary>
        public void RoundTripCheck(GraphicsDevice graphicsDevice, bool useExternalImages)
        {
            // Serialize a first time
            var         firstMemoryStream = new MemoryStream();
            var         firstBinaryWriter = new BinaryWriter(firstMemoryStream);
            ImageWriter firstImageWriter  = null;

            if (useExternalImages)
            {
                firstImageWriter = new ImageWriter();
                RegisterImages(firstImageWriter);
                firstImageWriter.WriteOutAllImages(firstMemoryStream);
            }

            var firstSerializeContext = new AnimationSerializeContext(firstBinaryWriter, firstImageWriter);

            Serialize(firstSerializeContext);
            var originalData = firstMemoryStream.ToArray();

            // Then deserialize that data
            var         br          = new BinaryReader(new MemoryStream(originalData));
            ImageBundle imageBundle = null;

            if (useExternalImages)
            {
                var helper = new SimpleTextureLoadHelper(graphicsDevice);
                imageBundle            = new ImageBundle();
                br.BaseStream.Position = imageBundle.ReadAllImages(originalData, (int)br.BaseStream.Position, helper);
            }

            var deserializeContext = new AnimationDeserializeContext(br, imageBundle, graphicsDevice);
            var deserialized       = new AnimationSet(deserializeContext);

            // Then serialize that deserialized data and see if it matches
            // (Ideally we'd recursivly check the AnimationSet to figure out if it matches, but that's a bit too hard)
            var         secondMemoryStream = new MemoryCompareStream(originalData);
            var         secondBinaryWriter = new BinaryWriter(secondMemoryStream);
            ImageWriter secondImageWriter  = null;

            if (useExternalImages)
            {
                secondImageWriter = new ImageWriter();
                deserialized.RegisterImages(secondImageWriter);
                secondImageWriter.WriteOutAllImages(secondMemoryStream);
            }

            var secondSerializeContext = new AnimationSerializeContext(secondBinaryWriter, secondImageWriter);

            deserialized.Serialize(secondSerializeContext);

            // Clean-up:
            if (imageBundle != null)
            {
                imageBundle.Dispose();
            }
        }
示例#5
0
        public void Serialize(AnimationSerializeContext context)
        {
            context.bw.WriteNullableString(friendlyName);
            spriteRef.Serialize(context);

            if (context.bw.WriteBoolean(shadowReceiver != null))
            {
                shadowReceiver.Serialize(context);
            }
        }
示例#6
0
文件: Mask.cs 项目: zcxxv1213/Pixel3D
        public void Serialize(AnimationSerializeContext context)
        {
            if (context.Version < 37)
            {
                context.bw.WriteNullableString(string.Empty); // was friendly name
            }
            context.bw.Write(isGeneratedAlphaMask);

            Debug.Assert(!Asserts.enabled || data.Valid);
            data.Serialize(context.bw);
        }
示例#7
0
        public void Serialize(AnimationSerializeContext context)
        {
            context.bw.Write(delay);
            context.bw.Write(positionDelta);
            context.bw.Write(shadowOffset);

            context.bw.Write(SnapToGround);

            // NOTE: This walks the layer linked list twice, but is only O(n), so no biggie
            int layerCount = layers.Count;

            context.bw.Write(layerCount);
            foreach (var cel in layers)
            {
                cel.Serialize(context);
            }

            masks.Serialize(context, m => m.Serialize(context));

            outgoingAttachments.Serialize(context, oa => oa.Serialize(context));
            incomingAttachments.Serialize(context, p => context.bw.Write(p));

            if (triggers == null)
            {
                context.bw.Write((int)0);
            }
            else
            {
                context.bw.Write(triggers.Count);
                for (int i = 0; i < triggers.Count; i++)
                {
                    context.bw.Write(triggers[i]);
                }
            }

            context.bw.Write(attachAtLayer.Clamp(0, layers.Count));
            context.bw.Write(canDrawLayersAboveSortedAttachees);

            context.bw.WriteNullableString(cue);
        }
示例#8
0
        public void Serialize(AnimationSerializeContext context)
        {
            if (Asserts.enabled && !ValidateAlphaMasks())
            {
                throw new InvalidOperationException("Attempting to save animation set with missing or invalid alpha masks");
            }

            context.bw.WriteNullableString(friendlyName);
            context.bw.Write(importOrigin);
            context.bw.WriteNullableString(behaviour);

            if (context.bw.WriteBoolean(Heightmap != null))
            {
                Heightmap.Serialize(context);
            }


            // If you don't seem to have set any physics bounds, I will just generate them...
            if ((physicsStartX == 0 && physicsEndX == 1 && physicsStartZ == 0 && physicsEndZ == 1 && physicsHeight == 0) || physicsEndX - physicsStartX <= 0)
            {
                AutoGeneratePhysicsAndDepthBounds();
            }


            // NOTE: only writing out values that cannot be auto-generated
            if (Heightmap != null)
            {
                Debug.Assert(!Asserts.enabled || Heightmap.IsObjectHeightmap || physicsHeight == 0);
                context.bw.Write(physicsHeight);
                if (physicsHeight > 0)
                {
                    depthBounds.Serialize(context);
                }
                context.bw.Write(flatDirection); // <- for the sake of editing, keep this value around
            }
            else
            {
                context.bw.Write(physicsStartX);
                context.bw.Write(physicsEndX);
                context.bw.Write(physicsStartZ);
                context.bw.Write(physicsHeight);
                context.bw.Write(flatDirection);

                if (physicsHeight == 0)
                {
                    context.bw.Write(physicsEndZ);
                }
            }

            if (context.Version >= 38)
            {
                context.bw.Write(coplanarPriority);
            }

            if (context.Version >= 36)
            {
                context.bw.Write(doAboveCheck);
            }

            if (context.bw.WriteBoolean(Ceiling != null))
            {
                Ceiling.Serialize(context);
            }


            animations.Serialize(context, a => a.Serialize(context));


            // Unused Animations
            {
                if (unusedAnimations == null)
                {
                    context.bw.Write(0); // unused animations is lazy-initialized
                }
                else
                {
                    context.bw.Write(unusedAnimations.Count);
                    foreach (var animation in unusedAnimations)
                    {
                        animation.Serialize(context);
                    }
                }
            }

            context.bw.WriteNullableString(cue);


            // Shadow layers:
            {
                if (shadowLayers == null)
                {
                    context.bw.Write((int)0);
                }
                else
                {
                    context.bw.Write(shadowLayers.Count);
                    foreach (var sl in shadowLayers)
                    {
                        context.bw.Write(sl.startHeight);
                        sl.shadowSpriteRef.Serialize(context);
                    }

                    RecalculateCachedShadowBounds();
                    context.bw.Write(cachedShadowBounds);
                }
            }
        }