inlife: librg stuff:
- check git merge
isolation_bkp/dynres
Dominik Madarász 2021-05-06 23:45:55 +02:00
parent d9bfd072c2
commit f204fbef58
6 changed files with 58 additions and 22 deletions

View File

@ -5,8 +5,8 @@
#include "utils/options.h"
#define DEFAULT_WORLD_SEED 302097
#define DEFAULT_BLOCK_SIZE 64 /* amount of units within a block (single axis) */
#define DEFAULT_CHUNK_SIZE 3 /* amount of blocks within a chunk (single axis) */
#define DEFAULT_BLOCK_SIZE 16 /* amount of units within a block (single axis) */
#define DEFAULT_CHUNK_SIZE 16 /* amount of blocks within a chunk (single axis) */
#define DEFAULT_WORLD_SIZE 8 /* amount of chunks within a world (single axis) */
int main(int argc, char** argv)

View File

@ -5,8 +5,8 @@
#include "entity_view.h"
#include "camera.h"
const uint16_t screenWidth = 800;
const uint16_t screenHeight = 450;
const uint16_t screenWidth = 1600;
const uint16_t screenHeight = 900;
static Camera2D render_camera;
@ -17,7 +17,7 @@ void platform_init() {
render_camera.target = (Vector2){0.0f,0.0f};
render_camera.offset = (Vector2){screenWidth/2.0f, screenHeight/2.0f};
render_camera.rotation = 0.0f;
render_camera.zoom = 1.0f;
render_camera.zoom = 0.3f;
}
void platform_shutdown() {
@ -31,6 +31,7 @@ uint8_t platform_is_running() {
void display_conn_status();
void DEBUG_draw_entities(uint64_t key, entity_view data);
void DEBUG_draw_ground(uint64_t key, entity_view data);
void platform_render() {
camera game_camera = camera_get();
@ -39,6 +40,7 @@ void platform_render() {
BeginDrawing();
ClearBackground(BLACK);
BeginMode2D(render_camera);
entity_view_map(&game_world_view_get_active()->entities, DEBUG_draw_ground);
entity_view_map(&game_world_view_get_active()->entities, DEBUG_draw_entities);
EndMode2D();
display_conn_status();
@ -57,12 +59,34 @@ void display_conn_status() {
}
}
void DEBUG_draw_ground(uint64_t key, entity_view data) {
world_view *view = game_world_view_get_active();
int32_t x = data.x * view->chunk_size * view->block_size;
int32_t y = data.y * view->chunk_size * view->block_size;
int32_t size = view->chunk_size * view->block_size;
int32_t half_size = size/2;
int16_t offset = 10;
switch (data.kind) {
case EKIND_CHUNK: {
DrawRectangle(x+offset-half_size, y+offset-half_size, size-offset, size-offset, GREEN);
char lol[80];
DrawText(TextFormat("%.01f %.01f", data.x, data.y), x-half_size+5, y-half_size+5, 65, BLACK);
}break;
default:break;
}
}
void DEBUG_draw_entities(uint64_t key, entity_view data) {
world_view *view = game_world_view_get_active();
uint16_t size = 100;
switch (data.kind) {
case EKIND_PLAYER: {
DrawCircle(data.x-8.0f, data.y-8.0f, 16.0f, RED);
DrawCircle(data.x, data.y, size, RED);
}break;
default:break;

View File

@ -1,7 +1,7 @@
#pragma once
#include "system.h"
#define PKT_BUFSIZ 4096
#define PKT_BUFSIZ 16384
typedef enum {
MSG_ID_00_INIT,

View File

@ -25,12 +25,16 @@ uint64_t player_spawn(char *name) {
ecs_set(world_ecs(), e, EcsName, {.alloc_value = name });
ecs_set(world_ecs(), e, Input, {0});
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
pos->x = rand()%100;
pos->y = rand()%100;
uint16_t world_dim = world_block_size() * world_chunk_size() * world_world_size();
uint16_t half_world_dim = world_dim / 2;
pos->x=3*32*16;
pos->y=0;
/*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);
librg_entity_radius_set(world_tracker(), e, 2); /* 2 chunk radius visibility */
librg_entity_radius_set(world_tracker(), e, 4);
librg_entity_chunk_set(world_tracker(), e, librg_chunk_from_realpos(world_tracker(), pos->x, pos->y, 0));
return (uint64_t)e;

View File

@ -102,8 +102,8 @@ 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, 1);
librg_config_chunkamount_set(world.tracker, world_size, world_size, 1);
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_chunkoffset_set(world.tracker, LIBRG_OFFSET_MID, LIBRG_OFFSET_MID, 0);
librg_event_set(world.tracker, LIBRG_WRITE_CREATE, tracker_write_create);
@ -124,13 +124,13 @@ int32_t world_init(int32_t seed, uint16_t block_size, uint16_t chunk_size, uint1
for (int i = 0; i < world_size * world_size; ++i) {
ecs_entity_t e = ecs_new(world.ecs, 0);
ecs_set(world.ecs, e, Chunk, {
.x = i % world_size,
.y = i / world_size,
});
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;
librg_chunk chid = librg_chunk_from_chunkpos(world.tracker, chunk->x, chunk->y, 0);
librg_entity_track(world.tracker, e);
librg_entity_chunk_set(world.tracker, e, i);
librg_entity_chunk_set(world.tracker, e, chid);
}
zpl_printf("[INFO] Created a new server world\n");

16
code/vendors/librg.h vendored
View File

@ -19977,6 +19977,11 @@ librg_chunk librg_chunk_from_chunkpos(librg_world *world, int16_t chunk_x, int16
int16_t chx = librg_util_chunkoffset_line(chunk_x, wld->chunkoffset.x, wld->worldsize.x);
int16_t chy = librg_util_chunkoffset_line(chunk_y, wld->chunkoffset.y, wld->worldsize.y);
int16_t chz = librg_util_chunkoffset_line(chunk_z, wld->chunkoffset.z, wld->worldsize.z);
#define kk(aax,aay) (aax > -aay && aax < aay)
#define ll(aax,aay) (aax <= -aay || aax >= aay)
zpl_printf("%d %d\n", chz, wld->worldsize.z);
if (ll(chx, wld->worldsize.x) || ll(chy, wld->worldsize.y) /*|| ll(chz, wld->worldsize.z)*/)
return LIBRG_CHUNK_INVALID;
librg_chunk id = (chz * wld->worldsize.y * wld->worldsize.z) + (chy * wld->worldsize.y) + (chx);
@ -19994,7 +19999,8 @@ int8_t librg_chunk_to_chunkpos(librg_world *world, librg_chunk id, int16_t *chun
if (id < 0 || id > (wld->worldsize.x * wld->worldsize.y * wld->worldsize.z)) {
return LIBRG_CHUNK_INVALID;
}
// TODO(zaklaus): fix ,calc here ok?
int16_t z = (int16_t)(id / (wld->worldsize.z * wld->worldsize.y));
int16_t r1 = (int16_t)(id % (wld->worldsize.z * wld->worldsize.y));
int16_t y = r1 / wld->worldsize.y;
@ -20463,13 +20469,15 @@ int32_t librg_world_fetch_ownerarray(librg_world *world, const int64_t *owner_id
// !
// =======================================================================//
static LIBRG_ALWAYS_INLINE void librg_util_chunkrange(librg_world *w, librg_table_i64 *ch, int cx, int cy, int cz, int8_t radius) {
static LIBRG_ALWAYS_INLINE void librg_util_chunkrange(librg_world_t *w, librg_table_i64 *ch, int cx, int cy, int cz, int8_t radius) {
int radius2 = radius * radius;
zpl_printf("========================\n");
for (int z=-radius; z<=radius; z++) {
for (int y=-radius; y<=radius; y++) {
for (int x=-radius; x<=radius; x++) {
if(x*x+y*y+z*z <= radius2) {
if (kk(x, w->worldsize.x) && kk(y, w->worldsize.y) && kk(z, w->worldsize.z) )
if(x*x+y*y+z*z <= radius2) {
librg_chunk id = librg_chunk_from_chunkpos(w, cx+x, cy+y, cz+z);
if (id != LIBRG_CHUNK_INVALID) librg_table_i64_set(ch, id, 1);
}