/// <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>(); }
/// <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); } }
protected internal override EffectMaterial Read( ContentReader input, EffectMaterial existingInstance ) { Effect effect = input.ReadExternalReference <Effect>(); EffectMaterial effectMaterial = new EffectMaterial(effect); Dictionary <string, object> dict = input.ReadObject <Dictionary <string, object> >(); foreach (KeyValuePair <string, object> item in dict) { EffectParameter parameter = effectMaterial.Parameters[item.Key]; if (parameter != null) { if (typeof(Texture).IsAssignableFrom(item.Value.GetType())) { parameter.SetValue((Texture)item.Value); } else { throw new NotImplementedException(); } } else { Debug.WriteLine("No parameter " + item.Key); } } return(effectMaterial); }
protected internal override EnvironmentMapEffect Read( ContentReader input, EnvironmentMapEffect existingInstance ) { EnvironmentMapEffect effect = new EnvironmentMapEffect(input.ContentManager.GetGraphicsDevice()); effect.Texture = input.ReadExternalReference <Texture>() as Texture2D; effect.EnvironmentMap = input.ReadExternalReference <TextureCube>() as TextureCube; effect.EnvironmentMapAmount = input.ReadSingle(); effect.EnvironmentMapSpecular = input.ReadVector3(); effect.FresnelFactor = input.ReadSingle(); effect.DiffuseColor = input.ReadVector3(); effect.EmissiveColor = input.ReadVector3(); effect.Alpha = input.ReadSingle(); return(effect); }
internal OgmoTileset(ContentReader reader) { this.Name = reader.ReadString(); this.Texture = reader.ReadExternalReference<Texture2D>(); this.TextureFile = reader.ReadString(); this.TileHeight = reader.ReadInt32(); this.TileWidth = reader.ReadInt32(); if (this.Texture != null) this.CreateSources(); }
protected internal override VertexBuffer Read(ContentReader input, VertexBuffer existingInstance) { var declaration = input.ReadExternalReference <VertexDeclaration>(); var vertexCount = (int)input.ReadUInt32(); var data = input.ReadBytes(vertexCount * declaration.VertexStride); var buffer = new VertexBuffer(input.GraphicsDevice, declaration, vertexCount, BufferUsage.WriteOnly); buffer.SetData(data); return(buffer); }
protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance) { var effect = new AlphaTestEffect(input.GraphicsDevice); effect.Texture = input.ReadExternalReference <Texture>() as Texture2D; effect.AlphaFunction = (CompareFunction)input.ReadInt32(); effect.DiffuseColor = input.ReadVector3(); 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() }); }
public SkyBox(ContentReader input) { // Graphics Device-Instanz abrufen this.GraphicsDevice = ((IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice; // Vertices einlesen und Vertex Buffer initialisieren VertexPositionTexture[] vertices = input.ReadObject<VertexPositionTexture[]>(); this.vertexBuffer = new VertexBuffer(this.GraphicsDevice, typeof(VertexPositionTexture), vertices.Length, BufferUsage.None); this.vertexBuffer.SetData<VertexPositionTexture>(vertices); // Anzahl der Vertices speichern this.numVertices = vertices.Length; // Division durch 3 ergibt die Anzahl der Primitive, da eine Dreiecksliste verwendet wird this.numPrimitives = this.numPrimitives / 3; // Vertex-Beschreibung erzeugen this.vertexDeclaration = new VertexDeclaration(VertexPositionTexture.VertexDeclaration.GetVertexElements()); // BasicEffect-Instanz erzeugen this.effect = new BasicEffect(this.GraphicsDevice); // Texturen einlesen this.frontTexture = input.ReadExternalReference<Texture2D>(); this.backTexture = input.ReadExternalReference<Texture2D>(); this.leftTexture = input.ReadExternalReference<Texture2D>(); this.rightTexture = input.ReadExternalReference<Texture2D>(); this.topTexture = input.ReadExternalReference<Texture2D>(); this.bottomTexture = input.ReadExternalReference<Texture2D>(); }
protected internal override SkinnedEffect Read(ContentReader input, SkinnedEffect existingInstance) { return(new SkinnedEffect(input.GraphicsDevice) { Texture = input.ReadExternalReference <Texture>() as Texture2D, WeightsPerVertex = input.ReadInt32(), DiffuseColor = input.ReadVector3(), EmissiveColor = input.ReadVector3(), SpecularColor = input.ReadVector3(), SpecularPower = input.ReadSingle(), Alpha = input.ReadSingle() }); }
protected internal override SkinnedEffect Read(ContentReader input, SkinnedEffect existingInstance) { var effect = new SkinnedEffect(input.GraphicsDevice); effect.Texture = input.ReadExternalReference <Texture> () as Texture2D; effect.WeightsPerVertex = input.ReadInt32(); effect.DiffuseColor = input.ReadVector3(); effect.EmissiveColor = input.ReadVector3(); effect.SpecularColor = input.ReadVector3(); effect.SpecularPower = input.ReadSingle(); effect.Alpha = input.ReadSingle(); return(effect); }
protected internal override BasicEffect Read(ContentReader input, BasicEffect existingInstance) { BasicEffect basicEffect = new BasicEffect(input.GraphicsDevice); Texture2D texture2D = input.ReadExternalReference <Texture>() as Texture2D; if (texture2D != null) { basicEffect.Texture = texture2D; basicEffect.TextureEnabled = true; } basicEffect.DiffuseColor = input.ReadVector3(); basicEffect.EmissiveColor = input.ReadVector3(); basicEffect.SpecularColor = input.ReadVector3(); basicEffect.SpecularPower = input.ReadSingle(); basicEffect.Alpha = input.ReadSingle(); basicEffect.VertexColorEnabled = input.ReadBoolean(); return(basicEffect); }
protected internal override EffectMaterial Read(ContentReader input, EffectMaterial existingInstance) { EffectMaterial effectMaterial = new EffectMaterial(input.ReadExternalReference <Effect>()); foreach (KeyValuePair <string, object> keyValuePair in input.ReadObject <Dictionary <string, object> >()) { EffectParameter effectParameter = effectMaterial.Parameters[keyValuePair.Key]; if (effectParameter != null) { if (!typeof(Texture).IsAssignableFrom(keyValuePair.Value.GetType())) { throw new NotImplementedException(); } effectParameter.SetValue((Texture)keyValuePair.Value); } } return(effectMaterial); }
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 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; }
protected internal override object Read(ContentReader input, object existingInstance) { return input.ReadExternalReference<object>(); }
protected internal override EffectMaterial Read(ContentReader input, EffectMaterial existingInstance) { var effect = input.ReadExternalReference <Effect> (); var effectMaterial = new EffectMaterial(effect); var dict = input.ReadObject <Dictionary <string, object> > (); foreach (KeyValuePair <string, object> item in dict) { var parameter = effectMaterial.Parameters [item.Key]; if (parameter != null) { Type itemType = item.Value.GetType(); if (ReflectionHelpers.IsAssignableFromType(typeof(Texture), itemType)) { parameter.SetValue((Texture)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(int), itemType)) { parameter.SetValue((int)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(bool), itemType)) { parameter.SetValue((bool)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(float), itemType)) { parameter.SetValue((float)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(float []), itemType)) { parameter.SetValue((float[])item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Vector2), itemType)) { parameter.SetValue((Vector2)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Vector2 []), itemType)) { parameter.SetValue((Vector2 [])item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Vector3), itemType)) { parameter.SetValue((Vector3)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Vector3 []), itemType)) { parameter.SetValue((Vector3 [])item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Vector4), itemType)) { parameter.SetValue((Vector4)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Vector4 []), itemType)) { parameter.SetValue((Vector4 [])item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Matrix), itemType)) { parameter.SetValue((Matrix)item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Matrix []), itemType)) { parameter.SetValue((Matrix[])item.Value); } else if (ReflectionHelpers.IsAssignableFromType(typeof(Quaternion), itemType)) { parameter.SetValue((Quaternion)item.Value); } else { throw new NotSupportedException("Parameter type is not supported"); } } else { Debug.WriteLine("No parameter " + item.Key); } } return(effectMaterial); }
protected internal override object Read(ContentReader input, object existingInstance) { return(input.ReadExternalReference <object>()); }
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); } }
private void loadTextures(ContentReader input, int textures_count) { list_textures = new Dictionary<string, Texture>(); for (int i = 0; i < textures_count; ++i) { string key = input.ReadString(); Texture texture = input.ReadExternalReference<Texture>(); list_textures.Add(key, texture); } }