Remove TARGET_WEB (#159)

Just a simple code cleanup opportunity I saw
"I won't be porting this to the web" - djoslin

Compiled and tested everything to see if it works, feel free to check yourself or look over the code

Also, I noticed TARGET_N64 was there too, might do a clean up on that since we all know this isn't getting ported to the N64 anytime soon.
This commit is contained in:
Agent X 2022-08-25 20:32:20 -04:00 committed by GitHub
parent 029dcb9bdb
commit 7e1110cde9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 16 additions and 334 deletions

View file

@ -30,9 +30,6 @@ TARGET_N64 = 0
# Build and optimize for Raspberry Pi(s)
TARGET_RPI ?= 0
# Build for Emscripten/WebGL
TARGET_WEB ?= 0
# Makeflag to enable OSX fixes
OSX_BUILD ?= 0
@ -132,10 +129,8 @@ else
endif
endif
ifeq ($(TARGET_WEB),0)
ifeq ($(HOST_OS),Windows)
WINDOWS_BUILD := 1
endif
ifeq ($(HOST_OS),Windows)
WINDOWS_BUILD := 1
endif
# MXE overrides
@ -239,10 +234,6 @@ else
PROF_FLAGS :=
endif
ifeq ($(TARGET_WEB),1)
OPT_FLAGS := -O2 -g4 --source-map-base http://localhost:8080/
endif
ifeq ($(TARGET_RPI),1)
machine = $(shell sh -c 'uname -m 2>/dev/null || echo unknown')
@ -321,10 +312,6 @@ ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL
DEFINES += OSX_BUILD=1
endif
ifeq ($(TARGET_WEB),1)
DEFINES := $(DEFINES) -DTARGET_WEB -DUSE_GLES
endif
# Check backends
ifneq (,$(filter $(RENDER_API),D3D11 D3D12))
@ -490,23 +477,15 @@ _ := $(shell $(PYTHON) $(TOOLS_DIR)/copy_mario_sounds.py)
BUILD_DIR_BASE := build
# BUILD_DIR is the location where all build artifacts are placed
ifeq ($(TARGET_WEB),1)
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_web
else
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
endif
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
ifeq ($(TARGET_WEB),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).html
else
ifeq ($(WINDOWS_BUILD),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).exe
else # Linux builds/binary namer
ifeq ($(TARGET_RPI),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).arm
else
EXE := $(BUILD_DIR)/$(TARGET_STRING)
endif
ifeq ($(WINDOWS_BUILD),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).exe
else # Linux builds/binary namer
ifeq ($(TARGET_RPI),1)
EXE := $(BUILD_DIR)/$(TARGET_STRING).arm
else
EXE := $(BUILD_DIR)/$(TARGET_STRING)
endif
endif
@ -701,9 +680,6 @@ else ifeq ($(COMPILER),clang)
CXX := clang++
CPP := clang++
EXTRA_CFLAGS += -Wno-unused-function -Wno-unused-variable -Wno-unknown-warning-option -Wno-self-assign -Wno-unknown-pragmas -Wno-unused-result
else ifeq ($(TARGET_WEB),1) # As in, web PC port
CC := emcc
CXX := emcc
else
ifeq ($(USE_QEMU_IRIX),1)
IRIX_ROOT := $(TOOLS_DIR)/ido5.3_compiler
@ -865,9 +841,6 @@ ifeq ($(WINDOWS_BUILD),1)
ifeq ($(TARGET_BITS), 32)
BACKEND_LDFLAGS += -ldbghelp
endif
else ifeq ($(TARGET_WEB),1)
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -Wall -Wextra -Wno-format-security $(TARGET_CFLAGS) -s USE_SDL=2
CFLAGS := $(OPT_FLAGS) $(DEF_INC_CFLAGS) $(BACKEND_CFLAGS) $(TARGET_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
else ifeq ($(TARGET_N64),0) # Linux / Other builds below
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(DEF_INC_CFLAGS) -Wall -Wextra $(TARGET_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(DEF_INC_CFLAGS) $(BACKEND_CFLAGS) $(TARGET_CFLAGS) -fno-strict-aliasing -fwrapv
@ -902,9 +875,7 @@ ifeq ($(TARGET_N64),1)
endif
endif
ifeq ($(TARGET_WEB),1)
LDFLAGS := -lm -lGL -lSDL2 -no-pie -s TOTAL_MEMORY=20MB -g4 --source-map-base http://localhost:8080/ -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain']"
else ifeq ($(WINDOWS_BUILD),1)
ifeq ($(WINDOWS_BUILD),1)
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread $(BACKEND_LDFLAGS) -static
ifeq ($(CROSS),)
LDFLAGS += -no-pie

View file

@ -164,8 +164,6 @@ make VERSION=jp -j6 # Compila la versión (J) usando 6
make VERSION=us MARCH=i686 TARGET_BITS=32 # Compila un ejecutable de la versión (U) de 32 bits
make TARGET_RPI=1 # Compila un ejecutable para Raspberry Pi
```
## Compilar para la web
Puedes compilar el juego para navegadores que admitan WebGL usando [Emscripten](https://github.com/emscripten-core). Para hacerlo, instala [emsdk](https://github.com/emscripten-core/emsdk) y ejecuta `make TARGET_WEB=1`.
## Script para compilar para Raspberry Pi
@ -185,19 +183,13 @@ El script está incluído en la rama master, pero también puede descargarse [aq
* La versión EU tiene bugs en los textos y no tiene audio.
* El movimiento analógico horizontal de la cámara vuelve al estilo antiguo en el nivel Bowser in the Dark World (#72)
* La cámara con el ratón falla cuando disparas a Mario hacia un árbol o un tubo. (#71)
* "make: Nothing to be done for 'default'" al compilar para web. (#67)
### Estos problemas están marcados como solucionados. Por favor, contacta si sigues teniendo estos problemas.
* El juego se llena de flags aleatorias en las builds de 64 bits para Windows
* Hazy Maze Cave se cuelga en pantalla completa (#57)
* La pantalla de título no tiene el cursor para manipular a Mario en pantalla completa. (#28)
## Parches
En la carpeta `./enhancements` hay varios archivos `patch`, que pueden aplicarse de la siguiente manera:
```
git apply fps.patch --ignore-whitespace --reject
```
Si ocurre un rechazo, puedes buscarlo con el comando `find | grep .rej`.
Intenta resolver los rechazos a través de [wiggle](https://github.com/neilbrown/wiggle).
```

View file

@ -27,6 +27,7 @@
#include "level_table.h"
#include "src/pc/lua/utils/smlua_model_utils.h"
#include "src/pc/lua/smlua.h"
#include "src/pc/djui/djui.h"
#define CMD_GET(type, offset) (*(type *) (CMD_PROCESS_OFFSET(offset) + (u8 *) sCurrentCmd))
@ -763,7 +764,7 @@ static void level_cmd_nop(void) {
}
static void level_cmd_show_dialog(void) {
if (sCurrAreaIndex != -1) {
if (sCurrAreaIndex != -1 && !gDjuiInMainMenu) {
if (CMD_GET(u8, 2) < 2) {
gAreas[sCurrAreaIndex].dialog[CMD_GET(u8, 2)] = CMD_GET(u8, 3);
}

View file

@ -1,151 +0,0 @@
#ifdef TARGET_WEB
#include <string.h>
#include <emscripten/html5.h>
#include "macros.h"
#include "controller_keyboard.h"
static const struct {
const char *code;
int scancode;
} keymap_browser[] = {
{"Escape", 0x01},
{"Digit1", 0x02 },
{"Digit2", 0x03 },
{"Digit3", 0x04 },
{"Digit4", 0x05 },
{"Digit5", 0x06 },
{"Digit6", 0x07 },
{"Digit7", 0x08 },
{"Digit8", 0x09 },
{"Digit9", 0x0a },
{"Digit0", 0x0b },
{"Minus", 0x0c },
{"Equal", 0x0d },
{"Backspace", 0x0e },
{"Tab", 0x0f },
{"KeyQ", 0x10 },
{"KeyW", 0x11 },
{"KeyE", 0x12 },
{"KeyR", 0x13 },
{"KeyT", 0x14 },
{"KeyY", 0x15 },
{"KeyU", 0x16 },
{"KeyI", 0x17 },
{"KeyO", 0x18 },
{"KeyP", 0x19 },
{"BracketLeft", 0x1a },
{"BracketRight", 0x1b },
{"Enter", 0x1c },
{"ControlLeft", 0x1d },
{"KeyA", 0x1e },
{"KeyS", 0x1f },
{"KeyD", 0x20 },
{"KeyF", 0x21 },
{"KeyG", 0x22 },
{"KeyH", 0x23 },
{"KeyJ", 0x24 },
{"KeyK", 0x25 },
{"KeyL", 0x26 },
{"Semicolon", 0x27 },
{"Quote", 0x28 },
{"Backquote", 0x29 },
{"ShiftLeft", 0x2a },
{"Backslash", 0x2b },
{"KeyZ", 0x2c },
{"KeyX", 0x2d },
{"KeyC", 0x2e },
{"KeyV", 0x2f },
{"KeyB", 0x30 },
{"KeyN", 0x31 },
{"KeyM", 0x32 },
{"Comma", 0x33 },
{"Period", 0x34 },
{"Slash", 0x35 },
{"ShiftRight", 0x36 },
{"NumpadMultiply", 0x37 },
{"AltLeft", 0x38 },
{"Space", 0x39 },
{"CapsLock", 0x3a },
{"F1", 0x3b },
{"F2", 0x3c },
{"F3", 0x3d },
{"F4", 0x3e },
{"F5", 0x3f },
{"F6", 0x40 },
{"F7", 0x41 },
{"F8", 0x42 },
{"F9", 0x43 },
{"F10", 0x44 },
{"NumLock", 0x45 },
{"ScrollLock", 0x46 },
{"Numpad7", 0x47 },
{"Numpad8", 0x48 },
{"Numpad9", 0x49 },
{"NumpadSubtract", 0x4a },
{"Numpad4", 0x4b },
{"Numpad5", 0x4c },
{"Numpad6", 0x4d },
{"NumpadAdd", 0x4e },
{"Numpad1", 0x4f },
{"Numpad2", 0x50 },
{"Numpad3", 0x51 },
{"Numpad0", 0x52 },
{"NumpadDecimal", 0x53 },
{"PrintScreen", 0x54 },
// 0x55
{"IntlBackslash", 0x56 },
{"F11", 0x57 },
{"F12", 0x58 },
{"IntlRo", 0x59 },
//{"Katakana", 0 },
//{"Hiragana", 0 },
{"NumpadEnter", 0x11c },
{"ControlRight", 0x11d },
{"NumpadDivide", 0x135 },
{"AltRight", 0x138 },
{"Home", 0x147 },
{"ArrowUp", 0x148 },
{"PageUp", 0x149 },
{"ArrowLeft", 0x14b },
{"ArrowRight", 0x14d },
{"End", 0x14f },
{"ArrowDown", 0x150 },
{"PageDown", 0x151 },
{"Insert", 0x152 },
{"Delete", 0x153 },
{"Pause", 0x21d },
{"MetaLeft", 0x15b },
{"MetaRight", 0x15c },
{"ContextMenu", 0x15d },
};
static EM_BOOL controller_emscripten_keyboard_handler(int event_type, const EmscriptenKeyboardEvent *key_event, UNUSED void *user_data) {
for (size_t i = 0; i < sizeof(keymap_browser) / sizeof(keymap_browser[0]); i++) {
if (strcmp(key_event->code, keymap_browser[i].code) == 0) {
if (event_type == EMSCRIPTEN_EVENT_KEYDOWN) {
return keyboard_on_key_down(keymap_browser[i].scancode);
} else if (event_type == EMSCRIPTEN_EVENT_KEYUP) {
return keyboard_on_key_up(keymap_browser[i].scancode);
}
break;
}
}
return EM_FALSE;
}
static EM_BOOL controller_emscripten_keyboard_blur_handler(UNUSED int event_type, UNUSED const EmscriptenFocusEvent *focus_event, UNUSED void *user_data) {
keyboard_on_all_keys_up();
return EM_TRUE;
}
void controller_emscripten_keyboard_init(void) {
// Should be #window according to docs, but that crashes
const char *target = EMSCRIPTEN_EVENT_TARGET_WINDOW;
emscripten_set_keydown_callback(target, NULL, EM_FALSE, controller_emscripten_keyboard_handler);
emscripten_set_keyup_callback(target, NULL, EM_FALSE, controller_emscripten_keyboard_handler);
emscripten_set_blur_callback(target, NULL, EM_FALSE, controller_emscripten_keyboard_blur_handler);
}
#endif

View file

@ -1,8 +0,0 @@
#ifndef CONTROLLER_KEYBOARD_EMSCRIPTEN_H
#define CONTROLLER_KEYBOARD_EMSCRIPTEN_H
#ifdef TARGET_WEB
void controller_emscripten_keyboard_init(void);
#endif
#endif

View file

@ -5,10 +5,6 @@
#include "pc/configfile.h"
#include "controller_api.h"
#ifdef TARGET_WEB
#include "controller_emscripten_keyboard.h"
#endif
#include "../configfile.h"
#include "controller_keyboard.h"
#include "controller_keyboard_debug.h"
@ -113,10 +109,6 @@ static void keyboard_bindkeys(void) {
static void keyboard_init(void) {
keyboard_bindkeys();
#ifdef TARGET_WEB
controller_emscripten_keyboard_init();
#endif
}
static void keyboard_read(OSContPad *pad) {

View file

@ -185,20 +185,6 @@ static void controller_sdl_read(OSContPad *pad) {
int16_t ltrig = get_axis(JOY_AXIS_LTRIG);
int16_t rtrig = get_axis(JOY_AXIS_RTRIG);
#ifdef TARGET_WEB
// Firefox has a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1606562
// It sets down y to 32768.0f / 32767.0f, which is greater than the allowed 1.0f,
// which SDL then converts to a int16_t by multiplying by 32767.0f, which overflows into -32768.
// Maximum up will hence never become -32768 with the current version of SDL2,
// so this workaround should be safe in compliant browsers.
if (lefty == -32768) {
lefty = 32767;
}
if (righty == -32768) {
righty = 32767;
}
#endif
for (int i = 0; i < num_joy_buttons; ++i) {
const bool new = SDL_JoystickGetButton(sdl_joy, i);
update_button(i, new);

View file

@ -246,20 +246,6 @@ static void controller_sdl_read(OSContPad *pad) {
int16_t ltrig = SDL_GameControllerGetAxis(sdl_cntrl, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
int16_t rtrig = SDL_GameControllerGetAxis(sdl_cntrl, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
#ifdef TARGET_WEB
// Firefox has a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1606562
// It sets down y to 32768.0f / 32767.0f, which is greater than the allowed 1.0f,
// which SDL then converts to a int16_t by multiplying by 32767.0f, which overflows into -32768.
// Maximum up will hence never become -32768 with the current version of SDL2,
// so this workaround should be safe in compliant browsers.
if (lefty == -32768) {
lefty = 32767;
}
if (righty == -32768) {
righty = 32767;
}
#endif
for (u32 i = 0; i < SDL_CONTROLLER_BUTTON_MAX; ++i) {
const bool new = SDL_GameControllerGetButton(sdl_cntrl, i);
update_button(i, new);

View file

@ -135,8 +135,6 @@ static void gfx_sdl_handle_events(void) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
#ifndef TARGET_WEB
// Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259
case SDL_KEYDOWN:
gfx_sdl_onkeydown(event.key.keysym.sym);
// ALT+F4 in case the OS doesn't do it (SDL1 doesn't seem to do it on my machine)
@ -146,7 +144,6 @@ static void gfx_sdl_handle_events(void) {
case SDL_KEYUP:
gfx_sdl_onkeyup(event.key.keysym.sym);
break;
#endif
case SDL_VIDEORESIZE:
window_w = configWindow.w = event.resize.w;
window_h = configWindow.h = event.resize.h;

View file

@ -167,8 +167,6 @@ static void gfx_sdl_handle_events(void) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
#ifndef TARGET_WEB
// Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259
case SDL_TEXTINPUT:
kb_text_input(event.text.text);
break;
@ -178,8 +176,7 @@ static void gfx_sdl_handle_events(void) {
case SDL_KEYUP:
gfx_sdl_onkeyup(event.key.keysym.scancode);
break;
#endif
case SDL_WINDOWEVENT: // TODO: Check if this makes sense to be included in the Web build
case SDL_WINDOWEVENT:
if (!IS_FULLSCREEN()) {
switch (event.window.event) {
case SDL_WINDOWEVENT_MOVED:

View file

@ -3,11 +3,6 @@
#include <string.h>
#include <signal.h>
#ifdef TARGET_WEB
#include <emscripten.h>
#include <emscripten/html5.h>
#endif
#include "sm64.h"
#include "pc/lua/smlua.h"
@ -263,49 +258,13 @@ void game_deinit(void) {
void game_exit(void) {
LOG_INFO("exiting cleanly");
game_deinit();
#ifndef TARGET_WEB
exit(0);
#endif
}
void inthand(UNUSED int signum) {
game_exit();
}
#ifdef TARGET_WEB
static void em_main_loop(void) {
}
static void request_anim_frame(void (*func)(double time)) {
EM_ASM(requestAnimationFrame(function(time) {
dynCall("vd", $0, [time]);
}), func);
}
static void on_anim_frame(double time) {
static double target_time;
time *= 0.03; // milliseconds to frame count (33.333 ms -> 1)
if (time >= target_time + 10.0) {
// We are lagging 10 frames behind, probably due to coming back after inactivity,
// so reset, with a small margin to avoid potential jitter later.
target_time = time - 0.010;
}
for (s32 i = 0; i < 2; i++) {
// If refresh rate is 15 Hz or something we might need to generate two frames
if (time >= target_time) {
produce_one_frame();
target_time = target_time + 1.0;
}
}
if (inited) // only continue if the init flag is still set
request_anim_frame(on_anim_frame);
}
#endif
void main_func(void) {
const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR;
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
@ -416,10 +375,6 @@ void main_func(void) {
discord_init();
#endif
#ifdef TARGET_WEB
emscripten_set_main_loop(em_main_loop, 0, 0);
request_anim_frame(on_anim_frame);
#else
while (true) {
wm_api->main_loop(produce_one_frame);
#ifdef DISCORDRPC
@ -430,7 +385,6 @@ void main_func(void) {
fflush(stderr);
#endif
}
#endif
bassh_deinit();
}

View file

@ -5,10 +5,6 @@
#include "platform.h"
#include "fs/fs.h"
#ifdef TARGET_WEB
#include <emscripten.h>
#endif
u8* gOverrideEeprom = NULL;
extern OSMgrArgs piMgrArgs;
@ -136,27 +132,6 @@ s32 osEepromLongRead(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
u8 content[512];
s32 ret = -1;
#ifdef TARGET_WEB
if (EM_ASM_INT({
var s = localStorage.sm64_save_file;
if (s && s.length === 684) {
try {
var binary = atob(s);
if (binary.length === 512) {
for (var i = 0; i < 512; i++) {
HEAPU8[$0 + i] = binary.charCodeAt(i);
}
return 1;
}
} catch (e) {
}
}
return 0;
}, content)) {
memcpy(buffer, content + address * 8, nbytes);
ret = 0;
}
#else
fs_file_t *fp = fs_open(SAVE_FILENAME);
if (fp == NULL) {
return -1;
@ -166,7 +141,7 @@ s32 osEepromLongRead(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes)
ret = 0;
}
fs_close(fp);
#endif
return ret;
}
@ -182,22 +157,12 @@ s32 osEepromLongWrite(UNUSED OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes
}
memcpy(content + address * 8, buffer, nbytes);
#ifdef TARGET_WEB
EM_ASM({
var str = "";
for (var i = 0; i < 512; i++) {
str += String.fromCharCode(HEAPU8[$0 + i]);
}
localStorage.sm64_save_file = btoa(str);
}, content);
s32 ret = 0;
#else
FILE *fp = fopen(fs_get_write_path(SAVE_FILENAME), "wb");
if (fp == NULL) {
return -1;
}
s32 ret = fwrite(content, 1, 512, fp) == 512 ? 0 : -1;
fclose(fp);
#endif
return ret;
}