set(DEPS_DIR "${CMAKE_SOURCE_DIR}/../deps/")
-add_compile_definitions(DRAGONTYPE_ENDIAN_HEADER="${CMAKE_SOURCE_DIR}/../deps/endian.h/endian.h")
-
include_directories(SYSTEM
${DEPS_DIR}
)
${CMAKE_SOURCE_DIR}
)
- add_compile_options(-Wall -Wextra -Wpedantic -Werror -fmax-errors=4)
+ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
+ link_directories("/usr/local/lib")
+ include_directories("/usr/local/include")
+ endif()
+
+ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
+ link_directories("/usr/X11R6/lib")
+ include_directories("/usr/X11R6/include")
+ endif()
+
+ add_compile_options(-Wall -Wextra -Wpedantic -Werror)
-set(SOURCES_COMMON
+set(DEPS_SOURCES
+ "${DEPS_DIR}/dragontype/array.c"
+ "${DEPS_DIR}/dragontype/bintree.c"
+ "${DEPS_DIR}/dragontype/list.c"
+ "${DEPS_DIR}/dragontype/number.c"
+ "${DEPS_DIR}/dragontype/queue.c"
+ "${DEPS_DIR}/dragonport/asprintf.c"
+ "${DEPS_DIR}/perlin/perlin.c"
+)
+
+set(COMMON_SOURCES
+ ${DEPS_SOURCES}
day.c
environment.c
map.c
perlin.c
signal_handlers.c
util.c
- "${DEPS_DIR}/dragontype/implementation.c"
- "${DEPS_DIR}/dragonport/asprintf.c"
- "${DEPS_DIR}/perlin/perlin.c"
)
add_executable(Dragonblocks
- ${SOURCES_COMMON}
+ ${COMMON_SOURCES}
client/blockmesh.c
client/camera.c
client/client.c
)
add_executable(DragonblocksServer
- ${SOURCES_COMMON}
+ ${COMMON_SOURCES}
server/biomes.c
server/database.c
server/mapgen.c
server/server.c
server/server_commands.c
server/server_map.c
+ server/trees.c
+ server/voxelctx.c
)
target_link_libraries(DragonblocksServer
+#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
pthread_mutex_lock(&client->mtx);
if (client->state == CS_ACTIVE)
- (void) (write_u32(client->fd, CC_BLOCK) && write_v3s32(client->fd, block->pos) && write_u64(client->fd, extra->size) && write(client->fd, extra->data, extra->size) != -1);
+ (void) (write_u32(client->fd, CC_BLOCK)
+ && write_v3s32(client->fd, block->pos)
+ && write_u64(client->fd, extra->size)
+ && write_u64(client->fd, extra->rawsize)
+ && write(client->fd, extra->data, extra->size) != -1);
pthread_mutex_unlock(&client->mtx);
}
if (extra->data)
free(extra->data);
- map_serialize_block(block, &extra->data, &extra->size);
+ map_serialize_block(block, &extra->data, &extra->size, &extra->rawsize);
database_save_block(block);
if (extra->state == MBS_CREATED)
extra->data = NULL;
ITERATE_MAPBLOCK {
- block->data[x][y][z] = map_node_create(NODE_AIR);
+ block->data[x][y][z] = map_node_create(NODE_AIR, NULL, 0);
extra->mgs_buffer[x][y][z] = MGS_VOID;
}
}
for (s32 x = -4; x <= +4; x++) {
for (s32 y = 0; y <= 3; y++) {
for (s32 z = -3; z <= +2; z++) {
- mapgen_set_node((v3s32) {x, server_map.spawn_height + y, z}, (MapNode) {NODE_AIR}, MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {x, server_map.spawn_height + y, z}, map_node_create(NODE_AIR, NULL, 0), MGS_PLAYER, &changed_blocks);
}
}
}
for (s32 x = -5; x <= +5; x++) {
for (s32 z = -4; z <= +3; z++) {
- mapgen_set_node((v3s32) {x, server_map.spawn_height - 1, z}, (MapNode) {NODE_WOOD}, MGS_PLAYER, &changed_blocks);
- mapgen_set_node((v3s32) {x, server_map.spawn_height + 4, z}, (MapNode) {NODE_WOOD}, MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {x, server_map.spawn_height - 1, z}, map_node_create(NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {x, server_map.spawn_height + 4, z}, map_node_create(NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
}
}
for (s32 y = 0; y <= 3; y++) {
for (s32 x = -5; x <= +5; x++) {
- mapgen_set_node((v3s32) {x, server_map.spawn_height + y, -4}, (MapNode) {((y == 1 || y == 2) && ((x >= -3 && x <= -1) || (x >= +1 && x <= +2))) ? NODE_AIR : NODE_WOOD}, MGS_PLAYER, &changed_blocks);
- mapgen_set_node((v3s32) {x, server_map.spawn_height + y, +3}, (MapNode) {((y == 1 || y == 2) && ((x >= -3 && x <= -2) || (x >= +1 && x <= +3))) ? NODE_AIR : NODE_WOOD}, MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {x, server_map.spawn_height + y, -4}, map_node_create(((y == 1 || y == 2) && ((x >= -3 && x <= -1) || (x >= +1 && x <= +2))) ? NODE_AIR : NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {x, server_map.spawn_height + y, +3}, map_node_create(((y == 1 || y == 2) && ((x >= -3 && x <= -2) || (x >= +1 && x <= +3))) ? NODE_AIR : NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
}
}
for (s32 y = 0; y <= 3; y++) {
for (s32 z = -3; z <= +2; z++) {
- mapgen_set_node((v3s32) {-5, server_map.spawn_height + y, z}, (MapNode) {NODE_WOOD}, MGS_PLAYER, &changed_blocks);
- mapgen_set_node((v3s32) {+5, server_map.spawn_height + y, z}, (MapNode) {((y != 3) && (z == -1 || z == +0)) ? NODE_AIR : NODE_WOOD}, MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {-5, server_map.spawn_height + y, z}, map_node_create(NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
+ mapgen_set_node((v3s32) {+5, server_map.spawn_height + y, z}, map_node_create(((y != 3) && (z == -1 || z == +0)) ? NODE_AIR : NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
}
}
if (node_definitions[node].solid)
break;
- mapgen_set_node(pos, (MapNode) {node == NODE_LAVA ? NODE_VULCANO_STONE : NODE_WOOD}, MGS_PLAYER, &changed_blocks);
+ mapgen_set_node(pos, map_node_create(node == NODE_LAVA ? NODE_VULCANO_STONE : NODE_OAK_WOOD, NULL, 0), MGS_PLAYER, &changed_blocks);
}
}
} else {
s32 spawn_height = -1;
- while (map_get_node(server_map.map, (v3s32) {0, ++spawn_height, 0}).type != NODE_AIR);
+ while (map_get_node(server_map.map, (v3s32) {0, ++spawn_height, 0}).type != NODE_AIR)
;
server_map.spawn_height = spawn_height + 5;
inflate(&stream, Z_NO_FLUSH);
inflateEnd(&stream);
- return stream.total_out == expected_decompressed_size;
+ return (size_t) stream.total_out == expected_decompressed_size;
}
// return true if a player is close enough to a block to access it
bool within_simulation_distance(v3f64 player_pos, v3s32 block_pos, u32 simulation_distance)
{
v3s32 player_block_pos = map_node_to_block_pos((v3s32) {player_pos.x, player_pos.y, player_pos.z}, NULL);
- return abs(player_block_pos.x - block_pos.x) <= simulation_distance && abs(player_block_pos.y - block_pos.y) <= simulation_distance && abs(player_block_pos.z - block_pos.z) <= simulation_distance;
+ return abs(player_block_pos.x - block_pos.x) <= (s32) simulation_distance && abs(player_block_pos.y - block_pos.y) <= (s32) simulation_distance && abs(player_block_pos.z - block_pos.z) <= (s32) simulation_distance;
}
f64 clamp(f64 v, f64 min, f64 max)
va_end(args);
return ptr;
}
+
+void *buffer_read(unsigned char **buffer, size_t *bufsiz, size_t size)
+{
+ if (size == 0)
+ return NULL;
+
+ if (*bufsiz < size)
+ return NULL;
+
+ void *old_buffer = *buffer;
+
+ *bufsiz -= size;
+ *buffer += size;
+
+ return old_buffer;
+}
+
+void buffer_write(unsigned char **buffer, size_t *bufsiz, void *data, size_t size)
+{
+ if (size == 0)
+ return;
+
+ size_t old_bufsiz = *bufsiz;
+
+ *bufsiz += size;
+ *buffer = realloc(*buffer, *bufsiz);
+
+ memcpy(*buffer + old_bufsiz, data, size);
+}