private void LoadShaders()
 {
     if (!done)
     {
         GaussianBlurTechnique = _resourceCache.GetTechnique(("GaussianBlur" + Radius));
         done = true;
     }
 }
Example #2
0
        private void Import()
        {
            var path = OpenFileDialog(OpenFileFilter);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            var manager = EffectsManager;

            EffectsManager = null;
            manager.ImportTechniques(path, true);
            EffectsManager = manager;
            TechniqueList.Clear();
            foreach (var tech in EffectsManager.RenderTechniques)
            {
                TechniqueList.Add(tech);
            }
        }
Example #3
0
        public void LoadContent()
        {
            reductionEffectTechnique      = _resourceManager.GetTechnique("reductionEffect");
            resolveShadowsEffectTechnique = _resourceManager.GetTechnique("resolveShadowsEffect");

            //// BUFFER TYPES ARE VERY IMPORTANT HERE AND IT WILL BREAK IF YOU CHANGE THEM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! HONK HONK
            //these work fine
            distortRT   = new RenderImage("distortRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F);
            distancesRT = new RenderImage("distancesRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F);

            //these need the buffer format
            shadowMap   = new RenderImage("shadowMap" + baseSize, 2, baseSize, ImageBufferFormats.BufferGR1616F);
            reductionRT = new RenderImage[reductionChainCount];
            for (int i = 0; i < reductionChainCount; i++)
            {
                reductionRT[i] = new RenderImage("reductionRT" + i + baseSize, 2 << i, baseSize,
                                                 ImageBufferFormats.BufferGR1616F);
            }
            shadowsRT          = new RenderImage("shadowsRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferRGB888A8);
            processedShadowsRT = new RenderImage("processedShadowsRT" + baseSize, baseSize, baseSize,
                                                 ImageBufferFormats.BufferRGB888A8);
        }
Example #4
0
        /// <summary>
        ///  <para>Loads all Resources from given Zip into the respective Resource Lists and Caches</para>
        /// </summary>
        public void LoadResourceZip(string path = null, string pw = null)
        {
            string zipPath  = path ?? _configurationManager.GetResourcePath();
            string password = pw ?? _configurationManager.GetResourcePassword();

            if (Assembly.GetEntryAssembly().GetName().Name == "SS14.UnitTesting")
            {
                string debugPath = "..\\";
                debugPath += zipPath;
                zipPath    = debugPath;
            }



            if (!File.Exists(zipPath))
            {
                throw new FileNotFoundException("Specified Zip does not exist: " + zipPath);
            }

            FileStream zipFileStream = File.OpenRead(zipPath);
            var        zipFile       = new ZipFile(zipFileStream);

            if (!string.IsNullOrWhiteSpace(password))
            {
                zipFile.Password = password;
            }

            #region Sort Resource pack
            var directories = from ZipEntry a in zipFile
                              where a.IsDirectory
                              orderby a.Name.ToLowerInvariant() == "textures" descending
                              select a;

            Dictionary <string, List <ZipEntry> > sorted = new Dictionary <string, List <ZipEntry> >();

            foreach (ZipEntry dir in directories)
            {
                if (sorted.ContainsKey(dir.Name.ToLowerInvariant()))
                {
                    continue;                                                  //Duplicate folder? shouldnt happen.
                }
                List <ZipEntry> folderContents = (from ZipEntry entry in zipFile
                                                  where entry.Name.ToLowerInvariant().Contains(dir.Name.ToLowerInvariant())
                                                  where entry.IsFile
                                                  select entry).ToList();

                sorted.Add(dir.Name.ToLowerInvariant(), folderContents);
            }

            sorted = sorted.OrderByDescending(x => x.Key == "textures/").ToDictionary(x => x.Key, x => x.Value); //Textures first.
            #endregion

            #region Load Resources
            foreach (KeyValuePair <string, List <ZipEntry> > current in sorted)
            {
                switch (current.Key)
                {
                case ("textures/"):
                    foreach (ZipEntry texture in current.Value)
                    {
                        if (supportedImageExtensions.Contains(Path.GetExtension(texture.Name).ToLowerInvariant()))
                        {
                            Texture loadedImg = LoadTextureFrom(zipFile, texture);
                            if (loadedImg == null)
                            {
                                continue;
                            }
                            else
                            {
                                _textures.Add(Path.GetFileNameWithoutExtension(texture.Name), loadedImg);
                            }
                        }
                    }
                    break;

                case ("tai/"):    // Tai? HANK HANK
                    foreach (ZipEntry tai in current.Value)
                    {
                        if (Path.GetExtension(tai.Name).ToLowerInvariant() == ".tai")
                        {
                            IEnumerable <KeyValuePair <string, Sprite> > loadedSprites = LoadSpritesFrom(zipFile, tai);
                            foreach (var currentSprite in loadedSprites.Where(currentSprite => !_sprites.ContainsKey(currentSprite.Key)))
                            {
                                _sprites.Add(currentSprite.Key, currentSprite.Value);
                            }
                        }
                    }
                    break;

                case ("fonts/"):
                    foreach (ZipEntry font in current.Value)
                    {
                        if (Path.GetExtension(font.Name).ToLowerInvariant() == ".ttf")
                        {
                            Font loadedFont = LoadFontFrom(zipFile, font);
                            if (loadedFont == null)
                            {
                                continue;
                            }
                            string ResourceName = Path.GetFileNameWithoutExtension(font.Name).ToLowerInvariant();
                            _fonts.Add(ResourceName, loadedFont);
                        }
                    }
                    break;

                case ("particlesystems/"):
                    foreach (ZipEntry particles in current.Value)
                    {
                        if (Path.GetExtension(particles.Name).ToLowerInvariant() == ".xml")
                        {
                            ParticleSettings particleSettings = LoadParticlesFrom(zipFile, particles);
                            if (particleSettings == null)
                            {
                                continue;
                            }
                            else
                            {
                                _particles.Add(Path.GetFileNameWithoutExtension(particles.Name), particleSettings);
                            }
                        }
                    }
                    break;

                case ("shaders/"):
                {
                    GLSLShader    LoadedShader;
                    TechniqueList List;

                    foreach (ZipEntry shader in current.Value)
                    {
                        int FirstIndex = shader.Name.IndexOf('/');
                        int LastIndex  = shader.Name.LastIndexOf('/');

                        if (FirstIndex != LastIndex)          // if the shader pixel/fragment files are in folder/technique group, construct shader and add it to a technique list.
                        {
                            string FolderName = shader.Name.Substring(FirstIndex + 1, LastIndex - FirstIndex - 1);

                            if (!_TechniqueList.Keys.Contains(FolderName))
                            {
                                List      = new TechniqueList();
                                List.Name = FolderName;
                                _TechniqueList.Add(FolderName, List);
                            }


                            LoadedShader = LoadShaderFrom(zipFile, shader);
                            if (LoadedShader == null)
                            {
                                continue;
                            }
                            else
                            {
                                _TechniqueList[FolderName].Add(LoadedShader);
                            }
                        }

                        // if the shader is not in a folder/technique group, add it to the shader dictionary
                        else if (Path.GetExtension(shader.Name).ToLowerInvariant() == ".vert" || Path.GetExtension(shader.Name).ToLowerInvariant() == ".frag")
                        {
                            LoadedShader = LoadShaderFrom(zipFile, shader);
                            if (LoadedShader == null)
                            {
                                continue;
                            }

                            else
                            {
                                _shaders.Add(Path.GetFileNameWithoutExtension(shader.Name).ToLowerInvariant(), LoadedShader);
                            }
                        }
                    }
                    break;
                }

                case ("animations/"):
                    foreach (ZipEntry animation in current.Value)
                    {
                        if (Path.GetExtension(animation.Name).ToLowerInvariant() == ".xml")
                        {
                            AnimationCollection animationCollection = LoadAnimationCollectionFrom(zipFile, animation);
                            if (animationCollection == null)
                            {
                                continue;
                            }
                            else
                            {
                                _animationCollections.Add(animationCollection.Name, animationCollection);
                            }
                        }
                    }
                    break;
                }
            }
            #endregion

            sorted = null;
            zipFile.Close();
            zipFileStream.Close();
            zipFileStream.Dispose();

            GC.Collect();
        }
        /// <summary>
        ///  <para>Loads all Resources from given Zip into the respective Resource Lists and Caches</para>
        /// </summary>
        public void LoadResourceZip(string path = null, string pw = null)
        {
            var cfgMgr = _config;

            cfgMgr.RegisterCVar("res.pack", Path.Combine("..", "..", "Resources", "ResourcePack.zip"), CVarFlags.ARCHIVE);

            string zipPath = path ?? _config.GetCVar <string>("res.pack");

            if (AppDomain.CurrentDomain.GetAssemblyByName("SS14.UnitTesting") != null)
            {
                string debugPath = "..";
                zipPath = Path.Combine(debugPath, zipPath);
            }

            zipPath = PathHelpers.ExecutableRelativeFile(zipPath);

            if (!File.Exists(zipPath))
            {
                throw new FileNotFoundException("Specified Zip does not exist: " + zipPath);
            }

            FileStream zipFileStream = File.OpenRead(zipPath);
            var        zipFile       = new ZipFile(zipFileStream);

            #region Sort Resource pack
            var directories = zipFile.Cast <ZipEntry>()
                              .Where(a => a.IsDirectory)
                              .OrderByDescending(a => a.Name.ToLowerInvariant() == "textures");

            Dictionary <string, List <ZipEntry> > sorted = new Dictionary <string, List <ZipEntry> >();

            foreach (ZipEntry dir in directories)
            {
                if (sorted.ContainsKey(dir.Name.ToLowerInvariant()))
                {
                    continue;                                                  //Duplicate folder? shouldnt happen.
                }
                List <ZipEntry> folderContents = (from ZipEntry entry in zipFile
                                                  where entry.Name.ToLowerInvariant().Contains(dir.Name.ToLowerInvariant())
                                                  where entry.IsFile
                                                  select entry).ToList();

                sorted.Add(dir.Name.ToLowerInvariant(), folderContents);
            }

            sorted = sorted.OrderByDescending(x => x.Key == "textures/").ToDictionary(x => x.Key, x => x.Value); //Textures first.
            #endregion Sort Resource pack

            Logger.Log("Loading resources...");

            #region Load Resources
            foreach (KeyValuePair <string, List <ZipEntry> > current in sorted)
            {
                switch (current.Key)
                {
                case ("textures/"):

                    int itemCount = current.Value.Count();
                    Task <Texture>[] taskArray = new Task <Texture> [itemCount];
                    for (int i = 0; i < itemCount; i++)
                    {
                        ZipEntry texture = current.Value[i];

                        if (_supportedImageExtensions.Contains(Path.GetExtension(texture.Name).ToLowerInvariant()))
                        {
                            taskArray[i] = Task <Texture> .Factory.StartNew(() =>
                            {
                                return(LoadTextureFrom(zipFile, texture));
                            });
                        }
                    }

                    Task.WaitAll(taskArray);
                    for (int i = 0; i < taskArray.Count(); i++)
                    {
                        Texture loadedImg = taskArray[i].Result;
                        if (loadedImg == null)
                        {
                            continue;
                        }
                        else
                        {
                            _textures.Add(Path.GetFileNameWithoutExtension(current.Value[i].Name), loadedImg);
                        }
                    }

                    break;

                case ("tai/"):     // Tai? HANK HANK
                    Logger.Log("Loading tai...");
                    foreach (ZipEntry tai in current.Value)
                    {
                        if (Path.GetExtension(tai.Name).ToLowerInvariant() == ".tai")
                        {
                            IEnumerable <KeyValuePair <string, Sprite> > loadedSprites = LoadSpritesFrom(zipFile, tai);
                            foreach (var currentSprite in loadedSprites.Where(currentSprite => !_sprites.ContainsKey(currentSprite.Key)))
                            {
                                _sprites.Add(currentSprite.Key, currentSprite.Value);
                            }
                        }
                    }
                    break;

                case ("particlesystems/"):
                    Logger.Log("Loading particlesystems...");
                    foreach (ZipEntry particles in current.Value)
                    {
                        if (Path.GetExtension(particles.Name).ToLowerInvariant() == ".xml")
                        {
                            ParticleSettings particleSettings = LoadParticlesFrom(zipFile, particles);
                            if (particleSettings == null)
                            {
                                continue;
                            }
                            else
                            {
                                _particles.Add(Path.GetFileNameWithoutExtension(particles.Name), particleSettings);
                            }
                        }
                    }
                    break;

                case ("shaders/"):
                {
                    Logger.Log("Loading shaders...");
                    GLSLShader    LoadedShader;
                    TechniqueList List;

                    foreach (ZipEntry shader in current.Value)
                    {
                        int FirstIndex = shader.Name.IndexOf('/');
                        int LastIndex  = shader.Name.LastIndexOf('/');

                        if (FirstIndex != LastIndex)          // if the shader pixel/fragment files are in folder/technique group, construct shader and add it to a technique list.
                        {
                            string FolderName = shader.Name.Substring(FirstIndex + 1, LastIndex - FirstIndex - 1);

                            if (!_techniqueList.Keys.Contains(FolderName))
                            {
                                List      = new TechniqueList();
                                List.Name = FolderName;
                                _techniqueList.Add(FolderName, List);
                            }

                            LoadedShader = LoadShaderFrom(zipFile, shader);
                            if (LoadedShader == null)
                            {
                                continue;
                            }
                            else
                            {
                                _techniqueList[FolderName].Add(LoadedShader);
                            }
                        }

                        // if the shader is not in a folder/technique group, add it to the shader dictionary
                        else if (Path.GetExtension(shader.Name).ToLowerInvariant() == ".vert" || Path.GetExtension(shader.Name).ToLowerInvariant() == ".frag")
                        {
                            LoadedShader = LoadShaderFrom(zipFile, shader);
                            if (LoadedShader == null)
                            {
                                continue;
                            }
                            else
                            {
                                _shaders.Add(Path.GetFileNameWithoutExtension(shader.Name).ToLowerInvariant(), LoadedShader);
                            }
                        }
                    }
                    break;
                }

                case ("animations/"):
                    Logger.Log("Loading animations...");
                    foreach (ZipEntry animation in current.Value)
                    {
                        if (Path.GetExtension(animation.Name).ToLowerInvariant() == ".xml")
                        {
                            AnimationCollection animationCollection = LoadAnimationCollectionFrom(zipFile, animation);
                            if (animationCollection == null)
                            {
                                continue;
                            }
                            else
                            {
                                _animationCollections.Add(animationCollection.Name, animationCollection);
                            }
                        }
                    }
                    break;
                }
            }
            #endregion Load Resources

            zipFile.Close();
            zipFileStream.Close();
            zipFileStream.Dispose();

            GC.Collect();
        }