mirror of https://github.com/OpenRCT2/OpenRCT2.git
Add StartRideMusic field to RTD
This commit is contained in:
parent
8c88a8684c
commit
a3ce24658c
|
@ -20,6 +20,7 @@
|
|||
#include "../object/MusicObject.h"
|
||||
#include "../object/ObjectManager.h"
|
||||
#include "Ride.h"
|
||||
#include "RideData.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
@ -31,21 +32,6 @@ namespace OpenRCT2::RideAudio
|
|||
{
|
||||
constexpr size_t MAX_RIDE_MUSIC_CHANNELS = 32;
|
||||
|
||||
/**
|
||||
* Represents a particular instance of ride music that can be heard in a viewport.
|
||||
* These are created each frame via enumerating each ride / viewport.
|
||||
*/
|
||||
struct ViewportRideMusicInstance
|
||||
{
|
||||
::RideId RideId;
|
||||
uint8_t TrackIndex{};
|
||||
|
||||
size_t Offset{};
|
||||
int16_t Volume{};
|
||||
int16_t Pan{};
|
||||
uint16_t Frequency{};
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents an audio channel to play a particular ride's music track.
|
||||
*/
|
||||
|
@ -186,56 +172,60 @@ namespace OpenRCT2::RideAudio
|
|||
_musicInstances.clear();
|
||||
}
|
||||
|
||||
static void StartRideMusicChannel(const ViewportRideMusicInstance& instance)
|
||||
void DefaultStartRideMusicChannel(const ViewportRideMusicInstance& instance)
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
// Create new music channel
|
||||
auto ride = get_ride(instance.RideId);
|
||||
if (ride->type == RIDE_TYPE_CIRCUS)
|
||||
auto musicObj = static_cast<MusicObject*>(objManager.GetLoadedObject(ObjectType::Music, ride->music));
|
||||
if (musicObj != nullptr)
|
||||
{
|
||||
ObjectEntryDescriptor desc(ObjectType::Audio, AudioObjectIdentifiers::Rct2Circus);
|
||||
auto audioObj = static_cast<AudioObject*>(objManager.GetLoadedObject(desc));
|
||||
if (audioObj != nullptr)
|
||||
auto track = musicObj->GetTrack(instance.TrackIndex);
|
||||
if (track != nullptr)
|
||||
{
|
||||
auto source = audioObj->GetSample(0);
|
||||
if (source != nullptr)
|
||||
auto stream = track->Asset.GetStream();
|
||||
if (stream != nullptr)
|
||||
{
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::Sound, false, 0);
|
||||
if (channel != nullptr)
|
||||
auto audioContext = GetContext()->GetAudioContext();
|
||||
auto source = audioContext->CreateStreamFromWAV(std::move(stream));
|
||||
if (source != nullptr)
|
||||
{
|
||||
_musicChannels.emplace_back(instance, channel, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto musicObj = static_cast<MusicObject*>(objManager.GetLoadedObject(ObjectType::Music, ride->music));
|
||||
if (musicObj != nullptr)
|
||||
{
|
||||
auto track = musicObj->GetTrack(instance.TrackIndex);
|
||||
if (track != nullptr)
|
||||
{
|
||||
auto stream = track->Asset.GetStream();
|
||||
if (stream != nullptr)
|
||||
{
|
||||
auto audioContext = GetContext()->GetAudioContext();
|
||||
auto source = audioContext->CreateStreamFromWAV(std::move(stream));
|
||||
if (source != nullptr)
|
||||
auto shouldLoop = musicObj->GetTrackCount() == 1;
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::RideMusic, shouldLoop, 0);
|
||||
if (channel != nullptr)
|
||||
{
|
||||
auto shouldLoop = musicObj->GetTrackCount() == 1;
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::RideMusic, shouldLoop, 0);
|
||||
if (channel != nullptr)
|
||||
{
|
||||
_musicChannels.emplace_back(instance, channel, source);
|
||||
}
|
||||
_musicChannels.emplace_back(instance, channel, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void CircusStartRideMusicChannel(const ViewportRideMusicInstance& instance)
|
||||
{
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
ObjectEntryDescriptor desc(ObjectType::Audio, AudioObjectIdentifiers::Rct2Circus);
|
||||
auto audioObj = static_cast<AudioObject*>(objManager.GetLoadedObject(desc));
|
||||
if (audioObj != nullptr)
|
||||
{
|
||||
auto source = audioObj->GetSample(0);
|
||||
if (source != nullptr)
|
||||
{
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::Sound, false, 0);
|
||||
if (channel != nullptr)
|
||||
{
|
||||
_musicChannels.emplace_back(instance, channel, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void StartRideMusicChannel(const ViewportRideMusicInstance& instance)
|
||||
{
|
||||
// Create new music channel
|
||||
auto ride = get_ride(instance.RideId);
|
||||
const auto& rtd = ride->GetRideTypeDescriptor();
|
||||
rtd.StartRideMusic(instance);
|
||||
}
|
||||
|
||||
static void StopInactiveRideMusicChannels()
|
||||
{
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../Identifiers.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct CoordsXYZ;
|
||||
|
@ -16,8 +18,26 @@ struct Ride;
|
|||
|
||||
namespace OpenRCT2::RideAudio
|
||||
{
|
||||
/**
|
||||
* Represents a particular instance of ride music that can be heard in a viewport.
|
||||
* These are created each frame via enumerating each ride / viewport.
|
||||
*/
|
||||
struct ViewportRideMusicInstance
|
||||
{
|
||||
::RideId RideId;
|
||||
uint8_t TrackIndex{};
|
||||
|
||||
size_t Offset{};
|
||||
int16_t Volume{};
|
||||
int16_t Pan{};
|
||||
uint16_t Frequency{};
|
||||
};
|
||||
|
||||
void ClearAllViewportInstances();
|
||||
void StopAllChannels();
|
||||
void UpdateMusicChannels();
|
||||
void UpdateMusicInstance(Ride& ride, const CoordsXYZ& rideCoords, uint16_t sampleRate);
|
||||
|
||||
void DefaultStartRideMusicChannel(const ViewportRideMusicInstance& instance);
|
||||
void CircusStartRideMusicChannel(const ViewportRideMusicInstance& instance);
|
||||
} // namespace OpenRCT2::RideAudio
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "../sprites.h"
|
||||
#include "../util/Util.h"
|
||||
#include "Ride.h"
|
||||
#include "RideAudio.h"
|
||||
#include "RideEntry.h"
|
||||
#include "ShopItem.h"
|
||||
#include "Track.h"
|
||||
|
@ -153,6 +154,7 @@ struct UpkeepCostsDescriptor
|
|||
using RideTrackGroup = OpenRCT2::BitSet<TRACK_GROUP_COUNT>;
|
||||
using RideMusicUpdateFunction = void (*)(Ride*);
|
||||
using PeepUpdateRideLeaveEntranceFunc = void (*)(Guest*, Ride*, CoordsXYZD&);
|
||||
using StartRideMusicFunction = void (*)(const OpenRCT2::RideAudio::ViewportRideMusicInstance&);
|
||||
struct RideTypeDescriptor
|
||||
{
|
||||
uint8_t AlternateType;
|
||||
|
@ -200,6 +202,7 @@ struct RideTypeDescriptor
|
|||
|
||||
// json name lookup
|
||||
std::string_view Name;
|
||||
StartRideMusicFunction StartRideMusic = OpenRCT2::RideAudio::DefaultStartRideMusicChannel;
|
||||
|
||||
TrackDesignCreateMode DesignCreateMode = TrackDesignCreateMode::Default;
|
||||
|
||||
|
@ -399,6 +402,7 @@ constexpr const RideTypeDescriptor DummyRTD =
|
|||
SET_FIELD(ColourPreview, { static_cast<uint32_t>(SPR_NONE), static_cast<uint32_t>(SPR_NONE) }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Ride),
|
||||
SET_FIELD(Name, "invalid"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::Ride),
|
||||
|
|
|
@ -51,5 +51,6 @@ constexpr const RideTypeDescriptor HybridCoasterRTD =
|
|||
SET_FIELD(ColourPreview, { SPR_RIDE_DESIGN_PREVIEW_HYBRID_COASTER_TRACK, SPR_RIDE_DESIGN_PREVIEW_HYBRID_COASTER_SUPPORTS }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Ride),
|
||||
SET_FIELD(Name, "hybrid_rc"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
};
|
||||
// clang-format on
|
||||
|
|
|
@ -50,6 +50,7 @@ constexpr const RideTypeDescriptor CircusRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Ride),
|
||||
SET_FIELD(Name, "circus"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::CircusStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, CircusMusicUpdate),
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../../sprites.h"
|
||||
#include "../../RideAudio.h"
|
||||
#include "../../RideData.h"
|
||||
#include "../../ShopItem.h"
|
||||
#include "../../Track.h"
|
||||
|
@ -51,6 +52,7 @@ constexpr const RideTypeDescriptor MazeRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Ride),
|
||||
SET_FIELD(Name, "maze"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Maze),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::Ride),
|
||||
|
|
|
@ -53,6 +53,7 @@ constexpr const RideTypeDescriptor SpiralSlideRTD =
|
|||
SET_FIELD(ColourPreview, { SPR_RIDE_DESIGN_PREVIEW_SPIRAL_SLIDE_TRACK, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Ride),
|
||||
SET_FIELD(Name, "spiral_slide"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::Ride),
|
||||
|
|
|
@ -47,6 +47,7 @@ constexpr const RideTypeDescriptor CashMachineRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::CashMachine),
|
||||
SET_FIELD(Name, "cash_machine"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::KioskOrFacility),
|
||||
|
|
|
@ -48,6 +48,7 @@ constexpr const RideTypeDescriptor DrinkStallRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Drink),
|
||||
SET_FIELD(Name, "drink_stall"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::ShopOrStall),
|
||||
|
|
|
@ -48,6 +48,7 @@ constexpr const RideTypeDescriptor FirstAidRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::FirstAid),
|
||||
SET_FIELD(Name, "first_aid"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::KioskOrFacility),
|
||||
|
|
|
@ -48,6 +48,7 @@ constexpr const RideTypeDescriptor FoodStallRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Food),
|
||||
SET_FIELD(Name, "food_stall"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::ShopOrStall),
|
||||
|
|
|
@ -48,6 +48,7 @@ constexpr const RideTypeDescriptor InformationKioskRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::InfoKiosk),
|
||||
SET_FIELD(Name, "information_kiosk"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::KioskOrFacility),
|
||||
|
|
|
@ -48,6 +48,7 @@ constexpr const RideTypeDescriptor ShopRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Shop),
|
||||
SET_FIELD(Name, "shop"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::ShopOrStall),
|
||||
|
|
|
@ -48,6 +48,7 @@ constexpr const RideTypeDescriptor ToiletsRTD =
|
|||
SET_FIELD(ColourPreview, { 0, 0 }),
|
||||
SET_FIELD(ColourKey, RideColourKey::Toilets),
|
||||
SET_FIELD(Name, "toilets"),
|
||||
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
|
||||
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
|
||||
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
|
||||
SET_FIELD(Classification, RideClassification::KioskOrFacility),
|
||||
|
|
Loading…
Reference in New Issue