From fa850fecb348421c7d8539a2707cceea6df73a6b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 25 Aug 2021 08:32:02 +1000 Subject: [PATCH] Fix compiling for Apple M1 wrongly using Carbon instead of Cocoa backend (Thanks doctorj1) --- src/Chat.c | 2 +- src/Core.h | 2 +- src/Drawer2D.c | 30 +++++++++++++++--------------- src/Drawer2D.h | 9 ++++----- src/Entity.c | 2 +- src/LBackend.c | 1 + src/Launcher.c | 1 + src/Server.c | 4 ++-- src/Widgets.c | 6 +++--- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Chat.c b/src/Chat.c index 66d9998c8..21e692708 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -186,7 +186,7 @@ static void AppendChatLog(const cc_string* text) { /* [HH:mm:ss] text */ String_InitArray(str, strBuffer); String_Format3(&str, "[%p2:%p2:%p2] ", &now.hour, &now.minute, &now.second); - Drawer2D_WithoutCols(&str, text); + Drawer2D_WithoutColors(&str, text); res = Stream_WriteLine(&logStream, &str); if (!res) return; diff --git a/src/Core.h b/src/Core.h index b53973bf6..0d3d32eb8 100644 --- a/src/Core.h +++ b/src/Core.h @@ -186,7 +186,7 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */ #define CC_BUILD_GLES #define CC_BUILD_GLMODERN #define CC_BUILD_IOS -#elif defined __x86_64__ +#elif defined __x86_64__ || defined __arm64__ #define CC_BUILD_COCOA #define CC_BUILD_MACOS #else diff --git a/src/Drawer2D.c b/src/Drawer2D.c index 1967dc84a..54803803b 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -318,7 +318,7 @@ void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int width, in tex->uv.V2 = (float)height / (float)bmp->height; } -cc_bool Drawer2D_ValidColCodeAt(const cc_string* text, int i) { +cc_bool Drawer2D_ValidColorCodeAt(const cc_string* text, int i) { if (i >= text->length) return false; return BitmapCol_A(Drawer2D_GetColor(text->buffer[i])) != 0; } @@ -329,19 +329,19 @@ cc_bool Drawer2D_IsEmptyText(const cc_string* text) { for (i = 0; i < text->length; i++) { if (text->buffer[i] != '&') return false; - if (!Drawer2D_ValidColCodeAt(text, i + 1)) return false; + if (!Drawer2D_ValidColorCodeAt(text, i + 1)) return false; i++; /* skip colour code */ } return true; } -void Drawer2D_WithoutCols(cc_string* str, const cc_string* src) { +void Drawer2D_WithoutColors(cc_string* str, const cc_string* src) { char c; int i; for (i = 0; i < src->length; i++) { c = src->buffer[i]; - if (c == '&' && Drawer2D_ValidColCodeAt(src, i + 1)) { + if (c == '&' && Drawer2D_ValidColorCodeAt(src, i + 1)) { i++; /* skip colour code */ } else { String_Append(str, c); @@ -349,19 +349,19 @@ void Drawer2D_WithoutCols(cc_string* str, const cc_string* src) { } } -char Drawer2D_LastCol(const cc_string* text, int start) { +char Drawer2D_LastColor(const cc_string* text, int start) { int i; if (start >= text->length) start = text->length - 1; for (i = start; i >= 0; i--) { if (text->buffer[i] != '&') continue; - if (Drawer2D_ValidColCodeAt(text, i + 1)) { + if (Drawer2D_ValidColorCodeAt(text, i + 1)) { return text->buffer[i + 1]; } } return '\0'; } -cc_bool Drawer2D_IsWhiteCol(char c) { return c == '\0' || c == 'f' || c == 'F'; } +cc_bool Drawer2D_IsWhiteColor(char c) { return c == '\0' || c == 'f' || c == 'F'; } /* Divides R/G/B by 4 */ #define SHADOW_MASK ((0x3F << BITMAPCOL_R_SHIFT) | (0x3F << BITMAPCOL_G_SHIFT) | (0x3F << BITMAPCOL_B_SHIFT)) @@ -441,7 +441,7 @@ static void DrawBitmappedTextCore(struct Bitmap* bmp, struct DrawTextArgs* args, for (i = 0; i < text.length; i++) { char c = text.buffer[i]; - if (c == '&' && Drawer2D_ValidColCodeAt(&text, i + 1)) { + if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) { col = Drawer2D_GetColor(text.buffer[i + 1]); if (shadow) col = GetShadowColor(col); @@ -536,7 +536,7 @@ static int MeasureBitmappedWidth(const struct DrawTextArgs* args) { text = args->text; for (i = 0; i < text.length; i++) { char c = text.buffer[i]; - if (c == '&' && Drawer2D_ValidColCodeAt(&text, i + 1)) { + if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) { i++; continue; /* skip over the colour code */ } width += Drawer2D_Width(point, c) + xPadding; @@ -613,7 +613,7 @@ void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args, /*########################################################################################################################* *---------------------------------------------------Drawer2D component----------------------------------------------------* *#########################################################################################################################*/ -static void InitHexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) { +static void InitHexEncodedColor(int i, int hex, cc_uint8 lo, cc_uint8 hi) { Drawer2D.Colors[i] = BitmapCol_Make( lo * ((hex >> 2) & 1) + hi * (hex >> 3), lo * ((hex >> 1) & 1) + hi * (hex >> 3), @@ -628,11 +628,11 @@ static void OnReset(void) { } for (i = 0; i <= 9; i++) { - InitHexEncodedCol('0' + i, i, 191, 64); + InitHexEncodedColor('0' + i, i, 191, 64); } for (i = 10; i <= 15; i++) { - InitHexEncodedCol('a' + (i - 10), i, 191, 64); - InitHexEncodedCol('A' + (i - 10), i, 191, 64); + InitHexEncodedColor('a' + (i - 10), i, 191, 64); + InitHexEncodedColor('A' + (i - 10), i, 191, 64); } } @@ -1059,7 +1059,7 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) { for (i = 0; i < text.length; i++) { char c = text.buffer[i]; - if (c == '&' && Drawer2D_ValidColCodeAt(&text, i + 1)) { + if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) { i++; continue; /* skip over the colour code */ } @@ -1167,7 +1167,7 @@ static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int for (i = 0; i < text.length; i++) { char c = text.buffer[i]; - if (c == '&' && Drawer2D_ValidColCodeAt(&text, i + 1)) { + if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) { col = Drawer2D_GetColor(text.buffer[i + 1]); if (shadow) col = GetShadowColor(col); diff --git a/src/Drawer2D.h b/src/Drawer2D.h index 4aa685098..a75aab09a 100644 --- a/src/Drawer2D.h +++ b/src/Drawer2D.h @@ -1,6 +1,5 @@ #ifndef CC_DRAWER2D_H #define CC_DRAWER2D_H -#include "PackedCol.h" #include "Constants.h" #include "Bitmap.h" /* Performs a variety of drawing operations on bitmaps, and converts bitmaps into textures. @@ -86,16 +85,16 @@ CC_API void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int wi /* Returns whether the given colour code is used/valid. */ /* NOTE: This can change if the server defines custom colour codes. */ -cc_bool Drawer2D_ValidColCodeAt(const cc_string* text, int i); +cc_bool Drawer2D_ValidColorCodeAt(const cc_string* text, int i); /* Whether text is empty or consists purely of valid colour codes. */ cc_bool Drawer2D_IsEmptyText(const cc_string* text); /* Copies all characters from str into src, except for used colour codes */ /* NOTE: Ampersands not followed by a used colour code are still copied */ -void Drawer2D_WithoutCols(cc_string* str, const cc_string* src); +void Drawer2D_WithoutColors(cc_string* str, const cc_string* src); /* Returns the last valid colour code in the given input, or \0 if not found. */ -char Drawer2D_LastCol(const cc_string* text, int start); +char Drawer2D_LastColor(const cc_string* text, int start); /* Returns whether the colour code is f, F or \0. */ -cc_bool Drawer2D_IsWhiteCol(char c); +cc_bool Drawer2D_IsWhiteColor(char c); void Drawer2D_ReducePadding_Tex(struct Texture* tex, int point, int scale); void Drawer2D_ReducePadding_Height(int* height, int point, int scale); diff --git a/src/Entity.c b/src/Entity.c index b6a24f5ef..91f136287 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -257,7 +257,7 @@ static void MakeNameTexture(struct Entity* e) { origWhiteCol = Drawer2D.Colors['f']; Drawer2D.Colors['f'] = shadowCol; - Drawer2D_WithoutCols(&colorlessName, &name); + Drawer2D_WithoutColors(&colorlessName, &name); args.text = colorlessName; Drawer2D_DrawText(&bmp, &args, NAME_OFFSET, NAME_OFFSET); diff --git a/src/LBackend.c b/src/LBackend.c index 04bb63cd0..fc0a369dc 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -16,6 +16,7 @@ #include "LScreens.h" #include "Input.h" #include "Utils.h" +#include "PackedCol.h" static struct Bitmap dirtBmp, stoneBmp; #define TILESIZE 48 diff --git a/src/Launcher.c b/src/Launcher.c index f25e5dfad..a2ecac7cd 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -19,6 +19,7 @@ #include "Logger.h" #include "Options.h" #include "LBackend.h" +#include "PackedCol.h" /* The area/region of the window that needs to be redrawn and presented to the screen. */ /* If width is 0, means no area needs to be redrawn. */ diff --git a/src/Server.c b/src/Server.c index 423a0e620..2e177c75b 100644 --- a/src/Server.c +++ b/src/Server.c @@ -141,7 +141,7 @@ static void SPConnection_AddPart(const cc_string* text) { String_InitArray(tmp, tmpBuffer); /* Prepend colour codes for subsequent lines of multi-line chat */ - if (!Drawer2D_IsWhiteCol(sp_lastCol)) { + if (!Drawer2D_IsWhiteColor(sp_lastCol)) { String_Append(&tmp, '&'); String_Append(&tmp, sp_lastCol); } @@ -153,7 +153,7 @@ static void SPConnection_AddPart(const cc_string* text) { } String_UNSAFE_TrimEnd(&tmp); - col = Drawer2D_LastCol(&tmp, tmp.length); + col = Drawer2D_LastColor(&tmp, tmp.length); if (col) sp_lastCol = col; Chat_Add(&tmp); } diff --git a/src/Widgets.c b/src/Widgets.c index f3eb81f7e..e58694bc0 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -959,7 +959,7 @@ static void InputWidget_FormatLine(struct InputWidget* w, int i, cc_string* line for (i = 0; i < src.length; i++) { char c = src.buffer[i]; - if (c == '%' && Drawer2D_ValidColCodeAt(&src, i + 1)) { c = '&'; } + if (c == '%' && Drawer2D_ValidColorCodeAt(&src, i + 1)) { c = '&'; } String_Append(line, c); } } @@ -994,7 +994,7 @@ static char InputWidget_GetLastCol(struct InputWidget* w, int x, int y) { line.length = 0; InputWidget_FormatLine(w, y, &line); - col = Drawer2D_LastCol(&line, x); + col = Drawer2D_LastColor(&line, x); if (col) return col; if (y > 0) { x = w->lines[y - 1].length; } } @@ -1621,7 +1621,7 @@ static void ChatInputWidget_RemakeTexture(void* widget) { /* Colour code continues in next line */ lastCol = InputWidget_GetLastCol(w, 0, i); - if (!Drawer2D_IsWhiteCol(lastCol)) { + if (!Drawer2D_IsWhiteColor(lastCol)) { String_Append(&line, '&'); String_Append(&line, lastCol); } /* Convert % to & for colour codes */