Skip to content

Commit

Permalink
Upgrades NVGT to SDL3!
Browse files Browse the repository at this point in the history
Thanks @braillescreen for modifying MacOS and Linux build scripts.
  • Loading branch information
samtupy committed Aug 15, 2024
1 parent 13f10d3 commit 83d0b3c
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 267 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ jobs:
final_package:
runs-on: ubuntu-latest
needs: ["windows_package", "mac_package", "linux_package"]
if: github.ref_name == 'main'
steps:
- uses: actions/checkout@v4
- name: set_version
Expand Down
10 changes: 5 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ Alias('cdb', cdb)
if env["PLATFORM"] == "win32":
env.Append(CCFLAGS = ["/EHsc", "/J", "/MT", "/Z7", "/std:c++20", "/GF", "/Zc:inline", "/O2", "/bigobj", "/permissive-"])
env.Append(LINKFLAGS = ["/NOEXP", "/NOIMPLIB"], no_import_lib = 1)
env.Append(LIBS = ["UniversalSpeechStatic", "enet", "angelscript64", "SDL2"])
env.Append(LIBS = ["UniversalSpeechStatic", "enet", "angelscript64", "SDL3"])
env.Append(LIBS = ["Kernel32", "User32", "imm32", "OneCoreUAP", "dinput8", "dxguid", "gdi32", "winspool", "shell32", "iphlpapi", "ole32", "oleaut32", "delayimp", "uuid", "comdlg32", "advapi32", "netapi32", "winmm", "version", "crypt32", "normaliz", "wldap32", "ws2_32"])
else:
env.Append(CXXFLAGS = ["-fms-extensions", "-std=c++20", "-fpermissive", "-O2", "-Wno-narrowing", "-Wno-int-to-pointer-cast", "-Wno-delete-incomplete", "-Wno-unused-result"], LIBS = ["m"])
if env["PLATFORM"] == "darwin":
# homebrew paths and other libraries/flags for MacOS
env.Append(CPPPATH = ["/opt/homebrew/include"], CCFLAGS = ["-mmacosx-version-min=14.0"], LIBPATH = ["/opt/homebrew/lib"])
# The following, to say the least, is absolutely not ideal. In some cases we have both static and dynamic libraries on the system and must explicitly choose the static one. The normal :libname.a trick doesn't seem to work on clang, we're just informed that libs couldn't be found. If anybody knows a better way to force static library linkage on MacOS particularly without the absolute paths, please let me know!
env.Append(LIBS = [File("/usr/local/lib/libangelscript.a"), File("/usr/local/lib/libenet.a"), File("/opt/homebrew/lib/libcrypto.a"), File("/opt/homebrew/lib/libSDL2.a"), File("/opt/homebrew/lib/libssl.a"), "iconv"])
env.Append(LIBS = [File("/usr/local/lib/libangelscript.a"), File("/usr/local/lib/libenet.a"), File("/usr/local/lib/libSDL3.a"), File("/opt/homebrew/lib/libcrypto.a"), File("/opt/homebrew/lib/libssl.a"), "iconv"])
elif env["PLATFORM"] == "posix":
# enable the gold linker to silence seemingly pointless warnings about symbols in the bass libraries, strip the resulting binaries, and add /usr/local/lib to the libpath because it seems we aren't finding libraries unless we do manually.
env.Append(CPPPATH = ["/usr/local/include"], LIBPATH = ["/usr/local/lib"], LINKFLAGS = ["-fuse-ld=gold", "-s"])
# We must explicitly denote the static linkage for several libraries or else gcc will choose the dynamic ones.
env.Append(LIBS = [":libangelscript.a", ":libenet.a", ":libSDL2.a", "crypto", "ssl"])
env.Append(LIBS = [":libangelscript.a", ":libenet.a", ":libSDL3.a", "crypto", "ssl"])
env.Append(CPPDEFINES = ["POCO_STATIC", "UNIVERSAL_SPEECH_STATIC", "NDEBUG", "UNICODE"])
env.Append(CPPPATH = ["#ASAddon/include", "#dep"], LIBPATH = ["#build/lib"])

Expand All @@ -56,15 +56,15 @@ if "version.cpp" in sources: sources.remove("version.cpp")
env.Command(target = "src/version.cpp", source = ["src/" + i for i in sources], action = env["generate_version"])
version_object = env.Object("build/obj_src/version", "src/version.cpp") # Things get weird if we do this after VariantDir.
VariantDir("build/obj_src", "src", duplicate = 0)
env.Append(LIBS = [["PocoFoundationMT", "PocoJSONMT", "PocoNetMT", "PocoNetSSLWinMT", "PocoUtilMT"] if env["PLATFORM"] == "win32" else ["PocoJSON", "PocoNet", "PocoNetSSL", "PocoUtil", "PocoCrypto", "PocoFoundation"], "phonon", "bass", "bass_fx", "bassmix", "SDL2main"])
env.Append(LIBS = [["PocoFoundationMT", "PocoJSONMT", "PocoNetMT", "PocoNetSSLWinMT", "PocoUtilMT"] if env["PLATFORM"] == "win32" else ["PocoJSON", "PocoNet", "PocoNetSSL", "PocoUtil", "PocoCrypto", "PocoFoundation"], "phonon", "bass", "bass_fx", "bassmix"])
env.Append(CPPDEFINES = ["NVGT_BUILDING", "NO_OBFUSCATE"], LIBS = ["ASAddon", "deps"])
if env["PLATFORM"] == "win32":
env.Append(LINKFLAGS = ["/OPT:REF", "/OPT:ICF", "/ignore:4099", "/delayload:bass.dll", "/delayload:bass_fx.dll", "/delayload:bassmix.dll", "/delayload:phonon.dll"])
elif env["PLATFORM"] == "darwin":
sources.append("apple.mm")
sources.append("macos.mm")
env["FRAMEWORKPREFIX"] = "-weak_framework"
env.Append(FRAMEWORKS = ["CoreAudio", "CoreFoundation", "CoreHaptics", "CoreVideo", "AudioToolbox", "AVFoundation", "AppKit", "IOKit", "Carbon", "Cocoa", "ForceFeedback", "GameController", "QuartzCore", "Metal"])
env.Append(FRAMEWORKS = ["CoreAudio", "CoreFoundation", "CoreHaptics", "CoreMedia", "CoreVideo", "AudioToolbox", "AVFoundation", "AppKit", "IOKit", "Carbon", "Cocoa", "ForceFeedback", "GameController", "QuartzCore", "Metal", "UniformTypeIdentifiers"])
env.Append(LIBS = ["objc"])
env.Append(LINKFLAGS = ["-Wl,-rpath,'@loader_path',-rpath,'@loader_path/lib',-rpath,'@loader_path/../Frameworks',-dead_strip_dylibs", "-mmacosx-version-min=14.0"])
elif env["PLATFORM"] == "posix":
Expand Down
19 changes: 7 additions & 12 deletions build/build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,11 @@ function setup_sdl {
# Install SDL this way to get many SDL deps. It is too old so we remove SDL itself and build from source, however.
sudo apt install libssl-dev libcurl4-openssl-dev libopus-dev libsdl2-dev -y
sudo apt remove libsdl2-dev -y

wget https://github.com/libsdl-org/SDL/releases/download/release-2.30.2/SDL2-2.30.2.tar.gz
tar -xvf SDL2-2.30.2.tar.gz
rm SDL2-2.30.2.tar.gz
cd SDL2-2.30.2

mkdir -p build
cd build
cmake ..
cmake --build .
git clone --depth 1 https://github.com/libsdl-org/SDL||true
mkdir -p SDL/build
cd SDL/build
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DSDL_SHARED=OFF -DSDL_STATIC=ON -DSDL_TEST_LIBRARY=OFF ..
cmake --build . --config MinSizeRel
sudo make install
cd ../..
echo SDL installed.
Expand All @@ -93,8 +88,7 @@ function setup_nvgt {
echo Not running on CI.
cd ..

# TODO - make `git clone` when public, CI most likely won't have gh.
gh repo clone https://github.com/samtupy/nvgt
git clone --depth 1 https://github.com/samtupy/nvgt||true
cd nvgt

else
Expand All @@ -110,6 +104,7 @@ function setup_nvgt {
cd ..
rm lindev.tar.gz
if ! which scons &> /dev/null; then
export PIP_BREAK_SYSTEM_PACKAGES=1
pip3 install --user scons
fi
scons -s no_upx=0
Expand Down
14 changes: 13 additions & 1 deletion build/build_macos.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/zsh

function setup_homebrew {
brew install autoconf automake libtool openssl sdl2 libgit2 bullet upx
brew install autoconf automake libtool openssl libgit2 bullet upx
}

function setup_angelscript {
Expand Down Expand Up @@ -55,6 +55,17 @@ function setup_poco {
rm poco-1.13.3-all.tar.gz
}

function setup_sdl {
echo Installing SDL...
git clone --depth 1 https://github.com/libsdl-org/SDL||true
mkdir -p SDL/build
cd SDL/build
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DSDL_SHARED=OFF -DSDL_STATIC=ON -DSDL_TEST_LIBRARY=OFF -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" ..
cmake --build . --config MinSizeRel
sudo make install
cd ../..
echo SDL installed.
}
function setup_nvgt {
echo Building NVGT...

Expand Down Expand Up @@ -91,6 +102,7 @@ function main {
setup_enet
#setup_libgit2
setup_poco
setup_sdl
setup_nvgt
echo Success!
exit 0
Expand Down
6 changes: 3 additions & 3 deletions doc/OSL/MIT/universal_speech.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
UniversalSpeech - screen reader library for windows

Copyright (c) 2011-2018 Quentin cosendey

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.
2 changes: 0 additions & 2 deletions doc/src/appendix/!To do.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,3 @@ Along the same line, partly due to initial closed source intentions and also par
### Rewrite system_fingerprint.cpp
Currently we are using parts of an apache2 licensed library for system fingerprint generation. Not only is it a bit rough but it also uses several architecture specific assembly instructions at times when we probably don't need any. We should rewrite this to use our own system instead comprised of calls into Poco, SDL and other libraries that can return various bits of system information, or at the very least find a solid tiny dependency that can handle it for us.

### SDL3 upgrade
At some point we do indeed intend to upgrade to SDL3 instead of sticking with SDL2. The priority of this task is somewhat unknown and at least partially revolves around making sure SDL3 is easy to acquire/build/install on all the platforms we're interested in using it on. So long as we manually build one of the prereleases, we're probably OK though it would be nice to wait until it shows up on brew, apt and other package managers.

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions doc/src/references/builtin/User Interface/Enums/joystick_type.md

This file was deleted.

32 changes: 10 additions & 22 deletions doc/src/references/builtin/User Interface/Enums/key_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,14 @@ This is a complete list of possible keycodes in NVGT, as well as a short descrip
* KEY_MUTE: the Mute key.
* KEY_VOLUMEUP: the Volume Up key.
* KEY_VOLUMEDOWN: the Volume Down key.
* KEY_AUDIONEXT: the Audio Next key.
* KEY_AUDIOPREV: the Audio Previous key.
* KEY_AUDIOSTOP: the Audio Stop key.
* KEY_AUDIOPLAY: the Audio Play key.
* KEY_AUDIOMUTE: the Audio Mute key.
* KEY_MEDIASELECT: the Media Select key.
* KEY_MEDIA_NEXT_TRACK: the next track key.
* KEY_MEDIA_PREVIOUS_TRACK: the previous track key.
* KEY_MEDIA_STOP: the stop media key.
* KEY_MEDIA_PLAY: the play media key.
* KEY_MUTE: the mute key.
* KEY_MEDIA_SELECT: the media select key.

## Browser and Application keys
* KEY_WWW: the WWW key.
* KEY_MAIL: the Mail key.
* KEY_CALCULATOR: the Calculator key.
* KEY_COMPUTER: the Computer key.
* KEY_AC_SEARCH: the AC Search key.
* KEY_AC_HOME: the AC Home key.
* KEY_AC_BACK: the AC Back key.
Expand All @@ -162,18 +158,10 @@ This is a complete list of possible keycodes in NVGT, as well as a short descrip
* KEY_AC_BOOKMARKS: the AC Bookmarks key.

## Additional keys
* KEY_BRIGHTNESSDOWN: the Brightness Down key.
* KEY_BRIGHTNESSUP: the Brightness Up key.
* KEY_DISPLAYSWITCH: the Display Switch key.
* KEY_KBDILLUMTOGGLE: the Keyboard Illumination Toggle key.
* KEY_KBDILLUMDOWN: the Keyboard Illumination Down key.
* KEY_KBDILLUMUP: the Keyboard Illumination Up key.
* KEY_EJECT: the Eject key.
* KEY_SLEEP: the Sleep key.
* KEY_APP1: the Application 1 key.
* KEY_APP2: the Application 2 key.
* KEY_AUDIOREWIND: the Audio Rewind key.
* KEY_AUDIOFASTFORWARD: the Audio Fast Forward key.
* KEY_MEDIA_EJECT: the eject key.
* KEY_SLEEP: the sleep key.
* KEY_MEDIA_REWIND: the media rewind key.
* KEY_MEDIA_FAST_FORWARD: the media fast forward key.
* KEY_SOFTLEFT: the Soft Left key.
* KEY_SOFTRIGHT: the Soft Right key.
* KEY_CALL: the Call key.
Expand Down
51 changes: 25 additions & 26 deletions src/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include <SDL3/SDL.h>
#include <obfuscate.h>
#include <thread.h>
#include <string>
Expand Down Expand Up @@ -63,7 +62,7 @@ int message_box(const std::string& title, const std::string& text, const std::ve
}
SDL_MessageBoxButtonData& sdlbtn = sdlbuttons.emplace_back();
sdlbtn.flags = button_flag;
sdlbtn.buttonid = i + 1;
sdlbtn.buttonID = i + 1;
sdlbtn.text = buttons[i].c_str() + skip;
}
SDL_MessageBoxData box = {mb_flags, g_WindowHandle, title.c_str(), text.c_str(), int(sdlbuttons.size()), sdlbuttons.data(), NULL};
Expand Down Expand Up @@ -195,17 +194,18 @@ bool g_WindowHidden = false;

static std::vector<SDL_Event> post_events; // holds events that should be processed after the next wait() call.
#ifdef _WIN32
void sdl_windows_messages(void* udata, void* hwnd, unsigned int message, uint64_t wParam, int64_t lParam) {
if (message == WM_KEYDOWN && wParam == 'V' && lParam == 1) {
SDL_bool sdl_windows_messages(void* udata, MSG* msg) {
if (msg->message == WM_KEYDOWN && msg->wParam == 'V' && msg->lParam == 1) {
SDL_Event e{};
e.type = SDL_KEYDOWN;
e.key.timestamp = SDL_GetTicks();
e.key.keysym.scancode = SDL_SCANCODE_PASTE;
e.key.keysym.sym = SDLK_PASTE;
e.type = SDL_EVENT_KEY_DOWN;
e.common.timestamp = SDL_GetTicksNS();
e.key.scancode = SDL_SCANCODE_PASTE;
e.key.key = SDLK_PASTE;
SDL_PushEvent(&e);
e.type = SDL_KEYUP;
e.type = SDL_EVENT_KEY_UP;
post_events.push_back(e);
}
return SDL_TRUE;
}
#endif
bool set_application_name(const std::string& name) {
Expand All @@ -225,15 +225,14 @@ bool ShowNVGTWindow(std::string& window_title) {
#ifdef _WIN32
SDL_SetWindowsMessageHook(sdl_windows_messages, NULL);
#endif
g_WindowHandle = SDL_CreateWindow(window_title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 640, 0);
g_WindowHandle = SDL_CreateWindow(window_title.c_str(), 640, 640, 0);
if (!g_WindowHandle) return false;
SDL_SysWMinfo winf;
SDL_VERSION(&winf.version);
SDL_GetWindowWMInfo(g_WindowHandle, &winf);
if (!SDL_HasScreenKeyboardSupport()) SDL_StartTextInput(g_WindowHandle);
SDL_PropertiesID window_props = SDL_GetWindowProperties(g_WindowHandle);
#ifdef _WIN32
g_OSWindowHandle = winf.info.win.window;
#elif defined(SDL_VIDEO_DRIVER_COCOA)
g_OSWindowHandle = winf.info.cocoa.window;
g_OSWindowHandle = (HWND)SDL_GetPointerProperty(window_props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
#elif defined(__APPLE__) // Will probably need to fix for IOS
g_OSWindowHandle = (NSWindow*)SDL_GetPointerProperty(window_props, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
SDL_ShowWindow(g_WindowHandle);
SDL_RaiseWindow(g_WindowHandle);
voice_over_window_created();
Expand Down Expand Up @@ -270,11 +269,11 @@ std::string get_window_text() {
}
void* get_window_os_handle() { return reinterpret_cast<void*>(g_OSWindowHandle); }
void handle_sdl_event(SDL_Event* evt) {
if (evt->type == SDL_KEYDOWN || evt->type == SDL_KEYUP || evt->type == SDL_TEXTINPUT || evt->type == SDL_MOUSEMOTION || evt->type == SDL_MOUSEBUTTONDOWN || evt->type == SDL_MOUSEBUTTONUP || evt->type == SDL_MOUSEWHEEL)
if (evt->type == SDL_EVENT_KEY_DOWN || evt->type == SDL_EVENT_KEY_UP || evt->type == SDL_EVENT_TEXT_INPUT || evt->type == SDL_EVENT_MOUSE_MOTION || evt->type == SDL_EVENT_MOUSE_BUTTON_DOWN || evt->type == SDL_EVENT_MOUSE_BUTTON_UP || evt->type == SDL_EVENT_MOUSE_WHEEL)
InputEvent(evt);
else if (evt->type == SDL_WINDOWEVENT && evt->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
else if (evt->type == SDL_EVENT_WINDOW_FOCUS_LOST)
lost_window_focus();
else if (evt->type == SDL_WINDOWEVENT && evt->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
else if (evt->type == SDL_EVENT_WINDOW_FOCUS_GAINED)
regained_window_focus();
}
void wait(int ms) {
Expand All @@ -299,13 +298,13 @@ void wait(int ms) {
#ifdef __APPLE__
// Hack to fix voiceover's weird handling of the left and right arrow keys. If a left/right arrow down/up event get generated in the same frame, we need to move the up event to the next frame.
bool evt_handled = false;
if (evt.type == SDL_KEYDOWN) {
if (evt.key.keysym.scancode == SDL_SCANCODE_LEFT) left_just_pressed = true;
if (evt.key.keysym.scancode == SDL_SCANCODE_RIGHT) right_just_pressed = true;
} else if ((left_just_pressed || right_just_pressed) && evt.type == SDL_KEYUP) {
if (evt.type == SDL_EVENT_KEY_DOWN) {
if (evt.key.scancode == SDL_SCANCODE_LEFT) left_just_pressed = true;
if (evt.key.scancode == SDL_SCANCODE_RIGHT) right_just_pressed = true;
} else if ((left_just_pressed || right_just_pressed) && evt.type == SDL_EVENT_KEY_UP) {
evt_handled = true;
if (left_just_pressed && evt.key.keysym.scancode == SDL_SCANCODE_LEFT) post_events.push_back(evt);
else if (right_just_pressed && evt.key.keysym.scancode == SDL_SCANCODE_RIGHT) post_events.push_back(evt);
if (left_just_pressed && evt.key.scancode == SDL_SCANCODE_LEFT) post_events.push_back(evt);
else if (right_just_pressed && evt.key.scancode == SDL_SCANCODE_RIGHT) post_events.push_back(evt);
else evt_handled = false;
}
if (evt_handled) continue;
Expand Down
2 changes: 1 addition & 1 deletion src/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#endif
#include <angelscript.h>
#include <string>
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>

extern SDL_Window* g_WindowHandle;

Expand Down
2 changes: 1 addition & 1 deletion src/angelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Poco/UnbufferedStreamBuf.h>
#include <Poco/zlib.h>
#include <Poco/Util/Application.h>
#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
#include "angelscript.h"
#include "bullet3.h"
#include "compression.h"
Expand Down
Loading

0 comments on commit 83d0b3c

Please sign in to comment.