pp refactor progress
This commit is contained in:
parent
f389b0e6f8
commit
bb300b9ef4
@ -122,8 +122,8 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
|
|||||||
|
|
||||||
//result.len += StringFormat(arena, Lit("[%F]"), FmtUid(ent->id.uid)).len;
|
//result.len += StringFormat(arena, Lit("[%F]"), FmtUid(ent->id.uid)).len;
|
||||||
{
|
{
|
||||||
b32 transmitting = sim_ent_has_prop(ent, SEPROP_SYNC_SRC);
|
b32 transmitting = sim_ent_has_prop(ent, Prop_SyncSrc);
|
||||||
b32 receiving = sim_ent_has_prop(ent, SEPROP_SYNC_DST);
|
b32 receiving = sim_ent_has_prop(ent, Prop_SyncDst);
|
||||||
if (transmitting & receiving)
|
if (transmitting & receiving)
|
||||||
{
|
{
|
||||||
result.len += PushString(arena, Lit(" networked (sending & receiving)")).len;
|
result.len += PushString(arena, Lit(" networked (sending & receiving)")).len;
|
||||||
@ -154,7 +154,7 @@ String DebugStringFromEntity(Arena *arena, Entity *ent)
|
|||||||
u64 chunk = ent->props[chunk_index];
|
u64 chunk = ent->props[chunk_index];
|
||||||
for (u64 part_index = 8; part_index-- > 0;)
|
for (u64 part_index = 8; part_index-- > 0;)
|
||||||
{
|
{
|
||||||
if ((chunk_index != (countof(ent->props) - 1)) || ((chunk_index * 64) + (part_index * 8)) <= SEPROP_COUNT)
|
if ((chunk_index != (countof(ent->props) - 1)) || ((chunk_index * 64) + (part_index * 8)) <= Prop_Count)
|
||||||
{
|
{
|
||||||
u8 part = (chunk >> (part_index * 8)) & 0xFF;
|
u8 part = (chunk >> (part_index * 8)) & 0xFF;
|
||||||
StringFromChar(arena, hex[(part >> 4) & 0x0F]);
|
StringFromChar(arena, hex[(part >> 4) & 0x0F]);
|
||||||
@ -365,8 +365,8 @@ MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _)
|
|||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
/* Sort by light */
|
/* Sort by light */
|
||||||
b32 a_cmp = sim_ent_has_prop(a, SEPROP_LIGHT_TEST);
|
b32 a_cmp = sim_ent_has_prop(a, Prop_LightTest);
|
||||||
b32 b_cmp = sim_ent_has_prop(b, SEPROP_LIGHT_TEST);
|
b32 b_cmp = sim_ent_has_prop(b, Prop_LightTest);
|
||||||
result = (a_cmp > b_cmp) - (a_cmp < b_cmp);
|
result = (a_cmp > b_cmp) - (a_cmp < b_cmp);
|
||||||
}
|
}
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
@ -937,7 +937,7 @@ void UpdateUser(P_Window *window)
|
|||||||
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)
|
||||||
{
|
{
|
||||||
Entity *chunk_ent = &g->ss_blended->ents[ent_index];
|
Entity *chunk_ent = &g->ss_blended->ents[ent_index];
|
||||||
if (sim_ent_is_valid_and_active(chunk_ent) && sim_ent_has_prop(chunk_ent, SEPROP_TILE_CHUNK))
|
if (sim_ent_is_valid_and_active(chunk_ent) && sim_ent_has_prop(chunk_ent, Prop_TileChunk))
|
||||||
{
|
{
|
||||||
struct user_tile_cache_entry *entry = user_tile_cache_entry_from_chunk_pos(chunk_ent->tile_chunk_pos);
|
struct user_tile_cache_entry *entry = user_tile_cache_entry_from_chunk_pos(chunk_ent->tile_chunk_pos);
|
||||||
if (!entry->valid)
|
if (!entry->valid)
|
||||||
@ -1081,9 +1081,9 @@ void UpdateUser(P_Window *window)
|
|||||||
Xform parent_xf = sim_ent_get_xform(parent);
|
Xform parent_xf = sim_ent_get_xform(parent);
|
||||||
|
|
||||||
b32 skip_debug_draw = !g->debug_camera && ent == local_camera;
|
b32 skip_debug_draw = !g->debug_camera && ent == local_camera;
|
||||||
skip_debug_draw = skip_debug_draw || sim_ent_has_prop(ent, SEPROP_MOTOR_JOINT);
|
skip_debug_draw = skip_debug_draw || sim_ent_has_prop(ent, Prop_MotorJoint);
|
||||||
|
|
||||||
b32 skip_debug_draw_transform = sim_ent_has_prop(ent, SEPROP_CAMERA);
|
b32 skip_debug_draw_transform = sim_ent_has_prop(ent, Prop_Camera);
|
||||||
skip_debug_draw_transform = 1;
|
skip_debug_draw_transform = 1;
|
||||||
|
|
||||||
Xform sprite_xform = MulXform(xf, ent->sprite_local_xform);
|
Xform sprite_xform = MulXform(xf, ent->sprite_local_xform);
|
||||||
@ -1091,7 +1091,7 @@ void UpdateUser(P_Window *window)
|
|||||||
/* Draw tracer */
|
/* Draw tracer */
|
||||||
/* TODO: Enable this */
|
/* TODO: Enable this */
|
||||||
#if 0
|
#if 0
|
||||||
if (sim_ent_has_prop(ent, SEPROP_TRACER))
|
if (sim_ent_has_prop(ent, Prop_Tracer))
|
||||||
{
|
{
|
||||||
Vec2 velocity = ent->tracer_start_velocity;
|
Vec2 velocity = ent->tracer_start_velocity;
|
||||||
|
|
||||||
@ -1143,7 +1143,7 @@ void UpdateUser(P_Window *window)
|
|||||||
/* TODO: Fade in placeholder if texture isn't loaded */
|
/* TODO: Fade in placeholder if texture isn't loaded */
|
||||||
if (sheet->loaded && texture->loaded)
|
if (sheet->loaded && texture->loaded)
|
||||||
{
|
{
|
||||||
b32 is_light = sim_ent_has_prop(ent, SEPROP_LIGHT_TEST);
|
b32 is_light = sim_ent_has_prop(ent, Prop_LightTest);
|
||||||
Vec3 emittance = ent->sprite_emittance;
|
Vec3 emittance = ent->sprite_emittance;
|
||||||
u32 tint = ent->sprite_tint;
|
u32 tint = ent->sprite_tint;
|
||||||
S_Frame frame = S_FrameFromIndex(sheet, ent->animation_frame);
|
S_Frame frame = S_FrameFromIndex(sheet, ent->animation_frame);
|
||||||
@ -1154,7 +1154,7 @@ void UpdateUser(P_Window *window)
|
|||||||
|
|
||||||
/* Draw tiles */
|
/* Draw tiles */
|
||||||
/* TODO: Something better */
|
/* TODO: Something better */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_TILE_CHUNK))
|
if (sim_ent_has_prop(ent, Prop_TileChunk))
|
||||||
{
|
{
|
||||||
Vec2I32 chunk_index = ent->tile_chunk_index;
|
Vec2I32 chunk_index = ent->tile_chunk_index;
|
||||||
S_Tag tile_sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
S_Tag tile_sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
||||||
@ -1187,7 +1187,7 @@ void UpdateUser(P_Window *window)
|
|||||||
{
|
{
|
||||||
TempArena temp = BeginTempArena(scratch.arena);
|
TempArena temp = BeginTempArena(scratch.arena);
|
||||||
|
|
||||||
if (sim_ent_has_prop(ent, SEPROP_KINEMATIC) || sim_ent_has_prop(ent, SEPROP_DYNAMIC))
|
if (sim_ent_has_prop(ent, Prop_Kinematic) || sim_ent_has_prop(ent, Prop_Dynamic))
|
||||||
{
|
{
|
||||||
DrawDebugMovement(ent);
|
DrawDebugMovement(ent);
|
||||||
}
|
}
|
||||||
@ -1269,7 +1269,7 @@ void UpdateUser(P_Window *window)
|
|||||||
|
|
||||||
/* Draw weld joint */
|
/* Draw weld joint */
|
||||||
#if 0
|
#if 0
|
||||||
if (sim_ent_has_prop(ent, SEPROP_WELD_JOINT))
|
if (sim_ent_has_prop(ent, Prop_WeldJoint))
|
||||||
{
|
{
|
||||||
Entity *e1 = sim_ent_from_id(g->ss_blended, ent->weld_joint_data.e1);
|
Entity *e1 = sim_ent_from_id(g->ss_blended, ent->weld_joint_data.e1);
|
||||||
Xform e1_xf = sim_ent_get_xform(e1);
|
Xform e1_xf = sim_ent_get_xform(e1);
|
||||||
@ -1285,7 +1285,7 @@ void UpdateUser(P_Window *window)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Draw mouse joint */
|
/* Draw mouse joint */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_MOUSE_JOINT))
|
if (sim_ent_has_prop(ent, Prop_MouseJoint))
|
||||||
{
|
{
|
||||||
Entity *target = sim_ent_from_id(g->ss_blended, ent->mouse_joint_data.target);
|
Entity *target = sim_ent_from_id(g->ss_blended, ent->mouse_joint_data.target);
|
||||||
Xform target_xf = sim_ent_get_xform(target);
|
Xform target_xf = sim_ent_get_xform(target);
|
||||||
@ -1338,7 +1338,7 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Draw contact constraint */
|
/* Draw contact constraint */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_CONTACT_CONSTRAINT))
|
if (sim_ent_has_prop(ent, Prop_ContactConstraint))
|
||||||
{
|
{
|
||||||
ContactConstraint *data = &ent->contact_constraint_data;
|
ContactConstraint *data = &ent->contact_constraint_data;
|
||||||
Entity *e0 = sim_ent_from_id(g->ss_blended, data->e0);
|
Entity *e0 = sim_ent_from_id(g->ss_blended, data->e0);
|
||||||
@ -1410,7 +1410,7 @@ void UpdateUser(P_Window *window)
|
|||||||
|
|
||||||
/* Draw collision debug */
|
/* Draw collision debug */
|
||||||
#if COLLIDER_DEBUG
|
#if COLLIDER_DEBUG
|
||||||
if (sim_ent_has_prop(ent, SEPROP_COLLISION_DEBUG))
|
if (sim_ent_has_prop(ent, Prop_CollisionDebug))
|
||||||
{
|
{
|
||||||
CollisionDebugData *data = &ent->collision_debug_data;
|
CollisionDebugData *data = &ent->collision_debug_data;
|
||||||
CLD_CollisionData collision_reuslt = data->collision_result;
|
CLD_CollisionData collision_reuslt = data->collision_result;
|
||||||
@ -1610,7 +1610,7 @@ void UpdateUser(P_Window *window)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Draw hierarchy */
|
/* Draw hierarchy */
|
||||||
if (sim_ent_has_prop(parent, SEPROP_ACTIVE) && !parent->is_root)
|
if (sim_ent_has_prop(parent, Prop_Active) && !parent->is_root)
|
||||||
{
|
{
|
||||||
u32 color = Rgba32F(0.6, 0.6, 1, 0.75);
|
u32 color = Rgba32F(0.6, 0.6, 1, 0.75);
|
||||||
f32 thickness = 2;
|
f32 thickness = 2;
|
||||||
@ -1622,7 +1622,7 @@ void UpdateUser(P_Window *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Draw camera rect */
|
/* Draw camera rect */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_CAMERA))
|
if (sim_ent_has_prop(ent, Prop_Camera))
|
||||||
{
|
{
|
||||||
u32 color = ent == local_camera ? Rgba32F(1, 1, 1, 0.5) : Rgba32F(0, 0.75, 0, 0.5);
|
u32 color = ent == local_camera ? Rgba32F(1, 1, 1, 0.5) : Rgba32F(0, 0.75, 0, 0.5);
|
||||||
f32 thickness = 3;
|
f32 thickness = 3;
|
||||||
@ -2086,13 +2086,13 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick)
|
|||||||
Snapshot *user_input_ss = sim_snapshot_acquire(user_input_client, prev_user_input_ss, tick);
|
Snapshot *user_input_ss = sim_snapshot_acquire(user_input_client, prev_user_input_ss, tick);
|
||||||
Entity *user_input_root = sim_ent_from_id(user_input_ss, SIM_ENT_ROOT_ID);
|
Entity *user_input_root = sim_ent_from_id(user_input_ss, SIM_ENT_ROOT_ID);
|
||||||
/* Find / create local control cmd ent */
|
/* Find / create local control cmd ent */
|
||||||
Entity *control_cmd = sim_ent_find_first_match_one(user_input_ss, SEPROP_CMD);
|
Entity *control_cmd = sim_ent_find_first_match_one(user_input_ss, Prop_Cmd);
|
||||||
if (!control_cmd->valid)
|
if (!control_cmd->valid)
|
||||||
{
|
{
|
||||||
control_cmd = sim_ent_acquire_sync_src(user_input_root);
|
control_cmd = sim_ent_acquire_sync_src(user_input_root);
|
||||||
control_cmd->cmd_kind = SIM_CMD_KIND_CONTROL;
|
control_cmd->cmd_kind = SIM_CMD_KIND_CONTROL;
|
||||||
control_cmd->predictor = user_input_client->player_id;
|
control_cmd->predictor = user_input_client->player_id;
|
||||||
sim_ent_enable_prop(control_cmd, SEPROP_CMD);
|
sim_ent_enable_prop(control_cmd, Prop_Cmd);
|
||||||
sim_ent_activate(control_cmd, user_input_ss->tick);
|
sim_ent_activate(control_cmd, user_input_ss->tick);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -2382,10 +2382,10 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
|
|||||||
for (u64 i = 0; i < ss->num_ents_reserved; ++i)
|
for (u64 i = 0; i < ss->num_ents_reserved; ++i)
|
||||||
{
|
{
|
||||||
Entity *ent = &ss->ents[i];
|
Entity *ent = &ss->ents[i];
|
||||||
if (ent->valid && sim_ent_has_prop(ent, SEPROP_SYNC_DST))
|
if (ent->valid && sim_ent_has_prop(ent, Prop_SyncDst))
|
||||||
{
|
{
|
||||||
sim_ent_disable_prop(ent, SEPROP_SYNC_DST);
|
sim_ent_disable_prop(ent, Prop_SyncDst);
|
||||||
sim_ent_enable_prop(ent, SEPROP_SYNC_SRC);
|
sim_ent_enable_prop(ent, Prop_SyncSrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2620,7 +2620,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
|
|||||||
|
|
||||||
if (master_ss->valid)
|
if (master_ss->valid)
|
||||||
{
|
{
|
||||||
Entity *master_player = sim_ent_find_first_match_one(master_ss, SEPROP_PLAYER_IS_MASTER);
|
Entity *master_player = sim_ent_find_first_match_one(master_ss, Prop_IsMaster);
|
||||||
|
|
||||||
/* Update ent id from master */
|
/* Update ent id from master */
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,8 +1,3 @@
|
|||||||
/* Id magic number constants (to be used in conjunction with ent ids in deterministic id combinations) */
|
|
||||||
#define SIM_ENT_CONTACT_BASIS_Uid (UID(0x6a2a5d2dbecf534f, 0x0a8ca7c372a015af))
|
|
||||||
#define SIM_ENT_COLLISION_DEBUG_BASIS_Uid (UID(0x302c01182013bb02, 0x570bd270399d11a5))
|
|
||||||
#define SIM_ENT_TILE_CHUNK_BASIS_Uid (UID(0x3ce42de071dd226b, 0x9b566f7df30c813a))
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Acquire
|
//~ Acquire
|
||||||
|
|
||||||
@ -56,7 +51,7 @@ Entity *sim_ent_acquire_sync_src(Entity *parent)
|
|||||||
{
|
{
|
||||||
Snapshot *ss = parent->ss;
|
Snapshot *ss = parent->ss;
|
||||||
Entity *e = sim_ent_acquire_raw(ss, parent, sim_ent_random_id());
|
Entity *e = sim_ent_acquire_raw(ss, parent, sim_ent_random_id());
|
||||||
sim_ent_enable_prop(e, SEPROP_SYNC_SRC);
|
sim_ent_enable_prop(e, Prop_SyncSrc);
|
||||||
e->owner = ss->local_player;
|
e->owner = ss->local_player;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
@ -65,7 +60,7 @@ Entity *sim_ent_acquire_sync_src_with_id(Entity *parent, EntityId id)
|
|||||||
{
|
{
|
||||||
Snapshot *ss = parent->ss;
|
Snapshot *ss = parent->ss;
|
||||||
Entity *e = sim_ent_acquire_raw(ss, parent, id);
|
Entity *e = sim_ent_acquire_raw(ss, parent, id);
|
||||||
sim_ent_enable_prop(e, SEPROP_SYNC_SRC);
|
sim_ent_enable_prop(e, Prop_SyncSrc);
|
||||||
e->owner = ss->local_player;
|
e->owner = ss->local_player;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
@ -75,7 +70,7 @@ Entity *sim_ent_acquire_sync_dst(Entity *parent, EntityId ent_id, EntityId owner
|
|||||||
{
|
{
|
||||||
Snapshot *ss = parent->ss;
|
Snapshot *ss = parent->ss;
|
||||||
Entity *e = sim_ent_acquire_raw(ss, parent, ent_id);
|
Entity *e = sim_ent_acquire_raw(ss, parent, ent_id);
|
||||||
sim_ent_enable_prop(e, SEPROP_SYNC_DST);
|
sim_ent_enable_prop(e, Prop_SyncDst);
|
||||||
e->owner = owner_id;
|
e->owner = owner_id;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
@ -114,7 +109,7 @@ void sim_ent_release(Entity *ent)
|
|||||||
sim_ent_release_raw(ent);
|
sim_ent_release_raw(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sim_ent_release_all_with_prop(Snapshot *ss, EntProp prop)
|
void sim_ent_release_all_with_prop(Snapshot *ss, Prop prop)
|
||||||
{
|
{
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
|
|
||||||
@ -133,7 +128,7 @@ void sim_ent_release_all_with_prop(Snapshot *ss, EntProp prop)
|
|||||||
* child entities will be released along with parent anyway) */
|
* child entities will be released along with parent anyway) */
|
||||||
for (u64 i = 0; i < ents_to_release_count; ++i) {
|
for (u64 i = 0; i < ents_to_release_count; ++i) {
|
||||||
Entity *ent = ents_to_release[i];
|
Entity *ent = ents_to_release[i];
|
||||||
if (ent->valid && !ent->is_root && !sim_ent_has_prop(ent, SEPROP_CMD) && !sim_ent_has_prop(ent, SEPROP_PLAYER)) {
|
if (ent->valid && !ent->is_root && !sim_ent_has_prop(ent, Prop_Cmd) && !sim_ent_has_prop(ent, Prop_Player)) {
|
||||||
sim_ent_release(ent);
|
sim_ent_release(ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +141,7 @@ void sim_ent_release_all_with_prop(Snapshot *ss, EntProp prop)
|
|||||||
|
|
||||||
void sim_ent_activate(Entity *ent, u64 current_tick)
|
void sim_ent_activate(Entity *ent, u64 current_tick)
|
||||||
{
|
{
|
||||||
sim_ent_enable_prop(ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(ent, Prop_Active);
|
||||||
ent->activation_tick = current_tick;
|
ent->activation_tick = current_tick;
|
||||||
++ent->continuity_gen;
|
++ent->continuity_gen;
|
||||||
}
|
}
|
||||||
@ -300,7 +295,7 @@ EntityId sim_ent_tile_chunk_id_from_tile_chunk_index(Vec2I32 chunk_index)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Query
|
//~ Query
|
||||||
|
|
||||||
Entity *sim_ent_find_first_match_one(Snapshot *ss, EntProp prop)
|
Entity *sim_ent_find_first_match_one(Snapshot *ss, Prop prop)
|
||||||
{
|
{
|
||||||
u64 count = ss->num_ents_reserved;
|
u64 count = ss->num_ents_reserved;
|
||||||
Entity *entities = ss->ents;
|
Entity *entities = ss->ents;
|
||||||
@ -489,21 +484,21 @@ void sim_ent_set_local_xform(Entity *ent, Xform xf)
|
|||||||
|
|
||||||
void sim_ent_set_linear_velocity(Entity *ent, Vec2 velocity)
|
void sim_ent_set_linear_velocity(Entity *ent, Vec2 velocity)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_KINEMATIC) || sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Kinematic) || sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
ent->linear_velocity = ClampVec2Len(velocity, SIM_MAX_LINEAR_VELOCITY);
|
ent->linear_velocity = ClampVec2Len(velocity, SIM_MAX_LINEAR_VELOCITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sim_ent_set_angular_velocity(Entity *ent, f32 velocity)
|
void sim_ent_set_angular_velocity(Entity *ent, f32 velocity)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_KINEMATIC) || sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Kinematic) || sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
ent->angular_velocity = ClampF32(velocity, -SIM_MAX_ANGULAR_VELOCITY, SIM_MAX_ANGULAR_VELOCITY);
|
ent->angular_velocity = ClampF32(velocity, -SIM_MAX_ANGULAR_VELOCITY, SIM_MAX_ANGULAR_VELOCITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sim_ent_apply_linear_impulse(Entity *ent, Vec2 impulse, Vec2 point)
|
void sim_ent_apply_linear_impulse(Entity *ent, Vec2 impulse, Vec2 point)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
Xform xf = sim_ent_get_xform(ent);
|
Xform xf = sim_ent_get_xform(ent);
|
||||||
Vec2 center = xf.og;
|
Vec2 center = xf.og;
|
||||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||||
@ -518,7 +513,7 @@ void sim_ent_apply_linear_impulse(Entity *ent, Vec2 impulse, Vec2 point)
|
|||||||
|
|
||||||
void sim_ent_apply_linear_impulse_to_center(Entity *ent, Vec2 impulse)
|
void sim_ent_apply_linear_impulse_to_center(Entity *ent, Vec2 impulse)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
Xform xf = sim_ent_get_xform(ent);
|
Xform xf = sim_ent_get_xform(ent);
|
||||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||||
f32 inv_mass = 1.f / (ent->mass_unscaled * scale);
|
f32 inv_mass = 1.f / (ent->mass_unscaled * scale);
|
||||||
@ -529,14 +524,14 @@ void sim_ent_apply_linear_impulse_to_center(Entity *ent, Vec2 impulse)
|
|||||||
|
|
||||||
void sim_ent_apply_force_to_center(Entity *ent, Vec2 force)
|
void sim_ent_apply_force_to_center(Entity *ent, Vec2 force)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
ent->force = AddVec2(ent->force, force);
|
ent->force = AddVec2(ent->force, force);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sim_ent_apply_angular_impulse(Entity *ent, f32 impulse)
|
void sim_ent_apply_angular_impulse(Entity *ent, f32 impulse)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
Xform xf = sim_ent_get_xform(ent);
|
Xform xf = sim_ent_get_xform(ent);
|
||||||
f32 scale = AbsF32(DeterminantFromXform(xf));
|
f32 scale = AbsF32(DeterminantFromXform(xf));
|
||||||
f32 inv_inertia = 1.f / (ent->inertia_unscaled * scale);
|
f32 inv_inertia = 1.f / (ent->inertia_unscaled * scale);
|
||||||
@ -546,7 +541,7 @@ void sim_ent_apply_angular_impulse(Entity *ent, f32 impulse)
|
|||||||
|
|
||||||
void sim_ent_apply_torque(Entity *ent, f32 torque)
|
void sim_ent_apply_torque(Entity *ent, f32 torque)
|
||||||
{
|
{
|
||||||
if (sim_ent_has_prop(ent, SEPROP_DYNAMIC)) {
|
if (sim_ent_has_prop(ent, Prop_Dynamic)) {
|
||||||
ent->torque += torque;
|
ent->torque += torque;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -620,7 +615,7 @@ void sim_ent_lerp(Entity *e, Entity *e0, Entity *e1, f64 blend)
|
|||||||
void sim_ent_sync_acquire_tree(Entity *local_parent, Entity *remote, EntityId remote_player)
|
void sim_ent_sync_acquire_tree(Entity *local_parent, Entity *remote, EntityId remote_player)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
if (sim_ent_has_prop(remote, SEPROP_SYNC_SRC)) {
|
if (sim_ent_has_prop(remote, Prop_SyncSrc)) {
|
||||||
Snapshot *local_ss = local_parent->ss;
|
Snapshot *local_ss = local_parent->ss;
|
||||||
Snapshot *remote_ss = remote->ss;
|
Snapshot *remote_ss = remote->ss;
|
||||||
|
|
||||||
@ -661,8 +656,8 @@ void sim_ent_sync(Entity *local, Entity *remote)
|
|||||||
local->prev_in_id_bin = old.prev_in_id_bin;
|
local->prev_in_id_bin = old.prev_in_id_bin;
|
||||||
local->next_free = old.next_free;
|
local->next_free = old.next_free;
|
||||||
|
|
||||||
sim_ent_disable_prop(local, SEPROP_SYNC_SRC);
|
sim_ent_disable_prop(local, Prop_SyncSrc);
|
||||||
sim_ent_enable_prop(local, SEPROP_SYNC_DST);
|
sim_ent_enable_prop(local, Prop_SyncDst);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
146
src/pp/pp_ent.h
146
src/pp/pp_ent.h
@ -1,66 +1,63 @@
|
|||||||
#define SIM_ENT_NIL_ID ((EntityId) { UID(0, 0) })
|
|
||||||
#define SIM_ENT_ROOT_ID ((EntityId) { UID(0xaaaaaaaaaaaaaaaa, 0xaaaaaaaaaaaaaaaa) })
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Entity props
|
//~ Entity props
|
||||||
|
|
||||||
typedef i32 EntProp; enum {
|
typedef i32 Prop; enum {
|
||||||
SEPROP_ACTIVE,
|
Prop_Active,
|
||||||
SEPROP_RELEASE,
|
Prop_Release,
|
||||||
|
|
||||||
SEPROP_SYNC_SRC, /* This entity is networked to other clients */
|
Prop_SyncSrc, /* This entity is networked to other clients */
|
||||||
SEPROP_SYNC_DST, /* This entity is not locally created, and will sync with incoming net src ents */
|
Prop_SyncDst, /* This entity is not locally created, and will sync with incoming net src ents */
|
||||||
|
|
||||||
SEPROP_PLAYER,
|
Prop_Player,
|
||||||
SEPROP_PLAYER_IS_MASTER,
|
Prop_IsMaster,
|
||||||
|
|
||||||
SEPROP_CMD,
|
Prop_Cmd,
|
||||||
|
|
||||||
SEPROP_TILE_CHUNK,
|
Prop_TileChunk,
|
||||||
SEPROP_WALL,
|
Prop_Wall,
|
||||||
|
|
||||||
/* Physics collision */
|
/* Physics collision */
|
||||||
SEPROP_SENSOR, /* This entity's collisions generate contacts */
|
Prop_Sensor, /* This entity's collisions generate contacts */
|
||||||
SEPROP_SOLID, /* This entity's collisions generate contacts to be solved by the physics system (overrides SEPROP_SENSOR) */
|
Prop_Solid, /* This entity's collisions generate contacts to be solved by the physics system (overrides Prop_Sensor) */
|
||||||
SEPROP_TOI, /* This entity's collisions are processed using TOI (time of impact) for precise collisions */
|
Prop_Toi, /* This entity's collisions are processed using TOI (time of impact) for precise collisions */
|
||||||
|
|
||||||
/* Physics movement */
|
/* Physics movement */
|
||||||
SEPROP_KINEMATIC, /* This entity reacts to velocity */
|
Prop_Kinematic, /* This entity reacts to velocity */
|
||||||
SEPROP_DYNAMIC, /* This entity reacts to velocity and forces (overrides SEPROP_KINEMATIC) */
|
Prop_Dynamic, /* This entity reacts to velocity and forces (overrides Prop_Kinematic) */
|
||||||
|
|
||||||
SEPROP_CONTROLLED,
|
Prop_Controlled,
|
||||||
|
|
||||||
SEPROP_COLLISION_DEBUG,
|
Prop_CollisionDebug,
|
||||||
SEPROP_CONTACT_CONSTRAINT,
|
Prop_ContactConstraint,
|
||||||
SEPROP_MOTOR_JOINT,
|
Prop_MotorJoint,
|
||||||
SEPROP_MOUSE_JOINT,
|
Prop_MouseJoint,
|
||||||
SEPROP_WELD_JOINT,
|
Prop_WeldJoint,
|
||||||
|
|
||||||
SEPROP_CAMERA,
|
Prop_Camera,
|
||||||
SEPROP_CAMERA_ACTIVE,
|
Prop_ActiveCamera,
|
||||||
|
|
||||||
SEPROP_BULLET,
|
Prop_Bullet,
|
||||||
SEPROP_WEAPON_SMG,
|
Prop_Smg,
|
||||||
SEPROP_WEAPON_LAUNCHER,
|
Prop_Launcher,
|
||||||
SEPROP_WEAPON_CHUCKER,
|
Prop_Chucker,
|
||||||
|
|
||||||
SEPROP_CHUCKER_ZONE,
|
Prop_ChuckerZone,
|
||||||
|
|
||||||
SEPROP_EXPLOSION,
|
Prop_Explosion,
|
||||||
|
|
||||||
SEPROP_TRACER,
|
Prop_Tracer,
|
||||||
|
|
||||||
SEPROP_QUAKE,
|
Prop_Quake,
|
||||||
|
|
||||||
SEPROP_ATTACHED,
|
Prop_Attached,
|
||||||
|
|
||||||
/* Test props */
|
/* Test props */
|
||||||
|
|
||||||
SEPROP_TEST,
|
Prop_Test,
|
||||||
SEPROP_TEST_SOUND_EMITTER,
|
Prop_SoundEmitterTest,
|
||||||
SEPROP_LIGHT_TEST,
|
Prop_LightTest,
|
||||||
|
|
||||||
SEPROP_COUNT
|
Prop_Count
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@ -73,7 +70,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
b32 valid; /* Is this ent allocated in memory that can be written to (can always be read) */
|
b32 valid; /* Is this ent allocated in memory that can be written to (can always be read) */
|
||||||
EntityId id;
|
EntityId id;
|
||||||
u64 props[(SEPROP_COUNT + 63) / 64];
|
u64 props[(Prop_Count + 63) / 64];
|
||||||
u64 continuity_gen;
|
u64 continuity_gen;
|
||||||
|
|
||||||
/* Is this the root ent */
|
/* Is this the root ent */
|
||||||
@ -99,8 +96,8 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Sync
|
//- Sync
|
||||||
|
|
||||||
/* SEPROP_SYNC_SRC */
|
/* Prop_SyncSrc */
|
||||||
/* SEPROP_SYNC_DST */
|
/* Prop_SyncDst */
|
||||||
|
|
||||||
/* Id of the player that owns simulation for this entity */
|
/* Id of the player that owns simulation for this entity */
|
||||||
EntityId owner;
|
EntityId owner;
|
||||||
@ -127,7 +124,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Cmd
|
//- Cmd
|
||||||
|
|
||||||
/* SEPROP_CMD */
|
/* Prop_Cmd */
|
||||||
|
|
||||||
CmdKind cmd_kind;
|
CmdKind cmd_kind;
|
||||||
EntityId cmd_player;
|
EntityId cmd_player;
|
||||||
@ -143,7 +140,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Chat
|
//- Chat
|
||||||
|
|
||||||
/* SEPROP_CHAT */
|
/* Prop_CHAT */
|
||||||
|
|
||||||
EntityId chat_player;
|
EntityId chat_player;
|
||||||
//String chat_msg;
|
//String chat_msg;
|
||||||
@ -151,7 +148,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Tile
|
//- Tile
|
||||||
|
|
||||||
/* SEPROP_TILE_CHUNK */
|
/* Prop_TileChunk */
|
||||||
|
|
||||||
/* FIXME: Move out of here */
|
/* FIXME: Move out of here */
|
||||||
u8 tile_chunk_tiles[SIM_TILES_PER_CHUNK_SQRT * SIM_TILES_PER_CHUNK_SQRT];
|
u8 tile_chunk_tiles[SIM_TILES_PER_CHUNK_SQRT * SIM_TILES_PER_CHUNK_SQRT];
|
||||||
@ -159,7 +156,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Client
|
//- Client
|
||||||
|
|
||||||
/* SEPROP_PLAYER */
|
/* Prop_Player */
|
||||||
|
|
||||||
/* FIXME: Lerp */
|
/* FIXME: Lerp */
|
||||||
|
|
||||||
@ -193,21 +190,21 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Constraints / joints
|
//- Constraints / joints
|
||||||
|
|
||||||
/* SEPROP_CONSTRAINT_CONTACT */
|
/* Prop_CONSTRAINT_CONTACT */
|
||||||
ContactConstraint contact_constraint_data;
|
ContactConstraint contact_constraint_data;
|
||||||
|
|
||||||
/* SEPROP_MOTOR_JOINT */
|
/* Prop_MotorJoint */
|
||||||
MotorJoint motor_joint_data;
|
MotorJoint motor_joint_data;
|
||||||
|
|
||||||
/* SEPROP_MOUSE_JOINT */
|
/* Prop_MouseJoint */
|
||||||
MouseJoint mouse_joint_data;
|
MouseJoint mouse_joint_data;
|
||||||
|
|
||||||
/* SEPROP_WELD_JOINT */
|
/* Prop_WeldJoint */
|
||||||
WeldJoint weld_joint_data;
|
WeldJoint weld_joint_data;
|
||||||
|
|
||||||
//- Control
|
//- Control
|
||||||
|
|
||||||
/* SEPROP_CONTROLLED */
|
/* Prop_Controlled */
|
||||||
|
|
||||||
EntityId controlling_player;
|
EntityId controlling_player;
|
||||||
|
|
||||||
@ -223,7 +220,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Physics
|
//- Physics
|
||||||
|
|
||||||
/* SEPROP_DYNAMIC */
|
/* Prop_Dynamic */
|
||||||
|
|
||||||
//f32 density; /* Density in kg/m^2 */
|
//f32 density; /* Density in kg/m^2 */
|
||||||
|
|
||||||
@ -259,13 +256,13 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Animation
|
//- Animation
|
||||||
|
|
||||||
/* SEPROP_ANIMATING */
|
/* Prop_ANIMATING */
|
||||||
i64 animation_last_frame_change_time_ns;
|
i64 animation_last_frame_change_time_ns;
|
||||||
u32 animation_frame;
|
u32 animation_frame;
|
||||||
|
|
||||||
//- Attachment
|
//- Attachment
|
||||||
|
|
||||||
/* SEPROP_ATTACHED */
|
/* Prop_Attached */
|
||||||
/* Slice name on the parent ent's sprite to attach to */
|
/* Slice name on the parent ent's sprite to attach to */
|
||||||
String attach_slice;
|
String attach_slice;
|
||||||
|
|
||||||
@ -275,14 +272,14 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Chucker
|
//- Chucker
|
||||||
|
|
||||||
/* SEPROP_WEAPON_CHUCKER */
|
/* Prop_Chucker */
|
||||||
|
|
||||||
EntityId chucker_zone;
|
EntityId chucker_zone;
|
||||||
EntityId chucker_joint;
|
EntityId chucker_joint;
|
||||||
|
|
||||||
//- Chucker zone
|
//- Chucker zone
|
||||||
|
|
||||||
/* SEPROP_CHUCKER_ZONE */
|
/* Prop_ChuckerZone */
|
||||||
|
|
||||||
EntityId chucker_zone_ent;
|
EntityId chucker_zone_ent;
|
||||||
u64 chucker_zone_ent_tick;
|
u64 chucker_zone_ent_tick;
|
||||||
@ -326,7 +323,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Tracer
|
//- Tracer
|
||||||
|
|
||||||
/* SEPROP_TRACER */
|
/* Prop_Tracer */
|
||||||
|
|
||||||
Vec2 tracer_start;
|
Vec2 tracer_start;
|
||||||
Vec2 tracer_start_velocity;
|
Vec2 tracer_start_velocity;
|
||||||
@ -338,7 +335,7 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Quake
|
//- Quake
|
||||||
|
|
||||||
/* SEPROP_QUAKE */
|
/* Prop_Quake */
|
||||||
|
|
||||||
f32 quake_intensity;
|
f32 quake_intensity;
|
||||||
f32 quake_frequency;
|
f32 quake_frequency;
|
||||||
@ -346,19 +343,19 @@ Struct(Entity) {
|
|||||||
|
|
||||||
//- Testing
|
//- Testing
|
||||||
|
|
||||||
/* SEPROP_TEST */
|
/* Prop_Test */
|
||||||
b32 test_initialized;
|
b32 test_initialized;
|
||||||
Xform test_start_local_xform;
|
Xform test_start_local_xform;
|
||||||
Xform test_start_sprite_xform;
|
Xform test_start_sprite_xform;
|
||||||
|
|
||||||
/* SEPROP_TEST_SOUND_EMITTER */
|
/* Prop_SoundEmitterTest */
|
||||||
String sound_name;
|
String sound_name;
|
||||||
MIX_TrackDesc sound_desc;
|
MIX_TrackDesc sound_desc;
|
||||||
MIX_Handle sound_handle;
|
MIX_Handle sound_handle;
|
||||||
|
|
||||||
//- Camera
|
//- Camera
|
||||||
|
|
||||||
/* SEPROP_CAMERA */
|
/* Prop_Camera */
|
||||||
EntityId camera_follow;
|
EntityId camera_follow;
|
||||||
Xform camera_quad_xform;
|
Xform camera_quad_xform;
|
||||||
f32 camera_lerp; /* Rate at which camera xform approaches target xform */
|
f32 camera_lerp; /* Rate at which camera xform approaches target xform */
|
||||||
@ -376,7 +373,7 @@ Struct(EntArray) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Struct(EntPropArray) {
|
Struct(EntPropArray) {
|
||||||
EntProp *props;
|
Prop *props;
|
||||||
u64 count;
|
u64 count;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -391,6 +388,17 @@ Inline Entity *sim_ent_nil(void)
|
|||||||
return *_g_sim_ent_nil;
|
return *_g_sim_ent_nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Id types
|
||||||
|
|
||||||
|
#define SIM_ENT_TILE_CHUNK_BASIS_Uid (UID(0x3ce42de071dd226b, 0x9b566f7df30c813a))
|
||||||
|
#define SIM_ENT_NIL_ID ((EntityId) { UID(0, 0) })
|
||||||
|
#define SIM_ENT_ROOT_ID ((EntityId) { UID(0xaaaaaaaaaaaaaaaa, 0xaaaaaaaaaaaaaaaa) })
|
||||||
|
|
||||||
|
/* Id magic number constants (to be used in conjunction with ent ids in deterministic id combinations) */
|
||||||
|
#define SIM_ENT_CONTACT_BASIS_Uid (UID(0x6a2a5d2dbecf534f, 0x0a8ca7c372a015af))
|
||||||
|
#define SIM_ENT_COLLISION_DEBUG_BASIS_Uid (UID(0x302c01182013bb02, 0x570bd270399d11a5))
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Id helpers
|
//~ Id helpers
|
||||||
|
|
||||||
@ -407,21 +415,21 @@ Inline b32 sim_ent_id_is_nil(EntityId id)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Property helpers
|
//~ Property helpers
|
||||||
|
|
||||||
Inline void sim_ent_enable_prop(Entity *ent, EntProp prop)
|
Inline void sim_ent_enable_prop(Entity *ent, Prop prop)
|
||||||
{
|
{
|
||||||
u64 index = prop / 64;
|
u64 index = prop / 64;
|
||||||
u64 bit = prop % 64;
|
u64 bit = prop % 64;
|
||||||
ent->props[index] |= ((u64)1 << bit);
|
ent->props[index] |= ((u64)1 << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Inline void sim_ent_disable_prop(Entity *ent, EntProp prop)
|
Inline void sim_ent_disable_prop(Entity *ent, Prop prop)
|
||||||
{
|
{
|
||||||
u64 index = prop / 64;
|
u64 index = prop / 64;
|
||||||
u64 bit = prop % 64;
|
u64 bit = prop % 64;
|
||||||
ent->props[index] &= ~((u64)1 << bit);
|
ent->props[index] &= ~((u64)1 << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Inline b32 sim_ent_has_prop(Entity *ent, EntProp prop)
|
Inline b32 sim_ent_has_prop(Entity *ent, Prop prop)
|
||||||
{
|
{
|
||||||
u64 index = prop / 64;
|
u64 index = prop / 64;
|
||||||
u64 bit = prop % 64;
|
u64 bit = prop % 64;
|
||||||
@ -430,7 +438,7 @@ Inline b32 sim_ent_has_prop(Entity *ent, EntProp prop)
|
|||||||
|
|
||||||
Inline b32 sim_ent_is_valid_and_active(Entity *ent)
|
Inline b32 sim_ent_is_valid_and_active(Entity *ent)
|
||||||
{
|
{
|
||||||
return ent->valid && sim_ent_has_prop(ent, SEPROP_ACTIVE);
|
return ent->valid && sim_ent_has_prop(ent, Prop_Active);
|
||||||
}
|
}
|
||||||
|
|
||||||
Inline b32 sim_ent_should_predict(Entity *ent)
|
Inline b32 sim_ent_should_predict(Entity *ent)
|
||||||
@ -448,7 +456,7 @@ Inline b32 sim_ent_should_simulate(Entity *ent)
|
|||||||
b32 result = 0;
|
b32 result = 0;
|
||||||
if (sim_ent_is_valid_and_active(ent)) {
|
if (sim_ent_is_valid_and_active(ent)) {
|
||||||
result = 1;
|
result = 1;
|
||||||
if (sim_ent_has_prop(ent, SEPROP_SYNC_DST)) {
|
if (sim_ent_has_prop(ent, Prop_SyncDst)) {
|
||||||
EntityId local_player = ent->ss->local_player;
|
EntityId local_player = ent->ss->local_player;
|
||||||
result = sim_ent_id_eq(local_player, ent->owner) || sim_ent_id_eq(local_player, ent->predictor);
|
result = sim_ent_id_eq(local_player, ent->owner) || sim_ent_id_eq(local_player, ent->predictor);
|
||||||
}
|
}
|
||||||
@ -471,7 +479,7 @@ Entity *sim_ent_acquire_sync_dst(Entity *parent, EntityId ent_id, EntityId owner
|
|||||||
|
|
||||||
void sim_ent_release_raw(Entity *ent);
|
void sim_ent_release_raw(Entity *ent);
|
||||||
void sim_ent_release(Entity *ent);
|
void sim_ent_release(Entity *ent);
|
||||||
void sim_ent_release_all_with_prop(Snapshot *ss, EntProp prop);
|
void sim_ent_release_all_with_prop(Snapshot *ss, Prop prop);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Activate operations
|
//~ Activate operations
|
||||||
@ -494,7 +502,7 @@ EntityId sim_ent_tile_chunk_id_from_tile_chunk_index(Vec2I32 chunk_start);
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Query operations
|
//~ Query operations
|
||||||
|
|
||||||
Entity *sim_ent_find_first_match_one(Snapshot *ss, EntProp prop);
|
Entity *sim_ent_find_first_match_one(Snapshot *ss, Prop prop);
|
||||||
Entity *sim_ent_find_first_match_all(Snapshot *ss, EntPropArray props);
|
Entity *sim_ent_find_first_match_all(Snapshot *ss, EntPropArray props);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
@ -10,7 +10,7 @@ internal b32 can_contact(Entity *e0, Entity *e1)
|
|||||||
b32 result = 0;
|
b32 result = 0;
|
||||||
result = e0 != e1 &&
|
result = e0 != e1 &&
|
||||||
!sim_ent_id_eq(e0->top, e1->top) &&
|
!sim_ent_id_eq(e0->top, e1->top) &&
|
||||||
!(sim_ent_has_prop(e0, SEPROP_WALL) && sim_ent_has_prop(e1, SEPROP_WALL));
|
!(sim_ent_has_prop(e0, Prop_Wall) && sim_ent_has_prop(e1, Prop_Wall));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
|||||||
for (u64 check0_index = 0; check0_index < ss->num_ents_reserved; ++check0_index) {
|
for (u64 check0_index = 0; check0_index < ss->num_ents_reserved; ++check0_index) {
|
||||||
Entity *check0 = &ss->ents[check0_index];
|
Entity *check0 = &ss->ents[check0_index];
|
||||||
if (!sim_ent_is_valid_and_active(check0)) continue;
|
if (!sim_ent_is_valid_and_active(check0)) continue;
|
||||||
if (!(sim_ent_has_prop(check0, SEPROP_SOLID) || sim_ent_has_prop(check0, SEPROP_SENSOR))) continue;
|
if (!(sim_ent_has_prop(check0, Prop_Solid) || sim_ent_has_prop(check0, Prop_Sensor))) continue;
|
||||||
if (check0->local_collider.count <= 0) continue;
|
if (check0->local_collider.count <= 0) continue;
|
||||||
|
|
||||||
Xform check0_xf = sim_ent_get_xform(check0);
|
Xform check0_xf = sim_ent_get_xform(check0);
|
||||||
@ -41,7 +41,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
|||||||
while ((space_entry = space_iter_next(&iter)) != 0) {
|
while ((space_entry = space_iter_next(&iter)) != 0) {
|
||||||
Entity *check1 = sim_ent_from_id(ss, space_entry->ent);
|
Entity *check1 = sim_ent_from_id(ss, space_entry->ent);
|
||||||
if (!sim_ent_is_valid_and_active(check1)) continue;
|
if (!sim_ent_is_valid_and_active(check1)) continue;
|
||||||
if (!(sim_ent_has_prop(check1, SEPROP_SOLID) || sim_ent_has_prop(check1, SEPROP_SENSOR))) continue;
|
if (!(sim_ent_has_prop(check1, Prop_Solid) || sim_ent_has_prop(check1, Prop_Sensor))) continue;
|
||||||
if (check1->local_collider.count <= 0) continue;
|
if (check1->local_collider.count <= 0) continue;
|
||||||
if (!can_contact(check0, check1)) continue;
|
if (!can_contact(check0, check1)) continue;
|
||||||
|
|
||||||
@ -97,12 +97,12 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
|||||||
constraint_ent->contact_constraint_data.e0 = e0->id;
|
constraint_ent->contact_constraint_data.e0 = e0->id;
|
||||||
constraint_ent->contact_constraint_data.e1 = e1->id;
|
constraint_ent->contact_constraint_data.e1 = e1->id;
|
||||||
/* Both entities must be solid and one must be dynamic for a solve to be necessary. */
|
/* Both entities must be solid and one must be dynamic for a solve to be necessary. */
|
||||||
constraint_ent->contact_constraint_data.skip_solve = !sim_ent_has_prop(e0, SEPROP_SOLID) || !sim_ent_has_prop(e1, SEPROP_SOLID) ||
|
constraint_ent->contact_constraint_data.skip_solve = !sim_ent_has_prop(e0, Prop_Solid) || !sim_ent_has_prop(e1, Prop_Solid) ||
|
||||||
!(sim_ent_has_prop(e0, SEPROP_DYNAMIC) || sim_ent_has_prop(e1, SEPROP_DYNAMIC));
|
!(sim_ent_has_prop(e0, Prop_Dynamic) || sim_ent_has_prop(e1, Prop_Dynamic));
|
||||||
sim_ent_enable_prop(constraint_ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(constraint_ent, Prop_Active);
|
||||||
|
|
||||||
/* TODO: Should we recalculate normal as more contact points are added? */
|
/* TODO: Should we recalculate normal as more contact points are added? */
|
||||||
sim_ent_enable_prop(constraint_ent, SEPROP_CONTACT_CONSTRAINT);
|
sim_ent_enable_prop(constraint_ent, Prop_ContactConstraint);
|
||||||
sim_ent_activate(constraint_ent, tick);
|
sim_ent_activate(constraint_ent, tick);
|
||||||
}
|
}
|
||||||
constraint = &constraint_ent->contact_constraint_data;
|
constraint = &constraint_ent->contact_constraint_data;
|
||||||
@ -233,7 +233,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
|
|||||||
if (!dbg_ent->valid) {
|
if (!dbg_ent->valid) {
|
||||||
/* FIXME: Entity never released */
|
/* FIXME: Entity never released */
|
||||||
dbg_ent = sim_ent_acquire_local_with_id(root, dbg_ent_id);
|
dbg_ent = sim_ent_acquire_local_with_id(root, dbg_ent_id);
|
||||||
sim_ent_enable_prop(dbg_ent, SEPROP_COLLISION_DEBUG);
|
sim_ent_enable_prop(dbg_ent, Prop_CollisionDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
CollisionDebugData *dbg = &dbg_ent->collision_debug_data;
|
CollisionDebugData *dbg = &dbg_ent->collision_debug_data;
|
||||||
@ -273,7 +273,7 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *constraint_ent = &ss->ents[sim_ent_index];
|
Entity *constraint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(constraint_ent)) continue;
|
if (!sim_ent_should_simulate(constraint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(constraint_ent, SEPROP_CONTACT_CONSTRAINT)) continue;
|
if (!sim_ent_has_prop(constraint_ent, Prop_ContactConstraint)) continue;
|
||||||
|
|
||||||
ContactConstraint *constraint = &constraint_ent->contact_constraint_data;
|
ContactConstraint *constraint = &constraint_ent->contact_constraint_data;
|
||||||
|
|
||||||
@ -295,14 +295,14 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
|||||||
f32 inv_i1 = 0;
|
f32 inv_i1 = 0;
|
||||||
{
|
{
|
||||||
/* If not simulated locally or ent is not dynamic, pretend contact mass is infinite */
|
/* If not simulated locally or ent is not dynamic, pretend contact mass is infinite */
|
||||||
if (sim_ent_should_simulate(e0) && sim_ent_has_prop(e0, SEPROP_DYNAMIC)) {
|
if (sim_ent_should_simulate(e0) && sim_ent_has_prop(e0, Prop_Dynamic)) {
|
||||||
f32 scale = AbsF32(DeterminantFromXform(e0_xf));
|
f32 scale = AbsF32(DeterminantFromXform(e0_xf));
|
||||||
f32 scaled_mass = e0->mass_unscaled * scale;
|
f32 scaled_mass = e0->mass_unscaled * scale;
|
||||||
f32 scaled_inertia = e0->inertia_unscaled * scale;
|
f32 scaled_inertia = e0->inertia_unscaled * scale;
|
||||||
inv_m0 = 1.f / scaled_mass;
|
inv_m0 = 1.f / scaled_mass;
|
||||||
inv_i0 = 1.f / scaled_inertia;
|
inv_i0 = 1.f / scaled_inertia;
|
||||||
}
|
}
|
||||||
if (sim_ent_should_simulate(e1) && sim_ent_has_prop(e1, SEPROP_DYNAMIC)) {
|
if (sim_ent_should_simulate(e1) && sim_ent_has_prop(e1, Prop_Dynamic)) {
|
||||||
f32 scale = AbsF32(DeterminantFromXform(e1_xf));
|
f32 scale = AbsF32(DeterminantFromXform(e1_xf));
|
||||||
f32 scaled_mass = e1->mass_unscaled * scale;
|
f32 scaled_mass = e1->mass_unscaled * scale;
|
||||||
f32 scaled_inertia = e1->inertia_unscaled * scale;
|
f32 scaled_inertia = e1->inertia_unscaled * scale;
|
||||||
@ -346,8 +346,8 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
|||||||
} else {
|
} else {
|
||||||
/* Mark constraint for removal */
|
/* Mark constraint for removal */
|
||||||
constraint_ent->contact_constraint_data.num_points = 0;
|
constraint_ent->contact_constraint_data.num_points = 0;
|
||||||
sim_ent_disable_prop(constraint_ent, SEPROP_ACTIVE);
|
sim_ent_disable_prop(constraint_ent, Prop_Active);
|
||||||
sim_ent_enable_prop(constraint_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(constraint_ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,18 +357,18 @@ void phys_prepare_contacts(PhysStepCtx *ctx, u64 phys_iteration)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *dbg_ent = &ss->ents[sim_ent_index];
|
Entity *dbg_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(dbg_ent)) continue;
|
if (!sim_ent_should_simulate(dbg_ent)) continue;
|
||||||
if (!sim_ent_has_prop(dbg_ent, SEPROP_COLLISION_DEBUG)) continue;
|
if (!sim_ent_has_prop(dbg_ent, Prop_CollisionDebug)) continue;
|
||||||
|
|
||||||
CollisionDebugData *dbg = &dbg_ent->collision_debug_data;
|
CollisionDebugData *dbg = &dbg_ent->collision_debug_data;
|
||||||
Entity *e0 = sim_ent_from_id(ss, dbg->e0);
|
Entity *e0 = sim_ent_from_id(ss, dbg->e0);
|
||||||
Entity *e1 = sim_ent_from_id(ss, dbg->e1);
|
Entity *e1 = sim_ent_from_id(ss, dbg->e1);
|
||||||
|
|
||||||
if (!(sim_ent_should_simulate(e0) && sim_ent_should_simulate(e1)) ||
|
if (!(sim_ent_should_simulate(e0) && sim_ent_should_simulate(e1)) ||
|
||||||
!(sim_ent_has_prop(e0, SEPROP_SOLID) || sim_ent_has_prop(e0, SEPROP_SENSOR)) ||
|
!(sim_ent_has_prop(e0, Prop_Solid) || sim_ent_has_prop(e0, Prop_Sensor)) ||
|
||||||
!(sim_ent_has_prop(e1, SEPROP_SOLID) || sim_ent_has_prop(e1, SEPROP_SENSOR))) {
|
!(sim_ent_has_prop(e1, Prop_Solid) || sim_ent_has_prop(e1, Prop_Sensor))) {
|
||||||
/* Mark dbg ent for removal */
|
/* Mark dbg ent for removal */
|
||||||
sim_ent_disable_prop(dbg_ent, SEPROP_ACTIVE);
|
sim_ent_disable_prop(dbg_ent, Prop_Active);
|
||||||
sim_ent_enable_prop(dbg_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(dbg_ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -382,7 +382,7 @@ void phys_warm_start_contacts(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *constraint_ent = &ss->ents[sim_ent_index];
|
Entity *constraint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(constraint_ent)) continue;
|
if (!sim_ent_should_simulate(constraint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(constraint_ent, SEPROP_CONTACT_CONSTRAINT)) continue;
|
if (!sim_ent_has_prop(constraint_ent, Prop_ContactConstraint)) continue;
|
||||||
|
|
||||||
ContactConstraint *constraint = &constraint_ent->contact_constraint_data;
|
ContactConstraint *constraint = &constraint_ent->contact_constraint_data;
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ void phys_solve_contacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *constraint_ent = &ss->ents[sim_ent_index];
|
Entity *constraint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(constraint_ent)) continue;
|
if (!sim_ent_should_simulate(constraint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(constraint_ent, SEPROP_CONTACT_CONSTRAINT)) continue;
|
if (!sim_ent_has_prop(constraint_ent, Prop_ContactConstraint)) continue;
|
||||||
|
|
||||||
ContactConstraint *constraint = &constraint_ent->contact_constraint_data;
|
ContactConstraint *constraint = &constraint_ent->contact_constraint_data;
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ void phys_prepare_motor_joints(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_MOTOR_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_MotorJoint)) continue;
|
||||||
|
|
||||||
MotorJoint *joint = &joint_ent->motor_joint_data;
|
MotorJoint *joint = &joint_ent->motor_joint_data;
|
||||||
|
|
||||||
@ -623,8 +623,8 @@ void phys_prepare_motor_joints(PhysStepCtx *ctx)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Mark joint for removal */
|
/* Mark joint for removal */
|
||||||
sim_ent_disable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_disable_prop(joint_ent, Prop_Active);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(joint_ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -636,7 +636,7 @@ void phys_warm_start_motor_joints(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_MOTOR_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_MotorJoint)) continue;
|
||||||
|
|
||||||
MotorJoint *joint = &joint_ent->motor_joint_data;
|
MotorJoint *joint = &joint_ent->motor_joint_data;
|
||||||
|
|
||||||
@ -668,7 +668,7 @@ void phys_solve_motor_joints(PhysStepCtx *ctx, f32 dt)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_MOTOR_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_MotorJoint)) continue;
|
||||||
|
|
||||||
MotorJoint *joint = &joint_ent->motor_joint_data;
|
MotorJoint *joint = &joint_ent->motor_joint_data;
|
||||||
|
|
||||||
@ -774,7 +774,7 @@ void phys_prepare_mouse_joints(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_MOUSE_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_MouseJoint)) continue;
|
||||||
|
|
||||||
MouseJoint *joint = &joint_ent->mouse_joint_data;
|
MouseJoint *joint = &joint_ent->mouse_joint_data;
|
||||||
Entity *ent = sim_ent_from_id(ss, joint->target);
|
Entity *ent = sim_ent_from_id(ss, joint->target);
|
||||||
@ -808,8 +808,8 @@ void phys_prepare_mouse_joints(PhysStepCtx *ctx)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Mark joint for removal */
|
/* Mark joint for removal */
|
||||||
sim_ent_disable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_disable_prop(joint_ent, Prop_Active);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(joint_ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -821,7 +821,7 @@ void phys_warm_start_mouse_joints(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_MOUSE_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_MouseJoint)) continue;
|
||||||
|
|
||||||
MouseJoint *joint = &joint_ent->mouse_joint_data;
|
MouseJoint *joint = &joint_ent->mouse_joint_data;
|
||||||
Entity *ent = sim_ent_from_id(ss, joint->target);
|
Entity *ent = sim_ent_from_id(ss, joint->target);
|
||||||
@ -843,7 +843,7 @@ void phys_solve_mouse_joints(PhysStepCtx *ctx, f32 dt)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_MOUSE_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_MouseJoint)) continue;
|
||||||
|
|
||||||
MouseJoint *joint = &joint_ent->mouse_joint_data;
|
MouseJoint *joint = &joint_ent->mouse_joint_data;
|
||||||
Entity *ent = sim_ent_from_id(ss, joint->target);
|
Entity *ent = sim_ent_from_id(ss, joint->target);
|
||||||
@ -939,7 +939,7 @@ void phys_prepare_weld_joints(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_WELD_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_WeldJoint)) continue;
|
||||||
|
|
||||||
/* TODO: Lookup and disable collision for any contacts between e0 & e1? */
|
/* TODO: Lookup and disable collision for any contacts between e0 & e1? */
|
||||||
|
|
||||||
@ -975,8 +975,8 @@ void phys_prepare_weld_joints(PhysStepCtx *ctx)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Mark joint for removal */
|
/* Mark joint for removal */
|
||||||
sim_ent_disable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_disable_prop(joint_ent, Prop_Active);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(joint_ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -988,7 +988,7 @@ void phys_warm_start_weld_joints(PhysStepCtx *ctx)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_WELD_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_WeldJoint)) continue;
|
||||||
|
|
||||||
WeldJoint *joint = &joint_ent->weld_joint_data;
|
WeldJoint *joint = &joint_ent->weld_joint_data;
|
||||||
|
|
||||||
@ -1025,7 +1025,7 @@ void phys_solve_weld_joints(PhysStepCtx *ctx, f32 dt)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *joint_ent = &ss->ents[sim_ent_index];
|
Entity *joint_ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(joint_ent)) continue;
|
if (!sim_ent_should_simulate(joint_ent)) continue;
|
||||||
if (!sim_ent_has_prop(joint_ent, SEPROP_WELD_JOINT)) continue;
|
if (!sim_ent_has_prop(joint_ent, Prop_WeldJoint)) continue;
|
||||||
|
|
||||||
WeldJoint *joint = &joint_ent->weld_joint_data;
|
WeldJoint *joint = &joint_ent->weld_joint_data;
|
||||||
Entity *e0 = sim_ent_from_id(ss, joint->e0);
|
Entity *e0 = sim_ent_from_id(ss, joint->e0);
|
||||||
@ -1106,8 +1106,8 @@ void phys_integrate_forces(PhysStepCtx *ctx, f32 dt)
|
|||||||
Entity *ent = &ss->ents[sim_ent_index];
|
Entity *ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
|
|
||||||
b32 is_dynamic = sim_ent_has_prop(ent, SEPROP_DYNAMIC);
|
b32 is_dynamic = sim_ent_has_prop(ent, Prop_Dynamic);
|
||||||
b32 is_kinematic = sim_ent_has_prop(ent, SEPROP_KINEMATIC);
|
b32 is_kinematic = sim_ent_has_prop(ent, Prop_Kinematic);
|
||||||
if (is_dynamic || is_kinematic) {
|
if (is_dynamic || is_kinematic) {
|
||||||
Vec2 linear_velocity = ent->linear_velocity;
|
Vec2 linear_velocity = ent->linear_velocity;
|
||||||
f32 angular_velocity = ent->angular_velocity;
|
f32 angular_velocity = ent->angular_velocity;
|
||||||
@ -1147,7 +1147,7 @@ void phys_integrate_velocities(PhysStepCtx *ctx, f32 dt)
|
|||||||
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) {
|
||||||
Entity *ent = &ss->ents[sim_ent_index];
|
Entity *ent = &ss->ents[sim_ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_DYNAMIC) && !sim_ent_has_prop(ent, SEPROP_KINEMATIC)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Dynamic) && !sim_ent_has_prop(ent, Prop_Kinematic)) continue;
|
||||||
|
|
||||||
Xform xf = get_derived_xform(ent, dt);
|
Xform xf = get_derived_xform(ent, dt);
|
||||||
sim_ent_set_xform(ent, xf);
|
sim_ent_set_xform(ent, xf);
|
||||||
@ -1168,8 +1168,8 @@ f32 phys_determine_earliest_toi(PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u3
|
|||||||
for (u64 e0_index = 0; e0_index < ss->num_ents_reserved; ++e0_index) {
|
for (u64 e0_index = 0; e0_index < ss->num_ents_reserved; ++e0_index) {
|
||||||
Entity *e0 = &ss->ents[e0_index];
|
Entity *e0 = &ss->ents[e0_index];
|
||||||
if (!sim_ent_should_simulate(e0)) continue;
|
if (!sim_ent_should_simulate(e0)) continue;
|
||||||
if (!(sim_ent_has_prop(e0, SEPROP_SOLID) || sim_ent_has_prop(e0, SEPROP_SENSOR))) continue;
|
if (!(sim_ent_has_prop(e0, Prop_Solid) || sim_ent_has_prop(e0, Prop_Sensor))) continue;
|
||||||
if (!sim_ent_has_prop(e0, SEPROP_TOI)) continue;
|
if (!sim_ent_has_prop(e0, Prop_Toi)) continue;
|
||||||
if (e0->local_collider.count <= 0) continue;
|
if (e0->local_collider.count <= 0) continue;
|
||||||
|
|
||||||
CLD_Shape e0_collider = e0->local_collider;
|
CLD_Shape e0_collider = e0->local_collider;
|
||||||
@ -1186,7 +1186,7 @@ f32 phys_determine_earliest_toi(PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u3
|
|||||||
while ((entry = space_iter_next(&iter)) != 0) {
|
while ((entry = space_iter_next(&iter)) != 0) {
|
||||||
Entity *e1 = sim_ent_from_id(ss, entry->ent);
|
Entity *e1 = sim_ent_from_id(ss, entry->ent);
|
||||||
if (!sim_ent_should_simulate(e1)) continue;
|
if (!sim_ent_should_simulate(e1)) continue;
|
||||||
if (!(sim_ent_has_prop(e1, SEPROP_SOLID) || sim_ent_has_prop(e1, SEPROP_SENSOR))) continue;
|
if (!(sim_ent_has_prop(e1, Prop_Solid) || sim_ent_has_prop(e1, Prop_Sensor))) continue;
|
||||||
if (e1->local_collider.count <= 0) continue;
|
if (e1->local_collider.count <= 0) continue;
|
||||||
if (!can_contact(e0, e1)) continue;
|
if (!can_contact(e0, e1)) continue;
|
||||||
|
|
||||||
|
|||||||
@ -597,7 +597,7 @@ void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile
|
|||||||
if (!chunk_ent->valid) {
|
if (!chunk_ent->valid) {
|
||||||
Entity *root = sim_ent_from_id(ss, SIM_ENT_ROOT_ID);
|
Entity *root = sim_ent_from_id(ss, SIM_ENT_ROOT_ID);
|
||||||
chunk_ent = sim_ent_acquire_sync_src_with_id(root, chunk_id);
|
chunk_ent = sim_ent_acquire_sync_src_with_id(root, chunk_id);
|
||||||
sim_ent_enable_prop(chunk_ent, SEPROP_TILE_CHUNK);
|
sim_ent_enable_prop(chunk_ent, Prop_TileChunk);
|
||||||
chunk_ent->tile_chunk_index = chunk_index;
|
chunk_ent->tile_chunk_index = chunk_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -680,7 +680,7 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re
|
|||||||
/* Sync ents with remote, skipping index 0 (nil) & index 1 (root) */
|
/* Sync ents with remote, skipping index 0 (nil) & index 1 (root) */
|
||||||
for (u64 i = 2; i < local_ss->num_ents_reserved; ++i) {
|
for (u64 i = 2; i < local_ss->num_ents_reserved; ++i) {
|
||||||
Entity *local_ent = &local_ss->ents[i];
|
Entity *local_ent = &local_ss->ents[i];
|
||||||
if (local_ent->valid && sim_ent_has_prop(local_ent, SEPROP_SYNC_DST)) {
|
if (local_ent->valid && sim_ent_has_prop(local_ent, Prop_SyncDst)) {
|
||||||
b32 should_sync = sim_ent_id_eq(local_ent->owner, remote_player) || sim_ent_id_is_nil(remote_player);
|
b32 should_sync = sim_ent_id_eq(local_ent->owner, remote_player) || sim_ent_id_is_nil(remote_player);
|
||||||
if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && sim_ent_id_eq(local_ent->predictor, local_ss->local_player)) {
|
if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && sim_ent_id_eq(local_ent->predictor, local_ss->local_player)) {
|
||||||
should_sync = 0;
|
should_sync = 0;
|
||||||
@ -692,13 +692,13 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re
|
|||||||
sim_ent_sync(local_ent, remote_ent);
|
sim_ent_sync(local_ent, remote_ent);
|
||||||
} else {
|
} else {
|
||||||
/* Remote ent is no longer valid / networked, release it */
|
/* Remote ent is no longer valid / networked, release it */
|
||||||
sim_ent_enable_prop(local_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(local_ent, Prop_Release);
|
||||||
sim_ent_disable_prop(local_ent, SEPROP_SYNC_DST);
|
sim_ent_disable_prop(local_ent, Prop_SyncDst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim_ent_release_all_with_prop(local_ss, SEPROP_RELEASE);
|
sim_ent_release_all_with_prop(local_ss, Prop_Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -984,7 +984,7 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss)
|
|||||||
Entity *e = sim_ent_from_index(ss, e);
|
Entity *e = sim_ent_from_index(ss, e);
|
||||||
Assert(e->valid); /* An entity that we don't have allocated should never have been marked for release */
|
Assert(e->valid); /* An entity that we don't have allocated should never have been marked for release */
|
||||||
if (e->valid) {
|
if (e->valid) {
|
||||||
sim_ent_enable_prop(e, SEPROP_RELEASE);
|
sim_ent_enable_prop(e, Prop_Release);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alloc_parent_index = BB_ReadUV();
|
alloc_parent_index = BB_ReadUV();
|
||||||
@ -1070,7 +1070,7 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss)
|
|||||||
if (BB_ReadBit(br)) {
|
if (BB_ReadBit(br)) {
|
||||||
struct sim_ent_decode_node *n = PushStruct(scratch.arena, struct sim_ent_decode_node)
|
struct sim_ent_decode_node *n = PushStruct(scratch.arena, struct sim_ent_decode_node)
|
||||||
} else {
|
} else {
|
||||||
sim_ent_enable_prop(e, SEPROP_RELEASE);
|
sim_ent_enable_prop(e, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1089,13 +1089,13 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss)
|
|||||||
/* Why is an already released ent being marked as released? */
|
/* Why is an already released ent being marked as released? */
|
||||||
Assert(e->valid);
|
Assert(e->valid);
|
||||||
if (e->valid) {
|
if (e->valid) {
|
||||||
sim_ent_enable_prop(e, SEPROP_RELEASE);
|
sim_ent_enable_prop(e, Prop_Release);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sim_ent_decode(br, e);
|
sim_ent_decode(br, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim_ent_release_all_with_prop(ss, SEPROP_RELEASE);
|
sim_ent_release_all_with_prop(ss, Prop_Release);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
|
|||||||
206
src/pp/pp_step.c
206
src/pp/pp_step.c
@ -36,11 +36,11 @@ Entity *SpawnTestSmg(Entity *parent)
|
|||||||
Entity *e = sim_ent_acquire_sync_src(parent);
|
Entity *e = sim_ent_acquire_sync_src(parent);
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
|
e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_ATTACHED);
|
sim_ent_enable_prop(e, Prop_Attached);
|
||||||
e->attach_slice = Lit("attach.wep");
|
e->attach_slice = Lit("attach.wep");
|
||||||
e->layer = SIM_LAYER_RELATIVE_WEAPON;
|
e->layer = SIM_LAYER_RELATIVE_WEAPON;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_WEAPON_SMG);
|
sim_ent_enable_prop(e, Prop_Smg);
|
||||||
e->primary_fire_delay = 1.0f / 10.0f;
|
e->primary_fire_delay = 1.0f / 10.0f;
|
||||||
e->secondary_fire_delay = 1.0f / 10.0f;
|
e->secondary_fire_delay = 1.0f / 10.0f;
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ Entity *SpawnTestLauncher(Entity *parent)
|
|||||||
Entity *e = sim_ent_acquire_sync_src(parent);
|
Entity *e = sim_ent_acquire_sync_src(parent);
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
|
e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_ATTACHED);
|
sim_ent_enable_prop(e, Prop_Attached);
|
||||||
e->attach_slice = Lit("attach.wep");
|
e->attach_slice = Lit("attach.wep");
|
||||||
e->layer = SIM_LAYER_RELATIVE_WEAPON;
|
e->layer = SIM_LAYER_RELATIVE_WEAPON;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_WEAPON_LAUNCHER);
|
sim_ent_enable_prop(e, Prop_Launcher);
|
||||||
e->primary_fire_delay = 1.0f / 10.0f;
|
e->primary_fire_delay = 1.0f / 10.0f;
|
||||||
e->secondary_fire_delay = 1.0f / 10.0f;
|
e->secondary_fire_delay = 1.0f / 10.0f;
|
||||||
|
|
||||||
@ -68,11 +68,11 @@ Entity *SpawnTestChucker(Entity *parent)
|
|||||||
Entity *chucker = sim_ent_acquire_sync_src(parent);
|
Entity *chucker = sim_ent_acquire_sync_src(parent);
|
||||||
chucker->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
|
chucker->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
|
||||||
|
|
||||||
sim_ent_enable_prop(chucker, SEPROP_ATTACHED);
|
sim_ent_enable_prop(chucker, Prop_Attached);
|
||||||
chucker->attach_slice = Lit("attach.wep");
|
chucker->attach_slice = Lit("attach.wep");
|
||||||
chucker->layer = SIM_LAYER_RELATIVE_WEAPON;
|
chucker->layer = SIM_LAYER_RELATIVE_WEAPON;
|
||||||
|
|
||||||
sim_ent_enable_prop(chucker, SEPROP_WEAPON_CHUCKER);
|
sim_ent_enable_prop(chucker, Prop_Chucker);
|
||||||
chucker->primary_fire_delay = 1.0f / 10.0f;
|
chucker->primary_fire_delay = 1.0f / 10.0f;
|
||||||
chucker->secondary_fire_delay = 1.0f / 2.0f;
|
chucker->secondary_fire_delay = 1.0f / 2.0f;
|
||||||
|
|
||||||
@ -80,12 +80,12 @@ Entity *SpawnTestChucker(Entity *parent)
|
|||||||
{
|
{
|
||||||
Entity *zone = sim_ent_acquire_sync_src(chucker);
|
Entity *zone = sim_ent_acquire_sync_src(chucker);
|
||||||
|
|
||||||
sim_ent_enable_prop(zone, SEPROP_CHUCKER_ZONE);
|
sim_ent_enable_prop(zone, Prop_ChuckerZone);
|
||||||
|
|
||||||
sim_ent_enable_prop(zone, SEPROP_ATTACHED);
|
sim_ent_enable_prop(zone, Prop_Attached);
|
||||||
zone->attach_slice = Lit("out");
|
zone->attach_slice = Lit("out");
|
||||||
|
|
||||||
sim_ent_enable_prop(zone, SEPROP_SENSOR);
|
sim_ent_enable_prop(zone, Prop_Sensor);
|
||||||
CLD_Shape collider = ZI;
|
CLD_Shape collider = ZI;
|
||||||
collider.count = 2;
|
collider.count = 2;
|
||||||
collider.points[1] = VEC2(0, -0.5);
|
collider.points[1] = VEC2(0, -0.5);
|
||||||
@ -116,7 +116,7 @@ Entity *SpawnTestEmployee(Entity *parent)
|
|||||||
f32 r = 0;
|
f32 r = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
sim_ent_enable_prop(e, SEPROP_TEST);
|
sim_ent_enable_prop(e, Prop_Test);
|
||||||
e->sprite = S_TagFromPath(Lit("sprite/tim.ase"));
|
e->sprite = S_TagFromPath(Lit("sprite/tim.ase"));
|
||||||
e->mass_unscaled = 10;
|
e->mass_unscaled = 10;
|
||||||
e->inertia_unscaled = 5;
|
e->inertia_unscaled = 5;
|
||||||
@ -145,7 +145,7 @@ Entity *SpawnTestEmployee(Entity *parent)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
sim_ent_enable_prop(e, Prop_LightTest);
|
||||||
e->sprite_emittance = VEC3(1, 1, 1);
|
e->sprite_emittance = VEC3(1, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
@ -160,8 +160,8 @@ Entity *SpawnTestEmployee(Entity *parent)
|
|||||||
//e->control_torque = 5000;
|
//e->control_torque = 5000;
|
||||||
e->control_torque = F32Infinity;
|
e->control_torque = F32Infinity;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_DYNAMIC);
|
sim_ent_enable_prop(e, Prop_Dynamic);
|
||||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
sim_ent_enable_prop(e, Prop_Solid);
|
||||||
|
|
||||||
employee = e;
|
employee = e;
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ Entity *SpawnTestEmployee(Entity *parent)
|
|||||||
Entity *e = SpawnTestChucker(employee);
|
Entity *e = SpawnTestChucker(employee);
|
||||||
employee->equipped = e->id;
|
employee->equipped = e->id;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
sim_ent_enable_prop(e, Prop_LightTest);
|
||||||
e->sprite_emittance = VEC3(1, 1, 1);
|
e->sprite_emittance = VEC3(1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,8 +189,8 @@ Entity *SpawnTestCamera(Entity *parent, Entity *follow)
|
|||||||
camera_ent = sim_ent_acquire_sync_src(parent);
|
camera_ent = sim_ent_acquire_sync_src(parent);
|
||||||
sim_ent_set_xform(camera_ent, XformIdentity);
|
sim_ent_set_xform(camera_ent, XformIdentity);
|
||||||
|
|
||||||
sim_ent_enable_prop(camera_ent, SEPROP_CAMERA);
|
sim_ent_enable_prop(camera_ent, Prop_Camera);
|
||||||
sim_ent_enable_prop(camera_ent, SEPROP_CAMERA_ACTIVE);
|
sim_ent_enable_prop(camera_ent, Prop_ActiveCamera);
|
||||||
camera_ent->camera_follow = follow->id;
|
camera_ent->camera_follow = follow->id;
|
||||||
|
|
||||||
f32 width = (f32)DEFAULT_CAMERA_WIDTH;
|
f32 width = (f32)DEFAULT_CAMERA_WIDTH;
|
||||||
@ -206,11 +206,11 @@ Entity *SpawnTestExplosion(Entity *parent, Vec2 pos, f32 strength, f32 radius)
|
|||||||
Entity *ent = sim_ent_acquire_sync_src(parent);
|
Entity *ent = sim_ent_acquire_sync_src(parent);
|
||||||
sim_ent_set_xform(ent, XformFromPos(pos));
|
sim_ent_set_xform(ent, XformFromPos(pos));
|
||||||
|
|
||||||
sim_ent_enable_prop(ent, SEPROP_EXPLOSION);
|
sim_ent_enable_prop(ent, Prop_Explosion);
|
||||||
ent->explosion_strength = strength;
|
ent->explosion_strength = strength;
|
||||||
ent->explosion_radius = radius;
|
ent->explosion_radius = radius;
|
||||||
|
|
||||||
sim_ent_enable_prop(ent, SEPROP_SENSOR);
|
sim_ent_enable_prop(ent, Prop_Sensor);
|
||||||
ent->local_collider.count = 1;
|
ent->local_collider.count = 1;
|
||||||
ent->local_collider.radius = radius;
|
ent->local_collider.radius = radius;
|
||||||
|
|
||||||
@ -259,11 +259,11 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos)
|
|||||||
//e->sprite_tint = Alpha32F(ColorBlue, 0.75);
|
//e->sprite_tint = Alpha32F(ColorBlue, 0.75);
|
||||||
//e->sprite_tint = Alpha32F(ColorWhite, 1);
|
//e->sprite_tint = Alpha32F(ColorWhite, 1);
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
sim_ent_enable_prop(e, Prop_Solid);
|
||||||
Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1));
|
Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1));
|
||||||
e->local_collider = CLD_ShapeFromQuad(collider_quad);
|
e->local_collider = CLD_ShapeFromQuad(collider_quad);
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
sim_ent_enable_prop(e, Prop_LightTest);
|
||||||
|
|
||||||
/* FIXME: Remove this */
|
/* FIXME: Remove this */
|
||||||
{
|
{
|
||||||
@ -275,7 +275,7 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos)
|
|||||||
e->sprite_tint = Rgba32F(r / 5, g / 5, b / 5, 1);
|
e->sprite_tint = Rgba32F(r / 5, g / 5, b / 5, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_DYNAMIC);
|
sim_ent_enable_prop(e, Prop_Dynamic);
|
||||||
e->mass_unscaled = 50;
|
e->mass_unscaled = 50;
|
||||||
e->inertia_unscaled = 2;
|
e->inertia_unscaled = 2;
|
||||||
#if 0
|
#if 0
|
||||||
@ -299,9 +299,9 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos)
|
|||||||
e->sprite_collider_slice = Lit("shape");
|
e->sprite_collider_slice = Lit("shape");
|
||||||
e->layer = SIM_LAYER_SHOULDERS;
|
e->layer = SIM_LAYER_SHOULDERS;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
sim_ent_enable_prop(e, Prop_Solid);
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_DYNAMIC);
|
sim_ent_enable_prop(e, Prop_Dynamic);
|
||||||
e->mass_unscaled = 0.5;
|
e->mass_unscaled = 0.5;
|
||||||
e->inertia_unscaled = 1000;
|
e->inertia_unscaled = 1000;
|
||||||
e->linear_ground_friction = 0.001;
|
e->linear_ground_friction = 0.001;
|
||||||
@ -328,7 +328,7 @@ void SpawnTestEntities3(Entity *parent, Vec2 pos)
|
|||||||
|
|
||||||
e->sprite_tint = ColorRed;
|
e->sprite_tint = ColorRed;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
sim_ent_enable_prop(e, Prop_Solid);
|
||||||
Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1));
|
Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1));
|
||||||
e->local_collider = CLD_ShapeFromQuad(collider_quad);
|
e->local_collider = CLD_ShapeFromQuad(collider_quad);
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ void SpawnTestEntities4(Entity *parent, Vec2 pos)
|
|||||||
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
e->sprite = S_TagFromPath(Lit("sprite/tile.ase"));
|
||||||
e->layer = SIM_LAYER_SHOULDERS;
|
e->layer = SIM_LAYER_SHOULDERS;
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
|
sim_ent_enable_prop(e, Prop_LightTest);
|
||||||
e->sprite_emittance = VEC3(2, 2, 2);
|
e->sprite_emittance = VEC3(2, 2, 2);
|
||||||
|
|
||||||
e->sprite_tint = Rgb32F(1, 1, 1);
|
e->sprite_tint = Rgb32F(1, 1, 1);
|
||||||
@ -386,7 +386,7 @@ void SpawnTestTile(Snapshot *world, Vec2 world_pos)
|
|||||||
S_EndScope(scope);
|
S_EndScope(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
sim_ent_enable_prop(e, SEPROP_SOLID);
|
sim_ent_enable_prop(e, Prop_Solid);
|
||||||
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y));
|
||||||
e->local_collider = CLD_ShapeFromQuad(collider_quad);
|
e->local_collider = CLD_ShapeFromQuad(collider_quad);
|
||||||
#else
|
#else
|
||||||
@ -401,7 +401,7 @@ void ClearLevelTest(SimStepCtx *ctx)
|
|||||||
for (u64 j = 0; j < world->num_ents_reserved; ++j) {
|
for (u64 j = 0; j < world->num_ents_reserved; ++j) {
|
||||||
Entity *ent = &world->ents[j];
|
Entity *ent = &world->ents[j];
|
||||||
if (ent->valid) {
|
if (ent->valid) {
|
||||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -450,13 +450,13 @@ void GenerateTestWalls(Snapshot *world)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!ent->valid) continue;
|
if (!ent->valid) continue;
|
||||||
if (sim_ent_has_prop(ent, SEPROP_TILE_CHUNK)) {
|
if (sim_ent_has_prop(ent, Prop_TileChunk)) {
|
||||||
/* Append chunk to array */
|
/* Append chunk to array */
|
||||||
*PushStructNoZero(scratch.arena, Entity *) = ent;
|
*PushStructNoZero(scratch.arena, Entity *) = ent;
|
||||||
++sorted_tile_chunks_count;
|
++sorted_tile_chunks_count;
|
||||||
} else if (sim_ent_has_prop(ent, SEPROP_WALL)) {
|
} else if (sim_ent_has_prop(ent, Prop_Wall)) {
|
||||||
/* Release existing wall */
|
/* Release existing wall */
|
||||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y_sorted_tile_chunks = PushStructsNoZero(scratch.arena, Entity *, sorted_tile_chunks_count);
|
y_sorted_tile_chunks = PushStructsNoZero(scratch.arena, Entity *, sorted_tile_chunks_count);
|
||||||
@ -664,7 +664,7 @@ void GenerateTestWalls(Snapshot *world)
|
|||||||
/* Create wall entities */
|
/* Create wall entities */
|
||||||
for (struct wall_node *node = first_wall; node; node = node->next) {
|
for (struct wall_node *node = first_wall; node; node = node->next) {
|
||||||
Entity *wall_ent = sim_ent_acquire_sync_src(root);
|
Entity *wall_ent = sim_ent_acquire_sync_src(root);
|
||||||
sim_ent_enable_prop(wall_ent, SEPROP_WALL);
|
sim_ent_enable_prop(wall_ent, Prop_Wall);
|
||||||
|
|
||||||
Vec2 start = sim_pos_from_world_tile_index(node->start);
|
Vec2 start = sim_pos_from_world_tile_index(node->start);
|
||||||
Vec2 end = sim_pos_from_world_tile_index(node->end);
|
Vec2 end = sim_pos_from_world_tile_index(node->end);
|
||||||
@ -672,7 +672,7 @@ void GenerateTestWalls(Snapshot *world)
|
|||||||
Xform xf = XformFromPos(start);
|
Xform xf = XformFromPos(start);
|
||||||
sim_ent_set_xform(wall_ent, xf);
|
sim_ent_set_xform(wall_ent, xf);
|
||||||
|
|
||||||
sim_ent_enable_prop(wall_ent, SEPROP_SOLID);
|
sim_ent_enable_prop(wall_ent, Prop_Solid);
|
||||||
wall_ent->local_collider.count = 2;
|
wall_ent->local_collider.count = 2;
|
||||||
wall_ent->local_collider.points[1] = SubVec2(end, start);
|
wall_ent->local_collider.points[1] = SubVec2(end, start);
|
||||||
|
|
||||||
@ -699,7 +699,7 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx)
|
|||||||
|
|
||||||
if (sim_ent_should_simulate(e0) && sim_ent_should_simulate(e1)) {
|
if (sim_ent_should_simulate(e0) && sim_ent_should_simulate(e1)) {
|
||||||
/* Bullet impact */
|
/* Bullet impact */
|
||||||
if (sim_ent_has_prop(e0, SEPROP_BULLET)) {
|
if (sim_ent_has_prop(e0, Prop_Bullet)) {
|
||||||
Vec2 normal = data->normal; /* Impact normal */
|
Vec2 normal = data->normal; /* Impact normal */
|
||||||
Vec2 vrel = data->vrel; /* Impact velocity */
|
Vec2 vrel = data->vrel; /* Impact velocity */
|
||||||
|
|
||||||
@ -708,7 +708,7 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx)
|
|||||||
Entity *src = sim_ent_from_id(world, bullet->bullet_src);
|
Entity *src = sim_ent_from_id(world, bullet->bullet_src);
|
||||||
|
|
||||||
/* Process collision if bullet already spent or * target share same top level parent */
|
/* Process collision if bullet already spent or * target share same top level parent */
|
||||||
if (!bullet->bullet_has_hit && !sim_ent_id_eq(src->top, target->top) && sim_ent_has_prop(target, SEPROP_SOLID)) {
|
if (!bullet->bullet_has_hit && !sim_ent_id_eq(src->top, target->top) && sim_ent_has_prop(target, Prop_Solid)) {
|
||||||
Vec2 point = data->point;
|
Vec2 point = data->point;
|
||||||
|
|
||||||
/* Update tracer */
|
/* Update tracer */
|
||||||
@ -741,7 +741,7 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx)
|
|||||||
f32 angular_velocity_range = 5;
|
f32 angular_velocity_range = 5;
|
||||||
f32 angular_velocity = RandF64FromState(&step_ctx->rand, -angular_velocity_range, angular_velocity_range);
|
f32 angular_velocity = RandF64FromState(&step_ctx->rand, -angular_velocity_range, angular_velocity_range);
|
||||||
|
|
||||||
sim_ent_enable_prop(decal, SEPROP_KINEMATIC);
|
sim_ent_enable_prop(decal, Prop_Kinematic);
|
||||||
sim_ent_set_linear_velocity(decal, linear_velocity);
|
sim_ent_set_linear_velocity(decal, linear_velocity);
|
||||||
sim_ent_set_angular_velocity(decal, angular_velocity);
|
sim_ent_set_angular_velocity(decal, angular_velocity);
|
||||||
|
|
||||||
@ -756,12 +756,12 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx)
|
|||||||
|
|
||||||
/* Update bullet */
|
/* Update bullet */
|
||||||
bullet->bullet_has_hit = 1;
|
bullet->bullet_has_hit = 1;
|
||||||
sim_ent_enable_prop(bullet, SEPROP_RELEASE);
|
sim_ent_enable_prop(bullet, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Explosion blast collision */
|
/* Explosion blast collision */
|
||||||
if (sim_ent_has_prop(e0, SEPROP_EXPLOSION)) {
|
if (sim_ent_has_prop(e0, Prop_Explosion)) {
|
||||||
Entity *exp = e0;
|
Entity *exp = e0;
|
||||||
Entity *victim = e1;
|
Entity *victim = e1;
|
||||||
|
|
||||||
@ -800,8 +800,8 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Chucker zone */
|
/* Chucker zone */
|
||||||
if (sim_ent_has_prop(e0, SEPROP_CHUCKER_ZONE)) {
|
if (sim_ent_has_prop(e0, Prop_ChuckerZone)) {
|
||||||
if (!sim_ent_id_eq(e0->top, e1->top) && sim_ent_has_prop(e1, SEPROP_SOLID)) {
|
if (!sim_ent_id_eq(e0->top, e1->top) && sim_ent_has_prop(e1, Prop_Solid)) {
|
||||||
e0->chucker_zone_ent = e1->id;
|
e0->chucker_zone_ent = e1->id;
|
||||||
e0->chucker_zone_ent_tick = world->tick;
|
e0->chucker_zone_ent_tick = world->tick;
|
||||||
}
|
}
|
||||||
@ -855,7 +855,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
/* FIXME: Player never released upon disconnect */
|
/* FIXME: Player never released upon disconnect */
|
||||||
player = sim_ent_acquire_sync_src(root);
|
player = sim_ent_acquire_sync_src(root);
|
||||||
player->player_client_handle = client->handle;
|
player->player_client_handle = client->handle;
|
||||||
sim_ent_enable_prop(player, SEPROP_PLAYER);
|
sim_ent_enable_prop(player, Prop_Player);
|
||||||
player->predictor = player->id;
|
player->predictor = player->id;
|
||||||
sim_ent_activate(player, world->tick);
|
sim_ent_activate(player, world->tick);
|
||||||
client->player_id = player->id;
|
client->player_id = player->id;
|
||||||
@ -864,9 +864,9 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
world_client->player_id = player->id;
|
world_client->player_id = player->id;
|
||||||
world->local_player = player->id;
|
world->local_player = player->id;
|
||||||
player->owner = player->id;
|
player->owner = player->id;
|
||||||
sim_ent_enable_prop(player, SEPROP_PLAYER_IS_MASTER);
|
sim_ent_enable_prop(player, Prop_IsMaster);
|
||||||
}
|
}
|
||||||
P_LogInfoF("Created player with id %F for sim client %F. is_master: %F", FmtUid(player->id.uid), FmtHandle(client->handle), FmtUint(sim_ent_has_prop(player, SEPROP_PLAYER_IS_MASTER)));
|
P_LogInfoF("Created player with id %F for sim client %F. is_master: %F", FmtUid(player->id.uid), FmtHandle(client->handle), FmtUint(sim_ent_has_prop(player, Prop_IsMaster)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update rtt */
|
/* Update rtt */
|
||||||
@ -889,16 +889,16 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
/* Mark all incoming ents as sync dsts */
|
/* Mark all incoming ents as sync dsts */
|
||||||
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
||||||
Entity *ent = &world->ents[i];
|
Entity *ent = &world->ents[i];
|
||||||
if (ent->valid && sim_ent_has_prop(ent, SEPROP_SYNC_SRC) && !sim_ent_id_eq(ent->owner, world_client->player_id)) {
|
if (ent->valid && sim_ent_has_prop(ent, Prop_SyncSrc) && !sim_ent_id_eq(ent->owner, world_client->player_id)) {
|
||||||
sim_ent_disable_prop(ent, SEPROP_SYNC_SRC);
|
sim_ent_disable_prop(ent, Prop_SyncSrc);
|
||||||
sim_ent_enable_prop(ent, SEPROP_SYNC_DST);
|
sim_ent_enable_prop(ent, Prop_SyncDst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark incoming cmds with correct client */
|
/* Mark incoming cmds with correct client */
|
||||||
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
||||||
Entity *ent = &world->ents[i];
|
Entity *ent = &world->ents[i];
|
||||||
if (ent->valid && sim_ent_has_prop(ent, SEPROP_CMD) && sim_ent_has_prop(ent, SEPROP_SYNC_DST)) {
|
if (ent->valid && sim_ent_has_prop(ent, Prop_Cmd) && sim_ent_has_prop(ent, Prop_SyncDst)) {
|
||||||
ent->cmd_player = ent->owner;
|
ent->cmd_player = ent->owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -907,9 +907,9 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
if (!is_master) {
|
if (!is_master) {
|
||||||
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
||||||
Entity *ent = &world->ents[i];
|
Entity *ent = &world->ents[i];
|
||||||
if (sim_ent_is_valid_and_active(ent) && sim_ent_has_prop(ent, SEPROP_CMD)) {
|
if (sim_ent_is_valid_and_active(ent) && sim_ent_has_prop(ent, Prop_Cmd)) {
|
||||||
if (!sim_ent_id_is_nil(ent->cmd_player) && sim_ent_id_eq(ent->cmd_player, world->local_player)) {
|
if (!sim_ent_id_is_nil(ent->cmd_player) && sim_ent_id_eq(ent->cmd_player, world->local_player)) {
|
||||||
sim_ent_enable_prop(ent, SEPROP_SYNC_SRC);
|
sim_ent_enable_prop(ent, Prop_SyncSrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -919,7 +919,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
|
|
||||||
//- Release entities at beginning of frame
|
//- Release entities at beginning of frame
|
||||||
|
|
||||||
sim_ent_release_all_with_prop(world, SEPROP_RELEASE);
|
sim_ent_release_all_with_prop(world, Prop_Release);
|
||||||
ResetSimAccel(world, ctx->accel);
|
ResetSimAccel(world, ctx->accel);
|
||||||
|
|
||||||
|
|
||||||
@ -928,9 +928,9 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!ent->valid) continue;
|
if (!ent->valid) continue;
|
||||||
if (sim_ent_has_prop(ent, SEPROP_SYNC_DST) && !sim_ent_is_owner(ent) && !sim_ent_should_predict(ent)) continue;
|
if (sim_ent_has_prop(ent, Prop_SyncDst) && !sim_ent_is_owner(ent) && !sim_ent_should_predict(ent)) continue;
|
||||||
|
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_ACTIVE)) {
|
if (!sim_ent_has_prop(ent, Prop_Active)) {
|
||||||
u64 atick = ent->activation_tick;
|
u64 atick = ent->activation_tick;
|
||||||
if (atick != 0 || world->tick >= atick) {
|
if (atick != 0 || world->tick >= atick) {
|
||||||
sim_ent_activate(ent, world->tick);
|
sim_ent_activate(ent, world->tick);
|
||||||
@ -945,7 +945,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *cmd_ent = &world->ents[ent_index];
|
Entity *cmd_ent = &world->ents[ent_index];
|
||||||
if (!is_master && !sim_ent_should_simulate(cmd_ent)) continue;
|
if (!is_master && !sim_ent_should_simulate(cmd_ent)) continue;
|
||||||
|
|
||||||
if (sim_ent_has_prop(cmd_ent, SEPROP_CMD)) {
|
if (sim_ent_has_prop(cmd_ent, Prop_Cmd)) {
|
||||||
Entity *player = sim_ent_from_id(world, cmd_ent->cmd_player);
|
Entity *player = sim_ent_from_id(world, cmd_ent->cmd_player);
|
||||||
if (sim_ent_should_simulate(player)) {
|
if (sim_ent_should_simulate(player)) {
|
||||||
b32 persist_cmd = 0;
|
b32 persist_cmd = 0;
|
||||||
@ -992,7 +992,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
if (flags & SIM_CONTROL_FLAG_DELETE) {
|
if (flags & SIM_CONTROL_FLAG_DELETE) {
|
||||||
Entity *ent = sim_ent_from_id(world, player->player_hovered_ent);
|
Entity *ent = sim_ent_from_id(world, player->player_hovered_ent);
|
||||||
if (ent->valid) {
|
if (ent->valid) {
|
||||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flags & SIM_CONTROL_FLAG_CLEAR_ALL) {
|
if (flags & SIM_CONTROL_FLAG_CLEAR_ALL) {
|
||||||
@ -1062,7 +1062,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
String msg = sim_data_from_key(sim_data_store, msg_key);
|
String msg = sim_data_from_key(sim_data_store, msg_key);
|
||||||
if (msg.len > 0) {
|
if (msg.len > 0) {
|
||||||
Entity *chat_ent = sim_ent_acquire_sync_src(root);
|
Entity *chat_ent = sim_ent_acquire_sync_src(root);
|
||||||
sim_ent_enable_prop(chat_ent, SEPROP_CHAT);
|
sim_ent_enable_prop(chat_ent, Prop_CHAT);
|
||||||
chat_ent->chat_player = player->id;
|
chat_ent->chat_player = player->id;
|
||||||
chat_ent->chat_msg = msg_key;
|
chat_ent->chat_msg = msg_key;
|
||||||
}
|
}
|
||||||
@ -1078,7 +1078,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
|
|
||||||
/* Release cmd */
|
/* Release cmd */
|
||||||
if (!persist_cmd) {
|
if (!persist_cmd) {
|
||||||
sim_ent_enable_prop(cmd_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(cmd_ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1091,7 +1091,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
|
|
||||||
if (sim_ent_has_prop(ent, SEPROP_CONTROLLED)) {
|
if (sim_ent_has_prop(ent, Prop_Controlled)) {
|
||||||
Entity *player = sim_ent_from_id(world, ent->controlling_player);
|
Entity *player = sim_ent_from_id(world, ent->controlling_player);
|
||||||
if (player->valid) {
|
if (player->valid) {
|
||||||
ent->control = player->player_control;
|
ent->control = player->player_control;
|
||||||
@ -1106,13 +1106,13 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
||||||
Entity *ent = &world->ents[i];
|
Entity *ent = &world->ents[i];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (sim_ent_has_prop(ent, SEPROP_PLAYER)) {
|
if (sim_ent_has_prop(ent, Prop_Player)) {
|
||||||
/* FIXME: Ents never released when client disconnects */
|
/* FIXME: Ents never released when client disconnects */
|
||||||
Entity *control_ent = sim_ent_from_id(world, ent->player_control_ent);
|
Entity *control_ent = sim_ent_from_id(world, ent->player_control_ent);
|
||||||
if (!control_ent->valid) {
|
if (!control_ent->valid) {
|
||||||
control_ent = SpawnTestEmployee(root);
|
control_ent = SpawnTestEmployee(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, Prop_Controlled);
|
||||||
ent->player_control_ent = control_ent->id;
|
ent->player_control_ent = control_ent->id;
|
||||||
control_ent->controlling_player = ent->id;
|
control_ent->controlling_player = ent->id;
|
||||||
}
|
}
|
||||||
@ -1197,7 +1197,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
|
|
||||||
/* Test collider */
|
/* Test collider */
|
||||||
#if 0
|
#if 0
|
||||||
if (sim_ent_has_prop(ent, SEPROP_TEST)) {
|
if (sim_ent_has_prop(ent, Prop_Test)) {
|
||||||
//if ((1)) {
|
//if ((1)) {
|
||||||
#if 0
|
#if 0
|
||||||
ent->local_collider.points[0] = VEC2(0, 0);
|
ent->local_collider.points[0] = VEC2(0, 0);
|
||||||
@ -1237,7 +1237,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_ATTACHED)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Attached)) continue;
|
||||||
|
|
||||||
Entity *parent = sim_ent_from_id(world, ent->parent);
|
Entity *parent = sim_ent_from_id(world, ent->parent);
|
||||||
S_Tag parent_sprite = parent->sprite;
|
S_Tag parent_sprite = parent->sprite;
|
||||||
@ -1262,7 +1262,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
|
|
||||||
if (sim_ent_has_prop(ent, SEPROP_CONTROLLED)) {
|
if (sim_ent_has_prop(ent, Prop_Controlled)) {
|
||||||
ControlData *control = &ent->control;
|
ControlData *control = &ent->control;
|
||||||
ControlFlag flags = control->flags;
|
ControlFlag flags = control->flags;
|
||||||
if (flags & SIM_CONTROL_FLAG_FIRE) {
|
if (flags & SIM_CONTROL_FLAG_FIRE) {
|
||||||
@ -1313,7 +1313,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fire smg */
|
/* Fire smg */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_WEAPON_SMG)) {
|
if (sim_ent_has_prop(ent, Prop_Smg)) {
|
||||||
if (primary_triggered) {
|
if (primary_triggered) {
|
||||||
S_Tag sprite = ent->sprite;
|
S_Tag sprite = ent->sprite;
|
||||||
u32 animation_frame = ent->animation_frame;
|
u32 animation_frame = ent->animation_frame;
|
||||||
@ -1328,7 +1328,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
{
|
{
|
||||||
bullet = sim_ent_acquire_sync_src(root);
|
bullet = sim_ent_acquire_sync_src(root);
|
||||||
|
|
||||||
sim_ent_enable_prop(bullet, SEPROP_BULLET);
|
sim_ent_enable_prop(bullet, Prop_Bullet);
|
||||||
bullet->bullet_src = ent->id;
|
bullet->bullet_src = ent->id;
|
||||||
bullet->bullet_src_pos = rel_pos;
|
bullet->bullet_src_pos = rel_pos;
|
||||||
bullet->bullet_src_dir = rel_dir;
|
bullet->bullet_src_dir = rel_dir;
|
||||||
@ -1352,7 +1352,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *tracer = sim_ent_acquire_sync_src(root);
|
Entity *tracer = sim_ent_acquire_sync_src(root);
|
||||||
tracer->tracer_fade_duration = 0.025f;
|
tracer->tracer_fade_duration = 0.025f;
|
||||||
tracer->layer = SIM_LAYER_TRACERS;
|
tracer->layer = SIM_LAYER_TRACERS;
|
||||||
sim_ent_enable_prop(tracer, SEPROP_TRACER);
|
sim_ent_enable_prop(tracer, Prop_Tracer);
|
||||||
|
|
||||||
bullet->bullet_tracer = tracer->id;
|
bullet->bullet_tracer = tracer->id;
|
||||||
}
|
}
|
||||||
@ -1360,7 +1360,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fire launcher */
|
/* Fire launcher */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_WEAPON_LAUNCHER)) {
|
if (sim_ent_has_prop(ent, Prop_Launcher)) {
|
||||||
if (primary_triggered) {
|
if (primary_triggered) {
|
||||||
S_Tag sprite = ent->sprite;
|
S_Tag sprite = ent->sprite;
|
||||||
u32 animation_frame = ent->animation_frame;
|
u32 animation_frame = ent->animation_frame;
|
||||||
@ -1375,7 +1375,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
{
|
{
|
||||||
bullet = sim_ent_acquire_sync_src(root);
|
bullet = sim_ent_acquire_sync_src(root);
|
||||||
|
|
||||||
sim_ent_enable_prop(bullet, SEPROP_BULLET);
|
sim_ent_enable_prop(bullet, Prop_Bullet);
|
||||||
bullet->bullet_src = ent->id;
|
bullet->bullet_src = ent->id;
|
||||||
bullet->bullet_src_pos = rel_pos;
|
bullet->bullet_src_pos = rel_pos;
|
||||||
bullet->bullet_src_dir = rel_dir;
|
bullet->bullet_src_dir = rel_dir;
|
||||||
@ -1398,7 +1398,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *tracer = sim_ent_acquire_sync_src(root);
|
Entity *tracer = sim_ent_acquire_sync_src(root);
|
||||||
tracer->tracer_fade_duration = 0.025f;
|
tracer->tracer_fade_duration = 0.025f;
|
||||||
tracer->layer = SIM_LAYER_TRACERS;
|
tracer->layer = SIM_LAYER_TRACERS;
|
||||||
sim_ent_enable_prop(tracer, SEPROP_TRACER);
|
sim_ent_enable_prop(tracer, Prop_Tracer);
|
||||||
|
|
||||||
bullet->bullet_tracer = tracer->id;
|
bullet->bullet_tracer = tracer->id;
|
||||||
}
|
}
|
||||||
@ -1406,7 +1406,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fire chucker */
|
/* Fire chucker */
|
||||||
if (sim_ent_has_prop(ent, SEPROP_WEAPON_CHUCKER)) {
|
if (sim_ent_has_prop(ent, Prop_Chucker)) {
|
||||||
if (primary_triggered) {
|
if (primary_triggered) {
|
||||||
}
|
}
|
||||||
if (secondary_triggered) {
|
if (secondary_triggered) {
|
||||||
@ -1416,13 +1416,13 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
if (sim_ent_is_valid_and_active(target) && zone->chucker_zone_ent_tick == world->tick - 1) {
|
if (sim_ent_is_valid_and_active(target) && zone->chucker_zone_ent_tick == world->tick - 1) {
|
||||||
if (!sim_ent_id_eq(old_joint_ent->weld_joint_data.e1, target->id)) {
|
if (!sim_ent_id_eq(old_joint_ent->weld_joint_data.e1, target->id)) {
|
||||||
Entity *joint_ent = sim_ent_acquire_sync_src(root);
|
Entity *joint_ent = sim_ent_acquire_sync_src(root);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(joint_ent, Prop_Active);
|
||||||
|
|
||||||
Xform xf0 = sim_ent_get_xform(ent);
|
Xform xf0 = sim_ent_get_xform(ent);
|
||||||
Xform xf1 = sim_ent_get_xform(target);
|
Xform xf1 = sim_ent_get_xform(target);
|
||||||
Xform xf0_to_xf1 = MulXform(InvertXform(xf0), xf1);
|
Xform xf0_to_xf1 = MulXform(InvertXform(xf0), xf1);
|
||||||
|
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_WELD_JOINT);
|
sim_ent_enable_prop(joint_ent, Prop_WeldJoint);
|
||||||
WeldJointDesc def = phys_weld_joint_def_init();
|
WeldJointDesc def = phys_weld_joint_def_init();
|
||||||
def.e0 = ent->id;
|
def.e0 = ent->id;
|
||||||
def.e1 = target->id;
|
def.e1 = target->id;
|
||||||
@ -1436,8 +1436,8 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (old_joint_ent->valid) {
|
if (old_joint_ent->valid) {
|
||||||
sim_ent_enable_prop(old_joint_ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(old_joint_ent, Prop_Release);
|
||||||
sim_ent_disable_prop(old_joint_ent, SEPROP_ACTIVE);
|
sim_ent_disable_prop(old_joint_ent, Prop_Active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1450,18 +1450,18 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
|
|
||||||
if (sim_ent_has_prop(ent, SEPROP_CONTROLLED)) {
|
if (sim_ent_has_prop(ent, Prop_Controlled)) {
|
||||||
Entity *joint_ent = sim_ent_from_id(world, ent->move_joint);
|
Entity *joint_ent = sim_ent_from_id(world, ent->move_joint);
|
||||||
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
|
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
|
||||||
joint_ent = sim_ent_acquire_sync_src(root);
|
joint_ent = sim_ent_acquire_sync_src(root);
|
||||||
joint_ent->predictor = ent->predictor;
|
joint_ent->predictor = ent->predictor;
|
||||||
joint_ent->mass_unscaled = F32Infinity;
|
joint_ent->mass_unscaled = F32Infinity;
|
||||||
joint_ent->inertia_unscaled = F32Infinity;
|
joint_ent->inertia_unscaled = F32Infinity;
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(joint_ent, Prop_Active);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_KINEMATIC);
|
sim_ent_enable_prop(joint_ent, Prop_Kinematic);
|
||||||
ent->move_joint = joint_ent->id;
|
ent->move_joint = joint_ent->id;
|
||||||
|
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_MOTOR_JOINT);
|
sim_ent_enable_prop(joint_ent, Prop_MotorJoint);
|
||||||
MotorJointDesc def = phys_motor_joint_def_init();
|
MotorJointDesc def = phys_motor_joint_def_init();
|
||||||
def.e0 = joint_ent->id; /* Re-using joint entity as e0 */
|
def.e0 = joint_ent->id; /* Re-using joint entity as e0 */
|
||||||
def.e1 = ent->id;
|
def.e1 = ent->id;
|
||||||
@ -1486,7 +1486,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
|
|
||||||
if (sim_ent_has_prop(ent, SEPROP_CONTROLLED)) {
|
if (sim_ent_has_prop(ent, Prop_Controlled)) {
|
||||||
Xform xf = sim_ent_get_xform(ent);
|
Xform xf = sim_ent_get_xform(ent);
|
||||||
Xform sprite_xf = MulXform(xf, ent->sprite_local_xform);
|
Xform sprite_xf = MulXform(xf, ent->sprite_local_xform);
|
||||||
|
|
||||||
@ -1497,9 +1497,9 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
joint_ent->predictor = ent->predictor;
|
joint_ent->predictor = ent->predictor;
|
||||||
joint_ent->mass_unscaled = F32Infinity;
|
joint_ent->mass_unscaled = F32Infinity;
|
||||||
joint_ent->inertia_unscaled = F32Infinity;
|
joint_ent->inertia_unscaled = F32Infinity;
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_KINEMATIC); /* Since we'll be setting velocity manually */
|
sim_ent_enable_prop(joint_ent, Prop_Kinematic); /* Since we'll be setting velocity manually */
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_MOTOR_JOINT);
|
sim_ent_enable_prop(joint_ent, Prop_MotorJoint);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(joint_ent, Prop_Active);
|
||||||
ent->aim_joint = joint_ent->id;
|
ent->aim_joint = joint_ent->id;
|
||||||
|
|
||||||
MotorJointDesc def = phys_motor_joint_def_init();
|
MotorJointDesc def = phys_motor_joint_def_init();
|
||||||
@ -1582,7 +1582,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_DYNAMIC)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Dynamic)) continue;
|
||||||
|
|
||||||
Entity *joint_ent = sim_ent_from_id(world, ent->ground_friction_joint);
|
Entity *joint_ent = sim_ent_from_id(world, ent->ground_friction_joint);
|
||||||
|
|
||||||
@ -1596,8 +1596,8 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
|
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
|
||||||
joint_ent = sim_ent_acquire_sync_src(root);
|
joint_ent = sim_ent_acquire_sync_src(root);
|
||||||
joint_ent->predictor = ent->predictor;
|
joint_ent->predictor = ent->predictor;
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_MOTOR_JOINT);
|
sim_ent_enable_prop(joint_ent, Prop_MotorJoint);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(joint_ent, Prop_Active);
|
||||||
joint_ent->motor_joint_data = phys_motor_joint_from_def(def);
|
joint_ent->motor_joint_data = phys_motor_joint_from_def(def);
|
||||||
ent->ground_friction_joint = joint_ent->id;
|
ent->ground_friction_joint = joint_ent->id;
|
||||||
}
|
}
|
||||||
@ -1612,7 +1612,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
for (u64 i = 0; i < world->num_ents_reserved; ++i) {
|
||||||
Entity *player = &world->ents[i];
|
Entity *player = &world->ents[i];
|
||||||
if (!sim_ent_should_simulate(player)) continue;
|
if (!sim_ent_should_simulate(player)) continue;
|
||||||
if (!sim_ent_has_prop(player, SEPROP_PLAYER)) continue;
|
if (!sim_ent_has_prop(player, Prop_Player)) continue;
|
||||||
|
|
||||||
Vec2 cursor = player->player_cursor_pos;
|
Vec2 cursor = player->player_cursor_pos;
|
||||||
b32 start_dragging = player->player_dbg_drag_start;
|
b32 start_dragging = player->player_dbg_drag_start;
|
||||||
@ -1634,8 +1634,8 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
joint_ent->mass_unscaled = F32Infinity;
|
joint_ent->mass_unscaled = F32Infinity;
|
||||||
joint_ent->inertia_unscaled = F32Infinity;
|
joint_ent->inertia_unscaled = F32Infinity;
|
||||||
player->player_dbg_drag_joint_ent = joint_ent->id;
|
player->player_dbg_drag_joint_ent = joint_ent->id;
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_MOUSE_JOINT);
|
sim_ent_enable_prop(joint_ent, Prop_MouseJoint);
|
||||||
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
|
sim_ent_enable_prop(joint_ent, Prop_Active);
|
||||||
}
|
}
|
||||||
Xform xf = sim_ent_get_xform(target_ent);
|
Xform xf = sim_ent_get_xform(target_ent);
|
||||||
|
|
||||||
@ -1675,10 +1675,10 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_EXPLOSION)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Explosion)) continue;
|
||||||
|
|
||||||
/* Explosion doesn't need to generate any more collisions after initial physics step */
|
/* Explosion doesn't need to generate any more collisions after initial physics step */
|
||||||
sim_ent_disable_prop(ent, SEPROP_SENSOR);
|
sim_ent_disable_prop(ent, Prop_Sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1687,7 +1687,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_TRACER)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Tracer)) continue;
|
||||||
|
|
||||||
Vec2 end = sim_ent_get_xform(ent).og;
|
Vec2 end = sim_ent_get_xform(ent).og;
|
||||||
|
|
||||||
@ -1697,7 +1697,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
|
|
||||||
if (DotVec2(tick_velocity, SubVec2(gradient_start, end)) > 0) {
|
if (DotVec2(tick_velocity, SubVec2(gradient_start, end)) > 0) {
|
||||||
/* Tracer has disappeared */
|
/* Tracer has disappeared */
|
||||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(ent, Prop_Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
ent->tracer_gradient_start = gradient_start;
|
ent->tracer_gradient_start = gradient_start;
|
||||||
@ -1710,15 +1710,15 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_BULLET)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Bullet)) continue;
|
||||||
|
|
||||||
if (ent->activation_tick == world->tick) {
|
if (ent->activation_tick == world->tick) {
|
||||||
Entity *src = sim_ent_from_id(world, ent->bullet_src);
|
Entity *src = sim_ent_from_id(world, ent->bullet_src);
|
||||||
Xform src_xf = sim_ent_get_xform(src);
|
Xform src_xf = sim_ent_get_xform(src);
|
||||||
|
|
||||||
/* Activate collision */
|
/* Activate collision */
|
||||||
sim_ent_enable_prop(ent, SEPROP_SENSOR);
|
sim_ent_enable_prop(ent, Prop_Sensor);
|
||||||
sim_ent_enable_prop(ent, SEPROP_TOI);
|
sim_ent_enable_prop(ent, Prop_Toi);
|
||||||
|
|
||||||
Vec2 pos = MulXformV2(src_xf, ent->bullet_src_pos);
|
Vec2 pos = MulXformV2(src_xf, ent->bullet_src_pos);
|
||||||
Vec2 vel = MulXformBasisV2(src_xf, ent->bullet_src_dir);
|
Vec2 vel = MulXformBasisV2(src_xf, ent->bullet_src_dir);
|
||||||
@ -1736,14 +1736,14 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
Xform xf = XformFromTrs(TRS(.t = pos, .r = AngleFromVec2(vel) + Pi / 2));
|
Xform xf = XformFromTrs(TRS(.t = pos, .r = AngleFromVec2(vel) + Pi / 2));
|
||||||
sim_ent_set_xform(ent, xf);
|
sim_ent_set_xform(ent, xf);
|
||||||
|
|
||||||
sim_ent_enable_prop(ent, SEPROP_KINEMATIC);
|
sim_ent_enable_prop(ent, Prop_Kinematic);
|
||||||
sim_ent_set_linear_velocity(ent, vel);
|
sim_ent_set_linear_velocity(ent, vel);
|
||||||
|
|
||||||
/* Initialize tracer */
|
/* Initialize tracer */
|
||||||
Entity *tracer = sim_ent_from_id(world, ent->bullet_tracer);
|
Entity *tracer = sim_ent_from_id(world, ent->bullet_tracer);
|
||||||
if (sim_ent_should_simulate(tracer)) {
|
if (sim_ent_should_simulate(tracer)) {
|
||||||
sim_ent_set_xform(tracer, xf);
|
sim_ent_set_xform(tracer, xf);
|
||||||
sim_ent_enable_prop(tracer, SEPROP_KINEMATIC);
|
sim_ent_enable_prop(tracer, Prop_Kinematic);
|
||||||
sim_ent_set_linear_velocity(tracer, ent->linear_velocity);
|
sim_ent_set_linear_velocity(tracer, ent->linear_velocity);
|
||||||
tracer->tracer_start = pos;
|
tracer->tracer_start = pos;
|
||||||
tracer->tracer_start_velocity = ent->linear_velocity;
|
tracer->tracer_start_velocity = ent->linear_velocity;
|
||||||
@ -1757,7 +1757,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
sim_ent_set_xform(quake, XformFromPos(pos));
|
sim_ent_set_xform(quake, XformFromPos(pos));
|
||||||
quake->quake_intensity = 0.2f;
|
quake->quake_intensity = 0.2f;
|
||||||
quake->quake_fade = quake->quake_intensity / 0.1f;
|
quake->quake_fade = quake->quake_intensity / 0.1f;
|
||||||
sim_ent_enable_prop(quake, SEPROP_QUAKE);
|
sim_ent_enable_prop(quake, Prop_Quake);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1768,7 +1768,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_CAMERA)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Camera)) continue;
|
||||||
|
|
||||||
Xform xf = sim_ent_get_xform(ent);
|
Xform xf = sim_ent_get_xform(ent);
|
||||||
|
|
||||||
@ -1809,7 +1809,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 quake_ent_index = 0; quake_ent_index < world->num_ents_reserved; ++quake_ent_index) {
|
for (u64 quake_ent_index = 0; quake_ent_index < world->num_ents_reserved; ++quake_ent_index) {
|
||||||
Entity *quake = &world->ents[quake_ent_index];
|
Entity *quake = &world->ents[quake_ent_index];
|
||||||
if (!sim_ent_should_simulate(quake)) continue;
|
if (!sim_ent_should_simulate(quake)) continue;
|
||||||
if (!sim_ent_has_prop(quake, SEPROP_QUAKE)) continue;
|
if (!sim_ent_has_prop(quake, Prop_Quake)) continue;
|
||||||
ent->shake += quake->quake_intensity;
|
ent->shake += quake->quake_intensity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1823,11 +1823,11 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &world->ents[ent_index];
|
Entity *ent = &world->ents[ent_index];
|
||||||
if (!sim_ent_should_simulate(ent)) continue;
|
if (!sim_ent_should_simulate(ent)) continue;
|
||||||
if (!sim_ent_has_prop(ent, SEPROP_QUAKE)) continue;
|
if (!sim_ent_has_prop(ent, Prop_Quake)) continue;
|
||||||
|
|
||||||
ent->quake_intensity = MaxF32(0, ent->quake_intensity - (ent->quake_fade * sim_dt));
|
ent->quake_intensity = MaxF32(0, ent->quake_intensity - (ent->quake_fade * sim_dt));
|
||||||
if (ent->quake_intensity <= 0) {
|
if (ent->quake_intensity <= 0) {
|
||||||
sim_ent_enable_prop(ent, SEPROP_RELEASE);
|
sim_ent_enable_prop(ent, Prop_Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1862,7 +1862,7 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
|
|
||||||
//- Release entities at end of frame
|
//- Release entities at end of frame
|
||||||
|
|
||||||
sim_ent_release_all_with_prop(world, SEPROP_RELEASE);
|
sim_ent_release_all_with_prop(world, Prop_Release);
|
||||||
|
|
||||||
|
|
||||||
//- Sync to publish client
|
//- Sync to publish client
|
||||||
@ -1878,8 +1878,8 @@ void StepSim(SimStepCtx *ctx)
|
|||||||
for (u64 ent_index = 2; ent_index < pub_world->num_ents_reserved; ++ent_index) {
|
for (u64 ent_index = 2; ent_index < pub_world->num_ents_reserved; ++ent_index) {
|
||||||
Entity *ent = &pub_world->ents[ent_index];
|
Entity *ent = &pub_world->ents[ent_index];
|
||||||
if (ent->valid) {
|
if (ent->valid) {
|
||||||
sim_ent_enable_prop(ent, SEPROP_SYNC_DST);
|
sim_ent_enable_prop(ent, Prop_SyncDst);
|
||||||
sim_ent_enable_prop(ent, SEPROP_SYNC_SRC);
|
sim_ent_enable_prop(ent, Prop_SyncSrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user