diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs
index 11545b2f2..b9e68640f 100644
--- a/ClassicalSharp/2D/Screens/ChatScreen.cs
+++ b/ClassicalSharp/2D/Screens/ChatScreen.cs
@@ -388,7 +388,7 @@ namespace ClassicalSharp.Gui.Screens {
public override bool HandlesKeyUp(Key key) {
if (!HandlesAllInput) return false;
- if (game.Server.SupportsFullCP437 && key == game.Input.Keys[KeyBind.ExtInput]) {
+ if (game.Server.SupportsFullCP437 && key == game.Mapping(KeyBind.ExtInput)) {
if (game.window.Focused) altText.SetActive(!altText.Active);
}
return true;
diff --git a/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs b/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs
index 27f7dc24a..b9a183d29 100644
--- a/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs
+++ b/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs
@@ -55,7 +55,7 @@ namespace ClassicalSharp.Gui.Screens {
string flags = HotkeyListScreen.MakeFlagsString(curHotkey.Flags);
if (curHotkey.Text == null) curHotkey.Text = "";
string staysOpen = curHotkey.StaysOpen ? "ON" : "OFF";
- bool existed = origHotkey.BaseKey != Key.None;
+ bool existed = origHotkey.Trigger != Key.None;
InputWidget input;
input = MenuInputWidget.Create(game, 500, 30, curHotkey.Text, textFont, new StringValidator())
@@ -63,7 +63,7 @@ namespace ClassicalSharp.Gui.Screens {
input.ShowCaret = true;
widgets = new Widget[] {
- Make(0, -150, "Key: " + curHotkey.BaseKey, BaseKeyClick),
+ Make(0, -150, "Key: " + curHotkey.Trigger, BaseKeyClick),
Make(0, -100, "Modifiers:" + flags, ModifiersClick),
input,
Make(-100, 10, "Input stays open: " + staysOpen, LeaveOpenClick),
@@ -94,25 +94,25 @@ namespace ClassicalSharp.Gui.Screens {
}
void SaveChangesClick(Game game, Widget widget) {
- if (origHotkey.BaseKey != Key.None) {
- HotkeyList.Remove(origHotkey.BaseKey, origHotkey.Flags);
- HotkeyList.UserRemovedHotkey(origHotkey.BaseKey, origHotkey.Flags);
+ if (origHotkey.Trigger != Key.None) {
+ HotkeyList.Remove(origHotkey.Trigger, origHotkey.Flags);
+ HotkeyList.UserRemovedHotkey(origHotkey.Trigger, origHotkey.Flags);
}
MenuInputWidget input = (MenuInputWidget)widgets[actionI];
- if (curHotkey.BaseKey != Key.None) {
- HotkeyList.Add(curHotkey.BaseKey, curHotkey.Flags,
+ if (curHotkey.Trigger != Key.None) {
+ HotkeyList.Add(curHotkey.Trigger, curHotkey.Flags,
input.Text.ToString(), curHotkey.StaysOpen);
- HotkeyList.UserAddedHotkey(curHotkey.BaseKey, curHotkey.Flags,
+ HotkeyList.UserAddedHotkey(curHotkey.Trigger, curHotkey.Flags,
curHotkey.StaysOpen, input.Text.ToString());
}
game.Gui.SetNewScreen(new HotkeyListScreen(game));
}
void RemoveHotkeyClick(Game game, Widget widget) {
- if (origHotkey.BaseKey != Key.None) {
- HotkeyList.Remove(origHotkey.BaseKey, origHotkey.Flags);
- HotkeyList.UserRemovedHotkey(origHotkey.BaseKey, origHotkey.Flags);
+ if (origHotkey.Trigger != Key.None) {
+ HotkeyList.Remove(origHotkey.Trigger, origHotkey.Flags);
+ HotkeyList.UserRemovedHotkey(origHotkey.Trigger, origHotkey.Flags);
}
game.Gui.SetNewScreen(new HotkeyListScreen(game));
}
@@ -131,8 +131,8 @@ namespace ClassicalSharp.Gui.Screens {
void FocusKeyDown(Key key) {
if (selectedI == keyI) {
- curHotkey.BaseKey = key;
- SetButton(keyI, "Key: " + curHotkey.BaseKey);
+ curHotkey.Trigger = key;
+ SetButton(keyI, "Key: " + curHotkey.Trigger);
supressNextPress = true;
} else if (selectedI == modifyI) {
if (key == Key.ControlLeft || key == Key.ControlRight) curHotkey.Flags |= 1;
@@ -151,7 +151,7 @@ namespace ClassicalSharp.Gui.Screens {
if (selectedI == -1) return;
if (selectedI == keyI) {
- SetButton(keyI, "Key: " + curHotkey.BaseKey);
+ SetButton(keyI, "Key: " + curHotkey.Trigger);
} else if (selectedI == modifyI) {
string flags = HotkeyListScreen.MakeFlagsString(curHotkey.Flags);
SetButton(modifyI, "Modifiers:" + flags);
diff --git a/ClassicalSharp/2D/Screens/Menu/HotkeyListScreen.cs b/ClassicalSharp/2D/Screens/Menu/HotkeyListScreen.cs
index 919f4d1a2..5d061cf61 100644
--- a/ClassicalSharp/2D/Screens/Menu/HotkeyListScreen.cs
+++ b/ClassicalSharp/2D/Screens/Menu/HotkeyListScreen.cs
@@ -17,7 +17,7 @@ namespace ClassicalSharp.Gui.Screens {
for (int i = 0; i < count; i++) {
Hotkey hKey = HotkeyList.Hotkeys[i];
- entries[i] = hKey.BaseKey + " |" + MakeFlagsString(hKey.Flags);
+ entries[i] = hKey.Trigger + " |" + MakeFlagsString(hKey.Flags);
}
for (int i = 0; i < items; i++)
entries[count + i] = empty;
@@ -51,7 +51,7 @@ namespace ClassicalSharp.Gui.Screens {
Key baseKey = (Key)Enum.Parse(typeof(Key), key);
for (int i = 0; i < HotkeyList.Hotkeys.Count; i++) {
Hotkey h = HotkeyList.Hotkeys[i];
- if (h.BaseKey == baseKey && h.Flags == flags) return h;
+ if (h.Trigger == baseKey && h.Flags == flags) return h;
}
return default(Hotkey);
}
diff --git a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs
index a8c8922dd..586d28b8f 100644
--- a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs
+++ b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs
@@ -68,7 +68,7 @@ namespace ClassicalSharp.Gui.Screens {
string ButtonText(int i) {
if (keyNames == null) keyNames = Enum.GetNames(typeof(Key));
- Key key = game.Input.Keys[binds[i]];
+ Key key = game.Mapping(binds[i]);
return desc[i] + ": " + keyNames[(int)key];
}
diff --git a/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs b/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs
index 0b06af440..22584fe42 100644
--- a/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs
+++ b/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs
@@ -109,7 +109,7 @@ namespace ClassicalSharp.Gui.Screens {
}
public override bool HandlesKeyDown(Key key) {
- if (key == game.Input.Keys[KeyBind.IDOverlay] || key == game.Input.Keys[KeyBind.PauseOrExit]) {
+ if (key == game.Mapping(KeyBind.IDOverlay) || key == game.Mapping(KeyBind.PauseOrExit)) {
game.Gui.DisposeOverlay(this);
return true;
}
diff --git a/ClassicalSharp/2D/Widgets/HotbarWidget.cs b/ClassicalSharp/2D/Widgets/HotbarWidget.cs
index 863031246..dda1101bb 100644
--- a/ClassicalSharp/2D/Widgets/HotbarWidget.cs
+++ b/ClassicalSharp/2D/Widgets/HotbarWidget.cs
@@ -109,7 +109,7 @@ namespace ClassicalSharp.Gui.Widgets {
// a) user presses alt then number
// b) user presses alt
// thus we only do case b) if case a) did not happen
- if (key != game.Input.Keys[KeyBind.HotbarSwitching]) return false;
+ if (key != game.Mapping(KeyBind.HotbarSwitching)) return false;
if (altHandled) { altHandled = false; return true; } // handled already
// Don't switch hotbar when alt+tab
diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs
index 20711466c..700f9ddc1 100644
--- a/ClassicalSharp/Entities/LocalPlayer.cs
+++ b/ClassicalSharp/Entities/LocalPlayer.cs
@@ -197,22 +197,21 @@ namespace ClassicalSharp.Entities {
}
public bool HandlesKey(Key key) {
- KeyMap keys = game.Input.Keys;
- if (key == keys[KeyBind.Respawn] && Hacks.CanRespawn) {
+ if (key == game.Mapping(KeyBind.Respawn) && Hacks.CanRespawn) {
DoRespawn();
- } else if (key == keys[KeyBind.SetSpawn] && Hacks.CanRespawn) {
+ } else if (key == game.Mapping(KeyBind.SetSpawn) && Hacks.CanRespawn) {
Spawn = Position;
Spawn.X = Utils.Floor(Spawn.X) + 0.5f;
Spawn.Z = Utils.Floor(Spawn.Z) + 0.5f;
SpawnRotY = RotY;
SpawnHeadX = HeadX;
DoRespawn();
- } else if (key == keys[KeyBind.Fly] && Hacks.CanFly && Hacks.Enabled) {
+ } else if (key == game.Mapping(KeyBind.Fly) && Hacks.CanFly && Hacks.Enabled) {
Hacks.Flying = !Hacks.Flying;
- } else if (key == keys[KeyBind.NoClip] && Hacks.CanNoclip && Hacks.Enabled && !Hacks.WOMStyleHacks) {
+ } else if (key == game.Mapping(KeyBind.NoClip) && Hacks.CanNoclip && Hacks.Enabled && !Hacks.WOMStyleHacks) {
if (Hacks.Noclip) Velocity.Y = 0;
Hacks.Noclip = !Hacks.Noclip;
- } else if (key == keys[KeyBind.Jump] && !onGround && !(Hacks.Flying || Hacks.Noclip)) {
+ } else if (key == game.Mapping(KeyBind.Jump) && !onGround && !(Hacks.Flying || Hacks.Noclip)) {
int maxJumps = Hacks.CanDoubleJump && Hacks.WOMStyleHacks ? 2 : 0;
maxJumps = Math.Max(maxJumps, Hacks.MaxJumps - 1);
diff --git a/ClassicalSharp/Game/GuiInterface.cs b/ClassicalSharp/Game/GuiInterface.cs
index 83a9384d8..c67719e90 100644
--- a/ClassicalSharp/Game/GuiInterface.cs
+++ b/ClassicalSharp/Game/GuiInterface.cs
@@ -124,18 +124,15 @@ namespace ClassicalSharp {
public void Render(double delta) {
game.Graphics.Mode2D(game.Width, game.Height);
- bool showHUD = activeScreen == null || !activeScreen.HidesHud;
+ bool showHUD = activeScreen == null || !activeScreen.HidesHud;
+ bool hudBefore = activeScreen == null || !activeScreen.RenderHudOver;
if (showHUD) statusScreen.Render(delta);
- if (showHUD && !activeScreen.RenderHudOver)
- hudScreen.Render(delta);
- if (activeScreen != null)
- activeScreen.Render(delta);
- if (showHUD && activeScreen.RenderHudOver)
- hudScreen.Render(delta);
+ if (showHUD && hudBefore) hudScreen.Render(delta);
+ if (activeScreen != null) activeScreen.Render(delta);
+ if (showHUD && !hudBefore) hudScreen.Render(delta);
- if (overlays.Count > 0)
- overlays[0].Render(delta);
+ if (overlays.Count > 0) { overlays[0].Render(delta); }
game.Graphics.Mode3D();
}
diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs
index a633c29b8..ee68fb2a5 100644
--- a/ClassicalSharp/Game/KeyMap.cs
+++ b/ClassicalSharp/Game/KeyMap.cs
@@ -20,16 +20,12 @@ namespace ClassicalSharp {
/// Maps a key binding to its actual key on the keyboard.
public class KeyMap {
- /// Gets the actual key on the keyboard that maps to the given key binding.
public Key this[KeyBind key] {
get { return keys[(int)key]; }
set { keys[(int)key] = value; SaveKeyBindings(); }
}
- /// Gets the default key on the keyboard that maps to the given key binding.
- public Key GetDefault(KeyBind key) {
- return defaultKeys[(int)key];
- }
+ public Key GetDefault(KeyBind key) { return defaultKeys[(int)key]; }
Key[] keys, defaultKeys;
diff --git a/ClassicalSharp/Hotkeys/HotkeyList.cs b/ClassicalSharp/Hotkeys/HotkeyList.cs
index 3194ce151..b0e7ebcc8 100644
--- a/ClassicalSharp/Hotkeys/HotkeyList.cs
+++ b/ClassicalSharp/Hotkeys/HotkeyList.cs
@@ -11,19 +11,15 @@ namespace ClassicalSharp.Hotkeys {
public static List Hotkeys = new List();
- /// Creates or updates an existing hotkey with the given baseKey and modifier flags.
- public static void Add(Key baseKey, byte flags, string text, bool more) {
- if (!UpdateExistingHotkey(baseKey, flags, text, more))
- AddNewHotkey(baseKey, flags, text, more);
+ public static void Add(Key trigger, byte flags, string text, bool more) {
+ if (!UpdateExistingHotkey(trigger, flags, text, more))
+ AddNewHotkey(trigger, flags, text, more);
}
- /// Removes an existing hotkey with the given baseKey and modifier flags.
- /// Whether a hotkey with the given baseKey and modifier flags was found
- /// and subsequently removed.
- public static bool Remove(Key baseKey, byte flags) {
+ public static bool Remove(Key trigger, byte flags) {
for (int i = 0; i < Hotkeys.Count; i++) {
Hotkey hKey = Hotkeys[i];
- if (hKey.BaseKey == baseKey && hKey.Flags == flags) {
+ if (hKey.Trigger == trigger && hKey.Flags == flags) {
Hotkeys.RemoveAt(i);
return true;
}
@@ -31,10 +27,10 @@ namespace ClassicalSharp.Hotkeys {
return false;
}
- static bool UpdateExistingHotkey(Key baseKey, byte flags, string text, bool more) {
+ static bool UpdateExistingHotkey(Key trigger, byte flags, string text, bool more) {
for (int i = 0; i < Hotkeys.Count; i++) {
Hotkey hKey = Hotkeys[i];
- if (hKey.BaseKey == baseKey && hKey.Flags == flags) {
+ if (hKey.Trigger == trigger && hKey.Flags == flags) {
hKey.Text = text;
hKey.StaysOpen = more;
Hotkeys[i] = hKey;
@@ -44,9 +40,9 @@ namespace ClassicalSharp.Hotkeys {
return false;
}
- static void AddNewHotkey(Key baseKey, byte flags, string text, bool more) {
+ static void AddNewHotkey(Key trigger, byte flags, string text, bool more) {
Hotkey hotkey;
- hotkey.BaseKey = baseKey;
+ hotkey.Trigger = trigger;
hotkey.Flags = flags;
hotkey.Text = text;
hotkey.StaysOpen = more;
@@ -68,7 +64,7 @@ namespace ClassicalSharp.Hotkeys {
for (int i = 0; i < Hotkeys.Count; i++) {
Hotkey hKey = Hotkeys[i];
- if ((hKey.Flags & flags) == hKey.Flags && hKey.BaseKey == key) {
+ if ((hKey.Flags & flags) == hKey.Flags && hKey.Trigger == key) {
text = hKey.Text;
moreInput = hKey.StaysOpen;
return true;
@@ -111,20 +107,20 @@ namespace ClassicalSharp.Hotkeys {
}
}
- public static void UserRemovedHotkey(Key baseKey, byte flags) {
- string key = "hotkey-" + baseKey + "&" + flags;
+ public static void UserRemovedHotkey(Key trigger, byte flags) {
+ string key = "hotkey-" + trigger + "&" + flags;
Options.Set(key, null);
}
- public static void UserAddedHotkey(Key baseKey, byte flags, bool moreInput, string text) {
- string key = "hotkey-" + baseKey + "&" + flags;
+ public static void UserAddedHotkey(Key trigger, byte flags, bool moreInput, string text) {
+ string key = "hotkey-" + trigger + "&" + flags;
string value = moreInput + "&" + text;
Options.Set(key, value);
}
}
public struct Hotkey {
- public Key BaseKey;
+ public Key Trigger;
public byte Flags; // ctrl 1, shift 2, alt 4
public bool StaysOpen; // whether the user is able to enter further input
public string Text; // contents to copy directly into the input bar
diff --git a/ClassicalSharp/Mode/Creative.cs b/ClassicalSharp/Mode/Creative.cs
index c085a5a01..a1cb3489e 100644
--- a/ClassicalSharp/Mode/Creative.cs
+++ b/ClassicalSharp/Mode/Creative.cs
@@ -13,10 +13,10 @@ namespace ClassicalSharp.Mode {
Game game;
public bool HandlesKeyDown(Key key) {
- if (key == game.Input.Keys[KeyBind.Inventory] && game.Gui.ActiveScreen == game.Gui.hudScreen) {
+ if (key == game.Mapping(KeyBind.Inventory) && game.Gui.ActiveScreen == game.Gui.hudScreen) {
game.Gui.SetNewScreen(new InventoryScreen(game));
return true;
- } else if (key == game.Input.Keys[KeyBind.DropBlock] && !game.ClassicMode) {
+ } else if (key == game.Mapping(KeyBind.DropBlock) && !game.ClassicMode) {
Inventory inv = game.Inventory;
if (inv.CanChangeSelected() && inv.Selected != Block.Air) {
// Don't assign Selected directly, because we don't want held block
diff --git a/src/Client/Deflate.c b/src/Client/Deflate.c
index 4a8533b14..ef5af3156 100644
--- a/src/Client/Deflate.c
+++ b/src/Client/Deflate.c
@@ -153,7 +153,7 @@ enum INFLATE_STATE_ {
};
/* Insert this byte into the bit buffer */
-#define Inflate_GetByte(state) state->AvailIn--; state->Bits |= (UInt32)(*state->NextIn) << state->NumBits; state->NextIn++; state->NumBits += 8;
+#define Inflate_GetByte(state) state->AvailIn--; state->Bits |= (UInt32)(*state->NextIn++) << state->NumBits; state->NumBits += 8;
/* Retrieves bits from the bit buffer */
#define Inflate_PeekBits(state, bits) (state->Bits & ((1UL << (bits)) - 1UL))
/* Consumes/eats up bits from the bit buffer */
diff --git a/src/Client/Gui.c b/src/Client/Gui.c
index 4c54fcedc..7de74b44a 100644
--- a/src/Client/Gui.c
+++ b/src/Client/Gui.c
@@ -210,21 +210,14 @@ void Gui_FreeOverlay(struct Screen* overlay) {
void Gui_RenderGui(Real64 delta) {
GfxCommon_Mode2D(Game_Width, Game_Height);
bool showHUD = Gui_Active == NULL || !Gui_Active->HidesHUD;
+ bool hudBefore = Gui_Active == NULL || !Gui_Active->RenderHUDOver;
if (showHUD) { Elem_Render(Gui_Status, delta); }
- if (showHUD && !Gui_Active->RenderHUDOver) {
- Elem_Render(Gui_HUD, delta);
- }
- if (Gui_Active) {
- Elem_Render(Gui_Active, delta);
- }
- if (showHUD && Gui_Active->RenderHUDOver) {
- Elem_Render(Gui_HUD, delta);
- }
+ if (showHUD && hudBefore) { Elem_Render(Gui_HUD, delta); }
+ if (Gui_Active) { Elem_Render(Gui_Active, delta); }
+ if (showHUD && !hudBefore) { Elem_Render(Gui_HUD, delta); }
- if (Gui_OverlaysCount > 0) {
- Elem_Render(Gui_Overlays[0], delta);
- }
+ if (Gui_OverlaysCount > 0) { Elem_Render(Gui_Overlays[0], delta); }
GfxCommon_Mode3D();
}
diff --git a/src/Client/Input.c b/src/Client/Input.c
index a14daff84..21636255e 100644
--- a/src/Client/Input.c
+++ b/src/Client/Input.c
@@ -214,9 +214,9 @@ static void Hotkeys_QuickSort(Int32 left, Int32 right) {
}
}
-void Hotkeys_AddNewHotkey(Key baseKey, UInt8 flags, STRING_PURE String* text, bool more) {
+void Hotkeys_AddNewHotkey(Key trigger, UInt8 flags, STRING_PURE String* text, bool more) {
struct HotkeyData hKey;
- hKey.BaseKey = baseKey;
+ hKey.Trigger = trigger;
hKey.Flags = flags;
hKey.TextIndex = HotkeysText.Count;
hKey.StaysOpen = more;
@@ -231,11 +231,11 @@ void Hotkeys_AddNewHotkey(Key baseKey, UInt8 flags, STRING_PURE String* text, bo
Hotkeys_QuickSort(0, HotkeysText.Count - 1);
}
-void Hotkeys_Add(Key baseKey, UInt8 flags, STRING_PURE String* text, bool more) {
+void Hotkeys_Add(Key trigger, UInt8 flags, STRING_PURE String* text, bool more) {
UInt32 i;
for (i = 0; i < HotkeysText.Count; i++) {
struct HotkeyData hKey = HotkeysList[i];
- if (hKey.BaseKey == baseKey && hKey.Flags == flags) {
+ if (hKey.Trigger == trigger && hKey.Flags == flags) {
StringsBuffer_Remove(&HotkeysText, hKey.TextIndex);
HotkeysList[i].StaysOpen = more;
HotkeysList[i].TextIndex = HotkeysText.Count;
@@ -243,14 +243,14 @@ void Hotkeys_Add(Key baseKey, UInt8 flags, STRING_PURE String* text, bool more)
return;
}
}
- Hotkeys_AddNewHotkey(baseKey, flags, text, more);
+ Hotkeys_AddNewHotkey(trigger, flags, text, more);
}
-bool Hotkeys_Remove(Key baseKey, UInt8 flags) {
+bool Hotkeys_Remove(Key trigger, UInt8 flags) {
UInt32 i, j;
for (i = 0; i < HotkeysText.Count; i++) {
struct HotkeyData hKey = HotkeysList[i];
- if (hKey.BaseKey == baseKey && hKey.Flags == flags) {
+ if (hKey.Trigger == trigger && hKey.Flags == flags) {
for (j = i + 1; j < HotkeysText.Count; j++) { HotkeysList[j - 1] = HotkeysList[j]; }
StringsBuffer_Remove(&HotkeysText, hKey.TextIndex);
HotkeysList[i].TextIndex = UInt32_MaxValue;
@@ -272,7 +272,7 @@ bool Hotkeys_IsHotkey(Key key, STRING_TRANSIENT String* text, bool* moreInput) {
UInt32 i;
for (i = 0; i < HotkeysText.Count; i++) {
struct HotkeyData hKey = HotkeysList[i];
- if ((hKey.Flags & flags) == hKey.Flags && hKey.BaseKey == key) {
+ if ((hKey.Flags & flags) == hKey.Flags && hKey.Trigger == key) {
String hkeyText = StringsBuffer_UNSAFE_Get(&HotkeysText, hKey.TextIndex);
String_AppendString(text, &hkeyText);
*moreInput = hKey.StaysOpen;
@@ -312,21 +312,21 @@ void Hotkeys_Init(void) {
}
}
-void Hotkeys_UserRemovedHotkey(Key baseKey, UInt8 flags) {
+void Hotkeys_UserRemovedHotkey(Key trigger, UInt8 flags) {
UChar keyBuffer[String_BufferSize(STRING_SIZE)];
String key = String_InitAndClearArray(keyBuffer);
- String_Format2(&key, "hotkey-%c&%b", Key_Names[baseKey], &flags);
+ String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags);
Options_Set(key.buffer, NULL);
}
-void Hotkeys_UserAddedHotkey(Key baseKey, UInt8 flags, bool moreInput, STRING_PURE String* text) {
+void Hotkeys_UserAddedHotkey(Key trigger, UInt8 flags, bool moreInput, STRING_PURE String* text) {
UChar keyBuffer[String_BufferSize(STRING_SIZE)];
String key = String_InitAndClearArray(keyBuffer);
UChar valueBuffer[String_BufferSize(STRING_SIZE * 2)];
String value = String_InitAndClearArray(valueBuffer);
- String_Format2(&key, "hotkey-%c&%b", Key_Names[baseKey], &flags);
+ String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags);
String_Format2(&value, "%t&%s", &moreInput, text);
Options_Set(key.buffer, &value);
}
diff --git a/src/Client/Input.h b/src/Client/Input.h
index 2f2621957..8c4e2ae46 100644
--- a/src/Client/Input.h
+++ b/src/Client/Input.h
@@ -120,7 +120,7 @@ void KeyBind_Init(void);
extern UInt8 Hotkeys_LWJGL[256];
struct HotkeyData {
UInt32 TextIndex; /* contents to copy directly into the input bar */
- UInt8 BaseKey; /* Member of Key enumeration */
+ UInt8 Trigger; /* Member of Key enumeration */
UInt8 Flags; /* ctrl 1, shift 2, alt 4 */
bool StaysOpen; /* whether the user is able to enter further input */
};
@@ -132,10 +132,10 @@ StringsBuffer HotkeysText;
#define HOTKEYS_FLAG_SHIFT 2
#define HOTKEYS_FLAG_ALT 4
-void Hotkeys_Add(Key baseKey, UInt8 flags, STRING_PURE String* text, bool more);
-bool Hotkeys_Remove(Key baseKey, UInt8 flags);
+void Hotkeys_Add(Key trigger, UInt8 flags, STRING_PURE String* text, bool more);
+bool Hotkeys_Remove(Key trigger, UInt8 flags);
bool Hotkeys_IsHotkey(Key key, STRING_TRANSIENT String* text, bool* moreInput);
void Hotkeys_Init(void);
-void Hotkeys_UserRemovedHotkey(Key baseKey, UInt8 flags);
-void Hotkeys_UserAddedHotkey(Key baseKey, UInt8 flags, bool moreInput, STRING_PURE String* text);
+void Hotkeys_UserRemovedHotkey(Key trigger, UInt8 flags);
+void Hotkeys_UserAddedHotkey(Key trigger, UInt8 flags, bool moreInput, STRING_PURE String* text);
#endif
diff --git a/src/Client/InputHandler.h b/src/Client/InputHandler.h
index 2a25d0007..d035502bf 100644
--- a/src/Client/InputHandler.h
+++ b/src/Client/InputHandler.h
@@ -1,6 +1,6 @@
#ifndef CC_INPUTHANDLER_H
#define CC_INPUTHANDLER_H
-#include "Typedefs.h"
+#include "Input.h"
/* Implements base handlers for mouse and keyboard input.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
diff --git a/src/Client/MapGenerator.c b/src/Client/MapGenerator.c
index 24f31e019..840a66286 100644
--- a/src/Client/MapGenerator.c
+++ b/src/Client/MapGenerator.c
@@ -504,83 +504,83 @@ void NotchyGen_Generate(void) {
/*########################################################################################################################*
*---------------------------------------------------Noise generation------------------------------------------------------*
*#########################################################################################################################*/
-void ImprovedNoise_Init(UInt8* p, Random* rnd) {
- /* shuffle randomly using fisher-yates */
- Int32 i;
- for (i = 0; i < 256; i++) { p[i] = i; }
-
- for (i = 0; i < 256; i++) {
- Int32 j = Random_Range(rnd, i, 256);
- UInt8 temp = p[i]; p[i] = p[j]; p[j] = temp;
- }
-
- for (i = 0; i < 256; i++) {
- p[i + 256] = p[i];
- }
-}
-
-Real32 ImprovedNoise_Calc(UInt8* p, Real32 x, Real32 y) {
- Int32 xFloor = x >= 0 ? (Int32)x : (Int32)x - 1;
- Int32 yFloor = y >= 0 ? (Int32)y : (Int32)y - 1;
- Int32 X = xFloor & 0xFF, Y = yFloor & 0xFF;
- x -= xFloor; y -= yFloor;
-
- Real32 u = x * x * x * (x * (x * 6 - 15) + 10); /* Fade(x) */
- Real32 v = y * y * y * (y * (y * 6 - 15) + 10); /* Fade(y) */
- Int32 A = p[X] + Y, B = p[X + 1] + Y;
-
- /* Normally, calculating Grad involves a function call. However, we can directly pack this table
- (since each value indicates either -1, 0 1) into a set of bit flags. This way we avoid needing
- to call another function that performs branching */
-#define xFlags 0x46552222
-#define yFlags 0x2222550A
-
- Int32 hash = (p[p[A]] & 0xF) << 1;
- Real32 g22 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[A], x, y) */
- hash = (p[p[B]] & 0xF) << 1;
- Real32 g12 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[B], x - 1, y) */
- Real32 c1 = g22 + u * (g12 - g22);
-
- hash = (p[p[A + 1]] & 0xF) << 1;
- Real32 g21 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[A + 1], x, y - 1) */
- hash = (p[p[B + 1]] & 0xF) << 1;
- Real32 g11 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[B + 1], x - 1, y - 1) */
- Real32 c2 = g21 + u * (g11 - g21);
-
- return c1 + v * (c2 - c1);
-}
-
-
-void OctaveNoise_Init(struct OctaveNoise* n, Random* rnd, Int32 octaves) {
- n->octaves = octaves;
- Int32 i;
- for (i = 0; i < octaves; i++) {
- ImprovedNoise_Init(n->p[i], rnd);
- }
-}
-
-Real32 OctaveNoise_Calc(struct OctaveNoise* n, Real32 x, Real32 y) {
- Real32 amplitude = 1, freq = 1;
- Real32 sum = 0;
- Int32 i;
-
- for (i = 0; i < n->octaves; i++) {
- sum += ImprovedNoise_Calc(n->p[i], x * freq, y * freq) * amplitude;
- amplitude *= 2.0f;
- freq *= 0.5f;
- }
- return sum;
-}
-
-
-void CombinedNoise_Init(struct CombinedNoise* n, Random* rnd, Int32 octaves1, Int32 octaves2) {
- OctaveNoise_Init(&n->noise1, rnd, octaves1);
- OctaveNoise_Init(&n->noise2, rnd, octaves2);
-}
-
-Real32 CombinedNoise_Calc(struct CombinedNoise* n, Real32 x, Real32 y) {
- Real32 offset = OctaveNoise_Calc(&n->noise2, x, y);
- return OctaveNoise_Calc(&n->noise1, x + offset, y);
+void ImprovedNoise_Init(UInt8* p, Random* rnd) {
+ /* shuffle randomly using fisher-yates */
+ Int32 i;
+ for (i = 0; i < 256; i++) { p[i] = i; }
+
+ for (i = 0; i < 256; i++) {
+ Int32 j = Random_Range(rnd, i, 256);
+ UInt8 temp = p[i]; p[i] = p[j]; p[j] = temp;
+ }
+
+ for (i = 0; i < 256; i++) {
+ p[i + 256] = p[i];
+ }
+}
+
+Real32 ImprovedNoise_Calc(UInt8* p, Real32 x, Real32 y) {
+ Int32 xFloor = x >= 0 ? (Int32)x : (Int32)x - 1;
+ Int32 yFloor = y >= 0 ? (Int32)y : (Int32)y - 1;
+ Int32 X = xFloor & 0xFF, Y = yFloor & 0xFF;
+ x -= xFloor; y -= yFloor;
+
+ Real32 u = x * x * x * (x * (x * 6 - 15) + 10); /* Fade(x) */
+ Real32 v = y * y * y * (y * (y * 6 - 15) + 10); /* Fade(y) */
+ Int32 A = p[X] + Y, B = p[X + 1] + Y;
+
+ /* Normally, calculating Grad involves a function call. However, we can directly pack this table
+ (since each value indicates either -1, 0 1) into a set of bit flags. This way we avoid needing
+ to call another function that performs branching */
+#define xFlags 0x46552222
+#define yFlags 0x2222550A
+
+ Int32 hash = (p[p[A]] & 0xF) << 1;
+ Real32 g22 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[A], x, y) */
+ hash = (p[p[B]] & 0xF) << 1;
+ Real32 g12 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[B], x - 1, y) */
+ Real32 c1 = g22 + u * (g12 - g22);
+
+ hash = (p[p[A + 1]] & 0xF) << 1;
+ Real32 g21 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[A + 1], x, y - 1) */
+ hash = (p[p[B + 1]] & 0xF) << 1;
+ Real32 g11 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[B + 1], x - 1, y - 1) */
+ Real32 c2 = g21 + u * (g11 - g21);
+
+ return c1 + v * (c2 - c1);
+}
+
+
+void OctaveNoise_Init(struct OctaveNoise* n, Random* rnd, Int32 octaves) {
+ n->octaves = octaves;
+ Int32 i;
+ for (i = 0; i < octaves; i++) {
+ ImprovedNoise_Init(n->p[i], rnd);
+ }
+}
+
+Real32 OctaveNoise_Calc(struct OctaveNoise* n, Real32 x, Real32 y) {
+ Real32 amplitude = 1, freq = 1;
+ Real32 sum = 0;
+ Int32 i;
+
+ for (i = 0; i < n->octaves; i++) {
+ sum += ImprovedNoise_Calc(n->p[i], x * freq, y * freq) * amplitude;
+ amplitude *= 2.0f;
+ freq *= 0.5f;
+ }
+ return sum;
+}
+
+
+void CombinedNoise_Init(struct CombinedNoise* n, Random* rnd, Int32 octaves1, Int32 octaves2) {
+ OctaveNoise_Init(&n->noise1, rnd, octaves1);
+ OctaveNoise_Init(&n->noise2, rnd, octaves2);
+}
+
+Real32 CombinedNoise_Calc(struct CombinedNoise* n, Real32 x, Real32 y) {
+ Real32 offset = OctaveNoise_Calc(&n->noise2, x, y);
+ return OctaveNoise_Calc(&n->noise1, x + offset, y);
}
diff --git a/src/Client/Menus.c b/src/Client/Menus.c
index 05e849e86..d0944f524 100644
--- a/src/Client/Menus.c
+++ b/src/Client/Menus.c
@@ -874,7 +874,7 @@ static void EditHotkeyScreen_MakeBaseKey(struct EditHotkeyScreen* screen, Widget
String text = String_InitAndClearArray(textBuffer);
String_AppendConst(&text, "Key: ");
- String_AppendConst(&text, Key_Names[screen->CurHotkey.BaseKey]);
+ String_AppendConst(&text, Key_Names[screen->CurHotkey.Trigger]);
EditHotkeyScreen_Make(screen, 0, 0, -150, &text, onClick);
}
@@ -931,16 +931,16 @@ static void EditHotkeyScreen_LeaveOpen(struct GuiElem* elem, struct GuiElem* wid
static void EditHotkeyScreen_SaveChanges(struct GuiElem* elem, struct GuiElem* widget) {
struct EditHotkeyScreen* screen = (struct EditHotkeyScreen*)elem;
struct HotkeyData hotkey = screen->OrigHotkey;
- if (hotkey.BaseKey != Key_None) {
- Hotkeys_Remove(hotkey.BaseKey, hotkey.Flags);
- Hotkeys_UserRemovedHotkey(hotkey.BaseKey, hotkey.Flags);
+ if (hotkey.Trigger != Key_None) {
+ Hotkeys_Remove(hotkey.Trigger, hotkey.Flags);
+ Hotkeys_UserRemovedHotkey(hotkey.Trigger, hotkey.Flags);
}
hotkey = screen->CurHotkey;
- if (hotkey.BaseKey != Key_None) {
+ if (hotkey.Trigger != Key_None) {
String text = screen->Input.Base.Text;
- Hotkeys_Add(hotkey.BaseKey, hotkey.Flags, &text, hotkey.StaysOpen);
- Hotkeys_UserAddedHotkey(hotkey.BaseKey, hotkey.Flags, hotkey.StaysOpen, &text);
+ Hotkeys_Add(hotkey.Trigger, hotkey.Flags, &text, hotkey.StaysOpen);
+ Hotkeys_UserAddedHotkey(hotkey.Trigger, hotkey.Flags, hotkey.StaysOpen, &text);
}
Gui_ReplaceActive(HotkeyListScreen_MakeInstance());
}
@@ -948,9 +948,9 @@ static void EditHotkeyScreen_SaveChanges(struct GuiElem* elem, struct GuiElem* w
static void EditHotkeyScreen_RemoveHotkey(struct GuiElem* elem, struct GuiElem* widget) {
struct EditHotkeyScreen* screen = (struct EditHotkeyScreen*)elem;
struct HotkeyData hotkey = screen->OrigHotkey;
- if (hotkey.BaseKey != Key_None) {
- Hotkeys_Remove(hotkey.BaseKey, hotkey.Flags);
- Hotkeys_UserRemovedHotkey(hotkey.BaseKey, hotkey.Flags);
+ if (hotkey.Trigger != Key_None) {
+ Hotkeys_Remove(hotkey.Trigger, hotkey.Flags);
+ Hotkeys_UserRemovedHotkey(hotkey.Trigger, hotkey.Flags);
}
Gui_ReplaceActive(HotkeyListScreen_MakeInstance());
}
@@ -990,7 +990,7 @@ static bool EditHotkeyScreen_HandlesKeyDown(struct GuiElem* elem, Key key) {
struct EditHotkeyScreen* screen = (struct EditHotkeyScreen*)elem;
if (screen->SelectedI >= 0) {
if (screen->SelectedI == 0) {
- screen->CurHotkey.BaseKey = key;
+ screen->CurHotkey.Trigger = key;
EditHotkeyScreen_MakeBaseKey(screen, EditHotkeyScreen_BaseKey);
} else if (screen->SelectedI == 1) {
if (key == Key_ControlLeft || key == Key_ControlRight) screen->CurHotkey.Flags |= HOTKEYS_FLAG_CTRL;
@@ -1018,7 +1018,7 @@ static void EditHotkeyScreen_ContextRecreated(void* obj) {
struct MenuInputValidator validator = MenuInputValidator_String();
String text = String_MakeNull();
- bool existed = screen->OrigHotkey.BaseKey != Key_None;
+ bool existed = screen->OrigHotkey.Trigger != Key_None;
if (existed) {
text = StringsBuffer_UNSAFE_Get(&HotkeysText, screen->OrigHotkey.TextIndex);
}
@@ -1540,7 +1540,7 @@ static void HotkeyListScreen_EntryClick(struct GuiElem* elem, struct GuiElem* w)
Int32 i;
for (i = 0; i < HotkeysText.Count; i++) {
struct HotkeyData h = HotkeysList[i];
- if (h.BaseKey == baseKey && h.Flags == flags) { original = h; break; }
+ if (h.Trigger == baseKey && h.Flags == flags) { original = h; break; }
}
Gui_ReplaceActive(EditHotkeyScreen_MakeInstance(original));
}
@@ -1558,7 +1558,7 @@ struct Screen* HotkeyListScreen_MakeInstance(void) {
struct HotkeyData hKey = HotkeysList[i];
String_Clear(&text);
- String_AppendConst(&text, Key_Names[hKey.BaseKey]);
+ String_AppendConst(&text, Key_Names[hKey.Trigger]);
String_AppendConst(&text, " |");
EditHotkeyScreen_MakeFlags(hKey.Flags, &text);
StringsBuffer_Add(&screen->Entries, &text);