polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 08d4282d319a787d2bde6c624156194640a6fad3
parent fabca1d3600c810f8bc8246c426b9147cacd8aed
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 24 Jul 2021 11:05:01 -0700

wasm fixes

Diffstat:
MMakefile | 19++++++++++++-------
Mdefault.nix | 2+-
Mmain.c | 6++++--
Msrc/gl.h | 2+-
Msrc/hires.c | 2+-
Msrc/input.h | 2+-
Msrc/quickhull.c | 4++--
Msrc/scene.c | 2+-
Msrc/update.c | 26+++++++++++++-------------
9 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,13 +7,15 @@ DEFS= -DGLFW_INCLUDE_NONE -DDEBUG # CFLAGS = $(DEFS) -ggdb -O0 -I src -Wall -Wextra -std=c99 \ -CFLAGS = $(DEFS) -O1 -g -I src -Wall -Werror -Wextra -std=c99 \ - -Wno-unused-function \ - -Wno-unused-parameter \ - -Wno-unused-variable \ - -Wmissing-field-initializers \ - -Wno-cast-align \ - -Wno-padded +CFLAGS = $(shell pkg-config --cflags sdl2 gl) \ + $(DEFS) -O1 -g -I src -Wall -Werror -Wextra -std=c99 \ + -Wno-unused-function \ + -Wno-unused-parameter \ + -Wno-unused-variable \ + -Wmissing-field-initializers \ + -Wno-cast-align \ + -Wno-padded + LDFLAGS = -lSDL2 -lGL -lm SRC=src @@ -67,6 +69,9 @@ $(BIN): main.o $(OBJS) @echo "link $@" @$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ +$(BIN).wasm: main.c $(SRCS) + emcc $(CFLAGS) $^ -s WASM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -o $@ + install: $(BIN) install -d $(PREFIX)/bin install $(BIN) $(PREFIX)/bin diff --git a/default.nix b/default.nix @@ -13,7 +13,7 @@ stdenv.mkDerivation rec { makeFlags = "PREFIX=$(out)"; - nativeBuildInputs = with pkgs; [ tinycc pkg-config gdb ]; + nativeBuildInputs = with pkgs; [ tinycc pkg-config gdb emscripten ]; buildInputs = with pkgs; [ SDL2 mesa libglvnd ] ++ (with xorg; [ libX11 libxcb libXau libXdmcp libXext libXcursor diff --git a/main.c b/main.c @@ -41,10 +41,12 @@ int main(void) /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */ int width = 640; + int hello; int height = 480; game_init(&game, width, height); - /* reset_scene(&game); */ - chess_scene(&game); + reset_scene(&game); + default_scene(&game); + //chess_scene(&game); check_gl(); double last = hires_time_in_seconds(); diff --git a/src/gl.h b/src/gl.h @@ -2,7 +2,7 @@ #define POLYADVENT_GL_H /* #include <epoxy/gl.h> */ -#include <SDL2/SDL.h> +#include <SDL.h> #include <GL/gl.h> #include <GL/glx.h> #include <GL/glext.h> diff --git a/src/hires.c b/src/hires.c @@ -1,7 +1,7 @@ #include <time.h> #include "common.h" -#include <SDL2/SDL.h> +#include <SDL.h> double hires_time_in_seconds() { double ticks_per_sec = (double)SDL_GetPerformanceFrequency(); diff --git a/src/input.h b/src/input.h @@ -3,7 +3,7 @@ #ifndef POLYADVENT_INPUT_H #define POLYADVENT_INPUT_H -#include <SDL2/SDL.h> +#include <SDL.h> #include "common.h" /* enum key_state { */ diff --git a/src/quickhull.c b/src/quickhull.c @@ -998,7 +998,7 @@ qh_face_t* qh__build_tetrahedron(qh_context_t* context, float epsilon) qh_vertex_t* v; qh_face_t* dface = NULL; - if (vertices[0] == i || vertices[1] == i || vertices[2] == i) { + if (vertices[0] == (long)i || vertices[1] == (long)i || vertices[2] == (long)i) { continue; } @@ -1014,7 +1014,7 @@ qh_face_t* qh__build_tetrahedron(qh_context_t* context, float epsilon) for (int j = 0; j < 3; ++j) { qh_half_edge_t* e = context->edges + dface->edges[j]; - if (i == e->to_vertex) { + if ((long)i == e->to_vertex) { valid = 0; break; } diff --git a/src/scene.c b/src/scene.c @@ -35,7 +35,7 @@ void default_scene(struct game *game) { assert(tnode); tower->model_id = get_static_model(model_tower, NULL); node_set_label(tnode, "tower"); - node_attach(&tower->node_id, &player->node_id); + //node_attach(&tower->node_id, &player->node_id); node_translate(tnode, V3(0.0, 50.0, 0.0)); node_recalc(tnode); float z = terrain->fn(terrain, tnode->mat[M_X], tnode->mat[M_Y]); diff --git a/src/update.c b/src/update.c @@ -304,8 +304,8 @@ void orbit_update_from_mouse(struct orbit *camera, struct input *input, node_recalc(target_node); vec3_copy(node_world(target_node), target); - /* assert(player_geom->max[2] != 0); */ - vec3_add(target, V3(0.0, 0.0, -15.0), target); + assert(player_geom->max[2] != 0); + vec3_add(target, V3(0.0, 0.0, player_geom->max[2]), target); /* vec3_add(target, V3(0.0, 0.0, 10.0), target); */ float mx = 0.0, my = 0.0; @@ -386,7 +386,7 @@ static void player_update(struct game *game, struct entity *player) orbit_update_from_mouse(camera, &game->input, game->user_settings.mouse_sens, player, game->dt); - /* camera_keep_above_ground(&game->terrain, cam_node); */ + camera_keep_above_ground(&game->terrain, cam_node); // move player camera toward camera orientation if (input_is_dragging(&game->input, SDL_BUTTON_RIGHT)) { @@ -403,8 +403,8 @@ static void player_update(struct game *game, struct entity *player) float pen; vec3_copy(node_world(node), pos); /* debug("node_world(player) %f %f %f\n", pos[0], pos[1], pos[2]); */ - /* struct tri *tri = collide_terrain(terrain, pos, move, &pen); */ - struct tri *tri = NULL; + struct tri *tri = collide_terrain(terrain, pos, move, &pen); + //struct tri *tri = NULL; /* node_translate(node, move); */ if (tri) { @@ -425,21 +425,21 @@ static void player_update(struct game *game, struct entity *player) /* debug("%d no tri\n", tric++); */ } - /* if (player->flags & ENT_ON_GROUND && */ - /* (was_key_pressed_this_frame(game, SDL_SCANCODE_SPACE) || */ - /* was_button_pressed_this_frame(game, SDL_CONTROLLER_BUTTON_X))) { */ - /* entity_jump(player, 2.0); */ - /* } */ + if (player->flags & ENT_ON_GROUND && + (was_key_pressed_this_frame(game, SDL_SCANCODE_SPACE) || + was_button_pressed_this_frame(game, SDL_CONTROLLER_BUTTON_X))) { + entity_jump(player, 2.0); + } /* debug("player velocity %f %f %f\n", */ /* player->velocity[0], */ /* player->velocity[1], */ /* player->velocity[2]); */ - /* if (player->flags & ENT_AT_REST) */ - /* vec3_scale(player->velocity, 0.00001, player->velocity); */ +// if (player->flags & ENT_AT_REST) +// vec3_scale(player->velocity, 0.00001, player->velocity); - /* node_translate(node, player->velocity); */ + node_translate(node, player->velocity); node_recalc(node); }