public static void ResetGraphics() { if (IsEnabled) { Current = new CFG(); /*GFX.LODMode = LODMode.Automatic; * GFX.LOD1Distance = 200; * GFX.LOD2Distance = 400; * GFX.EnableFrustumCulling = false; * GFX.EnableTextures = true; * GFX.Wireframe = false; * //GFX.EnableLighting = true; * //GFX.TestLightSpin = false; * //GFX.EnableHeadlight = true; * * DBG.ShowModelNames = true; * DBG.ShowModelBoundingBoxes = false; * DBG.ShowModelSubmeshBoundingBoxes = false; * DBG.ShowPrimitiveNametags = true; * DBG.PrimitiveNametagSize = 0.1f; * DBG.ShowGrid = true; * //DBG.SimpleTextLabelSize = true; * * GFX.World.FieldOfView = 43; * GFX.World.NearClipDistance = 0.1f; * GFX.World.FarClipDistance = 10000f;*/ Save(); Load(); } }
public void Run() { SetupCSharpDefaults(); SetupParamStudioConfig(); //new StudioServer(); long previousFrameTicks = 0; Stopwatch sw = new Stopwatch(); sw.Start(); while (_window.Exists) { bool focused = _window.Focused; if (!focused) { _desiredFrameLengthSeconds = 1.0 / 20.0f; } else { _desiredFrameLengthSeconds = 1.0 / 60.0f; } long currentFrameTicks = sw.ElapsedTicks; double deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds) { currentFrameTicks = sw.ElapsedTicks; deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; System.Threading.Thread.Sleep(focused ? 0 : 1); } previousFrameTicks = currentFrameTicks; InputSnapshot snapshot = null; Sdl2Events.ProcessEvents(); snapshot = _window.PumpEvents(); InputTracker.UpdateFrameInput(snapshot, _window); Update((float)deltaSeconds); if (!_window.Exists) { break; } if (_window.Focused) { Draw(); } else { // Flush the background queues Renderer.Frame(null, true); } } //DestroyAllObjects(); _gd.Dispose(); SaveParamStudioConfig(); CFG.Save(); System.Windows.Forms.Application.Exit(); }
public static void Load() { if (IsEnabled) { lock (_lock_SaveLoadCFG) { Current = Newtonsoft.Json.JsonConvert.DeserializeObject <CFG>( File.ReadAllText(GetConfigFilePath())); //InterrootLoader.Interroot = Current.InterrootLoader_Interroot; //InterrootLoader.Type = Current.InterrootLoader_Type; /*GFX.LODMode = Current.GFX_LODMode; * GFX.LOD1Distance = Current.GFX_LOD1Distance; * GFX.LOD2Distance = Current.GFX_LOD2Distance; * GFX.EnableFrustumCulling = Current.GFX_EnableFrustumCulling; * GFX.EnableTextures = Current.GFX_EnableTextures; * GFX.Wireframe = Current.GFX_Wireframe; * //GFX.EnableLighting = Current.GFX_EnableLighting; * //GFX.TestLightSpin = Current.GFX_TestLightSpin; * //GFX.EnableHeadlight = Current.GFX_EnableHeadlight; * * DBG.ShowModelNames = Current.DBG_ShowModelNames; * DBG.ShowModelBoundingBoxes = Current.DBG_ShowModelBoundingBoxes; * DBG.ShowModelSubmeshBoundingBoxes = Current.DBG_ShowModelSubmeshBoundingBoxes; * DBG.ShowPrimitiveNametags = Current.DBG_ShowPrimitiveNametags; * //DBG.PrimitiveNametagSize = Current.DBG_PrimitiveNametagSize; * DBG.ShowGrid = Current.DBG_ShowGrid; * //DBG.SimpleTextLabelSize = Current.DBG_SimpleTextLabelSize; * * GFX.World.CameraMoveSpeed = Current.GFX_World_CameraMoveSpeed; * GFX.World.CameraTurnSpeedGamepad = Current.GFX_World_CameraTurnSpeedGamepad; * GFX.World.CameraTurnSpeedMouse = Current.GFX_World_CameraTurnSpeedMouse; * GFX.World.FieldOfView = Current.GFX_World_FieldOfView; * GFX.World.NearClipDistance = Current.GFX_World_NearClipDistance; * GFX.World.FarClipDistance = Current.GFX_World_FarClipDistance; * * GFX.Display.Width = Current.GFX_Display_Width; * GFX.Display.Height = Current.GFX_Display_Height; * GFX.Display.Format = Current.GFX_Display_Format; * GFX.Display.Vsync = Current.GFX_Display_Vsync; * GFX.Display.Fullscreen = Current.GFX_Display_Fullscreen; * GFX.Display.SimpleMSAA = Current.GFX_Display_SimpleMSAA; * * GFX.Display.Apply();*/ } } }
public static void AttemptLoadOrDefault() { if (IsEnabled) { if (File.Exists(GetConfigFilePath())) { Load(); } else { Current = new CFG(); ResetControls(); ResetGraphics(); ResetDisplay(); Save(); } } }
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); } } }
public void Run() { /*Task.Run(() => * { * while (true) * { * Thread.Sleep(5000); * GC.Collect(); * GC.WaitForPendingFinalizers(); * * GC.Collect(); * } * });*/ // Flush geometry megabuffers for editor geometry //Renderer.GeometryBufferAllocator.FlushStaging(); long previousFrameTicks = 0; Stopwatch sw = new Stopwatch(); sw.Start(); while (_window.Exists) { bool focused = _window.Focused; if (!focused) { _desiredFrameLengthSeconds = 1.0 / 20.0f; } else { _desiredFrameLengthSeconds = 1.0 / 60.0f; } long currentFrameTicks = sw.ElapsedTicks; double deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds) { currentFrameTicks = sw.ElapsedTicks; deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; System.Threading.Thread.Sleep(focused ? 0 : 1); } previousFrameTicks = currentFrameTicks; InputSnapshot snapshot = null; Sdl2Events.ProcessEvents(); snapshot = _window.PumpEvents(); InputTracker.UpdateFrameInput(snapshot, _window); Update((float)deltaSeconds); if (!_window.Exists) { break; } if (_window.Focused) { Draw(); } else { // Flush the background queues Renderer.Frame(null, true); } } //DestroyAllObjects(); Resource.ResourceManager.Shutdown(); _gd.Dispose(); CFG.Save(); System.Windows.Forms.Application.Exit(); }