Skip to content

Commit

Permalink
See desc
Browse files Browse the repository at this point in the history
* improved string length checks for serverlist/ping
* order transparent falling block structures by depth
* remove polygon offset from block damage renderer
  • Loading branch information
xtreme8000 committed Jun 1, 2019
1 parent 962e028 commit 950a54c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/hud.c
Expand Up @@ -2143,11 +2143,11 @@ static void hud_serverlist_render(float scalex, float scaley) {
serverlist[k].max = (int)json_object_get_number(s,"players_max");
serverlist[k].ping = -1;

strncpy(serverlist[k].name,json_object_get_string(s,"name"),31);
strncpy(serverlist[k].map,json_object_get_string(s,"map"),20);
strncpy(serverlist[k].gamemode,json_object_get_string(s,"game_mode"),7);
strncpy(serverlist[k].identifier,json_object_get_string(s,"identifier"),31);
strncpy(serverlist[k].country,json_object_get_string(s,"country"),3);
strncpy(serverlist[k].name,json_object_get_string(s,"name"),sizeof(serverlist[k].name)-1);
strncpy(serverlist[k].map,json_object_get_string(s,"map"),sizeof(serverlist[k].map)-1);
strncpy(serverlist[k].gamemode,json_object_get_string(s,"game_mode"),sizeof(serverlist[k].gamemode)-1);
strncpy(serverlist[k].identifier,json_object_get_string(s,"identifier"),sizeof(serverlist[k].identifier)-1);
strncpy(serverlist[k].country,json_object_get_string(s,"country"),sizeof(serverlist[k].country)-1);

int port;
char ip[32];
Expand Down
28 changes: 23 additions & 5 deletions src/map.c
Expand Up @@ -93,8 +93,9 @@ static void push_char46(unsigned char* buffer, int* index, int r, int g, int b,
void map_damaged_voxels_render() {
matrix_identity();
matrix_upload();
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0.0F,-100.0F);
//glEnable(GL_POLYGON_OFFSET_FILL);
//glPolygonOffset(0.0F,-100.0F);
glDepthFunc(GL_EQUAL);
glEnable(GL_BLEND);
for(int k=0;k<8;k++) {
if(map_get(map_damaged_voxels[k].x,map_damaged_voxels[k].y,map_damaged_voxels[k].z)==0xFFFFFFFF) {
Expand Down Expand Up @@ -163,9 +164,10 @@ void map_damaged_voxels_render() {
}
}
}
glDepthFunc(GL_LEQUAL);
glDisable(GL_BLEND);
glPolygonOffset(0.0F,0.0F);
glDisable(GL_POLYGON_OFFSET_FILL);
//glPolygonOffset(0.0F,0.0F);
//glDisable(GL_POLYGON_OFFSET_FILL);
}

struct voxel {
Expand All @@ -180,7 +182,7 @@ static char stack_contains(struct voxel* stack2, int len, int x, int y, int z) {
return 0;
}

static struct {
static struct map_collapsing {
struct voxel* voxels;
unsigned int* voxels_color;
int voxel_count;
Expand Down Expand Up @@ -355,7 +357,20 @@ static void map_update_physics_sub(int x, int y, int z) {
}
}

int map_collapsing_cmp(const void* a, const void *b) {
struct map_collapsing* A = (struct map_collapsing*)a;
struct map_collapsing* B = (struct map_collapsing*)b;
if(A->used && !B->used)
return -1;
if(!A->used && B->used)
return 1;
return distance3D(B->p.x,B->p.y,B->p.z,camera_x,camera_y,camera_z)
-distance3D(A->p.x,A->p.y,A->p.z,camera_x,camera_y,camera_z);
}

void map_collapsing_render(float dt) {
qsort(map_collapsing_structures,32,sizeof(struct map_collapsing),map_collapsing_cmp);

glEnable(GL_BLEND);
for(int k=0;k<32;k++) {
if(map_collapsing_structures[k].used) {
Expand Down Expand Up @@ -542,6 +557,9 @@ void map_collapsing_render(float dt) {
free(colors);
free(vertices);
}
glColorMask(0,0,0,0);
glx_displaylist_draw(&map_collapsing_structures[k].displaylist,GLX_DISPLAYLIST_ENHANCED);
glColorMask(1,1,1,1);
glx_displaylist_draw(&map_collapsing_structures[k].displaylist,GLX_DISPLAYLIST_ENHANCED);

if(absf(map_collapsing_structures[k].v.y)<0.1F && hit_floor) {
Expand Down
8 changes: 4 additions & 4 deletions src/ping.c
Expand Up @@ -117,13 +117,13 @@ void* ping_update(void* data) {

strcpy(e.country,"LAN");
e.ping = ceil((window_time()-ping_start)*1000.0F);
sprintf(e.identifier,"aos://%i:%i",from.host,from.port);
snprintf(e.identifier,sizeof(e.identifier)-1,"aos://%i:%i",from.host,from.port);

JSON_Value* js = json_parse_string(tmp);
JSON_Object* root = json_value_get_object(js);
strcpy(e.name,json_object_get_string(root,"name"));
strcpy(e.gamemode,json_object_get_string(root,"game_mode"));
strcpy(e.map,json_object_get_string(root,"map"));
strncpy(e.name,json_object_get_string(root,"name"),sizeof(e.name)-1);
strncpy(e.gamemode,json_object_get_string(root,"game_mode"),sizeof(e.gamemode)-1);
strncpy(e.map,json_object_get_string(root,"map"),sizeof(e.map)-1);
e.current = json_object_get_number(root,"players_current");
e.max = json_object_get_number(root,"players_max");
json_value_free(js);
Expand Down

0 comments on commit 950a54c

Please sign in to comment.