Optimise allocations of cursor get/set calls, optimise allocations in PauseScreen.

This commit is contained in:
UnknownShadow200 2015-05-12 19:16:04 +10:00
parent 78d35a0b87
commit a8f663f129
5 changed files with 13 additions and 7 deletions

View file

@ -28,7 +28,11 @@ namespace ClassicalSharp {
}
Font titleFont, keyStatusFont, textFont;
static string[] keyNames;
public override void Init() {
if( keyNames == null ) {
keyNames = Enum.GetNames( typeof( Key ) );
}
titleFont = new Font( "Arial", 16, FontStyle.Bold );
keyStatusFont = new Font( "Arial", 13, FontStyle.Italic );
textFont = new Font( "Arial", 14, FontStyle.Bold );
@ -59,7 +63,8 @@ namespace ClassicalSharp {
widgets = new KeyMapWidget[mappings.Length];
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 );
widget.XOffset = offset;
widget.MoveTo( widget.X + widget.XOffset, widget.Y );

View file

@ -237,7 +237,7 @@ namespace ClassicalSharp {
for( int i = 0; i < handlers.Length; i++ ) {
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 ) {
string text = Clipboard.GetText();
if( String.IsNullOrEmpty( text ) ) return true;

View file

@ -169,7 +169,7 @@ namespace ClassicalSharp {
Key[] Keys = new Key[] {
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.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,
};

Binary file not shown.

View file

@ -1,6 +1,5 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Input;
@ -31,8 +30,10 @@ namespace ClassicalSharp {
public abstract class PerspectiveCamera : Camera {
protected Player player;
IInputDriver driver;
public PerspectiveCamera( Game window ) {
Window = window;
driver = window.InputDriver;
player = Window.LocalPlayer;
}
@ -53,12 +54,12 @@ namespace ClassicalSharp {
Vector2 Orientation;
void CentreMousePosition() {
if( !Window.Focused ) return;
Point current = Cursor.Position;
Point current = driver.DesktopCursorPos;
delta = new Point( current.X - previous.X, current.Y - previous.Y );
Rectangle bounds = Window.Bounds;
int cenX = bounds.Left + bounds.Width / 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 );
}
@ -66,7 +67,7 @@ namespace ClassicalSharp {
Rectangle bounds = Window.Bounds;
int cenX = bounds.Left + bounds.Width / 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 );
delta = Point.Empty;
}