mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Finish porting Options to C
This commit is contained in:
parent
0eec5dc504
commit
1fd71a5e64
@ -345,14 +345,14 @@ void Block_RecalculateBB(BlockID block) {
|
||||
TextureLoc texLoc = Block_GetTexLoc(block, FACE_XMAX);
|
||||
Int32 texX = texLoc & 0x0F, texY = texLoc >> 4;
|
||||
|
||||
Real32 topY = Block_GetSpriteBB_TopY(elemSize, texX, texY, bmp);
|
||||
Real32 topY = Block_GetSpriteBB_TopY(elemSize, texX, texY, bmp);
|
||||
Real32 bottomY = Block_GetSpriteBB_BottomY(elemSize, texX, texY, bmp);
|
||||
Real32 leftX = Block_GetSpriteBB_LeftX(elemSize, texX, texY, bmp);
|
||||
Real32 rightX = Block_GetSpriteBB_RightX(elemSize, texX, texY, bmp);
|
||||
Real32 leftX = Block_GetSpriteBB_LeftX(elemSize, texX, texY, bmp);
|
||||
Real32 rightX = Block_GetSpriteBB_RightX(elemSize, texX, texY, bmp);
|
||||
|
||||
Vector3 centre = Vector3_Create3(0.5f, 0, 0.5f);
|
||||
Vector3 minRaw = Vector3_RotateY3(leftX - 0.5f, bottomY, 0, 45.0f * MATH_DEG2RAD);
|
||||
Vector3 maxRaw = Vector3_RotateY3(rightX - 0.5f, topY, 0, 45.0f * MATH_DEG2RAD);
|
||||
Vector3 minRaw = Vector3_RotateY3(leftX - 0.5f, bottomY, 0, 45.0f * MATH_DEG2RAD);
|
||||
Vector3 maxRaw = Vector3_RotateY3(rightX - 0.5f, topY, 0, 45.0f * MATH_DEG2RAD);
|
||||
|
||||
Vector3_Add(&minRaw, ¢re, &Block_MinBB[block]);
|
||||
Vector3_Add(&maxRaw, ¢re, &Block_MaxBB[block]);
|
||||
|
@ -145,8 +145,8 @@ typedef void (*ChatCommandConstructor)(ChatCommand* cmd);
|
||||
|
||||
#define COMMANDS_PREFIX "/client"
|
||||
#define COMMANDS_PREFIX_SPACE "/client "
|
||||
#define Chat_AddRaw(str, raw) String str = String_FromConst(raw); Chat_Add(&str);
|
||||
|
||||
#define Command_SetName(raw) String name = String_FromConst(raw); cmd->Name = name;
|
||||
#define Command_SetHelp(Num, raw) String helpNum = String_FromConst(raw); cmd->Help[Num] = helpNum;
|
||||
ChatCommand commands_list[8];
|
||||
UInt32 commands_count;
|
||||
|
||||
@ -276,9 +276,9 @@ void HelpCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void HelpCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("Help"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client help [command name]"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&eDisplays the help for the given command."); cmd->Help[1] = help1;
|
||||
Command_SetName("Help");
|
||||
Command_SetHelp(0, "&a/client help [command name]");
|
||||
Command_SetHelp(1, "&eDisplays the help for the given command.");
|
||||
cmd->Execute = HelpCommand_Execute;
|
||||
}
|
||||
|
||||
@ -296,9 +296,9 @@ void GpuInfoCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void GpuInfoCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("GpuInfo"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client gpuinfo"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&eDisplays information about your GPU."); cmd->Help[1] = help1;
|
||||
Command_SetName("GpuInfo");
|
||||
Command_SetHelp(0, "&a/client gpuinfo");
|
||||
Command_SetHelp(1, "&eDisplays information about your GPU.");
|
||||
cmd->Execute = GpuInfoCommand_Execute;
|
||||
}
|
||||
|
||||
@ -313,12 +313,12 @@ void RenderTypeCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void RenderTypeCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("RenderType"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client rendertype [normal/legacy/legacyfast]"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&bnormal: &eDefault renderer, with all environmental effects enabled."); cmd->Help[1] = help1;
|
||||
String help2 = String_FromConst("&blegacy: &eMay be slightly slower than normal, but produces the same environmental effects."); cmd->Help[2] = help2;
|
||||
String help3 = String_FromConst("&blegacyfast: &eSacrifices clouds, fog and overhead sky for faster performance."); cmd->Help[3] = help3;
|
||||
String help4 = String_FromConst("&bnormalfast: &eSacrifices clouds, fog and overhead sky for faster performance."); cmd->Help[4] = help4;
|
||||
Command_SetName("RenderType");
|
||||
Command_SetHelp(0, "&a/client rendertype [normal/legacy/legacyfast]");
|
||||
Command_SetHelp(1, "&bnormal: &eDefault renderer, with all environmental effects enabled.");
|
||||
Command_SetHelp(2, "&blegacy: &eMay be slightly slower than normal, but produces the same environmental effects.");
|
||||
Command_SetHelp(3, "&blegacyfast: &eSacrifices clouds, fog and overhead sky for faster performance.");
|
||||
Command_SetHelp(4, "&bnormalfast: &eSacrifices clouds, fog and overhead sky for faster performance.");
|
||||
cmd->Execute = RenderTypeCommand_Execute;
|
||||
}
|
||||
|
||||
@ -338,9 +338,9 @@ void ResolutionCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void ResolutionCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("Resolution"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client resolution [width] [height]"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&ePrecisely sets the size of the rendered window."); cmd->Help[1] = help1;
|
||||
Command_SetName("Resolution");
|
||||
Command_SetHelp(0, "&a/client resolution [width] [height]");
|
||||
Command_SetHelp(1, "&ePrecisely sets the size of the rendered window.");
|
||||
cmd->Execute = ResolutionCommand_Execute;
|
||||
}
|
||||
|
||||
@ -357,10 +357,10 @@ void ModelCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void ModelCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("Model"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client model [name]"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&bnames: &echibi, chicken, creeper, human, pig, sheep"); cmd->Help[1] = help1;
|
||||
String help2 = String_FromConst("&e skeleton, spider, zombie, sitting, <numerical block id>"); cmd->Help[2] = help2;
|
||||
Command_SetName("Model");
|
||||
Command_SetHelp(0, "&a/client model [name]");
|
||||
Command_SetHelp(1, "&bnames: &echibi, chicken, creeper, human, pig, sheep");
|
||||
Command_SetHelp(2, "&e skeleton, spider, zombie, sitting, <numerical block id>")
|
||||
cmd->SingleplayerOnly = true;
|
||||
cmd->Execute = ModelCommand_Execute;
|
||||
}
|
||||
@ -462,12 +462,12 @@ void CuboidCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void CuboidCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("Cuboid"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client cuboid [block] [persist]"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&eFills the 3D rectangle between two points with [block]."); cmd->Help[1] = help1;
|
||||
String help2 = String_FromConst("&eIf no block is given, uses your currently held block."); cmd->Help[2] = help2;
|
||||
String help3 = String_FromConst("&e If persist is given and is \"yes\", then the command"); cmd->Help[3] = help3;
|
||||
String help4 = String_FromConst("&e will repeatedly cuboid, without needing to be typed in again."); cmd->Help[4] = help4;
|
||||
Command_SetName("Cuboid");
|
||||
Command_SetHelp(0, "&a/client cuboid [block] [persist]");
|
||||
Command_SetHelp(1, "&eFills the 3D rectangle between two points with [block].");
|
||||
Command_SetHelp(2, "&eIf no block is given, uses your currently held block.");
|
||||
Command_SetHelp(3, "&e If persist is given and is \"yes\", then the command");
|
||||
Command_SetHelp(4, "&e will repeatedly cuboid, without needing to be typed in again.");
|
||||
cmd->SingleplayerOnly = true;
|
||||
cmd->Execute = CuboidCommand_Execute;
|
||||
}
|
||||
@ -490,9 +490,9 @@ void TeleportCommand_Execute(STRING_PURE String* args, UInt32 argsCount) {
|
||||
}
|
||||
|
||||
void TeleportCommand_Make(ChatCommand* cmd) {
|
||||
String name = String_FromConst("TP"); cmd->Name = name;
|
||||
String help0 = String_FromConst("&a/client tp [x y z]"); cmd->Help[0] = help0;
|
||||
String help1 = String_FromConst("&eMoves you to the given coordinates."); cmd->Help[1] = help1;
|
||||
Command_SetName("TP");
|
||||
Command_SetHelp(0, "&a/client tp [x y z]");
|
||||
Command_SetHelp(1, "&eMoves you to the given coordinates.");
|
||||
cmd->SingleplayerOnly = true;
|
||||
cmd->Execute = TeleportCommand_Execute;
|
||||
}
|
||||
|
@ -18,4 +18,5 @@ void Chat_SetLogName(STRING_PURE String* name);
|
||||
void Chat_Send(STRING_PURE String* text);
|
||||
void Chat_Add(STRING_PURE String* text);
|
||||
void Chat_AddOf(STRING_PURE String* text, Int32 messageType);
|
||||
#define Chat_AddRaw(str, raw) String str = String_FromConst(raw); Chat_Add(&str);
|
||||
#endif
|
@ -3,16 +3,30 @@
|
||||
#include "ErrorHandler.h"
|
||||
#include "Utils.h"
|
||||
#include "Funcs.h"
|
||||
#include "Platform.h"
|
||||
|
||||
#define OPT_NOT_FOUND UInt32_MaxValue
|
||||
StringsBuffer Options_Changed;
|
||||
|
||||
void Options_Init(void) {
|
||||
StringsBuffer_Init(&Options_Keys);
|
||||
StringsBuffer_Init(&Options_Values);
|
||||
StringsBuffer_Init(&Options_Changed);
|
||||
}
|
||||
|
||||
void Options_Free(void) {
|
||||
StringsBuffer_Free(&Options_Keys);
|
||||
StringsBuffer_Free(&Options_Values);
|
||||
StringsBuffer_Free(&Options_Changed);
|
||||
}
|
||||
|
||||
bool Options_HasChanged(STRING_PURE String* key) {
|
||||
UInt32 i;
|
||||
for (i = 0; i < Options_Keys.Count; i++) {
|
||||
String curKey = StringsBuffer_UNSAFE_Get(&Options_Changed, i);
|
||||
if (String_CaselessEquals(&curKey, key)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UInt32 Options_Find(STRING_PURE String* key) {
|
||||
@ -95,13 +109,7 @@ void Options_Remove(UInt32 i) {
|
||||
|
||||
Int32 Options_Insert(STRING_PURE String* key, STRING_PURE String* value) {
|
||||
UInt32 i = Options_Find(key);
|
||||
if (i != OPT_NOT_FOUND) {
|
||||
Options_Remove(i);
|
||||
/* Reset Changed state for this option */
|
||||
for (; i < Array_NumElements(Options_Changed) - 1; i++) {
|
||||
Options_Changed[i] = Options_Changed[i + 1];
|
||||
}
|
||||
}
|
||||
if (i != OPT_NOT_FOUND) Options_Remove(i);
|
||||
|
||||
StringsBuffer_Add(&Options_Keys, key);
|
||||
StringsBuffer_Add(&Options_Values, value);
|
||||
@ -124,5 +132,81 @@ void Options_Set(const UInt8* keyRaw, STRING_PURE String* value) {
|
||||
} else {
|
||||
i = Options_Insert(&key, value);
|
||||
}
|
||||
if (i != OPT_NOT_FOUND) Options_Changed[i] = true;
|
||||
|
||||
if (i == OPT_NOT_FOUND || Options_HasChanged(&key)) return;
|
||||
StringsBuffer_Add(&Options_Changed, &key);
|
||||
}
|
||||
|
||||
void Options_Load(void) {
|
||||
/* Both of these are from when running from the launcher */
|
||||
Program.CleanupMainDirectory();
|
||||
|
||||
void* file = NULL;
|
||||
String path = String_FromConst("options.txt");
|
||||
ReturnCode result = Platform_FileOpen(&file, &path, true);
|
||||
|
||||
if (result == ReturnCode_FileNotFound) return;
|
||||
/* TODO: Should we just log failure to open? */
|
||||
ErrorHandler_CheckOrFail(result, "Options - Loading");
|
||||
|
||||
UInt8 lineBuffer[String_BufferSize(2048)];
|
||||
String line = String_InitAndClearArray(lineBuffer);
|
||||
Stream stream; Stream_FromFile(&stream, &file, &path);
|
||||
|
||||
/* Remove all the unchanged options */
|
||||
UInt32 i;
|
||||
for (i = Options_Keys.Count; i > 0; i--) {
|
||||
String key = StringsBuffer_UNSAFE_Get(&Options_Keys, i - 1);
|
||||
if (Options_HasChanged(&key)) continue;
|
||||
Options_Remove(i - 1);
|
||||
}
|
||||
|
||||
while (Stream_ReadLine(&stream, &line)) {
|
||||
if (line.length == 0 || line.buffer[0] == '#') continue;
|
||||
|
||||
Int32 sepIndex = String_IndexOf(&line, '=', 0);
|
||||
if (sepIndex <= 0) continue;
|
||||
String key = String_UNSAFE_Substring(&line, 0, sepIndex);
|
||||
|
||||
sepIndex++;
|
||||
if (sepIndex == line.length) continue;
|
||||
String value = String_UNSAFE_SubstringAt(&line, sepIndex);
|
||||
|
||||
if (!IsChangedOption(key)) {
|
||||
SetOption(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
result = stream.Close(&stream);
|
||||
ErrorHandler_CheckOrFail(result, "Options load - close file");
|
||||
}
|
||||
|
||||
void Options_Save(void) {
|
||||
void* file = NULL;
|
||||
String path = String_FromConst("options.txt");
|
||||
ReturnCode result = Platform_FileOpen(&file, &path, true);
|
||||
|
||||
/* TODO: Should we just log failure to save? */
|
||||
ErrorHandler_CheckOrFail(result, "Options - Saving");
|
||||
|
||||
UInt8 lineBuffer[String_BufferSize(2048)];
|
||||
String line = String_InitAndClearArray(lineBuffer);
|
||||
Stream stream; Stream_FromFile(&stream, &file, &path);
|
||||
UInt32 i;
|
||||
|
||||
for (i = 0; i < Options_Keys.Count; i++) {
|
||||
String key = StringsBuffer_UNSAFE_Get(&Options_Keys, i);
|
||||
String value = StringsBuffer_UNSAFE_Get(&Options_Values, i);
|
||||
|
||||
String_AppendString(&line, &key);
|
||||
String_Append(&line, '=');
|
||||
String_AppendString(&line, &value);
|
||||
|
||||
Stream_WriteLine(&stream, &line);
|
||||
String_Clear(&line);
|
||||
}
|
||||
|
||||
result = stream.Close(&stream);
|
||||
ErrorHandler_CheckOrFail(result, "Options save - close file");
|
||||
StringsBuffer_Free(&Options_Changed);
|
||||
}
|
@ -72,7 +72,6 @@
|
||||
|
||||
StringsBuffer Options_Keys;
|
||||
StringsBuffer Options_Values;
|
||||
bool Options_Changed[256];
|
||||
|
||||
void Options_Init(void);
|
||||
void Options_Free(void);
|
||||
@ -85,4 +84,6 @@ UInt32 Options_GetEnum(const UInt8* key, UInt32 defValue, const UInt8** names, U
|
||||
|
||||
void Options_SetInt32(const UInt8* keyRaw, Int32 value);
|
||||
void Options_Set(const UInt8* keyRaw, STRING_PURE String* value);
|
||||
void Options_Load(void);
|
||||
void Options_Save(void);
|
||||
#endif
|
@ -10,6 +10,7 @@
|
||||
extern UInt8* Platform_NewLine; /* Newline for text */
|
||||
extern UInt8 Platform_DirectorySeparator;
|
||||
extern ReturnCode ReturnCode_FileShareViolation;
|
||||
extern ReturnCode ReturnCode_FileNotFound;
|
||||
|
||||
void Platform_Init(void);
|
||||
void Platform_Free(void);
|
||||
|
@ -71,13 +71,13 @@ ReturnCode Stream_FileSeek(Stream* stream, Int32 offset, Int32 seekType) {
|
||||
|
||||
void Stream_FromFile(Stream* stream, void* file, STRING_PURE String* name) {
|
||||
Stream_SetName(stream, name);
|
||||
stream->Data = file;
|
||||
stream->Data = file;
|
||||
stream->Data2 = 0;
|
||||
|
||||
stream->Read = Stream_FileRead;
|
||||
stream->Read = Stream_FileRead;
|
||||
stream->Write = Stream_FileWrite;
|
||||
stream->Close = Stream_FileClose;
|
||||
stream->Seek = Stream_FileSeek;
|
||||
stream->Seek = Stream_FileSeek;
|
||||
}
|
||||
|
||||
ReturnCode Stream_PortionRead(Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
||||
@ -95,13 +95,13 @@ ReturnCode Stream_PortionSeek(Stream* stream, Int32 offset, Int32 seekType) { re
|
||||
|
||||
void Stream_ReadonlyPortion(Stream* stream, Stream* underlying, UInt32 len) {
|
||||
Stream_SetName(stream, &underlying->Name);
|
||||
stream->Data = underlying;
|
||||
stream->Data = underlying;
|
||||
stream->Data2 = len;
|
||||
|
||||
stream->Read = Stream_PortionRead;
|
||||
stream->Read = Stream_PortionRead;
|
||||
stream->Write = Stream_PortionWrite;
|
||||
stream->Close = Stream_PortionClose;
|
||||
stream->Seek = Stream_PortionSeek;
|
||||
stream->Seek = Stream_PortionSeek;
|
||||
}
|
||||
|
||||
|
||||
|
@ -481,6 +481,7 @@ void StringsBuffer_Free(StringsBuffer* buffer) {
|
||||
if (buffer->FlagsBufferElems > STRINGSBUFFER_FLAGS_DEF_ELEMS) {
|
||||
Platform_MemFree(buffer->FlagsBuffer);
|
||||
}
|
||||
StringsBuffer_UNSAFE_Reset(buffer);
|
||||
}
|
||||
|
||||
void StringsBuffer_UNSAFE_Reset(StringsBuffer* buffer) {
|
||||
|
@ -27,8 +27,6 @@ Texture Texture_From(GfxResourceID id, Int32 x, Int32 y, Int32 width, Int32 heig
|
||||
/* Makes an invalid texture. */
|
||||
Texture Texture_MakeInvalid(void);
|
||||
|
||||
/* Returns whether the given texture has a valid texture ID. */
|
||||
#define Texture_IsValid(tex) ((tex)->ID > 0)
|
||||
/* Renders this texture to the screen. */
|
||||
void Texture_Render(Texture* tex);
|
||||
/* Renders this texture to the screen, with the given colour as a shade. */
|
||||
|
@ -54,7 +54,7 @@ typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
|
||||
#define Int16_MinValue ((Int16)-32768)
|
||||
#define Int16_MaxValue ((Int16)32767)
|
||||
#define UInt16_MaxValue ((UInt16)65535)
|
||||
#define Int32_MinValue ((Int32)-2147483648L)
|
||||
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
|
||||
#define Int32_MaxValue ((Int32)2147483647L)
|
||||
#define UInt32_MaxValue ((UInt32)4294967295UL)
|
||||
|
||||
|
@ -17,6 +17,7 @@ HANDLE heap;
|
||||
UInt8* Platform_NewLine = "\r\n";
|
||||
UInt8 Platform_DirectorySeparator = '\\';
|
||||
ReturnCode ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION;
|
||||
ReturnCode ReturnCode_FileNotFound = ERROR_FILE_NOT_FOUND;
|
||||
|
||||
void Platform_Init(void) {
|
||||
heap = GetProcessHeap(); /* TODO: HeapCreate instead? probably not */
|
||||
|
Loading…
x
Reference in New Issue
Block a user