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

Commit

Permalink
0.5.3
Browse files Browse the repository at this point in the history
- Made internal messages more linear
- Fixed memory issues
- Updated README.md
- Changed default loopDelay value from 5ms to 1ms
- DEBUG=1+ is now required to print out detailed server start/stop info
  • Loading branch information
PQCraft committed Nov 28, 2022
1 parent 471eaae commit 35c8f96
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 59 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<div align="center">
<a HREF="#?"><img src="https://img.shields.io/github/languages/top/PQCraft/CaveCube?color=%232267a6&label=%20&logo=C&logoColor=white" alt="Language"/></a>
<a HREF="#?"><img src="https://img.shields.io/github/license/PQCraft/CaveCube?color=informational&label=License" alt="License"/></a>
<a HREF="#?"><img src="https://img.shields.io/badge/dynamic/json?color=informational&label=Latest%20release&query=tag_name&url=https%3A%2F%2Fapi.github.com%2Frepos%2FPQCraft%2FCaveCube%2Freleases%2Flatest" alt="Latest release"/></a>
<a HREF="#?"><img src="https://img.shields.io/badge/dynamic/json?color=informational&label=Version&query=tag_name&url=https%3A%2F%2Fapi.github.com%2Frepos%2FPQCraft%2FCaveCube%2Freleases%2Flatest" alt="Version"/></a>
<a HREF="#?"><img src="https://img.shields.io/github/downloads/PQCraft/CaveCube/latest/total?color=informational&label=Downloads&logo=github" alt="Downloads"/></a>
<a HREF="#?"><img src="https://img.shields.io/github/downloads/PQCraft/CaveCube/total?color=informational&label=Total%20downloads&logo=github" alt="Total downloads"/></a>
<a HREF="#?"><img src="https://img.shields.io/github/issues/PQCraft/CaveCube?label=Issues" alt="Issues"/></a>
<a HREF="#?"><img src="https://img.shields.io/github/issues-pr/PQCraft/CaveCube?label=Pull%20requests" alt="Pull requests"/></a>
</div>

[![](https://raw.githubusercontent.com/PQCraft/PQCraft/master/Screenshot_20220918_210819.png)](#?)
[![](https://raw.githubusercontent.com/PQCraft/PQCraft/master/Screenshot_20221128_010856.png)](#?)

---
### Contributing
Expand All @@ -36,7 +36,7 @@ OpenGL 3.3 or OpenGLES 3.0 support.
- To build for debugging, add `DEBUG=[level]` after `make` (eg. `make DEBUG=0 -j run`). This will build the executable with debug symbols, disable symbol stripping, and define the internal `DEBUG` macro with the level specified.<br>
- To compile with using SDL2 instead of GLFW, add `USESDL2=y` after `make`.<br>
- To compile using OpenGL ES instead of OpenGL, add `USEGLES=y` after `make`.<br>
- To change the target to the standalone server, add `SERVER=y` after `make`. This variable will change the object directory.<br>
- To change the target to the standalone server, add `MODULE=server` after `make`. This variable will change the object directory.<br>
- To cross compile to Windows on a non-Windows OS, add `WINCROSS=y` after `make`. This variable will change the object directory and binary name.<br>
- To compile a 32-bit binary on a 64-bit machine, add `M32=y` after `make`. This variable will change the object directory.<br>

Expand All @@ -49,4 +49,4 @@ When using MSYS2, the MINGW64 environment is recommended and always use `MSYS2=y

---
### Notes <img src="https://repology.org/badge/vertical-allrepos/cavecube.svg" alt="Packaging status" align="right"/><br>
- CaveCube can be installed on Arch Linux using the [cavecube](https://aur.archlinux.org/packages/cavecube) or [cavecube-bin](https://aur.archlinux.org/packages/cavecube-bin) package.<br>
- CaveCube can be installed on Arch Linux using the [cavecube](https://aur.archlinux.org/packages/cavecube), [cavecube-bin](https://aur.archlinux.org/packages/cavecube-bin), [cavecube-sdl2](https://aur.archlinux.org/packages/cavecube-sdl2), or [cavecube-sdl2-bin](https://aur.archlinux.org/packages/cavecube-sdl2-bin) AUR package.<br>
7 changes: 6 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- More UI elements (buttons, text boxes, etc)
- UI interaction (elem states, tooltips, etc)
- Add `fit_width_to_text` and `fit_height_to_text` attrib
- Add `text_fmt` attrib
- Add items to hotbar
- Redo almost everything to do with chunks/blocks
- Add physics in `src/physics/`
Expand Down Expand Up @@ -43,4 +44,8 @@
### IN-PROGRESS:

### DONE:
- Removed some left-over debugging code
- Made internal messages more linear
- Fixed memory issues
- Updated README.md
- Changed default loopDelay value from 5ms to 1ms
- DEBUG=1+ is now required to print out detailed server start/stop info
25 changes: 25 additions & 0 deletions extras/docs/world saves.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<World name corrected for general filesystem name limitations>/
server/
players/
[Player ID in 16 network order hex chars]
<Player data>
...
config.cfg
<Server config>
world/
entities/
[Entity ID in 16 hex chars]
<Entity data>
...
chunks/
<Dimension text id>/
[<Chunk X coord in 16 network order hex chars><Chunk Z coord in 16 network order hex chars>]
<Chunk data>
...
state
<The state of certain vars at the time of writing the save>
dynamic.inf
<Dynamic info about the world (modification date, playtime, etc) in a format readable by common/config.c>
static.inf
<Static info about the world (name, seed, creation date, etc) in a format readable by common/config.c>

1 change: 1 addition & 0 deletions src/common/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ struct config* openConfig(char* path) {
}
free(sect);
cfg->changed = false;
freeFile(fdata);
return cfg;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ bool doGame(char* addr, int port) {
tmpbuf[i] = malloc(4096);
}
declareConfigKey(config, "Game", "viewDist", "8", false);
declareConfigKey(config, "Game", "loopDelay", "5000", false);
declareConfigKey(config, "Game", "loopDelay", "1000", false);
declareConfigKey(config, "Player", "name", "Player", false);
declareConfigKey(config, "Player", "skin", "", false);
chunks = allocChunks(atoi(getConfigKey(config, "Game", "viewDist")));
Expand Down
6 changes: 6 additions & 0 deletions src/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ char* input_sa_names[] = {
"single.rotBlockX",
"single.rotBlockY",
"single.rotBlockZ",
"single.chat",
"single.command",
"single.fullscreen",
"single.debug",
//"single.leftClick",
Expand Down Expand Up @@ -138,6 +140,8 @@ input_keys input_sa[INPUT_ACTION_SINGLE__MAX] = {
KEY('k', 'b', SDL_SCANCODE_R, 0, 0, 0),
KEY('k', 'b', SDL_SCANCODE_F, 0, 0, 0),
KEY('k', 'b', SDL_SCANCODE_C, 0, 0, 0),
KEY('k', 'b', SDL_SCANCODE_T, 0, 0, 0),
KEY('k', 'b', SDL_SCANCODE_SLASH, 0, 0, 0),
KEY('k', 'b', SDL_SCANCODE_F11, 0, 0, 0),
KEY('k', 'b', SDL_SCANCODE_F3, 0, 0, 0),
//KEY('m', 'b', SDL_BUTTON(1), 0, 0, 0),
Expand All @@ -162,6 +166,8 @@ input_keys input_sa[INPUT_ACTION_SINGLE__MAX] = {
KEY('k', 'b', GLFW_KEY_R, 0, 0, 0),
KEY('k', 'b', GLFW_KEY_F, 0, 0, 0),
KEY('k', 'b', GLFW_KEY_C, 0, 0, 0),
KEY('k', 'b', GLFW_KEY_T, 0, 0, 0),
KEY('k', 'b', GLFW_KEY_SLASH, 0, 0, 0),
KEY('k', 'b', GLFW_KEY_F11, 0, 0, 0),
KEY('k', 'b', GLFW_KEY_F3, 0, 0, 0),
//KEY('m', 'b', GLFW_MOUSE_BUTTON_LEFT, 0, 0, 0),
Expand Down
2 changes: 2 additions & 0 deletions src/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum {
/*INPUT_ACTION_SINGLE_ROT_X*/ INPUT_ACTION_SINGLE_VARIANT_NEXT,
/*INPUT_ACTION_SINGLE_ROT_Y*/ INPUT_ACTION_SINGLE_VARIANT_PREV,
INPUT_ACTION_SINGLE_ROT_Z,
INPUT_ACTION_SINGLE_CHAT,
INPUT_ACTION_SINGLE_COMMAND,
INPUT_ACTION_SINGLE_FULLSCR,
INPUT_ACTION_SINGLE_DEBUG,
//INPUT_ACTION_SINGLE_LCLICK, // move to INPUT_ACTION_UI
Expand Down
2 changes: 1 addition & 1 deletion src/main/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define VER_MAJOR 0
#define VER_MINOR 5
#define VER_PATCH 2
#define VER_PATCH 3

#define _STR(x) #x
#define STR(x) _STR(x)
Expand Down
50 changes: 22 additions & 28 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,18 @@ struct msgdata_msg {
};

struct msgdata {
bool valid;
int size;
int rptr;
int wptr;
struct msgdata_msg* msg;
pthread_mutex_t lock;
uint64_t id;
pthread_mutex_t lock;
};

static force_inline void initMsgData(struct msgdata* mdata) {
mdata->valid = true;
mdata->size = 0;
mdata->rptr = -1;
mdata->wptr = -1;
mdata->msg = malloc(0);
pthread_mutex_init(&mdata->lock, NULL);
}
Expand All @@ -466,30 +468,19 @@ static void deinitMsgData(struct msgdata* mdata) {

static force_inline void addMsg(struct msgdata* mdata, int64_t x, int64_t z, uint64_t id, bool dep, int lvl) {
pthread_mutex_lock(&mdata->lock);
if (mdata->valid) {
int index = -1;
for (int i = 0; i < mdata->size; ++i) {
/*if (mdata->msg[i].valid && mdata->msg[i].x == x && mdata->msg[i].z == z) {
printf("dup: [%"PRId64", %"PRId64"] with [%d]\n", x, z, i);
goto skip;
} else*/ if (!mdata->msg[i].valid && index == -1) {
index = i;
break;
}
}
if (index == -1) {
index = mdata->size++;
mdata->msg = realloc(mdata->msg, mdata->size * sizeof(*mdata->msg));
}
//printf("adding [%d]/[%d]\n", index + 1, mdata->size);
mdata->msg[index].valid = true;
mdata->msg[index].dep = dep;
mdata->msg[index].lvl = lvl;
mdata->msg[index].x = x;
mdata->msg[index].z = z;
mdata->msg[index].id = (dep) ? id : mdata->id++;
//skip:;
if (mdata->wptr < 0 || mdata->rptr >= mdata->size) {
mdata->rptr = 0;
mdata->size = 0;
}
mdata->wptr = mdata->size++;
//printf("[%lu]: wptr: [%d] size: [%d]\n", (uintptr_t)mdata, mdata->wptr, mdata->size);
mdata->msg = realloc(mdata->msg, mdata->size * sizeof(*mdata->msg));
mdata->msg[mdata->wptr].valid = true;
mdata->msg[mdata->wptr].dep = dep;
mdata->msg[mdata->wptr].lvl = lvl;
mdata->msg[mdata->wptr].x = x;
mdata->msg[mdata->wptr].z = z;
mdata->msg[mdata->wptr].id = (dep) ? id : mdata->id++;
pthread_mutex_unlock(&mdata->lock);
}

Expand All @@ -506,8 +497,8 @@ void setMeshChunkOff(int64_t x, int64_t z) {

static force_inline bool getNextMsg(struct msgdata* mdata, struct msgdata_msg* msg) {
pthread_mutex_lock(&mdata->lock);
if (mdata->valid) {
for (int i = 0; i < mdata->size; ++i) {
if (mdata->rptr >= 0) {
for (int i = mdata->rptr; i < mdata->size; ++i) {
if (mdata->msg[i].valid) {
msg->valid = mdata->msg[i].valid;
msg->dep = mdata->msg[i].dep;
Expand All @@ -516,6 +507,8 @@ static force_inline bool getNextMsg(struct msgdata* mdata, struct msgdata_msg* m
msg->z = mdata->msg[i].z;
msg->id = mdata->msg[i].id;
mdata->msg[i].valid = false;
mdata->rptr = i + 1;
//printf("[%lu]: rptr: [%d] size: [%d]\n", (uintptr_t)mdata, mdata->rptr, mdata->size);
pthread_mutex_unlock(&mdata->lock);
//printf("returning [%d]/[%d]\n", i + 1, mdata->size);
return true;
Expand Down Expand Up @@ -1035,6 +1028,7 @@ static force_inline void meshUIElem(struct meshdata* md, struct ui_data* elemdat
y += tch * s;
}
}
free(tdata);
p->x -= mx;
p->width += mx * 2;
p->y -= my;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ bool calcUIProperties(struct ui_data* elemdata) {
void freeUI(struct ui_data* elemdata) {
clearUIElems(elemdata);
glDeleteBuffers(1, &elemdata->renddata.VBO);
free(elemdata->data);
free(elemdata);
}

Expand Down
Loading

0 comments on commit 35c8f96

Please sign in to comment.