public object GetService(Type type)
        {
            Asserter.AssertIsNotNull(type, "type");

            if (_services.ContainsKey(type))
            {
                return(_services[type]);
            }

            return(null);
        }
        public void AddService(Type type, object provider)
        {
            Asserter.AssertIsNotNull(type, "type");
            Asserter.AssertIsNotNull(provider, "provider");
            Asserter.Assert(!_services.ContainsKey(type), "Service is already present.");

            if (!type.IsAssignableFrom(provider.GetType()))
            {
                throw new ArgumentException(string.Format("Service type {0} must be assignable from type {1}.", provider.GetType().FullName, type.FullName));
            }

            _services.Add(type, provider);
        }
Esempio n. 3
0
        public Engine(DrawingSurface drawingSurface)
        {
            RootControl = (Control)App.Current.RootVisual;

            Asserter.AssertIsNotNull(RootControl, "RootControl");
            Asserter.AssertIsNotNull(drawingSurface, "drawingSurface");

            _drawingSurface             = drawingSurface;
            _content                    = new ContentManager(_gameServices);
            _content.RootDirectory      = "Content";
            _totalGameTime              = TimeSpan.Zero;
            _accumulatedElapsedGameTime = TimeSpan.Zero;
            _lastFrameElapsedGameTime   = TimeSpan.Zero;
            _targetElapsedTime          = TimeSpan.FromTicks(166667L);
            _drawState                  = new DrawState();
            _updateState                = new UpdateState();
            _gameServices               = new GameServiceContainer();
        }
 public void RemoveService(Type type)
 {
     Asserter.AssertIsNotNull(type, "type");
     _services.Remove(type);
 }