polyadvent

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

commit 991995701746671c527797fbed11933ac9c67c65
parent 2ff19ed7e53ecaf2407053de493508d0872674e7
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 28 Apr 2018 00:21:15 -0700

hmm

Diffstat:
Msrc/main.c | 1+
Msrc/terrain.c | 5+++--
Msrc/update.c | 28++++++++++++++++++++--------
3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -11,6 +11,7 @@ #include "event.h" #include "render.h" #include "terrain.h" +#include "util.h" #include <assert.h> #include <time.h> #include "poisson.h" diff --git a/src/terrain.c b/src/terrain.c @@ -20,6 +20,7 @@ static const u32 plane_indices[] = { double old_noisy_boi(void *data, double x, double y) { + /* return cos(x/10.0) * sin(y/10.0) * 20.0; */ struct perlin_settings *s = (struct perlin_settings*)data; double e = perlin2d(x, y, s->freq, s->depth) + s->o1s * perlin2d(s->o1 * x, s->o1 * y, s->freq, s->depth) @@ -124,8 +125,8 @@ terrain_create(struct terrain *terrain, struct perlin_settings *perlin) { del_indices[nv+2] = nv+2; } - printf("faces %d tris %d points %d\n", - del->num_faces, tri->num_triangles, tri->num_points); + /* printf("faces %d tris %d points %d\n", */ + /* del->num_faces, tri->num_triangles, tri->num_points); */ terrain->geom.num_verts = num_verts; terrain->geom.vertices = (float*)del_verts; diff --git a/src/update.c b/src/update.c @@ -53,6 +53,7 @@ void update (struct game *game, u32 dt) { static int last_gen_time = 50; static float n = 1; struct resources *res = &game->test_resources; + int once = 0; static struct perlin_settings terrain_settings = { .depth = 1, .freq = 0.04, @@ -74,13 +75,23 @@ void update (struct game *game, u32 dt) { if (game->input.keystates[SDL_SCANCODE_C]) { printf("light_dir %f %f %f\n", light[0], light[1], light[2]); + } int space_down = game->input.keystates[SDL_SCANCODE_SPACE]; if (space_down || passed < last_gen_time) { + if (space_down && once) { + printf("terrain amp %f exp %f freq %f (%d ms)\n", + terrain_settings.amplitude, + terrain_settings.exp, + terrain_settings.freq, + last_gen_time); + } passed += dt; + once = 0; } else { + once = 1; passed = 0; terrain_settings.oy += 1.0; @@ -90,16 +101,16 @@ void update (struct game *game, u32 dt) { /* terrain_settings.o2s = fabs(cos(n+2) * 0.5); */ /* terrain_settings.o2 = fabs(sin(n*0.02) * 2); */ /* terrain_settings.freq = fabs(-sin(n)*0.002 * cos(-n)) + 0.02; */ - /* terrain_settings.exp = fabs(cos(n)*2.0*cos(n)) + 5.0; */ - /* terrain_settings.amplitude = cos(1/n)*2.0*cos(n) + 0.5; */ + terrain_settings.exp = fabs(cos(n)*2.0*cos(n)) + 5.0; + terrain_settings.amplitude = cos(1/n)*2.0*cos(n) + 0.5; - /* terrain_destroy(game->terrain); */ - /* terrain_init(game->terrain); */ + terrain_destroy(game->terrain); + terrain_init(game->terrain); - /* int t1 = SDL_GetTicks(); */ - /* terrain_create(game->terrain, &terrain_settings); */ - /* int t2 = SDL_GetTicks(); */ - /* last_gen_time = t2 - t1; */ + int t1 = SDL_GetTicks(); + terrain_create(game->terrain, &terrain_settings); + int t2 = SDL_GetTicks(); + last_gen_time = t2 - t1; /* printf("terrain amp %f exp %f freq %f (%d ms)\n", */ /* terrain_settings.amplitude, */ @@ -107,6 +118,7 @@ void update (struct game *game, u32 dt) { /* terrain_settings.freq, */ /* last_gen_time); */ + /* res->light_dir[0] = cos(n) * 0.8; */ n += 0.01f; }