Exemplo n.º 1
0
        public void TestBasicInvalidations()
        {
            var services = new ServiceRegistry();
            services.AddService(typeof(IGame), new Game());

            var edit = new EditText(services);

            // - test the properties that are supposed to invalidate the object measurement
            UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.Font = null);
            UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.MaxLines = 34);
            UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.MinLines = 34);
            UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.SelectedText = "toto");
            UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.Text = "titi");
            UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.MaxLength = 3); // text is modified

            // - test the properties that are not supposed to invalidate the object layout state
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.IsReadOnly = !edit.IsReadOnly);
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.ActiveImage = new Sprite());
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.InactiveImage = new Sprite());
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.TextColor = new Color(1, 2, 3, 4));
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.SelectionColor = new Color(1, 2, 3, 4));
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.CaretColor = new Color(1, 7, 3, 4));
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.CaretPosition = 34);
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.SelectionLength = 2);
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.SelectionStart = 0);
            UIElementLayeringTests.TestNoInvalidation(edit, () => edit.MaxLength = 34); // text is not modified
        }
Exemplo n.º 2
0
        public SceneRenderer(GameSettingsAsset gameSettings)
        {
            if (gameSettings == null) throw new ArgumentNullException(nameof(gameSettings));

            // Initialize services
            Services = new ServiceRegistry();
            ContentManager = new ContentManager(Services);

            var renderingSettings = gameSettings.Get<RenderingSettings>();
            GraphicsDevice = GraphicsDevice.New(DeviceCreationFlags.None, new[] { renderingSettings.DefaultGraphicsProfile });

            var graphicsDeviceService = new GraphicsDeviceServiceLocal(Services, GraphicsDevice);
            EffectSystem = new EffectSystem(Services);
            GraphicsContext = new GraphicsContext(GraphicsDevice);
            Services.AddService(typeof(GraphicsContext), GraphicsContext);

            SceneSystem = new SceneSystem(Services);

            // Create game systems
            GameSystems = new GameSystemCollection(Services);
            GameSystems.Add(new GameFontSystem(Services));
            GameSystems.Add(new UISystem(Services));
            GameSystems.Add(EffectSystem);
            GameSystems.Add(SceneSystem);
            GameSystems.Initialize();

            // Fake presenter
            // TODO GRAPHICS REFACTOR: This is needed be for render stage setup
            GraphicsDevice.Presenter = new RenderTargetGraphicsPresenter(GraphicsDevice,
                Texture.New2D(GraphicsDevice, renderingSettings.DefaultBackBufferWidth, renderingSettings.DefaultBackBufferHeight,
                    renderingSettings.ColorSpace == ColorSpace.Linear ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget),
                PixelFormat.D24_UNorm_S8_UInt);

            SceneSystem.MainRenderFrame = RenderFrame.FromTexture(GraphicsDevice.Presenter.BackBuffer, GraphicsDevice.Presenter.DepthStencilBuffer);
        }
Exemplo n.º 3
0
 public SkyboxGeneratorContext()
 {
     Services = new ServiceRegistry();
     Assets = new AssetManager(Services);
     GraphicsDevice = GraphicsDevice.New();
     GraphicsDeviceService = new GraphicsDeviceServiceLocal(Services, GraphicsDevice);
     EffectSystem = new EffectSystem(Services);
     EffectSystem.Initialize();
     ((IContentable)EffectSystem).LoadContent();
     ((EffectCompilerCache)EffectSystem.Compiler).CompileEffectAsynchronously = false;
     DrawEffectContext = RenderContext.GetShared(Services);
 }
Exemplo n.º 4
0
 public SkyboxGeneratorContext(SkyboxAsset skybox)
 {
     if (skybox == null) throw new ArgumentNullException(nameof(skybox));
     Skybox = skybox;
     Services = new ServiceRegistry();
     Content = new ContentManager(Services);
     GraphicsDevice = GraphicsDevice.New();
     GraphicsDeviceService = new GraphicsDeviceServiceLocal(Services, GraphicsDevice);
     EffectSystem = new EffectSystem(Services);
     EffectSystem.Initialize();
     ((IContentable)EffectSystem).LoadContent();
     ((EffectCompilerCache)EffectSystem.Compiler).CompileEffectAsynchronously = false;
     RenderContext = RenderContext.GetShared(Services);
     RenderDrawContext = new RenderDrawContext(Services, RenderContext, new GraphicsContext(new CommandList(GraphicsDevice), new ResourceGroupAllocator(GraphicsDevice)));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameBase" /> class.
        /// </summary>
        protected GameBase()
        {
            // Internals
            Log = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
            updateTime = new GameTime();
            drawTime = new GameTime();
            playTimer = new TimerTick();
            updateTimer = new TimerTick();
            totalUpdateTime = new TimeSpan();
            timer = new TimerTick();
            IsFixedTimeStep = false;
            maximumElapsedTime = TimeSpan.FromMilliseconds(500.0);
            TargetElapsedTime = TimeSpan.FromTicks(10000000 / 60); // target elapsed time is by default 60Hz
            lastUpdateCount = new int[4];
            nextLastUpdateCountIndex = 0;

            // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 )
            // Example for a moving average of 4:
            // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f
            const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates)
            var maxLastCount = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length);
            updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length;

            // Externals
            Services = new ServiceRegistry();

            // Asset manager
            Asset = new AssetManager(Services);

            LaunchParameters = new LaunchParameters();
            GameSystems = new GameSystemCollection();

            // Create Platform
            gamePlatform = GamePlatform.Create(this);
            gamePlatform.Activated += gamePlatform_Activated;
            gamePlatform.Deactivated += gamePlatform_Deactivated;
            gamePlatform.Exiting += gamePlatform_Exiting;
            gamePlatform.WindowCreated += GamePlatformOnWindowCreated;

            // Setup registry
            Services.AddService(typeof(IGame), this);
            Services.AddService(typeof(IGamePlatform), gamePlatform);

            IsActive = true;
        }