simple_list to std::vector (nw)

This commit is contained in:
Miodrag Milanovic 2016-06-17 15:40:26 +02:00
parent f349b1083b
commit 5e906e9fcf
2 changed files with 30 additions and 34 deletions

View File

@ -42,7 +42,7 @@ device_sound_interface::~device_sound_interface()
// a new route to the device // a new route to the device
//------------------------------------------------- //-------------------------------------------------
device_sound_interface::sound_route &device_sound_interface::static_add_route(device_t &device, UINT32 output, const char *target, double gain, UINT32 input, UINT32 mixoutput) void device_sound_interface::static_add_route(device_t &device, UINT32 output, const char *target, double gain, UINT32 input, UINT32 mixoutput)
{ {
// find our sound interface // find our sound interface
device_sound_interface *sound; device_sound_interface *sound;
@ -50,7 +50,7 @@ device_sound_interface::sound_route &device_sound_interface::static_add_route(de
throw emu_fatalerror("MCFG_SOUND_ROUTE called on device '%s' with no sound interface", device.tag()); throw emu_fatalerror("MCFG_SOUND_ROUTE called on device '%s' with no sound interface", device.tag());
// append a new route to the list // append a new route to the list
return sound->m_route_list.append(*global_alloc(sound_route(output, input, gain, target, mixoutput))); sound->m_route_list.push_back(std::make_unique<sound_route>(output, input, gain, target, mixoutput));
} }
@ -67,7 +67,7 @@ void device_sound_interface::static_reset_routes(device_t &device)
throw emu_fatalerror("MCFG_SOUND_ROUTES_RESET called on device '%s' with no sound interface", device.tag()); throw emu_fatalerror("MCFG_SOUND_ROUTES_RESET called on device '%s' with no sound interface", device.tag());
// reset the routine list // reset the routine list
sound->m_route_list.reset(); sound->m_route_list.clear();
} }
@ -235,17 +235,17 @@ int device_sound_interface::inputnum_from_device(device_t &source_device, int ou
void device_sound_interface::interface_validity_check(validity_checker &valid) const void device_sound_interface::interface_validity_check(validity_checker &valid) const
{ {
// loop over all the routes // loop over all the routes
for (const sound_route &route : routes()) for (auto &route : routes())
{ {
// find a device with the requested tag // find a device with the requested tag
const device_t *target = device().siblingdevice(route.m_target.c_str()); const device_t *target = device().siblingdevice(route->m_target.c_str());
if (target == nullptr) if (target == nullptr)
osd_printf_error("Attempting to route sound to non-existant device '%s'\n", route.m_target.c_str()); osd_printf_error("Attempting to route sound to non-existant device '%s'\n", route->m_target.c_str());
// if it's not a speaker or a sound device, error // if it's not a speaker or a sound device, error
const device_sound_interface *sound; const device_sound_interface *sound;
if (target != nullptr && target->type() != SPEAKER && !target->interface(sound)) if (target != nullptr && target->type() != SPEAKER && !target->interface(sound))
osd_printf_error("Attempting to route sound to a non-sound device '%s' (%s)\n", route.m_target.c_str(), target->name()); osd_printf_error("Attempting to route sound to a non-sound device '%s' (%s)\n", route->m_target.c_str(), target->name());
} }
} }
@ -262,10 +262,10 @@ void device_sound_interface::interface_pre_start()
for (device_sound_interface &sound : iter) for (device_sound_interface &sound : iter)
{ {
// scan each route on the device // scan each route on the device
for (const sound_route &route : sound.routes()) for (auto &route : sound.routes())
{ {
// see if we are the target of this route; if we are, make sure the source device is started // see if we are the target of this route; if we are, make sure the source device is started
device_t *target_device = sound.device().siblingdevice(route.m_target.c_str()); device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
if (target_device == &m_device && !sound.device().started()) if (target_device == &m_device && !sound.device().started())
throw device_missing_dependencies(); throw device_missing_dependencies();
} }
@ -276,14 +276,14 @@ void device_sound_interface::interface_pre_start()
for (device_sound_interface &sound : iter) for (device_sound_interface &sound : iter)
{ {
// scan each route on the device // scan each route on the device
for (sound_route &route : sound.routes()) for (auto &route : sound.routes())
{ {
// see if we are the target of this route // see if we are the target of this route
device_t *target_device = sound.device().siblingdevice(route.m_target.c_str()); device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
if (target_device == &m_device && route.m_input == AUTO_ALLOC_INPUT) if (target_device == &m_device && route->m_input == AUTO_ALLOC_INPUT)
{ {
route.m_input = m_auto_allocated_inputs; route->m_input = m_auto_allocated_inputs;
m_auto_allocated_inputs += (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1; m_auto_allocated_inputs += (route->m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
} }
} }
} }
@ -301,32 +301,32 @@ void device_sound_interface::interface_post_start()
for (device_sound_interface &sound : sound_interface_iterator(m_device.machine().root_device())) for (device_sound_interface &sound : sound_interface_iterator(m_device.machine().root_device()))
{ {
// scan each route on the device // scan each route on the device
for (const sound_route &route : sound.routes()) for (auto &route : sound.routes())
{ {
// if we are the target of this route, hook it up // if we are the target of this route, hook it up
device_t *target_device = sound.device().siblingdevice(route.m_target.c_str()); device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
if (target_device == &m_device) if (target_device == &m_device)
{ {
// iterate over all outputs, matching any that apply // iterate over all outputs, matching any that apply
int inputnum = route.m_input; int inputnum = route->m_input;
int numoutputs = sound.outputs(); int numoutputs = sound.outputs();
for (int outputnum = 0; outputnum < numoutputs; outputnum++) for (int outputnum = 0; outputnum < numoutputs; outputnum++)
if (route.m_output == outputnum || route.m_output == ALL_OUTPUTS) if (route->m_output == outputnum || route->m_output == ALL_OUTPUTS)
{ {
// find the output stream to connect from // find the output stream to connect from
int streamoutputnum; int streamoutputnum;
sound_stream *outputstream = sound.output_to_stream_output(outputnum, streamoutputnum); sound_stream *outputstream = sound.output_to_stream_output(outputnum, streamoutputnum);
if (outputstream == nullptr) if (outputstream == nullptr)
fatalerror("Sound device '%s' specifies route for non-existant output #%d\n", route.m_target.c_str(), outputnum); fatalerror("Sound device '%s' specifies route for non-existant output #%d\n", route->m_target.c_str(), outputnum);
// find the input stream to connect to // find the input stream to connect to
int streaminputnum; int streaminputnum;
sound_stream *inputstream = input_to_stream_input(inputnum++, streaminputnum); sound_stream *inputstream = input_to_stream_input(inputnum++, streaminputnum);
if (inputstream == nullptr) if (inputstream == nullptr)
fatalerror("Sound device '%s' targeted output #%d to non-existant device '%s' input %d\n", route.m_target.c_str(), outputnum, m_device.tag(), inputnum - 1); fatalerror("Sound device '%s' targeted output #%d to non-existant device '%s' input %d\n", route->m_target.c_str(), outputnum, m_device.tag(), inputnum - 1);
// set the input // set the input
inputstream->set_input(streaminputnum, outputstream, streamoutputnum, route.m_gain); inputstream->set_input(streaminputnum, outputstream, streamoutputnum, route->m_gain);
} }
} }
} }
@ -358,8 +358,7 @@ void device_sound_interface::interface_pre_reset()
//------------------------------------------------- //-------------------------------------------------
device_sound_interface::sound_route::sound_route(int output, int input, float gain, const char *target, UINT32 mixoutput) device_sound_interface::sound_route::sound_route(int output, int input, float gain, const char *target, UINT32 mixoutput)
: m_next(nullptr), : m_output(output),
m_output(output),
m_input(input), m_input(input),
m_mixoutput(mixoutput), m_mixoutput(mixoutput),
m_gain(gain), m_gain(gain),
@ -416,15 +415,15 @@ void device_mixer_interface::interface_pre_start()
// iterate through all routes that point to us and note their mixer output // iterate through all routes that point to us and note their mixer output
for (device_sound_interface &sound : sound_interface_iterator(m_device.machine().root_device())) for (device_sound_interface &sound : sound_interface_iterator(m_device.machine().root_device()))
for (const sound_route &route : sound.routes()) for (auto &route : sound.routes())
{ {
// see if we are the target of this route // see if we are the target of this route
device_t *target_device = sound.device().siblingdevice(route.m_target.c_str()); device_t *target_device = sound.device().siblingdevice(route->m_target.c_str());
if (target_device == &device() && route.m_input < m_auto_allocated_inputs) if (target_device == &device() && route->m_input < m_auto_allocated_inputs)
{ {
int count = (route.m_output == ALL_OUTPUTS) ? sound.outputs() : 1; int count = (route->m_output == ALL_OUTPUTS) ? sound.outputs() : 1;
for (int output = 0; output < count; output++) for (int output = 0; output < count; output++)
m_outputmap[route.m_input + output] = route.m_mixoutput; m_outputmap[route->m_input + output] = route->m_mixoutput;
} }
} }

View File

@ -70,9 +70,6 @@ public:
public: public:
sound_route(int output, int input, float gain, const char *target, UINT32 mixoutput); sound_route(int output, int input, float gain, const char *target, UINT32 mixoutput);
sound_route *next() const { return m_next; }
sound_route * m_next; // pointer to next route
UINT32 m_output; // output index, or ALL_OUTPUTS UINT32 m_output; // output index, or ALL_OUTPUTS
UINT32 m_input; // target input index UINT32 m_input; // target input index
UINT32 m_mixoutput; // target mixer output UINT32 m_mixoutput; // target mixer output
@ -85,10 +82,10 @@ public:
virtual ~device_sound_interface(); virtual ~device_sound_interface();
// configuration access // configuration access
const simple_list<sound_route> &routes() const { return m_route_list; } const std::vector<std::unique_ptr<sound_route>> &routes() const { return m_route_list; }
// static inline configuration helpers // static inline configuration helpers
static sound_route &static_add_route(device_t &device, UINT32 output, const char *target, double gain, UINT32 input = AUTO_ALLOC_INPUT, UINT32 mixoutput = 0); static void static_add_route(device_t &device, UINT32 output, const char *target, double gain, UINT32 input = AUTO_ALLOC_INPUT, UINT32 mixoutput = 0);
static void static_reset_routes(device_t &device); static void static_reset_routes(device_t &device);
// sound stream update overrides // sound stream update overrides
@ -114,7 +111,7 @@ protected:
virtual void interface_pre_reset() override; virtual void interface_pre_reset() override;
// internal state // internal state
simple_list<sound_route> m_route_list; // list of sound routes std::vector<std::unique_ptr<sound_route>> m_route_list; // list of sound routes
int m_outputs; // number of outputs from this instance int m_outputs; // number of outputs from this instance
int m_auto_allocated_inputs; // number of auto-allocated inputs targeting us int m_auto_allocated_inputs; // number of auto-allocated inputs targeting us
}; };