mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
Rewrite some more functions
This commit is contained in:
parent
495dc85669
commit
a880feddc8
@ -11,7 +11,6 @@
|
|||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -23,7 +22,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* Unfortunately, errno constants are different in some older emscripten versions */
|
/* Unfortunately, errno constants are different in some older emscripten versions */
|
||||||
/* (linux errno compared to WASI errno) */
|
/* (linux errno numbers compared to WASI errno numbers) */
|
||||||
/* So just use the same numbers as interop_web.js (otherwise connecting always fail) */
|
/* So just use the same numbers as interop_web.js (otherwise connecting always fail) */
|
||||||
#define _EINPROGRESS 26
|
#define _EINPROGRESS 26
|
||||||
#define _EAGAIN 6 /* same as EWOULDBLOCK */
|
#define _EAGAIN 6 /* same as EWOULDBLOCK */
|
||||||
@ -85,18 +84,9 @@ TimeMS DateTime_CurrentUTC_MS(void) {
|
|||||||
return UnixTime_TotalMS(cur);
|
return UnixTime_TotalMS(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void interop_GetLocalTime(struct DateTime* t);
|
||||||
void DateTime_CurrentLocal(struct DateTime* t) {
|
void DateTime_CurrentLocal(struct DateTime* t) {
|
||||||
struct timeval cur;
|
interop_GetLocalTime(t);
|
||||||
struct tm loc_time;
|
|
||||||
gettimeofday(&cur, NULL);
|
|
||||||
localtime_r(&cur.tv_sec, &loc_time);
|
|
||||||
|
|
||||||
t->year = loc_time.tm_year + 1900;
|
|
||||||
t->month = loc_time.tm_mon + 1;
|
|
||||||
t->day = loc_time.tm_mday;
|
|
||||||
t->hour = loc_time.tm_hour;
|
|
||||||
t->minute = loc_time.tm_min;
|
|
||||||
t->second = loc_time.tm_sec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_uint64 Stopwatch_Measure(void) {
|
cc_uint64 Stopwatch_Measure(void) {
|
||||||
@ -116,11 +106,11 @@ cc_result Directory_Create(const cc_string* path) {
|
|||||||
return mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
|
return mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int interop_FileExists(const char* path);
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
char str[NATIVE_STR_LEN];
|
char str[NATIVE_STR_LEN];
|
||||||
struct stat sb;
|
|
||||||
Platform_EncodeUtf8(str, path);
|
Platform_EncodeUtf8(str, path);
|
||||||
return stat(str, &sb) == 0 && S_ISREG(sb.st_mode);
|
return interop_FileExists(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
|
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
|
||||||
@ -248,15 +238,7 @@ void Platform_LoadSysFonts(void) { }
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Socket----------------------------------------------------------*
|
*---------------------------------------------------------Socket----------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
extern int interop_SocketCreate(void);
|
|
||||||
extern int interop_SocketConnect(int sock, const char* addr, int port);
|
|
||||||
extern int interop_SocketClose(int sock);
|
|
||||||
extern int interop_SocketSend(int sock, const void* data, int len);
|
|
||||||
extern int interop_SocketRecv(int sock, void* data, int len);
|
|
||||||
extern int interop_SocketGetPending(int sock);
|
extern int interop_SocketGetPending(int sock);
|
||||||
extern int interop_SocketGetError(int sock);
|
|
||||||
extern int interop_SocketPoll(int sock);
|
|
||||||
|
|
||||||
cc_result Socket_Available(cc_socket s, int* available) {
|
cc_result Socket_Available(cc_socket s, int* available) {
|
||||||
int res = interop_SocketGetPending(s);
|
int res = interop_SocketGetPending(s);
|
||||||
/* returned result is negative for error */
|
/* returned result is negative for error */
|
||||||
@ -268,6 +250,7 @@ cc_result Socket_Available(cc_socket s, int* available) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int interop_SocketGetError(int sock);
|
||||||
cc_result Socket_GetError(cc_socket s, cc_result* result) {
|
cc_result Socket_GetError(cc_socket s, cc_result* result) {
|
||||||
int res = interop_SocketGetError(s);
|
int res = interop_SocketGetError(s);
|
||||||
/* returned result is negative for error */
|
/* returned result is negative for error */
|
||||||
@ -280,6 +263,8 @@ cc_result Socket_GetError(cc_socket s, cc_result* result) {
|
|||||||
}
|
}
|
||||||
int Socket_ValidAddress(const cc_string* address) { return true; }
|
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) {
|
||||||
char addr[NATIVE_STR_LEN];
|
char addr[NATIVE_STR_LEN];
|
||||||
int res;
|
int res;
|
||||||
@ -294,6 +279,7 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int interop_SocketRecv(int sock, void* data, int len);
|
||||||
cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
|
cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
|
||||||
/* recv only reads one WebSocket frame at most, hence call it multiple times */
|
/* recv only reads one WebSocket frame at most, hence call it multiple times */
|
||||||
int res; *modified = 0;
|
int res; *modified = 0;
|
||||||
@ -314,6 +300,7 @@ cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* m
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int interop_SocketSend(int sock, const void* data, int len);
|
||||||
cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
|
cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) {
|
||||||
/* returned result is negative for error */
|
/* returned result is negative for error */
|
||||||
int res = interop_SocketSend(s, data, count);
|
int res = interop_SocketSend(s, data, count);
|
||||||
@ -325,11 +312,13 @@ cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int interop_SocketClose(int sock);
|
||||||
cc_result Socket_Close(cc_socket s) {
|
cc_result Socket_Close(cc_socket s) {
|
||||||
/* returned result is negative for error */
|
/* returned result is negative for error */
|
||||||
return -interop_SocketClose(s);
|
return -interop_SocketClose(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int interop_SocketPoll(int sock);
|
||||||
cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) {
|
||||||
/* returned result is negative for error */
|
/* returned result is negative for error */
|
||||||
int res = interop_SocketPoll(s), flags;
|
int res = interop_SocketPoll(s), flags;
|
||||||
|
@ -21,7 +21,7 @@ mergeInto(LibraryManager.library, {
|
|||||||
elem.click();
|
elem.click();
|
||||||
document.body.removeChild(elem);
|
document.body.removeChild(elem);
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
interop_TakeScreenshot: function(path) {
|
interop_TakeScreenshot: function(path) {
|
||||||
var name = UTF8ToString(path);
|
var name = UTF8ToString(path);
|
||||||
@ -104,6 +104,27 @@ mergeInto(LibraryManager.library, {
|
|||||||
|
|
||||||
//########################################################################################################################
|
//########################################################################################################################
|
||||||
//---------------------------------------------------------Platform-------------------------------------------------------
|
//---------------------------------------------------------Platform-------------------------------------------------------
|
||||||
|
//########################################################################################################################
|
||||||
|
interop_OpenTab: function(url) {
|
||||||
|
window.open(UTF8ToString(url));
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
interop_Log: function(msg, len) {
|
||||||
|
Module.print(UTF8ArrayToString(HEAPU8, msg, len));
|
||||||
|
},
|
||||||
|
interop_GetLocalTime: function(time) {
|
||||||
|
var date = new Date();
|
||||||
|
HEAP32[(time|0 + 0)>>2] = date.getFullYear();
|
||||||
|
HEAP32[(time|0 + 4)>>2] = date.getMonth() + 1|0;
|
||||||
|
HEAP32[(time|0 + 8)>>2] = date.getDay();
|
||||||
|
HEAP32[(time|0 + 12)>>2] = date.getHours();
|
||||||
|
HEAP32[(time|0 + 16)>>2] = date.getMinutes();
|
||||||
|
HEAP32[(time|0 + 20)>>2] = date.getSeconds();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
//########################################################################################################################
|
||||||
|
//--------------------------------------------------------Filesystem------------------------------------------------------
|
||||||
//########################################################################################################################
|
//########################################################################################################################
|
||||||
interop_GetIndexedDBError: function(buffer) {
|
interop_GetIndexedDBError: function(buffer) {
|
||||||
if (window.cc_idbErr) stringToUTF8(window.cc_idbErr, buffer, 64);
|
if (window.cc_idbErr) stringToUTF8(window.cc_idbErr, buffer, 64);
|
||||||
@ -116,14 +137,18 @@ mergeInto(LibraryManager.library, {
|
|||||||
ccall('Platform_LogError', 'void', ['string'], [' &c' + err]);
|
ccall('Platform_LogError', 'void', ['string'], [' &c' + err]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
interop_OpenTab: function(url) {
|
interop_FileExists: function (raw) {
|
||||||
window.open(UTF8ToString(url));
|
var path = UTF8ToString(raw);
|
||||||
return 0;
|
try {
|
||||||
|
var lookup = FS.lookupPath(path, { follow: true });
|
||||||
|
if (!lookup.node) return false;
|
||||||
|
} catch (e) {
|
||||||
|
if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
interop_Log: function(msg, len) {
|
|
||||||
Module.print(UTF8ArrayToString(HEAPU8, msg, len));
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
//########################################################################################################################
|
//########################################################################################################################
|
||||||
//---------------------------------------------------------Sockets--------------------------------------------------------
|
//---------------------------------------------------------Sockets--------------------------------------------------------
|
||||||
@ -195,8 +220,6 @@ mergeInto(LibraryManager.library, {
|
|||||||
// always "fail" in non-blocking mode
|
// always "fail" in non-blocking mode
|
||||||
return SOCKETS.EINPROGRESS;
|
return SOCKETS.EINPROGRESS;
|
||||||
},
|
},
|
||||||
interop_SocketClose: function(sock) {
|
|
||||||
return SOCKETS.close(sock);
|
|
||||||
interop_SocketClose: function(sockFD) {
|
interop_SocketClose: function(sockFD) {
|
||||||
var sock = SOCKETS.sockets[sockFD];
|
var sock = SOCKETS.sockets[sockFD];
|
||||||
if (!sock) return SOCKETS.EBADF;
|
if (!sock) return SOCKETS.EBADF;
|
||||||
@ -295,8 +318,8 @@ mergeInto(LibraryManager.library, {
|
|||||||
//########################################################################################################################
|
//########################################################################################################################
|
||||||
//----------------------------------------------------------Window--------------------------------------------------------
|
//----------------------------------------------------------Window--------------------------------------------------------
|
||||||
//########################################################################################################################
|
//########################################################################################################################
|
||||||
interop_CanvasWidth: function() { return Module['canvas'].width },
|
interop_CanvasWidth: function() { return Module['canvas'].width; },
|
||||||
interop_CanvasHeight: function() { return Module['canvas'].height },
|
interop_CanvasHeight: function() { return Module['canvas'].height; },
|
||||||
interop_ScreenWidth: function() { return screen.width; },
|
interop_ScreenWidth: function() { return screen.width; },
|
||||||
interop_ScreenHeight: function() { return screen.height; },
|
interop_ScreenHeight: function() { return screen.height; },
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user