polyadvent

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

commit c24b87fb931515d719d01598d57c695a9bbba6a3
parent d07bfbbc047ed0ec2f5739350b69155d080718e1
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 22 Sep 2018 17:25:39 -0700

terrain experiment

Diffstat:
MMakefile | 2+-
Msrc/game.c | 4++--
Msrc/main.c | 8++------
Msrc/terrain.c | 3++-
Msrc/update.c | 14++++++++------
5 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,7 @@ NAME ?= polyadvent BIN ?= $(NAME) PREFIX ?= /usr/local -CFLAGS = -ggdb -I src -Wall -Werror -Wextra -std=c99 \ +CFLAGS = -ggdb -Ofast -I src -Wall -Werror -Wextra -std=c99 \ -Wno-unused-function \ -Wno-unused-parameter \ -Wno-unused-variable \ diff --git a/src/game.c b/src/game.c @@ -27,7 +27,7 @@ void game_init(struct game *game) { struct terrain *terrain = &game->terrain; mat4 *light_dir = game->test_resources.light_dir; - const double size = 10000; + const double size = 5000; const double pdist = 1.7; terrain->settings = (struct perlin_settings){ @@ -77,7 +77,7 @@ void game_init(struct game *game) { /* camera->mirrored = 1; */ node_translate(player, V3(terrain->size/2.,terrain->size/2.,0)); - node_translate(camera, V3(0,-30,20)); + node_translate(camera, V3(0,-30,100)); /* node_recalc(camera); */ terrain_node->pos[2] = 20.0; diff --git a/src/main.c b/src/main.c @@ -22,14 +22,10 @@ int main(void) { int nsamples; - int seed = time(NULL); - srand(seed); + /* int seed = time(NULL); */ + srand(42); struct game game; - struct slab slab; - struct geometry slab_geom; - - size_t length; /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */ int width = 640; diff --git a/src/terrain.c b/src/terrain.c @@ -72,7 +72,8 @@ terrain_create(struct terrain *terrain) { // 100 random samples from our noise function for (i = 0; i < (u32)terrain->n_samples; i++) { int n = i*3; - double x, y, dx, dy; + double x, y; + /* double dx, dy; */ x = terrain->samples[i].x; y = terrain->samples[i].y; diff --git a/src/update.c b/src/update.c @@ -9,10 +9,12 @@ #include "poisson.h" #include "uniform.h" -static void movement(struct game *game, struct node *node) { +static void movement(struct game *game, struct node *node, float speed_mult) { float amt = 0.03; static const float turn = 0.01; + amt *= speed_mult; + if (game->input.modifiers & KMOD_SHIFT) amt *= 50; @@ -126,7 +128,7 @@ static void player_movement(struct game *game) { // player movement static vec3 last_pos[3] = {0}; - movement(game, &res->player); + movement(game, &res->player, 1.0); if (!vec3_eq(res->player.pos, last_pos, 0.0001)) { @@ -169,10 +171,10 @@ void update (struct game *game, u32 dt) { } if (game->input.modifiers & KMOD_LALT) { - movement(game, &res->camera); + movement(game, &res->camera, 1.0); } - else if (game->input.modifiers & KMOD_LCTRL) { - movement(game, &res->terrain_node); + else if (game->input.modifiers & KMOD_RCTRL) { + movement(game, &res->terrain_node, 5.0); } else { player_movement(game); @@ -203,7 +205,7 @@ void update (struct game *game, u32 dt) { } } - if (space_down || passed < 500) { + if (space_down ) { passed += dt; } else { if (toggle_fog) {