]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Merge branch 'master' of github.com:dragonblocks/dragonblocks_alpha
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 17 Jan 2022 11:57:11 +0000 (12:57 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 17 Jan 2022 11:57:11 +0000 (12:57 +0100)
1  2 
src/CMakeLists.txt
src/server/server_map.c
src/util.c
src/util.h

diff --combined src/CMakeLists.txt
index 71daf3eb69f22f66d412a78f3313a3d2483142c4,2cc9ad44c0917917364c1bcbff96d7d045093487..0adb599d915c118d2c7d9ad405172cd39b7a8c32
@@@ -19,6 -19,8 +19,6 @@@ link_libraries
  
  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}
  )
@@@ -27,20 -29,19 +27,30 @@@ include_directories(BEFOR
        ${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
@@@ -89,15 -93,13 +99,15 @@@ target_include_directories(Dragonblock
  )
  
  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
diff --combined src/server/server_map.c
index f7cb57d16d136d0e76621361ca2aa1400eb0a265,4c40931f3de1674777a7db9e2599875abc7e2cf4..a6eb81f4d0b7f5c11486024565af14a08902de82
@@@ -1,4 -1,3 +1,4 @@@
 +#define _GNU_SOURCE
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
@@@ -22,11 -21,7 +22,11 @@@ static void send_block(Client *client, 
  
        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);
  }
  
@@@ -42,7 -37,7 +42,7 @@@ static void send_block_to_near(MapBloc
        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)
@@@ -131,7 -126,7 +131,7 @@@ static void on_create_block(MapBlock *b
                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;
                }
        }
@@@ -220,29 -215,29 +220,29 @@@ static void generate_spawn_hut(
        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);
                }
        }
  
@@@ -374,7 -369,7 +374,7 @@@ void server_map_prepare_spawn(
        } 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;
diff --combined src/util.c
index 56640171f958c2cac5c934c75c4c704ae8e208fa,187eabd122a1d3b456fd667b882eb8902c992118..3836e02bfeb485456b6b275424b2a76749bb3234
@@@ -98,14 -98,14 +98,14 @@@ bool my_decompress(const char *compress
        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)
@@@ -122,32 -122,3 +122,32 @@@ char *format_string(const char *format
        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);
 +}
diff --combined src/util.h
index cdb99657afe8c8eea12fd80f95fa28c847a61bc1,b7d49d80018108795c581689d74ba7d656b706ce..e9ff1218df6efe397ffd8a24c827b154102b4b90
@@@ -6,7 -6,10 +6,10 @@@
  #include <winsock2.h>
  #include <ws2tcpip.h>
  #else
+ #include <sys/types.h>
+ #include <sys/socket.h>
  #include <arpa/inet.h>
+ #include <netinet/in.h>
  #endif
  #include <dragontype/number.h>
  
@@@ -28,7 -31,5 +31,7 @@@ bool my_decompress(const char *compress
  bool within_simulation_distance(v3f64 player_pos, v3s32 block_pos, u32 simulation_distance);                                                          // return true if a player is close enough to a block to access it
  f64 clamp(f64 v, f64 min, f64 max);
  char *format_string(const char *format, ...);
 +void *buffer_read(unsigned char **buffer, size_t *bufsiz, size_t size);
 +void buffer_write(unsigned char **buffer, size_t *bufsiz, void *data, size_t size);
  
  #endif