diff --git a/Code/CMakeLists.txt b/Code/CMakeLists.txt index 405c83b..ac79c45 100644 --- a/Code/CMakeLists.txt +++ b/Code/CMakeLists.txt @@ -48,6 +48,22 @@ if(GLES) add_definitions(-DHAVE_GLES) endif(GLES) +if(SWITCH_LIBNX) + set(CMAKE_CXX_FLAGS "-O3 -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -ffunction-sections -fdata-sections -ftls-model=local-exec") + include_directories($ENV{DEVKITPRO}/libnx/include $ENV{DEVKITPRO}/portlibs/switch/include) + add_definitions(-D__SWITCH__) + add_custom_target(${CMAKE_PROJECT_NAME}.nro + DEPENDS ${CMAKE_PROJECT_NAME} + COMMAND nacptool --create "Eldritch" "usineur" "406" ${CMAKE_PROJECT_NAME}.nacp + COMMAND elf2nro Projects/Eld/${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME}.nro + --icon=${CMAKE_SOURCE_DIR}/icon.jpg --nacp=${CMAKE_PROJECT_NAME}.nacp + ) + add_custom_target(nxlink + DEPENDS ${CMAKE_PROJECT_NAME}.nro + COMMAND nxlink -a $(SWITCHIP) ${CMAKE_PROJECT_NAME}.nro -s -p ${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.nro + ) +endif(SWITCH_LIBNX) + add_subdirectory(Libraries/Core/) add_subdirectory(Libraries/Math/) add_subdirectory(Libraries/3D/) diff --git a/Code/Libraries/3D/src/GL2/gl2renderer.cpp b/Code/Libraries/3D/src/GL2/gl2renderer.cpp index 40adda4..63202ca 100644 --- a/Code/Libraries/3D/src/GL2/gl2renderer.cpp +++ b/Code/Libraries/3D/src/GL2/gl2renderer.cpp @@ -220,7 +220,7 @@ bool GL2Renderer::Reset() /*virtual*/ void GL2Renderer::Refresh() { -#if BUILD_SDL +#if BUILD_SDL && !BUILD_SWITCH // On Linux, at least, SDL needs to be set as the current context *after* the // GL window is shown, so this allows be to do it there. if( m_Window && m_Window->GetSDLWindow() && m_RenderContext ) diff --git a/Code/Libraries/Core/src/core.h b/Code/Libraries/Core/src/core.h index 76c211e..01017f9 100644 --- a/Code/Libraries/Core/src/core.h +++ b/Code/Libraries/Core/src/core.h @@ -35,6 +35,10 @@ #include #endif +#if BUILD_SWITCH +#include +#endif + // This should be the first file included in every .cpp (even before that // file's matching header). // This should be kept a very lightweight include that can go anywhere. diff --git a/Code/Libraries/Core/src/display.cpp b/Code/Libraries/Core/src/display.cpp index 24ad46d..af1768c 100644 --- a/Code/Libraries/Core/src/display.cpp +++ b/Code/Libraries/Core/src/display.cpp @@ -34,7 +34,11 @@ Display::Display() m_AspectRatio = static_cast( m_Width ) / static_cast( m_Height ); STATICHASH( Fullscreen ); +#if BUILD_SWITCH + m_Fullscreen = true; +#else m_Fullscreen = ConfigManager::GetBool( sFullscreen ); +#endif #if BUILD_LINUX // On Linux, changing the screen resolution isn't really supported, so always upscale. @@ -358,4 +362,4 @@ void Display::GetCurrentDisplayMode( int& Width, int& Height, int& RefreshRate ) PRINTF( "Using display mode %dx%d\n", BestDisplayMode.Width, BestDisplayMode.Height ); return BestDisplayMode; -} \ No newline at end of file +} diff --git a/Code/Libraries/Core/src/fileutil.cpp b/Code/Libraries/Core/src/fileutil.cpp index 71b83e1..54a4d3a 100644 --- a/Code/Libraries/Core/src/fileutil.cpp +++ b/Code/Libraries/Core/src/fileutil.cpp @@ -9,7 +9,7 @@ #include #endif -#if BUILD_LINUX || BUILD_MAC +#if BUILD_LINUX || BUILD_MAC || BUILD_SWITCH #include #include #include @@ -383,7 +383,7 @@ void GetFilesInFolderInternal( const SimpleString& Path, const SimpleString& Pre FindClose( FileHandle ); } -#elif BUILD_LINUX || BUILD_MAC +#elif BUILD_LINUX || BUILD_MAC || BUILD_SWITCH DIR* pDirectory = opendir( Path.CStr() ); if( pDirectory ) { @@ -465,7 +465,7 @@ void GetFoldersInFolderInternal( const SimpleString& Path, const SimpleString& P FindClose( FileHandle ); } -#elif BUILD_LINUX || BUILD_MAC +#elif BUILD_LINUX || BUILD_MAC || BUILD_SWITCH DIR* pDirectory = opendir( Path.CStr() ); if( pDirectory ) { diff --git a/Code/Libraries/Core/src/inputsystem.cpp b/Code/Libraries/Core/src/inputsystem.cpp index 1f4b8ee..10fa0bd 100644 --- a/Code/Libraries/Core/src/inputsystem.cpp +++ b/Code/Libraries/Core/src/inputsystem.cpp @@ -830,7 +830,11 @@ float InputSystem::GetVelocity( const HashedString& Axis ) const void InputSystem::SetMouseScale( const HashedString& Axis, const float Scale ) { DEBUGASSERT( m_MouseAdjustments.Search( Axis ).IsValid() ); +#if BUILD_SWITCH + m_MouseAdjustments[ Axis ].m_ScaleFactor = 0; +#else m_MouseAdjustments[ Axis ].m_ScaleFactor = Scale; +#endif } bool InputSystem::GetMouseInvert( const HashedString& Axis ) @@ -1788,4 +1792,4 @@ void InputSystem::PublishDisplayInputString( const SDisplayInput& DisplayInput ) MAKEHASH( m_DefinitionName ); MAKEHASHFROM( InputName, DisplayInput.m_Name ); ConfigManager::SetString( sInputName, InputString.CStr(), sm_DefinitionName ); -} \ No newline at end of file +} diff --git a/Code/Libraries/Core/src/timedate.cpp b/Code/Libraries/Core/src/timedate.cpp index 3df70bc..39ac834 100644 --- a/Code/Libraries/Core/src/timedate.cpp +++ b/Code/Libraries/Core/src/timedate.cpp @@ -10,7 +10,7 @@ timedate_tm_t TimeDate::GetLocalTime() _tzset(); // Apply environment variables so that _localtime_s will convert properly _time64( &Time ); _localtime64_s( &TimeStruct, &Time ); -#elif BUILD_LINUX || BUILD_MAC +#elif BUILD_LINUX || BUILD_MAC || BUILD_SWITCH tzset(); time( &Time ); localtime_r( &Time, &TimeStruct ); diff --git a/Code/Libraries/Core/src/timedate.h b/Code/Libraries/Core/src/timedate.h index 51cc4d5..a5cfa0a 100644 --- a/Code/Libraries/Core/src/timedate.h +++ b/Code/Libraries/Core/src/timedate.h @@ -7,7 +7,7 @@ #include typedef __time64_t timedate_time_t; typedef struct tm timedate_tm_t; -#elif BUILD_LINUX || BUILD_MAC +#elif BUILD_LINUX || BUILD_MAC || BUILD_SWITCH #include typedef time_t timedate_time_t; typedef struct tm timedate_tm_t; diff --git a/Code/Libraries/Core/src/versions.h b/Code/Libraries/Core/src/versions.h index 3d53833..e392328 100644 --- a/Code/Libraries/Core/src/versions.h +++ b/Code/Libraries/Core/src/versions.h @@ -19,8 +19,14 @@ #define BUILD_LINUX 0 #endif +#ifdef __SWITCH__ +#define BUILD_SWITCH 1 +#else +#define BUILD_SWITCH 0 +#endif + #define BUILD_STEAM 0 -#define BUILD_SDL ( 0 || BUILD_MAC || BUILD_LINUX ) +#define BUILD_SDL ( 0 || BUILD_MAC || BUILD_LINUX || BUILD_SWITCH ) #define BUILD_WINDOWS_NO_SDL ( BUILD_WINDOWS && ( !BUILD_SDL ) ) #define REPORT_BUILD 0 @@ -50,4 +56,4 @@ #endif #endif // REPORT_BUILD -#endif // VERSIONS_H \ No newline at end of file +#endif // VERSIONS_H diff --git a/Code/Libraries/Core/src/xinputcontroller.cpp b/Code/Libraries/Core/src/xinputcontroller.cpp index fe21194..a7be097 100644 --- a/Code/Libraries/Core/src/xinputcontroller.cpp +++ b/Code/Libraries/Core/src/xinputcontroller.cpp @@ -346,10 +346,17 @@ void XInputController::Tick( const float DeltaTime ) if( SDL_GameControllerGetAttached( m_Controller ) ) { #define SET_BUTTON( EB, SDLB ) m_CurrentState.m_Buttons[ EB ] = SDL_GameControllerGetButton( m_Controller, SDLB ) != 0 +#if BUILD_SWITCH + SET_BUTTON( EB_A, SDL_CONTROLLER_BUTTON_B ); + SET_BUTTON( EB_B, SDL_CONTROLLER_BUTTON_A ); + SET_BUTTON( EB_X, SDL_CONTROLLER_BUTTON_Y ); + SET_BUTTON( EB_Y, SDL_CONTROLLER_BUTTON_X ); +#else SET_BUTTON( EB_A, SDL_CONTROLLER_BUTTON_A ); SET_BUTTON( EB_B, SDL_CONTROLLER_BUTTON_B ); SET_BUTTON( EB_X, SDL_CONTROLLER_BUTTON_X ); SET_BUTTON( EB_Y, SDL_CONTROLLER_BUTTON_Y ); +#endif SET_BUTTON( EB_Up, SDL_CONTROLLER_BUTTON_DPAD_UP ); SET_BUTTON( EB_Down, SDL_CONTROLLER_BUTTON_DPAD_DOWN ); SET_BUTTON( EB_Left, SDL_CONTROLLER_BUTTON_DPAD_LEFT ); @@ -483,4 +490,4 @@ void XInputController::SetFeedback( float Low, float High ) Low = Saturate( Low ); High = Saturate( High ); SetVibration( ( c_uint16 )( Low * 65535.0f ), ( c_uint16 )( High * 65535.0f ) ); -} \ No newline at end of file +} diff --git a/Code/Libraries/Framework/CMakeLists.txt b/Code/Libraries/Framework/CMakeLists.txt index 022f3b7..60dd7e9 100644 --- a/Code/Libraries/Framework/CMakeLists.txt +++ b/Code/Libraries/Framework/CMakeLists.txt @@ -25,3 +25,6 @@ add_library(Framework ${framework_src}) target_link_libraries(Framework Core) target_link_libraries(Framework 3D) target_link_libraries(Framework UI) +if(SWITCH_LIBNX) +target_link_libraries(Framework vorbis ogg EGL drm_nouveau glapi GLESv2 nx) +endif(SWITCH_LIBNX) diff --git a/Code/Libraries/Framework/src/framework3d.cpp b/Code/Libraries/Framework/src/framework3d.cpp index 4d48d76..eefbd30 100644 --- a/Code/Libraries/Framework/src/framework3d.cpp +++ b/Code/Libraries/Framework/src/framework3d.cpp @@ -55,7 +55,9 @@ Framework3D::Framework3D() : m_EventManager( NULL ) , m_Display( NULL ) , m_Window( NULL ) +#if !BUILD_SWITCH , m_SplashWindow( NULL ) +#endif , m_Keyboard( NULL ) , m_Mouse( NULL ) , m_Clock( NULL ) @@ -158,6 +160,11 @@ void Framework3D::Main() } SDL_DisableScreenSaver(); +#if BUILD_SWITCH + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); +#endif #endif STATICHASH( Framework ); @@ -310,7 +317,9 @@ void Framework3D::Main() if( ShowWindowASAP() ) { +#if !BUILD_SWITCH SafeDelete( m_SplashWindow ); +#endif #if BUILD_WINDOWS_NO_SDL m_Window->Show( m_CmdShow ); #elif BUILD_SDL @@ -340,6 +349,7 @@ void Framework3D::CreateSplashWindow( const uint WindowIcon, const char* const T STATICHASH( Framework ); STATICHASH( SplashImage ); +#if !BUILD_SWITCH const char* const pSplashImage = ConfigManager::GetString( sSplashImage, NULL, sFramework ); if( !pSplashImage ) { @@ -385,6 +395,7 @@ void Framework3D::CreateSplashWindow( const uint WindowIcon, const char* const T { } #endif +#endif } /*virtual*/ void Framework3D::ShutDown() @@ -409,7 +420,9 @@ void Framework3D::CreateSplashWindow( const uint WindowIcon, const char* const T #endif SafeDelete( m_Display ); +#if !BUILD_SWITCH SafeDelete( m_SplashWindow ); +#endif SafeDelete( m_Clock ); SafeDelete( m_Keyboard ); SafeDelete( m_Mouse ); @@ -429,7 +442,7 @@ void Framework3D::CreateSplashWindow( const uint WindowIcon, const char* const T Profiler::DeleteInstance(); #endif -#if BUILD_SDL +#if BUILD_SDL && !BUILD_SWITCH SDL_Quit(); #endif @@ -1090,4 +1103,4 @@ LRESULT CALLBACK Framework3D::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, L return DefWindowProc( hWnd, uMsg, wParam, lParam ); } -#endif // BUILD_WINDOWS_NO_SDL \ No newline at end of file +#endif // BUILD_WINDOWS_NO_SDL diff --git a/Code/Libraries/Framework/src/framework3d.h b/Code/Libraries/Framework/src/framework3d.h index 35ee087..6adf46d 100644 --- a/Code/Libraries/Framework/src/framework3d.h +++ b/Code/Libraries/Framework/src/framework3d.h @@ -126,7 +126,9 @@ class Framework3D : public IWBEventObserver WBEventManager* m_EventManager; // Event manager for framework only, not for game. Display* m_Display; Window* m_Window; +#if !BUILD_SWITCH Window* m_SplashWindow; +#endif Keyboard* m_Keyboard; Mouse* m_Mouse; Clock* m_Clock; @@ -158,4 +160,4 @@ class Framework3D : public IWBEventObserver bool m_IsShuttingDown; }; -#endif \ No newline at end of file +#endif diff --git a/Code/Projects/Eld/src/eldframework.cpp b/Code/Projects/Eld/src/eldframework.cpp index 1d07a8f..0730c87 100644 --- a/Code/Projects/Eld/src/eldframework.cpp +++ b/Code/Projects/Eld/src/eldframework.cpp @@ -599,7 +599,9 @@ ENotificationPosition GetSteamNoticePos( const HashedString& SteamNoticePosName } // All done, show the window finally. +#if !BUILD_SWITCH SafeDelete( m_SplashWindow ); +#endif #if BUILD_WINDOWS_NO_SDL m_Window->Show( m_CmdShow ); #elif BUILD_SDL @@ -1809,7 +1811,9 @@ void EldFramework::PrepareForLoad() { PRINTF( "EldFramework::ToggleFullscreen\n" ); +#if !BUILD_SWITCH Framework3D::ToggleFullscreen(); +#endif // For fullscreen upscaling, we may need a new m_UpscaleView UpdateViews(); diff --git a/Code/Projects/Eld/src/main.cpp b/Code/Projects/Eld/src/main.cpp index 095fce4..8fd263a 100644 --- a/Code/Projects/Eld/src/main.cpp +++ b/Code/Projects/Eld/src/main.cpp @@ -128,6 +128,10 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin extern "C" int main( int argc, char* argv[] ) #endif { +#if BUILD_SWITCH + socketInitializeDefault(); + nxlinkStdio(); +#endif #if BUILD_WINDOWS_NO_SDL Unused( hPrevInstance ); Unused( lpCmdLine ); @@ -154,5 +158,10 @@ extern "C" int main( int argc, char* argv[] ) ShutDown(); +#if BUILD_SWITCH + SDL_Quit(); + socketExit(); +#endif + return 0; } diff --git a/Code/icon.jpg b/Code/icon.jpg new file mode 100644 index 0000000..08d958b Binary files /dev/null and b/Code/icon.jpg differ