From 813ea75a4bac26dc1d64ac41aa576bfdd2c9d688 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 7 Nov 2017 16:18:51 +1100 Subject: [PATCH] Remove some redundant font creations in launcher, fix few more C compile errors --- Launcher2/Gui/Screens/DirectConnectScreen.cs | 3 -- Launcher2/Gui/Views/ColoursView.cs | 2 +- Launcher2/Gui/Views/MainView.cs | 24 ++++--------- Launcher2/Gui/Views/ServersView.cs | 3 +- src/Client/Platform.h | 2 ++ src/Client/String.c | 38 +++++++++++--------- src/Client/String.h | 2 ++ src/Client/WinPlatform.c | 2 ++ 8 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Launcher2/Gui/Screens/DirectConnectScreen.cs b/Launcher2/Gui/Screens/DirectConnectScreen.cs index 4c084693b..197d7d4fb 100644 --- a/Launcher2/Gui/Screens/DirectConnectScreen.cs +++ b/Launcher2/Gui/Screens/DirectConnectScreen.cs @@ -10,10 +10,8 @@ using Launcher.Gui.Widgets; namespace Launcher.Gui.Screens { public sealed class DirectConnectScreen : InputScreen { - Font booleanFont; DirectConnectView view; public DirectConnectScreen(LauncherWindow game) : base(game) { - booleanFont = new Font(game.FontName, 22, FontStyle.Regular); enterIndex = 3; view = new DirectConnectView(game); widgets = view.widgets; @@ -57,7 +55,6 @@ namespace Launcher.Gui.Screens { public override void Dispose() { StoreFields(); base.Dispose(); - booleanFont.Dispose(); } static string cachedUser, cachedAddress, cachedMppass; diff --git a/Launcher2/Gui/Views/ColoursView.cs b/Launcher2/Gui/Views/ColoursView.cs index 8fde7988e..9e9eac349 100644 --- a/Launcher2/Gui/Views/ColoursView.cs +++ b/Launcher2/Gui/Views/ColoursView.cs @@ -14,7 +14,7 @@ namespace Launcher.Gui.Views { internal int defIndex, sliderIndex; public override void Init() { - titleFont = new Font(game.FontName, 15, FontStyle.Bold); + titleFont = new Font(game.FontName, 16, FontStyle.Bold); textFont = new Font(game.FontName, 14, FontStyle.Regular); inputHintFont = new Font(game.FontName, 12, FontStyle.Italic); MakeWidgets(); diff --git a/Launcher2/Gui/Views/MainView.cs b/Launcher2/Gui/Views/MainView.cs index 1b105597b..f1e01a0c7 100644 --- a/Launcher2/Gui/Views/MainView.cs +++ b/Launcher2/Gui/Views/MainView.cs @@ -7,7 +7,6 @@ using Launcher.Gui.Widgets; namespace Launcher.Gui.Views { public sealed class MainView : IView { - Font buttonFont, updateFont; internal int loginIndex, resIndex, dcIndex, spIndex, statusIndex; internal int sslIndex, settingsIndex; const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150; @@ -17,12 +16,9 @@ namespace Launcher.Gui.Views { } public override void Init() { - titleFont = new Font(game.FontName, 15, FontStyle.Bold); + titleFont = new Font(game.FontName, 16, FontStyle.Bold); textFont = new Font(game.FontName, 14, FontStyle.Regular); inputHintFont = new Font(game.FontName, 12, FontStyle.Italic); - - buttonFont = new Font(game.FontName, 16, FontStyle.Bold); - updateFont = new Font(game.FontName, 12, FontStyle.Italic); MakeWidgets(); } @@ -30,12 +26,6 @@ namespace Launcher.Gui.Views { Widget widget = widgets[index]; return widget == null ? "" : widget.Text; } - - public override void Dispose() { - buttonFont.Dispose(); - updateFont.Dispose(); - base.Dispose(); - } internal string updateText = "&eChecking.."; @@ -47,7 +37,7 @@ namespace Launcher.Gui.Views { .SetLocation(Anchor.Centre, Anchor.Centre, 0, -75); loginIndex = widgetIndex; - Makers.Button(this, "Sign in", 100, buttonHeight, buttonFont) + Makers.Button(this, "Sign in", 100, buttonHeight, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, -90, -25); statusIndex = widgetIndex; Makers.Label(this, Get(statusIndex), textFont) @@ -55,13 +45,13 @@ namespace Launcher.Gui.Views { resIndex = widgetIndex; - Makers.Button(this, "Resume", 100, buttonHeight, buttonFont) + Makers.Button(this, "Resume", 100, buttonHeight, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 90, -25); dcIndex = widgetIndex; - Makers.Button(this, "Direct connect", 200, buttonHeight, buttonFont) + Makers.Button(this, "Direct connect", 200, buttonHeight, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 60); spIndex = widgetIndex; - Makers.Button(this, "Singleplayer", 200, buttonHeight, buttonFont) + Makers.Button(this, "Singleplayer", 200, buttonHeight, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); sslIndex = widgetIndex; @@ -73,11 +63,11 @@ namespace Launcher.Gui.Views { widgets[sslIndex].Visible = sslVisible; widgets[sslIndex + 1].Visible = sslVisible; - Makers.Label(this, updateText, updateFont) + Makers.Label(this, updateText, inputHintFont) .SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -45); settingsIndex = widgetIndex; - Makers.Button(this, "Options", 100, buttonHeight, buttonFont) + Makers.Button(this, "Options", 100, buttonHeight, titleFont) .SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -6, -6); } } diff --git a/Launcher2/Gui/Views/ServersView.cs b/Launcher2/Gui/Views/ServersView.cs index 9140088a4..ec8151f3d 100644 --- a/Launcher2/Gui/Views/ServersView.cs +++ b/Launcher2/Gui/Views/ServersView.cs @@ -4,7 +4,6 @@ using System.Drawing; using ClassicalSharp; using Launcher.Drawing; using Launcher.Gui.Widgets; -using OpenTK.Input; namespace Launcher.Gui.Views { public sealed class ServersView : IView { @@ -20,7 +19,7 @@ namespace Launcher.Gui.Views { } public override void Init() { - titleFont = new Font(game.FontName, 15, FontStyle.Bold); + titleFont = new Font(game.FontName, 16, FontStyle.Bold); textFont = new Font(game.FontName, 14, FontStyle.Regular); inputHintFont = new Font(game.FontName, 12, FontStyle.Italic); tableFont = new Font(game.FontName, 11, FontStyle.Regular); diff --git a/src/Client/Platform.h b/src/Client/Platform.h index 7b81b76f3..18947378e 100644 --- a/src/Client/Platform.h +++ b/src/Client/Platform.h @@ -10,6 +10,8 @@ /* Newline for text */ extern UInt8* Platform_NewLine; +extern UInt8 Platform_DirectorySeparator; +extern ReturnCode ReturnCode_FileShareViolation; /* Initalises required state for this platform. */ void Platform_Init(void); diff --git a/src/Client/String.c b/src/Client/String.c index 87042154b..56480d04e 100644 --- a/src/Client/String.c +++ b/src/Client/String.c @@ -15,29 +15,20 @@ String String_FromRawBuffer(UInt8* buffer, UInt16 capacity) { Int32 i; /* Need to set region occupied by string to NULL for interop with native APIs */ - for (i = 0; i < capacity + 1; i++) { - buffer[i] = 0; - } + for (i = 0; i < capacity + 1; i++) { buffer[i] = NULL; } return str; } String String_FromReadonly(const UInt8* buffer) { UInt16 length = 0; - UInt8 cur = 0; - UInt8* ptr = buffer; + UInt8* cur = buffer; + while ((*cur) != NULL) { cur++; length++; } - while ((cur = *buffer) != 0) { - length++; buffer++; - } - - String str = String_FromEmptyBuffer(ptr, length); + String str = String_FromEmptyBuffer(buffer, length); str.length = length; return str; } - -String String_MakeNull(void) { - return String_FromEmptyBuffer(NULL, 0); -} +String String_MakeNull(void) { return String_FromEmptyBuffer(NULL, 0); } void String_MakeLowercase(STRING_TRANSIENT String* str) { @@ -49,8 +40,8 @@ void String_MakeLowercase(STRING_TRANSIENT String* str) { void String_Clear(STRING_TRANSIENT String* str) { Int32 i; - for (i = 0; i < str->length; i++) { - str->buffer[i] = 0; + for (i = 0; i < str->length; i++) { + str->buffer[i] = NULL; } str->length = 0; } @@ -389,4 +380,19 @@ bool Convert_TryParseBool(STRING_PURE String* str, bool* value) { } *value = false; return false; +} + +#define STRINGSBUFFER_LEN_SHIFT 10 +#define STRINGSBUFFER_LEN_MASK 0x3FFUL +void StringsBuffer_Get(StringsBuffer* buffer, UInt32 index, STRING_TRANSIENT String* text) { + if (index >= buffer->Count) ErrorHandler_Fail("Tried to get String past StringsBuffer end"); + String_Clear(text); + + UInt32 flags = buffer->FlagsBuffer[index]; + UInt32 offset = flags >> STRINGSBUFFER_LEN_SHIFT; + UInt32 len = flags & STRINGSBUFFER_LEN_MASK; + + UInt8* src = &buffer->FlagsBuffer[offset]; + UInt32 i; + for (i = 0; i < len; i++) { String_Append(text, src[i]); } } \ No newline at end of file diff --git a/src/Client/String.h b/src/Client/String.h index e8f44e011..00381b9e4 100644 --- a/src/Client/String.h +++ b/src/Client/String.h @@ -108,6 +108,8 @@ typedef struct StringsBuffer_ { UInt32 FlagsBufferSize; UInt32 Count; } StringsBuffer; + void StringsBuffer_Get(StringsBuffer* buffer, UInt32 index, STRING_TRANSIENT String* text); void StringsBuffer_Add(StringsBuffer* buffer, STRING_PURE String* text); +void StringsBuffer_Free(StringsBuffer* buffer); #endif \ No newline at end of file diff --git a/src/Client/WinPlatform.c b/src/Client/WinPlatform.c index dab791c80..a2120502c 100644 --- a/src/Client/WinPlatform.c +++ b/src/Client/WinPlatform.c @@ -12,6 +12,8 @@ HBITMAP hbmp; HANDLE heap; UInt8* Platform_NewLine = "\r\n"; +UInt8 Platform_DirectorySeparator = '\\'; +ReturnCode ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION; void Platform_Init(void) { heap = GetProcessHeap(); /* TODO: HeapCreate instead? probably not */