improve chunk baking
parent
b45ed4fa75
commit
6cfed15e8b
|
@ -34,6 +34,6 @@ int32_t pkt_00_init_handler(pkt_header *header) {
|
||||||
uint64_t peer_id = (uint64_t)header->udata;
|
uint64_t peer_id = (uint64_t)header->udata;
|
||||||
uint64_t ent_id = player_spawn(NULL);
|
uint64_t ent_id = player_spawn(NULL);
|
||||||
ecs_set(world_ecs(), ent_id, ClientInfo, {.peer = ent_id, .view_id = header->view_id });
|
ecs_set(world_ecs(), ent_id, ClientInfo, {.peer = ent_id, .view_id = header->view_id });
|
||||||
pkt_01_welcome_send(peer_id, header->view_id, ent_id, world_chunk_size(), world_chunk_amount());
|
pkt_01_welcome_send(world_seed(), peer_id, header->view_id, ent_id, world_chunk_size(), world_chunk_amount());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
||||||
pkt_desc pkt_01_welcome_desc[] = {
|
pkt_desc pkt_01_welcome_desc[] = {
|
||||||
|
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, seed) },
|
||||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, ent_id) },
|
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, ent_id) },
|
||||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
|
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, chunk_size) },
|
||||||
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, world_size) },
|
{ PKT_FIELD(CWP_ITEM_POSITIVE_INTEGER, pkt_01_welcome, world_size) },
|
||||||
|
@ -18,12 +19,13 @@ size_t pkt_01_welcome_encode(pkt_01_welcome *table) {
|
||||||
pkt_pack_struct(&pc, pkt_01_welcome_desc, PKT_STRUCT_PTR(table));
|
pkt_pack_struct(&pc, pkt_01_welcome_desc, PKT_STRUCT_PTR(table));
|
||||||
return pkt_pack_msg_size(&pc);
|
return pkt_pack_msg_size(&pc);
|
||||||
}
|
}
|
||||||
size_t pkt_01_welcome_send(uint64_t peer_id,
|
size_t pkt_01_welcome_send(uint32_t seed,
|
||||||
|
uint64_t peer_id,
|
||||||
uint16_t view_id,
|
uint16_t view_id,
|
||||||
uint64_t ent_id,
|
uint64_t ent_id,
|
||||||
uint16_t chunk_size,
|
uint16_t chunk_size,
|
||||||
uint16_t world_size) {
|
uint16_t world_size) {
|
||||||
pkt_01_welcome table = {.ent_id = ent_id, .chunk_size = chunk_size, .world_size = world_size};
|
pkt_01_welcome table = {.seed = seed, .ent_id = ent_id, .chunk_size = chunk_size, .world_size = world_size};
|
||||||
return pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, view_id, (void*)peer_id);
|
return pkt_world_write(MSG_ID_01_WELCOME, pkt_01_welcome_encode(&table), 1, view_id, (void*)peer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +36,7 @@ int32_t pkt_01_welcome_handler(pkt_header *header) {
|
||||||
world_view *view = game_world_view_get(header->view_id);
|
world_view *view = game_world_view_get(header->view_id);
|
||||||
|
|
||||||
zpl_printf("[INFO] initializing read-only world view ...\n");
|
zpl_printf("[INFO] initializing read-only world view ...\n");
|
||||||
world_view_init(view, table.ent_id, table.chunk_size, table.world_size);
|
world_view_init(view, table.seed, table.ent_id, table.chunk_size, table.world_size);
|
||||||
game_world_view_set_active(view);
|
game_world_view_set_active(view);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
#include "packet_utils.h"
|
#include "packet_utils.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
uint32_t seed;
|
||||||
uint64_t ent_id;
|
uint64_t ent_id;
|
||||||
uint16_t chunk_size;
|
uint16_t chunk_size;
|
||||||
uint16_t world_size;
|
uint16_t world_size;
|
||||||
} pkt_01_welcome;
|
} pkt_01_welcome;
|
||||||
|
|
||||||
size_t pkt_01_welcome_send(uint64_t peer_id,
|
size_t pkt_01_welcome_send(uint32_t seed,
|
||||||
|
uint64_t peer_id,
|
||||||
uint16_t view_id,
|
uint16_t view_id,
|
||||||
uint64_t ent_id,
|
uint64_t ent_id,
|
||||||
uint16_t chunk_size,
|
uint16_t chunk_size,
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "gen/texgen.h"
|
#include "gen/texgen.h"
|
||||||
#include "world_view.h"
|
#include "world_view.h"
|
||||||
|
#include "perlin.h"
|
||||||
|
|
||||||
#define BLOCKS_COUNT (sizeof(blocks)/sizeof(block))
|
#define BLOCKS_COUNT (sizeof(blocks)/sizeof(block))
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ void blocks_build_chunk_tex(uint64_t id, uint8_t *chunk_blocks, uint8_t *outer_c
|
||||||
DrawTexturePro(blk, src, dst, (Vector2){0.0f,0.0f}, 0.0f, WHITE);
|
DrawTexturePro(blk, src, dst, (Vector2){0.0f,0.0f}, 0.0f, WHITE);
|
||||||
#else
|
#else
|
||||||
static float rots[] = { 0.0f, 90.0f, 180.f, 270.0f };
|
static float rots[] = { 0.0f, 90.0f, 180.f, 270.0f };
|
||||||
float rot = rots[rand() % 4];
|
float rot = rots[(int32_t)(perlin_fbm(view->seed, x, y, 1.2f, 3) * 4.0f) % 4];
|
||||||
float half_block = WORLD_BLOCK_SIZE / 2.0f;
|
float half_block = WORLD_BLOCK_SIZE / 2.0f;
|
||||||
Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img;
|
Texture2D blk = blocks[chunk_blocks[(y*view->chunk_size)+x]].img;
|
||||||
Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
Rectangle src = {0, 0, WORLD_BLOCK_SIZE, WORLD_BLOCK_SIZE};
|
||||||
|
|
|
@ -318,6 +318,10 @@ uint32_t world_buf(uint8_t const **ptr, uint32_t *width) {
|
||||||
return world.size;
|
return world.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t world_seed(void) {
|
||||||
|
return world.seed;
|
||||||
|
}
|
||||||
|
|
||||||
ecs_world_t * world_ecs() {
|
ecs_world_t * world_ecs() {
|
||||||
if (world.ecs_stage != NULL) {
|
if (world.ecs_stage != NULL) {
|
||||||
return world.ecs_stage;
|
return world.ecs_stage;
|
||||||
|
|
|
@ -55,6 +55,7 @@ int32_t world_read(void* data, uint32_t datalen, void *udata);
|
||||||
int32_t world_write(pkt_header *pkt, void *udata);
|
int32_t world_write(pkt_header *pkt, void *udata);
|
||||||
|
|
||||||
uint32_t world_buf(uint8_t const **ptr, uint32_t *width);
|
uint32_t world_buf(uint8_t const **ptr, uint32_t *width);
|
||||||
|
uint32_t world_seed(void);
|
||||||
ecs_world_t *world_ecs(void);
|
ecs_world_t *world_ecs(void);
|
||||||
void world_set_stage(ecs_world_t *ecs);
|
void world_set_stage(ecs_world_t *ecs);
|
||||||
librg_world *world_tracker(void);
|
librg_world *world_tracker(void);
|
||||||
|
|
|
@ -75,7 +75,8 @@ world_view world_view_create(uint16_t view_id) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t chunk_size, uint16_t chunk_amount) {
|
void world_view_init(world_view *view, uint32_t seed, uint64_t ent_id, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||||
|
view->seed = seed;
|
||||||
view->owner_id = ent_id;
|
view->owner_id = ent_id;
|
||||||
view->chunk_size = chunk_size;
|
view->chunk_size = chunk_size;
|
||||||
view->chunk_amount = chunk_amount;
|
view->chunk_amount = chunk_amount;
|
||||||
|
|
|
@ -9,6 +9,7 @@ typedef struct {
|
||||||
entity_view_tbl entities;
|
entity_view_tbl entities;
|
||||||
librg_world *tracker;
|
librg_world *tracker;
|
||||||
|
|
||||||
|
uint32_t seed;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t dim;
|
uint32_t dim;
|
||||||
uint16_t chunk_size;
|
uint16_t chunk_size;
|
||||||
|
@ -21,5 +22,5 @@ typedef struct {
|
||||||
} world_view;
|
} world_view;
|
||||||
|
|
||||||
world_view world_view_create(uint16_t view_id);
|
world_view world_view_create(uint16_t view_id);
|
||||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t chunk_size, uint16_t chunk_amount);
|
void world_view_init(world_view *view, uint32_t seed, uint64_t ent_id, uint16_t chunk_size, uint16_t chunk_amount);
|
||||||
void world_view_destroy(world_view *view);
|
void world_view_destroy(world_view *view);
|
||||||
|
|
Loading…
Reference in New Issue