Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.5] Add platform-switch submodule #16

Draft
wants to merge 1 commit into
base: 3.5
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "platform/switch"]
path = platform/switch
url = https://github.com/Homebrodot/platform-switch
8 changes: 8 additions & 0 deletions core/project_settings.cpp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion on the main/3.5 branch...
f950ebd#r138181091
...can potentially avoid having any modifications to this file at all to add in Switch in support if we override OS::get_resource_path for the switch

That'll be a change that'll need doing on the platform-switch submodule repo rather than here, but wanted a note to remain on this branch as reminder that we should be able to remove it in a future update.

Original file line number Diff line number Diff line change
@@ -420,6 +420,14 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
}
#endif

#ifdef HORIZON_ENABLED
if (!found) {
if (_load_resource_pack("romfs:/game.pck")) {
found = true;
}
}
#endif

if (!found) {
// Try to load data pack at the location of the executable.
// As mentioned above, we have two potential names to attempt.
15 changes: 14 additions & 1 deletion drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
@@ -89,18 +89,20 @@ GLuint RasterizerStorageGLES2::system_fbo = 0;
#ifndef GLES_OVER_GL
#define glClearDepth glClearDepthf

#if defined IPHONE_ENABLED || defined ANDROID_ENABLED
// enable extensions manually for android and ios
#ifndef UWP_ENABLED
#include <dlfcn.h> // needed to load extensions
#endif
#endif

#ifdef IPHONE_ENABLED

#include <OpenGLES/ES2/glext.h>
//void *glRenderbufferStorageMultisampleAPPLE;
//void *glResolveMultisampleFramebufferAPPLE;
#define glRenderbufferStorageMultisample glRenderbufferStorageMultisampleAPPLE
#elif defined(ANDROID_ENABLED)
#elif defined ANDROID_ENABLED || defined HORIZON_ENABLED

#include <GLES2/gl2ext.h>
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC glRenderbufferStorageMultisampleEXT;
@@ -6294,6 +6296,17 @@ void RasterizerStorageGLES2::initialize() {
config.render_to_mipmap_supported = config.extensions.has("GL_OES_fbo_render_mipmap") && config.extensions.has("GL_EXT_texture_lod");
#endif

// If the desktop build is using S3TC, and you export / run from the IDE for android, if the device supports
// S3TC it will crash trying to load these textures, as they are not exported in the APK. This is a simple way
// to prevent Android devices trying to load S3TC, by faking lack of hardware support.

// Switch: this happens on Horizon too.
#ifndef TOOLS_ENABLED
#if defined ANDROID_ENABLED || defined HORIZON_ENABLED
config.s3tc_supported = false;
#endif
#endif

#ifdef GLES_OVER_GL
config.use_rgba_2d_shadows = false;
config.support_depth_texture = true;
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
@@ -8086,7 +8086,7 @@ void RasterizerStorageGLES3::initialize() {
// If the desktop build is using S3TC, and you export / run from the IDE for android, if the device supports
// S3TC it will crash trying to load these textures, as they are not exported in the APK. This is a simple way
// to prevent Android devices trying to load S3TC, by faking lack of hardware support.
#if defined(ANDROID_ENABLED) || defined(IPHONE_ENABLED)
#if defined(ANDROID_ENABLED) || defined(IPHONE_ENABLED) || defined(HORIZON_ENABLED)
config.s3tc_supported = false;
#endif
#endif
8 changes: 8 additions & 0 deletions drivers/unix/dir_access_unix.cpp
Original file line number Diff line number Diff line change
@@ -413,6 +413,9 @@ String DirAccessUnix::read_link(String p_file) {

p_file = fix_path(p_file);

#ifdef HORIZON_ENABLED
return p_file;
#else
char buf[256];
memset(buf, 0, 256);
ssize_t len = readlink(p_file.utf8().get_data(), buf, sizeof(buf));
@@ -421,9 +424,13 @@ String DirAccessUnix::read_link(String p_file) {
link.parse_utf8(buf, len);
}
return link;
#endif
}

Error DirAccessUnix::create_link(String p_source, String p_target) {
#ifdef HORIZON_ENABLED
return FAILED;
#else
if (p_target.is_rel_path())
p_target = get_current_dir().plus_file(p_target);

@@ -435,6 +442,7 @@ Error DirAccessUnix::create_link(String p_source, String p_target) {
} else {
return FAILED;
}
#endif
}

uint64_t DirAccessUnix::get_space_left() {
7 changes: 4 additions & 3 deletions drivers/unix/file_access_unix.cpp
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@

#include <errno.h>

#if defined(UNIX_ENABLED)
#if defined(UNIX_ENABLED) || defined(HORIZON_ENABLED)
#include <unistd.h>
#endif

@@ -130,6 +130,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
return last_error;
}

#ifndef HORIZON_ENABLED
// Set close on exec to avoid leaking it to subprocesses.
int fd = fileno(f);

@@ -142,7 +143,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
fcntl(fd, F_SETFD, opts | FD_CLOEXEC);
#endif
}

#endif
last_error = OK;
flags = p_mode_flags;
return OK;
@@ -279,7 +280,7 @@ bool FileAccessUnix::file_exists(const String &p_path) {
return false;
}

#ifdef UNIX_ENABLED
#if defined(UNIX_ENABLED) || defined(HORIZON_ENABLED)
// See if we have access to the file
if (access(filename.utf8().get_data(), F_OK)) {
return false;
10 changes: 9 additions & 1 deletion drivers/unix/ip_unix.cpp
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@

#include "ip_unix.h"

#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED)
#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED) || defined(HORIZON_ENABLED)

#include <string.h>

@@ -53,8 +53,10 @@
#ifdef __FreeBSD__
#include <sys/types.h>
#endif
#ifndef HORIZON_ENABLED
#include <ifaddrs.h>
#endif
#endif
#include <arpa/inet.h>
#include <sys/socket.h>
#ifdef __FreeBSD__
@@ -210,7 +212,12 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
#else // UNIX

void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
#ifdef HORIZON_ENABLED
struct ifaddrs *ifAddrStruct = nullptr;
struct ifaddrs *ifa = nullptr;
// todo: nifm
#else // HORIZON_ENABLED
struct ifaddrs *ifAddrStruct = nullptr;
struct ifaddrs *ifa = nullptr;
int family;

@@ -244,6 +251,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
if (ifAddrStruct != nullptr) {
freeifaddrs(ifAddrStruct);
}
#endif // !HORIZON_ENABLED
}
#endif

2 changes: 1 addition & 1 deletion drivers/unix/ip_unix.h
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@

#include "core/io/ip.h"

#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED)
#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED) || defined(HORIZON_ENABLED)

class IP_Unix : public IP {
GDCLASS(IP_Unix, IP);
6 changes: 4 additions & 2 deletions drivers/unix/net_socket_posix.cpp
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
#include "net_socket_posix.h"

#ifndef UNIX_SOCKET_UNAVAILABLE
#if defined(UNIX_ENABLED)
#if defined(UNIX_ENABLED) || defined(HORIZON_ENABLED)

#include <errno.h>
#include <netdb.h>
@@ -50,7 +50,7 @@
#include <netinet/in.h>

#include <sys/socket.h>
#ifdef JAVASCRIPT_ENABLED
#if defined(JAVASCRIPT_ENABLED) || defined(HORIZON_ENABLED)
#include <arpa/inet.h>
#endif

@@ -276,11 +276,13 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, St
memcpy(&greq.imr_interface, if_ip.get_ipv4(), 4);
ret = setsockopt(_sock, level, sock_opt, (const char *)&greq, sizeof(greq));
} else {
#ifndef HORIZON_ENABLED
struct ipv6_mreq greq;
int sock_opt = p_add ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP;
memcpy(&greq.ipv6mr_multiaddr, p_ip.get_ipv6(), 16);
greq.ipv6mr_interface = if_v6id;
ret = setsockopt(_sock, level, sock_opt, (const char *)&greq, sizeof(greq));
#endif
}
ERR_FAIL_COND_V(ret != 0, FAILED);

5 changes: 5 additions & 0 deletions modules/bullet/SCsub
Original file line number Diff line number Diff line change
@@ -200,6 +200,11 @@ if env["builtin_bullet"]:
thirdparty_sources = [thirdparty_dir + file for file in bullet2_src]

env_bullet.Prepend(CPPPATH=[thirdparty_dir])
# Treat Bullet headers as system headers to avoid raising warnings. Not supported on MSVC. (TODO SWITCH: devkitA64 issue prevents this from working)
if not env.msvc and env["platform"] != "switch":
env_bullet.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path])
else:
env_bullet.Prepend(CPPPATH=[thirdparty_dir])

env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD", "BT_THREADSAFE"])

4 changes: 2 additions & 2 deletions modules/gdnative/include/gdnative/gdnative.h
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
extern "C" {
#endif

#if defined(_WIN32) || defined(__ANDROID__)
#if defined(_WIN32) || defined(__ANDROID__) || defined(__SWITCH__)
#define GDCALLINGCONV
#define GDAPI GDCALLINGCONV
#elif defined(__APPLE__)
@@ -47,7 +47,7 @@ extern "C" {
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
#else // !_WIN32 && !__APPLE__
#else // !_WIN32 && !__APPLE__ && !__SWITCH__
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
1 change: 1 addition & 0 deletions platform/switch
Submodule switch added at 31761d
2 changes: 1 addition & 1 deletion thirdparty/enet/enet/godot.h
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
#include <stdint.h>
#include <winsock2.h>
#endif
#ifdef UNIX_ENABLED
#if defined(UNIX_ENABLED) || defined(HORIZON_ENABLED)
#include <arpa/inet.h>
#endif

95 changes: 95 additions & 0 deletions thirdparty/libnx/nacp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @file nacp.h
* @brief Control.nacp structure / related code for nacp.
* @copyright libnx Authors
*/

#pragma once

#include "thirdparty/libnx/types.h"

/// Language entry. These strings are UTF-8.
typedef struct {
char name[0x200];
char author[0x100];
} NacpLanguageEntry;

/// ApplicationNeighborDetectionGroupConfiguration
typedef struct {
u64 group_id; ///< GroupId
u8 key[0x10];
} NacpApplicationNeighborDetectionGroupConfiguration;

/// NeighborDetectionClientConfiguration
typedef struct {
NacpApplicationNeighborDetectionGroupConfiguration send_group_configuration; ///< SendGroupConfiguration
NacpApplicationNeighborDetectionGroupConfiguration receivable_group_configurations[0x10]; ///< ReceivableGroupConfigurations
} NacpNeighborDetectionClientConfiguration;

/// ApplicationJitConfiguration
typedef struct {
u64 flags; ///< Flags
u64 memory_size; ///< MemorySize
} NacpApplicationJitConfiguration;

/// ns ApplicationControlProperty
typedef struct {
NacpLanguageEntry lang[16]; ///< \ref NacpLanguageEntry
u8 isbn[0x25]; ///< Isbn
u8 startup_user_account; ///< StartupUserAccount
u8 user_account_switch_lock; ///< UserAccountSwitchLock
u8 add_on_content_registration_type; ///< AddOnContentRegistrationType
u32 attribute_flag; ///< AttributeFlag
u32 supported_language_flag; ///< SupportedLanguageFlag
u32 parental_control_flag; ///< ParentalControlFlag
u8 screenshot; ///< Screenshot
u8 video_capture; ///< VideoCapture
u8 data_loss_confirmation; ///< DataLossConfirmation
u8 play_log_policy; ///< PlayLogPolicy
u64 presence_group_id; ///< PresenceGroupId
s8 rating_age[0x20]; ///< RatingAge
char display_version[0x10]; ///< DisplayVersion
u64 add_on_content_base_id; ///< AddOnContentBaseId
u64 save_data_owner_id; ///< SaveDataOwnerId
u64 user_account_save_data_size; ///< UserAccountSaveDataSize
u64 user_account_save_data_journal_size; ///< UserAccountSaveDataJournalSize
u64 device_save_data_size; ///< DeviceSaveDataSize
u64 device_save_data_journal_size; ///< DeviceSaveDataJournalSize
u64 bcat_delivery_cache_storage_size; ///< BcatDeliveryCacheStorageSize
u64 application_error_code_category; ///< ApplicationErrorCodeCategory
u64 local_communication_id[0x8]; ///< LocalCommunicationId
u8 logo_type; ///< LogoType
u8 logo_handling; ///< LogoHandling
u8 runtime_add_on_content_install; ///< RuntimeAddOnContentInstall
u8 runtime_parameter_delivery; ///< RuntimeParameterDelivery
u8 reserved_x30f4[0x2]; ///< Reserved
u8 crash_report; ///< CrashReport
u8 hdcp; ///< Hdcp
u64 pseudo_device_id_seed; ///< SeedForPseudoDeviceId
char bcat_passphrase[0x41]; ///< BcatPassphrase
u8 startup_user_account_option; ///< StartupUserAccountOption
u8 reserved_for_user_account_save_data_operation[0x6]; ///< ReservedForUserAccountSaveDataOperation
u64 user_account_save_data_size_max; ///< UserAccountSaveDataSizeMax
u64 user_account_save_data_journal_size_max; ///< UserAccountSaveDataJournalSizeMax
u64 device_save_data_size_max; ///< DeviceSaveDataSizeMax
u64 device_save_data_journal_size_max; ///< DeviceSaveDataJournalSizeMax
u64 temporary_storage_size; ///< TemporaryStorageSize
u64 cache_storage_size; ///< CacheStorageSize
u64 cache_storage_journal_size; ///< CacheStorageJournalSize
u64 cache_storage_data_and_journal_size_max; ///< CacheStorageDataAndJournalSizeMax
u16 cache_storage_index_max; ///< CacheStorageIndexMax
u8 reserved_x318a[0x6]; ///< Reserved
u64 play_log_queryable_application_id[0x10]; ///< PlayLogQueryableApplicationId
u8 play_log_query_capability; ///< PlayLogQueryCapability
u8 repair_flag; ///< RepairFlag
u8 program_index; ///< ProgramIndex
u8 required_network_service_license_on_launch; ///< RequiredNetworkServiceLicenseOnLaunchFlag
u32 reserved_x3214; ///< Reserved
NacpNeighborDetectionClientConfiguration neighbor_detection_client_configuration; ///< NeighborDetectionClientConfiguration
NacpApplicationJitConfiguration jit_configuration; ///< JitConfiguration
u8 reserved_x33c0[0xc40]; ///< Reserved
} NacpStruct;

/// Get the NacpLanguageEntry from the input nacp corresponding to the current system language (this may fallback to other languages when needed). Output langentry is NULL if none found / content of entry is empty.
/// If you're using ns you may want to use \ref nsGetApplicationDesiredLanguage instead.
Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry);
Loading