mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
minor code cleanup
This commit is contained in:
parent
e052f7eb5f
commit
3286f3e7ee
@ -93,7 +93,9 @@ namespace ClassicalSharp {
|
|||||||
World = new World(this);
|
World = new World(this);
|
||||||
LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
|
LocalPlayer = new LocalPlayer(this); Components.Add(LocalPlayer);
|
||||||
Entities.List[EntityList.SelfID] = 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);
|
MapRenderer = new MapRenderer(this);
|
||||||
ChunkUpdater = new ChunkUpdater(this);
|
ChunkUpdater = new ChunkUpdater(this);
|
||||||
|
@ -212,7 +212,9 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void OnResize() {
|
internal void OnResize() {
|
||||||
Width = window.Width; Height = window.Height;
|
Size size = window.ClientSize;
|
||||||
|
Width = size.Width; Height = size.Height;
|
||||||
|
|
||||||
Graphics.OnWindowResize(this);
|
Graphics.OnWindowResize(this);
|
||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
Gui.OnResize();
|
Gui.OnResize();
|
||||||
|
@ -35,7 +35,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
MinZNear = 0.05f;
|
MinZNear = 0.05f;
|
||||||
IntPtr windowHandle = game.window.WindowInfo.WinHandle;
|
IntPtr windowHandle = game.window.WindowInfo.WinHandle;
|
||||||
d3d = new Direct3D();
|
d3d = new Direct3D();
|
||||||
int adapter = d3d.Adapters[0].Adapter;
|
const int adapter = 0; // default adapter
|
||||||
InitFields();
|
InitFields();
|
||||||
FindCompatibleFormat(adapter);
|
FindCompatibleFormat(adapter);
|
||||||
|
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using Clipboard = System.Windows.Forms.Clipboard;
|
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
/// <summary> Implementation of a native window and native input handling mechanism on Windows, OSX, and Linux. </summary>
|
/// <summary> Implementation of a native window and native input handling mechanism on Windows, OSX, and Linux. </summary>
|
||||||
public sealed class DesktopWindow : GameWindow {
|
public sealed class DesktopWindow : GameWindow {
|
||||||
|
|
||||||
public int Width { get { return ClientSize.Width; } }
|
|
||||||
public int Height { get { return ClientSize.Height; } }
|
|
||||||
|
|
||||||
Game game;
|
Game game;
|
||||||
public DesktopWindow(Game game, string username, bool nullContext, int width, int height) :
|
public DesktopWindow(Game game, string username, bool nullContext, int width, int height) :
|
||||||
base(width, height, GraphicsMode.Default, Program.AppName + " (" + username + ")", nullContext, 0, DisplayDevice.Primary) {
|
base(width, height, GraphicsMode.Default, Program.AppName + " (" + username + ")", nullContext, 0, DisplayDevice.Primary) {
|
||||||
|
@ -62,14 +62,12 @@ namespace OpenTK.Graphics {
|
|||||||
public abstract IntPtr GetAddress(string function);
|
public abstract IntPtr GetAddress(string function);
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Dispose( true );
|
Dispose(true);
|
||||||
GC.SuppressFinalize( this );
|
GC.SuppressFinalize( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void Dispose( bool calledManually );
|
protected abstract void Dispose(bool calledManually);
|
||||||
|
|
||||||
~GraphicsContextBase() {
|
~GraphicsContextBase() { Dispose(false); }
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,6 @@
|
|||||||
<Compile Include="SharpDX.Direct3D\Device.cs" />
|
<Compile Include="SharpDX.Direct3D\Device.cs" />
|
||||||
<Compile Include="SharpDX.Direct3D\Direct3D.cs" />
|
<Compile Include="SharpDX.Direct3D\Direct3D.cs" />
|
||||||
<Compile Include="SharpDX.Direct3D\Enumerations.cs" />
|
<Compile Include="SharpDX.Direct3D\Enumerations.cs" />
|
||||||
<Compile Include="SharpDX.Direct3D\PresentParameters.cs" />
|
|
||||||
<Compile Include="SharpDX.Direct3D\Resources.cs" />
|
<Compile Include="SharpDX.Direct3D\Resources.cs" />
|
||||||
<Compile Include="SharpDX.Direct3D\Structures.cs" />
|
<Compile Include="SharpDX.Direct3D\Structures.cs" />
|
||||||
<Compile Include="SharpDX\ComObject.cs" />
|
<Compile Include="SharpDX\ComObject.cs" />
|
||||||
|
@ -23,18 +23,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace SharpDX.Direct3D9 {
|
namespace SharpDX.Direct3D9 {
|
||||||
public class AdapterInformation {
|
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;
|
public int Adapter;
|
||||||
|
|
||||||
/// <summary> Gets the details. </summary>
|
|
||||||
public AdapterDetails Details;
|
public AdapterDetails Details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,12 +27,15 @@ namespace SharpDX.Direct3D9 {
|
|||||||
public unsafe class Direct3D : ComObject {
|
public unsafe class Direct3D : ComObject {
|
||||||
|
|
||||||
public Direct3D() {
|
public Direct3D() {
|
||||||
comPointer = Direct3DCreate9( SdkVersion );
|
comPointer = Direct3DCreate9(SdkVersion);
|
||||||
|
|
||||||
int count = GetAdapterCount();
|
int count = GetAdapterCount();
|
||||||
Adapters = new AdapterInformation[count];
|
Adapters = new AdapterInformation[count];
|
||||||
for( int i = 0; i < count; i++ ) {
|
|
||||||
Adapters[i] = new AdapterInformation( this, i );
|
for (int i = 0; i < count; i++) {
|
||||||
|
AdapterInformation info = new AdapterInformation();
|
||||||
|
info.Adapter = i;
|
||||||
|
info.Details = GetAdapterIdentifier(i);
|
||||||
|
Adapters[i] = info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ namespace SharpDX.Direct3D9 {
|
|||||||
|
|
||||||
const int SdkVersion = 32;
|
const int SdkVersion = 32;
|
||||||
[DllImport( "d3d9.dll" )]
|
[DllImport( "d3d9.dll" )]
|
||||||
static extern IntPtr Direct3DCreate9( int sdkVersion );
|
static extern IntPtr Direct3DCreate9(int sdkVersion);
|
||||||
|
|
||||||
public int GetAdapterCount() {
|
public int GetAdapterCount() {
|
||||||
return Interop.Calli(comPointer,(*(IntPtr**)comPointer)[4]);
|
return Interop.Calli(comPointer,(*(IntPtr**)comPointer)[4]);
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,6 +23,24 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace SharpDX.Direct3D9 {
|
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)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct Capabilities {
|
public struct Capabilities {
|
||||||
public DeviceType DeviceType;
|
public DeviceType DeviceType;
|
||||||
|
@ -20,33 +20,25 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SharpDX
|
namespace SharpDX {
|
||||||
{
|
public class ComObject : IDisposable {
|
||||||
public class ComObject : IDisposable
|
|
||||||
{
|
|
||||||
public IntPtr comPointer;
|
public IntPtr comPointer;
|
||||||
|
|
||||||
public ComObject(IntPtr pointer) {
|
public ComObject(IntPtr pointer) { comPointer = pointer; }
|
||||||
comPointer = pointer;
|
public ComObject() { }
|
||||||
}
|
|
||||||
|
|
||||||
protected ComObject() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsDisposed;
|
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
CheckAndDispose( true );
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ComObject() {
|
~ComObject() { Dispose(false); }
|
||||||
CheckAndDispose( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe void CheckAndDispose( bool disposing ) {
|
public bool IsDisposed;
|
||||||
|
unsafe void Dispose( bool disposing ) {
|
||||||
if( IsDisposed ) return;
|
if( IsDisposed ) return;
|
||||||
|
|
||||||
if( comPointer != IntPtr.Zero ) {
|
if( comPointer == IntPtr.Zero ) {
|
||||||
if( !disposing ) {
|
if( !disposing ) {
|
||||||
string text = String.Format( "Warning: Live ComObject [0x{0:X}], potential memory leak: {1}",
|
string text = String.Format( "Warning: Live ComObject [0x{0:X}], potential memory leak: {1}",
|
||||||
comPointer.ToInt64(), GetType().Name );
|
comPointer.ToInt64(), GetType().Name );
|
||||||
@ -60,7 +52,6 @@ namespace SharpDX
|
|||||||
}
|
}
|
||||||
comPointer = IntPtr.Zero;
|
comPointer = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
GC.SuppressFinalize( this );
|
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ namespace SharpDX {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class SharpDXException : Exception {
|
public class SharpDXException : Exception {
|
||||||
|
|
||||||
public int Code;
|
public int Code;
|
||||||
|
|
||||||
public SharpDXException(int result) : base(Format(result)) {
|
public SharpDXException(int result) : base(Format(result)) {
|
||||||
|
@ -80,7 +80,7 @@ void GLContext_Update(void);
|
|||||||
void GLContext_Free(void);
|
void GLContext_Free(void);
|
||||||
|
|
||||||
#define GLContext_IsInvalidAddress(ptr) (ptr == (void*)0 || ptr == (void*)1 || ptr == (void*)-1 || ptr == (void*)2)
|
#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);
|
void GLContext_SwapBuffers(void);
|
||||||
bool GLContext_GetVSync(void);
|
bool GLContext_GetVSync(void);
|
||||||
void GLContext_SetVSync(bool enabled);
|
void GLContext_SetVSync(bool enabled);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user