Skip to content

Commit

Permalink
add missing includes, remove no longer needed map locks
Browse files Browse the repository at this point in the history
Closes #100
Closes #101
  • Loading branch information
xtreme8000 committed Apr 4, 2020
1 parent 85f4bf6 commit f970167
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
12 changes: 11 additions & 1 deletion src/file.c
Expand Up @@ -21,6 +21,9 @@
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

#include "common.h"
#include "log.h"
Expand All @@ -31,7 +34,10 @@ struct file_handle {
int type;
};

enum { FILE_STD, FILE_SDL };
enum {
FILE_STD,
FILE_SDL,
};

void file_url(char* url) {
char cmd[strlen(url) + 16];
Expand Down Expand Up @@ -63,7 +69,11 @@ int file_dir_exists(const char* path) {

int file_dir_create(const char* path) {
#ifndef USE_ANDROID_FILE
#ifdef OS_WINDOWS
mkdir(path);
#else
mkdir(path, 0755);
#endif
#else
char str[256];
sprintf(str, "/sdcard/BetterSpades/%s", path);
Expand Down
2 changes: 2 additions & 0 deletions src/http.c
Expand Up @@ -23,4 +23,6 @@
#define _WIN32_WINNT 0x0501
#endif

#include <stdint.h>

#include "http.h"
21 changes: 1 addition & 20 deletions src/map.c
Expand Up @@ -19,7 +19,6 @@

#include <stdlib.h>
#include <math.h>
#include <pthread.h>
#include <string.h>
#include <stdint.h>

Expand All @@ -36,8 +35,6 @@
#include "particle.h"
#include "minheap.h"

pthread_rwlock_t map_lock;

uint8_t* map_heights;
int map_size_x = 512;
int map_size_y = 64;
Expand Down Expand Up @@ -657,42 +654,32 @@ float map_sunblock(int x, int y, int z) {

void map_init() {
libvxl_create(&map, 512, 512, 64, NULL, 0);
pthread_rwlock_init(&map_lock, NULL);
}

int map_height_at(int x, int z) {
int result[2];
pthread_rwlock_rdlock(&map_lock);
libvxl_map_gettop(&map, x, z, result);
pthread_rwlock_unlock(&map_lock);
return map_size_y - 1 - result[1];
}

int map_isair(int x, int y, int z) {
pthread_rwlock_rdlock(&map_lock);
int result = libvxl_map_issolid(&map, x, z, map_size_y - 1 - y);
pthread_rwlock_unlock(&map_lock);
return !result;
return !libvxl_map_issolid(&map, x, z, map_size_y - 1 - y);
}

unsigned int map_get(int x, int y, int z) {
pthread_rwlock_rdlock(&map_lock);
unsigned int result = libvxl_map_get(&map, x, z, map_size_y - 1 - y);
pthread_rwlock_unlock(&map_lock);
return rgb2bgr(result);
}

void map_set(int x, int y, int z, unsigned int color) {
if(x < 0 || y < 0 || z < 0 || x >= map_size_x || y >= map_size_y || z >= map_size_z)
return;

pthread_rwlock_wrlock(&map_lock);
if(color == 0xFFFFFFFF) {
libvxl_map_setair(&map, x, z, map_size_y - 1 - y);
} else {
libvxl_map_set(&map, x, z, map_size_y - 1 - y, rgb2bgr(color));
}
pthread_rwlock_unlock(&map_lock);

chunk_block_update(x, y, z);

Expand Down Expand Up @@ -848,21 +835,17 @@ int map_placedblock_color(int color) {
}

void map_vxl_load(void* v, size_t size) {
pthread_rwlock_wrlock(&map_lock);
libvxl_free(&map);
libvxl_create(&map, 512, 512, 64, v, size);
pthread_rwlock_unlock(&map_lock);
}

struct libvxl_block* map_copy_blocks(int chunk_x, int chunk_y, uint32_t* count) {
struct libvxl_chunk* chunk
= map.chunks + chunk_x + chunk_y * ((map_size_x + LIBVXL_CHUNK_SIZE - 1) / LIBVXL_CHUNK_SIZE);

pthread_rwlock_rdlock(&map_lock);
struct libvxl_block* blocks = malloc(chunk->index * sizeof(struct libvxl_block));
CHECK_ALLOCATION_ERROR(blocks)
memcpy(blocks, chunk->blocks, chunk->index * sizeof(struct libvxl_block));
pthread_rwlock_unlock(&map_lock);

if(count)
*count = chunk->index;
Expand All @@ -871,13 +854,11 @@ struct libvxl_block* map_copy_blocks(int chunk_x, int chunk_y, uint32_t* count)
}

uint32_t* map_copy_solids() {
pthread_rwlock_rdlock(&map_lock);
size_t sg
= (map.width * map.height * map.depth + (sizeof(uint32_t) * 8 - 1)) / (sizeof(uint32_t) * 8) * sizeof(uint32_t);
uint32_t* blocks = malloc(sg);
CHECK_ALLOCATION_ERROR(blocks)
memcpy(blocks, map.geometry, sg);
pthread_rwlock_unlock(&map_lock);

return blocks;
}
1 change: 1 addition & 0 deletions src/network.c
Expand Up @@ -19,6 +19,7 @@

#include <enet/enet.h>
#include <math.h>
#include <string.h>

#include "libdeflate.h"
#include "texture.h"
Expand Down
1 change: 1 addition & 0 deletions src/ping.c
Expand Up @@ -21,6 +21,7 @@
#include <pthread.h>
#include <math.h>
#include <unistd.h>
#include <string.h>

#include "window.h"
#include "ping.h"
Expand Down
8 changes: 3 additions & 5 deletions src/tracer.c
Expand Up @@ -41,14 +41,12 @@ void tracer_pvelocity(float* o, struct Player* p) {
}

static void tracer_minimap_single(struct Tracer* t, int large, float scalef, float minimap_x, float minimap_y) {
if(large) {
if(t->used) {
if(t->used) {
if(large) {
float ang = -atan2(t->r.direction.z, t->r.direction.x) - HALFPI;
texture_draw_rotated(&texture_tracer, minimap_x + t->r.origin.x * scalef,
minimap_y - t->r.origin.z * scalef, 15 * scalef, 15 * scalef, ang);
}
} else {
if(t->used) {
} else {
float tracer_x = t->r.origin.x - minimap_x;
float tracer_y = t->r.origin.z - minimap_y;
if(tracer_x > 0.0F && tracer_x < 128.0F && tracer_y > 0.0F && tracer_y < 128.0F) {
Expand Down

0 comments on commit f970167

Please sign in to comment.