simple_list to vector in rendlay (nw)

This commit is contained in:
Miodrag Milanovic 2016-07-01 14:46:18 +02:00
parent 39250949d8
commit bc01a8bfeb
2 changed files with 30 additions and 36 deletions

View File

@ -650,9 +650,6 @@ private:
// a component represents an image, rectangle, or disk in an element // a component represents an image, rectangle, or disk in an element
class component class component
{ {
//friend class layout_element;
friend class simple_list<component>;
public: public:
// construction/destruction // construction/destruction
component(running_machine &machine, xml_data_node &compnode, const char *dirname); component(running_machine &machine, xml_data_node &compnode, const char *dirname);
@ -662,7 +659,6 @@ private:
void normalize_bounds(float xoffs, float yoffs, float xscale, float yscale); void normalize_bounds(float xoffs, float yoffs, float xscale, float yscale);
// getters // getters
component *next() const { return m_next; }
int state() const { return m_state; } int state() const { return m_state; }
virtual int maxstate() const { return m_state; } virtual int maxstate() const { return m_state; }
const render_bounds &bounds() const { return m_bounds; } const render_bounds &bounds() const { return m_bounds; }
@ -686,7 +682,6 @@ private:
private: private:
// internal state // internal state
component * m_next; // link to next component
int m_state; // state where this component is visible (-1 means all states) int m_state; // state where this component is visible (-1 means all states)
render_bounds m_bounds; // bounds of the element render_bounds m_bounds; // bounds of the element
render_color m_color; // color of the element render_color m_color; // color of the element
@ -926,7 +921,7 @@ private:
layout_element * m_next; // link to next element layout_element * m_next; // link to next element
running_machine & m_machine; // reference to the owning machine running_machine & m_machine; // reference to the owning machine
std::string m_name; // name of this element std::string m_name; // name of this element
simple_list<component> m_complist; // list of components std::vector<std::unique_ptr<component>> m_complist; // list of components
int m_defstate; // default state of this element int m_defstate; // default state of this element
int m_maxstate; // maximum state value for all components int m_maxstate; // maximum state value for all components
std::vector<texture> m_elemtex; // array of element textures used for managing the scaled bitmaps std::vector<texture> m_elemtex; // array of element textures used for managing the scaled bitmaps

View File

@ -424,71 +424,68 @@ layout_element::layout_element(running_machine &machine, xml_data_node &elemnode
render_bounds bounds = { 0 }; render_bounds bounds = { 0 };
for (xml_data_node *compnode = elemnode.child; compnode != nullptr; compnode = compnode->next) for (xml_data_node *compnode = elemnode.child; compnode != nullptr; compnode = compnode->next)
{ {
component *newcomp; std::unique_ptr<component> newcomp;
// image nodes // image nodes
if (strcmp(compnode->name, "image") == 0) if (strcmp(compnode->name, "image") == 0)
newcomp = global_alloc(image_component(machine, *compnode, dirname)); newcomp = std::make_unique<image_component>(machine, *compnode, dirname);
// text nodes // text nodes
else if (strcmp(compnode->name, "text") == 0) else if (strcmp(compnode->name, "text") == 0)
newcomp = global_alloc(text_component(machine, *compnode, dirname)); newcomp = std::make_unique<text_component>(machine, *compnode, dirname);
// dotmatrix nodes // dotmatrix nodes
else if (strcmp(compnode->name, "dotmatrix") == 0) else if (strcmp(compnode->name, "dotmatrix") == 0)
newcomp = global_alloc(dotmatrix_component(8, machine, *compnode, dirname)); newcomp = std::make_unique<dotmatrix_component>(8, machine, *compnode, dirname);
else if (strcmp(compnode->name, "dotmatrix5dot") == 0) else if (strcmp(compnode->name, "dotmatrix5dot") == 0)
newcomp = global_alloc(dotmatrix_component(5, machine, *compnode, dirname)); newcomp = std::make_unique<dotmatrix_component>(5, machine, *compnode, dirname);
else if (strcmp(compnode->name, "dotmatrixdot") == 0) else if (strcmp(compnode->name, "dotmatrixdot") == 0)
newcomp = global_alloc(dotmatrix_component(1, machine, *compnode, dirname)); newcomp = std::make_unique<dotmatrix_component>(1, machine, *compnode, dirname);
// simplecounter nodes // simplecounter nodes
else if (strcmp(compnode->name, "simplecounter") == 0) else if (strcmp(compnode->name, "simplecounter") == 0)
newcomp = global_alloc(simplecounter_component(machine, *compnode, dirname)); newcomp = std::make_unique<simplecounter_component>(machine, *compnode, dirname);
// fruit machine reels // fruit machine reels
else if (strcmp(compnode->name, "reel") == 0) else if (strcmp(compnode->name, "reel") == 0)
newcomp = global_alloc(reel_component(machine, *compnode, dirname)); newcomp = std::make_unique<reel_component>(machine, *compnode, dirname);
// led7seg nodes // led7seg nodes
else if (strcmp(compnode->name, "led7seg") == 0) else if (strcmp(compnode->name, "led7seg") == 0)
newcomp = global_alloc(led7seg_component(machine, *compnode, dirname)); newcomp = std::make_unique<led7seg_component>(machine, *compnode, dirname);
// led8seg_gts1 nodes // led8seg_gts1 nodes
else if (strcmp(compnode->name, "led8seg_gts1") == 0) else if (strcmp(compnode->name, "led8seg_gts1") == 0)
newcomp = global_alloc(led8seg_gts1_component(machine, *compnode, dirname)); newcomp = std::make_unique<led8seg_gts1_component>(machine, *compnode, dirname);
// led14seg nodes // led14seg nodes
else if (strcmp(compnode->name, "led14seg") == 0) else if (strcmp(compnode->name, "led14seg") == 0)
newcomp = global_alloc(led14seg_component(machine, *compnode, dirname)); newcomp = std::make_unique<led14seg_component>(machine, *compnode, dirname);
// led14segsc nodes // led14segsc nodes
else if (strcmp(compnode->name, "led14segsc") == 0) else if (strcmp(compnode->name, "led14segsc") == 0)
newcomp = global_alloc(led14segsc_component(machine, *compnode, dirname)); newcomp = std::make_unique<led14segsc_component>(machine, *compnode, dirname);
// led16seg nodes // led16seg nodes
else if (strcmp(compnode->name, "led16seg") == 0) else if (strcmp(compnode->name, "led16seg") == 0)
newcomp = global_alloc(led16seg_component(machine, *compnode, dirname)); newcomp = std::make_unique<led16seg_component>(machine, *compnode, dirname);
// led16segsc nodes // led16segsc nodes
else if (strcmp(compnode->name, "led16segsc") == 0) else if (strcmp(compnode->name, "led16segsc") == 0)
newcomp = global_alloc(led16segsc_component(machine, *compnode, dirname)); newcomp = std::make_unique<led16segsc_component>(machine, *compnode, dirname);
// rect nodes // rect nodes
else if (strcmp(compnode->name, "rect") == 0) else if (strcmp(compnode->name, "rect") == 0)
newcomp = global_alloc(rect_component(machine, *compnode, dirname)); newcomp = std::make_unique<rect_component>(machine, *compnode, dirname);
// disk nodes // disk nodes
else if (strcmp(compnode->name, "disk") == 0) else if (strcmp(compnode->name, "disk") == 0)
newcomp = global_alloc(disk_component(machine, *compnode, dirname)); newcomp = std::make_unique<disk_component>(machine, *compnode, dirname);
// error otherwise // error otherwise
else else
throw emu_fatalerror("Unknown element component: %s", compnode->name); throw emu_fatalerror("Unknown element component: %s", compnode->name);
// insert the new component into the list
m_complist.append(*newcomp);
// accumulate bounds // accumulate bounds
if (first) if (first)
bounds = newcomp->bounds(); bounds = newcomp->bounds();
@ -498,6 +495,9 @@ layout_element::layout_element(running_machine &machine, xml_data_node &elemnode
// determine the maximum state // determine the maximum state
m_maxstate = std::max(m_maxstate, newcomp->maxstate()); m_maxstate = std::max(m_maxstate, newcomp->maxstate());
// insert the new component into the list
m_complist.push_back(std::move(newcomp));
} }
if (!m_complist.empty()) if (!m_complist.empty())
@ -509,8 +509,8 @@ layout_element::layout_element(running_machine &machine, xml_data_node &elemnode
float yscale = 1.0f / (bounds.y1 - bounds.y0); float yscale = 1.0f / (bounds.y1 - bounds.y0);
// normalize all the component bounds // normalize all the component bounds
for (component &curcomp : m_complist) for (auto &curcomp : m_complist)
curcomp.normalize_bounds(xoffs, yoffs, xscale, yscale); curcomp->normalize_bounds(xoffs, yoffs, xscale, yscale);
} }
// allocate an array of element textures for the states // allocate an array of element textures for the states
@ -557,19 +557,19 @@ void layout_element::element_scale(bitmap_argb32 &dest, bitmap_argb32 &source, c
texture *elemtex = (texture *)param; texture *elemtex = (texture *)param;
// iterate over components that are part of the current state // iterate over components that are part of the current state
for (component &curcomp : elemtex->m_element->m_complist) for (auto &curcomp : elemtex->m_element->m_complist)
if (curcomp.state() == -1 || curcomp.state() == elemtex->m_state) if (curcomp->state() == -1 || curcomp->state() == elemtex->m_state)
{ {
// get the local scaled bounds // get the local scaled bounds
rectangle bounds; rectangle bounds;
bounds.min_x = render_round_nearest(curcomp.bounds().x0 * dest.width()); bounds.min_x = render_round_nearest(curcomp->bounds().x0 * dest.width());
bounds.min_y = render_round_nearest(curcomp.bounds().y0 * dest.height()); bounds.min_y = render_round_nearest(curcomp->bounds().y0 * dest.height());
bounds.max_x = render_round_nearest(curcomp.bounds().x1 * dest.width()); bounds.max_x = render_round_nearest(curcomp->bounds().x1 * dest.width());
bounds.max_y = render_round_nearest(curcomp.bounds().y1 * dest.height()); bounds.max_y = render_round_nearest(curcomp->bounds().y1 * dest.height());
bounds &= dest.cliprect(); bounds &= dest.cliprect();
// based on the component type, add to the texture // based on the component type, add to the texture
curcomp.draw(elemtex->m_element->machine(), dest, bounds, elemtex->m_state); curcomp->draw(elemtex->m_element->machine(), dest, bounds, elemtex->m_state);
} }
} }
@ -611,8 +611,7 @@ layout_element::texture::~texture()
//------------------------------------------------- //-------------------------------------------------
layout_element::component::component(running_machine &machine, xml_data_node &compnode, const char *dirname) layout_element::component::component(running_machine &machine, xml_data_node &compnode, const char *dirname)
: m_next(nullptr), : m_state(0)
m_state(0)
{ {
// fetch common data // fetch common data
m_state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1); m_state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1);