-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use 3d chunks as they come from the server - Render the chunk from 0,0,0 and translate in shader - Use the chunk data as it is rather than unpacked to a map - Remove limitations that prevents blocks y < 0 to be rendered properly
- Loading branch information
1 parent
42c4b39
commit b111dad
Showing
9 changed files
with
277 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "chunk.h" | ||
|
||
char chunk_get(Chunk *chunk, int x, int y, int z) { | ||
int lx = x - chunk->p * CHUNK_SIZE; | ||
int ly = y - chunk->k * CHUNK_SIZE; | ||
int lz = z - chunk->q * CHUNK_SIZE; | ||
|
||
// TODO: Looking for a block in the wrong chunk is a bit weird, but hit code does it | ||
if(lx < CHUNK_SIZE && ly < CHUNK_SIZE && lz < CHUNK_SIZE && | ||
lx >= 0 && ly >= 0 && lz >= 0) { | ||
return chunk->blocks[lx+ly*CHUNK_SIZE+lz*CHUNK_SIZE*CHUNK_SIZE]; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
void chunk_set(Chunk *chunk, int x, int y, int z, int w) { | ||
int lx = x - chunk->p * CHUNK_SIZE; | ||
int ly = y - chunk->k * CHUNK_SIZE; | ||
int lz = z - chunk->q * CHUNK_SIZE; | ||
|
||
if(lx < CHUNK_SIZE && ly < CHUNK_SIZE && lz < CHUNK_SIZE && | ||
lx >= 0 && ly >= 0 && lz >= 0) { | ||
chunk->blocks[lx+ly*CHUNK_SIZE+lz*CHUNK_SIZE*CHUNK_SIZE] = w; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef _chunk_h_ | ||
#define _chunk_h_ | ||
|
||
#include <GLFW/glfw3.h> | ||
|
||
#define CHUNK_SIZE 32 | ||
|
||
typedef struct { | ||
char blocks[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE]; | ||
int p; | ||
int q; | ||
int k; | ||
int faces; | ||
int dirty; | ||
GLuint buffer; | ||
} Chunk; | ||
|
||
char chunk_get(Chunk *chunk, int x, int y, int z); | ||
void chunk_set(Chunk *chunk, int x, int y, int z, int w); | ||
|
||
#define CHUNK_FOR_EACH(blocks, ex, ey, ez, ew) \ | ||
for(int ex = 0; ex < CHUNK_SIZE; ex++) { \ | ||
for(int ey = 0; ey < CHUNK_SIZE; ey++) { \ | ||
for(int ez = 0; ez < CHUNK_SIZE; ez++) { \ | ||
int ew = blocks[ex+ey*CHUNK_SIZE+ez*CHUNK_SIZE*CHUNK_SIZE]; | ||
|
||
#define END_CHUNK_FOR_EACH \ | ||
} \ | ||
} \ | ||
} | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.