commit ff4cf6e4558768f9d7662153e37f90825316bbad
parent 934a7f4ce8a98cdfe3e988ba1ff77e3d969f500d
Author: William Casarin <jb55@jb55.com>
Date: Sat, 24 Jul 2021 11:34:24 -0700
no controller in wasm
Diffstat:
11 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
@@ -15,8 +15,8 @@ BASE_CFLAGS = $(DEFS) -O1 -g -I src -Wall -Werror -Wextra -std=c99 \
-Wno-cast-align \
-Wno-padded
-CFLAGS = $(pkg-config --cflags sdl2 gl) $(BASE_CFLAGS)
-EM_CFLAGS = -I$(shell nix-instantiate --eval --expr 'with import <nixpkgs> {}; "${'"$1"'}"' | sed 's/"//g')/share/emscripten/system/include $(BASE_CFLAGS)
+CFLAGS = $(BASE_CFLAGS)
+EM_CFLAGS = $(BASE_CFLAGS)
LDFLAGS = -lSDL2 -lGL -lm
diff --git a/src/fbo.c b/src/fbo.c
@@ -3,6 +3,8 @@
#include "fbo.h"
#include "util.h"
+#include <stdio.h>
+
void create_fbo(struct fbo *fbo, int width, int height) {
glGenFramebuffers(1, &fbo->handle);
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
diff --git a/src/game.c b/src/game.c
@@ -30,7 +30,7 @@ bool was_key_pressed_this_frame(struct game *game, int scancode)
return is_key_down_on_frame(&game->input, scancode, game->frame);
}
-bool was_button_pressed_this_frame(struct game *game, SDL_GameControllerButton button)
+bool was_button_pressed_this_frame(struct game *game, int button)
{
return is_button_down_on_frame(&game->input, button, game->frame);
}
@@ -193,6 +193,7 @@ void init_misc(struct game *game, int width, int height) {
// END TEXTURES
}
+/*
void init_controller(struct input *input) {
SDL_GameControllerAddMappingsFromFile("data/gamecontrollerdb.txt");
@@ -215,6 +216,7 @@ void init_controller(struct input *input) {
}
}
+*/
void init_resources(struct resources *res)
{
memset(res, 0, sizeof(*res));
@@ -235,6 +237,6 @@ void game_init(struct game *game, int width, int height) {
game->wireframe = 0;
init_input(&game->input);
- init_controller(&game->input);
+ //init_controller(&game->input);
init_misc(game, width, height);
}
diff --git a/src/game.h b/src/game.h
@@ -78,7 +78,7 @@ void game_init(struct game *game, int width, int height);
void quit_game(struct game *game);
void should_update(struct game *game);
bool was_key_pressed_this_frame(struct game *game, int scancode);
-bool was_button_pressed_this_frame(struct game *game, SDL_GameControllerButton button);
+bool was_button_pressed_this_frame(struct game *game, int button);
int is_free_camera(struct game *game);
#endif /* PA_GAME_H */
diff --git a/src/input.c b/src/input.c
@@ -29,7 +29,7 @@ static void key_up(struct input *input, int scancode, u64 current_frame) {
static void button_up(struct input *input, SDL_JoyButtonEvent *event, u64 current_frame)
{
- if (event->button >= SDL_CONTROLLER_BUTTON_MAX) return;
+ if (event->button >= MAX_CONTROLLER_BUTTONS) return;
/* printf("button up %d\n", event->button); */
struct input_edge *edge = &input->button_edge_states[event->button];
@@ -39,7 +39,7 @@ static void button_up(struct input *input, SDL_JoyButtonEvent *event, u64 curren
static void button_down(struct input *input, SDL_JoyButtonEvent *event, u64 current_frame)
{
- if (event->button >= SDL_CONTROLLER_BUTTON_MAX) return;
+ if (event->button >= MAX_CONTROLLER_BUTTONS) return;
printf("button down %d\n", event->button);
struct input_edge *edge = &input->button_edge_states[event->button];
@@ -152,7 +152,7 @@ void init_input(struct input *input) {
input->last_my = 0;
input->resized_height = 0;
input->resized_width = 0;
- input->controller = 0;
+ //input->controller = 0;
assert(input->keystates);
}
@@ -163,7 +163,7 @@ bool is_key_down_on_frame(struct input *input, u8 scancode, u64 frame) {
return edge->down_frame == frame && edge->is_down;
}
-bool is_button_down_on_frame(struct input *input, SDL_GameControllerButton button, u64 frame)
+bool is_button_down_on_frame(struct input *input, int button, u64 frame)
{
struct input_edge *edge = &input->button_edge_states[button];
return edge->down_frame == frame && edge->is_down;
@@ -183,11 +183,14 @@ int input_is_dragging(struct input *input, int mouse_button) {
return input->mbuttons[mouse_button-1];
}
-bool is_button_down(struct input *input, SDL_GameControllerButton button)
+bool is_button_down(struct input *input, int button)
{
+ return false;
+ /*
if (!input->controller) {
return false;
}
return SDL_GameControllerGetButton(input->controller, button) == 1;
+ */
}
diff --git a/src/input.h b/src/input.h
@@ -23,6 +23,7 @@
#define MAX_AXIS_VALUE 32767
#define MIN_AXIS_VALUE -32767
#define MAX_CONTROLLERS
+#define MAX_CONTROLLER_BUTTONS 15
struct input_edge {
int is_down;
@@ -30,11 +31,13 @@ struct input_edge {
u64 up_frame;
};
+
+
struct input {
/* enum key_state keys[0x7F-0x1F]; */
u8 const *keystates;
SDL_Keymod modifiers;
- SDL_GameController *controller;
+ //SDL_GameController *controller;
int mx, my, last_mx, last_my;
int axis[MAX_AXIS];
int axis_min_input;
@@ -50,14 +53,14 @@ struct input {
/* u8 frame_down_keys[KEY_BUFFER_SIZE]; */
/* u8 frame_up_keys[KEY_BUFFER_SIZE]; */
struct input_edge key_edge_states[SDL_NUM_SCANCODES];
- struct input_edge button_edge_states[SDL_CONTROLLER_BUTTON_MAX];
+ struct input_edge button_edge_states[MAX_CONTROLLER_BUTTONS];
};
int input_is_dragging(struct input *input, int mouse_button);
-bool is_button_down(struct input *input, SDL_GameControllerButton button);
+bool is_button_down(struct input *input, int button);
bool is_key_down_on_frame(struct input *input, u8 scancode, u64 frame);
-bool is_button_down_on_frame(struct input *input, SDL_GameControllerButton button, u64 frame);
+bool is_button_down_on_frame(struct input *input, int button, u64 frame);
void init_input(struct input *input);
void input_reset(struct input *input);
diff --git a/src/poisson.c b/src/poisson.c
@@ -5,6 +5,8 @@
#include "common.h"
#include "poisson.h"
+#include <stdio.h>
+
struct grid_info {
double size;
diff --git a/src/skybox.c b/src/skybox.c
@@ -3,6 +3,8 @@
#include "util.h"
#include "texture.h"
+#include <stdio.h>
+
static GLfloat skybox_vertices[] = {
1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0,-1.0, 1.0, 1.0,-1.0, 1.0, // v0-v1-v2-v3 top
1.0, 1.0,-1.0, 1.0, 1.0, 1.0, 1.0,-1.0, 1.0, 1.0,-1.0,-1.0, // v5-v0-v3-v4 right
diff --git a/src/terrain_collision.c b/src/terrain_collision.c
@@ -1,6 +1,7 @@
#include "terrain_collision.h"
+#include <float.h>
struct grid_query {
struct terrain_cell *cell;
diff --git a/src/ui.c b/src/ui.c
@@ -6,6 +6,8 @@
#include "util.h"
#include "common.h"
+#include <stdio.h>
+
// v1------v0
// | |
diff --git a/src/update.c b/src/update.c
@@ -44,8 +44,8 @@ static void movement(struct game *game, struct node *node, float speed_mult)
amt *= speed_mult;
- if ((game->input.modifiers & KMOD_SHIFT) ||
- is_button_down(&game->input, SDL_CONTROLLER_BUTTON_LEFTSTICK))
+ if ((game->input.modifiers & KMOD_SHIFT) /*||
+ is_button_down(&game->input, SDL_CONTROLLER_BUTTON_LEFTSTICK)*/)
{
amt *= 20;
}
@@ -426,8 +426,8 @@ static void player_update(struct game *game, struct entity *player)
}
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))) {
+ (was_key_pressed_this_frame(game, SDL_SCANCODE_SPACE) /*||
+ was_button_pressed_this_frame(game, SDL_CONTROLLER_BUTTON_X)*/)) {
entity_jump(player, 2.0);
}