Skip to content

Commit

Permalink
Fix emscripten (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn committed Dec 17, 2017
1 parent ef03367 commit 8478ed1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.emscripten.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ To build xash3d for emscripten, clone forked emscripten to home directory

```
git clone https://github.com/FWGS/emscripten -b xash3d
wget https://github.com/FWGS/emscripten-fastcomp/releases/download/xash3d-0.1/fastcomp.txz -O - |tar x
wget https://github.com/FWGS/emscripten-fastcomp/releases/download/xash3d-0.1/fastcomp.txz -O - |tar xJ
```

Set correct emscripten path in ~/.emscripten to make emcc work
Expand All @@ -66,7 +66,7 @@ clone xash3d repo:
```
git clone https://github.com/FWGS/xash3d
cd xash3d
git sumodule init && git submodule update
git submodule init && git submodule update
```

Switch to branch containing this file
Expand All @@ -87,7 +87,7 @@ Edit Makefile.emscripten to ensure using correct output paths (by default, ~/xas

Clone microndk repo

`git clone https://github.com/FWGS/mircondk`
`git clone https://github.com/FWGS/microndk`

Change dir to mainui_cpp, dlls or cl_dlls directory and do:

Expand Down
30 changes: 10 additions & 20 deletions engine/Makefile.emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
##############################################


CC = ~//emscripten/emcc --llvm-lto 3 -s INLINING_LIMIT=10
CXX = ~/emscripten/em++ --llvm-lto 3 -s INLINING_LIMIT=10
CC = ~/emscripten/emcc --llvm-lto 3 -s INLINING_LIMIT=10 -s USE_SDL=2
CXX = ~/emscripten/em++ --llvm-lto 3 -s INLINING_LIMIT=10 -s USE_SDL=2
# async mode - produces very large scripts. Unuseful with shared libraries
ASYNC ?= 0

OUTPUT_DIR ?= xash-em

XASH_COMMIT := $(firstword $(shell git rev-parse --short=6 HEAD) unknown)

ifeq ($(XASH_COMMIT),unknown)
Expand All @@ -34,7 +36,7 @@ ifeq ($(EMSCRIPTEN_SIMD),1)
CC += -s SIMD=1
CXX += -s SIMD=1
endif
CFLAGS =-Os -g0 -Wall -Wextra -Wsign-compare -Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-but-set-variable
CFLAGS =-Os -g0 -Wall -Wextra -Wsign-compare -Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-unused-parameter
obj/common/launcher.o : override CFLAGS = -O0 -g0
LDFLAGS =
LIBS = -lm
Expand All @@ -48,15 +50,14 @@ endif
TOPDIR = $(PWD)/..
INCLUDES :=
XASH_SINGLE_BINARY ?= 1
XASH_X11 ?= 1
INSTALL_DIR ?= ./install/
ifeq ($(NANOGL),1)
INCLUDES += -Inanogl -Inanogl/GL
endif
ifeq ($(WES),1)
INCLUDES += -Inanogl -Inanogl/GL -Igl-wes-v2/src
endif
INCLUDES += -I/usr/include/SDL2 -Icommon -I../common -I. -I../pm_shared -Iclient -Iserver -Iclient/vgui -Icommon/sdl
INCLUDES += -Icommon -I../common -I. -I../pm_shared -Iclient -Iserver -Iclient/vgui -Icommon/sdl

DEFINES = -DDEFAULT_DEV=5 -DXASH_SDL_DISABLE_RESIZE -DDEFAULT_MODE_WIDTH=640 -DDEFAULT_MODE_HEIGHT=480 -DDEFAULT_FULLSCREEN=0 -DWES_WEBGL -DXASH_ALLOW_SAVERESTORE_OFFSETS -DUSE_STB_SPRINTF=0 -DNO_SJLJ

Expand All @@ -76,11 +77,7 @@ ifeq ($(XASH_DEDICATED),1)
DEFINES += -DXASH_DEDICATED
else
DEFINES += -DXASH_SDL
LIBS += -lSDL2 -pthread
ifeq ($(XASH_X11),1)
LIBS += -lX11
DEFINES += -DXASH_X11
endif
LIBS += -pthread
endif

ifeq ($(NANOGL),1)
Expand All @@ -99,13 +96,6 @@ ifeq ($(XASH_STATIC),1)
XASH_SINGLE_BINARY := 1
endif

ifneq ($(XASH_STATIC),1)
LIBS += -ldl
endif

ifeq ($(XASH_STATIC_LIBDL),1)
LIBS += -ldl
endif
ifeq ($(XASH_DLL_LOADER),1)
DEFINES += -DDLL_LOADER
ifeq ($(XASH_SINGLE_BINARY),1)
Expand Down Expand Up @@ -145,12 +135,12 @@ SRCS += $(wildcard platform/sdl/*.c)
endif
OBJS = $(patsubst %.c,obj/%.o,$(SRCS))

~/xash-em/xash$(SIMD_SUF).html: $(OBJS) $(OBJS_CPP) platform/emscripten/shell.html
EMCC_FORCE_STDLIBS=1 $(CXX) -O3 --js-opts 1 -s INLINING_LIMIT=10 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s LEGACY_GL_CREATE_RESOURCE_ON_BIND=1 -s UNALIGNED_ACCESS_FUNCTION_LIST=\"platform/emscripten/unaligned.txt\" --shell-file platform/emscripten/shell.html -s NO_EXIT_RUNTIME=0 -s LZ4=1 -s -g0 -o "$@" -s MAIN_MODULE=1 -s USE_SDL=2 -s TOTAL_MEMORY=150994944 -fvisibility=hidden $(LDFLAGS) $(OBJS) $(OBJS_CPP) $(LIBS)
$(OUTPUT_DIR)/xash$(SIMD_SUF).html: $(OBJS) $(OBJS_CPP) platform/emscripten/shell.html
EMCC_FORCE_STDLIBS=1 $(CXX) -O3 --js-opts 1 -s INLINING_LIMIT=10 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s LEGACY_GL_CREATE_RESOURCE_ON_BIND=1 -s UNALIGNED_ACCESS_FUNCTION_LIST=\"platform/emscripten/unaligned.txt\" --shell-file platform/emscripten/shell.html -s NO_EXIT_RUNTIME=0 -s LZ4=1 -s -g0 -o "$@" -s MAIN_MODULE=1 -s TOTAL_MEMORY=150994944 -fvisibility=hidden $(LDFLAGS) $(OBJS) $(OBJS_CPP) $(LIBS)



DIRS := obj obj/server obj/client/vgui obj/common/sdl obj/common/imagelib obj/common/soundlib/libmpg obj/platform/sdl obj/nanogl
DIRS := obj obj/server obj/client/vgui obj/common/sdl obj/common/imagelib obj/common/soundlib/libmpg obj/platform/sdl obj/nanogl obj/gl-wes-v2/src $(OUTPUT_DIR)


$(OBJS): | $(DIRS)
Expand Down
3 changes: 1 addition & 2 deletions engine/platform/sdl/gl_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/

#if XASH_VIDEO == VIDEO_SDL && !defined XASH_GL_STATIC
#include "common.h"
#if XASH_VIDEO == VIDEO_SDL && !defined XASH_GL_STATIC
#include "client.h"
#include "gl_local.h"
#include "mod_local.h"
Expand Down
1 change: 1 addition & 0 deletions engine/platform/sdl/gl_sdl_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ GL_CreateContext
*/
qboolean GL_CreateContext( void )
{
int colorBits[3];
#ifdef XASH_NANOGL
nanoGL_Init();
#endif
Expand Down
4 changes: 3 additions & 1 deletion engine/platform/sdl/snd_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ void SNDDMA_Shutdown( void )
SDL_PauseAudioDevice( sdl_dev, 1 );
#ifndef __EMSCRIPTEN__
SDL_CloseAudioDevice( sdl_dev );
#endif
SDL_CloseAudio( );
#endif
}

#ifndef __EMSCRIPTEN__
if( SDL_WasInit( SDL_INIT_AUDIO ) )
SDL_QuitSubSystem( SDL_INIT_AUDIO );
#endif

if( dma.buffer )
{
Expand Down

0 comments on commit 8478ed1

Please sign in to comment.