From a058f92f77438f7df07fa0e557595c620bce8f02 Mon Sep 17 00:00:00 2001 From: kartofen Date: Tue, 11 Apr 2023 00:03:29 +0300 Subject: web build works --- build.sh | 34 +++++++++++++++++------- src/main.c | 7 ++--- src/sector.c | 2 +- src/shell.html | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 16 deletions(-) create mode 100644 src/shell.html diff --git a/build.sh b/build.sh index 8405053..9a37dce 100755 --- a/build.sh +++ b/build.sh @@ -5,15 +5,22 @@ cd ${0%/*} # go to project root NAME="main" DEBUG_FLAGS="-std=c99 -Wall -Wextra -g -pedantic -DDEBUG" -# PROD_FLAGS="-std=c99 ???" +PROD_FLAGS="-std=c99 -O2" SDL_FLAGS="`sdl2-config --cflags --libs`" -FLAGS="$DEBUG_FLAGS $SDL_FLAGS -lm" +LIB_FLAGS="-lm" + +FLAGS="$DEBUG_FLAGS $SDL_FLAGS $LIB_FLAGS" SRC="src" OBJ="obj" BIN="bin" FILES="files" RUN=0 +WEB=0 + +function __web__ { + WEB=1 +} function __run__ { RUN=1 @@ -25,7 +32,7 @@ function __leak__ { } function __prod__ { - FLAGS="$PROD_FLAGS $SDL_FLAGS" + FLAGS="$PROD_FLAGS $SDL_FLAGS $LIB_FLAGS" } function __clean__ { @@ -45,13 +52,20 @@ then __$1__ fi -gcc -o $OBJ/main.o -c $SRC/main.c $FLAGS -gcc -o $OBJ/player.o -c $SRC/player.c $FLAGS -gcc -o $OBJ/sector.o -c $SRC/sector.c $FLAGS +if { [[ $WEB -eq 0 ]]; } 2> /dev/null; then + gcc -o $OBJ/main.o -c $SRC/main.c $FLAGS + gcc -o $OBJ/player.o -c $SRC/player.c $FLAGS + gcc -o $OBJ/sector.o -c $SRC/sector.c $FLAGS -gcc -o $BIN/$NAME $OBJ/*.o $FLAGS + gcc -o $BIN/$NAME $OBJ/*.o $FLAGS -if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null -then - $VALGRND $BIN/$NAME + if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null; then + $VALGRND $BIN/$NAME + fi +else + emcc -o $BIN/portal-engine.html $SRC/*.c \ + $PROD_FLAGS $LIB_FLAGS \ + -s USE_SDL=2 -s ASYNCIFY \ + --shell-file $SRC/shell.html \ + --preload-file $FILES/map_clear.txt fi diff --git a/src/main.c b/src/main.c index 16d127e..432d26f 100644 --- a/src/main.c +++ b/src/main.c @@ -36,11 +36,6 @@ int main(void) SDL_Window *window = NULL; map_t map = {0}; - if(SDL_ShowCursor(SDL_DISABLE) < 0) { - log_error(LOG_INPUT, "SDL_ShowCursor: %s", SDL_GetError()); - } - - if(SDL_Init(SDL_INIT_VIDEO) != 0) { log_critical(LOG_VIDEO, "SDL_Init: %s", SDL_GetError()); goto exit; @@ -59,6 +54,8 @@ int main(void) log_critical(LOG_VIDEO, "SDL_GetWindowSurface %s", SDL_GetError()); goto exit; } + + SDL_SetRelativeMouseMode(SDL_TRUE); // --------------------------------------------- // if(map_load(&map, "files/map_clear.txt")) diff --git a/src/sector.c b/src/sector.c index a76b698..c315382 100644 --- a/src/sector.c +++ b/src/sector.c @@ -34,7 +34,7 @@ int map_draw(map_t *map, int SW, int SH) head = (head+1) % MAX_QUEUE; struct render_info now = queue[head]; - if(sect_rendered[now.sectno] >= 30) continue; + if(sect_rendered[now.sectno] >= 5) continue; struct sector *sect = &map->sectors[now.sectno]; for(size_t i = 0; i < sect->nverts; i++) diff --git a/src/shell.html b/src/shell.html new file mode 100644 index 0000000..03321c7 --- /dev/null +++ b/src/shell.html @@ -0,0 +1,83 @@ + + + + + + Pendulum + + + +
Downloading...
+ +
+ +
+ + + + + {{{ SCRIPT }}} + + +d -- cgit v1.2.3