Skip to content

Commit

Permalink
fix up everything
Browse files Browse the repository at this point in the history
  • Loading branch information
chucksellick committed Mar 5, 2025
1 parent 61d1173 commit b5505cd
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
33 changes: 21 additions & 12 deletions crawl-ref/source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ CFWARN_L += -Wextra \
DEFINES := $(EXTERNAL_DEFINES)

ifndef ANDROID
LDFLAGS := -sLEGACY_GL_EMULATION -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb -lworkerfs.js -sMAX_WEBGL_VERSION=2 -sGL_UNSAFE_OPTS=0
LDFLAGS := -sASYNCIFY -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb -sLEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0
# LDFLAGS := -sLEGACY_GL_EMULATION -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb -sGL_UNSAFE_OPTS=0 -sMAX_WEBGL_VERSION=2

# -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb -sMAX_WEBGL_VERSION=2
# -sGL_UNSAFE_OPTS=0
# LDFLAGS := -sLEGACY_GL_EMULATION -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb -lworkerfs.js -sMAX_WEBGL_VERSION=2 -sGL_UNSAFE_OPTS=0
endif

#
Expand Down Expand Up @@ -333,21 +338,25 @@ all: greet check-fonts $(GAME) docs webserver

# XX these are set wrong on mac cross-compiling
LIBPCRE := contrib/install/$(ARCH)/lib/libpcre.a
# LIBSDL2 :=
LIBSDL2 := contrib/sdl/build/libSDL2.a
# LIBSDL2 := contrib/install/$(ARCH)/lib/libSDL2.a
LIBPNG := contrib/install/$(ARCH)/lib/libpng.a
LIBSDL2IMAGE :=
LIBSDL2 :=
# LIBSDL2 := contrib/sdl/build/libSDL2.a
LIBSDL2 := contrib/install/$(ARCH)/lib/libSDL2.a
LIBPNG :=
# LIBPNG := contrib/install/$(ARCH)/lib/libpng.a
# LIBSDL2IMAGE :=
LIBSDL2IMAGE := contrib/sdl-image/build/libSDL2_image.a
# LIBSDL2IMAGE := contrib/install/$(ARCH)/lib/libSDL2_image.a
LIBSDL2MIXER := contrib/install/$(ARCH)/lib/libSDL2_mixer.a
LIBFREETYPE := contrib/install/$(ARCH)/lib/libfreetype.a
LIBFREETYPE :=
# LIBFREETYPE := contrib/install/$(ARCH)/lib/libfreetype.a
LIBSQLITE := contrib/install/$(ARCH)/lib/libsqlite3.a
ifdef USE_LUAJIT
LIBLUA := contrib/install/$(ARCH)/lib/libluajit.a
else
LIBLUA := contrib/install/$(ARCH)/lib/liblua.a
endif
LIBZ := contrib/install/$(ARCH)/lib/libz.a
LIBZ :=
# LIBZ := contrib/install/$(ARCH)/lib/libz.a

#
# Set up the TILES variant
Expand Down Expand Up @@ -528,7 +537,7 @@ export HOSTCC
else
# GCC := emcc -pthread -sSHARED_MEMORY -sWASM_WORKERS=1 -sUSE_ZLIB=1 -sUSE_FREETYPE=1 -sUSE_SDL_IMAGE=2
# GCC := emcc -pthread -sSHARED_MEMORY=1 -sWASM_WORKERS=1 -sUSE_ZLIB=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_FREETYPE=1
GCC := emcc -O3 -pthread -sSHARED_MEMORY=1 -sUSE_ZLIB=1 -sUSE_SDL_IMAGE=2 -sUSE_FREETYPE=1
GCC := emcc -O3 -pthread -sSHARED_MEMORY=1 -sWASM_WORKERS=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_ZLIB=1 -sUSE_FREETYPE=1 -sUSE_LIBPNG=1
# GCC := $(LMACH)$(GCC_VER_PREFIX)emcc$(GCC_VER_SUFFIX)
endif

Expand All @@ -539,7 +548,7 @@ export HOSTCXX
else
# GXX := em++ -pthread -sSHARED_MEMORY -sWASM_WORKERS=1 -sUSE_ZLIB=1 -sUSE_FREETYPE=1 -sUSE_SDL_IMAGE=2
# GXX := em++ -pthread -sSHARED_MEMORY=1 -sWASM_WORKERS=1 -sUSE_ZLIB=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_FREETYPE=1
GXX := em++ -O3 -pthread -sSHARED_MEMORY=1 -sUSE_ZLIB=1 -sUSE_SDL_IMAGE=2 -sUSE_FREETYPE=1
GXX := em++ -O3 -pthread -sSHARED_MEMORY=1 -sWASM_WORKERS=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_ZLIB=1 -sUSE_FREETYPE=1 -sUSE_LIBPNG=1
# GXX := $(LMACH)$(GCC_VER_PREFIX)em++$(GCC_VER_SUFFIX)
endif

Expand Down Expand Up @@ -746,7 +755,7 @@ DEFINES_L += -DUSE_TILE_LOCAL

ifdef BUILD_SDL2
INCLUDES_L += -isystem contrib/install/$(ARCH)/include/SDL2
# else
else
# EXTRA_LIBS += contrib/sdl2/build/libSDL2.a
endif
ifdef BUILD_FREETYPE
Expand Down Expand Up @@ -1683,7 +1692,7 @@ distclean: clean clean-contrib clean-rltiles
$(RM) -r $(DOXYGEN_HTML_GEN)

$(GAME): $(GAME_OBJS) $(CONTRIB_LIBS) dat/dlua/tags.lua
+$(QUIET_LINK)$(CXX) $(LDFLAGS) $(GAME_OBJS) -o $(GAME).html $(LIBS) --preload-file dat --use-preload-plugins
+$(QUIET_LINK)$(CXX) $(LDFLAGS) $(GAME_OBJS) -o $(GAME).html $(LIBS) --preload-file dat --preload-file usr --preload-file docs/crawl_manual.txt --use-preload-plugins

util/monster/vault_monster_data.h: dat/des util/gather_mons
util/gather_mons -v > $@
Expand Down
21 changes: 14 additions & 7 deletions crawl-ref/source/glwrapper-ogl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# ifdef USE_GLES
# ifdef __ANDROID__
# include <SDL.h>
# elif defined(__EMSCRIPTEN__)
# include <SDL2/SDL.h>
# include <SDL_opengles2.h>
# else
# include <SDL2/SDL.h>
# include <SDL_gles.h>
Expand Down Expand Up @@ -62,7 +65,7 @@ namespace opengl
return "GL_INVALID_VALUE";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
#endif
Expand Down Expand Up @@ -383,7 +386,7 @@ void OGLStateManager::reset_view_for_resize(const coord_def &m_windowsz,

// For ease, vertex positions are pixel positions.
#ifdef USE_GLES
# ifdef __ANDROID__
# if defined(__ANDROID__)
glOrthof(0, m_windowsz.x, m_windowsz.y, 0, -1000, 1000);
# else
glOrthox(0, m_windowsz.x, m_windowsz.y, 0, -1000, 1000);
Expand Down Expand Up @@ -423,19 +426,23 @@ void OGLStateManager::load_texture(unsigned char *pixels, unsigned int width,
int xoffset, int yoffset)
{
// Assumptions...
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
const GLenum bpp = GL_RGBA;
#else
const unsigned int bpp = 4;
#endif
const GLenum texture_format = GL_RGBA;
const GLenum format = GL_UNSIGNED_BYTE;
// Also assume that the texture is already bound using bind_texture

printf("Loading texture %i %i %i", GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#ifdef __EMSCRIPTEN__
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, GL_MODULATE);
#else
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#endif
glDebug("glTexEnvf");

#ifdef GL_CLAMP
#if defined(GL_CLAMP) && !defined(__EMSCRIPTEN__)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
#else
Expand All @@ -455,7 +462,7 @@ void OGLStateManager::load_texture(unsigned char *pixels, unsigned int width,
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
Options.tile_filter_scaling ? GL_LINEAR : GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, bpp, width, height, 0,
texture_format, format, pixels);
texture_format, format, pixels);
// TODO: possibly restructure this into the main block below
// so that we support mipmapping when glTexSubImage2D should be called.
if (m_mipmapFn != nullptr)
Expand All @@ -481,7 +488,7 @@ void OGLStateManager::load_texture(unsigned char *pixels, unsigned int width,
else
{
glTexImage2D(GL_TEXTURE_2D, 0, bpp, width, height, 0,
texture_format, format, pixels);
texture_format, format, pixels);
glDebug("glTexImage2D");
}
}
Expand Down
1 change: 1 addition & 0 deletions crawl-ref/source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,7 @@ static keycode_type _get_next_keycode()
}
else
break;
emscripten_sleep(1);
}

// This is the main clear_messages() with Option.clear_messages.
Expand Down
5 changes: 5 additions & 0 deletions crawl-ref/source/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "unwind.h"
#include "view.h"

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

static void _mpr(string text, msg_channel_type channel=MSGCH_PLAIN, int param=0,
bool nojoin=false, bool cap=true);

Expand Down Expand Up @@ -1508,6 +1512,7 @@ static int _last_msg_turn = -1; // Turn of last message.
static void _mpr(string text, msg_channel_type channel, int param, bool nojoin,
bool cap)
{
emscripten_log(EM_LOG_CONSOLE, text.c_str());
static bool _doing_c_message_hook = false;

rng::generator rng(rng::UI);
Expand Down
24 changes: 24 additions & 0 deletions crawl-ref/source/startup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
#ifdef __ANDROID__
#include "syscalls.h"
#endif
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include "version.h"

using namespace ui;
Expand All @@ -89,8 +92,12 @@ static void _initialize()

rng::seed(); // don't use any chosen seed yet

emscripten_log(EM_LOG_CONSOLE, "Seeded rng");

clua.init_libraries();

emscripten_log(EM_LOG_CONSOLE, "Inited clua");

init_char_table(Options.char_set);
init_show_table();
init_monster_symbols();
Expand All @@ -102,11 +109,15 @@ static void _initialize()
init_mon_name_cache();
init_mons_spells();

emscripten_log(EM_LOG_CONSOLE, "Inited stuff");

// init_item_name_cache() needs to be redone after init_char_table()
// and init_show_table() have been called, so that the glyphs will
// be set to use with item_names_by_glyph_cache.
init_item_name_cache();

emscripten_log(EM_LOG_CONSOLE, "Inited item name cache");

unwind_bool no_more(crawl_state.show_more_prompt, false);

// Init item array.
Expand All @@ -116,28 +127,40 @@ static void _initialize()
reset_all_monsters();
init_anon();

emscripten_log(EM_LOG_CONSOLE, "Inited loads of stuff");

env.igrid.init(NON_ITEM);
env.mgrid.init(NON_MONSTER);
env.map_knowledge.init(map_cell());
env.pgrid.init(terrain_property_t{});

emscripten_log(EM_LOG_CONSOLE, "Inited grid");

you.unique_creatures.reset();
you.unique_items.init(UNIQ_NOT_EXISTS);

emscripten_log(EM_LOG_CONSOLE, "Inited unqiues");

// Set up the Lua interpreter for the dungeon builder.
init_dungeon_lua();

emscripten_log(EM_LOG_CONSOLE, "Inited dlua");

#ifdef USE_TILE_LOCAL
// Draw the splash screen before the database gets initialised as that
// may take awhile and it's better if the player can look at a pretty
// screen while this happens.
loading_screen_open();
#endif

emscripten_log(EM_LOG_CONSOLE, "Loading screen opened");

// Initialise internal databases.
_loading_message("Loading databases...");
databaseSystemInit();

emscripten_log(EM_LOG_CONSOLE, "Database loaded");

_loading_message("Loading spells and features...");
init_feat_desc_cache();
init_spell_name_cache();
Expand All @@ -158,6 +181,7 @@ static void _initialize()
#ifdef USE_TILE_LOCAL
loading_screen_close();
#endif
emscripten_log(EM_LOG_CONSOLE, "Loading screen closed");

you.game_seed = crawl_state.seed;

Expand Down
5 changes: 5 additions & 0 deletions crawl-ref/source/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ class writer
: _filename(), _file(0), _chunk(0), _ignore_errors(false),
failed(false)
{
#ifndef __EMSCRIPTEN__
ASSERT(save);
_chunk = save->writer(chunkname);
#else
if (save)
_chunk = save->writer(chunkname);
#endif
}

~writer() { if (_chunk) delete _chunk; }
Expand Down

0 comments on commit b5505cd

Please sign in to comment.