mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
audio synchronization fix
This commit is contained in:
@@ -3511,7 +3511,7 @@ void TDynamicObject::RenderSounds()
|
||||
// McZapkie-010302: ulepszony dzwiek silnika
|
||||
double freq;
|
||||
double vol = 0;
|
||||
double dt = Timer::GetDeltaTime();
|
||||
double dt = Timer::GetDeltaRenderTime();
|
||||
|
||||
// double sounddist;
|
||||
// sounddist=SquareMagnitude(Global::pCameraPosition-vPosition);
|
||||
|
||||
@@ -1029,7 +1029,7 @@ bool TWorld::Update() {
|
||||
}
|
||||
|
||||
simulation::Events.update();
|
||||
simulation::Region->update();
|
||||
simulation::Region->update_events();
|
||||
simulation::Lights.update();
|
||||
|
||||
// render time routines follow:
|
||||
@@ -1062,6 +1062,7 @@ bool TWorld::Update() {
|
||||
|
||||
Timer::subsystem.sim_total.stop();
|
||||
|
||||
simulation::Region->update_sounds();
|
||||
GfxRenderer.Update( dt );
|
||||
ResourceSweep();
|
||||
|
||||
|
||||
131
scene.cpp
131
scene.cpp
@@ -17,42 +17,6 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
namespace scene {
|
||||
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
basic_cell::update() {
|
||||
|
||||
// sounds
|
||||
auto const deltatime = Timer::GetDeltaTime();
|
||||
for( auto *sound : m_sounds ) {
|
||||
|
||||
if( ( sound->GetStatus() & DSBSTATUS_PLAYING ) == DSBPLAY_LOOPING ) {
|
||||
sound->Play( 1, DSBPLAY_LOOPING, true, sound->vSoundPosition );
|
||||
sound->AdjFreq( 1.0, deltatime );
|
||||
}
|
||||
}
|
||||
// event launchers
|
||||
for( auto *launcher : m_eventlaunchers ) {
|
||||
if( ( true == launcher->check_conditions() )
|
||||
&& ( SquareMagnitude( launcher->location() - Global::pCameraPosition ) < launcher->dRadius ) ) {
|
||||
|
||||
WriteLog( "Eventlauncher " + launcher->name() );
|
||||
if( ( true == Global::shiftState )
|
||||
&& ( launcher->Event2 != nullptr ) ) {
|
||||
simulation::Events.AddToQuery( launcher->Event2, nullptr );
|
||||
}
|
||||
else if( launcher->Event1 ) {
|
||||
simulation::Events.AddToQuery( launcher->Event1, nullptr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TBD, TODO: move to sound renderer
|
||||
for( auto *path : m_paths ) {
|
||||
// dźwięki pojazdów, również niewidocznych
|
||||
path->RenderDynSounds();
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, finds and assigns traction piece to specified pantograph of provided vehicle
|
||||
void
|
||||
basic_cell::update_traction( TDynamicObject *Vehicle, int const Pantographindex ) {
|
||||
@@ -130,6 +94,47 @@ basic_cell::update_traction( TDynamicObject *Vehicle, int const Pantographindex
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
basic_cell::update_events() {
|
||||
|
||||
// event launchers
|
||||
for( auto *launcher : m_eventlaunchers ) {
|
||||
if( ( true == launcher->check_conditions() )
|
||||
&& ( SquareMagnitude( launcher->location() - Global::pCameraPosition ) < launcher->dRadius ) ) {
|
||||
|
||||
WriteLog( "Eventlauncher " + launcher->name() );
|
||||
if( ( true == Global::shiftState )
|
||||
&& ( launcher->Event2 != nullptr ) ) {
|
||||
simulation::Events.AddToQuery( launcher->Event2, nullptr );
|
||||
}
|
||||
else if( launcher->Event1 ) {
|
||||
simulation::Events.AddToQuery( launcher->Event1, nullptr );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
basic_cell::update_sounds() {
|
||||
|
||||
// sounds
|
||||
auto const deltatime = Timer::GetDeltaRenderTime();
|
||||
for( auto *sound : m_sounds ) {
|
||||
|
||||
if( ( sound->GetStatus() & DSBSTATUS_PLAYING ) == DSBPLAY_LOOPING ) {
|
||||
sound->Play( 1, DSBPLAY_LOOPING, true, sound->vSoundPosition );
|
||||
sound->AdjFreq( 1.0, deltatime );
|
||||
}
|
||||
}
|
||||
// TBD, TODO: move to sound renderer
|
||||
for( auto *path : m_paths ) {
|
||||
// dźwięki pojazdów, również niewidocznych
|
||||
path->RenderDynSounds();
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, triggers radio-stop procedure for all vehicles located on paths in the cell
|
||||
void
|
||||
basic_cell::radio_stop() {
|
||||
@@ -479,19 +484,6 @@ basic_cell::enclose_area( editor::basic_node *Node ) {
|
||||
|
||||
|
||||
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
basic_section::update( glm::dvec3 const &Location, float const Radius ) {
|
||||
|
||||
for( auto &cell : m_cells ) {
|
||||
|
||||
if( glm::length2( cell.area().center - Location ) < ( ( cell.area().radius + Radius ) * ( cell.area().radius + Radius ) ) ) {
|
||||
// we reject cells which aren't within our area of interest
|
||||
cell.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, finds and assigns traction piece(s) to pantographs of provided vehicle
|
||||
void
|
||||
basic_section::update_traction( TDynamicObject *Vehicle, int const Pantographindex ) {
|
||||
@@ -514,6 +506,32 @@ basic_section::update_traction( TDynamicObject *Vehicle, int const Pantographind
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, polls event launchers within radius around specified point
|
||||
void
|
||||
basic_section::update_events( glm::dvec3 const &Location, float const Radius ) {
|
||||
|
||||
for( auto &cell : m_cells ) {
|
||||
|
||||
if( glm::length2( cell.area().center - Location ) < ( ( cell.area().radius + Radius ) * ( cell.area().radius + Radius ) ) ) {
|
||||
// we reject cells which aren't within our area of interest
|
||||
cell.update_events();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, updates sounds within radius around specified point
|
||||
void
|
||||
basic_section::update_sounds( glm::dvec3 const &Location, float const Radius ) {
|
||||
|
||||
for( auto &cell : m_cells ) {
|
||||
|
||||
if( glm::length2( cell.area().center - Location ) < ( ( cell.area().radius + Radius ) * ( cell.area().radius + Radius ) ) ) {
|
||||
// we reject cells which aren't within our area of interest
|
||||
cell.update_sounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, triggers radio-stop procedure for all vehicles in 2km radius around specified location
|
||||
void
|
||||
basic_section::radio_stop( glm::dvec3 const &Location, float const Radius ) {
|
||||
@@ -706,14 +724,25 @@ basic_region::~basic_region() {
|
||||
for( auto *section : m_sections ) { if( section != nullptr ) { delete section; } }
|
||||
}
|
||||
|
||||
// legacy method, polls event launchers around camera
|
||||
void
|
||||
basic_region::update_events() {
|
||||
// render events and sounds from sectors near enough to the viewer
|
||||
auto const range = EU07_SECTIONSIZE; // arbitrary range
|
||||
auto const §ionlist = sections( Global::pCameraPosition, range );
|
||||
for( auto *section : sectionlist ) {
|
||||
section->update_events( Global::pCameraPosition, range );
|
||||
}
|
||||
}
|
||||
|
||||
// legacy method, updates sounds and polls event launchers around camera
|
||||
void
|
||||
basic_region::update() {
|
||||
basic_region::update_sounds() {
|
||||
// render events and sounds from sectors near enough to the viewer
|
||||
auto const range = 2750.f; // audible range of 100 db sound
|
||||
auto const §ionlist = sections( Global::pCameraPosition, range );
|
||||
for( auto *section : sectionlist ) {
|
||||
section->update( Global::pCameraPosition, range );
|
||||
section->update_sounds( Global::pCameraPosition, range );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
scene.h
31
scene.h
@@ -63,12 +63,15 @@ class basic_cell {
|
||||
|
||||
public:
|
||||
// methods
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
update();
|
||||
// legacy method, finds and assigns traction piece to specified pantograph of provided vehicle
|
||||
void
|
||||
update_traction( TDynamicObject *Vehicle, int const Pantographindex );
|
||||
// legacy method, polls event launchers within radius around specified point
|
||||
void
|
||||
update_events();
|
||||
// legacy method, updates sounds within radius around specified point
|
||||
void
|
||||
update_sounds();
|
||||
// legacy method, triggers radio-stop procedure for all vehicles located on paths in the cell
|
||||
void
|
||||
radio_stop();
|
||||
@@ -171,12 +174,15 @@ class basic_section {
|
||||
|
||||
public:
|
||||
// methods
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
update( glm::dvec3 const &Location, float const Radius );
|
||||
// legacy method, finds and assigns traction piece to specified pantograph of provided vehicle
|
||||
// legacy method, finds and assigns traction piece to specified pantograph of provided vehicle
|
||||
void
|
||||
update_traction( TDynamicObject *Vehicle, int const Pantographindex );
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
update_events( glm::dvec3 const &Location, float const Radius );
|
||||
// legacy method, updates sounds and polls event launchers within radius around specified point
|
||||
void
|
||||
update_sounds( glm::dvec3 const &Location, float const Radius );
|
||||
// legacy method, triggers radio-stop procedure for all vehicles in 2km radius around specified location
|
||||
void
|
||||
radio_stop( glm::dvec3 const &Location, float const Radius );
|
||||
@@ -255,12 +261,15 @@ public:
|
||||
// destructor
|
||||
~basic_region();
|
||||
// methods
|
||||
// legacy method, updates sounds and polls event launchers around camera
|
||||
void
|
||||
update();
|
||||
// legacy method, finds and assigns traction piece to specified pantograph of provided vehicle
|
||||
// legacy method, finds and assigns traction piece to specified pantograph of provided vehicle
|
||||
void
|
||||
update_traction( TDynamicObject *Vehicle, int const Pantographindex );
|
||||
// legacy method, polls event launchers around camera
|
||||
void
|
||||
update_events();
|
||||
// legacy method, updates sounds around camera
|
||||
void
|
||||
update_sounds();
|
||||
// stores content of the class in file with specified name
|
||||
void
|
||||
serialize( std::string const &Scenariofile );
|
||||
|
||||
Reference in New Issue
Block a user