Пример #1
0
 bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
 {
     connectorContext.Reader = context.BakedReader;
     Manager.RuntimeConnector.LoadShader(connectorContext);
     Handle = connectorContext.Handle;
     return(Handle != null);
 }
Пример #2
0
        bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
        {
            var br = context.BakedReader;

            mText = br.ReadString();

            return(true);
        }
Пример #3
0
        bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
        {
            var br = context.BakedReader;

            int count = br.ReadInt32();

            mArray = new float[count];
            for (int i = 0; i < count; i++)
            {
                mArray[i] = br.ReadSingle();
            }

            return(true);
        }
Пример #4
0
        unsafe bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
        {
            var br = context.BakedReader;

            int voxelCount = br.ReadInt32();
            var bytes      = br.ReadBytes(voxelCount * Marshal.SizeOf <Voxel>());

            //TODO - utilities to read to pointers (maybe brute hacks)
            Voxels = new Voxel[voxelCount];
            fixed(Voxel *v = Voxels)
            {
                Marshal.Copy(bytes, 0, new IntPtr(v), bytes.Length);
            }

            return(true);
        }
Пример #5
0
        bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
        {
            Console.WriteLine("Art.LoadBaked: " + context.ContentPath);

            var br = context.BakedReader;

            Manager.EmbeddedLoadBaked(Texture, context);

            mWidth  = br.ReadInt32();
            mHeight = br.ReadInt32();
            ox      = br.ReadInt32();
            oy      = br.ReadInt32();
            umin    = br.ReadSingle();
            vmin    = br.ReadSingle();
            umax    = br.ReadSingle();
            vmax    = br.ReadSingle();

            return(true);
        }
Пример #6
0
        bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
        {
            Reflect();

            var reader = context.BakedReader;

            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string    name   = reader.ReadString();
                FieldType ftReal = (FieldType)reader.ReadInt32();

                //we're doign a lot of double checking here, so nothing bad happens if we load old data on a newer config struct
                //This might not be necessary...
                //but I need to make config data 'depend' on the .dll
                //right now if the dll changes, the content might not rebuild (because the output would only be depending on the input ini)
                //so that's one reason we need the extra security here
                MyFieldInfo mfi;
                reflectionData.TryGetValue(name, out mfi);

                object data;
                switch (ftReal)
                {
                case FieldType.String: data = reader.ReadString(); break;

                case FieldType.Int32: data = reader.ReadInt32(); break;

                case FieldType.Float: data = reader.ReadSingle(); break;

                default: throw new InvalidOperationException();
                }

                if (ftReal == mfi.Type)
                {
                    mfi.FieldInfo.SetValue(this, data);
                }
            }

            return(true);
        }
Пример #7
0
        bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
        {
            Console.WriteLine("Texture.LoadBaked: " + context.ContentPath);

            var br = context.BakedReader;

            info        = new ImageInfo();
            info.Width  = br.ReadInt32();
            info.Height = br.ReadInt32();
            TextureFormat format = (TextureFormat)br.ReadInt32();

            int rawSize  = br.ReadInt32();
            int comprLen = br.ReadInt32();

            byte[] temp   = br.ReadBytes(comprLen);
            byte[] rawbuf = new byte[rawSize];

            //apply standard uncompression, for now
            fixed(byte *pOutBuf = rawbuf)
            fixed(byte *pInBuf = temp)
            {
                MTS.Engine.Native.zlib_uncompress(pOutBuf, pInBuf, rawSize, comprLen);
            }

            var ms               = new MemoryStream(rawbuf);
            var brRaw            = new BinaryReader(ms);
            var resLoaderContext = new RuntimeConnector_TextureContext();

            resLoaderContext.ImageBuffer = new ImageBuffer();
            //resLoaderContext.Reader = brRaw; //meaningless now, should be restored later
            resLoaderContext.ImageBuffer.Data   = rawbuf;
            resLoaderContext.ImageBuffer.Width  = info.Width;
            resLoaderContext.ImageBuffer.Height = info.Height;
            resLoaderContext.ImageBuffer.Format = format;
            mHandle     = this.Manager.RuntimeConnector.LoadTexture(resLoaderContext);
            mOwnsHandle = true;
            return(true);
        }
Пример #8
0
        public bool Load(ContentLoadContext context)
        {
            PipelineLoadBakedContext loadBakedContext = new PipelineLoadBakedContext();

            loadBakedContext.ContentPath = name;
            var fpBaked = Path.Combine(directoryOwner.BakedContentDiskRoot, name);


            var bakedLoader = content as IBakedLoader;

            //save time... assume this succeeds
            try
            {
                using (var fs = new FileStream(fpBaked, FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    loadBakedContext.BakedReader = new BinaryReader(fs);
                    return(bakedLoader.LoadBaked(loadBakedContext));
                }
            }
            catch
            {
                return(false);
            }
        }
Пример #9
0
 bool IBakedLoader.LoadBaked(PipelineLoadBakedContext context)
 {
     return(true);
 }
Пример #10
0
        public bool Load(ContentLoadContext context)
        {
            bool loaded = false;

            //try loading the baked content
            PipelineLoadBakedContext loadBakedContext = new PipelineLoadBakedContext();

            loadBakedContext.ContentPath = name;
            var fpBaked = Path.Combine(directoryOwner.BakedContentDiskRoot, name);

            var bakeable    = content.Manager.PipelineConnector.GetPipeline(content);
            var bakedLoader = content as IBakedLoader;

            //what is this hot garbage?? I would like a special context for preparing which has more limited information
            bakeContext = new PipelineBakeContext()
            {
                PipelineConnector  = content.Manager.PipelineConnector,
                Content            = content,
                RawContentDiskRoot = directoryOwner.RawContentDiskRoot,
                ContentPath        = name,
                RawContentDiskPath = Path.Combine(directoryOwner.RawContentDiskRoot, name),
                ForOven            = directoryOwner.Manager.DumpBakedContent,
                Attributes         = content.attributes ?? new object[0]
            };
            bakeable.Prepare(bakeContext);

            //TODO - dont even do this unless we support hot loading or arent bruted or something, I dont know
            bool resolvedDependencies = bakeContext.ResolveDependencies(name);

            //analyze whether we need to bake
            bool satisfied = true;

            //if the output doesnt exist, we do need to bake
            var fiTo = new FileInfo(fpBaked);

            if (!fiTo.Exists)
            {
                satisfied = false;
            }

            //check timestamps - we may need to bake if deps are out of date
            if (satisfied)
            {
                foreach (var dep in bakeContext.resolvedDependencies.Values)
                {
                    var fiFrom     = new FileInfo(dep);
                    var fiFromTime = fiFrom.LastWriteTimeUtc;
                    if (fiTo.LastWriteTimeUtc < fiFromTime)
                    {
                        satisfied = false;
                        break;
                    }
                }
            }

            //TODO: if we're the oven AND we're doing a clean operation, force to be unsatisfied

            if (satisfied)
            {
                if (directoryOwner.Manager.DumpBakedContent)
                {
                    //it's already there. nothing to do
                    //i GUESS this is what we can return
                    return(true);
                }

                //TODO: engine special functions to open files and report existence without two operations
                using (var fs = new FileStream(fpBaked, FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    loadBakedContext.BakedReader = new BinaryReader(fs);
                    loaded = bakedLoader.LoadBaked(loadBakedContext);
                }
            }

            //if it loaded, we're done
            if (loaded)
            {
                return(true);
            }

            //if it didnt load, we need to load it raw
            //that consists actually of baking it, and if that succeeded, loading that as baked

            //if we couldnt resolve dependencies, we can't bake
            if (!resolvedDependencies)
            {
                return(false);
            }

            var msBake = new MemoryStream();
            var bwBake = new BinaryWriter(msBake);

            bakeContext.BakedWriter = bwBake;

            bool baked = bakeable.Bake(bakeContext);

            //if it didnt bake, we definitely can't load it
            if (!baked)
            {
                return(false);
            }

            bwBake.Flush();
            msBake.Position = 0;

            //dump newly baked content (depending on configuration)
            if (content.Manager.DumpBakedContent)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fpBaked));
                using (var fs = new FileStream(fpBaked, FileMode.Create, FileAccess.Write, FileShare.None))
                    fs.Write(msBake.GetBuffer(), 0, (int)msBake.Length);

                //unclear what default timestamp should be in case there's no inputs
                //probably need to set it equal to the build time of the executing assembly - pipe that in from the oven?
                DateTime timestamp = DateTime.MinValue;
                foreach (var dep in bakeContext.resolvedDependencies.Values)
                {
                    var      fiFrom = new FileInfo(dep);
                    DateTime nextTs = fiFrom.LastWriteTimeUtc;
                    if (nextTs > timestamp)
                    {
                        timestamp = nextTs;
                    }
                }
                if (timestamp != DateTime.MinValue)
                {
                    fiTo.LastWriteTimeUtc = timestamp;
                }

                //no actual loading to do in this case
                return(true);
            }

            //now, load the baked content
            var bakedReader = new BinaryReader(msBake);

            loadBakedContext.BakedReader = bakedReader;
            loaded = bakedLoader.LoadBaked(loadBakedContext);

            //TODO: add sophisticated diagnostics log system and report this as a FAILED load

            //well, whether or not it worked, that's all we can do

            return(loaded);
        }