private void DoInitialize() { AssertNotDisposed(); /* If this is late, you can still create it yourself. * In fact, you can even go as far as creating the * _manager_ before base.Initialize(), but Begin/EndDraw * will not get called. Just... please, make the service * before calling Run(). */ graphicsDeviceManager = (IGraphicsDeviceManager) Services.GetService(typeof(IGraphicsDeviceManager)); if (graphicsDeviceManager != null) { graphicsDeviceManager.CreateDevice(); } Initialize(); /* We need to do this after virtual Initialize(...) is called. * 1. Categorize components into IUpdateable and IDrawable lists. * 2. Subscribe to Added/Removed events to keep the categorized * lists synced and to Initialize future components as they are * added. */ updateableComponents.Clear(); drawableComponents.Clear(); for (int i = 0; i < Components.Count; i += 1) { CategorizeComponent(Components[i]); } Components.ComponentAdded += OnComponentAdded; Components.ComponentRemoved += OnComponentRemoved; }
protected override void Initialize() { if (isSoftwareEmbedded) { // Create the graphics device IGraphicsDeviceManager graphicsDeviceManager = this.Services.GetService(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager; if (graphicsDeviceManager != null) { graphicsDeviceManager.CreateDevice(); } else { throw new Exception("Unable to retrieve GraphicsDeviceManager"); } // Width must a multiple of 2 em_renderTarget2D = new RenderTarget2D(GraphicsDevice, em_sizeViewport.X, em_sizeViewport.Y, true, SurfaceFormat.Bgr565, DepthFormat.Depth16); } Game.CGameManagement.currentState = "CInGame"; Game.CGameManagement.Initialize(); SamplerState sState = new SamplerState(); sState.Filter = TextureFilter.Linear; graphics.GraphicsDevice.SamplerStates[0] = sState; Display2D.C2DEffect.softwareViewport = GraphicsDevice.Viewport; base.Initialize(); }
public void Run() { if (inRun) { throw new InvalidOperationException("Run Method called more than once"); } inRun = true; BeginRun(); gameHost.Initialize(); graphicsManager = (IGraphicsDeviceManager)Services.GetService(typeof(IGraphicsDeviceManager)); if (graphicsManager != null) { graphicsManager.CreateDevice(); } graphicsService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService)); if (graphicsService != null) { /*graphicsService.DeviceCreated += DeviceCreated; * graphicsService.DeviceResetting += DeviceResetting; * graphicsService.DeviceReset += DeviceReset; * graphicsService.DeviceDisposing += DeviceDisposing;*/ } Initialize(); isActive = true; gameHost.Run(); EndRun(); inRun = false; }
private void DoInitialize() { AssertNotDisposed(); if (GraphicsDevice == null) { IGraphicsDeviceManager graphicsDeviceManager = Services.GetService( typeof(IGraphicsDeviceManager) ) as IGraphicsDeviceManager; graphicsDeviceManager.CreateDevice(); } Initialize(); /* We need to do this after virtual Initialize(...) is called. * 1. Categorize components into IUpdateable and IDrawable lists. * 2. Subscribe to Added/Removed events to keep the categorized * lists synced and to Initialize future components as they are * added. */ CategorizeComponents(); _components.ComponentAdded += Components_ComponentAdded; _components.ComponentRemoved += Components_ComponentRemoved; }
internal void InitializeBeforeRun() { try { using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize)) { // Make sure that the device is already created graphicsDeviceManager.CreateDevice(); // Gets the graphics device service graphicsDeviceService = Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; if (graphicsDeviceService == null) { throw new InvalidOperationException("No GraphicsDeviceService found"); } // Checks the graphics device if (graphicsDeviceService.GraphicsDevice == null) { throw new InvalidOperationException("No GraphicsDevice found"); } // Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc BeginDraw(); // Initialize this instance and all game systems Initialize(); LoadContentInternal(); IsRunning = true; BeginRun(); timer.Reset(); updateTime.Reset(totalUpdateTime); // Run the first time an update updateTimer.Reset(); using (Profiler.Begin(GameProfilingKeys.GameUpdate)) { Update(updateTime); } updateTimer.Tick(); singleFrameUpdateTime += updateTimer.ElapsedTime; // Reset PlayTime playTimer.Reset(); // Unbind Graphics Context without presenting EndDraw(false); } } catch (Exception ex) { Log.Error("Unexpected exception", ex); throw; } }
internal void InitializeBeforeRun() { try { using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize)) { // Initialize this instance and all game systems before trying to create the device. Initialize(); // Make sure that the device is already created graphicsDeviceManager.CreateDevice(); // Gets the graphics device service graphicsDeviceService = Services.GetService <IGraphicsDeviceService>(); if (graphicsDeviceService == null) { throw new InvalidOperationException("No GraphicsDeviceService found"); } // Checks the graphics device if (graphicsDeviceService.GraphicsDevice == null) { throw new InvalidOperationException("No GraphicsDevice found"); } // Setup the graphics device if it was not already setup. SetupGraphicsDeviceEvents(); // Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc BeginDraw(); LoadContentInternal(); IsRunning = true; BeginRun(); autoTickTimer.Reset(); UpdateTime.Reset(UpdateTime.Total); // Run the first time an update using (Profiler.Begin(GameProfilingKeys.GameUpdate)) { Update(UpdateTime); } // Unbind Graphics Context without presenting EndDraw(false); } } catch (Exception ex) { Log.Error("Unexpected exception", ex); throw; } }
/// <summary> /// Gives derived classes an opportunity to do work before any /// components are initialized. Note that the base implementation sets /// IsActive to true, so derived classes should either call the base /// implementation or set IsActive to true by their own means. /// </summary> public virtual void BeforeInitialize() { IsActive = true; if (this.Game.GraphicsDevice == null) { IGraphicsDeviceManager graphicsDeviceManager = Game.Services.GetService( typeof(IGraphicsDeviceManager) ) as IGraphicsDeviceManager; graphicsDeviceManager.CreateDevice(); } }
/// <summary> /// 执行初始化操作 /// </summary> internal void DoInitialize() { AssertNotDisposed(); if (GraphicsDevice == null && graphicsDeviceManager != null) { _graphicsDeviceManager.CreateDevice(); } Platform.BeforeInitialize(); Initialize(); }
void IDrawingSurfaceContentProviderNative.GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RawRectangleF textureSubRectangle) { try { if (!Exiting) { // TODO Check if surfaceSize changed to reinitialize the buffers? currentSize = surfaceSize; if (!isInitialized) { InitCallback(); isInitialized = true; } else if (this.synchronizedTexture == null) { // Dispose the graphics device if (graphicsDeviceService.GraphicsDevice != null) { graphicsDeviceService.GraphicsDevice.Dispose(); } // Make sure that the graphics device is created // This will create indirectly the synchronizedTexture on this instance. graphicsDeviceManager.CreateDevice(); } this.synchronizedTexture.BeginDraw(); RunCallback(); host.RequestAdditionalFrame(); this.synchronizedTexture.EndDraw(); } } catch (Exception ex) { // TODO: As we are in a callback from a native code, we cannot pass back this exception, // so how to pass back this exception to the user at an appropriate time? drawException = ex; Debug.WriteLine(drawException); } // Set output parameters. var output = new RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height); textureSubRectangle = new RawRectangleF { Left = output.Left, Top = output.Top, Right = output.Right, Bottom = output.Bottom }; synchronizedTexture = this.synchronizedTexture; }
/// <summary> /// 执行初始化操作 /// </summary> internal void DoInitialize() { AssertNotDisposed(); if (GraphicsDevice == null && graphicsDeviceManager != null) { _graphicsDeviceManager.CreateDevice(); } Platform.BeforeInitialize(); Initialize(); CategorizeComponents(); _components.ComponentAdded += Components_ComponentAdded; _components.ComponentRemoved += Components_ComponentRemoved; }
internal void DoInitialize() { AssertNotDisposed(); if (GraphicsDevice == null && graphicsDeviceManager != null) { _graphicsDeviceManager.CreateDevice(); } Platform.BeforeInitialize(); Initialize(); // We need to do this after virtual Initialize(...) is called. // 1. Categorize components into IUpdateable and IDrawable lists. // 2. Subscribe to Added/Removed events to keep the categorized // lists synced and to Initialize future components as they are // added. // CategorizeComponents(); // _components.ComponentAdded += Components_ComponentAdded; // _components.ComponentRemoved += Components_ComponentRemoved; }
protected override void Initialize() { if (isSoftwareEmbedded) { // Create the graphics device IGraphicsDeviceManager graphicsDeviceManager = this.Services.GetService(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager; if (graphicsDeviceManager != null) { graphicsDeviceManager.CreateDevice(); } else { throw new Exception("Unable to retrieve GraphicsDeviceManager"); } // Width must a multiple of 2 em_renderTarget2D = new RenderTarget2D(GraphicsDevice, em_sizeViewport.X, em_sizeViewport.Y, true, SurfaceFormat.Bgr565, DepthFormat.Depth16); } camera = new CCamera(GraphicsDevice, Vector3.Up + new Vector3(50f), Vector3.Zero, 0.5f, 10000f); base.Initialize(); }
private GraphicsDevice InitializeGraphicsService() { graphicsDeviceService = (IGraphicsDeviceService) Services.GetService(typeof(IGraphicsDeviceService)); if (graphicsDeviceService == null) { throw new InvalidOperationException( "No Graphics Device Service" ); } graphicsDeviceManager = (IGraphicsDeviceManager) Services.GetService(typeof(IGraphicsDeviceManager)); if (graphicsDeviceManager != null) { graphicsDeviceManager.CreateDevice(); } // This should have been filled by CreateDevice! return(graphicsDeviceService.GraphicsDevice); }
public void Run() { if(inRun) throw new InvalidOperationException("Run Method called more than once"); inRun = true; BeginRun(); gameHost.Initialize(); graphicsManager = (IGraphicsDeviceManager)Services.GetService(typeof (IGraphicsDeviceManager)); if (graphicsManager != null) graphicsManager.CreateDevice(); graphicsService = (IGraphicsDeviceService)Services.GetService(typeof (IGraphicsDeviceService)); if (graphicsService != null) { /*graphicsService.DeviceCreated += DeviceCreated; graphicsService.DeviceResetting += DeviceResetting; graphicsService.DeviceReset += DeviceReset; graphicsService.DeviceDisposing += DeviceDisposing;*/ } Initialize(); isActive = true; gameHost.Run(); EndRun(); inRun = false; }