cleanup
This commit is contained in:
parent
c4181e5c42
commit
678db8574f
6 changed files with 125 additions and 116 deletions
61
cubes.c
61
cubes.c
|
@ -1,16 +1,15 @@
|
|||
// the messiest part of this whole codebase
|
||||
|
||||
#include "const.h"
|
||||
#include "cubes.h"
|
||||
#include "gen.h"
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct args {
|
||||
Vertex *cube;
|
||||
Vertex *text;
|
||||
VertexI pos;
|
||||
// int is_text;
|
||||
struct v3f *cube;
|
||||
struct v3f *text;
|
||||
struct v3i pos;
|
||||
int a;
|
||||
int i;
|
||||
int a3;
|
||||
|
@ -21,12 +20,12 @@ int ox = -1024;
|
|||
int oy = -1024;
|
||||
int oz = -1024;
|
||||
|
||||
Chunk *chunk_old = NULL;
|
||||
struct chunk *chunk_old = NULL;
|
||||
|
||||
void gen_face(Vertex *cube, int i, int x, int y, int z, int x2, int y2, int z2,
|
||||
int *j, int is_text, Chunk dat, int ci, int a3) {
|
||||
VertexI a = {{x, y, z}};
|
||||
Vertex a2 = {{x, y, z}};
|
||||
void gen_face(struct v3f *cube, int i, int x, int y, int z, int x2, int y2,
|
||||
int z2, int *j, int is_text, struct chunk dat, int ci, int a3) {
|
||||
struct v3i a = {{x, y, z}};
|
||||
struct v3f a2 = {{x, y, z}};
|
||||
|
||||
if (is_text) {
|
||||
a.pos[i]--;
|
||||
|
@ -44,9 +43,9 @@ void gen_face(Vertex *cube, int i, int x, int y, int z, int x2, int y2, int z2,
|
|||
}
|
||||
}
|
||||
|
||||
Vertex b = a2;
|
||||
Vertex c = a2;
|
||||
Vertex d = a2;
|
||||
struct v3f b = a2;
|
||||
struct v3f c = a2;
|
||||
struct v3f d = a2;
|
||||
|
||||
if (is_text) {
|
||||
b.pos[0] += TEXT_GAP_H;
|
||||
|
@ -82,10 +81,10 @@ void *gen_chunk(void *args) {
|
|||
int y2 = args2.pos.pos[1];
|
||||
int z2 = args2.pos.pos[2];
|
||||
|
||||
Vertex *cube = args2.cube;
|
||||
Vertex *text = args2.text;
|
||||
struct v3f *cube = args2.cube;
|
||||
struct v3f *text = args2.text;
|
||||
|
||||
Vertex vNul = {{-10.0, -10.0, -10.0}};
|
||||
struct v3f vNul = {{-10.0, -10.0, -10.0}};
|
||||
if (x2 < 0 || y2 < 0 || z2 < 0) {
|
||||
for (int a = i; a < args2.i + (BLOCK_ALL * 18) * a3; a += 6 * a3) {
|
||||
cube[a] = vNul;
|
||||
|
@ -102,8 +101,8 @@ void *gen_chunk(void *args) {
|
|||
CHUNK_DIAMETER_H) %
|
||||
(CHUNK_ALL);*/
|
||||
|
||||
Chunk chunk = fetch_chunk(x2 / CHUNK_LENGTH, y2 / CHUNK_LENGTH,
|
||||
z2 / CHUNK_LENGTH, a, 0);
|
||||
struct chunk chunk = fetch_chunk(x2 / CHUNK_LENGTH, y2 / CHUNK_LENGTH,
|
||||
z2 / CHUNK_LENGTH, a, 0);
|
||||
|
||||
if (chunk.exists != 0 && the_j > -1)
|
||||
chunk_old[the_j] = chunk;
|
||||
|
@ -139,9 +138,11 @@ void *gen_chunk(void *args) {
|
|||
return (void *)i;
|
||||
}
|
||||
|
||||
int gen_cubes(Vertex *cube, Vertex *text, Vertex *cubeO, Vertex *textO, int x,
|
||||
int y, int z, int is_purge, int *i2) {
|
||||
Vertex noth = {{-1, -1, -1}};
|
||||
void free_chunks_old() { free(chunk_old); }
|
||||
|
||||
int gen_cubes(struct v3f *cube, struct v3f *text, struct v3f *cubeO,
|
||||
struct v3f *textO, int x, int y, int z, int is_purge, int *i2) {
|
||||
struct v3f noth = {{-1, -1, -1}};
|
||||
for (int i = 0; i < CBLOCK_ALL * 18; i++) {
|
||||
cube[i] = noth;
|
||||
text[i] = noth;
|
||||
|
@ -167,7 +168,7 @@ int gen_cubes(Vertex *cube, Vertex *text, Vertex *cubeO, Vertex *textO, int x,
|
|||
}
|
||||
|
||||
if (!chunk_old) {
|
||||
chunk_old = calloc((CHUNK_ALL), sizeof(struct Chunk));
|
||||
chunk_old = calloc((CHUNK_ALL), sizeof(struct chunk));
|
||||
}
|
||||
pthread_t thread_id[a3];
|
||||
int j = 0;
|
||||
|
@ -180,7 +181,7 @@ int gen_cubes(Vertex *cube, Vertex *text, Vertex *cubeO, Vertex *textO, int x,
|
|||
for (int z2 = z - (CHUNK_RADIUS_H)*CHUNK_LENGTH;
|
||||
z2 <= z + (CHUNK_RADIUS_H)*CHUNK_LENGTH; z2 += CHUNK_LENGTH) {
|
||||
|
||||
VertexI pos = {
|
||||
struct v3i pos = {
|
||||
{x + (((x2 / CHUNK_LENGTH) % (CHUNK_DIAMETER_H)) - CHUNK_RADIUS_H) *
|
||||
CHUNK_LENGTH,
|
||||
y + (((y2 / CHUNK_LENGTH) % (CHUNK_DIAMETER_V)) - CHUNK_RADIUS_V) *
|
||||
|
@ -200,7 +201,7 @@ int gen_cubes(Vertex *cube, Vertex *text, Vertex *cubeO, Vertex *textO, int x,
|
|||
|
||||
/*gen_chunk((void *)&args); */
|
||||
|
||||
Chunk old_chunk = chunk_old[a];
|
||||
struct chunk old_chunk = chunk_old[a];
|
||||
|
||||
int cached =
|
||||
(old_chunk.x == pos.pos[0] / CHUNK_LENGTH &&
|
||||
|
@ -238,8 +239,10 @@ int gen_cubes(Vertex *cube, Vertex *text, Vertex *cubeO, Vertex *textO, int x,
|
|||
max += 6;
|
||||
i2[(a / a3) - 1] = max;
|
||||
if (max > i) {
|
||||
memcpy(&(cubeO[j]), &(cube[i - 6 * a3]), (max - i) * sizeof(Vertex));
|
||||
memcpy(&(textO[j]), &(text[i - 6 * a3]), (max - i) * sizeof(Vertex));
|
||||
memcpy(&(cubeO[j]), &(cube[i - 6 * a3]),
|
||||
(max - i) * sizeof(struct v3f));
|
||||
memcpy(&(textO[j]), &(text[i - 6 * a3]),
|
||||
(max - i) * sizeof(struct v3f));
|
||||
j += max - i;
|
||||
}
|
||||
i = (BLOCK_ALL * 18) * a; // i = max + 6;
|
||||
|
@ -249,12 +252,6 @@ int gen_cubes(Vertex *cube, Vertex *text, Vertex *cubeO, Vertex *textO, int x,
|
|||
ox = x;
|
||||
oy = y;
|
||||
oz = z;
|
||||
/* if (i < CBLOCK_ALL * 9 && r < MAX_R) {
|
||||
printf("Expanding radius...\n");
|
||||
return gen_cubes(cube, text, x / CHUNK_LENGTH, y / CHUNK_LENGTH,
|
||||
z / CHUNK_LENGTH, r + 1);
|
||||
}
|
||||
*/
|
||||
|
||||
return j; // i;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue