/// <summary> /// Initializes a new instance of the <see cref="CollisionService" /> class. /// </summary> /// <param name="entityService">The entity service.</param> /// <param name="mapService">The map service.</param> /// <param name="renderService">The render service.</param> /// <param name="varService">The variable service.</param> public CollisionService(IEntityService entityService, IMapService mapService, IRenderService renderService, IVariableService varService) { if (entityService == null) { throw new ArgumentNullException(nameof(entityService)); } if (mapService == null) { throw new ArgumentNullException(nameof(mapService)); } if (renderService == null) { throw new ArgumentNullException(nameof(renderService)); } if (varService == null) { throw new ArgumentNullException(nameof(varService)); } _entityService = entityService; _mapService = mapService; _renderService = renderService; _varService = varService; _quadPool = new QuadtreePool(); _entListPool = new ObjectPool <List <GameEntity> >(() => new List <GameEntity>(10)); _varShowTracelines = _varService.GetVar <bool>("r_showtracelines"); }
/// <summary> /// Initializes a new instance of the <see cref="Renderer" /> class. /// </summary> /// <param name="gameEngine">The game engine.</param> /// <param name="form">The form.</param> /// <param name="width">The primary width of the view in pixels.</param> /// <param name="height">The primary height of the view in pixels.</param> public Renderer(IGameEngine gameEngine, GameForm form, int width, int height) { if (gameEngine == null) { throw new ArgumentNullException(nameof(gameEngine)); } if (form == null) { throw new ArgumentNullException(nameof(form)); } _form = form; _resize = false; _scale = 1.0f; _width = width; _height = height; _dwFactory = new SharpDX.DirectWrite.Factory(); InitFonts(); // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop. SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport); // Query the default device for the supported device and context interfaces. _device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>(); _d3dContext = _device.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>(); // Query for the adapter and more advanced DXGI objects. using (var dxgiDevice2 = _device.QueryInterface <SharpDX.DXGI.Device2>()) { _d2dFactory = new SharpDX.Direct2D1.Factory2(SharpDX.Direct2D1.FactoryType.SingleThreaded); // Get the default Direct2D device and create a context. using (var d2dDevice = new SharpDX.Direct2D1.Device1(_d2dFactory, dxgiDevice2)) { _d2dContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None); } } CreateSizeDependentResources(); _d2dContext.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased; _d2dContext.AntialiasMode = AntialiasMode.Aliased; _d2dContext.UnitMode = UnitMode.Pixels; _hudYellow = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 0.0f, 1.0f)); _hudWhite = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 1.0f, 1.0f)); _hudTextFormat = new TextFormat(_dwFactory, "Sonic Genesis/Mega Drive Font", _fontCollection, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 14); // init game stuff _game = gameEngine; _texResMan = new TextureResourceManager(gameEngine, _d2dContext); _spriteResMan = new SpriteResourceManager(gameEngine, _d2dContext); // get the services _mapService = _game.GetService <IMapService>(); _varService = _game.GetService <IVariableService>(); _entityService = _game.GetService <IEntityService>(); _renderService = _game.GetService <IRenderService>(); _collisionService = _game.GetService <ICollisionService>(); _varShowCollisionMaps = _varService.GetVar <bool>("r_showcollisionmaps"); _varShowTileFrames = _varService.GetVar <bool>("r_showtileframes"); _varShowEntityOrigins = _varService.GetVar <bool>("r_showentityorigins"); _varShowTraceLines = _varService.GetVar <bool>("r_showtracelines"); _varShowCollisionBoxes = _varService.GetVar <bool>("r_showcollisionboxes"); _rc = new RenderContext(); _spriteRenderList = new List <Animatable>(25); }