fp: Separate entity input from update

This commit is contained in:
doyle 2023-09-29 15:28:11 +10:00
parent 70b1596bb9
commit 543e759682

View File

@ -816,6 +816,8 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
}
Dqn_ProfilerZone update_zone = Dqn_Profiler_BeginZoneWithIndex(DQN_STRING8("FP_Update: Entity loop"), FP_ProfileZone_FPUpdate_EntityLoop);
// NOTE: Handle input ==========================================================================
for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) {
FP_GameEntity *entity = it.entity;
entity->alive_time_s += PHYSICS_STEP;
@ -982,6 +984,13 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
}
}
// NOTE: Move entity by mouse ==============================================================
if (game->active_entity == entity->handle && entity->flags & FP_GameEntityFlag_MoveByMouse) {
entity->velocity = {};
acceleration_meters_per_s = {};
entity->local_pos += input->mouse_p_delta;
}
// NOTE: Core equations of motion ==========================================================
bool has_collision = false;
{
@ -1073,14 +1082,15 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
}
}
// NOTE: Move entity by mouse ==============================================================
if (game->active_entity == entity->handle && entity->flags & FP_GameEntityFlag_MoveByMouse) {
if (entity->flags & FP_GameEntityFlag_MoveByMouse) {
entity->velocity = {};
entity->local_pos += input->mouse_p_delta;
}
// NOTE: Tick the state machine
FP_EntityActionStateMachine(game, input, entity, dir_vector);
}
// NOTE: Update entity =========================================================================
for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) {
FP_GameEntity *entity = it.entity;
// NOTE: Derive dynmamic bounding boxes ====================================================
if (entity->flags & FP_GameEntityFlag_DeriveHitBoxFromChildrenBoundingBox) {
Dqn_Rect children_bbox = {};
@ -1101,9 +1111,6 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
entity->local_hit_box_size = padded_bbox.size;
}
// NOTE: Handle input on entity ============================================================
FP_EntityActionStateMachine(game, input, entity, dir_vector);
// NOTE: Mob spawner =======================================================================
if (entity->flags & FP_GameEntityFlag_MobSpawner) {
@ -1144,13 +1151,11 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
}
}
}
}
Dqn_Profiler_EndZone(update_zone);
// NOTE: Do attacks ============================================================================
auto attack_zone = Dqn_Profiler_BeginZoneWithIndex(DQN_STRING8("FP_Update: Attacks"), FP_ProfileZone_FPUpdate_Attacks);
for (FP_GameEntityIterator attacker_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &attacker_it, game->root_entity); ) {
FP_GameEntity *attacker = attacker_it.entity;
{
Dqn_Profiler_ZoneScopeWithIndex("FP_Update: Attacks", FP_ProfileZone_FPUpdate_Attacks);
FP_GameEntity *attacker = entity;
// NOTE: Resolve attack boxes
if (!Dqn_V2_Area(attacker->attack_box_size))
@ -1192,7 +1197,9 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
defender->velocity = (acceleration * t) + defender->velocity * 2.0f;
}
}
Dqn_Profiler_EndZone(attack_zone);
}
Dqn_Profiler_EndZone(update_zone);
}
void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)