diff --git a/ClassicalSharp/2D/Screens/HudScreen.cs b/ClassicalSharp/2D/Screens/HudScreen.cs
index 251fe72d8..348f5ed75 100644
--- a/ClassicalSharp/2D/Screens/HudScreen.cs
+++ b/ClassicalSharp/2D/Screens/HudScreen.cs
@@ -28,7 +28,7 @@ namespace ClassicalSharp.Gui.Screens {
public override void Init() {
int size = game.Drawer2D.UseBitmappedChat ? 16 : 11;
playerFont = new Font(game.FontName, size);
- hotbar = game.Mode.MakeHotbar();
+ hotbar = new HotbarWidget(game);
hotbar.Init();
chat = new ChatScreen(game, this);
chat.Init();
diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj
index 83a89cafd..41247d31b 100644
--- a/ClassicalSharp/ClassicalSharp.csproj
+++ b/ClassicalSharp/ClassicalSharp.csproj
@@ -201,8 +201,6 @@
-
-
diff --git a/ClassicalSharp/Game/Game.Init.cs b/ClassicalSharp/Game/Game.Init.cs
index bbf1036e1..9c5491095 100644
--- a/ClassicalSharp/Game/Game.Init.cs
+++ b/ClassicalSharp/Game/Game.Init.cs
@@ -9,7 +9,6 @@ using ClassicalSharp.Entities;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Gui.Screens;
using ClassicalSharp.Map;
-using ClassicalSharp.Mode;
using ClassicalSharp.Model;
using ClassicalSharp.Network;
using ClassicalSharp.Particles;
@@ -53,10 +52,7 @@ namespace ClassicalSharp {
} else {
Mode = new CreativeGameMode();
}
- #else
- Mode = new CreativeGameMode();
#endif
- Components.Add(Mode);
Input = new InputHandler(this);
ParticleManager = new ParticleManager(); Components.Add(ParticleManager);
diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs
index 6db7bc37a..7b882fbb6 100644
--- a/ClassicalSharp/Game/Game.Properties.cs
+++ b/ClassicalSharp/Game/Game.Properties.cs
@@ -10,7 +10,6 @@ using ClassicalSharp.Entities;
using ClassicalSharp.Events;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Map;
-using ClassicalSharp.Mode;
using ClassicalSharp.Model;
using ClassicalSharp.Network;
using ClassicalSharp.Particles;
@@ -51,7 +50,6 @@ namespace ClassicalSharp {
public partial class Game {
public IGraphicsApi Graphics;
- public IGameMode Mode;
public World World;
public IServerConnection Server;
diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs
index 98a63fcc3..d3c8d2e61 100644
--- a/ClassicalSharp/Game/Game.cs
+++ b/ClassicalSharp/Game/Game.cs
@@ -313,7 +313,6 @@ namespace ClassicalSharp {
Graphics.BindIb(Graphics.defaultIb);
accumulator += delta;
Vertices = 0;
- Mode.BeginFrame(delta);
Camera.UpdateMouse();
if (!Focused && !Gui.ActiveScreen.HandlesAllInput) {
@@ -344,7 +343,6 @@ namespace ClassicalSharp {
Gui.Render(delta);
if (screenshotRequested) TakeScreenshot();
- Mode.EndFrame(delta);
Graphics.EndFrame(this);
LimitFPS();
}
diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs
index 881da75fc..88093bc5e 100644
--- a/ClassicalSharp/Game/InputHandler.cs
+++ b/ClassicalSharp/Game/InputHandler.cs
@@ -4,6 +4,7 @@ using ClassicalSharp.Entities;
using ClassicalSharp.Gui;
using ClassicalSharp.Gui.Screens;
using ClassicalSharp.Hotkeys;
+using ClassicalSharp.Map;
using OpenTK;
using OpenTK.Input;
@@ -162,7 +163,7 @@ namespace ClassicalSharp {
} else if (key == Keys[KeyBind.Screenshot]) {
game.screenshotRequested = true;
} else if (!game.Gui.ActiveScreen.HandlesKeyDown(key)) {
- if (!HandleBuiltinKey(key) && !game.LocalPlayer.HandlesKey(key))
+ if (!HandleCoreKey(key) && !game.LocalPlayer.HandlesKey(key))
HandleHotkey(key);
}
}
@@ -199,17 +200,9 @@ namespace ClassicalSharp {
return true;
}
- bool HandleBuiltinKey(Key key) {
+ bool HandleNonClassicKey(Key key) {
if (key == Keys[KeyBind.HideGui]) {
game.HideGui = !game.HideGui;
- } else if (key == Keys[KeyBind.HideFps]) {
- game.ShowFPS = !game.ShowFPS;
- } else if (key == Keys[KeyBind.Fullscreen]) {
- WindowState state = game.window.WindowState;
- if (state != WindowState.Minimized) {
- game.window.WindowState = state == WindowState.Fullscreen ?
- WindowState.Normal : WindowState.Fullscreen;
- }
} else if (key == Keys[KeyBind.SmoothCamera]) {
Toggle(key, ref game.SmoothCamera,
" &eSmooth camera is &aenabled",
@@ -224,16 +217,14 @@ namespace ClassicalSharp {
" &eAuto rotate is &cdisabled");
} else if (key == Keys[KeyBind.ThirdPerson]) {
game.CycleCamera();
- } else if (key == Keys[KeyBind.ToggleFog]) {
- int[] viewDists = game.UseClassicOptions ? classicViewDists : normViewDists;
- if (game.Input.ShiftDown) {
- CycleDistanceBackwards(viewDists);
- } else {
- CycleDistanceForwards(viewDists);
+ } else if (key == game.Mapping(KeyBind.DropBlock)) {
+ Inventory inv = game.Inventory;
+ if (inv.CanChangeSelected() && inv.Selected != Block.Air) {
+ // Don't assign Selected directly, because we don't want held block
+ // switching positions if they already have air in their inventory hotbar.
+ inv[inv.SelectedIndex] = Block.Air;
+ game.Events.RaiseHeldBlockChanged();
}
- } else if ((key == Keys[KeyBind.PauseOrExit] || key == Key.Pause) && !game.Gui.ActiveScreen.HandlesAllInput) {
- game.Gui.SetNewScreen(new PauseScreen(game));
- } else if (game.Mode.HandlesKeyDown(key)) {
} else if (key == Keys[KeyBind.IDOverlay]) {
if (game.Gui.overlays.Count > 0) return true;
game.Gui.ShowOverlay(new TexIdsOverlay(game), false);
@@ -246,6 +237,35 @@ namespace ClassicalSharp {
}
return true;
}
+
+ bool HandleCoreKey(Key key) {
+ if (key == Keys[KeyBind.HideFps]) {
+ game.ShowFPS = !game.ShowFPS;
+ } else if (key == Keys[KeyBind.Fullscreen]) {
+ WindowState state = game.window.WindowState;
+ if (state != WindowState.Minimized) {
+ game.window.WindowState = state == WindowState.Fullscreen ?
+ WindowState.Normal : WindowState.Fullscreen;
+ }
+ } else if (key == Keys[KeyBind.ToggleFog]) {
+ int[] viewDists = game.UseClassicOptions ? classicViewDists : normViewDists;
+ if (game.Input.ShiftDown) {
+ CycleDistanceBackwards(viewDists);
+ } else {
+ CycleDistanceForwards(viewDists);
+ }
+ } else if ((key == Keys[KeyBind.PauseOrExit] || key == Key.Pause) && !game.Gui.ActiveScreen.HandlesAllInput) {
+ game.Gui.SetNewScreen(new PauseScreen(game));
+ } else if (key == game.Mapping(KeyBind.Inventory) && game.Gui.ActiveScreen == game.Gui.hudScreen) {
+ game.Gui.SetNewScreen(new InventoryScreen(game));
+ } else if (key == Key.F5 && game.ClassicMode) {
+ Weather weather = game.World.Env.Weather == Weather.Sunny ? Weather.Rainy : Weather.Sunny;
+ game.World.Env.SetWeather(weather);
+ } else if (!game.ClassicMode) {
+ return HandleNonClassicKey(key);
+ }
+ return true;
+ }
void Toggle(Key key, ref bool target, string enableMsg, string disableMsg) {
target = !target;
diff --git a/ClassicalSharp/Game/Inventory.cs b/ClassicalSharp/Game/Inventory.cs
index d73aef989..2bc1e8f2f 100644
--- a/ClassicalSharp/Game/Inventory.cs
+++ b/ClassicalSharp/Game/Inventory.cs
@@ -10,6 +10,9 @@ namespace ClassicalSharp {
void IGameComponent.Init(Game game) {
this.game = game;
Reset(game);
+ this[0] = Block.Stone; this[1] = Block.Cobblestone; this[2] = Block.Brick;
+ this[3] = Block.Dirt; this[4] = Block.Wood; this[5] = Block.Log;
+ this[6] = Block.Leaves; this[7] = Block.Grass; this[8] = Block.Slab;
}
public void Reset(Game game) {
diff --git a/ClassicalSharp/Game/PickingHandler.cs b/ClassicalSharp/Game/PickingHandler.cs
index 6971421c8..7919821d0 100644
--- a/ClassicalSharp/Game/PickingHandler.cs
+++ b/ClassicalSharp/Game/PickingHandler.cs
@@ -36,15 +36,18 @@ namespace ClassicalSharp {
if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick) return;
if (left) {
- if (game.Mode.PickingLeft()) return;
+ // always play delete animations, even if we aren't picking a block.
+ game.HeldBlockRenderer.ClickAnim(true);
+
Vector3I pos = game.SelectedPos.BlockPos;
if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
BlockID old = game.World.GetBlock(pos);
if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) return;
- game.Mode.PickLeft(old);
+
+ game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
+ game.UserEvents.RaiseBlockChanged(pos, old, Block.Air);
} else if (right) {
- if (game.Mode.PickingRight()) return;
Vector3I pos = game.SelectedPos.TranslatedPos;
if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
@@ -58,13 +61,34 @@ namespace ClassicalSharp {
if (BlockInfo.Draw[block] == DrawType.Gas && BlockInfo.Draw[old] != DrawType.Gas) return;
if (!PickingHandler.CheckIsFree(game, block)) return;
- game.Mode.PickRight(old, block);
+ game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
+ game.UserEvents.RaiseBlockChanged(pos, old, block);
} else if (middle) {
Vector3I pos = game.SelectedPos.BlockPos;
- if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
+ if (!game.SelectedPos.Valid || !game.World.IsValidPos(pos)) return;
+ BlockID cur = game.World.GetBlock(pos);
- BlockID old = game.World.GetBlock(pos);
- game.Mode.PickMiddle(old);
+ if (BlockInfo.Draw[cur] == DrawType.Gas) return;
+ if (!(BlockInfo.CanPlace[cur] || BlockInfo.CanDelete[cur])) return;
+ if (!inv.CanChangeSelected() || inv.Selected == cur) return;
+
+ // Is the currently selected block an empty slot
+ if (inv[inv.SelectedIndex] == Block.Air) {
+ inv.Selected = cur; return;
+ }
+ // Try to replace same block
+ for (int i = 0; i < Inventory.BlocksPerRow; i++) {
+ if (inv[i] != cur) continue;
+ inv.SelectedIndex = i; return;
+ }
+ // Try to replace empty slots
+ for (int i = 0; i < Inventory.BlocksPerRow; i++) {
+ if (inv[i] != Block.Air) continue;
+ inv[i] = cur;
+ inv.SelectedIndex = i; return;
+ }
+ // Finally, replace the currently selected block.
+ inv.Selected = cur;
}
}
@@ -117,7 +141,7 @@ namespace ClassicalSharp {
}
// exclude exact map boundaries, otherwise player can get stuck outside map
- bool validPos =
+ bool validPos =
adjPos.X > 0 && adjPos.Y >= 0 && adjPos.Z > 0 &&
adjPos.X < game.World.Width && adjPos.Z < game.World.Length;
if (!validPos) return false;
@@ -133,7 +157,7 @@ namespace ClassicalSharp {
p.SetLocation(update, false);
return true;
}
-
+
static Predicate touchesAnySolid = IsSolidCollide;
static bool IsSolidCollide(BlockID b) { return BlockInfo.Collide[b] == CollideType.Solid; }
diff --git a/ClassicalSharp/Mode/Creative.cs b/ClassicalSharp/Mode/Creative.cs
deleted file mode 100644
index a1cb3489e..000000000
--- a/ClassicalSharp/Mode/Creative.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
-using System;
-using ClassicalSharp.Gui.Screens;
-using ClassicalSharp.Gui;
-using ClassicalSharp.Gui.Widgets;
-using OpenTK.Input;
-using BlockID = System.UInt16;
-
-namespace ClassicalSharp.Mode {
-
- public sealed class CreativeGameMode : IGameMode {
-
- Game game;
-
- public bool HandlesKeyDown(Key key) {
- if (key == game.Mapping(KeyBind.Inventory) && game.Gui.ActiveScreen == game.Gui.hudScreen) {
- game.Gui.SetNewScreen(new InventoryScreen(game));
- return true;
- } 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
- // switching positions if they already have air in their inventory hotbar.
- inv[inv.SelectedIndex] = Block.Air;
- game.Events.RaiseHeldBlockChanged();
- }
- return true;
- }
- return false;
- }
-
- public bool PickingLeft() {
- // always play delete animations, even if we aren't picking a block.
- game.HeldBlockRenderer.ClickAnim(true);
- return false;
- }
-
- public bool PickingRight() { return false; }
-
- public void PickLeft(BlockID old) {
- Vector3I pos = game.SelectedPos.BlockPos;
- game.UpdateBlock(pos.X, pos.Y, pos.Z, Block.Air);
- game.UserEvents.RaiseBlockChanged(pos, old, Block.Air);
- }
-
- public void PickMiddle(BlockID old) {
- Inventory inv = game.Inventory;
- if (BlockInfo.Draw[old] == DrawType.Gas) return;
- if (!(BlockInfo.CanPlace[old] || BlockInfo.CanDelete[old])) return;
- if (!inv.CanChangeSelected() || inv.Selected == old) return;
-
- // Is the currently selected block an empty slot
- if (inv[inv.SelectedIndex] == Block.Air) {
- inv.Selected = old; return;
- }
-
- // Try to replace same block
- for (int i = 0; i < Inventory.BlocksPerRow; i++) {
- if (inv[i] != old) continue;
- inv.SelectedIndex = i; return;
- }
-
- // Try to replace empty slots
- for (int i = 0; i < Inventory.BlocksPerRow; i++) {
- if (inv[i] != Block.Air) continue;
- inv[i] = old;
- inv.SelectedIndex = i; return;
- }
-
- // Finally, replace the currently selected block.
- inv.Selected = old;
- }
-
- public void PickRight(BlockID old, BlockID block) {
- Vector3I pos = game.SelectedPos.TranslatedPos;
- game.UpdateBlock(pos.X, pos.Y, pos.Z, block);
- game.UserEvents.RaiseBlockChanged(pos, old, block);
- }
-
- public Widget MakeHotbar() { return new HotbarWidget(game); }
-
- void IGameComponent.OnNewMapLoaded(Game game) { }
-
- void IGameComponent.Init(Game game) {
- this.game = game;
- Inventory inv = game.Inventory;
- inv[0] = Block.Stone; inv[1] = Block.Cobblestone; inv[2] = Block.Brick;
- inv[3] = Block.Dirt; inv[4] = Block.Wood; inv[5] = Block.Log;
- inv[6] = Block.Leaves; inv[7] = Block.Grass; inv[8] = Block.Slab;
- }
-
-
- void IGameComponent.Ready(Game game) { }
- void IGameComponent.Reset(Game game) { }
- void IGameComponent.OnNewMap(Game game) { }
- void IDisposable.Dispose() { }
-
- public void BeginFrame(double delta) { }
- public void EndFrame(double delta) { }
- }
-}
diff --git a/ClassicalSharp/Mode/IGameMode.cs b/ClassicalSharp/Mode/IGameMode.cs
deleted file mode 100644
index 6c3dfcef9..000000000
--- a/ClassicalSharp/Mode/IGameMode.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
-using System;
-using ClassicalSharp.Gui;
-using OpenTK.Input;
-using BlockID = System.UInt16;
-
-namespace ClassicalSharp.Mode {
-
- public interface IGameMode : IGameComponent {
-
- bool HandlesKeyDown(Key key);
- bool PickingLeft();
- bool PickingRight();
- void PickLeft(BlockID old);
- void PickMiddle(BlockID old);
- void PickRight(BlockID old, BlockID block);
- Widget MakeHotbar();
- void BeginFrame(double delta);
- void EndFrame(double delta);
- }
-}
diff --git a/Launcher2/LauncherWindow.cs b/Launcher2/LauncherWindow.cs
index b7f284b0e..9e0846a92 100644
--- a/Launcher2/LauncherWindow.cs
+++ b/Launcher2/LauncherWindow.cs
@@ -91,7 +91,7 @@ namespace Launcher {
void LoadFont() {
Options.Load();
- FontName = Options.Get("gui-fontname", "Arial");;
+ FontName = Options.Get("gui-fontname", "Arial");
try {
using (Font f = new Font(FontName, 16)) { }
} catch (Exception) {
diff --git a/src/Client/Animations.c b/src/Client/Animations.c
index 4112b58e5..899a39df5 100644
--- a/src/Client/Animations.c
+++ b/src/Client/Animations.c
@@ -1,6 +1,5 @@
#include "Animations.h"
#include "ExtMath.h"
-#include "Random.h"
#include "TerrainAtlas.h"
#include "Platform.h"
#include "Event.h"
diff --git a/src/Client/BlockPhysics.c b/src/Client/BlockPhysics.c
index c9511270f..50814206b 100644
--- a/src/Client/BlockPhysics.c
+++ b/src/Client/BlockPhysics.c
@@ -1,5 +1,4 @@
#include "BlockPhysics.h"
-#include "Random.h"
#include "World.h"
#include "Constants.h"
#include "Funcs.h"
diff --git a/src/Client/Builder.c b/src/Client/Builder.c
index 2da6ce187..076c5d8b7 100644
--- a/src/Client/Builder.c
+++ b/src/Client/Builder.c
@@ -8,7 +8,7 @@
#include "GraphicsAPI.h"
#include "ErrorHandler.h"
#include "Drawer.h"
-#include "Random.h"
+#include "ExtMath.h"
#include "ChunkUpdater.h"
#include "BlockID.h"
#include "Block.h"
diff --git a/src/Client/Client.vcxproj b/src/Client/Client.vcxproj
index b0d3ad3bd..fc88316a6 100644
--- a/src/Client/Client.vcxproj
+++ b/src/Client/Client.vcxproj
@@ -202,7 +202,6 @@
-
@@ -238,7 +237,6 @@
-
@@ -268,7 +266,6 @@
-
@@ -297,7 +294,6 @@
-
diff --git a/src/Client/Client.vcxproj.filters b/src/Client/Client.vcxproj.filters
index 9f64f1a86..b3f12c9bc 100644
--- a/src/Client/Client.vcxproj.filters
+++ b/src/Client/Client.vcxproj.filters
@@ -222,9 +222,6 @@
Header Files\Defines
-
- Header Files\Math
-
Header Files\2D\Utils
@@ -291,9 +288,6 @@
Header Files\2D
-
- Header Files\Game
-
Header Files\Game
@@ -392,9 +386,6 @@
Source Files\Rendering\Map
-
- Source Files\Math
-
Source Files\2D\Utils
@@ -482,9 +473,6 @@
Source Files\2D
-
- Source Files\Game
-
Source Files\Game
diff --git a/src/Client/ExtMath.c b/src/Client/ExtMath.c
index 82b4b4367..a2229bcc0 100644
--- a/src/Client/ExtMath.c
+++ b/src/Client/ExtMath.c
@@ -1,4 +1,6 @@
#include "ExtMath.h"
+#include "Platform.h"
+#include "Utils.h"
#include
/* TODO: Replace with own functions that don't rely on stdlib */
@@ -105,3 +107,48 @@ Real64 Math_FastExp(Real64 x) {
/* now need to work out exp(f) */
}
+
+
+/*########################################################################################################################*
+*--------------------------------------------------Random number generator------------------------------------------------*
+*#########################################################################################################################*/
+#define RND_VALUE (0x5DEECE66DULL)
+#define RND_MASK ((1ULL << 48) - 1)
+
+void Random_Init(Random* seed, Int32 seedInit) { Random_SetSeed(seed, seedInit); }
+void Random_InitFromCurrentTime(Random* rnd) {
+ DateTime now; Platform_CurrentUTCTime(&now);
+ Int64 totalMs = DateTime_TotalMs(&now);
+ Random_Init(rnd, (Int32)totalMs);
+}
+
+void Random_SetSeed(Random* seed, Int32 seedInit) {
+ *seed = (seedInit ^ RND_VALUE) & RND_MASK;
+}
+
+Int32 Random_Range(Random* seed, Int32 min, Int32 max) {
+ return min + Random_Next(seed, max - min);
+}
+
+Int32 Random_Next(Random* seed, Int32 n) {
+ if ((n & -n) == n) { /* i.e., n is a power of 2 */
+ *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
+ Int64 raw = (Int64)(*seed >> (48 - 31));
+ return (Int32)((n * raw) >> 31);
+ }
+
+ Int32 bits, val;
+ do {
+ *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
+ bits = (Int32)(*seed >> (48 - 31));
+ val = bits % n;
+ } while (bits - val + (n - 1) < 0);
+ return val;
+}
+
+Real32 Random_Float(Random* seed) {
+ *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
+ Int32 raw = (Int32)(*seed >> (48 - 24));
+ return raw / ((Real32)(1 << 24));
+}
+
diff --git a/src/Client/ExtMath.h b/src/Client/ExtMath.h
index bc45da101..67649afed 100644
--- a/src/Client/ExtMath.h
+++ b/src/Client/ExtMath.h
@@ -1,7 +1,8 @@
#ifndef CC_MATH_H
#define CC_MATH_H
#include "Typedefs.h"
-/* Simple math functions and constants.
+/* Simple math functions and constants. Also implements a RNG algorithm, based on
+ Java's implementation from https://docs.oracle.com/javase/7/docs/api/java/util/Random.html
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
@@ -40,8 +41,16 @@ Real32 Math_LerpAngle(Real32 leftAngle, Real32 rightAngle, Real32 t);
Int32 Math_NextPowOf2(Int32 value);
bool Math_IsPowOf2(Int32 value);
-
-#define Math_Clamp(value, min, max)\
-value = value < (min) ? (min) : value;\
-value = value > (max) ? (max) : value;
+#define Math_Clamp(val, min, max) val = val < (min) ? (min) : val; val = val > (max) ? (max) : val;
+
+typedef UInt64 Random;
+void Random_Init(Random* rnd, Int32 seed);
+void Random_InitFromCurrentTime(Random* rnd);
+void Random_SetSeed(Random* rnd, Int32 seed);
+/* Returns integer from min inclusive to max exclusive */
+Int32 Random_Range(Random* rnd, Int32 min, Int32 max);
+/* Returns integer from 0 inclusive to n exclusive */
+Int32 Random_Next(Random* rnd, Int32 n);
+/* Returns real from 0 inclusive to 1 exclusive */
+Real32 Random_Float(Random* rnd);
#endif
diff --git a/src/Client/Game.c b/src/Client/Game.c
index c289e1072..9da07064a 100644
--- a/src/Client/Game.c
+++ b/src/Client/Game.c
@@ -16,7 +16,6 @@
#include "Entity.h"
#include "Chat.h"
#include "Platform.h"
-#include "GameMode.h"
#include "Drawer2D.h"
#include "ModelCache.h"
#include "Particle.h"
@@ -443,7 +442,6 @@ void Game_Load(void) {
Entities_Init();
TextureCache_Init();
/* TODO: Survival vs Creative game mode */
- GameMode_MakeComponent(&comp); Game_AddComponent(&comp);
InputHandler_Init();
Particles_MakeComponent(&comp); Game_AddComponent(&comp);
@@ -687,7 +685,6 @@ static void Game_RenderFrame(Real64 delta) {
Gfx_BindIb(GfxCommon_defaultIb);
Game_Accumulator += delta;
Game_Vertices = 0;
- GameMode_BeginFrame(delta);
Camera_Active->UpdateMouse();
if (!Window_Focused && !Gui_GetActiveScreen()->HandlesAllInput) {
@@ -720,7 +717,6 @@ static void Game_RenderFrame(Real64 delta) {
Gui_RenderGui(delta);
if (Game_ScreenshotRequested) Game_TakeScreenshot();
- GameMode_EndFrame(delta);
Gfx_EndFrame();
Game_LimitFPS();
}
diff --git a/src/Client/GameMode.c b/src/Client/GameMode.c
deleted file mode 100644
index 3329bf5d2..000000000
--- a/src/Client/GameMode.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "GameMode.h"
-#include "Inventory.h"
-#include "Widgets.h"
-#include "Game.h"
-#include "Screens.h"
-#include "Block.h"
-#include "Event.h"
-#include "HeldBlockRenderer.h"
-#include "GameStructs.h"
-
-void GameMode_Init(void) {
- BlockID* inv = Inventory_Table;
- inv[0] = BLOCK_STONE; inv[1] = BLOCK_COBBLE; inv[2] = BLOCK_BRICK;
- inv[3] = BLOCK_DIRT; inv[4] = BLOCK_WOOD; inv[5] = BLOCK_LOG;
- inv[6] = BLOCK_LEAVES; inv[7] = BLOCK_GRASS; inv[8] = BLOCK_SLAB;
-}
-
-void GameMode_MakeComponent(struct IGameComponent* comp) {
- comp->Init = GameMode_Init;
-}
-
-bool GameMode_HandlesKeyDown(Key key) {
- struct Screen* activeScreen = Gui_GetActiveScreen();
- if (key == KeyBind_Get(KeyBind_Inventory) && activeScreen == Gui_HUD) {
- Gui_ReplaceActive(InventoryScreen_MakeInstance());
- return true;
- } else if (key == KeyBind_Get(KeyBind_DropBlock) && !Game_ClassicMode) {
- if (Inventory_CanChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) {
- /* Don't assign SelectedIndex directly, because we don't want held block
- switching positions if they already have air in their inventory hotbar. */
- Inventory_Set(Inventory_SelectedIndex, BLOCK_AIR);
- Event_RaiseVoid(&UserEvents_HeldBlockChanged);
- }
- return true;
- }
- return false;
-}
-
-bool GameMode_PickingLeft(void) {
- /* always play delete animations, even if we aren't picking a block */
- HeldBlockRenderer_ClickAnim(true);
- return false;
-}
-bool GameMode_PickingRight(void) { return false; }
-
-void GameMode_PickLeft(BlockID old) {
- Vector3I pos = Game_SelectedPos.BlockPos;
- Game_UpdateBlock(pos.X, pos.Y, pos.Z, BLOCK_AIR);
- Event_RaiseBlock(&UserEvents_BlockChanged, pos, old, BLOCK_AIR);
-}
-
-void GameMode_PickMiddle(BlockID old) {
- if (Block_Draw[old] == DRAW_GAS) return;
- if (!(Block_CanPlace[old] || Block_CanDelete[old])) return;
- if (!Inventory_CanChangeSelected() || Inventory_SelectedBlock == old) return;
- UInt32 i;
-
- /* Is the currently selected block an empty slot */
- if (Inventory_Get(Inventory_SelectedIndex) == BLOCK_AIR) {
- Inventory_SetSelectedBlock(old); return;
- }
-
- /* Try to replace same block */
- for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) {
- if (Inventory_Get(i) != old) continue;
- Inventory_SetSelectedIndex(i); return;
- }
-
- /* Try to replace empty slots */
- for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) {
- if (Inventory_Get(i) != BLOCK_AIR) continue;
- Inventory_Set(i, old);
- Inventory_SetSelectedIndex(i); return;
- }
-
- /* Finally, replace the currently selected block */
- Inventory_SetSelectedBlock(old);
-}
-
-void GameMode_PickRight(BlockID old, BlockID block) {
- Vector3I pos = Game_SelectedPos.TranslatedPos;
- Game_UpdateBlock(pos.X, pos.Y, pos.Z, block);
- Event_RaiseBlock(&UserEvents_BlockChanged, pos, old, block);
-}
-
-struct HotbarWidget GameMode_Hotbar;
-struct HotbarWidget* GameMode_MakeHotbar(void) { return &GameMode_Hotbar; }
-void GameMode_BeginFrame(Real64 delta) { }
-void GameMode_EndFrame(Real64 delta) { }
diff --git a/src/Client/GameMode.h b/src/Client/GameMode.h
deleted file mode 100644
index 935d0d762..000000000
--- a/src/Client/GameMode.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef CC_GAMEMODE_H
-#define CC_GAMEMODE_H
-#include "Input.h"
-/* Implements behaviour specific for creative / survival game modes.
- Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
-*/
-
-struct IGameComponent;
-struct HorbarWidget;
-void GameMode_MakeComponent(struct IGameComponent* comp);
-
-bool GameMode_HandlesKeyDown(Key key);
-bool GameMode_PickingLeft(void);
-bool GameMode_PickingRight(void);
-void GameMode_PickLeft(BlockID old);
-void GameMode_PickMiddle(BlockID old);
-void GameMode_PickRight(BlockID old, BlockID block);
-struct HotbarWidget* GameMode_MakeHotbar(void);
-void GameMode_BeginFrame(Real64 delta);
-void GameMode_EndFrame(Real64 delta);
-#endif
diff --git a/src/Client/GraphicsCommon.h b/src/Client/GraphicsCommon.h
index d511cbfd5..6e450299d 100644
--- a/src/Client/GraphicsCommon.h
+++ b/src/Client/GraphicsCommon.h
@@ -21,12 +21,12 @@ void GfxCommon_UpdateDynamicVb_Lines(GfxResourceID vb, void* vertices, Int32 vCo
This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. */
void GfxCommon_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, Int32 vCount);
-GfxResourceID GfxCommon_quadVb;
+GfxResourceID GfxCommon_quadVb, GfxCommon_texVb;
void GfxCommon_Draw2DFlat(Int32 x, Int32 y, Int32 width, Int32 height, PackedCol col);
void GfxCommon_Draw2DGradient(Int32 x, Int32 y, Int32 width, Int32 height, PackedCol top, PackedCol bottom);
-GfxResourceID GfxCommon_texVb;
void GfxCommon_Draw2DTexture(struct Texture* tex, PackedCol col);
void GfxCommon_Make2DQuad(struct Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices);
+
void GfxCommon_Mode2D(Int32 width, Int32 height);
void GfxCommon_Mode3D(void);
diff --git a/src/Client/InputHandler.c b/src/Client/InputHandler.c
index 0df528050..4a44f70bc 100644
--- a/src/Client/InputHandler.c
+++ b/src/Client/InputHandler.c
@@ -1,6 +1,7 @@
#include "InputHandler.h"
#include "Utils.h"
#include "ServerConnection.h"
+#include "HeldBlockRenderer.h"
#include "Game.h"
#include "Platform.h"
#include "ExtMath.h"
@@ -8,7 +9,6 @@
#include "Inventory.h"
#include "World.h"
#include "Event.h"
-#include "GameMode.h"
#include "Window.h"
#include "Entity.h"
#include "Chat.h"
@@ -139,44 +139,18 @@ static bool InputHandler_DoFovZoom(Real32 deltaPrecise) {
return InputHandler_SetFOV((Int32)input_fovIndex, true);
}
-static bool InputHandler_HandleCoreKey(Key key) {
+static bool InputHandler_HandleNonClassicKey(Key key) {
if (key == KeyBind_Get(KeyBind_HideGui)) {
Game_HideGui = !Game_HideGui;
- } else if (key == KeyBind_Get(KeyBind_HideFps)) {
- Game_ShowFPS = !Game_ShowFPS;
- } else if (key == KeyBind_Get(KeyBind_Fullscreen)) {
- UInt8 state = Window_GetWindowState();
- if (state != WINDOW_STATE_MAXIMISED) {
- bool fullscreen = state == WINDOW_STATE_FULLSCREEN;
- Window_SetWindowState(fullscreen ? WINDOW_STATE_NORMAL : WINDOW_STATE_FULLSCREEN);
- }
- } else if (key == KeyBind_Get(KeyBind_SmoothCamera)) {
- InputHandler_Toggle(key, &Game_SmoothCamera,
- " &eSmooth camera is &aenabled",
- " &eSmooth camera is &cdisabled");
- } else if (key == KeyBind_Get(KeyBind_AxisLines)) {
- InputHandler_Toggle(key, &Game_ShowAxisLines,
- " &eAxis lines (&4X&e, &2Y&e, &1Z&e) now show",
- " &eAxis lines no longer show");
- } else if (key == KeyBind_Get(KeyBind_Autorotate)) {
- InputHandler_Toggle(key, &Game_AutoRotate,
- " &eAuto rotate is &aenabled",
- " &eAuto rotate is &cdisabled");
} else if (key == KeyBind_Get(KeyBind_ThirdPerson)) {
Camera_CycleActive();
- } else if (key == KeyBind_Get(KeyBind_ToggleFog)) {
- Int32* viewDists = Game_UseClassicOptions ? input_classicViewDists : input_normViewDists;
- Int32 count = Game_UseClassicOptions ? Array_Elems(input_classicViewDists) : Array_Elems(input_normViewDists);
-
- if (Key_IsShiftPressed()) {
- InputHandler_CycleDistanceBackwards(viewDists, count);
- } else {
- InputHandler_CycleDistanceForwards(viewDists, count);
+ } else if (key == KeyBind_Get(KeyBind_DropBlock)) {
+ if (Inventory_CanChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) {
+ /* Don't assign SelectedIndex directly, because we don't want held block
+ switching positions if they already have air in their inventory hotbar. */
+ Inventory_Set(Inventory_SelectedIndex, BLOCK_AIR);
+ Event_RaiseVoid(&UserEvents_HeldBlockChanged);
}
- } else if ((key == KeyBind_Get(KeyBind_PauseOrExit) || key == Key_Pause) && !Gui_GetActiveScreen()->HandlesAllInput) {
- Gui_FreeActive();
- Gui_SetActive(PauseScreen_MakeInstance());
- } else if (GameMode_HandlesKeyDown(key)) {
} else if (key == KeyBind_Get(KeyBind_IDOverlay)) {
if (Gui_OverlaysCount > 0) return true;
struct Screen* overlay = TexIdsOverlay_MakeInstance();
@@ -191,6 +165,40 @@ static bool InputHandler_HandleCoreKey(Key key) {
return true;
}
+static bool InputHandler_HandleCoreKey(Key key) {
+ struct Screen* activeScreen = Gui_GetActiveScreen();
+
+ if (key == KeyBind_Get(KeyBind_HideFps)) {
+ Game_ShowFPS = !Game_ShowFPS;
+ } else if (key == KeyBind_Get(KeyBind_Fullscreen)) {
+ UInt8 state = Window_GetWindowState();
+ if (state != WINDOW_STATE_MAXIMISED) {
+ bool fullscreen = state == WINDOW_STATE_FULLSCREEN;
+ Window_SetWindowState(fullscreen ? WINDOW_STATE_NORMAL : WINDOW_STATE_FULLSCREEN);
+ }
+ } else if (key == KeyBind_Get(KeyBind_ToggleFog)) {
+ Int32* viewDists = Game_UseClassicOptions ? input_classicViewDists : input_normViewDists;
+ Int32 count = Game_UseClassicOptions ? Array_Elems(input_classicViewDists) : Array_Elems(input_normViewDists);
+
+ if (Key_IsShiftPressed()) {
+ InputHandler_CycleDistanceBackwards(viewDists, count);
+ } else {
+ InputHandler_CycleDistanceForwards(viewDists, count);
+ }
+ } else if ((key == KeyBind_Get(KeyBind_PauseOrExit) || key == Key_Pause) && !activeScreen->HandlesAllInput) {
+ Gui_FreeActive();
+ Gui_SetActive(PauseScreen_MakeInstance());
+ } else if (key == KeyBind_Get(KeyBind_Inventory) && activeScreen == Gui_HUD) {
+ Gui_ReplaceActive(InventoryScreen_MakeInstance());
+ } else if (key == Key_F5 && Game_ClassicMode) {
+ Int32 weather = WorldEnv_Weather == WEATHER_SUNNY ? WEATHER_RAINY : WEATHER_SUNNY;
+ WorldEnv_SetWeather(weather);
+ } else if (!Game_ClassicMode) {
+ return InputHandler_HandleNonClassicKey(key);
+ }
+ return true;
+}
+
static bool InputHandler_TouchesSolid(BlockID b) { return Block_Collide[b] == COLLIDE_SOLID; }
static bool InputHandler_PushbackPlace(struct AABB* blockBB) {
struct Entity* p = &LocalPlayer_Instance.Base;
@@ -298,15 +306,18 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right)
if (Gui_GetActiveScreen()->HandlesAllInput || !Inventory_CanPick) return;
if (left) {
- if (GameMode_PickingLeft()) return;
+ /* always play delete animations, even if we aren't picking a block */
+ HeldBlockRenderer_ClickAnim(true);
+
Vector3I pos = Game_SelectedPos.BlockPos;
if (!Game_SelectedPos.Valid || !World_IsValidPos_3I(pos)) return;
BlockID old = World_GetBlock_3I(pos);
if (Block_Draw[old] == DRAW_GAS || !Block_CanDelete[old]) return;
- GameMode_PickLeft(old);
+
+ Game_UpdateBlock(pos.X, pos.Y, pos.Z, BLOCK_AIR);
+ Event_RaiseBlock(&UserEvents_BlockChanged, pos, old, BLOCK_AIR);
} else if (right) {
- if (GameMode_PickingRight()) return;
Vector3I pos = Game_SelectedPos.TranslatedPos;
if (!Game_SelectedPos.Valid || !World_IsValidPos_3I(pos)) return;
@@ -317,15 +328,40 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right)
if (Game_CanPick(old) || !Block_CanPlace[block]) return;
/* air-ish blocks can only replace over other air-ish blocks */
if (Block_Draw[block] == DRAW_GAS && Block_Draw[old] != DRAW_GAS) return;
-
if (!InputHandler_CheckIsFree(block)) return;
- GameMode_PickRight(old, block);
+
+ Game_UpdateBlock(pos.X, pos.Y, pos.Z, block);
+ Event_RaiseBlock(&UserEvents_BlockChanged, pos, old, block);
} else if (middle) {
Vector3I pos = Game_SelectedPos.BlockPos;
if (!Game_SelectedPos.Valid || !World_IsValidPos_3I(pos)) return;
- BlockID old = World_GetBlock_3I(pos);
- GameMode_PickMiddle(old);
+ BlockID cur = World_GetBlock_3I(pos);
+ if (Block_Draw[cur] == DRAW_GAS) return;
+ if (!(Block_CanPlace[cur] || Block_CanDelete[cur])) return;
+ if (!Inventory_CanChangeSelected() || Inventory_SelectedBlock == cur) return;
+ UInt32 i;
+
+ /* Is the currently selected block an empty slot */
+ if (Inventory_Get(Inventory_SelectedIndex) == BLOCK_AIR) {
+ Inventory_SetSelectedBlock(cur); return;
+ }
+
+ /* Try to replace same block */
+ for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) {
+ if (Inventory_Get(i) != cur) continue;
+ Inventory_SetSelectedIndex(i); return;
+ }
+
+ /* Try to replace empty slots */
+ for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) {
+ if (Inventory_Get(i) != BLOCK_AIR) continue;
+ Inventory_Set(i, cur);
+ Inventory_SetSelectedIndex(i); return;
+ }
+
+ /* Finally, replace the currently selected block */
+ Inventory_SetSelectedBlock(cur);
}
}
diff --git a/src/Client/Inventory.c b/src/Client/Inventory.c
index ae46b9821..d6fd678f9 100644
--- a/src/Client/Inventory.c
+++ b/src/Client/Inventory.c
@@ -95,13 +95,21 @@ void Inventory_Remove(BlockID block) {
}
}
-static void Inventory_ResetState(void) {
+static void Inventory_Reset(void) {
Inventory_SetDefaultMapping();
Inventory_CanChangeHeldBlock = true;
Inventory_CanPick = true;
}
-void Inventory_MakeComponent(struct IGameComponent* comp) {
- comp->Init = Inventory_ResetState;
- comp->Reset = Inventory_ResetState;
+static void Inventory_Init(void) {
+ Inventory_Reset();
+ BlockID* inv = Inventory_Table;
+ inv[0] = BLOCK_STONE; inv[1] = BLOCK_COBBLE; inv[2] = BLOCK_BRICK;
+ inv[3] = BLOCK_DIRT; inv[4] = BLOCK_WOOD; inv[5] = BLOCK_LOG;
+ inv[6] = BLOCK_LEAVES; inv[7] = BLOCK_GRASS; inv[8] = BLOCK_SLAB;
+}
+
+void Inventory_MakeComponent(struct IGameComponent* comp) {
+ comp->Init = Inventory_Init;
+ comp->Reset = Inventory_Reset;
}
diff --git a/src/Client/MapGenerator.h b/src/Client/MapGenerator.h
index 23ba4dce3..3de2e774c 100644
--- a/src/Client/MapGenerator.h
+++ b/src/Client/MapGenerator.h
@@ -1,7 +1,7 @@
#ifndef CC_MAP_GEN_H
#define CC_MAP_GEN_H
#include "String.h"
-#include "Random.h"
+#include "ExtMath.h"
#include "Vectors.h"
/* Implements flatgrass map generator, and original classic vanilla map generation (with perlin noise)
Based on: https://github.com/UnknownShadow200/ClassicalSharp/wiki/Minecraft-Classic-map-generation-algorithm
@@ -20,16 +20,16 @@ BlockID* Gen_Blocks;
void FlatgrassGen_Generate(void);
void NotchyGen_Generate(void);
-#define NOISE_TABLE_SIZE 512
-void ImprovedNoise_Init(UInt8* p, Random* rnd);
-Real32 ImprovedNoise_Calc(UInt8* p, Real32 x, Real32 y);
-
-struct OctaveNoise { UInt8 p[8][NOISE_TABLE_SIZE]; Int32 octaves; };
-void OctaveNoise_Init(struct OctaveNoise* n, Random* rnd, Int32 octaves);
-Real32 OctaveNoise_Calc(struct OctaveNoise* n, Real32 x, Real32 y);
-
-struct CombinedNoise { struct OctaveNoise noise1, noise2; };
-void CombinedNoise_Init(struct CombinedNoise* n, Random* rnd, Int32 octaves1, Int32 octaves2);
+#define NOISE_TABLE_SIZE 512
+void ImprovedNoise_Init(UInt8* p, Random* rnd);
+Real32 ImprovedNoise_Calc(UInt8* p, Real32 x, Real32 y);
+
+struct OctaveNoise { UInt8 p[8][NOISE_TABLE_SIZE]; Int32 octaves; };
+void OctaveNoise_Init(struct OctaveNoise* n, Random* rnd, Int32 octaves);
+Real32 OctaveNoise_Calc(struct OctaveNoise* n, Real32 x, Real32 y);
+
+struct CombinedNoise { struct OctaveNoise noise1, noise2; };
+void CombinedNoise_Init(struct CombinedNoise* n, Random* rnd, Int32 octaves1, Int32 octaves2);
Real32 CombinedNoise_Calc(struct CombinedNoise* n, Real32 x, Real32 y);
diff --git a/src/Client/Menus.c b/src/Client/Menus.c
index 31a69286f..d9b11f49f 100644
--- a/src/Client/Menus.c
+++ b/src/Client/Menus.c
@@ -18,7 +18,6 @@
#include "Camera.h"
#include "AsyncDownloader.h"
#include "Block.h"
-#include "Random.h"
#include "World.h"
#include "Formats.h"
#include "ErrorHandler.h"
diff --git a/src/Client/ModelCache.h b/src/Client/ModelCache.h
index 75671ce1a..fbea45df4 100644
--- a/src/Client/ModelCache.h
+++ b/src/Client/ModelCache.h
@@ -7,16 +7,8 @@
*/
struct IModel;
-struct CachedModel {
- String Name; /* Name associated with the model, all lowercase. */
- struct IModel* Instance; /* Pointer to the actual model instance. */
-};
-
-struct CachedTexture {
- String Name; /* Filename of the texture. */
- GfxResourceID TexID; /* Native texture ID. */
-};
-
+struct CachedModel { String Name; struct IModel* Instance; };
+struct CachedTexture { String Name; GfxResourceID TexID; };
#if FALSE
public CustomModel[] CustomModels = new CustomModel[256];
#endif
diff --git a/src/Client/Particle.c b/src/Client/Particle.c
index 36eefb780..7e66fc314 100644
--- a/src/Client/Particle.c
+++ b/src/Client/Particle.c
@@ -4,7 +4,6 @@
#include "ExtMath.h"
#include "Lighting.h"
#include "Entity.h"
-#include "Random.h"
#include "TerrainAtlas.h"
#include "GraphicsAPI.h"
#include "GraphicsCommon.h"
diff --git a/src/Client/Program.c b/src/Client/Program.c
index e3ef62a53..e6e9f3549 100644
--- a/src/Client/Program.c
+++ b/src/Client/Program.c
@@ -70,7 +70,7 @@ int main(void) {
String title = String_FromConst(PROGRAM_APP_NAME);
String rawArgs = Platform_GetCommandLineArgs();
/* NOTE: Make sure to comment this out before pushing a commit */
- rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
+ //rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
String args[5]; Int32 argsCount = Array_Elems(args);
String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
diff --git a/src/Client/Random.c b/src/Client/Random.c
deleted file mode 100644
index 11452d850..000000000
--- a/src/Client/Random.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include "Random.h"
-#include "Platform.h"
-#include "Utils.h"
-#define RND_VALUE (0x5DEECE66DLL)
-#define RND_MASK ((1LL << 48) - 1)
-
-void Random_Init(Random* seed, Int32 seedInit) { Random_SetSeed(seed, seedInit); }
-void Random_InitFromCurrentTime(Random* rnd) {
- DateTime now; Platform_CurrentUTCTime(&now);
- Int64 totalMs = DateTime_TotalMs(&now);
- Random_Init(rnd, (Int32)totalMs);
-}
-
-void Random_SetSeed(Random* seed, Int32 seedInit) {
- *seed = (seedInit ^ RND_VALUE) & RND_MASK;
-}
-
-Int32 Random_Range(Random* seed, Int32 min, Int32 max) {
- return min + Random_Next(seed, max - min);
-}
-
-Int32 Random_Next(Random* seed, Int32 n) {
- if ((n & -n) == n) { /* i.e., n is a power of 2 */
- *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
- Int64 raw = (Int64)((UInt64)(*seed) >> (48 - 31));
- return (Int32)((n * raw) >> 31);
- }
-
- Int32 bits, val;
- do {
- *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
- bits = (Int32)((UInt64)(*seed) >> (48 - 31));
- val = bits % n;
- } while (bits - val + (n - 1) < 0);
- return val;
-}
-
-Real32 Random_Float(Random* seed) {
- *seed = (*seed * RND_VALUE + 0xBLL) & RND_MASK;
- Int32 raw = (Int32)((UInt64)(*seed) >> (48 - 24));
- return raw / ((Real32)(1 << 24));
-}
diff --git a/src/Client/Random.h b/src/Client/Random.h
deleted file mode 100644
index 221ef573f..000000000
--- a/src/Client/Random.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef CC_RANDOM_H
-#define CC_RANDOM_H
-#include "Typedefs.h"
-/* Implemented a random number generation algorithm.
- Based on Java's implementation from https://docs.oracle.com/javase/7/docs/api/java/util/Random.html
- Copyright 2014 - 2017 ClassicalSharp | Licensed under BSD-3
-*/
-
-typedef Int64 Random;
-void Random_Init(Random* rnd, Int32 seed);
-void Random_InitFromCurrentTime(Random* rnd);
-void Random_SetSeed(Random* rnd, Int32 seed);
-/* Returns integer from min inclusive to max exclusive */
-Int32 Random_Range(Random* rnd, Int32 min, Int32 max);
-/* Returns integer from 0 inclusive to n exclusive */
-Int32 Random_Next(Random* rnd, Int32 n);
-/* Returns real from 0 inclusive to 1 exclusive */
-Real32 Random_Float(Random* rnd);
-#endif