diff --git a/ClassicalSharp/2D/Screens/StatusScreen.cs b/ClassicalSharp/2D/Screens/StatusScreen.cs
index 24dc19f55..4eb4ec73c 100644
--- a/ClassicalSharp/2D/Screens/StatusScreen.cs
+++ b/ClassicalSharp/2D/Screens/StatusScreen.cs
@@ -42,7 +42,7 @@ namespace ClassicalSharp.Gui.Screens {
}
double accumulator;
- int frames, totalSeconds;
+ int frames;
void UpdateStatus(double delta) {
frames++;
@@ -50,7 +50,6 @@ namespace ClassicalSharp.Gui.Screens {
if (accumulator < 1) return;
int index = 0;
- totalSeconds++;
int fps = (int)(frames / accumulator);
statusBuffer.Clear()
diff --git a/src/Client/Block.c b/src/Client/Block.c
index 7456c836f..dd9b4d49a 100644
--- a/src/Client/Block.c
+++ b/src/Client/Block.c
@@ -450,8 +450,8 @@ bool Block_IsFaceHidden(BlockID block, BlockID other, Face face) {
#define AR_EQ2(s, x, y) (s.length >= 2 && Char_ToLower(s.buffer[0]) == x && Char_ToLower(s.buffer[1]) == y)
BlockID AutoRotate_Find(BlockID block, String* name, const UInt8* suffix) {
- UInt8 buffer[String_BufferSize(128)];
- String temp = String_InitAndClear(buffer, 128);
+ UInt8 buffer[String_BufferSize(STRING_SIZE * 2)];
+ String temp = String_InitAndClearArray(buffer);
String_AppendString(&temp, name);
String_AppendConst(&temp, suffix);
diff --git a/src/Client/Chat.c b/src/Client/Chat.c
index 5d58783be..4c29ea98e 100644
--- a/src/Client/Chat.c
+++ b/src/Client/Chat.c
@@ -7,13 +7,13 @@
#include "ServerConnection.h"
void ChatLine_Make(ChatLine* line, STRING_TRANSIENT String* text) {
- String dst = String_InitAndClear(line->Buffer, STRING_SIZE);
+ String dst = String_InitAndClearArray(line->Buffer);
String_AppendString(&dst, text);
line->Received = Platform_CurrentUTCTime();
}
UInt8 Chat_LogNameBuffer[String_BufferSize(STRING_SIZE)];
-String Chat_LogName = String_EmptyConstArray(Chat_LogNameBuffer);
+String Chat_LogName = String_FromEmptyArray(Chat_LogNameBuffer);
Stream Chat_LogStream;
DateTime ChatLog_LastLogDate;
@@ -62,7 +62,7 @@ void Chat_OpenLog(DateTime* now) {
UInt32 i;
for (i = 0; i < 20; i++) {
UInt8 pathBuffer[String_BufferSize(FILENAME_SIZE)];
- String path = String_InitAndClear(pathBuffer, FILENAME_SIZE);
+ String path = String_InitAndClearArray(pathBuffer);
String_AppendConst(&path, "logs");
String_Append(&path, Platform_DirectorySeparator);
@@ -106,7 +106,7 @@ void Chat_AppendLog(STRING_PURE String* text) {
ChatLog_LastLogDate = now;
if (Chat_LogStream.Data == NULL) return;
UInt8 logBuffer[String_BufferSize(STRING_SIZE * 2)];
- String str = String_InitAndClear(logBuffer, STRING_SIZE * 2);
+ String str = String_InitAndClearArray(logBuffer);
/* [HH:mm:ss] text */
String_Append(&str, '['); String_AppendPaddedInt32(&str, now.Hour, 2);
diff --git a/src/Client/ChunkUpdater.c b/src/Client/ChunkUpdater.c
index e95cb1599..df62abd3d 100644
--- a/src/Client/ChunkUpdater.c
+++ b/src/Client/ChunkUpdater.c
@@ -358,7 +358,6 @@ void ChunkUpdater_BuildChunk(ChunkInfo* info, Int32* chunkUpdates) {
void ChunkUpdater_QuickSort(Int32 left, Int32 right) {
ChunkInfo** values = MapRenderer_SortedChunks; ChunkInfo* value;
Int32* keys = ChunkUpdater_Distances; Int32 key;
-
while (left < right) {
Int32 i = left, j = right;
Int32 pivot = keys[(i + j) / 2];
diff --git a/src/Client/Client.vcxproj b/src/Client/Client.vcxproj
index 39d2292d5..15ba196b5 100644
--- a/src/Client/Client.vcxproj
+++ b/src/Client/Client.vcxproj
@@ -224,6 +224,7 @@
+
@@ -308,6 +309,7 @@
+
diff --git a/src/Client/Client.vcxproj.filters b/src/Client/Client.vcxproj.filters
index 0628d9118..a539f2576 100644
--- a/src/Client/Client.vcxproj.filters
+++ b/src/Client/Client.vcxproj.filters
@@ -381,6 +381,9 @@
Header Files\Entities
+
+ Header Files\Math
+
@@ -596,5 +599,8 @@
Source Files\Entities
+
+ Source Files\Math
+
\ No newline at end of file
diff --git a/src/Client/D3D9Api.c b/src/Client/D3D9Api.c
index 1ef663875..68cb82695 100644
--- a/src/Client/D3D9Api.c
+++ b/src/Client/D3D9Api.c
@@ -52,8 +52,8 @@ void D3D9_FreeResource(GfxResourceID* resource) {
*resource = NULL;
if (refCount <= 0) return;
- UInt8 logMsgBuffer[String_BufferSize(127)];
- String logMsg = String_InitAndClear(logMsgBuffer, 127);
+ UInt8 logMsgBuffer[String_BufferSize(STRING_SIZE * 2)];
+ String logMsg = String_InitAndClearArray(logMsgBuffer);
String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: ");
String_AppendInt32(&logMsg, id);
Platform_Log(&logMsg);
diff --git a/src/Client/Hotkeys.c b/src/Client/Hotkeys.c
index 876e408b2..755d7d415 100644
--- a/src/Client/Hotkeys.c
+++ b/src/Client/Hotkeys.c
@@ -142,7 +142,7 @@ void Hotkeys_Init(void) {
void Hotkeys_UserRemovedHotkey(Key baseKey, UInt8 flags) {
UInt8 keyBuffer[String_BufferSize(STRING_SIZE)];
- String key = String_InitAndClear(keyBuffer, STRING_SIZE);
+ String key = String_InitAndClearArray(keyBuffer);
String_AppendConst(&key, "hotkey-"); String_AppendConst(&key, Key_Names[baseKey]);
String_Append(&key, '&'); String_AppendInt32(&key, flags);
@@ -151,9 +151,9 @@ void Hotkeys_UserRemovedHotkey(Key baseKey, UInt8 flags) {
void Hotkeys_UserAddedHotkey(Key baseKey, UInt8 flags, bool moreInput, STRING_PURE String* text) {
UInt8 keyBuffer[String_BufferSize(STRING_SIZE)];
- String key = String_InitAndClear(keyBuffer, STRING_SIZE);
+ String key = String_InitAndClearArray(keyBuffer);
UInt8 valueBuffer[String_BufferSize(STRING_SIZE * 2)];
- String value = String_InitAndClear(valueBuffer, STRING_SIZE * 2);
+ String value = String_InitAndClearArray(valueBuffer);
String_AppendConst(&key, "hotkey-"); String_AppendConst(&key, Key_Names[baseKey]);
String_Append(&key, '&'); String_AppendInt32(&key, flags);
diff --git a/src/Client/Input.c b/src/Client/Input.c
index 7f2cb98f2..9bb488f21 100644
--- a/src/Client/Input.c
+++ b/src/Client/Input.c
@@ -137,7 +137,7 @@ bool KeyBind_IsPressed(KeyBind binding) { return Key_States[KeyBind_Keys[binding
void KeyBind_Load(void) {
UInt32 i;
UInt8 nameBuffer[String_BufferSize(STRING_SIZE)];
- String name = String_InitAndClear(nameBuffer, STRING_SIZE);
+ String name = String_InitAndClearArray(nameBuffer);
for (i = 0; i < KeyBind_Count; i++) {
KeyBind_MakeName(name);
@@ -149,7 +149,7 @@ void KeyBind_Load(void) {
void KeyBind_Save(void) {
UInt32 i;
UInt8 nameBuffer[String_BufferSize(STRING_SIZE)];
- String name = String_InitAndClear(nameBuffer, STRING_SIZE);
+ String name = String_InitAndClearArray(nameBuffer);
for (i = 0; i < KeyBind_Count; i++) {
KeyBind_MakeName(name);
diff --git a/src/Client/Options.c b/src/Client/Options.c
index 162b2379e..137c19c2c 100644
--- a/src/Client/Options.c
+++ b/src/Client/Options.c
@@ -109,7 +109,7 @@ Int32 Options_Insert(STRING_PURE String* key, STRING_PURE String* value) {
void Options_SetInt32(const UInt8* keyRaw, Int32 value) {
UInt8 numBuffer[String_BufferSize(STRING_INT32CHARS)];
- String numStr = String_InitAndClear(numBuffer, STRING_INT32CHARS);
+ String numStr = String_InitAndClearArray(numBuffer);
String_AppendInt32(&numStr, value);
Options_Set(keyRaw, &numStr);
}
diff --git a/src/Client/Player.c b/src/Client/Player.c
index 654a30ea9..c641fe584 100644
--- a/src/Client/Player.c
+++ b/src/Client/Player.c
@@ -27,7 +27,7 @@ void Player_MakeNameTexture(Player* player) {
player->NameTex.X = PLAYER_NAME_EMPTY_TEX;
} else {
UInt8 buffer[String_BufferSize(STRING_SIZE * 2)];
- String shadowName = String_InitAndClear(buffer, STRING_SIZE * 2);
+ String shadowName = String_InitAndClearArray(buffer);
size.Width += 3; size.Height += 3;
Bitmap bmp; Bitmap_AllocatePow2(&bmp, size.Width, size.Height);
diff --git a/src/Client/Screens.c b/src/Client/Screens.c
index 0ac251765..a750cb223 100644
--- a/src/Client/Screens.c
+++ b/src/Client/Screens.c
@@ -6,6 +6,8 @@
#include "Platform.h"
#include "Inventory.h"
#include "Drawer2D.h"
+#include "GraphicsAPI.h"
+#include "Player.h"
void Screen_FreeWidgets(Widget** widgets, UInt32 widgetsCount) {
if (widgets == NULL) return;
@@ -135,9 +137,9 @@ void InventoryScreen_Init(GuiElement* elem) {
Key_KeyRepeat = true;
Event_RegisterVoid(&BlockEvents_PermissionsChanged, InventoryScreen_OnBlockChanged);
- Event_RegisterVoid(&BlockEvents_BlockDefChanged, InventoryScreen_OnBlockChanged);
- Event_RegisterVoid(&GfxEvents_ContextLost, InventoryScreen_ContextLost);
- Event_RegisterVoid(&GfxEvents_ContextRecreated, InventoryScreen_ContextRecreated);
+ Event_RegisterVoid(&BlockEvents_BlockDefChanged, InventoryScreen_OnBlockChanged);
+ Event_RegisterVoid(&GfxEvents_ContextLost, InventoryScreen_ContextLost);
+ Event_RegisterVoid(&GfxEvents_ContextRecreated, InventoryScreen_ContextRecreated);
}
void InventoryScreen_Render(GuiElement* elem, Real64 delta) {
@@ -252,168 +254,200 @@ extern Screen* InventoryScreen_UNSAFE_RawPointer = &InventoryScreen_Instance.Bas
typedef struct StatusScreen_ {
Screen Base;
FontDesc Font;
- UInt8 StatusText[String_BufferSize(STRING_SIZE * 2)];
+ TextWidget Status, HackStates;
+ TextAtlas PosAtlas;
+ Real64 Accumulator;
+ Int32 Frames, FPS;
+ bool Speeding, HalfSpeeding, Noclip, Fly;
+ Int32 LastFov;
} StatusScreen;
+StatusScreen StatusScreen_Instance;
+
+void StatusScreen_Render(GuiElement* elem, Real64 delta) {
+ StatusScreen* screen = (StatusScreen*)elem;
+ StatusScreen_Update(screen, delta);
+ if (Game_HideGui || !Game_ShowFPS) return;
-namespace ClassicalSharp.Gui.Screens{
- public class StatusScreen : Screen, IGameComponent {
+ Gfx_SetTexturing(true);
+ elem = &screen->Status.Base.Base;
+ elem->Render(elem, delta);
- Font font;
- StringBuffer statusBuffer;
-
- public StatusScreen(Game game) : base(game) {
- statusBuffer = new StringBuffer(128);
+ if (!Game_ClassicMode && Gui_Active == NULL) {
+ StatusScreen_UpdateHackState(screen, false);
+ StatusScreen_DrawPosition(screen);
+ elem = &screen->HackStates.Base.Base;
+ elem->Render(elem, delta);
}
+ Gfx_SetTexturing(false);
+}
- public void Init(Game game) { }
- public void Ready(Game game) { Init(); }
- public void Reset(Game game) { }
- public void OnNewMap(Game game) { }
- public void OnNewMapLoaded(Game game) { }
+void StatusScreen_MakeText(StatusScreen* screen, STRING_TRANSIENT String* status) {
+ screen->FPS = (Int32)(screen->Frames / screen->Accumulator);
+ String_AppendInt32(status, screen->FPS);
+ String_AppendConst(status, " fps, ");
- TextWidget status, hackStates;
- TextAtlas posAtlas;
- public override void Render(double delta) {
- UpdateStatus(delta);
- if (game.HideGui || !game.ShowFPS) return;
-
- gfx.Texturing = true;
- status.Render(delta);
- if (!game.ClassicMode && game.Gui.activeScreen == null) {
- UpdateHackState(false);
- DrawPosition();
- hackStates.Render(delta);
- }
- gfx.Texturing = false;
- }
-
- double accumulator;
- int frames, totalSeconds;
-
- void UpdateStatus(double delta) {
- frames++;
- accumulator += delta;
- if (accumulator < 1) return;
-
- int index = 0;
- totalSeconds++;
- int fps = (int)(frames / accumulator);
-
- statusBuffer.Clear()
- .AppendNum(ref index, fps).Append(ref index, " fps, ");
- if (game.ClassicMode) {
- statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunk updates");
- } else {
- if (game.ChunkUpdates > 0) {
- statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, ");
- }
- int indices = (game.Vertices >> 2) * 6;
- statusBuffer.AppendNum(ref index, indices).Append(ref index, " vertices");
-
- int ping = PingList.AveragePingMilliseconds();
- if (ping != 0) {
- statusBuffer.Append(ref index, ", ping ").AppendNum(ref index, ping).Append(ref index, " ms");
- }
+ if (Game_ClassicMode) {
+ String_AppendInt32(status, Game_ChunkUpdates);
+ String_AppendConst(status, " chunk updates");
+ } else {
+ if (Game_ChunkUpdates > 0) {
+ String_AppendInt32(status, Game_ChunkUpdates);
+ String_AppendConst(status, " chunks/s, ");
}
- status.SetText(statusBuffer.ToString());
- accumulator = 0;
- frames = 0;
- game.ChunkUpdates = 0;
- }
+ Int32 indices = ICOUNT(Game_Vertices);
+ String_AppendInt32(status, indices);
+ String_AppendConst(status, " vertices");
- public override void Init() {
- font = new Font(game.FontName, 16);
- ContextRecreated();
-
- game.Events.ChatFontChanged += ChatFontChanged;
- gfx.ContextLost += ContextLost;
- gfx.ContextRecreated += ContextRecreated;
- }
-
- protected override void ContextLost() {
- status.Dispose();
- posAtlas.Dispose();
- hackStates.Dispose();
- }
-
- protected override void ContextRecreated() {
- status = new TextWidget(game, font)
- .SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
- status.ReducePadding = true;
- status.Init();
- string msg = statusBuffer.Length > 0 ? statusBuffer.ToString() : "FPS: no data yet";
- status.SetText(msg);
-
- posAtlas = new TextAtlas(game, 16);
- posAtlas.Pack("0123456789-, ()", font, "Position: ");
- posAtlas.tex.Y = (short)(status.Height + 2);
-
- int yOffset = status.Height + posAtlas.tex.Height + 2;
- hackStates = new TextWidget(game, font)
- .SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, yOffset);
- hackStates.ReducePadding = true;
- hackStates.Init();
- UpdateHackState(true);
- }
-
- public override void Dispose() {
- font.Dispose();
- ContextLost();
-
- game.Events.ChatFontChanged -= ChatFontChanged;
- gfx.ContextLost -= ContextLost;
- gfx.ContextRecreated -= ContextRecreated;
- }
-
- void ChatFontChanged(object sender, EventArgs e) { Recreate(); }
-
- public override void OnResize(int width, int height) { }
-
- void DrawPosition() {
- int index = 0;
- Texture tex = posAtlas.tex;
- tex.X1 = 2; tex.Width = (ushort)posAtlas.offset;
- IGraphicsApi.Make2DQuad(ref tex, FastColour.WhitePacked,
- game.ModelCache.vertices, ref index);
-
- Vector3I pos = Vector3I.Floor(game.LocalPlayer.Position);
- posAtlas.curX = posAtlas.offset + 2;
- VertexP3fT2fC4b[] vertices = game.ModelCache.vertices;
-
- posAtlas.Add(13, vertices, ref index);
- posAtlas.AddInt(pos.X, vertices, ref index);
- posAtlas.Add(11, vertices, ref index);
- posAtlas.AddInt(pos.Y, vertices, ref index);
- posAtlas.Add(11, vertices, ref index);
- posAtlas.AddInt(pos.Z, vertices, ref index);
- posAtlas.Add(14, vertices, ref index);
-
- gfx.BindTexture(posAtlas.tex.ID);
- gfx.UpdateDynamicVb_IndexedTris(game.ModelCache.vb, game.ModelCache.vertices, index);
- }
-
- bool speeding, halfSpeeding, noclip, fly;
- int lastFov;
- void UpdateHackState(bool force) {
- HacksComponent hacks = game.LocalPlayer.Hacks;
- if (force || hacks.Speeding != speeding || hacks.HalfSpeeding != halfSpeeding || hacks.Noclip != noclip ||
- hacks.Flying != fly || game.Fov != lastFov) {
- speeding = hacks.Speeding; halfSpeeding = hacks.HalfSpeeding; noclip = hacks.Noclip; fly = hacks.Flying;
- lastFov = game.Fov;
- int index = 0;
- statusBuffer.Clear();
-
- if (game.Fov != game.DefaultFov) statusBuffer.Append(ref index, "Zoom fov ")
- .AppendNum(ref index, lastFov).Append(ref index, " ");
- if (fly) statusBuffer.Append(ref index, "Fly ON ");
-
- bool speed = (speeding || halfSpeeding) &&
- (hacks.CanSpeed || hacks.BaseHorSpeed > 1);
- if (speed) statusBuffer.Append(ref index, "Speed ON ");
- if (noclip) statusBuffer.Append(ref index, "Noclip ON ");
- hackStates.SetText(statusBuffer.ToString());
+ Int32 ping = PingList.AveragePingMilliseconds();
+ if (ping != 0) {
+ String_AppendConst(status, ", ping ");
+ String_AppendInt32(status, ping);
+ String_AppendConst(status, " ms");
}
}
}
+
+void StatusScreen_Update(StatusScreen* screen, Real64 delta) {
+ screen->Frames++;
+ screen->Accumulator += delta;
+ if (screen->Accumulator < 1.0) return;
+
+ UInt8 statusBuffer[String_BufferSize(STRING_SIZE * 2)];
+ String status = String_InitAndClearArray(statusBuffer);
+ StatusScreen_MakeText(screen, &status);
+
+ TextWidget_SetText(&screen->Status, &status);
+ screen->Accumulator = 0.0;
+ screen->Frames = 0;
+ Game_ChunkUpdates = 0;
}
+
+void StatusScreen_OnResize(void) { }
+void StatusScreen_ChatFontChanged(void) {
+ Recreate();
+}
+
+void StatusScreen_ContextLost(void) {
+ StatusScreen* screen = &StatusScreen_Instance;
+ TextAtlas_Free(&screen->PosAtlas);
+ GuiElement* elem;
+
+ elem = &screen->Status.Base.Base;
+ elem->Free(elem);
+ elem = &screen->HackStates.Base.Base;
+ elem->Free(elem);
+}
+
+void StatusScreen_ContextRecreated(void) {
+ StatusScreen* screen = &StatusScreen_Instance;
+ status = new TextWidget(game, font)
+ .SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
+ status.ReducePadding = true;
+ status.Init();
+ string msg = statusBuffer.Length > 0 ? statusBuffer.ToString() : "FPS: no data yet";
+ status.SetText(msg);
+
+ posAtlas = new TextAtlas(game, 16);
+ posAtlas.Pack("0123456789-, ()", font, "Position: ");
+ posAtlas.tex.Y = (short)(status.Height + 2);
+
+ int yOffset = status.Height + posAtlas.tex.Height + 2;
+ hackStates = new TextWidget(game, font)
+ .SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, yOffset);
+ hackStates.ReducePadding = true;
+ hackStates.Init();
+ UpdateHackState(true);
+}
+
+void StatusScreen_Init(GuiElement* elem) {
+ font = new Font(game.FontName, 16);
+ StatusScreen_ContextRecreated();
+
+ Event_RegisterVoid(&ChatEvents_FontChanged, StatusScreen_ChatFontChanged);
+ Event_RegisterVoid(&GfxEvents_ContextLost, StatusScreen_ContextLost);
+ Event_RegisterVoid(&GfxEvents_ContextRecreated, StatusScreen_ContextRecreated);
+}
+
+void StatusScreen_Free(GuiElement* elem) {
+ StatusScreen* screen = (StatusScreen*)elem;
+ Platform_FreeFont(&screen->Font);
+ StatusScreen_ContextLost();
+
+ Event_UnregisterVoid(&ChatEvents_FontChanged, StatusScreen_ChatFontChanged);
+ Event_UnregisterVoid(&GfxEvents_ContextLost, StatusScreen_ContextLost);
+ Event_UnregisterVoid(&GfxEvents_ContextRecreated, StatusScreen_ContextRecreated);
+}
+
+void StatusScreen_DrawPosition(StatusScreen* screen) {
+ TextAtlas* atlas = &screen->PosAtlas;
+ VertexP3fT2fC4b vertices[4 * 8];
+
+ Texture tex = atlas->Tex; tex.X = 2; tex.Width = (UInt16)atlas->Offset;
+ GfxCommon_Make2DQuad(&tex, PACKEDCOL_WHITE,
+ IGraphicsApi.Make2DQuad(ref tex, FastColour.WhitePacked,
+ game.ModelCache.vertices, ref index);
+
+ Vector3I pos = Vector3I.Floor(game.LocalPlayer.Position);
+ posAtlas.curX = posAtlas.offset + 2;
+ VertexP3fT2fC4b[] vertices = game.ModelCache.vertices;
+
+ posAtlas.Add(13, vertices, ref index);
+ posAtlas.AddInt(pos.X, vertices, ref index);
+ posAtlas.Add(11, vertices, ref index);
+ posAtlas.AddInt(pos.Y, vertices, ref index);
+ posAtlas.Add(11, vertices, ref index);
+ posAtlas.AddInt(pos.Z, vertices, ref index);
+ posAtlas.Add(14, vertices, ref index);
+
+ gfx.BindTexture(posAtlas.tex.ID);
+ gfx.UpdateDynamicVb_IndexedTris(game.ModelCache.vb, game.ModelCache.vertices, index);
+}
+
+void StatusScreen_UpdateHackState(StatusScreen* screen, bool force) {
+ HacksComp* hacks = &LocalPlayer_Instance.Hacks;
+ if (force || hacks->Speeding != screen->Speeding || hacks->HalfSpeeding != screen->HalfSpeeding || hacks->Noclip != screen->Noclip || hacks->Flying != screen->Fly || Game_Fov != screen->LastFov) {
+ screen->Speeding = hacks->Speeding; screen->Noclip = hacks->Noclip;
+ screen->HalfSpeeding = hacks->HalfSpeeding; screen->Fly = hacks->Flying;
+ screen->LastFov = Game_Fov;
+
+ UInt8 statusBuffer[String_BufferSize(STRING_SIZE * 2)];
+ String status = String_InitAndClearArray(statusBuffer);
+
+ if (Game_Fov != Game_DefaultFov) {
+ String_AppendConst(&status, "Zoom fov ");
+ String_AppendInt32(&status, Game_Fov);
+ String_AppendConst(&status, " ");
+ }
+ if (hacks->Flying) String_AppendConst(&status, "Fly ON ");
+
+ bool speed = (hacks->Speeding || hacks->HalfSpeeding) && (hacks->CanSpeed || hacks->BaseHorSpeed > 1);
+ if (speed) String_AppendConst(&status, "Speed ON ");
+ if (hacks->Noclip) String_AppendConst(&status, "Noclip ON ");
+
+ TextWidget_SetText(&screen->HackStates, &status);
+ }
+}
+
+Screen* StatusScreen_MakeInstance(void) {
+ StatusScreen* screen = &StatusScreen_Instance;
+ Platform_MemSet(&screen, 0, sizeof(StatusScreen));
+ Screen_Reset(&screen->Base);
+
+ screen->Base.OnResize = StatusScreen_OnResize;
+ screen->Base.Base.Init = StatusScreen_Init;
+ screen->Base.Base.Render = StatusScreen_Render;
+ screen->Base.Base.Free = StatusScreen_Free;
+ return &screen->Base;
+}
+
+void StatusScreen_Reset(void) {
+ GuiElement* elem = &StatusScreen_Instance.Base.Base;
+ elem->Init(elem);
+}
+
+IGameComponent StatusScreen_MakeComponent(void) {
+ IGameComponent comp = IGameComponent_MakeEmpty();
+ comp.Reset = StatusScreen_Reset;
+ return comp;
+}
\ No newline at end of file
diff --git a/src/Client/Searcher.h b/src/Client/Searcher.h
index 8a2d5ce2f..fafe962d4 100644
--- a/src/Client/Searcher.h
+++ b/src/Client/Searcher.h
@@ -1,8 +1,10 @@
+#ifndef CC_SEARCHER_H
+#define CC_SEARCHER_H
#include "Typedefs.h"
#include "Entity.h"
-/* Calculates all possible blocks that a moving entity can intersect with.
- Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
+/* Calculates all possible blocks that a moving entity can intersect with.
+ Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
typedef struct SearcherState_ {
@@ -13,4 +15,5 @@ extern SearcherState* Searcher_States;
UInt32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entityExtentBB);
void Searcher_CalcTime(Vector3* vel, AABB *entityBB, AABB* blockBB, Real32* tx, Real32* ty, Real32* tz);
-void Searcher_Free(void);
\ No newline at end of file
+void Searcher_Free(void);
+#endif
\ No newline at end of file
diff --git a/src/Client/ServerConnection.c b/src/Client/ServerConnection.c
index 4571befb6..a581bae0f 100644
--- a/src/Client/ServerConnection.c
+++ b/src/Client/ServerConnection.c
@@ -10,11 +10,11 @@
#include "Player.h"
UInt8 ServerConnection_ServerNameBuffer[String_BufferSize(STRING_SIZE)];
-String ServerConnection_ServerName = String_EmptyConstArray(ServerConnection_ServerNameBuffer);
+String ServerConnection_ServerName = String_FromEmptyArray(ServerConnection_ServerNameBuffer);
UInt8 ServerConnection_ServerMOTDBuffer[String_BufferSize(STRING_SIZE)];
-String ServerConnection_ServerMOTD = String_EmptyConstArray(ServerConnection_ServerMOTDBuffer);
+String ServerConnection_ServerMOTD = String_FromEmptyArray(ServerConnection_ServerMOTDBuffer);
UInt8 ServerConnection_AppNameBuffer[String_BufferSize(STRING_SIZE)];
-String ServerConnection_AppName = String_EmptyConstArray(ServerConnection_AppNameBuffer);
+String ServerConnection_AppName = String_FromEmptyArray(ServerConnection_AppNameBuffer);
Int32 ServerConnection_Ticks;
void ServerConnection_ResetState(void) {
@@ -49,8 +49,8 @@ void SPConnection_Connect(STRING_PURE String* ip, Int32 port) {
UInt8 SPConnection_LastCol = NULL;
void SPConnection_AddChat(STRING_PURE String* text) {
- UInt8 tmpBuffer[STRING_SIZE * 2];
- String tmp = String_InitAndClear(tmpBuffer, STRING_SIZE * 2);
+ UInt8 tmpBuffer[String_BufferSize(STRING_SIZE * 2)];
+ String tmp = String_InitAndClearArray(tmpBuffer);
/* Prepend colour codes for subsequent lines of multi-line chat */
if (!Drawer2D_IsWhiteCol(SPConnection_LastCol)) {
String_Append(&tmp, '&');
diff --git a/src/Client/Stream.c b/src/Client/Stream.c
index f64870701..992829999 100644
--- a/src/Client/Stream.c
+++ b/src/Client/Stream.c
@@ -16,7 +16,7 @@ if (write == 0 || !ErrorHandler_Check(result)) {\
void Stream_Fail(Stream* stream, ReturnCode result, const UInt8* operation) {
UInt8 tmpBuffer[String_BufferSize(400)];
- String tmp = String_InitAndClear(tmpBuffer, 400);
+ String tmp = String_InitAndClearArray(tmpBuffer);
String_AppendConst(&tmp, "Failed ");
String_AppendConst(&tmp, operation);
@@ -50,7 +50,7 @@ Int32 Stream_TryReadByte(Stream* stream) {
void Stream_SetName(Stream* stream, STRING_PURE String* name) {
- stream->Name = String_InitAndClear(stream->NameBuffer, FILENAME_SIZE);
+ stream->Name = String_InitAndClearArray(stream->NameBuffer);
String_AppendString(&stream->Name, name);
}
diff --git a/src/Client/String.h b/src/Client/String.h
index 144cea452..8f27d5c2f 100644
--- a/src/Client/String.h
+++ b/src/Client/String.h
@@ -31,6 +31,7 @@ typedef struct String_ {
String String_MakeNull(void);
String String_Init(STRING_REF UInt8* buffer, UInt16 length, UInt16 capacity);
String String_InitAndClear(STRING_REF UInt8* buffer, UInt16 capacity);
+#define String_InitAndClearArray(buffer) String_InitAndClear(buffer, (UInt16)(sizeof(buffer) - 1))
/* Constructs a new string from a (maybe null terminated) buffer. */
String String_FromRaw(STRING_REF UInt8* buffer, UInt16 capacity);
/* Constructs a new string from a constant readonly buffer. */
@@ -38,7 +39,7 @@ String String_FromReadonly(STRING_REF const UInt8* buffer);
/* Constructs a new string from a compile time string constant. */
#define String_FromConst(text) { text, (UInt16)(sizeof(text) - 1), (UInt16)(sizeof(text) - 1)};
/* Constructs a new string from a compile time empty string buffer. */
-#define String_EmptyConstArray(buffer) { buffer, 0, (UInt16)(sizeof(buffer) - 1)};
+#define String_FromEmptyArray(buffer) { buffer, 0, (UInt16)(sizeof(buffer) - 1)};
/* Constructs a new string from a compile time array, that may have arbitary actual length of data at runtime */
#define String_FromRawArray(buffer) String_FromRaw(buffer, (UInt16)(sizeof(buffer) - 1))
diff --git a/src/Client/TerrainAtlas.c b/src/Client/TerrainAtlas.c
index c45b2a8ba..938bc6b27 100644
--- a/src/Client/TerrainAtlas.c
+++ b/src/Client/TerrainAtlas.c
@@ -77,8 +77,8 @@ void Atlas1D_Make1DTexture(Int32 i, Int32 atlas1DHeight, Int32* index) {
void Atlas1D_Convert2DTo1D(Int32 atlasesCount, Int32 atlas1DHeight) {
Atlas1D_Count = atlasesCount;
- UInt8 logBuffer[String_BufferSize(127)];
- String log = String_InitAndClear(logBuffer, 127);
+ UInt8 logBuffer[String_BufferSize(STRING_SIZE * 2)];
+ String log = String_InitAndClearArray(logBuffer);
String_AppendConst(&log, "Loaded new atlas: ");
String_AppendInt32(&log, atlasesCount);
diff --git a/src/Client/Widgets.c b/src/Client/Widgets.c
index f0c6dab1d..e8df10a1b 100644
--- a/src/Client/Widgets.c
+++ b/src/Client/Widgets.c
@@ -566,7 +566,6 @@ void TableWidget_UpdatePos(TableWidget* widget) {
TableWidget_UpdateDescTexPos(widget);
}
-#define TABLE_NAME_LEN 128
void TableWidget_RecreateDescTex(TableWidget* widget) {
if (widget->SelectedIndex == widget->LastCreatedIndex) return;
if (widget->ElementsCount == 0) return;
@@ -575,8 +574,8 @@ void TableWidget_RecreateDescTex(TableWidget* widget) {
Gfx_DeleteTexture(&widget->DescTex.ID);
if (widget->SelectedIndex == -1) return;
- UInt8 descBuffer[String_BufferSize(TABLE_NAME_LEN)];
- String desc = String_InitAndClear(descBuffer, TABLE_NAME_LEN);
+ UInt8 descBuffer[String_BufferSize(STRING_SIZE * 2)];
+ String desc = String_InitAndClearArray(descBuffer);
BlockID block = widget->Elements[widget->SelectedIndex];
TableWidget_MakeBlockDesc(&desc, block);
@@ -854,7 +853,7 @@ void SpecialInputWidget_UpdateColString(SpecialInputWidget* widget) {
if (Drawer2D_Cols[i].A > 0) count++;
}
- widget->ColString = String_InitAndClear(widget->ColBuffer, DRAWER2D_MAX_COLS * 4);
+ widget->ColString = String_InitAndClearArray(widget->ColBuffer);
String* buffer = &widget->ColString;
Int32 index = 0;
for (i = ' '; i <= '~'; i++) {
@@ -1195,7 +1194,7 @@ void InputWidget_RemakeTexture(InputWidget* widget) {
/* Colour code goes to next line */
if (!Drawer2D_IsWhiteCol(lastCol)) {
- String tmp = String_InitAndClear(tmpBuffer, STRING_SIZE + 2);
+ String tmp = String_InitAndClearArray(tmpBuffer);
String_Append(&tmp, '&'); String_Append(&tmp, lastCol);
String_AppendString(&tmp, &args.Text);
args.Text = tmp;
@@ -1383,7 +1382,7 @@ bool InputWidget_OtherKey(InputWidget* widget, Key key) {
Int32 maxChars = widget->GetMaxLines() * widget->MaxCharsPerLine;
if (key == Key_V && widget->Text.length < maxChars) {
UInt8 textBuffer[String_BufferSize(INPUTWIDGET_MAX_LINES * STRING_SIZE)];
- String text = String_InitAndClear(textBuffer, INPUTWIDGET_MAX_LINES * STRING_SIZE);
+ String text = String_InitAndClearArray(textBuffer);
Window_GetClipboardText(&text);
if (text.length == 0) return true;
diff --git a/src/Client/WinErrorHandler.c b/src/Client/WinErrorHandler.c
index 525de5155..9e48c329e 100644
--- a/src/Client/WinErrorHandler.c
+++ b/src/Client/WinErrorHandler.c
@@ -6,7 +6,7 @@
/* TODO: These might be better off as a function. */
#define ErrorHandler_WriteLogBody(raw_msg)\
UInt8 logMsgBuffer[String_BufferSize(2047)];\
-String logMsg = String_InitAndClear(logMsgBuffer, 2047);\
+String logMsg = String_InitAndClearArray(logMsgBuffer);\
String_AppendConst(&logMsg, "ClassicalSharp crashed.\r\n");\
String_AppendConst(&logMsg, "Message: ");\
String_AppendConst(&logMsg, raw_msg);\
diff --git a/src/Client/WordWrap.c b/src/Client/WordWrap.c
index 619d9f3ae..6ce066fcd 100644
--- a/src/Client/WordWrap.c
+++ b/src/Client/WordWrap.c
@@ -55,7 +55,7 @@ void WordWrap_Do(STRING_TRANSIENT String* text, STRING_TRANSIENT String* lines,
/* Need to make a copy because we mutate the characters. */
UInt8 copyBuffer[String_BufferSize(WORDWRAP_MAX_BUFFER_SIZE)];
- String copy = String_InitAndClear(copyBuffer, WORDWRAP_MAX_BUFFER_SIZE);
+ String copy = String_InitAndClearArray(copyBuffer);
String_AppendString(©, text);
Int32 usedLines = 0, totalChars = maxPerLine * numLines;