internal void Initialize(D3D11Host host)
        {
            Services = new GameServiceContainer();

            ServiceLocator.Initialize(Services);

            Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", host.GraphicsDevice);
            Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services);

            Services.AddService<IGraphicsDeviceService>(host);
            Services.AddService(host.GraphicsDevice);

            _mouse = new MouseService(host);
            Services.AddService<IMouseService>(_mouse);
            _mouse.ButtonDown += OnMouseButtonDown;
            _keyboard = new KeyboardService(host);
            Services.AddService<IKeyboardService>(_keyboard);
            _timer = new TimerService();
            Services.AddService<ITimerService>(_timer);
            Services.AddService(new FastSpriteBatch(host.GraphicsDevice));

            _timer.LastFrameUpdateTime = _gameTime;
            _timer.LastFrameRenderTime = _gameTime;

            SpriteBatch = new SpriteBatch(host.GraphicsDevice);
            Services.AddService(SpriteBatch);

            Content = new ContentManager(Services);
            Content.RootDirectory = Environment.CurrentDirectory;

            SpriteManager = new SpriteManagerService(Content);
            Services.AddService<ISpriteManagerService>(SpriteManager);

            SpriteManager.LoadSpriteSheet("Textures/Hulls.json");

            Host = host;
            World = new EntityWorld(false, false, false);
            int drawDepth = 0;
            World.CreateComponentPool<Transform>(200, 200);
            World.SystemManager.SetSystem(new GridRendererSystem(), Artemis.Manager.GameLoopType.Draw, drawDepth++);
            World.InitializeAll();
            World.CreateCamera(Constants.ActiveCameraTag, Host.GraphicsDevice);
            Emitter = new ParticleEmitterComponent();
        }
Example #2
0
 protected Scene()
 {
     World = new EntityWorld(false, false, false);
     World.CreateComponentPool<Transform>(200, 200);
 }
        internal void Initialize(D3D11Host host)
        {
            if (IsInitialized) return;
            IsInitialized = true;

            Services = new GameServiceContainer();

            ServiceLocator.Initialize(Services);
            _host = host;

            Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", _host.GraphicsDevice);
            Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services);

            Services.AddService<IGraphicsDeviceService>(host);
            Services.AddService(host.GraphicsDevice);

            _mouse = new MouseService(host);
            Services.AddService<IMouseService>(_mouse);
            _mouse.ButtonDown += OnMouseButtonDown;
            _keyboard = new KeyboardService(host);
            Services.AddService<IKeyboardService>(_keyboard);
            _timer = new TimerService();
            Services.AddService<ITimerService>(_timer);
            Services.AddService(new FastSpriteBatch(host.GraphicsDevice));

            _timer.LastFrameUpdateTime = _gameTime;
            _timer.LastFrameRenderTime = _gameTime;

            SpriteBatch = new SpriteBatch(host.GraphicsDevice);
            Services.AddService(SpriteBatch);

            Content = new ContentManager(Services);
            Content.RootDirectory = Environment.CurrentDirectory;

            SpriteManager = new SpriteManagerService(Content);
            Services.AddService<ISpriteManagerService>(SpriteManager);

            //LoadHullSprites("textures/hulls.json");

            Artemis.System.EntitySystem.BlackBoard.SetEntry("ContentManager", Content);

            World = new EntityWorld(false, false, false);

            World.CreateComponentPool<Transform>(200, 200);

            _gridSystem = new GridRendererSystem();
            _gridSystem.IsEnabled = false;
            World.SystemManager.SetSystem(_gridSystem, Artemis.Manager.GameLoopType.Draw, 1);
            //World.SystemManager.SetSystem(new ShipRendererSystem(), Artemis.Manager.GameLoopType.Draw, 2);
            World.SystemManager.SetSystem(new SceneGraphRendererSystem<StandardShipModelRenderer>(new StandardShipModelRenderer()), Artemis.Manager.GameLoopType.Draw, 3);
            World.SystemManager.SetSystem(new BoundingBoxRendererSystem(), Artemis.Manager.GameLoopType.Draw, 4);
            World.SystemManager.SetSystem(new GenericDrawableRendererSystem(), Artemis.Manager.GameLoopType.Draw, 5);
            _hardpointRendererSystem = new HardpointRendererSystem();
            _hardpointRendererSystem.IsEnabled = false;
            World.SystemManager.SetSystem(_hardpointRendererSystem, Artemis.Manager.GameLoopType.Draw, 6);

            World.SystemManager.SetSystem(new CameraControlSystem(), Artemis.Manager.GameLoopType.Update, 1);
            _transformSystem = new MouseControlledTransformSystem();
            World.SystemManager.SetSystem(_transformSystem, Artemis.Manager.GameLoopType.Update, 2);
            World.SystemManager.SetSystem(new ShipUpdateSystem(), Artemis.Manager.GameLoopType.Update, 3);
            World.SystemManager.SetSystem(new BoundingBoxSelectionSystem(), Artemis.Manager.GameLoopType.Update, 4);
            World.SystemManager.SetSystem(new ShowThrusterTrailsOverrideSystem(), Artemis.Manager.GameLoopType.Update, 5);

            World.InitializeAll();

            CameraEntity = World.CreateCamera(Constants.ActiveCameraTag, _host.GraphicsDevice);
            CameraEntity.Tag = Constants.ActiveCameraTag;
            Camera = CameraEntity.GetComponent<Camera>();

            GridEntity = World.CreateGrid(new Vector2(50, 50), GridColor);

            World.CreateCircle(Vector2.Zero, 10, 8, XnaColor.Red * 0.4f);

            host.PreviewKeyDown += HandleKeyboardInput;

            EditorService = new ShipEditorService(_mouse, World);
            CreateNewShipModelCommand.Execute(null);
            EditorService.SelectedPartEntities.CollectionChanged += (o, e) =>
            {
                if (e.NewItems != null && e.NewItems.Count > 0) {
                    var color = e.NewItems.Cast<Entity>().First().GetComponent<IShipPartComponent>().Part.Color;
                    _selectedColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedColor)));
                }
            };

            
            _mouse.WheelChanged += OnWheelChanged;
            IsHardpointsVisible = false;
            LoadHullSprites("textures/hulls.json");
            IsGridVisible = true;
        }