void InitialiseResourceCaches() { ContentManager = new CCContentManager(new GameServiceContainer()); FontAtlasCache = new CCFontAtlasCache(); SpriteFontCache = new CCSpriteFontCache(ContentManager); SpriteFrameCache = new CCSpriteFrameCache(); ParticleSystemCache = new CCParticleSystemCache(Scheduler); TextureCache = new CCTextureCache(Scheduler); AnimationCache = new CCAnimationCache(); // Link new caches to singleton instances // For now, this is required because a layer's resources (e.g. sprite) // may be loaded prior to a gameview being associated with that layer CCContentManager.SharedContentManager = ContentManager; CCFontAtlasCache.SharedFontAtlasCache = FontAtlasCache; CCSpriteFontCache.SharedSpriteFontCache = SpriteFontCache; CCSpriteFrameCache.SharedSpriteFrameCache = SpriteFrameCache; CCParticleSystemCache.SharedParticleSystemCache = ParticleSystemCache; CCTextureCache.SharedTextureCache = TextureCache; CCAnimationCache.SharedAnimationCache = AnimationCache; var serviceProvider = ContentManager.ServiceProvider as GameServiceContainer; serviceProvider.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService); }
public static void PurgeSharedTextureCache() { if (sharedTextureCache != null) { sharedTextureCache.Dispose(); sharedTextureCache = null; } }
// Initialize the stats display. public void Initialize() { if (!isInitialized) { // There is a special case for Xamarin iOS monotouch on emulator where they aggresively call // garbage collection themselves on the simulator. This should not affect the devices though. // So we check if we are running on a Device and only update the counters if we are. #if IOS if (Runtime.Arch != Arch.DEVICE) { isCheckGC = false; } #endif CCTexture2D texture; CCTextureCache textureCache = CCTextureCache.SharedTextureCache; stopwatch = new Stopwatch(); try { texture = !textureCache.Contains("cc_fps_images") ? textureCache.AddImage(CCFPSImage.PngData, "cc_fps_images", CCSurfaceFormat.Bgra4444) : textureCache["cc_fps_images"]; if (texture == null || (texture.ContentSizeInPixels.Width == 0 && texture.ContentSizeInPixels.Height == 0)) { CCLog.Log("CCStats: Failed to create stats texture"); return; } } catch (Exception ex) { // MonoGame may not allow texture.fromstream, // so catch this exception here and disable the stats CCLog.Log("CCStats: Failed to create stats texture:"); if (ex != null) { CCLog.Log(ex.ToString()); } return; } try { texture.IsAntialiased = false; // disable antialiasing so the labels are always sharp fpsLabel = new CCLabelAtlas("00.0", texture, 4, 8, '.'); updateTimeLabel = new CCLabelAtlas("0.000", texture, 4, 8, '.'); drawTimeLabel = new CCLabelAtlas("0.000", texture, 4, 8, '.'); drawCallLabel = new CCLabelAtlas("000", texture, 4, 8, '.'); memoryLabel = new CCLabelAtlas("0", texture, 4, 8, '.'); memoryLabel.Color = new CCColor3B(35, 185, 255); gcLabel = new CCLabelAtlas("0", texture, 4, 8, '.'); gcLabel.Color = new CCColor3B(255, 196, 54); } catch (Exception ex) { CCLog.Log("CCStats: Failed to create stats labels:"); if (ex != null) { CCLog.Log(ex.ToString()); } return; } } var factor = 1.0f; var pos = CCPoint.Zero; //CCApplication.SharedApplication.MainWindowDirector.VisibleOrigin; fpsLabel.Scale = factor; updateTimeLabel.Scale = factor; drawTimeLabel.Scale = factor; drawCallLabel.Scale = factor; memoryLabel.Scale = factor; gcLabel.Scale = factor; memoryLabel.Position = new CCPoint(4 * factor, 44 * factor) + pos; gcLabel.Position = new CCPoint(4 * factor, 36 * factor) + pos; drawCallLabel.Position = new CCPoint(4 * factor, 28 * factor) + pos; updateTimeLabel.Position = new CCPoint(4 * factor, 20 * factor) + pos; drawTimeLabel.Position = new CCPoint(4 * factor, 12 * factor) + pos; fpsLabel.Position = new CCPoint(4 * factor, 4 * factor) + pos; isInitialized = true; }
public CCTextureCache(CCApplication application) : this(application.Scheduler) { sharedTextureCache = this; }
/// <summary> /// Initialize CCStats. /// </summary> public void Initialize() { if (!isInitialized) { // There is a special case for Xamarin iOS monotouch on emulator where they aggresively call // garbage collection themselves on the simulator. This should not affect the devices though. // So we check if we are running on a Device and only update the counters if we are. #if IOS if (Runtime.Arch != Arch.DEVICE) { isCheckGC = false; } #endif CCTexture2D texture; CCTextureCache textureCache = CCTextureCache.SharedTextureCache; stopwatch = new Stopwatch(); try { texture = !textureCache.Contains("cc_fps_images") ? textureCache.AddImage(CCFPSImage.PngData, "cc_fps_images", CCSurfaceFormat.Bgra4444) : textureCache ["cc_fps_images"]; // Analysis disable CompareOfFloatsByEqualityOperator if (texture == null || (texture.ContentSizeInPixels.Width == 0 && texture.ContentSizeInPixels.Height == 0)) { CCLog.Log("CCStats: Failed to create stats texture"); return; } } catch (Exception ex) { // MonoGame may not allow texture.fromstream, // so catch this exception here and disable the stats CCLog.Log("CCStats: Failed to create stats texture:"); if (ex != null) { CCLog.Log(ex.ToString()); } return; } // We will remove the texture cc_fps_images from our cache to fix a problem of loosing the texture // when the cache is purged. If not then the statistics no longer show because it has been Disposed of. textureCache.RemoveTextureForKey("cc_fps_images"); try { texture.IsAntialiased = false; // disable antialiasing so the labels are always sharp fpsLabel = new CCLabelAtlas("00.0", texture, 4, 8, '.'); updateTimeLabel = new CCLabelAtlas("0.000", texture, 4, 8, '.'); drawTimeLabel = new CCLabelAtlas("0.000", texture, 4, 8, '.'); drawCallLabel = new CCLabelAtlas("000", texture, 4, 8, '.'); memoryLabel = new CCLabelAtlas("0", texture, 4, 8, '.'); memoryLabel.Color = new CCColor3B(35, 185, 255); gcLabel = new CCLabelAtlas("0", texture, 4, 8, '.'); gcLabel.Color = new CCColor3B(255, 196, 54); } catch (Exception ex) { CCLog.Log("CCStats: Failed to create stats labels:"); if (ex != null) { CCLog.Log(ex.ToString()); } return; } } isInitialized = true; Scale = 1; }