mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
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:
parent
370d3f0525
commit
a74998dc13
@ -42,7 +42,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double accumulator;
|
double accumulator;
|
||||||
int frames, totalSeconds;
|
int frames;
|
||||||
|
|
||||||
void UpdateStatus(double delta) {
|
void UpdateStatus(double delta) {
|
||||||
frames++;
|
frames++;
|
||||||
@ -50,7 +50,6 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
if (accumulator < 1) return;
|
if (accumulator < 1) return;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
totalSeconds++;
|
|
||||||
int fps = (int)(frames / accumulator);
|
int fps = (int)(frames / accumulator);
|
||||||
|
|
||||||
statusBuffer.Clear()
|
statusBuffer.Clear()
|
||||||
|
@ -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)
|
#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) {
|
BlockID AutoRotate_Find(BlockID block, String* name, const UInt8* suffix) {
|
||||||
UInt8 buffer[String_BufferSize(128)];
|
UInt8 buffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
String temp = String_InitAndClear(buffer, 128);
|
String temp = String_InitAndClearArray(buffer);
|
||||||
String_AppendString(&temp, name);
|
String_AppendString(&temp, name);
|
||||||
String_AppendConst(&temp, suffix);
|
String_AppendConst(&temp, suffix);
|
||||||
|
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
#include "ServerConnection.h"
|
#include "ServerConnection.h"
|
||||||
|
|
||||||
void ChatLine_Make(ChatLine* line, STRING_TRANSIENT String* text) {
|
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);
|
String_AppendString(&dst, text);
|
||||||
line->Received = Platform_CurrentUTCTime();
|
line->Received = Platform_CurrentUTCTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt8 Chat_LogNameBuffer[String_BufferSize(STRING_SIZE)];
|
UInt8 Chat_LogNameBuffer[String_BufferSize(STRING_SIZE)];
|
||||||
String Chat_LogName = String_EmptyConstArray(Chat_LogNameBuffer);
|
String Chat_LogName = String_FromEmptyArray(Chat_LogNameBuffer);
|
||||||
Stream Chat_LogStream;
|
Stream Chat_LogStream;
|
||||||
DateTime ChatLog_LastLogDate;
|
DateTime ChatLog_LastLogDate;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ void Chat_OpenLog(DateTime* now) {
|
|||||||
UInt32 i;
|
UInt32 i;
|
||||||
for (i = 0; i < 20; i++) {
|
for (i = 0; i < 20; i++) {
|
||||||
UInt8 pathBuffer[String_BufferSize(FILENAME_SIZE)];
|
UInt8 pathBuffer[String_BufferSize(FILENAME_SIZE)];
|
||||||
String path = String_InitAndClear(pathBuffer, FILENAME_SIZE);
|
String path = String_InitAndClearArray(pathBuffer);
|
||||||
String_AppendConst(&path, "logs");
|
String_AppendConst(&path, "logs");
|
||||||
String_Append(&path, Platform_DirectorySeparator);
|
String_Append(&path, Platform_DirectorySeparator);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ void Chat_AppendLog(STRING_PURE String* text) {
|
|||||||
ChatLog_LastLogDate = now;
|
ChatLog_LastLogDate = now;
|
||||||
if (Chat_LogStream.Data == NULL) return;
|
if (Chat_LogStream.Data == NULL) return;
|
||||||
UInt8 logBuffer[String_BufferSize(STRING_SIZE * 2)];
|
UInt8 logBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
String str = String_InitAndClear(logBuffer, STRING_SIZE * 2);
|
String str = String_InitAndClearArray(logBuffer);
|
||||||
|
|
||||||
/* [HH:mm:ss] text */
|
/* [HH:mm:ss] text */
|
||||||
String_Append(&str, '['); String_AppendPaddedInt32(&str, now.Hour, 2);
|
String_Append(&str, '['); String_AppendPaddedInt32(&str, now.Hour, 2);
|
||||||
|
@ -358,7 +358,6 @@ void ChunkUpdater_BuildChunk(ChunkInfo* info, Int32* chunkUpdates) {
|
|||||||
void ChunkUpdater_QuickSort(Int32 left, Int32 right) {
|
void ChunkUpdater_QuickSort(Int32 left, Int32 right) {
|
||||||
ChunkInfo** values = MapRenderer_SortedChunks; ChunkInfo* value;
|
ChunkInfo** values = MapRenderer_SortedChunks; ChunkInfo* value;
|
||||||
Int32* keys = ChunkUpdater_Distances; Int32 key;
|
Int32* keys = ChunkUpdater_Distances; Int32 key;
|
||||||
|
|
||||||
while (left < right) {
|
while (left < right) {
|
||||||
Int32 i = left, j = right;
|
Int32 i = left, j = right;
|
||||||
Int32 pivot = keys[(i + j) / 2];
|
Int32 pivot = keys[(i + j) / 2];
|
||||||
|
@ -224,6 +224,7 @@
|
|||||||
<ClInclude Include="PickedPosRenderer.h" />
|
<ClInclude Include="PickedPosRenderer.h" />
|
||||||
<ClInclude Include="Player.h" />
|
<ClInclude Include="Player.h" />
|
||||||
<ClInclude Include="Screens.h" />
|
<ClInclude Include="Screens.h" />
|
||||||
|
<ClInclude Include="Searcher.h" />
|
||||||
<ClInclude Include="SelectionBox.h" />
|
<ClInclude Include="SelectionBox.h" />
|
||||||
<ClInclude Include="ServerConnection.h" />
|
<ClInclude Include="ServerConnection.h" />
|
||||||
<ClInclude Include="SkyboxRenderer.h" />
|
<ClInclude Include="SkyboxRenderer.h" />
|
||||||
@ -308,6 +309,7 @@
|
|||||||
<ClCompile Include="Program.c" />
|
<ClCompile Include="Program.c" />
|
||||||
<ClCompile Include="Random.c" />
|
<ClCompile Include="Random.c" />
|
||||||
<ClCompile Include="Screens.c" />
|
<ClCompile Include="Screens.c" />
|
||||||
|
<ClCompile Include="Searcher.c" />
|
||||||
<ClCompile Include="SelectionBox.c" />
|
<ClCompile Include="SelectionBox.c" />
|
||||||
<ClCompile Include="ServerConnection.c" />
|
<ClCompile Include="ServerConnection.c" />
|
||||||
<ClCompile Include="SkyboxRenderer.c" />
|
<ClCompile Include="SkyboxRenderer.c" />
|
||||||
|
@ -381,6 +381,9 @@
|
|||||||
<ClInclude Include="EntityComponents.h">
|
<ClInclude Include="EntityComponents.h">
|
||||||
<Filter>Header Files\Entities</Filter>
|
<Filter>Header Files\Entities</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Searcher.h">
|
||||||
|
<Filter>Header Files\Math</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Noise.c">
|
<ClCompile Include="Noise.c">
|
||||||
@ -596,5 +599,8 @@
|
|||||||
<ClCompile Include="Player.c">
|
<ClCompile Include="Player.c">
|
||||||
<Filter>Source Files\Entities</Filter>
|
<Filter>Source Files\Entities</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Searcher.c">
|
||||||
|
<Filter>Source Files\Math</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -52,8 +52,8 @@ void D3D9_FreeResource(GfxResourceID* resource) {
|
|||||||
*resource = NULL;
|
*resource = NULL;
|
||||||
if (refCount <= 0) return;
|
if (refCount <= 0) return;
|
||||||
|
|
||||||
UInt8 logMsgBuffer[String_BufferSize(127)];
|
UInt8 logMsgBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
String logMsg = String_InitAndClear(logMsgBuffer, 127);
|
String logMsg = String_InitAndClearArray(logMsgBuffer);
|
||||||
String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: ");
|
String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: ");
|
||||||
String_AppendInt32(&logMsg, id);
|
String_AppendInt32(&logMsg, id);
|
||||||
Platform_Log(&logMsg);
|
Platform_Log(&logMsg);
|
||||||
|
@ -142,7 +142,7 @@ void Hotkeys_Init(void) {
|
|||||||
|
|
||||||
void Hotkeys_UserRemovedHotkey(Key baseKey, UInt8 flags) {
|
void Hotkeys_UserRemovedHotkey(Key baseKey, UInt8 flags) {
|
||||||
UInt8 keyBuffer[String_BufferSize(STRING_SIZE)];
|
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_AppendConst(&key, "hotkey-"); String_AppendConst(&key, Key_Names[baseKey]);
|
||||||
String_Append(&key, '&'); String_AppendInt32(&key, flags);
|
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) {
|
void Hotkeys_UserAddedHotkey(Key baseKey, UInt8 flags, bool moreInput, STRING_PURE String* text) {
|
||||||
UInt8 keyBuffer[String_BufferSize(STRING_SIZE)];
|
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)];
|
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_AppendConst(&key, "hotkey-"); String_AppendConst(&key, Key_Names[baseKey]);
|
||||||
String_Append(&key, '&'); String_AppendInt32(&key, flags);
|
String_Append(&key, '&'); String_AppendInt32(&key, flags);
|
||||||
|
@ -137,7 +137,7 @@ bool KeyBind_IsPressed(KeyBind binding) { return Key_States[KeyBind_Keys[binding
|
|||||||
void KeyBind_Load(void) {
|
void KeyBind_Load(void) {
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
UInt8 nameBuffer[String_BufferSize(STRING_SIZE)];
|
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++) {
|
for (i = 0; i < KeyBind_Count; i++) {
|
||||||
KeyBind_MakeName(name);
|
KeyBind_MakeName(name);
|
||||||
@ -149,7 +149,7 @@ void KeyBind_Load(void) {
|
|||||||
void KeyBind_Save(void) {
|
void KeyBind_Save(void) {
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
UInt8 nameBuffer[String_BufferSize(STRING_SIZE)];
|
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++) {
|
for (i = 0; i < KeyBind_Count; i++) {
|
||||||
KeyBind_MakeName(name);
|
KeyBind_MakeName(name);
|
||||||
|
@ -109,7 +109,7 @@ Int32 Options_Insert(STRING_PURE String* key, STRING_PURE String* value) {
|
|||||||
|
|
||||||
void Options_SetInt32(const UInt8* keyRaw, Int32 value) {
|
void Options_SetInt32(const UInt8* keyRaw, Int32 value) {
|
||||||
UInt8 numBuffer[String_BufferSize(STRING_INT32CHARS)];
|
UInt8 numBuffer[String_BufferSize(STRING_INT32CHARS)];
|
||||||
String numStr = String_InitAndClear(numBuffer, STRING_INT32CHARS);
|
String numStr = String_InitAndClearArray(numBuffer);
|
||||||
String_AppendInt32(&numStr, value);
|
String_AppendInt32(&numStr, value);
|
||||||
Options_Set(keyRaw, &numStr);
|
Options_Set(keyRaw, &numStr);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ void Player_MakeNameTexture(Player* player) {
|
|||||||
player->NameTex.X = PLAYER_NAME_EMPTY_TEX;
|
player->NameTex.X = PLAYER_NAME_EMPTY_TEX;
|
||||||
} else {
|
} else {
|
||||||
UInt8 buffer[String_BufferSize(STRING_SIZE * 2)];
|
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;
|
size.Width += 3; size.Height += 3;
|
||||||
Bitmap bmp; Bitmap_AllocatePow2(&bmp, size.Width, size.Height);
|
Bitmap bmp; Bitmap_AllocatePow2(&bmp, size.Width, size.Height);
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Inventory.h"
|
#include "Inventory.h"
|
||||||
#include "Drawer2D.h"
|
#include "Drawer2D.h"
|
||||||
|
#include "GraphicsAPI.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
void Screen_FreeWidgets(Widget** widgets, UInt32 widgetsCount) {
|
void Screen_FreeWidgets(Widget** widgets, UInt32 widgetsCount) {
|
||||||
if (widgets == NULL) return;
|
if (widgets == NULL) return;
|
||||||
@ -252,92 +254,93 @@ extern Screen* InventoryScreen_UNSAFE_RawPointer = &InventoryScreen_Instance.Bas
|
|||||||
typedef struct StatusScreen_ {
|
typedef struct StatusScreen_ {
|
||||||
Screen Base;
|
Screen Base;
|
||||||
FontDesc Font;
|
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 StatusScreen_Instance;
|
||||||
|
|
||||||
namespace ClassicalSharp.Gui.Screens{
|
void StatusScreen_Render(GuiElement* elem, Real64 delta) {
|
||||||
public class StatusScreen : Screen, IGameComponent {
|
StatusScreen* screen = (StatusScreen*)elem;
|
||||||
|
StatusScreen_Update(screen, delta);
|
||||||
|
if (Game_HideGui || !Game_ShowFPS) return;
|
||||||
|
|
||||||
Font font;
|
Gfx_SetTexturing(true);
|
||||||
StringBuffer statusBuffer;
|
elem = &screen->Status.Base.Base;
|
||||||
|
elem->Render(elem, delta);
|
||||||
|
|
||||||
public StatusScreen(Game game) : base(game) {
|
if (!Game_ClassicMode && Gui_Active == NULL) {
|
||||||
statusBuffer = new StringBuffer(128);
|
StatusScreen_UpdateHackState(screen, false);
|
||||||
|
StatusScreen_DrawPosition(screen);
|
||||||
|
elem = &screen->HackStates.Base.Base;
|
||||||
|
elem->Render(elem, delta);
|
||||||
}
|
}
|
||||||
|
Gfx_SetTexturing(false);
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(Game game) { }
|
void StatusScreen_MakeText(StatusScreen* screen, STRING_TRANSIENT String* status) {
|
||||||
public void Ready(Game game) { Init(); }
|
screen->FPS = (Int32)(screen->Frames / screen->Accumulator);
|
||||||
public void Reset(Game game) { }
|
String_AppendInt32(status, screen->FPS);
|
||||||
public void OnNewMap(Game game) { }
|
String_AppendConst(status, " fps, ");
|
||||||
public void OnNewMapLoaded(Game game) { }
|
|
||||||
|
|
||||||
TextWidget status, hackStates;
|
if (Game_ClassicMode) {
|
||||||
TextAtlas posAtlas;
|
String_AppendInt32(status, Game_ChunkUpdates);
|
||||||
public override void Render(double delta) {
|
String_AppendConst(status, " chunk updates");
|
||||||
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 {
|
} else {
|
||||||
if (game.ChunkUpdates > 0) {
|
if (Game_ChunkUpdates > 0) {
|
||||||
statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, ");
|
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) {
|
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());
|
void StatusScreen_Update(StatusScreen* screen, Real64 delta) {
|
||||||
accumulator = 0;
|
screen->Frames++;
|
||||||
frames = 0;
|
screen->Accumulator += delta;
|
||||||
game.ChunkUpdates = 0;
|
if (screen->Accumulator < 1.0) return;
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init() {
|
UInt8 statusBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
font = new Font(game.FontName, 16);
|
String status = String_InitAndClearArray(statusBuffer);
|
||||||
ContextRecreated();
|
StatusScreen_MakeText(screen, &status);
|
||||||
|
|
||||||
game.Events.ChatFontChanged += ChatFontChanged;
|
TextWidget_SetText(&screen->Status, &status);
|
||||||
gfx.ContextLost += ContextLost;
|
screen->Accumulator = 0.0;
|
||||||
gfx.ContextRecreated += ContextRecreated;
|
screen->Frames = 0;
|
||||||
}
|
Game_ChunkUpdates = 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ContextLost() {
|
void StatusScreen_OnResize(void) { }
|
||||||
status.Dispose();
|
void StatusScreen_ChatFontChanged(void) {
|
||||||
posAtlas.Dispose();
|
Recreate();
|
||||||
hackStates.Dispose();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ContextRecreated() {
|
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)
|
status = new TextWidget(game, font)
|
||||||
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
|
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
|
||||||
status.ReducePadding = true;
|
status.ReducePadding = true;
|
||||||
@ -355,25 +358,33 @@ namespace ClassicalSharp.Gui.Screens{
|
|||||||
hackStates.ReducePadding = true;
|
hackStates.ReducePadding = true;
|
||||||
hackStates.Init();
|
hackStates.Init();
|
||||||
UpdateHackState(true);
|
UpdateHackState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
void StatusScreen_Init(GuiElement* elem) {
|
||||||
font.Dispose();
|
font = new Font(game.FontName, 16);
|
||||||
ContextLost();
|
StatusScreen_ContextRecreated();
|
||||||
|
|
||||||
game.Events.ChatFontChanged -= ChatFontChanged;
|
Event_RegisterVoid(&ChatEvents_FontChanged, StatusScreen_ChatFontChanged);
|
||||||
gfx.ContextLost -= ContextLost;
|
Event_RegisterVoid(&GfxEvents_ContextLost, StatusScreen_ContextLost);
|
||||||
gfx.ContextRecreated -= ContextRecreated;
|
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() {
|
void StatusScreen_DrawPosition(StatusScreen* screen) {
|
||||||
int index = 0;
|
TextAtlas* atlas = &screen->PosAtlas;
|
||||||
Texture tex = posAtlas.tex;
|
VertexP3fT2fC4b vertices[4 * 8];
|
||||||
tex.X1 = 2; tex.Width = (ushort)posAtlas.offset;
|
|
||||||
|
Texture tex = atlas->Tex; tex.X = 2; tex.Width = (UInt16)atlas->Offset;
|
||||||
|
GfxCommon_Make2DQuad(&tex, PACKEDCOL_WHITE,
|
||||||
IGraphicsApi.Make2DQuad(ref tex, FastColour.WhitePacked,
|
IGraphicsApi.Make2DQuad(ref tex, FastColour.WhitePacked,
|
||||||
game.ModelCache.vertices, ref index);
|
game.ModelCache.vertices, ref index);
|
||||||
|
|
||||||
@ -391,29 +402,52 @@ namespace ClassicalSharp.Gui.Screens{
|
|||||||
|
|
||||||
gfx.BindTexture(posAtlas.tex.ID);
|
gfx.BindTexture(posAtlas.tex.ID);
|
||||||
gfx.UpdateDynamicVb_IndexedTris(game.ModelCache.vb, game.ModelCache.vertices, index);
|
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 speeding, halfSpeeding, noclip, fly;
|
bool speed = (hacks->Speeding || hacks->HalfSpeeding) && (hacks->CanSpeed || hacks->BaseHorSpeed > 1);
|
||||||
int lastFov;
|
if (speed) String_AppendConst(&status, "Speed ON ");
|
||||||
void UpdateHackState(bool force) {
|
if (hacks->Noclip) String_AppendConst(&status, "Noclip ON ");
|
||||||
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 ")
|
TextWidget_SetText(&screen->HackStates, &status);
|
||||||
.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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
#ifndef CC_SEARCHER_H
|
||||||
|
#define CC_SEARCHER_H
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
@ -14,3 +16,4 @@ extern SearcherState* Searcher_States;
|
|||||||
UInt32 Searcher_FindReachableBlocks(Entity* entity, AABB* entityBB, AABB* entityExtentBB);
|
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_CalcTime(Vector3* vel, AABB *entityBB, AABB* blockBB, Real32* tx, Real32* ty, Real32* tz);
|
||||||
void Searcher_Free(void);
|
void Searcher_Free(void);
|
||||||
|
#endif
|
@ -10,11 +10,11 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
|
|
||||||
UInt8 ServerConnection_ServerNameBuffer[String_BufferSize(STRING_SIZE)];
|
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)];
|
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)];
|
UInt8 ServerConnection_AppNameBuffer[String_BufferSize(STRING_SIZE)];
|
||||||
String ServerConnection_AppName = String_EmptyConstArray(ServerConnection_AppNameBuffer);
|
String ServerConnection_AppName = String_FromEmptyArray(ServerConnection_AppNameBuffer);
|
||||||
Int32 ServerConnection_Ticks;
|
Int32 ServerConnection_Ticks;
|
||||||
|
|
||||||
void ServerConnection_ResetState(void) {
|
void ServerConnection_ResetState(void) {
|
||||||
@ -49,8 +49,8 @@ void SPConnection_Connect(STRING_PURE String* ip, Int32 port) {
|
|||||||
|
|
||||||
UInt8 SPConnection_LastCol = NULL;
|
UInt8 SPConnection_LastCol = NULL;
|
||||||
void SPConnection_AddChat(STRING_PURE String* text) {
|
void SPConnection_AddChat(STRING_PURE String* text) {
|
||||||
UInt8 tmpBuffer[STRING_SIZE * 2];
|
UInt8 tmpBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
String tmp = String_InitAndClear(tmpBuffer, STRING_SIZE * 2);
|
String tmp = String_InitAndClearArray(tmpBuffer);
|
||||||
/* Prepend colour codes for subsequent lines of multi-line chat */
|
/* Prepend colour codes for subsequent lines of multi-line chat */
|
||||||
if (!Drawer2D_IsWhiteCol(SPConnection_LastCol)) {
|
if (!Drawer2D_IsWhiteCol(SPConnection_LastCol)) {
|
||||||
String_Append(&tmp, '&');
|
String_Append(&tmp, '&');
|
||||||
|
@ -16,7 +16,7 @@ if (write == 0 || !ErrorHandler_Check(result)) {\
|
|||||||
|
|
||||||
void Stream_Fail(Stream* stream, ReturnCode result, const UInt8* operation) {
|
void Stream_Fail(Stream* stream, ReturnCode result, const UInt8* operation) {
|
||||||
UInt8 tmpBuffer[String_BufferSize(400)];
|
UInt8 tmpBuffer[String_BufferSize(400)];
|
||||||
String tmp = String_InitAndClear(tmpBuffer, 400);
|
String tmp = String_InitAndClearArray(tmpBuffer);
|
||||||
|
|
||||||
String_AppendConst(&tmp, "Failed ");
|
String_AppendConst(&tmp, "Failed ");
|
||||||
String_AppendConst(&tmp, operation);
|
String_AppendConst(&tmp, operation);
|
||||||
@ -50,7 +50,7 @@ Int32 Stream_TryReadByte(Stream* stream) {
|
|||||||
|
|
||||||
|
|
||||||
void Stream_SetName(Stream* stream, STRING_PURE String* name) {
|
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);
|
String_AppendString(&stream->Name, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ typedef struct String_ {
|
|||||||
String String_MakeNull(void);
|
String String_MakeNull(void);
|
||||||
String String_Init(STRING_REF UInt8* buffer, UInt16 length, UInt16 capacity);
|
String String_Init(STRING_REF UInt8* buffer, UInt16 length, UInt16 capacity);
|
||||||
String String_InitAndClear(STRING_REF UInt8* buffer, 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. */
|
/* Constructs a new string from a (maybe null terminated) buffer. */
|
||||||
String String_FromRaw(STRING_REF UInt8* buffer, UInt16 capacity);
|
String String_FromRaw(STRING_REF UInt8* buffer, UInt16 capacity);
|
||||||
/* Constructs a new string from a constant readonly buffer. */
|
/* 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. */
|
/* Constructs a new string from a compile time string constant. */
|
||||||
#define String_FromConst(text) { text, (UInt16)(sizeof(text) - 1), (UInt16)(sizeof(text) - 1)};
|
#define String_FromConst(text) { text, (UInt16)(sizeof(text) - 1), (UInt16)(sizeof(text) - 1)};
|
||||||
/* Constructs a new string from a compile time empty string buffer. */
|
/* 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 */
|
/* 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))
|
#define String_FromRawArray(buffer) String_FromRaw(buffer, (UInt16)(sizeof(buffer) - 1))
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ void Atlas1D_Make1DTexture(Int32 i, Int32 atlas1DHeight, Int32* index) {
|
|||||||
|
|
||||||
void Atlas1D_Convert2DTo1D(Int32 atlasesCount, Int32 atlas1DHeight) {
|
void Atlas1D_Convert2DTo1D(Int32 atlasesCount, Int32 atlas1DHeight) {
|
||||||
Atlas1D_Count = atlasesCount;
|
Atlas1D_Count = atlasesCount;
|
||||||
UInt8 logBuffer[String_BufferSize(127)];
|
UInt8 logBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
String log = String_InitAndClear(logBuffer, 127);
|
String log = String_InitAndClearArray(logBuffer);
|
||||||
|
|
||||||
String_AppendConst(&log, "Loaded new atlas: ");
|
String_AppendConst(&log, "Loaded new atlas: ");
|
||||||
String_AppendInt32(&log, atlasesCount);
|
String_AppendInt32(&log, atlasesCount);
|
||||||
|
@ -566,7 +566,6 @@ void TableWidget_UpdatePos(TableWidget* widget) {
|
|||||||
TableWidget_UpdateDescTexPos(widget);
|
TableWidget_UpdateDescTexPos(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TABLE_NAME_LEN 128
|
|
||||||
void TableWidget_RecreateDescTex(TableWidget* widget) {
|
void TableWidget_RecreateDescTex(TableWidget* widget) {
|
||||||
if (widget->SelectedIndex == widget->LastCreatedIndex) return;
|
if (widget->SelectedIndex == widget->LastCreatedIndex) return;
|
||||||
if (widget->ElementsCount == 0) return;
|
if (widget->ElementsCount == 0) return;
|
||||||
@ -575,8 +574,8 @@ void TableWidget_RecreateDescTex(TableWidget* widget) {
|
|||||||
Gfx_DeleteTexture(&widget->DescTex.ID);
|
Gfx_DeleteTexture(&widget->DescTex.ID);
|
||||||
if (widget->SelectedIndex == -1) return;
|
if (widget->SelectedIndex == -1) return;
|
||||||
|
|
||||||
UInt8 descBuffer[String_BufferSize(TABLE_NAME_LEN)];
|
UInt8 descBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||||
String desc = String_InitAndClear(descBuffer, TABLE_NAME_LEN);
|
String desc = String_InitAndClearArray(descBuffer);
|
||||||
BlockID block = widget->Elements[widget->SelectedIndex];
|
BlockID block = widget->Elements[widget->SelectedIndex];
|
||||||
TableWidget_MakeBlockDesc(&desc, block);
|
TableWidget_MakeBlockDesc(&desc, block);
|
||||||
|
|
||||||
@ -854,7 +853,7 @@ void SpecialInputWidget_UpdateColString(SpecialInputWidget* widget) {
|
|||||||
if (Drawer2D_Cols[i].A > 0) count++;
|
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;
|
String* buffer = &widget->ColString;
|
||||||
Int32 index = 0;
|
Int32 index = 0;
|
||||||
for (i = ' '; i <= '~'; i++) {
|
for (i = ' '; i <= '~'; i++) {
|
||||||
@ -1195,7 +1194,7 @@ void InputWidget_RemakeTexture(InputWidget* widget) {
|
|||||||
|
|
||||||
/* Colour code goes to next line */
|
/* Colour code goes to next line */
|
||||||
if (!Drawer2D_IsWhiteCol(lastCol)) {
|
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_Append(&tmp, '&'); String_Append(&tmp, lastCol);
|
||||||
String_AppendString(&tmp, &args.Text);
|
String_AppendString(&tmp, &args.Text);
|
||||||
args.Text = tmp;
|
args.Text = tmp;
|
||||||
@ -1383,7 +1382,7 @@ bool InputWidget_OtherKey(InputWidget* widget, Key key) {
|
|||||||
Int32 maxChars = widget->GetMaxLines() * widget->MaxCharsPerLine;
|
Int32 maxChars = widget->GetMaxLines() * widget->MaxCharsPerLine;
|
||||||
if (key == Key_V && widget->Text.length < maxChars) {
|
if (key == Key_V && widget->Text.length < maxChars) {
|
||||||
UInt8 textBuffer[String_BufferSize(INPUTWIDGET_MAX_LINES * STRING_SIZE)];
|
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);
|
Window_GetClipboardText(&text);
|
||||||
|
|
||||||
if (text.length == 0) return true;
|
if (text.length == 0) return true;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* TODO: These might be better off as a function. */
|
/* TODO: These might be better off as a function. */
|
||||||
#define ErrorHandler_WriteLogBody(raw_msg)\
|
#define ErrorHandler_WriteLogBody(raw_msg)\
|
||||||
UInt8 logMsgBuffer[String_BufferSize(2047)];\
|
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, "ClassicalSharp crashed.\r\n");\
|
||||||
String_AppendConst(&logMsg, "Message: ");\
|
String_AppendConst(&logMsg, "Message: ");\
|
||||||
String_AppendConst(&logMsg, raw_msg);\
|
String_AppendConst(&logMsg, raw_msg);\
|
||||||
|
@ -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. */
|
/* Need to make a copy because we mutate the characters. */
|
||||||
UInt8 copyBuffer[String_BufferSize(WORDWRAP_MAX_BUFFER_SIZE)];
|
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);
|
String_AppendString(©, text);
|
||||||
|
|
||||||
Int32 usedLines = 0, totalChars = maxPerLine * numLines;
|
Int32 usedLines = 0, totalChars = maxPerLine * numLines;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user