fp: Fix natural sorting order breaking the sprite packer
This commit is contained in:
+18
-12
@@ -102,7 +102,7 @@ TELY_AssetSpriteSheet FP_LoadSpriteSheetFromSpec(TELY_Platform *platform, TELY_A
|
||||
anim->ms_per_frame = DQN_CAST(uint32_t)(1000.f / frames_per_second.value);
|
||||
DQN_ASSERT(anim->ms_per_frame != 0);
|
||||
} else {
|
||||
DQN_ASSERTF(line_splits.size == 4, "Expected 4 splits for sprite frame lines");
|
||||
DQN_ASSERTF(line_splits.size == 5, "Expected 5 splits for sprite frame lines");
|
||||
Dqn_String8ToU64Result x = Dqn_String8_ToU64(line_splits.data[0], 0);
|
||||
Dqn_String8ToU64Result y = Dqn_String8_ToU64(line_splits.data[1], 0);
|
||||
Dqn_String8ToU64Result w = Dqn_String8_ToU64(line_splits.data[2], 0);
|
||||
@@ -2222,16 +2222,22 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
|
||||
|
||||
// NOTE: Render entity sprites =============================================================
|
||||
if (entity->action.sprite.anim) {
|
||||
FP_GameEntityAction const *action = &entity->action;
|
||||
TELY_AssetAnimatedSprite const sprite = action->sprite;
|
||||
FP_GameEntityAction const *action = &entity->action;
|
||||
TELY_AssetAnimatedSprite const sprite = action->sprite;
|
||||
uint64_t const elapsed_ms = game->clock_ms - action->started_at_clock_ms;
|
||||
uint16_t const raw_anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite.anim->ms_per_frame);
|
||||
DQN_ASSERTF(sprite.anim->count, "We will modulo by 0 or overflow to UINT64_MAX");
|
||||
|
||||
// TODO(doyle): So many ways to create and get sprite data .. its a mess
|
||||
// I want to override per sprite anim height, we currently use the one
|
||||
// in the entity which is not correct.
|
||||
FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, action->state, entity->direction);
|
||||
|
||||
uint64_t elapsed_ms = game->clock_ms - action->started_at_clock_ms;
|
||||
uint16_t anim_frame = 0;
|
||||
if (action->sprite_play_once) {
|
||||
anim_frame = DQN_MIN(DQN_CAST(uint16_t)(elapsed_ms / sprite.anim->ms_per_frame), sprite.anim->count);
|
||||
} else {
|
||||
anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite.anim->ms_per_frame) % sprite.anim->count;
|
||||
}
|
||||
if (action->sprite_play_once)
|
||||
anim_frame = DQN_MIN(raw_anim_frame, (sprite.anim->count - 1));
|
||||
else
|
||||
anim_frame = raw_anim_frame % sprite.anim->count;
|
||||
|
||||
Dqn_usize sprite_index = sprite.anim->index + anim_frame;
|
||||
Dqn_Rect src_rect = {};
|
||||
@@ -2252,7 +2258,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
|
||||
}
|
||||
|
||||
Dqn_f32 sprite_in_meters = FP_Game_PixelsToMetersNx1(game, src_rect.size.y);
|
||||
Dqn_f32 size_scale = entity->sprite_height.meters / sprite_in_meters;
|
||||
Dqn_f32 size_scale = render_data.height.meters / sprite_in_meters;
|
||||
|
||||
Dqn_Rect dest_rect = {};
|
||||
dest_rect.size = src_rect.size * size_scale;
|
||||
@@ -2796,8 +2802,8 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
|
||||
phone_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - phone_icon_rect.size.x * .25f, next_pos.y - (phone_icon_rect.size.y * .35f));
|
||||
}
|
||||
|
||||
Dqn_f32 pixels_per_kb = 15.5f;
|
||||
Dqn_f32 bar_width = DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap / DQN_KILOBYTES(1) * pixels_per_kb;
|
||||
Dqn_f32 pixels_per_kb = 15.5f;
|
||||
Dqn_f32 bar_width = DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap / DQN_KILOBYTES(1) * pixels_per_kb;
|
||||
|
||||
Dqn_f32 bar_x = next_pos.x + (phone_icon_rect.size.x * .25f);
|
||||
Dqn_f32 data_plan_t = player->terry_mobile_data_plan / DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap;
|
||||
|
||||
Reference in New Issue
Block a user