@@ -198,7 +198,7 @@ namespace Lux {
198198 }
199199 });
200200 }
201-
201+ /*
202202 // Scripting
203203 {
204204 ScriptEngine::OnRuntimeStart(this);
@@ -210,7 +210,7 @@ namespace Lux {
210210 Entity entity = { e, this };
211211 ScriptEngine::OnCreateEntity(entity);
212212 }
213- }
213+ }*/
214214 }
215215
216216 void Scene::OnRuntimeStop ()
@@ -252,7 +252,7 @@ namespace Lux {
252252 });
253253 }
254254
255- ScriptEngine::OnRuntimeStop ();
255+ // ScriptEngine::OnRuntimeStop();
256256 }
257257
258258 void Scene::OnSimulationStart ()
@@ -280,10 +280,15 @@ namespace Lux {
280280
281281 m_Registry.view <NativeScriptComponent>().each ([=](auto entity, auto & nsc)
282282 {
283- // TODO: Move to Scene::OnScenePlay
284283 if (!nsc.Instance )
285284 {
285+ if (!nsc.InstantiateScript )
286+ return ;
287+
286288 nsc.Instance = nsc.InstantiateScript ();
289+ if (!nsc.Instance )
290+ return ;
291+
287292 nsc.Instance ->m_Entity = Entity{ entity, this };
288293 nsc.Instance ->OnCreate ();
289294 }
@@ -351,85 +356,64 @@ namespace Lux {
351356 if (asc.Audio && !asc.AudioSourceData .UsePlaylist )
352357 {
353358 Ref<AudioSource> audioSource = AssetManager::GetAsset<AudioSource>(asc.Audio );
359+ if (!audioSource)
360+ return ;
361+
354362 if (!audioSource->IsPlaying () && asc.Paused )
355363 {
356364 audioSource->SetConfig (asc.Config );
357365 audioSource->Play ();
358366 asc.Paused = false ;
359367 }
360368
361- if (audioSource != nullptr )
362- {
363- audioSource->SetConfig (asc.Config );
364- audioSource->SetPosition (glm::vec4 (transform.Translation , 1 .0f ));
365- // audioSource->SetDirection(forward);
366- }
369+ audioSource->SetConfig (asc.Config );
370+ audioSource->SetPosition (glm::vec4 (transform.Translation , 1 .0f ));
367371 }
368372 else if (asc.Audio && asc.AudioSourceData .UsePlaylist )
369373 {
370- LUX_PROFILE_SCOPE_COLOR (" Scene::OnUpdateRuntime::AudioSourceComponent 2 Scope" , 0xEE3AFF );
374+ auto & playlist = asc.AudioSourceData .Playlist ;
375+
376+ if (playlist.empty ())
377+ return ;
371378
372- Ref<AudioSource> audioSourceIndex = AssetManager::GetAsset<AudioSource>(asc.AudioSourceData .Playlist [asc.AudioSourceData .OldIndex ]);
379+ if (asc.AudioSourceData .OldIndex >= playlist.size ())
380+ asc.AudioSourceData .OldIndex = 0 ;
373381
374- // if (ac.AudioSourceData.OldIndex <= ac.AudioSourceData.Playlist.size() - 1)
375- if (asc.AudioSourceData .CurrentIndex < asc.AudioSourceData .Playlist .size () && audioSourceIndex != nullptr && asc.Config .PlayOnAwake && !audioSourceIndex->IsPlaying () && !asc.Paused )
382+ if (asc.AudioSourceData .CurrentIndex >= playlist.size ())
376383 {
377- LUX_PROFILE_SCOPE_COLOR (" Scene::OnUpdateRuntime::AudioSourceComponent 3 Scope" , 0xFF8E68 );
384+ if (asc.AudioSourceData .RepeatPlaylist )
385+ asc.AudioSourceData .CurrentIndex = 0 ;
386+ else
387+ return ;
388+ }
378389
379- audioSourceIndex = AssetManager::GetAsset<AudioSource>(asc.AudioSourceData .Playlist [asc.AudioSourceData .CurrentIndex ]);
390+ Ref<AudioSource> oldSource = AssetManager::GetAsset<AudioSource>(playlist[asc.AudioSourceData .OldIndex ]);
391+ Ref<AudioSource> currentSource = AssetManager::GetAsset<AudioSource>(playlist[asc.AudioSourceData .CurrentIndex ]);
380392
381- if (!audioSourceIndex->IsLooping ())
393+ if (!currentSource)
394+ return ;
395+
396+ if (asc.Config .PlayOnAwake && !asc.Paused && (!oldSource || !oldSource->IsPlaying ()))
397+ {
398+ if (!currentSource->IsLooping ())
382399 {
383- LUX_PROFILE_SCOPE_COLOR (" Scene::OnUpdateRuntime::AudioSourceComponent 4 Scope" , 0xFF2F68 );
400+ currentSource->SetConfig (asc.Config );
401+ currentSource->Play ();
402+ currentSource->SetPosition (glm::vec4 (transform.Translation , 1 .0f ));
384403
385- audioSourceIndex->SetConfig (asc.Config );
386- audioSourceIndex->Play ();
387404 asc.AudioSourceData .PlayingCurrentIndex = true ;
388405 asc.Paused = false ;
389-
390- // const rtmcpp::Mat4 inverted = rtmcpp::Inverse(transform.GetTransform());
391- // const rtmcpp::Vec3 forward = rtm::vector_normalize3(inverted.Value.z_axis);
392-
393- audioSourceIndex->SetConfig (asc.Config );
394- audioSourceIndex->SetPosition (glm::vec4 (transform.Translation , 1 .0f ));
395- // audioSourceIndex->SetDirection(forward);
396-
397- if (asc.AudioSourceData .RepeatAfterSpecificTrackPlays && asc.AudioSourceData .CurrentIndex == asc.AudioSourceData .StartIndex )
398- {
399- LUX_PROFILE_SCOPE_COLOR (" Scene::OnUpdateRuntime::AudioSourceComponent 5 Scope" , 0xA191FF );
400-
401- audioSourceIndex->SetLooping (true );
402- }
403-
404- if (asc.AudioSourceData .OldIndex != asc.AudioSourceData .CurrentIndex )
405- {
406- LUX_PROFILE_SCOPE_COLOR (" Scene::OnUpdateRuntime::AudioSourceComponent 6 Scope" , 0x8CCBFF );
407-
408- asc.AudioSourceData .OldIndex = asc.AudioSourceData .CurrentIndex ;
409- }
410-
406+ asc.AudioSourceData .OldIndex = asc.AudioSourceData .CurrentIndex ;
411407 asc.AudioSourceData .CurrentIndex ++;
412408 }
413409 }
414- else if (asc.AudioSourceData . CurrentIndex < asc. AudioSourceData . Playlist . size () && audioSourceIndex != nullptr && asc. Config .PlayOnAwake && asc.Paused )
410+ else if (asc.Config .PlayOnAwake && asc.Paused )
415411 {
416- audioSourceIndex ->SetConfig (asc.Config );
417- audioSourceIndex ->Play ();
412+ currentSource ->SetConfig (asc.Config );
413+ currentSource ->Play ();
418414 asc.AudioSourceData .PlayingCurrentIndex = true ;
419415 asc.Paused = false ;
420416 }
421-
422- if (asc.AudioSourceData .RepeatPlaylist && !asc.AudioSourceData .RepeatAfterSpecificTrackPlays && asc.AudioSourceData .CurrentIndex >= asc.AudioSourceData .Playlist .size ())
423- {
424- if (audioSourceIndex != nullptr && !audioSourceIndex->IsPlaying ())
425- asc.AudioSourceData .CurrentIndex = 0 ;
426- }
427-
428- if (asc.AudioSourceData .RepeatAfterSpecificTrackPlays && !asc.AudioSourceData .RepeatPlaylist && asc.AudioSourceData .CurrentIndex > asc.AudioSourceData .StartIndex )
429- {
430- if (audioSourceIndex != nullptr && !audioSourceIndex->IsPlaying ())
431- asc.AudioSourceData .CurrentIndex = asc.AudioSourceData .StartIndex ;
432- }
433417 }
434418 });
435419 }
@@ -470,7 +454,7 @@ namespace Lux {
470454 if (!asc.AudioSourceData .UsePlaylist )
471455 {
472456 Ref<AudioSource> audioSource = AssetManager::GetAsset<AudioSource>(asc.Audio );
473- if (audioSource->IsPlaying ())
457+ if (audioSource && audioSource ->IsPlaying ())
474458 {
475459 audioSource->SetConfig (asc.Config );
476460 audioSource->Pause ();
0 commit comments