mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 07:49:57 -04:00
Optimise allocations of cursor get/set calls, optimise allocations in PauseScreen.
This commit is contained in:
parent
78d35a0b87
commit
a8f663f129
@ -28,7 +28,11 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Font titleFont, keyStatusFont, textFont;
|
Font titleFont, keyStatusFont, textFont;
|
||||||
|
static string[] keyNames;
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
|
if( keyNames == null ) {
|
||||||
|
keyNames = Enum.GetNames( typeof( Key ) );
|
||||||
|
}
|
||||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||||
keyStatusFont = new Font( "Arial", 13, FontStyle.Italic );
|
keyStatusFont = new Font( "Arial", 13, FontStyle.Italic );
|
||||||
textFont = new Font( "Arial", 14, FontStyle.Bold );
|
textFont = new Font( "Arial", 14, FontStyle.Bold );
|
||||||
@ -59,7 +63,8 @@ namespace ClassicalSharp {
|
|||||||
widgets = new KeyMapWidget[mappings.Length];
|
widgets = new KeyMapWidget[mappings.Length];
|
||||||
|
|
||||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||||
string text = descriptions[i] + ": " + Window.Keys[mappings[i]];
|
Key tkKey = Window.Keys[mappings[i]];
|
||||||
|
string text = descriptions[i] + ": " + keyNames[(int)tkKey];
|
||||||
TextWidget widget = TextWidget.Create( Window, 0, startY, text, Docking.LeftOrTop, Docking.LeftOrTop, textFont );
|
TextWidget widget = TextWidget.Create( Window, 0, startY, text, Docking.LeftOrTop, Docking.LeftOrTop, textFont );
|
||||||
widget.XOffset = offset;
|
widget.XOffset = offset;
|
||||||
widget.MoveTo( widget.X + widget.XOffset, widget.Y );
|
widget.MoveTo( widget.X + widget.XOffset, widget.Y );
|
||||||
|
@ -237,7 +237,7 @@ namespace ClassicalSharp {
|
|||||||
for( int i = 0; i < handlers.Length; i++ ) {
|
for( int i = 0; i < handlers.Length; i++ ) {
|
||||||
if( handlers[i].HandlesKeyDown( key ) ) return true;
|
if( handlers[i].HandlesKeyDown( key ) ) return true;
|
||||||
}
|
}
|
||||||
bool controlDown = Window.IsKeyDown( Key.LControl) || Window.IsKeyDown( Key.RControl );
|
bool controlDown = Window.IsKeyDown( Key.ControlLeft ) || Window.IsKeyDown( Key.ControlRight );
|
||||||
if( key == Key.V && controlDown && chatInputText.Length < 64 ) {
|
if( key == Key.V && controlDown && chatInputText.Length < 64 ) {
|
||||||
string text = Clipboard.GetText();
|
string text = Clipboard.GetText();
|
||||||
if( String.IsNullOrEmpty( text ) ) return true;
|
if( String.IsNullOrEmpty( text ) ) return true;
|
||||||
|
@ -169,7 +169,7 @@ namespace ClassicalSharp {
|
|||||||
Key[] Keys = new Key[] {
|
Key[] Keys = new Key[] {
|
||||||
Key.W, Key.S, Key.A, Key.D, Key.Space, Key.R, Key.Y, Key.T,
|
Key.W, Key.S, Key.A, Key.D, Key.Space, Key.R, Key.Y, Key.T,
|
||||||
Key.Enter, Key.Escape, Key.B, Key.F12, Key.F11, Key.F7,
|
Key.Enter, Key.Escape, Key.B, Key.F12, Key.F11, Key.F7,
|
||||||
Key.F5, Key.F6, Key.Z, Key.LShift, Key.X, Key.Q, Key.E,
|
Key.F5, Key.F6, Key.Z, Key.ShiftLeft, Key.X, Key.Q, Key.E,
|
||||||
Key.Tab, Key.H,
|
Key.Tab, Key.H,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BIN
OpenTK.dll
BIN
OpenTK.dll
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
|
||||||
@ -31,8 +30,10 @@ namespace ClassicalSharp {
|
|||||||
public abstract class PerspectiveCamera : Camera {
|
public abstract class PerspectiveCamera : Camera {
|
||||||
|
|
||||||
protected Player player;
|
protected Player player;
|
||||||
|
IInputDriver driver;
|
||||||
public PerspectiveCamera( Game window ) {
|
public PerspectiveCamera( Game window ) {
|
||||||
Window = window;
|
Window = window;
|
||||||
|
driver = window.InputDriver;
|
||||||
player = Window.LocalPlayer;
|
player = Window.LocalPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,12 +54,12 @@ namespace ClassicalSharp {
|
|||||||
Vector2 Orientation;
|
Vector2 Orientation;
|
||||||
void CentreMousePosition() {
|
void CentreMousePosition() {
|
||||||
if( !Window.Focused ) return;
|
if( !Window.Focused ) return;
|
||||||
Point current = Cursor.Position;
|
Point current = driver.DesktopCursorPos;
|
||||||
delta = new Point( current.X - previous.X, current.Y - previous.Y );
|
delta = new Point( current.X - previous.X, current.Y - previous.Y );
|
||||||
Rectangle bounds = Window.Bounds;
|
Rectangle bounds = Window.Bounds;
|
||||||
int cenX = bounds.Left + bounds.Width / 2;
|
int cenX = bounds.Left + bounds.Width / 2;
|
||||||
int cenY = bounds.Top + bounds.Height / 2;
|
int cenY = bounds.Top + bounds.Height / 2;
|
||||||
Cursor.Position = new Point( cenX, cenY );
|
driver.DesktopCursorPos = new Point( cenX, cenY );
|
||||||
previous = new Point( cenX, cenY );
|
previous = new Point( cenX, cenY );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ namespace ClassicalSharp {
|
|||||||
Rectangle bounds = Window.Bounds;
|
Rectangle bounds = Window.Bounds;
|
||||||
int cenX = bounds.Left + bounds.Width / 2;
|
int cenX = bounds.Left + bounds.Width / 2;
|
||||||
int cenY = bounds.Top + bounds.Height / 2;
|
int cenY = bounds.Top + bounds.Height / 2;
|
||||||
Cursor.Position = new Point( cenX, cenY );
|
driver.DesktopCursorPos = new Point( cenX, cenY );
|
||||||
previous = new Point( cenX, cenY );
|
previous = new Point( cenX, cenY );
|
||||||
delta = Point.Empty;
|
delta = Point.Empty;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user