Fix being unable to press Escape to close overlays

This commit is contained in:
UnknownShadow200 2019-04-28 11:03:13 +10:00
parent f4c797f13e
commit 9b3df93c8e
11 changed files with 100 additions and 134 deletions

View file

@ -50,6 +50,7 @@ CC_API void Commands_Register(struct ChatCommand* cmd);
/* NOTE: This can only be set once. */
void Chat_SetLogName(const String* name);
/* Sends a chat message, raising ChatEvents.ChatSending event. */
/* NOTE: If logUsage is true, can press 'up' in chat input menu later to retype this. */
/* NOTE: /client is always interpreted as client-side commands. */
/* In multiplayer this is sent to the server, in singleplayer just Chat_Add. */
CC_API void Chat_Send(const String* text, bool logUsage);

View file

@ -145,11 +145,10 @@ static void Gui_Reset(void) {
static void Gui_Free(void) {
Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, Gui_FontChanged);
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Gui_FileChanged);
Gui_CloseActive();
Elem_TryFree(Gui_Active);
Elem_TryFree(Gui_Status);
Elem_TryFree(Gui_HUD);
if (Gui_Active) { Elem_TryFree(Gui_Active); }
Gfx_DeleteTexture(&Gui_GuiTex);
Gfx_DeleteTexture(&Gui_GuiClassicTex);
Gfx_DeleteTexture(&Gui_IconsTex);
@ -175,11 +174,14 @@ struct Screen* Gui_GetUnderlyingScreen(void) {
void Gui_FreeActive(void) {
if (Gui_Active) { Elem_TryFree(Gui_Active); }
}
void Gui_CloseActive(void) {
Gui_FreeActive();
Gui_SetActive(NULL);
void Gui_Close(void* screen) {
struct Screen* s = screen;
if (s) { Elem_TryFree(s); }
if (s == Gui_Active) Gui_SetActive(NULL);
}
void Gui_CloseActive(void) { Gui_Close(Gui_Active); }
void Gui_SetActive(struct Screen* screen) {
InputHandler_ScreenChanged(Gui_Active, screen);
if (screen) {
@ -214,8 +216,8 @@ void Gui_ShowOverlay(struct Screen* overlay, bool atFront) {
Camera_CheckFocus();
}
int Gui_IndexOverlay(const void* overlay) {
const struct Screen* s = overlay;
int Gui_IndexOverlay(const void* screen) {
const struct Screen* s = screen;
int i;
for (i = 0; i < Gui_OverlaysCount; i++) {
@ -224,12 +226,9 @@ int Gui_IndexOverlay(const void* overlay) {
return -1;
}
void Gui_FreeOverlay(void* overlay) {
struct Screen* s = overlay;
int i;
Elem_Free(s);
i = Gui_IndexOverlay(overlay);
void Gui_RemoveOverlay(void* screen) {
struct Screen* s = screen;
int i = Gui_IndexOverlay(screen);
if (i == -1) return;
for (; i < Gui_OverlaysCount - 1; i++) {

View file

@ -102,6 +102,8 @@ extern struct Screen* Gui_Active;
extern struct Screen* Gui_Overlays[GUI_MAX_OVERLAYS];
extern int Gui_OverlaysCount;
/* Calculates position of an element on a particular axis */
/* For example, to calculate X position of a text widget on screen */
int Gui_CalcPos(uint8_t anchor, int offset, int size, int axisLen);
/* Returns whether the given rectangle contains the given point. */
bool Gui_Contains(int recX, int recY, int width, int height, int x, int y);
@ -118,13 +120,17 @@ CC_NOINLINE void Gui_FreeActive(void);
/* Sets the active screen/menu that the user interacts with. */
/* NOTE: This doesn't free old active screen - must call Gui_FreeActive() first */
CC_NOINLINE void Gui_SetActive(struct Screen* screen);
/* NOTE: Same as Gui_FreeActive(); Gui_SetActive(NULL); */
/* Shortcut for Gui_Close(Gui_Active) */
CC_NOINLINE void Gui_CloseActive(void);
/* Frees the given screen, and if == Gui_Active, calls Gui_SetActive(NULL) */
CC_NOINLINE void Gui_Close(void* screen);
void Gui_RefreshHud(void);
void Gui_ShowOverlay(struct Screen* overlay, bool atFront);
int Gui_IndexOverlay(const void* overlay);
void Gui_FreeOverlay(void* overlay);
/* Returns index of the given screen in the overlays list, -1 if not */
int Gui_IndexOverlay(const void* screen);
/* Removes given screen from the overlays list */
void Gui_RemoveOverlay(const void* screen);
void Gui_RenderGui(double delta);
void Gui_OnResize(void);

View file

@ -40,8 +40,8 @@ const char* Key_Names[KEY_COUNT] = {
"Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9",
"KeypadDivide", "KeypadMultiply", "KeypadSubtract",
"KeypadAdd", "KeypadDecimal", "KeypadEnter",
"Tilde", "Minus", "Plus", "BracketLeft", "BracketRight",
"Semicolon", "Quote", "Comma", "Period", "Slash", "BackSlash",
"Tilde", "Minus", "Plus", "BracketLeft", "BracketRight", "Slash",
"Semicolon", "Quote", "Comma", "Period", "BackSlash",
"XButton1", "XButton2",
};

View file

@ -5,31 +5,6 @@
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based on OpenTK code
*/
/*
The Open Toolkit Library License
Copyright (c) 2006 - 2009 the Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
typedef enum Key_ {
KEY_NONE, /* Unrecognised key */
@ -61,8 +36,8 @@ typedef enum Key_ {
KEY_KP_DIVIDE, KEY_KP_MULTIPLY, KEY_KP_MINUS,
KEY_KP_PLUS, KEY_KP_DECIMAL, KEY_KP_ENTER,
KEY_TILDE, KEY_MINUS, KEY_EQUALS, KEY_LBRACKET, KEY_RBRACKET,
KEY_SEMICOLON, KEY_QUOTE, KEY_COMMA, KEY_PERIOD, KEY_SLASH, KEY_BACKSLASH,
KEY_TILDE, KEY_MINUS, KEY_EQUALS, KEY_LBRACKET, KEY_RBRACKET, KEY_SLASH,
KEY_SEMICOLON, KEY_QUOTE, KEY_COMMA, KEY_PERIOD, KEY_BACKSLASH,
KEY_XBUTTON1, KEY_XBUTTON2, /* so these can be used for hotkeys */
KEY_COUNT

View file

@ -461,10 +461,10 @@ static void InputHandler_KeyDown(void* obj, int key, bool was) {
Window_Close(); return;
} else if (key == KeyBinds[KEYBIND_SCREENSHOT] && !was) {
Game_ScreenshotRequested = true; return;
} else if (key == KEY_ESCAPE && active->Closable) {
Gui_Close(active);
} else if (Elem_HandlesKeyDown(active, key, was)) {
return;
} else if (key == KEY_ESCAPE && active->Closable) {
Gui_CloseActive();
} else if ((key == KEY_ESCAPE || key == KEY_PAUSE) && !active->HandlesAllInput) {
Gui_FreeActive();
Gui_SetActive(PauseScreen_MakeInstance()); return;

View file

@ -524,9 +524,7 @@ static void ListScreen_Free(void* screen) {
static bool ListScreen_KeyDown(void* screen, Key key, bool was) {
struct ListScreen* s = screen;
if (key == KEY_ESCAPE) {
Gui_CloseActive();
} else if (key == KEY_LEFT || key == KEY_PAGEUP) {
if (key == KEY_LEFT || key == KEY_PAGEUP) {
ListScreen_PageClick(s, false);
} else if (key == KEY_RIGHT || key == KEY_PAGEDOWN) {
ListScreen_PageClick(s, true);
@ -554,6 +552,7 @@ struct ListScreen* ListScreen_MakeInstance(void) {
struct ListScreen* s = &ListScreen_Instance;
StringsBuffer_Clear(&s->Entries);
s->HandlesAllInput = true;
s->Closable = true;
s->WidgetsCount = 0;
s->CurrentIndex = 0;
@ -567,7 +566,7 @@ struct ListScreen* ListScreen_MakeInstance(void) {
*--------------------------------------------------------MenuScreen-------------------------------------------------------*
*#########################################################################################################################*/
static bool MenuScreen_KeyDown(void* screen, Key key, bool was) {
if (key == KEY_ESCAPE) { Gui_CloseActive(); }
if (key == KEY_ESCAPE) { Gui_Close(screen); }
return key < KEY_F1 || key > KEY_F35;
}
static bool MenuScreen_MouseScroll(void* screen, float delta) { return true; }
@ -2919,6 +2918,11 @@ struct Screen* NostalgiaScreen_MakeInstance(void) {
/*########################################################################################################################*
*---------------------------------------------------------Overlay---------------------------------------------------------*
*#########################################################################################################################*/
static void Overlay_Free(void* screen) {
MenuScreen_Free(screen);
Gui_RemoveOverlay(screen);
}
static bool Overlay_KeyDown(void* screen, Key key, bool was) { return true; }
static void Overlay_MakeLabels(void* menu, struct TextWidget* labels, const String* lines) {
@ -2958,9 +2962,6 @@ static void WarningOverlay_MakeButtons(void* menu, struct ButtonWidget* btns, bo
static bool WarningOverlay_IsAlways(void* screen, void* w) { return Menu_Index(screen, w) >= 6; }
/*########################################################################################################################*
*------------------------------------------------------TexIdsOverlay------------------------------------------------------*
*#########################################################################################################################*/
/*########################################################################################################################*
*------------------------------------------------------TexIdsOverlay------------------------------------------------------*
*#########################################################################################################################*/
@ -3088,26 +3089,26 @@ static void TexIdsOverlay_Render(void* screen, double delta) {
}
static bool TexIdsOverlay_KeyDown(void* screen, Key key, bool was) {
struct Screen* active = Gui_GetUnderlyingScreen();
struct Screen* s = screen;
if (key == KeyBinds[KEYBIND_IDOVERLAY]) { Elem_Free(s); return true; }
if (key == KeyBinds[KEYBIND_IDOVERLAY] || key == KEY_ESCAPE) {
Gui_FreeOverlay(screen); return true;
}
return Elem_HandlesKeyDown(active, key, was);
/* allow user to chat when tex ids overlay is active */
s = Gui_GetUnderlyingScreen();
return Elem_HandlesKeyDown(s, key, was);
}
static bool TexIdsOverlay_KeyPress(void* screen, char keyChar) {
struct Screen* active = Gui_GetUnderlyingScreen();
return Elem_HandlesKeyPress(active, keyChar);
struct Screen* s = Gui_GetUnderlyingScreen();
return Elem_HandlesKeyPress(s, keyChar);
}
static bool TexIdsOverlay_KeyUp(void* screen, Key key) {
struct Screen* active = Gui_GetUnderlyingScreen();
return Elem_HandlesKeyUp(active, key);
struct Screen* s = Gui_GetUnderlyingScreen();
return Elem_HandlesKeyUp(s, key);
}
static struct ScreenVTABLE TexIdsOverlay_VTABLE = {
TexIdsOverlay_Init, TexIdsOverlay_Render, MenuScreen_Free, Gui_DefaultRecreate,
TexIdsOverlay_Init, TexIdsOverlay_Render, Overlay_Free, Gui_DefaultRecreate,
TexIdsOverlay_KeyDown, TexIdsOverlay_KeyUp, TexIdsOverlay_KeyPress,
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_OnResize, TexIdsOverlay_ContextLost, TexIdsOverlay_ContextRecreated,
@ -3117,6 +3118,7 @@ struct Screen* TexIdsOverlay_MakeInstance(void) {
struct TexIdsOverlay* s = &TexIdsOverlay_Instance;
s->HandlesAllInput = true;
s->Closable = true;
s->Widgets = widgets;
s->WidgetsCount = Array_Elems(widgets);
@ -3132,13 +3134,13 @@ static struct UrlWarningOverlay UrlWarningOverlay_Instance;
static void UrlWarningOverlay_OpenUrl(void* screen, void* b) {
struct UrlWarningOverlay* s = screen;
Process_StartOpen(&s->Url);
Gui_FreeOverlay(s);
Elem_Free(s);
}
static void UrlWarningOverlay_AppendUrl(void* screen, void* b) {
struct UrlWarningOverlay* s = screen;
if (Gui_ClickableChat) { HUDScreen_AppendInput(Gui_HUD, &s->Url); }
Gui_FreeOverlay(s);
Elem_Free(s);
}
static void UrlWarningOverlay_ContextRecreated(void* screen) {
@ -3158,7 +3160,7 @@ static void UrlWarningOverlay_ContextRecreated(void* screen) {
}
static struct ScreenVTABLE UrlWarningOverlay_VTABLE = {
MenuScreen_Init, MenuScreen_Render, MenuScreen_Free, Gui_DefaultRecreate,
MenuScreen_Init, MenuScreen_Render, Overlay_Free, Gui_DefaultRecreate,
Overlay_KeyDown, Menu_KeyUp, Menu_KeyPress,
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_OnResize, Menu_ContextLost, UrlWarningOverlay_ContextRecreated,
@ -3168,6 +3170,7 @@ struct Screen* UrlWarningOverlay_MakeInstance(const String* url) {
struct UrlWarningOverlay* s = &UrlWarningOverlay_Instance;
s->HandlesAllInput = true;
s->Closable = true;
s->Widgets = widgets;
s->WidgetsCount = Array_Elems(widgets);
@ -3185,21 +3188,15 @@ struct Screen* UrlWarningOverlay_MakeInstance(const String* url) {
static struct ConfirmDenyOverlay ConfirmDenyOverlay_Instance;
static void ConfirmDenyOverlay_ConfirmNoClick(void* screen, void* b) {
struct ConfirmDenyOverlay* s = screen;
String url;
Gui_FreeOverlay(s);
url = s->Url;
if (s->AlwaysDeny && !TextureCache_HasDenied(&url)) {
TextureCache_Deny(&url);
}
if (s->AlwaysDeny) TextureCache_Deny(&s->Url);
Elem_Free(s);
}
static void ConfirmDenyOverlay_GoBackClick(void* screen, void* b) {
struct ConfirmDenyOverlay* s = screen;
struct Screen* overlay;
Gui_FreeOverlay(s);
Elem_Free(s);
overlay = TexPackOverlay_MakeInstance(&s->Url);
Gui_ShowOverlay(overlay, true);
}
@ -3224,9 +3221,9 @@ static void ConfirmDenyOverlay_ContextRecreated(void* screen) {
}
static struct ScreenVTABLE ConfirmDenyOverlay_VTABLE = {
MenuScreen_Init, MenuScreen_Render, MenuScreen_Free, Gui_DefaultRecreate,
MenuScreen_Init, MenuScreen_Render, Overlay_Free, Gui_DefaultRecreate,
Overlay_KeyDown, Menu_KeyUp, Menu_KeyPress,
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_OnResize, Menu_ContextLost, ConfirmDenyOverlay_ContextRecreated,
};
struct Screen* ConfirmDenyOverlay_MakeInstance(const String* url, bool alwaysDeny) {
@ -3234,6 +3231,7 @@ struct Screen* ConfirmDenyOverlay_MakeInstance(const String* url, bool alwaysDen
struct ConfirmDenyOverlay* s = &ConfirmDenyOverlay_Instance;
s->HandlesAllInput = true;
s->Closable = true;
s->Widgets = widgets;
s->WidgetsCount = Array_Elems(widgets);
@ -3252,30 +3250,22 @@ struct Screen* ConfirmDenyOverlay_MakeInstance(const String* url, bool alwaysDen
static struct TexPackOverlay TexPackOverlay_Instance;
static void TexPackOverlay_YesClick(void* screen, void* widget) {
struct TexPackOverlay* s = screen;
String url;
bool isAlways;
Gui_FreeOverlay(s);
url = String_UNSAFE_SubstringAt(&s->Identifier, 3);
String url = String_UNSAFE_SubstringAt(&s->Identifier, 3);
Server_DownloadTexturePack(&url);
isAlways = WarningOverlay_IsAlways(s, widget);
if (isAlways && !TextureCache_HasAccepted(&url)) {
TextureCache_Accept(&url);
}
if (WarningOverlay_IsAlways(s, widget)) TextureCache_Accept(&url);
Elem_Free(s);
}
static void TexPackOverlay_NoClick(void* screen, void* widget) {
struct TexPackOverlay* s = screen;
struct Screen* overlay;
String url;
bool isAlways;
String url = String_UNSAFE_SubstringAt(&s->Identifier, 3);
bool always;
Gui_FreeOverlay(s);
url = String_UNSAFE_SubstringAt(&s->Identifier, 3);
isAlways = WarningOverlay_IsAlways(s, widget);
overlay = ConfirmDenyOverlay_MakeInstance(&url, isAlways);
Elem_Free(s);
always = WarningOverlay_IsAlways(s, widget);
overlay = ConfirmDenyOverlay_MakeInstance(&url, always);
Gui_ShowOverlay(overlay, true);
}
@ -3329,25 +3319,24 @@ static void TexPackOverlay_ContextRecreated(void* screen) {
}
static struct ScreenVTABLE TexPackOverlay_VTABLE = {
MenuScreen_Init, TexPackOverlay_Render, MenuScreen_Free, Gui_DefaultRecreate,
MenuScreen_Init, TexPackOverlay_Render, Overlay_Free, Gui_DefaultRecreate,
Overlay_KeyDown, Menu_KeyUp, Menu_KeyPress,
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_MouseDown, Menu_MouseUp, Menu_MouseMove, MenuScreen_MouseScroll,
Menu_OnResize, Menu_ContextLost, TexPackOverlay_ContextRecreated,
};
struct Screen* TexPackOverlay_MakeInstance(const String* url) {
static struct Widget* widgets[8];
struct TexPackOverlay* s = &TexPackOverlay_Instance;
void* overlay;
struct ConfirmDenyOverlay* deny = &ConfirmDenyOverlay_Instance;
/* If we are showing a texture pack overlay, completely free that overlay */
/* It doesn't matter anymore, because the new texture pack URL will always */
/* replace/override the old texture pack URL associated with that overlay */
overlay = &TexPackOverlay_Instance;
if (Gui_IndexOverlay(overlay) >= 0) { Gui_FreeOverlay(overlay); }
overlay = &ConfirmDenyOverlay_Instance;
if (Gui_IndexOverlay(overlay) >= 0) { Gui_FreeOverlay(overlay); }
if (Gui_IndexOverlay(s) >= 0) { Elem_Free(s); }
if (Gui_IndexOverlay(deny) >= 0) { Elem_Free(deny); }
s->HandlesAllInput = true;
s->Closable = true;
s->Widgets = widgets;
s->WidgetsCount = Array_Elems(widgets);

View file

@ -208,7 +208,7 @@ static void WoM_CheckMotd(void) {
String motd, host;
int index;
motd = Server.ServerMOTD;
motd = Server.MOTD;
if (!motd.length) return;
index = String_IndexOfString(&motd, &cfg);
if (Game_PureClassic || index == -1) return;
@ -367,19 +367,19 @@ void Classic_WriteLogin(const String* username, const String* verKey) {
static void Classic_Handshake(uint8_t* data) {
struct HacksComp* hacks;
Server.ServerName.length = 0;
Server.ServerMOTD.length = 0;
Server.Name.length = 0;
Server.MOTD.length = 0;
data++; /* protocol version */
Handlers_ReadString(&data, &Server.ServerName);
Handlers_ReadString(&data, &Server.ServerMOTD);
Chat_SetLogName(&Server.ServerName);
Handlers_ReadString(&data, &Server.Name);
Handlers_ReadString(&data, &Server.MOTD);
Chat_SetLogName(&Server.Name);
hacks = &LocalPlayer_Instance.Hacks;
HacksComp_SetUserType(hacks, *data, !cpe_blockPerms);
String_Copy(&hacks->HacksFlags, &Server.ServerName);
String_AppendString(&hacks->HacksFlags, &Server.ServerMOTD);
String_Copy(&hacks->HacksFlags, &Server.Name);
String_AppendString(&hacks->HacksFlags, &Server.MOTD);
HacksComp_UpdateState(hacks);
}
@ -397,7 +397,7 @@ static void Classic_StartLoading(void) {
classic_prevScreen = NULL;
}
Gui_SetActive(LoadingScreen_MakeInstance(&Server.ServerName, &Server.ServerMOTD));
Gui_SetActive(LoadingScreen_MakeInstance(&Server.Name, &Server.MOTD));
WoM_CheckMotd();
classic_receivedFirstPos = false;

View file

@ -177,13 +177,11 @@ static bool InventoryScreen_KeyDown(void* screen, Key key, bool was) {
struct InventoryScreen* s = screen;
struct TableWidget* table = &s->Table;
if (key == KEY_ESCAPE) {
Gui_CloseActive();
} else if (key == KeyBinds[KEYBIND_INVENTORY] && s->ReleasedInv) {
Gui_CloseActive();
if (key == KeyBinds[KEYBIND_INVENTORY] && s->ReleasedInv) {
Gui_Close(screen);
} else if (key == KEY_ENTER && table->SelectedIndex != -1) {
Inventory_SetSelectedBlock(table->Elements[table->SelectedIndex]);
Gui_CloseActive();
Gui_Close(screen);
} else if (Elem_HandlesKeyDown(table, key, was)) {
} else {
struct HUDScreen* hud = (struct HUDScreen*)Gui_HUD;
@ -216,7 +214,7 @@ static bool InventoryScreen_MouseDown(void* screen, int x, int y, MouseButton bt
if ((!handled || table->PendingClose) && btn == MOUSE_LEFT) {
hotbar = Key_IsControlPressed() || Key_IsShiftPressed();
if (!hotbar) Gui_CloseActive();
if (!hotbar) Gui_Close(screen);
}
return true;
}
@ -251,6 +249,7 @@ static struct ScreenVTABLE InventoryScreen_VTABLE = {
struct Screen* InventoryScreen_MakeInstance(void) {
struct InventoryScreen* s = &InventoryScreen_Instance;
s->HandlesAllInput = true;
s->Closable = true;
s->VTABLE = &InventoryScreen_VTABLE;
return (struct Screen*)s;
@ -648,10 +647,7 @@ static void GeneratingScreen_EndGeneration(void) {
Gui_CloseActive();
Gen_Done = false;
if (!Gen_Blocks) {
Chat_AddRaw("&cFailed to generate the map."); return;
}
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
Gen_Blocks = NULL;

View file

@ -23,10 +23,10 @@
#include "Platform.h"
#include "GameStructs.h"
static char server_nameBuffer[STRING_SIZE];
static char server_motdBuffer[STRING_SIZE];
static char server_appBuffer[STRING_SIZE];
static int server_ticks;
static char nameBuffer[STRING_SIZE];
static char motdBuffer[STRING_SIZE];
static char appBuffer[STRING_SIZE];
static int ticks;
struct _ServerConnectionData Server;
/*########################################################################################################################*
@ -217,11 +217,11 @@ static void SPConnection_SendPlayerClick(MouseButton button, bool pressed, Entit
static void SPConnection_Tick(struct ScheduledTask* task) {
if (Server.Disconnected) return;
if ((server_ticks % 3) == 0) {
if ((ticks % 3) == 0) { /* 60 -> 20 ticks a second */
Physics_Tick();
Server_CheckAsyncResources();
}
server_ticks++;
ticks++;
}
static void SPConnection_Init(void) {
@ -482,7 +482,7 @@ static void MPConnection_Tick(struct ScheduledTask* task) {
net_readCurrent = net_readBuffer + remaining;
/* Network is ticked 60 times a second. We only send position updates 20 times a second */
if ((server_ticks % 3) == 0) {
if ((ticks % 3) == 0) {
Server_CheckAsyncResources();
Handlers_Tick();
/* Have any packets been written? */
@ -490,7 +490,7 @@ static void MPConnection_Tick(struct ScheduledTask* task) {
Net_SendPacket();
}
}
server_ticks++;
ticks++;
}
void Net_SendPacket(void) {
@ -553,9 +553,9 @@ static void MPConnection_Reset(void) {
}
static void Server_Init(void) {
String_InitArray(Server.ServerName, server_nameBuffer);
String_InitArray(Server.ServerMOTD, server_motdBuffer);
String_InitArray(Server.AppName, server_appBuffer);
String_InitArray(Server.Name, nameBuffer);
String_InitArray(Server.MOTD, motdBuffer);
String_InitArray(Server.AppName, appBuffer);
if (!Game_IPAddress.length) {
SPConnection_Init();

View file

@ -63,11 +63,11 @@ CC_VAR extern struct _ServerConnectionData {
void (*SendPlayerClick)(MouseButton button, bool pressed, EntityID targetId, struct PickedPos* pos);
/* The current name of the server. (Shows as first line when loading) */
String ServerName;
String Name;
/* The current MOTD of the server. (Shows as second line when loading) */
String ServerMOTD;
String MOTD;
/* The software name the client identifies itself as being to the server. */
/* By default this is the same as PROGRAM_APP_NAME */
/* By default this is the same as GAME_APP_NAME */
String AppName;
/* Buffer to data to send to the server. */