diff --git a/src/engine/engine.c b/src/engine/engine.c index edda3046..c74b4819 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -52,7 +52,7 @@ engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) { shaderUseCamera(shader, camera); list = chunkListCreate(3, 3, 3); - chunkListShift(list, -1, 0, 0); + chunkListShift(list, 1, 0, 0); // Test // primitive = quadCreate( diff --git a/src/engine/util/math.h b/src/engine/util/math.h new file mode 100644 index 00000000..dc4825f2 --- /dev/null +++ b/src/engine/util/math.h @@ -0,0 +1,8 @@ +// Copyright (c) 2021 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once + +#define mod(a,b) (a%b+b)%b \ No newline at end of file diff --git a/src/engine/world/chunklist.c b/src/engine/world/chunklist.c index a9bbbfe3..536debae 100644 --- a/src/engine/world/chunklist.c +++ b/src/engine/world/chunklist.c @@ -89,9 +89,9 @@ void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z) { chunk = list->chunkList[i]; // Calculate the new local positions for the chunk. - nx = (chunk->x - list->x - x) % list->width; - ny = (chunk->y - list->y - y) % list->height; - nz = (chunk->z - list->z - z) % list->depth; + nx = mod(chunk->x - list->x - x, list->width); + ny = mod(chunk->y - list->y - y, list->height); + nz = mod(chunk->z - list->z - z, list->depth); // Load the chunk if we need to. We also use this to calculate new absolutes if( diff --git a/src/engine/world/chunklist.h b/src/engine/world/chunklist.h index b3ddd456..29c2f6d2 100644 --- a/src/engine/world/chunklist.h +++ b/src/engine/world/chunklist.h @@ -7,6 +7,7 @@ #include #include #include "chunk.h" +#include "./../util/math.h" #define CHUNK_INDEX_NULL = 0