Skip to content

Commit 8ebae00

Browse files
committed
4/22
1 parent fa3f75a commit 8ebae00

9 files changed

Lines changed: 455 additions & 37 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Deploy Web Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
concurrency:
16+
group: pages
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Configure Pages
27+
uses: actions/configure-pages@v5
28+
29+
- name: Install native build tools
30+
run: sudo apt-get update && sudo apt-get install -y cmake ninja-build
31+
32+
- name: Install Emscripten SDK
33+
run: |
34+
git clone https://github.com/emscripten-core/emsdk.git "$RUNNER_TEMP/emsdk"
35+
cd "$RUNNER_TEMP/emsdk"
36+
./emsdk install latest
37+
./emsdk activate latest
38+
39+
- name: Build WebAssembly site
40+
run: |
41+
source "$RUNNER_TEMP/emsdk/emsdk_env.sh"
42+
emcmake cmake -S . -B build-web -G Ninja -DCMAKE_BUILD_TYPE=Release
43+
cmake --build build-web
44+
45+
mkdir -p site
46+
cp build-web/PathFindingVisualizer.html site/index.html
47+
cp build-web/PathFindingVisualizer.js site/
48+
cp build-web/PathFindingVisualizer.wasm site/
49+
if [ -f build-web/PathFindingVisualizer.data ]; then
50+
cp build-web/PathFindingVisualizer.data site/
51+
fi
52+
touch site/.nojekyll
53+
54+
- name: Upload Pages artifact
55+
uses: actions/upload-pages-artifact@v3
56+
with:
57+
path: site
58+
59+
deploy:
60+
needs: build
61+
runs-on: ubuntu-latest
62+
environment:
63+
name: github-pages
64+
url: ${{ steps.deployment.outputs.page_url }}
65+
steps:
66+
- name: Deploy to GitHub Pages
67+
id: deployment
68+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

22
*build/
3+
build-web/
34
.vs/
4-
out/
5+
out/
6+
site/

Aframework/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#递归本文件夹所有的.cpp文件
2-
file(GLOB_RECURSE AFRAMEWORK CONFIGURE_DEPENDS ./*.cpp)
1+
file(GLOB AFRAMEWORK ./*.cpp)
2+
33
add_library(AframeworkLib ${AFRAMEWORK})

CMakeLists.txt

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.12)
1+
cmake_minimum_required(VERSION 3.13)
22

33
project(PathFindingStatVisualizer)
44

@@ -9,12 +9,17 @@ if(MSVC)
99
add_compile_options(/utf-8)
1010
endif()
1111

12-
file(GLOB ASSETS "./assets")
13-
file(COPY ${ASSETS} DESTINATION ${CMAKE_BINARY_DIR})
14-
1512
set(SDL_LINK_LIBS)
1613

17-
if(WIN32)
14+
if(EMSCRIPTEN)
15+
message(STATUS "Configuring WebAssembly build with Emscripten")
16+
add_compile_options(
17+
"SHELL:-sUSE_SDL=2"
18+
"SHELL:-sUSE_SDL_TTF=2"
19+
"SHELL:-sUSE_SDL_IMAGE=2"
20+
"SHELL:-sUSE_SDL_MIXER=2"
21+
)
22+
elseif(WIN32)
1823
include_directories("thirdparty/include")
1924

2025
if(MSVC)
@@ -64,7 +69,7 @@ set(PATH_FINDING_VISUALIZER_SOURCES
6469
"status.h"
6570
)
6671

67-
if(WIN32)
72+
if(WIN32 AND NOT EMSCRIPTEN)
6873
enable_language(RC)
6974
configure_file(
7075
"${CMAKE_SOURCE_DIR}/assets/icon/app_icon.rc.in"
@@ -76,19 +81,45 @@ endif()
7681

7782
add_executable(PathFindingVisualizer ${PATH_FINDING_VISUALIZER_SOURCES})
7883

79-
if(WIN32)
84+
if(WIN32 AND NOT EMSCRIPTEN)
8085
set_target_properties(PathFindingVisualizer PROPERTIES
8186
WIN32_EXECUTABLE "$<CONFIG:Release>"
8287
)
8388
endif()
8489

85-
target_link_libraries(PathFindingVisualizer
86-
applicationLib algorithmLib AframeworkLib imguiLib
90+
if(EMSCRIPTEN)
91+
set_target_properties(PathFindingVisualizer PROPERTIES SUFFIX ".html")
92+
endif()
93+
94+
target_link_libraries(
95+
PathFindingVisualizer
96+
applicationLib
97+
algorithmLib
98+
AframeworkLib
99+
imguiLib
87100
${SDL_LINK_LIBS}
88101
)
89102

90-
add_custom_command(TARGET PathFindingVisualizer POST_BUILD
91-
COMMAND ${CMAKE_COMMAND} -E copy_directory
92-
"${CMAKE_SOURCE_DIR}/assets"
93-
"$<TARGET_FILE_DIR:PathFindingVisualizer>/assets"
94-
)
103+
if(EMSCRIPTEN)
104+
target_link_options(PathFindingVisualizer PRIVATE
105+
"SHELL:-sUSE_SDL_TTF=2"
106+
"SHELL:-sUSE_SDL_IMAGE=2"
107+
"SHELL:-sUSE_SDL_MIXER=2"
108+
"SHELL:--use-port=sdl2"
109+
"SHELL:--use-port=sdl2_image:formats=png"
110+
"SHELL:-sALLOW_MEMORY_GROWTH=1"
111+
"SHELL:-sASSERTIONS=1"
112+
"SHELL:-sNO_EXIT_RUNTIME=1"
113+
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/assets@/assets"
114+
"SHELL:--shell-file ${CMAKE_SOURCE_DIR}/web/shell.html"
115+
)
116+
else()
117+
file(GLOB ASSETS "./assets")
118+
file(COPY ${ASSETS} DESTINATION ${CMAKE_BINARY_DIR})
119+
120+
add_custom_command(TARGET PathFindingVisualizer POST_BUILD
121+
COMMAND ${CMAKE_COMMAND} -E copy_directory
122+
"${CMAKE_SOURCE_DIR}/assets"
123+
"$<TARGET_FILE_DIR:PathFindingVisualizer>/assets"
124+
)
125+
endif()

algorithm/path_finder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Pathfinder
8686
[[nodiscard]] bool rebuild_path(Point start, Point goal);
8787

8888
Board* _board = nullptr;
89-
MoveMode _move_mode = MoveMode::FourWay;
89+
MoveMode _move_mode = MoveMode::EightWay;
9090
DiagonalMovePolicy _diagonal_policy = DiagonalMovePolicy::BlockIfEitherSideBlocked;
9191

9292
bool _finished = false;

0 commit comments

Comments
 (0)