minor code cleanup

This commit is contained in:
UnknownShadow200 2018-07-07 21:18:04 +10:00
parent e052f7eb5f
commit 3286f3e7ee
14 changed files with 537 additions and 597 deletions

View File

@ -93,7 +93,9 @@ namespace ClassicalSharp {
World = new World(this);
LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
Entities.List[EntityList.SelfID] = LocalPlayer;
Width = window.Width; Height = window.Height;
Size size = window.ClientSize;
Width = size.Width; Height = size.Height;
MapRenderer = new MapRenderer(this);
ChunkUpdater = new ChunkUpdater(this);

View File

@ -212,7 +212,9 @@ namespace ClassicalSharp {
}
internal void OnResize() {
Width = window.Width; Height = window.Height;
Size size = window.ClientSize;
Width = size.Width; Height = size.Height;
Graphics.OnWindowResize(this);
UpdateProjection();
Gui.OnResize();

View File

@ -35,7 +35,7 @@ namespace ClassicalSharp.GraphicsAPI {
MinZNear = 0.05f;
IntPtr windowHandle = game.window.WindowInfo.WinHandle;
d3d = new Direct3D();
int adapter = d3d.Adapters[0].Adapter;
const int adapter = 0; // default adapter
InitFields();
FindCompatibleFormat(adapter);

View File

@ -1,19 +1,14 @@
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
using System;
using System.Drawing;
using System.IO;
using OpenTK;
using OpenTK.Graphics;
using Clipboard = System.Windows.Forms.Clipboard;
namespace ClassicalSharp {
/// <summary> Implementation of a native window and native input handling mechanism on Windows, OSX, and Linux. </summary>
public sealed class DesktopWindow : GameWindow {
public int Width { get { return ClientSize.Width; } }
public int Height { get { return ClientSize.Height; } }
Game game;
public DesktopWindow(Game game, string username, bool nullContext, int width, int height) :
base(width, height, GraphicsMode.Default, Program.AppName + " (" + username + ")", nullContext, 0, DisplayDevice.Primary) {

View File

@ -68,8 +68,6 @@ namespace OpenTK.Graphics {
protected abstract void Dispose(bool calledManually);
~GraphicsContextBase() {
Dispose(false);
}
~GraphicsContextBase() { Dispose(false); }
}
}

View File

@ -115,7 +115,6 @@
<Compile Include="SharpDX.Direct3D\Device.cs" />
<Compile Include="SharpDX.Direct3D\Direct3D.cs" />
<Compile Include="SharpDX.Direct3D\Enumerations.cs" />
<Compile Include="SharpDX.Direct3D\PresentParameters.cs" />
<Compile Include="SharpDX.Direct3D\Resources.cs" />
<Compile Include="SharpDX.Direct3D\Structures.cs" />
<Compile Include="SharpDX\ComObject.cs" />

View File

@ -23,18 +23,7 @@ using System.Runtime.InteropServices;
namespace SharpDX.Direct3D9 {
public class AdapterInformation {
readonly Direct3D d3d;
internal AdapterInformation(Direct3D direct3D, int adapter) {
d3d = direct3D;
Adapter = adapter;
Details = direct3D.GetAdapterIdentifier(adapter);
}
/// <summary> Gets the adapter ordinal. </summary>
public int Adapter;
/// <summary> Gets the details. </summary>
public AdapterDetails Details;
}

View File

@ -28,11 +28,14 @@ namespace SharpDX.Direct3D9 {
public Direct3D() {
comPointer = Direct3DCreate9(SdkVersion);
int count = GetAdapterCount();
Adapters = new AdapterInformation[count];
for (int i = 0; i < count; i++) {
Adapters[i] = new AdapterInformation( this, i );
AdapterInformation info = new AdapterInformation();
info.Adapter = i;
info.Details = GetAdapterIdentifier(i);
Adapters[i] = info;
}
}

View File

@ -1,56 +0,0 @@
// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace SharpDX.Direct3D9 {
[StructLayout(LayoutKind.Sequential)]
public struct PresentParameters {
public int BackBufferWidth;
public int BackBufferHeight;
public Format BackBufferFormat;
public int BackBufferCount;
public int MultiSampleType;
public int MultiSampleQuality;
public SwapEffect SwapEffect;
public IntPtr DeviceWindowHandle;
public RawBool Windowed;
public RawBool EnableAutoDepthStencil;
public Format AutoDepthStencilFormat;
public PresentFlags PresentFlags;
public int FullScreenRefreshRateInHz;
public PresentInterval PresentationInterval;
public void InitDefaults() {
AutoDepthStencilFormat = Format.D24X8;
BackBufferWidth = 800;
BackBufferHeight = 600;
BackBufferFormat = Format.X8R8G8B8;
BackBufferCount = 1;
DeviceWindowHandle = IntPtr.Zero;
EnableAutoDepthStencil = true;
PresentFlags = PresentFlags.None;
PresentationInterval = PresentInterval.Immediate;
SwapEffect = SwapEffect.Discard;
Windowed = true;
}
}
}

View File

@ -23,6 +23,24 @@ using System.Runtime.InteropServices;
namespace SharpDX.Direct3D9 {
[StructLayout(LayoutKind.Sequential)]
public struct PresentParameters {
public int BackBufferWidth;
public int BackBufferHeight;
public Format BackBufferFormat;
public int BackBufferCount;
public int MultiSampleType;
public int MultiSampleQuality;
public SwapEffect SwapEffect;
public IntPtr DeviceWindowHandle;
public RawBool Windowed;
public RawBool EnableAutoDepthStencil;
public Format AutoDepthStencilFormat;
public PresentFlags PresentFlags;
public int FullScreenRefreshRateInHz;
public PresentInterval PresentationInterval;
}
[StructLayout(LayoutKind.Sequential)]
public struct Capabilities {
public DeviceType DeviceType;

View File

@ -20,33 +20,25 @@
using System;
using System.Runtime.InteropServices;
namespace SharpDX
{
public class ComObject : IDisposable
{
namespace SharpDX {
public class ComObject : IDisposable {
public IntPtr comPointer;
public ComObject(IntPtr pointer) {
comPointer = pointer;
}
protected ComObject() {
}
public bool IsDisposed;
public ComObject(IntPtr pointer) { comPointer = pointer; }
public ComObject() { }
public void Dispose() {
CheckAndDispose( true );
Dispose(true);
GC.SuppressFinalize(this);
}
~ComObject() {
CheckAndDispose( false );
}
~ComObject() { Dispose(false); }
unsafe void CheckAndDispose( bool disposing ) {
public bool IsDisposed;
unsafe void Dispose( bool disposing ) {
if( IsDisposed ) return;
if( comPointer != IntPtr.Zero ) {
if( comPointer == IntPtr.Zero ) {
if( !disposing ) {
string text = String.Format( "Warning: Live ComObject [0x{0:X}], potential memory leak: {1}",
comPointer.ToInt64(), GetType().Name );
@ -60,7 +52,6 @@ namespace SharpDX
}
comPointer = IntPtr.Zero;
}
GC.SuppressFinalize( this );
IsDisposed = true;
}
}

View File

@ -37,7 +37,6 @@ namespace SharpDX {
}
public class SharpDXException : Exception {
public int Code;
public SharpDXException(int result) : base(Format(result)) {

View File

@ -80,7 +80,7 @@ void GLContext_Update(void);
void GLContext_Free(void);
#define GLContext_IsInvalidAddress(ptr) (ptr == (void*)0 || ptr == (void*)1 || ptr == (void*)-1 || ptr == (void*)2)
void* GLContext_GetAddress(const UInt8* function);
void* GLContext_GetAddress(const UChar* function);
void GLContext_SwapBuffers(void);
bool GLContext_GetVSync(void);
void GLContext_SetVSync(bool enabled);