/// <summary> /// Initialisation de XNA et du SharedGraphicsManager /// </summary> private void InitializeXNA() { Services = new GameServiceContainer(); Services.AddService(typeof(IGraphicsDeviceService), new SharedGraphicsDeviceManager()); Content = new ContentManager(Services); Content.RootDirectory = "Content"; }
public Game1() { Services = new GameServiceContainer(); _graphicsManager = new SharedGraphicsDeviceManager(); Services.AddService(typeof(IGraphicsDeviceService), _graphicsManager); Content = new ContentManager(Services, "Content"); Instance = this; }
/// <summary>Initializes a new game state manager</summary> /// <param name="gameServices"> /// Services container the game state manager will add itself to /// </param> public GameStateManager(GameServiceContainer gameServices) : base(gameServices) { this.gameServices = gameServices; this.activeGameStates = new Stack<GameState>(); // Register ourselves as a service gameServices.AddService(typeof(IGameStateService), this); }
public void Setup() { this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService(); GameServiceContainer services = new GameServiceContainer(); services.AddService( typeof(IGraphicsDeviceService), this.mockedGraphicsDeviceService ); this.testComponent = new GraphicsDeviceDrawableComponent(services); }
/// <summary> /// Initializes a new GUI manager using the XNA service container /// </summary> /// <param name="gameServices"> /// Game service container the GuiManager will register itself in and /// to take the services it consumes from. /// </param> public GuiManager(GameServiceContainer gameServices) { this.gameServices = gameServices; gameServices.AddService(typeof(IGuiService), this); // Do not look for the consumed services yet. XNA uses a two-stage // initialization where in the first stage all managers register themselves // before seeking out the services they use in the second stage, marked // by a call to the Initialize() method. }
public AWGame(GraphicsDeviceService graphicsDeviceService) { GraphicsDeviceService = graphicsDeviceService; Services = new GameServiceContainer(); if (graphicsDeviceService != null) Services.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService); Components = new AWGameComponentCollection(); GameTime = new AWGameTime(); _framerateTimer = new AWTimer(() => GameTime.TotalRealTime, TimeSpan.FromSeconds(1)) { SkipPastIntervals = true }; _frameDrawTimes = new RunningSequenceTimeSpan(TimeSpan.FromSeconds(1)); _frameDrawStopwatch = new Stopwatch(); }
public XnaForms(IntPtr handle, int width, int height) { deviceManager = new DeviceManager(handle, width, height); services = new GameServiceContainer(); services.AddService(typeof (IGraphicsDeviceService), deviceManager); contentManager = new ContentManager(services); gameTime = new GameTime(); }
public Game() { _instance = this; LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); Content = new ContentManager(_services); Platform = GamePlatform.Create(this); Platform.Activated += Platform_Activated; Platform.Deactivated += Platform_Deactivated; _services.AddService(typeof(GamePlatform), Platform); }
public void Initialize(GraphicsDeviceManager graphics) { //Start the log Log.Initialize(); Log.Write("Initializing the engine"); GraphicsDevice = graphics.GraphicsDevice; Blackboard.Set("GraphicsDevice", GraphicsDevice); Blackboard.Set("BasicEffect", new BasicEffect(GraphicsDevice)); Services = new GameServiceContainer(); Services.AddService(typeof(IGraphicsDeviceManager), graphics); Services.AddService(typeof(IGraphicsDeviceService), graphics); //Add content manager ContentManager = new WaffleCatContentManager(Services); ContentManager.RootDirectory = "Content"; Blackboard.Set("ContentManager", ContentManager); if (World == null) World = new World(); World.Initialize(); }
public Game() { _instance = this; TitleContainer.Initialize(); LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); Content = new ContentManager(_services); Platform = GamePlatform.Create(this); Platform.Activated += OnActivated; Platform.Deactivated += OnDeactivated; _services.AddService(typeof(GamePlatform), Platform); /* Set the window title * TODO: Get the title from the WindowsPhoneManifest.xml for WP7 projects */ string windowTitle = string.Empty; // When running unit tests this can return null Assembly assembly = Assembly.GetEntryAssembly(); if (assembly != null) { // Use the Title attribute of the Assembly if possible AssemblyTitleAttribute assemblyTitleAtt = (AssemblyTitleAttribute) AssemblyTitleAttribute.GetCustomAttribute( assembly, typeof(AssemblyTitleAttribute) ); if (assemblyTitleAtt != null) { windowTitle = assemblyTitleAtt.Title; } // Otherwise, fallback to the Name of the assembly if (string.IsNullOrEmpty(windowTitle)) { windowTitle = assembly.GetName().Name; } } Window.Title = windowTitle; }
public Game() { _instance = this; LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); _content = new ContentManager(_services); Platform = GamePlatform.Create(this); Platform.Activated += OnActivated; Platform.Deactivated += OnDeactivated; _services.AddService(typeof(GamePlatform), Platform); #if WINDOWS_STOREAPP && !WINDOWS_PHONE81 Platform.ViewStateChanged += Platform_ApplicationViewChanged; #endif }
public Game() { Instance = this; AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); _content = new ContentManager(_services); Platform = GamePlatform.Create(this); Platform.Activated += OnActivated; Platform.Deactivated += OnDeactivated; _services.AddService(typeof(GamePlatform), Platform); AudioDevice.Initialize(); }
public Game() { _instance = this; LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); Content = new ContentManager(_services); Platform = GamePlatform.Create(this); Platform.Activated += OnActivated; Platform.Deactivated += OnDeactivated; _services.AddService(typeof(GamePlatform), Platform); #if WINDOWS_STOREAPP Platform.ViewStateChanged += Platform_ApplicationViewChanged; #endif #if MONOMAC || WINDOWS || LINUX // Set the window title. // TODO: Get the title from the WindowsPhoneManifest.xml for WP7 projects. string windowTitle = string.Empty; // When running unit tests this can return null. var assembly = Assembly.GetEntryAssembly(); if (assembly != null) { //Use the Title attribute of the Assembly if possible. var assemblyTitleAtt = ((AssemblyTitleAttribute)AssemblyTitleAttribute.GetCustomAttribute(assembly, typeof(AssemblyTitleAttribute))); if (assemblyTitleAtt != null) { windowTitle = assemblyTitleAtt.Title; } // Otherwise, fallback to the Name of the assembly. if (string.IsNullOrEmpty(windowTitle)) { windowTitle = assembly.GetName().Name; } } Window.Title = windowTitle; #endif }
public Game() { _instance = this; LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); _content = new ContentManager(_services); Platform = GamePlatform.PlatformCreate(this); Platform.Activated += OnActivated; Platform.Deactivated += OnDeactivated; _services.AddService(typeof(GamePlatform), Platform); // Calling Update() for first time initializes some systems FrameworkDispatcher.Update(); // Allow some optional per-platform construction to occur too. PlatformConstruct(); }
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(); }
public Game() { _instance = this; LaunchParameters = new LaunchParameters(); _services = new GameServiceContainer(); _components = new GameComponentCollection(); _content = new ContentManager(_services); Platform = GamePlatform.PlatformCreate(this); Platform.Activated += OnActivated; Platform.Deactivated += OnDeactivated; _services.AddService(typeof(GamePlatform), Platform); // Calling Update() for first time initializes some systems FrameworkDispatcher.Update(); #if WINDOWS_STOREAPP && !WINDOWS_PHONE81 Platform.ViewStateChanged += Platform_ApplicationViewChanged; #endif }
/// <summary> /// Initializes the services. /// </summary> private void InitializeServices(GameServiceContainer services) { AlmiranteEngine.ResourceContents = new ResourceContentManager(services, "Content"); services.AddService(typeof(ResourceContentManager), AlmiranteEngine.ResourceContents); AlmiranteEngine.Time = new TimeManager(); services.AddService(typeof(TimeManager), AlmiranteEngine.Time); AlmiranteEngine.Camera = new CameraManager(); services.AddService(typeof(CameraManager), AlmiranteEngine.Camera); AlmiranteEngine.Audio = new AudioManager(); services.AddService(typeof(AudioManager), AlmiranteEngine.Audio); if (!windows) { AlmiranteEngine.DeviceManager = new GraphicsDeviceManager(Application); services.AddService(typeof(GraphicsDeviceManager), AlmiranteEngine.DeviceManager); } AlmiranteEngine.Settings = new Settings(); services.AddService(typeof(Settings), AlmiranteEngine.Settings); AlmiranteEngine.Resources = new ResourceManager(AlmiranteEngine.ResourceContents); services.AddService(typeof(ResourceManager), AlmiranteEngine.Resources); AlmiranteEngine.Input = new InputManager(); services.AddService(typeof(InputManager), AlmiranteEngine.Input); AlmiranteEngine.Scenes = new SceneManager(); services.AddService(typeof(SceneManager), AlmiranteEngine.Scenes); this.InitializeExports(); }
/// <summary> /// Initializes the services. /// </summary> private void InitializeServices(GameServiceContainer services) { ResourceContents = new ResourceContentManager(services, "Content"); services.AddService(typeof (ResourceContentManager), ResourceContents); Time = new TimeManager(); services.AddService(typeof (TimeManager), Time); Camera = new CameraManager(); services.AddService(typeof (CameraManager), Camera); Audio = new AudioManager(); services.AddService(typeof (AudioManager), Audio); if (!windows) { DeviceManager = new GraphicsDeviceManager(Application); services.AddService(typeof (GraphicsDeviceManager), DeviceManager); } Settings = new Settings(); services.AddService(typeof (Settings), Settings); Resources = new ResourceManager(ResourceContents); services.AddService(typeof (ResourceManager), Resources); Input = new InputManager(); services.AddService(typeof (InputManager), Input); Scenes = new SceneManager(); services.AddService(typeof (SceneManager), Scenes); InitializeExports(); }
internal XNAWinFormsHostAppWrapper(XNALogic logic, Application parent, WinFormsHostControl host) { this.parent = parent; this.logic = logic; this.control = host; System.Windows.Forms.Control parentControl = this.control; while (parentControl != null) { if (parentControl is System.Windows.Forms.Form) { this.parentForm = (System.Windows.Forms.Form)parentControl; break; } parentControl = parentControl.Parent; } if (parentForm == null) throw new ArgumentException("Unable to find Parent Form for display handle"); parentForm.MouseWheel += new System.Windows.Forms.MouseEventHandler(parentControl_MouseWheel); parentForm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(parentForm_FormClosed); formsDeviceService = new WinFormsHostGraphicsDeviceService(this, this.control.ClientSize.Width, this.control.ClientSize.Height); services = new GameServiceContainer(); services.AddService(typeof(IGraphicsDeviceService), formsDeviceService); services.AddService(typeof(IGraphicsDeviceManager), formsDeviceService); presentation = RenderTargetUsage.PlatformContents; content = new ContentManager(services); int width = 0; int height = 0; SurfaceFormat format = SurfaceFormat.Color; width = control.ClientSize.Width; height = control.ClientSize.Height; parent.SetWindowSizeAndFormat(width, height, format, DepthFormat.Depth24Stencil8); parent.SetupGraphicsDeviceManager(null, ref presentation); formsDeviceService.CreateDevice(presentation, host); host.SetApplication(parent, this, formsDeviceService); host.BeginInvoke((EventHandler)delegate { parent.SetGraphicsDevice(GraphicsDevice); logic.Initialise(); logic.LoadContent(); }); }
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; }
public void TestCreateFromServiceProvider() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); GameServiceContainer container = new GameServiceContainer(); container.AddService(typeof(IGraphicsDeviceService), service); using(IDisposable keeper = service.CreateDevice()) { using(Drawable drawable = new TestDrawable(container)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }
private void generateDefault_Click(object sender, EventArgs e) { string outputPath =Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Terraria\Texture Packs\Stock\Images"; Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Terraria\Texture Packs\Stock"); Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Terraria\Texture Packs\Stock\Fonts"); Directory.CreateDirectory(outputPath); GameServiceContainer gsc = new GameServiceContainer(); GraphicsAdapter ga = GraphicsAdapter.DefaultAdapter; GraphicsProfile gp = GraphicsProfile.HiDef; PresentationParameters pp = new PresentationParameters(); pp.DeviceWindowHandle = this.Handle; pp.IsFullScreen = false; pp.BackBufferHeight = this.ClientSize.Height; pp.BackBufferWidth = this.ClientSize.Width; pp.BackBufferFormat = SurfaceFormat.Color; GraphicsDevice gd = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, gp, pp); gsc.AddService(typeof(IGraphicsDeviceService), new FakeGraphicsDeviceService(gd)); ContentManager cm = new ContentManager(gsc, Directory.GetCurrentDirectory() + @"\Content"); DirectoryInfo di = new DirectoryInfo(@"Content\Images"); foreach (var fi in di.GetFiles("*.xnb")) { var image = cm.Load<Texture2D>("Images/" + fi.Name.Substring(0, fi.Name.Length - 4)); if (image != null) { using (var fs = new FileStream(String.Format(@"{0}\{1}.png", outputPath, fi.Name.Substring(0, fi.Name.Length - 4)), FileMode.Create, FileAccess.Write)) { image.SaveAsPng(fs, image.Width, image.Height); } } } cm.Dispose(); MessageBox.Show("Stock texture pack created at: \n\n" + outputPath); }
/// <summary> /// Default constructor of form. It sets up the Xna environment /// </summary> public frmMain() { InitializeComponent(); CreateDevice(); defaultDepthStencil = gfxDevice.DepthStencilBuffer; // initialize the content manager GfxService gfxService = new GfxService(gfxDevice); GameServiceContainer services = new GameServiceContainer(); services.AddService(typeof(IGraphicsDeviceService), gfxService); contentMgr = new ContentManager(services,"Content"); spriteBatch = new SpriteBatch(gfxDevice); basicEffect = new BasicEffect(gfxDevice, new EffectPool()); basicEffect.VertexColorEnabled = true; Initialize(); // attach game and control loops (this.scrMainLayout.Panel2 as Control).KeyDown += new KeyEventHandler(this.scrMainLayoutPanel2_KeyDown); (this.scrMainLayout.Panel2 as Control).KeyUp += new KeyEventHandler(this.scrMainLayoutPanel2_KeyUp); (this.scrMainLayout.Panel2 as Control).MouseWheel += new MouseEventHandler(this.scrMainLayoutPanel2_MouseWheel); gameLoopEvent = new EventHandler(Application_Idle); Application.Idle += gameLoopEvent; long perfcount; QueryPerformanceCounter(out perfcount); lastTimeCount = perfcount; }
/// <summary> /// Creates a service provider containing only the graphics device service /// </summary> /// <param name="graphicsDeviceService"> /// Graphics device service that will be provided by the service provider /// </param> /// <returns> /// A new service provider that provides the graphics device service /// </returns> public static IServiceProvider MakePrivateServiceProvider( IGraphicsDeviceService graphicsDeviceService ) { GameServiceContainer serviceContainer = new GameServiceContainer(); serviceContainer.AddService( typeof(IGraphicsDeviceService), graphicsDeviceService ); return serviceContainer; }
/// <summary>Handles second-stage initialization of the GUI manager</summary> public void Initialize() { // Set up a default input capturer if none was assigned by the user. // We only require an IInputService if the user doesn't use a custom input // capturer (which could be based on any other input library) if (this.inputCapturer == null) { if (this.inputService == null) { this.inputService = getInputService(this.gameServices); } this.inputCapturer = new Input.DefaultInputCapturer(this.inputService); // If a screen was assigned to the GUI before the input capturer was // created, then the input capturer hasn't been given the screen as its // input sink yet. if (this.screen != null) { this.inputCapturer.InputReceiver = this.screen; } } // Set up a default GUI visualizer if none was assigned by the user. // We only require an IGraphicsDeviceService if the user doesn't use a // custom visualizer (which could be using any kind of rendering) if (this.guiVisualizer == null) { if (this.graphicsDeviceService == null) { this.graphicsDeviceService = getGraphicsDeviceService(this.gameServices); } // Use a private service container. We know exactly what will be loaded from // the content manager our default GUI visualizer creates and if the user is // being funny, the graphics device service passed to the constructor might // be different from the one registered in the game service container. var services = new GameServiceContainer(); services.AddService(typeof(IGraphicsDeviceService), this.graphicsDeviceService); Visualizer = Visuals.Flat.FlatGuiVisualizer.FromResource( services, Resources.SuaveSkinResources.ResourceManager, "SuaveSkin" ); } }
private static void InitializeDefaultCore(IGraphicsDeviceService graphicsDeviceService) { if (graphicsDeviceService == null) throw new ArgumentNullException("graphicsDeviceService"); //TODO: Remove this or make a way to remove it if it is not used (ContentManager) //////////////////////////////////////////////////////////////// var services = new GameServiceContainer(); services.AddService(typeof (IGraphicsDeviceService), graphicsDeviceService); //TODO: Enable the user to change the RootDirectory _contentManager = new ContentManager(services, "Content"); /////////////////////////////////////////////////// SpriteRenderer = new SpriteBatchRenderer(Window.GraphicsDevice); Entities = new EntitiesManager(); Settings = new SettingsManager(); Input = new InputManager(); Cameras = new CameraManager(); Music = new MusicManager(_contentManager); SoundFX = new SoundFXManager(_contentManager); Textures = new TextureManager(_contentManager); Fonts = new FontsManager(_contentManager); InitializeManagers(); }
private void IntializeContentManager() { GameServiceContainer gameProvider = new GameServiceContainer(); gameProvider.AddService(typeof(IGraphicsDeviceService), new MyGraphicsDeviceService(GraphicsDevice)); Content = new ContentManager(gameProvider); }