From 81678a8c5c09669488f32e5a1956aac7111ca66d Mon Sep 17 00:00:00 2001 From: Caroline Joy Bell Date: Thu, 1 Feb 2024 16:17:11 -0600 Subject: [PATCH] git subrepo clone https://github.com/c08oprkiua/godot-wii-u platform/wiiu subrepo: subdir: "platform/wiiu" merged: "1b5c230ac9" upstream: origin: "https://github.com/c08oprkiua/godot-wii-u" branch: "main" commit: "1b5c230ac9" git-subrepo: version: "0.4.6" origin: "https://github.com/ingydotnet/git-subrepo" commit: "110b9eb" --- platform/wiiu/.gitrepo | 12 ++ platform/wiiu/README.md | 39 ++++ platform/wiiu/detect.py | 82 +++++++ platform/wiiu/export/export.cpp | 51 +++++ platform/wiiu/export/export.h | 36 ++++ platform/wiiu/godot_wiiu.cpp | 63 ++++++ platform/wiiu/graphics/CafeGLSLCompiler.h | 87 ++++++++ platform/wiiu/graphics/rd_gx2_texture.cpp | 88 ++++++++ .../wiiu/graphics/rendering_device_gx2.cpp | 32 +++ platform/wiiu/graphics/rendering_device_gx2.h | 200 ++++++++++++++++++ .../wiiu/graphics/wiiu_display_server.cpp | 2 + platform/wiiu/graphics/wiiu_display_server.h | 30 +++ .../wiiu/graphics/wiiu_drc_display_server.cpp | 26 +++ .../wiiu/graphics/wiiu_tv_display_server.cpp | 4 + platform/wiiu/input/drc.cpp | 7 + platform/wiiu/input/drc.h | 0 platform/wiiu/input/input_wiiu.h | 48 +++++ platform/wiiu/input/kpad.cpp | 5 + platform/wiiu/input/kpad.h | 0 platform/wiiu/logo.png | Bin 0 -> 5762 bytes platform/wiiu/os_wiiu.cpp | 109 ++++++++++ platform/wiiu/os_wiiu.h | 117 ++++++++++ platform/wiiu/platform_config.h | 6 + platform/wiiu/platform_thread.cpp | 109 ++++++++++ platform/wiiu/platform_thread.h | 79 +++++++ platform/wiiu/processor/wiiu_mutex.cpp | 0 platform/wiiu/processor/wiiu_mutex.h | 0 platform/wiiu/processor/wiiu_semaphore.cpp | 0 platform/wiiu/processor/wiiu_semaphore.h | 0 platform/wiiu/processor/wiiu_thread.cpp | 39 ++++ platform/wiiu/processor/wiiu_thread.h | 19 ++ 31 files changed, 1290 insertions(+) create mode 100644 platform/wiiu/.gitrepo create mode 100644 platform/wiiu/README.md create mode 100644 platform/wiiu/detect.py create mode 100644 platform/wiiu/export/export.cpp create mode 100644 platform/wiiu/export/export.h create mode 100644 platform/wiiu/godot_wiiu.cpp create mode 100644 platform/wiiu/graphics/CafeGLSLCompiler.h create mode 100644 platform/wiiu/graphics/rd_gx2_texture.cpp create mode 100644 platform/wiiu/graphics/rendering_device_gx2.cpp create mode 100644 platform/wiiu/graphics/rendering_device_gx2.h create mode 100644 platform/wiiu/graphics/wiiu_display_server.cpp create mode 100644 platform/wiiu/graphics/wiiu_display_server.h create mode 100644 platform/wiiu/graphics/wiiu_drc_display_server.cpp create mode 100644 platform/wiiu/graphics/wiiu_tv_display_server.cpp create mode 100644 platform/wiiu/input/drc.cpp create mode 100644 platform/wiiu/input/drc.h create mode 100644 platform/wiiu/input/input_wiiu.h create mode 100644 platform/wiiu/input/kpad.cpp create mode 100644 platform/wiiu/input/kpad.h create mode 100644 platform/wiiu/logo.png create mode 100644 platform/wiiu/os_wiiu.cpp create mode 100644 platform/wiiu/os_wiiu.h create mode 100644 platform/wiiu/platform_config.h create mode 100644 platform/wiiu/platform_thread.cpp create mode 100644 platform/wiiu/platform_thread.h create mode 100644 platform/wiiu/processor/wiiu_mutex.cpp create mode 100644 platform/wiiu/processor/wiiu_mutex.h create mode 100644 platform/wiiu/processor/wiiu_semaphore.cpp create mode 100644 platform/wiiu/processor/wiiu_semaphore.h create mode 100644 platform/wiiu/processor/wiiu_thread.cpp create mode 100644 platform/wiiu/processor/wiiu_thread.h diff --git a/platform/wiiu/.gitrepo b/platform/wiiu/.gitrepo new file mode 100644 index 000000000000..eaea60c69c30 --- /dev/null +++ b/platform/wiiu/.gitrepo @@ -0,0 +1,12 @@ +; DO NOT EDIT (unless you know what you are doing) +; +; This subdirectory is a git "subrepo", and this file is maintained by the +; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme +; +[subrepo] + remote = https://github.com/c08oprkiua/godot-wii-u + branch = main + commit = 1b5c230ac9fda518cb0152dd487a0b2273e595c9 + parent = c7fb0645af400a1859154bcee9394e63bdabd198 + method = merge + cmdver = 0.4.6 diff --git a/platform/wiiu/README.md b/platform/wiiu/README.md new file mode 100644 index 000000000000..c4c5dea2dc1c --- /dev/null +++ b/platform/wiiu/README.md @@ -0,0 +1,39 @@ +# godot-wii-u +WIP port of Godot 4 to Wii U + +Uses Wii U Toolchain. + +This repo will only contain the relevant folders to add to an existing copy of the Godot source code. + + +# Progress +## Vital core things +- [ ] Threading (coreinit) + - [ ] Thread (coreinit/thread) + - [ ] Mutex (coreinit/mutex) + - [ ] Semaphore (coreinit/semaphore) +- [ ] Crash handling +- [ ] OS integration + - [ ] Home Menu (ProcUI) + - [ ] Keyboard overlay (swkbd) + - [x] Software information + - [x] Hardware information + - [ ] Time (Time) + +## Secondary vital core things +- [ ] Filesystem access +- [ ] Graphics (gx2, gx2r) +- [ ] Audio (sndcore2) +- [ ] Input + - [ ] Gamepad (VPAD) + - [ ] Wii remotes (KPAD) + +## Nice QoL things +- [ ] Networking + - [ ] HTTPClient + +# Compiling + +I'm adding this here just so people don't ask about it. The SCons script to build the platform isn't done, nor will I worry about it until I have enough done to make it work trying to compile to see if it works. + +If you have any questions, join [The Homebrodot Discord](https://discord.gg/mYzXDke5yv),[my Discord](https://discord.com/invite/Mu6YUEmerN) or make an issue here on GitHub. diff --git a/platform/wiiu/detect.py b/platform/wiiu/detect.py new file mode 100644 index 000000000000..fdd12c487115 --- /dev/null +++ b/platform/wiiu/detect.py @@ -0,0 +1,82 @@ +import os +import platform +import sys + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from SCons import Environment + +#Godot for Wii U +#Based heavily on the Android port, because that's a prime example of linking external libraries, +#compiling for an arch that is not the host's arch, etc. Also based on SeleDream's port of Godot 4 to 3DS. + +def is_active(): + return False #Needs to be true for the platform to be usable, false for convenience + +def get_name(): + return "Wii U" + +def can_build(): + if not(os.getenv("DEVKITPRO") and os.getenv("DEVKITPPC")): + print("Either DevKitPro or DevKitPPC were not found, Wii U disabled.") + return False + return True + + +def get_opts(): + from SCons.Variables import BoolVariable, EnumVariable + + return [ + EnumVariable("linker", "Linker program", "default", ("default", "bfd", "gold", "lld", "mold")), + BoolVariable("use_static_cpp", "Link libgcc and libstdc++ statically for better portability", True), + BoolVariable("use_coverage", "Test Godot coverage", False), + BoolVariable("use_ubsan", "Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)", False), + BoolVariable("use_asan", "Use LLVM/GCC compiler address sanitizer (ASAN)", False), + BoolVariable("use_lsan", "Use LLVM/GCC compiler leak sanitizer (LSAN)", False), + BoolVariable("use_tsan", "Use LLVM/GCC compiler thread sanitizer (TSAN)", False), + BoolVariable("use_msan", "Use LLVM compiler memory sanitizer (MSAN)", False), + BoolVariable("use_sowrap", "Dynamically load system libraries", True), + BoolVariable("alsa", "Use ALSA", True), + BoolVariable("touch", "Enable touch events", True), #probably the only option here that should stay lol + BoolVariable("execinfo", "Use libexecinfo on systems where glibc is not available", False), + ] + +def get_doc_classes(): + return [ + "EditorExportPlatformWiiU", + ] + +def get_doc_path(): + return "doc_classes" + +def get_flags(): + return [ + ("arch", "ppc32"), + ] + +def configure(env: "Environment"): + # Validate arch. These are supported COMPILE arches, not supported EXPORT arches. + supported_arches = ["x86_32", "x86_64", "arm32", "arm64"] #Does devkitppc even work on ARM...??? + if env["arch"] not in supported_arches: + print( + 'Unsupported CPU architecture "%s" for Wii U. Supported architectures are: %s.' + % (env["arch"], ", ".join(supported_arches)) + ) + sys.exit() + + ## Build type + + env["bits"] = "32" + + ## Compiler configuration + devkitpath = env["DEVKITPRO"] + wutpath = devkitpath + "/wut" + wuhbpath = devkitpath + "tools/bin/wuhbtool" #I figure this will be needed to export to wuhb? + #Link flags + + env.Prepend(CPPPATH=["#platform/wiiu"]) + env.Append(LIBS=["wut"]) + + + diff --git a/platform/wiiu/export/export.cpp b/platform/wiiu/export/export.cpp new file mode 100644 index 000000000000..09a0c883fa1e --- /dev/null +++ b/platform/wiiu/export/export.cpp @@ -0,0 +1,51 @@ +/*************************************************************************/ +/* export.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "export.h" + +#include "editor/export/editor_export.h" + +void register_wiiu_exporter_types(){ + GDREGISTER_VIRTUAL_CLASS(EditorExportPlatformWiiU) +} + +void register_wiiu_exporter() { + + { + Ref exporter = Ref( memnew(EditorExportPlatformWiiU) ); + exporter->set_binary_extension("rpx"); + exporter->set_release_binary32("wiiu_release"); + exporter->set_debug_binary32("wiiu_debug"); + platform->set_name("Wii U"); + platform->set_os_name("Wii U"); + + EditorExport::get_singleton()->add_export_platform(exporter); + } + +} diff --git a/platform/wiiu/export/export.h b/platform/wiiu/export/export.h new file mode 100644 index 000000000000..f29ebb468c02 --- /dev/null +++ b/platform/wiiu/export/export.h @@ -0,0 +1,36 @@ +/*************************************************************************/ +/* export.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef WIIU_EXPORT_H +#define WIIU_EXPORT_H + +void register_wiiu_exporter_types(); +void register_wiiu_exporter(); + +#endif \ No newline at end of file diff --git a/platform/wiiu/godot_wiiu.cpp b/platform/wiiu/godot_wiiu.cpp new file mode 100644 index 000000000000..337bd0554a79 --- /dev/null +++ b/platform/wiiu/godot_wiiu.cpp @@ -0,0 +1,63 @@ +//WUT stuff +#include +#include +#include +#include + +//platform files +#include "os_wiiu.h" +#include "processor/wiiu_thread.h" +#include "graphics/CafeGLSLCompiler.h" + +#ifndef PLATFORM_THREAD_OVERRIDE +#include "core/os/thread.h" +#else +#include "platform/wiiu/platform_thread.h" +#endif + +int main(int argc, char *argv) { + OS_WiiU os; + + //Setting the special platform thread functions + Thread::PlatformFunctions customfuncs; + customfuncs.init = wiiu_thread_init; + customfuncs.set_name = wiiu_thread_set_name; + customfuncs.set_priority = wiiu_thread_set_priority; + customfuncs.wrapper = wiiu_thread_call_wrap; + customfuncs.term = wiiu_thread_term; + Thread::_set_platform_functions(customfuncs) + + //Start the Wii U stuff + WHBProcInit(); + WhbGfxInit(); + InitGLSLCompiler(); + VPADInit(); //idc if it's depreciated + KPADInit(); + + + + + //Basically copy pasted from godot_linuxbsd.cpp's main function + char *cwd = (char *)malloc(PATH_MAX); + ERR_FAIL_NULL_V(cwd, ERR_OUT_OF_MEMORY); + char *ret = getcwd(cwd, PATH_MAX); + //Set up Godot + Error err = Main::setup(argv[0], argc - 1, &argv[1]); + if (err != OK) { + free(cwd); + if (err == ERR_HELP) { // Returned by --help and --version, so success. + return 0; + } + return 255; + } + //Run the Godot-integrated main loop + if (Main::start()) { + os.set_exit_code(EXIT_SUCCESS); + os.run(); // This is the REAL main loop + } + Main::cleanup(); + + + + return os.get_exit_code(); +} \ No newline at end of file diff --git a/platform/wiiu/graphics/CafeGLSLCompiler.h b/platform/wiiu/graphics/CafeGLSLCompiler.h new file mode 100644 index 000000000000..1f4eb04ad44e --- /dev/null +++ b/platform/wiiu/graphics/CafeGLSLCompiler.h @@ -0,0 +1,87 @@ +#pragma once +#include + +#if defined(__WUT__) || defined(__WIIU__) +#include +#include +#include + +#define GLSL_COMPILER_CAFE_RPL // use compiler as rpl +#endif + +#ifdef GLSL_COMPILER_CAFE_RPL +inline OSDynLoad_Module s_glslCompilerModule = nullptr; +#endif + +enum GLSL_COMPILER_FLAG +{ + // reserved for future use + GLSL_COMPILER_FLAG_NONE = 0, + GLSL_COMPILER_FLAG_GENERATE_DISASSEMBLY = 1 << 0, // write disassembly to stderr +}; + +inline GX2VertexShader* (*GLSL_CompileVertexShader)(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags); +inline GX2PixelShader* (*GLSL_CompilePixelShader)(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags); +inline void (*GLSL_FreeVertexShader)(GX2VertexShader* shader); +inline void (*GLSL_FreePixelShader)(GX2PixelShader* shader); +inline void (*__GLSL_DestroyGLSLCompiler)(); + +#ifndef GLSL_COMPILER_CAFE_RPL +extern "C" +{ + void InitGLSLCompiler(); + void DestroyGLSLCompiler(); + GX2VertexShader* CompileVertexShader(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags); + GX2PixelShader* CompilePixelShader(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags); + void FreeVertexShader(GX2VertexShader* shader); + void FreePixelShader(GX2PixelShader* shader); +}; +#endif + +static inline bool GLSL_Init() +{ + void (*_InitGLSLCompiler)() = nullptr; +#if defined(__WUT__) || defined(__WIIU__) + if (s_glslCompilerModule != nullptr) + return false; + OSDynLoad_Error r = OSDynLoad_Acquire("glslcompiler", &s_glslCompilerModule); + if(r != OS_DYNLOAD_OK) // try alternate path + r = OSDynLoad_Acquire("~/wiiu/libs/glslcompiler.rpl", &s_glslCompilerModule); + if (r != OS_DYNLOAD_OK) + { + OSReport("glslcompiler.rpl not found\n"); + return false; + } + // find exports + OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "InitGLSLCompiler", (void**)&_InitGLSLCompiler); + OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "CompileVertexShader", (void**)&GLSL_CompileVertexShader); + OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "CompilePixelShader", (void**)&GLSL_CompilePixelShader); + OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "FreeVertexShader", (void**)&GLSL_FreeVertexShader); + OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "FreePixelShader", (void**)&GLSL_FreePixelShader); + OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "DestroyGLSLCompiler", (void**)&__GLSL_DestroyGLSLCompiler); +#else + _InitGLSLCompiler = InitGLSLCompiler; + GLSL_CompileVertexShader = CompileVertexShader; + GLSL_CompilePixelShader = CompilePixelShader; + GLSL_FreeVertexShader = FreeVertexShader; + GLSL_FreePixelShader = FreePixelShader; + __GLSL_DestroyGLSLCompiler = DestroyGLSLCompiler; +#endif + _InitGLSLCompiler(); + return true; +} + +static inline bool GLSL_Shutdown() +{ +#ifdef GLSL_COMPILER_CAFE_RPL + if (s_glslCompilerModule == nullptr) + return false; + __GLSL_DestroyGLSLCompiler(); + OSDynLoad_Release(s_glslCompilerModule); + s_glslCompilerModule = nullptr; +#else + __GLSL_DestroyGLSLCompiler(); +#endif + return true; +} + diff --git a/platform/wiiu/graphics/rd_gx2_texture.cpp b/platform/wiiu/graphics/rd_gx2_texture.cpp new file mode 100644 index 000000000000..a74f735b389d --- /dev/null +++ b/platform/wiiu/graphics/rd_gx2_texture.cpp @@ -0,0 +1,88 @@ +#include "rendering_device_gx2.h" + +//"I paid for the whole GX2, I'm gonna use the whole GX2." +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +RID RenderingDevice_GX2::texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector> &p_data){ + GX2Surface newsurface; + newsurface.width = p_format.width; + newsurface.height = p_format.height; + newsurface.depth = p_format.depth; + newsurface.mipmaps = p_format.mipmaps; + + +} + +RID texture_create_shared(const TextureView &p_view, RID p_with_texture){ + +} + +RID texture_create_from_extension(TextureType p_type, DataFormat p_format, TextureSamples p_samples, BitField p_flags, uint64_t p_image, uint64_t p_width, uint64_t p_height, uint64_t p_depth, uint64_t p_layers){ + +} + +RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D, uint32_t p_layers = 0){ + +} + +Error RenderingDevice_GX2::texture_update(RID p_texture, uint32_t p_layer, const Vector &p_data, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS){ + +} + +Vector RenderingDevice_GX2::texture_get_data(RID p_texture, uint32_t p_layer){ + +} // CPU textures will return immediately, while GPU textures will most likely force a flush + +bool RenderingDevice_GX2::texture_is_format_supported_for_usage(DataFormat p_format, BitField p_usage){ + +} + +bool RenderingDevice_GX2::texture_is_shared(RID p_texture){ + +} + +bool RenderingDevice_GX2::texture_is_valid(RID p_texture){ + +} + +TextureFormat RenderingDevice_GX2::texture_get_format(RID p_texture){ + +} + +Size2i RenderingDevice_GX2::texture_size(RID p_texture){ + +} + +uint64_t RenderingDevice_GX2::texture_get_native_handle(RID p_texture){ + +} + +Error RenderingDevice_GX2::texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS){ + +} + +Error RenderingDevice_GX2::texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS){ + +} + +Error RenderingDevice_GX2::texture_resolve_multisample(RID p_from_texture, RID p_to_texture, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS){ + +} diff --git a/platform/wiiu/graphics/rendering_device_gx2.cpp b/platform/wiiu/graphics/rendering_device_gx2.cpp new file mode 100644 index 000000000000..f92d938c15a7 --- /dev/null +++ b/platform/wiiu/graphics/rendering_device_gx2.cpp @@ -0,0 +1,32 @@ +#include "rendering_device_gx2.h" + +//"I paid for the whole GX2, I'm gonna use the whole GX2." +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +RID RenderingDevice_GX2::texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector> &p_data){ + GX2Surface newsurface; + newsurface.width = p_format.width; + newsurface.height = p_format.height; + newsurface.depth = p_format.depth; + newsurface.mipmaps = p_format.mipmaps; + + +} \ No newline at end of file diff --git a/platform/wiiu/graphics/rendering_device_gx2.h b/platform/wiiu/graphics/rendering_device_gx2.h new file mode 100644 index 000000000000..d13676fc69a8 --- /dev/null +++ b/platform/wiiu/graphics/rendering_device_gx2.h @@ -0,0 +1,200 @@ +#include "servers/rendering/rendering_device.h" + +class RenderingDevice_GX2: public RenderingDevice { +public: + + virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector> &p_data = Vector>()) = 0; + virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture) = 0; + virtual RID texture_create_from_extension(TextureType p_type, DataFormat p_format, TextureSamples p_samples, BitField p_flags, uint64_t p_image, uint64_t p_width, uint64_t p_height, uint64_t p_depth, uint64_t p_layers) = 0; + + virtual RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D, uint32_t p_layers = 0) = 0; + + virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector &p_data, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual Vector texture_get_data(RID p_texture, uint32_t p_layer) = 0; // CPU textures will return immediately, while GPU textures will most likely force a flush + + virtual bool texture_is_format_supported_for_usage(DataFormat p_format, BitField p_usage) const = 0; + virtual bool texture_is_shared(RID p_texture) = 0; + virtual bool texture_is_valid(RID p_texture) = 0; + virtual TextureFormat texture_get_format(RID p_texture) = 0; + virtual Size2i texture_size(RID p_texture) = 0; + virtual uint64_t texture_get_native_handle(RID p_texture) = 0; + + virtual Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + + virtual FramebufferFormatID framebuffer_format_create_multipass(const Vector &p_attachments, const Vector &p_passes, uint32_t p_view_count = 1) = 0; + virtual FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1) = 0; + virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0) = 0; + + virtual RID framebuffer_create(const Vector &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1) = 0; + virtual RID framebuffer_create_multipass(const Vector &p_texture_attachments, const Vector &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1) = 0; + virtual RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID) = 0; + virtual bool framebuffer_is_valid(RID p_framebuffer) const = 0; + virtual void framebuffer_set_invalidation_callback(RID p_framebuffer, InvalidationCallback p_callback, void *p_userdata) = 0; + + virtual FramebufferFormatID framebuffer_get_format(RID p_framebuffer) = 0; + + + virtual RID sampler_create(const SamplerState &p_state) = 0; + virtual bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_sampler_filter) const = 0; + + virtual RID vertex_buffer_create(uint32_t p_size_bytes, const Vector &p_data = Vector(), bool p_use_as_storage = false) = 0; + + typedef int64_t VertexFormatID; + + // This ID is warranted to be unique for the same formats, does not need to be freed + virtual VertexFormatID vertex_format_create(const Vector &p_vertex_formats) = 0; + virtual RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector &p_src_buffers, const Vector &p_offsets = Vector()) = 0; + + virtual RID index_buffer_create(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector &p_data = Vector(), bool p_use_restart_indices = false) = 0; + virtual RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count) = 0; + + virtual bool has_feature(const Features p_feature) const = 0; + + virtual Vector shader_compile_spirv_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language = SHADER_LANGUAGE_GLSL, String *r_error = nullptr, bool p_allow_cache = true); + virtual String shader_get_spirv_cache_key() const; + + static void shader_set_compile_to_spirv_function(ShaderCompileToSPIRVFunction p_function); + static void shader_set_spirv_cache_function(ShaderCacheFunction p_function); + static void shader_set_get_cache_key_function(ShaderSPIRVGetCacheKeyFunction p_function); + + virtual String shader_get_binary_cache_key() const = 0; + virtual Vector shader_compile_binary_from_spirv(const Vector &p_spirv, const String &p_shader_name = "") = 0; + + virtual RID shader_create_from_spirv(const Vector &p_spirv, const String &p_shader_name = ""); + virtual RID shader_create_from_bytecode(const Vector &p_shader_binary, RID p_placeholder = RID()) = 0; + virtual RID shader_create_placeholder() = 0; + + virtual uint64_t shader_get_vertex_input_attribute_mask(RID p_shader) = 0; + + virtual RID uniform_buffer_create(uint32_t p_size_bytes, const Vector &p_data = Vector()) = 0; + virtual RID storage_buffer_create(uint32_t p_size, const Vector &p_data = Vector(), BitField p_usage = 0) = 0; + virtual RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector &p_data = Vector()) = 0; + + virtual RID uniform_set_create(const Vector &p_uniforms, RID p_shader, uint32_t p_shader_set) = 0; + virtual bool uniform_set_is_valid(RID p_uniform_set) = 0; + virtual void uniform_set_set_invalidation_callback(RID p_uniform_set, InvalidationCallback p_callback, void *p_userdata) = 0; + + virtual Error buffer_copy(RID p_src_buffer, RID p_dst_buffer, uint32_t p_src_offset, uint32_t p_dst_offset, uint32_t p_size, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual Vector buffer_get_data(RID p_buffer, uint32_t p_offset = 0, uint32_t p_size = 0) = 0; // This causes stall, only use to retrieve large buffers for saving. + + virtual bool render_pipeline_is_valid(RID p_pipeline) = 0; + virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, BitField p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector &p_specialization_constants = Vector()) = 0; + + virtual RID compute_pipeline_create(RID p_shader, const Vector &p_specialization_constants = Vector()) = 0; + virtual bool compute_pipeline_is_valid(RID p_pipeline) = 0; + + virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const = 0; + virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const = 0; + virtual FramebufferFormatID screen_get_framebuffer_format() const = 0; + + virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color()) = 0; + virtual DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector &p_clear_color_values = Vector(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector &p_storage_textures = Vector()) = 0; + virtual Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector &p_clear_color_values = Vector(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector &p_storage_textures = Vector()) = 0; + + virtual void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color) = 0; + virtual void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline) = 0; + virtual void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index) = 0; + virtual void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array) = 0; + virtual void draw_list_bind_index_array(DrawListID p_list, RID p_index_array) = 0; + virtual void draw_list_set_line_width(DrawListID p_list, float p_width) = 0; + virtual void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size) = 0; + + virtual void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0) = 0; + + virtual void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect) = 0; + virtual void draw_list_disable_scissor(DrawListID p_list) = 0; + + virtual uint32_t draw_list_get_current_pass() = 0; + virtual DrawListID draw_list_switch_to_next_pass() = 0; + virtual Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids) = 0; + + virtual void draw_list_end(BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + + virtual ComputeListID compute_list_begin(bool p_allow_draw_overlap = false) = 0; + virtual void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline) = 0; + virtual void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index) = 0; + virtual void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size) = 0; + virtual void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) = 0; + virtual void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads) = 0; + virtual void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset) = 0; + virtual void compute_list_add_barrier(ComputeListID p_list) = 0; + + virtual void compute_list_end(BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0; + + virtual void barrier(BitField p_from = BARRIER_MASK_ALL_BARRIERS, BitField p_to = BARRIER_MASK_ALL_BARRIERS) = 0; + virtual void full_barrier() = 0; + + virtual void free(RID p_id) = 0; + + virtual void capture_timestamp(const String &p_name) = 0; + virtual uint32_t get_captured_timestamps_count() const = 0; + virtual uint64_t get_captured_timestamps_frame() const = 0; + virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const = 0; + virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const = 0; + virtual String get_captured_timestamp_name(uint32_t p_index) const = 0; + + + virtual uint64_t get_memory_usage(MemoryType p_type) const = 0; + + virtual RenderingDevice *create_local_device() = 0; + + virtual void set_resource_name(RID p_id, const String p_name) = 0; + + virtual void draw_command_begin_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1)) = 0; + virtual void draw_command_insert_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1)) = 0; + virtual void draw_command_end_label() = 0; + + virtual String get_device_vendor_name() const = 0; + virtual String get_device_name() const = 0; + virtual RenderingDevice::DeviceType get_device_type() const = 0; + virtual String get_device_api_version() const = 0; + virtual String get_device_pipeline_cache_uuid() const = 0; + + virtual uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0) = 0; + + static RenderingDevice *get_singleton(); + RenderingDevice(); + +protected: + static const char *shader_stage_names[RenderingDevice::SHADER_STAGE_MAX]; + + static const uint32_t MAX_UNIFORM_SETS = 16; + + //binders to script API + RID _texture_create(const Ref &p_format, const Ref &p_view, const TypedArray &p_data = Array()); + RID _texture_create_shared(const Ref &p_view, RID p_with_texture); + RID _texture_create_shared_from_slice(const Ref &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D); + Ref _texture_get_format(RID p_rd_texture); + + FramebufferFormatID _framebuffer_format_create(const TypedArray &p_attachments, uint32_t p_view_count); + FramebufferFormatID _framebuffer_format_create_multipass(const TypedArray &p_attachments, const TypedArray &p_passes, uint32_t p_view_count); + RID _framebuffer_create(const TypedArray &p_textures, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1); + RID _framebuffer_create_multipass(const TypedArray &p_textures, const TypedArray &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1); + RID _sampler_create(const Ref &p_state); + VertexFormatID _vertex_format_create(const TypedArray &p_vertex_formats); + RID _vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const TypedArray &p_src_buffers, const Vector &p_offsets = Vector()); + + Ref _shader_compile_spirv_from_source(const Ref &p_source, bool p_allow_cache = true); + Vector _shader_compile_binary_from_spirv(const Ref &p_bytecode, const String &p_shader_name = ""); + RID _shader_create_from_spirv(const Ref &p_spirv, const String &p_shader_name = ""); + + RID _uniform_set_create(const TypedArray &p_uniforms, RID p_shader, uint32_t p_shader_set); + + Error _buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector &p_data, BitField p_post_barrier = BARRIER_MASK_ALL_BARRIERS); + + RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref &p_rasterization_state, const Ref &p_multisample_state, const Ref &p_depth_stencil_state, const Ref &p_blend_state, BitField p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray &p_specialization_constants); + RID _compute_pipeline_create(RID p_shader, const TypedArray &p_specialization_constants); + + DrawListID _draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector &p_clear_color_values = Vector(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray &p_storage_textures = TypedArray()); + Vector _draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector &p_clear_color_values = Vector(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray &p_storage_textures = TypedArray()); + void _draw_list_set_push_constant(DrawListID p_list, const Vector &p_data, uint32_t p_data_size); + void _compute_list_set_push_constant(ComputeListID p_list, const Vector &p_data, uint32_t p_data_size); + Vector _draw_list_switch_to_next_pass_split(uint32_t p_splits); + + Error _reflect_spirv(const Vector &p_spirv, SpirvReflectionData &r_reflection_data); + +} \ No newline at end of file diff --git a/platform/wiiu/graphics/wiiu_display_server.cpp b/platform/wiiu/graphics/wiiu_display_server.cpp new file mode 100644 index 000000000000..7da847d08ec5 --- /dev/null +++ b/platform/wiiu/graphics/wiiu_display_server.cpp @@ -0,0 +1,2 @@ + +#include "servers/display_server.h" \ No newline at end of file diff --git a/platform/wiiu/graphics/wiiu_display_server.h b/platform/wiiu/graphics/wiiu_display_server.h new file mode 100644 index 000000000000..094b14d8dff7 --- /dev/null +++ b/platform/wiiu/graphics/wiiu_display_server.h @@ -0,0 +1,30 @@ +#include "servers/display_server.h" + +#include + + +//Wii U has various TV resolutions ranging from 480i to 1080p. +class WiiUTVDisplayServer: public DisplayServer { + has_feature(Feature feature); +} + +//DRC is 480p, maybe I could support 720p cause I heard 720p gamepad streams +//are a thing, and this class will also handle button inputs from the DRC because +//of how the VPAD library works +class WiiUDRCDisplayServer: public DisplayServer { + +private: + + VPADStatus drc_state; + VPADChan drc_chan = VPAD_CHAN_0; + VPADReadError drc_err; + +public: + + bool has_feature(Feature feature); + + void update_drc_inputs(); //call this in main loop to update VPADStatus + + //Nintendoland uses it vertically, so... + void screen_set_orientation(ScreenOrientation p_orientation, int p_screen); +} \ No newline at end of file diff --git a/platform/wiiu/graphics/wiiu_drc_display_server.cpp b/platform/wiiu/graphics/wiiu_drc_display_server.cpp new file mode 100644 index 000000000000..3c353b49bca2 --- /dev/null +++ b/platform/wiiu/graphics/wiiu_drc_display_server.cpp @@ -0,0 +1,26 @@ +#include "wiiu_display_server.h" +#include + +void WiiUDRCDisplayServer::has_feature(Feature feature){ + return false; //Placeholder; it should support touch screen, etc. +} + +void WiiUDRCDisplayServer::update_drc_inputs(){ + VPADRead(drc_chan,drc_state, 1, *drc_err); + + /* + Check drc_err for errors + + + + Pass off controller inputs to Input, idk how yet + + Orphan values to pass to "unrelated" places: + * battery: ???? + * slideVolume, usingHeadphones: Audio output (coming soon:tm:) + * micStatus: Audio input (coming soon:tm:) + + VPAD has several layers of touch validity checks it provides to get, well, accurate + touch results. + +} \ No newline at end of file diff --git a/platform/wiiu/graphics/wiiu_tv_display_server.cpp b/platform/wiiu/graphics/wiiu_tv_display_server.cpp new file mode 100644 index 000000000000..cff89dac4506 --- /dev/null +++ b/platform/wiiu/graphics/wiiu_tv_display_server.cpp @@ -0,0 +1,4 @@ + #include "wiiu_display_server.h" + + WiiUTVDisplayServer::has_feature(Feature feature){ +} \ No newline at end of file diff --git a/platform/wiiu/input/drc.cpp b/platform/wiiu/input/drc.cpp new file mode 100644 index 000000000000..cbc17bef3179 --- /dev/null +++ b/platform/wiiu/input/drc.cpp @@ -0,0 +1,7 @@ +#include "input_wiiu.h" + +#include + +void InputWiiU::process_vpad(){ + +} \ No newline at end of file diff --git a/platform/wiiu/input/drc.h b/platform/wiiu/input/drc.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/wiiu/input/input_wiiu.h b/platform/wiiu/input/input_wiiu.h new file mode 100644 index 000000000000..d929dc7e4b93 --- /dev/null +++ b/platform/wiiu/input/input_wiiu.h @@ -0,0 +1,48 @@ +#include "core/input/input.h" +#include +#include + +//Note: Touch input is *usually* handled by DisplayServer, not the input singleton, +//which might cause issues with multi-DRC and touch inputs, idk. + +//This class handles input from both the gamepad and any connected Wiimotes or other controllers. +//However, the backing code + +class InputWiiU { +public: + InputWiiU(); + ~InputWiiU(); + + DRC vpads[1]; + Wiimote kpads[3]; + + struct DRC { + //Pointer to a DisplayServer exclusive to that gamepad, + //so that multiple unique displays are possible + + VPadStatus drcinputs; + //Whether the DRC is actually connected/in use + bool active; + } + + struct Wiimote { + KPADStatus basebuttons; + //Whether the Wiimote is actually active + bool active; + + } + + void process_vpad(); + void process_kpad(); + + void process_inputs(); + void process_joypads(){ + process_vpad(); + process_kpad(); + }; + + void setup_kpad(); + void setup_vpad(); + + Input *input; +}; \ No newline at end of file diff --git a/platform/wiiu/input/kpad.cpp b/platform/wiiu/input/kpad.cpp new file mode 100644 index 000000000000..86947b367862 --- /dev/null +++ b/platform/wiiu/input/kpad.cpp @@ -0,0 +1,5 @@ +#include "input_wiiu.h" + +void InputWiiU::process_kpad(){ + +} \ No newline at end of file diff --git a/platform/wiiu/input/kpad.h b/platform/wiiu/input/kpad.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/wiiu/logo.png b/platform/wiiu/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..7a9654aa0f8f447d1ba59b4d54e5bb67f8bb6ba3 GIT binary patch literal 5762 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 + +//For system info +#include +#include +#include + +//Temporary until fileaccess is implemented? +#include + +void OS_WiiU::alert(const String &p_alert, const String &p_title) { + //Not sure what this FSClient stuff does but it's important + //TODO: Memory allocation in a Godot-native way + FSClient *fsClient = (FSClient *) //something memory allocation + FSAddClient(*fsClient, FS_ERROR_OK) + + nn::erreula::CreateArg newargument; + newargument.region = nn::erreula::RegionType::USA; + newargument.language = nn:erreula::LangType::English; + //newargument.workMemory = //something memory allocation + newargument.fsClient = *fsClient + + nn::erreula::AppearArg errorbubble; + errorbubble.errorArg.errorType = nn::erreula::ErrorType::Message1Button; + errorbubble.errorArg.renderTarget = nn::erreula::RenderTarget::Both; + //To-do: Have it ask for whichever controller is P1 + errorbubble.errorArg.errorMessage = p_alert; + errorbubble.errorArg.button1Label = "Ok"; + errorbubble.errorArg.errorTitle = p_title; + nn::erreula::AppearErrorViewer(errorbubble); + //I think the rest of the "cleanup" code is supposed to go elsewhere, like a mainloop or something +} + +String OS_WiiU::get_name() const { + return "Wii U"; +} + +String OS_WiiU::get_distribution_name() const { + return "Cafe OS"; +} + +String OS_WiiU::get_version() const { + //Still dunno what's going on here + MCPSystemVersion returnthis; + uint32_t param1; + MCP_GetSystemVersion(param1, *returnthis); + return "5.5.5"; +} + +String OS_WiiU::get_processor_name() const { + return "Espresso"; +} + +PackedStringArray OS_WiiU::get_video_adapter_driver_info() const { + PackedStringArray info; + info.append("amd"); + info.append("1.0"); + return info; +} + +Error OS_WiiU::shell_open(String uri) { + //Implement check for http, open in Internet Browser if found + //Implement for some sort of titleid handle, for launching apps + return ERR_METHOD_NOT_FOUND +} + +double OS_WiiU::get_unix_time() { + OSCalendarTime thetime; + thetime = OSGetTime(); + +} + +void OS_WiiU::run(){ + if (!main_loop) { + return; + } + + main_loop->initialize(); + + //uint64_t last_ticks=get_ticks_usec(); + + //int frames=0; + //uint64_t frame=0; + + while (true) { + DisplayServer::get_singleton()->process_events(); // get rid of pending events + input_wiiu->process_inputs(); + + + if (Main::iteration()) { + break; + } + +} \ No newline at end of file diff --git a/platform/wiiu/os_wiiu.h b/platform/wiiu/os_wiiu.h new file mode 100644 index 000000000000..a4df5bb5694f --- /dev/null +++ b/platform/wiiu/os_wiiu.h @@ -0,0 +1,117 @@ +#include "core/config/project_settings.h" +#include "core/input/input.h" +#include "core/os/os.h" + + +#include "input/drc.h" +#include "input/kpad.h" + + +class OS_WiiU : public OS { +public: + + InputWiiU *input_wiiu; + + enum TVResolution { + RESOLUTION_1080P, + RESOLUTION_720P, + RESOLUTION_480P, + } + + TVResolution tvres; + + //Most of this is copy pasted from the Windows platform code + + //I think I need to go back and redo my implementation of this + virtual void alert(const String &p_alert, const String &p_title = "ALERT!") override; + + //Dunno what this is. + virtual Error get_entropy(uint8_t *r_buffer, int p_bytes) override; + + //Maybe these will be used for RPLs? I'll have to look into what exactly these are for + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override; + virtual Error close_dynamic_library(void *p_library_handle) override; + virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) override; + + virtual MainLoop *get_main_loop() const override; + + //OS info, some of this is implemented + virtual String get_name() const override; + virtual String get_distribution_name() const override; + virtual String get_version() const override; + virtual String get_locale() const override; + + + virtual String get_executable_path() const override; + + //Hardware info + virtual String get_processor_name() const override; + virtual Vector get_video_adapter_driver_info() const override; + + //To-do: Initialized WPADs, DRCs (which will be DisplayServer+VPAD) + virtual void initialize_joypads() override {} + + //Time/date info. Should be easy, I just haven't put it in + virtual DateTime get_datetime(bool p_utc) const override; + virtual TimeZoneInfo get_time_zone_info() const override; + virtual double get_unix_time() const override; + + //Font info + virtual Vector get_system_fonts() const override; + virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override; + virtual Vector get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override; + + + virtual Error set_cwd(const String &p_cwd) override; + + virtual void delay_usec(uint32_t p_usec) const override; + virtual uint64_t get_ticks_usec() const override; + + virtual Dictionary get_memory_info() const override; + + virtual Error execute(const String &p_path, const List &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) override; + virtual Error create_process(const String &p_path, const List &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override; + virtual Error kill(const ProcessID &p_pid) override; + virtual int get_process_id() const override; + virtual bool is_process_running(const ProcessID &p_pid) const override; + + //...What is an environment? + virtual bool has_environment(const String &p_var) const override; + virtual String get_environment(const String &p_var) const override; + virtual void set_environment(const String &p_var, const String &p_value) const override; + virtual void unset_environment(const String &p_var) const override; + + virtual uint64_t get_embedded_pck_offset() const override; + + virtual String get_config_path() const override; + virtual String get_data_path() const override; + virtual String get_cache_path() const override; + virtual String get_godot_dir_name() const override; + + virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override; + virtual String get_user_data_dir() const override; + + virtual String get_unique_id() const override; + + virtual Error shell_open(String p_uri) override; + virtual Error shell_show_in_file_manager(String p_path, bool p_open_folder) override; + + //Basically the main loop for the platform *within* the engine + void run(); + + virtual bool _check_internal_feature_support(const String &p_feature) override; + + virtual void disable_crash_handler() override; + virtual bool is_disable_crash_handler() const override; + virtual void initialize_debugging() override; + + virtual Error move_to_trash(const String &p_path) override; + + OS_WiiU(); + ~OS_WiiU(); +} + +// +class WiiUTerminalLogger: public StdLogger { + +} \ No newline at end of file diff --git a/platform/wiiu/platform_config.h b/platform/wiiu/platform_config.h new file mode 100644 index 000000000000..3c3d256a37a5 --- /dev/null +++ b/platform/wiiu/platform_config.h @@ -0,0 +1,6 @@ +#ifndef PLATFORM_CONFIG_H +#define PLATFORM_CONFIG_H + +#define PLATFORM_THREAD_OVERRIDE + +#endif \ No newline at end of file diff --git a/platform/wiiu/platform_thread.cpp b/platform/wiiu/platform_thread.cpp new file mode 100644 index 000000000000..60891776e1aa --- /dev/null +++ b/platform/wiiu/platform_thread.cpp @@ -0,0 +1,109 @@ +#include "platform_thread.h" +#include "core/object/script_language.h" +#include "core/templates/safe_refcount.h" + +#include + +Thread::PlatformFunctions Thread::platform_functions; + +SafeNumeric Thread::id_counter(1); // The first value after .increment() is 2, hence by default the main thread ID should be 1. + +thread_local Thread::ID Thread::caller_id = Thread::UNASSIGNED_ID; + +void Thread::PlatformFunctions::init(){ + +} + +void Thread::PlatformFunctions::set_name(const String &thr_name){ + char char_name = thr_name.ascii().ptr(); + OSSetThreadName(thread, char_name); +} + +void Thread::plat_set_priority(Thread::Priority priority){ + if (priority == Thread::Priority::PRIORITY_HIGH) { + OSSetThreadPriority(thread, 0); + } + else if (settings.priority == Thread::Priority::PRIORITY_NORMAL) { + OSSetThreadPriority(thread, 16); + } + else if (settings.priority == Thread::Priority::PRIORITY_LOW){ + OSSetThreadPriority(thread, 32); + } + +} + +void Thread::PlatformFunctions::term(){ + +} + +void Thread::PlatformFunctions::wrapper(){ + +} + +void Thread::_set_platform_functions(const PlatformFunctions &p_functions) { + platform_functions = p_functions; +} + +void Thread::callback(ID p_caller_id, const Settings &p_settings, Callback p_callback, void *p_userdata) { + Thread::caller_id = p_caller_id; + if (platform_functions.set_priority) { + platform_functions.set_priority(p_settings.priority); + } + if (platform_functions.init) { + platform_functions.init(); + } + ScriptServer::thread_enter(); // Scripts may need to attach a stack. + if (platform_functions.wrapper) { + platform_functions.wrapper(p_callback, p_userdata); + } else { + p_callback(p_userdata); + } + ScriptServer::thread_exit(); + if (platform_functions.term) { + platform_functions.term(); + } +} + +Thread::ID Thread::start(Thread::Callback p_callback, void *p_user, const Settings &p_settings) { + ERR_FAIL_COND_V_MSG(id != UNASSIGNED_ID, UNASSIGNED_ID, "A Thread object has been re-started without wait_to_finish() having been called on it."); + id = id_counter.increment(); + + //thread = THREADING_NAMESPACE::thread(&Thread::callback, id, p_settings, p_callback, p_user); + + OSCreateThread(thread,); + return id; +} + +bool Thread::is_started() const { + return id != UNASSIGNED_ID; +} + +void Thread::wait_to_finish() { + ERR_FAIL_COND_MSG(id == UNASSIGNED_ID, "Attempt of waiting to finish on a thread that was never started."); + ERR_FAIL_COND_MSG(id == get_caller_id(), "Threads can't wait to finish on themselves, another thread must wait."); + uint32_t joinresult; + OSJoinThread(thread, *joinresult) + //re-init thread? + //thread = ; + id = UNASSIGNED_ID; +} + +Error Thread::set_name(const String &p_name) { + if (platform_functions.set_name) { + return platform_functions.set_name(p_name); + } + + return ERR_UNAVAILABLE; +} + +Thread::~Thread() { + if (id != UNASSIGNED_ID) { +#ifdef DEBUG_ENABLED + WARN_PRINT( + "A Thread object is being destroyed without its completion having been realized.\n" + "Please call wait_to_finish() on it to ensure correct cleanup."); +#endif + //thread.detach(); + OSDetachThread(thread); + } +} \ No newline at end of file diff --git a/platform/wiiu/platform_thread.h b/platform/wiiu/platform_thread.h new file mode 100644 index 000000000000..9265b4cda8d3 --- /dev/null +++ b/platform/wiiu/platform_thread.h @@ -0,0 +1,79 @@ +#include "platform_config.h" + +#include "core/templates/safe_refcount.h" +#include "core/typedefs.h" + +class String; + +class Thread { +public: + typedef void (*Callback)(void *p_userdata); + + typedef uint64_t ID; + + enum : ID { + UNASSIGNED_ID = 0, + MAIN_ID = 1 + }; + + enum Priority { + PRIORITY_LOW, + PRIORITY_NORMAL, + PRIORITY_HIGH + }; + + struct Settings { + Priority priority; + Settings() { priority = PRIORITY_NORMAL; } + }; + + struct PlatformFunctions { + Error (*set_name)(const String &) = nullptr; + void (*set_priority)(Thread::Priority) = nullptr; + void (*init)() = nullptr; + void (*wrapper)(Thread::Callback, void *) = nullptr; + void (*term)() = nullptr; + }; + +private: + friend class Main; + + ID id = UNASSIGNED_ID; + static SafeNumeric id_counter; + static thread_local ID caller_id; + + OSThread *thread; + + static void callback(ID p_caller_id, const Settings &p_settings, Thread::Callback p_callback, void *p_userdata); + + static PlatformFunctions platform_functions; + + static void make_main_thread() { caller_id = MAIN_ID; } + static void release_main_thread() { caller_id = UNASSIGNED_ID; } + +public: + static void _set_platform_functions(const PlatformFunctions &p_functions); + + _FORCE_INLINE_ ID get_id() const { return id; } + // get the ID of the caller thread + _FORCE_INLINE_ static ID get_caller_id() { + if (unlikely(caller_id == UNASSIGNED_ID)) { + caller_id = id_counter.increment(); + } + return caller_id; + } + // get the ID of the main thread + _FORCE_INLINE_ static ID get_main_id() { return MAIN_ID; } + + _FORCE_INLINE_ static bool is_main_thread() { return caller_id == MAIN_ID; } // Gain a tiny bit of perf here because there is no need to validate caller_id here, because only main thread will be set as 1. + + static Error set_name(const String &p_name); + + ID start(Thread::Callback p_callback, void *p_user, const Settings &p_settings = Settings()); + bool is_started() const; + ///< waits until thread is finished, and deallocates it. + void wait_to_finish(); + + Thread(); + ~Thread(); +}; \ No newline at end of file diff --git a/platform/wiiu/processor/wiiu_mutex.cpp b/platform/wiiu/processor/wiiu_mutex.cpp new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/wiiu/processor/wiiu_mutex.h b/platform/wiiu/processor/wiiu_mutex.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/wiiu/processor/wiiu_semaphore.cpp b/platform/wiiu/processor/wiiu_semaphore.cpp new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/wiiu/processor/wiiu_semaphore.h b/platform/wiiu/processor/wiiu_semaphore.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/wiiu/processor/wiiu_thread.cpp b/platform/wiiu/processor/wiiu_thread.cpp new file mode 100644 index 000000000000..3ee74bf7cdfb --- /dev/null +++ b/platform/wiiu/processor/wiiu_thread.cpp @@ -0,0 +1,39 @@ +#include + +#include "wiiu_thread.h" + +#ifndef PLATFORM_THREAD_OVERRIDE +#include "core/os/thread.h" +#else +#include "platform/wiiu/platform_thread.h" + +void wiiu_thread_set_name(const String thrname){ + char char_name = thr_name.ascii().ptr(); + OSSetThreadName(thread, char_name); +} + +void wiiu_thread_set_priority(Thread::Settings settings){ + + if (settings.priority == Thread::Priority::PRIORITY_HIGH) { + OSSetThreadPriority() + } + else if (settings.priority == Thread::Priority::PRIORITY_NORMAL) { + + } + else if (settings.priority == Thread::Priority::PRIORITY_LOW){ + + } + +} + +void wiiu_thread_init(){ + +} + +void wiiu_thread_call_wrap(Thread::Callback, void *){ + +} + +void wiiu_thread_term(){ + +} \ No newline at end of file diff --git a/platform/wiiu/processor/wiiu_thread.h b/platform/wiiu/processor/wiiu_thread.h new file mode 100644 index 000000000000..804e990cd52b --- /dev/null +++ b/platform/wiiu/processor/wiiu_thread.h @@ -0,0 +1,19 @@ + +#include "core/templates/safe_refcount.h" +#include "core/typedefs.h" + +#ifdef PLATFORM_THREAD_OVERRIDE +#include "platform/wiiu/platform_thread.h" +#else +#include "core/os/thread.h" +#endif + +void wiiu_thread_set_priority(Thread::Settings settings); + +void wiiu_thread_set_name(const String thrname); + +void wiiu_thread_init(); + +void wiiu_thread_call_wrap(Thread::Callback, void *); + +void wiiu_thread_term(); \ No newline at end of file