Permalink
Browse files

Fix upper 8 bits blocks array not being freed on new map, oops. Fix t…

…urning off 'use custom blocks' then rejoining crashing the game.
  • Loading branch information...
UnknownShadow200 committed Oct 9, 2018
1 parent 9730242 commit c86db5a4547c00daa53e08e76436071b56dae1e6
Showing with 51 additions and 43 deletions.
  1. +16 −16 src/Block.c
  2. +10 −10 src/Input.c
  3. +7 −7 src/Input.h
  4. +9 −9 src/Menus.c
  5. +1 −0 src/ServerConnection.c
  6. +8 −1 src/World.c
View
@@ -467,20 +467,20 @@ static BlockID AutoRotate_Find(BlockID block, const String* name, const char* su
}
static BlockID AutoRotate_RotateCorner(BlockID block, const String* name) {
float offsetX = Game_SelectedPos.Intersect.X - (float)Game_SelectedPos.TranslatedPos.X;
float offsetZ = Game_SelectedPos.Intersect.Z - (float)Game_SelectedPos.TranslatedPos.Z;
float x = Game_SelectedPos.Intersect.X - (float)Game_SelectedPos.TranslatedPos.X;
float z = Game_SelectedPos.Intersect.Z - (float)Game_SelectedPos.TranslatedPos.Z;
if (offsetX < 0.5f && offsetZ < 0.5f) return AutoRotate_Find(block, name, "-NW");
if (offsetX >= 0.5f && offsetZ < 0.5f) return AutoRotate_Find(block, name, "-NE");
if (offsetX < 0.5f && offsetZ >= 0.5f) return AutoRotate_Find(block, name, "-SW");
if (offsetX >= 0.5f && offsetZ >= 0.5f) return AutoRotate_Find(block, name, "-SE");
if (x < 0.5f && z < 0.5f) return AutoRotate_Find(block, name, "-NW");
if (x >= 0.5f && z < 0.5f) return AutoRotate_Find(block, name, "-NE");
if (x < 0.5f && z >= 0.5f) return AutoRotate_Find(block, name, "-SW");
if (x >= 0.5f && z >= 0.5f) return AutoRotate_Find(block, name, "-SE");
return block;
}
static BlockID AutoRotate_RotateVertical(BlockID block, const String* name) {
float offsetY = Game_SelectedPos.Intersect.Y - (float)Game_SelectedPos.TranslatedPos.Y;
float y = Game_SelectedPos.Intersect.Y - (float)Game_SelectedPos.TranslatedPos.Y;
if (offsetY >= 0.5f) {
if (y >= 0.5f) {
return AutoRotate_Find(block, name, "-U");
} else {
return AutoRotate_Find(block, name, "-D");
@@ -490,10 +490,10 @@ static BlockID AutoRotate_RotateVertical(BlockID block, const String* name) {
static BlockID AutoRotate_RotateOther(BlockID block, const String* name) {
/* Fence type blocks */
if (AutoRotate_Find(BLOCK_AIR, name, "-UD") == BLOCK_AIR) {
float headY = LocalPlayer_Instance.Base.HeadY;
headY = LocationUpdate_Clamp(headY);
float yaw = LocalPlayer_Instance.Base.HeadY;
yaw = LocationUpdate_Clamp(yaw);
if (headY < 45.0f || (headY >= 135.0f && headY < 225.0f) || headY > 315.0f) {
if (yaw < 45.0f || (yaw >= 135.0f && yaw < 225.0f) || yaw > 315.0f) {
return AutoRotate_Find(block, name, "-WE");
} else {
return AutoRotate_Find(block, name, "-NS");
@@ -509,14 +509,14 @@ static BlockID AutoRotate_RotateOther(BlockID block, const String* name) {
}
static BlockID AutoRotate_RotateDirection(BlockID block, const String* name) {
float headY = LocalPlayer_Instance.Base.HeadY;
headY = LocationUpdate_Clamp(headY);
float yaw = LocalPlayer_Instance.Base.HeadY;
yaw = LocationUpdate_Clamp(yaw);
if (headY >= 45.0f && headY < 135.0f) {
if (yaw >= 45.0f && yaw < 135.0f) {
return AutoRotate_Find(block, name, "-E");
} else if (headY >= 135.0f && headY < 225.0f) {
} else if (yaw >= 135.0f && yaw < 225.0f) {
return AutoRotate_Find(block, name, "-S");
} else if (headY >= 225.0f && headY < 315.0f) {
} else if (yaw >= 225.0f && yaw < 315.0f) {
return AutoRotate_Find(block, name, "-W");
} else {
return AutoRotate_Find(block, name, "-N");
View
@@ -246,7 +246,7 @@ static void Hotkeys_RemoveText(int index) {
}
void Hotkeys_Add(Key trigger, uint8_t flags, const String* text, bool more) {
void Hotkeys_Add(Key trigger, int flags, const String* text, bool more) {
int i; struct HotkeyData* hKey = HotkeysList;
for (i = 0; i < HotkeysText.Count; i++, hKey++) {
@@ -261,7 +261,7 @@ void Hotkeys_Add(Key trigger, uint8_t flags, const String* text, bool more) {
Hotkeys_AddNewHotkey(trigger, flags, text, more);
}
bool Hotkeys_Remove(Key trigger, uint8_t flags) {
bool Hotkeys_Remove(Key trigger, int flags) {
int i, j; struct HotkeyData* hKey = HotkeysList;
for (i = 0; i < HotkeysText.Count; i++, hKey++) {
@@ -277,10 +277,10 @@ bool Hotkeys_Remove(Key trigger, uint8_t flags) {
}
int Hotkeys_FindPartial(Key key) {
uint8_t flags = 0;
if (Key_IsControlPressed()) flags |= HOTKEYS_FLAG_CTRL;
if (Key_IsShiftPressed()) flags |= HOTKEYS_FLAG_SHIFT;
if (Key_IsAltPressed()) flags |= HOTKEYS_FLAG_ALT;
int flags = 0;
if (Key_IsControlPressed()) flags |= HOTKEY_FLAG_CTRL;
if (Key_IsShiftPressed()) flags |= HOTKEY_FLAG_SHIFT;
if (Key_IsAltPressed()) flags |= HOTKEY_FLAG_ALT;
int i;
for (i = 0; i < HotkeysText.Count; i++) {
@@ -316,21 +316,21 @@ void Hotkeys_Init(void) {
}
}
void Hotkeys_UserRemovedHotkey(Key trigger, uint8_t flags) {
void Hotkeys_UserRemovedHotkey(Key trigger, int flags) {
char keyBuffer[STRING_SIZE];
String key = String_FromArray(keyBuffer);
String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags);
String_Format2(&key, "hotkey-%c&%i", Key_Names[trigger], &flags);
Options_SetString(&key, NULL);
}
void Hotkeys_UserAddedHotkey(Key trigger, uint8_t flags, bool moreInput, const String* text) {
void Hotkeys_UserAddedHotkey(Key trigger, int flags, bool moreInput, const String* text) {
char keyBuffer[STRING_SIZE];
String key = String_FromArray(keyBuffer);
char valueBuffer[STRING_SIZE * 2];
String value = String_FromArray(valueBuffer);
String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags);
String_Format2(&key, "hotkey-%c&%i", Key_Names[trigger], &flags);
String_Format2(&value, "%t&%s", &moreInput, text);
Options_SetString(&key, &value);
}
View
@@ -128,14 +128,14 @@ struct HotkeyData {
#define HOTKEYS_MAX_COUNT 256
struct HotkeyData HotkeysList[HOTKEYS_MAX_COUNT];
StringsBuffer HotkeysText;
#define HOTKEYS_FLAG_CTRL 1
#define HOTKEYS_FLAG_SHIFT 2
#define HOTKEYS_FLAG_ALT 4
enum HOTKEY_FLAGS {
HOTKEY_FLAG_CTRL = 1, HOTKEY_FLAG_SHIFT = 2, HOTKEY_FLAG_ALT = 4,
};
void Hotkeys_Add(Key trigger, uint8_t flags, const String* text, bool more);
bool Hotkeys_Remove(Key trigger, uint8_t flags);
void Hotkeys_Add(Key trigger, int flags, const String* text, bool more);
bool Hotkeys_Remove(Key trigger, int flags);
int Hotkeys_FindPartial(Key key);
void Hotkeys_Init(void);
void Hotkeys_UserRemovedHotkey(Key trigger, uint8_t flags);
void Hotkeys_UserAddedHotkey(Key trigger, uint8_t flags, bool moreInput, const String* text);
void Hotkeys_UserRemovedHotkey(Key trigger, int flags);
void Hotkeys_UserAddedHotkey(Key trigger, int flags, bool moreInput, const String* text);
#endif
View
@@ -919,9 +919,9 @@ static bool EditHotkeyScreen_KeyDown(void* screen, Key key) {
s->CurHotkey.Trigger = key;
EditHotkeyScreen_MakeBaseKey(s, EditHotkeyScreen_BaseKey);
} else if (s->SelectedI == 1) {
if (key == Key_ControlLeft || key == Key_ControlRight) s->CurHotkey.Flags |= HOTKEYS_FLAG_CTRL;
else if (key == Key_ShiftLeft || key == Key_ShiftRight) s->CurHotkey.Flags |= HOTKEYS_FLAG_SHIFT;
else if (key == Key_AltLeft || key == Key_AltRight) s->CurHotkey.Flags |= HOTKEYS_FLAG_ALT;
if (key == Key_ControlLeft || key == Key_ControlRight) s->CurHotkey.Flags |= HOTKEY_FLAG_CTRL;
else if (key == Key_ShiftLeft || key == Key_ShiftRight) s->CurHotkey.Flags |= HOTKEY_FLAG_SHIFT;
else if (key == Key_AltLeft || key == Key_AltRight) s->CurHotkey.Flags |= HOTKEY_FLAG_ALT;
else s->CurHotkey.Flags = 0;
EditHotkeyScreen_MakeModifiers(s, EditHotkeyScreen_Modifiers);
@@ -1498,9 +1498,9 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
String shift = String_FromConst("Shift");
String alt = String_FromConst("Alt");
if (String_ContainsString(&value, &ctrl)) flags |= HOTKEYS_FLAG_CTRL;
if (String_ContainsString(&value, &shift)) flags |= HOTKEYS_FLAG_SHIFT;
if (String_ContainsString(&value, &alt)) flags |= HOTKEYS_FLAG_ALT;
if (String_ContainsString(&value, &ctrl)) flags |= HOTKEY_FLAG_CTRL;
if (String_ContainsString(&value, &shift)) flags |= HOTKEY_FLAG_SHIFT;
if (String_ContainsString(&value, &alt)) flags |= HOTKEY_FLAG_ALT;
}
Key baseKey = Utils_ParseEnum(&key, Key_None, Key_Names, Key_Count);
@@ -1515,9 +1515,9 @@ static void HotkeyListScreen_EntryClick(void* screen, void* widget) {
}
static void HotkeyListScreen_MakeFlags(int flags, String* str) {
if (flags & HOTKEYS_FLAG_CTRL) String_AppendConst(str, " Ctrl");
if (flags & HOTKEYS_FLAG_SHIFT) String_AppendConst(str, " Shift");
if (flags & HOTKEYS_FLAG_ALT) String_AppendConst(str, " Alt");
if (flags & HOTKEY_FLAG_CTRL) String_AppendConst(str, " Ctrl");
if (flags & HOTKEY_FLAG_SHIFT) String_AppendConst(str, " Shift");
if (flags & HOTKEY_FLAG_ALT) String_AppendConst(str, " Alt");
}
struct Screen* HotkeyListScreen_MakeInstance(void) {
View
@@ -500,6 +500,7 @@ static void MPConnection_Reset(void) {
}
net_writeFailed = false;
Block_SetUsedCount(256);
Handlers_Reset();
ServerConnection_Free();
}
View
@@ -11,15 +11,22 @@
#include "Game.h"
void World_Reset(void) {
#ifdef EXTENDED_BLOCKS
if (World_Blocks != World_Blocks2) Mem_Free(World_Blocks2);
#endif
Mem_Free(World_Blocks);
World_Width = 0; World_Height = 0; World_Length = 0;
World_MaxX = 0; World_MaxY = 0; World_MaxZ = 0;
#ifdef EXTENDED_BLOCKS
World_Blocks2 = NULL;
#endif
World_Blocks = NULL; World_BlocksSize = 0;
Env_Reset();
Random rnd;
Random_InitFromCurrentTime(&rnd);
/* add a bit of randomness for uuid */
/* seed a bit more randomness for uuid */
int i;
for (i = 0; i < Game_Username.length; i++) {
Random_Next(&rnd, Game_Username.buffer[i] + 3);

0 comments on commit c86db5a

Please sign in to comment.