diff --git a/C-client-notes.md b/C-client-notes.md index 4ac9a7e6c..1f5f77262 100644 --- a/C-client-notes.md +++ b/C-client-notes.md @@ -87,5 +87,5 @@ void String_Format4(str, format, a1, a2, a3, a4); | ```%c``` | char* | ```%c``` of ```"ABCD"``` = ```ABCD``` | | ```%s``` | String | ```%s``` of ```{"ABCD", 2, 4}``` = ```AB``` | | ```%r``` | char, raw | ```%r``` of ```47``` = ```\``` | -| ```%x``` | UInt64, hex | ```%x``` of ```31``` = ```2F``` | -| ```%y``` | UInt32, hex | ```%y``` of ```11``` = ```B``` | +| ```%x``` | UIntPtr, hex | ```%x``` of ```31``` = ```2F``` | +| ```%h``` | UInt32, hex | ```%h``` of ```11``` = ```B``` | diff --git a/src/AsyncDownloader.c b/src/AsyncDownloader.c index 107846715..7c4c6aa3f 100644 --- a/src/AsyncDownloader.c +++ b/src/AsyncDownloader.c @@ -205,7 +205,7 @@ static void AsyncDownloader_ProcessRequest(struct AsyncRequest* request) { if (request->ResultData) { UInt32 size = request->ResultSize; - UInt64 addr = (UInt64)request->ResultData; + UIntPtr addr = (UIntPtr)request->ResultData; Platform_Log2("HTTP returned data: %i bytes at %x", &size, &addr); } } diff --git a/src/Chat.c b/src/Chat.c index f88e746f8..812974469 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -142,10 +142,10 @@ static void Chat_AppendLog(const String* text) { } void Chat_LogError(ReturnCode result, const char* place) { - Chat_Add4("&cError %y when %c", &result, place, NULL, NULL); + Chat_Add4("&cError %h when %c", &result, place, NULL, NULL); } void Chat_LogError2(ReturnCode result, const char* place, const String* path) { - Chat_Add4("&cError %y when %c '%s'", &result, place, path, NULL); + Chat_Add4("&cError %h when %c '%s'", &result, place, path, NULL); } void Chat_Add1(const char* format, const void* a1) { Chat_Add4(format, a1, NULL, NULL, NULL); diff --git a/src/Core.h b/src/Core.h index 3c57f40eb..101b2e2c8 100644 --- a/src/Core.h +++ b/src/Core.h @@ -9,6 +9,11 @@ typedef unsigned __int8 UInt8; typedef unsigned __int16 UInt16; typedef unsigned __int32 UInt32; typedef unsigned __int64 UInt64; +#ifdef _WIN64 +typedef unsigned __int64 UIntPtr; +#else +typedef unsigned int UIntPtr; +#endif typedef signed __int8 Int8; typedef signed __int16 Int16; @@ -21,6 +26,7 @@ typedef uint8_t UInt8; typedef uint16_t UInt16; typedef uint32_t UInt32; typedef uint64_t UInt64; +typedef uintptr_t UIntPtr; typedef int8_t Int8; typedef int16_t Int16; diff --git a/src/D3D9Api.c b/src/D3D9Api.c index 07f32797b..364a7620a 100644 --- a/src/D3D9Api.c +++ b/src/D3D9Api.c @@ -53,7 +53,7 @@ static void D3D9_FreeResource(GfxResourceID* resource) { *resource = NULL; if (refCount <= 0) return; - UInt64 addr = (UInt64)(unk); + UIntPtr addr = (UIntPtr)unk; Platform_Log2("D3D9 resource has %i outstanding references! ID 0x%x", &refCount, &addr); } diff --git a/src/Entity.c b/src/Entity.c index 5a292cc5d..e8faac4de 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -142,7 +142,7 @@ void Entity_SetModel(struct Entity* e, const String* model) { name = String_FromReadonly("humanoid"); e->ModelScale = Vector3_Create1(2.0f); } - e->ModelIsSheepNoFur = String_CaselessEqualsConst(&name, "sheep_nofur"); + e->_ModelIsSheepNoFur = String_CaselessEqualsConst(&name, "sheep_nofur"); e->ModelBlock = BLOCK_AIR; e->Model = ModelCache_Get(&name); diff --git a/src/Entity.h b/src/Entity.h index 3bacf510c..30122b18d 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -74,7 +74,7 @@ struct Entity { struct Model* Model; BlockID ModelBlock; /* BlockID, if model name was originally a vaid block id. */ - bool ModelIsSheepNoFur; /* Hacky, but only sheep model relies on model name. So use just 1 byte. */ + bool _ModelIsSheepNoFur; /* Hacky, but only sheep model relies on model name. So use just 1 byte. */ struct AABB ModelAABB; Vector3 ModelScale, Size; float StepSize; diff --git a/src/ErrorHandler.c b/src/ErrorHandler.c index bf8cd6fae..111a4b584 100644 --- a/src/ErrorHandler.c +++ b/src/ErrorHandler.c @@ -16,7 +16,7 @@ static void ErrorHandler_DumpCommon(String* str, void* ctx); #include #include -struct StackPointers { UInt64 Instruction, Frame, Stack; }; +struct StackPointers { UIntPtr Instruction, Frame, Stack; }; struct SymbolAndName { IMAGEHLP_SYMBOL Symbol; char Name[256]; }; @@ -70,7 +70,7 @@ static Int32 ErrorHandler_GetFrames(CONTEXT* ctx, struct StackPointers* pointers static BOOL CALLBACK ErrorHandler_DumpModule(const char* name, ULONG_PTR base, ULONG size, void* ctx) { char buffer[STRING_SIZE * 4]; String str = String_FromArray(buffer); - DWORD64 start = base, end = base + (size - 1); + UIntPtr start = base, end = base + (size - 1); String_Format3(&str, "%c = %x-%x\r\n", name, &start, &end); ErrorHandler_Log(&str); @@ -88,7 +88,7 @@ static void ErrorHandler_Backtrace(String* backtrace, void* ctx) { for (i = 0; i < frames; i++) { Int32 number = i + 1; - UInt64 addr = (UInt64)pointers[i].Instruction; + UIntPtr addr = pointers[i].Instruction; char strBuffer[STRING_SIZE * 10]; String str = String_FromArray(strBuffer); @@ -141,9 +141,9 @@ static void ErrorHandler_DumpRegisters(CONTEXT* ctx) { String_AppendConst(&str, "-- registers --\r\n"); #ifdef _M_IX86 - String_Format3(&str, "eax=%y ebx=%y ecx=%y\r\n", &ctx->Eax, &ctx->Ebx, &ctx->Ecx); - String_Format3(&str, "edx=%y esi=%y edi=%y\r\n", &ctx->Edx, &ctx->Esi, &ctx->Edi); - String_Format3(&str, "eip=%y ebp=%y esp=%y\r\n", &ctx->Eip, &ctx->Ebp, &ctx->Esp); + String_Format3(&str, "eax=%x ebx=%x ecx=%x\r\n", &ctx->Eax, &ctx->Ebx, &ctx->Ecx); + String_Format3(&str, "edx=%x esi=%x edi=%x\r\n", &ctx->Edx, &ctx->Esi, &ctx->Edi); + String_Format3(&str, "eip=%x ebp=%x esp=%x\r\n", &ctx->Eip, &ctx->Ebp, &ctx->Esp); #elif _M_X64 String_Format3(&str, "rax=%x rbx=%x rcx=%x\r\n", &ctx->Rax, &ctx->Rbx, &ctx->Rcx); String_Format3(&str, "rdx=%x rsi=%x rdi=%x\r\n", &ctx->Rdx, &ctx->Rsi, &ctx->Rdi); @@ -177,9 +177,9 @@ static LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInf char msgBuffer[STRING_SIZE * 2 + 1]; String msg = String_NT_Array(msgBuffer); - UInt32 code = (UInt32)pInfo->ExceptionRecord->ExceptionCode; - UInt64 addr = (UInt64)pInfo->ExceptionRecord->ExceptionAddress; - String_Format2(&msg, "Unhandled exception 0x%y at 0x%x", &code, &addr); + UInt32 code = (UInt32)pInfo->ExceptionRecord->ExceptionCode; + UIntPtr addr = (UIntPtr)pInfo->ExceptionRecord->ExceptionAddress; + String_Format2(&msg, "Unhandled exception 0x%h at 0x%x", &code, &addr); msg.buffer[msg.length] = '\0'; ErrorHandler_DumpRegisters(pInfo->ContextRecord); @@ -490,7 +490,7 @@ static void ErrorHandler_Backtrace(String* backtrace_, void* ctx) { for (i = 0; i < frames; i++) { Int32 number = i + 1; - UInt64 addr = (UInt64)addrs[i]; + UIntPtr addr = (UIntPtr)addrs[i]; char strBuffer[STRING_SIZE * 5]; String str = String_FromArray(strBuffer); @@ -520,9 +520,9 @@ static void ErrorHandler_DumpRegisters(void* ctx) { /* TODO: There must be a better way of getting these.. */ #ifdef __i386__ - String_Format3(&str, "eax=%y ebx=%y ecx=%y\n", &r.gregs[11], &r.gregs[8], &r.gregs[10]); - String_Format3(&str, "edx=%y esi=%y edi=%y\n", &r.gregs[9], &r.gregs[5], &r.gregs[4]); - String_Format3(&str, "eip=%y ebp=%y esp=%y\n", &r.gregs[14], &r.gregs[6], &r.gregs[7]); + String_Format3(&str, "eax=%x ebx=%x ecx=%x\n", &r.gregs[11], &r.gregs[8], &r.gregs[10]); + String_Format3(&str, "edx=%x esi=%x edi=%x\n", &r.gregs[9], &r.gregs[5], &r.gregs[4]); + String_Format3(&str, "eip=%x ebp=%x esp=%x\n", &r.gregs[14], &r.gregs[6], &r.gregs[7]); #elif __x86_64__ String_Format3(&str, "rax=%x rbx=%x rcx=%x\n", &r.gregs[13], &r.gregs[11], &r.gregs[14]); String_Format3(&str, "rdx=%x rsi=%x rdi=%x\n", &r.gregs[12], &r.gregs[9], &r.gregs[8]); @@ -576,8 +576,8 @@ static void ErrorHandler_SignalHandler(int sig, siginfo_t* info, void* ctx) { char msgBuffer[STRING_SIZE * 2 + 1]; String msg = String_NT_Array(msgBuffer); - Int32 type = info->si_signo, code = info->si_code; - UInt64 addr = (UInt64)info->si_addr; + Int32 type = info->si_signo, code = info->si_code; + UIntPtr addr = (UIntPtr)info->si_addr; String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr); msg.buffer[msg.length] = '\0'; @@ -638,9 +638,9 @@ static void ErrorHandler_FailCommon(ReturnCode result, const char* raw_msg, void char msgBuffer[3070 + 1]; String msg = String_NT_Array(msgBuffer); - String_Format3(&msg, "ClassiCube crashed.%cMessge: %c%c", Platform_NewLine, raw_msg, Platform_NewLine); + String_Format3(&msg, "ClassiCube crashed.%cMessage: %c%c", Platform_NewLine, raw_msg, Platform_NewLine); if (result) { - String_Format2(&msg, "%y%c", &result, Platform_NewLine); + String_Format2(&msg, "%h%c", &result, Platform_NewLine); } else { result = 1; } ErrorHandler_Log(&msg); diff --git a/src/HeldBlockRenderer.c b/src/HeldBlockRenderer.c index 06dbe58ea..bed805cca 100644 --- a/src/HeldBlockRenderer.c +++ b/src/HeldBlockRenderer.c @@ -35,7 +35,8 @@ static void HeldBlockRenderer_RenderModel(void) { Model_RenderArm(model, &held_entity); Gfx_SetAlphaTest(false); } else { - String name = String_FromConst("block"); model = ModelCache_Get(&name); + String block = String_FromConst("block"); + model = ModelCache_Get(&block); held_entity.ModelScale = Vector3_Create1(0.4f); GfxCommon_SetupAlphaState(Block_Draw[held_block]); diff --git a/src/ModelCache.c b/src/ModelCache.c index 10d0b1100..464252f0e 100644 --- a/src/ModelCache.c +++ b/src/ModelCache.c @@ -454,7 +454,7 @@ static void SheepModel_DrawModel(struct Entity* entity) { Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &Sheep_RightLegBack, false); Model_UpdateVB(); - if (entity->ModelIsSheepNoFur) return; + if (entity->_ModelIsSheepNoFur) return; Gfx_BindTexture(ModelCache_Textures[fur_Index].TexID); Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &Fur_Head, true); diff --git a/src/NixWindow.c b/src/NixWindow.c index 00ce62802..7e964294b 100644 --- a/src/NixWindow.c +++ b/src/NixWindow.c @@ -192,8 +192,8 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, const String* ti win_rootWin = DisplayDevice_Meta[2]; /* Open a display connection to the X server, and obtain the screen and root window */ - UInt64 addr = (UInt64)win_display; - Platform_Log3("Display: %y, Screen %i, Root window: %y", &addr, &win_screen, &win_rootWin); + UIntPtr addr = (UIntPtr)win_display; + Platform_Log3("Display: %x, Screen %i, Root window: %h", &addr, &win_screen, &win_rootWin); Window_RegisterAtoms(); win_visual = GLContext_SelectVisual(mode); diff --git a/src/Platform.h b/src/Platform.h index 29ef31666..639ca5e66 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -10,7 +10,7 @@ struct AsyncRequest; enum SOCKET_SELECT { SOCKET_SELECT_READ, SOCKET_SELECT_WRITE }; #if CC_BUILD_WIN -typedef void* SocketPtr; +typedef UIntPtr SocketPtr; #else typedef Int32 SocketPtr; #endif diff --git a/src/String.c b/src/String.c index ce2f5705c..8973a6373 100644 --- a/src/String.c +++ b/src/String.c @@ -226,7 +226,7 @@ bool String_AppendReal32(String* str, float num, Int32 fracDigits) { return true; } -bool String_Hex32(String* str, UInt32 value) { +NOINLINE_ static bool String_Hex32(String* str, UInt32 value) { char hex[9]; hex[8] = '\0'; Int32 i; @@ -239,7 +239,7 @@ bool String_Hex32(String* str, UInt32 value) { return String_AppendConst(str, hex); } -bool String_Hex64(String* str, UInt64 value) { +NOINLINE_ static bool String_Hex64(String* str, UInt64 value) { char hex[17]; hex[16] = '\0'; Int32 i; @@ -450,8 +450,12 @@ void String_Format4(String* str, const char* format, const void* a1, const void* case 'r': String_Append(str, *((char*)arg)); break; case 'x': - String_Hex64(str, *((UInt64*)arg)); break; - case 'y': + if (sizeof(UIntPtr) == 4) { + String_Hex32(str, *((UInt32*)arg)); break; + } else { + String_Hex64(str, *((UInt64*)arg)); break; + } + case 'h': String_Hex32(str, *((UInt32*)arg)); break; default: ErrorHandler_Fail("Invalid type for string format"); diff --git a/src/String.h b/src/String.h index 5d043e226..5b7f5e27a 100644 --- a/src/String.h +++ b/src/String.h @@ -58,8 +58,6 @@ NOINLINE_ bool String_AppendInt32(String* str, Int32 num); NOINLINE_ bool String_AppendUInt32(String* str, UInt32 num); NOINLINE_ bool String_AppendUInt64(String* str, UInt64 num); NOINLINE_ bool String_AppendReal32(String* str, float num, Int32 fracDigits); /* TODO: Need to account for , or . for decimal */ -NOINLINE_ bool String_Hex32(String* str, UInt32 value); -NOINLINE_ bool String_Hex64(String* str, UInt64 value); NOINLINE_ bool String_AppendConst(String* str, const char* src); NOINLINE_ bool String_AppendString(String* str, const String* src); NOINLINE_ bool String_AppendColorless(String* str, const String* src);