commit b1a46d36e722165b16cd948a1169d0da9194e62d
parent e584a50fcb186c8b1dfe83a77b7c85b68988147d
Author: William Casarin <jb55@jb55.com>
Date: Sun, 19 Apr 2020 17:18:12 -0700
fix terrain collision index oob issues
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -106,7 +106,7 @@ void game_init(struct game *game, int width, int height) {
game->quit = 0;
game->frame = 0;
- const double size = 10000.0;
+ const double size = 5000.0;
double scale = 0.03;
terrain->settings = (struct perlin_settings){
@@ -127,9 +127,10 @@ void game_init(struct game *game, int width, int height) {
init_terrain(terrain, size);
int seed;
- terrain->samples = load_samples(&seed, &terrain->n_samples);
+ /* terrain->samples = load_samples(&seed, &terrain->n_samples); */
+ terrain->n_samples = 0;
create_terrain(terrain, size, game->seed);
- /* update_terrain(terrain); */
+ /* update_terrain(terrain, terrain->cell_size); */
/* get_entity(&terrain->entity_id)->flags |= ENT_INVISIBLE; */
diff --git a/src/terrain.c b/src/terrain.c
@@ -213,7 +213,7 @@ void create_terrain(struct terrain *terrain, float scale, int seed) {
del_point2d_t *points = calloc(terrain->n_samples, sizeof(*points));
float *verts = calloc(terrain->n_samples * 3, sizeof(*verts));
terrain->cell_size = pdist;
- terrain->n_cells = round(size / terrain->cell_size);
+ terrain->n_cells = round(size / terrain->cell_size) + 1;
debug("n_cells %d\n", terrain->n_cells);
struct terrain_cell *grid =