From 72fb33f9b624aa300cc0ffa45cba49651c85026f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 25 Aug 2019 19:56:17 +1000 Subject: [PATCH] Even more const and fix compiler warnings --- src/Block.c | 2 +- src/Block.h | 2 +- src/Game.c | 2 +- src/Game.h | 2 +- src/Utils.c | 2 +- src/Utils.h | 2 +- src/Widgets.c | 12 ++++++------ src/Widgets.h | 16 ++++++++-------- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Block.c b/src/Block.c index 670e92546..4b63ea4c2 100644 --- a/src/Block.c +++ b/src/Block.c @@ -11,7 +11,7 @@ struct _BlockLists Blocks; -const char* Sound_Names[SOUND_COUNT] = { +const char* const Sound_Names[SOUND_COUNT] = { "none", "wood", "gravel", "grass", "stone", "metal", "glass", "cloth", "sand", "snow", }; diff --git a/src/Block.h b/src/Block.h index fc6299b18..4ffaeb47a 100644 --- a/src/Block.h +++ b/src/Block.h @@ -16,7 +16,7 @@ enum SoundType { SOUND_STONE, SOUND_METAL, SOUND_GLASS, SOUND_CLOTH, SOUND_SAND, SOUND_SNOW, SOUND_COUNT }; -extern const char* Sound_Names[SOUND_COUNT]; +extern const char* const Sound_Names[SOUND_COUNT]; /* Describes how a block is rendered in the world. */ enum DrawType { diff --git a/src/Game.c b/src/Game.c index 32ab55142..90c49c4c7 100644 --- a/src/Game.c +++ b/src/Game.c @@ -63,7 +63,7 @@ String Game_Username = String_FromArray(Game_UsernameBuffer); String Game_Mppass = String_FromArray(Game_MppassBuffer); String Game_Hash = String_FromArray(Game_HashBuffer); -const char* FpsLimit_Names[FPS_LIMIT_COUNT] = { +const char* const FpsLimit_Names[FPS_LIMIT_COUNT] = { "LimitVSync", "Limit30FPS", "Limit60FPS", "Limit120FPS", "Limit144FPS", "LimitNone", }; diff --git a/src/Game.h b/src/Game.h index a7035411d..6ec025cc0 100644 --- a/src/Game.h +++ b/src/Game.h @@ -51,7 +51,7 @@ extern bool Game_HideGui; enum FpsLimitMethod { FPS_LIMIT_VSYNC, FPS_LIMIT_30, FPS_LIMIT_60, FPS_LIMIT_120, FPS_LIMIT_144, FPS_LIMIT_NONE, FPS_LIMIT_COUNT }; -extern const char* FpsLimit_Names[FPS_LIMIT_COUNT]; +extern const char* const FpsLimit_Names[FPS_LIMIT_COUNT]; extern float Game_RawHotbarScale, Game_RawChatScale, Game_RawInventoryScale; float Game_Scale(float value); diff --git a/src/Utils.c b/src/Utils.c index d01566f2b..37f671fd1 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -11,7 +11,7 @@ /*########################################################################################################################* *----------------------------------------------------------Misc-----------------------------------------------------------* *#########################################################################################################################*/ -int Utils_ParseEnum(const String* text, int defValue, const char** names, int namesCount) { +int Utils_ParseEnum(const String* text, int defValue, const char* const* names, int namesCount) { int i; for (i = 0; i < namesCount; i++) { if (String_CaselessEqualsConst(text, names[i])) return i; diff --git a/src/Utils.h b/src/Utils.h index 87512cce5..bae5ece01 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -27,7 +27,7 @@ struct DateTime { #define HOURS_PER_DAY 24 #define MILLIS_PER_DAY (1000 * 60 * 60 * 24) -CC_NOINLINE int Utils_ParseEnum(const String* text, int defValue, const char** names, int namesCount); +CC_NOINLINE int Utils_ParseEnum(const String* text, int defValue, const char* const* names, int namesCount); /* Returns whether value starts with http:// or https:// */ bool Utils_IsUrlPrefix(const String* value); diff --git a/src/Widgets.c b/src/Widgets.c index 530fd7f53..b0cd443ce 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -1250,7 +1250,7 @@ static void Hex_Default(struct MenuInputDesc* d, String* value) { PackedCol_ToHex(value, d->meta.h.Default); } -struct MenuInputVTABLE HexValidator_VTABLE = { +const struct MenuInputVTABLE HexValidator_VTABLE = { Hex_Range, Hex_ValidChar, Hex_ValidString, Hex_ValidValue, Hex_Default }; @@ -1277,7 +1277,7 @@ static void Int_Default(struct MenuInputDesc* d, String* value) { String_AppendInt(value, d->meta.i.Default); } -struct MenuInputVTABLE IntValidator_VTABLE = { +const struct MenuInputVTABLE IntValidator_VTABLE = { Int_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Int_Default }; @@ -1286,7 +1286,7 @@ static void Seed_Range(struct MenuInputDesc* d, String* range) { } static void Seed_NoDefault(struct MenuInputDesc* d, String* value) { } -struct MenuInputVTABLE SeedValidator_VTABLE = { +const struct MenuInputVTABLE SeedValidator_VTABLE = { Seed_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Seed_NoDefault }; @@ -1313,7 +1313,7 @@ static void Float_Default(struct MenuInputDesc* d, String* value) { String_AppendFloat(value, d->meta.f.Default, 3); } -struct MenuInputVTABLE FloatValidator_VTABLE = { +const struct MenuInputVTABLE FloatValidator_VTABLE = { Float_Range, Float_ValidChar, Float_ValidString, Float_ValidValue, Float_Default }; @@ -1327,7 +1327,7 @@ static bool Path_ValidChar(struct MenuInputDesc* d, char c) { } static bool Path_ValidString(struct MenuInputDesc* d, const String* s) { return true; } -struct MenuInputVTABLE PathValidator_VTABLE = { +const struct MenuInputVTABLE PathValidator_VTABLE = { Path_Range, Path_ValidChar, Path_ValidString, Path_ValidString, Seed_NoDefault }; @@ -1343,7 +1343,7 @@ static bool String_ValidString(struct MenuInputDesc* d, const String* s) { return s->length <= STRING_SIZE; } -struct MenuInputVTABLE StringValidator_VTABLE = { +const struct MenuInputVTABLE StringValidator_VTABLE = { String_Range, String_ValidChar, String_ValidString, String_ValidString, Seed_NoDefault }; diff --git a/src/Widgets.h b/src/Widgets.h index 023e6a8ce..f1f08bbfb 100644 --- a/src/Widgets.h +++ b/src/Widgets.h @@ -148,21 +148,21 @@ struct MenuInputVTABLE { }; struct MenuInputDesc { - struct MenuInputVTABLE* VTABLE; + const struct MenuInputVTABLE* VTABLE; union { - struct { const char** Names; int Count; } e; + struct { const char* const* Names; int Count; } e; struct { int Min, Max, Default; } i; struct { float Min, Max, Default; } f; struct { PackedCol Default; } h; } meta; }; -extern struct MenuInputVTABLE HexValidator_VTABLE; -extern struct MenuInputVTABLE IntValidator_VTABLE; -extern struct MenuInputVTABLE SeedValidator_VTABLE; -extern struct MenuInputVTABLE FloatValidator_VTABLE; -extern struct MenuInputVTABLE PathValidator_VTABLE; -extern struct MenuInputVTABLE StringValidator_VTABLE; +extern const struct MenuInputVTABLE HexValidator_VTABLE; +extern const struct MenuInputVTABLE IntValidator_VTABLE; +extern const struct MenuInputVTABLE SeedValidator_VTABLE; +extern const struct MenuInputVTABLE FloatValidator_VTABLE; +extern const struct MenuInputVTABLE PathValidator_VTABLE; +extern const struct MenuInputVTABLE StringValidator_VTABLE; #define MenuInput_Hex(v, def) v.VTABLE = &HexValidator_VTABLE; v.meta.h.Default = def; #define MenuInput_Int(v, lo, hi, def) v.VTABLE = &IntValidator_VTABLE; v.meta.i.Min = lo; v.meta.i.Max = hi; v.meta.i.Default = def;