コード例 #1
0
ファイル: StyleManager.cs プロジェクト: OkashiKami/Odyssey
        public StyleManager(IServiceRegistry services)
        {
            this.services = services;
            content       = services.GetService <IAssetProvider>();

            content.AddMapping("Theme", typeof(Theme));
            content.AddMapping("Font", typeof(Font));

            content.AssetsLoaded += InitializeFontCollection;
            sharedResources       = new Dictionary <string, ResourceDescription>();
        }
コード例 #2
0
ファイル: Application.cs プロジェクト: OkashiKami/Odyssey
        internal Application()
        {
            var platformTypeAttribute = ReflectionHelper.GetAttribute <PlatformTypeAttribute>(GetType());

            if (!ReflectionHelper.IsTypeDerived(platformTypeAttribute.PlatformType, typeof(ApplicationPlatform)))
            {
                throw new InvalidOperationException("PlatformType must be derived from ApplicationPlatform.");
            }

            services                 = new ServiceRegistry();
            appTime                  = new ApplicationTime();
            totalTime                = new TimeSpan();
            timer                    = new TimerTick();
            IsFixedTimeStep          = false;
            maximumElapsedTime       = TimeSpan.FromMilliseconds(500.0);
            TargetElapsedTime        = TimeSpan.FromTicks(10000000 / 120); // 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;

            services.AddService(typeof(IWindowService), this);
            services.AddService(typeof(ITimeService), appTime);

            // Setup Content Manager
            contentManager = new ContentManager(services);
            contentManager.AddMapping(AssetType.EngineReferences, typeof(EngineReferenceCollection));
            contentManager.AddMapping(AssetType.Model, typeof(Model));
            contentManager.AddMapping(AssetType.Effect, typeof(ShaderCollection));
            contentManager.AddMapping(AssetType.Texture2D, typeof(Texture2D));
            contentManager.AddMapping(AssetType.TextureCube, typeof(TextureCube));
            contentManager.AddMapping(AssetType.Cutscene, typeof(Cutscene));

            var additionalServices = ReflectionHelper.GetAttributes <RequiredServiceAttribute>(GetType());

            foreach (var requiredService in additionalServices)
            {
                var service = Activator.CreateInstance(requiredService.ClassType, services);
                services.AddService(requiredService.ServiceType, service);
            }

            // Setup Platform
            applicationPlatform                = (ApplicationPlatform)Activator.CreateInstance(platformTypeAttribute.PlatformType, this);
            applicationPlatform.Activated     += ApplicationPlatformActivated;
            applicationPlatform.Deactivated   += ApplicationPlatformDeactivated;
            applicationPlatform.Exiting       += ApplicationPlatform_Exiting;
            applicationPlatform.WindowCreated += ApplicationPlatformWindowCreated;
        }