world_size -> chunk_amount
parent
ad4167b4f7
commit
57b1193ef1
|
@ -14,9 +14,9 @@ typedef struct {
|
|||
uint32_t height;
|
||||
uint16_t block_size;
|
||||
uint16_t chunk_size;
|
||||
uint16_t world_size;
|
||||
uint16_t chunk_amount;
|
||||
} world_view;
|
||||
|
||||
world_view world_view_create(uint16_t view_id);
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t world_size);
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount);
|
||||
void world_view_destroy(world_view *view);
|
||||
|
|
|
@ -94,7 +94,7 @@ void flecs_dash_init() {
|
|||
ecs_set_target_fps(world_ecs(), 60);
|
||||
}
|
||||
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size, int8_t is_dash_enabled) {
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled) {
|
||||
is_viewer_only = play_mode;
|
||||
platform_init();
|
||||
world_viewers_init(num_viewers);
|
||||
|
@ -108,7 +108,7 @@ void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t bl
|
|||
} else {
|
||||
stdcpp_set_os_api();
|
||||
world_setup_pkt_handlers(pkt_reader, sp_pkt_writer);
|
||||
world_init(seed, block_size, chunk_size, world_size);
|
||||
world_init(seed, block_size, chunk_size, chunk_amount);
|
||||
if (is_dash_enabled) flecs_dash_init();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,18 +43,18 @@ world_view world_view_create(uint16_t view_id) {
|
|||
return view;
|
||||
}
|
||||
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
|
||||
void world_view_init(world_view *view, uint64_t ent_id, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||
view->owner_id = ent_id;
|
||||
view->chunk_size = chunk_size;
|
||||
view->world_size = world_size;
|
||||
view->chunk_amount = chunk_amount;
|
||||
|
||||
view->width = chunk_size * world_size;
|
||||
view->height = chunk_size * world_size;
|
||||
view->width = block_size * chunk_size * chunk_amount;
|
||||
view->height = block_size * chunk_size * chunk_amount;
|
||||
view->block_size = block_size;
|
||||
view->size = view->width * view->height;
|
||||
|
||||
librg_config_chunksize_set(view->tracker, block_size * chunk_size, block_size * chunk_size, 1);
|
||||
librg_config_chunkamount_set(view->tracker, world_size, world_size, 1);
|
||||
librg_config_chunkamount_set(view->tracker, chunk_amount, chunk_amount, 1);
|
||||
librg_config_chunkoffset_set(view->tracker, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, 0);
|
||||
|
||||
librg_event_set(view->tracker, LIBRG_READ_CREATE, tracker_read_create);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "system.h"
|
||||
#include "world_view.h"
|
||||
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size, int8_t is_dash_enabled);
|
||||
void game_init(int8_t play_mode, uint32_t num_viewers, int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount, int8_t is_dash_enabled);
|
||||
void game_shutdown();
|
||||
uint8_t game_is_running();
|
||||
int8_t game_is_networked();
|
||||
|
|
|
@ -33,6 +33,6 @@ int32_t pkt_00_init_handler(pkt_header *header) {
|
|||
uint64_t peer_id = (uint64_t)header->udata;
|
||||
uint64_t ent_id = player_spawn(NULL);
|
||||
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_block_size(), world_chunk_size(), world_world_size());
|
||||
pkt_01_welcome_send(peer_id, header->view_id, ent_id, world_block_size(), world_chunk_size(), world_chunk_amount());
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -30,10 +30,9 @@ uint64_t player_spawn(char *name) {
|
|||
ecs_add(world_ecs(), e, Walking);
|
||||
ecs_add(world_ecs(), e, Player);
|
||||
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
|
||||
uint16_t world_dim = world_block_size() * world_chunk_size() * world_world_size();
|
||||
uint16_t half_world_dim = world_dim / 2;
|
||||
pos->x=rand() % world_dim - half_world_dim;
|
||||
pos->y=rand() % world_dim - half_world_dim;
|
||||
uint16_t half_world_dim = world_dim() / 2;
|
||||
pos->x=rand() % world_dim() - half_world_dim;
|
||||
pos->y=rand() % world_dim() - half_world_dim;
|
||||
|
||||
librg_entity_track(world_tracker(), e);
|
||||
librg_entity_owner_set(world_tracker(), e, (int64_t)e);
|
||||
|
|
|
@ -15,7 +15,7 @@ typedef struct {
|
|||
uint32_t height;
|
||||
uint16_t block_size;
|
||||
uint16_t chunk_size;
|
||||
uint16_t world_size;
|
||||
uint16_t chunk_amount;
|
||||
uint64_t tracker_update;
|
||||
ecs_world_t *ecs;
|
||||
librg_world *tracker;
|
||||
|
@ -77,17 +77,17 @@ void world_setup_pkt_handlers(world_pkt_reader_proc *reader_proc, world_pkt_writ
|
|||
world.writer_proc = writer_proc;
|
||||
}
|
||||
|
||||
int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size) {
|
||||
int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount) {
|
||||
if (world.data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
world.seed = seed;
|
||||
world.chunk_size = chunk_size;
|
||||
world.world_size = world_size;
|
||||
world.chunk_amount = chunk_amount;
|
||||
|
||||
world.width = chunk_size * world_size;
|
||||
world.height = chunk_size * world_size;
|
||||
world.width = chunk_size * chunk_amount;
|
||||
world.height = chunk_size * chunk_amount;
|
||||
world.block_size = block_size;
|
||||
world.size = world.width * world.height;
|
||||
|
||||
|
@ -102,7 +102,7 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
|
|||
|
||||
/* config our world grid */
|
||||
librg_config_chunksize_set(world.tracker, block_size * chunk_size, block_size * chunk_size, 0);
|
||||
librg_config_chunkamount_set(world.tracker, world_size, world_size, 0);
|
||||
librg_config_chunkamount_set(world.tracker, chunk_amount, chunk_amount, 0);
|
||||
librg_config_chunkoffset_set(world.tracker, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, 0);
|
||||
|
||||
librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create);
|
||||
|
@ -121,11 +121,11 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
|
|||
|
||||
ECS_IMPORT(world.ecs, General);
|
||||
|
||||
for (int i = 0; i < world_size * world_size; ++i) {
|
||||
for (int i = 0; i < chunk_amount * chunk_amount; ++i) {
|
||||
ecs_entity_t e = ecs_new(world.ecs, 0);
|
||||
Chunk *chunk = ecs_get_mut(world.ecs, e, Chunk, NULL);
|
||||
chunk->x = i % world_size - world_size/2;
|
||||
chunk->y = i / world_size - world_size/2;
|
||||
chunk->x = i % chunk_amount - chunk_amount/2;
|
||||
chunk->y = i / chunk_amount - chunk_amount/2;
|
||||
|
||||
librg_chunk chid = librg_chunk_from_chunkpos(world.tracker, chunk->x, chunk->y, 0);
|
||||
librg_entity_track(world.tracker, e);
|
||||
|
@ -221,8 +221,12 @@ uint16_t world_chunk_size(void) {
|
|||
return world.chunk_size;
|
||||
}
|
||||
|
||||
uint16_t world_world_size(void) {
|
||||
return world.world_size;
|
||||
uint16_t world_chunk_amount(void) {
|
||||
return world.chunk_amount;
|
||||
}
|
||||
|
||||
uint16_t world_dim(void) {
|
||||
return world.block_size * world.chunk_size * world.chunk_amount;
|
||||
}
|
||||
|
||||
#include "world_gen.c"
|
||||
|
|
|
@ -18,7 +18,7 @@ typedef WORLD_PKT_READER(world_pkt_reader_proc);
|
|||
typedef WORLD_PKT_WRITER(world_pkt_writer_proc);
|
||||
|
||||
void world_setup_pkt_handlers(world_pkt_reader_proc *reader_proc, world_pkt_writer_proc *writer_proc);
|
||||
int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t world_size);
|
||||
int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint16_t chunk_amount);
|
||||
int32_t world_destroy(void);
|
||||
int32_t world_update(void);
|
||||
int32_t world_read(void* data, uint32_t datalen, void *udata);
|
||||
|
@ -30,4 +30,5 @@ librg_world * world_tracker(void);
|
|||
|
||||
uint16_t world_block_size(void);
|
||||
uint16_t world_chunk_size(void);
|
||||
uint16_t world_world_size(void);
|
||||
uint16_t world_chunk_amount(void);
|
||||
uint16_t world_dim(void);
|
||||
|
|
Loading…
Reference in New Issue