aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmin Mesbah <dev@aminmesbah.com>2019-06-23 17:48:46 -0700
committerAmin Mesbah <dev@aminmesbah.com>2019-06-23 17:48:46 -0700
commitbf648ab1d6ac4e21a955175413be894f6021d686 (patch)
tree03e08b39ab4d0eaf179395df063ff5f0e08c3bac
parentc708056e7562c2ba83b5917edb76c75a915d0a64 (diff)
downloadtransparent-cube-bf648ab1d6ac4e21a955175413be894f6021d686.zip
transparent-cube-bf648ab1d6ac4e21a955175413be894f6021d686.tar.gz
Remove emscripten
-rw-r--r--Makefile26
-rwxr-xr-xbuild_wasm.sh3
-rw-r--r--src/platform_emscripten.c99
-rw-r--r--src/platform_emscripten.h19
4 files changed, 13 insertions, 134 deletions
diff --git a/Makefile b/Makefile
index 547a0c2..d91166b 100644
--- 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
index 0828cbb..112189a 100755
--- 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
deleted file mode 100644
index 150dfab..0000000
--- a/src/platform_emscripten.c
+++ /dev/null
@@ -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
deleted file mode 100644
index ca0a961..0000000
--- a/src/platform_emscripten.h
+++ /dev/null
@@ -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