From e9b6a979873d5c632ce252129630bf2c971f6975 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 16 Aug 2017 17:21:24 +1000 Subject: [PATCH] Fix custom blocks not loading in singleplayer from last few commits --- ClassicalSharp/Map/Formats/MapCw.Importer.cs | 1 + OpenTK/Platform/Windows/WinGLNative.cs | 4 +- OpenTK/Platform/Windows/WinWindowInfo.cs | 50 ++++---------------- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/ClassicalSharp/Map/Formats/MapCw.Importer.cs b/ClassicalSharp/Map/Formats/MapCw.Importer.cs index f0efeec1f..df547f038 100644 --- a/ClassicalSharp/Map/Formats/MapCw.Importer.cs +++ b/ClassicalSharp/Map/Formats/MapCw.Importer.cs @@ -172,6 +172,7 @@ namespace ClassicalSharp.Map { BlockInfo.LightOffset[id] = BlockInfo.CalcLightOffset(id); game.Events.RaiseBlockDefinitionChanged(); + game.Inventory.AddDefault(id); BlockInfo.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F)); BlockInfo.CanPlace[id] = true; diff --git a/OpenTK/Platform/Windows/WinGLNative.cs b/OpenTK/Platform/Windows/WinGLNative.cs index 486f8848f..b00fe5e22 100644 --- a/OpenTK/Platform/Windows/WinGLNative.cs +++ b/OpenTK/Platform/Windows/WinGLNative.cs @@ -427,7 +427,7 @@ namespace OpenTK.Platform.Windows /// Starts the teardown sequence for the current window. void DestroyWindow() { if (exists) { - Debug.Print("Destroying window: {0}", window.ToString()); + Debug.Print("Destroying window: {0}", window.WindowHandle); API.DestroyWindow(window.WindowHandle); exists = false; } @@ -725,7 +725,7 @@ namespace OpenTK.Platform.Windows } IntPtr foreground = API.GetForegroundWindow(); if( foreground != IntPtr.Zero ) - focused = foreground == window.handle; + focused = foreground == window.WindowHandle; } public IWindowInfo WindowInfo { diff --git a/OpenTK/Platform/Windows/WinWindowInfo.cs b/OpenTK/Platform/Windows/WinWindowInfo.cs index 87e4b0d14..06af18194 100644 --- a/OpenTK/Platform/Windows/WinWindowInfo.cs +++ b/OpenTK/Platform/Windows/WinWindowInfo.cs @@ -33,7 +33,7 @@ namespace OpenTK.Platform.Windows { /// \internal /// Describes a win32 window. public sealed class WinWindowInfo : IWindowInfo { - internal IntPtr handle, dc; + internal IntPtr dc; bool disposed; /// Constructs a new instance. @@ -42,48 +42,22 @@ namespace OpenTK.Platform.Windows { /// Constructs a new instance with the specified window handle and parent. /// The window handle for this instance. - public WinWindowInfo(IntPtr handle) { - this.handle = handle; + public WinWindowInfo(IntPtr windowHandle) { + WindowHandle = windowHandle; } /// Gets or sets the handle of the window. - public IntPtr WindowHandle { get { return handle; } set { handle = value; } } + public IntPtr WindowHandle; /// Gets the device context for this window instance. public IntPtr DeviceContext { get { - if (dc == IntPtr.Zero) - dc = API.GetDC(this.WindowHandle); + if (dc == IntPtr.Zero) dc = API.GetDC(this.WindowHandle); //dc = Functions.GetWindowDC(this.WindowHandle); return dc; } } - /// Returns a System.String that represents the current window. - /// A System.String that represents the current window. - public override string ToString() { - return String.Format("Windows.WindowInfo: Handle {0}", WindowHandle); - } - - /// Checks if this and obj reference the same win32 window. - /// The object to check against. - /// True if this and obj reference the same win32 window; false otherwise. - public override bool Equals(object obj) { - if (obj == null) return false; - if (this.GetType() != obj.GetType()) return false; - WinWindowInfo info = (WinWindowInfo)obj; - - if (info == null) return false; - // TODO: Assumes windows will always have unique handles. - return handle.Equals(info.handle); - } - - /// Returns the hash code for this instance. - /// A hash code for the current WinWindowInfo. - public override int GetHashCode() { - return handle.GetHashCode(); - } - /// Releases the unmanaged resources consumed by this instance. public void Dispose() { Dispose(true); @@ -92,20 +66,16 @@ namespace OpenTK.Platform.Windows { void Dispose(bool manual) { if (!disposed) { - if (dc != IntPtr.Zero) - if (!API.ReleaseDC(this.handle, this.dc)) - Debug.Print("[Warning] Failed to release device context {0}. Windows error: {1}.", this.dc, Marshal.GetLastWin32Error()); + if (dc != IntPtr.Zero && !API.ReleaseDC(WindowHandle, dc)) { + Debug.Print("[Warning] Failed to release device context {0}. Windows error: {1}.", this.dc, Marshal.GetLastWin32Error()); + } disposed = true; } } - ~WinWindowInfo() { - Dispose(false); - } + ~WinWindowInfo() { Dispose(false); } - public IntPtr WinHandle { - get { return WindowHandle; } - } + public IntPtr WinHandle { get { return WindowHandle; } } } }