feat: start emscripten web

This commit is contained in:
whaffman 2025-07-03 18:17:55 +02:00
parent c2caa8aa34
commit e7d536d087
3 changed files with 66 additions and 26 deletions

View File

@ -1,12 +1,12 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/06/11 18:43:00 by qmennen ### ########.fr #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: qmennen <qmennen@student.codam.nl> +#+ #
# +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/07/03 18:16:26 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
@ -30,6 +30,9 @@ MLX42_INC_PATH = $(MLX42_PATH)/include/MLX42
GLAD_INC_PATH = $(MLX42_PATH)/include/glad
MLX42 = $(MLX42_PATH)/build/libmlx42.a
WEB = web/demo.html
MLX_WEB_LIB = $(MLX42_PATH)/build_web/libmlx42_web.a
CC = cc
RM = rm -rf
@ -37,7 +40,7 @@ INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH) -I./$(MLX42_INC_PATH) -I./$(GLA
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDLIBS := -L$(LIBFT_PATH) -lft -L$(MLX42_PATH)/build -lmlx42 -ldl -lglfw -pthread -lm
LDLIBS := -L$(LIBFT_PATH) -lft -L$(MLX42_PATH)/build -lmlx42 -ldl -lglfw -pthread -lm
endif
VPATH = $(shell find $(SRC_PATH) -type d | tr '\n' ':')
@ -236,7 +239,25 @@ submodules:
git submodule update --init; \
fi
.PHONY: all clean fclean re srcs run help dist
#WEBSTUFF
$(MLX_WEB_LIB):
@cd $(MLX42_PATH) && emcmake cmake -B build_web
@cd $(MLX42_PATH) && cmake --build build_web --parallel
@-mv $(MLX42_PATH)/build_web/libmlx42.a $(MLX_WEB_LIB)
web: $(WEB)
$(WEB): $(SRCS) $(MLX_WEB_LIB)
mkdir -p web
emcc -DWEB -O3 $(INCLUDES) -pthread $(SOURCES) \
-o $(WEB) \
$(MLX_WEB_LIB) \
-s USE_GLFW=3 -s USE_WEBGL2=1 -s FULL_ES3=1 -s WASM=1 \
-s NO_EXIT_RUNTIME=1 -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
-s ALLOW_MEMORY_GROWTH
.PHONY: all clean fclean re srcs run help dist web
red:=$(shell tput setaf 1)
green:=$(shell tput setaf 2)

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
/* Updated: 2025/06/11 20:32:00 by qmennen ### ########.fr */
/* :::::::: */
/* cub3d.h :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
/* Updated: 2025/07/03 18:11:02 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -40,6 +40,11 @@
# define M_PI 3.14159265358979323846
# endif
# ifdef WEB
# include <emscripten.h>
# include <emscripten/html5.h>
# endif
# define RESET "\033[0m"
# define BLACK "\033[0;30m"
# define RED "\033[0;31m"

View File

@ -1,21 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
/* Updated: 2025/06/11 18:42:53 by qmennen ### ########.fr */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
/* Updated: 2025/07/03 18:15:07 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int main(int argc, char **argv)
mlx_t *g_mlx;
#ifdef WEB
static void emscripten_main_loop(void)
{
t_game_manager *manager;
t_game *game;
mlx_loop(g_mlx);
}
#endif
int main(int argc, char **argv)
{
t_game_manager *manager;
t_game *game;
errno = 0;
game = NULL;
@ -35,7 +44,12 @@ int main(int argc, char **argv)
mlx_key_hook(game->screen->mlx, keyhandle, manager);
mlx_loop_hook(game->screen->mlx, game_manager_update, manager);
mlx_close_hook(game->screen->mlx, game_manager_destroy, manager);
#ifdef WEB
g_mlx = game->screen->mlx;
emscripten_set_main_loop_arg(emscripten_main_loop, 0, true);
#else
mlx_loop(game->screen->mlx);
#endif
game_manager_destroy(manager);
return (EXIT_SUCCESS);
}