diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f036e67..ea011c4e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,11 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "vita") add_subdirectory(dusksdl2) add_subdirectory(duskgl) -elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii") +elseif(DUSK_TARGET_SYSTEM STREQUAL "wii") + add_subdirectory(duskwii) + add_subdirectory(duskdolphin) + +elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube") add_subdirectory(duskdolphin) endif() \ No newline at end of file diff --git a/src/dusk/CMakeLists.txt b/src/dusk/CMakeLists.txt index 03a75469..a4192a65 100644 --- a/src/dusk/CMakeLists.txt +++ b/src/dusk/CMakeLists.txt @@ -77,4 +77,4 @@ add_subdirectory(time) add_subdirectory(ui) add_subdirectory(network) add_subdirectory(util) -add_subdirectory(thread) \ No newline at end of file +# add_subdirectory(thread) \ No newline at end of file diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index b0cb047a..954e3c30 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -127,7 +127,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { (vec3){ distance, distance, distance } ); componentid_t camCam = entityAddComponent(cam, COMPONENT_TYPE_CAMERA); - entityCameraSetZFar(cam, camCam, distance * 6.0f); + entityCameraSetZFar(cam, camCam, 100.0f); // Floor entityid_t floorEnt = entityManagerAdd(); diff --git a/src/duskdolphin/CMakeLists.txt b/src/duskdolphin/CMakeLists.txt index 8eeda261..2020cd58 100644 --- a/src/duskdolphin/CMakeLists.txt +++ b/src/duskdolphin/CMakeLists.txt @@ -18,4 +18,5 @@ target_sources(${DUSK_BINARY_TARGET_NAME} add_subdirectory(asset) add_subdirectory(log) add_subdirectory(display) -add_subdirectory(input) \ No newline at end of file +add_subdirectory(input) +add_subdirectory(system) \ No newline at end of file diff --git a/src/duskdolphin/system/CMakeLists.txt b/src/duskdolphin/system/CMakeLists.txt new file mode 100644 index 00000000..679b705d --- /dev/null +++ b/src/duskdolphin/system/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + systemdolphin.c +) diff --git a/src/duskdolphin/system/systemdolphin.c b/src/duskdolphin/system/systemdolphin.c new file mode 100644 index 00000000..dfebeb9c --- /dev/null +++ b/src/duskdolphin/system/systemdolphin.c @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "systemdolphin.h" +#include "input/input.h" +#include "util/string.h" +#include "assert/assert.h" + +errorret_t systemInitDolphin(void) { + errorOk(); +} + +systemdialogtype_t systemGetActiveDialogTypeDolphin(void) { + return SYSTEM_DIALOG_TYPE_NONE; +} \ No newline at end of file diff --git a/src/duskdolphin/system/systemdolphin.h b/src/duskdolphin/system/systemdolphin.h new file mode 100644 index 00000000..79c21663 --- /dev/null +++ b/src/duskdolphin/system/systemdolphin.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "system/system.h" + +/** + * Initializes the Dolphin system module. + * + * @return Error code indicating success or failure. + */ +errorret_t systemInitDolphin(void); + +/** + * Returns which Dolphin system dialog is currently open (if any). + * + * @return Currently open system dialog type. + */ +systemdialogtype_t systemGetActiveDialogTypeDolphin(void); \ No newline at end of file diff --git a/src/duskdolphin/system/systemplatform.h b/src/duskdolphin/system/systemplatform.h new file mode 100644 index 00000000..483f7eef --- /dev/null +++ b/src/duskdolphin/system/systemplatform.h @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "system/systemdolphin.h" + +#define systemInitPlatform systemInitDolphin +#define systemGetActiveDialogTypePlatform systemGetActiveDialogTypeDolphin \ No newline at end of file diff --git a/src/duskwii/CMakeLists.txt b/src/duskwii/CMakeLists.txt new file mode 100644 index 00000000..b85a8f61 --- /dev/null +++ b/src/duskwii/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Includes +target_include_directories(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) + +# Sources +target_sources(${DUSK_BINARY_TARGET_NAME} + PUBLIC +) + +# Subdirs +add_subdirectory(network) \ No newline at end of file diff --git a/src/duskwii/network/CMakeLists.txt b/src/duskwii/network/CMakeLists.txt new file mode 100644 index 00000000..5a01b909 --- /dev/null +++ b/src/duskwii/network/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + networkwii.c +) diff --git a/src/duskwii/network/networkplatform.h b/src/duskwii/network/networkplatform.h new file mode 100644 index 00000000..2f62a01e --- /dev/null +++ b/src/duskwii/network/networkplatform.h @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "networkwii.h" + +#define networkPlatformInit networkWiiInit +#define networkPlatformUpdate networkWiiUpdate +#define networkPlatformDispose networkWiiDispose +#define networkPlatformIsConnected networkWiiIsConnected +#define networkPlatformRequestConnection networkWiiRequestConnection +#define networkPlatformRequestDisconnection networkWiiRequestDisconnection +#define networkPlatformGetInfo networkWiiGetInfo + +typedef networkwii_t networkplatform_t; diff --git a/src/duskwii/network/networkwii.c b/src/duskwii/network/networkwii.c new file mode 100644 index 00000000..df3fcbe8 --- /dev/null +++ b/src/duskwii/network/networkwii.c @@ -0,0 +1,112 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "network/network.h" +#include "util/memory.h" +#include "assert/assert.h" + +errorret_t networkWiiInit() { + s32 ret = net_init(); + if(ret < 0) errorThrow("Failed to init Wii network stack: %d", ret); + errorOk(); +} + +errorret_t networkWiiUpdate() { + errorOk(); +} + +errorret_t networkWiiDispose() { + net_deinit(); + errorOk(); +} + +bool_t networkWiiIsConnected() { + return NETWORK.state == NETWORK_STATE_CONNECTED; +} + +void networkWiiRequestConnection( + void (*onConnected)(void *user), + void (*onFailed)(errorret_t error, void *user), + void (*onDisconnect)(errorret_t error, void *user), + void *user +) { + assertTrue( + NETWORK.state == NETWORK_STATE_CONNECTING, + "Network host should be in a connecting state." + ); + + NETWORK.platform.onConnected = onConnected; + NETWORK.platform.onFailed = onFailed; + NETWORK.platform.onConnectedUser = user; + + memoryZero(NETWORK.platform.ip, NETWORK_WII_IP_MAX); + memoryZero(NETWORK.platform.netmask, NETWORK_WII_IP_MAX); + memoryZero(NETWORK.platform.gateway, NETWORK_WII_IP_MAX); + + // Negotiate DHCP using the Wi-Fi settings saved in Wii System Menu. + // This call blocks until the interface is configured or times out. + s32 ret = if_config( + NETWORK.platform.ip, + NETWORK.platform.netmask, + NETWORK.platform.gateway, + true, + 20 + ); + + if(ret >= 0) { + NETWORK.state = NETWORK_STATE_CONNECTED; + assertNotNull( + NETWORK.platform.onConnected, + "Network platform onConnected callback should be set." + ); + NETWORK.platform.onConnected(NETWORK.platform.onConnectedUser); + } else { + NETWORK.state = NETWORK_STATE_DISCONNECTED; + assertNotNull( + NETWORK.platform.onFailed, + "Network platform onFailed callback should be set." + ); + errorret_t error = errorThrowImpl( + &NETWORK.errorState, + ERROR_NOT_OK, + __FILE__, __func__, __LINE__, + "Failed to connect to Wii network" + ); + NETWORK.platform.onFailed(error, NETWORK.platform.onConnectedUser); + } +} + +void networkWiiRequestDisconnection( + void (*onComplete)(void *user), + void *user +) { + assertTrue( + NETWORK.state == NETWORK_STATE_DISCONNECTING, + "Network host should be in a disconnecting state." + ); + + NETWORK.state = NETWORK_STATE_DISCONNECTED; + onComplete(user); +} + +networkinfo_t networkWiiGetInfo() { + networkinfo_t info; + memoryZero(&info, sizeof(networkinfo_t)); + + info.type = NETWORK_TYPE_IPV4; + int ret = sscanf( + NETWORK.platform.ip, + "%hhu.%hhu.%hhu.%hhu", + &info.ipv4.ip[0], + &info.ipv4.ip[1], + &info.ipv4.ip[2], + &info.ipv4.ip[3] + ); + assertTrue(ret == 4, "Failed to parse Wii IP address"); + + return info; +} diff --git a/src/duskwii/network/networkwii.h b/src/duskwii/network/networkwii.h new file mode 100644 index 00000000..a8ae1b8a --- /dev/null +++ b/src/duskwii/network/networkwii.h @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "error/error.h" +#include "network/networkinfo.h" +#include + +#define NETWORK_WII_IP_MAX 16 + +typedef struct { + char ip[NETWORK_WII_IP_MAX]; + char netmask[NETWORK_WII_IP_MAX]; + char gateway[NETWORK_WII_IP_MAX]; + + void *onConnectedUser; + void (*onConnected)(void *user); + void (*onFailed)(errorret_t error, void *user); +} networkwii_t; + +/** + * Initializes the Wii network stack via IOS. Does not connect; use + * networkWiiRequestConnection for that. + * + * @return Error state (if any). + */ +errorret_t networkWiiInit(); + +/** + * Called each frame. No-op on Wii since connection is synchronous. + * + * @return Error state (if any). + */ +errorret_t networkWiiUpdate(); + +/** + * Disposes the Wii network stack. + * + * @return Error state (if any). + */ +errorret_t networkWiiDispose(); + +/** + * Returns true if the Wii is connected to a network. + * + * @return True if connected. + */ +bool_t networkWiiIsConnected(); + +/** + * Requests the Wii to connect to the network using the Wi-Fi settings saved + * in the Wii System Menu. Blocks until connected or failed. + * + * @param onConnected Callback on successful connection. + * @param onFailed Callback if connection fails. + * @param onDisconnect Callback when connection is later lost. + * @param user User data passed to all callbacks. + */ +void networkWiiRequestConnection( + void (*onConnected)(void *user), + void (*onFailed)(errorret_t error, void *user), + void (*onDisconnect)(errorret_t error, void *user), + void *user +); + +/** + * Requests the Wii to disconnect from the network. + * + * @param onComplete Callback when disconnection is complete. + * @param user User data passed to the callback. + */ +void networkWiiRequestDisconnection( + void (*onComplete)(void *user), + void *user +); + +/** + * Returns the current network IP information. + * + * @return Network info for the active connection. + */ +networkinfo_t networkWiiGetInfo();