code: various improvements

isolation_bkp/dynres
Dominik Madarász 2021-08-11 00:02:11 +02:00
parent 401edb98c9
commit f74b66e7b4
13 changed files with 16787 additions and 16744 deletions

BIN
art/showcase.dem 100644

Binary file not shown.

View File

@ -32,7 +32,7 @@ static ecs_entity_t *temp_actors = NULL;
#define REPLAY_VERSION 2
static char replay_filename[1024] = {0};
static char replaybuf[UINT16_MAX];
static char replaybuf[sizeof(replay_record)*UINT16_MAX + 32];
void debug_replay_store(void) {
assert(replay_filename[0]);

View File

@ -86,8 +86,8 @@ static int UIMeasureText(const char *text, int fontSize);
#include "debug_replay.c"
#include "debug_ui_widgets.c"
#include "debug_ui_actions.c"
#include "debug_ui_widgets.c"
static debug_item items[] = {
{
@ -109,6 +109,19 @@ static debug_item items[] = {
.list = {
.items = (debug_item[]) {
{ .kind = DITEM_BUTTON, .name = "spawn car", .on_click = ActSpawnCar },
{
.kind = DITEM_LIST,
.name = "demo npcs",
.list = {
.items = (debug_item[]) {
{ .kind = DITEM_TEXT, .name = "npcs", .proc = DrawDemoNPCCount },
{ .kind = DITEM_BUTTON, .name = "spawn 1000 npcs", .on_click = ActSpawnDemoNPCs },
{ .kind = DITEM_BUTTON, .name = "remove all demo npcs", .on_click = ActDespawnDemoNPCs },
{ .kind = DITEM_END },
},
.is_collapsed = true
}
},
{ .kind = DITEM_END },
}
}

View File

@ -112,3 +112,37 @@ ActReplayLoad(void) {
}
}
// NOTE(zaklaus): Demo NPCs
static ecs_entity_t *demo_npcs = NULL;
static inline void
ActSpawnDemoNPCs(void) {
if (!demo_npcs) zpl_array_init(demo_npcs, zpl_heap());
if (zpl_array_count(demo_npcs) >= 10000) return;
for (uint32_t i = 0; i < 1000; i++) {
uint64_t e = entity_spawn(EKIND_DEMO_NPC);
ecs_add(world_ecs(), e, EcsDemoNPC);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
pos->x=rand() % world_dim();
pos->y=rand() % world_dim();
Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL);
v->x = (rand()%3-1) * 100;
v->y = (rand()%3-1) * 100;
zpl_array_append(demo_npcs, e);
}
}
static inline void
ActDespawnDemoNPCs(void) {
if (!demo_npcs) return;
for (uint32_t i = 0; i < zpl_array_count(demo_npcs); i++) {
entity_despawn(demo_npcs[i]);
}
zpl_array_free(demo_npcs);
demo_npcs = 0;
}

View File

@ -76,3 +76,11 @@ DrawReplayFileName(debug_item *it, float xpos, float ypos) {
(void)it;
return DrawFormattedText(xpos, ypos, TextFormat("%s", replay_filename[0] ? replay_filename : "<unnamed>"));
}
// NOTE(zaklaus): demo npcs
static inline debug_draw_result
DrawDemoNPCCount(debug_item *it, float xpos, float ypos) {
(void)it;
return DrawFormattedText(xpos, ypos, TextFormat("%d", demo_npcs ? zpl_array_count(demo_npcs) : 0));
}

View File

@ -33,7 +33,6 @@ int main(int argc, char** argv) {
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
//zpl_opts_add(&opts, "cs", "chunk-size", "amount of blocks within a chunk (single axis)", ZPL_OPTS_INT);
zpl_opts_add(&opts, "ws", "world-size", "amount of chunks within a world (single axis)", ZPL_OPTS_INT);
zpl_opts_add(&opts, "n", "npc-count", "amount of demo npcs to spawn", ZPL_OPTS_INT);
uint32_t ok = zpl_opts_compile(&opts, argc, argv);
@ -49,7 +48,6 @@ int main(int argc, char** argv) {
uint16_t num_viewers = zpl_opts_integer(&opts, "viewer-count", 1);
uint16_t chunk_size = DEFAULT_CHUNK_SIZE; //zpl_opts_integer(&opts, "chunk-size", DEFAULT_CHUNK_SIZE);
uint16_t world_size = zpl_opts_integer(&opts, "world-size", DEFAULT_WORLD_SIZE);
uint32_t npc_count = zpl_opts_integer(&opts, "npc-count", 1000);
if (zpl_opts_has_arg(&opts, "random-seed")) {
zpl_random rnd={0};
@ -66,23 +64,6 @@ int main(int argc, char** argv) {
sighandler_register();
game_init(is_viewer_only, num_viewers, seed, chunk_size, world_size, is_dash_enabled);
// TODO(zaklaus): VERY TEMPORARY -- SPAWN SOME NPCS THAT RANDOMLY MOVE
#if 1
{
for (uint32_t i = 0; i < npc_count; i++) {
uint64_t e = entity_spawn(EKIND_DEMO_NPC);
ecs_add(world_ecs(), e, EcsDemoNPC);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
pos->x=rand() % world_dim();
pos->y=rand() % world_dim();
Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL);
v->x = (rand()%3-1) * 100;
v->y = (rand()%3-1) * 100;
}
}
#endif
while (game_is_running()) {
profile (PROF_MAIN_LOOP) {
game_input();

View File

@ -26,6 +26,7 @@ static Camera2D render_camera;
void platform_init() {
InitWindow(screenWidth, screenHeight, "eco2d - client");
SetWindowState(FLAG_WINDOW_UNDECORATED|FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE);
SetTargetFPS(0);
screenWidth = GetScreenWidth();

View File

@ -51,8 +51,8 @@ entity_view world_build_entity_view(int64_t e) {
view.heading = veh->heading;
}
if (ecs_get(world_ecs(), e, Chunk)) {
Chunk *chpos = ecs_get_mut(world_ecs(), e, Chunk, 0);
Chunk *chpos = 0;
if ((chpos = ecs_get_mut_if(world_ecs(), e, Chunk))) {
view.x = chpos->x;
view.y = chpos->y;
view.blocks_used = 1;

View File

@ -15,9 +15,9 @@
#define WORLD_LAYERING 0
#define WORLD_TRACKER_LAYERS 3
#define WORLD_TRACKER_UPDATE_FAST_MS 100
#define WORLD_TRACKER_UPDATE_NORMAL_MS 500
#define WORLD_TRACKER_UPDATE_SLOW_MS 1000
#define WORLD_TRACKER_UPDATE_FAST_MS 10
#define WORLD_TRACKER_UPDATE_NORMAL_MS 50
#define WORLD_TRACKER_UPDATE_SLOW_MS 100
#define WORLD_BLOCK_SIZE 64
#define WORLD_PKT_READER(name) int32_t name(void* data, uint32_t datalen, void *udata)

View File

@ -19,14 +19,6 @@ ECS_TYPE_DECLARE(Walking);
ECS_TYPE_DECLARE(Flying);
ECS_TYPE_DECLARE(EcsClient);
// NOTE(zaklaus): custom macro to define meta components outside the current scope
#ifndef ECS_META_DEFINE
#define ECS_META_DEFINE(world, T)\
ECS_COMPONENT_DEFINE(world, T);\
ecs_new_meta(world, ecs_entity(T), &__##T##__);
#endif
void ComponentsImport(ecs_world_t *ecs) {
ECS_MODULE(ecs, Components);
ECS_IMPORT(ecs, FlecsMeta);

View File

@ -2,6 +2,20 @@
#include "flecs/flecs.h"
#include "flecs/flecs_meta.h"
// NOTE(zaklaus): custom macro to define meta components outside the current scope
#ifndef ECS_META_DEFINE
#define ECS_META_DEFINE(world, T)\
ECS_COMPONENT_DEFINE(world, T);\
ecs_new_meta(world, ecs_entity(T), &__##T##__);
#endif
#ifndef ecs_get_mut_if
#define ecs_get_mut_if(world, entity, component)\
(ecs_get(world, entity, component) ? ecs_get_mut(world, entity, component, NULL) : NULL)
#endif
ECS_STRUCT(Vector2D, {
float x;
float y;

View File

@ -7,14 +7,15 @@ void EnterOrLeaveVehicle(ecs_iter_t *it) {
for (int i = 0; i < it->count; i++) {
if (!in[i].use) continue;
in[i].use = false;
if (!world_entity_valid(in[i].parent)) {
size_t ents_count;
int64_t *ents = world_chunk_query_entities(it->entities[i], &ents_count, 2);
for (size_t j = 0; j < ents_count; j++) {
if (ecs_get(world_ecs(), ents[j], Vehicle)) {
Vehicle *veh = ecs_get_mut(world_ecs(), ents[j], Vehicle, NULL);
Vehicle *veh = 0;
if ((veh = ecs_get_mut_if(world_ecs(), ents[j], Vehicle))) {
Position const* p2 = ecs_get(world_ecs(), ents[j], Position);
float dx = p2->x - p[i].x;
@ -34,9 +35,8 @@ void EnterOrLeaveVehicle(ecs_iter_t *it) {
}
}
} else {
if (ecs_get(world_ecs(), in[i].parent, Vehicle)) {
Vehicle *veh = ecs_get_mut(world_ecs(), in[i].parent, Vehicle, NULL);
Vehicle *veh = 0;
if ((veh = ecs_get_mut_if(world_ecs(), in[i].parent, Vehicle))) {
for (int k = 0; k < 4; k++) {
if (veh->seats[k] == it->entities[i]) {
veh->seats[k] = 0;

32960
code/vendors/zpl.h vendored

File diff suppressed because it is too large Load Diff