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 distortRT = new RenderImage("distortRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F); distancesRT = new RenderImage("distancesRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F); 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); }
/// <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(); }
public void Startup() { LastUpdate = DateTime.Now; Now = DateTime.Now; _cleanupList = new List<RenderTarget>(); _cleanupSpriteList = new List<CluwneSprite>(); UserInterfaceManager.DisposeAllComponents(); //Init serializer var serializer = IoCManager.Resolve<ISS14Serializer>(); _entityManager = new EntityManager(NetworkManager); IoCManager.Resolve<IEntityManagerContainer>().EntityManager = _entityManager; NetworkManager.MessageArrived += NetworkManagerMessageArrived; NetworkManager.RequestMap(); IoCManager.Resolve<IMapManager>().TileChanged += OnTileChanged; IoCManager.Resolve<IPlayerManager>().OnPlayerMove += OnPlayerMove; // TODO This should go somewhere else, there should be explicit session setup and teardown at some point. NetworkManager.SendClientName(ConfigurationManager.GetPlayerName()); // Create new _baseTarget = new RenderImage("baseTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_baseTarget); //_baseTargetSprite = new CluwneSprite(_baseTarget); //_cleanupSpriteList.Add(_baseTargetSprite); _sceneTarget = new RenderImage("sceneTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_sceneTarget); _tilesTarget = new RenderImage("tilesTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_tilesTarget); _overlayTarget = new RenderImage("OverlayTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_overlayTarget); // _overlayTarget.SourceBlend = AlphaBlendOperation.SourceAlpha; // _overlayTarget.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; // _overlayTarget.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_overlayTarget.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _composedSceneTarget = new RenderImage("composedSceneTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(_composedSceneTarget); _lightTarget = new RenderImage("lightTarget", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(_lightTarget); _lightTargetSprite = new CluwneSprite("lightTargetSprite", _lightTarget) { DepthWriteEnabled = false }; _cleanupSpriteList.Add(_lightTargetSprite); _lightTargetIntermediate = new RenderImage("lightTargetIntermediate", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(_lightTargetIntermediate); _lightTargetIntermediateSprite = new CluwneSprite("lightTargetIntermediateSprite", _lightTargetIntermediate) { DepthWriteEnabled = false }; _cleanupSpriteList.Add(_lightTargetIntermediateSprite); _gasBatch = new SpriteBatch(); //_gasBatch.SourceBlend = AlphaBlendOperation.SourceAlpha; //_gasBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //_gasBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_gasBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _wallTopsBatch = new SpriteBatch(); //_wallTopsBatch.SourceBlend = AlphaBlendOperation.SourceAlpha; //_wallTopsBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //_wallTopsBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_wallTopsBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _decalBatch = new SpriteBatch(); //_decalBatch.SourceBlend = AlphaBlendOperation.SourceAlpha; //_decalBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //_decalBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_decalBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _floorBatch = new SpriteBatch(); _wallBatch = new SpriteBatch(); _gaussianBlur = new GaussianBlur(ResourceManager); _realScreenWidthTiles = (float)CluwneLib.Screen.Size.X / MapManager.TileSize; _realScreenHeightTiles = (float)CluwneLib.Screen.Size.Y / MapManager.TileSize; //Init GUI components _gameChat = new Chatbox(ResourceManager, UserInterfaceManager, KeyBindingManager); _gameChat.TextSubmitted += ChatTextboxTextSubmitted; UserInterfaceManager.AddComponent(_gameChat); //UserInterfaceManager.AddComponent(new StatPanelComponent(ConfigurationManager.GetPlayerName(), PlayerManager, NetworkManager, ResourceManager)); var statusBar = new StatusEffectBar(ResourceManager, PlayerManager); statusBar.Position = new Point((int)CluwneLib.Screen.Size.X - 800, 10); UserInterfaceManager.AddComponent(statusBar); var hotbar = new Hotbar(ResourceManager); hotbar.Position = new Point(5, (int)CluwneLib.Screen.Size.Y - hotbar.ClientArea.Height - 5); hotbar.Update(0); UserInterfaceManager.AddComponent(hotbar); #region Lighting quadRenderer = new QuadRenderer(); quadRenderer.LoadContent(); shadowMapResolver = new ShadowMapResolver(quadRenderer, ShadowmapSize.Size1024, ShadowmapSize.Size1024, ResourceManager); shadowMapResolver.LoadContent(); lightArea128 = new LightArea(ShadowmapSize.Size128); lightArea256 = new LightArea(ShadowmapSize.Size256); lightArea512 = new LightArea(ShadowmapSize.Size512); lightArea1024 = new LightArea(ShadowmapSize.Size1024); screenShadows = new RenderImage("screenShadows", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(screenShadows); screenShadows.UseDepthBuffer = false; shadowIntermediate = new RenderImage("shadowIntermediate", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowIntermediate); shadowIntermediate.UseDepthBuffer = false; shadowBlendIntermediate = new RenderImage("shadowBlendIntermediate", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowBlendIntermediate); shadowBlendIntermediate.UseDepthBuffer = false; playerOcclusionTarget = new RenderImage("playerOcclusionTarget", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(playerOcclusionTarget); playerOcclusionTarget.UseDepthBuffer = false; LightblendTechnique = IoCManager.Resolve<IResourceManager>().GetTechnique("lightblend"); Lightmap = IoCManager.Resolve<IResourceManager>().GetShader("lightmap"); playerVision = IoCManager.Resolve<ILightManager>().CreateLight(); playerVision.SetColor(0, 0, 0, 0); playerVision.SetRadius(1024); playerVision.Move(Vector2.Zero); #endregion _handsGui = new HandsGui(); _handsGui.Position = new Point(hotbar.Position.X + 5, hotbar.Position.Y + 7); UserInterfaceManager.AddComponent(_handsGui); var combo = new HumanComboGui(PlayerManager, NetworkManager, ResourceManager, UserInterfaceManager); combo.Update(0); combo.Position = new Point(hotbar.ClientArea.Right - combo.ClientArea.Width + 5, hotbar.Position.Y - combo.ClientArea.Height - 5); UserInterfaceManager.AddComponent(combo); var healthPanel = new HealthPanel(); healthPanel.Position = new Point(hotbar.ClientArea.Right - 1, hotbar.Position.Y + 11); healthPanel.Update(0); UserInterfaceManager.AddComponent(healthPanel); var targetingUi = new TargetingGui(); targetingUi.Update(0); targetingUi.Position = new Point(healthPanel.Position.X + healthPanel.ClientArea.Width, healthPanel.Position.Y - 40); UserInterfaceManager.AddComponent(targetingUi); var inventoryButton = new ImageButton { ImageNormal = "button_inv", Position = new Point(hotbar.Position.X + 172, hotbar.Position.Y + 2) }; inventoryButton.Update(0); inventoryButton.Clicked += inventoryButton_Clicked; UserInterfaceManager.AddComponent(inventoryButton); var statusButton = new ImageButton { ImageNormal = "button_status", Position = new Point(inventoryButton.ClientArea.Right, inventoryButton.Position.Y) }; statusButton.Update(0); statusButton.Clicked += statusButton_Clicked; UserInterfaceManager.AddComponent(statusButton); var craftButton = new ImageButton { ImageNormal = "button_craft", Position = new Point(statusButton.ClientArea.Right, statusButton.Position.Y) }; craftButton.Update(0); craftButton.Clicked += craftButton_Clicked; UserInterfaceManager.AddComponent(craftButton); var menuButton = new ImageButton { ImageNormal = "button_menu", Position = new Point(craftButton.ClientArea.Right, craftButton.Position.Y) }; menuButton.Update(0); menuButton.Clicked += menuButton_Clicked; UserInterfaceManager.AddComponent(menuButton); }
private void LoadShaders() { if (!done) { GaussianBlurTechnique = _resourceManager.GetTechnique(("GaussianBlur" + Radius)); done = true; } }
private void InitalizeLighting() { shadowMapResolver = new ShadowMapResolver(ShadowmapSize.Size1024, ShadowmapSize.Size1024, ResourceManager); shadowMapResolver.LoadContent(); lightArea128 = new LightArea(ShadowmapSize.Size128); lightArea256 = new LightArea(ShadowmapSize.Size256); lightArea512 = new LightArea(ShadowmapSize.Size512); lightArea1024 = new LightArea(ShadowmapSize.Size1024); screenShadows = new RenderImage("screenShadows", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(screenShadows); screenShadows.UseDepthBuffer = false; shadowIntermediate = new RenderImage("shadowIntermediate", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowIntermediate); shadowIntermediate.UseDepthBuffer = false; shadowBlendIntermediate = new RenderImage("shadowBlendIntermediate", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowBlendIntermediate); shadowBlendIntermediate.UseDepthBuffer = false; playerOcclusionTarget = new RenderImage("playerOcclusionTarget", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(playerOcclusionTarget); playerOcclusionTarget.UseDepthBuffer = false; LightblendTechnique = IoCManager.Resolve<IResourceManager>().GetTechnique("lightblend"); Lightmap = IoCManager.Resolve<IResourceManager>().GetShader("lightmap"); playerVision = IoCManager.Resolve<ILightManager>().CreateLight(); playerVision.SetColor(Color.Blue); playerVision.SetRadius(1024); playerVision.Move(new Vector2f()); _occluderDebugTarget = new RenderImage("debug", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y); }