Ejemplo n.º 1
0
        public DependencyContainer Register(string name, Type type, Func <object> builder)
        {
            var cacheKey = new NameAndType(name, type);

            if (!_registrations.TryGetValue(cacheKey, out var list))
            {
                _registrations.TryAdd(cacheKey, list = new List <Func <object> >());
            }

            list.Add(builder);

            var enumerableCacheKey = new NameAndType($"{Constants.EnumerableSlot}{name}", typeof(IEnumerable <>).MakeGenericType(type));

            if (_registrations.TryGetValue(enumerableCacheKey, out var enumerableList))
            {
                return(this);
            }

            if (_registrations.TryAdd(enumerableCacheKey, enumerableList = new List <Func <object> >()))
            {
                enumerableList.Add(() =>
                {
                    var collection = (IList)Instancing.CreateInstance(typeof(List <>).MakeGenericType(type));
                    foreach (var itemBuilder in list)
                    {
                        collection.Add(itemBuilder());
                    }
                    return(collection);
                });
            }

            return(this);
        }
Ejemplo n.º 2
0
        public IActionResult Patch([FromQuery] string type, [FromBody] JsonPatchDocument patch,
                                   [FromRoute] string section = null)
        {
            if (string.IsNullOrWhiteSpace(section))
            {
                return(this.NotAcceptableError(ErrorEvents.UnsafeRequest,
                                               "You must specify a known configuration sub-section, to avoid exposing sensitive root-level data."));
            }

            var prototype = ResolvePrototypeName(type);

            if (prototype == null)
            {
                return(this.NotAcceptableError(ErrorEvents.InvalidParameter,
                                               $"No configuration type found with name '{type}'."));
            }

            var config = _root.GetSection(section.Replace("/", ":"));

            if (config == null)
            {
                return(this.NotFoundError(ErrorEvents.InvalidParameter,
                                          $"Configuration sub-section path '{section}' not found."));
            }

            var model = Instancing.CreateInstance(prototype);

            config.FastBind(model, _customBinders);
            patch.ApplyTo(model);

            return(Put(type, model, section));
        }
Ejemplo n.º 3
0
 public void LoadFromCache(Instancing.CachedPrefab cachedGO)
 {
     MonoHash hash = helper.GetHash();
     hash.fullPosHash = cachedGO.hash;
     MonoHash.AddToHashLookup(hash, helper);
     helper.transform.position = cachedGO.position;
     helper.transform.localScale = cachedGO.scale;
     helper.transform.rotation = Quaternion.Euler(cachedGO.rotation);
     JSONClass components = cachedGO.components;
     for (int i = 0; i < components.Count; i++)
     {
         System.Type key = System.Type.GetType(components.GetKey(i));
         if (key == null)
         {
             Console.LogWarning("Could not find key " + components.GetKey(i) + " in " + helper.name + ".");
             continue;
         }
         MonoHelper component = helper.GetComponentInChildren(key) as MonoHelper;
         if (component == null)
         {
             Console.LogWarning("Could not find component " + components.GetKey(i) + " in " + helper.name + ".");
             continue;
         }
         component.FromJSON(components[i].AsObject);
     }
 }
Ejemplo n.º 4
0
 private TPrototype TryGetImplementation <TInterface, TPrototype>()
     where TPrototype : class, TInterface
 {
     return(ServiceProvider?.GetService(typeof(TPrototype)) as TPrototype ??
            Instancing.CreateInstance <TPrototype>() ??
            Dummy <TPrototype>());
 }
    public void AddInstance(GameObject obj)
    {
        //TODO
        Instancing script = obj.GetComponent <Instancing>();

        script.InitializeAnimation();
        _InstancingData.Add(script);
    }
Ejemplo n.º 6
0
        public static TBuilder AddActiveRoute <TBuilder, TController, TFeature, TFeatureOptions>(
            this IMvcCoreBuilder mvcBuilder)
            where TBuilder : IFeatureBuilder
            where TFeature : class, IDynamicFeature
            where TFeatureOptions : class
        {
            AddActiveRouteImpl <TController, TFeature, TFeatureOptions>(mvcBuilder);

            return(Instancing.CreateInstance <TBuilder>(mvcBuilder.Services));
        }
    private void Start()
    {
        playerWeapon      = GetComponentInChildren <Instancing>();
        playerMover       = GetComponent <CharacterMover>();
        PauseMenu.enabled = false;
        Paused            = false;

        StartCoroutine(PauseMenuStart());
        StartCoroutine(PauseMenuStop());
    }
    public GameObject CreateInstance(GameObject prefab)
    {
        Debug.Assert(prefab != null);
        GameObject obj    = Instantiate(prefab, Vector3.zero, Quaternion.identity);
        Instancing script = obj.GetComponent <Instancing>();

        //AnimationInstancing prototypeScript = prefab.GetComponent<AnimationInstancing>();
        script.prototype = prefab;
        return(obj);
    }
Ejemplo n.º 9
0
        public override ShapedData <T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            if (reader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException();
            }

            T data;

            if (typeof(T).ImplementsGeneric(typeof(Many <>)))
            {
                // FIXME: Instancing can't handle nested generic types, so we have to use manual reflection here
                //        until it is resolved.
                var underlyingType = typeof(T).GetGenericArguments()[0];
                var enumerableType = typeof(List <>).MakeGenericType(underlyingType);
                var enumerable     = Activator.CreateInstance(enumerableType);
                data = (T)(Activator.CreateInstance(typeof(T), enumerable) ?? throw new NullReferenceException());
            }
            else
            {
                data = Instancing.CreateInstance <T>();
            }

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return(new ShapedData <T>(data)); // success: end of object
                }
                if (reader.TokenType != JsonTokenType.PropertyName)
                {
                    throw new JsonException(); // fail: did not pass through previous property value
                }
                var key = reader.GetString();

                if (string.IsNullOrWhiteSpace(key) || !_members.TryGetValue(key, out var member) || !member.CanWrite)
                {
                    continue;
                }

                var value = JsonSerializer.Deserialize(ref reader, member.Type, options);

                if (!_writer.TrySetValue(data, key, value !))
                {
                    throw new JsonException();
                }
            }

            // fail: passed through JsonTokenType.EndObject
            throw new JsonException();
        }
Ejemplo n.º 10
0
        private object BindTemplateInstance(Type type, IConfiguration config)
        {
            lock (Sync)
            {
                var template = Instancing.CreateInstance(type);
                if (!_empties.TryGetValue(type, out _))
                {
                    _empties.Add(type, ValueHash.ComputeHash(template));
                }

                config.FastBind(template, _customBinders);
                return(ValueHash.ComputeHash(template) == _empties[type] ? null : template);
            }
        }
Ejemplo n.º 11
0
        // ReSharper disable once SuggestBaseTypeForParameter
        private static object GetTestContainerInstance(Type type, TestFixture fixture, IMessageLogger logger)
        {
            logger?.SendMessage(TestMessageLevel.Informational, $"Creating instance for type {type.FullName}");

            object instance = null;

            try
            {
                if (type.GetConstructor(new[] { typeof(TestFixture) }) != null)
                {
                    logger?.SendMessage(TestMessageLevel.Informational, $"{type.Name}(TestFixture fixture) {{ ... }}");
                    instance = Instancing.CreateInstance(type, fixture);
                }
                else if (type.GetConstructor(new[] { typeof(IServiceCollection) }) != null)
                {
                    logger?.SendMessage(TestMessageLevel.Informational,
                                        $"{type.Name}(IServiceCollection services) {{ ... }}");
                    instance = Instancing.CreateInstance(type, fixture);
                }
                else if (type.GetConstructor(new[] { typeof(IServiceProvider) }) != null)
                {
                    logger?.SendMessage(TestMessageLevel.Informational,
                                        $"{type.Name}(IServiceProvider serviceProvider) {{ ... }}");
                    instance = Instancing.CreateInstance(type, fixture);
                }
                else if (type.GetConstructor(Type.EmptyTypes) != null)
                {
                    logger?.SendMessage(TestMessageLevel.Informational, $"{type.Name}() {{ ... }}");
                    instance = Instancing.CreateInstance(type);
                }
            }
            catch (Exception e)
            {
                logger?.SendMessage(TestMessageLevel.Error, e.ToString());
                instance = null;
            }

            if (instance != null)
            {
                return(instance);
            }

            logger?.SendMessage(TestMessageLevel.Error,
                                "Could not find a suitable constructor for the test containing class");
            return(null);
        }
Ejemplo n.º 12
0
 protected GivenACollectionStore(string endpoint, ITestOutputHelper output,
                                 WebApplicationFactory <TStartup> factory)
 {
     _endpoint = endpoint;
     _factory  = factory.WithTestLogging(output)
                 .WithoutLocalizationStartupService()
                 .WithWebHostBuilder(builder =>
     {
         builder.ConfigureTestServices(services =>
         {
             services.RemoveAll <TService>();
             services.AddSingleton(r =>
             {
                 var service = Instancing.CreateInstance <TService>(services.BuildServiceProvider());
                 Populate(service);
                 return(service);
             });
         });
     });
 }
Ejemplo n.º 13
0
        public void Invoke(string handler)
        {
            if (!_handlers.TryGetValue(handler, out var accessor))
            {
                var tokens = handler.Split('.');
                if (tokens.Length > 1)
                {
                    var typeString   = tokens[0];
                    var methodString = tokens[1];

                    var resolver = UiServices.GetRequiredService <ITypeResolver>();
                    var type     = resolver.FindFirstByName(typeString);
                    var method   = type.GetMethod(methodString);

                    _instances[handler] = Instancing.CreateInstance(type, UiServices);
                    _handlers[handler]  = accessor = CallAccessor.Create(method);
                }
            }

            accessor?.Call(_instances[handler], UiServices);
        }
Ejemplo n.º 14
0
        public static object ToAnonymousObject(IDictionary <string, object> hash)
        {
            var anonymousType = TypeFactory.BuildAnonymousType(hash);
            var instance      = Instancing.CreateInstance(anonymousType);
            var accessor      = WriteAccessor.Create(anonymousType, AccessorMemberTypes.Properties,
                                                     AccessorMemberScope.Public, out var members);

            foreach (var member in members)
            {
                if (!member.CanWrite)
                {
                    continue; // should be accessible by design
                }
                if (!hash.TryGetValue(member.Name, out var value))
                {
                    continue; // should be mapped one-to-one
                }
                accessor.TrySetValue(instance, member.Name, value);
            }

            return(instance);
        }
Ejemplo n.º 15
0
        private static void AddActiveRouteImpl <TController, TFeature, TFeatureOptions>(IMvcCoreBuilder mvcBuilder)
            where TFeature : class, IDynamicFeature
            where TFeatureOptions : class
        {
            // Add [DynamicController(typeof(TComponentOptions))] if not present
            if (!typeof(TController).HasAttribute <DynamicControllerAttribute>())
            {
                var attribute = new DynamicControllerAttribute(typeof(TFeatureOptions));
                TypeDescriptor.AddAttributes(typeof(TController), attribute);
                var attributes = TypeDescriptor.GetAttributes(typeof(TController));
                if (!attributes.Contains(attribute))
                {
                    throw new InvalidOperationException("Could not add attribute dynamically on this runtime.");
                }
            }

            // See: https://github.com/aspnet/Mvc/issues/5992
            mvcBuilder.AddApplicationPart(typeof(TController).Assembly);
            mvcBuilder.ConfigureApplicationPartManager(x =>
            {
                x.ApplicationParts.Add(new DynamicControllerApplicationPart(new[] { typeof(TController).GetTypeInfo() }));
            });

            var componentDescriptor = ServiceDescriptor.Singleton(r =>
            {
                var component = Instancing.CreateInstance <TFeature>();
                component.GetRouteTemplate = () =>
                {
                    var o = r.GetRequiredService <IOptionsMonitor <TFeatureOptions> >();
                    return(o.CurrentValue is IFeatureNamespace ns ? ns.RootPath ?? string.Empty : string.Empty);
                };
                return(component);
            });

            mvcBuilder.Services.Replace(componentDescriptor);
            mvcBuilder.Services.AddTransient <IDynamicFeature>(r =>
            {
                // cached singleton
                var component = r.GetService <TFeature>();

                // each resolution, we could be discovering a different controller that needs hydration into its type
                for (var i = 0; i < component.ControllerTypes.Count; i++)
                {
                    var controllerType = component.ControllerTypes[i];
                    if (controllerType.IsGenericType && controllerType.Name == typeof(TController).Name)
                    {
                        component.ControllerTypes[i] = typeof(TController);
                    }
                }

                return(component);
            });

            mvcBuilder.AddAuthorization(x =>
            {
                if (x.GetPolicy(Constants.Security.Policies.NoPolicy) == null)
                {
                    x.AddPolicy(Constants.Security.Policies.NoPolicy, b => { b.RequireAssertion(context => true); });
                }
            });
        }
Ejemplo n.º 16
0
        public bool TryResolve(string name, Type type, out object instance)
        {
            var cacheKey = new NameAndType(name, type);

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                var enumerableCacheKey = new NameAndType($"{Constants.EnumerableSlot}{name}", typeof(IEnumerable <>).MakeGenericType(type.GetGenericArguments()));
                if (_registrations.TryGetValue(enumerableCacheKey, out var enumerableList))
                {
                    foreach (var entry in enumerableList)
                    {
                        instance = entry();

                        if (!_registrations.ContainsKey(cacheKey))
                        {
                            return(true); // nothing to merge
                        }
                        var merged = (IList)Instancing.CreateInstance(typeof(List <>).MakeGenericType(type.GetGenericArguments()));
                        foreach (var x in (IList)instance)
                        {
                            merged.Add(x);
                        }

                        if (_registrations.TryGetValue(cacheKey, out var singleList))
                        {
                            foreach (var y in singleList)
                            {
                                foreach (var x in (IList)y())
                                {
                                    merged.Add(x);
                                }

                                break;
                            }
                        }

                        instance = merged;
                        return(true);
                    }
                }
            }

            if (_registrations.TryGetValue(cacheKey, out var list))
            {
                foreach (var entry in list)
                {
                    instance = entry();
                    return(true);
                }
            }

            if (!type.IsAbstract)
            {
                instance = Instancing.CreateInstance(type, this);
                if (instance != null)
                {
                    return(true);
                }
            }

            instance = _fallback?.GetService(type);
            if (instance != null)
            {
                return(true);
            }

            instance = default;
            return(false);
        }
Ejemplo n.º 17
0
 public void DistroyInstace(Instancing instance)
 {
     //TODO
 }
Ejemplo n.º 18
0
    private void generateBoneMatrixData()
    {
        Vector3 cameraPosition = cameraTransform.position;

        for (int i = 0; i != _InstancingData.Count; ++i) //对列表中每个对象做Instancing。
        {
            Instancing instance = _InstancingData[i];
            //if (!instance.IsPlaying())
            //    continue;
            //if (instance.aniIndex < 0 && instance.parentInstance == null)
            //    continue;

            instance.UpdateAnimation();

            //if (!instance.visible)
            //    continue;

            //here only one Lod
            //instance.UpdateLod(cameraPosition);

            //Instancing.LodInfo lod = instance.lodInfo[instance.lodLevel];
            Instancing.LodInfo lod = instance.lodInfo[0];

            int aniTextureIndex = -1;
            //if (instance.parentInstance != null)
            //    aniTextureIndex = instance.parentInstance.aniTextureIndex;
            //else
            aniTextureIndex = instance.aniTextureIndex;

            for (int j = 0; j != lod.vertexCacheList.Length; ++j)
            {
                VertexCache cache        = lod.vertexCacheList[j] as VertexCache;
                int         packageIndex = cache.runtimePackageIndex[aniTextureIndex];
                Debug.Assert(packageIndex < cache.packageList[aniTextureIndex].Count);
                VertexCache.InstancingPackage package = cache.packageList[aniTextureIndex][packageIndex];
                if (package.instancingCount + 1 > instancingPackageSize)
                {
                    ++cache.runtimePackageIndex[aniTextureIndex];
                    packageIndex = cache.runtimePackageIndex[aniTextureIndex];
                    if (packageIndex >= cache.packageList[aniTextureIndex].Count)
                    {
                        VertexCache.InstancingPackage newPackage = CreatePackage(cache.instanceData,
                                                                                 cache.mesh,
                                                                                 cache.materials,
                                                                                 aniTextureIndex);
                        cache.packageList[aniTextureIndex].Add(newPackage);
                        PreparePackageMaterial(newPackage, cache, aniTextureIndex);
                        newPackage.instancingCount = 1;
                    }
                }
                else
                {
                    ++package.instancingCount;
                }
            }

            VertexCache  vertexCache = lod.vertexCacheList[0];
            InstanceData data        = vertexCache.instanceData;

            int index = vertexCache.runtimePackageIndex[aniTextureIndex];
            VertexCache.InstancingPackage pkg = vertexCache.packageList[aniTextureIndex][index];
            int count = pkg.instancingCount - 1;
            if (count >= 0)
            {
                Matrix4x4   worldMat = instance.worldTransform.localToWorldMatrix;
                Matrix4x4[] arrayMat = data.WorldMatrix[aniTextureIndex][index];
                arrayMat[count].m00 = worldMat.m00;
                arrayMat[count].m01 = worldMat.m01;
                arrayMat[count].m02 = worldMat.m02;
                arrayMat[count].m03 = worldMat.m03;
                arrayMat[count].m10 = worldMat.m10;
                arrayMat[count].m11 = worldMat.m11;
                arrayMat[count].m12 = worldMat.m12;
                arrayMat[count].m13 = worldMat.m13;
                arrayMat[count].m20 = worldMat.m20;
                arrayMat[count].m21 = worldMat.m21;
                arrayMat[count].m22 = worldMat.m22;
                arrayMat[count].m23 = worldMat.m23;
                arrayMat[count].m30 = worldMat.m30;
                arrayMat[count].m31 = worldMat.m31;
                arrayMat[count].m32 = worldMat.m32;
                arrayMat[count].m33 = worldMat.m33;
                float frameIndex = 0, preFrameIndex = -1;
                //if (instance.parentInstance != null)
                //{
                //    frameIndex = instance.parentInstance.aniInfo[instance.parentInstance.aniIndex].animationIndex +
                //                 instance.parentInstance.curFrame;
                //    if (instance.parentInstance.preAniIndex >= 0)
                //        preFrameIndex =
                //            instance.parentInstance.aniInfo[instance.parentInstance.preAniIndex].animationIndex +
                //            instance.parentInstance.preAniFrame;
                //}
                //else
                //{
                //frameIndex = instance.aniInfo[instance.aniIndex].animationIndex + instance.curFrame;
                //if (instance.preAniIndex >= 0)
                //    preFrameIndex = instance.aniInfo[instance.preAniIndex].animationIndex + instance.preAniFrame;
                frameIndex = instance.curFrame;
                if (instance.preAniIndex >= 0)
                {
                    preFrameIndex = instance.preAniFrame;
                }
                //}

                data.FrameIndex[aniTextureIndex][index][count]         = frameIndex;
                data.PreFrameIndex[aniTextureIndex][index][count]      = preFrameIndex;
                data.TransitionProgress[aniTextureIndex][index][count] = instance.transitionProgress;
            }
        }
    }
Ejemplo n.º 19
0
        public static IHostBuilder ConfigureApiServer <TStartup>(this IHostBuilder builder, Func <IConfiguration, IConfiguration>?configSelector = default) where TStartup : class
        {
            TStartup?startup = default;

            builder.ConfigureLogging((context, loggingBuilder) =>
            {
                loggingBuilder.AddLightingDb("logging");
            });

            builder.ConfigureAppConfiguration((context, configBuilder) => { });

            builder.ConfigureWebHostDefaults(configure =>
            {
                configure.UseKestrel(o =>
                {
                    o.AddServerHeader = false; // we add our own header via configuration
                });

                configure.UseStartup <TStartup>(); // only called for method validation
                configure.UseStaticWebAssets();

                configure.ConfigureServices((context, services) =>
                {
                    var config = configSelector != default
                        ? configSelector(context.Configuration)
                        : context.Configuration.GetSection(Constants.DefaultConfigSection);

                    var startupAssembly = typeof(TStartup).Assembly;

                    // Resource assemblies:
                    //
                    foreach (var dependent in startupAssembly.GetReferencedAssemblies())
                    {
                        Assembly.Load(dependent);
                    }
                    var resourceAssemblies = new HashSet <Assembly>
                    {
                        // BetterAPI
                        typeof(ApiOptions).Assembly,

                        // BetterAPI.Primitives
                        typeof(User).Assembly,

                        // User application
                        startupAssembly
                    };
                    foreach (var type in AppDomain.CurrentDomain.GetAssemblies()
                             .Where(a => !a.IsDynamic)
                             .SelectMany(x => x.GetTypes()))
                    {
                        if (type.IsInterface || !typeof(IResource).IsAssignableFrom(type))
                        {
                            continue;
                        }
                        if (resourceAssemblies.Contains(type.Assembly))
                        {
                            continue;
                        }

                        resourceAssemblies.Add(type.Assembly);
                    }

                    services.AddApiServer(config, context.HostingEnvironment, resourceAssemblies);

                    //
                    // The default ApplicationPartManager relies on the entryAssemblyName, which is this library.
                    // So we need to register the calling application's own controllers as well, here.
                    var mvcBuilder = services.AddControllers();
                    foreach (var assembly in resourceAssemblies)
                    {
                        mvcBuilder.AddApplicationPart(assembly);
                    }

                    //
                    // Calling `configure.UseStartup<TStartup>()` will replace our defaults, so call manually:
                    var serviceProvider = services.BuildServiceProvider();
                    startup ??= Instancing.CreateInstance <TStartup>(serviceProvider);
                    var accessor = CallAccessor.Create(typeof(TStartup).GetMethod(nameof(IStartup.ConfigureServices)) ??
                                                       throw new InvalidOperationException());
                    accessor.Call(startup, new object[] { services });
                });

                configure.Configure((context, app) =>
                {
                    app.UseApiServer(context.HostingEnvironment);

                    //
                    // Calling `configure.UseStartup<TStartup>()` will replace our defaults, so call manually:
                    startup ??= Instancing.CreateInstance <TStartup>(app.ApplicationServices);
                    var accessor = CallAccessor.Create(typeof(TStartup).GetMethod(nameof(IStartup.Configure)) ??
                                                       throw new InvalidOperationException());
                    accessor.Call(startup, new AppBuilderServiceProvider(app, app.ApplicationServices));
                });
            });

            return(builder);
        }
        private static void BindNonScalar(this IConfiguration configuration, ref object instance, BinderOptions options,
                                          IEnumerable <ICustomConfigurationBinder> customBinders)
        {
            if (instance == null)
            {
                return;
            }

            var scope = AccessorMemberScope.Public;

            if (options.BindNonPublicProperties)
            {
                scope |= AccessorMemberScope.Private;
            }

            var type  = instance.GetType();
            var read  = ReadAccessor.Create(type, AccessorMemberTypes.Properties, scope, out var members);
            var write = WriteAccessor.Create(type, AccessorMemberTypes.Properties, scope);

            if (IsTypeDiscriminated(type, out _))
            {
                // Set base properties so the converter has the right values to work with
                SetMembers(configuration, instance, options, members, read, write, customBinders);

                // Give a custom converter a chance to change what is bound
                var converter = TypeDescriptor.GetConverter(type);
                if (converter.CanConvertFrom(type))
                {
                    instance = converter.ConvertFrom(instance);
                    if (instance != null)
                    {
                        type  = instance.GetType();
                        read  = ReadAccessor.Create(type, AccessorMemberTypes.Properties, scope, out members);
                        write = WriteAccessor.Create(type, AccessorMemberTypes.Properties, scope);
                    }
                }
                else
                {
                    foreach (var binder in customBinders ?? Enumerable.Empty <ICustomConfigurationBinder>())
                    {
                        if (!binder.CanConvertFrom(type))
                        {
                            continue;
                        }

                        var subType = binder.GetTypeFor(instance);
                        if (subType == null)
                        {
                            continue;
                        }

                        type     = subType;
                        instance = Instancing.CreateInstance(type);
                        read     = ReadAccessor.Create(type, AccessorMemberTypes.Properties, scope, out members);
                        write    = WriteAccessor.Create(type, AccessorMemberTypes.Properties, scope);
                        goto setMembers;
                    }
                }
            }

setMembers:
            SetMembers(configuration, instance, options, members, read, write, customBinders);
        }
Ejemplo n.º 21
0
        public void Update(GameTime pGameTime)
        {
            float totalSeconds = (float)pGameTime.ElapsedGameTime.TotalSeconds;

            GamePadState currentState = GamePad.GetState(PlayerIndex.One);

            if (currentState.IsConnected)
            {
                // TODO gamepad support
            }
            else
            {
                if (_camera.Type == Camera.ProjectionType.PERSPECTIVE_PROJECTION)
                {
                    // Handle mouse input
                    MouseState mouseState = Mouse.GetState();

                    if (mouseState.LeftButton == ButtonState.Pressed)
                    {
                        if (!_mlb)
                        {
                            _mlb             = true;
                            _currentMousePos = new Vector2(mouseState.X, mouseState.Y);
                        }
                        else
                        {
                            Vector2 mPos  = new Vector2(mouseState.X, mouseState.Y);
                            Vector2 delta = mPos - _currentMousePos;
                            _currentMousePos = mPos;

                            float yaw   = delta.X;
                            float pitch = delta.Y;

                            _camera.Rotate(yaw, pitch);
                        }
                    }
                    else
                    {
                        _mlb = false;
                    }

                    //Zoom
                    if (_msw)
                    {
                        _msw         = true;
                        _scrollWheel = mouseState.ScrollWheelValue;
                    }
                    else
                    {
                        int delta = _scrollWheel - mouseState.ScrollWheelValue;

                        _camera.Zoom(delta);

                        _scrollWheel = mouseState.ScrollWheelValue;
                    }
                }
                else
                {
                    KeyboardState keyState = Keyboard.GetState();

                    if (keyState.IsKeyDown(Keys.Left))
                    {
                        _camera.Horizontal(-.5f);
                    }
                    else if (keyState.IsKeyDown(Keys.Right))
                    {
                        _camera.Horizontal(.5f);
                    }
                    else if (keyState.IsKeyDown(Keys.Up))
                    {
                        _camera.Vertical(.5f);
                    }
                    else if (keyState.IsKeyDown(Keys.Down))
                    {
                        _camera.Vertical(-.5f);
                    }
                    else if (keyState.IsKeyDown(Keys.Add))
                    {
                        _camera.Zoom(-1f);
                    }
                    else if (keyState.IsKeyDown(Keys.Subtract))
                    {
                        _camera.Zoom(1f);
                    }
                    else if (keyState.IsKeyDown(Keys.Space))
                    {
                        _nextMode = true;
                    }
                    else if (_nextMode)
                    {
                        Instancing.nextMode();
                        _nextMode = false;
                    }
                }
            }
        }