feat: start emscripten web
This commit is contained in:
parent
c2caa8aa34
commit
e7d536d087
39
Makefile
39
Makefile
@ -1,12 +1,12 @@
|
|||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
# #
|
# #
|
||||||
# ::: :::::::: #
|
# :::::::: #
|
||||||
# Makefile :+: :+: :+: #
|
# Makefile :+: :+: #
|
||||||
# +:+ +:+ +:+ #
|
# +:+ #
|
||||||
# By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ #
|
# By: qmennen <qmennen@student.codam.nl> +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+ #
|
||||||
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
|
||||||
# Updated: 2025/06/11 18:43:00 by qmennen ### ########.fr #
|
# 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
|
GLAD_INC_PATH = $(MLX42_PATH)/include/glad
|
||||||
MLX42 = $(MLX42_PATH)/build/libmlx42.a
|
MLX42 = $(MLX42_PATH)/build/libmlx42.a
|
||||||
|
|
||||||
|
WEB = web/demo.html
|
||||||
|
MLX_WEB_LIB = $(MLX42_PATH)/build_web/libmlx42_web.a
|
||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
RM = rm -rf
|
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)
|
UNAME_S := $(shell uname -s)
|
||||||
ifeq ($(UNAME_S),Linux)
|
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
|
endif
|
||||||
|
|
||||||
VPATH = $(shell find $(SRC_PATH) -type d | tr '\n' ':')
|
VPATH = $(shell find $(SRC_PATH) -type d | tr '\n' ':')
|
||||||
@ -236,7 +239,25 @@ submodules:
|
|||||||
git submodule update --init; \
|
git submodule update --init; \
|
||||||
fi
|
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)
|
red:=$(shell tput setaf 1)
|
||||||
green:=$(shell tput setaf 2)
|
green:=$(shell tput setaf 2)
|
||||||
|
|||||||
19
inc/cub3d.h
19
inc/cub3d.h
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* :::::::: */
|
||||||
/* cub3d.h :+: :+: :+: */
|
/* cub3d.h :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
/* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/06/11 20:32:00 by qmennen ### ########.fr */
|
/* Updated: 2025/07/03 18:11:02 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -40,6 +40,11 @@
|
|||||||
# define M_PI 3.14159265358979323846
|
# define M_PI 3.14159265358979323846
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef WEB
|
||||||
|
# include <emscripten.h>
|
||||||
|
# include <emscripten/html5.h>
|
||||||
|
# endif
|
||||||
|
|
||||||
# define RESET "\033[0m"
|
# define RESET "\033[0m"
|
||||||
# define BLACK "\033[0;30m"
|
# define BLACK "\033[0;30m"
|
||||||
# define RED "\033[0;31m"
|
# define RED "\033[0;31m"
|
||||||
|
|||||||
34
src/main.c
34
src/main.c
@ -1,21 +1,30 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* :::::::: */
|
||||||
/* main.c :+: :+: :+: */
|
/* main.c :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/06/11 18:42:53 by qmennen ### ########.fr */
|
/* Updated: 2025/07/03 18:15:07 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cub3d.h"
|
#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;
|
mlx_loop(g_mlx);
|
||||||
t_game *game;
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
t_game_manager *manager;
|
||||||
|
t_game *game;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
game = NULL;
|
game = NULL;
|
||||||
@ -35,7 +44,12 @@ int main(int argc, char **argv)
|
|||||||
mlx_key_hook(game->screen->mlx, keyhandle, manager);
|
mlx_key_hook(game->screen->mlx, keyhandle, manager);
|
||||||
mlx_loop_hook(game->screen->mlx, game_manager_update, manager);
|
mlx_loop_hook(game->screen->mlx, game_manager_update, manager);
|
||||||
mlx_close_hook(game->screen->mlx, game_manager_destroy, 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);
|
mlx_loop(game->screen->mlx);
|
||||||
|
#endif
|
||||||
game_manager_destroy(manager);
|
game_manager_destroy(manager);
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user