Tidying some stuff up

This commit is contained in:
2021-04-04 22:33:18 +10:00
parent 02921d7f3b
commit ac63eb6b6a
12 changed files with 80 additions and 34 deletions

View File

@ -14,18 +14,30 @@ void chunkCreate(chunk_t *chunk) {
chunk->primitive = primitiveCreate(count * 4, count * 6);
i = 0;
for(y = 0; y < CHUNK_HEIGHT; y++) {
for(x = 0; x < CHUNK_WIDTH; x++) {
quadBuffer(chunk->primitive,
x, y, 0, 0,
x+1, y+1, 1, 1,
i*4, i*6
);
i++;
for(z = 0; z < CHUNK_DEPTH; z++) {
for(y = 0; y < CHUNK_HEIGHT; y++) {
for(x = 0; x < CHUNK_WIDTH; x++) {
quadBuffer(chunk->primitive,
x, y, 0, 0,
x+1, y+1, 1, 1,
i*4, i*6
);
i++;
}
}
}
}
void chunkRender(chunk_t *chunk, shader_t *shader) {
float x, y, z;
x = (chunk->x * CHUNK_WIDTH);
y = (chunk->y * CHUNK_HEIGHT);
z = (chunk->z * CHUNK_DEPTH);
shaderUsePosition(shader, x*2, y*2, z*2, 0, 0, 0);
primitiveDraw(chunk->primitive, 0, chunk->primitive->indiceCount);
}
void chunkLoad(chunk_t *chunk, int32_t x, int32_t y, int32_t z) {
}

View File

@ -6,9 +6,10 @@
#pragma once
#include <stdint.h>
#include "../display/primitive.h"
#include "../display/shader.h"
#include "../display/primitives/quad.h"
#define CHUNK_WIDTH 32
#define CHUNK_WIDTH 3
#define CHUNK_HEIGHT CHUNK_WIDTH
#define CHUNK_DEPTH CHUNK_HEIGHT
@ -28,6 +29,8 @@ typedef struct {
*/
void chunkCreate(chunk_t *chunk);
void chunkRender(chunk_t *chunk, shader_t *shader);
/**
* Loads a given chunk into the memory specified.
*

View File

@ -35,9 +35,9 @@ chunklist_t * chunkListCreate(int32_t width, int32_t height, int32_t depth) {
// Load initial chunks, ZYX order is important.
i = 0;
for(z = 0; z < width; z++) {
for(z = 0; z < depth; z++) {
for(y = 0; y < height; y++) {
for(x = 0; x < depth; x++) {
for(x = 0; x < width; x++) {
chunk = list->chunks + i;
list->chunkList[i] = chunk;
@ -131,4 +131,14 @@ void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z) {
// Now copy that array over.
memcpy(list->chunkList, chunkList, sizeof(chunk_t *) * list->count);
free(chunkList);
}
void chunkListAlign(chunklist_t *list, int32_t x, int32_t y, int32_t z) {
int32_t lx, ly, lz;
lx = x - list->x;
ly = y - list->y;
lz = z - list->z;
chunkListShift(list, lx, ly, lz);
}

View File

@ -53,4 +53,14 @@ void chunkListDispose(chunklist_t *list);
* @param y Y movement to shift chunk along.
* @param z Z movement to shift chunk along.
*/
void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z);
void chunkListShift(chunklist_t *list, int32_t x, int32_t y, int32_t z);
/**
* Align the chunk list (in absolute space).
*
* @param list List to align.
* @param x X movement to shift chunk along.
* @param y Y movement to shift chunk along.
* @param z Z movement to shift chunk along.
*/
void chunkListAlign(chunklist_t *list, int32_t x, int32_t y, int32_t z);

View File

@ -20,6 +20,13 @@ world_t * worldCreate() {
return world;
}
void worldRender(world_t *world, shader_t *shader) {
int32_t i;
for(i = 0; i < world->chunkList->count; i++) {
chunkRender(world->chunkList->chunks + i, shader);
}
}
void worldDispose(world_t *world) {
free(world);
}

View File

@ -5,6 +5,7 @@
#pragma once
#include "chunklist.h"
#include "../display/shader.h"
typedef struct {
chunklist_t *chunkList;
@ -12,4 +13,6 @@ typedef struct {
world_t * worldCreate();
void worldRender(world_t *world, shader_t *shader);
void worldDispose(world_t *world);