-Got rid of most of the remaining problematic uses of make_unique_clear.

-sound/discrete.cpp: Use C++ std::vector and range-based for.
This commit is contained in:
Vas Crabb 2020-09-30 14:10:43 +10:00
parent dfb6ab880b
commit 3b59cb8860
27 changed files with 337 additions and 359 deletions

View File

@ -44,9 +44,6 @@
#include <iostream>
/* for_each collides with c++ standard libraries - include it here */
#define for_each(_T, _e, _l) for (_T _e = (_l)->begin_ptr() ; _e <= (_l)->end_ptr(); _e++)
// device type definition
DEFINE_DEVICE_TYPE(DISCRETE, discrete_sound_device, "discrete", "Discrete Sound")
@ -124,7 +121,7 @@ public:
node_step_list_t step_list;
/* list of source nodes */
vector_t<input_buffer> source_list; /* discrete_source_node */
std::vector<input_buffer> source_list; /* discrete_source_node */
int task_group;
@ -144,7 +141,7 @@ protected:
void check(discrete_task *dest_task);
void prepare_for_queue(int samples);
vector_t<output_buffer> m_buffers;
std::vector<output_buffer> m_buffers;
discrete_device & m_device;
private:
@ -183,27 +180,25 @@ private:
inline void discrete_task::step_nodes(void)
{
for_each(input_buffer *, sn, &source_list)
for (input_buffer &sn : source_list)
{
sn->buffer = *sn->ptr++;
sn.buffer = *sn.ptr++;
}
if (EXPECTED(!m_device.profiling()))
{
for_each(discrete_step_interface **, entry, &step_list)
for (discrete_step_interface *entry : step_list)
{
/* Now step the node */
(*entry)->step();
entry->step();
}
}
else
{
osd_ticks_t last = get_profile_ticks();
for_each(discrete_step_interface **, entry, &step_list)
for (discrete_step_interface *node : step_list)
{
discrete_step_interface *node = *entry;
node->run_time -= last;
node->step();
last = get_profile_ticks();
@ -212,8 +207,8 @@ inline void discrete_task::step_nodes(void)
}
/* buffer the outputs */
for_each(output_buffer *, outbuf, &m_buffers)
*(outbuf->ptr++) = *outbuf->source;
for (output_buffer &outbuf : m_buffers)
*outbuf.ptr++ = *outbuf.source;
}
void *discrete_task::task_callback(void *param, int threadid)
@ -221,14 +216,14 @@ void *discrete_task::task_callback(void *param, int threadid)
task_list_t *list = (task_list_t *) param;
do
{
for_each(discrete_task **, task, list)
for (discrete_task *task : *list)
{
/* try to lock */
if ((*task)->lock_threadid(threadid))
if (task->lock_threadid(threadid))
{
if (!(*task)->process())
if (!task->process())
return nullptr;
(*task)->unlock();
task->unlock();
}
}
} while (1);
@ -241,11 +236,9 @@ bool discrete_task::process(void)
int samples = std::min(int(m_samples), MAX_SAMPLES_PER_TASK_SLICE);
/* check dependencies */
for_each(input_buffer *, sn, &source_list)
for (input_buffer &sn : source_list)
{
int avail;
avail = sn->linked_outbuf->ptr - sn->ptr;
int avail = sn.linked_outbuf->ptr - sn.ptr;
if (avail < 0)
throw emu_fatalerror("discrete_task::process: available samples are negative");
if (avail < samples)
@ -273,13 +266,13 @@ void discrete_task::prepare_for_queue(int samples)
{
m_samples = samples;
/* set up task buffers */
for_each(output_buffer *, ob, &m_buffers)
ob->ptr = ob->node_buf;
for (output_buffer &ob : m_buffers)
ob.ptr = ob.node_buf;
/* initialize sources */
for_each(input_buffer *, sn, &source_list)
for (input_buffer &sn : source_list)
{
sn->ptr = sn->linked_outbuf->node_buf;
sn.ptr = sn.linked_outbuf->node_buf;
}
}
@ -290,13 +283,13 @@ void discrete_task::check(discrete_task *dest_task)
/* Determine, which nodes in the task are referenced by nodes in dest_task
* and add them to the list of nodes to be buffered for further processing
*/
for_each(discrete_step_interface **, node_entry, &step_list)
for (discrete_step_interface *node_entry : step_list)
{
discrete_base_node *task_node = (*node_entry)->self;
discrete_base_node *task_node = node_entry->self;
for_each(discrete_step_interface **, step_entry, &dest_task->step_list)
for (discrete_step_interface *step_entry : dest_task->step_list)
{
discrete_base_node *dest_node = (*step_entry)->self;
discrete_base_node *dest_node = step_entry->self;
/* loop over all active inputs */
for (inputnum = 0; inputnum < dest_node->active_inputs(); inputnum++)
@ -311,7 +304,7 @@ void discrete_task::check(discrete_task *dest_task)
int i, found = -1;
output_buffer *pbuf = nullptr;
for (i = 0; i < m_buffers.count(); i++)
for (i = 0; i < m_buffers.size(); i++)
// if (m_buffers[i].node->block_node() == inputnode_num)
if (m_buffers[i].node_num == inputnode_num)
{
@ -330,8 +323,8 @@ void discrete_task::check(discrete_task *dest_task)
buf.source = dest_node->m_input[inputnum];
buf.node_num = inputnode_num;
//buf.node = device->discrete_find_node(inputnode);
m_buffers.count();
pbuf = m_buffers.add(buf);
m_buffers.push_back(buf);
pbuf = &m_buffers.back();
}
m_device.discrete_log("dso_task_start - buffering %d(%d) in task %p group %d referenced by %d group %d", NODE_INDEX(inputnode_num), NODE_CHILD_NODE_NUM(inputnode_num), this, task_group, dest_node->index(), dest_task->task_group);
@ -342,10 +335,10 @@ void discrete_task::check(discrete_task *dest_task)
source.linked_outbuf = pbuf;
source.buffer = 0.0; /* please compiler */
source.ptr = nullptr;
dest_task->source_list.add(source);
dest_task->source_list.push_back(source);
/* point the input to a buffered location */
dest_node->m_input[inputnum] = &dest_task->source_list[dest_task->source_list.count()-1].buffer; // was copied! &source.buffer;
dest_node->m_input[inputnum] = &dest_task->source_list.back().buffer; // was copied! &source.buffer;
}
}
@ -520,7 +513,7 @@ void discrete_device::discrete_build_list(const discrete_block *intf, sound_bloc
if (intf[node_count].type == DSS_NULL)
fatalerror("discrete_build_list: DISCRETE_REPLACE at end of node_list\n");
for (int i=0; i < block_list.count(); i++)
for (int i=0; i < block_list.size(); i++)
{
const discrete_block *block = block_list[i];
@ -540,9 +533,9 @@ void discrete_device::discrete_build_list(const discrete_block *intf, sound_bloc
}
else if (intf[node_count].type == DSO_DELETE)
{
vector_t<int> deletethem;
std::vector<int> deletethem;
for (int i=0; i<block_list.count(); i++)
for (int i=0; i<block_list.size(); i++)
{
const discrete_block *block = block_list[i];
@ -550,16 +543,16 @@ void discrete_device::discrete_build_list(const discrete_block *intf, sound_bloc
(block->node <= intf[node_count].input_node[1]))
{
discrete_log("discrete_build_list() - DISCRETE_DELETE deleted NODE_%02d", NODE_INDEX(block->node) );
deletethem.add(i);
deletethem.push_back(i);
}
}
for_each (int *, i, &deletethem)
block_list.remove(*i);
for (int i : deletethem)
block_list.erase(block_list.begin() + i); // FIXME: how is this supposed to work if there's more than one item to remove? indices are shifted back on each removal
}
else
{
discrete_log("discrete_build_list() - adding node %d\n", node_count);
block_list.add(&intf[node_count]);
block_list.push_back(&intf[node_count]);
}
node_count++;
@ -575,7 +568,7 @@ void discrete_device::discrete_sanity_check(const sound_block_list_t &block_list
int node_count = 0;
discrete_log("discrete_start() - Doing node list sanity check");
for (int i=0; i < block_list.count(); i++)
for (int i=0; i < block_list.size(); i++)
{
const discrete_block *block = block_list[i];
@ -622,10 +615,10 @@ static uint64_t list_run_time(const node_list_t &list)
{
uint64_t total = 0;
for_each(discrete_base_node **, node, &list)
for (discrete_base_node *node : list)
{
discrete_step_interface *step;
if ((*node)->interface(step))
if (node->interface(step))
total += step->run_time;
}
return total;
@ -635,9 +628,9 @@ static uint64_t step_list_run_time(const node_step_list_t &list)
{
uint64_t total = 0;
for_each(discrete_step_interface **, node, &list)
for (discrete_step_interface *node : list)
{
total += (*node)->run_time;
total += node->run_time;
}
return total;
}
@ -651,28 +644,28 @@ void discrete_device::display_profiling(void)
/* calculate total time */
total = list_run_time(m_node_list);
count = m_node_list.count();
count = m_node_list.size();
/* print statistics */
util::stream_format(std::cout, "Total Samples : %16d\n", m_total_samples);
osd_printf_info("Total Samples : %16d\n", m_total_samples);
tresh = total / count;
util::stream_format(std::cout, "Threshold (mean): %16d\n", tresh / m_total_samples );
for_each(discrete_base_node **, node, &m_node_list)
osd_printf_info("Threshold (mean): %16d\n", tresh / m_total_samples);
for (discrete_base_node *node : m_node_list)
{
discrete_step_interface *step;
if ((*node)->interface(step))
if (node->interface(step))
if (step->run_time > tresh)
util::stream_format(std::cout, "%3d: %20s %8.2f %10.2f\n", (*node)->index(), (*node)->module_name(), double(step->run_time) / double(total) * 100.0, double(step->run_time) / double(m_total_samples));
osd_printf_info("%3d: %20s %8.2f %10.2f\n", node->index(), node->module_name(), double(step->run_time) / double(total) * 100.0, double(step->run_time) / double(m_total_samples));
}
/* Task information */
for_each(discrete_task **, task, &task_list)
for (discrete_task *task : task_list)
{
tt = step_list_run_time((*task)->step_list);
tt = step_list_run_time(task->step_list);
util::stream_format(std::cout, "Task(%d): %8.2f %15.2f\n", (*task)->task_group, tt / double(total) * 100.0, tt / double(m_total_samples));
osd_printf_info("Task(%d): %8.2f %15.2f\n", task->task_group, tt / double(total) * 100.0, tt / double(m_total_samples));
}
util::stream_format(std::cout, "Average samples/double->update: %8.2f\n", double(m_total_samples) / double(m_total_stream_updates));
osd_printf_info("Average samples/double->update: %8.2f\n", double(m_total_samples) / double(m_total_stream_updates));
}
@ -692,7 +685,7 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list)
/* check whether we have tasks ... */
if (USE_DISCRETE_TASKS)
{
for (int i = 0; i < block_list.count(); i++)
for (int i = 0; i < block_list.size(); i++)
{
if (block_list[i]->type == DSO_TASK_START)
has_tasks = 1;
@ -705,11 +698,11 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list)
* No need to create a node since there are no dependencies.
*/
task = auto_alloc_clear(machine(), <discrete_task>(*this));
task_list.add(task);
task_list.push_back(task);
}
/* loop over all nodes */
for (int i = 0; i < block_list.count(); i++)
for (int i = 0; i < block_list.size(); i++)
{
const discrete_block *block = block_list[i];
@ -743,8 +736,8 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list)
task->task_group = block->initial[0];
if (task->task_group < 0 || task->task_group >= DISCRETE_MAX_TASK_GROUPS)
fatalerror("discrete_dso_task: illegal task_group %d\n", task->task_group);
//util::stream_format(std::cout, "task group %d\n", task->task_group);
task_list.add(task);
//logerror("task group %d\n", task->task_group);
task_list.push_back(task);
}
break;
@ -770,7 +763,7 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list)
}
/* add to node list */
m_node_list.add(node);
m_node_list.push_back(node);
/* our running order just follows the order specified */
/* does the node step ? */
@ -781,7 +774,7 @@ void discrete_device::init_nodes(const sound_block_list_t &block_list)
if (task == nullptr)
fatalerror("init_nodes() - found node outside of task: %s\n", node->module_name() );
else
task->step_list.add(step);
task->step_list.push_back(step);
}
if (USE_DISCRETE_TASKS && block->type == DSO_TASK_END)
@ -810,11 +803,11 @@ int discrete_device::same_module_index(const discrete_base_node &node)
{
int index = 0;
for_each(discrete_base_node **, n, &m_node_list)
for (discrete_base_node *n : m_node_list)
{
if (*n == &node)
if (n == &node)
return index;
if ((*n)->module_type() == node.module_type())
if (n->module_type() == node.module_type())
index++;
}
return -1;
@ -903,27 +896,27 @@ void discrete_device::device_start()
init_nodes(block_list);
/* now go back and find pointers to all input nodes */
for_each(discrete_base_node **, node, &m_node_list)
for (discrete_base_node *node : m_node_list)
{
(*node)->resolve_input_nodes();
node->resolve_input_nodes();
}
/* allocate a queue */
m_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ);
/* Process nodes which have a start func */
for_each(discrete_base_node **, node, &m_node_list)
for (discrete_base_node *node : m_node_list)
{
(*node)->start();
node->start();
}
/* Now set up tasks */
for_each(discrete_task **, task, &task_list)
for (discrete_task *task : task_list)
{
for_each(discrete_task **, dest_task, &task_list)
for (discrete_task *dest_task : task_list)
{
if ((*task)->task_group > (*dest_task)->task_group)
(*dest_task)->check((*task));
if (task->task_group > dest_task->task_group)
dest_task->check(task);
}
}
}
@ -942,9 +935,9 @@ void discrete_device::device_stop()
/* Process nodes which have a stop func */
for_each(discrete_base_node **, node, &m_node_list)
for (discrete_base_node *node : m_node_list)
{
(*node)->stop();
node->stop();
}
if (DISCRETE_DEBUGLOG)
@ -969,31 +962,31 @@ void discrete_sound_device::device_start()
discrete_device::device_start();
/* look for input stream nodes */
for_each(discrete_base_node **, node, &m_node_list)
for (discrete_base_node *node : m_node_list)
{
/* if we are an stream input node, track that */
discrete_dss_input_stream_node *input_stream = dynamic_cast<discrete_dss_input_stream_node *>(*node);
discrete_dss_input_stream_node *input_stream = dynamic_cast<discrete_dss_input_stream_node *>(node);
if (input_stream != nullptr)
{
m_input_stream_list.add(input_stream);
m_input_stream_list.push_back(input_stream);
}
/* if this is an output interface, add it the output list */
discrete_sound_output_interface *out;
if ((*node)->interface(out))
m_output_list.add(out);
if (node->interface(out))
m_output_list.push_back(out);
}
/* if no outputs, give an error */
if (m_output_list.count() == 0)
if (m_output_list.empty())
fatalerror("init_nodes() - Couldn't find an output node\n");
/* initialize the stream(s) */
m_stream = stream_alloc(m_input_stream_list.count(), m_output_list.count(), m_sample_rate);
m_stream = stream_alloc(m_input_stream_list.size(), m_output_list.size(), m_sample_rate);
/* Finalize stream_input_nodes */
for_each(discrete_dss_input_stream_node **, node, &m_input_stream_list)
for (discrete_dss_input_stream_node *node : m_input_stream_list)
{
(*node)->stream_start();
node->stream_start();
}
@ -1008,12 +1001,12 @@ void discrete_device::device_reset()
update_to_current_time();
/* loop over all nodes */
for_each (discrete_base_node **, node, &m_node_list)
for (discrete_base_node *node : m_node_list)
{
/* Fimxe : node_level */
(*node)->m_output[0] = 0;
node->m_output[0] = 0;
(*node)->reset();
node->reset();
}
}
@ -1037,17 +1030,18 @@ void discrete_device::process(int samples)
return;
/* Setup tasks */
for_each(discrete_task **, task, &task_list)
for (discrete_task *task : task_list)
{
/* unlock the thread */
(*task)->unlock();
task->unlock();
(*task)->prepare_for_queue(samples);
task->prepare_for_queue(samples);
}
for_each(discrete_task **, task, &task_list)
for (discrete_task *task : task_list)
{
/* Fire a work item for each task */
(void)task;
osd_work_item_queue(m_queue, discrete_task::task_callback, (void *) &task_list, WORK_ITEM_FLAG_AUTO_RELEASE);
}
osd_work_queue_wait(m_queue, osd_ticks_per_second()*10);
@ -1069,17 +1063,17 @@ void discrete_sound_device::sound_stream_update(sound_stream &stream, std::vecto
int outputnum = 0;
/* Setup any output streams */
for_each(discrete_sound_output_interface **, node, &m_output_list)
for (discrete_sound_output_interface *node : m_output_list)
{
(*node)->set_output_ptr(outputs[outputnum]);
node->set_output_ptr(outputs[outputnum]);
outputnum++;
}
/* Setup any input streams */
for_each(discrete_dss_input_stream_node **, node, &m_input_stream_list)
for (discrete_dss_input_stream_node *node : m_input_stream_list)
{
(*node)->m_inview = &inputs[(*node)->m_stream_in_number];
(*node)->m_inview_sample = 0;
node->m_inview = &inputs[node->m_stream_in_number];
node->m_inview_sample = 0;
}
/* just process it */

View File

@ -7,6 +7,9 @@
#include "machine/rescap.h"
#include <vector>
/***********************************************************************
*
* MAME - Discrete sound system emulation library
@ -3745,88 +3748,6 @@ enum
*
*************************************/
/*
* add and delete may be slow - the focus is on access!
*/
// TODO: replace with vector from utils
template<class _ElementType> struct vector_t
{
public:
vector_t(int initial) {
m_count = 0;
m_allocated = initial;
m_arr = make_unique_clear<_ElementType[]>(m_allocated);
}
vector_t() {
m_count = 0;
m_allocated = 16;
m_arr = make_unique_clear<_ElementType[]>(m_allocated);
}
~vector_t() {
m_arr = nullptr;
}
_ElementType& operator [] (unsigned int index) const // get array item
{
return m_arr[index];
}
vector_t(const vector_t &a) // copy constructor
{
m_allocated = a.count();
if (m_allocated < 16)
m_allocated = 16;
m_count = a.count();
m_arr = make_unique_clear<_ElementType[]>(m_allocated);
for (int i=0; i < m_count; i++)
m_arr[i] = a[i];
}
vector_t& operator = (const vector_t &a) // assignment operator
{
if (this == &a) return *this;
m_allocated = a.count();
if (m_allocated < 16)
m_allocated = 16;
m_count = a.count();
m_arr = make_unique_clear<_ElementType[]>(m_allocated);
for (int i=0; i < m_count; i++)
m_arr[i] = a[i];
return *this;
}
inline _ElementType* add(_ElementType object)
{
if (m_count >= m_allocated)
{
auto oldarr = make_unique_clear<_ElementType[]>(m_allocated);
for (int i = 0; i < m_count; i++)
oldarr[i] = m_arr[i];
m_allocated *= 2;
m_arr = make_unique_clear<_ElementType[]>(m_allocated);
for (int i = 0; i < m_count; i++)
m_arr[i] = oldarr[i];
}
m_arr[m_count] = object;
m_count++;
return &m_arr[m_count-1];
}
inline void remove(int index)
{
for (int i=index+1; i < m_count; i++)
m_arr[i-1] = m_arr[i];
m_count--;
}
inline void clear(void) { m_count = 0; }
inline int count(void) const { return m_count; }
inline _ElementType *begin_ptr(void) const { return m_arr.get(); }
inline _ElementType *end_ptr(void) const { return m_arr.get() + (m_count - 1); }
private:
std::unique_ptr<_ElementType[]> m_arr;
int m_count;
int m_allocated;
};
/*************************************
*
* Node-specific struct types
@ -4185,9 +4106,9 @@ class discrete_task;
class discrete_base_node;
class discrete_dss_input_stream_node;
class discrete_device;
typedef vector_t<discrete_base_node *> node_list_t;
typedef vector_t<discrete_dss_input_stream_node *> istream_node_list_t;
typedef vector_t<discrete_task *> task_list_t;
typedef std::vector<discrete_base_node *> node_list_t;
typedef std::vector<discrete_dss_input_stream_node *> istream_node_list_t;
typedef std::vector<discrete_task *> task_list_t;
/*************************************
@ -4216,7 +4137,7 @@ struct discrete_block
const char * name; /* Node Name */
const char * mod_name; /* Module / class name */
};
typedef vector_t<const discrete_block *> sound_block_list_t;
typedef std::vector<const discrete_block *> sound_block_list_t;
/*************************************
*
@ -4233,7 +4154,7 @@ public:
osd_ticks_t run_time;
discrete_base_node * self;
};
typedef vector_t<discrete_step_interface *> node_step_list_t;
typedef std::vector<discrete_step_interface *> node_step_list_t;
class discrete_input_interface
{
@ -4256,7 +4177,7 @@ public:
//**************************************************************************
class discrete_sound_output_interface;
typedef vector_t<discrete_sound_output_interface *> node_output_list_t;
typedef std::vector<discrete_sound_output_interface *> node_output_list_t;
// ======================> discrete_device

View File

@ -575,7 +575,7 @@ void multipcm_device::device_start()
save_item(NAME(m_address));
// Slots
m_slots = make_unique_clear<slot_t []>(28);
m_slots = std::make_unique<slot_t []>(28);
save_pointer(STRUCT_MEMBER(m_slots, m_regs), 28);
save_pointer(STRUCT_MEMBER(m_slots, m_playing), 28);

View File

@ -37,17 +37,17 @@ protected:
private:
struct sample_t
{
uint32_t m_start;
uint32_t m_loop;
uint32_t m_end;
uint8_t m_attack_reg;
uint8_t m_decay1_reg;
uint8_t m_decay2_reg;
uint8_t m_decay_level;
uint8_t m_release_reg;
uint8_t m_key_rate_scale;
uint8_t m_lfo_vibrato_reg;
uint8_t m_lfo_amplitude_reg;
uint32_t m_start = 0;
uint32_t m_loop = 0;
uint32_t m_end = 0;
uint8_t m_attack_reg = 0;
uint8_t m_decay1_reg = 0;
uint8_t m_decay2_reg = 0;
uint8_t m_decay_level = 0;
uint8_t m_release_reg = 0;
uint8_t m_key_rate_scale = 0;
uint8_t m_lfo_vibrato_reg = 0;
uint8_t m_lfo_amplitude_reg = 0;
};
enum class state_t : u8
@ -60,38 +60,38 @@ private:
struct envelope_gen_t
{
int32_t m_volume;
state_t m_state;
int32_t step;
int32_t m_volume = 0;
state_t m_state = state_t::ATTACK;
int32_t step = 0;
//step vals
int32_t m_attack_rate; // Attack
int32_t m_decay1_rate; // Decay1
int32_t m_decay2_rate; // Decay2
int32_t m_release_rate; // Release
int32_t m_decay_level; // Decay level
int32_t m_attack_rate = 0; // Attack
int32_t m_decay1_rate = 0; // Decay1
int32_t m_decay2_rate = 0; // Decay2
int32_t m_release_rate = 0; // Release
int32_t m_decay_level = 0; // Decay level
};
struct lfo_t
{
uint16_t m_phase;
uint32_t m_phase_step;
int32_t *m_table;
int32_t *m_scale;
uint16_t m_phase = 0;
uint32_t m_phase_step = 0;
int32_t *m_table = nullptr;
int32_t *m_scale = nullptr;
};
struct slot_t
{
uint8_t m_regs[8];
bool m_playing;
uint8_t m_regs[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
bool m_playing = false;
sample_t m_sample;
uint32_t m_base;
uint32_t m_offset;
uint32_t m_step;
uint32_t m_pan;
uint32_t m_total_level;
uint32_t m_dest_total_level;
int32_t m_total_level_step;
int32_t m_prev_sample;
uint32_t m_base = 0;
uint32_t m_offset = 0;
uint32_t m_step = 0;
uint32_t m_pan = 0;
uint32_t m_total_level = 0;
uint32_t m_dest_total_level = 0;
int32_t m_total_level_step = 0;
int32_t m_prev_sample = 0;
envelope_gen_t m_envelope_gen;
lfo_t m_pitch_lfo; // Pitch lfo
lfo_t m_amplitude_lfo; // AM lfo

View File

@ -85,7 +85,7 @@ void vector_device::device_start()
m_vector_index = 0;
/* allocate memory for tables */
m_vector_list = make_unique_clear<point[]>(MAX_POINTS);
m_vector_list = std::make_unique<point[]>(MAX_POINTS);
}
/*

View File

@ -25,12 +25,12 @@ typedef std::function<std::int32_t (running_machine &, void *, int, std::string
struct slider_state
{
slider_update update; // callback
void * arg; // argument
std::int32_t minval; // minimum value
std::int32_t defval; // default value
std::int32_t maxval; // maximum value
std::int32_t incval; // increment value
int id;
void * arg = nullptr; // argument
std::int32_t minval = 0; // minimum value
std::int32_t defval = 0; // default value
std::int32_t maxval = 0; // maximum value
std::int32_t incval = 0; // increment value
int id = 0;
std::string description; // textual description
};

View File

@ -1487,7 +1487,7 @@ std::vector<ui::menu_item>& mame_ui_manager::get_slider_list(void)
std::unique_ptr<slider_state> mame_ui_manager::slider_alloc(int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg)
{
auto state = make_unique_clear<slider_state>();
auto state = std::make_unique<slider_state>();
state->minval = minval;
state->defval = defval;

View File

@ -64,13 +64,13 @@ public:
struct spoint_t
{
int32_t x, y;
int32_t x = 0, y = 0;
};
struct point_t
{
float x, y, z;
float xx, yy;
float x = 0, y = 0, z = 0;
float xx = 0, yy = 0;
spoint_t s;
};

View File

@ -26,14 +26,21 @@
#include "emupal.h"
#include "screen.h"
#include <algorithm>
class model2_renderer;
struct raster_state;
struct geo_state;
struct triangle;
class model2_state : public driver_device
{
public:
struct plane;
struct texture_parameter;
struct triangle;
struct quad_m2;
struct raster_state;
struct geo_state;
model2_state(const machine_config &mconfig, device_type type, const char *tag) :
driver_device(mconfig, type, tag),
m_textureram0(*this, "textureram0"),
@ -626,6 +633,8 @@ public:
typedef void (model2_renderer::*scanline_render_func)(int32_t scanline, const extent_t& extent, const m2_poly_extra_data& object, int threadid);
public:
using triangle = model2_state::triangle;
model2_renderer(model2_state& state)
: poly_manager<float, m2_poly_extra_data, 4, 0x10000>(state.machine())
, m_state(state)
@ -722,37 +731,54 @@ typedef model2_renderer::vertex_t poly_vertex;
*
*******************************************/
struct plane
struct model2_state::plane
{
poly_vertex normal;
float distance;
plane() : normal(0, 0)
{
std::fill(std::begin(normal.p), std::end(normal.p), 0);
}
poly_vertex normal;
float distance = 0;
};
struct texture_parameter
struct model2_state::texture_parameter
{
float diffuse;
float ambient;
u32 specular_control;
float specular_scale;
float diffuse = 0;
float ambient = 0;
u32 specular_control = 0;
float specular_scale = 0;
};
struct triangle
struct model2_state::triangle
{
void * next;
poly_vertex v[3];
u16 z;
u16 texheader[4];
u8 luma;
int16_t viewport[4];
int16_t center[2];
triangle() : v{ { 0, 0 }, { 0, 0 }, { 0, 0 } }
{
for (poly_vertex &vertex : v)
std::fill(std::begin(vertex.p), std::end(vertex.p), 0);
}
void * next = nullptr;
poly_vertex v[3];
u16 z = 0;
u16 texheader[4] = { 0, 0, 0, 0 };
u8 luma = 0;
int16_t viewport[4] = { 0, 0, 0, 0 };
int16_t center[2] = { 0, 0 };
};
struct quad_m2
struct model2_state::quad_m2
{
poly_vertex v[4];
u16 z;
u16 texheader[4];
u8 luma;
quad_m2() : v{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }
{
for (poly_vertex &vertex : v)
std::fill(std::begin(vertex.p), std::end(vertex.p), 0);
}
poly_vertex v[4];
u16 z = 0;
u16 texheader[4] = { 0, 0, 0, 0 };
u8 luma = 0;
};
/*******************************************
@ -763,28 +789,36 @@ struct quad_m2
#define MAX_TRIANGLES 32768
struct raster_state
struct model2_state::raster_state
{
// u32 mode; /* bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation */
u16 *texture_rom; /* Texture ROM pointer */
u32 texture_rom_mask; /* Texture ROM mask */
int16_t viewport[4]; /* View port (startx,starty,endx,endy) */
int16_t center[4][2]; /* Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y]) */
u16 center_sel; /* Selected center */
u32 reverse; /* Left/Right Reverse */
float z_adjust; /* ZSort Mode */
float triangle_z; /* Current Triangle z value */
u8 master_z_clip; /* Master Z-Clip value */
u32 cur_command; /* Current command */
u32 command_buffer[32]; /* Command buffer */
u32 command_index; /* Command buffer index */
triangle tri_list[MAX_TRIANGLES]; /* Triangle list */
u32 tri_list_index; /* Triangle list index */
triangle *tri_sorted_list[0x10000]; /* Sorted Triangle list */
u16 min_z; /* Minimum sortable Z value */
u16 max_z; /* Maximum sortable Z value */
u16 texture_ram[0x10000]; /* Texture RAM pointer */
u8 log_ram[0x40000]; /* Log RAM pointer */
raster_state()
{
std::fill(std::begin(command_buffer), std::end(command_buffer), 0);
std::fill(std::begin(tri_sorted_list), std::end(tri_sorted_list), nullptr);
std::fill(std::begin(texture_ram), std::end(texture_ram), 0);
std::fill(std::begin(log_ram), std::end(log_ram), 0);
}
// u32 mode = 0; // bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation
u16 * texture_rom = nullptr; // Texture ROM pointer
u32 texture_rom_mask = 0; // Texture ROM mask
int16_t viewport[4] = { 0, 0, 0, 0 }; // View port (startx,starty,endx,endy)
int16_t center[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; // Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y])
u16 center_sel = 0; // Selected center
u32 reverse = 0; // Left/Right Reverse
float z_adjust = 0; // ZSort Mode
float triangle_z = 0; // Current Triangle z value
u8 master_z_clip = 0; // Master Z-Clip value
u32 cur_command = 0; // Current command
u32 command_buffer[32]; // Command buffer
u32 command_index = 0; // Command buffer index
triangle tri_list[MAX_TRIANGLES]; // Triangle list
u32 tri_list_index = 0; // Triangle list index
triangle * tri_sorted_list[0x10000]; // Sorted Triangle list
u16 min_z = 0; // Minimum sortable Z value
u16 max_z = 0; // Maximum sortable Z value
u16 texture_ram[0x10000]; // Texture RAM pointer
u8 log_ram[0x40000]; // Log RAM pointer
};
/*******************************************
@ -793,21 +827,31 @@ struct raster_state
*
*******************************************/
struct geo_state
struct model2_state::geo_state
{
raster_state * raster;
u32 mode; /* bit 0 = Enable Specular, bit 1 = Calculate Normals */
u32 * polygon_rom; /* Polygon ROM pointer */
u32 polygon_rom_mask; /* Polygon ROM mask */
float matrix[12]; /* Current Transformation Matrix */
poly_vertex focus; /* Focus (x,y) */
poly_vertex light; /* Light Vector */
float lod; /* LOD */
float coef_table[32]; /* Distane Coefficient table */
texture_parameter texture_parameters[32]; /* Texture parameters */
u32 polygon_ram0[0x8000]; /* Fast Polygon RAM pointer */
u32 polygon_ram1[0x8000]; /* Slow Polygon RAM pointer */
model2_state *state;
geo_state() : focus(0, 0), light(0, 0)
{
std::fill(std::begin(matrix), std::end(matrix), 0);
std::fill(std::begin(focus.p), std::end(focus.p), 0);
std::fill(std::begin(light.p), std::end(light.p), 0);
std::fill(std::begin(coef_table), std::end(coef_table), 0);
std::fill(std::begin(polygon_ram0), std::end(polygon_ram0), 0);
std::fill(std::begin(polygon_ram1), std::end(polygon_ram1), 0);
}
raster_state * raster = nullptr;
u32 mode = 0; // bit 0 = Enable Specular, bit 1 = Calculate Normals
u32 * polygon_rom = nullptr; // Polygon ROM pointer
u32 polygon_rom_mask = 0; // Polygon ROM mask
float matrix[12]; // Current Transformation Matrix
poly_vertex focus; // Focus (x,y)
poly_vertex light; // Light Vector
float lod = 0; // LOD
float coef_table[32]; // Distane Coefficient table
texture_parameter texture_parameters[32]; // Texture parameters
u32 polygon_ram0[0x8000]; // Fast Polygon RAM pointer
u32 polygon_ram1[0x8000]; // Slow Polygon RAM pointer
model2_state * state = nullptr;
};
#endif // MAME_INCLUDES_MODEL2_H

View File

@ -105,11 +105,11 @@ protected:
struct f2_tempsprite
{
u32 code, color;
bool flipx, flipy;
int x, y;
int zoomx, zoomy;
u64 primask;
u32 code = 0, color = 0;
bool flipx = false, flipy = false;
int x = 0, y = 0;
int zoomx = 0, zoomy = 0;
u64 primask = 0;
};
/* memory pointers */
optional_shared_ptr<u16> m_sprite_extension;
@ -118,7 +118,7 @@ protected:
std::unique_ptr<u16[]> m_spriteram_delayed;
/* video-related */
std::unique_ptr<struct f2_tempsprite[]> m_spritelist;
std::unique_ptr<f2_tempsprite[]> m_spritelist;
int m_sprite_type;
u16 m_spritebank[8];

View File

@ -39,7 +39,7 @@ void namcos21_dsp_c67_device::device_start()
m_yield_hack_cb.resolve_safe();
m_pointram = std::make_unique<uint8_t[]>(PTRAM_SIZE);
m_mpDspState = make_unique_clear<dsp_state>();
m_mpDspState = std::make_unique<dsp_state>();
save_item(NAME(m_dspram16));
}

View File

@ -8,13 +8,16 @@
#include "machine/namco_c67.h"
#include "video/namcos21_3d.h"
#define PTRAM_SIZE 0x20000
#include <algorithm>
#define ENABLE_LOGGING 0
class namcos21_dsp_c67_device : public device_t
{
public:
static constexpr unsigned PTRAM_SIZE = 0x20000;
enum
{ /* Namco System21 */
NAMCOS21_AIRCOMBAT = 0x4000,
@ -51,20 +54,27 @@ protected:
virtual void device_add_mconfig(machine_config &config) override;
private:
#define DSP_BUF_MAX (4096*12)
static constexpr unsigned DSP_BUF_MAX = 4096*12;
struct dsp_state
{
unsigned masterSourceAddr;
dsp_state()
{
std::fill(std::begin(slaveInputBuffer), std::end(slaveInputBuffer), 0);
std::fill(std::begin(slaveOutputBuffer), std::end(slaveOutputBuffer), 0);
std::fill(std::begin(masterDirectDrawBuffer), std::end(masterDirectDrawBuffer), 0);
}
unsigned masterSourceAddr = 0;
uint16_t slaveInputBuffer[DSP_BUF_MAX];
unsigned slaveBytesAvailable;
unsigned slaveBytesAdvertised;
unsigned slaveInputStart;
unsigned slaveBytesAvailable = 0;
unsigned slaveBytesAdvertised = 0;
unsigned slaveInputStart = 0;
uint16_t slaveOutputBuffer[DSP_BUF_MAX];
unsigned slaveOutputSize;
unsigned slaveOutputSize = 0;
uint16_t masterDirectDrawBuffer[256];
unsigned masterDirectDrawSize;
int masterFinished;
int slaveActive;
unsigned masterDirectDrawSize = 0;
int masterFinished = 0;
int slaveActive = 0;
};
required_device<namcos21_3d_device> m_renderer;

View File

@ -240,7 +240,7 @@ void deco_mxc06_device::device_start()
{
m_colpri_cb.resolve();
m_flip_screen = false;
m_spritelist = make_unique_clear<struct sprite_t[]>(0x400);
m_spritelist = std::make_unique<sprite_t[]>(0x400);
save_item(NAME(m_flip_screen));
}

View File

@ -28,11 +28,11 @@ protected:
private:
struct sprite_t
{
int height;
u32 code[8], colour;
int x[8], y[8];
bool flipx, flipy;
u32 pri_mask;
int height = 0;
u32 code[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }, colour = 0;
int x[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }, y[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
bool flipx = false, flipy = false;
u32 pri_mask = 0;
};
colpri_cb_delegate m_colpri_cb;
bool m_flip_screen;

View File

@ -1573,9 +1573,9 @@ void model1_state::video_start()
m_poly_ram = make_unique_clear<uint32_t[]>(0x400000);
m_tgp_ram = make_unique_clear<uint16_t[]>(0x100000-0x40000);
m_pointdb = make_unique_clear<model1_state::point_t[]>(1000000*2);
m_quaddb = make_unique_clear<model1_state::quad_t[]>(1000000);
m_quadind = make_unique_clear<model1_state::quad_t *[]>(1000000);
m_pointdb = std::make_unique<point_t[]>(1000000*2);
m_quaddb = std::make_unique<quad_t[]>(1000000);
m_quadind = make_unique_clear<quad_t *[]>(1000000);
m_pointpt = &m_pointdb[0];
m_quadpt = &m_quaddb[0];

View File

@ -157,7 +157,7 @@ static inline void vector_cross3( poly_vertex *dst, poly_vertex *v0, poly_vertex
dst->pz = (p1.x * p2.y) - (p1.y * p2.x);
}
static inline void apply_focus( geo_state *geo, poly_vertex *p0)
static inline void apply_focus( model2_state::geo_state *geo, poly_vertex *p0)
{
p0->x *= geo->focus.x;
p0->y *= geo->focus.y;
@ -201,7 +201,7 @@ static int32_t clip_polygon(poly_vertex *v, int32_t num_vertices, poly_vertex *v
poly_vertex *cur, *out;
float curdot, nextdot, scale;
int32_t i, curin, nextin, nextvert, outcount;
plane clip_plane;
model2_state::plane clip_plane;
clip_plane.normal.x = 0.0f;
clip_plane.normal.y = 0.0f;
@ -285,7 +285,7 @@ inline bool model2_state::check_culling( raster_state *raster, u32 attr, float m
void model2_state::raster_init( memory_region *texture_rom )
{
m_raster = make_unique_clear<raster_state>();
m_raster = std::make_unique<raster_state>();
m_raster->texture_rom = (u16 *)texture_rom->base();
m_raster->texture_rom_mask = (texture_rom->bytes() / 2) - 1;
@ -1159,7 +1159,7 @@ void model2_state::model2_3d_push( raster_state *raster, u32 input )
void model2_state::geo_init(memory_region *polygon_rom)
{
m_geo = make_unique_clear<geo_state>();
m_geo = std::make_unique<geo_state>();
m_geo->state = this;
m_geo->raster = m_raster.get();

View File

@ -53,7 +53,7 @@ nmk_16bit_sprite_device::nmk_16bit_sprite_device(const machine_config &mconfig,
void nmk_16bit_sprite_device::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element *gfx, u16* spriteram, int size)
{
const bool priority = !m_colpri_cb.isnull();
struct sprite_t *sprite_ptr = m_spritelist.get();
sprite_t *sprite_ptr = m_spritelist.get();
const int xpos_max = m_xmask + 1;
const int ypos_max = m_ymask + 1;
@ -260,7 +260,7 @@ void nmk_16bit_sprite_device::device_start()
m_colpri_cb.resolve();
m_ext_cb.resolve();
m_flip_screen = false;
m_spritelist = make_unique_clear<struct sprite_t[]>((0x1000/0x10) * 16 * 16);
m_spritelist = std::make_unique<sprite_t[]>((0x1000/0x10) * 16 * 16);
save_item(NAME(m_flip_screen));
}

View File

@ -34,10 +34,10 @@ protected:
private:
struct sprite_t
{
u32 code, colour;
int x, y;
bool flipx, flipy;
u32 pri_mask;
u32 code = 0, colour = 0;
int x = 0, y = 0;
bool flipx = false, flipy = false;
u32 pri_mask = 0;
};
colpri_cb_delegate m_colpri_cb; // callback for colour, priority
ext_cb_delegate m_ext_cb; // callback for flipx, flipy or code bit modification
@ -46,7 +46,7 @@ private:
int m_xmask, m_ymask; // x,y position masking
int m_screen_width, m_screen_height; // screen size related to flipscreen
u32 m_max_sprite_clock; // max sprite cycles, related to screen total size?
std::unique_ptr<struct sprite_t[]> m_spritelist; // sprite list caches
std::unique_ptr<sprite_t[]> m_spritelist; // sprite list caches
};
DECLARE_DEVICE_TYPE(NMK_16BIT_SPRITE, nmk_16bit_sprite_device)

View File

@ -3976,7 +3976,7 @@ void powervr2_device::device_start()
{
irq_cb.resolve_safe();
grab = make_unique_clear<receiveddata[]>(NUM_BUFFERS);
grab = std::make_unique<receiveddata[]>(NUM_BUFFERS);
pvr_build_parameterconfig();

View File

@ -79,32 +79,33 @@ public:
float poly_base_color[4], poly_offs_color[4],
poly_last_mode_2_base_color[4];
struct texinfo {
uint32_t address, vqbase;
struct texinfo
{
uint32_t address = 0, vqbase = 0;
uint32_t tsinstruction;
uint32_t tsinstruction = 0;
int textured, sizex, sizey, stride, sizes, pf, palette, mode, mipmapped, blend_mode, filter_mode;
int coltype;
int textured = 0, sizex = 0, sizey = 0, stride = 0, sizes = 0, pf = 0, palette = 0, mode = 0, mipmapped = 0, blend_mode = 0, filter_mode = 0;
int coltype = 0;
uint32_t (powervr2_device::*r)(struct texinfo *t, float x, float y);
uint32_t (*blend)(uint32_t s, uint32_t d);
int (*u_func)(float uv, int size);
int (*v_func)(float uv, int size);
int palbase, cd;
uint32_t (powervr2_device::*r)(texinfo *t, float x, float y) = nullptr;
uint32_t (*blend)(uint32_t s, uint32_t d) = nullptr;
int (*u_func)(float uv, int size) = nullptr;
int (*v_func)(float uv, int size) = nullptr;
int palbase = 0, cd = 0;
};
typedef struct
struct vert
{
float x, y, w, u, v;
float x = 0, y = 0, w = 0, u = 0, v = 0;
// base and offset colors
float b[4], o[4];
} vert;
float b[4] = { 0, 0, 0, 0 }, o[4] = { 0, 0, 0, 0 };
};
struct strip
{
int svert, evert;
int svert = 0, evert = 0;
texinfo ti;
};
@ -138,18 +139,18 @@ public:
struct poly_group {
strip strips[MAX_STRIPS];
int strips_size;
int strips_size = 0;
};
struct receiveddata {
vert verts[MAX_VERTS];
struct poly_group groups[DISPLAY_LIST_COUNT];
uint32_t ispbase;
uint32_t fbwsof1;
uint32_t fbwsof2;
int busy;
int valid;
int verts_size;
uint32_t ispbase = 0;
uint32_t fbwsof1 = 0;
uint32_t fbwsof2 = 0;
int busy = 0;
int valid = 0;
int verts_size = 0;
};
enum {

View File

@ -50,7 +50,7 @@ void taitof2_state::core_vh_start(int sprite_type, int hide, int flip_hide)
m_spriteram_delayed = make_unique_clear<u16[]>(m_spriteram.bytes() / 2);
m_spriteram_buffered = make_unique_clear<u16[]>(m_spriteram.bytes() / 2);
m_spritelist = make_unique_clear<struct f2_tempsprite[]>(0x400);
m_spritelist = std::make_unique<f2_tempsprite[]>(0x400);
for (int i = 0; i < 8; i ++)
{
@ -508,7 +508,7 @@ void taitof2_state::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, co
/* pdrawgfx() needs us to draw sprites front to back, so we have to build a list
while processing sprite ram and then draw them all at the end */
struct f2_tempsprite *sprite_ptr = m_spritelist.get();
f2_tempsprite *sprite_ptr = m_spritelist.get();
/* must remember enable status from last frame because driftout fails to
reactivate them from a certain point onwards. */

View File

@ -405,7 +405,7 @@ void chain_manager::create_selection_slider(uint32_t screen_index)
return;
}
std::unique_ptr<slider_state> state = make_unique_clear<slider_state>();
std::unique_ptr<slider_state> state = std::make_unique<slider_state>();
state->minval = 0;
state->defval = m_current_chain[screen_index];

View File

@ -111,7 +111,7 @@ int32_t bgfx_input_pair::texture_changed(int32_t id, std::string *str, int32_t n
void bgfx_input_pair::create_selection_slider(uint32_t screen_index)
{
m_slider_state = make_unique_clear<slider_state>();
m_slider_state = std::make_unique<slider_state>();
m_slider_state->minval = 0;
m_slider_state->defval = m_current_texture;

View File

@ -54,7 +54,7 @@ void bgfx_slider::import(float val)
std::unique_ptr<slider_state> bgfx_slider::create_core_slider()
{
auto state = make_unique_clear<slider_state>();
auto state = std::make_unique<slider_state>();
state->minval = int32_t(floor(m_min / m_step + 0.5f));
state->defval = int32_t(floor(m_default / m_step + 0.5f));

View File

@ -1976,7 +1976,7 @@ static void get_vector(const char *data, int count, float *out, bool report_erro
std::unique_ptr<slider_state> shaders::slider_alloc(int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg)
{
auto state = make_unique_clear<slider_state>();
auto state = std::make_unique<slider_state>();
state->minval = minval;
state->defval = defval;

View File

@ -7,7 +7,7 @@ static class std::vector<std::unique_ptr<osd_netdev::entry_t>> netdev_list;
void add_netdev(const char *name, const char *description, create_netdev func)
{
auto entry = make_unique_clear<osd_netdev::entry_t>();
auto entry = std::make_unique<osd_netdev::entry_t>();
entry->id = netdev_list.size();
strncpy(entry->name, name, 255);
entry->name[255] = '\0';

View File

@ -5,6 +5,8 @@
#pragma once
#include <algorithm>
class osd_netdev;
#define CREATE_NETDEV(name) class osd_netdev *name(const char *ifname, class device_network_interface *ifdev, int rate)
@ -15,10 +17,16 @@ class osd_netdev
public:
struct entry_t
{
int id;
entry_t()
{
std::fill(std::begin(name), std::end(name), 0);
std::fill(std::begin(description), std::end(description), 0);
}
int id = 0;
char name[256];
char description[256];
create_netdev func;
create_netdev func = nullptr;
};
osd_netdev(class device_network_interface *ifdev, int rate);
virtual ~osd_netdev();