cleanup
This commit is contained in:
parent
c4181e5c42
commit
678db8574f
6 changed files with 125 additions and 116 deletions
30
gen.c
30
gen.c
|
@ -1,10 +1,10 @@
|
|||
#include "const.h"
|
||||
#include "cubes.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Chunk *chunks = NULL;
|
||||
struct chunk *chunks = NULL;
|
||||
int lastI = 0;
|
||||
int seed = 69420;
|
||||
int prevExists = 0;
|
||||
|
@ -14,17 +14,17 @@ double interpolate(double a0, double a1, double w) {
|
|||
|
||||
int hash_combine(int a, int b) { return b + 0x9e3779b9 + (a << 6) + (a >> 2); }
|
||||
|
||||
Vertex2 perlin_grad(int x, int y) {
|
||||
struct v2f perlin_grad(int x, int y) {
|
||||
int x_hash = hash_combine(x, seed);
|
||||
int y_hash = hash_combine(seed, y);
|
||||
|
||||
double random = hash_combine(x_hash, y_hash) * (M_PI / ~(~0u >> 1));
|
||||
Vertex2 out = {cos(random), sin(random)};
|
||||
struct v2f out = {cos(random), sin(random)};
|
||||
return out;
|
||||
}
|
||||
|
||||
double perlin_dot(double ix, double iy, double x, double y) {
|
||||
Vertex2 grad = perlin_grad(ix, iy);
|
||||
struct v2f grad = perlin_grad(ix, iy);
|
||||
|
||||
double dx = x - (double)ix;
|
||||
double dy = y - (double)iy;
|
||||
|
@ -58,11 +58,11 @@ double perlin_calc(double x, double y, double s) {
|
|||
return value;
|
||||
}
|
||||
|
||||
Chunk fetch_chunk(int x, int y, int z, int ci, int h) {
|
||||
struct chunk fetch_chunk(int x, int y, int z, int ci, int h) {
|
||||
|
||||
Chunk *chunks2 = chunks; // &chunks[CBUF_ALL * ci];
|
||||
struct chunk *chunks2 = chunks; // &chunks[CBUF_ALL * ci];
|
||||
|
||||
Chunk chunk;
|
||||
struct chunk chunk;
|
||||
|
||||
if (x < 0 || y < 0 || z < 0) {
|
||||
chunk.exists = 0;
|
||||
|
@ -102,7 +102,7 @@ Chunk fetch_chunk(int x, int y, int z, int ci, int h) {
|
|||
|
||||
FILE *fp = fopen(fname, "rb+");
|
||||
|
||||
int code = (fp) ? fread(&chunk, sizeof(Chunk), 1, fp) : 0;
|
||||
int code = (fp) ? fread(&chunk, sizeof(struct chunk), 1, fp) : 0;
|
||||
if (code != 0) {
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
|
@ -151,7 +151,7 @@ Chunk fetch_chunk(int x, int y, int z, int ci, int h) {
|
|||
return chunk;
|
||||
}
|
||||
|
||||
fwrite(&chunk, sizeof(Chunk), 1, fp);
|
||||
fwrite(&chunk, sizeof(struct chunk), 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
return chunk;
|
||||
|
@ -160,15 +160,17 @@ Chunk fetch_chunk(int x, int y, int z, int ci, int h) {
|
|||
void purge_chunks(int ci) {
|
||||
/*
|
||||
free(chunks);
|
||||
chunks = calloc(CBUF_ALL, sizeof(Chunk));
|
||||
chunks = calloc(CBUF_ALL, sizeof(struct chunk));
|
||||
*/
|
||||
if (chunks == NULL) {
|
||||
chunks = calloc(CHUNK_ALL, sizeof(Chunk));
|
||||
chunks = calloc(CHUNK_ALL, sizeof(struct chunk));
|
||||
}
|
||||
// memset(chunks, 0, sizeof(Chunk) *CHUNK_ALL);
|
||||
// memset(chunks, 0, sizeof(struct chunk) *CHUNK_ALL);
|
||||
}
|
||||
|
||||
int cube_exists(int x, int y, int z, Chunk dat, int ci) {
|
||||
void free_chunks() { free(chunks); }
|
||||
|
||||
int cube_exists(int x, int y, int z, struct chunk dat, int ci) {
|
||||
if (x < 0 || y < 0 || z < 0)
|
||||
return 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue