commit c1ca717d96a9b6079ebd6bc52fc94bfaa3298d14
parent 7d3ccccd8dac4ddc2a16ff1091c5ada21b214ebc
Author: amin <dev@aminmesbah.com>
Date: Mon, 24 Jun 2019 00:48:45 +0000
Remove emscripten
FossilOrigin-Name: cce86488d2bb733d9f09411900d65e7a57bcd7855b4ee7cfbca3051af334232b
Diffstat:
4 files changed, 13 insertions(+), 134 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,10 +1,10 @@
CC = clang
-CFLAGS = -std=c99 -Ilib -Wall -Wextra -Wshadow -Wswitch-enum -Wno-unused-parameter -Wno-missing-braces
+CFLAGS = -std=c11 -Ilib -Wall -Wextra -Wshadow -Wswitch-enum -Wno-unused-parameter -Wno-missing-braces
LDFLAGS = -ldl -lglfw -lGL
SRC_FILES = platform_linux.c
SRC = $(addprefix src/, $(SRC_FILES))
-EXE_FILE = quaternion_demo
+EXE_FILE = transparent_cube
LIB_FILES = game.c
LIB = $(addprefix src/, $(LIB_FILES))
@@ -20,17 +20,11 @@ RELLIB = $(RELDIR)/$(LIB_NAME)
RELLIBTMP = $(RELLIB).tmp
RELCFLAGS = -DPLATFORM_HOTLOAD_GAME_CODE -O2 -Os
-EMS_FILES = platform_emscripten.c
-EMSSRC = $(addprefix src/, $(EMS_FILES))
-EMSDIR = out/emscripten
-EMSEXE = $(EMSDIR)/$(EXE_FILE).html
-EMSCFLAGS = --preload-file shader -s USE_GLFW=3 -s USE_WEBGL2=1
-
-.PHONY: default all build_debug build_lib build_release clean debug dir_debug dir_release emscripten memcheck run todo
+.PHONY: default all build_debug build_lib build_release clean debug dir_debug dir_release memcheck run todo wasm
default: build_release
-all: build_debug build_release emscripten
+all: build_debug build_release wasm
build_debug: dir_debug
$(CC) $(CFLAGS) $(DBGCFLAGS) $(SRC) -o $(DBGEXE) $(LDFLAGS)
@@ -43,7 +37,7 @@ build_release: dir_release build_lib
$(CC) $(CFLAGS) $(RELCFLAGS) $(SRC) -o $(RELEXE) $(LDFLAGS)
clean:
- rm -f $(RELDIR)/* $(DBGDIR)/*
+ rm -rf out/
debug: build_debug
gdb $(DBGEXE)
@@ -54,18 +48,20 @@ dir_debug:
dir_release:
@mkdir -p $(RELDIR)
+dir_wasm:
+ @mkdir -p $(EMSDIR)
+
memcheck: build_debug
valgrind --track-origins=yes ./$(DBGEXE)
run: build_release
./$(RELEXE)
-emscripten:
- @mkdir -p $(EMSDIR)
- emcc $(CFLAGS) $(EMSCFLAGS) -O2 -Os $(EMSSRC) -o $(EMSEXE) $(LDFLAGS)
-
todo:
@grep -FIR --colour=never --ignore-case --line-number todo src/ \
| sed -re 's/^([^:]+):[[:space:]]*(.*)/\1\x01\2/' \
| sed -re 's/^([^:]+):[[:space:]]*(.*)/\1\x01\2/' \
| column -s $$'\x01' -t
+
+wasm:
+ ./build_wasm.sh
diff --git a/build_wasm.sh b/build_wasm.sh
@@ -22,9 +22,10 @@ clang \
-fno-builtin \
-std=c11 \
-DGAME_WEBGL \
+ -o $wasm_dir/wasm.bc \
src/platform_wasm.c
-llvm-link -o $wasm_dir/wasm.bc src/*.bc
+llvm-link -o $wasm_dir/wasm.bc $wasm_dir/wasm.bc
opt -O3 -disable-simplify-libcalls $wasm_dir/wasm.bc -o $wasm_dir/wasm.bc
llc -O3 -disable-simplify-libcalls -filetype=obj $wasm_dir/wasm.bc -o $wasm_dir/wasm.o
diff --git a/src/platform_emscripten.c b/src/platform_emscripten.c
@@ -1,99 +0,0 @@
-#include <inttypes.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <time.h>
-
-#include <emscripten.h>
-
-#define GLFW_INCLUDE_ES3
-#include <GLFW/glfw3.h>
-
-#include "game.c"
-#include "platform_emscripten.h"
-
-void error_callback(int error, const char *description);
-void framebuffer_size_callback(GLFWwindow *window, int width, int height);
-void platform_main_loop(void *data);
-
-
-int main(void)
-{
- glfwSetErrorCallback(error_callback);
-
- if (!glfwInit())
- {
- fprintf(stderr, "GLFW initialization failed\n");
- return -1;
- }
-
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
-
- GLFWwindow* window = glfwCreateWindow(PLATFORM_SCR_WIDTH, PLATFORM_SCR_HEIGHT, "Quaternion Demo", NULL, NULL);
- if (!window)
- {
- fprintf(stderr, "GLFW window creation failed\n");
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
-
- struct GameState game_state = {0};
- game_init(&game_state, PLATFORM_SCR_WIDTH, PLATFORM_SCR_HEIGHT);
-
- struct LoopArgs loop_args = {
- .counter = 0,
- .previous_s = 0.0f,
- .lag = 0.0f,
- .game_state = &game_state,
- .window = window,
- };
- void *args = &loop_args;
-
- emscripten_set_main_loop_arg(platform_main_loop, args, 0, 1);
-
- game_cleanup(&game_state);
-
- glfwDestroyWindow(window);
- glfwTerminate();
-
- return 0;
-}
-
-
-void platform_main_loop(void *data)
-{
- struct LoopArgs *args = (struct LoopArgs *)(data);
-
- // glfwGetTimerValue() is not currently implemented in Emscripten.
- double current_s = glfwGetTime();
- double elapsed_s = current_s - args->previous_s;
- args->previous_s = current_s;
- args->lag += elapsed_s;
- //printf("%f, %f\n", elapsed_s, args->lag);
-
- int32_t framebuffer_width = PLATFORM_SCR_WIDTH;
- int32_t framebuffer_height = PLATFORM_SCR_HEIGHT;
- glfwGetFramebufferSize(args->window, &framebuffer_width, &framebuffer_height);
-
- // TODO: args->lag just increases forever. Fix that.
- game_update_and_render(args->game_state, args->lag, framebuffer_width, framebuffer_height);
-
- glfwSwapBuffers(args->window);
- glfwPollEvents();
-}
-
-
-void error_callback(int error, const char *description)
-{
- fprintf(stderr, "Error: %s\n", description);
-}
-
-
-void framebuffer_size_callback(GLFWwindow *window, int width, int height)
-{
- glViewport(0, 0, width, height);
-}
diff --git a/src/platform_emscripten.h b/src/platform_emscripten.h
@@ -1,19 +0,0 @@
-#ifndef PLATFORM_EMSCRIPTEN_H
-#define PLATFORM_EMSCRIPTEN_H
-
-#include <stdbool.h>
-#include <time.h>
-
-#define PLATFORM_SCR_WIDTH 600
-#define PLATFORM_SCR_HEIGHT 600
-
-struct LoopArgs
-{
- int counter;
- struct GameState *game_state;
- double previous_s;
- double lag;
- GLFWwindow* window;
-};
-
-#endif // PLATFORM_EMSCRIPTEN_H