18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 10:46:45 +01:00

Merge the review fixes of the PRs below from feat/eu07m-clip-event into feat/eu07m-channels

RaPrepare() applies the clips, then the channels, then the animation events, so an event on a node takes over from both.
The spec has the fixes of #538, #540 and #542 in English.
This commit is contained in:
maj00r
2026-11-29 18:23:01 +01:00
23 changed files with 260 additions and 43 deletions
+23 -7
View File
@@ -572,6 +572,9 @@ void TAnimModel::update_instanceable_flag() {
// gfx.instancedlights: the lights go with the matrix of each instance (instance_light_bits()), and the instanced walk
// animates each instance (RaAnimate) and prepares the model with all the parts of the lights shown (RaPrepareInstanced)
if( ( iNumLights != 0 ) && ( false == Global.gfx_instancedlights ) ) { ++s_rejected_lights; return; }
// light colours of its own (lightcolors of the node) go onto the shared submodels as the instance is prepared (RaPrepare),
// which the instances of a bucket don't each get: such an instance is drawn on its own
if( std::ranges::any_of( m_lightcolors, []( glm::vec3 const &Colour ) { return Colour.r >= 0.f; } ) ) { ++s_rejected_lights; return; }
if( !m_animlist.empty() ) { ++s_rejected_animlist; return; }
if( submodel_tree_blocks_instancing( pModel->Root ) ) { ++s_rejected_animated_submodel; return; }
m_instanceable = true;
@@ -758,14 +761,15 @@ void TAnimModel::RaPrepare()
TSubModel::iVariantSeed = 0;
TSubModel::pasText = &asText; // przekazanie tekstu do wyświetlacza (!!!! do przemyślenia)
for (auto entry : m_animlist) {
entry->PrepareModel();
}
// the clips first, then the channels, as they may set the same nodes; an animation event of the scenery on a node (rotate,
// translate...) takes over from both, a clip which ended or was stopped included, as the later one set on the submodel counts
apply_clips();
// after the clips playing, as they may set the same nodes
if( ( pModel != nullptr ) && ( false == pModel->channels().empty() ) ) {
apply_channels();
}
for (auto entry : m_animlist) {
entry->PrepareModel();
}
}
// the state of the lit and the dark part of a numbered light, as RaPrepare() shows them
@@ -809,7 +813,11 @@ bool TAnimModel::play_clip( std::string_view const Name, float const Speed ) {
if( pModel == nullptr ) { return false; }
auto const &clips { pModel->clips() };
auto const found { std::ranges::find( clips, Name, &animation::clip::name ) };
// the name regardless of case, as the submodels are found by theirs
auto const same { [ Name ]( animation::clip const &Clip ) {
return std::ranges::equal( Clip.name, Name, []( char const Left, char const Right ) {
return std::tolower( static_cast<unsigned char>( Left ) ) == std::tolower( static_cast<unsigned char>( Right ) ); } ); } };
auto const found { std::ranges::find_if( clips, same ) };
if( found == clips.end() ) { return false; }
auto const index { static_cast<std::size_t>( std::distance( clips.begin(), found ) ) };
std::erase_if( m_clips, [ index ]( clip_playing const &Playing ) { return Playing.clip == index; } );
@@ -820,7 +828,15 @@ bool TAnimModel::play_clip( std::string_view const Name, float const Speed ) {
void TAnimModel::stop_clips() {
m_clips.clear();
// the clips are held where they are, not dropped: the pose lives in the submodels the instances of the model share, so the
// nodes of this instance are set again for each of its draws (apply_clips()), or another instance playing a clip would leave
// them at rest
auto const now { Timer::GetTime() };
for( auto &playing : m_clips ) {
if( false == playing.held.has_value() ) {
playing.held = ( now - playing.start ) * playing.speed;
}
}
m_autoplaystarted = true;
}
@@ -891,7 +907,7 @@ void TAnimModel::apply_clips() {
auto const count { pModel->submodel_count() };
for( auto const &playing : m_clips ) {
auto const &clip { clips[ playing.clip ] };
auto const time { animation::clip_time( clip, ( now - playing.start ) * playing.speed ) };
auto const time { animation::clip_time( clip, playing.held.value_or( ( now - playing.start ) * playing.speed ) ) };
for( auto const &node : clip.nodes ) {
if( ( node.node < 0 ) || ( node.node >= count ) ) { continue; }
root[ node.node ].SetClipTransform( animation::local_transform( clip, node, time ) );