diff --git a/src/Core.h b/src/Core.h index c7a79447e..a6ccb447d 100644 --- a/src/Core.h +++ b/src/Core.h @@ -43,6 +43,7 @@ typedef signed __int64 int64_t; typedef uint16_t Codepoint; typedef uint8_t bool; +typedef uint8_t bool; #define true 1 #define false 0 #ifndef NULL diff --git a/src/Entity.c b/src/Entity.c index c3e41cf65..5b56e444e 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -409,14 +409,18 @@ static void TabList_RemoveAt(int index) { } } -bool TabList_Remove(EntityID id) { - if (!TabList_Valid(id)) return false; +static void TabList_Delete(EntityID id) { + if (!TabList_Valid(id)) return; TabList_RemoveAt(TabList_PlayerNames[id]); TabList_RemoveAt(TabList_ListNames[id]); TabList_RemoveAt(TabList_GroupNames[id]); TabList_GroupRanks[id] = 0; - return true; +} + +void TabList_Remove(EntityID id) { + TabList_Delete(id); + Event_RaiseInt(&TabListEvents.Removed, id); } void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank) { @@ -424,7 +428,7 @@ void TabList_Set(EntityID id, const String* player, const String* list, const St String_InitArray(colorlessName, colorlessBuffer); String_AppendColorless(&colorlessName, player); - TabList_Remove(id); + TabList_Delete(id); TabList_PlayerNames[id] = TabList_Buffer.Count; StringsBuffer_Add(&TabList_Buffer, &colorlessName); TabList_ListNames[id] = TabList_Buffer.Count; StringsBuffer_Add(&TabList_Buffer, list); diff --git a/src/Entity.h b/src/Entity.h index be0d70a50..ddb89bcd0 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -16,9 +16,6 @@ extern struct IGameComponent Entities_Component; /* Offset used to avoid floating point roundoff errors. */ #define ENTITY_ADJUSTMENT 0.001f -/* Maxmimum number of characters in a model name. */ -#define ENTITY_MAX_MODEL_LENGTH 11 - #define ENTITIES_MAX_COUNT 256 #define ENTITIES_SELF_ID 255 @@ -34,8 +31,7 @@ typedef enum ShadowMode_ { extern ShadowMode Entities_ShadowMode; extern const char* ShadowMode_Names[SHADOW_MODE_COUNT]; -#define ENTITY_TYPE_NONE 0 -#define ENTITY_TYPE_PLAYER 1 +enum EntityType { ENTITY_TYPE_NONE, ENTITY_TYPE_PLAYER }; #define LOCATIONUPDATE_FLAG_POS 0x01 #define LOCATIONUPDATE_FLAG_HEADX 0x02 @@ -120,8 +116,11 @@ extern uint16_t TabList_PlayerNames[TABLIST_MAX_NAMES]; extern uint16_t TabList_ListNames[TABLIST_MAX_NAMES]; extern uint16_t TabList_GroupNames[TABLIST_MAX_NAMES]; extern uint8_t TabList_GroupRanks[TABLIST_MAX_NAMES]; + +/* Returns whether the given tab list entry is used at all. */ bool TabList_Valid(EntityID id); -bool TabList_Remove(EntityID id); +/* Removes the tab list entry with the given ID, raising TabListEvents.Removed event. */ +void TabList_Remove(EntityID id); void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank); #define TabList_UNSAFE_GetPlayer(id) StringsBuffer_UNSAFE_Get(&TabList_Buffer, TabList_PlayerNames[id]); diff --git a/src/Game.c b/src/Game.c index 337a722ec..6437e6459 100644 --- a/src/Game.c +++ b/src/Game.c @@ -700,7 +700,7 @@ void Game_Free(void* obj) { Logger_Warn2 = Logger_DialogWarn2; Gfx_Free(); - if (!Options_HasAnyChanged()) return; + if (!Options_ChangedCount()) return; Options_Load(); Options_Save(); } diff --git a/src/Http.c b/src/Http.c index 14f5b9fc7..882b5cd55 100644 --- a/src/Http.c +++ b/src/Http.c @@ -497,7 +497,6 @@ static struct HttpRequestList http_processed; const static String http_skinServer = String_FromConst("http://static.classicube.net/skins/"); static struct HttpRequest http_curRequest; static volatile int http_curProgress = ASYNC_PROGRESS_NOTHING; -bool Http_UseCookies; /* Adds a req to the list of pending requests, waking up worker thread if needed. */ static void Http_Add(const String* url, bool priority, const String* id, uint8_t type, TimeMS* lastModified, const String* etag, const void* data, uint32_t size) { diff --git a/src/Http.h b/src/Http.h index e1e210a91..5a6dcdea1 100644 --- a/src/Http.h +++ b/src/Http.h @@ -11,9 +11,6 @@ struct ScheduledTask; #define URL_MAX_SIZE (STRING_SIZE * 2) extern struct IGameComponent Http_Component; -/* TODO: Implement these */ -extern bool Http_UseCookies; -/* TODO: Connection pooling */ enum HttpRequestType { REQUEST_TYPE_GET, REQUEST_TYPE_HEAD, REQUEST_TYPE_POST }; enum HttpProgress { diff --git a/src/Launcher.c b/src/Launcher.c index 39278afec..3838b7bd0 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -230,9 +230,7 @@ void Launcher_Run(void) { Launcher_Framebuffer.Height = Game_Height; Window_InitRaw(&Launcher_Framebuffer); - Http_UseCookies = true; Http_Component.Init(); - Resources_CheckExistence(); CheckUpdateTask_Run(); @@ -251,7 +249,7 @@ void Launcher_Run(void) { Thread_Sleep(10); } - if (Options_HasAnyChanged()) { + if (Options_ChangedCount()) { Options_Load(); Options_Save(); } diff --git a/src/Options.c b/src/Options.c index 1fa4b2e21..807590b7f 100644 --- a/src/Options.c +++ b/src/Options.c @@ -14,7 +14,7 @@ const char* FpsLimit_Names[FPS_LIMIT_COUNT] = { struct EntryList Options; static StringsBuffer Options_Changed; -bool Options_HasAnyChanged(void) { return Options_Changed.Count > 0; } +int Options_ChangedCount(void) { return Options_Changed.Count; } void Options_Free(void) { StringsBuffer_Clear(&Options.Entries); @@ -64,7 +64,7 @@ void Options_Get(const char* key, String* value, const char* defValue) { int Options_GetInt(const char* key, int min, int max, int defValue) { String str; int value; - if (!Options_UNSAFE_Get(key, &str)) return defValue; + if (!Options_UNSAFE_Get(key, &str)) return defValue; if (!Convert_ParseInt(&str, &value)) return defValue; Math_Clamp(value, min, max); @@ -74,7 +74,7 @@ int Options_GetInt(const char* key, int min, int max, int defValue) { bool Options_GetBool(const char* key, bool defValue) { String str; bool value; - if (!Options_UNSAFE_Get(key, &str)) return defValue; + if (!Options_UNSAFE_Get(key, &str)) return defValue; if (!Convert_ParseBool(&str, &value)) return defValue; return value; @@ -83,7 +83,7 @@ bool Options_GetBool(const char* key, bool defValue) { float Options_GetFloat(const char* key, float min, float max, float defValue) { String str; float value; - if (!Options_UNSAFE_Get(key, &str)) return defValue; + if (!Options_UNSAFE_Get(key, &str)) return defValue; if (!Convert_ParseFloat(&str, &value)) return defValue; Math_Clamp(value, min, max); diff --git a/src/Options.h b/src/Options.h index 2adc26404..cafb3930f 100644 --- a/src/Options.h +++ b/src/Options.h @@ -72,8 +72,8 @@ extern const char* FpsLimit_Names[FPS_LIMIT_COUNT]; #define OPT_MAX_CHUNK_UPDATES "gfx-maxchunkupdates" extern struct EntryList Options; -/* Returns whether user has changed any options this session. */ -bool Options_HasAnyChanged(void); +/* Returns the number of options changed via Options_SetXYZ since last save. */ +int Options_ChangedCount(void); /* Frees any memory allocated in storing options. */ void Options_Free(void); diff --git a/src/PacketHandlers.c b/src/PacketHandlers.c index cf4fe0637..bf91da143 100644 --- a/src/PacketHandlers.c +++ b/src/PacketHandlers.c @@ -133,11 +133,6 @@ static void Handlers_AddTablistEntry(EntityID id, const String* playerName, cons } } -static void Handlers_RemoveTablistEntry(EntityID id) { - Event_RaiseInt(&TabListEvents.Removed, id); - TabList_Remove(id); -} - static void Handlers_CheckName(EntityID id, String* name, String* skin) { String colorlessName; char colorlessBuffer[STRING_SIZE]; @@ -194,7 +189,7 @@ void Handlers_RemoveEntity(EntityID id) { /* See comment about some servers in Classic_AddEntity */ if (!Classic_TabList_Get(id)) return; - Handlers_RemoveTablistEntry(id); + TabList_Remove(id); Classic_TabList_Reset(id); } @@ -1040,7 +1035,7 @@ static void CPE_ExtAddEntity(uint8_t* data) { static void CPE_ExtRemovePlayerName(uint8_t* data) { EntityID id = data[1]; - Handlers_RemoveTablistEntry(id); + TabList_Remove(id); } static void CPE_MakeSelection(uint8_t* data) { diff --git a/src/Utils.c b/src/Utils.c index 3d77ce25f..a8409da01 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -114,10 +114,6 @@ int Utils_ParseEnum(const String* text, int defValue, const char** names, int na return defValue; } -bool Utils_IsValidInputChar(char c, bool supportsCP437) { - return supportsCP437 || (Convert_CP437ToUnicode(c) == c); -} - bool Utils_IsUrlPrefix(const String* value, int index) { const static String http = String_FromConst("http://"); const static String https = String_FromConst("https://"); diff --git a/src/Utils.h b/src/Utils.h index b69305cdb..2468561c3 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -32,7 +32,6 @@ void DateTime_FromTotalMs(struct DateTime* time, TimeMS ms); void DateTime_HttpDate(TimeMS ms, String* str); CC_NOINLINE int Utils_ParseEnum(const String* text, int defValue, const char** names, int namesCount); -bool Utils_IsValidInputChar(char c, bool supportsCP437); bool Utils_IsUrlPrefix(const String* value, int index); /* Creates the directory if it doesn't exist. (logs failure in chat) */ diff --git a/src/Widgets.c b/src/Widgets.c index 1dfd2ad60..3f1923c04 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -1008,7 +1008,7 @@ void InputWidget_Clear(struct InputWidget* w) { } static bool InputWidget_AllowedChar(void* widget, char c) { - return Utils_IsValidInputChar(c, ServerConnection_SupportsFullCP437); + return ServerConnection_SupportsFullCP437 || (Convert_CP437ToUnicode(c) == c); } static void InputWidget_AppendChar(struct InputWidget* w, char c) { @@ -1440,7 +1440,7 @@ static void String_Range(struct MenuInputValidator* v, String* range) { } static bool String_ValidChar(struct MenuInputValidator* v, char c) { - return c != '&' && Utils_IsValidInputChar(c, true); + return c != '&'; } static bool String_ValidString(struct MenuInputValidator* v, const String* s) {