Permalink
Browse files

and more

  • Loading branch information...
UnknownShadow200 committed Nov 6, 2018
1 parent aeec580 commit 30bb86babd50d1be4c616b3658250294fef2543c
Showing with 109 additions and 94 deletions.
  1. +2 −2 src/AsyncDownloader.c
  2. +3 −3 src/Chat.c
  3. +5 −4 src/Entity.c
  4. +8 −8 src/Game.c
  5. +2 −2 src/Input.c
  6. +43 −37 src/Menus.c
  7. +2 −2 src/Options.c
  8. +10 −9 src/PacketHandlers.c
  9. +11 −8 src/Platform.c
  10. +8 −5 src/Screens.c
  11. +3 −2 src/ServerConnection.c
  12. +9 −8 src/TexturePack.c
  13. +3 −4 src/Widgets.c
@@ -110,8 +110,8 @@ static void AsyncDownloader_Add(const String* url, bool priority, const String*
}
void AsyncDownloader_GetSkin(const String* id, const String* skinName) {
char urlBuffer[STRING_SIZE];
String url = String_FromArray(urlBuffer);
String url; char urlBuffer[STRING_SIZE];
String_InitArray(url, urlBuffer);
if (Utils_IsUrlPrefix(skinName, 0)) {
String_Copy(&url, skinName);
@@ -262,14 +262,14 @@ static struct ChatCommand* Commands_GetMatch(const String* cmdName) {
}
static void Commands_PrintDefault(void) {
char strBuffer[STRING_SIZE];
String str = String_FromArray(strBuffer);
String name;
struct ChatCommand* cmd;
int i;
String str; char strBuffer[STRING_SIZE];
Chat_AddRaw("&eList of client commands:");
String_InitArray(str, strBuffer);
for (i = 0; i < commands_count; i++) {
cmd = &commands_list[i];
name = String_FromReadonly(cmd->Name);
@@ -444,12 +444,13 @@ bool TabList_Remove(EntityID id) {
}
void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank) {
char playerNameBuffer[STRING_SIZE];
String playerName = String_FromArray(playerNameBuffer);
String_AppendColorless(&playerName, player);
String colorlessName; char colorlessBuffer[STRING_SIZE];
String_InitArray(colorlessName, colorlessBuffer);
String_AppendColorless(&colorlessName, player);
TabList_Remove(id);
TabList_PlayerNames[id] = TabList_Buffer.Count; StringsBuffer_Add(&TabList_Buffer, &playerName);
TabList_PlayerNames[id] = TabList_Buffer.Count; StringsBuffer_Add(&TabList_Buffer, &colorlessName);
TabList_ListNames[id] = TabList_Buffer.Count; StringsBuffer_Add(&TabList_Buffer, list);
TabList_GroupNames[id] = TabList_Buffer.Count; StringsBuffer_Add(&TabList_Buffer, group);
TabList_GroupRanks[id] = rank;
@@ -324,9 +324,10 @@ static void Game_OnLowVRAMDetected(void* obj) {
}
static void Game_ExtractInitialTexturePack(void) {
char texPackBuffer[STRING_SIZE];
String texPack = String_FromArray(texPackBuffer);
String texPack; char texPackBuffer[STRING_SIZE];
Options_Get(OPT_DEFAULT_TEX_PACK, &game_defTexPack, "default.zip");
String_InitArray(texPack, texPackBuffer);
String_AppendConst(&texPack, "default.zip");
TexturePack_ExtractZip_File(&texPack);
@@ -641,21 +642,20 @@ static void Game_DoScheduledTasks(double time) {
}
void Game_TakeScreenshot(void) {
char fileBuffer[STRING_SIZE];
String filename = String_FromArray(fileBuffer);
char pathBuffer[FILENAME_SIZE];
String path = String_FromArray(pathBuffer);
DateTime now;
struct Stream stream;
ReturnCode res;
String filename; char fileBuffer[STRING_SIZE];
String path; char pathBuffer[FILENAME_SIZE];
Game_ScreenshotRequested = false;
if (!Utils_EnsureDirectory("screenshots")) return;
DateTime_CurrentLocal(&now);
String_InitArray(filename, fileBuffer);
String_Format3(&filename, "screenshot_%p2-%p2-%p4", &now.Day, &now.Month, &now.Year);
String_Format3(&filename, "-%p2-%p2-%p2.png", &now.Hour, &now.Minute, &now.Second);
String_InitArray(path, pathBuffer);
String_Format2(&path, "screenshots%r%s", &Directory_Separator, &filename);
res = Stream_CreateFile(&stream, &path);
@@ -155,11 +155,11 @@ void KeyBind_Load(void) {
}
void KeyBind_Save(void) {
char nameBuffer[STRING_SIZE];
String name = String_FromArray(nameBuffer);
String value;
int i;
String name; char nameBuffer[STRING_SIZE];
String_InitArray(name, nameBuffer);
for (i = 0; i < KeyBind_Count; i++) {
name.length = 0;
String_Format1(&name, "key-%c", KeyBind_Names[i]);
@@ -382,17 +382,21 @@ static void ListScreen_Make(struct ListScreen* s, int i, int x, const String* te
}
static void ListScreen_UpdatePage(struct ListScreen* s) {
int start = LIST_SCREEN_ITEMS, end = s->Entries.Count - LIST_SCREEN_ITEMS;
s->Buttons[5].Disabled = s->CurrentIndex < start;
int beg, end;
int num, pages;
String page; char pageBuffer[STRING_SIZE];
beg = LIST_SCREEN_ITEMS;
end = s->Entries.Count - LIST_SCREEN_ITEMS;
s->Buttons[5].Disabled = s->CurrentIndex < beg;
s->Buttons[6].Disabled = s->CurrentIndex >= end;
if (Game_ClassicMode) return;
char pageBuffer[STRING_SIZE];
String page = String_FromArray(pageBuffer);
int num = (s->CurrentIndex / LIST_SCREEN_ITEMS) + 1;
int pages = Math_CeilDiv(s->Entries.Count, LIST_SCREEN_ITEMS);
if (Game_ClassicMode) return;
num = (s->CurrentIndex / LIST_SCREEN_ITEMS) + 1;
pages = Math_CeilDiv(s->Entries.Count, LIST_SCREEN_ITEMS);
if (pages == 0) pages = 1;
String_InitArray(page, pageBuffer);
String_Format2(&page, "&7Page %i of %i", &num, &pages);
TextWidget_Set(&s->Page, &page, &s->Font);
}
@@ -443,8 +447,7 @@ static void ListScreen_ContextRecreated(void* screen) {
ListScreen_Make(s, 5, -220, &lArrow, ListScreen_MoveBackwards);
ListScreen_Make(s, 6, 220, &rArrow, ListScreen_MoveForwards);
Menu_Back(s, 7, &s->Buttons[7], "Done", &s->Font, Menu_SwitchPause);
Menu_Back(s, 7, &s->Buttons[7], "Done", &s->Font, Menu_SwitchPause);
Menu_Label(s, 8, &s->Title, &s->TitleText, &s->Font,
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -155);
Menu_Label(s, 9, &s->Page, &String_Empty, &s->Font,
@@ -646,7 +649,7 @@ static void PauseScreen_ContextRecreated(void* screen) {
Menu_Button(s, 6, &s->Buttons[6], 120, &quitMsg, &s->TitleFont, PauseScreen_Quit,
ANCHOR_MAX, ANCHOR_MAX, 5, 5);
Menu_Back(s, 7, &s->Buttons[7], "Back to game", &s->TitleFont, PauseScreen_Game);
Menu_Back(s, 7, &s->Buttons[7], "Back to game",&s->TitleFont, PauseScreen_Game);
}
if (!ServerConnection_IsSinglePlayer) {
@@ -1106,10 +1109,10 @@ static void GenLevelScreen_ContextRecreated(void* screen) {
static String title = String_FromConst("Generate new level");
static String flat = String_FromConst("Flatgrass");
static String norm = String_FromConst("Vanilla");
struct GenLevelScreen* s = screen;
char tmpBuffer[STRING_SIZE];
String tmp = String_FromArray(tmpBuffer);
String tmp; char tmpBuffer[STRING_SIZE];
String_InitArray(tmp, tmpBuffer);
String_AppendInt(&tmp, World_Width);
GenLevelScreen_Input(s, 0, -80, false, &tmp);
@@ -1124,14 +1127,13 @@ static void GenLevelScreen_ContextRecreated(void* screen) {
GenLevelScreen_Label(s, 2, -150, 0, "Length:");
GenLevelScreen_Label(s, 3, -140, 40, "Seed:");
Menu_Label(s, 8, &s->Labels[4], &title, &s->TextFont,
Menu_Label(s, 8, &s->Labels[4], &title, &s->TextFont,
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -130);
Menu_Button(s, 9, &s->Buttons[0], 200, &flat, &s->TitleFont, GenLevelScreen_Flatgrass,
ANCHOR_CENTRE, ANCHOR_CENTRE, -120, 100);
Menu_Button(s, 10, &s->Buttons[1], 200, &norm, &s->TitleFont, GenLevelScreen_Notchy,
ANCHOR_CENTRE, ANCHOR_CENTRE, 120, 100);
Menu_Back(s, 11, &s->Buttons[2], "Cancel", &s->TitleFont, Menu_SwitchPause);
Menu_Back(s, 11, &s->Buttons[2], "Cancel", &s->TitleFont, Menu_SwitchPause);
}
struct ScreenVTABLE GenLevelScreen_VTABLE = {
@@ -1361,7 +1363,7 @@ static void SaveLevelScreen_ContextRecreated(void* screen) {
ANCHOR_CENTRE, ANCHOR_CENTRE, 110, 120);
Menu_Back(s, 3, &s->Buttons[2], "Cancel", &s->TitleFont, Menu_SwitchPause);
Menu_Input(s, 4, &s->Input, 500, &String_Empty, &s->TextFont, &validator,
Menu_Input(s, 4, &s->Input, 500, &String_Empty, &s->TextFont, &validator,
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -30);
s->Widgets[5] = NULL; /* description widget placeholder */
}
@@ -1416,10 +1418,10 @@ static void TexturePackScreen_FilterFiles(const String* path, void* obj) {
}
struct Screen* TexturePackScreen_MakeInstance(void) {
static String title = String_FromConst("Select a texture pack zip");
static String path = String_FromConst("texpacks");
static String title = String_FromConst("Select a texture pack zip");
static String path = String_FromConst("texpacks");
struct ListScreen* s = ListScreen_MakeInstance();
s->TitleText = title;
s->EntryClick = TexturePackScreen_EntryClick;
@@ -1533,19 +1535,20 @@ static void HotkeyListScreen_MakeFlags(int flags, String* str) {
}
struct Screen* HotkeyListScreen_MakeInstance(void) {
static String title = String_FromConst("Modify hotkeys");
static String empty = String_FromConst(LIST_SCREEN_EMPTY);
static String title = String_FromConst("Modify hotkeys");
static String empty = String_FromConst(LIST_SCREEN_EMPTY);
struct ListScreen* s = ListScreen_MakeInstance();
char textBuffer[STRING_SIZE];
String text = String_FromArray(textBuffer);
struct HotkeyData hKey;
int i;
String text; char textBuffer[STRING_SIZE];
struct ListScreen* s = ListScreen_MakeInstance();
String_InitArray(text, textBuffer);
s->TitleText = title;
s->EntryClick = HotkeyListScreen_EntryClick;
for (i = 0; i < HotkeysText.Count; i++) {
struct HotkeyData hKey = HotkeysList[i];
hKey = HotkeysList[i];
text.length = 0;
String_AppendConst(&text, Key_Names[hKey.Trigger]);
@@ -1928,9 +1931,10 @@ static void MenuOptionsScreen_SetFPS(const String* v) {
}
static void MenuOptionsScreen_Set(struct MenuOptionsScreen* s, int i, const String* text) {
char titleBuffer[STRING_SIZE];
String title = String_FromArray(titleBuffer);
String title; char titleBuffer[STRING_SIZE];
s->Buttons[i].SetValue(text);
String_InitArray(title, titleBuffer);
/* need to get btn again here (e.g. changing FPS invalidates all widgets) */
String_AppendConst(&title, s->Buttons[i].OptName);
@@ -2147,19 +2151,20 @@ static void MenuOptionsScreen_Enum(void* screen, void* widget) {
static void MenuOptionsScreen_Input(void* screen, void* widget) {
static String okay = String_FromConst("OK");
static String def = String_FromConst("Default value");
struct MenuOptionsScreen* s = screen;
struct ButtonWidget* btn = widget;
int i;
char valueBuffer[STRING_SIZE];
String value = String_FromArray(valueBuffer);
String value; char valueBuffer[STRING_SIZE];
s->ActiveI = Menu_Index(s, btn);
MenuOptionsScreen_FreeExtHelp(s);
MenuOptionsScreen_FreeInput(s);
btn->GetValue(&value);
String_InitArray(value, valueBuffer);
btn->GetValue(&value);
i = s->WidgetsCount;
Menu_Input(s, i - 1, &s->Input, 400, &value, &s->TextFont, &s->Validators[s->ActiveI],
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 110);
Menu_Button(s, i - 2, &s->OK, 40, &okay, &s->TitleFont, MenuOptionsScreen_OK,
@@ -2282,7 +2287,7 @@ static void ClassicOptionsScreen_ContextRecreated(void* screen) {
Menu_Button(s, 9, &s->Buttons[9], 400, &title, &s->TitleFont, Menu_SwitchKeysClassic,
ANCHOR_CENTRE, ANCHOR_MAX, 0, 95);
Menu_Back(s, 10, &s->Buttons[10], "Done", &s->TitleFont, Menu_SwitchPause);
Menu_Back(s, 10, &s->Buttons[10], "Done", &s->TitleFont, Menu_SwitchPause);
/* Disable certain options */
if (!ServerConnection_IsSinglePlayer) Menu_Remove(s, 3);
@@ -2435,9 +2440,10 @@ static void GraphicsOptionsScreen_SetShadows(const String* v) {
static void GraphicsOptionsScreen_GetMipmaps(String* v) { Menu_GetBool(v, Gfx_Mipmaps); }
static void GraphicsOptionsScreen_SetMipmaps(const String* v) {
String url; char urlBuffer[STRING_SIZE];
Gfx_Mipmaps = Menu_SetBool(v, OPT_MIPMAPS);
char urlBuffer[STRING_SIZE];
String url = String_FromArray(urlBuffer);
String_InitArray(url, urlBuffer);
String_Copy(&url, &World_TextureUrl);
/* always force a reload from cache */
@@ -2626,12 +2632,12 @@ static void HacksSettingsScreen_SetClipping(const String* v) {
static void HacksSettingsScreen_GetJump(String* v) { String_AppendFloat(v, LocalPlayer_JumpHeight(), 3); }
static void HacksSettingsScreen_SetJump(const String* v) {
struct PhysicsComp* physics = &LocalPlayer_Instance.Physics;
char strBuffer[STRING_SIZE];
String str = String_FromArray(strBuffer);
String str; char strBuffer[STRING_SIZE];
PhysicsComp_CalculateJumpVelocity(physics, Menu_Float(v));
physics->UserJumpVel = physics->JumpVel;
String_InitArray(str, strBuffer);
String_AppendFloat(&str, physics->JumpVel, 8);
Options_Set(OPT_JUMP_VELOCITY, &str);
}
@@ -198,16 +198,16 @@ void Options_Load(void) {
void Options_Save(void) {
static String path = String_FromConst("options.txt");
char lineBuffer[768];
String line = String_FromArray(lineBuffer);
String key, value;
struct Stream stream;
int i;
ReturnCode res;
String line; char lineBuffer[768];
res = Stream_CreateFile(&stream, &path);
if (res) { Chat_LogError2(res, "creating", &path); return; }
String_InitArray(line, lineBuffer);
for (i = 0; i < Options_Keys.Count; i++) {
key = StringsBuffer_UNSAFE_Get(&Options_Keys, i);
@@ -132,19 +132,20 @@ static void Handlers_RemoveTablistEntry(EntityID id) {
TabList_Remove(id);
}
static void Handlers_CheckName(EntityID id, String* displayName, String* skinName) {
String_StripCols(skinName);
Handlers_RemoveEndPlus(displayName);
Handlers_RemoveEndPlus(skinName);
static void Handlers_CheckName(EntityID id, String* name, String* skin) {
String colorlessName; char colorlessBuffer[STRING_SIZE];
String_StripCols(skin);
Handlers_RemoveEndPlus(name);
Handlers_RemoveEndPlus(skin);
/* Server is only allowed to change our own name colours. */
if (id != ENTITIES_SELF_ID) return;
char nameNoColsBuffer[STRING_SIZE];
String nameNoCols = String_FromArray(nameNoColsBuffer);
String_AppendColorless(&nameNoCols, displayName);
String_InitArray(colorlessName, colorlessBuffer);
String_AppendColorless(&colorlessName, name);
if (!String_Equals(&nameNoCols, &Game_Username)) { String_Copy(displayName, &Game_Username); }
if (!skinName->length) { String_Copy(skinName, &Game_Username); }
if (!String_Equals(&colorlessName, &Game_Username)) String_Copy(name, &Game_Username);
if (!skin->length) String_Copy(skin, &Game_Username);
}
static void Classic_ReadAbsoluteLocation(uint8_t* data, EntityID id, bool interpolate);
@@ -383,16 +383,19 @@ bool File_Exists(const String* path) {
}
ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallback callback) {
char pathBuffer[MAX_PATH + 10];
String path = String_FromArray(pathBuffer);
WCHAR str[300];
WIN32_FIND_DATAW entry;
HANDLE find;
ReturnCode res;
String path; char pathBuffer[MAX_PATH + 10];
/* Need to append \* to search for files in directory */
String_InitArray(path, pathBuffer);
String_Format1(&path, "%s\\*", dirPath);
WCHAR str[300]; Platform_ConvertString(str, &path);
WIN32_FIND_DATAW entry;
HANDLE find = FindFirstFileW(str, &entry);
Platform_ConvertString(str, &path);
find = FindFirstFileW(str, &entry);
if (find == INVALID_HANDLE_VALUE) return GetLastError();
ReturnCode res;
do {
path.length = 0;
@@ -513,7 +516,7 @@ bool File_Exists(const String* path) {
ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallback callback) {
char str[600];
DIR* dirPtr;
struct dirent* entry;
struct dirent* entry;
char* src;
int len, res;
char pathBuffer[FILENAME_SIZE];
Oops, something went wrong.

0 comments on commit 30bb86b

Please sign in to comment.