Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
0.5.4
Browse files Browse the repository at this point in the history
- Renderer improvements
- Added chunk compression using zlib
- Improved mesher latency
- Added transparency sorting
- Fixed OpenGLES
- Added tinted and stained glass
  • Loading branch information
PQCraft committed Dec 5, 2022
1 parent fad3915 commit 3a2e2d1
Show file tree
Hide file tree
Showing 44 changed files with 68 additions and 19 deletions.
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- Redo doGame() and remove loopDelay
- Remove collision spaghetti
- Use physics code for collision and raycasting
- Make updateChunks() use a message list
- Add some server events
- Add event for collecting player info
- Add event for running physics
Expand All @@ -25,8 +24,7 @@
- Make server ask for and handle player's positions
- Redo BMD to CCM (delete `src/bmd/` and add `src/ccm/`)
- Add parts, model types (3D, BLOCK, 2D, etc), and data types (VERT, ANI, AABB, etc)
- Impose a limit on block models where triangles must make up quads due to transparency sorting
- Either add a checker function or make the block model format use quads and convert to triangles on load
- Block models use quads instead of triangles
- 3D model rendering in `src/renderer/renderer.c`
- Audio (probably miniaudio or SDL_Mixer) in `src/audio/`
- Redo worldgen in `src/game/worldgen.(c|h)`
Expand All @@ -42,6 +40,7 @@
- Direct3D support
- Greedy mesher in `src/renderer/renderer.c`
- Android support (requires that it be buildable from the command-line using `make` so it can be used in `mkrelease.sh`)
- Make updateChunks() use a message list

### IN-PROGRESS:

Expand All @@ -50,3 +49,5 @@
- Added chunk compression using zlib
- Improved mesher latency
- Added transparency sorting
- Fixed OpenGLES
- Added tinted and stained glass
4 changes: 2 additions & 2 deletions resources/base/engine/shaders/code/GLSL/ui/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ void main() {
} else {
fragColor = texture(fontTexData, vec3(texCoord, texNum));
}
if (bool(u) && int(charty) >= int(charth) - scale) {
if (bool(u) && float(int(charty)) >= float(int(charth)) - scale) {
fragColor = mcolor;
}
if (bool(s) && int(charty) >= int(charth / 2.0) - scale && int(charty) < int(charth / 2.0)) {
if (bool(s) && float(int(charty)) >= float(int(charth / 2.0)) - scale && float(int(charty)) < float(int(charth / 2.0))) {
fragColor = mcolor;
}
fragColor *= mcolor;
Expand Down
1 change: 1 addition & 0 deletions resources/base/game/data/blocks/7/0.inf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name=Water
animation=6
animationdiv=19
backfaces=true
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/1.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Tinted Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/10.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Aqua Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/11.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Cobalt Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/12.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Brown Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/13.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Black Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/14.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Grey Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/15.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=White Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/2.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Blue Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/3.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Purple Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/4.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Pink Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/5.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Rose Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/6.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Red Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/7.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Orange Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/8.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Yellow Stained Glass
texa=.0
2 changes: 2 additions & 0 deletions resources/base/game/data/blocks/8/9.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Green Stained Glass
texa=.0
Binary file removed resources/base/game/textures/blocks/7/0.old/0.png
Binary file not shown.
Binary file removed resources/base/game/textures/blocks/7/0.old/1.png
Binary file not shown.
Binary file removed resources/base/game/textures/blocks/7/0.old/2.png
Binary file not shown.
Binary file removed resources/base/game/textures/blocks/7/0.old/3.png
Binary file not shown.
Binary file removed resources/base/game/textures/blocks/7/0.old/4.png
Binary file not shown.
Binary file removed resources/base/game/textures/blocks/7/0.old/5.png
Binary file not shown.
Binary file added resources/base/game/textures/blocks/8/1/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/10/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/11/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/12/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/13/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/14/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/15/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/2/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/3/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/4/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/5/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/6/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/7/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/8/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/base/game/textures/blocks/8/9/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/game/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void initBlocks() {
blockinf[i].data[j].light_r = atoi(getInfoVarStatic((char*)varcfg->data, "light_r", "0", 16));
blockinf[i].data[j].light_g = atoi(getInfoVarStatic((char*)varcfg->data, "light_g", "0", 16));
blockinf[i].data[j].light_b = atoi(getInfoVarStatic((char*)varcfg->data, "light_b", "0", 16));
blockinf[i].data[j].backfaces = getBool(getInfoVarStatic((char*)varcfg->data, "backfaces", "false", 16));
freeResource(varcfg);
#if DBGLVL(1)
printf(" Variant #%d: id \"%s\", name \"%s\"\n", j, blockinf[i].data[j].id, blockinf[i].data[j].name);
Expand Down
1 change: 1 addition & 0 deletions src/game/blocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct blockinfo_data {
uint8_t light_r:4;
uint8_t light_g:4;
uint8_t light_b:4;
bool backfaces;
};

struct blockinfo {
Expand Down
6 changes: 4 additions & 2 deletions src/game/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ void moveChunks(struct chunkdata* chunks, int64_t cxo, int64_t czo, int cx, int
}
}
for (int d = chunks->info.dist; d < 0; ++d) {
sortChunk(-1, d, d, false);
sortChunk(-1, d, 0, false);
sortChunk(-1, 0, d, false);
}
for (int d = 1; d <= (int)chunks->info.dist; ++d) {
sortChunk(-1, d, d, false);
sortChunk(-1, d, 0, false);
sortChunk(-1, 0, d, false);
}
pthread_mutex_unlock(&uclock);
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct __attribute__((packed)) blockdata {
uint8_t light_g:4;
uint8_t light_b:4;
uint8_t light_n:4;
uint8_t attrib:4;
uint8_t charge:8;
uint8_t charge:4;
uint8_t flags:8;
};

struct rendorder {
Expand Down
33 changes: 23 additions & 10 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ static force_inline bool isVisible(struct frustum* frust, float ax, float ay, fl
return true;
}

static float sc_camx, sc_camy, sc_camz;

void updateCam() {
static float uc_fov = -1.0, uc_asp = -1.0;
static avec3 uc_campos;
Expand All @@ -212,9 +214,9 @@ void updateCam() {
//setMat4(rendinf.shaderprog, "projection", uc_proj);
uc_uproj = false;
}
uc_campos[0] = rendinf.campos.x;
uc_campos[1] = rendinf.campos.y;
uc_campos[2] = rendinf.campos.z;
uc_campos[0] = sc_camx = rendinf.campos.x;
uc_campos[1] = sc_camy = rendinf.campos.y;
uc_campos[2] = sc_camz = rendinf.campos.z;
uc_rotradx = rendinf.camrot.x * M_PI / 180.0;
uc_rotrady = (rendinf.camrot.y - 90.0) * M_PI / 180.0;
uc_rotradz = rendinf.camrot.z * M_PI / 180.0;
Expand Down Expand Up @@ -269,7 +271,12 @@ static void fbsize(GLFWwindow* win, int w, int h) {

void setFullscreen(bool fullscreen) {
static int winox = -1, winoy = -1;

#if defined(USESDL2)
#else
glfwSetFramebufferSizeCallback(rendinf.window, NULL);
#endif

if (fullscreen) {
rendinf.aspect = (float)rendinf.full_width / (float)rendinf.full_height;
rendinf.width = rendinf.full_width;
Expand Down Expand Up @@ -328,7 +335,10 @@ void setFullscreen(bool fullscreen) {

glViewport(0, 0, rendinf.width, rendinf.height);

#if defined(USESDL2)
#else
glfwSetFramebufferSizeCallback(rendinf.window, fbsize);
#endif
}

static force_inline bool makeShaderProg(char* hdrtext, char* _vstext, char* _fstext, GLuint* p) {
Expand Down Expand Up @@ -621,9 +631,9 @@ static force_inline void _sortChunk(int32_t c, int xoff, int zoff, bool update)
if (!chunks->renddata[c].sortvert || !chunks->renddata[c].tcount[1]) return;
if (update && !chunks->renddata[c].visible) return;
//printf("sorting: [%d, %d]\n", xoff, zoff);
float camx = rendinf.campos.x - xoff * 16;
float camy = rendinf.campos.y;
float camz = -rendinf.campos.z - zoff * 16;
float camx = sc_camx - xoff * 16;
float camy = sc_camy;
float camz = -sc_camz - zoff * 16;
int32_t tmpsize = chunks->renddata[c].tcount[1] / 3 / 2;
//if (!xoff && !zoff) printf("tri count of 0, 0: [%d]\n", tmpsize);
struct tricmp* data = malloc(tmpsize * sizeof(struct tricmp));
Expand Down Expand Up @@ -723,8 +733,11 @@ static force_inline void mesh(int64_t x, int64_t z, uint64_t id) {
bdata2[5] = rendGetBlock(c, x, y, z - 1);
for (int i = 0; i < 6; ++i) {
if (bdata2[i].id && blockinf[bdata2[i].id].id) {
if (!blockinf[bdata2[i].id].data[bdata2[i].subid].transparency) continue;
if (blockinf[bdata.id].data[bdata.subid].transparency && (bdata.id == bdata2[i].id)) continue;
if (blockinf[bdata2[i].id].data[bdata2[i].subid].transparency) {
if (bdata.id == bdata2[i].id && bdata.subid == bdata2[i].subid) continue;
} else {
continue;
}
}
if (bdata2[i].id == 255) continue;
uint32_t baseVert1 = ((x << 28) | (y << 16) | (z << 8)) & 0xF0FF0F00;
Expand All @@ -737,7 +750,7 @@ static force_inline void mesh(int64_t x, int64_t z, uint64_t id) {
mtsetvert(&_vptr2, &vpsize2, &vplen2, &vptr2, constBlockVert1[i][j] | baseVert1);
mtsetvert(&_vptr2, &vpsize2, &vplen2, &vptr2, constBlockVert2[i][j] | baseVert2);
mtsetvert(&_vptr2, &vpsize2, &vplen2, &vptr2, baseVert3);
if (!bdata2[i].id) {
if (!bdata2[i].id && blockinf[bdata.id].data[bdata.subid].backfaces) {
mtsetvert(&_vptr2, &vpsize2, &vplen2, &vptr2, constBlockVert1[i][5 - j] | baseVert1);
mtsetvert(&_vptr2, &vpsize2, &vplen2, &vptr2, constBlockVert2[i][5 - j] | baseVert2);
mtsetvert(&_vptr2, &vpsize2, &vplen2, &vptr2, baseVert3);
Expand Down Expand Up @@ -1608,7 +1621,7 @@ bool startRenderer() {
vs = loadResource(RESOURCE_TEXTFILE, "engine/shaders/code/GLSL/ui/vertex.glsl");
fs = loadResource(RESOURCE_TEXTFILE, "engine/shaders/code/GLSL/ui/fragment.glsl");
if (!vs || !fs || !makeShaderProg((char*)hdr->data, (char*)vs->data, (char*)fs->data, &shader_ui)) {
fputs("startRenderer: Failed to compile text shader\n", stderr);
fputs("startRenderer: Failed to compile UI shader\n", stderr);
return false;
}
freeResource(vs);
Expand Down

0 comments on commit 3a2e2d1

Please sign in to comment.