summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis-build-docker.sh20
-rwxr-xr-x.travis-build.sh10
-rwxr-xr-x.travis-deps.sh30
-rwxr-xr-x.travis-upload.sh235
-rw-r--r--.travis.yml18
-rw-r--r--CMakeLists.txt4
-rw-r--r--README.md2
-rw-r--r--appveyor.yml185
-rw-r--r--dist/citra.icnsbin1027012 -> 211056 bytes
-rw-r--r--dist/citra.icobin509287 -> 370070 bytes
-rw-r--r--dist/citra.manifest24
-rw-r--r--dist/citra.svg80
-rw-r--r--dist/doc-icon.pngbin8791 -> 7768 bytes
m---------externals/soundtouch0
-rw-r--r--src/audio_core/hle/source.cpp49
-rw-r--r--src/audio_core/interpolate.cpp86
-rw-r--r--src/audio_core/interpolate.h27
-rw-r--r--src/citra/citra.cpp2
-rw-r--r--src/citra/citra.rc8
-rw-r--r--src/citra/config.cpp9
-rw-r--r--src/citra/default_ini.h27
-rw-r--r--src/citra/emu_window/emu_window_sdl2.cpp10
-rw-r--r--src/citra/emu_window/emu_window_sdl2.h4
-rw-r--r--src/citra_qt/CMakeLists.txt3
-rw-r--r--src/citra_qt/bootmanager.cpp10
-rw-r--r--src/citra_qt/bootmanager.h4
-rw-r--r--src/citra_qt/citra-qt.rc12
-rw-r--r--src/citra_qt/configuration/config.cpp17
-rw-r--r--src/citra_qt/configuration/configure.ui15
-rw-r--r--src/citra_qt/configuration/configure_dialog.cpp1
-rw-r--r--src/citra_qt/configuration/configure_graphics.ui11
-rw-r--r--src/citra_qt/configuration/configure_web.cpp52
-rw-r--r--src/citra_qt/configuration/configure_web.h30
-rw-r--r--src/citra_qt/configuration/configure_web.ui153
-rw-r--r--src/citra_qt/main.cpp46
-rw-r--r--src/citra_qt/main.h2
-rw-r--r--src/citra_qt/ui_settings.h2
-rw-r--r--src/core/CMakeLists.txt8
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic.cpp2
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp8
-rw-r--r--src/core/arm/skyeye_common/armstate.h2
-rw-r--r--src/core/core.cpp5
-rw-r--r--src/core/file_sys/archive_backend.cpp2
-rw-r--r--src/core/frontend/emu_window.cpp97
-rw-r--r--src/core/frontend/emu_window.h114
-rw-r--r--src/core/frontend/framebuffer_layout.cpp36
-rw-r--r--src/core/frontend/framebuffer_layout.h11
-rw-r--r--src/core/frontend/input.h25
-rw-r--r--src/core/frontend/motion_emu.cpp89
-rw-r--r--src/core/frontend/motion_emu.h52
-rw-r--r--src/core/hle/applets/erreula.cpp4
-rw-r--r--src/core/hle/applets/mii_selector.cpp10
-rw-r--r--src/core/hle/applets/mii_selector.h57
-rw-r--r--src/core/hle/applets/mint.cpp4
-rw-r--r--src/core/hle/applets/swkbd.cpp4
-rw-r--r--src/core/hle/kernel/kernel.h5
-rw-r--r--src/core/hle/kernel/thread.cpp6
-rw-r--r--src/core/hle/lock.cpp11
-rw-r--r--src/core/hle/lock.h18
-rw-r--r--src/core/hle/service/apt/apt.cpp229
-rw-r--r--src/core/hle/service/apt/apt.h6
-rw-r--r--src/core/hle/service/dsp_dsp.cpp7
-rw-r--r--src/core/hle/service/hid/hid.cpp44
-rw-r--r--src/core/hle/service/hid/hid.h2
-rw-r--r--src/core/hle/service/ir/ir_rst.cpp2
-rw-r--r--src/core/hle/service/nwm/nwm_uds.cpp165
-rw-r--r--src/core/hle/service/nwm/nwm_uds.h12
-rw-r--r--src/core/hle/service/nwm/uds_beacon.cpp3
-rw-r--r--src/core/hle/service/nwm/uds_beacon.h30
-rw-r--r--src/core/hle/service/nwm/uds_connection.cpp79
-rw-r--r--src/core/hle/service/nwm/uds_connection.h51
-rw-r--r--src/core/hle/svc.cpp8
-rw-r--r--src/core/hw/gpu.cpp2
-rw-r--r--src/core/hw/gpu.h4
-rw-r--r--src/core/loader/ncch.cpp8
-rw-r--r--src/core/memory.cpp9
-rw-r--r--src/core/settings.cpp2
-rw-r--r--src/core/settings.h10
-rw-r--r--src/core/telemetry_session.cpp57
-rw-r--r--src/core/telemetry_session.h12
-rw-r--r--src/input_common/CMakeLists.txt2
-rw-r--r--src/input_common/main.cpp15
-rw-r--r--src/input_common/main.h7
-rw-r--r--src/input_common/motion_emu.cpp168
-rw-r--r--src/input_common/motion_emu.h46
-rw-r--r--src/input_common/sdl/sdl.cpp2
-rw-r--r--src/network/packet.cpp38
-rw-r--r--src/network/packet.h4
-rw-r--r--src/network/room.cpp84
-rw-r--r--src/network/room.h19
-rw-r--r--src/network/room_member.cpp128
-rw-r--r--src/network/room_member.h59
-rw-r--r--src/video_core/regs_framebuffer.h10
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp3
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp37
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp13
-rw-r--r--src/video_core/renderer_opengl/gl_state.h3
-rw-r--r--src/video_core/swrasterizer/clipper.cpp4
-rw-r--r--src/video_core/swrasterizer/framebuffer.cpp2
-rw-r--r--src/video_core/swrasterizer/lighting.cpp90
-rw-r--r--src/video_core/swrasterizer/lighting.h3
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp4
-rw-r--r--src/video_core/swrasterizer/rasterizer.h6
-rw-r--r--src/video_core/swrasterizer/texturing.cpp4
-rw-r--r--src/web_service/telemetry_json.cpp3
-rw-r--r--src/web_service/telemetry_json.h7
-rw-r--r--src/web_service/web_backend.cpp67
-rw-r--r--src/web_service/web_backend.h18
108 files changed, 2346 insertions, 1000 deletions
diff --git a/.travis-build-docker.sh b/.travis-build-docker.sh
new file mode 100644
index 000000000..ca6fae42b
--- /dev/null
+++ b/.travis-build-docker.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -e
+set -x
+
+cd /citra
+
+apt-get update
+apt-get install -y build-essential libsdl2-dev qtbase5-dev libqt5opengl5-dev libcurl4-openssl-dev libssl-dev wget git
+
+# Get a recent version of CMake
+wget https://cmake.org/files/v3.9/cmake-3.9.0-Linux-x86_64.sh
+echo y | sh cmake-3.9.0-Linux-x86_64.sh --prefix=cmake
+export PATH=/citra/cmake/cmake-3.9.0-Linux-x86_64/bin:$PATH
+
+mkdir build && cd build
+cmake .. -DCMAKE_BUILD_TYPE=Release
+make -j4
+
+ctest -VV -C Release
diff --git a/.travis-build.sh b/.travis-build.sh
index df6e236b6..64f5aed94 100755
--- a/.travis-build.sh
+++ b/.travis-build.sh
@@ -44,15 +44,7 @@ fi
#if OS is linux or is not set
if [ "$TRAVIS_OS_NAME" = "linux" -o -z "$TRAVIS_OS_NAME" ]; then
- export CC=gcc-6
- export CXX=g++-6
- export PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH
-
- mkdir build && cd build
- cmake ..
- make -j4
-
- ctest -VV -C Release
+ docker run -v $(pwd):/citra ubuntu:16.04 /bin/bash /citra/.travis-build-docker.sh
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
set -o pipefail
diff --git a/.travis-deps.sh b/.travis-deps.sh
index 25a287c7f..0cee68041 100755
--- a/.travis-deps.sh
+++ b/.travis-deps.sh
@@ -5,35 +5,7 @@ set -x
#if OS is linux or is not set
if [ "$TRAVIS_OS_NAME" = "linux" -o -z "$TRAVIS_OS_NAME" ]; then
- export CC=gcc-6
- export CXX=g++-6
- mkdir -p $HOME/.local
-
- if [ ! -e $HOME/.local/bin/cmake ]; then
- echo "CMake not found in the cache, get and extract it..."
- curl -L http://www.cmake.org/files/v3.6/cmake-3.6.3-Linux-x86_64.tar.gz \
- | tar -xz -C $HOME/.local --strip-components=1
- else
- echo "Using cached CMake"
- fi
-
- if [ ! -e $HOME/.local/lib/libSDL2.la ]; then
- echo "SDL2 not found in cache, get and build it..."
- wget http://libsdl.org/release/SDL2-2.0.5.tar.gz -O - | tar xz
- cd SDL2-2.0.5
- ./configure --prefix=$HOME/.local
- make -j4 && make install
- else
- echo "Using cached SDL2"
- fi
-
- export DEBIAN_FRONTEND=noninteractive
- # Amazing placebo security
- curl http://apt.llvm.org/llvm-snapshot.gpg.key | sudo -E apt-key add -
- sudo -E add-apt-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
- sudo -E apt-get -yq update
- sudo -E apt-get -yq install clang-format-3.9
-
+ docker pull ubuntu:16.04
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
brew update
brew install qt5 sdl2 dylibbundler p7zip
diff --git a/.travis-upload.sh b/.travis-upload.sh
index 8cfab31cb..8c1fa21c5 100755
--- a/.travis-upload.sh
+++ b/.travis-upload.sh
@@ -1,134 +1,139 @@
-if [ "$TRAVIS_EVENT_TYPE" = "push" ]&&[ "$TRAVIS_BRANCH" = "master" ]; then
- GITDATE="`git show -s --date=short --format='%ad' | sed 's/-//g'`"
- GITREV="`git show -s --format='%h'`"
- mkdir -p artifacts
-
- if [ "$TRAVIS_OS_NAME" = "linux" -o -z "$TRAVIS_OS_NAME" ]; then
- REV_NAME="citra-linux-${GITDATE}-${GITREV}"
- ARCHIVE_NAME="${REV_NAME}.tar.xz"
- COMPRESSION_FLAGS="-cJvf"
- mkdir "$REV_NAME"
-
- cp build/src/citra/citra "$REV_NAME"
- cp build/src/citra_qt/citra-qt "$REV_NAME"
- elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
- REV_NAME="citra-osx-${GITDATE}-${GITREV}"
- ARCHIVE_NAME="${REV_NAME}.tar.gz"
- COMPRESSION_FLAGS="-czvf"
- mkdir "$REV_NAME"
-
- cp build/src/citra/Release/citra "$REV_NAME"
- cp -r build/src/citra_qt/Release/citra-qt.app "$REV_NAME"
-
- # move qt libs into app bundle for deployment
- $(brew --prefix)/opt/qt5/bin/macdeployqt "${REV_NAME}/citra-qt.app"
-
- # move SDL2 libs into folder for deployment
- dylibbundler -b -x "${REV_NAME}/citra" -cd -d "${REV_NAME}/libs" -p "@executable_path/libs/"
-
- # Make the changes to make the citra-qt app standalone (i.e. not dependent on the current brew installation).
- # To do this, the absolute references to each and every QT framework must be re-written to point to the local frameworks
- # (in the Contents/Frameworks folder).
- # The "install_name_tool" is used to do so.
-
- # Coreutils is a hack to coerce Homebrew to point to the absolute Cellar path (symlink dereferenced). i.e:
- # ls -l /usr/local/opt/qt5:: /usr/local/opt/qt5 -> ../Cellar/qt5/5.6.1-1
- # grealpath ../Cellar/qt5/5.6.1-1:: /usr/local/Cellar/qt5/5.6.1-1
- brew install coreutils
-
- REV_NAME_ALT=$REV_NAME/
- # grealpath is located in coreutils, there is no "realpath" for OS X :(
- QT_BREWS_PATH=$(grealpath "$(brew --prefix qt5)")
- BREW_PATH=$(brew --prefix)
- QT_VERSION_NUM=5
-
- $BREW_PATH/opt/qt5/bin/macdeployqt "${REV_NAME_ALT}citra-qt.app" \
- -executable="${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt"
-
- # These are the files that macdeployqt packed into Contents/Frameworks/ - we don't want those, so we replace them.
- declare -a macos_libs=("QtCore" "QtWidgets" "QtGui" "QtOpenGL" "QtPrintSupport")
-
- for macos_lib in "${macos_libs[@]}"
+GITDATE="`git show -s --date=short --format='%ad' | sed 's/-//g'`"
+GITREV="`git show -s --format='%h'`"
+mkdir -p artifacts
+
+if [ "$TRAVIS_OS_NAME" = "linux" -o -z "$TRAVIS_OS_NAME" ]; then
+ REV_NAME="citra-linux-${GITDATE}-${GITREV}"
+ ARCHIVE_NAME="${REV_NAME}.tar.xz"
+ COMPRESSION_FLAGS="-cJvf"
+ mkdir "$REV_NAME"
+
+ cp build/src/citra/citra "$REV_NAME"
+ cp build/src/citra_qt/citra-qt "$REV_NAME"
+elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
+ REV_NAME="citra-osx-${GITDATE}-${GITREV}"
+ ARCHIVE_NAME="${REV_NAME}.tar.gz"
+ COMPRESSION_FLAGS="-czvf"
+ mkdir "$REV_NAME"
+
+ cp build/src/citra/Release/citra "$REV_NAME"
+ cp -r build/src/citra_qt/Release/citra-qt.app "$REV_NAME"
+
+ # move qt libs into app bundle for deployment
+ $(brew --prefix)/opt/qt5/bin/macdeployqt "${REV_NAME}/citra-qt.app"
+
+ # move SDL2 libs into folder for deployment
+ dylibbundler -b -x "${REV_NAME}/citra" -cd -d "${REV_NAME}/libs" -p "@executable_path/libs/"
+
+ # Make the changes to make the citra-qt app standalone (i.e. not dependent on the current brew installation).
+ # To do this, the absolute references to each and every QT framework must be re-written to point to the local frameworks
+ # (in the Contents/Frameworks folder).
+ # The "install_name_tool" is used to do so.
+
+ # Coreutils is a hack to coerce Homebrew to point to the absolute Cellar path (symlink dereferenced). i.e:
+ # ls -l /usr/local/opt/qt5:: /usr/local/opt/qt5 -> ../Cellar/qt5/5.6.1-1
+ # grealpath ../Cellar/qt5/5.6.1-1:: /usr/local/Cellar/qt5/5.6.1-1
+ brew install coreutils
+
+ REV_NAME_ALT=$REV_NAME/
+ # grealpath is located in coreutils, there is no "realpath" for OS X :(
+ QT_BREWS_PATH=$(grealpath "$(brew --prefix qt5)")
+ BREW_PATH=$(brew --prefix)
+ QT_VERSION_NUM=5
+
+ $BREW_PATH/opt/qt5/bin/macdeployqt "${REV_NAME_ALT}citra-qt.app" \
+ -executable="${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt"
+
+ # These are the files that macdeployqt packed into Contents/Frameworks/ - we don't want those, so we replace them.
+ declare -a macos_libs=("QtCore" "QtWidgets" "QtGui" "QtOpenGL" "QtPrintSupport")
+
+ for macos_lib in "${macos_libs[@]}"
+ do
+ SC_FRAMEWORK_PART=$macos_lib.framework/Versions/$QT_VERSION_NUM/$macos_lib
+ # Replace macdeployqt versions of the Frameworks with our own (from /usr/local/opt/qt5/lib/)
+ cp "$BREW_PATH/opt/qt5/lib/$SC_FRAMEWORK_PART" "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$SC_FRAMEWORK_PART"
+
+ # Replace references within the embedded Framework files with "internal" versions.
+ for macos_lib2 in "${macos_libs[@]}"
do
- SC_FRAMEWORK_PART=$macos_lib.framework/Versions/$QT_VERSION_NUM/$macos_lib
- # Replace macdeployqt versions of the Frameworks with our own (from /usr/local/opt/qt5/lib/)
- cp "$BREW_PATH/opt/qt5/lib/$SC_FRAMEWORK_PART" "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$SC_FRAMEWORK_PART"
-
- # Replace references within the embedded Framework files with "internal" versions.
- for macos_lib2 in "${macos_libs[@]}"
- do
- # Since brew references both the non-symlinked and symlink paths of QT5, it needs to be duplicated.
- # /usr/local/Cellar/qt5/5.6.1-1/lib and /usr/local/opt/qt5/lib both resolve to the same files.
- # So the two lines below are effectively duplicates when resolved as a path, but as strings, they aren't.
- RM_FRAMEWORK_PART=$macos_lib2.framework/Versions/$QT_VERSION_NUM/$macos_lib2
- install_name_tool -change \
- $QT_BREWS_PATH/lib/$RM_FRAMEWORK_PART \
- @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
- "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$SC_FRAMEWORK_PART"
- install_name_tool -change \
- "$BREW_PATH/opt/qt5/lib/$RM_FRAMEWORK_PART" \
- @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
- "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$SC_FRAMEWORK_PART"
- done
+ # Since brew references both the non-symlinked and symlink paths of QT5, it needs to be duplicated.
+ # /usr/local/Cellar/qt5/5.6.1-1/lib and /usr/local/opt/qt5/lib both resolve to the same files.
+ # So the two lines below are effectively duplicates when resolved as a path, but as strings, they aren't.
+ RM_FRAMEWORK_PART=$macos_lib2.framework/Versions/$QT_VERSION_NUM/$macos_lib2
+ install_name_tool -change \
+ $QT_BREWS_PATH/lib/$RM_FRAMEWORK_PART \
+ @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
+ "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$SC_FRAMEWORK_PART"
+ install_name_tool -change \
+ "$BREW_PATH/opt/qt5/lib/$RM_FRAMEWORK_PART" \
+ @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
+ "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$SC_FRAMEWORK_PART"
done
-
- # Handles `This application failed to start because it could not find or load the Qt platform plugin "cocoa"`
- # Which manifests itself as:
- # "Exception Type: EXC_CRASH (SIGABRT) | Exception Codes: 0x0000000000000000, 0x0000000000000000 | Exception Note: EXC_CORPSE_NOTIFY"
- # There may be more dylibs needed to be fixed...
- declare -a macos_plugins=("Plugins/platforms/libqcocoa.dylib")
-
- for macos_lib in "${macos_plugins[@]}"
+ done
+
+ # Handles `This application failed to start because it could not find or load the Qt platform plugin "cocoa"`
+ # Which manifests itself as:
+ # "Exception Type: EXC_CRASH (SIGABRT) | Exception Codes: 0x0000000000000000, 0x0000000000000000 | Exception Note: EXC_CORPSE_NOTIFY"
+ # There may be more dylibs needed to be fixed...
+ declare -a macos_plugins=("Plugins/platforms/libqcocoa.dylib")
+
+ for macos_lib in "${macos_plugins[@]}"
+ do
+ install_name_tool -id @executable_path/../$macos_lib "${REV_NAME_ALT}citra-qt.app/Contents/$macos_lib"
+ for macos_lib2 in "${macos_libs[@]}"
do
- install_name_tool -id @executable_path/../$macos_lib "${REV_NAME_ALT}citra-qt.app/Contents/$macos_lib"
- for macos_lib2 in "${macos_libs[@]}"
- do
- RM_FRAMEWORK_PART=$macos_lib2.framework/Versions/$QT_VERSION_NUM/$macos_lib2
- install_name_tool -change \
- $QT_BREWS_PATH/lib/$RM_FRAMEWORK_PART \
- @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
- "${REV_NAME_ALT}citra-qt.app/Contents/$macos_lib"
- install_name_tool -change \
- "$BREW_PATH/opt/qt5/lib/$RM_FRAMEWORK_PART" \
- @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
- "${REV_NAME_ALT}citra-qt.app/Contents/$macos_lib"
- done
+ RM_FRAMEWORK_PART=$macos_lib2.framework/Versions/$QT_VERSION_NUM/$macos_lib2
+ install_name_tool -change \
+ $QT_BREWS_PATH/lib/$RM_FRAMEWORK_PART \
+ @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
+ "${REV_NAME_ALT}citra-qt.app/Contents/$macos_lib"
+ install_name_tool -change \
+ "$BREW_PATH/opt/qt5/lib/$RM_FRAMEWORK_PART" \
+ @executable_path/../Frameworks/$RM_FRAMEWORK_PART \
+ "${REV_NAME_ALT}citra-qt.app/Contents/$macos_lib"
done
+ done
- for macos_lib in "${macos_libs[@]}"
- do
- # Debugging info for Travis-CI
- otool -L "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$macos_lib.framework/Versions/$QT_VERSION_NUM/$macos_lib"
- done
+ for macos_lib in "${macos_libs[@]}"
+ do
+ # Debugging info for Travis-CI
+ otool -L "${REV_NAME_ALT}citra-qt.app/Contents/Frameworks/$macos_lib.framework/Versions/$QT_VERSION_NUM/$macos_lib"
+ done
- # Make the citra-qt.app application launch a debugging terminal.
- # Store away the actual binary
- mv ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt-bin
+ # Make the citra-qt.app application launch a debugging terminal.
+ # Store away the actual binary
+ mv ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt-bin
- cat > ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt <<EOL
+ cat > ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt <<EOL
#!/usr/bin/env bash
cd "\`dirname "\$0"\`"
chmod +x citra-qt-bin
open citra-qt-bin --args "\$@"
EOL
- # Content that will serve as the launching script for citra (within the .app folder)
+ # Content that will serve as the launching script for citra (within the .app folder)
- # Make the launching script executable
- chmod +x ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt
+ # Make the launching script executable
+ chmod +x ${REV_NAME_ALT}citra-qt.app/Contents/MacOS/citra-qt
- fi
+fi
+
+# Copy documentation
+cp license.txt "$REV_NAME"
+cp README.md "$REV_NAME"
- # Copy documentation
- cp license.txt "$REV_NAME"
- cp README.md "$REV_NAME"
+tar $COMPRESSION_FLAGS "$ARCHIVE_NAME" "$REV_NAME"
- tar $COMPRESSION_FLAGS "$ARCHIVE_NAME" "$REV_NAME"
+# Find out what release we are building
+if [ -z $TRAVIS_TAG ]; then
+ RELEASE_NAME=head
+else
+ RELEASE_NAME=$(echo $TRAVIS_TAG | cut -d- -f1)
+fi
- mv "$REV_NAME" nightly
+mv "$REV_NAME" $RELEASE_NAME
- 7z a "$REV_NAME.7z" nightly
+7z a "$REV_NAME.7z" $RELEASE_NAME
- # move the compiled archive into the artifacts directory to be uploaded by travis releases
- mv "$ARCHIVE_NAME" artifacts/
- mv "$REV_NAME.7z" artifacts/
-fi
+# move the compiled archive into the artifacts directory to be uploaded by travis releases
+mv "$ARCHIVE_NAME" artifacts/
+mv "$REV_NAME.7z" artifacts/
diff --git a/.travis.yml b/.travis.yml
index 846758881..b92d7f236 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,23 +8,15 @@ matrix:
sudo: false
osx_image: xcode7.3
+services:
+ - docker
+
addons:
apt:
- sources:
- - ubuntu-toolchain-r-test
packages:
- - gcc-6
- - g++-6
- - qt5-default
- - libqt5opengl5-dev
- - xorg-dev
- - lib32stdc++6 # For CMake
+ - clang-format-3.9
- p7zip-full
-cache:
- directories:
- - "$HOME/.local"
-
install: "./.travis-deps.sh"
script: "./.travis-build.sh"
after_success: "./.travis-upload.sh"
@@ -37,4 +29,4 @@ deploy:
file: "artifacts/*"
skip_cleanup: true
on:
- repo: citra-emu/citra-nightly
+ tags: true
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ddba04ef9..f8060270e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,8 +129,8 @@ else()
set(CMAKE_C_FLAGS_RELEASE "/O2 /GS- /MD" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" CACHE STRING "" FORCE)
- set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
endif()
# Set file offset size to 64 bits.
diff --git a/README.md b/README.md
index e766918f7..31f5afe27 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ For development discussion, please join us @ #citra on freenode.
Most of the development happens on GitHub. It's also where [our central repository](https://github.com/citra-emu/citra) is hosted.
-If you want to contribute please take a look at the [Contributor's Guide](CONTRIBUTING.md), [TODO list](https://docs.google.com/document/d/1SWIop0uBI9IW8VGg97TAtoT_CHNoP42FzYmvG1F4QDA) and [Developer Information](https://github.com/citra-emu/citra/wiki/Developer-Information). You should as well contact any of the developers in the forum in order to know about the current state of the emulator.
+If you want to contribute please take a look at the [Contributor's Guide](CONTRIBUTING.md) and [Developer Information](https://github.com/citra-emu/citra/wiki/Developer-Information). You should as well contact any of the developers in the forum in order to know about the current state of the emulator because the [TODO list](https://docs.google.com/document/d/1SWIop0uBI9IW8VGg97TAtoT_CHNoP42FzYmvG1F4QDA) isn't maintained anymore.
### Building
diff --git a/appveyor.yml b/appveyor.yml
index d062a1f3e..ec9ca3747 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,15 +1,21 @@
# shallow clone
clone_depth: 10
-# don't build on tag
-skip_tags: true
-
cache:
- C:\ProgramData\chocolatey\bin -> appveyor.yml
- C:\ProgramData\chocolatey\lib -> appveyor.yml
os: Visual Studio 2017
+environment:
+ # Tell msys2 to add mingw64 to the path
+ MSYSTEM: MINGW64
+ # Tell msys2 to inherit the current directory when starting the shell
+ CHERE_INVOKING: 1
+ matrix:
+ - BUILD_TYPE: mingw
+ - BUILD_TYPE: msvc
+
platform:
- x64
@@ -18,70 +24,153 @@ configuration:
install:
- git submodule update --init --recursive
+ - ps: |
+ if ($env:BUILD_TYPE -eq 'mingw') {
+ $dependencies = "mingw64/mingw-w64-x86_64-cmake",
+ "mingw64/mingw-w64-x86_64-qt5",
+ "mingw64/mingw-w64-x86_64-curl",
+ "mingw64/mingw-w64-x86_64-SDL2"
+ # redirect err to null to prevent warnings from becoming errors
+ # workaround to prevent pacman from failing due to cyclical dependencies
+ C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw64/mingw-w64-x86_64-freetype mingw64/mingw-w64-x86_64-fontconfig" 2> $null
+ C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S $dependencies" 2> $null
+ }
before_build:
- - mkdir build
- - cd build
- - cmake -G "Visual Studio 15 2017 Win64" -DCITRA_USE_BUNDLED_QT=1 -DCITRA_USE_BUNDLED_SDL2=1 -DCMAKE_USE_OPENSSL=0 ..
+ - mkdir %BUILD_TYPE%_build
+ - cd %BUILD_TYPE%_build
+ - ps: |
+ if ($env:BUILD_TYPE -eq 'msvc') {
+ # redirect stderr and change the exit code to prevent powershell from cancelling the build if cmake prints a warning
+ cmd /C 'cmake -G "Visual Studio 15 2017 Win64" -DCITRA_USE_BUNDLED_QT=1 -DCITRA_USE_BUNDLED_SDL2=1 -DCMAKE_USE_OPENSSL=0 .. 2>&1 && exit 0'
+ } else {
+ C:\msys64\usr\bin\bash.exe -lc "cmake -G 'MSYS Makefiles' -DUSE_SYSTEM_CURL=1 -DCMAKE_BUILD_TYPE=Release .. 2>&1"
+ }
- cd ..
-build:
- project: build/citra.sln
- parallel: true
+build_script:
+ - ps: |
+ if ($env:BUILD_TYPE -eq 'msvc') {
+ # https://www.appveyor.com/docs/build-phase
+ msbuild msvc_build/citra.sln /maxcpucount /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
+ } else {
+ C:\msys64\usr\bin\bash.exe -lc 'mingw32-make -C mingw_build/ 2>&1'
+ }
after_build:
- ps: |
$GITDATE = $(git show -s --date=short --format='%ad') -replace "-",""
$GITREV = $(git show -s --format='%h')
- $GIT_LONG_HASH = $(git rev-parse HEAD)
- # Where are these spaces coming from? Regardless, let's remove them
- $MSVC_BUILD_NAME = "citra-windows-msvc-$GITDATE-$GITREV.zip" -replace " ", ""
- $MSVC_BUILD_PDB = "citra-windows-msvc-$GITDATE-$GITREV-debugsymbols.zip" -replace " ", ""
- $MSVC_SEVENZIP = "citra-windows-msvc-$GITDATE-$GITREV.7z" -replace " ", ""
- $BINTRAY_VERSION = "nightly-$GIT_LONG_HASH" -replace " ", ""
-
- # set the build names as env vars so the artifacts can upload them
- $env:MSVC_BUILD_NAME = $MSVC_BUILD_NAME
- $env:MSVC_BUILD_PDB = $MSVC_BUILD_PDB
- $env:MSVC_SEVENZIP = $MSVC_SEVENZIP
- $env:GITREV = $GITREV
-
- 7z a -tzip $MSVC_BUILD_PDB .\build\bin\release\*.pdb
- rm .\build\bin\release\*.pdb
-
- mkdir nightly
- Copy-Item .\build\bin\release\* -Destination nightly -Recurse
- Copy-Item .\license.txt -Destination nightly
- Copy-Item .\README.md -Destination nightly
-
- 7z a -tzip $MSVC_BUILD_NAME nightly\*
- 7z a $MSVC_SEVENZIP nightly
+
+ # Find out which kind of release we are producing by tag name
+ if ($env:APPVEYOR_REPO_TAG_NAME) {
+ $RELEASE_DIST, $RELEASE_VERSION = $env:APPVEYOR_REPO_TAG_NAME.split('-')
+ } else {
+ # There is no repo tag - make assumptions
+ $RELEASE_DIST = "head"
+ }
+
+ if ($env:BUILD_TYPE -eq 'msvc') {
+ # Where are these spaces coming from? Regardless, let's remove them
+ $MSVC_BUILD_ZIP = "citra-windows-msvc-$GITDATE-$GITREV.zip" -replace " ", ""
+ $MSVC_BUILD_PDB = "citra-windows-msvc-$GITDATE-$GITREV-debugsymbols.zip" -replace " ", ""
+ $MSVC_SEVENZIP = "citra-windows-msvc-$GITDATE-$GITREV.7z" -replace " ", ""
+
+ # set the build names as env vars so the artifacts can upload them
+ $env:BUILD_ZIP = $MSVC_BUILD_ZIP
+ $env:BUILD_SYMBOLS = $MSVC_BUILD_PDB
+ $env:BUILD_UPDATE = $MSVC_SEVENZIP
+
+ 7z a -tzip $MSVC_BUILD_PDB .\msvc_build\bin\release\*.pdb
+ rm .\msvc_build\bin\release\*.pdb
+
+ mkdir $RELEASE_DIST
+ Copy-Item .\msvc_build\bin\release\* -Destination $RELEASE_DIST -Recurse
+ Copy-Item .\license.txt -Destination $RELEASE_DIST
+ Copy-Item .\README.md -Destination $RELEASE_DIST
+ 7z a -tzip $MSVC_BUILD_ZIP $RELEASE_DIST\*
+ 7z a $MSVC_SEVENZIP $RELEASE_DIST
+ } else {
+ $MINGW_BUILD_ZIP = "citra-windows-mingw-$GITDATE-$GITREV.zip" -replace " ", ""
+ $MINGW_SEVENZIP = "citra-windows-mingw-$GITDATE-$GITREV.7z" -replace " ", ""
+ # not going to bother adding separate debug symbols for mingw, so just upload a README for it
+ # if someone wants to add them, change mingw to compile with -g and use objdump and strip to separate the symbols from the binary
+ $MINGW_NO_DEBUG_SYMBOLS = "README_No_Debug_Symbols.txt"
+ Set-Content -Path $MINGW_NO_DEBUG_SYMBOLS -Value "This is a workaround for Appveyor since msvc has debug symbols but mingw doesnt" -Force
+
+ # store the build information in env vars so we can use them as artifacts
+ $env:BUILD_ZIP = $MINGW_BUILD_ZIP
+ $env:BUILD_SYMBOLS = $MINGW_NO_DEBUG_SYMBOLS
+ $env:BUILD_UPDATE = $MINGW_SEVENZIP
+
+ $CMAKE_SOURCE_DIR = "$env:APPVEYOR_BUILD_FOLDER"
+ $CMAKE_BINARY_DIR = "$CMAKE_SOURCE_DIR/mingw_build"
+ $RELEASE_DIST = $RELEASE_DIST + "-mingw"
+
+ mkdir $RELEASE_DIST
+ mkdir $RELEASE_DIST/platforms
+
+ # copy the compiled binaries and other release files to the release folder
+ Get-ChildItem "$CMAKE_BINARY_DIR" -Recurse -Filter "citra*.exe" | Copy-Item -destination $RELEASE_DIST
+ Copy-Item -path "$CMAKE_SOURCE_DIR/license.txt" -destination $RELEASE_DIST
+ Copy-Item -path "$CMAKE_SOURCE_DIR/README.md" -destination $RELEASE_DIST
+
+ # copy all the dll dependencies to the release folder
+ # hardcoded list because we don't build static and determining the list of dlls from the binary is a pain.
+ $MingwDLLs = "Qt5Core.dll","Qt5Widgets.dll","Qt5Gui.dll","Qt5OpenGL.dll",
+ # QT dll dependencies
+ "libbz2-*.dll","libicudt*.dll","libicuin*.dll","libicuuc*.dll","libffi-*.dll",
+ "libfreetype-*.dll","libglib-*.dll","libgobject-*.dll","libgraphite2.dll","libiconv-*.dll",
+ "libharfbuzz-*.dll","libintl-*.dll","libpcre-*.dll","libpcre16-*.dll","libpng16-*.dll",
+ # Runtime/Other dependencies
+ "libgcc_s_seh-*.dll","libstdc++-*.dll","libwinpthread-*.dll","SDL2.dll","zlib1.dll",
+ # curl dependencies
+ "libcurl-*.dll","libnghttp2-*.dll","libeay32.dll","libgmp-*.dll","librtmp-*.dll",
+ "libgnutls-*.dll","libhogweed-*.dll","libnettle-*.dll","libssh2-*.dll",
+ "ssleay32.dll","libidn-*.dll","libp11-kit-*.dll","libtasn1-*.dll","libunistring-*.dll"
+ foreach ($file in $MingwDLLs) {
+ Copy-Item -path "C:/msys64/mingw64/bin/$file" -force -destination "$RELEASE_DIST"
+ }
+ # the above list copies a few extra debug dlls that aren't needed (thanks globbing patterns!)
+ # so we can remove them by hardcoding another list of extra dlls to remove
+ $DebugDLLs = "libicudtd*.dll","libicuind*.dll","libicuucd*.dll"
+ foreach ($file in $DebugDLLs) {
+ Remove-Item -path "$RELEASE_DIST/$file"
+ }
+
+ # copy the qt windows plugin dll to platforms
+ Copy-Item -path "C:/msys64/mingw64/share/qt5/plugins/platforms/qwindows.dll" -force -destination "$RELEASE_DIST/platforms"
+
+ 7z a -tzip $MINGW_BUILD_ZIP $RELEASE_DIST\*
+ 7z a $MINGW_SEVENZIP $RELEASE_DIST
+ }
test_script:
- - cd build && ctest -VV -C Release && cd ..
+ - cd %BUILD_TYPE%_build
+ - ps: |
+ if ($env:BUILD_TYPE -eq 'msvc') {
+ ctest -VV -C Release
+ } else {
+ C:\msys64\usr\bin\bash.exe -lc "ctest -VV -C Release"
+ }
+ - cd ..
artifacts:
- - path: $(MSVC_BUILD_NAME)
- name: msvcbuild
+ - path: $(BUILD_ZIP)
+ name: build
type: zip
- - path: $(MSVC_BUILD_PDB)
- name: msvcdebug
- type: zip
- - path: $(MSVC_SEVENZIP)
- name: msvcupdate
+ - path: $(BUILD_SYMBOLS)
+ name: debugsymbols
+ - path: $(BUILD_UPDATE)
+ name: update
deploy:
provider: GitHub
- release: nightly-$(appveyor_build_number)
- description: |
- Citra nightly releases. Please choose the correct download for your operating system from the list below.
-
- Short Commit Hash $(GITREV)
+ release: $(appveyor_repo_tag_name)
auth_token:
secure: "dbpsMC/MgPKWFNJCXpQl4cR8FYhepkPLjgNp/pRMktZ8oLKTqPYErfreaIxb/4P1"
- artifact: msvcupdate,msvcbuild
+ artifact: update,build
draft: false
prerelease: false
on:
- branch: master
- appveyor_repo_name: citra-emu/citra-nightly
+ appveyor_repo_tag: true
diff --git a/dist/citra.icns b/dist/citra.icns
index 9d3dcca83..ef7bf4e6e 100644
--- a/dist/citra.icns
+++ b/dist/citra.icns
Binary files differ
diff --git a/dist/citra.ico b/dist/citra.ico
index 4fef651e2..2c408b935 100644
--- a/dist/citra.ico
+++ b/dist/citra.ico
Binary files differ
diff --git a/dist/citra.manifest b/dist/citra.manifest
new file mode 100644
index 000000000..fd30b656f
--- /dev/null
+++ b/dist/citra.manifest
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+ <application xmlns="urn:schemas-microsoft-com:asm.v3">
+ <windowsSettings>
+ <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
+ <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
+ </windowsSettings>
+ </application>
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
+ <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
+ <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
+ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
+ </application>
+ </compatibility>
+</assembly> \ No newline at end of file
diff --git a/dist/citra.svg b/dist/citra.svg
index 7b299cd89..b6abc1ccf 100644
--- a/dist/citra.svg
+++ b/dist/citra.svg
@@ -1,80 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright 2014 Citra Emulator Project
- Licensed under GPLv2 or any later version
- Refer to the license.txt file included.
--->
-<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 341.071 338.846">
- <radialGradient id="a" cx="170.5356" cy="167.271" r="170.5332" gradientTransform="matrix(1 0 0 0.9935 0 3.2396)" gradientUnits="userSpaceOnUse">
- <stop offset="0.5193" stop-color="#FFFFFF" stop-opacity="0.1"/>
- <stop offset="0.9415" stop-color="#000000" stop-opacity="0.5"/>
- <stop offset="1" stop-color="#1A1818" stop-opacity="0"/>
- </radialGradient>
- <ellipse fill="url(#a)" cx="170.535" cy="169.423" rx="170.535" ry="169.423"/>
- <circle fill="#D16F17" cx="170.536" cy="167.885" r="161.557"/>
- <linearGradient id="b" gradientUnits="userSpaceOnUse" x1="234.4458" y1="33.5771" x2="97.5655" y2="321.2358">
- <stop offset="0" stop-color="#FFF8BD"/>
- <stop offset="1" stop-color="#F6DCAE"/>
- </linearGradient>
- <circle fill="url(#b)" cx="170.536" cy="167.885" r="155.295"/>
- <g>
- <linearGradient id="c" gradientUnits="userSpaceOnUse" x1="332.436" y1="91.7446" x2="111.1593" y2="342.0988">
- <stop offset="0" stop-color="#F7A076"/>
- <stop offset="0.4455" stop-color="#F3816C"/>
- <stop offset="1" stop-color="#F06878"/>
- </linearGradient>
- <path fill="url(#c)" stroke="#F06564" stroke-miterlimit="10" d="M309.704,123.138
- c-5.9-7.802-128.517,44.681-128.517,44.681S303.803,221.01,309.704,212.5C322.434,194.142,323.182,140.957,309.704,123.138z"/>
- <linearGradient id="d" gradientUnits="userSpaceOnUse" x1="285.5845" y1="50.3345" x2="64.3074" y2="300.6891">
- <stop offset="0" stop-color="#9DC63B"/>
- <stop offset="1" stop-color="#9BC183"/>
- </linearGradient>
- <path fill="url(#d)" stroke="#72AA42" stroke-miterlimit="10" d="M300.518,100.96c-3.98-21.983-41.059-60.12-63.189-63.188
- c-9.688-1.345-59.28,122.469-59.28,122.469S302.364,111.149,300.518,100.96z"/>
- <linearGradient id="e" gradientUnits="userSpaceOnUse" x1="229.4995" y1="0.7637" x2="8.2231" y2="251.1176">
- <stop offset="0" stop-color="#D5DE26"/>
- <stop offset="1" stop-color="#C5D94B"/>
- </linearGradient>
- <path fill="url(#e)" stroke="#BECD30" stroke-miterlimit="10" d="M215.151,28.584c-18.357-12.73-71.543-13.478-89.362,0.001
- c-7.801,5.899,44.682,128.516,44.682,128.516S223.663,34.484,215.151,28.584z"/>
- <linearGradient id="f" gradientUnits="userSpaceOnUse" x1="219.3823" y1="-8.1782" x2="-1.8941" y2="242.1756">
- <stop offset="0" stop-color="#F2D200"/>
- <stop offset="1" stop-color="#FDEF52"/>
- </linearGradient>
- <path fill="url(#f)" stroke="#E1BE29" stroke-miterlimit="10" d="M162.893,160.239c0,0-49.092-124.315-59.281-122.469
- c-21.982,3.979-60.12,41.058-63.188,63.189C39.078,110.646,162.893,160.239,162.893,160.239z"/>
- <linearGradient id="g" gradientUnits="userSpaceOnUse" x1="226.0718" y1="-2.2656" x2="4.7951" y2="248.0886">
- <stop offset="0" stop-color="#FFCD10"/>
- <stop offset="1" stop-color="#F29634"/>
- </linearGradient>
- <path fill="url(#g)" stroke="#F79421" stroke-miterlimit="10" d="M31.236,123.136c-12.73,18.357-13.479,71.543,0,89.362
- c5.898,7.801,128.516-44.682,128.516-44.682S37.135,114.625,31.236,123.136z"/>
- <linearGradient id="h" gradientUnits="userSpaceOnUse" x1="272.9214" y1="39.144" x2="51.6446" y2="289.4984">
- <stop offset="0" stop-color="#F79F1C"/>
- <stop offset="0.4455" stop-color="#F08021"/>
- <stop offset="1" stop-color="#ED693C"/>
- </linearGradient>
- <path fill="url(#h)" stroke="#F16622" stroke-miterlimit="10" d="M40.422,234.676c3.979,21.982,41.057,60.12,63.188,63.188
- c9.687,1.346,59.279-122.468,59.279-122.468S38.574,224.487,40.422,234.676z"/>
- <linearGradient id="i" gradientUnits="userSpaceOnUse" x1="329.0083" y1="88.7129" x2="107.7311" y2="339.0677">
- <stop offset="0" stop-color="#E47C26"/>
- <stop offset="0.4455" stop-color="#DF5B27"/>
- <stop offset="1" stop-color="#DD3A3A"/>
- </linearGradient>
- <path fill="url(#i)" stroke="#E03827" stroke-miterlimit="10" d="M125.787,307.051c18.357,12.73,71.543,13.48,89.362,0
- c7.801-5.898-44.681-128.515-44.681-128.515S117.275,301.153,125.787,307.051z"/>
- <linearGradient id="j" gradientUnits="userSpaceOnUse" x1="339.1245" y1="97.6562" x2="117.8478" y2="348.0104">
- <stop offset="0" stop-color="#F3783C"/>
- <stop offset="0.4455" stop-color="#EF5339"/>
- <stop offset="1" stop-color="#ED294A"/>
- </linearGradient>
- <path fill="url(#j)" stroke="#ED2836" stroke-miterlimit="10" d="M178.047,175.398c0,0,49.09,124.315,59.28,122.467
- c21.982-3.979,60.121-41.057,63.189-63.188C301.86,224.991,178.047,175.398,178.047,175.398z"/>
- </g>
- <linearGradient id="k" gradientUnits="userSpaceOnUse" x1="170.5352" y1="6.3281" x2="170.5351" y2="329.4424">
- <stop offset="0" stop-color="#FFFFFF" stop-opacity="0.2"/>
- <stop offset="0.4504" stop-color="#908E8E" stop-opacity="0.05"/>
- <stop offset="1" stop-color="#030003" stop-opacity="0.2"/>
- </linearGradient>
- <circle fill="url(#k)" cx="170.536" cy="167.885" r="161.557"/>
-</svg>
+<svg version="1.1" viewBox="0 0 433.93 397.43" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink"><metadata><rdf:RDF><cc:Work rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/><dc:title/></cc:Work></rdf:RDF></metadata><defs><linearGradient id="linearGradient7230"><stop stop-color="#f15a24" offset="0"/><stop stop-color="#f15a24" stop-opacity="0" offset="1"/></linearGradient><radialGradient id="radialGradient4297" cx="0" cy="0" r="1" fx=".33908" fy="-.55275" gradientTransform="matrix(135.72 53.102 32.823 -83.888 479.47 287.23)" gradientUnits="userSpaceOnUse"><stop stop-color="#ffff87" offset="0"/><stop stop-color="#ffff87" offset=".12648"/><stop stop-color="#ffc503" offset=".14449"/><stop stop-color="#ffc503" offset=".21612"/><stop stop-color="#ffc503" offset=".39528"/><stop stop-color="#ffc503" offset=".4406"/><stop stop-color="#ffc003" offset=".49983"/><stop stop-color="#ffc003" offset=".62818"/><stop stop-color="#ffc003" offset=".72864"/><stop stop-color="#ff8904" stop-opacity=".86935" offset=".84938"/><stop stop-color="#ff8904" offset=".98742"/><stop stop-color="#ff8904" offset="1"/></radialGradient><radialGradient id="radialGradient4331" cx="-.042447" cy=".042662" r="1" gradientTransform="matrix(97.003 -81.357 -81.357 -97.003 516.33 432.83)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffba05" offset=".66567"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4351" cx="0" cy="0" r="1" gradientTransform="matrix(-12.353 -91.85 -91.85 12.353 493.83 420.5)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4371" cx="0" cy="0" r="1" fx="-.89202" fy="-.452" gradientTransform="matrix(58.797 44.174 44.174 -58.797 591.5 452.83)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4391" cx="0" cy="0" r="1" gradientTransform="matrix(-63.936 -51.968 -51.968 63.936 480.5 419.5)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4413" cx="-.27681" cy="-.01256" r="1" gradientTransform="matrix(166.21 117.68 75.941 -107.26 545.45 466.23)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffee05" offset=".49699"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4433" cx=".0693" cy=".0013088" r="1" gradientTransform="matrix(92.166 1.56 1.3981 -82.601 484.17 431.17)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4453" cx="0" cy="0" r="1" gradientTransform="matrix(112.47 78.731 51.056 -72.937 527.5 460.5)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffba05" offset="1"/></radialGradient><radialGradient id="radialGradient4475" cx=".13237" cy="-.0012055" r="1" fx="-.080444" fy=".038791" gradientTransform="matrix(64.042 -58.572 -66.76 -72.994 505.91 439.83)" gradientUnits="userSpaceOnUse"><stop stop-color="#ff0" offset="0"/><stop stop-color="#ffcf05" offset=".62977"/><stop stop-color="#ffcf05" offset="1"/></radialGradient><linearGradient id="linearGradient7248-9" x1="382.8" x2="662.93" y1="393.32" y2="393.32" gradientUnits="userSpaceOnUse" xlink:href="#linearGradient7230"/><clipPath id="clipPath4307-2"><path d="m640.25 512.56c0.366-0.686 1.015-1.901 1.507-3.229 0.237-0.588 0.284-0.774 0.375-1.057 0.174-0.52 0.277-0.819 0.368-1.099 0.09-0.28 0.019-0.115 0.107-0.392 0.087-0.277 0.181-0.577 0.264-0.852 0.082-0.276 0.15-0.659 0.224-0.934 0.076-0.276 0.167-0.604 0.233-0.881 0.066-0.276 0.257-1.337 0.312-1.615 0.316-1.599 0.241-2.12 0.401-3.701 0.16-1.58 0.244-3.151 0.26-4.712 0.016-1.563-0.038-3.115-0.154-4.66-0.117-1.545-0.296-3.081-0.533-4.61-0.237-1.528-0.531-3.049-0.877-4.562-0.345-1.513-0.742-3.02-1.184-4.518-0.442-1.5-0.93-2.992-1.457-4.478-0.527-1.485-1.094-2.964-1.694-4.438-1.181-2.896-2.451-5.732-3.805-8.51-1.353-2.778-2.789-5.5-4.302-8.169-1.512-2.671-3.099-5.288-4.755-7.858-1.656-2.571-3.38-5.093-5.165-7.574-1.785-2.48-3.631-4.918-5.53-7.318-1.9-2.4-3.853-4.762-5.852-7.09s-4.044-4.624-6.129-6.89c-2.084-2.267-4.207-4.506-6.362-6.72-2.218-2.28-4.472-4.518-6.76-6.714-2.287-2.197-4.608-4.353-6.961-6.47s-4.737-4.196-7.152-6.237-4.86-4.046-7.334-6.016c-2.473-1.969-4.975-3.904-7.504-5.806-2.528-1.902-5.084-3.771-7.664-5.609-2.581-1.838-5.187-3.645-7.816-5.423-2.63-1.778-5.282-3.527-7.957-5.247-3.325-2.142-6.677-4.217-10.058-6.225-3.381-2.007-6.792-3.946-10.232-5.813-3.441-1.867-6.912-3.661-10.416-5.38s-7.041-3.362-10.611-4.924c-3.571-1.563-7.177-3.046-10.818-4.446-1.846-0.709-3.702-1.398-5.566-2.064-1.814-0.648-3.636-1.274-5.468-1.88-3.716-1.228-7.47-2.37-11.263-3.42-3.794-1.049-7.627-2.009-11.502-2.872-1.624-0.362-3.249-0.695-4.876-1-1.627-0.304-3.255-0.578-4.886-0.823-1.631-0.244-3.262-0.457-4.896-0.638s-3.269-0.33-4.907-0.445c-1.636-0.116-3.275-0.197-4.915-0.245-1.639-0.046-3.28-0.058-4.923-0.034-1.641 0.024-3.285 0.085-4.929 0.183-1.645 0.097-3.29 0.233-4.937 0.408-1.337 0.142-2.664 0.317-3.979 0.531s-2.617 0.466-3.906 0.759c-1.288 0.294-2.562 0.627-3.819 1.007-1.256 0.38-2.496 0.805-3.717 1.278-1.22 0.475-2.422 0.997-3.602 1.571-1.179 0.575-2.337 1.201-3.471 1.884-1.133 0.683-2.244 1.421-3.326 2.22-1.084 0.798-2.656 1.973-3.685 2.893l-3.143-7.259c-3.143-7.26 1.5-6 3.143-8.5 1.644-2.5 0.357-9 0.217-15s6.64-11.5 9.64-14.5c3-3.001 10-10.5 14.5-11.82 4.5-1.319 23.5-16.18 30-18.181 6.5-1.999 13.5-6.999 22-8.499s19-3 27.5-3 26.5-0.5 38.5 0 27 3 33 4 20 2.5 27.5 4.5 23.5 8 27 11.5 28 13.999 33.5 20c5.5 6 24 39.5 25 45.5s14 47.499 17 53c3 5.5 0 39.499 0 45.5 0 6-10 45-10 45l-13.5 28.5-14 14.5z"/></clipPath><radialGradient id="radialGradient7556" cx="698.21" cy="478.94" r="186.38" gradientTransform="matrix(1.2034 -.41433 .38181 1.1089 -338.27 245.75)" gradientUnits="userSpaceOnUse"><stop stop-color="#f15a24" stop-opacity="0" offset="0"/><stop stop-color="#f15a24" stop-opacity="0" offset=".68534"/><stop stop-color="#f14a24" offset="1"/></radialGradient></defs><g transform="translate(-265.81 -357.85)"><g transform="translate(-206,70)"><path d="m651.83 684.53c-17.986-2.258-43.941-8.1382-59.303-13.436-45.416-15.66-91.627-51.387-112.29-86.813-7.3922-12.675-9.8553-29.065-7.6405-50.846 1.5707-15.448 4.2385-24.955 10.938-38.978 20.81-43.561 55.611-85.05 100.64-119.99 33.898-26.298 69.589-47.881 101.64-61.46 27.534-11.666 61.915-21.532 84.068-24.123 27.343-3.1985 56.096 1.1638 74.647 11.325 18.752 10.271 30.61 25.375 43.922 55.939 12.492 28.684 17.312 55.294 17.291 95.461-0.0151 34.075-4.1728 58.552-14.29 84.174-8.402 21.279-21.718 44.014-36.542 62.391-6.6008 8.1824-26.727 28.053-35.45 35-19.832 15.793-45.654 30.387-66.248 37.441-17.156 5.8765-39.99 11.132-59.144 13.612-9.676 1.253-33.307 1.4198-42.243 0.29802z" fill="#fff" stroke-width=".75166"/><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m508.37 418.38c-1.948-9.873-2.175-19.875-2.148-30.734 0.105-4.803-8e-3 -10.436 0.607-16.082 1.248-11.467 5.143-14.109 15.617-9.51 17.862 7.84 33.696 18.829 47.854 32.241 3.988 3.779 8.185 7.422 11.089 12.202 2.673 4.397 2.097 6.88-2.266 9.608-1.396 0.873-2.949 1.54-4.502 2.103-5.181 1.881-10.542 3.121-15.918 4.281-12.621 2.721-25.222 5.644-38.216 5.823-0.08 1e-3 -0.159 1e-3 -0.239 1e-3 -6.452 0-10.63-3.605-11.878-9.933" fill="url(#radialGradient4331)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m492.04 416.52c-3.243-1.617-5.823-4.156-8.361-6.684-16.977-16.905-32.998-34.704-48.672-52.819-4.26-4.924-8.651-9.823-11.376-15.886-1.919-4.27-0.934-6.454 3.654-7.668 4.725-1.249 9.544-1.787 14.436-1.358 11.696 1.026 22.799 4.32 33.655 8.677 10.044 4.032 16.339 11.18 18.544 21.838 2.891 13.979 3.907 28.175 4.618 42.392 0 2.182 0.021 4.364-0.013 6.545-0.01 0.636-0.15 1.274-0.276 1.902-0.545 2.722-1.447 4.01-3.104 4.01-0.83 0-1.848-0.323-3.105-0.949" fill="url(#radialGradient4351)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m623.43 485.96c-2.879-0.515-5.736-1.318-8.503-2.282-15.719-5.482-30.649-12.847-45.782-19.703-12.92-5.855-25.833-11.785-38.083-19.013-2.413-1.425-5.354-3.1-4.765-6.319 0.504-2.751 3.758-2.789 6.016-3.319 17.339-4.073 35.01-5.712 51.316-7.058 10.474 0.119 18.926 1.786 25.516 8.829 6.88 7.354 12.632 15.489 16.919 24.601 2.691 5.72 4.477 11.786 4.479 18.169 2e-3 4.153-1.835 6.272-5.267 6.272-0.571 0-1.188-0.059-1.846-0.177" fill="url(#radialGradient4371)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m475.92 419.25c-0.367-0.104-0.71-0.292-1.065-0.437-22.555-9.166-44.21-20.249-65.865-31.321-5.464-2.792-10.748-5.939-15.684-9.652-5.297-3.984-8.316-8.98-7.651-15.694 0-0.89-0.035-1.662 5e-3 -2.431 0.397-7.627 4.249-12.981 10.812-16.559 6.098-3.323 11.35-1.172 16.365 2.52 1.236 0.911 2.498 1.799 3.649 2.811 22.843 20.104 43.28 42.565 63.347 65.381 1.264 1.437 3.447 3.141 2.012 5.299-0.613 0.922-1.333 1.232-2.102 1.231-1.232 0-2.589-0.797-3.823-1.148" fill="url(#radialGradient4391)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m589.81 520.12c-2.155-1.598-4.18-3.381-6.195-5.159-14.338-12.647-27.085-26.892-40.259-40.697-5.472-5.734-10.87-11.588-15.617-17.981-0.828-1.116-1.856-2.369-0.83-3.824 0.972-1.379 2.519-1.147 3.87-0.737 1.831 0.556 3.62 1.272 5.386 2.018 23.705 10.024 46.647 21.655 69.496 33.464 6.568 3.394 13.185 6.854 18.588 12.131 2.02 1.974 3.277 4.24 3.342 7.436-0.072 2.307-0.943 4.698-2.221 6.96-4.063 7.191-12.308 11.156-20.705 11.156-5.215 0-10.489-1.53-14.855-4.767" fill="url(#radialGradient4413)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m413.44 432.07c-5.861-6.67-11.407-13.524-15.914-21.172-2.874-4.876-5.175-10.064-6.355-15.632-0.819-3.866 0.412-5.458 3.711-5.517 2.078 0.023 4.038 0.607 5.971 1.3 18.942 6.786 36.964 15.693 55.17 24.173 7.774 3.62 15.486 7.375 22.781 11.914 2.187 1.361 4.634 2.997 4.191 5.914-0.396 2.604-3.356 2.319-5.257 3.169-0.692 0.308-1.469 0.436-2.215 0.612-11.727 2.765-23.679 4.039-35.625 5.305-1.381 0.147-2.734 0.221-4.058 0.221-8.707 0-16.182-3.211-22.4-10.287" fill="url(#radialGradient4433)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m567.31 526.82c-14.169-1.46-27.39-6.06-40.199-12.109-7.73-3.652-12.567-9.493-14.146-17.954-1.793-9.597-3.042-19.253-2.904-29.045 0-2.697-0.068-5.395 0.022-8.089 0.067-1.997-0.399-4.391 1.83-5.503 2.219-1.108 4.351 0.084 6.055 1.392 2.834 2.177 5.567 4.529 8.099 7.054 14.061 14.024 27.283 28.841 40.42 43.726 4.051 4.589 8.321 9.1 10.964 14.772 1.594 3.423 0.812 4.978-2.88 5.7-1.112 0.218-2.231 0.3-3.353 0.3-1.302 0-2.607-0.11-3.908-0.244" fill="url(#radialGradient4453)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m493.43 497.7c-3.943-1.236-7.454-3.334-11.002-5.368-14.602-8.364-28.162-18.128-39.782-30.405-5.392-5.696-4.536-9.429 2.935-11.564 13.892-3.97 27.998-7.036 42.519-7.395 7.646-0.189 11.495 3.378 12.86 10.836 1.395 7.615 1.69 15.275 1.485 25.395-0.22 3.072 0.784 8.645-0.687 14.051-0.943 3.472-2.527 5.026-5.134 5.025-0.929 0-1.988-0.197-3.194-0.575" fill="url(#radialGradient4475)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)"><path d="m641.75 509.34c0.237-0.588 0.284-0.774 0.375-1.057 0.174-0.52 0.277-0.819 0.368-1.099 0.09-0.28 0.019-0.115 0.107-0.392 0.087-0.277 0.181-0.577 0.264-0.852 0.082-0.276 0.15-0.659 0.224-0.934 0.076-0.276 0.167-0.604 0.233-0.881 0.066-0.276 0.257-1.337 0.312-1.615 0.316-1.599 0.241-2.12 0.401-3.701 0.16-1.58 0.244-3.151 0.26-4.712 0.016-1.563-0.038-3.115-0.154-4.66-0.117-1.545-0.296-3.081-0.533-4.61-0.237-1.528-0.531-3.049-0.877-4.562-0.345-1.513-0.742-3.02-1.184-4.518-0.442-1.5-0.93-2.992-1.457-4.478-0.527-1.485-1.094-2.964-1.694-4.438-1.181-2.896-2.451-5.732-3.805-8.51-1.353-2.778-2.789-5.5-4.302-8.169-1.512-2.671-3.099-5.288-4.755-7.858-1.656-2.571-3.38-5.093-5.165-7.574-1.785-2.48-3.631-4.918-5.53-7.318-1.9-2.4-3.853-4.762-5.852-7.09s-4.044-4.624-6.129-6.89c-2.084-2.267-4.207-4.506-6.362-6.72-2.218-2.28-4.472-4.518-6.76-6.714-2.287-2.197-4.608-4.353-6.961-6.47s-4.737-4.196-7.152-6.237-4.86-4.046-7.334-6.016c-2.473-1.969-4.975-3.904-7.504-5.806-2.528-1.902-5.084-3.771-7.664-5.609-2.581-1.838-5.187-3.645-7.816-5.423-2.63-1.778-5.282-3.527-7.957-5.247-3.325-2.142-6.677-4.217-10.058-6.225-3.381-2.007-6.792-3.946-10.232-5.813-3.441-1.867-6.912-3.661-10.416-5.38s-7.041-3.362-10.611-4.924c-3.571-1.563-7.177-3.046-10.818-4.446-1.846-0.709-3.702-1.398-5.566-2.064-1.814-0.648-3.636-1.274-5.468-1.88-3.716-1.228-7.47-2.37-11.263-3.42-3.794-1.049-7.627-2.009-11.502-2.872-1.624-0.362-3.249-0.695-4.876-1-1.627-0.304-3.255-0.578-4.886-0.823-1.631-0.244-3.262-0.457-4.896-0.638s-3.269-0.33-4.907-0.445c-1.636-0.116-3.275-0.197-4.915-0.245-1.639-0.046-3.28-0.058-4.923-0.034-1.641 0.024-3.285 0.085-4.929 0.183-1.645 0.097-3.29 0.233-4.937 0.408-1.337 0.142-2.664 0.317-3.979 0.531s-2.617 0.466-3.906 0.759c-1.288 0.294-2.562 0.627-3.819 1.007-1.256 0.38-2.496 0.805-3.717 1.278-1.22 0.475-2.422 0.997-3.602 1.571-0.749 0.365-1.489 0.751-2.22 1.159-0.522 0.286-1.038 0.583-1.55 0.891-1.134 0.683-2.243 1.421-3.327 2.219-0.744 0.549-1.475 1.125-2.194 1.731-0.282 0.225-0.554 0.448-0.806 0.662 5.18-5.701 10.508-11.008 15.987-15.904 5.538-4.95 11.227-9.48 17.07-13.573 5.843-4.094 11.839-7.751 17.987-10.956 6.148-3.204 12.449-5.954 18.901-8.236 6.453-2.28 13.059-4.091 19.816-5.415 6.758-1.325 13.668-2.162 20.731-2.495s14.278-0.163 21.645 0.528c7.368 0.692 14.887 1.904 22.56 3.654 8.186 1.866 15.978 4.164 23.376 6.884 7.397 2.719 14.401 5.861 21.012 9.414 6.611 3.555 12.828 7.522 18.655 11.891 5.826 4.371 11.261 9.143 16.304 14.311 5.045 5.167 9.698 10.729 13.962 16.675 4.264 5.947 8.14 12.278 11.626 18.985 3.487 6.707 6.586 13.789 9.296 21.238 2.712 7.449 5.037 15.264 6.975 23.436 0.548 2.31 1.025 4.624 1.432 6.944 0.408 2.318 0.747 4.641 1.023 6.968 0.275 2.327 0.486 4.658 0.637 6.991 0.15 2.333 0.241 4.671 0.276 7.01 0.034 2.339 0.013 4.681-0.061 7.024-0.074 2.345-0.2 4.69-0.374 7.037-0.174 2.348-0.396 4.697-0.664 7.046-0.266 2.349-0.577 4.699-0.928 7.049-0.39 2.617-0.912 5.345-1.535 8.125-0.623 2.779-1.346 5.609-2.142 8.427-0.795 2.819-1.66 5.626-2.569 8.359-0.907 2.733-1.855 5.391-2.816 7.915-0.959 2.523-1.931 4.909-2.883 7.098-0.953 2.189-1.888 4.179-2.773 5.909-0.886 1.73-1.723 3.199-2.481 4.346-0.475 0.717-1.25 1.831-1.946 2.775 0.215-0.462 0.433-0.967 0.627-1.49" fill="url(#radialGradient4297)"/></g><g transform="matrix(1.3333 0 0 -1.3333 0 1024)" fill="url(#linearGradient7248-9)"><g clip-path="url(#clipPath4307-2)" fill="url(#linearGradient7248-9)"><g transform="translate(382.92 331.6)" fill="url(#linearGradient7248-9)"><path d="m0 0c6.615-7.221 13.678-14.033 21.222-20.267 7.539-6.237 15.577-11.868 24.046-16.747 8.468-4.879 17.397-8.961 26.656-12.07 9.256-3.117 18.837-5.252 28.533-6.374 9.697-1.126 19.503-1.24 29.23-0.453 9.731 0.785 19.379 2.465 28.846 4.853 18.922 4.75 37.215 12.333 53.364 23.285 8.065 5.472 15.569 11.768 22.33 18.787 6.768 7.012 12.789 14.739 18.015 22.967 10.462 16.478 17.733 34.859 22.474 53.789l0.439 1.778 0.209 0.872 0.186 0.899 0.747 3.597 0.373 1.798 0.093 0.45 0.024 0.112c-7e-3 -0.038 7e-3 0.055 0.01 0.076l0.034 0.227 0.134 0.908 0.539 3.634 0.269 1.817c0.077 0.534 0.118 1.199 0.18 1.791l0.338 3.658 0.164 1.796 0.075 1.835 0.15 3.671c0.264 9.752-0.472 19.521-1.882 29.184-1.502 9.646-4.173 19.05-7.353 28.281l-1.228 3.463-0.307 0.865-0.144 0.409-0.173 0.426-0.689 1.702-1.379 3.405-0.685 1.671-0.778 1.664-1.557 3.327-0.371 0.788-0.455 0.798-0.909 1.596-1.8039 3.187c-12.883 30.325-179.5-236.54-259.07-177.56zm-8e-3 8e-3c92.186-40.479 231.35 107.76 257.54 180.96 0.828-0.982 1.523-1.975 2.238-2.986 0.351-0.52 0.707-0.981 1.036-1.569l0.913-1.594 0.912-1.594 0.457-0.797c0.183-0.358 0.275-0.576 0.417-0.871l2.346-4.986c0.271-0.617 0.473-1.148 0.713-1.726l1.387-3.402 0.693-1.701 0.173-0.425 0.164-0.457 0.309-0.865 1.235-3.459c3.22-9.271 5.937-18.782 7.475-28.508 1.444-9.716 2.213-19.555 1.972-29.393l-0.14-3.671-0.069-1.836-0.164-1.863-0.329-3.659c-0.063-0.625-0.09-1.185-0.183-1.864l-0.264-1.818-0.528-3.635-0.132-0.909-0.033-0.227-0.024-0.152-0.023-0.112-0.092-0.45-0.369-1.8-0.736-3.599-0.185-0.9-0.216-0.915-0.436-1.79c-2.367-9.534-5.355-18.932-9.077-28.033-3.717-9.105-8.196-17.911-13.474-26.221-5.276-8.31-11.358-16.118-18.197-23.206-6.832-7.094-14.416-13.459-22.563-18.989-8.15-5.528-16.852-10.229-25.9-14.096-9.054-3.857-18.44-6.901-27.983-9.247-9.54-2.354-19.27-3.997-29.075-4.737-9.804-0.741-19.683-0.576-29.444 0.61-9.761 1.181-19.397 3.381-28.694 6.565-9.3 3.177-18.256 7.329-26.737 12.275-8.488 4.941-16.474 10.71-23.972 17.028-7.497 6.325-14.5 13.22-21.044 20.512z" fill="url(#linearGradient7248-9)"/></g></g></g><path d="m853.83 340.91z" fill="none" stroke="#000" stroke-width="1px"/><path d="m512.59 583.25c24.074 19.047 61.695 18.896 102.99 7.7902 41.299-11.105 86.278-33.164 124.63-62.438 43.462-33.178 74.436-61.06 97.049-98.852 10.211-17.065 16.881-32.679 20.405-47.4 3.5243-14.721 2.1355-27.046-3.4171-40.626 0 0 22.052 31.822 28.025 81.607 2.9864 24.893 1.4477 59.407-11.26 93.337-11.843 31.622-27.743 61.223-54.874 85.55-1.0301 0.92357-12.207 12.478-32.938 24.374-25.596 14.688-46.884 22.5-75.534 27.634-34.926 6.2583-59.469 4.4522-85.833-1.8111-36.815-8.7462-71.794-28.542-110.24-69.041" fill="url(#radialGradient7556)"/></g></g></svg>
diff --git a/dist/doc-icon.png b/dist/doc-icon.png
index 420b1546f..9b5773214 100644
--- a/dist/doc-icon.png
+++ b/dist/doc-icon.png
Binary files differ
diff --git a/externals/soundtouch b/externals/soundtouch
-Subproject 5274ec4dec498bd88ccbcd28862a0f78a3b95ef
+Subproject 019d2089bbadf70d73ba85aa8ea51490b071262
diff --git a/src/audio_core/hle/source.cpp b/src/audio_core/hle/source.cpp
index 92484c526..de4e88cae 100644
--- a/src/audio_core/hle/source.cpp
+++ b/src/audio_core/hle/source.cpp
@@ -244,17 +244,27 @@ void Source::GenerateFrame() {
break;
}
- const size_t size_to_copy =
- std::min(state.current_buffer.size(), current_frame.size() - frame_position);
-
- std::copy(state.current_buffer.begin(), state.current_buffer.begin() + size_to_copy,
- current_frame.begin() + frame_position);
- state.current_buffer.erase(state.current_buffer.begin(),
- state.current_buffer.begin() + size_to_copy);
-
- frame_position += size_to_copy;
- state.next_sample_number += static_cast<u32>(size_to_copy);
+ switch (state.interpolation_mode) {
+ case InterpolationMode::None:
+ AudioInterp::None(state.interp_state, state.current_buffer, state.rate_multiplier,
+ current_frame, frame_position);
+ break;
+ case InterpolationMode::Linear:
+ AudioInterp::Linear(state.interp_state, state.current_buffer, state.rate_multiplier,
+ current_frame, frame_position);
+ break;
+ case InterpolationMode::Polyphase:
+ // TODO(merry): Implement polyphase interpolation
+ LOG_DEBUG(Audio_DSP, "Polyphase interpolation unimplemented; falling back to linear");
+ AudioInterp::Linear(state.interp_state, state.current_buffer, state.rate_multiplier,
+ current_frame, frame_position);
+ break;
+ default:
+ UNIMPLEMENTED();
+ break;
+ }
}
+ state.next_sample_number += frame_position;
state.filters.ProcessFrame(current_frame);
}
@@ -305,25 +315,6 @@ bool Source::DequeueBuffer() {
return true;
}
- switch (state.interpolation_mode) {
- case InterpolationMode::None:
- state.current_buffer =
- AudioInterp::None(state.interp_state, state.current_buffer, state.rate_multiplier);
- break;
- case InterpolationMode::Linear:
- state.current_buffer =
- AudioInterp::Linear(state.interp_state, state.current_buffer, state.rate_multiplier);
- break;
- case InterpolationMode::Polyphase:
- // TODO(merry): Implement polyphase interpolation
- state.current_buffer =
- AudioInterp::Linear(state.interp_state, state.current_buffer, state.rate_multiplier);
- break;
- default:
- UNIMPLEMENTED();
- break;
- }
-
// the first playthrough starts at play_position, loops start at the beginning of the buffer
state.current_sample_number = (!buf.has_played) ? buf.play_position : 0;
state.next_sample_number = state.current_sample_number;
diff --git a/src/audio_core/interpolate.cpp b/src/audio_core/interpolate.cpp
index 8a5d4181a..16e68bc5c 100644
--- a/src/audio_core/interpolate.cpp
+++ b/src/audio_core/interpolate.cpp
@@ -13,74 +13,64 @@ namespace AudioInterp {
constexpr u64 scale_factor = 1 << 24;
constexpr u64 scale_mask = scale_factor - 1;
-/// Here we step over the input in steps of rate_multiplier, until we consume all of the input.
+/// Here we step over the input in steps of rate, until we consume all of the input.
/// Three adjacent samples are passed to fn each step.
template <typename Function>
-static StereoBuffer16 StepOverSamples(State& state, const StereoBuffer16& input,
- float rate_multiplier, Function fn) {
- ASSERT(rate_multiplier > 0);
+static void StepOverSamples(State& state, StereoBuffer16& input, float rate,
+ DSP::HLE::StereoFrame16& output, size_t& outputi, Function fn) {
+ ASSERT(rate > 0);
- if (input.size() < 2)
- return {};
+ if (input.empty())
+ return;
- StereoBuffer16 output;
- output.reserve(static_cast<size_t>(input.size() / rate_multiplier));
+ input.insert(input.begin(), {state.xn2, state.xn1});
- u64 step_size = static_cast<u64>(rate_multiplier * scale_factor);
+ const u64 step_size = static_cast<u64>(rate * scale_factor);
+ u64 fposition = state.fposition;
+ size_t inputi = 0;
- u64 fposition = 0;
- const u64 max_fposition = input.size() * scale_factor;
+ while (outputi < output.size()) {
+ inputi = static_cast<size_t>(fposition / scale_factor);
- while (fposition < 1 * scale_factor) {
- u64 fraction = fposition & scale_mask;
-
- output.push_back(fn(fraction, state.xn2, state.xn1, input[0]));
-
- fposition += step_size;
- }
-
- while (fposition < 2 * scale_factor) {
- u64 fraction = fposition & scale_mask;
-
- output.push_back(fn(fraction, state.xn1, input[0], input[1]));
-
- fposition += step_size;
- }
+ if (inputi + 2 >= input.size()) {
+ inputi = input.size() - 2;
+ break;
+ }
- while (fposition < max_fposition) {
u64 fraction = fposition & scale_mask;
-
- size_t index = static_cast<size_t>(fposition / scale_factor);
- output.push_back(fn(fraction, input[index - 2], input[index - 1], input[index]));
+ output[outputi++] = fn(fraction, input[inputi], input[inputi + 1], input[inputi + 2]);
fposition += step_size;
}
- state.xn2 = input[input.size() - 2];
- state.xn1 = input[input.size() - 1];
+ state.xn2 = input[inputi];
+ state.xn1 = input[inputi + 1];
+ state.fposition = fposition - inputi * scale_factor;
- return output;
+ input.erase(input.begin(), input.begin() + inputi + 2);
}
-StereoBuffer16 None(State& state, const StereoBuffer16& input, float rate_multiplier) {
- return StepOverSamples(
- state, input, rate_multiplier,
+void None(State& state, StereoBuffer16& input, float rate, DSP::HLE::StereoFrame16& output,
+ size_t& outputi) {
+ StepOverSamples(
+ state, input, rate, output, outputi,
[](u64 fraction, const auto& x0, const auto& x1, const auto& x2) { return x0; });
}
-StereoBuffer16 Linear(State& state, const StereoBuffer16& input, float rate_multiplier) {
+void Linear(State& state, StereoBuffer16& input, float rate, DSP::HLE::StereoFrame16& output,
+ size_t& outputi) {
// Note on accuracy: Some values that this produces are +/- 1 from the actual firmware.
- return StepOverSamples(state, input, rate_multiplier,
- [](u64 fraction, const auto& x0, const auto& x1, const auto& x2) {
- // This is a saturated subtraction. (Verified by black-box fuzzing.)
- s64 delta0 = MathUtil::Clamp<s64>(x1[0] - x0[0], -32768, 32767);
- s64 delta1 = MathUtil::Clamp<s64>(x1[1] - x0[1], -32768, 32767);
-
- return std::array<s16, 2>{
- static_cast<s16>(x0[0] + fraction * delta0 / scale_factor),
- static_cast<s16>(x0[1] + fraction * delta1 / scale_factor),
- };
- });
+ StepOverSamples(state, input, rate, output, outputi,
+ [](u64 fraction, const auto& x0, const auto& x1, const auto& x2) {
+ // This is a saturated subtraction. (Verified by black-box fuzzing.)
+ s64 delta0 = MathUtil::Clamp<s64>(x1[0] - x0[0], -32768, 32767);
+ s64 delta1 = MathUtil::Clamp<s64>(x1[1] - x0[1], -32768, 32767);
+
+ return std::array<s16, 2>{
+ static_cast<s16>(x0[0] + fraction * delta0 / scale_factor),
+ static_cast<s16>(x0[1] + fraction * delta1 / scale_factor),
+ };
+ });
}
} // namespace AudioInterp
diff --git a/src/audio_core/interpolate.h b/src/audio_core/interpolate.h
index 19a7b66cb..59f59bc14 100644
--- a/src/audio_core/interpolate.h
+++ b/src/audio_core/interpolate.h
@@ -6,6 +6,7 @@
#include <array>
#include <vector>
+#include "audio_core/hle/common.h"
#include "common/common_types.h"
namespace AudioInterp {
@@ -14,31 +15,35 @@ namespace AudioInterp {
using StereoBuffer16 = std::vector<std::array<s16, 2>>;
struct State {
- // Two historical samples.
+ /// Two historical samples.
std::array<s16, 2> xn1 = {}; ///< x[n-1]
std::array<s16, 2> xn2 = {}; ///< x[n-2]
+ /// Current fractional position.
+ u64 fposition = 0;
};
/**
* No interpolation. This is equivalent to a zero-order hold. There is a two-sample predelay.
* @param state Interpolation state.
* @param input Input buffer.
- * @param rate_multiplier Stretch factor. Must be a positive non-zero value.
- * rate_multiplier > 1.0 performs decimation and rate_multipler < 1.0
- * performs upsampling.
- * @return The resampled audio buffer.
+ * @param rate Stretch factor. Must be a positive non-zero value.
+ * rate > 1.0 performs decimation and rate < 1.0 performs upsampling.
+ * @param output The resampled audio buffer.
+ * @param outputi The index of output to start writing to.
*/
-StereoBuffer16 None(State& state, const StereoBuffer16& input, float rate_multiplier);
+void None(State& state, StereoBuffer16& input, float rate, DSP::HLE::StereoFrame16& output,
+ size_t& outputi);
/**
* Linear interpolation. This is equivalent to a first-order hold. There is a two-sample predelay.
* @param state Interpolation state.
* @param input Input buffer.
- * @param rate_multiplier Stretch factor. Must be a positive non-zero value.
- * rate_multiplier > 1.0 performs decimation and rate_multipler < 1.0
- * performs upsampling.
- * @return The resampled audio buffer.
+ * @param rate Stretch factor. Must be a positive non-zero value.
+ * rate > 1.0 performs decimation and rate < 1.0 performs upsampling.
+ * @param output The resampled audio buffer.
+ * @param outputi The index of output to start writing to.
*/
-StereoBuffer16 Linear(State& state, const StereoBuffer16& input, float rate_multiplier);
+void Linear(State& state, StereoBuffer16& input, float rate, DSP::HLE::StereoFrame16& output,
+ size_t& outputi);
} // namespace AudioInterp
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index 14574e56c..e524c5535 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -165,6 +165,8 @@ int main(int argc, char** argv) {
break; // Expected case
}
+ Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "SDL");
+
while (emu_window->IsOpen()) {
system.RunLoop();
}
diff --git a/src/citra/citra.rc b/src/citra/citra.rc
index fea603004..c490ef302 100644
--- a/src/citra/citra.rc
+++ b/src/citra/citra.rc
@@ -1,3 +1,4 @@
+#include "winresrc.h"
/////////////////////////////////////////////////////////////////////////////
//
// Icon
@@ -7,3 +8,10 @@
// remains consistent on all systems.
CITRA_ICON ICON "../../dist/citra.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// RT_MANIFEST
+//
+
+1 RT_MANIFEST "../../dist/citra.manifest"
diff --git a/src/citra/config.cpp b/src/citra/config.cpp
index 69247b166..a48ef08c7 100644
--- a/src/citra/config.cpp
+++ b/src/citra/config.cpp
@@ -76,6 +76,11 @@ void Config::ReadValues() {
Settings::values.analogs[i] = default_param;
}
+ Settings::values.motion_device = sdl2_config->Get(
+ "Controls", "motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01");
+ Settings::values.touch_device =
+ sdl2_config->Get("Controls", "touch_device", "engine:emu_window");
+
// Core
Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true);
@@ -153,8 +158,12 @@ void Config::ReadValues() {
static_cast<u16>(sdl2_config->GetInteger("Debugging", "gdbstub_port", 24689));
// Web Service
+ Settings::values.enable_telemetry =
+ sdl2_config->GetBoolean("WebService", "enable_telemetry", true);
Settings::values.telemetry_endpoint_url = sdl2_config->Get(
"WebService", "telemetry_endpoint_url", "https://services.citra-emu.org/api/telemetry");
+ Settings::values.citra_username = sdl2_config->Get("WebService", "citra_username", "");
+ Settings::values.citra_token = sdl2_config->Get("WebService", "citra_token", "");
}
void Config::Reload() {
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h
index a12498e0f..4b13a2e1b 100644
--- a/src/citra/default_ini.h
+++ b/src/citra/default_ini.h
@@ -12,7 +12,7 @@ const char* sdl2_config_file = R"(
# It should be in the format of "engine:[engine_name],[param1]:[value1],[param2]:[value2]..."
# Escape characters $0 (for ':'), $1 (for ',') and $2 (for '$') can be used in values
-# for button input, the following devices are avaible:
+# for button input, the following devices are available:
# - "keyboard" (default) for keyboard input. Required parameters:
# - "code": the code of the key to bind
# - "sdl" for joystick input using SDL. Required parameters:
@@ -21,7 +21,7 @@ const char* sdl2_config_file = R"(
# - "hat"(optional): the index of the hat to bind as direction buttons
# - "axis"(optional): the index of the axis to bind
# - "direction"(only used for hat): the direction name of the hat to bind. Can be "up", "down", "left" or "right"
-# - "threshould"(only used for axis): a float value in (-1.0, 1.0) which the button is
+# - "threshold"(only used for axis): a float value in (-1.0, 1.0) which the button is
# triggered if the axis value crosses
# - "direction"(only used for axis): "+" means the button is triggered when the axis value
# is greater than the threshold; "-" means the button is triggered when the axis value
@@ -42,8 +42,8 @@ button_zl=
button_zr=
button_home=
-# for analog input, the following devices are avaible:
-# - "analog_from_button" (default) for emulating analog input from direction buttons. Required parameters:
+# for analog input, the following devices are available:
+# - "analog_from_button" (default) for emulating analog input from direction buttons. Required parameters:
# - "up", "down", "left", "right": sub-devices for each direction.
# Should be in the format as a button input devices using escape characters, for example, "engine$0keyboard$1code$00"
# - "modifier": sub-devices as a modifier.
@@ -56,6 +56,16 @@ button_home=
circle_pad=
c_stick=
+# for motion input, the following devices are available:
+# - "motion_emu" (default) for emulating motion input from mouse input. Required parameters:
+# - "update_period": update period in milliseconds (default to 100)
+# - "sensitivity": the coefficient converting mouse movement to tilting angle (default to 0.01)
+motion_device=
+
+# for touch input, the following devices are available:
+# - "emu_window" (default) for emulating touch input from mouse input to the emulation window. No parameters required
+touch_device=
+
[Core]
# Whether to use the Just-In-Time (JIT) compiler for CPU emulation
# 0: Interpreter (slow), 1 (default): JIT (fast)
@@ -170,7 +180,14 @@ use_gdbstub=false
gdbstub_port=24689
[WebService]
+# Whether or not to enable telemetry
+# 0: No, 1 (default): Yes
+enable_telemetry =
# Endpoint URL for submitting telemetry data
-telemetry_endpoint_url =
+telemetry_endpoint_url = https://services.citra-emu.org/api/telemetry
+# Username and token for Citra Web Service
+# See https://services.citra-emu.org/ for more info
+citra_username =
+citra_token =
)";
}
diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp
index b0f808399..25643715a 100644
--- a/src/citra/emu_window/emu_window_sdl2.cpp
+++ b/src/citra/emu_window/emu_window_sdl2.cpp
@@ -16,11 +16,12 @@
#include "core/settings.h"
#include "input_common/keyboard.h"
#include "input_common/main.h"
+#include "input_common/motion_emu.h"
#include "network/network.h"
void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
- motion_emu->Tilt(x, y);
+ InputCommon::GetMotionEmu()->Tilt(x, y);
}
void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
@@ -32,9 +33,9 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
}
} else if (button == SDL_BUTTON_RIGHT) {
if (state == SDL_PRESSED) {
- motion_emu->BeginTilt(x, y);
+ InputCommon::GetMotionEmu()->BeginTilt(x, y);
} else {
- motion_emu->EndTilt();
+ InputCommon::GetMotionEmu()->EndTilt();
}
}
}
@@ -61,8 +62,6 @@ EmuWindow_SDL2::EmuWindow_SDL2() {
InputCommon::Init();
Network::Init();
- motion_emu = std::make_unique<Motion::MotionEmu>(*this);
-
SDL_SetMainReady();
// Initialize the window
@@ -117,7 +116,6 @@ EmuWindow_SDL2::EmuWindow_SDL2() {
EmuWindow_SDL2::~EmuWindow_SDL2() {
SDL_GL_DeleteContext(gl_context);
SDL_Quit();
- motion_emu = nullptr;
Network::Shutdown();
InputCommon::Shutdown();
diff --git a/src/citra/emu_window/emu_window_sdl2.h b/src/citra/emu_window/emu_window_sdl2.h
index 1ce2991f7..3664d2fbe 100644
--- a/src/citra/emu_window/emu_window_sdl2.h
+++ b/src/citra/emu_window/emu_window_sdl2.h
@@ -7,7 +7,6 @@
#include <memory>
#include <utility>
#include "core/frontend/emu_window.h"
-#include "core/frontend/motion_emu.h"
struct SDL_Window;
@@ -57,7 +56,4 @@ private:
using SDL_GLContext = void*;
/// The OpenGL context associated with the window
SDL_GLContext gl_context;
-
- /// Motion sensors emulation
- std::unique_ptr<Motion::MotionEmu> motion_emu;
};
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index f364b2284..e0a19fd9e 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -12,6 +12,7 @@ set(SRCS
configuration/configure_graphics.cpp
configuration/configure_input.cpp
configuration/configure_system.cpp
+ configuration/configure_web.cpp
debugger/graphics/graphics.cpp
debugger/graphics/graphics_breakpoint_observer.cpp
debugger/graphics/graphics_breakpoints.cpp
@@ -42,6 +43,7 @@ set(HEADERS
configuration/configure_graphics.h
configuration/configure_input.h
configuration/configure_system.h
+ configuration/configure_web.h
debugger/graphics/graphics.h
debugger/graphics/graphics_breakpoint_observer.h
debugger/graphics/graphics_breakpoints.h
@@ -71,6 +73,7 @@ set(UIS
configuration/configure_graphics.ui
configuration/configure_input.ui
configuration/configure_system.ui
+ configuration/configure_web.ui
debugger/registers.ui
hotkeys.ui
main.ui
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index 30554890f..7107bfc60 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -17,6 +17,7 @@
#include "core/settings.h"
#include "input_common/keyboard.h"
#include "input_common/main.h"
+#include "input_common/motion_emu.h"
#include "network/network.h"
EmuThread::EmuThread(GRenderWindow* render_window)
@@ -201,7 +202,6 @@ qreal GRenderWindow::windowPixelRatio() {
}
void GRenderWindow::closeEvent(QCloseEvent* event) {
- motion_emu = nullptr;
emit Closed();
QWidget::closeEvent(event);
}
@@ -221,7 +221,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {
this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio),
static_cast<unsigned>(pos.y() * pixelRatio));
} else if (event->button() == Qt::RightButton) {
- motion_emu->BeginTilt(pos.x(), pos.y());
+ InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y());
}
}
@@ -230,14 +230,14 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
qreal pixelRatio = windowPixelRatio();
this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u),
std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u));
- motion_emu->Tilt(pos.x(), pos.y());
+ InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y());
}
void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton)
this->TouchReleased();
else if (event->button() == Qt::RightButton)
- motion_emu->EndTilt();
+ InputCommon::GetMotionEmu()->EndTilt();
}
void GRenderWindow::focusOutEvent(QFocusEvent* event) {
@@ -290,13 +290,11 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(
}
void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) {
- motion_emu = std::make_unique<Motion::MotionEmu>(*this);
this->emu_thread = emu_thread;
child->DisablePainting();
}
void GRenderWindow::OnEmulationStopping() {
- motion_emu = nullptr;
emu_thread = nullptr;
child->EnablePainting();
}
diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h
index 4b3a3b3cc..6974edcbb 100644
--- a/src/citra_qt/bootmanager.h
+++ b/src/citra_qt/bootmanager.h
@@ -12,7 +12,6 @@
#include "common/thread.h"
#include "core/core.h"
#include "core/frontend/emu_window.h"
-#include "core/frontend/motion_emu.h"
class QKeyEvent;
class QScreen;
@@ -158,9 +157,6 @@ private:
EmuThread* emu_thread;
- /// Motion sensors emulation
- std::unique_ptr<Motion::MotionEmu> motion_emu;
-
protected:
void showEvent(QShowEvent* event) override;
};
diff --git a/src/citra_qt/citra-qt.rc b/src/citra_qt/citra-qt.rc
index fea603004..a48a9440d 100644
--- a/src/citra_qt/citra-qt.rc
+++ b/src/citra_qt/citra-qt.rc
@@ -1,3 +1,4 @@
+#include "winresrc.h"
/////////////////////////////////////////////////////////////////////////////
//
// Icon
@@ -5,5 +6,14 @@
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
-CITRA_ICON ICON "../../dist/citra.ico"
+// QT requires that the default application icon is named IDI_ICON1
+IDI_ICON1 ICON "../../dist/citra.ico"
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// RT_MANIFEST
+//
+
+1 RT_MANIFEST "../../dist/citra.manifest"
diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp
index 75abb4ce6..ef114aad3 100644
--- a/src/citra_qt/configuration/config.cpp
+++ b/src/citra_qt/configuration/config.cpp
@@ -57,6 +57,13 @@ void Config::ReadValues() {
Settings::values.analogs[i] = default_param;
}
+ Settings::values.motion_device =
+ qt_config->value("motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01")
+ .toString()
+ .toStdString();
+ Settings::values.touch_device =
+ qt_config->value("touch_device", "engine:emu_window").toString().toStdString();
+
qt_config->endGroup();
qt_config->beginGroup("Core");
@@ -134,10 +141,13 @@ void Config::ReadValues() {
qt_config->endGroup();
qt_config->beginGroup("WebService");
+ Settings::values.enable_telemetry = qt_config->value("enable_telemetry", true).toBool();
Settings::values.telemetry_endpoint_url =
qt_config->value("telemetry_endpoint_url", "https://services.citra-emu.org/api/telemetry")
.toString()
.toStdString();
+ Settings::values.citra_username = qt_config->value("citra_username").toString().toStdString();
+ Settings::values.citra_token = qt_config->value("citra_token").toString().toStdString();
qt_config->endGroup();
qt_config->beginGroup("UI");
@@ -189,6 +199,7 @@ void Config::ReadValues() {
UISettings::values.show_status_bar = qt_config->value("showStatusBar", true).toBool();
UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool();
UISettings::values.first_start = qt_config->value("firstStart", true).toBool();
+ UISettings::values.callout_flags = qt_config->value("calloutFlags", 0).toUInt();
qt_config->endGroup();
}
@@ -203,6 +214,8 @@ void Config::SaveValues() {
qt_config->setValue(QString::fromStdString(Settings::NativeAnalog::mapping[i]),
QString::fromStdString(Settings::values.analogs[i]));
}
+ qt_config->setValue("motion_device", QString::fromStdString(Settings::values.motion_device));
+ qt_config->setValue("touch_device", QString::fromStdString(Settings::values.touch_device));
qt_config->endGroup();
qt_config->beginGroup("Core");
@@ -277,8 +290,11 @@ void Config::SaveValues() {
qt_config->endGroup();
qt_config->beginGroup("WebService");
+ qt_config->setValue("enable_telemetry", Settings::values.enable_telemetry);
qt_config->setValue("telemetry_endpoint_url",
QString::fromStdString(Settings::values.telemetry_endpoint_url));
+ qt_config->setValue("citra_username", QString::fromStdString(Settings::values.citra_username));
+ qt_config->setValue("citra_token", QString::fromStdString(Settings::values.citra_token));
qt_config->endGroup();
qt_config->beginGroup("UI");
@@ -314,6 +330,7 @@ void Config::SaveValues() {
qt_config->setValue("showStatusBar", UISettings::values.show_status_bar);
qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing);
qt_config->setValue("firstStart", UISettings::values.first_start);
+ qt_config->setValue("calloutFlags", UISettings::values.callout_flags);
qt_config->endGroup();
}
diff --git a/src/citra_qt/configuration/configure.ui b/src/citra_qt/configuration/configure.ui
index 85e206e42..6abd1917e 100644
--- a/src/citra_qt/configuration/configure.ui
+++ b/src/citra_qt/configuration/configure.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>441</width>
- <height>501</height>
+ <width>740</width>
+ <height>500</height>
</rect>
</property>
<property name="windowTitle">
@@ -49,6 +49,11 @@
<string>Debug</string>
</attribute>
</widget>
+ <widget class="ConfigureWeb" name="webTab">
+ <attribute name="title">
+ <string>Web</string>
+ </attribute>
+ </widget>
</widget>
</item>
<item>
@@ -97,6 +102,12 @@
<header>configuration/configure_graphics.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>ConfigureWeb</class>
+ <extends>QWidget</extends>
+ <header>configuration/configure_web.h</header>
+ <container>1</container>
+ </customwidget>
</customwidgets>
<resources/>
<connections>
diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp
index dfc8c03a7..b87dc0e6c 100644
--- a/src/citra_qt/configuration/configure_dialog.cpp
+++ b/src/citra_qt/configuration/configure_dialog.cpp
@@ -23,5 +23,6 @@ void ConfigureDialog::applyConfiguration() {
ui->graphicsTab->applyConfiguration();
ui->audioTab->applyConfiguration();
ui->debugTab->applyConfiguration();
+ ui->webTab->applyConfiguration();
Settings::Apply();
}
diff --git a/src/citra_qt/configuration/configure_graphics.ui b/src/citra_qt/configuration/configure_graphics.ui
index 228f2a869..b340149d5 100644
--- a/src/citra_qt/configuration/configure_graphics.ui
+++ b/src/citra_qt/configuration/configure_graphics.ui
@@ -146,17 +146,22 @@
<widget class="QComboBox" name="layout_combobox">
<item>
<property name="text">
- <string notr="true">Default</string>
+ <string>Default</string>
</property>
</item>
<item>
<property name="text">
- <string notr="true">Single Screen</string>
+ <string>Single Screen</string>
</property>
</item>
<item>
<property name="text">
- <string notr="true">Large Screen</string>
+ <string>Large Screen</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Side by Side</string>
</property>
</item>
</widget>
diff --git a/src/citra_qt/configuration/configure_web.cpp b/src/citra_qt/configuration/configure_web.cpp
new file mode 100644
index 000000000..8715fb018
--- /dev/null
+++ b/src/citra_qt/configuration/configure_web.cpp
@@ -0,0 +1,52 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "citra_qt/configuration/configure_web.h"
+#include "core/settings.h"
+#include "core/telemetry_session.h"
+#include "ui_configure_web.h"
+
+ConfigureWeb::ConfigureWeb(QWidget* parent)
+ : QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) {
+ ui->setupUi(this);
+ connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this,
+ &ConfigureWeb::refreshTelemetryID);
+
+ this->setConfiguration();
+}
+
+ConfigureWeb::~ConfigureWeb() {}
+
+void ConfigureWeb::setConfiguration() {
+ ui->web_credentials_disclaimer->setWordWrap(true);
+ ui->telemetry_learn_more->setOpenExternalLinks(true);
+ ui->telemetry_learn_more->setText("<a "
+ "href='https://citra-emu.org/entry/"
+ "telemetry-and-why-thats-a-good-thing/'>Learn more</a>");
+
+ ui->web_signup_link->setOpenExternalLinks(true);
+ ui->web_signup_link->setText("<a href='https://services.citra-emu.org/'>Sign up</a>");
+ ui->web_token_info_link->setOpenExternalLinks(true);
+ ui->web_token_info_link->setText(
+ "<a href='https://citra-emu.org/wiki/citra-web-service/'>What is my token?</a>");
+
+ ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry);
+ ui->edit_username->setText(QString::fromStdString(Settings::values.citra_username));
+ ui->edit_token->setText(QString::fromStdString(Settings::values.citra_token));
+ ui->label_telemetry_id->setText("Telemetry ID: 0x" +
+ QString::number(Core::GetTelemetryId(), 16).toUpper());
+}
+
+void ConfigureWeb::applyConfiguration() {
+ Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked();
+ Settings::values.citra_username = ui->edit_username->text().toStdString();
+ Settings::values.citra_token = ui->edit_token->text().toStdString();
+ Settings::Apply();
+}
+
+void ConfigureWeb::refreshTelemetryID() {
+ const u64 new_telemetry_id{Core::RegenerateTelemetryId()};
+ ui->label_telemetry_id->setText("Telemetry ID: 0x" +
+ QString::number(new_telemetry_id, 16).toUpper());
+}
diff --git a/src/citra_qt/configuration/configure_web.h b/src/citra_qt/configuration/configure_web.h
new file mode 100644
index 000000000..20bc254b9
--- /dev/null
+++ b/src/citra_qt/configuration/configure_web.h
@@ -0,0 +1,30 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <QWidget>
+
+namespace Ui {
+class ConfigureWeb;
+}
+
+class ConfigureWeb : public QWidget {
+ Q_OBJECT
+
+public:
+ explicit ConfigureWeb(QWidget* parent = nullptr);
+ ~ConfigureWeb();
+
+ void applyConfiguration();
+
+public slots:
+ void refreshTelemetryID();
+
+private:
+ void setConfiguration();
+
+ std::unique_ptr<Ui::ConfigureWeb> ui;
+};
diff --git a/src/citra_qt/configuration/configure_web.ui b/src/citra_qt/configuration/configure_web.ui
new file mode 100644
index 000000000..d8d283fad
--- /dev/null
+++ b/src/citra_qt/configuration/configure_web.ui
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ConfigureWeb</class>
+ <widget class="QWidget" name="ConfigureWeb">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QGroupBox" name="groupBoxWebConfig">
+ <property name="title">
+ <string>Citra Web Service</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayoutCitraWebService">
+ <item>
+ <widget class="QLabel" name="web_credentials_disclaimer">
+ <property name="text">
+ <string>By providing your username and token, you agree to allow Citra to collect additional usage data, which may include user identifying information.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="gridLayoutCitraUsername">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_username">
+ <property name="text">
+ <string>Username: </string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="edit_username">
+ <property name="maxLength">
+ <number>36</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_token">
+ <property name="text">
+ <string>Token: </string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="edit_token">
+ <property name="maxLength">
+ <number>36</number>
+ </property>
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="web_signup_link">
+ <property name="text">
+ <string>Sign up</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLabel" name="web_token_info_link">
+ <property name="text">
+ <string>What is my token?</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Telemetry</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="toggle_telemetry">
+ <property name="text">
+ <string>Share anonymous usage data with the Citra team</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="telemetry_learn_more">
+ <property name="text">
+ <string>Learn more</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="gridLayoutTelemetryId">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_telemetry_id">
+ <property name="text">
+ <string>Telemetry ID:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="button_regenerate_telemetry_id">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>Regenerate</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index c1ae0ccc8..8adbcfe86 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -48,6 +48,47 @@
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
#endif
+/**
+ * "Callouts" are one-time instructional messages shown to the user. In the config settings, there
+ * is a bitfield "callout_flags" options, used to track if a message has already been shown to the
+ * user. This is 32-bits - if we have more than 32 callouts, we should retire and recyle old ones.
+ */
+enum class CalloutFlag : uint32_t {
+ Telemetry = 0x1,
+};
+
+static void ShowCalloutMessage(const QString& message, CalloutFlag flag) {
+ if (UISettings::values.callout_flags & static_cast<uint32_t>(flag)) {
+ return;
+ }
+
+ UISettings::values.callout_flags |= static_cast<uint32_t>(flag);
+
+ QMessageBox msg;
+ msg.setText(message);
+ msg.setStandardButtons(QMessageBox::Ok);
+ msg.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ msg.setStyleSheet("QLabel{min-width: 900px;}");
+ msg.exec();
+}
+
+void GMainWindow::ShowCallouts() {
+ static const QString telemetry_message =
+ tr("To help improve Citra, the Citra Team collects anonymous usage data. No private or "
+ "personally identifying information is collected. This data helps us to understand how "
+ "people use Citra and prioritize our efforts. Furthermore, it helps us to more easily "
+ "identify emulation bugs and performance issues. This data includes:<ul><li>Information"
+ " about the version of Citra you are using</li><li>Performance data about the games you "
+ "play</li><li>Your configuration settings</li><li>Information about your computer "
+ "hardware</li><li>Emulation errors and crash information</li></ul>By default, this "
+ "feature is enabled. To disable this feature, click 'Emulation' from the menu and then "
+ "select 'Configure...'. Then, on the 'Web' tab, uncheck 'Share anonymous usage data with"
+ " the Citra team'. <br/><br/>By using this software, you agree to the above terms.<br/>"
+ "<br/><a href='https://citra-emu.org/entry/telemetry-and-why-thats-a-good-thing/'>Learn "
+ "more</a>");
+ ShowCalloutMessage(telemetry_message, CalloutFlag::Telemetry);
+}
+
GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
Pica::g_debug_context = Pica::DebugContext::Construct();
setAcceptDrops(true);
@@ -73,6 +114,9 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
UpdateUITheme();
+ // Show one-time "callout" messages to the user
+ ShowCallouts();
+
QStringList args = QApplication::arguments();
if (args.length() >= 2) {
BootGame(args[1]);
@@ -320,6 +364,8 @@ bool GMainWindow::LoadROM(const QString& filename) {
const Core::System::ResultStatus result{system.Load(render_window, filename.toStdString())};
+ Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "Qt");
+
if (result != Core::System::ResultStatus::Success) {
switch (result) {
case Core::System::ResultStatus::ErrorGetLoader:
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h
index 360de2ced..d59a6d67d 100644
--- a/src/citra_qt/main.h
+++ b/src/citra_qt/main.h
@@ -80,6 +80,8 @@ private:
void BootGame(const QString& filename);
void ShutdownGame();
+ void ShowCallouts();
+
/**
* Stores the filename in the recently loaded files list.
* The new filename is stored at the beginning of the recently loaded files list.
diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h
index 025c73f84..d85c92765 100644
--- a/src/citra_qt/ui_settings.h
+++ b/src/citra_qt/ui_settings.h
@@ -48,6 +48,8 @@ struct Values {
// Shortcut name <Shortcut, context>
std::vector<Shortcut> shortcuts;
+
+ uint32_t callout_flags;
};
extern Values values;
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 360f407f3..78dec8600 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -33,7 +33,6 @@ set(SRCS
frontend/camera/interface.cpp
frontend/emu_window.cpp
frontend/framebuffer_layout.cpp
- frontend/motion_emu.cpp
gdbstub/gdbstub.cpp
hle/config_mem.cpp
hle/applets/applet.cpp
@@ -60,6 +59,7 @@ set(SRCS
hle/kernel/timer.cpp
hle/kernel/vm_manager.cpp
hle/kernel/wait_object.cpp
+ hle/lock.cpp
hle/romfs.cpp
hle/service/ac/ac.cpp
hle/service/ac/ac_i.cpp
@@ -145,6 +145,7 @@ set(SRCS
hle/service/nwm/nwm_tst.cpp
hle/service/nwm/nwm_uds.cpp
hle/service/nwm/uds_beacon.cpp
+ hle/service/nwm/uds_connection.cpp
hle/service/nwm/uds_data.cpp
hle/service/pm_app.cpp
hle/service/ptm/ptm.cpp
@@ -226,7 +227,6 @@ set(HEADERS
frontend/emu_window.h
frontend/framebuffer_layout.h
frontend/input.h
- frontend/motion_emu.h
gdbstub/gdbstub.h
hle/config_mem.h
hle/function_wrappers.h
@@ -258,6 +258,7 @@ set(HEADERS
hle/kernel/timer.h
hle/kernel/vm_manager.h
hle/kernel/wait_object.h
+ hle/lock.h
hle/result.h
hle/romfs.h
hle/service/ac/ac.h
@@ -344,6 +345,7 @@ set(HEADERS
hle/service/nwm/nwm_tst.h
hle/service/nwm/nwm_uds.h
hle/service/nwm/uds_beacon.h
+ hle/service/nwm/uds_connection.h
hle/service/nwm/uds_data.h
hle/service/pm_app.h
hle/service/ptm/ptm.h
@@ -388,7 +390,7 @@ set(HEADERS
create_directory_groups(${SRCS} ${HEADERS})
add_library(core STATIC ${SRCS} ${HEADERS})
-target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
+target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core)
target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp dynarmic fmt)
if (ENABLE_WEB_SERVICE)
target_link_libraries(core PUBLIC json-headers web_service)
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp
index 7d2790b08..0a0b91590 100644
--- a/src/core/arm/dynarmic/arm_dynarmic.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic.cpp
@@ -136,7 +136,7 @@ MICROPROFILE_DEFINE(ARM_Jit, "ARM JIT", "ARM JIT", MP_RGB(255, 64, 64));
void ARM_Dynarmic::ExecuteInstructions(int num_instructions) {
MICROPROFILE_SCOPE(ARM_Jit);
- unsigned ticks_executed = jit->Run(static_cast<unsigned>(num_instructions));
+ std::size_t ticks_executed = jit->Run(static_cast<unsigned>(num_instructions));
AddTicks(ticks_executed);
}
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index f4fbb8d04..3522d1e82 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -759,7 +759,7 @@ static ThumbDecodeStatus DecodeThumbInstruction(u32 inst, u32 addr, u32* arm_ins
ThumbDecodeStatus ret = TranslateThumbInstruction(addr, inst, arm_inst, inst_size);
if (ret == ThumbDecodeStatus::BRANCH) {
int inst_index;
- int table_length = arm_instruction_trans_len;
+ int table_length = static_cast<int>(arm_instruction_trans_len);
u32 tinstr = GetThumbInstruction(inst, addr);
switch ((tinstr & 0xF800) >> 11) {
@@ -838,7 +838,7 @@ static unsigned int InterpreterTranslateInstruction(const ARMul_State* cpu, cons
return inst_size;
}
-static int InterpreterTranslateBlock(ARMul_State* cpu, int& bb_start, u32 addr) {
+static int InterpreterTranslateBlock(ARMul_State* cpu, std::size_t& bb_start, u32 addr) {
MICROPROFILE_SCOPE(DynCom_Decode);
// Decode instruction, get index
@@ -871,7 +871,7 @@ static int InterpreterTranslateBlock(ARMul_State* cpu, int& bb_start, u32 addr)
return KEEP_GOING;
}
-static int InterpreterTranslateSingle(ARMul_State* cpu, int& bb_start, u32 addr) {
+static int InterpreterTranslateSingle(ARMul_State* cpu, std::size_t& bb_start, u32 addr) {
MICROPROFILE_SCOPE(DynCom_Decode);
ARM_INST_PTR inst_base = nullptr;
@@ -1620,7 +1620,7 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) {
unsigned int addr;
unsigned int num_instrs = 0;
- int ptr;
+ std::size_t ptr;
LOAD_NZCVT;
DISPATCH : {
diff --git a/src/core/arm/skyeye_common/armstate.h b/src/core/arm/skyeye_common/armstate.h
index 1a707ff7e..893877797 100644
--- a/src/core/arm/skyeye_common/armstate.h
+++ b/src/core/arm/skyeye_common/armstate.h
@@ -230,7 +230,7 @@ public:
// TODO(bunnei): Move this cache to a better place - it should be per codeset (likely per
// process for our purposes), not per ARMul_State (which tracks CPU core state).
- std::unordered_map<u32, int> instruction_cache;
+ std::unordered_map<u32, std::size_t> instruction_cache;
private:
void ResetMPCoreCP15Registers();
diff --git a/src/core/core.cpp b/src/core/core.cpp
index d08f18623..5332318cf 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -19,6 +19,7 @@
#include "core/loader/loader.h"
#include "core/memory_setup.h"
#include "core/settings.h"
+#include "network/network.h"
#include "video_core/video_core.h"
namespace Core {
@@ -188,6 +189,10 @@ void System::Shutdown() {
cpu_core = nullptr;
app_loader = nullptr;
telemetry_session = nullptr;
+ if (auto room_member = Network::GetRoomMember().lock()) {
+ Network::GameInfo game_info{};
+ room_member->SendGameInfo(game_info);
+ }
LOG_DEBUG(Core, "Shutdown OK");
}
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp
index 1fae0ede0..87a240d7a 100644
--- a/src/core/file_sys/archive_backend.cpp
+++ b/src/core/file_sys/archive_backend.cpp
@@ -90,6 +90,8 @@ std::u16string Path::AsU16Str() const {
LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
return {};
}
+
+ UNREACHABLE();
}
std::vector<u8> Path::AsBinary() const {
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index 4f7d54a33..e67394177 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -2,14 +2,55 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include <algorithm>
#include <cmath>
-#include "common/assert.h"
-#include "core/3ds.h"
-#include "core/core.h"
+#include <mutex>
#include "core/frontend/emu_window.h"
+#include "core/frontend/input.h"
#include "core/settings.h"
+class EmuWindow::TouchState : public Input::Factory<Input::TouchDevice>,
+ public std::enable_shared_from_this<TouchState> {
+public:
+ std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage&) override {
+ return std::make_unique<Device>(shared_from_this());
+ }
+
+ std::mutex mutex;
+
+ bool touch_pressed = false; ///< True if touchpad area is currently pressed, otherwise false
+
+ float touch_x = 0.0f; ///< Touchpad X-position
+ float touch_y = 0.0f; ///< Touchpad Y-position
+
+private:
+ class Device : public Input::TouchDevice {
+ public:
+ explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {}
+ std::tuple<float, float, bool> GetStatus() const override {
+ if (auto state = touch_state.lock()) {
+ std::lock_guard<std::mutex> guard(state->mutex);
+ return std::make_tuple(state->touch_x, state->touch_y, state->touch_pressed);
+ }
+ return std::make_tuple(0.0f, 0.0f, false);
+ }
+
+ private:
+ std::weak_ptr<TouchState> touch_state;
+ };
+};
+
+EmuWindow::EmuWindow() {
+ // TODO: Find a better place to set this.
+ config.min_client_area_size = std::make_pair(400u, 480u);
+ active_config = config;
+ touch_state = std::make_shared<TouchState>();
+ Input::RegisterFactory<Input::TouchDevice>("emu_window", touch_state);
+}
+
+EmuWindow::~EmuWindow() {
+ Input::UnregisterFactory<Input::TouchDevice>("emu_window");
+}
+
/**
* Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout
* @param layout FramebufferLayout object describing the framebuffer size and screen positions
@@ -38,22 +79,26 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
return;
- touch_x = Core::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) /
- (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left);
- touch_y = Core::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) /
- (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
+ std::lock_guard<std::mutex> guard(touch_state->mutex);
+ touch_state->touch_x =
+ static_cast<float>(framebuffer_x - framebuffer_layout.bottom_screen.left) /
+ (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left);
+ touch_state->touch_y =
+ static_cast<float>(framebuffer_y - framebuffer_layout.bottom_screen.top) /
+ (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
- touch_pressed = true;
+ touch_state->touch_pressed = true;
}
void EmuWindow::TouchReleased() {
- touch_pressed = false;
- touch_x = 0;
- touch_y = 0;
+ std::lock_guard<std::mutex> guard(touch_state->mutex);
+ touch_state->touch_pressed = false;
+ touch_state->touch_x = 0;
+ touch_state->touch_y = 0;
}
void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
- if (!touch_pressed)
+ if (!touch_state->touch_pressed)
return;
if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
@@ -62,29 +107,6 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
TouchPressed(framebuffer_x, framebuffer_y);
}
-void EmuWindow::AccelerometerChanged(float x, float y, float z) {
- constexpr float coef = 512;
-
- std::lock_guard<std::mutex> lock(accel_mutex);
-
- // TODO(wwylele): do a time stretch as it in GyroscopeChanged
- // The time stretch formula should be like
- // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity
- accel_x = static_cast<s16>(x * coef);
- accel_y = static_cast<s16>(y * coef);
- accel_z = static_cast<s16>(z * coef);
-}
-
-void EmuWindow::GyroscopeChanged(float x, float y, float z) {
- constexpr float FULL_FPS = 60;
- float coef = GetGyroscopeRawToDpsCoefficient();
- float stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale();
- std::lock_guard<std::mutex> lock(gyro_mutex);
- gyro_x = static_cast<s16>(x * coef * stretch);
- gyro_y = static_cast<s16>(y * coef * stretch);
- gyro_z = static_cast<s16>(z * coef * stretch);
-}
-
void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) {
Layout::FramebufferLayout layout;
if (Settings::values.custom_layout == true) {
@@ -97,6 +119,9 @@ void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height)
case Settings::LayoutOption::LargeScreen:
layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen);
break;
+ case Settings::LayoutOption::SideScreen:
+ layout = Layout::SideFrameLayout(width, height, Settings::values.swap_screen);
+ break;
case Settings::LayoutOption::Default:
default:
layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen);
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h
index 9414123a4..c10dee51b 100644
--- a/src/core/frontend/emu_window.h
+++ b/src/core/frontend/emu_window.h
@@ -4,11 +4,10 @@
#pragma once
-#include <mutex>
+#include <memory>
#include <tuple>
#include <utility>
#include "common/common_types.h"
-#include "common/math_util.h"
#include "core/frontend/framebuffer_layout.h"
/**
@@ -69,84 +68,6 @@ public:
void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y);
/**
- * Signal accelerometer state has changed.
- * @param x X-axis accelerometer value
- * @param y Y-axis accelerometer value
- * @param z Z-axis accelerometer value
- * @note all values are in unit of g (gravitational acceleration).
- * e.g. x = 1.0 means 9.8m/s^2 in x direction.
- * @see GetAccelerometerState for axis explanation.
- */
- void AccelerometerChanged(float x, float y, float z);
-
- /**
- * Signal gyroscope state has changed.
- * @param x X-axis accelerometer value
- * @param y Y-axis accelerometer value
- * @param z Z-axis accelerometer value
- * @note all values are in deg/sec.
- * @see GetGyroscopeState for axis explanation.
- */
- void GyroscopeChanged(float x, float y, float z);
-
- /**
- * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed).
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @todo Fix this function to be thread-safe.
- * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and
- * `pressed` is true if the touch screen is currently being pressed
- */
- std::tuple<u16, u16, bool> GetTouchState() const {
- return std::make_tuple(touch_x, touch_y, touch_pressed);
- }
-
- /**
- * Gets the current accelerometer state (acceleration along each three axis).
- * Axis explained:
- * +x is the same direction as LEFT on D-pad.
- * +y is normal to the touch screen, pointing outward.
- * +z is the same direction as UP on D-pad.
- * Units:
- * 1 unit of return value = 1/512 g (measured by hw test),
- * where g is the gravitational acceleration (9.8 m/sec2).
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @return std::tuple of (x, y, z)
- */
- std::tuple<s16, s16, s16> GetAccelerometerState() {
- std::lock_guard<std::mutex> lock(accel_mutex);
- return std::make_tuple(accel_x, accel_y, accel_z);
- }
-
- /**
- * Gets the current gyroscope state (angular rates about each three axis).
- * Axis explained:
- * +x is the same direction as LEFT on D-pad.
- * +y is normal to the touch screen, pointing outward.
- * +z is the same direction as UP on D-pad.
- * Orientation is determined by right-hand rule.
- * Units:
- * 1 unit of return value = (1/coef) deg/sec,
- * where coef is the return value of GetGyroscopeRawToDpsCoefficient().
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @return std::tuple of (x, y, z)
- */
- std::tuple<s16, s16, s16> GetGyroscopeState() {
- std::lock_guard<std::mutex> lock(gyro_mutex);
- return std::make_tuple(gyro_x, gyro_y, gyro_z);
- }
-
- /**
- * Gets the coefficient for units conversion of gyroscope state.
- * The conversion formula is r = coefficient * v,
- * where v is angular rate in deg/sec,
- * and r is the gyroscope state.
- * @return float-type coefficient
- */
- f32 GetGyroscopeRawToDpsCoefficient() const {
- return 14.375f; // taken from hw test, and gyroscope's document
- }
-
- /**
* Returns currently active configuration.
* @note Accesses to the returned object need not be consistent because it may be modified in
* another thread
@@ -180,21 +101,8 @@ public:
void UpdateCurrentFramebufferLayout(unsigned width, unsigned height);
protected:
- EmuWindow() {
- // TODO: Find a better place to set this.
- config.min_client_area_size = std::make_pair(400u, 480u);
- active_config = config;
- touch_x = 0;
- touch_y = 0;
- touch_pressed = false;
- accel_x = 0;
- accel_y = -512;
- accel_z = 0;
- gyro_x = 0;
- gyro_y = 0;
- gyro_z = 0;
- }
- virtual ~EmuWindow() {}
+ EmuWindow();
+ virtual ~EmuWindow();
/**
* Processes any pending configuration changes from the last SetConfig call.
@@ -250,20 +158,8 @@ private:
/// ProcessConfigurationChanges)
WindowConfig active_config; ///< Internal active configuration
- bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false
-
- u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320)
- u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240)
-
- std::mutex accel_mutex;
- s16 accel_x; ///< Accelerometer X-axis value in native 3DS units
- s16 accel_y; ///< Accelerometer Y-axis value in native 3DS units
- s16 accel_z; ///< Accelerometer Z-axis value in native 3DS units
-
- std::mutex gyro_mutex;
- s16 gyro_x; ///< Gyroscope X-axis value in native 3DS units
- s16 gyro_y; ///< Gyroscope Y-axis value in native 3DS units
- s16 gyro_z; ///< Gyroscope Z-axis value in native 3DS units
+ class TouchState;
+ std::shared_ptr<TouchState> touch_state;
/**
* Clip the provided coordinates to be inside the touchscreen area.
diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp
index d2d02f9ff..e9f778fcb 100644
--- a/src/core/frontend/framebuffer_layout.cpp
+++ b/src/core/frontend/framebuffer_layout.cpp
@@ -141,6 +141,40 @@ FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool swapped
return res;
}
+FramebufferLayout SideFrameLayout(unsigned width, unsigned height, bool swapped) {
+ ASSERT(width > 0);
+ ASSERT(height > 0);
+
+ FramebufferLayout res{width, height, true, true, {}, {}};
+ // Aspect ratio of both screens side by side
+ const float emulation_aspect_ratio = static_cast<float>(Core::kScreenTopHeight) /
+ (Core::kScreenTopWidth + Core::kScreenBottomWidth);
+ float window_aspect_ratio = static_cast<float>(height) / width;
+ MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
+ // Find largest Rectangle that can fit in the window size with the given aspect ratio
+ MathUtil::Rectangle<unsigned> screen_rect =
+ maxRectangle(screen_window_area, emulation_aspect_ratio);
+ // Find sizes of top and bottom screen
+ MathUtil::Rectangle<unsigned> top_screen = maxRectangle(screen_rect, TOP_SCREEN_ASPECT_RATIO);
+ MathUtil::Rectangle<unsigned> bot_screen = maxRectangle(screen_rect, BOT_SCREEN_ASPECT_RATIO);
+
+ if (window_aspect_ratio < emulation_aspect_ratio) {
+ // Apply borders to the left and right sides of the window.
+ u32 shift_horizontal = (screen_window_area.GetWidth() - screen_rect.GetWidth()) / 2;
+ top_screen = top_screen.TranslateX(shift_horizontal);
+ bot_screen = bot_screen.TranslateX(shift_horizontal);
+ } else {
+ // Window is narrower than the emulation content => apply borders to the top and bottom
+ u32 shift_vertical = (screen_window_area.GetHeight() - screen_rect.GetHeight()) / 2;
+ top_screen = top_screen.TranslateY(shift_vertical);
+ bot_screen = bot_screen.TranslateY(shift_vertical);
+ }
+ // Move the top screen to the right if we are swapped.
+ res.top_screen = swapped ? top_screen.TranslateX(bot_screen.GetWidth()) : top_screen;
+ res.bottom_screen = swapped ? bot_screen : bot_screen.TranslateX(top_screen.GetWidth());
+ return res;
+}
+
FramebufferLayout CustomFrameLayout(unsigned width, unsigned height) {
ASSERT(width > 0);
ASSERT(height > 0);
@@ -158,4 +192,4 @@ FramebufferLayout CustomFrameLayout(unsigned width, unsigned height) {
res.bottom_screen = bot_screen;
return res;
}
-}
+} // namespace Layout
diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h
index 9a7738969..4983cf103 100644
--- a/src/core/frontend/framebuffer_layout.h
+++ b/src/core/frontend/framebuffer_layout.h
@@ -54,6 +54,17 @@ FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swa
FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swapped);
/**
+* Factory method for constructing a Frame with the Top screen and bottom
+* screen side by side
+* This is useful for devices with small screens, like the GPDWin
+* @param width Window framebuffer width in pixels
+* @param height Window framebuffer height in pixels
+* @param is_swapped if true, the bottom screen will be the left display
+* @return Newly created FramebufferLayout object with default screen regions initialized
+*/
+FramebufferLayout SideFrameLayout(unsigned width, unsigned height, bool is_swapped);
+
+/**
* Factory method for constructing a custom FramebufferLayout
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h
index 0a5713dc0..8c256beb5 100644
--- a/src/core/frontend/input.h
+++ b/src/core/frontend/input.h
@@ -11,6 +11,7 @@
#include <utility>
#include "common/logging/log.h"
#include "common/param_package.h"
+#include "common/vector_math.h"
namespace Input {
@@ -107,4 +108,28 @@ using ButtonDevice = InputDevice<bool>;
*/
using AnalogDevice = InputDevice<std::tuple<float, float>>;
+/**
+ * A motion device is an input device that returns a tuple of accelerometer state vector and
+ * gyroscope state vector.
+ *
+ * For both vectors:
+ * x+ is the same direction as LEFT on D-pad.
+ * y+ is normal to the touch screen, pointing outward.
+ * z+ is the same direction as UP on D-pad.
+ *
+ * For accelerometer state vector
+ * Units: g (gravitational acceleration)
+ *
+ * For gyroscope state vector:
+ * Orientation is determined by right-hand rule.
+ * Units: deg/sec
+ */
+using MotionDevice = InputDevice<std::tuple<Math::Vec3<float>, Math::Vec3<float>>>;
+
+/**
+ * A touch device is an input device that returns a tuple of two floats and a bool. The floats are
+ * x and y coordinates in the range 0.0 - 1.0, and the bool indicates whether it is pressed.
+ */
+using TouchDevice = InputDevice<std::tuple<float, float, bool>>;
+
} // namespace Input
diff --git a/src/core/frontend/motion_emu.cpp b/src/core/frontend/motion_emu.cpp
deleted file mode 100644
index 9a5b3185d..000000000
--- a/src/core/frontend/motion_emu.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2016 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include "common/math_util.h"
-#include "common/quaternion.h"
-#include "core/frontend/emu_window.h"
-#include "core/frontend/motion_emu.h"
-
-namespace Motion {
-
-static constexpr int update_millisecond = 100;
-static constexpr auto update_duration =
- std::chrono::duration_cast<std::chrono::steady_clock::duration>(
- std::chrono::milliseconds(update_millisecond));
-
-MotionEmu::MotionEmu(EmuWindow& emu_window)
- : motion_emu_thread(&MotionEmu::MotionEmuThread, this, std::ref(emu_window)) {}
-
-MotionEmu::~MotionEmu() {
- if (motion_emu_thread.joinable()) {
- shutdown_event.Set();
- motion_emu_thread.join();
- }
-}
-
-void MotionEmu::MotionEmuThread(EmuWindow& emu_window) {
- auto update_time = std::chrono::steady_clock::now();
- Math::Quaternion<float> q = MakeQuaternion(Math::Vec3<float>(), 0);
- Math::Quaternion<float> old_q;
-
- while (!shutdown_event.WaitUntil(update_time)) {
- update_time += update_duration;
- old_q = q;
-
- {
- std::lock_guard<std::mutex> guard(tilt_mutex);
-
- // Find the quaternion describing current 3DS tilting
- q = MakeQuaternion(Math::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x),
- tilt_angle);
- }
-
- auto inv_q = q.Inverse();
-
- // Set the gravity vector in world space
- auto gravity = Math::MakeVec(0.0f, -1.0f, 0.0f);
-
- // Find the angular rate vector in world space
- auto angular_rate = ((q - old_q) * inv_q).xyz * 2;
- angular_rate *= 1000 / update_millisecond / MathUtil::PI * 180;
-
- // Transform the two vectors from world space to 3DS space
- gravity = QuaternionRotate(inv_q, gravity);
- angular_rate = QuaternionRotate(inv_q, angular_rate);
-
- // Update the sensor state
- emu_window.AccelerometerChanged(gravity.x, gravity.y, gravity.z);
- emu_window.GyroscopeChanged(angular_rate.x, angular_rate.y, angular_rate.z);
- }
-}
-
-void MotionEmu::BeginTilt(int x, int y) {
- mouse_origin = Math::MakeVec(x, y);
- is_tilting = true;
-}
-
-void MotionEmu::Tilt(int x, int y) {
- constexpr float SENSITIVITY = 0.01f;
- auto mouse_move = Math::MakeVec(x, y) - mouse_origin;
- if (is_tilting) {
- std::lock_guard<std::mutex> guard(tilt_mutex);
- if (mouse_move.x == 0 && mouse_move.y == 0) {
- tilt_angle = 0;
- } else {
- tilt_direction = mouse_move.Cast<float>();
- tilt_angle = MathUtil::Clamp(tilt_direction.Normalize() * SENSITIVITY, 0.0f,
- MathUtil::PI * 0.5f);
- }
- }
-}
-
-void MotionEmu::EndTilt() {
- std::lock_guard<std::mutex> guard(tilt_mutex);
- tilt_angle = 0;
- is_tilting = false;
-}
-
-} // namespace Motion
diff --git a/src/core/frontend/motion_emu.h b/src/core/frontend/motion_emu.h
deleted file mode 100644
index 99d41a726..000000000
--- a/src/core/frontend/motion_emu.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2016 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-#include "common/thread.h"
-#include "common/vector_math.h"
-
-class EmuWindow;
-
-namespace Motion {
-
-class MotionEmu final {
-public:
- MotionEmu(EmuWindow& emu_window);
- ~MotionEmu();
-
- /**
- * Signals that a motion sensor tilt has begun.
- * @param x the x-coordinate of the cursor
- * @param y the y-coordinate of the cursor
- */
- void BeginTilt(int x, int y);
-
- /**
- * Signals that a motion sensor tilt is occurring.
- * @param x the x-coordinate of the cursor
- * @param y the y-coordinate of the cursor
- */
- void Tilt(int x, int y);
-
- /**
- * Signals that a motion sensor tilt has ended.
- */
- void EndTilt();
-
-private:
- Math::Vec2<int> mouse_origin;
-
- std::mutex tilt_mutex;
- Math::Vec2<float> tilt_direction;
- float tilt_angle = 0;
-
- bool is_tilting = false;
-
- Common::Event shutdown_event;
- std::thread motion_emu_thread;
-
- void MotionEmuThread(EmuWindow& emu_window);
-};
-
-} // namespace Motion
diff --git a/src/core/hle/applets/erreula.cpp b/src/core/hle/applets/erreula.cpp
index 75d7fd9fc..518f371f5 100644
--- a/src/core/hle/applets/erreula.cpp
+++ b/src/core/hle/applets/erreula.cpp
@@ -31,8 +31,8 @@ ResultCode ErrEula::ReceiveParameter(const Service::APT::MessageParameter& param
heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
// Create a SharedMemory that directly points to this heap block.
framebuffer_memory = Kernel::SharedMemory::CreateForApplet(
- heap_memory, 0, heap_memory->size(), MemoryPermission::ReadWrite,
- MemoryPermission::ReadWrite, "ErrEula Memory");
+ heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
+ "ErrEula Memory");
// Send the response message with the newly created SharedMemory
Service::APT::MessageParameter result;
diff --git a/src/core/hle/applets/mii_selector.cpp b/src/core/hle/applets/mii_selector.cpp
index 89f08daa2..f225c23a5 100644
--- a/src/core/hle/applets/mii_selector.cpp
+++ b/src/core/hle/applets/mii_selector.cpp
@@ -38,8 +38,8 @@ ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& p
heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
// Create a SharedMemory that directly points to this heap block.
framebuffer_memory = Kernel::SharedMemory::CreateForApplet(
- heap_memory, 0, heap_memory->size(), MemoryPermission::ReadWrite,
- MemoryPermission::ReadWrite, "MiiSelector Memory");
+ heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
+ "MiiSelector Memory");
// Send the response message with the newly created SharedMemory
Service::APT::MessageParameter result;
@@ -66,7 +66,7 @@ ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& pa
// continue.
MiiResult result;
memset(&result, 0, sizeof(result));
- result.result_code = 0;
+ result.return_code = 0;
// Let the application know that we're closing
Service::APT::MessageParameter message;
@@ -82,5 +82,5 @@ ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& pa
}
void MiiSelector::Update() {}
-}
-} // namespace
+} // namespace Applets
+} // namespace HLE
diff --git a/src/core/hle/applets/mii_selector.h b/src/core/hle/applets/mii_selector.h
index ec00e29d2..136ce8948 100644
--- a/src/core/hle/applets/mii_selector.h
+++ b/src/core/hle/applets/mii_selector.h
@@ -16,51 +16,46 @@ namespace HLE {
namespace Applets {
struct MiiConfig {
- u8 unk_000;
- u8 unk_001;
- u8 unk_002;
- u8 unk_003;
- u8 unk_004;
+ u8 enable_cancel_button;
+ u8 enable_guest_mii;
+ u8 show_on_top_screen;
+ INSERT_PADDING_BYTES(5);
+ u16 title[0x40];
+ INSERT_PADDING_BYTES(4);
+ u8 show_guest_miis;
INSERT_PADDING_BYTES(3);
- u16 unk_008;
- INSERT_PADDING_BYTES(0x82);
- u8 unk_08C;
- INSERT_PADDING_BYTES(3);
- u16 unk_090;
+ u32 initially_selected_mii_index;
+ u8 guest_mii_whitelist[6];
+ u8 user_mii_whitelist[0x64];
INSERT_PADDING_BYTES(2);
- u32 unk_094;
- u16 unk_098;
- u8 unk_09A[0x64];
- u8 unk_0FE;
- u8 unk_0FF;
- u32 unk_100;
+ u32 magic_value;
};
-
static_assert(sizeof(MiiConfig) == 0x104, "MiiConfig structure has incorrect size");
#define ASSERT_REG_POSITION(field_name, position) \
static_assert(offsetof(MiiConfig, field_name) == position, \
"Field " #field_name " has invalid position")
-ASSERT_REG_POSITION(unk_008, 0x08);
-ASSERT_REG_POSITION(unk_08C, 0x8C);
-ASSERT_REG_POSITION(unk_090, 0x90);
-ASSERT_REG_POSITION(unk_094, 0x94);
-ASSERT_REG_POSITION(unk_0FE, 0xFE);
+ASSERT_REG_POSITION(title, 0x08);
+ASSERT_REG_POSITION(show_guest_miis, 0x8C);
+ASSERT_REG_POSITION(initially_selected_mii_index, 0x90);
+ASSERT_REG_POSITION(guest_mii_whitelist, 0x94);
#undef ASSERT_REG_POSITION
struct MiiResult {
- u32 result_code;
- u8 unk_04;
- INSERT_PADDING_BYTES(7);
- u8 unk_0C[0x60];
- u8 unk_6C[0x16];
+ u32 return_code;
+ u32 is_guest_mii_selected;
+ u32 selected_guest_mii_index;
+ // TODO(mailwl): expand to Mii Format structure: https://www.3dbrew.org/wiki/Mii
+ u8 selected_mii_data[0x5C];
INSERT_PADDING_BYTES(2);
+ u16 mii_data_checksum;
+ u16 guest_mii_name[0xC];
};
static_assert(sizeof(MiiResult) == 0x84, "MiiResult structure has incorrect size");
#define ASSERT_REG_POSITION(field_name, position) \
static_assert(offsetof(MiiResult, field_name) == position, \
"Field " #field_name " has invalid position")
-ASSERT_REG_POSITION(unk_0C, 0x0C);
-ASSERT_REG_POSITION(unk_6C, 0x6C);
+ASSERT_REG_POSITION(selected_mii_data, 0x0C);
+ASSERT_REG_POSITION(guest_mii_name, 0x6C);
#undef ASSERT_REG_POSITION
class MiiSelector final : public Applet {
@@ -79,5 +74,5 @@ private:
MiiConfig config;
};
-}
-} // namespace
+} // namespace Applets
+} // namespace HLE
diff --git a/src/core/hle/applets/mint.cpp b/src/core/hle/applets/mint.cpp
index 31a79ea17..50d79190b 100644
--- a/src/core/hle/applets/mint.cpp
+++ b/src/core/hle/applets/mint.cpp
@@ -31,8 +31,8 @@ ResultCode Mint::ReceiveParameter(const Service::APT::MessageParameter& paramete
heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
// Create a SharedMemory that directly points to this heap block.
framebuffer_memory = Kernel::SharedMemory::CreateForApplet(
- heap_memory, 0, heap_memory->size(), MemoryPermission::ReadWrite,
- MemoryPermission::ReadWrite, "Mint Memory");
+ heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
+ "Mint Memory");
// Send the response message with the newly created SharedMemory
Service::APT::MessageParameter result;
diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp
index fdf8807b0..0bc471a3a 100644
--- a/src/core/hle/applets/swkbd.cpp
+++ b/src/core/hle/applets/swkbd.cpp
@@ -41,8 +41,8 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con
heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
// Create a SharedMemory that directly points to this heap block.
framebuffer_memory = Kernel::SharedMemory::CreateForApplet(
- heap_memory, 0, heap_memory->size(), MemoryPermission::ReadWrite,
- MemoryPermission::ReadWrite, "SoftwareKeyboard Memory");
+ heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
+ "SoftwareKeyboard Memory");
// Send the response message with the newly created SharedMemory
Service::APT::MessageParameter result;
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 9cf288b08..73fab3981 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -8,6 +8,7 @@
#include <string>
#include <utility>
#include <boost/smart_ptr/intrusive_ptr.hpp>
+#include "common/assert.h"
#include "common/common_types.h"
namespace Kernel {
@@ -84,6 +85,8 @@ public:
case HandleType::ClientSession:
return false;
}
+
+ UNREACHABLE();
}
public:
@@ -129,4 +132,4 @@ void Init(u32 system_mode);
/// Shutdown the kernel
void Shutdown();
-} // namespace
+} // namespace Kernel
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index f5f2eb2f7..b957c45dd 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -478,8 +478,6 @@ void Thread::BoostPriority(s32 priority) {
}
SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) {
- DEBUG_ASSERT(!GetCurrentThread());
-
// Initialize new "main" thread
auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0,
Memory::HEAP_VADDR_END);
@@ -489,9 +487,7 @@ SharedPtr<Thread> SetupMainThread(u32 entry_point, s32 priority) {
thread->context.fpscr =
FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO | FPSCR_IXC; // 0x03C00010
- // Run new "main" thread
- SwitchContext(thread.get());
-
+ // Note: The newly created thread will be run when the scheduler fires.
return thread;
}
diff --git a/src/core/hle/lock.cpp b/src/core/hle/lock.cpp
new file mode 100644
index 000000000..1c24c7ce9
--- /dev/null
+++ b/src/core/hle/lock.cpp
@@ -0,0 +1,11 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <core/hle/lock.h>
+
+namespace HLE {
+std::recursive_mutex g_hle_lock;
+}
diff --git a/src/core/hle/lock.h b/src/core/hle/lock.h
new file mode 100644
index 000000000..5c99fe996
--- /dev/null
+++ b/src/core/hle/lock.h
@@ -0,0 +1,18 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <mutex>
+
+namespace HLE {
+/*
+ * Synchronizes access to the internal HLE kernel structures, it is acquired when a guest
+ * application thread performs a syscall. It should be acquired by any host threads that read or
+ * modify the HLE kernel state. Note: Any operation that directly or indirectly reads from or writes
+ * to the emulated memory is not protected by this mutex, and should be avoided in any threads other
+ * than the CPU thread.
+ */
+extern std::recursive_mutex g_hle_lock;
+} // namespace HLE
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index 0109fa2b2..58d94768c 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -34,8 +34,6 @@ static bool shared_font_loaded = false;
static bool shared_font_relocated = false;
static Kernel::SharedPtr<Kernel::Mutex> lock;
-static Kernel::SharedPtr<Kernel::Event> notification_event; ///< APT notification event
-static Kernel::SharedPtr<Kernel::Event> parameter_event; ///< APT parameter event
static u32 cpu_percent; ///< CPU time available to the running application
@@ -44,32 +42,160 @@ static u8 unknown_ns_state_field;
static ScreencapPostPermission screen_capture_post_permission;
-/// Parameter data to be returned in the next call to Glance/ReceiveParameter
+/// Parameter data to be returned in the next call to Glance/ReceiveParameter.
+/// TODO(Subv): Use std::optional once we migrate to C++17.
static boost::optional<MessageParameter> next_parameter;
+enum class AppletPos { Application = 0, Library = 1, System = 2, SysLibrary = 3, Resident = 4 };
+
+static constexpr size_t NumAppletSlot = 4;
+
+enum class AppletSlot : u8 {
+ Application,
+ SystemApplet,
+ HomeMenu,
+ LibraryApplet,
+
+ // An invalid tag
+ Error,
+};
+
+union AppletAttributes {
+ u32 raw;
+
+ BitField<0, 3, u32> applet_pos;
+
+ AppletAttributes() : raw(0) {}
+ AppletAttributes(u32 attributes) : raw(attributes) {}
+};
+
+struct AppletSlotData {
+ AppletId applet_id;
+ AppletSlot slot;
+ bool registered;
+ AppletAttributes attributes;
+ Kernel::SharedPtr<Kernel::Event> notification_event;
+ Kernel::SharedPtr<Kernel::Event> parameter_event;
+};
+
+// Holds data about the concurrently running applets in the system.
+static std::array<AppletSlotData, NumAppletSlot> applet_slots = {};
+
+// This overload returns nullptr if no applet with the specified id has been started.
+static AppletSlotData* GetAppletSlotData(AppletId id) {
+ auto GetSlot = [](AppletSlot slot) -> AppletSlotData* {
+ return &applet_slots[static_cast<size_t>(slot)];
+ };
+
+ if (id == AppletId::Application) {
+ auto* slot = GetSlot(AppletSlot::Application);
+ if (slot->applet_id != AppletId::None)
+ return slot;
+
+ return nullptr;
+ }
+
+ if (id == AppletId::AnySystemApplet) {
+ auto* system_slot = GetSlot(AppletSlot::SystemApplet);
+ if (system_slot->applet_id != AppletId::None)
+ return system_slot;
+
+ // The Home Menu is also a system applet, but it lives in its own slot to be able to run
+ // concurrently with other system applets.
+ auto* home_slot = GetSlot(AppletSlot::HomeMenu);
+ if (home_slot->applet_id != AppletId::None)
+ return home_slot;
+
+ return nullptr;
+ }
+
+ if (id == AppletId::AnyLibraryApplet || id == AppletId::AnySysLibraryApplet) {
+ auto* slot = GetSlot(AppletSlot::LibraryApplet);
+ if (slot->applet_id == AppletId::None)
+ return nullptr;
+
+ u32 applet_pos = slot->attributes.applet_pos;
+
+ if (id == AppletId::AnyLibraryApplet && applet_pos == static_cast<u32>(AppletPos::Library))
+ return slot;
+
+ if (id == AppletId::AnySysLibraryApplet &&
+ applet_pos == static_cast<u32>(AppletPos::SysLibrary))
+ return slot;
+
+ return nullptr;
+ }
+
+ if (id == AppletId::HomeMenu || id == AppletId::AlternateMenu) {
+ auto* slot = GetSlot(AppletSlot::HomeMenu);
+ if (slot->applet_id != AppletId::None)
+ return slot;
+
+ return nullptr;
+ }
+
+ for (auto& slot : applet_slots) {
+ if (slot.applet_id == id)
+ return &slot;
+ }
+
+ return nullptr;
+}
+
+static AppletSlotData* GetAppletSlotData(AppletAttributes attributes) {
+ // Mapping from AppletPos to AppletSlot
+ static constexpr std::array<AppletSlot, 6> applet_position_slots = {
+ AppletSlot::Application, AppletSlot::LibraryApplet, AppletSlot::SystemApplet,
+ AppletSlot::LibraryApplet, AppletSlot::Error, AppletSlot::LibraryApplet};
+
+ u32 applet_pos = attributes.applet_pos;
+ if (applet_pos >= applet_position_slots.size())
+ return nullptr;
+
+ AppletSlot slot = applet_position_slots[applet_pos];
+
+ if (slot == AppletSlot::Error)
+ return nullptr;
+
+ return &applet_slots[static_cast<size_t>(slot)];
+}
+
void SendParameter(const MessageParameter& parameter) {
next_parameter = parameter;
- // Signal the event to let the application know that a new parameter is ready to be read
- parameter_event->Signal();
+ // Signal the event to let the receiver know that a new parameter is ready to be read
+ auto* const slot_data = GetAppletSlotData(static_cast<AppletId>(parameter.destination_id));
+ ASSERT(slot_data);
+
+ slot_data->parameter_event->Signal();
}
void Initialize(Service::Interface* self) {
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x2, 2, 0); // 0x20080
u32 app_id = rp.Pop<u32>();
- u32 flags = rp.Pop<u32>();
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 3);
- rb.Push(RESULT_SUCCESS);
- rb.PushCopyHandles(Kernel::g_handle_table.Create(notification_event).Unwrap(),
- Kernel::g_handle_table.Create(parameter_event).Unwrap());
+ u32 attributes = rp.Pop<u32>();
- // TODO(bunnei): Check if these events are cleared every time Initialize is called.
- notification_event->Clear();
- parameter_event->Clear();
+ LOG_DEBUG(Service_APT, "called app_id=0x%08X, attributes=0x%08X", app_id, attributes);
+
+ auto* const slot_data = GetAppletSlotData(attributes);
+
+ // Note: The real NS service does not check if the attributes value is valid before accessing
+ // the data in the array
+ ASSERT_MSG(slot_data, "Invalid application attributes");
+
+ if (slot_data->registered) {
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
+ rb.Push(ResultCode(ErrorDescription::AlreadyExists, ErrorModule::Applet,
+ ErrorSummary::InvalidState, ErrorLevel::Status));
+ return;
+ }
- ASSERT_MSG((nullptr != lock), "Cannot initialize without lock");
- lock->Release();
+ slot_data->applet_id = static_cast<AppletId>(app_id);
+ slot_data->attributes.raw = attributes;
- LOG_DEBUG(Service_APT, "called app_id=0x%08X, flags=0x%08X", app_id, flags);
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 3);
+ rb.Push(RESULT_SUCCESS);
+ rb.PushCopyHandles(Kernel::g_handle_table.Create(slot_data->notification_event).Unwrap(),
+ Kernel::g_handle_table.Create(slot_data->parameter_event).Unwrap());
}
void GetSharedFont(Service::Interface* self) {
@@ -120,7 +246,12 @@ void GetLockHandle(Service::Interface* self) {
// this will cause the app to wait until parameter_event is signaled.
u32 applet_attributes = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(3, 2);
- rb.Push(RESULT_SUCCESS); // No error
+ rb.Push(RESULT_SUCCESS); // No error
+
+ // TODO(Subv): The output attributes should have an AppletPos of either Library or System |
+ // Library (depending on the type of the last launched applet) if the input attributes'
+ // AppletPos has the Library bit set.
+
rb.Push(applet_attributes); // Applet Attributes, this value is passed to Enable.
rb.Push<u32>(0); // Least significant bit = power button state
Kernel::Handle handle_copy = Kernel::g_handle_table.Create(lock).Unwrap();
@@ -133,10 +264,22 @@ void GetLockHandle(Service::Interface* self) {
void Enable(Service::Interface* self) {
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x3, 1, 0); // 0x30040
u32 attributes = rp.Pop<u32>();
+
+ LOG_DEBUG(Service_APT, "called attributes=0x%08X", attributes);
+
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(RESULT_SUCCESS); // No error
- parameter_event->Signal(); // Let the application know that it has been started
- LOG_WARNING(Service_APT, "(STUBBED) called attributes=0x%08X", attributes);
+
+ auto* const slot_data = GetAppletSlotData(attributes);
+
+ if (!slot_data) {
+ rb.Push(ResultCode(ErrCodes::InvalidAppletSlot, ErrorModule::Applet,
+ ErrorSummary::InvalidState, ErrorLevel::Status));
+ return;
+ }
+
+ slot_data->registered = true;
+
+ rb.Push(RESULT_SUCCESS);
}
void GetAppletManInfo(Service::Interface* self) {
@@ -154,22 +297,27 @@ void GetAppletManInfo(Service::Interface* self) {
void IsRegistered(Service::Interface* self) {
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x9, 1, 0); // 0x90040
- u32 app_id = rp.Pop<u32>();
+ AppletId app_id = static_cast<AppletId>(rp.Pop<u32>());
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS); // No error
- // TODO(Subv): An application is considered "registered" if it has already called APT::Enable
- // handle this properly once we implement multiprocess support.
- bool is_registered = false; // Set to not registered by default
+ auto* const slot_data = GetAppletSlotData(app_id);
+
+ // Check if an LLE applet was registered first, then fallback to HLE applets
+ bool is_registered = slot_data && slot_data->registered;
- if (app_id == static_cast<u32>(AppletId::AnyLibraryApplet)) {
- is_registered = HLE::Applets::IsLibraryAppletRunning();
- } else if (auto applet = HLE::Applets::Applet::Get(static_cast<AppletId>(app_id))) {
- is_registered = true; // Set to registered
+ if (!is_registered) {
+ if (app_id == AppletId::AnyLibraryApplet) {
+ is_registered = HLE::Applets::IsLibraryAppletRunning();
+ } else if (auto applet = HLE::Applets::Applet::Get(app_id)) {
+ // The applet exists, set it as registered.
+ is_registered = true;
+ }
}
+
rb.Push(is_registered);
- LOG_WARNING(Service_APT, "(STUBBED) called app_id=0x%08X", app_id);
+ LOG_DEBUG(Service_APT, "called app_id=0x%08X", static_cast<u32>(app_id));
}
void InquireNotification(Service::Interface* self) {
@@ -864,14 +1012,23 @@ void Init() {
screen_capture_post_permission =
ScreencapPostPermission::CleanThePermission; // TODO(JamePeng): verify the initial value
- // TODO(bunnei): Check if these are created in Initialize or on APT process startup.
- notification_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT_U:Notification");
- parameter_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT_U:Start");
+ for (size_t slot = 0; slot < applet_slots.size(); ++slot) {
+ auto& slot_data = applet_slots[slot];
+ slot_data.slot = static_cast<AppletSlot>(slot);
+ slot_data.applet_id = AppletId::None;
+ slot_data.attributes.raw = 0;
+ slot_data.registered = false;
+ slot_data.notification_event =
+ Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Notification");
+ slot_data.parameter_event =
+ Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Parameter");
+ }
// Initialize the parameter to wake up the application.
next_parameter.emplace();
next_parameter->signal = static_cast<u32>(SignalType::Wakeup);
next_parameter->destination_id = static_cast<u32>(AppletId::Application);
+ applet_slots[static_cast<size_t>(AppletSlot::Application)].parameter_event->Signal();
}
void Shutdown() {
@@ -879,8 +1036,12 @@ void Shutdown() {
shared_font_loaded = false;
shared_font_relocated = false;
lock = nullptr;
- notification_event = nullptr;
- parameter_event = nullptr;
+
+ for (auto& slot : applet_slots) {
+ slot.registered = false;
+ slot.notification_event = nullptr;
+ slot.parameter_event = nullptr;
+ }
next_parameter = boost::none;
diff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.h
index 106754853..96b28b438 100644
--- a/src/core/hle/service/apt/apt.h
+++ b/src/core/hle/service/apt/apt.h
@@ -72,6 +72,8 @@ enum class SignalType : u32 {
/// App Id's used by APT functions
enum class AppletId : u32 {
+ None = 0,
+ AnySystemApplet = 0x100,
HomeMenu = 0x101,
AlternateMenu = 0x103,
Camera = 0x110,
@@ -83,6 +85,7 @@ enum class AppletId : u32 {
Miiverse = 0x117,
MiiversePost = 0x118,
AmiiboSettings = 0x119,
+ AnySysLibraryApplet = 0x200,
SoftwareKeyboard1 = 0x201,
Ed1 = 0x202,
PnoteApp = 0x204,
@@ -119,8 +122,9 @@ enum class ScreencapPostPermission : u32 {
namespace ErrCodes {
enum {
ParameterPresent = 2,
+ InvalidAppletSlot = 4,
};
-}
+} // namespace ErrCodes
/// Send a parameter to the currently-running application, which will read it via ReceiveParameter
void SendParameter(const MessageParameter& parameter);
diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp
index 7d746054f..42f8950f9 100644
--- a/src/core/hle/service/dsp_dsp.cpp
+++ b/src/core/hle/service/dsp_dsp.cpp
@@ -147,9 +147,10 @@ static void LoadComponent(Service::Interface* self) {
LOG_INFO(Service_DSP, "Firmware hash: %#" PRIx64,
Common::ComputeHash64(component_data.data(), component_data.size()));
// Some versions of the firmware have the location of DSP structures listed here.
- ASSERT(size > 0x37C);
- LOG_INFO(Service_DSP, "Structures hash: %#" PRIx64,
- Common::ComputeHash64(component_data.data() + 0x340, 60));
+ if (size > 0x37C) {
+ LOG_INFO(Service_DSP, "Structures hash: %#" PRIx64,
+ Common::ComputeHash64(component_data.data() + 0x340, 60));
+ }
LOG_WARNING(Service_DSP,
"(STUBBED) called size=0x%X, prog_mask=0x%08X, data_mask=0x%08X, buffer=0x%08X",
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 2014b8461..aa5d821f9 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -7,8 +7,9 @@
#include <cmath>
#include <memory>
#include "common/logging/log.h"
+#include "core/3ds.h"
+#include "core/core.h"
#include "core/core_timing.h"
-#include "core/frontend/emu_window.h"
#include "core/frontend/input.h"
#include "core/hle/ipc.h"
#include "core/hle/kernel/event.h"
@@ -18,7 +19,6 @@
#include "core/hle/service/hid/hid_spvr.h"
#include "core/hle/service/hid/hid_user.h"
#include "core/hle/service/service.h"
-#include "video_core/video_core.h"
namespace Service {
namespace HID {
@@ -50,10 +50,15 @@ constexpr u64 pad_update_ticks = BASE_CLOCK_RATE_ARM11 / 234;
constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE_ARM11 / 104;
constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE_ARM11 / 101;
+constexpr float accelerometer_coef = 512.0f; // measured from hw test result
+constexpr float gyroscope_coef = 14.375f; // got from hwtest GetGyroscopeLowRawToDpsCoefficient call
+
static std::atomic<bool> is_device_reload_pending;
static std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
buttons;
static std::unique_ptr<Input::AnalogDevice> circle_pad;
+static std::unique_ptr<Input::MotionDevice> motion_device;
+static std::unique_ptr<Input::TouchDevice> touch_device;
DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
// 30 degree and 60 degree are angular thresholds for directions
@@ -90,6 +95,8 @@ static void LoadInputDevices() {
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
circle_pad = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CirclePad]);
+ motion_device = Input::CreateDevice<Input::MotionDevice>(Settings::values.motion_device);
+ touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device);
}
static void UnloadInputDevices() {
@@ -97,6 +104,8 @@ static void UnloadInputDevices() {
button.reset();
}
circle_pad.reset();
+ motion_device.reset();
+ touch_device.reset();
}
static void UpdatePadCallback(u64 userdata, int cycles_late) {
@@ -165,8 +174,10 @@ static void UpdatePadCallback(u64 userdata, int cycles_late) {
// Get the current touch entry
TouchDataEntry& touch_entry = mem->touch.entries[mem->touch.index];
bool pressed = false;
-
- std::tie(touch_entry.x, touch_entry.y, pressed) = VideoCore::g_emu_window->GetTouchState();
+ float x, y;
+ std::tie(x, y, pressed) = touch_device->GetStatus();
+ touch_entry.x = static_cast<u16>(x * Core::kScreenBottomWidth);
+ touch_entry.y = static_cast<u16>(y * Core::kScreenBottomHeight);
touch_entry.valid.Assign(pressed ? 1 : 0);
// TODO(bunnei): We're not doing anything with offset 0xA8 + 0x18 of HID SharedMemory, which
@@ -193,10 +204,19 @@ static void UpdateAccelerometerCallback(u64 userdata, int cycles_late) {
mem->accelerometer.index = next_accelerometer_index;
next_accelerometer_index = (next_accelerometer_index + 1) % mem->accelerometer.entries.size();
+ Math::Vec3<float> accel;
+ std::tie(accel, std::ignore) = motion_device->GetStatus();
+ accel *= accelerometer_coef;
+ // TODO(wwylele): do a time stretch like the one in UpdateGyroscopeCallback
+ // The time stretch formula should be like
+ // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity
+
AccelerometerDataEntry& accelerometer_entry =
mem->accelerometer.entries[mem->accelerometer.index];
- std::tie(accelerometer_entry.x, accelerometer_entry.y, accelerometer_entry.z) =
- VideoCore::g_emu_window->GetAccelerometerState();
+
+ accelerometer_entry.x = static_cast<s16>(accel.x);
+ accelerometer_entry.y = static_cast<s16>(accel.y);
+ accelerometer_entry.z = static_cast<s16>(accel.z);
// Make up "raw" entry
// TODO(wwylele):
@@ -227,8 +247,14 @@ static void UpdateGyroscopeCallback(u64 userdata, int cycles_late) {
next_gyroscope_index = (next_gyroscope_index + 1) % mem->gyroscope.entries.size();
GyroscopeDataEntry& gyroscope_entry = mem->gyroscope.entries[mem->gyroscope.index];
- std::tie(gyroscope_entry.x, gyroscope_entry.y, gyroscope_entry.z) =
- VideoCore::g_emu_window->GetGyroscopeState();
+
+ Math::Vec3<float> gyro;
+ std::tie(std::ignore, gyro) = motion_device->GetStatus();
+ double stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale();
+ gyro *= gyroscope_coef * stretch;
+ gyroscope_entry.x = static_cast<s16>(gyro.x);
+ gyroscope_entry.y = static_cast<s16>(gyro.y);
+ gyroscope_entry.z = static_cast<s16>(gyro.z);
// Make up "raw" entry
mem->gyroscope.raw_entry.x = gyroscope_entry.x;
@@ -326,7 +352,7 @@ void GetGyroscopeLowRawToDpsCoefficient(Service::Interface* self) {
cmd_buff[1] = RESULT_SUCCESS.raw;
- f32 coef = VideoCore::g_emu_window->GetGyroscopeRawToDpsCoefficient();
+ f32 coef = gyroscope_coef;
memcpy(&cmd_buff[2], &coef, 4);
}
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index 1ef972e70..ef25926b5 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -24,7 +24,7 @@ namespace HID {
*/
struct PadState {
union {
- u32 hex;
+ u32 hex{};
BitField<0, 1, u32> a;
BitField<1, 1, u32> b;
diff --git a/src/core/hle/service/ir/ir_rst.cpp b/src/core/hle/service/ir/ir_rst.cpp
index 837413f93..0912d5756 100644
--- a/src/core/hle/service/ir/ir_rst.cpp
+++ b/src/core/hle/service/ir/ir_rst.cpp
@@ -18,7 +18,7 @@ namespace Service {
namespace IR {
union PadState {
- u32_le hex;
+ u32_le hex{};
BitField<14, 1, u32_le> zl;
BitField<15, 1, u32_le> zr;
diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp
index 6dbdff044..893bbb1e7 100644
--- a/src/core/hle/service/nwm/nwm_uds.cpp
+++ b/src/core/hle/service/nwm/nwm_uds.cpp
@@ -4,6 +4,7 @@
#include <array>
#include <cstring>
+#include <mutex>
#include <unordered_map>
#include <vector>
#include "common/common_types.h"
@@ -15,8 +16,10 @@
#include "core/hle/result.h"
#include "core/hle/service/nwm/nwm_uds.h"
#include "core/hle/service/nwm/uds_beacon.h"
+#include "core/hle/service/nwm/uds_connection.h"
#include "core/hle/service/nwm/uds_data.h"
#include "core/memory.h"
+#include "network/network.h"
namespace Service {
namespace NWM {
@@ -51,6 +54,135 @@ static NetworkInfo network_info;
// Event that will generate and send the 802.11 beacon frames.
static int beacon_broadcast_event;
+// Mutex to synchronize access to the list of received beacons between the emulation thread and the
+// network thread.
+static std::mutex beacon_mutex;
+
+// Number of beacons to store before we start dropping the old ones.
+// TODO(Subv): Find a more accurate value for this limit.
+constexpr size_t MaxBeaconFrames = 15;
+
+// List of the last <MaxBeaconFrames> beacons received from the network.
+static std::deque<Network::WifiPacket> received_beacons;
+
+/**
+ * Returns a list of received 802.11 beacon frames from the specified sender since the last call.
+ */
+std::deque<Network::WifiPacket> GetReceivedBeacons(const MacAddress& sender) {
+ std::lock_guard<std::mutex> lock(beacon_mutex);
+ // TODO(Subv): Filter by sender.
+ return std::move(received_beacons);
+}
+
+/// Sends a WifiPacket to the room we're currently connected to.
+void SendPacket(Network::WifiPacket& packet) {
+ // TODO(Subv): Implement.
+}
+
+// Inserts the received beacon frame in the beacon queue and removes any older beacons if the size
+// limit is exceeded.
+void HandleBeaconFrame(const Network::WifiPacket& packet) {
+ std::lock_guard<std::mutex> lock(beacon_mutex);
+
+ received_beacons.emplace_back(packet);
+
+ // Discard old beacons if the buffer is full.
+ if (received_beacons.size() > MaxBeaconFrames)
+ received_beacons.pop_front();
+}
+
+/*
+ * Returns an available index in the nodes array for the
+ * currently-hosted UDS network.
+ */
+static u16 GetNextAvailableNodeId() {
+ ASSERT_MSG(connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost),
+ "Can not accept clients if we're not hosting a network");
+
+ for (u16 index = 0; index < connection_status.max_nodes; ++index) {
+ if ((connection_status.node_bitmask & (1 << index)) == 0)
+ return index;
+ }
+
+ // Any connection attempts to an already full network should have been refused.
+ ASSERT_MSG(false, "No available connection slots in the network");
+}
+
+/*
+ * Start a connection sequence with an UDS server. The sequence starts by sending an 802.11
+ * authentication frame with SEQ1.
+ */
+void StartConnectionSequence(const MacAddress& server) {
+ ASSERT(connection_status.status == static_cast<u32>(NetworkStatus::NotConnected));
+
+ // TODO(Subv): Handle timeout.
+
+ // Send an authentication frame with SEQ1
+ using Network::WifiPacket;
+ WifiPacket auth_request;
+ auth_request.channel = network_channel;
+ auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ1);
+ auth_request.destination_address = server;
+ auth_request.type = WifiPacket::PacketType::Authentication;
+
+ SendPacket(auth_request);
+}
+
+/// Sends an Association Response frame to the specified mac address
+void SendAssociationResponseFrame(const MacAddress& address) {
+ ASSERT_MSG(connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost));
+
+ using Network::WifiPacket;
+ WifiPacket assoc_response;
+ assoc_response.channel = network_channel;
+ // TODO(Subv): This will cause multiple clients to end up with the same association id, but
+ // we're not using that for anything.
+ u16 association_id = 1;
+ assoc_response.data = GenerateAssocResponseFrame(AssocStatus::Successful, association_id,
+ network_info.network_id);
+ assoc_response.destination_address = address;
+ assoc_response.type = WifiPacket::PacketType::AssociationResponse;
+
+ SendPacket(assoc_response);
+}
+
+/*
+ * Handles the authentication request frame and sends the authentication response and association
+ * response frames. Once an Authentication frame with SEQ1 is received by the server, it responds
+ * with an Authentication frame containing SEQ2, and immediately sends an Association response frame
+ * containing the details of the access point and the assigned association id for the new client.
+ */
+void HandleAuthenticationFrame(const Network::WifiPacket& packet) {
+ // Only the SEQ1 auth frame is handled here, the SEQ2 frame doesn't need any special behavior
+ if (GetAuthenticationSeqNumber(packet.data) == AuthenticationSeq::SEQ1) {
+ ASSERT_MSG(connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost));
+
+ // Respond with an authentication response frame with SEQ2
+ using Network::WifiPacket;
+ WifiPacket auth_request;
+ auth_request.channel = network_channel;
+ auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ2);
+ auth_request.destination_address = packet.transmitter_address;
+ auth_request.type = WifiPacket::PacketType::Authentication;
+
+ SendPacket(auth_request);
+
+ SendAssociationResponseFrame(packet.transmitter_address);
+ }
+}
+
+/// Callback to parse and handle a received wifi packet.
+void OnWifiPacketReceived(const Network::WifiPacket& packet) {
+ switch (packet.type) {
+ case Network::WifiPacket::PacketType::Beacon:
+ HandleBeaconFrame(packet);
+ break;
+ case Network::WifiPacket::PacketType::Authentication:
+ HandleAuthenticationFrame(packet);
+ break;
+ }
+}
+
/**
* NWM_UDS::Shutdown service function
* Inputs:
@@ -111,8 +243,7 @@ static void RecvBeaconBroadcastData(Interface* self) {
u32 total_size = sizeof(BeaconDataReplyHeader);
// Retrieve all beacon frames that were received from the desired mac address.
- std::deque<WifiPacket> beacons =
- GetReceivedPackets(WifiPacket::PacketType::Beacon, mac_address);
+ auto beacons = GetReceivedBeacons(mac_address);
BeaconDataReplyHeader data_reply_header{};
data_reply_header.total_entries = beacons.size();
@@ -193,6 +324,9 @@ static void InitializeWithVersion(Interface* self) {
rb.Push(RESULT_SUCCESS);
rb.PushCopyHandles(Kernel::g_handle_table.Create(connection_status_event).Unwrap());
+ // TODO(Subv): Connect the OnWifiPacketReceived function to the wifi packet received callback of
+ // the room we're currently in.
+
LOG_DEBUG(Service_NWM, "called sharedmem_size=0x%08X, version=0x%08X, sharedmem_handle=0x%08X",
sharedmem_size, version, sharedmem_handle);
}
@@ -610,32 +744,23 @@ static void BeaconBroadcastCallback(u64 userdata, int cycles_late) {
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost))
return;
- // TODO(Subv): Actually send the beacon.
std::vector<u8> frame = GenerateBeaconFrame(network_info, node_info);
+ using Network::WifiPacket;
+ WifiPacket packet;
+ packet.type = WifiPacket::PacketType::Beacon;
+ packet.data = std::move(frame);
+ packet.destination_address = Network::BroadcastMac;
+ packet.channel = network_channel;
+
+ SendPacket(packet);
+
// Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late,
beacon_broadcast_event, 0);
}
/*
- * Returns an available index in the nodes array for the
- * currently-hosted UDS network.
- */
-static u32 GetNextAvailableNodeId() {
- ASSERT_MSG(connection_status.status == static_cast<u32>(NetworkStatus::ConnectedAsHost),
- "Can not accept clients if we're not hosting a network");
-
- for (unsigned index = 0; index < connection_status.max_nodes; ++index) {
- if ((connection_status.node_bitmask & (1 << index)) == 0)
- return index;
- }
-
- // Any connection attempts to an already full network should have been refused.
- ASSERT_MSG(false, "No available connection slots in the network");
-}
-
-/*
* Called when a client connects to an UDS network we're hosting,
* updates the connection status and signals the update event.
* @param network_node_id Network Node Id of the connecting client.
diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h
index 141f49f9c..f1caaf974 100644
--- a/src/core/hle/service/nwm/nwm_uds.h
+++ b/src/core/hle/service/nwm/nwm_uds.h
@@ -42,6 +42,7 @@ using NodeList = std::vector<NodeInfo>;
enum class NetworkStatus {
NotConnected = 3,
ConnectedAsHost = 6,
+ Connecting = 7,
ConnectedAsClient = 9,
ConnectedAsSpectator = 10,
};
@@ -85,6 +86,17 @@ static_assert(offsetof(NetworkInfo, oui_value) == 0xC, "oui_value is at the wron
static_assert(offsetof(NetworkInfo, wlan_comm_id) == 0x10, "wlancommid is at the wrong offset.");
static_assert(sizeof(NetworkInfo) == 0x108, "NetworkInfo has incorrect size.");
+/// Additional block tag ids in the Beacon and Association Response frames
+enum class TagId : u8 {
+ SSID = 0,
+ SupportedRates = 1,
+ DSParameterSet = 2,
+ TrafficIndicationMap = 5,
+ CountryInformation = 7,
+ ERPInformation = 42,
+ VendorSpecific = 221
+};
+
class NWM_UDS final : public Interface {
public:
NWM_UDS();
diff --git a/src/core/hle/service/nwm/uds_beacon.cpp b/src/core/hle/service/nwm/uds_beacon.cpp
index 6332b404c..552eaf65e 100644
--- a/src/core/hle/service/nwm/uds_beacon.cpp
+++ b/src/core/hle/service/nwm/uds_beacon.cpp
@@ -325,8 +325,5 @@ std::vector<u8> GenerateBeaconFrame(const NetworkInfo& network_info, const NodeL
return buffer;
}
-std::deque<WifiPacket> GetReceivedPackets(WifiPacket::PacketType type, const MacAddress& sender) {
- return {};
-}
} // namespace NWM
} // namespace Service
diff --git a/src/core/hle/service/nwm/uds_beacon.h b/src/core/hle/service/nwm/uds_beacon.h
index caacf4c6f..50cc76da2 100644
--- a/src/core/hle/service/nwm/uds_beacon.h
+++ b/src/core/hle/service/nwm/uds_beacon.h
@@ -17,17 +17,6 @@ namespace NWM {
using MacAddress = std::array<u8, 6>;
constexpr std::array<u8, 3> NintendoOUI = {0x00, 0x1F, 0x32};
-/// Additional block tag ids in the Beacon frames
-enum class TagId : u8 {
- SSID = 0,
- SupportedRates = 1,
- DSParameterSet = 2,
- TrafficIndicationMap = 5,
- CountryInformation = 7,
- ERPInformation = 42,
- VendorSpecific = 221
-};
-
/**
* Internal vendor-specific tag ids as stored inside
* VendorSpecific blocks in the Beacon frames.
@@ -135,20 +124,6 @@ struct BeaconData {
static_assert(sizeof(BeaconData) == 0x12, "BeaconData has incorrect size.");
-/// Information about a received WiFi packet.
-/// Acts as our own 802.11 header.
-struct WifiPacket {
- enum class PacketType { Beacon, Data };
-
- PacketType type; ///< The type of 802.11 frame, Beacon / Data.
-
- /// Raw 802.11 frame data, starting at the management frame header for management frames.
- std::vector<u8> data;
- MacAddress transmitter_address; ///< Mac address of the transmitter.
- MacAddress destination_address; ///< Mac address of the receiver.
- u8 channel; ///< WiFi channel where this frame was transmitted.
-};
-
/**
* Decrypts the beacon data buffer for the network described by `network_info`.
*/
@@ -161,10 +136,5 @@ void DecryptBeaconData(const NetworkInfo& network_info, std::vector<u8>& buffer)
*/
std::vector<u8> GenerateBeaconFrame(const NetworkInfo& network_info, const NodeList& nodes);
-/**
- * Returns a list of received 802.11 frames from the specified sender
- * matching the type since the last call.
- */
-std::deque<WifiPacket> GetReceivedPackets(WifiPacket::PacketType type, const MacAddress& sender);
} // namespace NWM
} // namespace Service
diff --git a/src/core/hle/service/nwm/uds_connection.cpp b/src/core/hle/service/nwm/uds_connection.cpp
new file mode 100644
index 000000000..c8a76ec2a
--- /dev/null
+++ b/src/core/hle/service/nwm/uds_connection.cpp
@@ -0,0 +1,79 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "core/hle/service/nwm/nwm_uds.h"
+#include "core/hle/service/nwm/uds_connection.h"
+#include "fmt/format.h"
+
+namespace Service {
+namespace NWM {
+
+// Note: These values were taken from a packet capture of an o3DS XL
+// broadcasting a Super Smash Bros. 4 lobby.
+constexpr u16 DefaultExtraCapabilities = 0x0431;
+
+std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq) {
+ AuthenticationFrame frame{};
+ frame.auth_seq = static_cast<u16>(seq);
+
+ std::vector<u8> data(sizeof(frame));
+ std::memcpy(data.data(), &frame, sizeof(frame));
+
+ return data;
+}
+
+AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body) {
+ AuthenticationFrame frame;
+ std::memcpy(&frame, body.data(), sizeof(frame));
+
+ return static_cast<AuthenticationSeq>(frame.auth_seq);
+}
+
+/**
+ * Generates an SSID tag of an 802.11 Beacon frame with an 8-byte character representation of the
+ * specified network id as the SSID value.
+ * @param network_id The network id to use.
+ * @returns A buffer with the SSID tag.
+ */
+static std::vector<u8> GenerateSSIDTag(u32 network_id) {
+ constexpr u8 SSIDSize = 8;
+
+ struct {
+ u8 id = static_cast<u8>(TagId::SSID);
+ u8 size = SSIDSize;
+ } tag_header;
+
+ std::vector<u8> buffer(sizeof(tag_header) + SSIDSize);
+
+ std::memcpy(buffer.data(), &tag_header, sizeof(tag_header));
+
+ std::string network_name = fmt::format("{0:08X}", network_id);
+
+ std::memcpy(buffer.data() + sizeof(tag_header), network_name.c_str(), SSIDSize);
+
+ return buffer;
+}
+
+std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id) {
+ AssociationResponseFrame frame{};
+ frame.capabilities = DefaultExtraCapabilities;
+ frame.status_code = static_cast<u16>(status);
+ // The association id is ORed with this magic value (0xC000)
+ constexpr u16 AssociationIdMagic = 0xC000;
+ frame.assoc_id = association_id | AssociationIdMagic;
+
+ std::vector<u8> data(sizeof(frame));
+ std::memcpy(data.data(), &frame, sizeof(frame));
+
+ auto ssid_tag = GenerateSSIDTag(network_id);
+ data.insert(data.end(), ssid_tag.begin(), ssid_tag.end());
+
+ // TODO(Subv): Add the SupportedRates tag.
+ // TODO(Subv): Add the DSParameterSet tag.
+ // TODO(Subv): Add the ERPInformation tag.
+ return data;
+}
+
+} // namespace NWM
+} // namespace Service
diff --git a/src/core/hle/service/nwm/uds_connection.h b/src/core/hle/service/nwm/uds_connection.h
new file mode 100644
index 000000000..73f55a4fd
--- /dev/null
+++ b/src/core/hle/service/nwm/uds_connection.h
@@ -0,0 +1,51 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <vector>
+#include "common/common_types.h"
+#include "common/swap.h"
+#include "core/hle/service/service.h"
+
+namespace Service {
+namespace NWM {
+
+/// Sequence number of the 802.11 authentication frames.
+enum class AuthenticationSeq : u16 { SEQ1 = 1, SEQ2 = 2 };
+
+enum class AuthAlgorithm : u16 { OpenSystem = 0 };
+
+enum class AuthStatus : u16 { Successful = 0 };
+
+enum class AssocStatus : u16 { Successful = 0 };
+
+struct AuthenticationFrame {
+ u16_le auth_algorithm = static_cast<u16>(AuthAlgorithm::OpenSystem);
+ u16_le auth_seq;
+ u16_le status_code = static_cast<u16>(AuthStatus::Successful);
+};
+
+static_assert(sizeof(AuthenticationFrame) == 6, "AuthenticationFrame has wrong size");
+
+struct AssociationResponseFrame {
+ u16_le capabilities;
+ u16_le status_code;
+ u16_le assoc_id;
+};
+
+static_assert(sizeof(AssociationResponseFrame) == 6, "AssociationResponseFrame has wrong size");
+
+/// Generates an 802.11 authentication frame, starting at the frame body.
+std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq);
+
+/// Returns the sequence number from the body of an Authentication frame.
+AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body);
+
+/// Generates an 802.11 association response frame with the specified status, association id and
+/// network id, starting at the frame body.
+std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id);
+
+} // namespace NWM
+} // namespace Service
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index e4b803046..dfc36748c 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -31,6 +31,7 @@
#include "core/hle/kernel/timer.h"
#include "core/hle/kernel/vm_manager.h"
#include "core/hle/kernel/wait_object.h"
+#include "core/hle/lock.h"
#include "core/hle/result.h"
#include "core/hle/service/service.h"
@@ -1188,7 +1189,7 @@ struct FunctionDef {
Func* func;
const char* name;
};
-}
+} // namespace
static const FunctionDef SVC_Table[] = {
{0x00, nullptr, "Unknown"},
@@ -1332,6 +1333,9 @@ MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
void CallSVC(u32 immediate) {
MICROPROFILE_SCOPE(Kernel_SVC);
+ // Lock the global kernel mutex when we enter the kernel HLE.
+ std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
+
const FunctionDef* info = GetSVCInfo(immediate);
if (info) {
if (info->func) {
@@ -1342,4 +1346,4 @@ void CallSVC(u32 immediate) {
}
}
-} // namespace
+} // namespace SVC
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index 6838e449c..83ad9d898 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -29,7 +29,7 @@ namespace GPU {
Regs g_regs;
/// 268MHz CPU clocks / 60Hz frames per second
-const u64 frame_ticks = BASE_CLOCK_RATE_ARM11 / SCREEN_REFRESH_RATE;
+const u64 frame_ticks = static_cast<u64>(BASE_CLOCK_RATE_ARM11 / SCREEN_REFRESH_RATE);
/// Event id for CoreTiming
static int vblank_event;
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h
index 21b127fee..e3d0a0e08 100644
--- a/src/core/hw/gpu.h
+++ b/src/core/hw/gpu.h
@@ -74,9 +74,9 @@ struct Regs {
case PixelFormat::RGB5A1:
case PixelFormat::RGBA4:
return 2;
- default:
- UNIMPLEMENTED();
}
+
+ UNREACHABLE();
}
INSERT_PADDING_WORDS(0x4);
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index c007069a9..7aff7f29b 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -20,6 +20,7 @@
#include "core/loader/ncch.h"
#include "core/loader/smdh.h"
#include "core/memory.h"
+#include "network/network.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Loader namespace
@@ -350,6 +351,13 @@ ResultStatus AppLoader_NCCH::Load() {
Core::Telemetry().AddField(Telemetry::FieldType::Session, "ProgramId", program_id);
+ if (auto room_member = Network::GetRoomMember().lock()) {
+ Network::GameInfo game_info;
+ ReadTitle(game_info.name);
+ game_info.id = ncch_header.program_id;
+ room_member->SendGameInfo(game_info);
+ }
+
is_loaded = true; // Set state to loaded
result = LoadExec(); // Load the executable into memory for booting
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 65649d9d7..097bc5b47 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -9,6 +9,7 @@
#include "common/logging/log.h"
#include "common/swap.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/lock.h"
#include "core/memory.h"
#include "core/memory_setup.h"
#include "core/mmio.h"
@@ -181,6 +182,9 @@ T Read(const VAddr vaddr) {
return value;
}
+ // The memory access might do an MMIO or cached access, so we have to lock the HLE kernel state
+ std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
+
PageType type = current_page_table->attributes[vaddr >> PAGE_BITS];
switch (type) {
case PageType::Unmapped:
@@ -219,6 +223,9 @@ void Write(const VAddr vaddr, const T data) {
return;
}
+ // The memory access might do an MMIO or cached access, so we have to lock the HLE kernel state
+ std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
+
PageType type = current_page_table->attributes[vaddr >> PAGE_BITS];
switch (type) {
case PageType::Unmapped:
@@ -746,4 +753,4 @@ boost::optional<VAddr> PhysicalToVirtualAddress(const PAddr addr) {
return boost::none;
}
-} // namespace
+} // namespace Memory
diff --git a/src/core/settings.cpp b/src/core/settings.cpp
index d4f0429d1..efcf1267d 100644
--- a/src/core/settings.cpp
+++ b/src/core/settings.cpp
@@ -36,4 +36,4 @@ void Apply() {
Service::IR::ReloadInputDevices();
}
-} // namespace
+} // namespace Settings
diff --git a/src/core/settings.h b/src/core/settings.h
index ee16bb90a..024f14666 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -15,6 +15,7 @@ enum class LayoutOption {
Default,
SingleScreen,
LargeScreen,
+ SideScreen,
};
namespace NativeButton {
@@ -70,7 +71,7 @@ enum Values {
static const std::array<const char*, NumAnalogs> mapping = {{
"circle_pad", "c_stick",
}};
-} // namespace NumAnalog
+} // namespace NativeAnalog
struct Values {
// CheckNew3DS
@@ -79,6 +80,8 @@ struct Values {
// Controls
std::array<std::string, NativeButton::NumButtons> buttons;
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
+ std::string motion_device;
+ std::string touch_device;
// Core
bool use_cpu_jit;
@@ -128,7 +131,10 @@ struct Values {
u16 gdbstub_port;
// WebService
+ bool enable_telemetry;
std::string telemetry_endpoint_url;
+ std::string citra_username;
+ std::string citra_token;
} extern values;
// a special value for Values::region_value indicating that citra will automatically select a region
@@ -136,4 +142,4 @@ struct Values {
static constexpr int REGION_VALUE_AUTO_SELECT = -1;
void Apply();
-}
+} // namespace Settings
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 94483f385..104a16cc9 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -3,8 +3,10 @@
// Refer to the license.txt file included.
#include <cstring>
+#include <cryptopp/osrng.h>
#include "common/assert.h"
+#include "common/file_util.h"
#include "common/scm_rev.h"
#include "common/x64/cpu_detect.h"
#include "core/core.h"
@@ -29,12 +31,65 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) {
UNREACHABLE();
}
+static u64 GenerateTelemetryId() {
+ u64 telemetry_id{};
+ CryptoPP::AutoSeededRandomPool rng;
+ rng.GenerateBlock(reinterpret_cast<CryptoPP::byte*>(&telemetry_id), sizeof(u64));
+ return telemetry_id;
+}
+
+u64 GetTelemetryId() {
+ u64 telemetry_id{};
+ static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
+
+ if (FileUtil::Exists(filename)) {
+ FileUtil::IOFile file(filename, "rb");
+ if (!file.IsOpen()) {
+ LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str());
+ return {};
+ }
+ file.ReadBytes(&telemetry_id, sizeof(u64));
+ } else {
+ FileUtil::IOFile file(filename, "wb");
+ if (!file.IsOpen()) {
+ LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str());
+ return {};
+ }
+ telemetry_id = GenerateTelemetryId();
+ file.WriteBytes(&telemetry_id, sizeof(u64));
+ }
+
+ return telemetry_id;
+}
+
+u64 RegenerateTelemetryId() {
+ const u64 new_telemetry_id{GenerateTelemetryId()};
+ static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
+
+ FileUtil::IOFile file(filename, "wb");
+ if (!file.IsOpen()) {
+ LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str());
+ return {};
+ }
+ file.WriteBytes(&new_telemetry_id, sizeof(u64));
+ return new_telemetry_id;
+}
+
TelemetrySession::TelemetrySession() {
#ifdef ENABLE_WEB_SERVICE
- backend = std::make_unique<WebService::TelemetryJson>();
+ if (Settings::values.enable_telemetry) {
+ backend = std::make_unique<WebService::TelemetryJson>(
+ Settings::values.telemetry_endpoint_url, Settings::values.citra_username,
+ Settings::values.citra_token);
+ } else {
+ backend = std::make_unique<Telemetry::NullVisitor>();
+ }
#else
backend = std::make_unique<Telemetry::NullVisitor>();
#endif
+ // Log one-time top-level information
+ AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
+
// Log one-time session start information
const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
diff --git a/src/core/telemetry_session.h b/src/core/telemetry_session.h
index cf53835c3..65613daae 100644
--- a/src/core/telemetry_session.h
+++ b/src/core/telemetry_session.h
@@ -35,4 +35,16 @@ private:
std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
};
+/**
+ * Gets TelemetryId, a unique identifier used for the user's telemetry sessions.
+ * @returns The current TelemetryId for the session.
+ */
+u64 GetTelemetryId();
+
+/**
+ * Regenerates TelemetryId, a unique identifier used for the user's telemetry sessions.
+ * @returns The new TelemetryId that was generated.
+ */
+u64 RegenerateTelemetryId();
+
} // namespace Core
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt
index e3e36ada7..92792a702 100644
--- a/src/input_common/CMakeLists.txt
+++ b/src/input_common/CMakeLists.txt
@@ -2,12 +2,14 @@ set(SRCS
analog_from_button.cpp
keyboard.cpp
main.cpp
+ motion_emu.cpp
)
set(HEADERS
analog_from_button.h
keyboard.h
main.h
+ motion_emu.h
)
if(SDL2_FOUND)
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 699f41e6b..557353740 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -7,6 +7,7 @@
#include "input_common/analog_from_button.h"
#include "input_common/keyboard.h"
#include "input_common/main.h"
+#include "input_common/motion_emu.h"
#ifdef HAVE_SDL2
#include "input_common/sdl/sdl.h"
#endif
@@ -14,12 +15,16 @@
namespace InputCommon {
static std::shared_ptr<Keyboard> keyboard;
+static std::shared_ptr<MotionEmu> motion_emu;
void Init() {
- keyboard = std::make_shared<InputCommon::Keyboard>();
+ keyboard = std::make_shared<Keyboard>();
Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard);
Input::RegisterFactory<Input::AnalogDevice>("analog_from_button",
- std::make_shared<InputCommon::AnalogFromButton>());
+ std::make_shared<AnalogFromButton>());
+ motion_emu = std::make_shared<MotionEmu>();
+ Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu);
+
#ifdef HAVE_SDL2
SDL::Init();
#endif
@@ -29,6 +34,8 @@ void Shutdown() {
Input::UnregisterFactory<Input::ButtonDevice>("keyboard");
keyboard.reset();
Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button");
+ Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
+ motion_emu.reset();
#ifdef HAVE_SDL2
SDL::Shutdown();
@@ -39,6 +46,10 @@ Keyboard* GetKeyboard() {
return keyboard.get();
}
+MotionEmu* GetMotionEmu() {
+ return motion_emu.get();
+}
+
std::string GenerateKeyboardParam(int key_code) {
Common::ParamPackage param{
{"engine", "keyboard"}, {"code", std::to_string(key_code)},
diff --git a/src/input_common/main.h b/src/input_common/main.h
index 140bbd014..5604f0fa8 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -11,7 +11,7 @@ namespace InputCommon {
/// Initializes and registers all built-in input device factories.
void Init();
-/// Unresisters all build-in input device factories and shut them down.
+/// Deregisters all built-in input device factories and shuts them down.
void Shutdown();
class Keyboard;
@@ -19,6 +19,11 @@ class Keyboard;
/// Gets the keyboard button device factory.
Keyboard* GetKeyboard();
+class MotionEmu;
+
+/// Gets the motion emulation factory.
+MotionEmu* GetMotionEmu();
+
/// Generates a serialized param package for creating a keyboard button device
std::string GenerateKeyboardParam(int key_code);
diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp
new file mode 100644
index 000000000..59a035e70
--- /dev/null
+++ b/src/input_common/motion_emu.cpp
@@ -0,0 +1,168 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <chrono>
+#include <mutex>
+#include <thread>
+#include <tuple>
+#include "common/math_util.h"
+#include "common/quaternion.h"
+#include "common/thread.h"
+#include "common/vector_math.h"
+#include "input_common/motion_emu.h"
+
+namespace InputCommon {
+
+// Implementation class of the motion emulation device
+class MotionEmuDevice {
+public:
+ MotionEmuDevice(int update_millisecond, float sensitivity)
+ : update_millisecond(update_millisecond),
+ update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>(
+ std::chrono::milliseconds(update_millisecond))),
+ sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {}
+
+ ~MotionEmuDevice() {
+ if (motion_emu_thread.joinable()) {
+ shutdown_event.Set();
+ motion_emu_thread.join();
+ }
+ }
+
+ void BeginTilt(int x, int y) {
+ mouse_origin = Math::MakeVec(x, y);
+ is_tilting = true;
+ }
+
+ void Tilt(int x, int y) {
+ auto mouse_move = Math::MakeVec(x, y) - mouse_origin;
+ if (is_tilting) {
+ std::lock_guard<std::mutex> guard(tilt_mutex);
+ if (mouse_move.x == 0 && mouse_move.y == 0) {
+ tilt_angle = 0;
+ } else {
+ tilt_direction = mouse_move.Cast<float>();
+ tilt_angle = MathUtil::Clamp(tilt_direction.Normalize() * sensitivity, 0.0f,
+ MathUtil::PI * 0.5f);
+ }
+ }
+ }
+
+ void EndTilt() {
+ std::lock_guard<std::mutex> guard(tilt_mutex);
+ tilt_angle = 0;
+ is_tilting = false;
+ }
+
+ std::tuple<Math::Vec3<float>, Math::Vec3<float>> GetStatus() {
+ std::lock_guard<std::mutex> guard(status_mutex);
+ return status;
+ }
+
+private:
+ const int update_millisecond;
+ const std::chrono::steady_clock::duration update_duration;
+ const float sensitivity;
+
+ Math::Vec2<int> mouse_origin;
+
+ std::mutex tilt_mutex;
+ Math::Vec2<float> tilt_direction;
+ float tilt_angle = 0;
+
+ bool is_tilting = false;
+
+ Common::Event shutdown_event;
+
+ std::tuple<Math::Vec3<float>, Math::Vec3<float>> status;
+ std::mutex status_mutex;
+
+ // Note: always keep the thread declaration at the end so that other objects are initialized
+ // before this!
+ std::thread motion_emu_thread;
+
+ void MotionEmuThread() {
+ auto update_time = std::chrono::steady_clock::now();
+ Math::Quaternion<float> q = MakeQuaternion(Math::Vec3<float>(), 0);
+ Math::Quaternion<float> old_q;
+
+ while (!shutdown_event.WaitUntil(update_time)) {
+ update_time += update_duration;
+ old_q = q;
+
+ {
+ std::lock_guard<std::mutex> guard(tilt_mutex);
+
+ // Find the quaternion describing current 3DS tilting
+ q = MakeQuaternion(Math::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x),
+ tilt_angle);
+ }
+
+ auto inv_q = q.Inverse();
+
+ // Set the gravity vector in world space
+ auto gravity = Math::MakeVec(0.0f, -1.0f, 0.0f);
+
+ // Find the angular rate vector in world space
+ auto angular_rate = ((q - old_q) * inv_q).xyz * 2;
+ angular_rate *= 1000 / update_millisecond / MathUtil::PI * 180;
+
+ // Transform the two vectors from world space to 3DS space
+ gravity = QuaternionRotate(inv_q, gravity);
+ angular_rate = QuaternionRotate(inv_q, angular_rate);
+
+ // Update the sensor state
+ {
+ std::lock_guard<std::mutex> guard(status_mutex);
+ status = std::make_tuple(gravity, angular_rate);
+ }
+ }
+ }
+};
+
+// Interface wrapper held by input receiver as a unique_ptr. It holds the implementation class as
+// a shared_ptr, which is also observed by the factory class as a weak_ptr. In this way the factory
+// can forward all the inputs to the implementation only when it is valid.
+class MotionEmuDeviceWrapper : public Input::MotionDevice {
+public:
+ MotionEmuDeviceWrapper(int update_millisecond, float sensitivity) {
+ device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity);
+ }
+
+ std::tuple<Math::Vec3<float>, Math::Vec3<float>> GetStatus() const {
+ return device->GetStatus();
+ }
+
+ std::shared_ptr<MotionEmuDevice> device;
+};
+
+std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackage& params) {
+ int update_period = params.Get("update_period", 100);
+ float sensitivity = params.Get("sensitivity", 0.01f);
+ auto device_wrapper = std::make_unique<MotionEmuDeviceWrapper>(update_period, sensitivity);
+ // Previously created device is disconnected here. Having two motion devices for 3DS is not
+ // expected.
+ current_device = device_wrapper->device;
+ return std::move(device_wrapper);
+}
+
+void MotionEmu::BeginTilt(int x, int y) {
+ if (auto ptr = current_device.lock()) {
+ ptr->BeginTilt(x, y);
+ }
+}
+
+void MotionEmu::Tilt(int x, int y) {
+ if (auto ptr = current_device.lock()) {
+ ptr->Tilt(x, y);
+ }
+}
+
+void MotionEmu::EndTilt() {
+ if (auto ptr = current_device.lock()) {
+ ptr->EndTilt();
+ }
+}
+
+} // namespace InputCommon
diff --git a/src/input_common/motion_emu.h b/src/input_common/motion_emu.h
new file mode 100644
index 000000000..7a7e22467
--- /dev/null
+++ b/src/input_common/motion_emu.h
@@ -0,0 +1,46 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/frontend/input.h"
+
+namespace InputCommon {
+
+class MotionEmuDevice;
+
+class MotionEmu : public Input::Factory<Input::MotionDevice> {
+public:
+ /**
+ * Creates a motion device emulated from mouse input
+ * @param params contains parameters for creating the device:
+ * - "update_period": update period in milliseconds
+ * - "sensitivity": the coefficient converting mouse movement to tilting angle
+ */
+ std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override;
+
+ /**
+ * Signals that a motion sensor tilt has begun.
+ * @param x the x-coordinate of the cursor
+ * @param y the y-coordinate of the cursor
+ */
+ void BeginTilt(int x, int y);
+
+ /**
+ * Signals that a motion sensor tilt is occurring.
+ * @param x the x-coordinate of the cursor
+ * @param y the y-coordinate of the cursor
+ */
+ void Tilt(int x, int y);
+
+ /**
+ * Signals that a motion sensor tilt has ended.
+ */
+ void EndTilt();
+
+private:
+ std::weak_ptr<MotionEmuDevice> current_device;
+};
+
+} // namespace InputCommon
diff --git a/src/input_common/sdl/sdl.cpp b/src/input_common/sdl/sdl.cpp
index 756ee58b7..d404afa89 100644
--- a/src/input_common/sdl/sdl.cpp
+++ b/src/input_common/sdl/sdl.cpp
@@ -159,7 +159,7 @@ public:
* - "axis"(optional): the index of the axis to bind
* - "direction"(only used for hat): the direction name of the hat to bind. Can be "up",
* "down", "left" or "right"
- * - "threshould"(only used for axis): a float value in (-1.0, 1.0) which the button is
+ * - "threshold"(only used for axis): a float value in (-1.0, 1.0) which the button is
* triggered if the axis value crosses
* - "direction"(only used for axis): "+" means the button is triggered when the axis value
* is greater than the threshold; "-" means the button is triggered when the axis value
diff --git a/src/network/packet.cpp b/src/network/packet.cpp
index 660e92c0d..cc60f2fbc 100644
--- a/src/network/packet.cpp
+++ b/src/network/packet.cpp
@@ -13,6 +13,18 @@
namespace Network {
+#ifndef htonll
+u64 htonll(u64 x) {
+ return ((1 == htonl(1)) ? (x) : ((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32));
+}
+#endif
+
+#ifndef ntohll
+u64 ntohll(u64 x) {
+ return ((1 == ntohl(1)) ? (x) : ((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32));
+}
+#endif
+
void Packet::Append(const void* in_data, std::size_t size_in_bytes) {
if (in_data && (size_in_bytes > 0)) {
std::size_t start = data.size();
@@ -100,6 +112,20 @@ Packet& Packet::operator>>(u32& out_data) {
return *this;
}
+Packet& Packet::operator>>(s64& out_data) {
+ s64 value;
+ Read(&value, sizeof(value));
+ out_data = ntohll(value);
+ return *this;
+}
+
+Packet& Packet::operator>>(u64& out_data) {
+ u64 value;
+ Read(&value, sizeof(value));
+ out_data = ntohll(value);
+ return *this;
+}
+
Packet& Packet::operator>>(float& out_data) {
Read(&out_data, sizeof(out_data));
return *this;
@@ -183,6 +209,18 @@ Packet& Packet::operator<<(u32 in_data) {
return *this;
}
+Packet& Packet::operator<<(s64 in_data) {
+ s64 toWrite = htonll(in_data);
+ Append(&toWrite, sizeof(toWrite));
+ return *this;
+}
+
+Packet& Packet::operator<<(u64 in_data) {
+ u64 toWrite = htonll(in_data);
+ Append(&toWrite, sizeof(toWrite));
+ return *this;
+}
+
Packet& Packet::operator<<(float in_data) {
Append(&in_data, sizeof(in_data));
return *this;
diff --git a/src/network/packet.h b/src/network/packet.h
index 94b351ab1..5a2e58dc2 100644
--- a/src/network/packet.h
+++ b/src/network/packet.h
@@ -72,6 +72,8 @@ public:
Packet& operator>>(u16& out_data);
Packet& operator>>(s32& out_data);
Packet& operator>>(u32& out_data);
+ Packet& operator>>(s64& out_data);
+ Packet& operator>>(u64& out_data);
Packet& operator>>(float& out_data);
Packet& operator>>(double& out_data);
Packet& operator>>(char* out_data);
@@ -89,6 +91,8 @@ public:
Packet& operator<<(u16 in_data);
Packet& operator<<(s32 in_data);
Packet& operator<<(u32 in_data);
+ Packet& operator<<(s64 in_data);
+ Packet& operator<<(u64 in_data);
Packet& operator<<(float in_data);
Packet& operator<<(double in_data);
Packet& operator<<(const char* in_data);
diff --git a/src/network/room.cpp b/src/network/room.cpp
index fbbaf8b93..261049ab0 100644
--- a/src/network/room.cpp
+++ b/src/network/room.cpp
@@ -4,9 +4,9 @@
#include <algorithm>
#include <atomic>
+#include <mutex>
#include <random>
#include <thread>
-#include <vector>
#include "enet/enet.h"
#include "network/packet.h"
#include "network/room.h"
@@ -29,12 +29,14 @@ public:
struct Member {
std::string nickname; ///< The nickname of the member.
- std::string game_name; ///< The current game of the member
+ GameInfo game_info; ///< The current game of the member
MacAddress mac_address; ///< The assigned mac address of the member.
ENetPeer* peer; ///< The remote peer.
};
using MemberList = std::vector<Member>;
- MemberList members; ///< Information about the members of this room.
+ MemberList members; ///< Information about the members of this room
+ mutable std::mutex member_mutex; ///< Mutex for locking the members list
+ /// This should be a std::shared_mutex as soon as C++17 is supported
RoomImpl()
: random_gen(std::random_device()()), NintendoOUI{0x00, 0x1F, 0x32, 0x00, 0x00, 0x00} {}
@@ -147,7 +149,7 @@ void Room::RoomImpl::ServerLoop() {
case IdJoinRequest:
HandleJoinRequest(&event);
break;
- case IdSetGameName:
+ case IdSetGameInfo:
HandleGameNamePacket(&event);
break;
case IdWifiPacket:
@@ -213,7 +215,10 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
member.nickname = nickname;
member.peer = event->peer;
- members.push_back(std::move(member));
+ {
+ std::lock_guard<std::mutex> lock(member_mutex);
+ members.push_back(std::move(member));
+ }
// Notify everyone that the room information has changed.
BroadcastRoomInformation();
@@ -223,12 +228,14 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
bool Room::RoomImpl::IsValidNickname(const std::string& nickname) const {
// A nickname is valid if it is not already taken by anybody else in the room.
// TODO(B3N30): Check for empty names, spaces, etc.
+ std::lock_guard<std::mutex> lock(member_mutex);
return std::all_of(members.begin(), members.end(),
[&nickname](const auto& member) { return member.nickname != nickname; });
}
bool Room::RoomImpl::IsValidMacAddress(const MacAddress& address) const {
// A MAC address is valid if it is not already taken by anybody else in the room.
+ std::lock_guard<std::mutex> lock(member_mutex);
return std::all_of(members.begin(), members.end(),
[&address](const auto& member) { return member.mac_address != address; });
}
@@ -279,6 +286,7 @@ void Room::RoomImpl::SendCloseMessage() {
packet << static_cast<u8>(IdCloseRoom);
ENetPacket* enet_packet =
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
+ std::lock_guard<std::mutex> lock(member_mutex);
for (auto& member : members) {
enet_peer_send(member.peer, 0, enet_packet);
}
@@ -295,10 +303,14 @@ void Room::RoomImpl::BroadcastRoomInformation() {
packet << room_information.member_slots;
packet << static_cast<u32>(members.size());
- for (const auto& member : members) {
- packet << member.nickname;
- packet << member.mac_address;
- packet << member.game_name;
+ {
+ std::lock_guard<std::mutex> lock(member_mutex);
+ for (const auto& member : members) {
+ packet << member.nickname;
+ packet << member.mac_address;
+ packet << member.game_info.name;
+ packet << member.game_info.id;
+ }
}
ENetPacket* enet_packet =
@@ -335,11 +347,13 @@ void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) {
ENET_PACKET_FLAG_RELIABLE);
if (destination_address == BroadcastMac) { // Send the data to everyone except the sender
+ std::lock_guard<std::mutex> lock(member_mutex);
for (const auto& member : members) {
if (member.peer != event->peer)
enet_peer_send(member.peer, 0, enet_packet);
}
} else { // Send the data only to the destination client
+ std::lock_guard<std::mutex> lock(member_mutex);
auto member = std::find_if(members.begin(), members.end(),
[destination_address](const Member& member) -> bool {
return member.mac_address == destination_address;
@@ -361,6 +375,8 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) {
auto CompareNetworkAddress = [event](const Member member) -> bool {
return member.peer == event->peer;
};
+
+ std::lock_guard<std::mutex> lock(member_mutex);
const auto sending_member = std::find_if(members.begin(), members.end(), CompareNetworkAddress);
if (sending_member == members.end()) {
return; // Received a chat message from a unknown sender
@@ -385,22 +401,32 @@ void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) {
in_packet.Append(event->packet->data, event->packet->dataLength);
in_packet.IgnoreBytes(sizeof(u8)); // Igonore the message type
- std::string game_name;
- in_packet >> game_name;
- auto member =
- std::find_if(members.begin(), members.end(),
- [event](const Member& member) -> bool { return member.peer == event->peer; });
- if (member != members.end()) {
- member->game_name = game_name;
- BroadcastRoomInformation();
+ GameInfo game_info;
+ in_packet >> game_info.name;
+ in_packet >> game_info.id;
+
+ {
+ std::lock_guard<std::mutex> lock(member_mutex);
+ auto member =
+ std::find_if(members.begin(), members.end(), [event](const Member& member) -> bool {
+ return member.peer == event->peer;
+ });
+ if (member != members.end()) {
+ member->game_info = game_info;
+ }
}
+ BroadcastRoomInformation();
}
void Room::RoomImpl::HandleClientDisconnection(ENetPeer* client) {
// Remove the client from the members list.
- members.erase(std::remove_if(members.begin(), members.end(),
- [client](const Member& member) { return member.peer == client; }),
- members.end());
+ {
+ std::lock_guard<std::mutex> lock(member_mutex);
+ members.erase(
+ std::remove_if(members.begin(), members.end(),
+ [client](const Member& member) { return member.peer == client; }),
+ members.end());
+ }
// Announce the change to all clients.
enet_peer_disconnect(client, 0);
@@ -437,6 +463,19 @@ const RoomInformation& Room::GetRoomInformation() const {
return room_impl->room_information;
}
+std::vector<Room::Member> Room::GetRoomMemberList() const {
+ std::vector<Room::Member> member_list;
+ std::lock_guard<std::mutex> lock(room_impl->member_mutex);
+ for (const auto& member_impl : room_impl->members) {
+ Member member;
+ member.nickname = member_impl.nickname;
+ member.mac_address = member_impl.mac_address;
+ member.game_info = member_impl.game_info;
+ member_list.push_back(member);
+ }
+ return member_list;
+};
+
void Room::Destroy() {
room_impl->state = State::Closed;
room_impl->room_thread->join();
@@ -447,7 +486,10 @@ void Room::Destroy() {
}
room_impl->room_information = {};
room_impl->server = nullptr;
- room_impl->members.clear();
+ {
+ std::lock_guard<std::mutex> lock(room_impl->member_mutex);
+ room_impl->members.clear();
+ }
room_impl->room_information.member_slots = 0;
room_impl->room_information.name.clear();
}
diff --git a/src/network/room.h b/src/network/room.h
index 65b0d008a..8285a4d0c 100644
--- a/src/network/room.h
+++ b/src/network/room.h
@@ -7,6 +7,7 @@
#include <array>
#include <memory>
#include <string>
+#include <vector>
#include "common/common_types.h"
namespace Network {
@@ -21,6 +22,11 @@ struct RoomInformation {
u32 member_slots; ///< Maximum number of members in this room
};
+struct GameInfo {
+ std::string name{""};
+ u64 id{0};
+};
+
using MacAddress = std::array<u8, 6>;
/// A special MAC address that tells the room we're joining to assign us a MAC address
/// automatically.
@@ -34,7 +40,7 @@ enum RoomMessageTypes : u8 {
IdJoinRequest = 1,
IdJoinSuccess,
IdRoomInformation,
- IdSetGameName,
+ IdSetGameInfo,
IdWifiPacket,
IdChatMessage,
IdNameCollision,
@@ -51,6 +57,12 @@ public:
Closed, ///< The room is not opened and can not accept connections.
};
+ struct Member {
+ std::string nickname; ///< The nickname of the member.
+ GameInfo game_info; ///< The current game of the member
+ MacAddress mac_address; ///< The assigned mac address of the member.
+ };
+
Room();
~Room();
@@ -65,6 +77,11 @@ public:
const RoomInformation& GetRoomInformation() const;
/**
+ * Gets a list of the mbmers connected to the room.
+ */
+ std::vector<Member> GetRoomMemberList() const;
+
+ /**
* Creates the socket for this room. Will bind to default address if
* server is empty string.
*/
diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp
index dac9bacae..f229ec6fd 100644
--- a/src/network/room_member.cpp
+++ b/src/network/room_member.cpp
@@ -5,6 +5,7 @@
#include <atomic>
#include <list>
#include <mutex>
+#include <set>
#include <thread>
#include "common/assert.h"
#include "enet/enet.h"
@@ -25,6 +26,9 @@ public:
/// Information about the room we're connected to.
RoomInformation room_information;
+ /// The current game name, id and version
+ GameInfo current_game_info;
+
std::atomic<State> state{State::Idle}; ///< Current state of the RoomMember.
void SetState(const State new_state);
bool IsConnected() const;
@@ -37,6 +41,24 @@ public:
std::unique_ptr<std::thread> loop_thread;
std::mutex send_list_mutex; ///< Mutex that controls access to the `send_list` variable.
std::list<Packet> send_list; ///< A list that stores all packets to send the async
+
+ template <typename T>
+ using CallbackSet = std::set<CallbackHandle<T>>;
+ std::mutex callback_mutex; ///< The mutex used for handling callbacks
+
+ class Callbacks {
+ public:
+ template <typename T>
+ CallbackSet<T>& Get();
+
+ private:
+ CallbackSet<WifiPacket> callback_set_wifi_packet;
+ CallbackSet<ChatEntry> callback_set_chat_messages;
+ CallbackSet<RoomInformation> callback_set_room_information;
+ CallbackSet<State> callback_set_state;
+ };
+ Callbacks callbacks; ///< All CallbackSets to all events
+
void MemberLoop();
void StartLoop();
@@ -84,12 +106,20 @@ public:
* Disconnects the RoomMember from the Room
*/
void Disconnect();
+
+ template <typename T>
+ void Invoke(const T& data);
+
+ template <typename T>
+ CallbackHandle<T> Bind(std::function<void(const T&)> callback);
};
// RoomMemberImpl
void RoomMember::RoomMemberImpl::SetState(const State new_state) {
- state = new_state;
- // TODO(B3N30): Invoke the callback functions
+ if (state != new_state) {
+ state = new_state;
+ Invoke<State>(state);
+ }
}
bool RoomMember::RoomMemberImpl::IsConnected() const {
@@ -195,9 +225,10 @@ void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* ev
for (auto& member : member_information) {
packet >> member.nickname;
packet >> member.mac_address;
- packet >> member.game_name;
+ packet >> member.game_info.name;
+ packet >> member.game_info.id;
}
- // TODO(B3N30): Invoke callbacks
+ Invoke(room_information);
}
void RoomMember::RoomMemberImpl::HandleJoinPacket(const ENetEvent* event) {
@@ -209,7 +240,7 @@ void RoomMember::RoomMemberImpl::HandleJoinPacket(const ENetEvent* event) {
// Parse the MAC Address from the packet
packet >> mac_address;
- // TODO(B3N30): Invoke callbacks
+ SetState(State::Joined);
}
void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) {
@@ -235,7 +266,7 @@ void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) {
packet >> wifi_packet.data;
- // TODO(B3N30): Invoke callbacks
+ Invoke<WifiPacket>(wifi_packet);
}
void RoomMember::RoomMemberImpl::HandleChatPacket(const ENetEvent* event) {
@@ -248,7 +279,7 @@ void RoomMember::RoomMemberImpl::HandleChatPacket(const ENetEvent* event) {
ChatEntry chat_entry{};
packet >> chat_entry.nickname;
packet >> chat_entry.message;
- // TODO(B3N30): Invoke callbacks
+ Invoke<ChatEntry>(chat_entry);
}
void RoomMember::RoomMemberImpl::Disconnect() {
@@ -276,6 +307,46 @@ void RoomMember::RoomMemberImpl::Disconnect() {
server = nullptr;
}
+template <>
+RoomMember::RoomMemberImpl::CallbackSet<WifiPacket>& RoomMember::RoomMemberImpl::Callbacks::Get() {
+ return callback_set_wifi_packet;
+}
+
+template <>
+RoomMember::RoomMemberImpl::CallbackSet<RoomMember::State>&
+RoomMember::RoomMemberImpl::Callbacks::Get() {
+ return callback_set_state;
+}
+
+template <>
+RoomMember::RoomMemberImpl::CallbackSet<RoomInformation>&
+RoomMember::RoomMemberImpl::Callbacks::Get() {
+ return callback_set_room_information;
+}
+
+template <>
+RoomMember::RoomMemberImpl::CallbackSet<ChatEntry>& RoomMember::RoomMemberImpl::Callbacks::Get() {
+ return callback_set_chat_messages;
+}
+
+template <typename T>
+void RoomMember::RoomMemberImpl::Invoke(const T& data) {
+ std::lock_guard<std::mutex> lock(callback_mutex);
+ CallbackSet<T> callback_set = callbacks.Get<T>();
+ for (auto const& callback : callback_set)
+ (*callback)(data);
+}
+
+template <typename T>
+RoomMember::CallbackHandle<T> RoomMember::RoomMemberImpl::Bind(
+ std::function<void(const T&)> callback) {
+ std::lock_guard<std::mutex> lock(callback_mutex);
+ CallbackHandle<T> handle;
+ handle = std::make_shared<std::function<void(const T&)>>(callback);
+ callbacks.Get<T>().insert(handle);
+ return handle;
+}
+
// RoomMember
RoomMember::RoomMember() : room_member_impl{std::make_unique<RoomMemberImpl>()} {
room_member_impl->client = enet_host_create(nullptr, 1, NumChannels, 0, 0);
@@ -339,6 +410,7 @@ void RoomMember::Join(const std::string& nick, const char* server_addr, u16 serv
room_member_impl->SetState(State::Joining);
room_member_impl->StartLoop();
room_member_impl->SendJoinRequest(nick, preferred_mac);
+ SendGameInfo(room_member_impl->current_game_info);
} else {
room_member_impl->SetState(State::CouldNotConnect);
}
@@ -366,17 +438,53 @@ void RoomMember::SendChatMessage(const std::string& message) {
room_member_impl->Send(std::move(packet));
}
-void RoomMember::SendGameName(const std::string& game_name) {
+void RoomMember::SendGameInfo(const GameInfo& game_info) {
+ room_member_impl->current_game_info = game_info;
+ if (!IsConnected())
+ return;
+
Packet packet;
- packet << static_cast<u8>(IdSetGameName);
- packet << game_name;
+ packet << static_cast<u8>(IdSetGameInfo);
+ packet << game_info.name;
+ packet << game_info.id;
room_member_impl->Send(std::move(packet));
}
+RoomMember::CallbackHandle<RoomMember::State> RoomMember::BindOnStateChanged(
+ std::function<void(const RoomMember::State&)> callback) {
+ return room_member_impl->Bind(callback);
+}
+
+RoomMember::CallbackHandle<WifiPacket> RoomMember::BindOnWifiPacketReceived(
+ std::function<void(const WifiPacket&)> callback) {
+ return room_member_impl->Bind(callback);
+}
+
+RoomMember::CallbackHandle<RoomInformation> RoomMember::BindOnRoomInformationChanged(
+ std::function<void(const RoomInformation&)> callback) {
+ return room_member_impl->Bind(callback);
+}
+
+RoomMember::CallbackHandle<ChatEntry> RoomMember::BindOnChatMessageRecieved(
+ std::function<void(const ChatEntry&)> callback) {
+ return room_member_impl->Bind(callback);
+}
+
+template <typename T>
+void RoomMember::Unbind(CallbackHandle<T> handle) {
+ std::lock_guard<std::mutex> lock(room_member_impl->callback_mutex);
+ room_member_impl->callbacks.Get<T>().erase(handle);
+}
+
void RoomMember::Leave() {
room_member_impl->SetState(State::Idle);
room_member_impl->loop_thread->join();
room_member_impl->loop_thread.reset();
}
+template void RoomMember::Unbind(CallbackHandle<WifiPacket>);
+template void RoomMember::Unbind(CallbackHandle<RoomMember::State>);
+template void RoomMember::Unbind(CallbackHandle<RoomInformation>);
+template void RoomMember::Unbind(CallbackHandle<ChatEntry>);
+
} // namespace Network
diff --git a/src/network/room_member.h b/src/network/room_member.h
index bc1af3a7e..98770a234 100644
--- a/src/network/room_member.h
+++ b/src/network/room_member.h
@@ -4,6 +4,7 @@
#pragma once
+#include <functional>
#include <memory>
#include <string>
#include <vector>
@@ -53,12 +54,23 @@ public:
struct MemberInformation {
std::string nickname; ///< Nickname of the member.
- std::string game_name; ///< Name of the game they're currently playing, or empty if they're
+ GameInfo game_info; ///< Name of the game they're currently playing, or empty if they're
/// not playing anything.
MacAddress mac_address; ///< MAC address associated with this member.
};
using MemberList = std::vector<MemberInformation>;
+ // The handle for the callback functions
+ template <typename T>
+ using CallbackHandle = std::shared_ptr<std::function<void(const T&)>>;
+
+ /**
+ * Unbinds a callback function from the events.
+ * @param handle The connection handle to disconnect
+ */
+ template <typename T>
+ void Unbind(CallbackHandle<T> handle);
+
RoomMember();
~RoomMember();
@@ -113,10 +125,49 @@ public:
void SendChatMessage(const std::string& message);
/**
- * Sends the current game name to the room.
- * @param game_name The game name.
+ * Sends the current game info to the room.
+ * @param game_info The game information.
+ */
+ void SendGameInfo(const GameInfo& game_info);
+
+ /**
+ * Binds a function to an event that will be triggered every time the State of the member
+ * changed. The function wil be called every time the event is triggered. The callback function
+ * must not bind or unbind a function. Doing so will cause a deadlock
+ * @param callback The function to call
+ * @return A handle used for removing the function from the registered list
+ */
+ CallbackHandle<State> BindOnStateChanged(std::function<void(const State&)> callback);
+
+ /**
+ * Binds a function to an event that will be triggered every time a WifiPacket is received.
+ * The function wil be called everytime the event is triggered.
+ * The callback function must not bind or unbind a function. Doing so will cause a deadlock
+ * @param callback The function to call
+ * @return A handle used for removing the function from the registered list
+ */
+ CallbackHandle<WifiPacket> BindOnWifiPacketReceived(
+ std::function<void(const WifiPacket&)> callback);
+
+ /**
+ * Binds a function to an event that will be triggered every time the RoomInformation changes.
+ * The function wil be called every time the event is triggered.
+ * The callback function must not bind or unbind a function. Doing so will cause a deadlock
+ * @param callback The function to call
+ * @return A handle used for removing the function from the registered list
+ */
+ CallbackHandle<RoomInformation> BindOnRoomInformationChanged(
+ std::function<void(const RoomInformation&)> callback);
+
+ /**
+ * Binds a function to an event that will be triggered every time a ChatMessage is received.
+ * The function wil be called every time the event is triggered.
+ * The callback function must not bind or unbind a function. Doing so will cause a deadlock
+ * @param callback The function to call
+ * @return A handle used for removing the function from the registered list
*/
- void SendGameName(const std::string& game_name);
+ CallbackHandle<ChatEntry> BindOnChatMessageRecieved(
+ std::function<void(const ChatEntry&)> callback);
/**
* Leaves the current room.
diff --git a/src/video_core/regs_framebuffer.h b/src/video_core/regs_framebuffer.h
index a50bd4111..7b565f911 100644
--- a/src/video_core/regs_framebuffer.h
+++ b/src/video_core/regs_framebuffer.h
@@ -256,10 +256,9 @@ struct FramebufferRegs {
return 3;
case DepthFormat::D24S8:
return 4;
- default:
- LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
- UNIMPLEMENTED();
}
+
+ ASSERT_MSG(false, "Unknown depth format %u", format);
}
// Returns the number of bits per depth component of the specified depth format
@@ -270,10 +269,9 @@ struct FramebufferRegs {
case DepthFormat::D24:
case DepthFormat::D24S8:
return 24;
- default:
- LOG_CRITICAL(HW_GPU, "Unknown depth format %u", format);
- UNIMPLEMENTED();
}
+
+ ASSERT_MSG(false, "Unknown depth format %u", format);
}
INSERT_PADDING_WORDS(0x20);
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 1c6c15a58..aa95ef21d 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -28,6 +28,9 @@ MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) {
+ // Clipping plane 0 is always enabled for PICA fixed clip plane z <= 0
+ state.clip_distance[0] = true;
+
// Create sampler objects
for (size_t i = 0; i < texture_samplers.size(); ++i) {
texture_samplers[i].Create();
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index bb192affd..c536e61e1 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -8,6 +8,7 @@
#include "common/assert.h"
#include "common/bit_field.h"
#include "common/logging/log.h"
+#include "core/core.h"
#include "video_core/regs_framebuffer.h"
#include "video_core/regs_lighting.h"
#include "video_core/regs_rasterizer.h"
@@ -525,11 +526,12 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
"float geo_factor = 1.0;\n";
// Compute fragment normals and tangents
- const std::string pertubation =
- "2.0 * (" + SampleTexture(config, lighting.bump_selector) + ").rgb - 1.0";
+ auto Perturbation = [&]() {
+ return "2.0 * (" + SampleTexture(config, lighting.bump_selector) + ").rgb - 1.0";
+ };
if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) {
// Bump mapping is enabled using a normal map
- out += "vec3 surface_normal = " + pertubation + ";\n";
+ out += "vec3 surface_normal = " + Perturbation() + ";\n";
// Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher
// precision result
@@ -543,7 +545,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
out += "vec3 surface_tangent = vec3(1.0, 0.0, 0.0);\n";
} else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
// Bump mapping is enabled using a tangent map
- out += "vec3 surface_tangent = " + pertubation + ";\n";
+ out += "vec3 surface_tangent = " + Perturbation() + ";\n";
// Mathematically, recomputing Z-component of the tangent vector won't affect the relevant
// computation below, which is also confirmed on 3DS. So we don't bother recomputing here
// even if 'renorm' is enabled.
@@ -593,8 +595,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
// Note: even if the normal vector is modified by normal map, which is not the
// normal of the tangent plane anymore, the half angle vector is still projected
// using the modified normal vector.
- std::string half_angle_proj = "normalize(half_vector) - normal / dot(normal, "
- "normal) * dot(normal, normalize(half_vector))";
+ std::string half_angle_proj =
+ "normalize(half_vector) - normal * dot(normal, normalize(half_vector))";
// Note: the half angle vector projection is confirmed not normalized before the dot
// product. The result is in fact not cos(phi) as the name suggested.
index = "dot(" + half_angle_proj + ", tangent)";
@@ -749,7 +751,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
}
// Fresnel
- if (lighting.lut_fr.enable &&
+ // Note: only the last entry in the light slots applies the Fresnel factor
+ if (light_index == lighting.src_num - 1 && lighting.lut_fr.enable &&
LightingRegs::IsLightingSamplerSupported(lighting.config,
LightingRegs::LightingSampler::Fresnel)) {
// Lookup fresnel LUT value
@@ -758,17 +761,17 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
lighting.lut_fr.type, lighting.lut_fr.abs_input);
value = "(" + std::to_string(lighting.lut_fr.scale) + " * " + value + ")";
- // Enabled for difffuse lighting alpha component
+ // Enabled for diffuse lighting alpha component
if (lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::PrimaryAlpha ||
lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
- out += "diffuse_sum.a *= " + value + ";\n";
+ out += "diffuse_sum.a = " + value + ";\n";
}
// Enabled for the specular lighting alpha component
if (lighting.fresnel_selector ==
LightingRegs::LightingFresnelSelector::SecondaryAlpha ||
lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
- out += "specular_sum.a *= " + value + ";\n";
+ out += "specular_sum.a = " + value + ";\n";
}
}
@@ -1111,7 +1114,10 @@ vec4 secondary_fragment_color = vec4(0.0);
"gl_FragCoord.y < scissor_y2)) discard;\n";
}
- out += "float z_over_w = 1.0 - gl_FragCoord.z * 2.0;\n";
+ // After perspective divide, OpenGL transform z_over_w from [-1, 1] to [near, far]. Here we use
+ // default near = 0 and far = 1, and undo the transformation to get the original z_over_w, then
+ // do our own transformation according to PICA specification.
+ out += "float z_over_w = 2.0 * gl_FragCoord.z - 1.0;\n";
out += "float depth = z_over_w * depth_scale + depth_offset;\n";
if (state.depthmap_enable == RasterizerRegs::DepthBuffering::WBuffering) {
out += "depth /= gl_FragCoord.w;\n";
@@ -1151,6 +1157,11 @@ vec4 secondary_fragment_color = vec4(0.0);
// Blend the fog
out += "last_tex_env_out.rgb = mix(fog_color.rgb, last_tex_env_out.rgb, fog_factor);\n";
+ } else if (state.fog_mode == TexturingRegs::FogMode::Gas) {
+ Core::Telemetry().AddField(Telemetry::FieldType::Session, "VideoCore_Pica_UseGasMode",
+ true);
+ LOG_CRITICAL(Render_OpenGL, "Unimplemented gas mode");
+ UNIMPLEMENTED();
}
out += "gl_FragDepth = depth;\n";
@@ -1194,7 +1205,9 @@ void main() {
texcoord0_w = vert_texcoord0_w;
normquat = vert_normquat;
view = vert_view;
- gl_Position = vec4(vert_position.x, vert_position.y, -vert_position.z, vert_position.w);
+ gl_Position = vert_position;
+ gl_ClipDistance[0] = -vert_position.z; // fixed PICA clipping plane z <= 0
+ // TODO (wwylele): calculate gl_ClipDistance[1] from user-defined clipping plane
}
)";
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index bc9d34b84..06a905766 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -68,6 +68,8 @@ OpenGLState::OpenGLState() {
draw.vertex_buffer = 0;
draw.uniform_buffer = 0;
draw.shader_program = 0;
+
+ clip_distance = {};
}
void OpenGLState::Apply() const {
@@ -261,6 +263,17 @@ void OpenGLState::Apply() const {
glUseProgram(draw.shader_program);
}
+ // Clip distance
+ for (size_t i = 0; i < clip_distance.size(); ++i) {
+ if (clip_distance[i] != cur_state.clip_distance[i]) {
+ if (clip_distance[i]) {
+ glEnable(GL_CLIP_DISTANCE0 + i);
+ } else {
+ glDisable(GL_CLIP_DISTANCE0 + i);
+ }
+ }
+ }
+
cur_state = *this;
}
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 745a74479..437fe34c4 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -4,6 +4,7 @@
#pragma once
+#include <array>
#include <glad/glad.h>
namespace TextureUnits {
@@ -123,6 +124,8 @@ public:
GLuint shader_program; // GL_CURRENT_PROGRAM
} draw;
+ std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE
+
OpenGLState();
/// Get the currently active OpenGL state
diff --git a/src/video_core/swrasterizer/clipper.cpp b/src/video_core/swrasterizer/clipper.cpp
index 7537689b7..cdbc71502 100644
--- a/src/video_core/swrasterizer/clipper.cpp
+++ b/src/video_core/swrasterizer/clipper.cpp
@@ -125,10 +125,6 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu
{Math::MakeVec(f0, f0, f0, -f1), Math::Vec4<float24>(f0, f0, f0, EPSILON)}, // w = EPSILON
}};
- // TODO: If one vertex lies outside one of the depth clipping planes, some platforms (e.g. Wii)
- // drop the whole primitive instead of clipping the primitive properly. We should test if
- // this happens on the 3DS, too.
-
// Simple implementation of the Sutherland-Hodgman clipping algorithm.
// TODO: Make this less inefficient (currently lots of useless buffering overhead happens here)
for (auto edge : clipping_edges) {
diff --git a/src/video_core/swrasterizer/framebuffer.cpp b/src/video_core/swrasterizer/framebuffer.cpp
index 7de3aac75..f34eab6cf 100644
--- a/src/video_core/swrasterizer/framebuffer.cpp
+++ b/src/video_core/swrasterizer/framebuffer.cpp
@@ -352,6 +352,8 @@ u8 LogicOp(u8 src, u8 dest, FramebufferRegs::LogicOp op) {
case FramebufferRegs::LogicOp::OrInverted:
return ~src | dest;
}
+
+ UNREACHABLE();
};
} // namespace Rasterizer
diff --git a/src/video_core/swrasterizer/lighting.cpp b/src/video_core/swrasterizer/lighting.cpp
index 63088eee8..5fa748611 100644
--- a/src/video_core/swrasterizer/lighting.cpp
+++ b/src/video_core/swrasterizer/lighting.cpp
@@ -22,18 +22,37 @@ static float LookupLightingLut(const Pica::State::Lighting& lighting, size_t lut
std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
const Pica::LightingRegs& lighting, const Pica::State::Lighting& lighting_state,
- const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view) {
+ const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view,
+ const Math::Vec4<u8> (&texture_color)[4]) {
- // TODO(Subv): Bump mapping
- Math::Vec3<float> surface_normal = {0.0f, 0.0f, 1.0f};
+ Math::Vec3<float> surface_normal;
+ Math::Vec3<float> surface_tangent;
if (lighting.config0.bump_mode != LightingRegs::LightingBumpMode::None) {
- LOG_CRITICAL(HW_GPU, "unimplemented bump mapping");
- UNIMPLEMENTED();
+ Math::Vec3<float> perturbation =
+ texture_color[lighting.config0.bump_selector].xyz().Cast<float>() / 127.5f -
+ Math::MakeVec(1.0f, 1.0f, 1.0f);
+ if (lighting.config0.bump_mode == LightingRegs::LightingBumpMode::NormalMap) {
+ if (!lighting.config0.disable_bump_renorm) {
+ const float z_square = 1 - perturbation.xy().Length2();
+ perturbation.z = std::sqrt(std::max(z_square, 0.0f));
+ }
+ surface_normal = perturbation;
+ surface_tangent = Math::MakeVec(1.0f, 0.0f, 0.0f);
+ } else if (lighting.config0.bump_mode == LightingRegs::LightingBumpMode::TangentMap) {
+ surface_normal = Math::MakeVec(0.0f, 0.0f, 1.0f);
+ surface_tangent = perturbation;
+ } else {
+ LOG_ERROR(HW_GPU, "Unknown bump mode %u", lighting.config0.bump_mode.Value());
+ }
+ } else {
+ surface_normal = Math::MakeVec(0.0f, 0.0f, 1.0f);
+ surface_tangent = Math::MakeVec(1.0f, 0.0f, 0.0f);
}
// Use the normalized the quaternion when performing the rotation
auto normal = Math::QuaternionRotate(normquat, surface_normal);
+ auto tangent = Math::QuaternionRotate(normquat, surface_tangent);
Math::Vec4<float> diffuse_sum = {0.0f, 0.0f, 0.0f, 1.0f};
Math::Vec4<float> specular_sum = {0.0f, 0.0f, 0.0f, 1.0f};
@@ -55,6 +74,9 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
light_vector.Normalize();
+ Math::Vec3<float> norm_view = view.Normalized();
+ Math::Vec3<float> half_vector = norm_view + light_vector;
+
float dist_atten = 1.0f;
if (!lighting.IsDistAttenDisabled(num)) {
auto distance = (-view - position).Length();
@@ -74,17 +96,15 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
auto GetLutValue = [&](LightingRegs::LightingLutInput input, bool abs,
LightingRegs::LightingScale scale_enum,
LightingRegs::LightingSampler sampler) {
- Math::Vec3<float> norm_view = view.Normalized();
- Math::Vec3<float> half_angle = (norm_view + light_vector).Normalized();
float result = 0.0f;
switch (input) {
case LightingRegs::LightingLutInput::NH:
- result = Math::Dot(normal, half_angle);
+ result = Math::Dot(normal, half_vector.Normalized());
break;
case LightingRegs::LightingLutInput::VH:
- result = Math::Dot(norm_view, half_angle);
+ result = Math::Dot(norm_view, half_vector.Normalized());
break;
case LightingRegs::LightingLutInput::NV:
@@ -95,6 +115,22 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
result = Math::Dot(light_vector, normal);
break;
+ case LightingRegs::LightingLutInput::SP: {
+ Math::Vec3<s32> spot_dir{light_config.spot_x.Value(), light_config.spot_y.Value(),
+ light_config.spot_z.Value()};
+ result = Math::Dot(light_vector, spot_dir.Cast<float>() / 2047.0f);
+ break;
+ }
+ case LightingRegs::LightingLutInput::CP:
+ if (lighting.config0.config == LightingRegs::LightingConfig::Config7) {
+ const Math::Vec3<float> norm_half_vector = half_vector.Normalized();
+ const Math::Vec3<float> half_vector_proj =
+ norm_half_vector - normal * Math::Dot(normal, norm_half_vector);
+ result = Math::Dot(half_vector_proj, tangent);
+ } else {
+ result = 0.0f;
+ }
+ break;
default:
LOG_CRITICAL(HW_GPU, "Unknown lighting LUT input %u\n", static_cast<u32>(input));
UNIMPLEMENTED();
@@ -125,6 +161,16 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
LookupLightingLut(lighting_state, static_cast<size_t>(sampler), index, delta);
};
+ // If enabled, compute spot light attenuation value
+ float spot_atten = 1.0f;
+ if (!lighting.IsSpotAttenDisabled(num) &&
+ LightingRegs::IsLightingSamplerSupported(
+ lighting.config0.config, LightingRegs::LightingSampler::SpotlightAttenuation)) {
+ auto lut = LightingRegs::SpotlightAttenuationSampler(num);
+ spot_atten = GetLutValue(lighting.lut_input.sp, lighting.abs_lut_input.disable_sp == 0,
+ lighting.lut_scale.sp, lut);
+ }
+
// Specular 0 component
float d0_lut_value = 1.0f;
if (lighting.config1.disable_lut_d0 == 0 &&
@@ -184,7 +230,8 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
d1_lut_value * refl_value * light_config.specular_1.ToVec3f();
// Fresnel
- if (lighting.config1.disable_lut_fr == 0 &&
+ // Note: only the last entry in the light slots applies the Fresnel factor
+ if (light_index == lighting.max_light_index && lighting.config1.disable_lut_fr == 0 &&
LightingRegs::IsLightingSamplerSupported(lighting.config0.config,
LightingRegs::LightingSampler::Fresnel)) {
@@ -196,14 +243,14 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
if (lighting.config0.fresnel_selector ==
LightingRegs::LightingFresnelSelector::PrimaryAlpha ||
lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
- diffuse_sum.a() *= lut_value;
+ diffuse_sum.a() = lut_value;
}
// Enabled for the specular lighting alpha component
if (lighting.config0.fresnel_selector ==
LightingRegs::LightingFresnelSelector::SecondaryAlpha ||
lighting.config0.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
- specular_sum.a() *= lut_value;
+ specular_sum.a() = lut_value;
}
}
@@ -224,12 +271,23 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
else
dot_product = std::max(dot_product, 0.0f);
+ if (light_config.config.geometric_factor_0 || light_config.config.geometric_factor_1) {
+ float geo_factor = half_vector.Length2();
+ geo_factor = geo_factor == 0.0f ? 0.0f : std::min(dot_product / geo_factor, 1.0f);
+ if (light_config.config.geometric_factor_0) {
+ specular_0 *= geo_factor;
+ }
+ if (light_config.config.geometric_factor_1) {
+ specular_1 *= geo_factor;
+ }
+ }
+
auto diffuse =
light_config.diffuse.ToVec3f() * dot_product + light_config.ambient.ToVec3f();
- diffuse_sum += Math::MakeVec(diffuse * dist_atten, 0.0f);
+ diffuse_sum += Math::MakeVec(diffuse * dist_atten * spot_atten, 0.0f);
- specular_sum +=
- Math::MakeVec((specular_0 + specular_1) * clamp_highlights * dist_atten, 0.0f);
+ specular_sum += Math::MakeVec(
+ (specular_0 + specular_1) * clamp_highlights * dist_atten * spot_atten, 0.0f);
}
diffuse_sum += Math::MakeVec(lighting.global_ambient.ToVec3f(), 0.0f);
@@ -244,7 +302,7 @@ std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
MathUtil::Clamp(specular_sum.z, 0.0f, 1.0f) * 255,
MathUtil::Clamp(specular_sum.w, 0.0f, 1.0f) * 255)
.Cast<u8>();
- return {diffuse, specular};
+ return std::make_tuple(diffuse, specular);
}
} // namespace Pica
diff --git a/src/video_core/swrasterizer/lighting.h b/src/video_core/swrasterizer/lighting.h
index 438dca926..d807a3d94 100644
--- a/src/video_core/swrasterizer/lighting.h
+++ b/src/video_core/swrasterizer/lighting.h
@@ -13,6 +13,7 @@ namespace Pica {
std::tuple<Math::Vec4<u8>, Math::Vec4<u8>> ComputeFragmentsColors(
const Pica::LightingRegs& lighting, const Pica::State::Lighting& lighting_state,
- const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view);
+ const Math::Quaternion<float>& normquat, const Math::Vec3<float>& view,
+ const Math::Vec4<u8> (&texture_color)[4]);
} // namespace Pica
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index fdc1df199..862135614 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -437,8 +437,8 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
GetInterpolatedAttribute(v0.view.y, v1.view.y, v2.view.y).ToFloat32(),
GetInterpolatedAttribute(v0.view.z, v1.view.z, v2.view.z).ToFloat32(),
};
- std::tie(primary_fragment_color, secondary_fragment_color) =
- ComputeFragmentsColors(g_state.regs.lighting, g_state.lighting, normquat, view);
+ std::tie(primary_fragment_color, secondary_fragment_color) = ComputeFragmentsColors(
+ g_state.regs.lighting, g_state.lighting, normquat, view, texture_color);
}
for (unsigned tev_stage_index = 0; tev_stage_index < tev_stages.size();
diff --git a/src/video_core/swrasterizer/rasterizer.h b/src/video_core/swrasterizer/rasterizer.h
index 2f0877581..66cd6cfd4 100644
--- a/src/video_core/swrasterizer/rasterizer.h
+++ b/src/video_core/swrasterizer/rasterizer.h
@@ -19,10 +19,9 @@ struct Vertex : Shader::OutputVertex {
// Linear interpolation
// factor: 0=this, 1=vtx
+ // Note: This function cannot be called after perspective divide
void Lerp(float24 factor, const Vertex& vtx) {
pos = pos * factor + vtx.pos * (float24::FromFloat32(1) - factor);
-
- // TODO: Should perform perspective correct interpolation here...
quat = quat * factor + vtx.quat * (float24::FromFloat32(1) - factor);
color = color * factor + vtx.color * (float24::FromFloat32(1) - factor);
tc0 = tc0 * factor + vtx.tc0 * (float24::FromFloat32(1) - factor);
@@ -30,12 +29,11 @@ struct Vertex : Shader::OutputVertex {
tc0_w = tc0_w * factor + vtx.tc0_w * (float24::FromFloat32(1) - factor);
view = view * factor + vtx.view * (float24::FromFloat32(1) - factor);
tc2 = tc2 * factor + vtx.tc2 * (float24::FromFloat32(1) - factor);
-
- screenpos = screenpos * factor + vtx.screenpos * (float24::FromFloat32(1) - factor);
}
// Linear interpolation
// factor: 0=v0, 1=v1
+ // Note: This function cannot be called after perspective divide
static Vertex Lerp(float24 factor, const Vertex& v0, const Vertex& v1) {
Vertex ret = v0;
ret.Lerp(factor, v1);
diff --git a/src/video_core/swrasterizer/texturing.cpp b/src/video_core/swrasterizer/texturing.cpp
index 4f02b93f2..79b1ce841 100644
--- a/src/video_core/swrasterizer/texturing.cpp
+++ b/src/video_core/swrasterizer/texturing.cpp
@@ -89,6 +89,8 @@ Math::Vec3<u8> GetColorModifier(TevStageConfig::ColorModifier factor,
case ColorModifier::OneMinusSourceBlue:
return (Math::Vec3<u8>(255, 255, 255) - values.bbb()).Cast<u8>();
}
+
+ UNREACHABLE();
};
u8 GetAlphaModifier(TevStageConfig::AlphaModifier factor, const Math::Vec4<u8>& values) {
@@ -119,6 +121,8 @@ u8 GetAlphaModifier(TevStageConfig::AlphaModifier factor, const Math::Vec4<u8>&
case AlphaModifier::OneMinusSourceBlue:
return 255 - values.b();
}
+
+ UNREACHABLE();
};
Math::Vec3<u8> ColorCombine(TevStageConfig::Operation op, const Math::Vec3<u8> input[3]) {
diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp
index a2d007e77..6ad2ffcd4 100644
--- a/src/web_service/telemetry_json.cpp
+++ b/src/web_service/telemetry_json.cpp
@@ -3,7 +3,6 @@
// Refer to the license.txt file included.
#include "common/assert.h"
-#include "core/settings.h"
#include "web_service/telemetry_json.h"
#include "web_service/web_backend.h"
@@ -81,7 +80,7 @@ void TelemetryJson::Complete() {
SerializeSection(Telemetry::FieldType::UserFeedback, "UserFeedback");
SerializeSection(Telemetry::FieldType::UserConfig, "UserConfig");
SerializeSection(Telemetry::FieldType::UserSystem, "UserSystem");
- PostJson(Settings::values.telemetry_endpoint_url, TopSection().dump());
+ PostJson(endpoint_url, TopSection().dump(), true, username, token);
}
} // namespace WebService
diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h
index 39038b4f9..9e78c6803 100644
--- a/src/web_service/telemetry_json.h
+++ b/src/web_service/telemetry_json.h
@@ -17,7 +17,9 @@ namespace WebService {
*/
class TelemetryJson : public Telemetry::VisitorInterface {
public:
- TelemetryJson() = default;
+ TelemetryJson(const std::string& endpoint_url, const std::string& username,
+ const std::string& token)
+ : endpoint_url(endpoint_url), username(username), token(token) {}
~TelemetryJson() = default;
void Visit(const Telemetry::Field<bool>& field) override;
@@ -49,6 +51,9 @@ private:
nlohmann::json output;
std::array<nlohmann::json, 7> sections;
+ std::string endpoint_url;
+ std::string username;
+ std::string token;
};
} // namespace WebService
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp
index 13e4555ac..d28a3f757 100644
--- a/src/web_service/web_backend.cpp
+++ b/src/web_service/web_backend.cpp
@@ -2,51 +2,62 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
+#include <cstdlib>
+#include <thread>
#include <cpr/cpr.h>
-#include <stdlib.h>
#include "common/logging/log.h"
#include "web_service/web_backend.h"
namespace WebService {
static constexpr char API_VERSION[]{"1"};
-static constexpr char ENV_VAR_USERNAME[]{"CITRA_WEB_SERVICES_USERNAME"};
-static constexpr char ENV_VAR_TOKEN[]{"CITRA_WEB_SERVICES_TOKEN"};
-
-static std::string GetEnvironmentVariable(const char* name) {
- const char* value{getenv(name)};
- if (value) {
- return value;
- }
- return {};
-}
-
-const std::string& GetUsername() {
- static const std::string username{GetEnvironmentVariable(ENV_VAR_USERNAME)};
- return username;
-}
-const std::string& GetToken() {
- static const std::string token{GetEnvironmentVariable(ENV_VAR_TOKEN)};
- return token;
-}
+static std::unique_ptr<cpr::Session> g_session;
-void PostJson(const std::string& url, const std::string& data) {
+void PostJson(const std::string& url, const std::string& data, bool allow_anonymous,
+ const std::string& username, const std::string& token) {
if (url.empty()) {
LOG_ERROR(WebService, "URL is invalid");
return;
}
- if (GetUsername().empty() || GetToken().empty()) {
- LOG_ERROR(WebService, "Environment variables %s and %s must be set to POST JSON",
- ENV_VAR_USERNAME, ENV_VAR_TOKEN);
+ const bool are_credentials_provided{!token.empty() && !username.empty()};
+ if (!allow_anonymous && !are_credentials_provided) {
+ LOG_ERROR(WebService, "Credentials must be provided for authenticated requests");
return;
}
- cpr::PostAsync(cpr::Url{url}, cpr::Body{data}, cpr::Header{{"Content-Type", "application/json"},
- {"x-username", GetUsername()},
- {"x-token", GetToken()},
- {"api-version", API_VERSION}});
+#ifdef _WIN32
+ // On Windows, CPR/libcurl does not properly initialize Winsock. The below code is used to
+ // initialize Winsock globally, which fixes this problem. Without this, only the first CPR
+ // session will properly be created, and subsequent ones will fail.
+ WSADATA wsa_data;
+ const int wsa_result{WSAStartup(MAKEWORD(2, 2), &wsa_data)};
+ if (wsa_result) {
+ LOG_CRITICAL(WebService, "WSAStartup failed: %d", wsa_result);
+ }
+#endif
+
+ // Built request header
+ cpr::Header header;
+ if (are_credentials_provided) {
+ // Authenticated request if credentials are provided
+ header = {{"Content-Type", "application/json"},
+ {"x-username", username.c_str()},
+ {"x-token", token.c_str()},
+ {"api-version", API_VERSION}};
+ } else {
+ // Otherwise, anonymous request
+ header = cpr::Header{{"Content-Type", "application/json"}, {"api-version", API_VERSION}};
+ }
+
+ // Post JSON asynchronously
+ static cpr::AsyncResponse future;
+ future = cpr::PostAsync(cpr::Url{url.c_str()}, cpr::Body{data.c_str()}, header);
}
} // namespace WebService
diff --git a/src/web_service/web_backend.h b/src/web_service/web_backend.h
index 2753d3b68..d17100398 100644
--- a/src/web_service/web_backend.h
+++ b/src/web_service/web_backend.h
@@ -10,22 +10,14 @@
namespace WebService {
/**
- * Gets the current username for accessing services.citra-emu.org.
- * @returns Username as a string, empty if not set.
- */
-const std::string& GetUsername();
-
-/**
- * Gets the current token for accessing services.citra-emu.org.
- * @returns Token as a string, empty if not set.
- */
-const std::string& GetToken();
-
-/**
* Posts JSON to services.citra-emu.org.
* @param url URL of the services.citra-emu.org endpoint to post data to.
* @param data String of JSON data to use for the body of the POST request.
+ * @param allow_anonymous If true, allow anonymous unauthenticated requests.
+ * @param username Citra username to use for authentication.
+ * @param token Citra token to use for authentication.
*/
-void PostJson(const std::string& url, const std::string& data);
+void PostJson(const std::string& url, const std::string& data, bool allow_anonymous,
+ const std::string& username = {}, const std::string& token = {});
} // namespace WebService