PSP networking matches linux now.
This commit is contained in:
+38
-25
@@ -29,33 +29,49 @@
|
||||
engine_t ENGINE;
|
||||
entityid_t phBoxEnt;
|
||||
componentid_t phBoxPhys;
|
||||
float_t disconnectTime = FLT_MAX;
|
||||
|
||||
float_t onlineSwapTime = FLT_MAX;
|
||||
|
||||
void goOnline();
|
||||
void goOffline();
|
||||
|
||||
void onNetworkConnected(void *user) {
|
||||
disconnectTime = TIME.time + 3.0f;
|
||||
printf("Network connected, I will disconnect at: %.2f1.\n", disconnectTime);
|
||||
// networkHTTPRequest(
|
||||
// "http://10.0.0.94:3000/test",
|
||||
// NETWORK_HTTP_REQUEST_METHOD_GET,
|
||||
// NULL, NULL, 0, NULL,
|
||||
// onTestResponse,
|
||||
// onTestError
|
||||
// );
|
||||
onlineSwapTime = TIME.time + 3.0f;
|
||||
printf("Network connected, I will disconnect at: %.2f1.\n", onlineSwapTime);
|
||||
}
|
||||
|
||||
void onNetworkFailed(errorret_t error, void *user) {
|
||||
printf("Network connection failed: %s\n", error.state->message);
|
||||
onlineSwapTime = TIME.time + 3.0f;
|
||||
printf("Failed to connect to network, will try again at %.2f1.\n", onlineSwapTime);
|
||||
}
|
||||
|
||||
void onNetworkDisconnected(errorret_t error, void *user) {
|
||||
printf("Network disconnected.\n");
|
||||
onlineSwapTime = TIME.time + 3.0f;
|
||||
printf("Network disconnected, will go online at %.2f1.\n", onlineSwapTime);
|
||||
errorCatch(errorPrint(error));
|
||||
}
|
||||
|
||||
void onNetworkDisconnectFinished(void *user) {
|
||||
printf("Finished disconnecting from network.\n");
|
||||
onlineSwapTime = TIME.time + 3.0f;
|
||||
printf("Finished disconnecting from network, will go online at %.2f1.\n", onlineSwapTime);
|
||||
}
|
||||
|
||||
void goOnline() {
|
||||
printf("Going online...\n");
|
||||
networkRequestConnection(
|
||||
onNetworkConnected,
|
||||
onNetworkFailed,
|
||||
onNetworkDisconnected,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
void goOffline() {
|
||||
printf("Going offline...\n");
|
||||
networkRequestDisconnection(onNetworkDisconnectFinished, NULL);
|
||||
}
|
||||
|
||||
|
||||
errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
memoryZero(&ENGINE, sizeof(engine_t));
|
||||
ENGINE.running = true;
|
||||
@@ -77,14 +93,8 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
errorChain(networkInit());
|
||||
errorChain(gameInit());
|
||||
|
||||
printf("Going online...\n");
|
||||
networkRequestConnection(
|
||||
onNetworkConnected,
|
||||
onNetworkFailed,
|
||||
onNetworkDisconnected,
|
||||
NULL
|
||||
);
|
||||
|
||||
printf("Init done, going to queue online in 3 seconds...\n");
|
||||
onlineSwapTime = TIME.time + 3.0f;
|
||||
|
||||
// Camera
|
||||
entityid_t cam = entityManagerAdd();
|
||||
@@ -163,10 +173,13 @@ errorret_t engineUpdate(void) {
|
||||
|
||||
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
|
||||
|
||||
if(TIME.time >= disconnectTime) {
|
||||
printf("Time to disconnect from the network.\n");
|
||||
networkRequestDisconnection(onNetworkDisconnectFinished, NULL);
|
||||
disconnectTime = FLT_MAX;
|
||||
if(TIME.time >= onlineSwapTime) {
|
||||
onlineSwapTime = FLT_MAX;
|
||||
if(NETWORK.state == NETWORK_STATE_CONNECTED) {
|
||||
goOffline();
|
||||
} else {
|
||||
goOnline();
|
||||
}
|
||||
}
|
||||
|
||||
errorOk();
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
#define networkPlatformDispose networkPSPDispose
|
||||
#define networkPlatformIsConnected networkPSPIsConnected
|
||||
#define networkPlatformRequestConnection networkPSPRequestConnection
|
||||
#define networkPlatformRequestDisconnection networkPSPRequestDisconnection
|
||||
|
||||
typedef networkpsp_t networkplatform_t;
|
||||
@@ -11,8 +11,6 @@
|
||||
#include "assert/assert.h"
|
||||
#include "display/displaysdl2.h"
|
||||
|
||||
#include <pspsdk.h>
|
||||
|
||||
errorret_t networkPSPInit() {
|
||||
// Requests the PSP to load the network modules.
|
||||
int ret;
|
||||
@@ -35,19 +33,6 @@ errorret_t networkPSPInit() {
|
||||
// ret = sceUtilityLoadNetModule(PSP_NET_MODULE_HTTP);
|
||||
// if(ret < 0) errorThrow("Failed to init NET HTTP: 0x%08X", ret);
|
||||
|
||||
// Init the PSP network stack.
|
||||
ret = sceNetInit(0x20000, 0x20, 4096, 0x20, 4096);
|
||||
if(ret < 0) errorThrow("sceNetInit failed: 0x%08X", ret);
|
||||
|
||||
ret = sceNetInetInit();
|
||||
if(ret < 0) errorThrow("sceNetInetInit failed: 0x%08X", ret);
|
||||
|
||||
ret = sceNetResolverInit();
|
||||
if(ret < 0) errorThrow("sceNetResolverInit failed: 0x%08X", ret);
|
||||
|
||||
ret = sceNetApctlInit(0x1800, 0x30);
|
||||
if(ret < 0) errorThrow("sceNetApctlInit failed: 0x%08X", ret);
|
||||
|
||||
// ret = sceSslInit(0x28000);
|
||||
// if(ret < 0) errorThrow("sceSslInit failed: 0x%08X", ret);
|
||||
|
||||
@@ -69,16 +54,12 @@ errorret_t networkPSPInit() {
|
||||
|
||||
errorret_t networkPSPUpdate() {
|
||||
int ret;
|
||||
if(
|
||||
NETWORK.state == NETWORK_STATE_CONNECTING ||
|
||||
NETWORK.state == NETWORK_STATE_DISCONNECTING
|
||||
) {
|
||||
if(NETWORK.state == NETWORK_STATE_CONNECTING) {
|
||||
switch(sceUtilityNetconfGetStatus()) {
|
||||
case PSP_UTILITY_DIALOG_INIT:
|
||||
break;
|
||||
|
||||
case PSP_UTILITY_DIALOG_NONE:
|
||||
printf("Diag none?\n");
|
||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||
errorThrow("PSP Netconf dialog disappeared without result");
|
||||
break;
|
||||
@@ -111,7 +92,6 @@ errorret_t networkPSPUpdate() {
|
||||
);
|
||||
NETWORK.platform.onConnected(NETWORK.platform.onConnectedUser);
|
||||
} else {
|
||||
printf("Offline.\n");
|
||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||
|
||||
assertNotNull(
|
||||
@@ -119,6 +99,12 @@ errorret_t networkPSPUpdate() {
|
||||
"Network platform onFailed callback should be set."
|
||||
);
|
||||
|
||||
// Kill the PSP network stack.
|
||||
errorret_t err = networkPSPTerm();
|
||||
if(err.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(err));
|
||||
}
|
||||
|
||||
errorret_t error = errorThrowImpl(
|
||||
&NETWORK.errorState,
|
||||
ERROR_NOT_OK,
|
||||
@@ -138,10 +124,8 @@ errorret_t networkPSPUpdate() {
|
||||
}
|
||||
|
||||
errorret_t networkPSPDispose() {
|
||||
sceNetApctlTerm();
|
||||
sceNetResolverTerm();
|
||||
sceNetInetTerm();
|
||||
sceNetTerm();
|
||||
sceUtilityNetconfGetStatus();
|
||||
errorCatch(errorPrint(networkPSPTerm()));
|
||||
|
||||
sceUtilityUnloadNetModule(PSP_NET_MODULE_HTTP);
|
||||
sceUtilityUnloadNetModule(PSP_NET_MODULE_INET);
|
||||
@@ -169,12 +153,28 @@ void networkPSPRequestConnection(
|
||||
NETWORK.platform.onFailed = onFailed;
|
||||
NETWORK.platform.onConnectedUser = user;
|
||||
|
||||
memoryZero(&NETWORK.platform.dialogData, sizeof(NETWORK.platform.dialogData));
|
||||
memoryZero(&NETWORK.platform.dialogAdhoc, sizeof(NETWORK.platform.dialogAdhoc));
|
||||
int ret;
|
||||
|
||||
// Init the PSP network stack.
|
||||
ret = sceNetInit(0x20000, 0x20, 4096, 0x20, 4096);
|
||||
assertTrue(ret >= 0, "Failed to init net: 0x%08X");
|
||||
|
||||
ret = sceNetInetInit();
|
||||
assertTrue(ret >= 0, "Failed to init net inet: 0x%08X");
|
||||
|
||||
ret = sceNetResolverInit();
|
||||
assertTrue(ret >= 0, "Failed to init net resolver: 0x%08X");
|
||||
|
||||
ret = sceNetApctlInit(0x1800, 0x30);
|
||||
assertTrue(ret >= 0, "Failed to init net apctl: 0x%08X");
|
||||
|
||||
|
||||
// This is all related to getting the PSP online, refer to;
|
||||
// https://github.com/joel16/CMFileManager-PSP/blob/00dab16c64cd48bf6452fc274a3b898d77c39a8d/app/source/net.cpp#L97
|
||||
// since I follow this implementation closely.
|
||||
memoryZero(&NETWORK.platform.dialogData, sizeof(NETWORK.platform.dialogData));
|
||||
memoryZero(&NETWORK.platform.dialogAdhoc, sizeof(NETWORK.platform.dialogAdhoc));
|
||||
|
||||
NETWORK.platform.dialogData.base.size = sizeof(pspUtilityNetconfData);
|
||||
NETWORK.platform.dialogData.base.language = systemPSPGetLanguage();
|
||||
NETWORK.platform.dialogData.base.buttonSwap = systemPSPGetCrossButtonSetting();
|
||||
@@ -187,15 +187,11 @@ void networkPSPRequestConnection(
|
||||
&NETWORK.platform.dialogAdhoc
|
||||
);
|
||||
|
||||
|
||||
int ret = sceUtilityNetconfInitStart(&NETWORK.platform.dialogData);
|
||||
if(ret < 0) {
|
||||
assertUnreachable("Failed to init netconf");
|
||||
}
|
||||
// At this point, PSP is in control.
|
||||
ret = sceUtilityNetconfInitStart(&NETWORK.platform.dialogData);
|
||||
assertTrue(ret >= 0, "Failed to init netconf");
|
||||
}
|
||||
|
||||
void networkPSPRequestDisconection(
|
||||
void networkPSPRequestDisconnection(
|
||||
void (*onComplete)(void *user),
|
||||
void *user
|
||||
) {
|
||||
@@ -204,11 +200,36 @@ void networkPSPRequestDisconection(
|
||||
"Network host should be in a disconnecting state."
|
||||
);
|
||||
|
||||
NETWORK.platform.onComplete = onComplete;
|
||||
NETWORK.platform.onCompleteUser = user;
|
||||
|
||||
int ret = sceUtilityNetconfShutdownStart();
|
||||
if(ret < 0) {
|
||||
assertUnreachable("Failed to start netconf shutdown");
|
||||
errorret_t err = networkPSPTerm();
|
||||
if(err.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(err));
|
||||
}
|
||||
|
||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||
onComplete(user);
|
||||
}
|
||||
|
||||
errorret_t networkPSPTerm() {
|
||||
int ret;
|
||||
ret = sceNetApctlTerm();
|
||||
if(ret < 0) {
|
||||
errorThrow("Failed to terminate netctl: 0x%08X", ret);
|
||||
}
|
||||
|
||||
ret = sceNetResolverTerm();
|
||||
if(ret < 0) {
|
||||
errorThrow("Failed to terminate net resolver: 0x%08X", ret);
|
||||
}
|
||||
|
||||
ret = sceNetInetTerm();
|
||||
if(ret < 0) {
|
||||
errorThrow("Failed to terminate net inet: 0x%08X", ret);
|
||||
}
|
||||
|
||||
ret = sceNetTerm();
|
||||
if(ret < 0) {
|
||||
errorThrow("Failed to terminate net: 0x%08X", ret);
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -34,10 +34,6 @@ typedef struct {
|
||||
void *onConnectedUser;
|
||||
void (*onConnected)(void *user);
|
||||
void (*onFailed)(errorret_t error, void *user);
|
||||
|
||||
// Used during disconnecting
|
||||
void *onCompleteUser;
|
||||
void (*onComplete)(void *user);
|
||||
} networkpsp_t;
|
||||
|
||||
/**
|
||||
@@ -85,3 +81,22 @@ void networkPSPRequestConnection(
|
||||
void (*onDisconnect)(errorret_t error, void *user),
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Requests the PSP to disconnect from the network (Shows the Wi-Fi disconnecting).
|
||||
*
|
||||
* @param onComplete Callback when disconnection is complete.
|
||||
* @param user User data to pass to the callback.
|
||||
*/
|
||||
void networkPSPRequestDisconnection(
|
||||
void (*onComplete)(void *user),
|
||||
void *user
|
||||
);
|
||||
|
||||
/**
|
||||
* Disposes the PSP sce net libraries, doesn't unload the modules and won't
|
||||
* term the dialog if it's active.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkPSPTerm();
|
||||
Reference in New Issue
Block a user