PSP networking matches linux now.
This commit is contained in:
+38
-25
@@ -29,33 +29,49 @@
|
|||||||
engine_t ENGINE;
|
engine_t ENGINE;
|
||||||
entityid_t phBoxEnt;
|
entityid_t phBoxEnt;
|
||||||
componentid_t phBoxPhys;
|
componentid_t phBoxPhys;
|
||||||
float_t disconnectTime = FLT_MAX;
|
|
||||||
|
float_t onlineSwapTime = FLT_MAX;
|
||||||
|
|
||||||
|
void goOnline();
|
||||||
|
void goOffline();
|
||||||
|
|
||||||
void onNetworkConnected(void *user) {
|
void onNetworkConnected(void *user) {
|
||||||
disconnectTime = TIME.time + 3.0f;
|
onlineSwapTime = TIME.time + 3.0f;
|
||||||
printf("Network connected, I will disconnect at: %.2f1.\n", disconnectTime);
|
printf("Network connected, I will disconnect at: %.2f1.\n", onlineSwapTime);
|
||||||
// networkHTTPRequest(
|
|
||||||
// "http://10.0.0.94:3000/test",
|
|
||||||
// NETWORK_HTTP_REQUEST_METHOD_GET,
|
|
||||||
// NULL, NULL, 0, NULL,
|
|
||||||
// onTestResponse,
|
|
||||||
// onTestError
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onNetworkFailed(errorret_t error, void *user) {
|
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) {
|
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));
|
errorCatch(errorPrint(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
void onNetworkDisconnectFinished(void *user) {
|
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) {
|
errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||||
memoryZero(&ENGINE, sizeof(engine_t));
|
memoryZero(&ENGINE, sizeof(engine_t));
|
||||||
ENGINE.running = true;
|
ENGINE.running = true;
|
||||||
@@ -76,15 +92,9 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
|||||||
physicsManagerInit();
|
physicsManagerInit();
|
||||||
errorChain(networkInit());
|
errorChain(networkInit());
|
||||||
errorChain(gameInit());
|
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
|
// Camera
|
||||||
entityid_t cam = entityManagerAdd();
|
entityid_t cam = entityManagerAdd();
|
||||||
@@ -163,10 +173,13 @@ errorret_t engineUpdate(void) {
|
|||||||
|
|
||||||
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
|
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
|
||||||
|
|
||||||
if(TIME.time >= disconnectTime) {
|
if(TIME.time >= onlineSwapTime) {
|
||||||
printf("Time to disconnect from the network.\n");
|
onlineSwapTime = FLT_MAX;
|
||||||
networkRequestDisconnection(onNetworkDisconnectFinished, NULL);
|
if(NETWORK.state == NETWORK_STATE_CONNECTED) {
|
||||||
disconnectTime = FLT_MAX;
|
goOffline();
|
||||||
|
} else {
|
||||||
|
goOnline();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
|
|||||||
@@ -13,5 +13,6 @@
|
|||||||
#define networkPlatformDispose networkPSPDispose
|
#define networkPlatformDispose networkPSPDispose
|
||||||
#define networkPlatformIsConnected networkPSPIsConnected
|
#define networkPlatformIsConnected networkPSPIsConnected
|
||||||
#define networkPlatformRequestConnection networkPSPRequestConnection
|
#define networkPlatformRequestConnection networkPSPRequestConnection
|
||||||
|
#define networkPlatformRequestDisconnection networkPSPRequestDisconnection
|
||||||
|
|
||||||
typedef networkpsp_t networkplatform_t;
|
typedef networkpsp_t networkplatform_t;
|
||||||
@@ -11,8 +11,6 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "display/displaysdl2.h"
|
#include "display/displaysdl2.h"
|
||||||
|
|
||||||
#include <pspsdk.h>
|
|
||||||
|
|
||||||
errorret_t networkPSPInit() {
|
errorret_t networkPSPInit() {
|
||||||
// Requests the PSP to load the network modules.
|
// Requests the PSP to load the network modules.
|
||||||
int ret;
|
int ret;
|
||||||
@@ -35,19 +33,6 @@ errorret_t networkPSPInit() {
|
|||||||
// ret = sceUtilityLoadNetModule(PSP_NET_MODULE_HTTP);
|
// ret = sceUtilityLoadNetModule(PSP_NET_MODULE_HTTP);
|
||||||
// if(ret < 0) errorThrow("Failed to init NET HTTP: 0x%08X", ret);
|
// 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);
|
// ret = sceSslInit(0x28000);
|
||||||
// if(ret < 0) errorThrow("sceSslInit failed: 0x%08X", ret);
|
// if(ret < 0) errorThrow("sceSslInit failed: 0x%08X", ret);
|
||||||
|
|
||||||
@@ -69,16 +54,12 @@ errorret_t networkPSPInit() {
|
|||||||
|
|
||||||
errorret_t networkPSPUpdate() {
|
errorret_t networkPSPUpdate() {
|
||||||
int ret;
|
int ret;
|
||||||
if(
|
if(NETWORK.state == NETWORK_STATE_CONNECTING) {
|
||||||
NETWORK.state == NETWORK_STATE_CONNECTING ||
|
|
||||||
NETWORK.state == NETWORK_STATE_DISCONNECTING
|
|
||||||
) {
|
|
||||||
switch(sceUtilityNetconfGetStatus()) {
|
switch(sceUtilityNetconfGetStatus()) {
|
||||||
case PSP_UTILITY_DIALOG_INIT:
|
case PSP_UTILITY_DIALOG_INIT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSP_UTILITY_DIALOG_NONE:
|
case PSP_UTILITY_DIALOG_NONE:
|
||||||
printf("Diag none?\n");
|
|
||||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||||
errorThrow("PSP Netconf dialog disappeared without result");
|
errorThrow("PSP Netconf dialog disappeared without result");
|
||||||
break;
|
break;
|
||||||
@@ -111,7 +92,6 @@ errorret_t networkPSPUpdate() {
|
|||||||
);
|
);
|
||||||
NETWORK.platform.onConnected(NETWORK.platform.onConnectedUser);
|
NETWORK.platform.onConnected(NETWORK.platform.onConnectedUser);
|
||||||
} else {
|
} else {
|
||||||
printf("Offline.\n");
|
|
||||||
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
NETWORK.state = NETWORK_STATE_DISCONNECTED;
|
||||||
|
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
@@ -119,6 +99,12 @@ errorret_t networkPSPUpdate() {
|
|||||||
"Network platform onFailed callback should be set."
|
"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(
|
errorret_t error = errorThrowImpl(
|
||||||
&NETWORK.errorState,
|
&NETWORK.errorState,
|
||||||
ERROR_NOT_OK,
|
ERROR_NOT_OK,
|
||||||
@@ -138,10 +124,8 @@ errorret_t networkPSPUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorret_t networkPSPDispose() {
|
errorret_t networkPSPDispose() {
|
||||||
sceNetApctlTerm();
|
sceUtilityNetconfGetStatus();
|
||||||
sceNetResolverTerm();
|
errorCatch(errorPrint(networkPSPTerm()));
|
||||||
sceNetInetTerm();
|
|
||||||
sceNetTerm();
|
|
||||||
|
|
||||||
sceUtilityUnloadNetModule(PSP_NET_MODULE_HTTP);
|
sceUtilityUnloadNetModule(PSP_NET_MODULE_HTTP);
|
||||||
sceUtilityUnloadNetModule(PSP_NET_MODULE_INET);
|
sceUtilityUnloadNetModule(PSP_NET_MODULE_INET);
|
||||||
@@ -169,12 +153,28 @@ void networkPSPRequestConnection(
|
|||||||
NETWORK.platform.onFailed = onFailed;
|
NETWORK.platform.onFailed = onFailed;
|
||||||
NETWORK.platform.onConnectedUser = user;
|
NETWORK.platform.onConnectedUser = user;
|
||||||
|
|
||||||
memoryZero(&NETWORK.platform.dialogData, sizeof(NETWORK.platform.dialogData));
|
int ret;
|
||||||
memoryZero(&NETWORK.platform.dialogAdhoc, sizeof(NETWORK.platform.dialogAdhoc));
|
|
||||||
|
// 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;
|
// This is all related to getting the PSP online, refer to;
|
||||||
// https://github.com/joel16/CMFileManager-PSP/blob/00dab16c64cd48bf6452fc274a3b898d77c39a8d/app/source/net.cpp#L97
|
// https://github.com/joel16/CMFileManager-PSP/blob/00dab16c64cd48bf6452fc274a3b898d77c39a8d/app/source/net.cpp#L97
|
||||||
// since I follow this implementation closely.
|
// 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.size = sizeof(pspUtilityNetconfData);
|
||||||
NETWORK.platform.dialogData.base.language = systemPSPGetLanguage();
|
NETWORK.platform.dialogData.base.language = systemPSPGetLanguage();
|
||||||
NETWORK.platform.dialogData.base.buttonSwap = systemPSPGetCrossButtonSetting();
|
NETWORK.platform.dialogData.base.buttonSwap = systemPSPGetCrossButtonSetting();
|
||||||
@@ -187,15 +187,11 @@ void networkPSPRequestConnection(
|
|||||||
&NETWORK.platform.dialogAdhoc
|
&NETWORK.platform.dialogAdhoc
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ret = sceUtilityNetconfInitStart(&NETWORK.platform.dialogData);
|
||||||
int ret = sceUtilityNetconfInitStart(&NETWORK.platform.dialogData);
|
assertTrue(ret >= 0, "Failed to init netconf");
|
||||||
if(ret < 0) {
|
|
||||||
assertUnreachable("Failed to init netconf");
|
|
||||||
}
|
|
||||||
// At this point, PSP is in control.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void networkPSPRequestDisconection(
|
void networkPSPRequestDisconnection(
|
||||||
void (*onComplete)(void *user),
|
void (*onComplete)(void *user),
|
||||||
void *user
|
void *user
|
||||||
) {
|
) {
|
||||||
@@ -204,11 +200,36 @@ void networkPSPRequestDisconection(
|
|||||||
"Network host should be in a disconnecting state."
|
"Network host should be in a disconnecting state."
|
||||||
);
|
);
|
||||||
|
|
||||||
NETWORK.platform.onComplete = onComplete;
|
errorret_t err = networkPSPTerm();
|
||||||
NETWORK.platform.onCompleteUser = user;
|
if(err.code != ERROR_OK) {
|
||||||
|
errorCatch(errorPrint(err));
|
||||||
int ret = sceUtilityNetconfShutdownStart();
|
|
||||||
if(ret < 0) {
|
|
||||||
assertUnreachable("Failed to start netconf shutdown");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 *onConnectedUser;
|
||||||
void (*onConnected)(void *user);
|
void (*onConnected)(void *user);
|
||||||
void (*onFailed)(errorret_t error, void *user);
|
void (*onFailed)(errorret_t error, void *user);
|
||||||
|
|
||||||
// Used during disconnecting
|
|
||||||
void *onCompleteUser;
|
|
||||||
void (*onComplete)(void *user);
|
|
||||||
} networkpsp_t;
|
} networkpsp_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,4 +80,23 @@ void networkPSPRequestConnection(
|
|||||||
void (*onFailed)(errorret_t error, void *user),
|
void (*onFailed)(errorret_t error, void *user),
|
||||||
void (*onDisconnect)(errorret_t error, void *user),
|
void (*onDisconnect)(errorret_t error, void *user),
|
||||||
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