chucker sensor

This commit is contained in:
jacob 2025-05-16 21:21:22 -05:00
parent c432ca5b77
commit 88dc2a22ab
4 changed files with 92 additions and 54 deletions

View File

@ -139,12 +139,13 @@ enum sim_control_flag {
/* Testing */ /* Testing */
SIM_CONTROL_FLAG_DRAG = 1 << 2, SIM_CONTROL_FLAG_DRAG = 1 << 2,
SIM_CONTROL_FLAG_CLEAR_ALL = 1 << 3, SIM_CONTROL_FLAG_DELETE = 1 << 3,
SIM_CONTROL_FLAG_SPAWN1_TEST = 1 << 4, SIM_CONTROL_FLAG_CLEAR_ALL = 1 << 4,
SIM_CONTROL_FLAG_SPAWN2_TEST = 1 << 5, SIM_CONTROL_FLAG_SPAWN1_TEST = 1 << 5,
SIM_CONTROL_FLAG_TILE_TEST = 1 << 6, SIM_CONTROL_FLAG_SPAWN2_TEST = 1 << 6,
SIM_CONTROL_FLAG_EXPLODE_TEST = 1 << 7, SIM_CONTROL_FLAG_TILE_TEST = 1 << 7,
SIM_CONTROL_FLAG_TELEPORT_TEST = 1 << 8, SIM_CONTROL_FLAG_EXPLODE_TEST = 1 << 8,
SIM_CONTROL_FLAG_TELEPORT_TEST = 1 << 9,
}; };
struct sim_control { struct sim_control {

View File

@ -51,17 +51,59 @@ void sim_accel_reset(struct sim_snapshot *ss, struct sim_accel *accel)
/* TODO: Remove this */ /* TODO: Remove this */
INTERNAL struct sim_ent *spawn_test_employee(struct sim_step_ctx *ctx) INTERNAL struct sim_ent *spawn_test_launcher(struct sim_ent *parent)
{ {
struct sim_snapshot *world = ctx->world; struct sim_ent *e = sim_ent_alloc_sync_src(parent);
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID); e->sprite = sprite_tag_from_path(LIT("res/graphics/gun.ase"));
sim_ent_enable_prop(e, SEPROP_ATTACHED);
e->attach_slice = LIT("attach.wep");
e->layer = SIM_LAYER_RELATIVE_WEAPON;
sim_ent_enable_prop(e, SEPROP_WEAPON_LAUNCHER);
e->primary_fire_delay = 1.0f / 10.0f;
e->secondary_fire_delay = 1.0f / 10.0f;
return e;
}
INTERNAL struct sim_ent *spawn_test_chucker(struct sim_ent *parent)
{
struct sim_ent *chucker = sim_ent_alloc_sync_src(parent);
chucker->sprite = sprite_tag_from_path(LIT("res/graphics/gun.ase"));
sim_ent_enable_prop(chucker, SEPROP_ATTACHED);
chucker->attach_slice = LIT("attach.wep");
chucker->layer = SIM_LAYER_RELATIVE_WEAPON;
sim_ent_enable_prop(chucker, SEPROP_WEAPON_CHUCKER);
chucker->primary_fire_delay = 1.0f / 10.0f;
chucker->secondary_fire_delay = 1.0f / 10.0f;
/* Chucker sensor */
{
struct sim_ent *sensor = sim_ent_alloc_sync_src(chucker);
sim_ent_enable_prop(sensor, SEPROP_ATTACHED);
sensor->attach_slice = LIT("out");
sim_ent_enable_prop(sensor, SEPROP_SENSOR);
struct collider_shape collider = ZI;
collider.count = 1;
collider.radius = 0.1;
sensor->local_collider = collider;
}
return chucker;
}
INTERNAL struct sim_ent *spawn_test_employee(struct sim_ent *parent)
{
/* Player */ /* Player */
struct sim_ent *employee = sim_ent_nil(); struct sim_ent *employee = sim_ent_nil();
//if (!ctx->extra_spawn) {
{ {
struct sim_ent *e = sim_ent_alloc_sync_src(root); struct sim_ent *e = sim_ent_alloc_sync_src(parent);
struct v2 pos = V2(1, -1); struct v2 pos = V2(1, -1);
@ -114,30 +156,21 @@ INTERNAL struct sim_ent *spawn_test_employee(struct sim_step_ctx *ctx)
/* Player weapon */ /* Player weapon */
if (employee->valid) { if (employee->valid) {
struct sim_ent *e = sim_ent_alloc_sync_src(employee); (UNUSED)spawn_test_launcher;
e->sprite = sprite_tag_from_path(LIT("res/graphics/gun.ase")); (UNUSED)spawn_test_chucker;
sim_ent_enable_prop(e, SEPROP_ATTACHED);
e->attach_slice = LIT("attach.wep");
e->layer = SIM_LAYER_RELATIVE_WEAPON;
sim_ent_enable_prop(e, SEPROP_WEAPON_CHUCKER);
e->primary_fire_delay = 1.0f / 10.0f;
e->secondary_fire_delay = 1.0f / 10.0f;
struct sim_ent *e = spawn_test_chucker(employee);
employee->equipped = e->id; employee->equipped = e->id;
} }
return employee; return employee;
} }
INTERNAL struct sim_ent *spawn_test_camera(struct sim_snapshot *world, struct sim_ent *follow) INTERNAL struct sim_ent *spawn_test_camera(struct sim_ent *parent, struct sim_ent *follow)
{ {
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
struct sim_ent *camera_ent = sim_ent_nil(); struct sim_ent *camera_ent = sim_ent_nil();
if (follow->valid) { if (follow->valid) {
camera_ent = sim_ent_alloc_sync_src(root); camera_ent = sim_ent_alloc_sync_src(parent);
sim_ent_set_xform(camera_ent, XFORM_IDENT); sim_ent_set_xform(camera_ent, XFORM_IDENT);
sim_ent_enable_prop(camera_ent, SEPROP_CAMERA); sim_ent_enable_prop(camera_ent, SEPROP_CAMERA);
@ -152,11 +185,9 @@ INTERNAL struct sim_ent *spawn_test_camera(struct sim_snapshot *world, struct si
return camera_ent; return camera_ent;
} }
INTERNAL struct sim_ent *spawn_test_explosion(struct sim_snapshot *world, struct v2 pos, f32 strength, f32 radius) INTERNAL struct sim_ent *spawn_test_explosion(struct sim_ent *parent, struct v2 pos, f32 strength, f32 radius)
{ {
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID); struct sim_ent *ent = sim_ent_alloc_sync_src(parent);
struct sim_ent *ent = sim_ent_alloc_sync_src(root);
sim_ent_set_xform(ent, XFORM_POS(pos)); sim_ent_set_xform(ent, XFORM_POS(pos));
sim_ent_enable_prop(ent, SEPROP_EXPLOSION); sim_ent_enable_prop(ent, SEPROP_EXPLOSION);
@ -178,37 +209,27 @@ INTERNAL void test_teleport(struct sim_ent *ent, struct v2 pos)
sim_ent_set_xform(ent, xf); sim_ent_set_xform(ent, xf);
} }
INTERNAL void spawn_test_entities1(struct sim_step_ctx *ctx, struct v2 pos) INTERNAL void spawn_test_entities1(struct sim_ent *parent, struct v2 pos)
{ {
struct sim_snapshot *world = ctx->world;
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
(UNUSED)pos; (UNUSED)pos;
root->mass_unscaled = F32_INFINITY;
root->inertia_unscaled = F32_INFINITY;
/* Enemy */ /* Enemy */
if (ctx->is_master) { {
struct sim_ent *e = spawn_test_employee(ctx); struct sim_ent *e = spawn_test_employee(parent);
struct xform xf = sim_ent_get_xform(e); struct xform xf = sim_ent_get_xform(e);
xf.og = pos; xf.og = pos;
sim_ent_set_xform(e, xf); sim_ent_set_xform(e, xf);
} }
} }
INTERNAL void spawn_test_entities2(struct sim_step_ctx *ctx, struct v2 pos) INTERNAL void spawn_test_entities2(struct sim_ent *parent, struct v2 pos)
{ {
struct sim_snapshot *world = ctx->world;
struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID);
(UNUSED)pos; (UNUSED)pos;
root->mass_unscaled = F32_INFINITY;
root->inertia_unscaled = F32_INFINITY;
/* Big box */ /* Big box */
#if 1 #if 1
{ {
struct sim_ent *e = sim_ent_alloc_local(root); struct sim_ent *e = sim_ent_alloc_local(parent);
f32 r = 0; f32 r = 0;
struct v2 size = V2(0.5, 0.25); struct v2 size = V2(0.5, 0.25);
@ -232,7 +253,7 @@ INTERNAL void spawn_test_entities2(struct sim_step_ctx *ctx, struct v2 pos)
/* Tiny box */ /* Tiny box */
#if 0 #if 0
{ {
struct sim_ent *e = sim_ent_alloc_sync_src(root); struct sim_ent *e = sim_ent_alloc_sync_src(parent);
f32 r = PI / 4; f32 r = PI / 4;
struct v2 size = V2(0.5, 0.25); struct v2 size = V2(0.5, 0.25);
@ -330,7 +351,7 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
/* Create explosion */ /* Create explosion */
if (bullet->bullet_explosion_strength > 0) { if (bullet->bullet_explosion_strength > 0) {
spawn_test_explosion(world, point, bullet->bullet_explosion_strength, bullet->bullet_explosion_radius); spawn_test_explosion(root, point, bullet->bullet_explosion_strength, bullet->bullet_explosion_radius);
} }
/* Update bullet */ /* Update bullet */
@ -566,6 +587,12 @@ void sim_step(struct sim_step_ctx *ctx)
player->player_dbg_drag_stop = true; player->player_dbg_drag_stop = true;
} }
} }
if (flags & SIM_CONTROL_FLAG_DELETE) {
struct sim_ent *ent = sim_ent_from_id(world, player->player_hovered_ent);
if (ent->valid) {
sim_ent_enable_prop(ent, SEPROP_RELEASE);
}
}
if (flags & SIM_CONTROL_FLAG_CLEAR_ALL) { if (flags & SIM_CONTROL_FLAG_CLEAR_ALL) {
if (is_master && !(old_control.flags & SIM_CONTROL_FLAG_CLEAR_ALL)) { if (is_master && !(old_control.flags & SIM_CONTROL_FLAG_CLEAR_ALL)) {
test_clear_level(ctx); test_clear_level(ctx);
@ -578,7 +605,7 @@ void sim_step(struct sim_step_ctx *ctx)
for (u32 j = 0; j < count; ++j) { for (u32 j = 0; j < count; ++j) {
struct v2 pos = player->player_cursor_pos; struct v2 pos = player->player_cursor_pos;
pos.y += (((f32)j / (f32)count) - 0.5) * spread; pos.y += (((f32)j / (f32)count) - 0.5) * spread;
spawn_test_entities1(ctx, pos); spawn_test_entities1(root, pos);
} }
} }
if (flags & SIM_CONTROL_FLAG_SPAWN2_TEST) { if (flags & SIM_CONTROL_FLAG_SPAWN2_TEST) {
@ -589,14 +616,14 @@ void sim_step(struct sim_step_ctx *ctx)
for (u32 j = 0; j < count; ++j) { for (u32 j = 0; j < count; ++j) {
struct v2 pos = player->player_cursor_pos; struct v2 pos = player->player_cursor_pos;
pos.y += (((f32)j / (f32)count) - 0.5) * spread; pos.y += (((f32)j / (f32)count) - 0.5) * spread;
spawn_test_entities2(ctx, pos); spawn_test_entities2(root, pos);
} }
} }
} }
if (flags & SIM_CONTROL_FLAG_EXPLODE_TEST) { if (flags & SIM_CONTROL_FLAG_EXPLODE_TEST) {
if (!(old_control.flags & SIM_CONTROL_FLAG_EXPLODE_TEST)) { if (!(old_control.flags & SIM_CONTROL_FLAG_EXPLODE_TEST)) {
logf_info("Explosion (test)"); logf_info("Explosion (test)");
spawn_test_explosion(world, player->player_cursor_pos, 100, 2); spawn_test_explosion(root, player->player_cursor_pos, 100, 2);
} }
} }
} }
@ -692,7 +719,7 @@ void sim_step(struct sim_step_ctx *ctx)
/* FIXME: Ents never released when client disconnects */ /* FIXME: Ents never released when client disconnects */
struct sim_ent *control_ent = sim_ent_from_id(world, ent->player_control_ent); struct sim_ent *control_ent = sim_ent_from_id(world, ent->player_control_ent);
if (!control_ent->valid) { if (!control_ent->valid) {
control_ent = spawn_test_employee(ctx); control_ent = spawn_test_employee(root);
control_ent->predictor = ent->id; control_ent->predictor = ent->id;
sim_ent_enable_prop(control_ent, SEPROP_CONTROLLED); sim_ent_enable_prop(control_ent, SEPROP_CONTROLLED);
ent->player_control_ent = control_ent->id; ent->player_control_ent = control_ent->id;
@ -700,10 +727,14 @@ void sim_step(struct sim_step_ctx *ctx)
} }
struct sim_ent *camera_ent = sim_ent_from_id(world, ent->player_camera_ent); struct sim_ent *camera_ent = sim_ent_from_id(world, ent->player_camera_ent);
if (!camera_ent->valid) { if (!camera_ent->valid) {
camera_ent = spawn_test_camera(world, control_ent); camera_ent = spawn_test_camera(root, control_ent);
camera_ent->predictor = ent->id; camera_ent->predictor = ent->id;
ent->player_camera_ent = camera_ent->id; ent->player_camera_ent = camera_ent->id;
} }
struct sim_ent *camera_follow = sim_ent_from_id(world, camera_ent->camera_follow);
if (!camera_follow->valid) {
camera_ent->camera_follow = control_ent->id;
}
} }
} }
} }

View File

@ -140,12 +140,14 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = {
[SYS_BTN_D] = USER_BIND_KIND_MOVE_RIGHT, [SYS_BTN_D] = USER_BIND_KIND_MOVE_RIGHT,
[SYS_BTN_ALT] = USER_BIND_KIND_WALK, [SYS_BTN_ALT] = USER_BIND_KIND_WALK,
[SYS_BTN_M1] = USER_BIND_KIND_FIRE, [SYS_BTN_M1] = USER_BIND_KIND_FIRE,
[SYS_BTN_M2] = USER_BIND_KIND_FIRE_ALT,
/* Testing */ /* Testing */
[SYS_BTN_M4] = USER_BIND_KIND_TILE_TEST, [SYS_BTN_M4] = USER_BIND_KIND_TILE_TEST,
[SYS_BTN_M2] = USER_BIND_KIND_DEBUG_DRAG, [SYS_BTN_M5] = USER_BIND_KIND_DEBUG_DRAG,
[SYS_BTN_M4] = USER_BIND_KIND_DEBUG_DELETE,
[SYS_BTN_F] = USER_BIND_KIND_DEBUG_EXPLODE, [SYS_BTN_F] = USER_BIND_KIND_DEBUG_EXPLODE,
[SYS_BTN_T] = USER_BIND_KIND_DEBUG_TELEPORT, [SYS_BTN_T] = USER_BIND_KIND_DEBUG_TELEPORT,
[SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR, [SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR,
@ -675,7 +677,6 @@ INTERNAL void user_update(void)
for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) { for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) {
struct sim_ent *ent = &G.ss_blended->ents[ent_index]; struct sim_ent *ent = &G.ss_blended->ents[ent_index];
if (!sim_ent_is_valid_and_active(ent)) continue; if (!sim_ent_is_valid_and_active(ent)) continue;
if (!ent->is_top) continue;
struct collider_shape ent_collider = ent->local_collider; struct collider_shape ent_collider = ent->local_collider;
if (ent_collider.count > 0) { if (ent_collider.count > 0) {
@ -683,7 +684,7 @@ INTERNAL void user_update(void)
struct xform ent_xf = sim_ent_get_xform(ent); struct xform ent_xf = sim_ent_get_xform(ent);
struct collider_collision_points_result res = collider_collision_points(&ent_collider, &mouse_shape, ent_xf, mouse_xf); struct collider_collision_points_result res = collider_collision_points(&ent_collider, &mouse_shape, ent_xf, mouse_xf);
if (res.num_points > 0) { if (res.num_points > 0) {
hovered_ent = ent; hovered_ent = sim_ent_from_id(G.ss_blended, ent->top);
break; break;
} }
} }
@ -1593,6 +1594,7 @@ INTERNAL void user_update(void)
struct bind_state fire_state = G.bind_states[USER_BIND_KIND_FIRE]; struct bind_state fire_state = G.bind_states[USER_BIND_KIND_FIRE];
struct bind_state fire_alt_state = G.bind_states[USER_BIND_KIND_FIRE_ALT]; struct bind_state fire_alt_state = G.bind_states[USER_BIND_KIND_FIRE_ALT];
struct bind_state drag_state = G.bind_states[USER_BIND_KIND_DEBUG_DRAG]; struct bind_state drag_state = G.bind_states[USER_BIND_KIND_DEBUG_DRAG];
struct bind_state delete_state = G.bind_states[USER_BIND_KIND_DEBUG_DELETE];
struct bind_state clear_state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR]; struct bind_state clear_state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
struct bind_state spawn1_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN1]; struct bind_state spawn1_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN1];
struct bind_state spawn2_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN2]; struct bind_state spawn2_state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN2];
@ -1611,6 +1613,9 @@ INTERNAL void user_update(void)
if (drag_state.num_presses || drag_state.is_held) { if (drag_state.num_presses || drag_state.is_held) {
control.flags |= SIM_CONTROL_FLAG_DRAG; control.flags |= SIM_CONTROL_FLAG_DRAG;
} }
if (delete_state.num_presses || delete_state.is_held) {
control.flags |= SIM_CONTROL_FLAG_DELETE;
}
if (clear_state.num_presses_and_repeats) { if (clear_state.num_presses_and_repeats) {
control.flags |= SIM_CONTROL_FLAG_CLEAR_ALL; control.flags |= SIM_CONTROL_FLAG_CLEAR_ALL;
} }

View File

@ -38,6 +38,7 @@ enum user_bind_kind {
USER_BIND_KIND_DEBUG_PAUSE, USER_BIND_KIND_DEBUG_PAUSE,
USER_BIND_KIND_DEBUG_STEP, USER_BIND_KIND_DEBUG_STEP,
USER_BIND_KIND_DEBUG_DRAG, USER_BIND_KIND_DEBUG_DRAG,
USER_BIND_KIND_DEBUG_DELETE,
USER_BIND_KIND_DEBUG_TELEPORT, USER_BIND_KIND_DEBUG_TELEPORT,
USER_BIND_KIND_DEBUG_EXPLODE, USER_BIND_KIND_DEBUG_EXPLODE,
USER_BIND_KIND_FULLSCREEN, USER_BIND_KIND_FULLSCREEN,