From ffc441e15d81aa074acb2445b741cad887a04d4e Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Fri, 3 Mar 2023 11:04:40 +0000 Subject: [PATCH 01/19] Universal Mac OS Binary (#254) (#255) * universal binary support * update action workflow --- .github/workflows/build-all.yml | 37 ++++++++++++++++++--------------- .github/workflows/itch.yml | 2 +- Makefile | 2 ++ scripts/setup_static_mac_sdl.sh | 4 ++-- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index cb916c27..2054ab02 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -15,10 +15,10 @@ jobs: - name: Verify run: emcc -v - name: Checkout - uses: actions/checkout@v2.0.0 + uses: actions/checkout@v3.0.0 - run: git fetch --prune --unshallow - run: make MODE=release dome.html ARCH=web - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: dome-web path: | @@ -31,13 +31,13 @@ jobs: static: [1, 0] steps: - name: Checkout - uses: actions/checkout@v2.0.0 + uses: actions/checkout@v3.0.0 - run: git fetch --prune --unshallow - run: sudo apt-get update - run: sudo apt-get install build-essential mercurial make cmake autoconf automake libtool libasound2-dev libpulse-dev libaudio-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev libxss-dev libgl1-mesa-dev libdbus-1-dev libudev-dev libgles2-mesa-dev libegl1-mesa-dev libibus-1.0-dev fcitx-libs-dev libsamplerate0-dev libsndio-dev libwayland-dev libxkbcommon-dev - name: Cache dependancies if: ${{matrix.static == 1}} - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ./lib/SDL* @@ -49,7 +49,7 @@ jobs: - run: ./scripts/setup_static_linux_sdl.sh if: ${{matrix.static == 1}} - run: make MODE=release STATIC=${{matrix.static}} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{matrix.static == 1}} with: name: dome-linux-x64 @@ -57,7 +57,7 @@ jobs: dome main.wren - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{matrix.static == 0}} with: name: dome-linux-x64-shared @@ -69,10 +69,13 @@ jobs: runs-on: macOS-latest steps: - name: Checkout - uses: actions/checkout@v2.0.0 - - run: sudo xcode-select -switch /Applications/Xcode_14.2.app/Contents/Developer + uses: actions/checkout@v3.0.0 + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '14.2' + # - run: sudo xcode-select -switch /Applications/Xcode_14.2.app/Contents/Developer - name: Cache dependancies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ./lib/SDL* @@ -81,9 +84,9 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('./scripts/vars.sh') }}-sdl - run: ./scripts/setup_static_mac_sdl.sh - run: make MIN_MAC_VERSION=10.12 STATIC=1 - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: - name: dome-macosx-x64 + name: dome-macosx-all path: | dome main.wren @@ -96,7 +99,7 @@ jobs: run: shell: msys2 {0} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: msys2/setup-msys2@v2 with: msystem: ${{ matrix.msystem }} @@ -112,14 +115,14 @@ jobs: - run: git fetch --prune --unshallow - run: gcc -v - run: "make STATIC=1 TARGET_NAME=dome CC=gcc" - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{ (matrix.msystem == 'MINGW32') }} with: name: dome-windows-x32 path: | dome.exe main.wren - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{ (matrix.msystem == 'MINGW64') }} with: name: dome-windows-x64 @@ -148,7 +151,7 @@ jobs: args: zip -qq -r dome-windows-x32.zip dome-windows-x32 - uses: montudor/action-zip@v0.1.0 with: - args: zip -qq -r dome-macosx-x64.zip dome-macosx-x64 + args: zip -qq -r dome-macosx-all.zip dome-macosx-all - uses: montudor/action-zip@v0.1.0 with: args: zip -qq -r dome-web.zip dome-web @@ -195,8 +198,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-macosx-x64.zip - asset_name: dome-${{github.event.release.tag_name}}-macosx-x64.zip + asset_path: ./dome-macosx-all.zip + asset_name: dome-${{github.event.release.tag_name}}-macosx-all.zip asset_content_type: application/zip - name: Upload Web Engine uses: actions/upload-release-asset@v1 diff --git a/.github/workflows/itch.yml b/.github/workflows/itch.yml index 4f5db3e9..fa3dabc0 100644 --- a/.github/workflows/itch.yml +++ b/.github/workflows/itch.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - platform: ["windows-x64", "windows-x32", "macosx-x64", "linux-x64", "linux-x64-shared"] + platform: ["windows-x64", "windows-x32", "macosx-all", "linux-x64", "linux-x64-shared"] # Steps represent a sequence of tasks that will be executed as part of the job steps: diff --git a/Makefile b/Makefile index 8fbdf44d..62540f16 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,8 @@ CFLAGS += -D_XOPEN_SOURCE=500 else ifneq ($(filter macosx,$(TAGS)),) CFLAGS += -mmacosx-version-min=10.12 CFLAGS += -D_DARWIN_C_SOURCE +CFLAGS += -arch x86_64 -arch arm64 +WREN_PARAMS += -arch x86_64 -arch arm64 endif ifneq ($(filter release,$(TAGS)),) diff --git a/scripts/setup_static_mac_sdl.sh b/scripts/setup_static_mac_sdl.sh index e97e3730..1156a218 100755 --- a/scripts/setup_static_mac_sdl.sh +++ b/scripts/setup_static_mac_sdl.sh @@ -5,9 +5,9 @@ git submodule update --init -- $DIRECTORY if ! [ -d "$DIRECTORY/$FOLDER" ]; then cd $DIRECTORY mkdir ${FOLDER} ; cd ${FOLDER} - ../configure CC=$(sh $DIRECTORY/build-scripts/clang-fat.sh) # --disable-shared + ../configure CC="sh $DIRECTORY/build-scripts/clang-fat.sh" #--disable-shared else - cd $DIRECTORY/${FOLDER} + cd $DIRECTORY/$FOLDER fi make From d4497b36071feb9043917a4bbe031809c00e797c Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sat, 11 Mar 2023 10:09:01 +0000 Subject: [PATCH 02/19] fixing spritesheet docs title --- docs/modules/graphics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/graphics.md b/docs/modules/graphics.md index dc00cd4d..3fc9b927 100644 --- a/docs/modules/graphics.md +++ b/docs/modules/graphics.md @@ -265,7 +265,7 @@ The code snippet above: * It then rotates it 90 degrees clockwise * Finally, it scales the tile up by 2 in both the X and Y direction, but it flips the tile vertically. -## SpriteSheet +## SpriteSheet This class can load in an image and divide it into a fixed-size grid of smaller squares, as a convenience. It's useful for loading multiple sprites from a single file. This can also be used as the foundation of an From 70b1591e606def87be7fa40b4f062d30368b61ff Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 06:51:18 +0000 Subject: [PATCH 03/19] adding windows-only build --- .github/workflows/windows-only.yml | 126 +++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 .github/workflows/windows-only.yml diff --git a/.github/workflows/windows-only.yml b/.github/workflows/windows-only.yml new file mode 100644 index 00000000..57f720ec --- /dev/null +++ b/.github/workflows/windows-only.yml @@ -0,0 +1,126 @@ +name: Windows only test build +on: + workflow_dispatch: +# A workflow run is made up of one or more jobs that can run sequentially or in parallel + +jobs: + build-windows: + runs-on: windows-latest + strategy: + matrix: + msystem: [MINGW32, MINGW64] + defaults: + run: + shell: msys2 {0} + steps: + - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.msystem }} + release: true + update: true + install: git make mercurial subversion + + - run: pacman --noconfirm -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-SDL2 + if: ${{ (matrix.msystem == 'MINGW64') }} + - run: pacman --noconfirm -S mingw-w64-i686-toolchain mingw-w64-i686-SDL2 + if: ${{ (matrix.msystem == 'MINGW32') }} + + - run: git fetch --prune --unshallow + - run: gcc -v + - run: "make STATIC=1 TARGET_NAME=dome CC=gcc" + - uses: actions/upload-artifact@v3 + if: ${{ (matrix.msystem == 'MINGW32') }} + with: + name: dome-windows-x32 + path: | + dome.exe + main.wren + - uses: actions/upload-artifact@v3 + if: ${{ (matrix.msystem == 'MINGW64') }} + with: + name: dome-windows-x64 + path: | + dome.exe + main.wren + + release-artifacts: + if: ${{ github.event.action == 'published' }} + needs: [ build-linux, build-mac, build-windows, build-web ] + runs-on: ubuntu-latest + name: Upload Release Artifacts + steps: + - uses: actions/download-artifact@v2 + - uses: montudor/action-zip@v0.1.0 + with: + args: zip -qq -r dome-linux-x64.zip dome-linux-x64 + - uses: montudor/action-zip@v0.1.0 + with: + args: zip -qq -r dome-linux-x64-shared.zip dome-linux-x64-shared + - uses: montudor/action-zip@v0.1.0 + with: + args: zip -qq -r dome-windows-x64.zip dome-windows-x64 + - uses: montudor/action-zip@v0.1.0 + with: + args: zip -qq -r dome-windows-x32.zip dome-windows-x32 + - uses: montudor/action-zip@v0.1.0 + with: + args: zip -qq -r dome-macosx-all.zip dome-macosx-all + - uses: montudor/action-zip@v0.1.0 + with: + args: zip -qq -r dome-web.zip dome-web + - run: ls -la + - name: Upload Linux Shared + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./dome-linux-x64-shared.zip + asset_name: dome-${{github.event.release.tag_name}}-linux-x64-shared.zip + asset_content_type: application/zip + - name: Upload Linux Static + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./dome-linux-x64.zip + asset_name: dome-${{github.event.release.tag_name}}-linux-x64.zip + asset_content_type: application/zip + - name: Upload Windows x64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./dome-windows-x64.zip + asset_name: dome-${{github.event.release.tag_name}}-windows-x64.zip + asset_content_type: application/zip + - name: Upload Windows x32 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./dome-windows-x32.zip + asset_name: dome-${{github.event.release.tag_name}}-windows-x32.zip + asset_content_type: application/zip + - name: Upload Mac OS X + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./dome-macosx-all.zip + asset_name: dome-${{github.event.release.tag_name}}-macosx-all.zip + asset_content_type: application/zip + - name: Upload Web Engine + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./dome-web.zip + asset_name: dome-${{github.event.release.tag_name}}-web.zip + asset_content_type: application/zip From b86e865f4946cbc440105f98ee56c04b47ebfa54 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 06:53:24 +0000 Subject: [PATCH 04/19] fixing windows flow --- .github/workflows/windows-only.yml | 83 ------------------------------ 1 file changed, 83 deletions(-) diff --git a/.github/workflows/windows-only.yml b/.github/workflows/windows-only.yml index 57f720ec..64623433 100644 --- a/.github/workflows/windows-only.yml +++ b/.github/workflows/windows-only.yml @@ -35,92 +35,9 @@ jobs: name: dome-windows-x32 path: | dome.exe - main.wren - uses: actions/upload-artifact@v3 if: ${{ (matrix.msystem == 'MINGW64') }} with: name: dome-windows-x64 path: | dome.exe - main.wren - - release-artifacts: - if: ${{ github.event.action == 'published' }} - needs: [ build-linux, build-mac, build-windows, build-web ] - runs-on: ubuntu-latest - name: Upload Release Artifacts - steps: - - uses: actions/download-artifact@v2 - - uses: montudor/action-zip@v0.1.0 - with: - args: zip -qq -r dome-linux-x64.zip dome-linux-x64 - - uses: montudor/action-zip@v0.1.0 - with: - args: zip -qq -r dome-linux-x64-shared.zip dome-linux-x64-shared - - uses: montudor/action-zip@v0.1.0 - with: - args: zip -qq -r dome-windows-x64.zip dome-windows-x64 - - uses: montudor/action-zip@v0.1.0 - with: - args: zip -qq -r dome-windows-x32.zip dome-windows-x32 - - uses: montudor/action-zip@v0.1.0 - with: - args: zip -qq -r dome-macosx-all.zip dome-macosx-all - - uses: montudor/action-zip@v0.1.0 - with: - args: zip -qq -r dome-web.zip dome-web - - run: ls -la - - name: Upload Linux Shared - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-linux-x64-shared.zip - asset_name: dome-${{github.event.release.tag_name}}-linux-x64-shared.zip - asset_content_type: application/zip - - name: Upload Linux Static - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-linux-x64.zip - asset_name: dome-${{github.event.release.tag_name}}-linux-x64.zip - asset_content_type: application/zip - - name: Upload Windows x64 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-windows-x64.zip - asset_name: dome-${{github.event.release.tag_name}}-windows-x64.zip - asset_content_type: application/zip - - name: Upload Windows x32 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-windows-x32.zip - asset_name: dome-${{github.event.release.tag_name}}-windows-x32.zip - asset_content_type: application/zip - - name: Upload Mac OS X - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-macosx-all.zip - asset_name: dome-${{github.event.release.tag_name}}-macosx-all.zip - asset_content_type: application/zip - - name: Upload Web Engine - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./dome-web.zip - asset_name: dome-${{github.event.release.tag_name}}-web.zip - asset_content_type: application/zip From 3cab85fb7849e1d5fa49e119f3cb0a998c731475 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 07:03:43 +0000 Subject: [PATCH 05/19] Disabling HighDPI on windows --- src/modules/dome.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/dome.c b/src/modules/dome.c index 4a0695aa..1b18464b 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -70,6 +70,13 @@ WINDOW_resize(WrenVM* vm) { uint32_t width = wrenGetSlotDouble(vm, 1); uint32_t height = wrenGetSlotDouble(vm, 2); +#ifdef _WIN32 + SDL_SetWindowSize(engine->window, width, height); + int32_t newWidth, newHeight; + SDL_GetRendererOutputSize(engine->renderer, &newWidth, &newHeight); + SDL_SetWindowSize(engine->window, newWidth, newHeight); +#else + // Account for High DPI by comparing the current window size // to the renderer's client output size. // This is considered more accurate than SDL's built in methods. @@ -88,6 +95,7 @@ WINDOW_resize(WrenVM* vm) { int32_t newWidth, newHeight; SDL_GetRendererOutputSize(engine->renderer, &newWidth, &newHeight); SDL_SetWindowSize(engine->window, newWidth / factorH, newHeight/factorV); +#endif #else SDL_SetWindowSize(engine->window, engine->canvas.width, engine->canvas.height); #endif From cb1a6045b1c3d310a741de339333bb474701b1ca Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 07:13:54 +0000 Subject: [PATCH 06/19] Mingw --- src/engine.c | 2 +- src/modules/dome.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine.c b/src/engine.c index 0799a631..3a2afa32 100644 --- a/src/engine.c +++ b/src/engine.c @@ -237,7 +237,7 @@ ENGINE_start(ENGINE* engine) { int result = EXIT_SUCCESS; uint32_t windowFlags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE; -#if defined _WIN32 +#if defined _WIN32 || defined __MINGW32__ SDL_setenv("SDL_AUDIODRIVER", "directsound", true); #else windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI; diff --git a/src/modules/dome.c b/src/modules/dome.c index 1b18464b..8ebaa603 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -70,7 +70,7 @@ WINDOW_resize(WrenVM* vm) { uint32_t width = wrenGetSlotDouble(vm, 1); uint32_t height = wrenGetSlotDouble(vm, 2); -#ifdef _WIN32 +#if defined _WIN32 || defined __MINGW32__ SDL_SetWindowSize(engine->window, width, height); int32_t newWidth, newHeight; SDL_GetRendererOutputSize(engine->renderer, &newWidth, &newHeight); From 445389f9f438d6d58e7a3eb7bb70bf9bb592420a Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 07:35:11 +0000 Subject: [PATCH 07/19] applying nodpi hint --- src/engine.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine.c b/src/engine.c index 3a2afa32..ecc9f8dd 100644 --- a/src/engine.c +++ b/src/engine.c @@ -237,8 +237,10 @@ ENGINE_start(ENGINE* engine) { int result = EXIT_SUCCESS; uint32_t windowFlags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE; -#if defined _WIN32 || defined __MINGW32__ +#if defined (_WIN32) || defined (__MINGW32__) SDL_setenv("SDL_AUDIODRIVER", "directsound", true); + SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); + SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1"); #else windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif From 83b0c660843460d761a1db4789b9b21b140ee1ea Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 07:53:24 +0000 Subject: [PATCH 08/19] long shot windows fix now --- main.wren | 5 ++++- src/modules/dome.c | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main.wren b/main.wren index 554b6ed6..018c315e 100644 --- a/main.wren +++ b/main.wren @@ -1,7 +1,10 @@ +import "dome" for Window import "graphics" for Canvas, Color class Main { construct new() {} - init() {} + init() { + Window.resize(1920, 1280) + } update() {} draw(dt) { Canvas.print("DOME Installed Successfully.", 10, 10, Color.white) diff --git a/src/modules/dome.c b/src/modules/dome.c index 8ebaa603..0a1f9e3f 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -71,7 +71,20 @@ WINDOW_resize(WrenVM* vm) { uint32_t height = wrenGetSlotDouble(vm, 2); #if defined _WIN32 || defined __MINGW32__ - SDL_SetWindowSize(engine->window, width, height); + + SDL_DisplayMode dm; + + if (SDL_GetDesktopDisplayMode(0, &dm) != 0) + { + SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError()); + return 1; + } + + int w, h; + w = dm.w; + h = dm.h; + + SDL_SetWindowSize(engine->window, min(width, w-1), min(height, h - 1)); int32_t newWidth, newHeight; SDL_GetRendererOutputSize(engine->renderer, &newWidth, &newHeight); SDL_SetWindowSize(engine->window, newWidth, newHeight); From 9c4fd768064ac0ed679fe36c42a31fa18d505151 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Sun, 12 Mar 2023 12:12:57 +0000 Subject: [PATCH 09/19] scalable web view --- assets/shell.html | 33 ++++++++++++++++++++++++++------- src/game.c | 2 +- src/modules/dome.c | 5 +++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/assets/shell.html b/assets/shell.html index 0391d734..0e327fae 100644 --- a/assets/shell.html +++ b/assets/shell.html @@ -11,25 +11,33 @@ } html, body { - background-color: black; + background-color: #1B0326; color: white; - max-width: 100vw; - max-height: 100vh; + width: 100%; + height: 100%; } textarea.emscripten { font-family: monospace; width: 80%; display: none; } div.emscripten { text-align: center; } div.emscripten_border { - border: 1px solid white; + border: 0px solid white; + width: 100%; + height: 100%; + text-align:center; margin: 0 auto; } /* the canvas *must not* have any border or padding, or mouse coords will be wrong */ canvas.emscripten { margin: 0; + display:inline; + /* width: auto; - height: 100%; + height: 100%; + */ + height: 100% !important; + width: auto !important; border: 0px none; - background-color: black; + background-color: #1B0326; outline: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); /* mobile webkit */ image-rendering: -moz-crisp-edges; @@ -39,7 +47,16 @@ } @@ -131,6 +148,8 @@ Module.SDL2.audio.scriptProcessorNode['connect'](Module.SDL2.audioContext['destination']); } } + document.getElementById('canvas').addEventListener('click', resumeAudio); + document.addEventListener('keydown', resumeAudio); diff --git a/src/game.c b/src/game.c index 788ad05c..5a1aacbc 100644 --- a/src/game.c +++ b/src/game.c @@ -50,6 +50,7 @@ DOME_processInput(LOOP_STATE* state) { { if (event.window.event == SDL_WINDOWEVENT_RESIZED || event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { + SDL_RenderGetViewport(engine->renderer, &(engine->viewport)); break; } @@ -303,7 +304,6 @@ int DOME_begin(ENGINE* engine, char* entryPath) { loop.drawMethod = wrenMakeCallHandle(vm, "draw(_)"); SDL_SetRenderDrawColor(engine->renderer, 0x00, 0x00, 0x00, 0xFF); - // Initiate game loop wrenSetSlotHandle(vm, 0, loop.gameClass); diff --git a/src/modules/dome.c b/src/modules/dome.c index 0a1f9e3f..ab1a7b55 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -66,10 +66,11 @@ WINDOW_resize(WrenVM* vm) { ASSERT_SLOT_TYPE(vm, 1, NUM, "width"); ASSERT_SLOT_TYPE(vm, 2, NUM, "height"); -#ifndef __EMSCRIPTEN__ uint32_t width = wrenGetSlotDouble(vm, 1); uint32_t height = wrenGetSlotDouble(vm, 2); +#ifndef __EMSCRIPTEN__ + #if defined _WIN32 || defined __MINGW32__ SDL_DisplayMode dm; @@ -110,7 +111,7 @@ WINDOW_resize(WrenVM* vm) { SDL_SetWindowSize(engine->window, newWidth / factorH, newHeight/factorV); #endif #else - SDL_SetWindowSize(engine->window, engine->canvas.width, engine->canvas.height); + //SDL_SetWindowSize(engine->window, width, height); #endif ENGINE_updateTextRegion(engine); } From a05ce19203fab18e87a8a7bfb52a4e061812662c Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Mon, 13 Mar 2023 16:41:23 +0000 Subject: [PATCH 10/19] Restoring our main --- main.wren | 6 ++---- src/modules/dome.c | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/main.wren b/main.wren index 018c315e..a6dbd3d4 100644 --- a/main.wren +++ b/main.wren @@ -1,10 +1,8 @@ -import "dome" for Window import "graphics" for Canvas, Color + class Main { construct new() {} - init() { - Window.resize(1920, 1280) - } + init() {} update() {} draw(dt) { Canvas.print("DOME Installed Successfully.", 10, 10, Color.white) diff --git a/src/modules/dome.c b/src/modules/dome.c index 0a1f9e3f..1c138b87 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -100,6 +100,8 @@ WINDOW_resize(WrenVM* vm) { double factorH = currentRenderWidth / currentWinWidth; double factorV = currentRenderHeight / currentWinHeight; + factorH = 1; + factorV = 1; SDL_SetWindowSize(engine->window, width / factorH, height / factorV); // Window may not have resized to the specified value because of From 09693b7d360543305a2f032ff9b280d9305a17d3 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Mon, 13 Mar 2023 16:41:57 +0000 Subject: [PATCH 11/19] Ripping out a lot of the DPI-scaling code, it's not helpful --- src/engine.c | 4 +--- src/modules/dome.c | 46 +++++++++++++--------------------------------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/engine.c b/src/engine.c index ecc9f8dd..f5f0f4dd 100644 --- a/src/engine.c +++ b/src/engine.c @@ -239,12 +239,10 @@ ENGINE_start(ENGINE* engine) { uint32_t windowFlags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE; #if defined (_WIN32) || defined (__MINGW32__) SDL_setenv("SDL_AUDIODRIVER", "directsound", true); - SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); - SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1"); #else windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif - SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); +// SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); //Initialize SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { diff --git a/src/modules/dome.c b/src/modules/dome.c index 1c138b87..7eb45a23 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -65,52 +65,32 @@ WINDOW_resize(WrenVM* vm) { ENGINE* engine = (ENGINE*)wrenGetUserData(vm); ASSERT_SLOT_TYPE(vm, 1, NUM, "width"); ASSERT_SLOT_TYPE(vm, 2, NUM, "height"); - -#ifndef __EMSCRIPTEN__ uint32_t width = wrenGetSlotDouble(vm, 1); uint32_t height = wrenGetSlotDouble(vm, 2); -#if defined _WIN32 || defined __MINGW32__ - +#ifndef __EMSCRIPTEN__ SDL_DisplayMode dm; if (SDL_GetDesktopDisplayMode(0, &dm) != 0) { SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError()); - return 1; + return; } int w, h; w = dm.w; h = dm.h; - - SDL_SetWindowSize(engine->window, min(width, w-1), min(height, h - 1)); - int32_t newWidth, newHeight; - SDL_GetRendererOutputSize(engine->renderer, &newWidth, &newHeight); - SDL_SetWindowSize(engine->window, newWidth, newHeight); -#else - - // Account for High DPI by comparing the current window size - // to the renderer's client output size. - // This is considered more accurate than SDL's built in methods. - int32_t currentWinWidth, currentWinHeight; - int32_t currentRenderWidth, currentRenderHeight; - SDL_GetWindowSize(engine->window, ¤tWinWidth, ¤tWinHeight); - SDL_GetRendererOutputSize(engine->renderer, ¤tRenderWidth, ¤tRenderHeight); - - double factorH = currentRenderWidth / currentWinWidth; - double factorV = currentRenderHeight / currentWinHeight; - factorH = 1; - factorV = 1; - - SDL_SetWindowSize(engine->window, width / factorH, height / factorV); - // Window may not have resized to the specified value because of - // desktop restraints, but SDL doesn't check this. - // We can fetch the final display size from the renderer output. - int32_t newWidth, newHeight; - SDL_GetRendererOutputSize(engine->renderer, &newWidth, &newHeight); - SDL_SetWindowSize(engine->window, newWidth / factorH, newHeight/factorV); -#endif + if (width > w || height > h) { + SDL_MaximizeWindow(engine->window); + } else { + SDL_SetWindowSize(engine->window, width, height); + // Window may not have resized to the specified value because of + // desktop restraints, but SDL doesn't check this. + // We can fetch the final display size from the renderer output. + int32_t newWidth, newHeight; + SDL_GetWindowSize(engine->window, &newWidth, &newHeight); + SDL_SetWindowSize(engine->window, newWidth, newHeight); + } #else SDL_SetWindowSize(engine->window, engine->canvas.width, engine->canvas.height); #endif From 55faeb3f824bc8035c76d469afa5fdd3a952743c Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Mon, 13 Mar 2023 21:19:31 +0000 Subject: [PATCH 12/19] Cleanup --- src/engine.c | 1 - src/modules/dome.c | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/engine.c b/src/engine.c index f5f0f4dd..3b977c14 100644 --- a/src/engine.c +++ b/src/engine.c @@ -242,7 +242,6 @@ ENGINE_start(ENGINE* engine) { #else windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif -// SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1"); //Initialize SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { diff --git a/src/modules/dome.c b/src/modules/dome.c index 7eb45a23..8b7367b3 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -73,14 +73,13 @@ WINDOW_resize(WrenVM* vm) { if (SDL_GetDesktopDisplayMode(0, &dm) != 0) { - SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError()); + ENGINE_printLog(engine, "SDL_GetDesktopDisplayMode failed %s", SDL_GetError()); return; } - int w, h; - w = dm.w; - h = dm.h; - if (width > w || height > h) { + int32_t displayWidth = dm.w; + int32_t displayHeight = dm.h; + if (width > displayWidth || height > displayHeight) { SDL_MaximizeWindow(engine->window); } else { SDL_SetWindowSize(engine->window, width, height); @@ -92,6 +91,7 @@ WINDOW_resize(WrenVM* vm) { SDL_SetWindowSize(engine->window, newWidth, newHeight); } #else + // In web mode, we fix to the canvas size and let the browser scale the window/canvas SDL_SetWindowSize(engine->window, engine->canvas.width, engine->canvas.height); #endif ENGINE_updateTextRegion(engine); From ae2299fbf519813d24143a5a473fec834001f87d Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Mon, 13 Mar 2023 21:22:16 +0000 Subject: [PATCH 13/19] tweaking logic --- src/modules/dome.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/modules/dome.c b/src/modules/dome.c index 8b7367b3..c6cd8371 100644 --- a/src/modules/dome.c +++ b/src/modules/dome.c @@ -83,13 +83,14 @@ WINDOW_resize(WrenVM* vm) { SDL_MaximizeWindow(engine->window); } else { SDL_SetWindowSize(engine->window, width, height); - // Window may not have resized to the specified value because of - // desktop restraints, but SDL doesn't check this. - // We can fetch the final display size from the renderer output. - int32_t newWidth, newHeight; - SDL_GetWindowSize(engine->window, &newWidth, &newHeight); - SDL_SetWindowSize(engine->window, newWidth, newHeight); } + // Window may not have resized to the specified value because of + // desktop restraints, but SDL doesn't check this and remembers + // the requested size only. + // We can fetch the final display size to set to the correct value + int32_t newWidth, newHeight; + SDL_GetWindowSize(engine->window, &newWidth, &newHeight); + SDL_SetWindowSize(engine->window, newWidth, newHeight); #else // In web mode, we fix to the canvas size and let the browser scale the window/canvas SDL_SetWindowSize(engine->window, engine->canvas.width, engine->canvas.height); From c44417438d3badcdad9b3379be57e2f764cdb052 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Tue, 14 Mar 2023 21:54:07 +0000 Subject: [PATCH 14/19] Final tweaks for 1.8.2 --- assets/shell.html | 4 +--- src/modules/graphics.wren | 2 +- src/modules/image.wren | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/assets/shell.html b/assets/shell.html index 0e327fae..8955353c 100644 --- a/assets/shell.html +++ b/assets/shell.html @@ -37,7 +37,7 @@ height: 100% !important; width: auto !important; border: 0px none; - background-color: #1B0326; + /*background-color: #1B0326; */ outline: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); /* mobile webkit */ image-rendering: -moz-crisp-edges; @@ -49,13 +49,11 @@ diff --git a/src/modules/graphics.wren b/src/modules/graphics.wren index 43bd38f2..6052529d 100644 --- a/src/modules/graphics.wren +++ b/src/modules/graphics.wren @@ -202,7 +202,7 @@ class Canvas { // These need to be at the bottom to prevent cyclic dependancy import "color" for Color -import "image" for Drawable, ImageData, SpriteSheet +import "image" for Drawable, ImageData, SpriteSheet, Bitmap, Image import "vector" for Point, Vec, Vector import "font" for Font, RasterizedFont diff --git a/src/modules/image.wren b/src/modules/image.wren index 9dc76ff8..060d6385 100644 --- a/src/modules/image.wren +++ b/src/modules/image.wren @@ -120,11 +120,11 @@ class SpriteSheet { } static load(path, tileSize, scale) { - var image = ImageData.loadFromFile(path) + var image = ImageData.load(path) return SpriteSheet.new(image, tileSize, scale) } static load(path, tileSize) { - return SpriteSheet.loadFromFile(path, tileSize, 1) + return SpriteSheet.load(path, tileSize, 1) } construct new(image, tileSize) { From c0ea6e91dee38b736f3e2aa78775602c898cfb2b Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Tue, 14 Mar 2023 21:55:51 +0000 Subject: [PATCH 15/19] Returning background color of web shell to black --- assets/shell.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/shell.html b/assets/shell.html index 8955353c..7d40f370 100644 --- a/assets/shell.html +++ b/assets/shell.html @@ -11,7 +11,7 @@ } html, body { - background-color: #1B0326; + background-color: black; color: white; width: 100%; height: 100%; @@ -37,7 +37,6 @@ height: 100% !important; width: auto !important; border: 0px none; - /*background-color: #1B0326; */ outline: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); /* mobile webkit */ image-rendering: -moz-crisp-edges; From 5edaee37233b994d4146e90460658147dbe415f3 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Wed, 15 Mar 2023 06:39:12 +0000 Subject: [PATCH 16/19] Fixes [#261] --- docs/modules/dome.md | 3 ++- src/modules/audio.c | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/modules/dome.md b/docs/modules/dome.md index 6e12f229..961791cd 100644 --- a/docs/modules/dome.md +++ b/docs/modules/dome.md @@ -175,4 +175,5 @@ This is the background color of the window. Note that to this _does not_ affect #### `static resize(width: Number, height: Number): Void` -This allows you to control the size of DOME's window. The viewport will scale accordingly, but the canvas will NOT resize. +This allows you to control the size of DOME's window. The viewport will scale accordingly, but the canvas will NOT resize. DOME treats high DPI displays with a scaling factor (determined by the operating system) so the +true window size may not match your chosen dimensions. diff --git a/src/modules/audio.c b/src/modules/audio.c index 6f742b03..3bd377fb 100644 --- a/src/modules/audio.c +++ b/src/modules/audio.c @@ -54,13 +54,13 @@ AUDIO_allocate(WrenVM* vm) { data->spec.freq = freq; data->spec.format = AUDIO_F32LSB; data->length = totalFrameCount; - } else if (strncmp(fileBuffer, "ID3", 3) == 0) { + } else { data->audioType = AUDIO_TYPE_MP3; drmp3_config config = { 0 }; drmp3_uint64 totalFrameCount; tempBuffer = drmp3_open_memory_and_read_pcm_frames_s16(fileBuffer, length, &config, &totalFrameCount, NULL); if (tempBuffer == NULL) { - VM_ABORT(vm, "Invalid MP3 file"); + VM_ABORT(vm, "Audio file was of an incompatible format"); return; } @@ -68,9 +68,6 @@ AUDIO_allocate(WrenVM* vm) { data->spec.freq = config.sampleRate; data->spec.format = AUDIO_F32LSB; data->length = totalFrameCount; - } else { - VM_ABORT(vm, "Audio file was of an incompatible format"); - return; } data->buffer = calloc(data->length, bytesPerSample); From 4906e9eceeadf9857ec6314fd604219c820fb104 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Wed, 15 Mar 2023 07:05:36 +0000 Subject: [PATCH 17/19] Fix #260 --- src/engine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine.c b/src/engine.c index 3b977c14..8daa2f80 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1186,17 +1186,21 @@ ENGINE_canvasResize(ENGINE* engine, uint32_t newWidth, uint32_t newHeight, uint3 return false; } - engine->canvas.pixels = realloc(engine->canvas.pixels, engine->canvas.width * engine->canvas.height * 4); + engine->canvas.pixels = realloc(engine->canvas.pixels, engine->canvas.width * engine->canvas.height * sizeof(uint32_t)); if (engine->canvas.pixels == NULL) { return false; } + /* ENGINE_rectfill(engine, 0, 0, engine->canvas.width, engine->canvas.height, color); + */ + SDL_RenderClear(engine->renderer); SDL_RenderGetViewport(engine->renderer, &(engine->viewport)); ENGINE_updateTextRegion(engine); #ifdef __EMSCRIPTEN__ SDL_SetWindowSize(engine->window, engine->canvas.width, engine->canvas.height); #endif + memset((uint32_t*)engine->canvas.pixels, color, engine->canvas.width * engine->canvas.height); return true; } From 9d8ecf9fecd05f1b8dc5d26fadbf3de9a6fe3ce7 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Wed, 15 Mar 2023 07:10:16 +0000 Subject: [PATCH 18/19] Added a small api to the spritesheet for two-dimensional indexing --- docs/modules/graphics.md | 7 +++++++ docs/modules/image.md | 0 src/modules/image.wren | 2 ++ 3 files changed, 9 insertions(+) delete mode 100644 docs/modules/image.md diff --git a/docs/modules/graphics.md b/docs/modules/graphics.md index 3fc9b927..cf926bee 100644 --- a/docs/modules/graphics.md +++ b/docs/modules/graphics.md @@ -300,6 +300,13 @@ Draw tile `index` on the spritesheet at location `(x, y)` on screen. Draw tile `index` on the spritesheet at location `(x, y)` on screen. This will also apply the given transform `parameterMap` to the tile being drawn. You can reference the `ImageData.transform` documentation for a list of available parameters. +#### `draw(tileX: Number, tileY: Number, x: Number, y: Number)` +Draw tile `(tileX, tileY)` on the spritesheet at location `(x, y)` on screen. + +#### `draw(tileX: Number, tileY: Number, x: Number, y: Number, parameterMap)` +Draw tile `(tileX, tileY)` on the spritesheet at location `(x, y)` on screen. This will also apply the given transform `parameterMap` to the tile being drawn. +You can reference the `ImageData.transform` documentation for a list of available parameters. + ### Instance Methods #### `fg: Color` diff --git a/docs/modules/image.md b/docs/modules/image.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/modules/image.wren b/src/modules/image.wren index 060d6385..9a2a2115 100644 --- a/src/modules/image.wren +++ b/src/modules/image.wren @@ -167,6 +167,8 @@ class SpriteSheet { return _cache[s] } + draw(sx, sy, x, y, modMap) { draw(sy * _width + sx, x, y, modMap) } + draw(sx, sy, x, y) { draw(sy * _width + sx, x, y) } draw(s, x, y) { draw(s, x, y, null) } draw(s, x, y, modMap) { getTile(s).modify(modMap || { From 45205e1dc718baa4e52e2a36eb10c4e7731bd484 Mon Sep 17 00:00:00 2001 From: Aviv Beeri Date: Wed, 15 Mar 2023 07:42:39 +0000 Subject: [PATCH 19/19] Added drawFrom convenience method --- docs/modules/graphics.md | 4 ++-- src/modules/image.wren | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/modules/graphics.md b/docs/modules/graphics.md index cf926bee..0c5c7dd8 100644 --- a/docs/modules/graphics.md +++ b/docs/modules/graphics.md @@ -300,10 +300,10 @@ Draw tile `index` on the spritesheet at location `(x, y)` on screen. Draw tile `index` on the spritesheet at location `(x, y)` on screen. This will also apply the given transform `parameterMap` to the tile being drawn. You can reference the `ImageData.transform` documentation for a list of available parameters. -#### `draw(tileX: Number, tileY: Number, x: Number, y: Number)` +#### `drawFrom(tileX: Number, tileY: Number, x: Number, y: Number)` Draw tile `(tileX, tileY)` on the spritesheet at location `(x, y)` on screen. -#### `draw(tileX: Number, tileY: Number, x: Number, y: Number, parameterMap)` +#### `drawFrom(tileX: Number, tileY: Number, x: Number, y: Number, parameterMap)` Draw tile `(tileX, tileY)` on the spritesheet at location `(x, y)` on screen. This will also apply the given transform `parameterMap` to the tile being drawn. You can reference the `ImageData.transform` documentation for a list of available parameters. diff --git a/src/modules/image.wren b/src/modules/image.wren index 9a2a2115..5df9744d 100644 --- a/src/modules/image.wren +++ b/src/modules/image.wren @@ -167,8 +167,8 @@ class SpriteSheet { return _cache[s] } - draw(sx, sy, x, y, modMap) { draw(sy * _width + sx, x, y, modMap) } - draw(sx, sy, x, y) { draw(sy * _width + sx, x, y) } + drawFrom(sx, sy, x, y, modMap) { draw(sy * _width + sx, x, y, modMap) } + drawFrom(sx, sy, x, y) { draw(sy * _width + sx, x, y) } draw(s, x, y) { draw(s, x, y, null) } draw(s, x, y, modMap) { getTile(s).modify(modMap || {