Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the Tower class.
        /// </summary>
        /// <param name="reader">The Content Reader for Castle XML Files</param>
        public Tower(ContentReader reader)
        {
            id = reader.ReadInt32();
              hasCannon = reader.ReadBoolean();
              var position = reader.ReadObject<Vector2>();
              x = (int)position.X;
              y = (int)position.Y;
              height = reader.ReadSingle();
              corners = reader.ReadInt32();
              radius = reader.ReadSingle();
              coverRadius = reader.ReadSingle();
              coverHeight = reader.ReadSingle();
              viewDirection = new Vector3(x, coverHeight + 2, y + 1);

              wallTexture = reader.ReadExternalReference<Texture2D>();
              coverTexture = reader.ReadExternalReference<Texture2D>();

              ////InitTowerGraphics();

              if (HasCannon)
              {
            hasCannon = true;
            cannon = new Cannon(X, coverHeight, Y, null);
              }
        }
Exemple #2
0
        internal ObjectLayer(ContentReader reader, ObjectRegistry registry)
            : base(reader)
        {
            _registry = registry;
            _objects = new List<ObjectInstance>();

            int objCount = reader.ReadInt32();
            for (int i = 0; i < objCount; i++) {
                int id = reader.ReadInt32();
                int dx = reader.ReadInt32();
                int dy = reader.ReadInt32();
                float rotation = reader.ReadSingle();
                float scaleX = reader.ReadSingle();
                float scaleY = reader.ReadSingle();

                PropertyCollection properties = new PropertyCollection(reader);

                _objects.Add(new ObjectInstance(_registry.GetObjectPool(id), id, dx, dy) {
                    Rotation = rotation,
                    ScaleX = scaleX,
                    ScaleY = scaleY,
                    Properties = properties,
                });
            }
        }
Exemple #3
0
        public static VGFontData Deserialize(ContentReader reader)
        {
            var data = new VGFontData
            {
                FillRule = (VGFillRule)reader.ReadByte(),
                EmSquareSize = reader.ReadSingle(),
                LeadingSize = reader.ReadSingle(),
                Extents = reader.ReadVector4(),
                Vertices = new StencilVertex[reader.ReadInt32()],
                Glyphs = new VGFontData.GlyphInfo[reader.ReadInt32()]
            };

            for (int i = 0; i < data.Vertices.Length; i++)
                data.Vertices[i] = StencilVertex.Deserialize(reader);

            for (int i = 0; i < data.Glyphs.Length; i++)
                data.Glyphs[i] = new VGFontData.GlyphInfo
                {
                    Character = reader.ReadChar(),
                    Offset = reader.ReadInt32(),
                    Triangles = reader.ReadInt32(),
                    Escape = new Vector2
                    {
                        X = reader.ReadSingle(),
                        Y = reader.ReadSingle()
                    }
                };

            data.Kerning = VGKerningTable.Deserialize(reader);
            return data;
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the Wall class.
 /// Important: SetFromToVectors must be called afterwards!
 /// </summary>
 /// <param name="reader">The Content Type Reader.</param>
 public Wall(ContentReader reader)
 {
     fromIndex = reader.ReadInt32();
       toIndex = reader.ReadInt32();
       height = reader.ReadSingle();
       wallTexture = reader.ReadExternalReference<Texture2D>();
 }
Exemple #5
0
        internal Layer(ContentReader reader)
        {
            ScaleX = 1f;
            ScaleY = 1f;

            Id = reader.ReadInt16();
            Name = reader.ReadString();
            Visible = reader.ReadBoolean();
            Opacity = reader.ReadSingle();
            Properties = new PropertyCollection(reader);
        }
Exemple #6
0
        protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance)
        {
            AlphaTestEffect effect = new AlphaTestEffect(input.ContentManager.GetGraphicsDevice());

            effect.Texture            = input.ReadExternalReference <Texture>() as Texture2D;
            effect.AlphaFunction      = (CompareFunction)input.ReadInt32();
            effect.ReferenceAlpha     = (int)input.ReadUInt32();
            effect.DiffuseColor       = input.ReadVector3();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
Exemple #7
0
        protected internal override BasicEffect Read(
            ContentReader input,
            BasicEffect existingInstance
            )
        {
            BasicEffect effect  = new BasicEffect(input.GraphicsDevice);
            Texture2D   texture = input.ReadExternalReference <Texture>() as Texture2D;

            if (texture != null)
            {
                effect.Texture        = texture;
                effect.TextureEnabled = true;
            }
            effect.DiffuseColor       = input.ReadVector3();
            effect.EmissiveColor      = input.ReadVector3();
            effect.SpecularColor      = input.ReadVector3();
            effect.SpecularPower      = input.ReadSingle();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
 protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance)
 {
     return(new AlphaTestEffect(input.GraphicsDevice)
     {
         Texture = input.ReadExternalReference <Texture>() as Texture2D,
         AlphaFunction = (CompareFunction)input.ReadInt32(),
         ReferenceAlpha = (int)input.ReadUInt32(),
         DiffuseColor = input.ReadVector3(),
         Alpha = input.ReadSingle(),
         VertexColorEnabled = input.ReadBoolean()
     });
 }
        protected internal override SpriteFont Read(ContentReader input, SpriteFont existingInstance)
        {
            if (existingInstance != null)
            {
                // Read the texture into the existing texture instance
                input.ReadObject <Texture2D>(existingInstance._texture);

                // discard the rest of the SpriteFont data as we are only reloading GPU resources for now
                input.ReadObject <List <Rectangle> >();
                input.ReadObject <List <Rectangle> >();
                input.ReadObject <List <char> >();
                input.ReadInt32();
                input.ReadSingle();
                input.ReadObject <List <Vector3> >();
                if (input.ReadBoolean())
                {
                    input.ReadChar();
                }

                return(existingInstance);
            }
            else
            {
                // Create a fresh SpriteFont instance
                Texture2D        texture        = input.ReadObject <Texture2D>();
                List <Rectangle> glyphs         = input.ReadObject <List <Rectangle> >();
                List <Rectangle> cropping       = input.ReadObject <List <Rectangle> >();
                List <char>      charMap        = input.ReadObject <List <char> >();
                int            lineSpacing      = input.ReadInt32();
                float          spacing          = input.ReadSingle();
                List <Vector3> kerning          = input.ReadObject <List <Vector3> >();
                char?          defaultCharacter = null;
                if (input.ReadBoolean())
                {
                    defaultCharacter = new char?(input.ReadChar());
                }
                return(new SpriteFont(texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultCharacter));
            }
        }
Exemple #10
0
        protected internal override DualTextureEffect Read(
            ContentReader input,
            DualTextureEffect existingInstance
            )
        {
            DualTextureEffect effect = new DualTextureEffect(input.ContentManager.GetGraphicsDevice());

            effect.Texture            = input.ReadExternalReference <Texture>() as Texture2D;
            effect.Texture2           = input.ReadExternalReference <Texture>() as Texture2D;
            effect.DiffuseColor       = input.ReadVector3();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
Exemple #11
0
        protected internal override Curve Read(ContentReader input, Curve existingInstance)
        {
            Curve curve = existingInstance;

            if (curve == null)
            {
                curve = new Curve();
            }

            curve.PreLoop  = (CurveLoopType)input.ReadInt32();
            curve.PostLoop = (CurveLoopType)input.ReadInt32();
            int num6 = input.ReadInt32();

            for (int i = 0; i < num6; i++)
            {
                float           position   = input.ReadSingle();
                float           num4       = input.ReadSingle();
                float           tangentIn  = input.ReadSingle();
                float           tangentOut = input.ReadSingle();
                CurveContinuity continuity = (CurveContinuity)input.ReadInt32();
                curve.Keys.Add(new CurveKey(position, num4, tangentIn, tangentOut, continuity));
            }
            return(curve);
        }
Exemple #12
0
        protected internal override SpriteFont Read(ContentReader input, SpriteFont existingInstance)
        {
            Texture2D texture = input.ReadObject <Texture2D>();

            texture.IsSpriteFontTexture = true;
            List <Rectangle> glyphs         = input.ReadObject <List <Rectangle> >();
            List <Rectangle> cropping       = input.ReadObject <List <Rectangle> >();
            List <char>      charMap        = input.ReadObject <List <char> >();
            int            lineSpacing      = input.ReadInt32();
            float          spacing          = input.ReadSingle();
            List <Vector3> kerning          = input.ReadObject <List <Vector3> >();
            char?          defaultCharacter = null;

            if (input.ReadBoolean())
            {
                defaultCharacter = new char?(input.ReadChar());
            }
            return(new SpriteFont(texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultCharacter));
        }
Exemple #13
0
 private void ReadMeshes(ContentReader input, VertexDeclaration[] vertexDeclarations)
 {
     int length = input.ReadInt32();
     ModelMesh[] meshes = new ModelMesh[length];
     for (int i = 0; i < length; i++)
     {
         string name = input.ReadObject<string>();
         ModelBone parentBone = this.ReadBoneReference(input);
         BoundingSphere boundingSphere = new BoundingSphere();
         boundingSphere.Center = input.ReadVector3();
         boundingSphere.Radius = input.ReadSingle();
         VertexBuffer vertexBuffer = input.ReadObject<VertexBuffer>();
         IndexBuffer indexBuffer = input.ReadObject<IndexBuffer>();
         object tag = input.ReadObject<object>();
         ModelMeshPart[] meshParts = ReadMeshParts(input, vertexBuffer, indexBuffer, vertexDeclarations);
         meshes[i] = new ModelMesh(name, parentBone, boundingSphere, vertexBuffer, indexBuffer, meshParts, tag);
     }
     this.meshes = new ModelMeshCollection(meshes);
 }
 protected internal override float Read(ContentReader input, float existingInstance)
 {
     return(input.ReadSingle());
 }
        internal static SkinnedModelBasicEffect Read(ContentReader input)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
                    input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice graphicsDevice = graphicsDeviceService.GraphicsDevice;
            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(graphicsDevice,
                (EffectPool)null);

            basicEffect.material.EmissiveColor = input.ReadVector3();
            basicEffect.material.DiffuseColor = input.ReadVector3();
            basicEffect.material.SpecularColor = input.ReadVector3();
            basicEffect.material.SpecularPower = input.ReadSingle();

            basicEffect.DiffuseMapEnabled = input.ReadBoolean();
            basicEffect.NormalMapEnabled = input.ReadBoolean();
            basicEffect.SpecularMapEnabled = input.ReadBoolean();
            basicEffect.DiffuseMap = input.ReadObject<Texture2D>(); ;
            basicEffect.NormalMap = input.ReadObject<Texture2D>(); ;
            basicEffect.SpecularMap = input.ReadObject<Texture2D>(); ;

            basicEffect.lightEnabled = false;
            basicEffect.enabledLights = EnabledLights.One;

            return basicEffect;
        }
        internal static SkinnedModelBasicEffect Read(ContentReader input)
        {
            Effect effect = input.ReadObject<Effect>();

            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(effect);

            basicEffect.material.EmissiveColor = input.ReadVector3();
            basicEffect.material.DiffuseColor = input.ReadVector3();
            basicEffect.material.SpecularColor = input.ReadVector3();
            basicEffect.material.SpecularPower = input.ReadSingle();

            basicEffect.DiffuseMapEnabled = input.ReadBoolean();
            basicEffect.NormalMapEnabled = input.ReadBoolean();
            basicEffect.SpecularMapEnabled = input.ReadBoolean();

            basicEffect.DiffuseMap = input.ReadExternalReference<Texture2D>();
            basicEffect.NormalMap = input.ReadExternalReference<Texture2D>();
            basicEffect.SpecularMap = input.ReadExternalReference<Texture2D>();

            basicEffect.lightEnabled = false;
            basicEffect.enabledLights = EnabledLights.One;

            return basicEffect;
        }
Exemple #17
0
        internal Map(ContentReader reader)
        {
            // read in the basic map information
            Version = new Version(reader.ReadString());
            Orientation = (Orientation)reader.ReadByte();
            Width = reader.ReadInt32();
            Height = reader.ReadInt32();
            TileWidth = reader.ReadInt32();
            TileHeight = reader.ReadInt32();
            Properties = new PropertyCollection();
            Properties.Read(reader);

            // create a list for our tiles
            List<Tile> tiles = new List<Tile>();
            Tiles = new Collection<Tile>(tiles);

            // read in each tile set
            int numTileSets = reader.ReadInt32();
            for (int i = 0; i < numTileSets; i++)
            {
                // get the id and texture
                int firstId = reader.ReadInt32();
                string tilesetName = reader.ReadString();

                bool collisionSet = reader.ReadBoolean();

                Texture2D texture = reader.ReadExternalReference<Texture2D>();

                // read in each individual tile
                int numTiles = reader.ReadInt32();
                for (int j = 0; j < numTiles; j++)
                {
                    int id = firstId + j;

                    // Read the source rectangle from the file.
                    Rectangle source = reader.ReadObject<Rectangle>();

                    PropertyCollection props = new PropertyCollection();
                    props.Read(reader);

                    // Read in color data for collision purposes
                    // You'll probably want to limit this to just the tilesets that are used for collision
                    // I'm checking for the name of my tileset that contains wall tiles
                    // Color data takes up a fair bit of RAM
                    Color[] collisionData = null;
                    bool[] collisionBitData = null;
                    if (collisionSet)
                    {
                        int numOfBytes = TileWidth * TileHeight;
                        collisionData = new Color[numOfBytes];
                        collisionBitData = new bool[numOfBytes];

                        texture.GetData<Color>(
                            0,
                            source,
                            collisionData,
                            0,
                            numOfBytes
                        );

                        for (int col = 0; col < numOfBytes; col++)
                        {
                            if (collisionData[col].A > 0)
                            {
                                collisionBitData[col] = true;
                            }
                        }
                        collisionData = null;
                    }

                    Tile t = new Tile(texture, source, props, collisionBitData);
                    while (id >= tiles.Count)
                    {
                        tiles.Add(null);
                    }
                    tiles.Insert(id, t);
                }
            }

            // read in all the layers
            List<Layer> layers = new List<Layer>();
            Layers = new Collection<Layer>(layers);
            int numLayers = reader.ReadInt32();
            for (int i = 0; i < numLayers; i++)
            {
                Layer layer = null;

                // read generic layer data
                string type = reader.ReadString();
                string name = reader.ReadString();
                int width = reader.ReadInt32();
                int height = reader.ReadInt32();
                bool visible = reader.ReadBoolean();
                float opacity = reader.ReadSingle();
                PropertyCollection props = new PropertyCollection();
                props.Read(reader);

                // using the type, figure out which object to create
                if (type == "layer")
                {
                    int[] data = reader.ReadObject<int[]>();
                    layer = new TileLayer(name, width, height, visible, opacity, props, this, data);
                }
                else if (type == "objectgroup")
                {
                    List<MapObject> objects = new List<MapObject>();

                    // read in all of our objects
                    int numObjects = reader.ReadInt32();
                    for (int j = 0; j < numObjects; j++)
                    {
                        string objName = reader.ReadString();
                        string objType = reader.ReadString();
                        Rectangle objLoc = reader.ReadObject<Rectangle>();
                        List<Point> objPoints = reader.ReadObject<List<Point>>();
                        PropertyCollection objProps = new PropertyCollection();
                        objProps.Read(reader);

                        objects.Add(new MapObject(objName, objType, objLoc, objPoints, objProps));
                    }

                    layer = new MapObjectLayer(name, width, height, visible, opacity, props, objects);
                }
                else
                {
                    throw new Exception("Invalid type: " + type);
                }

                layers.Add(layer);
                namedLayers.Add(name, layer);
            }
        }
Exemple #18
0
 protected internal override BoundingSphere Read(ContentReader input, BoundingSphere existingInstance)
 {
     return(new BoundingSphere(input.ReadVector3(), input.ReadSingle()));
 }
 protected internal override Matrix4x4 Read(
     ContentReader input,
     Matrix4x4 existingInstance
     )
 {
     // 4x4 matrix
     return(new Matrix4x4(
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle(),
                input.ReadSingle()
                ));
 }
Exemple #20
0
        internal Map(ContentReader reader)
        {
            // read in the basic map information
            Version = new Version(reader.ReadString());
            Orientation = (Orientation)reader.ReadByte();
            WidthInTiles = reader.ReadInt32();
            HeightInTiles = reader.ReadInt32();
            TileWidth = reader.ReadInt32();
            TileHeight = reader.ReadInt32();
            Properties = new PropertyCollection(reader);
            bool makeTilesUnique = reader.ReadBoolean();

            // create a list for our tiles
            List<Tile> tiles = new List<Tile>();
            Tiles = new ReadOnlyCollection<Tile>(tiles);

            // read in each tile set
            int numTileSets = reader.ReadInt32();
            for (int i = 0; i < numTileSets; i++)
            {
                // get the id and texture
                int firstId = reader.ReadInt32();
                Texture2D texture = reader.ReadExternalReference<Texture2D>();

                // read in each individual tile
                int numTiles = reader.ReadInt32();
                for (int j = 0; j < numTiles; j++)
                {
                    int id = firstId + j;
                    Rectangle source = reader.ReadObject<Rectangle>();
                    PropertyCollection props = new PropertyCollection(reader);

                    Tile t = new Tile(texture, source, props);
                    while (id >= tiles.Count)
                    {
                        tiles.Add(null);
                    }
                    tiles.Insert(id, t);
                }
            }

            // read in all the layers
            List<Layer> layers = new List<Layer>();
            Layers = new ReadOnlyCollection<Layer>(layers);
            int numLayers = reader.ReadInt32();
            for (int i = 0; i < numLayers; i++)
            {
                Layer layer = null;

                // read generic layer data
                string type = reader.ReadString();
                string name = reader.ReadString();
                int width = reader.ReadInt32();
                int height = reader.ReadInt32();
                bool visible = reader.ReadBoolean();
                float opacity = reader.ReadSingle();
                PropertyCollection props = new PropertyCollection(reader);

                // calculate the default layer depth of the layer
                float layerDepth = 1f - (LayerDepthSpacing * i);

                // using the type, figure out which object to create
                if (type == "layer")
                {
                    uint[] data = reader.ReadObject<uint[]>();
                    layer = new TileLayer(name, width, height, layerDepth, visible, opacity, props, this, data, makeTilesUnique);
                }
                else if (type == "objectgroup")
                {
                    List<MapObject> objects = new List<MapObject>();

                    // read in all of our objects
                    int numObjects = reader.ReadInt32();
                    for (int j = 0; j < numObjects; j++)
                    {
                        string objName = reader.ReadString();
                        string objType = reader.ReadString();
                        Rectangle objLoc = reader.ReadObject<Rectangle>();
                        PropertyCollection objProps = new PropertyCollection(reader);

                        objects.Add(new MapObject(objName, objType, objLoc, objProps));
                    }

                    layer = new MapObjectLayer(name, width, height, layerDepth, visible, opacity, props, objects);

                    // read in the layer's color
                    (layer as MapObjectLayer).Color = reader.ReadColor();
                }
                else
                {
                    throw new Exception("Invalid type: " + type);
                }

                layers.Add(layer);
                namedLayers.Add(name, layer);
            }
        }
        internal static SkinnedEffect Read(ContentReader input)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
                    input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice graphicsDevice = graphicsDeviceService.GraphicsDevice;

            SkinnedEffect basicEffect = new SkinnedEffect(graphicsDevice);


            input.ReadVector3();
            input.ReadVector3();
            input.ReadVector3();
            input.ReadSingle();

            input.ReadBoolean();
            input.ReadBoolean();
            input.ReadBoolean();
            input.ReadObject<Texture2D>(); 
            input.ReadObject<Texture2D>(); 
            input.ReadObject<Texture2D>(); 

            return basicEffect;
        }
        internal static SkinnedModelBasicEffect Read(ContentReader input)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
                    input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice graphicsDevice = graphicsDeviceService.GraphicsDevice;

            //ResourceContentManager cnt = new ResourceContentManager(input.ContentManager.ServiceProvider, Resource1.ResourceManager);            z
#if WINDOWS           
            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(graphicsDevice, Resource1.SkinnedModelEffect);
#else
            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(graphicsDevice, Resource1.SkinnedModelEffect2);
#endif
            

            input.ReadVector3();
            input.ReadVector3();
            input.ReadVector3();
            input.ReadSingle();

            basicEffect.DiffuseMapEnabled = input.ReadBoolean();
            basicEffect.NormalMapEnabled = input.ReadBoolean();
            basicEffect.SpecularMapEnabled = input.ReadBoolean();
            basicEffect.DiffuseMap = input.ReadObject<Texture2D>(); ;
            basicEffect.NormalMap = input.ReadObject<Texture2D>(); ;
            basicEffect.SpecularMap = input.ReadObject<Texture2D>(); ;            

            return basicEffect;
        }
Exemple #23
0
 protected internal override Matrix Read(ContentReader input, Matrix existingInstance)
 {
     return(new Matrix(input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle(), input.ReadSingle()));
 }
Exemple #24
0
 protected internal override Plane Read(ContentReader input, Plane existingInstance)
 {
     existingInstance.Normal = input.ReadVector3();
     existingInstance.D      = input.ReadSingle();
     return(existingInstance);
 }