More work on porting status screen, avoid needing to declare sizeof string twice when making a string from compile time array on stack

This commit is contained in:
UnknownShadow200 2017-12-26 08:24:16 +11:00
parent 370d3f0525
commit a74998dc13
20 changed files with 237 additions and 194 deletions

View File

@ -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()

View File

@ -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);

View File

@ -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);

View File

@ -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];

View File

@ -224,6 +224,7 @@
<ClInclude Include="PickedPosRenderer.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="Screens.h" />
<ClInclude Include="Searcher.h" />
<ClInclude Include="SelectionBox.h" />
<ClInclude Include="ServerConnection.h" />
<ClInclude Include="SkyboxRenderer.h" />
@ -308,6 +309,7 @@
<ClCompile Include="Program.c" />
<ClCompile Include="Random.c" />
<ClCompile Include="Screens.c" />
<ClCompile Include="Searcher.c" />
<ClCompile Include="SelectionBox.c" />
<ClCompile Include="ServerConnection.c" />
<ClCompile Include="SkyboxRenderer.c" />

View File

@ -381,6 +381,9 @@
<ClInclude Include="EntityComponents.h">
<Filter>Header Files\Entities</Filter>
</ClInclude>
<ClInclude Include="Searcher.h">
<Filter>Header Files\Math</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Noise.c">
@ -596,5 +599,8 @@
<ClCompile Include="Player.c">
<Filter>Source Files\Entities</Filter>
</ClCompile>
<ClCompile Include="Searcher.c">
<Filter>Source Files\Math</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
@ -252,92 +254,93 @@ 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;
namespace ClassicalSharp.Gui.Screens{
public class StatusScreen : Screen, IGameComponent {
void StatusScreen_Render(GuiElement* elem, Real64 delta) {
StatusScreen* screen = (StatusScreen*)elem;
StatusScreen_Update(screen, delta);
if (Game_HideGui || !Game_ShowFPS) return;
Font font;
StringBuffer statusBuffer;
Gfx_SetTexturing(true);
elem = &screen->Status.Base.Base;
elem->Render(elem, delta);
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");
if (Game_ClassicMode) {
String_AppendInt32(status, Game_ChunkUpdates);
String_AppendConst(status, " chunk updates");
} else {
if (game.ChunkUpdates > 0) {
statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, ");
if (Game_ChunkUpdates > 0) {
String_AppendInt32(status, Game_ChunkUpdates);
String_AppendConst(status, " chunks/s, ");
}
int indices = (game.Vertices >> 2) * 6;
statusBuffer.AppendNum(ref index, indices).Append(ref index, " vertices");
int ping = PingList.AveragePingMilliseconds();
Int32 indices = ICOUNT(Game_Vertices);
String_AppendInt32(status, indices);
String_AppendConst(status, " vertices");
Int32 ping = PingList.AveragePingMilliseconds();
if (ping != 0) {
statusBuffer.Append(ref index, ", ping ").AppendNum(ref index, ping).Append(ref index, " ms");
String_AppendConst(status, ", ping ");
String_AppendInt32(status, ping);
String_AppendConst(status, " ms");
}
}
}
status.SetText(statusBuffer.ToString());
accumulator = 0;
frames = 0;
game.ChunkUpdates = 0;
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;
}
public override void Init() {
font = new Font(game.FontName, 16);
ContextRecreated();
game.Events.ChatFontChanged += ChatFontChanged;
gfx.ContextLost += ContextLost;
gfx.ContextRecreated += ContextRecreated;
void StatusScreen_OnResize(void) { }
void StatusScreen_ChatFontChanged(void) {
Recreate();
}
protected override void ContextLost() {
status.Dispose();
posAtlas.Dispose();
hackStates.Dispose();
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);
}
protected override void ContextRecreated() {
void StatusScreen_ContextRecreated(void) {
StatusScreen* screen = &StatusScreen_Instance;
status = new TextWidget(game, font)
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
status.ReducePadding = true;
@ -357,23 +360,31 @@ namespace ClassicalSharp.Gui.Screens{
UpdateHackState(true);
}
public override void Dispose() {
font.Dispose();
ContextLost();
void StatusScreen_Init(GuiElement* elem) {
font = new Font(game.FontName, 16);
StatusScreen_ContextRecreated();
game.Events.ChatFontChanged -= ChatFontChanged;
gfx.ContextLost -= ContextLost;
gfx.ContextRecreated -= ContextRecreated;
Event_RegisterVoid(&ChatEvents_FontChanged, StatusScreen_ChatFontChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, StatusScreen_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, StatusScreen_ContextRecreated);
}
void ChatFontChanged(object sender, EventArgs e) { Recreate(); }
void StatusScreen_Free(GuiElement* elem) {
StatusScreen* screen = (StatusScreen*)elem;
Platform_FreeFont(&screen->Font);
StatusScreen_ContextLost();
public override void OnResize(int width, int height) { }
Event_UnregisterVoid(&ChatEvents_FontChanged, StatusScreen_ChatFontChanged);
Event_UnregisterVoid(&GfxEvents_ContextLost, StatusScreen_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, StatusScreen_ContextRecreated);
}
void DrawPosition() {
int index = 0;
Texture tex = posAtlas.tex;
tex.X1 = 2; tex.Width = (ushort)posAtlas.offset;
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);
@ -393,27 +404,50 @@ namespace ClassicalSharp.Gui.Screens{
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();
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;
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 ");
UInt8 statusBuffer[String_BufferSize(STRING_SIZE * 2)];
String status = String_InitAndClearArray(statusBuffer);
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());
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;
}

View File

@ -1,3 +1,5 @@
#ifndef CC_SEARCHER_H
#define CC_SEARCHER_H
#include "Typedefs.h"
#include "Entity.h"
@ -14,3 +16,4 @@ 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);
#endif

View File

@ -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, '&');

View File

@ -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);
}

View File

@ -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))

View File

@ -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);

View File

@ -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;

View File

@ -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);\

View File

@ -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(&copy, text);
Int32 usedLines = 0, totalChars = maxPerLine * numLines;