mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 07:18:34 -04:00
Allow blocking sockets
This commit is contained in:
parent
7c92e21ce6
commit
68d8b748d2
20
src/Camera.c
20
src/Camera.c
@ -17,23 +17,23 @@ static struct RayTracer cameraClipPos;
|
||||
static Vec2 cam_rotOffset;
|
||||
static cc_bool cam_isForwardThird;
|
||||
static float cam_deltaX, cam_deltaY;
|
||||
static double last_time;
|
||||
|
||||
static void Camera_OnRawMovement(float deltaX, float deltaY) {
|
||||
cam_deltaX += deltaX; cam_deltaY += deltaY;
|
||||
}
|
||||
|
||||
void Camera_KeyLookUpdate(cc_bool up, cc_bool down, cc_bool right, cc_bool left) {
|
||||
static TimeMS last_now = 0;
|
||||
TimeMS now = DateTime_CurrentUTC_MS();
|
||||
|
||||
void Camera_KeyLookUpdate(void) {
|
||||
if (Gui.InputGrab) return;
|
||||
// divide by 25 to have reasonable sensitivity for default mouse sens
|
||||
float delta = (Camera.Sensitivity / 25.0f) * (float)(now - last_now);
|
||||
if (up) cam_deltaY -= delta;
|
||||
if (down) cam_deltaY += delta;
|
||||
if (right) cam_deltaX += delta;
|
||||
if (left) cam_deltaX -= delta;
|
||||
float delta = (Camera.Sensitivity / 25.0f) * (1000 * (Game.Time - last_time));
|
||||
|
||||
last_now = now;
|
||||
if (KeyBind_IsPressed(KEYBIND_LOOK_UP)) cam_deltaY -= delta;
|
||||
if (KeyBind_IsPressed(KEYBIND_LOOK_DOWN)) cam_deltaY += delta;
|
||||
if (KeyBind_IsPressed(KEYBIND_LOOK_LEFT)) cam_deltaX -= delta;
|
||||
if (KeyBind_IsPressed(KEYBIND_LOOK_RIGHT)) cam_deltaX += delta;
|
||||
|
||||
last_time = Game.Time;
|
||||
}
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
@ -80,5 +80,5 @@ CC_API void Camera_Register(struct Camera* camera);
|
||||
void Camera_CheckFocus(void);
|
||||
void Camera_UpdateProjection(void);
|
||||
void Camera_SetFov(int fov);
|
||||
void Camera_KeyLookUpdate(cc_bool up, cc_bool down, cc_bool right, cc_bool left);
|
||||
void Camera_KeyLookUpdate(void);
|
||||
#endif
|
||||
|
@ -490,6 +490,7 @@ static void Game_Render3D(double delta, float t) {
|
||||
|
||||
Selections_Render();
|
||||
Entities_RenderHoveredNames();
|
||||
Camera_KeyLookUpdate();
|
||||
InputHandler_Tick();
|
||||
if (!Game_HideGui) HeldBlockRenderer_Render(delta);
|
||||
}
|
||||
|
@ -774,17 +774,9 @@ void InputHandler_Tick(void) {
|
||||
if (Gui.InputGrab) return;
|
||||
|
||||
cc_bool left, middle, right;
|
||||
cc_bool look_up, look_down, look_right, look_left;
|
||||
TimeMS now = DateTime_CurrentUTC_MS();
|
||||
int delta = (int)(now - input_lastClick);
|
||||
|
||||
look_up = KeyBind_IsPressed(KEYBIND_LOOK_UP);
|
||||
look_down = KeyBind_IsPressed(KEYBIND_LOOK_DOWN);
|
||||
look_right = KeyBind_IsPressed(KEYBIND_LOOK_RIGHT);
|
||||
look_left = KeyBind_IsPressed(KEYBIND_LOOK_LEFT);
|
||||
|
||||
Camera_KeyLookUpdate(look_up, look_down, look_right, look_left);
|
||||
|
||||
if (delta < 250) return; /* 4 times per second */
|
||||
input_lastClick = now;
|
||||
|
||||
|
20
src/Menus.c
20
src/Menus.c
@ -1935,8 +1935,8 @@ static void KeyBindsScreen_Show(int bindsCount, const cc_uint8* binds, const cha
|
||||
*-----------------------------------------------ClassicKeyBindsScreen--------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void ClassicKeyBindingsScreen_Show(void) {
|
||||
static const cc_uint8 binds[10] = { KEYBIND_FORWARD, KEYBIND_BACK, KEYBIND_JUMP, KEYBIND_CHAT, KEYBIND_SET_SPAWN, KEYBIND_LEFT, KEYBIND_RIGHT, KEYBIND_INVENTORY, KEYBIND_FOG, KEYBIND_RESPAWN };
|
||||
static const char* const descs[10] = { "Forward", "Back", "Jump", "Chat", "Save location", "Left", "Right", "Build", "Toggle fog", "Load location" };
|
||||
static const cc_uint8 binds[] = { KEYBIND_FORWARD, KEYBIND_BACK, KEYBIND_JUMP, KEYBIND_CHAT, KEYBIND_SET_SPAWN, KEYBIND_LEFT, KEYBIND_RIGHT, KEYBIND_INVENTORY, KEYBIND_FOG, KEYBIND_RESPAWN };
|
||||
static const char* const descs[] = { "Forward", "Back", "Jump", "Chat", "Save location", "Left", "Right", "Build", "Toggle fog", "Load location" };
|
||||
|
||||
if (Game_ClassicHacks) {
|
||||
KeyBindsScreen_Reset(NULL, Menu_SwitchKeysClassicHacks, 260);
|
||||
@ -1966,8 +1966,8 @@ void ClassicHacksKeyBindingsScreen_Show(void) {
|
||||
*-----------------------------------------------NormalKeyBindingsScreen---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void NormalKeyBindingsScreen_Show(void) {
|
||||
static const cc_uint8 binds[12] = { KEYBIND_FORWARD, KEYBIND_BACK, KEYBIND_JUMP, KEYBIND_CHAT, KEYBIND_SET_SPAWN, KEYBIND_TABLIST, KEYBIND_LEFT, KEYBIND_RIGHT, KEYBIND_INVENTORY, KEYBIND_FOG, KEYBIND_RESPAWN, KEYBIND_SEND_CHAT };
|
||||
static const char* const descs[12] = { "Forward", "Back", "Jump", "Chat", "Set spawn", "Player list", "Left", "Right", "Inventory", "Toggle fog", "Respawn", "Send chat" };
|
||||
static const cc_uint8 binds[] = { KEYBIND_FORWARD, KEYBIND_BACK, KEYBIND_JUMP, KEYBIND_CHAT, KEYBIND_SET_SPAWN, KEYBIND_TABLIST, KEYBIND_LEFT, KEYBIND_RIGHT, KEYBIND_INVENTORY, KEYBIND_FOG, KEYBIND_RESPAWN, KEYBIND_SEND_CHAT };
|
||||
static const char* const descs[] = { "Forward", "Back", "Jump", "Chat", "Set spawn", "Player list", "Left", "Right", "Inventory", "Toggle fog", "Respawn", "Send chat" };
|
||||
|
||||
KeyBindsScreen_Reset(NULL, Menu_SwitchKeysHacks, 250);
|
||||
KeyBindsScreen_SetLayout(-140, 10, 6);
|
||||
@ -1979,8 +1979,8 @@ void NormalKeyBindingsScreen_Show(void) {
|
||||
*------------------------------------------------HacksKeyBindingsScreen---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void HacksKeyBindingsScreen_Show(void) {
|
||||
static const cc_uint8 binds[8] = { KEYBIND_SPEED, KEYBIND_NOCLIP, KEYBIND_HALF_SPEED, KEYBIND_ZOOM_SCROLL, KEYBIND_FLY, KEYBIND_FLY_UP, KEYBIND_FLY_DOWN, KEYBIND_THIRD_PERSON };
|
||||
static const char* const descs[8] = { "Speed", "Noclip", "Half speed", "Scroll zoom", "Fly", "Fly up", "Fly down", "Third person" };
|
||||
static const cc_uint8 binds[] = { KEYBIND_SPEED, KEYBIND_NOCLIP, KEYBIND_HALF_SPEED, KEYBIND_ZOOM_SCROLL, KEYBIND_FLY, KEYBIND_FLY_UP, KEYBIND_FLY_DOWN, KEYBIND_THIRD_PERSON };
|
||||
static const char* const descs[] = { "Speed", "Noclip", "Half speed", "Scroll zoom", "Fly", "Fly up", "Fly down", "Third person" };
|
||||
|
||||
KeyBindsScreen_Reset(Menu_SwitchKeysNormal, Menu_SwitchKeysOther, 260);
|
||||
KeyBindsScreen_SetLayout(-40, 10, 4);
|
||||
@ -1992,8 +1992,8 @@ void HacksKeyBindingsScreen_Show(void) {
|
||||
*------------------------------------------------OtherKeyBindingsScreen---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void OtherKeyBindingsScreen_Show(void) {
|
||||
static const cc_uint8 binds[12] = { KEYBIND_EXT_INPUT, KEYBIND_HIDE_FPS, KEYBIND_HIDE_GUI, KEYBIND_HOTBAR_SWITCH, KEYBIND_DROP_BLOCK,KEYBIND_SCREENSHOT, KEYBIND_FULLSCREEN, KEYBIND_AXIS_LINES, KEYBIND_AUTOROTATE, KEYBIND_SMOOTH_CAMERA, KEYBIND_IDOVERLAY, KEYBIND_BREAK_LIQUIDS };
|
||||
static const char* const descs[12] = { "Show ext input", "Hide FPS", "Hide gui", "Hotbar switching", "Drop block", "Screenshot", "Fullscreen", "Show axis lines", "Auto-rotate", "Smooth camera", "ID overlay", "Breakable liquids" };
|
||||
static const cc_uint8 binds[] = { KEYBIND_EXT_INPUT, KEYBIND_HIDE_FPS, KEYBIND_HIDE_GUI, KEYBIND_HOTBAR_SWITCH, KEYBIND_DROP_BLOCK,KEYBIND_SCREENSHOT, KEYBIND_FULLSCREEN, KEYBIND_AXIS_LINES, KEYBIND_AUTOROTATE, KEYBIND_SMOOTH_CAMERA, KEYBIND_IDOVERLAY, KEYBIND_BREAK_LIQUIDS };
|
||||
static const char* const descs[] = { "Show ext input", "Hide FPS", "Hide gui", "Hotbar switching", "Drop block", "Screenshot", "Fullscreen", "Show axis lines", "Auto-rotate", "Smooth camera", "ID overlay", "Breakable liquids" };
|
||||
|
||||
KeyBindsScreen_Reset(Menu_SwitchKeysHacks, Menu_SwitchKeysMouse, 260);
|
||||
KeyBindsScreen_SetLayout(-140, 10, 6);
|
||||
@ -2005,8 +2005,8 @@ void OtherKeyBindingsScreen_Show(void) {
|
||||
*------------------------------------------------MouseKeyBindingsScreen---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void MouseKeyBindingsScreen_Show(void) {
|
||||
static const cc_uint8 binds[7] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK, KEYBIND_LOOK_UP, KEYBIND_LOOK_DOWN, KEYBIND_LOOK_LEFT, KEYBIND_LOOK_RIGHT };
|
||||
static const char* const descs[7] = { "Delete block", "Pick block", "Place block", "Look Up", "Look Down", "Look Left", "Look Right" };
|
||||
static const cc_uint8 binds[] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK, KEYBIND_LOOK_UP, KEYBIND_LOOK_DOWN, KEYBIND_LOOK_LEFT, KEYBIND_LOOK_RIGHT };
|
||||
static const char* const descs[] = { "Delete block", "Pick block", "Place block", "Look Up", "Look Down", "Look Left", "Look Right" };
|
||||
|
||||
KeyBindsScreen_Reset(Menu_SwitchKeysOther, NULL, 260);
|
||||
KeyBindsScreen_SetLayout(-140, 10, 3);
|
||||
|
@ -241,8 +241,8 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable);
|
||||
/* Returns non-zero if the given address is valid for a socket to connect to */
|
||||
int Socket_ValidAddress(const cc_string* address);
|
||||
|
||||
/* Allocates a new non-blocking socket and then begins connecting to the given address:port. */
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port);
|
||||
/* Allocates a new socket and then begins connecting to the given address:port. */
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking);
|
||||
/* Attempts to read data from the given socket. */
|
||||
/* NOTE: A closed socket may set modified to 0, but still return 'success' (i.e. 0) */
|
||||
cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified);
|
||||
|
@ -354,10 +354,9 @@ int Socket_ValidAddress(const cc_string* address) {
|
||||
return ParseAddress(&addr, address);
|
||||
}
|
||||
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) {
|
||||
union SocketAddress addr;
|
||||
cc_result res;
|
||||
int flags;
|
||||
|
||||
*s = -1;
|
||||
if (!ParseAddress(&addr, address))
|
||||
@ -366,9 +365,10 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
*s = socket(AF_INET, SOCK_STREAM, 0); // https://www.3dbrew.org/wiki/SOCU:socket
|
||||
if (*s == -1) return errno;
|
||||
|
||||
// non blocking mode
|
||||
flags = fcntl(*s, F_GETFL, 0);
|
||||
if (flags >= 0) fcntl(*s, F_SETFL, flags | O_NONBLOCK);
|
||||
if (nonblocking) {
|
||||
int flags = fcntl(*s, F_GETFL, 0);
|
||||
if (flags >= 0) fcntl(*s, F_SETFL, flags | O_NONBLOCK);
|
||||
}
|
||||
|
||||
addr.v4.sin_family = AF_INET;
|
||||
addr.v4.sin_port = htons(port);
|
||||
|
@ -347,7 +347,7 @@ int Socket_ValidAddress(const cc_string* address) {
|
||||
return ParseAddress(&addr, address);
|
||||
}
|
||||
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) {
|
||||
union SocketAddress addr;
|
||||
int res;
|
||||
|
||||
@ -357,8 +357,10 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
*s = sceNetInetSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (*s < 0) return sceNetInetGetErrno();
|
||||
|
||||
int on = 1;
|
||||
sceNetInetSetsockopt(*s, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(int));
|
||||
if (nonblocking) {
|
||||
int on = 1;
|
||||
sceNetInetSetsockopt(*s, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(int));
|
||||
}
|
||||
|
||||
addr.v4.sin_family = AF_INET;
|
||||
addr.v4.sin_port = htons(port);
|
||||
|
@ -529,8 +529,8 @@ int Socket_ValidAddress(const cc_string* address) {
|
||||
return ParseAddress(&addr, address);
|
||||
}
|
||||
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
int family, addrSize = 0, blocking_raw = -1; /* non-blocking mode */
|
||||
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;
|
||||
|
||||
@ -540,7 +540,11 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
|
||||
*s = socket(family, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (*s == -1) return errno;
|
||||
ioctl(*s, FIONBIO, &blocking_raw);
|
||||
|
||||
if (nonblocking) {
|
||||
int blocking_raw = -1; /* non-blocking mode */
|
||||
ioctl(*s, FIONBIO, &blocking_raw);
|
||||
}
|
||||
|
||||
#ifdef AF_INET6
|
||||
if (family == AF_INET6) {
|
||||
|
@ -256,7 +256,7 @@ int Socket_ValidAddress(const cc_string* address) { return true; }
|
||||
|
||||
extern int interop_SocketCreate(void);
|
||||
extern int interop_SocketConnect(int sock, const char* addr, int port);
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) {
|
||||
char addr[NATIVE_STR_LEN];
|
||||
int res;
|
||||
String_EncodeUtf8(addr, address);
|
||||
|
@ -498,8 +498,7 @@ int Socket_ValidAddress(const cc_string* address) {
|
||||
return Socket_ParseAddress(&addr, &addrSize, address, 0);
|
||||
}
|
||||
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
int blockingMode = -1; /* non-blocking mode */
|
||||
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) {
|
||||
SOCKADDR_STORAGE addr;
|
||||
cc_result res;
|
||||
INT addrSize;
|
||||
@ -510,7 +509,11 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
||||
|
||||
*s = _socket(addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (*s == -1) return _WSAGetLastError();
|
||||
_ioctlsocket(*s, FIONBIO, &blockingMode);
|
||||
|
||||
if (nonblocking) {
|
||||
int blockingMode = -1; /* non-blocking mode */
|
||||
_ioctlsocket(*s, FIONBIO, &blockingMode);
|
||||
}
|
||||
|
||||
res = _connect(*s, (SOCKADDR*)&addr, addrSize);
|
||||
return res == -1 ? _WSAGetLastError() : 0;
|
||||
|
@ -283,7 +283,7 @@ static void MPConnection_BeginConnect(void) {
|
||||
Blocks.CanPlace[BLOCK_STILL_WATER] = false; Blocks.CanDelete[BLOCK_STILL_WATER] = false;
|
||||
Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
|
||||
|
||||
res = Socket_Connect(&net_socket, &Server.Address, Server.Port);
|
||||
res = Socket_Connect(&net_socket, &Server.Address, Server.Port, true);
|
||||
if (res == ERR_INVALID_ARGUMENT) {
|
||||
static const cc_string reason = String_FromConst("Invalid IP address");
|
||||
MPConnection_Fail(&reason);
|
||||
|
Loading…
x
Reference in New Issue
Block a user