Ejemplo n.º 1
0
        public object ReadContent(IAssetProvider readerManager, ref ContentReaderParameters parameters)
        {
            parameters.KeepStreamOpen = false;
            var image = Image.Load(parameters.Stream);

            if (image != null)
            {
                image.Name = parameters.AssetName;
            }
            return(image);
        }
Ejemplo n.º 2
0
 public object ReadContent(IAssetProvider assetManager, ref ContentReaderParameters parameters)
 {
     try
     {
         DataContractSerializer serializer = new DataContractSerializer(typeof(EngineReference[]));
         var data = (EngineReference[])serializer.ReadObject(parameters.Stream);
         return(new EngineReferenceCollection(data));
     }
     catch (SerializationException e)
     {
         LogEvent.Tool.Error(e.Message);
         throw;
     }
 }
Ejemplo n.º 3
0
        public object ReadContent(IAssetProvider assetManager, ref ContentReaderParameters parameters)
        {
            var xmlReaderSettings = new XmlReaderSettings()
            {
                IgnoreComments   = true,
                IgnoreWhitespace = true,
            };
            var   content = parameters.Services.GetService <IAssetProvider>();
            Theme theme   = content.Contains(parameters.AssetName) ? content.Load <Theme>(parameters.AssetName) : new Theme();

            theme.DeserializeXml(theme, XmlReader.Create(parameters.Stream, xmlReaderSettings));

            return(theme);
        }
Ejemplo n.º 4
0
        public object ReadContent(IAssetProvider assetManager, ref ContentReaderParameters parameters)
        {
            var xmlReaderSettings = new XmlReaderSettings()
            {
                IgnoreComments   = true,
                IgnoreWhitespace = true,
            };

            var xmlReader = XmlReader.Create(parameters.Stream, xmlReaderSettings);
            var cutscene  = new Cutscene(parameters.Services);
            var scene     = parameters.Services.GetService <IResourceProvider>();

            cutscene.DeserializeXml(scene, xmlReader);
            return(cutscene);
        }
Ejemplo n.º 5
0
        object IContentReader.ReadContent(IAssetProvider readerManager, ref ContentReaderParameters parameters)
        {
            parameters.KeepStreamOpen = false;
            var service = readerManager.Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;

            if (service == null)
            {
                throw new InvalidOperationException("Unable to retrieve a IDirectXDeviceService service provider");
            }

            if (service.DirectXDevice == null)
            {
                throw new InvalidOperationException("DirectXDevice is not initialized");
            }

            return(ReadContent(readerManager, service.DirectXDevice, ref parameters));
        }
Ejemplo n.º 6
0
        public object ReadContent(IAssetProvider assetManager, ref ContentReaderParameters parameters)
        {
            var shaderCollection = new ShaderCollection();

            try
            {
                var bs = new BinarySerializer(parameters.Stream, SerializerMode.Read)
                {
                    AllowIdentity = true
                };
                bs.Serialize(ref shaderCollection);
            }
            catch (SerializationException e)
            {
                LogEvent.Tool.Error(e.Message);
                throw;
            }
            return(shaderCollection);
        }
Ejemplo n.º 7
0
        private object LoadAsset(string assetName, Stream stream, Type type, object options = null)
        {
            object result;

            var parameters = new ContentReaderParameters
            {
                AssetName = assetName,
                AssetType = type,
                Stream    = stream,
                Options   = options,
                Services  = services
            };

            try
            {
                IContentReader contentReader;
                lock (registeredContentReaders)
                {
                    if (!registeredContentReaders.TryGetValue(type, out contentReader))
                    {
#if WIN8METRO
                        var contentReaderAttribute =
                            SharpDX.Utilities.GetCustomAttribute <ContentReaderAttribute>(type.GetTypeInfo(), true);
#else
                        var contentReaderAttribute = SharpDX.Utilities.GetCustomAttribute <ContentReaderAttribute>(type, true);
#endif

                        if (contentReaderAttribute != null)
                        {
                            contentReader = Activator.CreateInstance(contentReaderAttribute.ContentReaderType) as IContentReader;
                            if (contentReader != null)
                            {
                                Readers.Add(type, contentReader);
                            }
                        }
                    }
                }

                if (contentReader == null)
                {
                    throw new NotSupportedException(string.Format(
                                                        "Type [{0}] doesn't provide a ContentReaderAttribute, and there is no registered content reader for it.",
                                                        type.FullName));
                }

                result = contentReader.ReadContent(this, ref parameters);

                if (result == null)
                {
                    throw new NotSupportedException(string.Format(
                                                        "Registered ContentReader of type [{0}] fails to load content of type [{1}] from file [{2}].",
                                                        contentReader.GetType(), type.FullName, assetName));
                }
            }
            finally
            {
                // If we don't need to keep the stream open, then we can close it
                // and make sure that we will close the stream even if there is an exception.
                if (!parameters.KeepStreamOpen)
                {
                    stream.Dispose();
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
 protected abstract T ReadContent(IAssetProvider readerManager, DirectXDevice device, ref ContentReaderParameters parameters);
Ejemplo n.º 9
0
        protected override Model ReadContent(IAssetProvider readerManager, DirectXDevice device, ref ContentReaderParameters parameters)
        {
            var assetPath = Path.GetDirectoryName(parameters.AssetName);

            // Loads the model.
            var model = Model.Load(device, parameters.Stream, parameters.AssetName);

            if (model == null)
            {
                return(null);
            }

            // If the model has no name, use filename
            if (model.Name == null)
            {
                model.Name = Path.GetFileName(parameters.AssetName);
            }

            return(model);
        }
Ejemplo n.º 10
0
        protected override Texture ReadContent(IAssetProvider readerManager, DirectXDevice device, ref ContentReaderParameters parameters)
        {
            var texture = Texture.Load(device, parameters.Stream);

            if (texture != null)
            {
                string name = string.Format("{0}_{1}", GetPrefix(texture.GetType()), parameters.AssetName);
                texture.Initialize();
                texture.Name = texture.DebugName = name;
            }
            return(texture);
        }
Ejemplo n.º 11
0
 public object ReadContent(IAssetProvider assetManager, ref ContentReaderParameters parameters)
 {
     return(new Font(parameters.Stream));
 }