blob: e81f10071a4004016ccec520932cdb422a6baa73 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include "world.h"
#include <stdlib.h>
#include <string.h>
int world_init(int32_t seed, struct world** world) {
srand(seed);
struct world* wld = malloc(sizeof(struct world));
memset(wld, 0, sizeof(struct world));
wld->seed = seed;
for (int i = 0; i < WORLD_WIDTH; i++) {
for (int j = 0; j < WORLD_LENGTH; j++) {
struct chunk* chunk;
vec2 coords = { i, j };
chunk_gen(wld, coords, &chunk);
wld->chunks[i][j] = chunk;
}
}
*world = wld;
return 0;
}
int world_get_chunk(struct world* world, vec2 coord, struct chunk** chunk) {
int x = (int)coord[0] % WORLD_WIDTH;
int y = (int)coord[1] % WORLD_LENGTH;
*chunk = world->chunks[x][y];
return 0;
}
|