From 64c54b8a3879f8f4411840f8cd596b24ddd5507c Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:31:37 +0100 Subject: [PATCH] feat(events): the animation event starts and stops the clips of EU07M models A clip of stage 8 played on its own (autoplay) or from the code; a scenery event can start it now. - New form of the animation event: "animation clip ". A pace above 0 starts the clip from its beginning at that pace (a clip playing starts over), 0 stops the clips of the model, its nodes left where the clips put them. A clip the model hasn't gets "Bad event: ... can't find clip ..." in the log. The event is written back in the same form. The forms before it (rotate, translate, digital, .vmd) read and run as they did. The current release doesn't read the new form. - The editor self-test gets "eventrun ", which finds the targets of the event and runs it at once, since the editor runs no events. Checked in the game (Vulkan): after "clip bend 0" the tube stands still (no pixel differs between three shots), after "clip bend 2" it moves, "clip nosuchclip 1" logs the error (time let run in the editor for the test only). No unit test: the unit tests don't link world/Event.cpp. Unit tests 1200/1200. Not built with GCC here. --- application/editormodeselftest.cpp | 1 + application/editormodeselftestscene.cpp | 13 +++++++++ docs/eu07m-format.md | 9 +++++-- world/Event.cpp | 35 +++++++++++++++++++++++++ world/Event.h | 3 +++ 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index c211d7ce3..a62a02f53 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -99,6 +99,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c // key [ctrl] a key or right button event, as the window gives it // lineside the tab of the objects along the track in the track window // event queues the event +// eventrun runs the event at once, its targets found first, as the simulation does (the editor runs none) // clip [speed] starts an animation clip of the model of the instance (EU07M), by the simulation time // animate turns a submodel of a model instance to the angles, as an animation event does (the // editor doesn't run the events); the animation goes by the simulation time diff --git a/application/editormodeselftestscene.cpp b/application/editormodeselftestscene.cpp index 978fdae42..71c0ce808 100644 --- a/application/editormodeselftestscene.cpp +++ b/application/editormodeselftestscene.cpp @@ -573,6 +573,19 @@ editor_mode::selftest_result editor_mode::selftest_scene(std::string const &comm WriteLog("SELFTEST event " + name + (event != nullptr ? " queued" : ": no such event")); return selftest_result::handled; } + if (command == "eventrun") + { + std::string name; + words >> name; + auto *event{simulation::Events.FindEvent(name)}; + if (event != nullptr) + { + event->init(); + event->run(); + } + WriteLog("SELFTEST eventrun " + name + (event != nullptr ? " run" : ": no such event")); + return selftest_result::handled; + } if (command == "clip") { std::string node; diff --git a/docs/eu07m-format.md b/docs/eu07m-format.md index 2c503641f..975516f02 100644 --- a/docs/eu07m-format.md +++ b/docs/eu07m-format.md @@ -262,8 +262,13 @@ Części węzła bez ścieżki zostają takie, jak w jego TRS. ustawia transformy węzłów (`TSubModel::SetClipTransform()`, animacja `at_Clip`), tak jak inne animacje egzemplarza. Węzły, które klipy przesuwają, są przy wczytaniu oznaczane jako animowane, więc model z klipami nie jest instancjonowany. Klip ruszający jointami skóry zgina skinowane części (sekcja „Skinning”). -- **Jeszcze nie:** event scenerii, który startuje klip, oraz powiązanie kanałów `CHNL` z czasem klipu. Obecne wydanie - nie czyta tych sekcji, a plik bez nich wczytuje się jak dotąd. +- **Event scenerii.** `event animation clip endevent` startuje klip od + początku w podanym tempie (klip już grający zaczyna od nowa), a tempo 0 zatrzymuje klipy modelu; węzły zostają tam, + gdzie klip je zostawił. Klip, którego model nie ma, daje w logu `Bad event: ... can't find clip`. To nowa forma + eventu `animation`, której obecne wydanie nie czyta; dotychczasowe formy (`rotate`, `translate`, `digital`, `.vmd`) + czytają się jak dotąd. +- **Jeszcze nie:** powiązanie kanałów `CHNL` z czasem klipu. Obecne wydanie nie czyta sekcji klipów, a plik bez nich + wczytuje się jak dotąd. ### Skinning diff --git a/world/Event.cpp b/world/Event.cpp index ba51d4078..cf02e9409 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -1576,6 +1576,10 @@ animation_event::init() { // animacja modelu init_targets( simulation::Instances, "model instance" ); // custom target initialization code + if( m_animationtype == clip_animation ) { + // clips go by the model, not by its submodels + return; + } if( m_animationtype == 4 ) { // vmd animations target whole model return; @@ -1657,6 +1661,14 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) >> m_animationparams[ 2 ] >> m_animationparams[ 3 ]; } + else if( token == "clip" ) { + // an animation clip of the model (EU07M): its name and pace; a pace of 0 stops the clips playing + Input.getTokens(); + Input >> m_animationsubmodel; + m_animationtype = clip_animation; + Input.getTokens( 1 ); + Input >> m_animationparams[ 0 ]; + } else if( token.ends_with(".vmd") ) // na razie tu, może będzie inaczej { // animacja z pliku VMD { @@ -1692,6 +1704,10 @@ void animation_event::run_() { WriteLog( "Type: Animation" ); + if( m_animationtype == clip_animation ) { + run_clips(); + return; + } // animation modes target specific submodels m_animationcontainers.remove_if([this](std::weak_ptr ptr) { @@ -1721,6 +1737,21 @@ animation_event::run_() { }); } +void +animation_event::run_clips() const { + + for( auto const &target : m_targets ) { + auto *model { static_cast( std::get( target ) ) }; + if( model == nullptr ) { continue; } + if( m_animationparams[ 0 ] <= 0.0 ) { + model->stop_clips(); + } + else if( false == model->play_clip( m_animationsubmodel, static_cast( m_animationparams[ 0 ] ) ) ) { + ErrorLog( "Bad event: \"" + m_name + "\" (type: " + type() + ") can't find clip " + m_animationsubmodel + " in model instance \"" + model->name() + "\"" ); + } + } +} + void animation_event::finish() const { @@ -1735,6 +1766,10 @@ animation_event::finish() const { void animation_event::export_as_text_( std::ostream &Output ) const { + if( m_animationtype == clip_animation ) { + Output << "clip " << m_animationsubmodel << ' ' << m_animationparams[ 0 ] << ' '; + return; + } // animation type Output << ( m_animationtype == 1 ? "rotate" : diff --git a/world/Event.h b/world/Event.h index 91ed85973..d6125ff38 100644 --- a/world/Event.h +++ b/world/Event.h @@ -439,6 +439,8 @@ public: void init() override; // the animation it set brought to its end at once, for the editor which shows it with the time stopped void finish() const; + // the form "clip ": an animation clip of the model (EU07M) started, or the clips stopped with a pace of 0 + static constexpr int clip_animation{ 16 }; private: // methods @@ -448,6 +450,7 @@ private: void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override; // run() subclass details void run_() override; + void run_clips() const; // export_as_text() subclass details void export_as_text_( std::ostream &Output ) const override; // members