Add compat layer for v2 demos

isolation_bkp/dynres
Dominik Madarász 2021-09-08 11:52:11 +02:00
parent 56b7b30684
commit 8b437d53cd
4 changed files with 55 additions and 4 deletions

View File

@ -20,6 +20,8 @@ typedef struct {
uint64_t delay;
} replay_record;
#include "debug_replay_compat_v2.c"
static uint8_t is_recording = false;
static replay_record *records = NULL;
static uint64_t last_record_time = 0.0f;
@ -32,7 +34,7 @@ static ecs_entity_t plr = 0;
static ecs_entity_t *temp_actors = NULL;
#define REPLAY_MAGIC 0x421DC97E
#define REPLAY_VERSION 2
#define REPLAY_VERSION 3
static char replay_filename[1024] = {0};
static char replaybuf[sizeof(replay_record)*UINT16_MAX + 32];
@ -75,7 +77,11 @@ void debug_replay_load(void) {
ZPL_ASSERT(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_MAGIC);
cw_unpack_next(&uc);
ZPL_ASSERT(uc.item.type == CWP_ITEM_POSITIVE_INTEGER && uc.item.as.u64 == REPLAY_VERSION);
ZPL_ASSERT(uc.item.type == CWP_ITEM_POSITIVE_INTEGER);
uint64_t version = uc.item.as.u64;
ZPL_ASSERT(version >= 2);
cw_unpack_next(&uc);
ZPL_ASSERT(uc.item.type == CWP_ITEM_ARRAY);
@ -86,9 +92,17 @@ void debug_replay_load(void) {
for (size_t i = 0; i < items; i++) {
cw_unpack_next(&uc);
ZPL_ASSERT(uc.item.type == CWP_ITEM_BIN);
replay_record rec = {0};
switch (version) {
case 2:{
debug_replay_load_record_v2(&rec, uc.item.as.bin.start);
}break;
default:{
zpl_memcopy(&rec, uc.item.as.bin.start, sizeof(replay_record));
}break;
}
zpl_array_append(records, rec);
}
}

View File

@ -0,0 +1,28 @@
typedef struct {
float x;
float y;
uint8_t use;
uint8_t sprint;
} pkt_send_keystate_v2;
typedef struct {
replay_kind kind;
pkt_send_keystate_v2 pkt;
uint64_t delay;
} replay_record_v2;
void debug_replay_load_record_v2(replay_record *rec, void const *buf) {
replay_record_v2 v2_rec;
zpl_memcopy(&v2_rec, buf, sizeof(replay_record_v2));
pkt_send_keystate pkt = {
.x = v2_rec.pkt.x,
.y = v2_rec.pkt.y,
.sprint = v2_rec.pkt.sprint,
.use = v2_rec.pkt.use,
};
rec->kind = v2_rec.kind;
rec->pkt = pkt;
rec->delay = v2_rec.delay;
}

View File

@ -16,6 +16,7 @@ typedef struct {
uint8_t swap_from;
uint8_t swap_to;
} pkt_send_keystate;
size_t pkt_send_keystate_send(uint16_t view_id,
float x,
float y,

View File

@ -156,11 +156,19 @@ void VehicleHandling(ecs_iter_t *it) {
debug_v2 b2 = {p[i].x + zpl_cos(car->heading)*(car->wheel_base), p[i].y + zpl_sin(car->heading)*(car->wheel_base)};
debug_push_line((debug_v2){p[i].x, p[i].y}, b2, 0x0000FFFF);
// NOTE(zaklaus): force
{
float dx = zpl_cos(car->heading);
float dy = zpl_sin(car->heading);
debug_push_circle((debug_v2){p[i].x+dx*car->force, p[i].y+dy*car->force}, 5.0f, 0x00FF00FF);
}
// NOTE(zaklaus): steer
{
float dx = zpl_sin(car->heading);
float dy = -zpl_cos(car->heading);
debug_push_circle((debug_v2){p[i].x+dx*car->steer*-20, p[i].y+dy*car->steer*-20}, 5.0f, 0x00FFAAFF);
}
}
}
}