Ejemplo n.º 1
0
        // This method is optional. By sorting the wad textures it may result ahead of time
        // we may have better texture space efficency.
        public void PreloadReplaceWad(IEnumerable <WadMoveable> newMoveables, IEnumerable <WadStatic> newStatics)
        {
            Dispose();
            try
            {
                PreloadReplaceTextures(newMoveables, newStatics);
            }
            catch (TextureAtlasFullException)
            {
                logger.Error("Unable to preload wad because the texture atlas became too full!");
                return;
            }

            // Create moveable models
            Parallel.ForEach(newMoveables, moveable =>
            {
                var model = AnimatedModel.FromWadMoveable(GraphicsDevice, moveable, AllocateTexture);
                lock (Moveables)
                    Moveables.Add(moveable, model);
            });

            // Create static meshes
            Parallel.ForEach(newStatics, @static =>
            {
                var model = new StaticModel(GraphicsDevice);
                model.Meshes.Add(ObjectMesh.FromWad2(GraphicsDevice, @static.Mesh, AllocateTexture));
                model.UpdateBuffers();
                lock (Statics)
                    Statics.Add(@static, model);
            });
        }
Ejemplo n.º 2
0
        public StaticModel GetStatic(WadStatic @static, bool maybeRebuildAll = true)
        {
            // Check if the data is already loaded
            // If yes attempt to use that one
            StaticModel model;

            if (Statics.TryGetValue(@static, out model))
            {
                if (model.Version >= @static.Version)
                {
                    return(model);
                }
                ReclaimTextureSpace(model);
                model.Dispose();
                Statics.Remove(@static);
            }

            // The data is either new or has changed, unfortunately we need to reload it
            try
            {
                model = new StaticModel(GraphicsDevice);
                model.Meshes.Add(ObjectMesh.FromWad2(GraphicsDevice, @static.Mesh, AllocateTexture));
                model.UpdateBuffers();
            }
            catch (TextureAtlasFullException exc)
            {
                logger.Info(exc.Message);

                if (maybeRebuildAll)
                {
                    logger.Info("Starting to rebuild the entire atlas.");
                    Dispose();
                    return(GetStatic(@static, false));
                }
            }

            Statics.Add(@static, model);
            return(model);
        }