Beispiel #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load\\
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            GraphicsDevice.PresentationParameters.MultiSampleCount = 8;

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Standard = Content.Load <Effect>("Standard");
            Half     = Content.Load <Effect>("Half");

            Console.WriteLine("LOADING TEXTURES");

            var sw = new Stopwatch();

            {
                sw.Start();
                NewModelRocks = ModelLoader.LoadStandardModel(GraphicsDevice, "Assets/Models/rocks.smod");
                NewModelPipe  = ModelLoader.LoadStandardModel(GraphicsDevice, "Assets/Models/pipe.smod");
                sw.Stop();
                Console.WriteLine("Time taken to load model via file:" + sw.ElapsedMilliseconds + "ms");
                sw.Reset();
            }

            {
                // This way appears slightly faster (~10%) but I don't think it's worth the trade off of loading the entire chunk into memory
                var jobScheduler = new JobScheduler();
                var chunkReader  = new AssetChunkReader();

                var chunkFileName = "Assets/Chunk/textures.chunk";

                chunkReader.AssociateChunk(chunkFileName);

                sw.Start();

                var fs1 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs2 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs3 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs4 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs5 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs6 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs7 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                var fs8 = new FileStream(chunkFileName, FileMode.Open, FileAccess.Read, FileShare.Read);


                jobScheduler.QueueJob("Assets/Textures/tex16/walls.tex16", () => { WallTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/walls.tex16", fs1); });
                jobScheduler.QueueJob("Assets/Textures/tex16/rocks.tex16", () => { RockTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/rocks.tex16", fs2); });

                jobScheduler.QueueJob("Assets/Textures/tex16/doorbars.tex16", () => { DoorBarsTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/doorbars.tex16", fs3); });
                jobScheduler.QueueJob("Assets/Textures/tex16/floor.tex16", () => { FloorTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/floor.tex16", fs4); });

                jobScheduler.QueueJob("Assets/Textures/tex16/goat.tex16", () => { GoatTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/goat.tex16", fs5); });
                jobScheduler.QueueJob("Assets/Textures/tex16/ice.tex16", () => { IceTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/ice.tex16", fs6); });
                jobScheduler.QueueJob("Assets/Textures/tex16/torch.tex16", () => { TorchTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/torch.tex16", fs7); });
                jobScheduler.QueueJob("Assets/Textures/tex16/water.tex16", () => { WaterTexture = chunkReader.LoadTextureFromStream(GraphicsDevice, "Assets/Textures/tex16/water.tex16", fs8); });

                jobScheduler.ExecuteAll(() =>
                {
                    fs1.Close();
                    fs2.Close();
                    fs3.Close();
                    fs4.Close();
                    fs5.Close();
                    fs6.Close();
                    fs7.Close();
                    fs8.Close();

                    sw.Stop();
                    Console.WriteLine("Time taken to load tex16 (multithreaded) from Chunk file: " + sw.ElapsedMilliseconds + "ms");
                    sw.Reset();
                });
            }
        }