Web cross compilation started

This commit is contained in:
Your Name 2026-02-05 23:00:59 +01:00
parent d079f6eccc
commit 36ee91abb1
12 changed files with 103 additions and 255 deletions

View File

@ -1,194 +0,0 @@
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# Update with future time fix and install build dependencies
RUN apt-get -o Acquire::Max-FutureTime=86400 update -y --fix-missing
RUN apt-get install -y build-essential xorg libx11-dev libxext-dev libbsd-dev libpthread-stubs0-dev libasound2-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
# Build the miniRT project
WORKDIR /best_rt
COPY . .
RUN make
# Install VNC and graphics dependencies
RUN apt-get update && apt-get install -y \
tigervnc-standalone-server \
python3 \
python3-pip \
wget \
git \
openbox \
x11-utils \
libgl1-mesa-dev \
libglu1-mesa-dev \
net-tools \
procps \
lsof \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install websockify
RUN pip3 install websockify --break-system-packages
# Install noVNC
RUN git clone https://github.com/novnc/noVNC.git /opt/noVNC
# Create VNC directory and set password
RUN mkdir -p /root/.vnc && \
echo "1312" | vncpasswd -f > /root/.vnc/passwd && \
chmod 600 /root/.vnc/passwd
RUN rm /opt/noVNC/*.html
RUN mv /best_rt/vnc/minimal.html /opt/noVNC/vnc.html
RUN echo '<!DOCTYPE html>\n\
<html>\n\
<head>\n\
<title>miniRT</title>\n\
<style>\n\
body { margin: 0; padding: 0; background: #000; overflow: hidden; }\n\
iframe { width: 100vw; height: 100vh; border: none; }\n\
</style>\n\
</head>\n\
<body>\n\
<iframe src="/clean.html"></iframe>\n\
</body>\n\
</html>' > /opt/noVNC/minimal.html
# Create VNC startup script that keeps session alive
RUN echo '#!/bin/bash\n\
export USER=root\n\
export HOME=/root\n\
xsetroot -solid grey\n\
# Start openbox to keep session alive\n\
openbox-session &\n\
# Keep the session running\n\
while true; do sleep 3600; done\n\
' > /root/.vnc/xstartup && chmod +x /root/.vnc/xstartup
# Create connection monitor script
RUN echo '#!/bin/bash\n\
\n\
APP_PID=""\n\
CLIENT_TIMEOUT=30 # Stop app after 30 seconds of no clients\n\
CHECK_INTERVAL=5 # Check every 5 seconds\n\
\n\
log() {\n\
echo "[$(date "+%H:%M:%S")] $1"\n\
}\n\
\n\
has_vnc_clients() {\n\
# Check for active VNC connections\n\
netstat -tn 2>/dev/null | grep -q ":5901.*ESTABLISHED"\n\
}\n\
\n\
has_websocket_clients() {\n\
# Check for active WebSocket connections (noVNC)\n\
netstat -tn 2>/dev/null | grep -q ":6080.*ESTABLISHED"\n\
}\n\
\n\
start_app() {\n\
if [ -z "$APP_PID" ] || ! kill -0 "$APP_PID" 2>/dev/null; then\n\
log "Starting miniRT application..."\n\
cd /best_rt\n\
/best_rt/miniRT /best_rt/scenes/multilight.rt &\n\
APP_PID=$!\n\
log "miniRT started with PID: $APP_PID"\n\
fi\n\
}\n\
\n\
stop_app() {\n\
if [ -n "$APP_PID" ] && kill -0 "$APP_PID" 2>/dev/null; then\n\
log "Stopping miniRT application (PID: $APP_PID)..."\n\
kill "$APP_PID" 2>/dev/null\n\
wait "$APP_PID" 2>/dev/null\n\
APP_PID=""\n\
log "miniRT stopped"\n\
fi\n\
}\n\
\n\
# Main monitoring loop\n\
last_client_time=0\n\
\n\
while true; do\n\
current_time=$(date +%s)\n\
\n\
if has_vnc_clients || has_websocket_clients; then\n\
# Client connected\n\
last_client_time=$current_time\n\
start_app\n\
else\n\
# No clients\n\
if [ "$last_client_time" -gt 0 ]; then\n\
time_since_last_client=$((current_time - last_client_time))\n\
if [ "$time_since_last_client" -gt "$CLIENT_TIMEOUT" ]; then\n\
stop_app\n\
last_client_time=0\n\
fi\n\
fi\n\
fi\n\
\n\
sleep "$CHECK_INTERVAL"\n\
done\n\
' > /monitor-clients.sh && chmod +x /monitor-clients.sh
# Create a simple mime.types file for websockify
RUN echo 'text/html html htm shtml;\n\
application/javascript js;\n\
text/css css;\n\
image/png png;\n\
image/jpeg jpg jpeg;\n\
image/gif gif;\n\
image/svg+xml svg;\n\
' > /opt/noVNC/mime.types
# Create smart startup script
RUN echo '#!/bin/bash\n\
export USER=root\n\
export HOME=/root\n\
export DISPLAY=:1\n\
\n\
log() {\n\
echo "[$(date "+%H:%M:%S")] $1"\n\
}\n\
\n\
log "Starting VNC server..."\n\
vncserver :1 -geometry 1920x1080 -depth 24 -localhost no\n\
sleep 5\n\
\n\
log "Starting noVNC web interface..."\n\
cd /opt/noVNC\n\
python3 -m websockify 6080 localhost:5901 &\n\
NOVNC_PID=$!\n\
\n\
sleep 3\n\
xhost + 2>/dev/null || true\n\
\n\
log "VNC ready at http://localhost:6080/vnc.html"\n\
log "Starting client monitor..."\n\
log "miniRT will start automatically when a client connects"\n\
log "miniRT will stop automatically when no clients for 30 seconds"\n\
\n\
# Start the client monitor\n\
/monitor-clients.sh &\n\
MONITOR_PID=$!\n\
\n\
# Handle cleanup on exit\n\
cleanup() {\n\
log "Shutting down..."\n\
kill $NOVNC_PID 2>/dev/null\n\
kill $MONITOR_PID 2>/dev/null\n\
vncserver -kill :1 2>/dev/null\n\
exit 0\n\
}\n\
\n\
trap cleanup SIGTERM SIGINT\n\
\n\
# Wait for processes\n\
wait\n\
' > /start.sh && chmod +x /start.sh
EXPOSE 6080 5901
CMD ["/start.sh"]

View File

@ -12,7 +12,7 @@
CC := cc
CFLAGS := -Wall -Werror -Wextra -g3
CFLAGS := -Wall -Werror -Wextra
LDFLAGS := -lm
@ -22,6 +22,21 @@ SRCDIR := src
SRC := minirt.c
PLATFORM ?= PLATFORM_DESKTOP
LIBRAYLIB := libraylib.a
ifeq ($(PLATFORM), PLATFORM_WEB)
LIBRAYLIB := libraylib.web.a
NAME := $(NAME).html
CC := emcc
AR := emar
CFLAGS += -v
LDFLAGS += -s USE_GLFW=3 -s ASYNCIFY --shell-file raylib/src/shell.html -DPLATFORM_WEB -s INITIAL_MEMORY=2147483648
endif
VNC_SCRIPT := ./script/run_vnc.sh
SCENEDIR := scene
SRCSCENE := $(addprefix $(SCENEDIR)/, $(addsuffix .c,\
camera camera_info camera_ray_define \
@ -48,7 +63,7 @@ SRCUTIL := $(addprefix $(UTILDIR)/, $(addsuffix .c,\
minirt_utils vector_math2 vector_math vector \
detect_overflow_utils detect_overflow))
LIBS := libft/libft.a memory/memory.a raylib/src/libraylib.a
LIBS := libft/libft.a memory/memory.a raylib/src/$(LIBRAYLIB)
MAP := mapgen
@ -66,9 +81,9 @@ else
CFLAGS += -O3
endif
all: $(OBJDIR) $(NAME)
all: $(LIBS) $(OBJDIR) $(NAME)
$(NAME): $(OBJ) $(LIBS) minirt.h $(OBJIO) $(OBJSCENE) $(OBJUTIL) $(OBJRENDER)
$(NAME): $(OBJ) minirt.h $(OBJIO) $(OBJSCENE) $(OBJUTIL) $(OBJRENDER)
$(CC) $(CFLAGS) -o $@ $(OBJ) $(OBJIO) $(OBJSCENE) $(OBJUTIL) $(OBJRENDER) $(LIBS) $(LDFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/$(SCENEDIR)/%.c minirt.h
@ -91,19 +106,16 @@ $(MAP): src/mapgeb/map_gen_buffer.c src/mapgeb/map.c
$(CC) $(CFLAGS) $^ src/io/buffer.c $(LIBS) -o $@ -lm
$(LIBS):
make -C libft
make -C memory
make -C libft/printf
make -C raylib/src PLATFORM=PLATFORM_DESKTOP
make AR=$(AR) CC=$(CC) -C libft
make AR=$(AR) CC=$(CC) -C memory
make AR=$(AR) CC=$(CC) -C libft/printf
make -C raylib/src PLATFORM=$(PLATFORM)
$(OBJDIR):
mkdir -p $(OBJDIR) $(OBJDIR)/$(SRCDIR) $(OBJDIR)/$(RENDERDIR) $(OBJDIR)/$(IODIR) $(OBJDIR)/$(UTILDIR) $(OBJDIR)/$(SCENEDIR)
docker-build: all
docker build -t miniRT .
docker-run: docker-build
docker run -d -p 6080:6080 -p 5901:5901 miniRT:latest
vnc: all
$(VNC_SCRIPT)
clean:
rm -rf $(OBJDIR)

View File

@ -1,29 +0,0 @@
services:
postgres_key:
container_name: postgres_key
image: postgres:alpine
environment:
- POSTGRES_USER=keycloak_user
- POSTGRES_PASSWORD=keycloak_password
- POSTGRES_DB=keycloak_db
networks:
keycloak-shared-network:
ports:
- "15432:15432"
volumes:
- keycloak_data:/var/lib/postgresql/data
- ./postgres/logs:/var/logs/postgres
volumes:
keycloak_data:
networks:
jobited-net:
driver: bridge
keycloak-shared-network:
external: true

View File

@ -13,6 +13,7 @@
NAME := libft.a
CC := cc
AR := ar
CFLAGS:= -Wall -Wextra -Werror
@ -46,10 +47,10 @@ LIBS := printf
all: $(NAME)
bonus: $(OBJBON) $(OBJ)
ar rcs libft.a $(OBJ) $(OBJBON)
$(AR) rcs libft.a $(OBJ) $(OBJBON)
$(NAME): $(OBJ) $(OBJGNL) $(OBJPRINT) $(LIBS)
ar rcs libft.a $(OBJ) $(OBJGNL) $(OBJPRINT)
$(AR) rcs libft.a $(OBJ) $(OBJGNL) $(OBJPRINT)
$(LIBS):
make -C $(LIBS)

View File

@ -12,6 +12,7 @@
NAME := libftprintf.a
CC := cc
AR := ar
CFLAGS := -Wall -Werror -Wextra
SRC := ft_fprintf.c ft_printf.c ft_putascii.c ft_puthex.c ft_putptr.c ft_strlen.c ft_putfloat.c
OBJ := $(SRC:.c=.o)
@ -19,7 +20,7 @@ OBJ := $(SRC:.c=.o)
all: $(NAME)
$(NAME): $(OBJ)
ar rsc $@ $(OBJ)
$(AR) rsc $@ $(OBJ)
$(OBJ): $(SRC)
$(CC) $(CFLAGS) -c $(SRC)

View File

@ -11,6 +11,7 @@
# **************************************************************************** #
CC := cc
AR := ar
CFLAGS := -Wall -Wextra -Werror -g3
@ -23,7 +24,7 @@ OBJ := $(SRC:.c=.o)
all: $(NAME)
$(NAME): $(OBJ) $(LIBS)
ar rcs $(NAME) $(OBJ)
$(AR) rcs $(NAME) $(OBJ)
$(OBJ): $(SRC)
$(CC) $(CFLAGS) -c $(SRC)

BIN
miniRT Executable file

Binary file not shown.

1
miniRT.html Normal file

File diff suppressed because one or more lines are too long

1
miniRT.js Normal file

File diff suppressed because one or more lines are too long

BIN
miniRT.wasm Executable file

Binary file not shown.

38
scripts/run_vnc.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
VNC=novnc
XVNC=Xvnc
XVNC_HOST=0.0.0.0
XVNC_PORT=5901
DISPLAY_WIDTH=$1
DISPLAY_HEIGHT=$2
if ! command -v novnc &> /dev/null; then
echo "NoVnc installation missing! Aborting..."
exit 1
fi
if ! command -v Xvnc &> /dev/null; then
echo "X server or vnc extention missing! Aborting..."
exit 1
fi
$XVNC :1 \
-geometry ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} \
-depth 24 \
-SecurityTypes None \
-interface $XVNC_HOST \
-rfbport $XVNC_PORT \
&
sleep 2
$VNC --vnc localhost:5901 &
sleep 2
export DISPLAY=:1
exec ./miniRT

View File

@ -12,6 +12,8 @@
#include "../minirt.h"
t_data data;
void create_display() {
InitWindow(WI, HI, "miniRT in Raylib!!");
SetTargetFPS(60);
@ -199,23 +201,9 @@ void get_key_code(int keys[]) {
}
}
int main(int argc, char **argv)
{
t_data data;
char *path;
t_thread thread[THREAD_COUNT];
void main_loop() {
int keys[3] = { 0 };
if (argc == 1)
path = "scenes/multilight.rt";
else
path = validate_file_extension(argc, argv);
initialize_data(&data, path);
lst_memory(&data, data_destroy_func, ADD);
threads_init(thread, &data);
rendering_loop(&data);
data.threads = thread;
while(!WindowShouldClose()) {
Vector2 mouse_pos = GetMousePosition();
if (data.mouse.left_is_pressed || data.mouse.right_is_pressed)
{
@ -238,6 +226,34 @@ int main(int argc, char **argv)
rendering_loop(&data);
data.scene.resolution_x = 1;
data.scene.resolution_y = 1;
}
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
int main(int argc, char **argv)
{
char *path;
t_thread thread[THREAD_COUNT];
if (argc == 1)
path = "scenes/multilight.rt";
else
path = validate_file_extension(argc, argv);
initialize_data(&data, path);
lst_memory(&data, data_destroy_func, ADD);
threads_init(thread, &data);
rendering_loop(&data);
data.threads = thread;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(main_loop, 0, 1);
#else
while(!WindowShouldClose()) {
main_loop();
}
#endif /* ifdef __EMSCRIPTEN__ */
return (0);
}