Exemplo n.º 1
0
        public InputGameController(IFrameworkMessenger frameworkMessenger, IApplicationMessenger applicationMessenger)
        {
            _frameworkMessenger   = frameworkMessenger;
            _applicationMessenger = applicationMessenger;

            Sdl2Native.SDL_Init(SDLInitFlags.GameController);

            _eventQueue = new Queue <SDL_Event>();

            _controllers = new Dictionary <int, GameController>();

            UpdateGamepadRegister();
        }
Exemplo n.º 2
0
 static unsafe TestUtils()
 {
     int result = Sdl2Native.SDL_Init(SDLInitFlags.Video);
     if (result != 0)
     {
         InitializationFailedMessage = GetString(Sdl2Native.SDL_GetError());
         InitializedSdl2 = false;
     }
     else
     {
         InitializedSdl2 = true;
     }
 }
Exemplo n.º 3
0
        public static void CreateWindowAndGraphicsDevice(
            WindowCreateInfo windowCI,
            GraphicsDeviceOptions deviceOptions,
            GraphicsBackend preferredBackend,
            out Sdl2Window window,
            out GraphicsDevice gd)
        {
            Sdl2Native.SDL_Init(SDLInitFlags.Video);
            if (preferredBackend == GraphicsBackend.OpenGL || preferredBackend == GraphicsBackend.OpenGLES)
            {
                SetSDLGLContextAttributes(deviceOptions, preferredBackend);
            }

            window = CreateWindow(ref windowCI);
            gd     = CreateGraphicsDevice(window, deviceOptions, preferredBackend);
        }
Exemplo n.º 4
0
        public static void CreateWindowAndGraphicsDevice(
            WindowProps windowProps,
            GraphicsDeviceOptions deviceOptions,
            GraphicsBackend preferredBackend,
            out Sdl2Window window,
            out GraphicsDevice gd)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(typeof(WindowStartup));
            using (Profiler sdlProfiler = new Profiler("SDL_Init"))
#endif
            Sdl2Native.SDL_Init(SDLInitFlags.Video);

            window = CreateWindow(ref windowProps, preferredBackend);
            gd     = CreateGraphicsDevice(window, deviceOptions, preferredBackend);
        }
Exemplo n.º 5
0
        public DesktopWindow(string title, uint width, uint height)
        {
            const int centered = Sdl2Native.SDL_WINDOWPOS_CENTERED;

            Sdl2Native.SDL_Init(SDLInitFlags.Video | SDLInitFlags.GameController);
            _window = new Sdl2Window(title,
                                     centered, centered,
                                     (int)width, (int)height,
                                     SDL_WindowFlags.OpenGL,
                                     threadedProcessing: false
                                     );
            SwapchainSource = VeldridStartup.GetSwapchainSource(_window);

            _arrow  = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Arrow);
            _hand   = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Hand);
            _wait   = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Wait);
            _cursor = SystemCursor.Arrow;
        }
Exemplo n.º 6
0
        public Lanegam() : base(preferredBackend: GraphicsBackend.Direct3D11)
        {
            Sdl2Native.SDL_Init(SDLInitFlags.GameController);
            Sdl2ControllerTracker.CreateDefault(out _controllerTracker);

            GraphicsDevice.SyncToVerticalBlank = true;

            _imGuiRenderable = new ImGuiRenderable(Window.Width, Window.Height);
            _resizeHandled  += (w, h) => _imGuiRenderable.WindowResized(w, h);

            _scene = new Scene(GraphicsDevice, Window);
            _scene.Camera.Controller = _controllerTracker;
            _sc.SetCurrentScene(_scene);

            _scene.AddRenderable(_imGuiRenderable);

            _sc.Camera.Position = new Vector3(-6, 24f, -0.43f);
            _sc.Camera.Yaw      = MathF.PI * 1.25f;
            _sc.Camera.Pitch    = 0;

            ScreenDuplicator duplicator = new ScreenDuplicator();

            _scene.AddRenderable(duplicator);

            _fsq = new FullScreenQuad();
            _scene.AddRenderable(_fsq);

            particlePlane = new ParticlePlane(_scene.Camera);
            //_scene.AddRenderable(particlePlane);

            spriteRenderable = new SpriteRenderable();
            _scene.AddRenderable(spriteRenderable);
            _scene.AddUpdateable(spriteRenderable);

            CreateGraphicsDeviceObjects();

            ImGui.StyleColorsClassic();
        }
Exemplo n.º 7
0
        public NeoDemo()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo
            {
                X                  = 50,
                Y                  = 50,
                WindowWidth        = 960,
                WindowHeight       = 540,
                WindowInitialState = WindowState.Normal,
                WindowTitle        = "Veldrid NeoDemo"
            };
            GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(false, null, false, ResourceBindingModel.Improved, true, true, _colorSrgb);

#if DEBUG
            gdOptions.Debug = true;
#endif
            VeldridStartup.CreateWindowAndGraphicsDevice(
                windowCI,
                gdOptions,
                //VeldridStartup.GetPlatformDefaultBackend(),
                //GraphicsBackend.Metal,
                // GraphicsBackend.Vulkan,
                // GraphicsBackend.OpenGL,
                //GraphicsBackend.OpenGLES,
                out _window,
                out _gd);
            _window.Resized += () => _windowResized = true;

            Sdl2Native.SDL_Init(SDLInitFlags.GameController);
            Sdl2ControllerTracker.CreateDefault(out _controllerTracker);

            _scene = new Scene(_gd, _window, _controllerTracker);

            _sc.SetCurrentScene(_scene);

            _igRenderable   = new ImGuiRenderable(_window.Width, _window.Height);
            _resizeHandled += (w, h) => _igRenderable.WindowResized(w, h);
            _scene.AddRenderable(_igRenderable);
            _scene.AddUpdateable(_igRenderable);

            Skybox skybox = Skybox.LoadDefaultSkybox();
            _scene.AddRenderable(skybox);

            AddSponzaAtriumObjects();
            _sc.Camera.Position = new Vector3(-80, 25, -4.3f);
            _sc.Camera.Yaw      = -MathF.PI / 2;
            _sc.Camera.Pitch    = -MathF.PI / 9;

            ShadowmapDrawer texDrawIndexeder = new ShadowmapDrawer(() => _window, () => _sc.NearShadowMapView);
            _resizeHandled           += (w, h) => texDrawIndexeder.OnWindowResized();
            texDrawIndexeder.Position = new Vector2(10, 25);
            _scene.AddRenderable(texDrawIndexeder);

            ShadowmapDrawer texDrawIndexeder2 = new ShadowmapDrawer(() => _window, () => _sc.MidShadowMapView);
            _resizeHandled            += (w, h) => texDrawIndexeder2.OnWindowResized();
            texDrawIndexeder2.Position = new Vector2(20 + texDrawIndexeder2.Size.X, 25);
            _scene.AddRenderable(texDrawIndexeder2);

            ShadowmapDrawer texDrawIndexeder3 = new ShadowmapDrawer(() => _window, () => _sc.FarShadowMapView);
            _resizeHandled            += (w, h) => texDrawIndexeder3.OnWindowResized();
            texDrawIndexeder3.Position = new Vector2(30 + (texDrawIndexeder3.Size.X * 2), 25);
            _scene.AddRenderable(texDrawIndexeder3);

            ShadowmapDrawer reflectionTexDrawer = new ShadowmapDrawer(() => _window, () => _sc.ReflectionColorView);
            _resizeHandled += (w, h) => reflectionTexDrawer.OnWindowResized();
            reflectionTexDrawer.Position = new Vector2(40 + (reflectionTexDrawer.Size.X * 3), 25);
            _scene.AddRenderable(reflectionTexDrawer);

            ScreenDuplicator duplicator = new ScreenDuplicator();
            _scene.AddRenderable(duplicator);

            _fsq = new FullScreenQuad();
            _scene.AddRenderable(_fsq);

            CreateAllObjects();
            ImGui.StyleColorsClassic();
        }
Exemplo n.º 8
0
        unsafe public MapStudioNew()
        {
            CFG.AttemptLoadOrDefault();

            if (UseRenderdoc)
            {
                RenderDoc.Load(out RenderDocManager);
                RenderDocManager.OverlayEnabled = false;
            }

            WindowCreateInfo windowCI = new WindowCreateInfo
            {
                X                  = CFG.Current.GFX_Display_X,
                Y                  = CFG.Current.GFX_Display_Y,
                WindowWidth        = CFG.Current.GFX_Display_Width,
                WindowHeight       = CFG.Current.GFX_Display_Height,
                WindowInitialState = WindowState.Maximized,
                WindowTitle        = "Dark Souls Map Studio " + _version + " by Katalash",
            };
            GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(false, PixelFormat.R32_Float, true, ResourceBindingModel.Improved, true, true, _colorSrgb);

#if DEBUG
            gdOptions.Debug = true;
#endif

            VeldridStartup.CreateWindowAndGraphicsDevice(
                windowCI,
                gdOptions,
                //VeldridStartup.GetPlatformDefaultBackend(),
                //GraphicsBackend.Metal,
                GraphicsBackend.Vulkan,

                //GraphicsBackend.Direct3D11,
                //GraphicsBackend.OpenGL,
                //GraphicsBackend.OpenGLES,
                out _window,
                out _gd);
            _window.Resized += () => _windowResized = true;
            _window.Moved   += (p) => _windowMoved = true;

            Sdl2Native.SDL_Init(SDLInitFlags.GameController);
            //Sdl2ControllerTracker.CreateDefault(out _controllerTracker);

            var factory = _gd.ResourceFactory;
            TextureSamplerResourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                            new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                                                                            new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment)));

            Scene.Renderer.Initialize(_gd);

            ImguiRenderer = new ImGuiRenderer(_gd, _gd.SwapchainFramebuffer.OutputDescription, CFG.Current.GFX_Display_Width,
                                              CFG.Current.GFX_Display_Height, ColorSpaceHandling.Legacy);
            MainWindowCommandList = factory.CreateCommandList();
            GuiCommandList        = factory.CreateCommandList();

            _assetLocator = new AssetLocator();
            MSBEditor     = new MsbEditor.MsbEditorScreen(_window, _gd, _assetLocator);
            ModelEditor   = new MsbEditor.ModelEditorScreen(_window, _gd, _assetLocator);
            ParamEditor   = new MsbEditor.ParamEditorScreen(_window, _gd);
            TextEditor    = new MsbEditor.TextEditorScreen(_window, _gd);

            MsbEditor.ParamBank.LoadParams(_assetLocator);
            MsbEditor.FMGBank.LoadFMGs(_assetLocator);
            MsbEditor.MtdBank.LoadMtds(_assetLocator);

            ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
            var fonts    = ImGui.GetIO().Fonts;
            var fileJp   = Path.Combine(AppContext.BaseDirectory, $@"Assets\Fonts\NotoSansCJKtc-Light.otf");
            var fontJp   = File.ReadAllBytes(fileJp);
            var fileEn   = Path.Combine(AppContext.BaseDirectory, $@"Assets\Fonts\RobotoMono-Light.ttf");
            var fontEn   = File.ReadAllBytes(fileEn);
            var fileIcon = Path.Combine(AppContext.BaseDirectory, $@"Assets\Fonts\forkawesome-webfont.ttf");
            var fontIcon = File.ReadAllBytes(fileIcon);
            //fonts.AddFontFromFileTTF($@"Assets\Fonts\NotoSansCJKtc-Medium.otf", 20.0f, null, fonts.GetGlyphRangesJapanese());
            fonts.Clear();
            fixed(byte *p = fontEn)
            {
                var ptr = ImGuiNative.ImFontConfig_ImFontConfig();
                var cfg = new ImFontConfigPtr(ptr);

                cfg.GlyphMinAdvanceX = 5.0f;
                cfg.OversampleH      = 5;
                cfg.OversampleV      = 5;
                var f = fonts.AddFontFromMemoryTTF((IntPtr)p, fontEn.Length, 14.0f, cfg, fonts.GetGlyphRangesDefault());
            }

            fixed(byte *p = fontJp)
            {
                var ptr = ImGuiNative.ImFontConfig_ImFontConfig();
                var cfg = new ImFontConfigPtr(ptr);

                cfg.MergeMode        = true;
                cfg.GlyphMinAdvanceX = 7.0f;
                cfg.OversampleH      = 5;
                cfg.OversampleV      = 5;
                var f = fonts.AddFontFromMemoryTTF((IntPtr)p, fontJp.Length, 16.0f, cfg, fonts.GetGlyphRangesJapanese());
            }

            fixed(byte *p = fontIcon)
            {
                ushort[] ranges = { ForkAwesome.IconMin, ForkAwesome.IconMax, 0 };
                var      ptr    = ImGuiNative.ImFontConfig_ImFontConfig();
                var      cfg    = new ImFontConfigPtr(ptr);

                cfg.MergeMode        = true;
                cfg.GlyphMinAdvanceX = 12.0f;
                cfg.OversampleH      = 5;
                cfg.OversampleV      = 5;
                ImFontGlyphRangesBuilder b = new ImFontGlyphRangesBuilder();

                fixed(ushort *r = ranges)
                {
                    var f = fonts.AddFontFromMemoryTTF((IntPtr)p, fontIcon.Length, 16.0f, cfg, (IntPtr)r);
                }
            }

            fonts.Build();
            ImguiRenderer.RecreateFontDeviceTexture();
            ImguiRenderer.OnSetupDone();

            var style = ImGui.GetStyle();
            style.TabBorderSize = 0;

            if (CFG.Current.LastProjectFile != null && CFG.Current.LastProjectFile != "")
            {
                if (File.Exists(CFG.Current.LastProjectFile))
                {
                    var project = MsbEditor.ProjectSettings.Deserialize(CFG.Current.LastProjectFile);
                    AttemptLoadProject(project, CFG.Current.LastProjectFile, false);
                }
            }
        }
Exemplo n.º 9
0
 public static void Start()
 {
     Sdl2Native.SDL_Init(SDLInitFlags.Video);
 }
Exemplo n.º 10
0
        public void Run()
        {
            ChangeBackend();
            PerfTracker.StartupEvent("Set up backend");
            Sdl2Native.SDL_Init(SDLInitFlags.GameController);
            ImGui.StyleColorsClassic();
            Raise(new WindowResizedEvent(Window.Width, Window.Height));
            Raise(new BeginFrameEvent());

            var frameCounter = new FrameCounter();

            PerfTracker.StartupEvent("Startup done, rendering first frame");
            while (!_done)
            {
                ChangeBackend();

                PerfTracker.BeginFrame();
                double deltaSeconds = frameCounter.StartFrame();
                using (PerfTracker.FrameEvent("1 Raising begin frame"))
                    Raise(new BeginFrameEvent());

                InputSnapshot snapshot;
                using (PerfTracker.FrameEvent("2 Processing SDL events"))
                {
                    Sdl2Events.ProcessEvents();
                    snapshot = Window.PumpEvents();
                }

                if (!Window.Exists)
                {
                    break;
                }

                if (_pendingCursorUpdate.HasValue)
                {
                    using (PerfTracker.FrameEvent("3 Warping mouse"))
                    {
                        Sdl2Native.SDL_WarpMouseInWindow(
                            Window.SdlWindowHandle,
                            (int)_pendingCursorUpdate.Value.X,
                            (int)_pendingCursorUpdate.Value.Y);

                        _pendingCursorUpdate = null;
                    }
                }

                using (PerfTracker.FrameEvent("4 Raising input event"))
                    Raise(new InputEvent(deltaSeconds, snapshot, Window.MouseDelta));

                using (PerfTracker.FrameEvent("5 Performing update"))
                    Update((float)deltaSeconds);

                if (!Window.Exists)
                {
                    break;
                }

                using (PerfTracker.FrameEvent("6 Drawing"))
                    Draw();

                var flags = Resolve <IEngineSettings>().Flags;
                if (GraphicsDevice.SyncToVerticalBlank != flags.HasFlag(EngineFlags.VSync))
                {
                    GraphicsDevice.SyncToVerticalBlank = flags.HasFlag(EngineFlags.VSync);
                }

                using (PerfTracker.FrameEvent("7 Swap buffers"))
                {
                    CoreTrace.Log.Info("Engine", "Swapping buffers...");
                    GraphicsDevice.SwapBuffers();
                    CoreTrace.Log.Info("Engine", "Draw complete");
                }
            }

            DestroyAllObjects();
            GraphicsDevice.Dispose();
            Window.Close();
        }