Merge branch 'master' into SocketsRewrite

This commit is contained in:
UnknownShadow200 2022-12-31 23:56:22 +11:00 committed by GitHub
commit 99895e990a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 164 additions and 75 deletions

View file

@ -303,7 +303,7 @@ static void LoadOptions(void) {
Game_ClassicMode = Options_GetBool(OPT_CLASSIC_MODE, false);
Game_ClassicHacks = Options_GetBool(OPT_CLASSIC_HACKS, false);
Game_AllowCustomBlocks = Options_GetBool(OPT_CUSTOM_BLOCKS, true);
Game_UseCPE = Options_GetBool(OPT_CPE, true);
Game_UseCPE = !Game_ClassicMode && Options_GetBool(OPT_CPE, true);
Game_SimpleArmsAnim = Options_GetBool(OPT_SIMPLE_ARMS_ANIM, false);
Game_ViewBobbing = Options_GetBool(OPT_VIEW_BOBBING, true);

View file

@ -64,7 +64,7 @@ void GameVersion_Load(void) {
int version = Options_GetInt("protocol-version", PROTOCOL_0017, PROTOCOL_0030, PROTOCOL_0030);
const struct GameVersion* ver = NULL;
if (!Game_ClassicMode) {
if (Game_UseCPE) {
ver = &version_cpe;
} else if (version == PROTOCOL_0030) {
ver = &version_0030;

View file

@ -153,7 +153,7 @@ static void Menu_SwitchGui(void* a, void* b) { GuiOptionsScreen_Show(); }
static void Menu_SwitchGfx(void* a, void* b) { GraphicsOptionsScreen_Show(); }
static void Menu_SwitchHacks(void* a, void* b) { HacksSettingsScreen_Show(); }
static void Menu_SwitchEnv(void* a, void* b) { EnvSettingsScreen_Show(); }
static void Menu_SwitchNostalgia(void* a, void* b) { NostalgiaScreen_Show(); }
static void Menu_SwitchNostalgia(void* a, void* b) { NostalgiaMenuScreen_Show(); }
static void Menu_SwitchGenLevel(void* a, void* b) { GenLevelScreen_Show(); }
static void Menu_SwitchClassicGenLevel(void* a, void* b) { ClassicGenScreen_Show(); }
@ -2554,7 +2554,7 @@ static void ClassicOptionsScreen_RecreateExtra(struct MenuOptionsScreen* s) {
}
static void ClassicOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
static const struct MenuOptionDesc buttons[9] = {
static const struct MenuOptionDesc buttons[] = {
{ -1, -150, "Music", MenuOptionsScreen_Bool,
ClassicOptionsScreen_GetMusic, ClassicOptionsScreen_SetMusic },
{ -1, -100, "Invert mouse", MenuOptionsScreen_Bool,
@ -2635,7 +2635,7 @@ static void EnvSettingsScreen_GetEdgeHeight(cc_string* v) { String_AppendInt(v,
static void EnvSettingsScreen_SetEdgeHeight(const cc_string* v) { Env_SetEdgeHeight(Menu_Int(v)); }
static void EnvSettingsScreen_InitWidgets(struct MenuOptionsScreen* s) {
static const struct MenuOptionDesc buttons[10] = {
static const struct MenuOptionDesc buttons[] = {
{ -1, -150, "Clouds color", MenuOptionsScreen_Input,
EnvSettingsScreen_GetCloudsColor, EnvSettingsScreen_SetCloudsColor },
{ -1, -100, "Sky color", MenuOptionsScreen_Input,
@ -2723,7 +2723,7 @@ static void GraphicsOptionsScreen_SetCameraMass(const cc_string* c) {
}
static void GraphicsOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
static const struct MenuOptionDesc buttons[8] = {
static const struct MenuOptionDesc buttons[] = {
{ -1, -100, "Camera Mass", MenuOptionsScreen_Input,
GraphicsOptionsScreen_GetCameraMass, GraphicsOptionsScreen_SetCameraMass },
{ -1, -50, "FPS mode", MenuOptionsScreen_Enum,
@ -3105,7 +3105,80 @@ void MiscOptionsScreen_Show(void) {
/*########################################################################################################################*
*-----------------------------------------------------NostalgiaScreen-----------------------------------------------------*
*--------------------------------------------------NostalgiaMenuScreen-----------------------------------------------------*
*#########################################################################################################################*/
static struct NostalgiaMenuScreen {
Screen_Body
struct ButtonWidget btnA, btnF, done;
struct TextWidget title;
} NostalgiaMenuScreen;
static struct Widget* nostalgiaMenu_widgets[] = {
(struct Widget*)&NostalgiaMenuScreen.btnA, (struct Widget*)&NostalgiaMenuScreen.btnF,
(struct Widget*)&NostalgiaMenuScreen.done, (struct Widget*)&NostalgiaMenuScreen.title
};
#define NOSTALGIA_MENU_MAX_VERTICES (3 * BUTTONWIDGET_MAX + TEXTWIDGET_MAX)
static void NostalgiaMenuScreen_Appearance(void* a, void* b) { NostalgiaAppearanceScreen_Show(); }
static void NostalgiaMenuScreen_Functionality(void* a, void* b) { NostalgiaFunctionalityScreen_Show(); }
static void NostalgiaMenuScreen_SwitchBack(void* a, void* b) {
if (Gui.ClassicMenu) { Menu_SwitchPause(a, b); } else { Menu_SwitchOptions(a, b); }
}
static void NostalgiaMenuScreen_ContextRecreated(void* screen) {
struct NostalgiaMenuScreen* s = (struct NostalgiaMenuScreen*)screen;
struct FontDesc titleFont;
Screen_UpdateVb(screen);
Gui_MakeTitleFont(&titleFont);
TextWidget_SetConst(&s->title, "Nostalgia options", &titleFont);
ButtonWidget_SetConst(&s->btnA, "Appearance", &titleFont);
ButtonWidget_SetConst(&s->btnF, "Functionality", &titleFont);
ButtonWidget_SetConst(&s->done, "Done", &titleFont);
Font_Free(&titleFont);
}
static void NostalgiaMenuScreen_Layout(void* screen) {
struct NostalgiaMenuScreen* s = (struct NostalgiaMenuScreen*)screen;
Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100);
Widget_SetLocation(&s->btnA, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -25);
Widget_SetLocation(&s->btnF, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 25);
Menu_LayoutBack(&s->done);
}
static void NostalgiaMenuScreen_Init(void* screen) {
struct NostalgiaMenuScreen* s = (struct NostalgiaMenuScreen*)screen;
s->widgets = nostalgiaMenu_widgets;
s->numWidgets = Array_Elems(nostalgiaMenu_widgets);
s->maxVertices = NOSTALGIA_MENU_MAX_VERTICES;
TextWidget_Init(&s->title);
ButtonWidget_Init(&s->btnA, 400, NostalgiaMenuScreen_Appearance);
ButtonWidget_Init(&s->btnF, 400, NostalgiaMenuScreen_Functionality);
ButtonWidget_Init(&s->done, 400, NostalgiaMenuScreen_SwitchBack);
}
static const struct ScreenVTABLE NostalgiaMenuScreen_VTABLE = {
NostalgiaMenuScreen_Init, Screen_NullUpdate, Screen_NullFunc,
MenuScreen_Render2, Screen_BuildMesh,
Screen_InputDown, Screen_InputUp, Screen_TKeyPress, Screen_TText,
Menu_PointerDown, Screen_PointerUp, Menu_PointerMove, Screen_TMouseScroll,
NostalgiaMenuScreen_Layout, Screen_ContextLost, NostalgiaMenuScreen_ContextRecreated
};
void NostalgiaMenuScreen_Show(void) {
struct NostalgiaMenuScreen* s = &NostalgiaMenuScreen;
s->grabsInput = true;
s->closable = true;
s->VTABLE = &NostalgiaMenuScreen_VTABLE;
Gui_Add((struct Screen*)s, GUI_PRIORITY_MENU);
}
/*########################################################################################################################*
*------------------------------------------------NostalgiaAppearanceScreen------------------------------------------------*
*#########################################################################################################################*/
static void NostalgiaScreen_GetHand(cc_string* v) { Menu_GetBool(v, Models.ClassicArms); }
static void NostalgiaScreen_SetHand(const cc_string* v) { Models.ClassicArms = Menu_SetBool(v, OPT_CLASSIC_ARM_MODEL); }
@ -3116,6 +3189,12 @@ static void NostalgiaScreen_SetAnim(const cc_string* v) {
Options_SetBool(OPT_SIMPLE_ARMS_ANIM, Game_SimpleArmsAnim);
}
static void NostalgiaScreen_GetClassicChat(cc_string* v) { Menu_GetBool(v, Gui.ClassicChat); }
static void NostalgiaScreen_SetClassicChat(const cc_string* v) { Gui.ClassicChat = Menu_SetBool(v, OPT_CLASSIC_CHAT); }
static void NostalgiaScreen_GetClassicInv(cc_string* v) { Menu_GetBool(v, Gui.ClassicInventory); }
static void NostalgiaScreen_SetClassicInv(const cc_string* v) { Gui.ClassicInventory = Menu_SetBool(v, OPT_CLASSIC_INVENTORY); }
static void NostalgiaScreen_GetGui(cc_string* v) { Menu_GetBool(v, Gui.ClassicTexture); }
static void NostalgiaScreen_SetGui(const cc_string* v) { Gui.ClassicTexture = Menu_SetBool(v, OPT_CLASSIC_GUI); }
@ -3125,66 +3204,73 @@ static void NostalgiaScreen_SetList(const cc_string* v) { Gui.ClassicTabList = M
static void NostalgiaScreen_GetOpts(cc_string* v) { Menu_GetBool(v, Gui.ClassicMenu); }
static void NostalgiaScreen_SetOpts(const cc_string* v) { Gui.ClassicMenu = Menu_SetBool(v, OPT_CLASSIC_OPTIONS); }
static void NostalgiaAppearanceScreen_InitWidgets(struct MenuOptionsScreen* s) {
static const struct MenuOptionDesc buttons[] = {
{ -1, -100, "Classic hand model", MenuOptionsScreen_Bool,
NostalgiaScreen_GetHand, NostalgiaScreen_SetHand },
{ -1, -50, "Classic walk anim", MenuOptionsScreen_Bool,
NostalgiaScreen_GetAnim, NostalgiaScreen_SetAnim },
{ -1, 0, "Classic chat", MenuOptionsScreen_Bool,
NostalgiaScreen_GetClassicChat, NostalgiaScreen_SetClassicChat },
{ -1, 50, "Classic inventory", MenuOptionsScreen_Bool,
NostalgiaScreen_GetClassicInv, NostalgiaScreen_SetClassicInv },
{ 1, -50, "Classic GUI textures", MenuOptionsScreen_Bool,
NostalgiaScreen_GetGui, NostalgiaScreen_SetGui },
{ 1, 0, "Classic player list", MenuOptionsScreen_Bool,
NostalgiaScreen_GetList, NostalgiaScreen_SetList },
{ 1, 50, "Classic options", MenuOptionsScreen_Bool,
NostalgiaScreen_GetOpts, NostalgiaScreen_SetOpts },
};
s->numCore = Array_Elems(buttons);
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_InitButtons(s, buttons, Array_Elems(buttons), Menu_SwitchNostalgia);
}
void NostalgiaAppearanceScreen_Show(void) {
MenuOptionsScreen_Show(NULL, NULL, 0, NostalgiaAppearanceScreen_InitWidgets);
}
/*########################################################################################################################*
*----------------------------------------------NostalgiaFunctionalityScreen-----------------------------------------------*
*#########################################################################################################################*/
static void NostalgiaScreen_GetTexs(cc_string* v) { Menu_GetBool(v, Game_AllowServerTextures); }
static void NostalgiaScreen_SetTexs(const cc_string* v) { Game_AllowServerTextures = Menu_SetBool(v, OPT_SERVER_TEXTURES); }
static void NostalgiaScreen_GetCustom(cc_string* v) { Menu_GetBool(v, Game_AllowCustomBlocks); }
static void NostalgiaScreen_SetCustom(const cc_string* v) { Game_AllowCustomBlocks = Menu_SetBool(v, OPT_CUSTOM_BLOCKS); }
static void NostalgiaScreen_GetCPE(cc_string* v) { Menu_GetBool(v, Game_UseCPE); }
static void NostalgiaScreen_SetCPE(const cc_string* v) { Game_UseCPE = Menu_SetBool(v, OPT_CPE); }
static void NostalgiaScreen_GetTexs(cc_string* v) { Menu_GetBool(v, Game_AllowServerTextures); }
static void NostalgiaScreen_SetTexs(const cc_string* v) { Game_AllowServerTextures = Menu_SetBool(v, OPT_SERVER_TEXTURES); }
static void NostalgiaScreen_GetClassicChat(cc_string* v) { Menu_GetBool(v, Gui.ClassicChat); }
static void NostalgiaScreen_SetClassicChat(const cc_string* v) { Gui.ClassicChat = Menu_SetBool(v, OPT_CLASSIC_CHAT); }
static void NostalgiaScreen_GetClassicInv(cc_string* v) { Menu_GetBool(v, Gui.ClassicInventory); }
static void NostalgiaScreen_SetClassicInv(const cc_string* v) { Gui.ClassicInventory = Menu_SetBool(v, OPT_CLASSIC_INVENTORY); }
static void NostalgiaScreen_SwitchBack(void* a, void* b) {
if (Gui.ClassicMenu) { Menu_SwitchPause(a, b); } else { Menu_SwitchOptions(a, b); }
}
static struct TextWidget nostalgia_desc;
static void NostalgiaScreen_RecreateExtra(struct MenuOptionsScreen* s) {
TextWidget_SetConst(&nostalgia_desc, "&eButtons on the right require restarting game", &s->textFont);
}
static void NostalgiaScreen_InitWidgets(struct MenuOptionsScreen* s) {
static void NostalgiaFunctionalityScreen_InitWidgets(struct MenuOptionsScreen* s) {
static const struct MenuOptionDesc buttons[] = {
{ -1, -150, "Classic hand model", MenuOptionsScreen_Bool,
NostalgiaScreen_GetHand, NostalgiaScreen_SetHand },
{ -1, -100, "Classic walk anim", MenuOptionsScreen_Bool,
NostalgiaScreen_GetAnim, NostalgiaScreen_SetAnim },
{ -1, -50, "Classic gui textures", MenuOptionsScreen_Bool,
NostalgiaScreen_GetGui, NostalgiaScreen_SetGui },
{ -1, 0, "Classic player list", MenuOptionsScreen_Bool,
NostalgiaScreen_GetList, NostalgiaScreen_SetList },
{ -1, 50, "Classic options", MenuOptionsScreen_Bool,
NostalgiaScreen_GetOpts, NostalgiaScreen_SetOpts },
{ 1, -150, "Allow custom blocks", MenuOptionsScreen_Bool,
NostalgiaScreen_GetCustom, NostalgiaScreen_SetCustom },
{ 1, -100, "Use CPE", MenuOptionsScreen_Bool,
NostalgiaScreen_GetCPE, NostalgiaScreen_SetCPE },
{ 1, -50, "Use server textures", MenuOptionsScreen_Bool,
{ -1, 0, "Use server textures", MenuOptionsScreen_Bool,
NostalgiaScreen_GetTexs, NostalgiaScreen_SetTexs },
{ 1, 0, "Use classic chat", MenuOptionsScreen_Bool,
NostalgiaScreen_GetClassicChat, NostalgiaScreen_SetClassicChat },
{ 1, 50, "Use classic inventory", MenuOptionsScreen_Bool,
NostalgiaScreen_GetClassicInv, NostalgiaScreen_SetClassicInv },
{ 1, -50, "Allow custom blocks", MenuOptionsScreen_Bool,
NostalgiaScreen_GetCustom, NostalgiaScreen_SetCustom },
{ 1, - 0, "Non-classic features", MenuOptionsScreen_Bool,
NostalgiaScreen_GetCPE, NostalgiaScreen_SetCPE }
};
s->numCore = 10 + 1;
s->maxVertices += 10 * BUTTONWIDGET_MAX + TEXTWIDGET_MAX;
s->numCore = Array_Elems(buttons) + 1;
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX + TEXTWIDGET_MAX;
s->DoRecreateExtra = NostalgiaScreen_RecreateExtra;
MenuOptionsScreen_InitButtons(s, buttons, Array_Elems(buttons), NostalgiaScreen_SwitchBack);
MenuOptionsScreen_InitButtons(s, buttons, Array_Elems(buttons), Menu_SwitchNostalgia);
TextWidget_Init(&nostalgia_desc);
Widget_SetLocation(&nostalgia_desc, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 100);
s->widgets[10] = (struct Widget*)&nostalgia_desc;
s->widgets[3] = (struct Widget*)&nostalgia_desc;
}
void NostalgiaScreen_Show(void) {
MenuOptionsScreen_Show(NULL, NULL, 0, NostalgiaScreen_InitWidgets);
void NostalgiaFunctionalityScreen_Show(void) {
MenuOptionsScreen_Show(NULL, NULL, 0, NostalgiaFunctionalityScreen_InitWidgets);
}

View file

@ -35,7 +35,9 @@ void GuiOptionsScreen_Show(void);
void GraphicsOptionsScreen_Show(void);
void HacksSettingsScreen_Show(void);
void EnvSettingsScreen_Show(void);
void NostalgiaScreen_Show(void);
void NostalgiaAppearanceScreen_Show(void);
void NostalgiaFunctionalityScreen_Show(void);
void NostalgiaMenuScreen_Show(void);
void UrlWarningOverlay_Show(const cc_string* url);
void TexIdsOverlay_Show(void);

View file

@ -369,6 +369,28 @@ static cc_result MapState_Read(struct MapState* m) {
/*########################################################################################################################*
*----------------------------------------------------Classic protocol-----------------------------------------------------*
*#########################################################################################################################*/
void Classic_SendLogin(void) {
cc_uint8 data[131];
data[0] = OPCODE_HANDSHAKE;
{
data[1] = Game_Version.Protocol;
WriteString(&data[2], &Game_Username);
WriteString(&data[66], &Game_Mppass);
/* The 'user type' field's behaviour depends on protocol version: */
/* version 7 - 0x42 specifies CPE client, any other value is ignored? */
/* version 6 - any value ignored? */
/* version 5 - field doesn't exist */
/* Theroetically, this means packet size is 131 bytes for 6/7, 130 bytes for 5 and below. */
/* In practice, some version 7 server software always expects to read 131 bytes for handshake packet, */
/* and will get stuck waiting for data if client connects using version 5 and only sends 130 bytes */
/* To workaround this, include a 'ping packet' after 'version 5 handshake packet' - version 5 server software */
/* will do nothing with the ping packet, and the aforementioned server software will be happy with 131 bytes */
data[130] = Game_UseCPE ? 0x42 : (Game_Version.Protocol <= PROTOCOL_0019 ? OPCODE_PING : 0x00);
}
Server.SendData(data, 131);
}
void Classic_SendChat(const cc_string* text, cc_bool partial) {
cc_uint8 data[66];
data[0] = OPCODE_MESSAGE;
@ -422,29 +444,6 @@ void Classic_SendSetBlock(int x, int y, int z, cc_bool place, BlockID block) {
Server.SendData(tmp, (cc_uint32)(data - tmp));
}
#define Classic_HandshakeSize() (Game_Version.Protocol > PROTOCOL_0019 ? 131 : 130)
void Classic_SendLogin(void) {
cc_uint8 data[131];
data[0] = OPCODE_HANDSHAKE;
{
data[1] = Game_Version.Protocol;
WriteString(&data[2], &Game_Username);
WriteString(&data[66], &Game_Mppass);
/* The 'user type' field's behaviour depends on protocol version: */
/* version 7 - 0x42 specifies CPE client, any other value is ignored? */
/* version 6 - any value ignored? */
/* version 5 - field doesn't exist */
/* Theroetically, this means packet size is 131 bytes for 6/7, 130 bytes for 5 and below. */
/* In practice, some version 7 server software always expects to read 131 bytes for handshake packet, */
/* and will get stuck waiting for data if client connects using version 5 and only sends 130 bytes */
/* To workaround this, include a 'ping packet' after 'version 5 handshake packet' - version 5 server software */
/* will do nothing with the ping packet, and the aforementioned server software will be happy with 131 bytes */
data[130] = Game_UseCPE ? 0x42 : (Game_Version.Protocol <= PROTOCOL_0019 ? OPCODE_PING : 0x00);
}
Server.SendData(data, 131);
}
static void Classic_Handshake(cc_uint8* data) {
struct HacksComp* hacks;

View file

@ -1368,6 +1368,7 @@ void ChatScreen_OpenInput(const cc_string* text) {
Gui_UpdateInputGrab();
OpenKeyboardArgs_Init(&args, text, KEYBOARD_TYPE_TEXT | KEYBOARD_FLAG_SEND);
args.placeholder = "Enter chat";
args.multiline = true;
Window_OpenKeyboard(&args);
s->input.base.disabled = args.opaque;

View file

@ -161,7 +161,7 @@ void Window_DrawFramebuffer(Rect2D r);
/* Frees the previously allocated framebuffer. */
void Window_FreeFramebuffer(struct Bitmap* bmp);
struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; cc_bool opaque; };
struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; cc_bool opaque, multiline; };
void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type);
/* Displays on-screen keyboard for platforms that lack physical keyboard input. */
/* NOTE: On desktop platforms, this won't do anything. */

View file

@ -1318,8 +1318,8 @@ void GLContext_GetApiInfo(cc_string* info) {
unsigned int vram, acc;
if (!queryRendererMESA) return;
queryRendererMESA(0x8186, &acc);
queryRendererMESA(0x8187, &vram);
queryRendererMESA(0x8186, &acc); /* GLX_RENDERER_ACCELERATED_MESA */
queryRendererMESA(0x8187, &vram); /* GLX_RENDERER_VIDEO_MEMORY_MESA */
String_Format2(info, "VRAM: %i MB, %c", &vram,
acc ? "HW accelerated" : "no HW acceleration");
}

View file

@ -74,7 +74,8 @@ void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_st
args->text = text;
args->type = type;
args->placeholder = "";
args->opaque = false;
args->opaque = false;
args->multiline = false;
}