private void UnloadPreRenderedTexture() { if (PreRenderedTexture != null && PreRenderedTexture.IsDisposed == false) { FlatRedBallServices.GetContentManagerByName(ContentManager).RemoveDisposable(PreRenderedTexture); PreRenderedTexture.Dispose(); } }
public static void LoadStaticContent(string contentManagerName) { if (string.IsNullOrEmpty(contentManagerName)) { throw new ArgumentException("contentManagerName cannot be empty or null"); } ContentManagerName = contentManagerName; #if DEBUG if (contentManagerName == FlatRedBallServices.GlobalContentManager) { HasBeenLoadedWithGlobalContentManager = true; } else if (HasBeenLoadedWithGlobalContentManager) { throw new Exception("This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs"); } #endif bool registerUnload = false; if (LoadedContentManagers.Contains(contentManagerName) == false) { LoadedContentManagers.Add(contentManagerName); lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("BoardTileStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } if (!FlatRedBallServices.IsLoaded <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/boardtile/tilenone.png", ContentManagerName)) { registerUnload = true; } TileNone = FlatRedBallServices.Load <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/boardtile/tilenone.png", ContentManagerName); if (!FlatRedBallServices.IsLoaded <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/boardtile/tileotexture.png", ContentManagerName)) { registerUnload = true; } TileOTexture = FlatRedBallServices.Load <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/boardtile/tileotexture.png", ContentManagerName); if (!FlatRedBallServices.IsLoaded <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/boardtile/tilextexture.png", ContentManagerName)) { registerUnload = true; } TileXTexture = FlatRedBallServices.Load <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/boardtile/tilextexture.png", ContentManagerName); } if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("BoardTileStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } } CustomLoadStaticContent(contentManagerName); }
public static void LoadStaticContent(string contentManagerName) { if (string.IsNullOrEmpty(contentManagerName)) { throw new ArgumentException("contentManagerName cannot be empty or null"); } ContentManagerName = contentManagerName; #if DEBUG if (contentManagerName == FlatRedBallServices.GlobalContentManager) { HasBeenLoadedWithGlobalContentManager = true; } else if (HasBeenLoadedWithGlobalContentManager) { throw new Exception("This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs"); } #endif bool registerUnload = false; if (LoadedContentManagers.Contains(contentManagerName) == false) { LoadedContentManagers.Add(contentManagerName); lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("PlatformerCharacterBaseStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } if (MovementValues == null) { { // We put the { and } to limit the scope of oldDelimiter char oldDelimiter = CsvFileManager.Delimiter; CsvFileManager.Delimiter = ','; Dictionary <string, MovementValues> temporaryCsvObject = new Dictionary <string, MovementValues>(); CsvFileManager.CsvDeserializeDictionary <string, MovementValues>("content/entities/platformercharacterbase/movementvalues.csv", temporaryCsvObject); CsvFileManager.Delimiter = oldDelimiter; MovementValues = temporaryCsvObject; } } } if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("PlatformerCharacterBaseStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } } CustomLoadStaticContent(contentManagerName); }
public static new void LoadStaticContent(string contentManagerName) { if (string.IsNullOrEmpty(contentManagerName)) { throw new ArgumentException("contentManagerName cannot be empty or null"); } ContentManagerName = contentManagerName; PlatformerCharacterBase.LoadStaticContent(contentManagerName); #if DEBUG if (contentManagerName == FlatRedBallServices.GlobalContentManager) { HasBeenLoadedWithGlobalContentManager = true; } else if (HasBeenLoadedWithGlobalContentManager) { throw new Exception("This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs"); } #endif bool registerUnload = false; if (LoadedContentManagers.Contains(contentManagerName) == false) { LoadedContentManagers.Add(contentManagerName); lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("PlayerStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } if (!FlatRedBallServices.IsLoaded <FlatRedBall.Graphics.Animation.AnimationChainList>(@"content/entities/player/animationchainlistfile.achx", ContentManagerName)) { registerUnload = true; } AnimationChainListFile = FlatRedBallServices.Load <FlatRedBall.Graphics.Animation.AnimationChainList>(@"content/entities/player/animationchainlistfile.achx", ContentManagerName); if (!FlatRedBallServices.IsLoaded <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/player/playertexture.png", ContentManagerName)) { registerUnload = true; } PlayerTexture = FlatRedBallServices.Load <Microsoft.Xna.Framework.Graphics.Texture2D>(@"content/entities/player/playertexture.png", ContentManagerName); } if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("PlayerStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } } CustomLoadStaticContent(contentManagerName); }
public static void LoadStaticContent(string contentManagerName) { if (string.IsNullOrEmpty(contentManagerName)) { throw new ArgumentException("contentManagerName cannot be empty or null"); } ContentManagerName = contentManagerName; #if DEBUG if (contentManagerName == FlatRedBallServices.GlobalContentManager) { HasBeenLoadedWithGlobalContentManager = true; } else if (HasBeenLoadedWithGlobalContentManager) { throw new Exception("This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs"); } #endif bool registerUnload = false; if (LoadedContentManagers.Contains(contentManagerName) == false) { LoadedContentManagers.Add(contentManagerName); lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("ParallaxBackgroundStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } if (!FlatRedBallServices.IsLoaded <System.String>(@"content/entities/parallaxbackground/license.txt", ContentManagerName)) { registerUnload = true; } License = FlatRedBallServices.Load <System.String>(@"content/entities/parallaxbackground/license.txt", ContentManagerName); } if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("ParallaxBackgroundStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } } CustomLoadStaticContent(contentManagerName); }
public void PerformRender(string contentManagerName, string textureName) { if (HasRendered) { throw new InvalidOperationException("This has already rendered once, call ReRender instead."); } HasRendered = true; ReRender(); mRenderTarget.Name = textureName; var contentManager = FlatRedBallServices.GetContentManagerByName(contentManagerName); contentManager.AddDisposable(textureName, mRenderTarget); }
public static void LoadStaticContent(string contentManagerName) { if (string.IsNullOrEmpty(contentManagerName)) { throw new ArgumentException("contentManagerName cannot be empty or null"); } ContentManagerName = contentManagerName; #if DEBUG if (contentManagerName == FlatRedBallServices.GlobalContentManager) { HasBeenLoadedWithGlobalContentManager = true; } else if (HasBeenLoadedWithGlobalContentManager) { throw new Exception("This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs"); } #endif bool registerUnload = false; if (LoadedContentManagers.Contains(contentManagerName) == false) { LoadedContentManagers.Add(contentManagerName); lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("AiSelectorStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } } FrbTicTacToe.Entities.Label.LoadStaticContent(contentManagerName); if (registerUnload && ContentManagerName != FlatRedBallServices.GlobalContentManager) { lock (mLockObject) { if (!mRegisteredUnloads.Contains(ContentManagerName) && ContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.GetContentManagerByName(ContentManagerName).AddUnloadMethod("AiSelectorStaticUnload", UnloadStaticContent); mRegisteredUnloads.Add(ContentManagerName); } } } CustomLoadStaticContent(contentManagerName); }
public void ForceUpdateImageData() { #region Update the texture if (mImageData != null) { for (int x = 0; x < mNumberOfXTiles; x++) { for (int y = 0; y < mNumberOfYTiles; y++) { Color colorToSet; if (mBlockedTiles[x][y] == 0) { if (mRevealedTiles[x][y] == 0) { colorToSet = HiddenClearedColor; } else { colorToSet = RevealedClearedColor; } } else { if (mRevealedTiles[x][y] == 0) { colorToSet = HiddenBlockedColor; } else { colorToSet = RevealedBlockedColor; } } //byte blue = (byte)(255 * (mBlockedTiles[x][y] & 1)); //byte green = (byte)(255 * (mRevealedTiles[x][y] & 1)); //byte red = 255; mImageData.SetPixel(x, y, colorToSet); } } ContentManager contentManager = FlatRedBallServices.GetContentManagerByName(this.ContentManagerName); //FlatRedBallServices.GlobalContentManager); if (mSprite != null) { if (mSprite.Texture != null) { contentManager.UnloadAsset(mSprite.Texture); mSprite.Texture.Dispose(); } bool generateMipmaps = false; mSprite.Texture = mImageData.ToTexture2D(generateMipmaps, FlatRedBallServices.GraphicsDevice); contentManager.AddDisposable("VisibilityGridTexture #" + NumberCreated, mSprite.Texture); NumberCreated++; } } #endregion }
public void UpdateFromStructure(BaseStructure structure, IEntityFactory factory, int currentSatoshis) { BuildingFactory = factory; RangeTuple = new Tuple <int, int>((int)structure.RangedRadius, (int)structure.MinimumRangeRadius); RangeXOffset = structure.PivotPoint.RelativeX; RangeYOffset = structure.SpriteInstance.RelativeY; BuildingType = structure.GetType(); structureInfo = new StructureInfoRuntime.StructureInfoSaveState(structure); UpdateAffordability(currentSatoshis); RenderTarget2D renderTarget = null; var renderName = BuildingType.FullName + ".png"; var contentManagerName = FlatRedBallServices.GlobalContentManager; if (FlatRedBallServices .GetContentManagerByName(contentManagerName) .IsAssetLoadedByName <RenderTarget2D>(renderName)) { renderTarget = FlatRedBallServices .GetContentManagerByName(contentManagerName) .GetDisposable <RenderTarget2D>(renderName); } var baseHeight = structure.SpriteInstance.Height; var baseWidth = structure.SpriteInstance.Width; if (renderTarget == null) { structure.LightSpriteInstance.Visible = false; structure.LightAimSpriteInstance.Visible = false; structure.AimSpriteInstance.RelativeRotationZ = MathHelper.ToRadians(0); structure.Collision.Visible = false; structure.LightSpriteInstance.Visible = false; var relativeY = structure.SpriteInstance.RelativeY; structure.SpriteInstance.RelativeY = 0; relativeY = structure.SpriteInstance.RelativeY - relativeY; structure.PivotPoint.RelativeY += relativeY; structure.ForceUpdateDependenciesDeep(); var aimHeight = structure.AimSpriteInstance.Height; var aimWidth = structure.AimSpriteInstance.Width; var aimRelativeX = structure.PivotPoint.RelativeX + structure.AimSpriteInstance.RelativeX; var aimRelativeY = structure.PivotPoint.RelativeY + structure.AimSpriteInstance.RelativeY; var structureTop = Math.Min(-baseHeight / 2, -aimRelativeY - aimHeight / 2); var structureBottom = Math.Max(baseHeight / 2, -aimRelativeY + aimHeight / 2); var structureLeft = Math.Min(-baseWidth / 2, aimRelativeX - aimWidth / 2); var structureRight = Math.Max((baseWidth / 2), aimRelativeX + aimWidth / 2); var structureHeight = (int)Math.Abs(structureTop - structureBottom); var structureWidth = (int)Math.Abs(structureRight - structureLeft); // This layer holds whatever we want drawn var temporaryLayer = new Layer(); // Define the layer. This uses the current game's resolution, but it could be any size renderTarget = new RenderTarget2D( FlatRedBallServices.GraphicsDevice, structureWidth, structureHeight); temporaryLayer.RenderTarget = renderTarget; structure.MoveToLayer(temporaryLayer); structure.Y = -structureHeight / 2 + structure.SpriteInstance.Height / 2; structure.ForceUpdateDependenciesDeep(); // Rendering requires a camera. We'll create a temporary one (don't add it to the SpriteManager) var temporaryCamera = new Camera(null, structureWidth, structureHeight) { DrawsWorld = false, Z = 40 }; // We only want the camera to draw the layer temporaryCamera.UsePixelCoordinates(); temporaryCamera.AddLayer(temporaryLayer); Renderer.DrawCamera(temporaryCamera, null); //using (var fileStream = File.Create("test.png")) //{ // structureTexture.SaveAsPng(fileStream, structureTexture.Width, structureTexture.Height); //} FlatRedBallServices.AddDisposable( renderName, renderTarget, contentManagerName); } StructureSprite.SourceFile = renderTarget; StructureSprite.TextureHeight = renderTarget.Height; StructureSprite.TextureWidth = renderTarget.Width; StructureSprite.TextureLeft = 0; StructureSprite.TextureTop = 0; if (renderTarget.Width > renderTarget.Height) { StructureSprite.WidthUnits = DimensionUnitType.Percentage; StructureSprite.HeightUnits = DimensionUnitType.PercentageOfOtherDimension; StructureSprite.Width = 100; StructureSprite.Height = baseHeight / baseWidth * 100; } else { StructureSprite.HeightUnits = DimensionUnitType.Percentage; StructureSprite.WidthUnits = DimensionUnitType.PercentageOfOtherDimension; StructureSprite.Height = 100; StructureSprite.Width = baseWidth / baseHeight * 100; } }