Vita: Fix not compiling, launcher window colours having red and blue swapped, networking not working properly

This commit is contained in:
UnknownShadow200 2023-08-19 10:40:31 +10:00
parent 8ec22586fb
commit 3be053e52e
4 changed files with 67 additions and 46 deletions

View File

@ -8,7 +8,7 @@ struct Stream;
/* Represents a packed 32 bit RGBA colour, suitable for native graphics API texture pixels. */
typedef cc_uint32 BitmapCol;
#if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID || defined CC_BUILD_PSP
#if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID || defined CC_BUILD_PSP || defined CC_BUILD_PSVITA
#define BITMAPCOLOR_R_SHIFT 0
#define BITMAPCOLOR_G_SHIFT 8
#define BITMAPCOLOR_B_SHIFT 16

View File

@ -292,26 +292,25 @@ union SocketAddress {
};
static int ParseHost(union SocketAddress* addr, const char* host) {
int rid, ret;
int rid = sceNetResolverCreate("CC resolver", NULL, 0);
if (rid < 0) return ERR_INVALID_ARGUMENT;
if ((rid = sceNetResolverCreate("CC resolver", NULL, 0)) < 0) return 0;
ret = sceNetResolverStartNtoa(rid, host, &addr->v4.sin_addr, 1 /* timeout */, 5 /* retries */, 0 /* flags */);
int ret = sceNetResolverStartNtoa(rid, host, &addr->v4.sin_addr, 1 /* timeout */, 5 /* retries */, 0 /* flags */);
sceNetResolverDestroy(rid);
return ret >= 0;
return ret;
}
static int ParseAddress(union SocketAddress* addr, const cc_string* address) {
char str[NATIVE_STR_LEN];
String_EncodeUtf8(str, address);
if (sceNetInetPton(SCE_NET_AF_INET, str, &addr->v4.sin_addr) > 0) return true;
if (sceNetInetPton(SCE_NET_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) {
@ -319,7 +318,7 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bo
int res;
*s = -1;
if (!ParseAddress(&addr, address)) return ERR_INVALID_ARGUMENT;
if ((res = ParseAddress(&addr, address))) return res;
*s = sceNetSocket("CC socket", SCE_NET_AF_INET, SCE_NET_SOCK_STREAM, SCE_NET_IPPROTO_TCP);
if (*s < 0) return *s;
@ -332,12 +331,13 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bo
addr.v4.sin_family = SCE_NET_AF_INET;
addr.v4.sin_port = sceNetHtons(port);
return sceNetConnect(*s, &addr.raw, sizeof(addr.v4));
res = sceNetConnect(*s, &addr.raw, sizeof(addr.v4));
return res;
}
cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
int recvCount = sceNetRecv(s, data, count, 0);
if (recvCount < 0) { *modified = recvCount; return 0; }
if (recvCount >= 0) { *modified = recvCount; return 0; }
*modified = 0;
return recvCount;
@ -345,7 +345,7 @@ cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* m
cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
int sentCount = sceNetSend(s, data, count, 0);
if (sentCount < 0) { *modified = sentCount; return 0; }
if (sentCount >= 0) { *modified = sentCount; return 0; }
*modified = 0;
return sentCount;

View File

@ -721,7 +721,7 @@ int SysFont_TextWidth(struct DrawTextArgs* args) {
void SysFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
interop_SysTextDraw(args, bmp, x, y, shadow);
}
#elif defined CC_BUILD_PSP
#elif defined CC_BUILD_PSP || defined CC_BUILD_PSVITA
void SysFonts_Register(const cc_string* path) { }
const cc_string* SysFonts_UNSAFE_GetDefault(void) { return &String_Empty; }

View File

@ -10,16 +10,17 @@
#include "Bitmap.h"
#include "Errors.h"
#include "ExtMath.h"
#include "Logger.h"
#include <vitasdk.h>
static cc_bool launcherMode;
struct _DisplayData DisplayInfo;
struct _WinData WindowInfo;
// no DPI scaling on Xbox
// no DPI scaling on PS Vita
int Display_ScaleX(int x) { return x; }
int Display_ScaleY(int y) { return y; }
#define BUFFER_WIDTH 960
//#define BUFFER_WIDTH 960 TODO: 1024?
#define SCREEN_WIDTH 960
#define SCREEN_HEIGHT 544
@ -62,49 +63,69 @@ void Window_Close(void) {
/*########################################################################################################################*
*----------------------------------------------------Input processing-----------------------------------------------------*
*#########################################################################################################################*/
void Window_ProcessEvents(void) {
static void HandleButtons_Launcher(int mods) {
Input_SetNonRepeatable(CCPAD_START, mods & SCE_CTRL_TRIANGLE);
Input_SetNonRepeatable(CCPAD_SELECT, mods & SCE_CTRL_SQUARE);
// fake tab with PSP_CTRL_SQUARE for Launcher too
//Input_SetNonRepeatable(IPT_TAB, mods & SCE_CTRL_SQUARE);
Input_SetNonRepeatable(CCPAD_LEFT, mods & SCE_CTRL_LEFT);
Input_SetNonRepeatable(CCPAD_RIGHT, mods & SCE_CTRL_RIGHT);
Input_SetNonRepeatable(CCPAD_UP, mods & SCE_CTRL_UP);
Input_SetNonRepeatable(CCPAD_DOWN, mods & SCE_CTRL_DOWN);
}
static void HandleButtons_Game(int mods) {
Input_SetNonRepeatable(CCPAD_A, mods & SCE_CTRL_TRIANGLE);
Input_SetNonRepeatable(CCPAD_B, mods & SCE_CTRL_SQUARE);
Input_SetNonRepeatable(CCPAD_X, mods & SCE_CTRL_CROSS);
Input_SetNonRepeatable(CCPAD_Y, mods & SCE_CTRL_CIRCLE);
Input_SetNonRepeatable(CCPAD_START, mods & SCE_CTRL_START);
Input_SetNonRepeatable(CCPAD_SELECT, mods & SCE_CTRL_SELECT);
Input_SetNonRepeatable(CCPAD_LEFT, mods & SCE_CTRL_LEFT);
Input_SetNonRepeatable(CCPAD_RIGHT, mods & SCE_CTRL_RIGHT);
Input_SetNonRepeatable(CCPAD_UP, mods & SCE_CTRL_UP);
Input_SetNonRepeatable(CCPAD_DOWN, mods & SCE_CTRL_DOWN);
Input_SetNonRepeatable(CCPAD_L, mods & SCE_CTRL_LTRIGGER);
Input_SetNonRepeatable(CCPAD_R, mods & SCE_CTRL_RTRIGGER);
}
static void ProcessCircleInput(SceCtrlData* pad, double delta) {
float scale = (delta * 60.0) / 32.0f;
int dx = pad->lx - 127;
int dy = pad->ly - 127;
if (Math_AbsI(dx) <= 8) dx = 0;
if (Math_AbsI(dy) <= 8) dy = 0;
Event_RaiseRawMove(&PointerEvents.RawMoved, dx * scale, dy * scale);
}
void Window_ProcessEvents(double delta) {
SceCtrlData pad;
/* TODO implement */
sceCtrlReadBufferPositive(0, &pad, 1);
int mods = pad.buttons;
int dx = pad.lx - 127;
int dy = pad.ly - 127;
if (Input_RawMode && (Math_AbsI(dx) > 1 || Math_AbsI(dy) > 1)) {
//Platform_Log2("RAW: %i, %i", &dx, &dy);
Event_RaiseRawMove(&PointerEvents.RawMoved, dx / 32.0f, dy / 32.0f);
if (launcherMode) {
HandleButtons_Launcher(mods);
} else {
HandleButtons_Game(mods);
}
Input_SetNonRepeatable(KeyBinds[KEYBIND_PLACE_BLOCK], mods & SCE_CTRL_LTRIGGER);
Input_SetNonRepeatable(KeyBinds[KEYBIND_DELETE_BLOCK], mods & SCE_CTRL_RTRIGGER);
Input_SetNonRepeatable(KeyBinds[KEYBIND_JUMP], mods & SCE_CTRL_TRIANGLE);
Input_SetNonRepeatable(KeyBinds[KEYBIND_CHAT], mods & SCE_CTRL_CIRCLE);
Input_SetNonRepeatable(KeyBinds[KEYBIND_INVENTORY], mods & SCE_CTRL_CROSS);
// PSP_CTRL_SQUARE
Input_SetNonRepeatable(IPT_ENTER, mods & SCE_CTRL_START);
Input_SetNonRepeatable(IPT_ESCAPE, mods & SCE_CTRL_SELECT);
// fake tab with PSP_CTRL_SQUARE for Launcher too
Input_SetNonRepeatable(IPT_TAB, mods & SCE_CTRL_SQUARE);
Input_SetNonRepeatable(KeyBinds[KEYBIND_LEFT], mods & SCE_CTRL_LEFT);
Input_SetNonRepeatable(IPT_LEFT, mods & SCE_CTRL_LEFT);
Input_SetNonRepeatable(KeyBinds[KEYBIND_RIGHT], mods & SCE_CTRL_RIGHT);
Input_SetNonRepeatable(IPT_RIGHT, mods & SCE_CTRL_RIGHT);
Input_SetNonRepeatable(KeyBinds[KEYBIND_FORWARD], mods & SCE_CTRL_UP);
Input_SetNonRepeatable(IPT_UP, mods & SCE_CTRL_UP);
Input_SetNonRepeatable(KeyBinds[KEYBIND_BACK], mods & SCE_CTRL_DOWN);
Input_SetNonRepeatable(IPT_DOWN, mods & SCE_CTRL_DOWN);
if (Input.RawMode) {
ProcessCircleInput(&pad, delta);
}
}
void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita
void Window_EnableRawMouse(void) { Input_RawMode = true; }
void Window_EnableRawMouse(void) { Input.RawMode = true; }
void Window_UpdateRawMouse(void) { }
void Window_DisableRawMouse(void) { Input_RawMode = false; }
void Window_DisableRawMouse(void) { Input.RawMode = false; }
/*########################################################################################################################*