diff --git a/misc/xbox/ps_colored.ps.cg b/misc/xbox/ps_coloured.ps.cg similarity index 100% rename from misc/xbox/ps_colored.ps.cg rename to misc/xbox/ps_coloured.ps.cg diff --git a/misc/xbox/colored_vs.cg b/misc/xbox/vs_coloured.vs.cg similarity index 84% rename from misc/xbox/colored_vs.cg rename to misc/xbox/vs_coloured.vs.cg index 9da2030ac..1a070a3e2 100644 --- a/misc/xbox/colored_vs.cg +++ b/misc/xbox/vs_coloured.vs.cg @@ -19,14 +19,14 @@ vOut main( position = float4(input.position.xyz, 1.0f); position = mul(position, mvp); - //position.xyz = position.xyz / position.w; + position.xyz = position.xyz / position.w; position.x = position.x * half_viewport.x + half_viewport.x; position.y = -position.y * half_viewport.y + half_viewport.y; position.z = position.z * half_viewport.z + half_viewport.z; - position.w = half_viewport.w; + //position.w = 1.0 / half_viewport.w; - result.col = input.color; result.pos = position; + result.col = input.color; return result; } diff --git a/misc/xbox/vs_textured_vs.cg b/misc/xbox/vs_textured.vs.cg similarity index 95% rename from misc/xbox/vs_textured_vs.cg rename to misc/xbox/vs_textured.vs.cg index 2fb019b53..c2a6f1c6f 100644 --- a/misc/xbox/vs_textured_vs.cg +++ b/misc/xbox/vs_textured.vs.cg @@ -28,8 +28,8 @@ vOut main( position.z = position.z * half_viewport.z + half_viewport.z; //position.w = 1.0 / half_viewport.w; - result.col = input.color; result.pos = position; + result.col = input.color; result.tex = input.tex; return result; } diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index 0cf94c9d2..d9bf1cac1 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -21,6 +21,7 @@ // Current format and size of vertices static int gfx_stride, gfx_format = -1; + static void LoadVertexShader(uint32_t* program, int programSize) { uint32_t* p; @@ -40,7 +41,23 @@ static void LoadVertexShader(uint32_t* program, int programSize) { } } -static void LoadFragmentShader(void) { +static uint32_t vs_coloured_program[] = { + #include "../misc/xbox/vs_coloured.inl" +}; +static uint32_t vs_textured_program[] = { + #include "../misc/xbox/vs_textured.inl" +}; + + +static void LoadFragmentShader_Coloured(void) { + uint32_t* p; + + p = pb_begin(); + #include "../misc/xbox/ps_coloured.inl" + pb_end(p); +} + +static void LoadFragmentShader_Textured(void) { uint32_t* p; p = pb_begin(); @@ -48,12 +65,6 @@ static void LoadFragmentShader(void) { pb_end(p); } -static uint32_t vs_coloured_program[] = { - #include "../misc/xbox/vs_colored.inl" -}; -static uint32_t vs_textured_program[] = { - #include "../misc/xbox/vs_textured.inl" -}; static void SetupShaders(void) { uint32_t *p; @@ -109,7 +120,7 @@ void Gfx_Create(void) { pb_show_front_screen(); SetupShaders(); - LoadFragmentShader(); + Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED); ResetState(); // 1x1 dummy white texture @@ -612,8 +623,10 @@ void Gfx_SetVertexFormat(VertexFormat fmt) { if (fmt == VERTEX_FORMAT_TEXTURED) { LoadVertexShader(vs_textured_program, sizeof(vs_textured_program)); + LoadFragmentShader_Textured(); } else { LoadVertexShader(vs_coloured_program, sizeof(vs_coloured_program)); + LoadFragmentShader_Coloured(); } } @@ -645,8 +658,6 @@ void Gfx_DrawVb_Lines(int verticesCount) { #define MAX_BATCH 120 static void DrawIndexedVertices(int verticesCount, int startVertex) { // TODO switch to indexed rendering - if (gfx_format == VERTEX_FORMAT_COLOURED) return; - // TODO REMOVE REMOVE REMOVE DrawArrays(NV097_SET_BEGIN_END_OP_QUADS, startVertex, verticesCount); } diff --git a/src/Makefile_xbox b/src/Makefile_xbox index b198d1512..fd2630662 100644 --- a/src/Makefile_xbox +++ b/src/Makefile_xbox @@ -2,7 +2,7 @@ XBE_TITLE = ClassiCube GEN_XISO = $(XBE_TITLE).iso SRCS = $(wildcard src/*.c) NXDK_DIR = /home/test/Downloads/nxdk -SHADER_OBJS = misc/xbox/vs_colored.inl misc/xbox/ps_colored.inl +SHADER_OBJS = misc/xbox/vs_coloured.inl misc/xbox/vs_textured.inl misc/xbox/ps_coloured.inl misc/xbox/ps_textured.inl NXDK_NET = y NXDK_LDFLAGS = -stack:131072 diff --git a/src/Platform.h b/src/Platform.h index a7aa7f010..2e8f4bf1a 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -8,7 +8,7 @@ Copyright 2014-2023 ClassiCube | Licensed under BSD-3 struct DateTime; enum Socket_PollMode { SOCKET_POLL_READ, SOCKET_POLL_WRITE }; -#ifdef CC_BUILD_WIN +#if defined CC_BUILD_WIN || defined CC_BUILD_XBOX typedef cc_uintptr cc_socket; typedef void* cc_file; #define _NL "\r\n" diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index 5a1e45bd5..f4963750d 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -19,8 +19,8 @@ const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION; const cc_result ReturnCode_FileNotFound = ERROR_FILE_NOT_FOUND; -const cc_result ReturnCode_SocketInProgess = WSAEINPROGRESS; -const cc_result ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK; +const cc_result ReturnCode_SocketInProgess = EINPROGRESS; +const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK; const cc_result ReturnCode_DirectoryExists = ERROR_ALREADY_EXISTS; const char* Platform_AppNameSuffix = " XBox"; @@ -306,80 +306,82 @@ static int ParseHost(union SocketAddress* addr, const char* host) { struct addrinfo hints = { 0 }; struct addrinfo* result; struct addrinfo* cur; - int family = 0, res; + int found = 0, res; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; - res = getaddrinfo(host, NULL, &hints, &result); - if (res) return 0; + res = lwip_getaddrinfo(host, NULL, &hints, &result); + if (res) return res; for (cur = result; cur; cur = cur->ai_next) { if (cur->ai_family != AF_INET) continue; - family = AF_INET; + found = true; Mem_Copy(addr, cur->ai_addr, cur->ai_addrlen); break; } - freeaddrinfo(result); - return family; + lwip_freeaddrinfo(result); + return found ? 0 : ERR_INVALID_ARGUMENT; } static int ParseAddress(union SocketAddress* addr, const cc_string* address) { char str[NATIVE_STR_LEN]; String_EncodeUtf8(str, address); - if (inet_pton(AF_INET, str, &addr->v4.sin_addr) > 0) return AF_INET; + if (inet_pton(AF_INET, str, &addr->v4.sin_addr) > 0) return 0; return ParseHost(addr, str); } int Socket_ValidAddress(const cc_string* address) { union SocketAddress addr; - return ParseAddress(&addr, address); + return ParseAddress(&addr, address) == 0; } cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) { int family, addrSize = 0; union SocketAddress addr; - cc_result res; + int res; + // TODO TODO TODO TODO TODO + // if 'addrSize = 0' is removed, then the game never gets past 'Fetching cdn.classicube.net...' + // so probably relying on undefined behaviour somewhere... - *s = -1; - if (!(family = ParseAddress(&addr, address))) - return ERR_INVALID_ARGUMENT; + *s = -1; + res = ParseAddress(&addr, address); + if (res) return res; - *s = socket(family, SOCK_STREAM, IPPROTO_TCP); + *s = lwip_socket(AF_INET, SOCK_STREAM, 0); if (*s == -1) return errno; if (nonblocking) { int blocking_raw = -1; /* non-blocking mode */ - ioctl(*s, FIONBIO, &blocking_raw); + lwip_ioctl(*s, FIONBIO, &blocking_raw); } - addr.v4.sin_family = AF_INET; - addr.v4.sin_port = htons(port); - addrSize = sizeof(addr.v4); + addr.v4.sin_family = AF_INET; + addr.v4.sin_port = htons(port); - res = connect(*s, &addr.raw, addrSize); + res = lwip_connect(*s, &addr.raw, sizeof(addr.v4)); return res == -1 ? errno : 0; } cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) { - int recvCount = recv(s, data, count, 0); + int recvCount = lwip_recv(s, data, count, 0); if (recvCount != -1) { *modified = recvCount; return 0; } *modified = 0; return errno; } cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) { - int sentCount = send(s, data, count, 0); + int sentCount = lwip_send(s, data, count, 0); if (sentCount != -1) { *modified = sentCount; return 0; } *modified = 0; return errno; } void Socket_Close(cc_socket s) { - shutdown(s, SHUT_RDWR); - close(s); + lwip_shutdown(s, SHUT_RDWR); + lwip_close(s); } static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { @@ -388,7 +390,7 @@ static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { pfd.fd = s; pfd.events = mode == SOCKET_POLL_READ ? POLLIN : POLLOUT; - if (poll(&pfd, 1, 0) == -1) { *success = false; return errno; } + if (lwip_poll(&pfd, 1, 0) == -1) { *success = false; return errno; } /* to match select, closed socket still counts as readable */ flags = mode == SOCKET_POLL_READ ? (POLLIN | POLLHUP) : POLLOUT; @@ -406,7 +408,7 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { if (res || *writable) return res; /* https://stackoverflow.com/questions/29479953/so-error-value-after-successful-socket-operation */ - getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &resultSize); + lwip_getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &resultSize); return res; } @@ -421,7 +423,7 @@ cc_result Process_StartOpen(const cc_string* args) { static void InitHDD(void) { hdd_mounted = nxMountDrive('E', "\\Device\\Harddisk0\\Partition1\\"); if (!hdd_mounted) { - Platform_LogConst("Failed to mount E:\ from Data partition"); + Platform_LogConst("Failed to mount E:/ from Data partition"); return; } Directory_Create(&String_Empty); // create root ClassiCube folder