Example #1
0
        public ShaderManager(IoCContainer container)
        {
            IDeviceContextService contextService = container.Resolve <IDeviceContextService>();

            _context     = contextService.Context;
            _shaderCache = new Dictionary <string, Shader>();
        }
Example #2
0
        public Engine(IoCContainer container)
        {
            _container = container;
#if DEBUG_REFERENCES
            SharpDX.Configuration.EnableObjectTracking     = true;
            SharpDX.Configuration.EnableReleaseOnFinalizer = true;
#endif
            IDeviceContextService deviceContextService = _container.Resolve <IDeviceContextService>();

            _form    = deviceContextService.Form;
            _context = deviceContextService.Context;

            _form.Icon         = Resources.openuo;
            _form.Text         = string.Format("OpenUO v{0}", new AssemblyInfo(Assembly.GetEntryAssembly()).Version);
            _form.ResizeBegin += OnResizeBegin;
            _form.ResizeEnd   += OnResizeEnd;
            _form.FormClosed  += OnFormClosed;

            _updateState = new UpdateState();
            _gameTime    = new GameTime();
            _world       = new World(container);

            container.Resolve <IConsole>().WriteLine("Testing 123");

            _config           = _container.Resolve <IConfiguration>();
            _updateChain      = _container.Resolve <IChain <UpdateState> >();
            _worldRenderChain = _container.Resolve <IWorldRenderChain>();
            _uiRenderChain    = _container.Resolve <IUIRenderChain>();

            _screenTarget = new DrawScreenTarget(_context);

            _updateChain.Freeze();
            _worldRenderChain.Freeze();
            _uiRenderChain.Freeze();
        }
Example #3
0
        public TestRendering(IoCContainer container)
        {
            camera = new Camera2D();

            RenderDelegateChainStep renderStep = new RenderDelegateChainStep("TestRendering", Render);

            container.Resolve <IUIRenderChain>().RegisterStep(renderStep);

            IInput input = container.Resolve <IInput>();

            input.AddBinding(string.Empty, false, false, false, System.Windows.Forms.Keys.Up, null, (s, e) => { camera.Position += Vector3.UnitY; });
            input.AddBinding(string.Empty, false, false, false, System.Windows.Forms.Keys.Down, null, (s, e) => { camera.Position -= Vector3.UnitY; });
            input.AddBinding(string.Empty, false, false, false, System.Windows.Forms.Keys.Left, null, (s, e) => { camera.Position += Vector3.UnitX; });
            input.AddBinding(string.Empty, false, false, false, System.Windows.Forms.Keys.Right, null, (s, e) => { camera.Position -= Vector3.UnitX; });

            IDeviceContextService deviceContextService = container.Resolve <IDeviceContextService>();
            DeviceContext         context = deviceContextService.Context;

            deviceContextService.Form.ResizeEnd += new EventHandler(Form_ResizeEnd);

            _texture  = Texture2D.FromFile(context, "Resources\\Helix.jpg", Usage.None, Pool.Managed);
            _elements = new TexturedElement[250];

            for (int i = 0; i < _elements.Length; i++)
            {
                _elements[i]          = new TexturedElement(new SharpDX.Vector2(50, 50));
                _elements[i].Position = new Vector2(i * 20, i * 20);
            }

            _vertices = new Vertices <VertexPositionTexture>(context,
                                                             new VertexPositionTexture()
            {
                Position = new Vector3(-0.5f, -0.5f, 0), TextureCoordinate = new Vector2(0, 0)
            },
                                                             new VertexPositionTexture()
            {
                Position = new Vector3(-0.5f, 0.5f, 0), TextureCoordinate = new Vector2(1, 0)
            },
                                                             new VertexPositionTexture()
            {
                Position = new Vector3(0.5f, -0.5f, 0), TextureCoordinate = new Vector2(0, 1)
            },
                                                             new VertexPositionTexture()
            {
                Position = new Vector3(0.5f, 0.5f, 0), TextureCoordinate = new Vector2(1, 1)
            });
        }
Example #4
0
        public InputManager(IoCContainer container)
        {
            IDeviceContextService deviceContextManager = container.Resolve <IDeviceContextService>();

            RenderForm form = deviceContextManager.Form;

            form.KeyDown          += OnKeyDown;
            form.KeyUp            += OnKeyUp;
            form.MouseClick       += OnMouseClick;
            form.MouseDoubleClick += OnMouseDoubleClick;
            form.MouseDown        += OnMouseDown;
            form.MouseMove        += OnMouseMove;
            form.MouseUp          += OnMouseUp;
            form.MouseWheel       += OnMouseWheel;

            _keyBindings   = new Dictionary <Keys, InputBinding>();
            _mouseBindings = new Dictionary <MouseButtons, InputBinding>();
        }
Example #5
0
        protected override void Initialize()
        {
#if DEBUG
            new DebugTraceListener {
                TraceLevel = TraceLevels.Verbose
            };
#endif

            //Register engine managers
            Container.Register <IConfiguration, ConfigurationManager>().AsSingleton();
            Container.Register <IDeviceContextService, DeviceContextManager>().AsSingleton();
            Container.Register <IInput, InputManager>().AsSingleton();
            Container.Register <INetwork, NetworkManager>().AsSingleton();
            Container.Register <IShaderManager, ShaderManager>().AsSingleton();

            //Register Render Chains
            Container.Register <IWorldRenderChain, WorldRenderChain>().AsSingleton();
            Container.Register <IUIRenderChain, UIRenderChain>().AsSingleton();

            //Register Update Chain
            Container.Register <IChain <UpdateState>, UpdateChain>().AsSingleton();

            //Kernel.Bind<IStorageAdapterParameterBuilder>().To<DirectX9UnicodeFontAdapterParameterBuilder>()
            //    .When(request =>
            //        request.ParentRequest.Service == typeof(IUnicodeFontFactory<Texture2D>));

            //Register UO file factories
            //Kernel.Bind<IAnimationDataFactory<AnimationData>>().To<AnimationDataFactory<AnimationData>>().InSingletonScope();
            //Kernel.Bind<IAnimationFactory<Texture2D>>().To<AnimationFactory<Texture2D>>().InSingletonScope();
            //Kernel.Bind<IArtworkFactory<Texture2D>>().To<ArtworkFactory<Texture2D>>().InSingletonScope();
            //Kernel.Bind<IASCIIFontFactory<Texture2D>>().To<ASCIIFontFactory<Texture2D>>().InSingletonScope();
            //Kernel.Bind<IGumpFactory<Texture2D>>().To<GumpFactory<Texture2D>>().InSingletonScope();
            //Kernel.Bind<ISkillsFactory<Skill>>().To<SkillsFactory<Skill>>().InSingletonScope();
            //Kernel.Bind<ISoundFactory<Sound>>().To<SoundFactory<Sound>>().InSingletonScope();
            //Kernel.Bind<ITexmapFactory<Texture2D>>().To<TexmapFactory<Texture2D>>().InSingletonScope();
            //Kernel.Bind<IUnicodeFontFactory<Texture2D>>().To<UnicodeFontFactory<Texture2D>>().InSingletonScope();

            //Register client components
            Container.Register <IConsole>().AsSingleton();

            IConfiguration config = Container.Resolve <IConfiguration>();
            config.RestoreDefaultsInvoked += OnConfigRestoreDefaultsInvoked;

            if (config.GetValue <bool>(ConfigSections.Diagnostics, ConfigKeys.ShowConsole))
            {
                NativeMethods.AllocConsole();

                if (config.GetValue <bool>(ConfigSections.Diagnostics, ConfigKeys.ConsoleTraceListener, false))
                {
                    new ConsoleTraceListener();
                }
            }

            if (config.GetValue <bool>(ConfigSections.Diagnostics, ConfigKeys.FileTraceListener, false))
            {
                new DebugLogTraceListener("debug.log");
            }

            IDeviceContextService deviceContextService = Container.Resolve <IDeviceContextService>();

            IShaderManager shaderManager = Container.Resolve <IShaderManager>();
            shaderManager.Register <SimpleTextureEffect>(new SimpleTextureEffect(deviceContextService.Context));
            shaderManager.Register <CombineShader>(new CombineShader(deviceContextService.Context));

            new GameConsoleTracer(Container);

            new TestRendering(Container);
        }