Added cube.

This commit is contained in:
2021-04-03 22:44:11 +11:00
parent 4e01dd0964
commit 5cf46fa821
11 changed files with 152 additions and 24 deletions

View File

@ -6,10 +6,28 @@
*/
#include "chunk.h"
#include <stdio.h>
void chunkCreate(chunk_t *chunk) {
int32_t count, x, y, z, i;
count = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH;
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++;
}
}
}
void chunkLoad(chunk_t *chunk, int32_t x, int32_t y, int32_t z) {
}
void chunkUnload(chunk_t *chunk) {

View File

@ -5,11 +5,29 @@
#pragma once
#include <stdint.h>
#include "../display/primitive.h"
#include "../display/primitives/quad.h"
#define CHUNK_WIDTH 32
#define CHUNK_HEIGHT CHUNK_WIDTH
#define CHUNK_DEPTH CHUNK_HEIGHT
typedef uint8_t tile_t;
typedef struct {
int32_t x, y, z;
tile_t *tiles;
primitive_t *primitive;
} chunk_t;
/**
* Initializes a chunk for the first time.
*
* @param chunk Pointer to the chunk to initialize.
*/
void chunkCreate(chunk_t *chunk);
/**
* Loads a given chunk into the memory specified.
*

View File

@ -9,6 +9,7 @@
chunklist_t * chunkListCreate(int32_t width, int32_t height, int32_t depth) {
chunklist_t *list;
chunk_t *chunk;
int32_t i, x, y, z;
list = malloc(sizeof(chunklist_t));
@ -32,12 +33,12 @@ chunklist_t * chunkListCreate(int32_t width, int32_t height, int32_t depth) {
return NULL;
}
// Load initial chunks, ZYX order is necessary.
// Load initial chunks, ZYX order is important.
i = 0;
for(z = 0; z < width; z++) {
for(y = 0; y < height; y++) {
for(x = 0; x < depth; x++) {
chunk_t *chunk = list->chunks + i;
chunk = list->chunks + i;
list->chunkList[i] = chunk;
// Load initial coordinates
@ -45,8 +46,8 @@ chunklist_t * chunkListCreate(int32_t width, int32_t height, int32_t depth) {
chunk->y = y;
chunk->z = z;
chunkCreate(chunk);
chunkLoad(chunk, x, y, z);
i++;
}
}

View File

@ -33,7 +33,7 @@ typedef struct {
* @param width The width (x axis) of chunks to keep loaded.
* @param height The height (y axis) of chunks to keep loaded.
* @param depth The depth (z axis) of chunks to keep loaded.
* @returns A new chunk list.
* @return A new chunk list.
*/
chunklist_t * chunkListCreate(int32_t width, int32_t height, int32_t depth);

View File

@ -9,6 +9,13 @@
world_t * worldCreate() {
world_t *world = malloc(sizeof(world_t));
if(world == NULL) return NULL;
world->chunkList = chunkListCreate(3, 3, 1);
if(world->chunkList == NULL) {
free(world);
return NULL;
}
return world;
}

View File

@ -7,8 +7,9 @@
#include "chunklist.h"
typedef struct {
uint32_t x;
chunklist_t *chunkList;
} world_t;
world_t * worldCreate();
void worldDispose(world_t *world);