From ec8042864703f9ce6cc9b0cf528e6a8528104b89 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Wed, 25 Nov 2020 19:18:26 +1100 Subject: Fairly significant overhaul of Lua engine and some cleanup. The things that were previously called device iterators are not iterators in the C++ sense of the word. This is confusing for newcomers. These have been renamed to be device enumerators. Several Lua methods and properties that previously returned tables now return lightweight wrappers for the underlying objects. This means creating them is a lot faster, but you can't modify them, and the performance characteristics of different operations varies. The render manager's target list uses 1-based indexing to be more like idiomatic Lua. It's now possible to create a device enumerator on any device, and then get subdevices (or sibling devices) using a relative tag. Much more render/layout functionality has been exposed to Lua. Layout scripts now have access to the layout file and can directly set the state of an item with no bindings, or register callbacks to obtain state. Some things that were previously methods are now read-only properties. Layout files are no longer required to supply a "name". This was problematic because the same layout file could be loaded for multiple instances of the same device, and each instance of the layout file should use the correct inputs (and in the future outputs) for the device instance it's associated with. This should also fix video output with MSVC builds by avoiding delegates that return things that don't fit in a register. --- plugins/console/init.lua | 15 +- plugins/layout/init.lua | 19 +- scripts/build/complay.py | 21 +- src/devices/bus/abcbus/abc890.cpp | 20 +- src/devices/bus/abcbus/abcbus.h | 2 +- src/devices/bus/c64/bn1541.cpp | 4 +- src/devices/bus/coco/coco_dwsock.h | 2 +- src/devices/bus/tanbus/tanbus.h | 2 +- src/devices/bus/tmc600/euro.h | 2 +- src/devices/imagedev/cassette.h | 2 +- src/devices/imagedev/midiin.h | 2 +- src/devices/imagedev/midiout.h | 2 +- src/devices/machine/bcreader.h | 2 +- src/devices/machine/laserdsc.h | 2 +- src/devices/machine/netlist.cpp | 2 +- src/devices/machine/ram.h | 2 +- src/devices/sound/samples.h | 2 +- src/devices/video/voodoo.cpp | 2 +- src/emu/addrmap.cpp | 2 +- src/emu/crsshair.cpp | 6 +- src/emu/debug/debugcmd.cpp | 66 +-- src/emu/debug/debugcon.cpp | 4 +- src/emu/debug/debugcpu.cpp | 12 +- src/emu/debug/dvbpoints.cpp | 2 +- src/emu/debug/dvdisasm.cpp | 2 +- src/emu/debug/dvmemory.cpp | 2 +- src/emu/debug/dvstate.cpp | 12 +- src/emu/debug/dvwpoints.cpp | 2 +- src/emu/devfind.cpp | 2 +- src/emu/device.h | 100 ++-- src/emu/didisasm.h | 2 +- src/emu/diexec.cpp | 4 +- src/emu/diexec.h | 2 +- src/emu/digfx.h | 2 +- src/emu/diimage.cpp | 4 +- src/emu/diimage.h | 2 +- src/emu/dimemory.h | 5 +- src/emu/dinetwork.h | 2 +- src/emu/dinvram.h | 2 +- src/emu/dipalette.h | 2 +- src/emu/dipty.h | 2 +- src/emu/dirtc.h | 2 +- src/emu/dislot.h | 2 +- src/emu/disound.cpp | 6 +- src/emu/disound.h | 4 +- src/emu/distate.h | 2 +- src/emu/divideo.cpp | 4 +- src/emu/divideo.h | 2 +- src/emu/drivenum.cpp | 2 +- src/emu/driver.cpp | 2 +- src/emu/emufwd.h | 1 + src/emu/emumem.cpp | 3 +- src/emu/emumem.h | 2 +- src/emu/emuopts.cpp | 8 +- src/emu/image.cpp | 12 +- src/emu/ioport.cpp | 2 +- src/emu/machine.cpp | 24 +- src/emu/main.h | 2 +- src/emu/mconfig.cpp | 6 +- src/emu/network.cpp | 4 +- src/emu/profiler.cpp | 2 +- src/emu/render.cpp | 26 +- src/emu/render.h | 66 ++- src/emu/rendlay.cpp | 292 ++++++++--- src/emu/romload.cpp | 6 +- src/emu/schedule.cpp | 2 +- src/emu/screen.cpp | 2 +- src/emu/screen.h | 2 +- src/emu/softlist_dev.cpp | 6 +- src/emu/softlist_dev.h | 2 +- src/emu/sound.cpp | 14 +- src/emu/speaker.h | 2 +- src/emu/validity.cpp | 14 +- src/emu/video.cpp | 20 +- src/frontend/mame/audit.cpp | 4 +- src/frontend/mame/cheat.cpp | 2 +- src/frontend/mame/clifront.cpp | 20 +- src/frontend/mame/infoxml.cpp | 34 +- src/frontend/mame/luaengine.cpp | 485 +++++++++++------- src/frontend/mame/luaengine.h | 42 +- src/frontend/mame/luaengine.ipp | 95 +++- src/frontend/mame/luaengine_render.cpp | 636 ++++++++++++++++++++++-- src/frontend/mame/mame.cpp | 20 +- src/frontend/mame/mameopts.cpp | 2 +- src/frontend/mame/media_ident.cpp | 2 +- src/frontend/mame/ui/datmenu.cpp | 3 +- src/frontend/mame/ui/devctrl.h | 20 +- src/frontend/mame/ui/devopt.cpp | 14 +- src/frontend/mame/ui/filemngr.cpp | 4 +- src/frontend/mame/ui/info.cpp | 12 +- src/frontend/mame/ui/info_pty.cpp | 2 +- src/frontend/mame/ui/inifile.cpp | 2 +- src/frontend/mame/ui/mainmenu.cpp | 12 +- src/frontend/mame/ui/miscmenu.cpp | 4 +- src/frontend/mame/ui/selgame.cpp | 4 +- src/frontend/mame/ui/selsoft.cpp | 6 +- src/frontend/mame/ui/slotopt.cpp | 4 +- src/frontend/mame/ui/swlist.cpp | 3 +- src/frontend/mame/ui/ui.cpp | 16 +- src/frontend/mame/ui/viewgfx.cpp | 8 +- src/mame/drivers/apple2gs.cpp | 2 +- src/mame/drivers/pc9801.cpp | 2 +- src/mame/layout/mdndclab.lay | 147 +++--- src/mame/layout/v4dbltak.lay | 70 +-- src/mame/machine/hp9845_optrom.cpp | 4 +- src/mame/machine/msx.cpp | 10 +- src/osd/modules/debugger/debugimgui.cpp | 4 +- src/osd/modules/debugger/qt/mainwindow.cpp | 8 +- src/osd/modules/debugger/win/consolewininfo.cpp | 10 +- src/osd/modules/debugger/win/debugwininfo.cpp | 2 +- src/osd/modules/render/aviwrite.cpp | 2 +- src/osd/modules/render/bgfx/chain.cpp | 2 +- src/osd/modules/render/d3d/d3dhlsl.cpp | 10 +- src/osd/modules/render/drawd3d.cpp | 4 +- src/osd/sdl/window.cpp | 2 +- 115 files changed, 1803 insertions(+), 824 deletions(-) diff --git a/plugins/console/init.lua b/plugins/console/init.lua index 52d54fdcc1a..af8a8b7965d 100644 --- a/plugins/console/init.lua +++ b/plugins/console/init.lua @@ -28,11 +28,16 @@ function console.startplugin() print(num, line) end end - print(" _/ _/ _/_/ _/ _/ _/_/_/_/"); - print(" _/_/ _/_/ _/ _/ _/_/ _/_/ _/ "); - print(" _/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/ "); - print(" _/ _/ _/ _/ _/ _/ _/ "); - print("_/ _/ _/ _/ _/ _/ _/_/_/_/ \n"); + print(" /| /| /| /| /| _______") + print(" / | / | / | / | / | / /") + print(" / |/ | / | / |/ | / ____/ ") + print(" / | / | / | / /_ ") + print(" / |/ | / |/ __/ ") + print(" / /| /| /| |/ /| /| /____ ") + print(" / / | / | / | / | / | / ") + print("/ _/ |/ / / |___/ |/ /_______/ ") + print(" / / ") + print(" / _/ \n") print(emu.app_name() .. " " .. emu.app_version(), "\nCopyright (C) Nicola Salmoria and the MAME team\n"); print(_VERSION, "\nCopyright (C) Lua.org, PUC-Rio\n"); -- linenoise isn't thread safe but that means history can handled here diff --git a/plugins/layout/init.lua b/plugins/layout/init.lua index 8301167633e..aeb0ad77e44 100644 --- a/plugins/layout/init.lua +++ b/plugins/layout/init.lua @@ -13,17 +13,24 @@ local layout = exports function layout.startplugin() local scripts = {} - local function prepare_layout(script) - local env = { machine = manager:machine(), pairs = pairs, ipairs = ipairs, - table = { insert = table.insert, remove = table.remove } } + local function prepare_layout(file, script) + local env = { + machine = manager:machine(), + file = file, + print = print, + pairs = pairs, + ipairs = ipairs, + string = { format = string.format }, + table = { insert = table.insert, remove = table.remove } } local script, err = load(script, script, "t", env) if not script then emu.print_verbose("error loading layout script " .. err) return end - local name - script, name = script() - scripts[name] = script + local hooks = script() + if hooks ~= nil then + table.insert(scripts, hooks) + end end emu.register_callback(prepare_layout, "layout") diff --git a/scripts/build/complay.py b/scripts/build/complay.py index 6903418e242..445d25fe8ab 100755 --- a/scripts/build/complay.py +++ b/scripts/build/complay.py @@ -299,6 +299,16 @@ class LayoutChecker(Minifyer): self.have_color.append({ }) def checkViewItem(self, name, attrs): + if 'id' in attrs: + if not attrs['id']: + self.handleError('Element %s attribute id is empty' % (name, )) + elif not self.VARPATTERN.match(attrs['id']): + if attrs['id'] in self.item_ids: + self.handleError('Element %s has duplicate id "%s" (previous %s)' % (name, attrs['id'], self.item_ids[attrs['id']])) + else: + self.item_ids[attrs['id']] = self.formatLocation() + if self.repeat_depth[-1]: + self.handleError('Element %s attribute id "%s" in repeat contains no parameter references' % (name, attrs['id'])) if ('blend' in attrs) and (attrs['blend'] not in self.BLENDMODES) and not self.VARPATTERN.match(attrs['blend']): self.handleError('Element %s attribute blend "%s" is unsupported' % (name, attrs['blend'])) if 'inputtag' in attrs: @@ -340,6 +350,7 @@ class LayoutChecker(Minifyer): long(attrs['version']) except: self.handleError('Element mamelayout attribute version "%s" is not an integer' % (attrs['version'], )) + self.have_script = None self.variable_scopes.append({ }) self.repeat_depth.append(0) self.handlers.append((self.layoutStartHandler, self.layoutEndHandler)) @@ -379,6 +390,7 @@ class LayoutChecker(Minifyer): self.handleError('Element group has duplicate name (previous %s)' % (self.groups[attrs['name']], )) self.handlers.append((self.groupViewStartHandler, self.groupViewEndHandler)) self.variable_scopes.append({ }) + self.item_ids = { } self.repeat_depth.append(0) self.have_bounds.append(None) elif ('view' == name) and (not self.repeat_depth[-1]): @@ -389,9 +401,10 @@ class LayoutChecker(Minifyer): if attrs['name'] not in self.views: self.views[attrs['name']] = self.formatLocation() elif not self.VARPATTERN.match(attrs['name']): - self.handleError('Element view has duplicate name (previous %s)' % (self.views[attrs['name']], )) + self.handleError('Element view has duplicate name "%s" (previous %s)' % (attrs['name'], self.views[attrs['name']])) self.handlers.append((self.groupViewStartHandler, self.groupViewEndHandler)) self.variable_scopes.append({ }) + self.item_ids = { } self.repeat_depth.append(0) self.have_bounds.append(None) elif 'repeat' == name: @@ -407,6 +420,10 @@ class LayoutChecker(Minifyer): self.checkParameter(attrs) self.ignored_depth = 1 elif ('script' == name) and (not self.repeat_depth[-1]): + if self.have_script is None: + self.have_script = self.formatLocation() + else: + self.handleError('Duplicate script element (previous %s)' % (self.have_script, )) self.ignored_depth = 1 else: self.handleError('Encountered unexpected element %s' % (name, )) @@ -427,6 +444,7 @@ class LayoutChecker(Minifyer): self.handleError('Group "%s" not found (first referenced at %s)' % (group, self.referenced_groups[group])) if not self.views: self.handleError('No view elements found') + del self.have_script self.handlers.pop() def elementStartHandler(self, name, attrs): @@ -602,6 +620,7 @@ class LayoutChecker(Minifyer): elif self.repeat_depth[-1]: self.repeat_depth[-1] -= 1 else: + del self.item_ids self.current_collections = None self.repeat_depth.pop() self.have_bounds.pop() diff --git a/src/devices/bus/abcbus/abc890.cpp b/src/devices/bus/abcbus/abc890.cpp index 27530439929..9374096f38b 100644 --- a/src/devices/bus/abcbus/abc890.cpp +++ b/src/devices/bus/abcbus/abc890.cpp @@ -192,7 +192,7 @@ void abc890_device::device_reset() void abc890_device::abcbus_cs(uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) slot.write_cs(data); } @@ -205,7 +205,7 @@ uint8_t abc890_device::abcbus_inp() { uint8_t data = 0xff; - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) data &= slot.read_inp(); return data; @@ -218,7 +218,7 @@ uint8_t abc890_device::abcbus_inp() void abc890_device::abcbus_out(uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) slot.write_out(data); } @@ -231,7 +231,7 @@ uint8_t abc890_device::abcbus_stat() { uint8_t data = 0xff; - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) data &= slot.read_stat(); return data; @@ -244,7 +244,7 @@ uint8_t abc890_device::abcbus_stat() void abc890_device::abcbus_c1(uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) slot.write_c1(data); } @@ -255,7 +255,7 @@ void abc890_device::abcbus_c1(uint8_t data) void abc890_device::abcbus_c2(uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) slot.write_c2(data); } @@ -266,7 +266,7 @@ void abc890_device::abcbus_c2(uint8_t data) void abc890_device::abcbus_c3(uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) slot.write_c3(data); } @@ -277,7 +277,7 @@ void abc890_device::abcbus_c3(uint8_t data) void abc890_device::abcbus_c4(uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) slot.write_c4(data); } @@ -290,7 +290,7 @@ uint8_t abc890_device::abcbus_xmemfl(offs_t offset) { uint8_t data = 0xff; - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) { data &= slot.xmemfl_r(offset); } @@ -305,7 +305,7 @@ uint8_t abc890_device::abcbus_xmemfl(offs_t offset) void abc890_device::abcbus_xmemw(offs_t offset, uint8_t data) { - for (abcbus_slot_device &slot : abcbus_slot_device_iterator(*this)) + for (abcbus_slot_device &slot : abcbus_slot_device_enumerator(*this)) { slot.xmemw_w(offset, data); } diff --git a/src/devices/bus/abcbus/abcbus.h b/src/devices/bus/abcbus/abcbus.h index 1c5721650e4..c25cc8b51f2 100644 --- a/src/devices/bus/abcbus/abcbus.h +++ b/src/devices/bus/abcbus/abcbus.h @@ -271,7 +271,7 @@ void abcbus_cards(device_slot_interface &device); void abc1600bus_cards(device_slot_interface &device); -typedef device_type_iterator abcbus_slot_device_iterator; +typedef device_type_enumerator abcbus_slot_device_enumerator; #endif // MAME_DEVICES_ABCBUS_ABCBUS_H diff --git a/src/devices/bus/c64/bn1541.cpp b/src/devices/bus/c64/bn1541.cpp index dbb5fc4bb1a..ffdf84b77d1 100644 --- a/src/devices/bus/c64/bn1541.cpp +++ b/src/devices/bus/c64/bn1541.cpp @@ -75,9 +75,9 @@ c64_bn1541_device::c64_bn1541_device(const machine_config &mconfig, const char * void c64_bn1541_device::device_start() { - for (device_t &device : device_iterator(machine().root_device())) + for (device_t &device : device_enumerator(machine().root_device())) { - for (device_t &subdevice : device_iterator(device)) + for (device_t &subdevice : device_enumerator(device)) { if (subdevice.interface(m_other) && &subdevice != this) { diff --git a/src/devices/bus/coco/coco_dwsock.h b/src/devices/bus/coco/coco_dwsock.h index add3186a126..56e82e01f81 100644 --- a/src/devices/bus/coco/coco_dwsock.h +++ b/src/devices/bus/coco/coco_dwsock.h @@ -67,6 +67,6 @@ private: DECLARE_DEVICE_TYPE(COCO_DWSOCK, beckerport_device) // device iterator -typedef device_type_iterator beckerport_device_iterator; +typedef device_type_enumerator beckerport_device_enumerator; #endif // MAME_BUS_COCO_COCO_DWSOCKH_H diff --git a/src/devices/bus/tanbus/tanbus.h b/src/devices/bus/tanbus/tanbus.h index f5823a6df34..7f5e87eb0aa 100644 --- a/src/devices/bus/tanbus/tanbus.h +++ b/src/devices/bus/tanbus/tanbus.h @@ -144,6 +144,6 @@ void tanbus_devices(device_slot_interface &device); void tanbus6809_devices(device_slot_interface &device); -typedef device_type_iterator tanbus_slot_device_iterator; +typedef device_type_enumerator tanbus_slot_device_enumerator; #endif // MAME_BUS_TANBUS_TANBUS_H diff --git a/src/devices/bus/tmc600/euro.h b/src/devices/bus/tmc600/euro.h index c63fe2f3793..699de5b8383 100644 --- a/src/devices/bus/tmc600/euro.h +++ b/src/devices/bus/tmc600/euro.h @@ -102,7 +102,7 @@ DECLARE_DEVICE_TYPE(TMC600_EUROBUS_SLOT, tmc600_eurobus_slot_device) void tmc600_eurobus_cards(device_slot_interface &device); -typedef device_type_iterator tmc600_eurobus_slot_iterator; +typedef device_type_enumerator tmc600_eurobus_slot_enumerator; #endif // MAME_DEVICES_TMC600_EURO_H diff --git a/src/devices/imagedev/cassette.h b/src/devices/imagedev/cassette.h index e36b61d688d..5310bb546d3 100644 --- a/src/devices/imagedev/cassette.h +++ b/src/devices/imagedev/cassette.h @@ -140,6 +140,6 @@ private: DECLARE_DEVICE_TYPE(CASSETTE, cassette_image_device) // device iterator -typedef device_type_iterator cassette_device_iterator; +typedef device_type_enumerator cassette_device_enumerator; #endif // MAME_DEVICES_IMAGEDEV_CASSETTE_H diff --git a/src/devices/imagedev/midiin.h b/src/devices/imagedev/midiin.h index dbebdfd71fc..ef8e9e315b0 100644 --- a/src/devices/imagedev/midiin.h +++ b/src/devices/imagedev/midiin.h @@ -72,6 +72,6 @@ private: DECLARE_DEVICE_TYPE(MIDIIN, midiin_device) // device iterator -typedef device_type_iterator midiin_device_iterator; +typedef device_type_enumerator midiin_device_enumerator; #endif // MAME_IMAGEDEV_MIDIIN_H diff --git a/src/devices/imagedev/midiout.h b/src/devices/imagedev/midiout.h index 20bc87131c5..aaba05de929 100644 --- a/src/devices/imagedev/midiout.h +++ b/src/devices/imagedev/midiout.h @@ -60,6 +60,6 @@ private: DECLARE_DEVICE_TYPE(MIDIOUT, midiout_device) // device iterator -typedef device_type_iterator midiout_device_iterator; +typedef device_type_enumerator midiout_device_enumerator; #endif // MAME_IMAGEDEV_MIDIOUT_H diff --git a/src/devices/machine/bcreader.h b/src/devices/machine/bcreader.h index 48253de4380..6fd3966bef0 100644 --- a/src/devices/machine/bcreader.h +++ b/src/devices/machine/bcreader.h @@ -47,6 +47,6 @@ protected: DECLARE_DEVICE_TYPE(BARCODE_READER, barcode_reader_device) // device type iterator -typedef device_type_iterator barcode_reader_device_iterator; +typedef device_type_enumerator barcode_reader_device_enumerator; #endif // MAME_DEVICES_MACHINE_BCREADER_H diff --git a/src/devices/machine/laserdsc.h b/src/devices/machine/laserdsc.h index 14594bcf7cd..d55b5980a54 100644 --- a/src/devices/machine/laserdsc.h +++ b/src/devices/machine/laserdsc.h @@ -327,7 +327,7 @@ private: }; // iterator - interface iterator works for subclasses too -typedef device_interface_iterator laserdisc_device_iterator; +typedef device_interface_enumerator laserdisc_device_enumerator; diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index a13349e318f..76149986551 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -211,7 +211,7 @@ netlist_data_memregions_t::netlist_data_memregions_t(const device_t &dev) static bool rom_exists(device_t &root, pstring name) { // iterate, starting with the driver's ROMs and continuing with device ROMs - for (device_t &device : device_iterator(root)) + for (device_t &device : device_enumerator(root)) { // scan the ROM entries for this device for (tiny_rom_entry const *romp = device.rom_region(); romp && !ROMENTRY_ISEND(romp); ++romp) diff --git a/src/devices/machine/ram.h b/src/devices/machine/ram.h index 04a8a92da39..2af1f800ab4 100644 --- a/src/devices/machine/ram.h +++ b/src/devices/machine/ram.h @@ -83,6 +83,6 @@ private: DECLARE_DEVICE_TYPE(RAM, ram_device) // device iterator -typedef device_type_iterator ram_device_iterator; +typedef device_type_enumerator ram_device_enumerator; #endif // MAME_MACHINE_RAM_H diff --git a/src/devices/sound/samples.h b/src/devices/sound/samples.h index 394af9d0fdf..e7c2e5660fa 100644 --- a/src/devices/sound/samples.h +++ b/src/devices/sound/samples.h @@ -119,7 +119,7 @@ protected: }; // iterator, since lots of people are interested in these devices -typedef device_type_iterator samples_device_iterator; +typedef device_type_enumerator samples_device_enumerator; // ======================> samples_iterator diff --git a/src/devices/video/voodoo.cpp b/src/devices/video/voodoo.cpp index 9ee468dc412..ff34c3b2d18 100644 --- a/src/devices/video/voodoo.cpp +++ b/src/devices/video/voodoo.cpp @@ -5724,7 +5724,7 @@ void voodoo_device::device_start() /* set the type, and initialize the chip mask */ index = 0; - for (device_t &scan : device_iterator(machine().root_device())) + for (device_t &scan : device_enumerator(machine().root_device())) if (scan.type() == this->type()) { if (&scan == this) diff --git a/src/emu/addrmap.cpp b/src/emu/addrmap.cpp index d38d518aa55..7aeefd7baca 100644 --- a/src/emu/addrmap.cpp +++ b/src/emu/addrmap.cpp @@ -1175,7 +1175,7 @@ void address_map::map_validity_check(validity_checker &valid, int spacenum) cons std::string entry_region = entry.m_devbase.subtag(entry.m_region); // look for the region - for (device_t &dev : device_iterator(m_device->mconfig().root_device())) + for (device_t &dev : device_enumerator(m_device->mconfig().root_device())) { for (romload::region const ®ion : romload::entries(dev.rom_region()).get_regions()) { diff --git a/src/emu/crsshair.cpp b/src/emu/crsshair.cpp index 027d8828e32..0e570bb9eaf 100644 --- a/src/emu/crsshair.cpp +++ b/src/emu/crsshair.cpp @@ -123,7 +123,7 @@ render_crosshair::render_crosshair(running_machine &machine, int player) , m_time(0) { // for now, use the main screen - m_screen = screen_device_iterator(machine.root_device()).first(); + m_screen = screen_device_enumerator(machine.root_device()).first(); } @@ -377,8 +377,8 @@ crosshair_manager::crosshair_manager(running_machine &machine) machine.configuration().config_register("crosshairs", config_load_delegate(&crosshair_manager::config_load, this), config_save_delegate(&crosshair_manager::config_save, this)); /* register the animation callback */ - screen_device *first_screen = screen_device_iterator(machine.root_device()).first(); - if (first_screen != nullptr) + screen_device *first_screen = screen_device_enumerator(machine.root_device()).first(); + if (first_screen) first_screen->register_vblank_callback(vblank_state_delegate(&crosshair_manager::animate, this)); } diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 949f1194061..3aa7544f3ff 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -422,7 +422,7 @@ u64 debugger_commands::execute_s32(int params, const u64 *param) u64 debugger_commands::get_cpunum() { - execute_interface_iterator iter(m_machine.root_device()); + execute_interface_enumerator iter(m_machine.root_device()); return iter.indexof(m_console.get_visible_cpu()->execute()); } @@ -558,7 +558,7 @@ bool debugger_commands::validate_cpu_parameter(const char *param, device_t *&res // attempt to find by numerical index int index = 0; - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) { // real CPUs should have pcbase const device_state_interface *state; @@ -1074,7 +1074,7 @@ void debugger_commands::execute_focus(int ref, const std::vector &p cpu->debug()->ignore(false); /* then loop over CPUs and set the ignore flags on all other CPUs */ - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) if (&exec.device() != cpu) exec.device().debug()->ignore(true); m_console.printf("Now focused on CPU '%s'\n", cpu->tag()); @@ -1093,7 +1093,7 @@ void debugger_commands::execute_ignore(int ref, const std::vector & std::string buffer; /* loop over all executable devices */ - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) /* build up a comma-separated list */ if (!exec.device().debug()->observing()) @@ -1125,7 +1125,7 @@ void debugger_commands::execute_ignore(int ref, const std::vector & { /* make sure this isn't the last live CPU */ bool gotone = false; - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) if (&exec.device() != devicelist[paramnum] && exec.device().debug()->observing()) { gotone = true; @@ -1156,7 +1156,7 @@ void debugger_commands::execute_observe(int ref, const std::vector std::string buffer; /* loop over all executable devices */ - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) /* build up a comma-separated list */ if (exec.device().debug()->observing()) @@ -1204,7 +1204,7 @@ void debugger_commands::execute_suspend(int ref, const std::vector std::string buffer; /* loop over all executable devices */ - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) /* build up a comma-separated list */ if (exec.device().debug()->suspended()) @@ -1233,7 +1233,7 @@ void debugger_commands::execute_suspend(int ref, const std::vector { /* make sure this isn't the last live CPU */ bool gotone = false; - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) if (&exec.device() != devicelist[paramnum] && !exec.device().debug()->suspended()) { gotone = true; @@ -1263,7 +1263,7 @@ void debugger_commands::execute_resume(int ref, const std::vector & std::string buffer; /* loop over all executable devices */ - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) /* build up a comma-separated list */ if (exec.device().debug()->suspended()) @@ -1303,7 +1303,7 @@ void debugger_commands::execute_resume(int ref, const std::vector & void debugger_commands::execute_cpulist(int ref, const std::vector ¶ms) { int index = 0; - for (device_execute_interface &exec : execute_interface_iterator(m_machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(m_machine.root_device())) { device_state_interface *state; if (exec.device().interface(state) && state->state_find_entry(STATE_GENPCBASE) != nullptr) @@ -1462,7 +1462,7 @@ void debugger_commands::execute_bpclear(int ref, const std::vector /* if 0 parameters, clear all */ if (params.empty()) { - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) device.debug()->breakpoint_clear_all(); m_console.printf("Cleared all breakpoints\n"); } @@ -1473,7 +1473,7 @@ void debugger_commands::execute_bpclear(int ref, const std::vector else { bool found = false; - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (device.debug()->breakpoint_clear(bpindex)) found = true; if (found) @@ -1496,7 +1496,7 @@ void debugger_commands::execute_bpdisenable(int ref, const std::vectorbreakpoint_enable_all(ref); if (ref == 0) m_console.printf("Disabled all breakpoints\n"); @@ -1510,7 +1510,7 @@ void debugger_commands::execute_bpdisenable(int ref, const std::vectorbreakpoint_enable(bpindex, ref)) found = true; if (found) @@ -1532,7 +1532,7 @@ void debugger_commands::execute_bplist(int ref, const std::vector & std::string buffer; /* loop over all CPUs */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (!device.debug()->breakpoint_list().empty()) { m_console.printf("Device '%s' breakpoints:\n", device.tag()); @@ -1621,7 +1621,7 @@ void debugger_commands::execute_wpclear(int ref, const std::vector /* if 0 parameters, clear all */ if (params.empty()) { - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) device.debug()->watchpoint_clear_all(); m_console.printf("Cleared all watchpoints\n"); } @@ -1632,7 +1632,7 @@ void debugger_commands::execute_wpclear(int ref, const std::vector else { bool found = false; - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (device.debug()->watchpoint_clear(wpindex)) found = true; if (found) @@ -1655,7 +1655,7 @@ void debugger_commands::execute_wpdisenable(int ref, const std::vectorwatchpoint_enable_all(ref); if (ref == 0) m_console.printf("Disabled all watchpoints\n"); @@ -1669,7 +1669,7 @@ void debugger_commands::execute_wpdisenable(int ref, const std::vectorwatchpoint_enable(wpindex, ref)) found = true; if (found) @@ -1691,7 +1691,7 @@ void debugger_commands::execute_wplist(int ref, const std::vector & std::string buffer; /* loop over all CPUs */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) for (int spacenum = 0; spacenum < device.debug()->watchpoint_space_count(); ++spacenum) if (!device.debug()->watchpoint_vector(spacenum).empty()) { @@ -1763,7 +1763,7 @@ void debugger_commands::execute_rpclear(int ref, const std::vector /* if 0 parameters, clear all */ if (params.empty()) { - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) device.debug()->registerpoint_clear_all(); m_console.printf("Cleared all registerpoints\n"); } @@ -1774,7 +1774,7 @@ void debugger_commands::execute_rpclear(int ref, const std::vector else { bool found = false; - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (device.debug()->registerpoint_clear(rpindex)) found = true; if (found) @@ -1797,7 +1797,7 @@ void debugger_commands::execute_rpdisenable(int ref, const std::vectorregisterpoint_enable_all(ref); if (ref == 0) m_console.printf("Disabled all registerpoints\n"); @@ -1811,7 +1811,7 @@ void debugger_commands::execute_rpdisenable(int ref, const std::vectorregisterpoint_enable(rpindex, ref)) found = true; if (found) @@ -1833,7 +1833,7 @@ void debugger_commands::execute_rplist(int ref, const std::vector & std::string buffer; /* loop over all CPUs */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (!device.debug()->registerpoint_list().empty()) { m_console.printf("Device '%s' registerpoints:\n", device.tag()); @@ -1867,7 +1867,7 @@ void debugger_commands::execute_hotspot(int ref, const std::vector bool cleared = false; /* loop over CPUs and find live spots */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (device.debug()->hotspot_tracking_enabled()) { device.debug()->hotspot_track(0, 0); @@ -1919,7 +1919,7 @@ void debugger_commands::execute_stateload(int ref, const std::vectortrack_pc_data_clear(); device.debug()->track_mem_data_clear(); @@ -1937,7 +1937,7 @@ void debugger_commands::execute_rewind(int ref, const std::vector & bool success = m_machine.rewind_step(); if (success) // clear all PC & memory tracks - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) { device.debug()->track_pc_data_clear(); device.debug()->track_mem_data_clear(); @@ -3657,7 +3657,7 @@ void debugger_commands::execute_snap(int ref, const std::vector &pa const char *filename = params[0].c_str(); int scrnum = (params.size() > 1) ? atoi(params[1].c_str()) : 0; - screen_device_iterator iter(m_machine.root_device()); + screen_device_enumerator iter(m_machine.root_device()); screen_device *screen = iter.byindex(scrnum); if ((screen == nullptr) || !m_machine.render().is_live(*screen)) @@ -3750,7 +3750,7 @@ void debugger_commands::execute_memdump(int ref, const std::vector file = fopen(filename, "w"); if (file) { - memory_interface_iterator iter(m_machine.root_device()); + memory_interface_enumerator iter(m_machine.root_device()); for (device_memory_interface &memory : iter) { for (int space = 0; space != memory.max_space_count(); space++) if (memory.has_space(space)) @@ -3871,7 +3871,7 @@ void debugger_commands::execute_hardreset(int ref, const std::vector ¶ms) { - image_interface_iterator iter(m_machine.root_device()); + image_interface_enumerator iter(m_machine.root_device()); for (device_image_interface &img : iter) m_console.printf("%s: %s\n", img.brief_instance_name(), img.exists() ? img.filename() : "[empty slot]"); if (iter.first() == nullptr) @@ -3885,7 +3885,7 @@ void debugger_commands::execute_images(int ref, const std::vector & void debugger_commands::execute_mount(int ref, const std::vector ¶ms) { bool done = false; - for (device_image_interface &img : image_interface_iterator(m_machine.root_device())) + for (device_image_interface &img : image_interface_enumerator(m_machine.root_device())) { if (img.brief_instance_name() == params[0]) { @@ -3908,7 +3908,7 @@ void debugger_commands::execute_mount(int ref, const std::vector &p void debugger_commands::execute_unmount(int ref, const std::vector ¶ms) { bool done = false; - for (device_image_interface &img : image_interface_iterator(m_machine.root_device())) + for (device_image_interface &img : image_interface_enumerator(m_machine.root_device())) { if (img.brief_instance_name() == params[0]) { diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index 500310bd459..8bce3a26668 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -68,10 +68,10 @@ debugger_console::debugger_console(running_machine &machine) register_command("condump", CMDFLAG_NONE, 0, 1, 1, std::bind(&debugger_console::execute_condump, this, _1, _2)); /* first CPU is visible by default */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) { auto *cpu = dynamic_cast(&device); - if (cpu != nullptr) + if (cpu) { m_visiblecpu = cpu; break; diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index c3dd9a0c3a6..3c325d3a841 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -60,9 +60,9 @@ debugger_cpu::debugger_cpu(running_machine &machine) m_symtable->add("wpaddr", symbol_table::READ_ONLY, &m_wpaddr); m_symtable->add("wpdata", symbol_table::READ_ONLY, &m_wpdata); - screen_device_iterator screen_iterator = screen_device_iterator(m_machine.root_device()); - screen_device_iterator::auto_iterator iter = screen_iterator.begin(); - const uint32_t count = (uint32_t)screen_iterator.count(); + screen_device_enumerator screen_enumerator = screen_device_enumerator(m_machine.root_device()); + screen_device_enumerator::iterator iter = screen_enumerator.begin(); + const uint32_t count = (uint32_t)screen_enumerator.count(); if (count == 1) { @@ -104,7 +104,7 @@ void debugger_cpu::flush_traces() { /* this can be called on exit even when no debugging is enabled, so make sure the devdebug is valid before proceeding */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (device.debug() != nullptr) device.debug()->trace_flush(); } @@ -146,7 +146,7 @@ bool debugger_cpu::comment_save() // for each device bool found_comments = false; - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) if (device.debug() && device.debug()->comment_count() > 0) { // create a node for this device @@ -272,7 +272,7 @@ void debugger_cpu::on_vblank(screen_device &device, bool vblank_state) void debugger_cpu::reset_transient_flags() { /* loop over CPUs and reset the transient flags */ - for (device_t &device : device_iterator(m_machine.root_device())) + for (device_t &device : device_enumerator(m_machine.root_device())) device.debug()->reset_transient_flag(); m_stop_when_not_device = nullptr; } diff --git a/src/emu/debug/dvbpoints.cpp b/src/emu/debug/dvbpoints.cpp index 5a2cb7b0455..ba99c147a72 100644 --- a/src/emu/debug/dvbpoints.cpp +++ b/src/emu/debug/dvbpoints.cpp @@ -122,7 +122,7 @@ void debug_view_breakpoints::enumerate_sources() m_source_list.clear(); // iterate over devices with disassembly interfaces - for (device_disasm_interface &dasm : disasm_interface_iterator(machine().root_device())) + for (device_disasm_interface &dasm : disasm_interface_enumerator(machine().root_device())) { m_source_list.emplace_back( std::make_unique( diff --git a/src/emu/debug/dvdisasm.cpp b/src/emu/debug/dvdisasm.cpp index 956b0bdc29b..a08d500e92f 100644 --- a/src/emu/debug/dvdisasm.cpp +++ b/src/emu/debug/dvdisasm.cpp @@ -86,7 +86,7 @@ void debug_view_disasm::enumerate_sources() m_source_list.clear(); // iterate over devices with disassembly interfaces - for (device_disasm_interface &dasm : disasm_interface_iterator(machine().root_device())) + for (device_disasm_interface &dasm : disasm_interface_enumerator(machine().root_device())) { if (dasm.device().memory().space_config(AS_PROGRAM)) { diff --git a/src/emu/debug/dvmemory.cpp b/src/emu/debug/dvmemory.cpp index 4e9b8506a62..3ae8008f0a2 100644 --- a/src/emu/debug/dvmemory.cpp +++ b/src/emu/debug/dvmemory.cpp @@ -145,7 +145,7 @@ void debug_view_memory::enumerate_sources() m_source_list.reserve(machine().save().registration_count()); // first add all the devices' address spaces - for (device_memory_interface &memintf : memory_interface_iterator(machine().root_device())) + for (device_memory_interface &memintf : memory_interface_enumerator(machine().root_device())) { for (int spacenum = 0; spacenum < memintf.max_space_count(); ++spacenum) { diff --git a/src/emu/debug/dvstate.cpp b/src/emu/debug/dvstate.cpp index e24550bf34f..50e8c1610c4 100644 --- a/src/emu/debug/dvstate.cpp +++ b/src/emu/debug/dvstate.cpp @@ -74,7 +74,7 @@ void debug_view_state::enumerate_sources() m_source_list.clear(); // iterate over devices that have state interfaces - for (device_state_interface &state : state_interface_iterator(machine().root_device())) + for (device_state_interface &state : state_interface_enumerator(machine().root_device())) { m_source_list.emplace_back( std::make_unique( @@ -114,8 +114,8 @@ void debug_view_state::recompute() // add a cycles entry: cycles:99999999 m_state_list.emplace_back(REG_CYCLES, "cycles", 8); - screen_device_iterator screen_iterator = screen_device_iterator(machine().root_device()); - screen_device_iterator::auto_iterator iter = screen_iterator.begin(); + screen_device_enumerator screen_iterator(machine().root_device()); + screen_device_enumerator::iterator iter = screen_iterator.begin(); const int screen_count = screen_iterator.count(); if (screen_count == 1) @@ -236,19 +236,19 @@ void debug_view_state::view_update() case REG_BEAMX_S0: case REG_BEAMX_S1: case REG_BEAMX_S2: case REG_BEAMX_S3: case REG_BEAMX_S4: case REG_BEAMX_S5: case REG_BEAMX_S6: case REG_BEAMX_S7: - curitem.update(screen_device_iterator(machine().root_device()).byindex(-(curitem.index() - REG_BEAMX_S0))->hpos(), cycles_changed); + curitem.update(screen_device_enumerator(machine().root_device()).byindex(-(curitem.index() - REG_BEAMX_S0))->hpos(), cycles_changed); valstr = string_format("%4d", curitem.value()); break; case REG_BEAMY_S0: case REG_BEAMY_S1: case REG_BEAMY_S2: case REG_BEAMY_S3: case REG_BEAMY_S4: case REG_BEAMY_S5: case REG_BEAMY_S6: case REG_BEAMY_S7: - curitem.update(screen_device_iterator(machine().root_device()).byindex(-(curitem.index() - REG_BEAMY_S0))->vpos(), cycles_changed); + curitem.update(screen_device_enumerator(machine().root_device()).byindex(-(curitem.index() - REG_BEAMY_S0))->vpos(), cycles_changed); valstr = string_format("%4d", curitem.value()); break; case REG_FRAME_S0: case REG_FRAME_S1: case REG_FRAME_S2: case REG_FRAME_S3: case REG_FRAME_S4: case REG_FRAME_S5: case REG_FRAME_S6: case REG_FRAME_S7: - curitem.update(screen_device_iterator(machine().root_device()).byindex(-(curitem.index() - REG_FRAME_S0))->frame_number(), cycles_changed); + curitem.update(screen_device_enumerator(machine().root_device()).byindex(-(curitem.index() - REG_FRAME_S0))->frame_number(), cycles_changed); valstr = string_format("%-6d", curitem.value()); break; diff --git a/src/emu/debug/dvwpoints.cpp b/src/emu/debug/dvwpoints.cpp index f177cdf6a5c..605dcf8fe42 100644 --- a/src/emu/debug/dvwpoints.cpp +++ b/src/emu/debug/dvwpoints.cpp @@ -139,7 +139,7 @@ void debug_view_watchpoints::enumerate_sources() m_source_list.clear(); // iterate over devices with disassembly interfaces - for (device_disasm_interface &dasm : disasm_interface_iterator(machine().root_device())) + for (device_disasm_interface &dasm : disasm_interface_enumerator(machine().root_device())) { m_source_list.emplace_back( std::make_unique( diff --git a/src/emu/devfind.cpp b/src/emu/devfind.cpp index bbf3d35c1fb..d6bc984703e 100644 --- a/src/emu/devfind.cpp +++ b/src/emu/devfind.cpp @@ -95,7 +95,7 @@ bool finder_base::validate_memregion(bool required) const std::string const region_fulltag(m_base.get().subtag(m_tag)); // look for the region - for (device_t const &dev : device_iterator(m_base.get().mconfig().root_device())) + for (device_t const &dev : device_enumerator(m_base.get().mconfig().root_device())) { for (romload::region const ®ion : romload::entries(dev.rom_region()).get_regions()) { diff --git a/src/emu/device.h b/src/emu/device.h index fa973c56556..f6785a2741b 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -1008,13 +1008,13 @@ private: }; -// ======================> device_iterator +// ======================> device_enumerator // helper class to iterate over the hierarchy of devices depth-first -class device_iterator +class device_enumerator { public: - class auto_iterator + class iterator { public: typedef std::ptrdiff_t difference_type; @@ -1024,7 +1024,7 @@ public: typedef std::forward_iterator_tag iterator_category; // construction - auto_iterator(device_t *devptr, int curdepth, int maxdepth) + iterator(device_t *devptr, int curdepth, int maxdepth) : m_curdevice(devptr) , m_curdepth(curdepth) , m_maxdepth(maxdepth) @@ -1036,12 +1036,12 @@ public: int depth() const { return m_curdepth; } // required operator overrides - bool operator==(auto_iterator const &iter) const { return m_curdevice == iter.m_curdevice; } - bool operator!=(auto_iterator const &iter) const { return m_curdevice != iter.m_curdevice; } + bool operator==(iterator const &iter) const { return m_curdevice == iter.m_curdevice; } + bool operator!=(iterator const &iter) const { return m_curdevice != iter.m_curdevice; } device_t &operator*() const { assert(m_curdevice); return *m_curdevice; } device_t *operator->() const { return m_curdevice; } - auto_iterator &operator++() { advance(); return *this; } - auto_iterator operator++(int) { auto_iterator const result(*this); ++*this; return result; } + iterator &operator++() { advance(); return *this; } + iterator operator++(int) { iterator const result(*this); ++*this; return result; } protected: // search depth-first for the next device @@ -1082,18 +1082,17 @@ public: } // protected state - device_t * m_curdevice; - int m_curdepth; - const int m_maxdepth; + device_t * m_curdevice; + int m_curdepth; + int m_maxdepth; }; // construction - device_iterator(device_t &root, int maxdepth = 255) - : m_root(root), m_maxdepth(maxdepth) { } + device_enumerator(device_t &root, int maxdepth = 255) : m_root(root), m_maxdepth(maxdepth) { } // standard iterators - auto_iterator begin() const { return auto_iterator(&m_root, 0, m_maxdepth); } - auto_iterator end() const { return auto_iterator(nullptr, 0, m_maxdepth); } + iterator begin() const { return iterator(&m_root, 0, m_maxdepth); } + iterator end() const { return iterator(nullptr, 0, m_maxdepth); } // return first item device_t *first() const { return begin().current(); } @@ -1135,32 +1134,31 @@ public: private: // internal state - device_t & m_root; - int m_maxdepth; + device_t & m_root; + int m_maxdepth; }; -// ======================> device_type_iterator +// ======================> device_type_enumerator // helper class to find devices of a given type in the device hierarchy template -class device_type_iterator +class device_type_enumerator { public: - class auto_iterator : protected device_iterator::auto_iterator + class iterator : protected device_enumerator::iterator { public: - using device_iterator::auto_iterator::difference_type; - using device_iterator::auto_iterator::iterator_category; - using device_iterator::auto_iterator::depth; + using device_enumerator::iterator::difference_type; + using device_enumerator::iterator::iterator_category; + using device_enumerator::iterator::depth; typedef DeviceClass value_type; typedef DeviceClass *pointer; typedef DeviceClass &reference; // construction - auto_iterator(device_t *devptr, int curdepth, int maxdepth) - : device_iterator::auto_iterator(devptr, curdepth, maxdepth) + iterator(device_t *devptr, int curdepth, int maxdepth) : device_enumerator::iterator(devptr, curdepth, maxdepth) { // make sure the first device is of the specified type while (m_curdevice && (m_curdevice->type().type() != typeid(DeviceType))) @@ -1168,8 +1166,8 @@ public: } // required operator overrides - bool operator==(auto_iterator const &iter) const { return m_curdevice == iter.m_curdevice; } - bool operator!=(auto_iterator const &iter) const { return m_curdevice != iter.m_curdevice; } + bool operator==(iterator const &iter) const { return m_curdevice == iter.m_curdevice; } + bool operator!=(iterator const &iter) const { return m_curdevice != iter.m_curdevice; } // getters returning specified device type DeviceClass *current() const { return downcast(m_curdevice); } @@ -1177,25 +1175,23 @@ public: DeviceClass *operator->() const { return downcast(m_curdevice); } // search for devices of the specified type - auto_iterator &operator++() + iterator &operator++() { - advance(); - while (m_curdevice && (m_curdevice->type().type() != typeid(DeviceType))) - advance(); + do { advance(); } while (m_curdevice && (m_curdevice->type().type() != typeid(DeviceType))); return *this; } - auto_iterator operator++(int) { auto_iterator const result(*this); ++*this; return result; } + iterator operator++(int) { iterator const result(*this); ++*this; return result; } }; // construction - device_type_iterator(device_t &root, int maxdepth = 255) : m_root(root), m_maxdepth(maxdepth) { } + device_type_enumerator(device_t &root, int maxdepth = 255) : m_root(root), m_maxdepth(maxdepth) { } // standard iterators - auto_iterator begin() const { return auto_iterator(&m_root, 0, m_maxdepth); } - auto_iterator end() const { return auto_iterator(nullptr, 0, m_maxdepth); } - auto_iterator cbegin() const { return auto_iterator(&m_root, 0, m_maxdepth); } - auto_iterator cend() const { return auto_iterator(nullptr, 0, m_maxdepth); } + iterator begin() const { return iterator(&m_root, 0, m_maxdepth); } + iterator end() const { return iterator(nullptr, 0, m_maxdepth); } + iterator cbegin() const { return iterator(&m_root, 0, m_maxdepth); } + iterator cend() const { return iterator(nullptr, 0, m_maxdepth); } // return first item DeviceClass *first() const { return begin().current(); } @@ -1233,20 +1229,19 @@ private: }; -// ======================> device_interface_iterator +// ======================> device_interface_enumerator // helper class to find devices with a given interface in the device hierarchy // also works for finding devices derived from a given subclass -template -class device_interface_iterator +template +class device_interface_enumerator { public: - class auto_iterator : public device_iterator::auto_iterator + class iterator : public device_enumerator::iterator { -public: + public: // construction - auto_iterator(device_t *devptr, int curdepth, int maxdepth) - : device_iterator::auto_iterator(devptr, curdepth, maxdepth) + iterator(device_t *devptr, int curdepth, int maxdepth) : device_enumerator::iterator(devptr, curdepth, maxdepth) { // set the iterator for the first device with the interface find_interface(); @@ -1257,14 +1252,15 @@ public: InterfaceClass &operator*() const { assert(m_interface != nullptr); return *m_interface; } // search for devices with the specified interface - const auto_iterator &operator++() { advance(); find_interface(); return *this; } + const iterator &operator++() { advance(); find_interface(); return *this; } + iterator operator++(int) { iterator const result(*this); ++*this; return result; } -private: + private: // private helper void find_interface() { // advance until finding a device with the interface - for ( ; m_curdevice != nullptr; advance()) + for ( ; m_curdevice; advance()) if (m_curdevice->interface(m_interface)) return; @@ -1276,14 +1272,12 @@ private: InterfaceClass *m_interface; }; -public: // construction - device_interface_iterator(device_t &root, int maxdepth = 255) - : m_root(root), m_maxdepth(maxdepth) { } + device_interface_enumerator(device_t &root, int maxdepth = 255) : m_root(root), m_maxdepth(maxdepth) { } // standard iterators - auto_iterator begin() const { return auto_iterator(&m_root, 0, m_maxdepth); } - auto_iterator end() const { return auto_iterator(nullptr, 0, m_maxdepth); } + iterator begin() const { return iterator(&m_root, 0, m_maxdepth); } + iterator end() const { return iterator(nullptr, 0, m_maxdepth); } // return first item InterfaceClass *first() const { return begin().current(); } @@ -1390,4 +1384,4 @@ inline device_t::interface_list::auto_iterator device_t::interface_list::auto_it } -#endif /* MAME_EMU_DEVICE_H */ +#endif // MAME_EMU_DEVICE_H diff --git a/src/emu/didisasm.h b/src/emu/didisasm.h index 0813520a8c7..fef59c3372e 100644 --- a/src/emu/didisasm.h +++ b/src/emu/didisasm.h @@ -55,6 +55,6 @@ private: }; // iterator -typedef device_interface_iterator disasm_interface_iterator; +typedef device_interface_enumerator disasm_interface_enumerator; #endif // MAME_EMU_DIDISASM_H diff --git a/src/emu/diexec.cpp b/src/emu/diexec.cpp index c142fd960e1..55613cf90f2 100644 --- a/src/emu/diexec.cpp +++ b/src/emu/diexec.cpp @@ -350,7 +350,7 @@ void device_execute_interface::interface_validity_check(validity_checker &valid) // validate the interrupts if (!m_vblank_interrupt.isnull()) { - screen_device_iterator iter(device().mconfig().root_device()); + screen_device_enumerator iter(device().mconfig().root_device()); if (iter.first() == nullptr) osd_printf_error("VBLANK interrupt specified, but the driver is screenless\n"); else if (m_vblank_interrupt_screen != nullptr && device().siblingdevice(m_vblank_interrupt_screen) == nullptr) @@ -379,7 +379,7 @@ void device_execute_interface::interface_pre_start() m_driver_irq.resolve(); // fill in the initial states - int const index = device_iterator(device().machine().root_device()).indexof(*this); + int const index = device_enumerator(device().machine().root_device()).indexof(*this); m_suspend = SUSPEND_REASON_RESET; m_profiler = profile_type(index + PROFILER_DEVICE_FIRST); m_inttrigger = index + TRIGGER_INT; diff --git a/src/emu/diexec.h b/src/emu/diexec.h index c661544ba73..065248a9046 100644 --- a/src/emu/diexec.h +++ b/src/emu/diexec.h @@ -340,6 +340,6 @@ public: }; // iterator -typedef device_interface_iterator execute_interface_iterator; +typedef device_interface_enumerator execute_interface_enumerator; #endif // MAME_EMU_DIEXEC_H diff --git a/src/emu/digfx.h b/src/emu/digfx.h index 3829cd2882e..6ba323baafc 100644 --- a/src/emu/digfx.h +++ b/src/emu/digfx.h @@ -199,7 +199,7 @@ private: }; // iterator -typedef device_interface_iterator gfx_interface_iterator; +typedef device_interface_enumerator gfx_interface_enumerator; #endif /* MAME_EMU_DIGFX_H */ diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index db890ad3d8c..0b78816c8e5 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -1260,7 +1260,7 @@ void device_image_interface::update_names() // count instances of the general image type, or device type if custom int count = 0; int index = -1; - for (const device_image_interface &image : image_interface_iterator(device().mconfig().root_device())) + for (const device_image_interface &image : image_interface_enumerator(device().mconfig().root_device())) { if (this == &image) index = count; @@ -1302,7 +1302,7 @@ const software_part *device_image_interface::find_software_item(const std::strin : nullptr; // find the software list if explicitly specified - for (software_list_device &swlistdev : software_list_device_iterator(device().mconfig().root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(device().mconfig().root_device())) { if (list_name.empty() || (list_name == swlistdev.list_name())) { diff --git a/src/emu/diimage.h b/src/emu/diimage.h index 9f67530383f..9ec748c3bed 100644 --- a/src/emu/diimage.h +++ b/src/emu/diimage.h @@ -331,6 +331,6 @@ private: }; // iterator -typedef device_interface_iterator image_interface_iterator; +typedef device_interface_enumerator image_interface_enumerator; #endif /* MAME_EMU_DIIMAGE_H */ diff --git a/src/emu/dimemory.h b/src/emu/dimemory.h index 1c0d14ebe45..f15a04166f4 100644 --- a/src/emu/dimemory.h +++ b/src/emu/dimemory.h @@ -126,8 +126,7 @@ private: }; // iterator -typedef device_interface_iterator memory_interface_iterator; +typedef device_interface_enumerator memory_interface_enumerator; - -#endif /* MAME_EMU_DIMEMORY_H */ +#endif // MAME_EMU_DIMEMORY_H diff --git a/src/emu/dinetwork.h b/src/emu/dinetwork.h index d844be951ab..d165d752852 100644 --- a/src/emu/dinetwork.h +++ b/src/emu/dinetwork.h @@ -50,6 +50,6 @@ protected: // iterator -typedef device_interface_iterator network_interface_iterator; +typedef device_interface_enumerator network_interface_enumerator; #endif // MAME_EMU_DINETWORK_H diff --git a/src/emu/dinvram.h b/src/emu/dinvram.h index 65fd25d2578..fb02a9c6e14 100644 --- a/src/emu/dinvram.h +++ b/src/emu/dinvram.h @@ -48,7 +48,7 @@ protected: }; // iterator -typedef device_interface_iterator nvram_interface_iterator; +typedef device_interface_enumerator nvram_interface_enumerator; #endif /* MAME_EMU_DINVRAM */ diff --git a/src/emu/dipalette.h b/src/emu/dipalette.h index 7e41f968cea..1e84b2848e8 100644 --- a/src/emu/dipalette.h +++ b/src/emu/dipalette.h @@ -140,7 +140,7 @@ private: }; // interface type iterator -typedef device_interface_iterator palette_interface_iterator; +typedef device_interface_enumerator palette_interface_enumerator; #endif // MAME_EMU_DIPALETTE_H diff --git a/src/emu/dipty.h b/src/emu/dipty.h index e3297da9967..790d4ec39b0 100644 --- a/src/emu/dipty.h +++ b/src/emu/dipty.h @@ -37,6 +37,6 @@ protected: }; // iterator -typedef device_interface_iterator pty_interface_iterator; +typedef device_interface_enumerator pty_interface_enumerator; #endif // MAME_EMU_DIPTY_H diff --git a/src/emu/dirtc.h b/src/emu/dirtc.h index 76658b12a9f..89a08deb830 100644 --- a/src/emu/dirtc.h +++ b/src/emu/dirtc.h @@ -75,7 +75,7 @@ protected: }; // iterator -typedef device_interface_iterator rtc_interface_iterator; +typedef device_interface_enumerator rtc_interface_enumerator; #endif // MAME_EMU_DIRTC_H diff --git a/src/emu/dislot.h b/src/emu/dislot.h index a88102f84e5..ae9d8ec4575 100644 --- a/src/emu/dislot.h +++ b/src/emu/dislot.h @@ -227,6 +227,6 @@ protected: } }; -typedef device_interface_iterator slot_interface_iterator; +typedef device_interface_enumerator slot_interface_enumerator; #endif // MAME_EMU_DISLOT_H diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp index 7cbfe36bbff..abd5e4f4e12 100644 --- a/src/emu/disound.cpp +++ b/src/emu/disound.cpp @@ -287,7 +287,7 @@ void device_sound_interface::interface_validity_check(validity_checker &valid) c void device_sound_interface::interface_pre_start() { // scan all the sound devices - sound_interface_iterator iter(device().machine().root_device()); + sound_interface_enumerator iter(device().machine().root_device()); for (device_sound_interface const &sound : iter) { // scan each route on the device @@ -332,7 +332,7 @@ void device_sound_interface::interface_pre_start() void device_sound_interface::interface_post_start() { // iterate over all the sound devices - for (device_sound_interface &sound : sound_interface_iterator(device().machine().root_device())) + for (device_sound_interface &sound : sound_interface_enumerator(device().machine().root_device())) { // scan each route on the device for (sound_route const &route : sound.routes()) @@ -440,7 +440,7 @@ void device_mixer_interface::interface_pre_start() m_outputmap.resize(m_auto_allocated_inputs); // iterate through all routes that point to us and note their mixer output - for (device_sound_interface const &sound : sound_interface_iterator(device().machine().root_device())) + for (device_sound_interface const &sound : sound_interface_enumerator(device().machine().root_device())) { for (sound_route const &route : sound.routes()) { diff --git a/src/emu/disound.h b/src/emu/disound.h index 1d24150bfb2..e48ba290bc6 100644 --- a/src/emu/disound.h +++ b/src/emu/disound.h @@ -113,7 +113,7 @@ protected: }; // iterator -typedef device_interface_iterator sound_interface_iterator; +typedef device_interface_enumerator sound_interface_enumerator; @@ -142,7 +142,7 @@ protected: }; // iterator -typedef device_interface_iterator mixer_interface_iterator; +typedef device_interface_enumerator mixer_interface_enumerator; #endif // MAME_EMU_DISOUND_H diff --git a/src/emu/distate.h b/src/emu/distate.h index 5888313440e..0155d2afb11 100644 --- a/src/emu/distate.h +++ b/src/emu/distate.h @@ -373,7 +373,7 @@ protected: }; // iterator -typedef device_interface_iterator state_interface_iterator; +typedef device_interface_enumerator state_interface_enumerator; diff --git a/src/emu/divideo.cpp b/src/emu/divideo.cpp index b894f11fb5d..9ce8d53ac10 100644 --- a/src/emu/divideo.cpp +++ b/src/emu/divideo.cpp @@ -88,7 +88,7 @@ void device_video_interface::interface_validity_check(validity_checker &valid) c else { // otherwise, look for a single match - screen_device_iterator iter(device().mconfig().root_device()); + screen_device_enumerator iter(device().mconfig().root_device()); screen = iter.first(); if (iter.count() > 1) osd_printf_error("No screen specified for device '%s', but multiple screens found\n", device().tag()); @@ -121,7 +121,7 @@ void device_video_interface::interface_pre_start() else { // otherwise, look for a single match - screen_device_iterator iter(device().machine().root_device()); + screen_device_enumerator iter(device().machine().root_device()); m_screen = iter.first(); if (iter.count() > 1) throw emu_fatalerror("No screen specified for device '%s', but multiple screens found", device().tag()); diff --git a/src/emu/divideo.h b/src/emu/divideo.h index 626d5bc66b4..096f4fd9958 100644 --- a/src/emu/divideo.h +++ b/src/emu/divideo.h @@ -68,7 +68,7 @@ private: }; // iterator -typedef device_interface_iterator video_interface_iterator; +typedef device_interface_enumerator video_interface_enumerator; #endif /* MAME_EMU_DIVIDEO_H */ diff --git a/src/emu/drivenum.cpp b/src/emu/drivenum.cpp index 5a29dcabd9a..574205379cd 100644 --- a/src/emu/drivenum.cpp +++ b/src/emu/drivenum.cpp @@ -340,7 +340,7 @@ void driver_enumerator::release_current() const if (cached != m_config.end()) { // iterate over software lists in this entry and reset - for (software_list_device &swlistdev : software_list_device_iterator(cached->second->root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(cached->second->root_device())) swlistdev.release(); } } diff --git a/src/emu/driver.cpp b/src/emu/driver.cpp index eb128669f5c..04c6489aae3 100644 --- a/src/emu/driver.cpp +++ b/src/emu/driver.cpp @@ -211,7 +211,7 @@ ioport_constructor driver_device::device_input_ports() const void driver_device::device_start() { // reschedule ourselves to be last - for (device_t &test : device_iterator(*this)) + for (device_t &test : device_enumerator(*this)) if (&test != this && !test.started()) throw device_missing_dependencies(); diff --git a/src/emu/emufwd.h b/src/emu/emufwd.h index 1b6b48af522..aa8b72b8d9c 100644 --- a/src/emu/emufwd.h +++ b/src/emu/emufwd.h @@ -197,6 +197,7 @@ class output_manager; // declared in render.h class layout_element; class layout_view; +class layout_file; class render_container; class render_manager; class render_target; diff --git a/src/emu/emumem.cpp b/src/emu/emumem.cpp index c930fd31469..f7eb15a208f 100644 --- a/src/emu/emumem.cpp +++ b/src/emu/emumem.cpp @@ -302,9 +302,8 @@ memory_manager::~memory_manager() void memory_manager::initialize() { // loop over devices and spaces within each device - memory_interface_iterator iter(machine().root_device()); std::vector memories; - for (device_memory_interface &memory : iter) + for (device_memory_interface &memory : memory_interface_enumerator(machine().root_device())) { memories.push_back(&memory); allocate(memory); diff --git a/src/emu/emumem.h b/src/emu/emumem.h index be26838b91e..5e419241162 100644 --- a/src/emu/emumem.h +++ b/src/emu/emumem.h @@ -1658,7 +1658,7 @@ public: handler_entry *unmap_w() const { return m_unmap_w; } handler_entry *nop_r() const { return m_nop_r; } handler_entry *nop_w() const { return m_nop_w; } - + protected: // internal helpers virtual std::pair get_cache_info() = 0; diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp index d28d1bede37..ceda32dbbcc 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp @@ -567,7 +567,7 @@ bool emu_options::add_and_remove_slot_options() // create the configuration machine_config config(*m_system, *this); - for (const device_slot_interface &slot : slot_interface_iterator(config.root_device())) + for (const device_slot_interface &slot : slot_interface_enumerator(config.root_device())) { // come up with the canonical name of the slot const char *slot_option_name = slot.slot_name(); @@ -664,7 +664,7 @@ bool emu_options::add_and_remove_image_options() machine_config config(*m_system, *this); // iterate through all image devices - for (device_image_interface &image : image_interface_iterator(config.root_device())) + for (device_image_interface &image : image_interface_enumerator(config.root_device())) { const std::string &canonical_name(image.canonical_instance_name()); @@ -745,7 +745,7 @@ void emu_options::reevaluate_default_card_software() found = false; // iterate through all slot devices - for (device_slot_interface &slot : slot_interface_iterator(config.root_device())) + for (device_slot_interface &slot : slot_interface_enumerator(config.root_device())) { // retrieve info about the device instance auto &slot_opt(slot_option(slot.slot_name())); @@ -883,7 +883,7 @@ emu_options::software_options emu_options::evaluate_initial_softlist_options(con // and set up a configuration machine_config config(*m_system, *this); - software_list_device_iterator iter(config.root_device()); + software_list_device_enumerator iter(config.root_device()); if (iter.count() == 0) throw emu_fatalerror(EMU_ERR_FATALERROR, "Error: unknown option: %s\n", software_identifier.c_str()); diff --git a/src/emu/image.cpp b/src/emu/image.cpp index 4613d411c91..5da34b1abc5 100644 --- a/src/emu/image.cpp +++ b/src/emu/image.cpp @@ -30,7 +30,7 @@ image_manager::image_manager(running_machine &machine) : m_machine(machine) { // make sure that any required devices have been allocated - for (device_image_interface &image : image_interface_iterator(machine.root_device())) + for (device_image_interface &image : image_interface_enumerator(machine.root_device())) { // ignore things not user loadable if (!image.user_loadable()) @@ -93,7 +93,7 @@ void image_manager::unload_all() // extract the options options_extract(); - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { // unload this image image.unload(); @@ -110,7 +110,7 @@ void image_manager::config_load(config_type cfg_type, util::xml::data_node const if ((dev_instance != nullptr) && (dev_instance[0] != '\0')) { - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { if (!strcmp(dev_instance, image.instance_name().c_str())) { @@ -134,7 +134,7 @@ void image_manager::config_save(config_type cfg_type, util::xml::data_node *pare /* only care about game-specific data */ if (cfg_type == config_type::GAME) { - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { const char *const dev_instance = image.instance_name().c_str(); @@ -182,7 +182,7 @@ int image_manager::write_config(emu_options &options, const char *filename, cons void image_manager::options_extract() { - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { // There are two scenarios where we want to extract the option: // @@ -230,7 +230,7 @@ void image_manager::options_extract() void image_manager::postdevice_init() { /* make sure that any required devices have been allocated */ - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { image_init_result result = image.finish_load(); diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp index e9fd8d7b6d7..e3b2aa9b473 100644 --- a/src/emu/ioport.cpp +++ b/src/emu/ioport.cpp @@ -1675,7 +1675,7 @@ time_t ioport_manager::initialize() init_port_types(); // if we have a token list, proceed - device_iterator iter(machine().root_device()); + device_enumerator iter(machine().root_device()); for (device_t &device : iter) { std::string errors; diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index 246cca0dd3e..f25d236083a 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -140,7 +140,7 @@ running_machine::running_machine(const machine_config &_config, machine_manager m_dummy_space.config_complete(); // set the machine on all devices - device_iterator iter(root_device()); + device_enumerator iter(root_device()); for (device_t &device : iter) device.set_machine(*this); @@ -222,7 +222,7 @@ void running_machine::start() m_sound = std::make_unique(*this); // resolve objects that can be used by memory maps - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) device.resolve_pre_map(); // configure the address spaces, load ROMs (which needs @@ -252,7 +252,7 @@ void running_machine::start() manager().create_custom(*this); // resolve objects that are created by memory maps - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) device.resolve_post_map(); // register callbacks for the devices, then start them @@ -551,7 +551,7 @@ std::string running_machine::get_statename(const char *option) const //printf("check template: %s\n", devname_str.c_str()); // verify that there is such a device for this system - for (device_image_interface &image : image_interface_iterator(root_device())) + for (device_image_interface &image : image_interface_enumerator(root_device())) { // get the device name std::string tempdevname(image.brief_instance_name()); @@ -878,7 +878,7 @@ void running_machine::current_datetime(system_time &systime) void running_machine::set_rtc_datetime(const system_time &systime) { - for (device_rtc_interface &rtc : rtc_interface_iterator(root_device())) + for (device_rtc_interface &rtc : rtc_interface_enumerator(root_device())) if (rtc.has_battery()) rtc.set_current_time(systime); } @@ -1047,7 +1047,7 @@ void running_machine::start_all_devices() { // iterate over all devices int failed_starts = 0; - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) if (!device.started()) { // attempt to start the device, catching any expected exceptions @@ -1104,7 +1104,7 @@ void running_machine::stop_all_devices() debugger().cpu().comment_save(); // iterate over devices and stop them - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) device.stop(); } @@ -1116,7 +1116,7 @@ void running_machine::stop_all_devices() void running_machine::presave_all_devices() { - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) device.pre_save(); } @@ -1128,7 +1128,7 @@ void running_machine::presave_all_devices() void running_machine::postload_all_devices() { - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) device.post_load(); } @@ -1181,7 +1181,7 @@ std::string running_machine::nvram_filename(device_t &device) const void running_machine::nvram_load() { - for (device_nvram_interface &nvram : nvram_interface_iterator(root_device())) + for (device_nvram_interface &nvram : nvram_interface_enumerator(root_device())) { emu_file file(options().nvram_directory(), OPEN_FLAG_READ); if (file.open(nvram_filename(nvram.device())) == osd_file::error::NONE) @@ -1201,7 +1201,7 @@ void running_machine::nvram_load() void running_machine::nvram_save() { - for (device_nvram_interface &nvram : nvram_interface_iterator(root_device())) + for (device_nvram_interface &nvram : nvram_interface_enumerator(root_device())) { if (nvram.nvram_can_save()) { @@ -1269,7 +1269,7 @@ void running_machine::export_http_api() writer.Key("devices"); writer.StartArray(); - device_iterator iter(this->root_device()); + device_enumerator iter(this->root_device()); for (device_t &device : iter) writer.String(device.tag()); diff --git a/src/emu/main.h b/src/emu/main.h index 609985a48bf..3c75205de14 100644 --- a/src/emu/main.h +++ b/src/emu/main.h @@ -59,7 +59,7 @@ public: static void periodic_check(); static bool frame_hook(); static void sound_hook(); - static void layout_file_cb(util::xml::data_node const &layout); + static void layout_script_cb(layout_file &file, const char *script); static bool standalone(); }; diff --git a/src/emu/mconfig.cpp b/src/emu/mconfig.cpp index cf162ae4f06..32b82468c3a 100644 --- a/src/emu/mconfig.cpp +++ b/src/emu/mconfig.cpp @@ -51,7 +51,7 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options) device_add("root", gamedrv.type, 0); // intialize slot devices - make sure that any required devices have been allocated - for (device_slot_interface &slot : slot_interface_iterator(root_device())) + for (device_slot_interface &slot : slot_interface_enumerator(root_device())) { device_t &owner = slot.device(); const char *slot_option_name = owner.tag() + 1; @@ -104,7 +104,7 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options) } // then notify all devices that their configuration is complete - for (device_t &device : device_iterator(root_device())) + for (device_t &device : device_enumerator(root_device())) if (!device.configured()) device.config_complete(); } @@ -380,7 +380,7 @@ void machine_config::remove_references(device_t &device) } // iterate over all devices and remove any references - for (device_t &scan : device_iterator(root_device())) + for (device_t &scan : device_enumerator(root_device())) scan.subdevices().m_tagmap.clear(); } diff --git a/src/emu/network.cpp b/src/emu/network.cpp index 1456013a74f..92ac826e9d8 100644 --- a/src/emu/network.cpp +++ b/src/emu/network.cpp @@ -44,7 +44,7 @@ void network_manager::config_load(config_type cfg_type, util::xml::data_node con if ((tag != nullptr) && (tag[0] != '\0')) { - for (device_network_interface &network : network_interface_iterator(machine().root_device())) + for (device_network_interface &network : network_interface_enumerator(machine().root_device())) { if (!strcmp(tag, network.device().tag())) { int interface = node->get_attribute_int("interface", 0); @@ -74,7 +74,7 @@ void network_manager::config_save(config_type cfg_type, util::xml::data_node *pa /* only care about game-specific data */ if (cfg_type == config_type::GAME) { - for (device_network_interface &network : network_interface_iterator(machine().root_device())) + for (device_network_interface &network : network_interface_enumerator(machine().root_device())) { util::xml::data_node *const node = parentnode->add_child("device", nullptr); if (node != nullptr) diff --git a/src/emu/profiler.cpp b/src/emu/profiler.cpp index 173e2f4d767..765373e34e7 100644 --- a/src/emu/profiler.cpp +++ b/src/emu/profiler.cpp @@ -193,7 +193,7 @@ void real_profiler_state::update_text(running_machine &machine) } // loop over all types and generate the string - device_iterator iter(machine.root_device()); + device_enumerator iter(machine.root_device()); std::ostringstream stream; for (curtype = PROFILER_DEVICE_FIRST; curtype < PROFILER_TOTAL; ++curtype) { diff --git a/src/emu/render.cpp b/src/emu/render.cpp index 41563bdb873..c81db6c78d8 100644 --- a/src/emu/render.cpp +++ b/src/emu/render.cpp @@ -1073,7 +1073,7 @@ unsigned render_target::configured_view(const char *viewname, int targetindex, i // if we don't have a match, default to the nth view std::vector > screens; - for (screen_device &screen : screen_device_iterator(m_manager.machine().root_device())) + for (screen_device &screen : screen_device_enumerator(m_manager.machine().root_device())) screens.push_back(screen); if (!view && !screens.empty()) { @@ -1615,17 +1615,10 @@ void render_target::debug_append(render_container &container) void render_target::resolve_tags() { for (layout_file &file : m_filelist) - { - for (layout_view &view : file.views()) - { - view.resolve_tags(); - if (¤t_view() == &view) - { - view.recompute(visibility_mask(), m_layerconfig.zoom_to_screen()); - view.preload(); - } - } - } + file.resolve_tags(); + + current_view().recompute(visibility_mask(), m_layerconfig.zoom_to_screen()); + current_view().preload(); } @@ -1779,7 +1772,7 @@ void render_target::load_additional_layout_files(const char *basename, bool have bool m_rotated; std::pair m_physical, m_native; }; - screen_device_iterator iter(m_manager.machine().root_device()); + screen_device_enumerator iter(m_manager.machine().root_device()); std::vector const screens(std::begin(iter), std::end(iter)); // need this because views aren't fully set up yet @@ -2208,13 +2201,12 @@ bool render_target::load_layout_file(device_t &device, util::xml::data_node cons { m_filelist.emplace_back(device, rootnode, searchpath, dirname); } - catch (emu_fatalerror &) + catch (emu_fatalerror &err) { + osd_printf_warning("%s\n", err.what()); return false; } - emulator_info::layout_file_cb(rootnode); - return true; } @@ -3053,7 +3045,7 @@ render_manager::render_manager(running_machine &machine) machine.configuration().config_register("video", config_load_delegate(&render_manager::config_load, this), config_save_delegate(&render_manager::config_save, this)); // create one container per screen - for (screen_device &screen : screen_device_iterator(machine.root_device())) + for (screen_device &screen : screen_device_enumerator(machine.root_device())) screen.set_container(*container_alloc(&screen)); } diff --git a/src/emu/render.h b/src/emu/render.h index 3dc7376957c..e24893033c6 100644 --- a/src/emu/render.h +++ b/src/emu/render.h @@ -176,7 +176,7 @@ namespace emu::render::detail { struct bounds_step { - constexpr render_bounds get() const { return bounds; } + void get(render_bounds &result) const { result = bounds; } int state; render_bounds bounds; @@ -186,7 +186,7 @@ using bounds_vector = std::vector; struct color_step { - constexpr render_color get() const { return color; } + void get(render_color &result) const { result = color; } int state; render_color color; @@ -735,6 +735,10 @@ public: friend class layout_view; public: + using state_delegate = delegate; + using bounds_delegate = delegate; + using color_delegate = delegate; + // construction/destruction item( view_environment &env, @@ -746,12 +750,13 @@ public: ~item(); // getters + std::string const &id() const { return m_id; } layout_element *element() const { return m_element; } screen_device *screen() { return m_screen; } bool bounds_animated() const { return m_bounds.size() > 1U; } bool color_animated() const { return m_color.size() > 1U; } - render_bounds bounds() const { return m_get_bounds(); } - render_color color() const { return m_get_color(); } + render_bounds bounds() const { render_bounds result; m_get_bounds(result); return result; } + render_color color() const { render_color result; m_get_color(result); return result; } int blend_mode() const { return m_blend_mode; } u32 visibility_mask() const { return m_visibility_mask; } int orientation() const { return m_orientation; } @@ -766,24 +771,35 @@ public: int element_state() const { return m_get_elem_state(); } int animation_state() const { return m_get_anim_state(); } + // set state + void set_state(int state) { m_elem_state = state; } + + // set handlers + void set_element_state_callback(state_delegate &&handler); + void set_animation_state_callback(state_delegate &&handler); + void set_bounds_callback(bounds_delegate &&handler); + void set_color_callback(color_delegate &&handler); + // resolve tags, if any void resolve_tags(); private: using bounds_vector = emu::render::detail::bounds_vector; using color_vector = emu::render::detail::color_vector; - using state_delegate = delegate; - using bounds_delegate = delegate; - using color_delegate = delegate; + state_delegate default_get_elem_state(); + state_delegate default_get_anim_state(); + bounds_delegate default_get_bounds(); + color_delegate default_get_color(); + int get_state() const; int get_output() const; int get_input_raw() const; int get_input_field_cached() const; int get_input_field_conditional() const; int get_anim_output() const; int get_anim_input() const; - render_bounds get_interpolated_bounds() const; - render_color get_interpolated_color() const; + void get_interpolated_bounds(render_bounds &result) const; + void get_interpolated_color(render_color &result) const; static layout_element *find_element(view_environment &env, util::xml::data_node const &itemnode, element_map &elemmap); static bounds_vector make_bounds(view_environment &env, util::xml::data_node const &itemnode, layout_group::transform const &trans); @@ -804,26 +820,28 @@ public: output_finder<> m_output; // associated output output_finder<> m_animoutput; // associated output for animation if different ioport_port * m_animinput_port; // input port used for animation + int m_elem_state; // element state used in absence of bindings ioport_value const m_animmask; // mask for animation state u8 const m_animshift; // shift for animation state ioport_port * m_input_port; // input port of this item ioport_field const * m_input_field; // input port field of this item ioport_value const m_input_mask; // input mask of this item u8 const m_input_shift; // input mask rightshift for raw (trailing 0s) - bool const m_input_raw; // get raw data from input port bool m_clickthrough; // should click pass through to lower elements screen_device * m_screen; // pointer to screen - int m_orientation; // orientation of this item + int const m_orientation; // orientation of this item bounds_vector m_bounds; // bounds of the item color_vector const m_color; // color of the item int m_blend_mode; // blending mode to use when drawing u32 m_visibility_mask; // combined mask of parent visibility groups // cold items + std::string const m_id; // optional unique item identifier std::string const m_input_tag; // input tag of this item std::string const m_animinput_tag; // tag of input port for animation state bounds_vector const m_rawbounds; // raw (original) bounds of the item bool const m_have_output; // whether we actually have an output + bool const m_input_raw; // get raw data from input port bool const m_have_animoutput; // whether we actually have an output for animation bool const m_has_clickthrough; // whether clickthrough was explicitly configured }; @@ -893,9 +911,11 @@ public: ~layout_view(); // getters + item *get_item(std::string const &id); item_list &items() { return m_items; } bool has_screen(screen_device &screen); const std::string &name() const { return m_name; } + const std::string &unqualified_name() const { return m_unqualified_name; } size_t visible_screen_count() const { return m_screens.size(); } float effective_aspect() const { return m_effaspect; } const render_bounds &bounds() const { return m_bounds; } @@ -920,6 +940,12 @@ public: private: struct layer_lists; + using item_id_map = std::unordered_map< + std::reference_wrapper, + item &, + std::hash, + std::equal_to >; + // add items, recursing for groups void add_items( layer_lists &layers, @@ -937,7 +963,6 @@ private: static std::string make_name(layout_environment &env, util::xml::data_node const &viewnode); // internal state - std::string m_name; // name of the layout float m_effaspect; // X/Y of the layout in current configuration render_bounds m_bounds; // computed bounds of the view in current configuration item_list m_items; // list of layout items @@ -949,6 +974,9 @@ private: screen_ref_vector m_screens; // list screens visible in current configuration // cold items + std::string m_name; // display name for the view + std::string m_unqualified_name; // the name exactly as specified in the layout file + item_id_map m_items_by_id; // items with non-empty ID indexed by ID visibility_toggle_vector m_vistoggles; // collections of items that can be shown/hidden render_bounds m_expbounds; // explicit bounds of the view u32 m_defvismask; // default visibility mask @@ -966,16 +994,24 @@ public: using element_map = std::unordered_map; using group_map = std::unordered_map; using view_list = std::list; + using resolve_tags_delegate = delegate; // construction/destruction layout_file(device_t &device, util::xml::data_node const &rootnode, char const *searchpath, char const *dirname); ~layout_file(); // getters + device_t &device() const { return m_device; } element_map const &elements() const { return m_elemmap; } view_list &views() { return m_viewlist; } view_list const &views() const { return m_viewlist; } + // resolve tags, if any + void resolve_tags(); + + // set handlers + void set_resolve_tags_callback(resolve_tags_delegate &&handler); + private: using environment = emu::render::detail::layout_environment; @@ -988,8 +1024,10 @@ private: bool init); // internal state - element_map m_elemmap; // list of shared layout elements - view_list m_viewlist; // list of views + device_t & m_device; // device that caused file to be loaded + element_map m_elemmap; // list of shared layout elements + view_list m_viewlist; // list of views + resolve_tags_delegate m_resolve_tags; // additional actions after resolving tags }; // ======================> render_target diff --git a/src/emu/rendlay.cpp b/src/emu/rendlay.cpp index 326089c3f10..46124cf73f6 100644 --- a/src/emu/rendlay.cpp +++ b/src/emu/rendlay.cpp @@ -89,11 +89,6 @@ constexpr layout_group::transform identity_transform{{ {{ 1.0F, 0.0F, 0.0F }}, { // HELPERS //************************************************************************** -constexpr int get_state_dummy(layout_view::item &item) -{ - return 0; -} - inline void render_bounds_transform(render_bounds &bounds, layout_group::transform const &trans) { bounds = render_bounds{ @@ -420,7 +415,7 @@ private: try_insert("deviceshortname", device().shortname()); util::ovectorstream tmp; unsigned i(0U); - for (screen_device const &screen : screen_device_iterator(machine().root_device())) + for (screen_device const &screen : screen_device_enumerator(machine().root_device())) { std::pair const physaspect(screen.physical_aspect()); s64 const w(screen.visible_area().width()), h(screen.visible_area().height()); @@ -3955,9 +3950,9 @@ layout_view::layout_view( util::xml::data_node const &viewnode, element_map &elemmap, group_map &groupmap) - : m_name(make_name(env, viewnode)) - , m_effaspect(1.0f) - , m_items() + : m_effaspect(1.0f) + , m_name(make_name(env, viewnode)) + , m_unqualified_name(env.get_attribute_string(viewnode, "name", "")) , m_defvismask(0U) , m_has_art(false) { @@ -4044,6 +4039,16 @@ layout_view::layout_view( m_items.splice(m_items.end(), layers.marquees); } + // index items with keys supplied + for (item &curitem : m_items) + { + if (!curitem.id().empty()) + { + if (!m_items_by_id.emplace(curitem.id(), curitem).second) + throw layout_syntax_error("view contains item with duplicate id attribute"); + } + } + // calculate metrics recompute(default_visibility_mask(), false); for (group_map::value_type &group : groupmap) @@ -4060,9 +4065,20 @@ layout_view::~layout_view() } +//------------------------------------------------- +// get_item - get item by ID +//------------------------------------------------- + +layout_view::item *layout_view::get_item(std::string const &id) +{ + auto const found(m_items_by_id.find(id)); + return (m_items_by_id.end() != found) ? &found->second : nullptr; +} + + //------------------------------------------------- // has_screen - return true if this view contains -// the given screen +// the specified screen //------------------------------------------------- bool layout_view::has_screen(screen_device &screen) @@ -4395,8 +4411,8 @@ void layout_view::add_items( std::string layout_view::make_name(layout_environment &env, util::xml::data_node const &viewnode) { char const *const name(env.get_attribute_string(viewnode, "name", nullptr)); - if (!name) - throw layout_syntax_error("view must have name attribute"); + if (!name || !*name) + throw layout_syntax_error("view must have non-empty name attribute"); if (env.is_root_device()) { @@ -4432,30 +4448,32 @@ layout_view::item::item( , m_output(env.device(), env.get_attribute_string(itemnode, "name", "")) , m_animoutput(env.device(), make_animoutput_tag(env, itemnode)) , m_animinput_port(nullptr) + , m_elem_state(m_element ? m_element->default_state() : 0) , m_animmask(make_animmask(env, itemnode)) , m_animshift(get_state_shift(m_animmask)) , m_input_port(nullptr) , m_input_field(nullptr) , m_input_mask(env.get_attribute_int(itemnode, "inputmask", 0)) , m_input_shift(get_state_shift(m_input_mask)) - , m_input_raw(env.get_attribute_bool(itemnode, "inputraw", 0)) , m_clickthrough(env.get_attribute_bool(itemnode, "clickthrough", "yes")) , m_screen(nullptr) , m_orientation(orientation_add(env.parse_orientation(itemnode.get_child("orientation")), orientation)) , m_color(make_color(env, itemnode, color)) , m_blend_mode(get_blend_mode(env, itemnode)) , m_visibility_mask(env.visibility_mask()) + , m_id(env.get_attribute_string(itemnode, "id", "")) , m_input_tag(make_input_tag(env, itemnode)) , m_animinput_tag(make_animinput_tag(env, itemnode)) , m_rawbounds(make_bounds(env, itemnode, trans)) , m_have_output(env.get_attribute_string(itemnode, "name", "")[0]) + , m_input_raw(env.get_attribute_bool(itemnode, "inputraw", 0)) , m_have_animoutput(!make_animoutput_tag(env, itemnode).empty()) , m_has_clickthrough(env.get_attribute_string(itemnode, "clickthrough", "")[0]) { // fetch common data int index = env.get_attribute_int(itemnode, "index", -1); if (index != -1) - m_screen = screen_device_iterator(env.machine().root_device()).byindex(index); + m_screen = screen_device_enumerator(env.machine().root_device()).byindex(index); // sanity checks if (strcmp(itemnode.get_name(), "screen") == 0) @@ -4492,9 +4510,65 @@ layout_view::item::~item() } -//--------------------------------------------- +//------------------------------------------------- +// set_element_state_callback - set callback to +// obtain element state value +//------------------------------------------------- + +void layout_view::item::set_element_state_callback(state_delegate &&handler) +{ + if (!handler.isnull()) + m_get_elem_state = std::move(handler); + else + m_get_elem_state = default_get_elem_state(); +} + + +//------------------------------------------------- +// set_animation_state_callback - set callback to +// obtain animation state +//------------------------------------------------- + +void layout_view::item::set_animation_state_callback(state_delegate &&handler) +{ + if (!handler.isnull()) + m_get_anim_state = std::move(handler); + else + m_get_anim_state = default_get_anim_state(); +} + + +//------------------------------------------------- +// set_bounds_callback - set callback to obtain +// bounds +//------------------------------------------------- + +void layout_view::item::set_bounds_callback(bounds_delegate &&handler) +{ + if (!handler.isnull()) + m_get_bounds = std::move(handler); + else + m_get_bounds = default_get_bounds(); +} + + +//------------------------------------------------- +// set_color_callback - set callback to obtain +// color +//------------------------------------------------- + +void layout_view::item::set_color_callback(color_delegate &&handler) +{ + if (!handler.isnull()) + m_get_color = std::move(handler); + else + m_get_color = default_get_color(); +} + + +//------------------------------------------------- // resolve_tags - resolve tags, if any are set -//--------------------------------------------- +//------------------------------------------------- void layout_view::item::resolve_tags() { @@ -4537,39 +4611,87 @@ void layout_view::item::resolve_tags() } } - // choose optimal element state function + // choose optimal handlers + m_get_elem_state = default_get_elem_state(); + m_get_anim_state = default_get_anim_state(); + m_get_bounds = default_get_bounds(); + m_get_color = default_get_color(); +} + + +//------------------------------------------------- +// default_get_elem_state - get default element +// state handler +//------------------------------------------------- + +layout_view::item::state_delegate layout_view::item::default_get_elem_state() +{ if (m_have_output) - m_get_elem_state = state_delegate(&item::get_output, this); + return state_delegate(&item::get_output, this); else if (!m_input_port) - m_get_elem_state = state_delegate(&get_state_dummy, this); + return state_delegate(&item::get_state, this); else if (m_input_raw) - m_get_elem_state = state_delegate(&item::get_input_raw, this); + return state_delegate(&item::get_input_raw, this); else if (m_input_field) - m_get_elem_state = state_delegate(&item::get_input_field_cached, this); + return state_delegate(&item::get_input_field_cached, this); else - m_get_elem_state = state_delegate(&item::get_input_field_conditional, this); + return state_delegate(&item::get_input_field_conditional, this); +} - // choose optimal animation state function + +//------------------------------------------------- +// default_get_anim_state - get default animation +// state handler +//------------------------------------------------- + +layout_view::item::state_delegate layout_view::item::default_get_anim_state() +{ if (m_have_animoutput) - m_get_anim_state = state_delegate(&item::get_anim_output, this); + return state_delegate(&item::get_anim_output, this); else if (m_animinput_port) - m_get_anim_state = state_delegate(&item::get_anim_input, this); + return state_delegate(&item::get_anim_input, this); else - m_get_anim_state = m_get_elem_state; + return default_get_elem_state(); +} - // choose optional bounds and colour functions - m_get_bounds = (m_bounds.size() == 1U) + +//------------------------------------------------- +// default_get_bounds - get default bounds handler +//------------------------------------------------- + +layout_view::item::bounds_delegate layout_view::item::default_get_bounds() +{ + return (m_bounds.size() == 1U) ? bounds_delegate(&emu::render::detail::bounds_step::get, &m_bounds.front()) : bounds_delegate(&item::get_interpolated_bounds, this); - m_get_color = (m_color.size() == 1U) +} + + +//------------------------------------------------- +// default_get_color - get default color handler +//------------------------------------------------- + +layout_view::item::color_delegate layout_view::item::default_get_color() +{ + return (m_color.size() == 1U) ? color_delegate(&emu::render::detail::color_step::get, &const_cast(m_color.front())) : color_delegate(&item::get_interpolated_color, this); } -//--------------------------------------------- +//------------------------------------------------- +// get_state - get state when no bindings +//------------------------------------------------- + +int layout_view::item::get_state() const +{ + return m_elem_state; +} + + +//------------------------------------------------- // get_output - get element state output -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_output() const { @@ -4578,9 +4700,9 @@ int layout_view::item::get_output() const } -//--------------------------------------------- +//------------------------------------------------- // get_input_raw - get element state input -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_input_raw() const { @@ -4589,9 +4711,9 @@ int layout_view::item::get_input_raw() const } -//--------------------------------------------- +//------------------------------------------------- // get_input_field_cached - element state -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_input_field_cached() const { @@ -4601,9 +4723,9 @@ int layout_view::item::get_input_field_cached() const } -//--------------------------------------------- +//------------------------------------------------- // get_input_field_conditional - element state -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_input_field_conditional() const { @@ -4614,9 +4736,9 @@ int layout_view::item::get_input_field_conditional() const } -//--------------------------------------------- +//------------------------------------------------- // get_anim_output - get animation output -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_anim_output() const { @@ -4625,9 +4747,9 @@ int layout_view::item::get_anim_output() const } -//--------------------------------------------- +//------------------------------------------------- // get_anim_input - get animation input -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_anim_input() const { @@ -4636,31 +4758,31 @@ int layout_view::item::get_anim_input() const } -//--------------------------------------------- +//------------------------------------------------- // get_interpolated_bounds - animated bounds -//--------------------------------------------- +//------------------------------------------------- -render_bounds layout_view::item::get_interpolated_bounds() const +void layout_view::item::get_interpolated_bounds(render_bounds &result) const { assert(m_bounds.size() > 1U); - return interpolate_bounds(m_bounds, m_get_anim_state()); + result = interpolate_bounds(m_bounds, m_get_anim_state()); } -//--------------------------------------------- +//------------------------------------------------- // get_interpolated_color - animated color -//--------------------------------------------- +//------------------------------------------------- -render_color layout_view::item::get_interpolated_color() const +void layout_view::item::get_interpolated_color(render_color &result) const { assert(m_color.size() > 1U); - return interpolate_color(m_color, m_get_anim_state()); + result = interpolate_color(m_color, m_get_anim_state()); } -//--------------------------------------------- +//------------------------------------------------- // find_element - find element definition -//--------------------------------------------- +//------------------------------------------------- layout_element *layout_view::item::find_element(view_environment &env, util::xml::data_node const &itemnode, element_map &elemmap) { @@ -4677,9 +4799,9 @@ layout_element *layout_view::item::find_element(view_environment &env, util::xml } -//--------------------------------------------- +//------------------------------------------------- // make_bounds - get transformed bounds -//--------------------------------------------- +//------------------------------------------------- layout_view::item::bounds_vector layout_view::item::make_bounds( view_environment &env, @@ -4710,9 +4832,9 @@ layout_view::item::bounds_vector layout_view::item::make_bounds( } -//--------------------------------------------- +//------------------------------------------------- // make_color - get color inflection points -//--------------------------------------------- +//------------------------------------------------- layout_view::item::color_vector layout_view::item::make_color( view_environment &env, @@ -4744,10 +4866,9 @@ layout_view::item::color_vector layout_view::item::make_color( } -//--------------------------------------------- -// make_animoutput_tag - get animation output -// tag -//--------------------------------------------- +//------------------------------------------------- +// make_animoutput_tag - get animation output tag +//------------------------------------------------- std::string layout_view::item::make_animoutput_tag(view_environment &env, util::xml::data_node const &itemnode) { @@ -4759,9 +4880,9 @@ std::string layout_view::item::make_animoutput_tag(view_environment &env, util:: } -//--------------------------------------------- +//------------------------------------------------- // make_animmask - get animation state mask -//--------------------------------------------- +//------------------------------------------------- ioport_value layout_view::item::make_animmask(view_environment &env, util::xml::data_node const &itemnode) { @@ -4770,10 +4891,10 @@ ioport_value layout_view::item::make_animmask(view_environment &env, util::xml:: } -//--------------------------------------------- +//------------------------------------------------- // make_animinput_tag - get absolute tag for // animation input -//--------------------------------------------- +//------------------------------------------------- std::string layout_view::item::make_animinput_tag(view_environment &env, util::xml::data_node const &itemnode) { @@ -4783,9 +4904,9 @@ std::string layout_view::item::make_animinput_tag(view_environment &env, util::x } -//--------------------------------------------- +//------------------------------------------------- // make_input_tag - get absolute input tag -//--------------------------------------------- +//------------------------------------------------- std::string layout_view::item::make_input_tag(view_environment &env, util::xml::data_node const &itemnode) { @@ -4794,9 +4915,9 @@ std::string layout_view::item::make_input_tag(view_environment &env, util::xml:: } -//--------------------------------------------- +//------------------------------------------------- // get_blend_mode - explicit or implicit blend -//--------------------------------------------- +//------------------------------------------------- int layout_view::item::get_blend_mode(view_environment &env, util::xml::data_node const &itemnode) { @@ -4826,9 +4947,9 @@ int layout_view::item::get_blend_mode(view_environment &env, util::xml::data_nod } -//--------------------------------------------- +//------------------------------------------------- // get_state_shift - shift to right-align LSB -//--------------------------------------------- +//------------------------------------------------- unsigned layout_view::item::get_state_shift(ioport_value mask) { @@ -4873,7 +4994,8 @@ layout_file::layout_file( util::xml::data_node const &rootnode, char const *searchpath, char const *dirname) - : m_elemmap() + : m_device(device) + , m_elemmap() , m_viewlist() { try @@ -4910,6 +5032,11 @@ layout_file::layout_file( osd_printf_warning("Error instantiating layout view %s: %s\n", env.get_attribute_string(*viewnode, "name", ""), err.what()); } } + + // load the content of the first script node + util::xml::data_node const *const scriptnode = mamelayoutnode->get_child("script"); + if (scriptnode) + emulator_info::layout_script_cb(*this, scriptnode->get_value()); } catch (layout_syntax_error const &err) { @@ -4928,6 +5055,31 @@ layout_file::~layout_file() } +//------------------------------------------------- +// resolve_tags - resolve tags +//------------------------------------------------- + +void layout_file::resolve_tags() +{ + for (layout_view &view : views()) + view.resolve_tags(); + + if (!m_resolve_tags.isnull()) + m_resolve_tags(); +} + + +//------------------------------------------------- +// set_resolve_tags_callback - set callback for +// additional tasks after resolving tags +//------------------------------------------------- + +void layout_file::set_resolve_tags_callback(resolve_tags_delegate &&handler) +{ + m_resolve_tags = std::move(handler); +} + + void layout_file::add_elements( environment &env, util::xml::data_node const &parentnode, diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp index 164f2c97fbc..f7b55c18229 100644 --- a/src/emu/romload.cpp +++ b/src/emu/romload.cpp @@ -411,7 +411,7 @@ void rom_load_manager::count_roms() m_romstotalsize = 0; /* loop over regions, then over files */ - for (device_t &device : device_iterator(machine().config().root_device())) + for (device_t &device : device_enumerator(machine().config().root_device())) for (region = rom_first_region(device); region != nullptr; region = rom_next_region(region)) for (rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom)) if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == device.system_bios()) @@ -1338,7 +1338,7 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list void rom_load_manager::process_region_list() { // loop until we hit the end - device_iterator deviter(machine().root_device()); + device_enumerator deviter(machine().root_device()); std::vector searchpath; for (device_t &device : deviter) { @@ -1436,7 +1436,7 @@ rom_load_manager::rom_load_manager(running_machine &machine) { // figure out which BIOS we are using std::map card_bios; - for (device_t &device : device_iterator(machine.config().root_device())) + for (device_t &device : device_enumerator(machine.config().root_device())) { device_slot_interface const *const slot(dynamic_cast(&device)); if (slot) diff --git a/src/emu/schedule.cpp b/src/emu/schedule.cpp index 410ca6e9b7d..28b98cdb91a 100644 --- a/src/emu/schedule.cpp +++ b/src/emu/schedule.cpp @@ -787,7 +787,7 @@ void device_scheduler::rebuild_execute_list() device_execute_interface **suspend_tailptr = &suspend_list; // iterate over all devices - for (device_execute_interface &exec : execute_interface_iterator(machine().root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(machine().root_device())) { // append to the appropriate list exec.m_nextexec = nullptr; diff --git a/src/emu/screen.cpp b/src/emu/screen.cpp index c265b14e31b..88e0dc00e8c 100644 --- a/src/emu/screen.cpp +++ b/src/emu/screen.cpp @@ -890,7 +890,7 @@ void screen_device::device_start() if (m_oldstyle_vblank_supplied) logerror("%s: Deprecated legacy Old Style screen configured (MCFG_SCREEN_VBLANK_TIME), please use MCFG_SCREEN_RAW_PARAMS instead.\n",this->tag()); - m_is_primary_screen = (this == screen_device_iterator(machine().root_device()).first()); + m_is_primary_screen = (this == screen_device_enumerator(machine().root_device()).first()); } diff --git a/src/emu/screen.h b/src/emu/screen.h index cf7ea4b7ede..d3f4ce418b1 100644 --- a/src/emu/screen.h +++ b/src/emu/screen.h @@ -550,7 +550,7 @@ private: DECLARE_DEVICE_TYPE(SCREEN, screen_device) // iterator helper -typedef device_type_iterator screen_device_iterator; +typedef device_type_enumerator screen_device_enumerator; /*! @defgroup Screen device configuration functions diff --git a/src/emu/softlist_dev.cpp b/src/emu/softlist_dev.cpp index e2842b315b4..a69f6ccab00 100644 --- a/src/emu/softlist_dev.cpp +++ b/src/emu/softlist_dev.cpp @@ -189,7 +189,7 @@ void software_list_device::release() software_list_device *software_list_device::find_by_name(const machine_config &config, const std::string &name) { // iterate over each device in the system and find a match - for (software_list_device &swlistdev : software_list_device_iterator(config.root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(config.root_device())) if (swlistdev.list_name() == name) return &swlistdev; return nullptr; @@ -205,7 +205,7 @@ software_list_device *software_list_device::find_by_name(const machine_config &c void software_list_device::display_matches(const machine_config &config, const char *interface, const std::string &name) { // check if there is at least one software list - software_list_device_iterator deviter(config.root_device()); + software_list_device_enumerator deviter(config.root_device()); if (deviter.first() != nullptr) osd_printf_error("\n\"%s\" approximately matches the following\n" "supported software items (best match first):\n\n", name.c_str()); @@ -361,7 +361,7 @@ device_image_interface *software_list_device::find_mountable_image(const machine if (mount != nullptr && strcmp(mount, "no") == 0) return nullptr; - for (device_image_interface &image : image_interface_iterator(mconfig.root_device())) + for (device_image_interface &image : image_interface_enumerator(mconfig.root_device())) { const char *interface = image.image_interface(); if (interface != nullptr && part.matches_interface(interface) && filter(image)) diff --git a/src/emu/softlist_dev.h b/src/emu/softlist_dev.h index f3d222d65d5..d6f7f078553 100644 --- a/src/emu/softlist_dev.h +++ b/src/emu/softlist_dev.h @@ -163,7 +163,7 @@ private: DECLARE_DEVICE_TYPE(SOFTWARE_LIST, software_list_device) // device type iterator -typedef device_type_iterator software_list_device_iterator; +typedef device_type_enumerator software_list_device_enumerator; #endif // MAME_EMU_SOFTLIST_DEV_H diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp index 139e6339089..95bc85bc4ae 100644 --- a/src/emu/sound.cpp +++ b/src/emu/sound.cpp @@ -1102,7 +1102,7 @@ sound_manager::sound_manager(running_machine &machine) : // count the mixers #if VERBOSE - mixer_interface_iterator iter(machine.root_device()); + mixer_interface_enumerator iter(machine.root_device()); VPRINTF(("total mixers = %d\n", iter.count())); #endif @@ -1199,7 +1199,7 @@ void sound_manager::set_attenuation(float attenuation) bool sound_manager::indexed_mixer_input(int index, mixer_input &info) const { // scan through the mixers until we find the indexed input - for (device_mixer_interface &mixer : mixer_interface_iterator(machine().root_device())) + for (device_mixer_interface &mixer : mixer_interface_enumerator(machine().root_device())) { if (index < mixer.inputs()) { @@ -1270,7 +1270,7 @@ void sound_manager::recursive_remove_stream_from_orphan_list(sound_stream *which void sound_manager::apply_sample_rate_changes() { // update sample rates if they have changed - for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + for (speaker_device &speaker : speaker_device_enumerator(machine().root_device())) { int stream_out; sound_stream *stream = speaker.output_to_stream_output(0, stream_out); @@ -1292,7 +1292,7 @@ void sound_manager::apply_sample_rate_changes() void sound_manager::reset() { // reset all the sound chips - for (device_sound_interface &sound : sound_interface_iterator(machine().root_device())) + for (device_sound_interface &sound : sound_interface_enumerator(machine().root_device())) sound.device().reset(); // apply any sample rate changes now @@ -1308,7 +1308,7 @@ void sound_manager::reset() m_orphan_stream_list[stream.get()] = 0; // then walk the graph like we do on update and remove any we touch - for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + for (speaker_device &speaker : speaker_device_enumerator(machine().root_device())) { int dummy; sound_stream *output = speaker.output_to_stream_output(0, dummy); @@ -1318,7 +1318,7 @@ void sound_manager::reset() #if (SOUND_DEBUG) // dump the sound graph when we start up - for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + for (speaker_device &speaker : speaker_device_enumerator(machine().root_device())) { int index; sound_stream *output = speaker.output_to_stream_output(0, index); @@ -1487,7 +1487,7 @@ void sound_manager::update(void *ptr, int param) std::fill_n(&m_rightmix[0], m_samples_this_update, 0); // force all the speaker streams to generate the proper number of samples - for (speaker_device &speaker : speaker_device_iterator(machine().root_device())) + for (speaker_device &speaker : speaker_device_enumerator(machine().root_device())) speaker.mix(&m_leftmix[0], &m_rightmix[0], m_last_update, endtime, m_samples_this_update, (m_muted & MUTE_REASON_SYSTEM)); // determine the maximum in this section diff --git a/src/emu/speaker.h b/src/emu/speaker.h index fd20c4b94b8..54aa00603c9 100644 --- a/src/emu/speaker.h +++ b/src/emu/speaker.h @@ -90,7 +90,7 @@ protected: // speaker device iterator -using speaker_device_iterator = device_type_iterator; +using speaker_device_enumerator = device_type_enumerator; #endif // MAME_EMU_SPEAKER_H diff --git a/src/emu/validity.cpp b/src/emu/validity.cpp index c8b5b52892c..c7363cf7b7a 100644 --- a/src/emu/validity.cpp +++ b/src/emu/validity.cpp @@ -1539,7 +1539,7 @@ void validity_checker::validate_driver(device_t &root) device_t::feature_type const imperfect(m_current_driver->type.imperfect_features()); if (!(m_current_driver->flags & (machine_flags::IS_BIOS_ROOT | machine_flags::NO_SOUND_HW)) && !(unemulated & device_t::feature::SOUND)) { - sound_interface_iterator iter(root); + sound_interface_enumerator iter(root); if (!iter.first()) osd_printf_error("Driver is missing MACHINE_NO_SOUND or MACHINE_NO_SOUND_HW flag\n"); } @@ -1563,7 +1563,7 @@ void validity_checker::validate_driver(device_t &root) void validity_checker::validate_roms(device_t &root) { // iterate, starting with the driver's ROMs and continuing with device ROMs - for (device_t &device : device_iterator(root)) + for (device_t &device : device_enumerator(root)) { // track the current device m_current_device = &device; @@ -1869,7 +1869,7 @@ void validity_checker::validate_condition(ioport_condition &condition, device_t void validity_checker::validate_inputs(device_t &root) { // iterate over devices - for (device_t &device : device_iterator(root)) + for (device_t &device : device_enumerator(root)) { // see if this device has ports; if not continue if (device.input_ports() == nullptr) @@ -2011,7 +2011,7 @@ void validity_checker::validate_devices(machine_config &config) { std::unordered_set device_map; - for (device_t &device : device_iterator(config.root_device())) + for (device_t &device : device_enumerator(config.root_device())) { // track the current device m_current_device = &device; @@ -2057,7 +2057,7 @@ void validity_checker::validate_devices(machine_config &config) additions(card); } - for (device_slot_interface &subslot : slot_interface_iterator(*card)) + for (device_slot_interface &subslot : slot_interface_enumerator(*card)) { if (subslot.fixed()) { @@ -2077,11 +2077,11 @@ void validity_checker::validate_devices(machine_config &config) } } - for (device_t &card_dev : device_iterator(*card)) + for (device_t &card_dev : device_enumerator(*card)) card_dev.config_complete(); validate_roms(*card); - for (device_t &card_dev : device_iterator(*card)) + for (device_t &card_dev : device_enumerator(*card)) { m_current_device = &card_dev; card_dev.findit(this); diff --git a/src/emu/video.cpp b/src/emu/video.cpp index 56d60ba1661..26b7fe1d2c2 100644 --- a/src/emu/video.cpp +++ b/src/emu/video.cpp @@ -115,7 +115,7 @@ video_manager::video_manager(running_machine &machine) // extract initial execution state from global configuration settings update_refresh_speed(); - const unsigned screen_count(screen_device_iterator(machine.root_device()).count()); + const unsigned screen_count(screen_device_enumerator(machine.root_device()).count()); const bool no_screens(!screen_count); // create a render target for snapshots @@ -263,7 +263,7 @@ void video_manager::frame_update(bool from_debugger) if (phase == machine_phase::RUNNING) { // reset partial updates if we're paused or if the debugger is active - screen_device *const screen = screen_device_iterator(machine().root_device()).first(); + screen_device *const screen = screen_device_enumerator(machine().root_device()).first(); bool const debugger_enabled = machine().debug_flags & DEBUG_FLAG_ENABLED; bool const within_instruction_hook = debugger_enabled && machine().debugger().within_instruction_hook(); if (screen && ((machine().paused() && machine().options().update_in_pause()) || from_debugger || within_instruction_hook)) @@ -304,7 +304,7 @@ std::string video_manager::speed_text() // display the number of partial updates as well int partials = 0; - for (screen_device &screen : screen_device_iterator(machine().root_device())) + for (screen_device &screen : screen_device_enumerator(machine().root_device())) partials += screen.partial_updates(); if (partials > 1) util::stream_format(str, "\n%d partial updates", partials); @@ -353,7 +353,7 @@ void video_manager::save_active_screen_snapshots() if (m_snap_native) { // write one snapshot per visible screen - for (screen_device &screen : screen_device_iterator(machine().root_device())) + for (screen_device &screen : screen_device_enumerator(machine().root_device())) if (machine().render().is_live(screen)) { emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); @@ -455,8 +455,8 @@ void video_manager::begin_recording_screen(const std::string &filename, uint32_t void video_manager::begin_recording(const char *name, movie_recording::format format) { // create a snapshot bitmap so we know what the target size is - screen_device_iterator iterator = screen_device_iterator(machine().root_device()); - screen_device_iterator::auto_iterator iter = iterator.begin(); + screen_device_enumerator iterator(machine().root_device()); + screen_device_enumerator::iterator iter(iterator.begin()); uint32_t count = (uint32_t)iterator.count(); const bool no_screens(!count); @@ -637,7 +637,7 @@ inline int video_manager::original_speed_setting() const bool video_manager::finish_screen_updates() { // finish updating the screens - screen_device_iterator iter(machine().root_device()); + screen_device_enumerator iter(machine().root_device()); bool has_live_screen = false; for (screen_device &screen : iter) @@ -953,7 +953,7 @@ void video_manager::update_refresh_speed() // find the screen with the shortest frame period (max refresh rate) // note that we first check the token since this can get called before all screens are created attoseconds_t min_frame_period = ATTOSECONDS_PER_SECOND; - for (screen_device &screen : screen_device_iterator(machine().root_device())) + for (screen_device &screen : screen_device_enumerator(machine().root_device())) { attoseconds_t period = screen.frame_period().attoseconds(); if (period != 0) @@ -1056,7 +1056,7 @@ void video_manager::create_snapshot_bitmap(screen_device *screen) // select the appropriate view in our dummy target if (m_snap_native && screen != nullptr) { - screen_device_iterator iter(machine().root_device()); + screen_device_enumerator iter(machine().root_device()); int view_index = iter.indexof(*screen); assert(view_index != -1); m_snap_target->set_view(view_index); @@ -1175,7 +1175,7 @@ osd_file::error video_manager::open_next(emu_file &file, const char *extension, //printf("check template: %s\n", snapdevname.c_str()); // verify that there is such a device for this system - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { // get the device name std::string tempdevname(image.brief_instance_name()); diff --git a/src/frontend/mame/audit.cpp b/src/frontend/mame/audit.cpp index 736d6f9bf2f..ce8e1368992 100644 --- a/src/frontend/mame/audit.cpp +++ b/src/frontend/mame/audit.cpp @@ -212,7 +212,7 @@ media_auditor::summary media_auditor::audit_media(const char *validation) // iterate over devices and regions std::vector searchpath; - for (device_t &device : device_iterator(m_enumerator.config()->root_device())) + for (device_t &device : device_enumerator(m_enumerator.config()->root_device())) { searchpath.clear(); @@ -400,7 +400,7 @@ media_auditor::summary media_auditor::audit_samples() std::size_t found = 0; // iterate over sample entries - for (samples_device &device : samples_device_iterator(m_enumerator.config()->root_device())) + for (samples_device &device : samples_device_enumerator(m_enumerator.config()->root_device())) { // by default we just search using the driver name std::string searchpath(m_enumerator.driver().name); diff --git a/src/frontend/mame/cheat.cpp b/src/frontend/mame/cheat.cpp index 39846db0099..be5e9da9191 100644 --- a/src/frontend/mame/cheat.cpp +++ b/src/frontend/mame/cheat.cpp @@ -1146,7 +1146,7 @@ void cheat_manager::reload() // load the cheat file, if it's a system that has a software list then try softlist_name/shortname.xml first, // if it fails to load then try to load via crc32 - basename/crc32.xml ( eg. 01234567.xml ) - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { if (image.exists()) { diff --git a/src/frontend/mame/clifront.cpp b/src/frontend/mame/clifront.cpp index 978227bade0..1e8a59453c7 100644 --- a/src/frontend/mame/clifront.cpp +++ b/src/frontend/mame/clifront.cpp @@ -514,7 +514,7 @@ void cli_frontend::listcrc(const std::vector &args) args, [] (device_t &root, char const *type, bool first) { - for (device_t const &device : device_iterator(root)) + for (device_t const &device : device_enumerator(root)) { for (tiny_rom_entry const *rom = device.rom_region(); rom && !ROMENTRY_ISEND(rom); ++rom) { @@ -548,7 +548,7 @@ void cli_frontend::listroms(const std::vector &args) // iterate through ROMs bool hasroms = false; - for (device_t const &device : device_iterator(root)) + for (device_t const &device : device_enumerator(root)) { for (const rom_entry *region = rom_first_region(device); region; region = rom_next_region(region)) { @@ -618,7 +618,7 @@ void cli_frontend::listsamples(const std::vector &args) while (drivlist.next()) { // see if we have samples - samples_device_iterator iter(drivlist.config()->root_device()); + samples_device_enumerator iter(drivlist.config()->root_device()); if (iter.count() == 0) continue; @@ -665,7 +665,7 @@ void cli_frontend::listdevices(const std::vector &args) // build a list of devices std::vector device_list; - for (device_t &device : device_iterator(drivlist.config()->root_device())) + for (device_t &device : device_enumerator(drivlist.config()->root_device())) device_list.push_back(&device); // sort them by tag @@ -747,7 +747,7 @@ void cli_frontend::listslots(const std::vector &args) { // iterate bool first = true; - for (const device_slot_interface &slot : slot_interface_iterator(drivlist.config()->root_device())) + for (const device_slot_interface &slot : slot_interface_enumerator(drivlist.config()->root_device())) { if (slot.fixed()) continue; @@ -815,7 +815,7 @@ void cli_frontend::listmedia(const std::vector &args) { // iterate bool first = true; - for (const device_image_interface &imagedev : image_interface_iterator(drivlist.config()->root_device())) + for (const device_image_interface &imagedev : image_interface_enumerator(drivlist.config()->root_device())) { if (!imagedev.user_loadable()) continue; @@ -1215,7 +1215,7 @@ void cli_frontend::listsoftware(const std::vector &args) args, [this, &list_map, &firstlist] (device_t &root, char const *type, bool first) { - for (software_list_device &swlistdev : software_list_device_iterator(root)) + for (software_list_device &swlistdev : software_list_device_enumerator(root)) { if (list_map.insert(swlistdev.list_name()).second) { @@ -1268,7 +1268,7 @@ void cli_frontend::verifysoftware(const std::vector &args) { matched++; - for (software_list_device &swlistdev : software_list_device_iterator(drivlist.config()->root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(drivlist.config()->root_device())) { if (swlistdev.is_original()) { @@ -1330,7 +1330,7 @@ void cli_frontend::getsoftlist(const std::vector &args) std::vector(), [this, gamename, &list_map, &firstlist] (device_t &root, char const *type, bool first) { - for (software_list_device &swlistdev : software_list_device_iterator(root)) + for (software_list_device &swlistdev : software_list_device_enumerator(root)) { if (core_strwildcmp(gamename, swlistdev.list_name().c_str()) == 0 && list_map.insert(swlistdev.list_name()).second) { @@ -1375,7 +1375,7 @@ void cli_frontend::verifysoftlist(const std::vector &args) while (drivlist.next()) { - for (software_list_device &swlistdev : software_list_device_iterator(drivlist.config()->root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(drivlist.config()->root_device())) { if (core_strwildcmp(gamename, swlistdev.list_name().c_str()) == 0 && list_map.insert(swlistdev.list_name()).second) { diff --git a/src/frontend/mame/infoxml.cpp b/src/frontend/mame/infoxml.cpp index 59b3a637aee..88d9e305b87 100644 --- a/src/frontend/mame/infoxml.cpp +++ b/src/frontend/mame/infoxml.cpp @@ -566,7 +566,7 @@ void output_footer(std::ostream &out) void output_one(std::ostream &out, driver_enumerator &drivlist, const game_driver &driver, device_type_set *devtypes) { machine_config config(driver, drivlist.options()); - device_iterator iter(config.root_device()); + device_enumerator iter(config.root_device()); // allocate input ports and build overall emulation status ioport_list portlist; @@ -685,7 +685,7 @@ void output_one_device(std::ostream &out, machine_config &config, device_t &devi { bool has_speaker = false, has_input = false; // check if the device adds speakers to the system - sound_interface_iterator snditer(device); + sound_interface_enumerator snditer(device); if (snditer.first() != nullptr) has_speaker = true; @@ -694,7 +694,7 @@ void output_one_device(std::ostream &out, machine_config &config, device_t &devi std::string errors; device_t::feature_type overall_unemulated(device.type().unemulated_features()); device_t::feature_type overall_imperfect(device.type().imperfect_features()); - for (device_t &dev : device_iterator(device)) + for (device_t &dev : device_enumerator(device)) { portlist.append(dev, errors); overall_unemulated |= dev.type().unemulated_features(); @@ -762,7 +762,7 @@ void output_devices(std::ostream &out, emu_options &lookup_options, device_type_ } // notify this device and all its subdevices that they are now configured - for (device_t &device : device_iterator(*dev)) + for (device_t &device : device_enumerator(*dev)) if (!device.configured()) device.config_complete(); @@ -791,7 +791,7 @@ void output_devices(std::ostream &out, emu_options &lookup_options, device_type_ void output_device_refs(std::ostream &out, device_t &root) { - for (device_t &device : device_iterator(root)) + for (device_t &device : device_enumerator(root)) if (&device != &root) out << util::string_format("\t\t\n", normalize_string(device.shortname())); } @@ -805,7 +805,7 @@ void output_device_refs(std::ostream &out, device_t &root) void output_sampleof(std::ostream &out, device_t &device) { // iterate over sample devices - for (samples_device &samples : samples_device_iterator(device)) + for (samples_device &samples : samples_device_enumerator(device)) { samples_iterator sampiter(samples); if (sampiter.altbasename() != nullptr) @@ -990,7 +990,7 @@ void output_rom(std::ostream &out, driver_enumerator *drivlist, const game_drive void output_sample(std::ostream &out, device_t &device) { // iterate over sample devices - for (samples_device &samples : samples_device_iterator(device)) + for (samples_device &samples : samples_device_enumerator(device)) { samples_iterator iter(samples); std::unordered_set already_printed; @@ -1015,7 +1015,7 @@ void output_sample(std::ostream &out, device_t &device) void output_chips(std::ostream &out, device_t &device, const char *root_tag) { // iterate over executable devices - for (device_execute_interface &exec : execute_interface_iterator(device)) + for (device_execute_interface &exec : execute_interface_enumerator(device)) { if (strcmp(exec.device().tag(), device.tag())) { @@ -1032,7 +1032,7 @@ void output_chips(std::ostream &out, device_t &device, const char *root_tag) } // iterate over sound devices - for (device_sound_interface &sound : sound_interface_iterator(device)) + for (device_sound_interface &sound : sound_interface_enumerator(device)) { if (strcmp(sound.device().tag(), device.tag()) != 0 && sound.issound()) { @@ -1059,7 +1059,7 @@ void output_chips(std::ostream &out, device_t &device, const char *root_tag) void output_display(std::ostream &out, device_t &device, machine_flags::type const *flags, const char *root_tag) { // iterate over screens - for (const screen_device &screendev : screen_device_iterator(device)) + for (const screen_device &screendev : screen_device_enumerator(device)) { if (strcmp(screendev.tag(), device.tag())) { @@ -1144,11 +1144,11 @@ void output_display(std::ostream &out, device_t &device, machine_flags::type con void output_sound(std::ostream &out, device_t &device) { - speaker_device_iterator spkiter(device); + speaker_device_enumerator spkiter(device); int speakers = spkiter.count(); // if we have no sound, zero m_output the speaker count - sound_interface_iterator snditer(device); + sound_interface_enumerator snditer(device); if (snditer.first() == nullptr) speakers = 0; @@ -1851,7 +1851,7 @@ void output_features(std::ostream &out, device_type type, device_t::feature_type void output_images(std::ostream &out, device_t &device, const char *root_tag) { - for (const device_image_interface &imagedev : image_interface_iterator(device)) + for (const device_image_interface &imagedev : image_interface_enumerator(device)) { if (strcmp(imagedev.device().tag(), device.tag())) { @@ -1912,7 +1912,7 @@ void output_images(std::ostream &out, device_t &device, const char *root_tag) void output_slots(std::ostream &out, machine_config &config, device_t &device, const char *root_tag, device_type_set *devtypes) { - for (device_slot_interface &slot : slot_interface_iterator(device)) + for (device_slot_interface &slot : slot_interface_enumerator(device)) { // shall we list fixed slots as non-configurable? bool const listed(!slot.fixed() && strcmp(slot.device().tag(), device.tag())); @@ -1936,7 +1936,7 @@ void output_slots(std::ostream &out, machine_config &config, device_t &device, c dev->config_complete(); if (devtypes) - for (device_t &subdevice : device_iterator(*dev)) devtypes->insert(&subdevice.type()); + for (device_t &subdevice : device_enumerator(*dev)) devtypes->insert(&subdevice.type()); if (listed && option.second->selectable()) { @@ -1965,7 +1965,7 @@ void output_slots(std::ostream &out, machine_config &config, device_t &device, c void output_software_lists(std::ostream &out, device_t &root, const char *root_tag) { - for (const software_list_device &swlist : software_list_device_iterator(root)) + for (const software_list_device &swlist : software_list_device_enumerator(root)) { if (&static_cast(swlist) == &root) { @@ -1992,7 +1992,7 @@ void output_software_lists(std::ostream &out, device_t &root, const char *root_t void output_ramoptions(std::ostream &out, device_t &root) { - for (const ram_device &ram : ram_device_iterator(root, 1)) + for (const ram_device &ram : ram_device_enumerator(root, 1)) { if (!std::strcmp(ram.tag(), ":" RAM_TAG)) { diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index 880ade2ab23..48ebc897899 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -37,24 +37,144 @@ //************************************************************************** extern "C" { - int luaopen_zlib(lua_State *L); - int luaopen_lfs(lua_State *L); - int luaopen_linenoise(lua_State *L); - int luaopen_lsqlite3(lua_State *L); -} + +int luaopen_zlib(lua_State *L); +int luaopen_lfs(lua_State *L); +int luaopen_linenoise(lua_State *L); +int luaopen_lsqlite3(lua_State *L); + +} // extern "C" + + +template +struct lua_engine::devenum +{ + devenum(device_t &d) : device(d), iter(d) { } + + device_t &device; + T iter; + int count = -1; +}; + namespace sol { - sol::buffer *sol_lua_get(sol::types, lua_State *L, int index, sol::stack::record &tracking) + +sol::buffer *sol_lua_get(sol::types, lua_State *L, int index, sol::stack::record &tracking) +{ + return new sol::buffer(stack::get(L, index), L); +} + +int sol_lua_push(sol::types, lua_State *L, buffer *value) +{ + delete value; + return 1; +} + +template +struct usertype_container > : lua_engine::immutable_container_helper, T> +{ +private: + using enumerator = lua_engine::devenum; + + template + static int next_pairs(lua_State *L) { - return new sol::buffer(stack::get(L, index), L); + typename usertype_container::indexed_iterator &i(stack::unqualified_get >(L, 1)); + if (i.src.end() == i.it) + return stack::push(L, lua_nil); + int result; + if constexpr (Indexed) + result = stack::push(L, i.ix + 1); + else + result = stack::push(L, i.it->tag()); + result += stack::push_reference(L, *i.it); + ++i; + return result; } - int sol_lua_push(sol::types, lua_State *L, buffer *value) + + template + static int start_pairs(lua_State *L) { - delete value; - return 1; + enumerator &self(usertype_container::get_self(L)); + stack::push(L, next_pairs); + stack::push >(L, self.iter, self.iter.begin()); + stack::push(L, lua_nil); + return 3; + } + +public: + static int at(lua_State *L) + { + enumerator &self(usertype_container::get_self(L)); + std::ptrdiff_t const index(stack::unqualified_get(L, 2)); + auto const dev(self.iter.byindex(index - 1)); + if (dev) + return stack::push_reference(L, *dev); + else + return stack::push(L, lua_nil); } -} + + static int get(lua_State *L) + { + enumerator &self(usertype_container::get_self(L)); + char const *const tag(stack::unqualified_get(L)); + device_t *const dev(self.device.subdevice(tag)); + if (dev) + { + auto *const check(T(*dev, 0).first()); + bool match; + if constexpr (std::is_base_of_v) + match = check && (static_cast(check) == dev); + else if constexpr (std::is_base_of_v) + match = check && (&check->device() == dev); + else + match = check && (dynamic_cast(check) == dev); + if (match) + return stack::push_reference(L, *check); + } + return stack::push(L, lua_nil); + } + + static int index_get(lua_State *L) + { + return get(L); + } + + static int index_of(lua_State *L) + { + enumerator &self(usertype_container::get_self(L)); + auto &dev(stack::unqualified_get(L, 2)); + std::ptrdiff_t found(self.iter.indexof(dev)); + if (0 > found) + return stack::push(L, lua_nil); + else + return stack::push(L, found + 1); + } + + static int size(lua_State *L) + { + enumerator &self(usertype_container::get_self(L)); + if (0 > self.count) + self.count = self.iter.count(); + return stack::push(L, self.count); + } + + static int empty(lua_State *L) + { + enumerator &self(usertype_container::get_self(L)); + if (0 > self.count) + self.count = self.iter.count(); + return stack::push(L, !self.count); + } + + static int next(lua_State *L) { return stack::push(L, next_pairs); } + static int pairs(lua_State *L) { return start_pairs(L); } + static int ipairs(lua_State *L) { return start_pairs(L); } +}; + +} // namespace sol + int sol_lua_push(sol::types, lua_State *L, osd_file::error &&value) { @@ -461,17 +581,23 @@ void lua_engine::initialize() * emu.print_error(str) - output to stderr at error level * emu.print_info(str) - output to stderr at info level * emu.print_debug(str) - output to stderr at debug level + * + * emu.device_enumerator(dev) - get device enumerator starting at arbitrary point in tree + * emu.screen_enumerator(dev) - get screen device enumerator starting at arbitrary point in tree + * emu.image_enumerator(dev) - get image interface enumerator starting at arbitrary point in tree */ sol::table emu = sol().create_named_table("emu"); emu["app_name"] = &emulator_info::get_appname_lower; emu["app_version"] = &emulator_info::get_bare_build_version; - emu["gamename"] = [this](){ return machine().system().type.fullname(); }; - emu["romname"] = [this](){ return machine().basename(); }; - emu["softname"] = [this]() { return machine().options().software_name(); }; - emu["keypost"] = [this](const char *keys){ machine().ioport().natkeyboard().post_utf8(keys); }; - emu["time"] = [this](){ return machine().time().as_double(); }; - emu["start"] = [this](const char *driver) { + emu["gamename"] = [this] () { return machine().system().type.fullname(); }; + emu["romname"] = [this] () { return machine().basename(); }; + emu["softname"] = [this] () { return machine().options().software_name(); }; + emu["keypost"] = [this] (const char *keys) { machine().ioport().natkeyboard().post_utf8(keys); }; + emu["time"] = [this] () { return machine().time().as_double(); }; + emu["start"] = + [this](const char *driver) + { int i = driver_list::find(driver); if (i != -1) { @@ -480,69 +606,86 @@ void lua_engine::initialize() } return 1; }; - emu["pause"] = [this](){ return machine().pause(); }; - emu["unpause"] = [this](){ return machine().resume(); }; - emu["step"] = [this]() { + emu["pause"] = [this] () { return machine().pause(); }; + emu["unpause"] = [this] () { return machine().resume(); }; + emu["step"] = + [this] () + { mame_machine_manager::instance()->ui().set_single_step(true); machine().resume(); }; - emu["register_prestart"] = [this](sol::function func){ register_function(func, "LUA_ON_PRESTART"); }; - emu["register_start"] = [this](sol::function func){ register_function(func, "LUA_ON_START"); }; - emu["register_stop"] = [this](sol::function func){ register_function(func, "LUA_ON_STOP"); }; - emu["register_pause"] = [this](sol::function func){ register_function(func, "LUA_ON_PAUSE"); }; - emu["register_resume"] = [this](sol::function func){ register_function(func, "LUA_ON_RESUME"); }; - emu["register_frame"] = [this](sol::function func){ register_function(func, "LUA_ON_FRAME"); }; - emu["register_frame_done"] = [this](sol::function func){ register_function(func, "LUA_ON_FRAME_DONE"); }; - emu["register_sound_update"] = [this](sol::function func){ register_function(func, "LUA_ON_SOUND_UPDATE"); }; - emu["register_periodic"] = [this](sol::function func){ register_function(func, "LUA_ON_PERIODIC"); }; - emu["register_mandatory_file_manager_override"] = [this](sol::function func) { register_function(func, "LUA_ON_MANDATORY_FILE_MANAGER_OVERRIDE"); }; + emu["register_prestart"] = [this] (sol::function func) { register_function(func, "LUA_ON_PRESTART"); }; + emu["register_start"] = [this] (sol::function func) { register_function(func, "LUA_ON_START"); }; + emu["register_stop"] = [this] (sol::function func) { register_function(func, "LUA_ON_STOP"); }; + emu["register_pause"] = [this] (sol::function func) { register_function(func, "LUA_ON_PAUSE"); }; + emu["register_resume"] = [this] (sol::function func) { register_function(func, "LUA_ON_RESUME"); }; + emu["register_frame"] = [this] (sol::function func) { register_function(func, "LUA_ON_FRAME"); }; + emu["register_frame_done"] = [this] (sol::function func) { register_function(func, "LUA_ON_FRAME_DONE"); }; + emu["register_sound_update"] = [this] (sol::function func) { register_function(func, "LUA_ON_SOUND_UPDATE"); }; + emu["register_periodic"] = [this] (sol::function func) { register_function(func, "LUA_ON_PERIODIC"); }; + emu["register_mandatory_file_manager_override"] = [this] (sol::function func) { register_function(func, "LUA_ON_MANDATORY_FILE_MANAGER_OVERRIDE"); }; emu["register_before_load_settings"] = [this](sol::function func) { register_function(func, "LUA_ON_BEFORE_LOAD_SETTINGS"); }; - emu["register_menu"] = [this](sol::function cb, sol::function pop, const std::string &name) { + emu["register_menu"] = + [this] (sol::function cb, sol::function pop, const std::string &name) + { std::string cbfield = "menu_cb_" + name; std::string popfield = "menu_pop_" + name; sol().registry()[cbfield] = cb; sol().registry()[popfield] = pop; m_menu.push_back(name); }; - emu["show_menu"] = [this](const char *name) { + emu["show_menu"] = + [this](const char *name) + { mame_ui_manager &mui = mame_machine_manager::instance()->ui(); render_container &container = machine().render().ui_container(); ui::menu_plugin::show_menu(mui, container, (char *)name); }; - emu["register_callback"] = [this](sol::function cb, const std::string &name) { + emu["register_callback"] = + [this] (sol::function cb, const std::string &name) + { std::string field = "cb_" + name; sol().registry()[field] = cb; }; - emu["print_verbose"] = [](const char *str) { osd_printf_verbose("%s\n", str); }; - emu["print_error"] = [](const char *str) { osd_printf_error("%s\n", str); }; - emu["print_info"] = [](const char *str) { osd_printf_info("%s\n", str); }; - emu["print_debug"] = [](const char *str) { osd_printf_debug("%s\n", str); }; - emu["driver_find"] = [this](const char *driver) -> sol::object { - int i = driver_list::find(driver); - if(i == -1) + emu["print_verbose"] = [] (const char *str) { osd_printf_verbose("%s\n", str); }; + emu["print_error"] = [] (const char *str) { osd_printf_error("%s\n", str); }; + emu["print_info"] = [] (const char *str) { osd_printf_info("%s\n", str); }; + emu["print_debug"] = [] (const char *str) { osd_printf_debug("%s\n", str); }; + emu["driver_find"] = + [this] (const char *driver) -> sol::object + { + const int i = driver_list::find(driver); + if (i < 0) return sol::make_object(sol(), sol::lua_nil); return sol::make_object(sol(), driver_list::driver(i)); }; - emu["wait"] = lua_CFunction([](lua_State *L) { - lua_engine *engine = mame_machine_manager::instance()->lua(); - luaL_argcheck(L, lua_isnumber(L, 1), 1, "waiting duration expected"); - int ret = lua_pushthread(L); - if(ret == 1) - return luaL_error(L, "cannot wait from outside coroutine"); - int ref = luaL_ref(L, LUA_REGISTRYINDEX); - engine->machine().scheduler().timer_set(attotime::from_double(lua_tonumber(L, 1)), timer_expired_delegate(FUNC(lua_engine::resume), engine), ref, nullptr); - return lua_yield(L, 0); - }); + emu["wait"] = lua_CFunction( + [](lua_State *L) + { + lua_engine *engine = mame_machine_manager::instance()->lua(); + luaL_argcheck(L, lua_isnumber(L, 1), 1, "waiting duration expected"); + int ret = lua_pushthread(L); + if (ret == 1) + return luaL_error(L, "cannot wait from outside coroutine"); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + engine->machine().scheduler().timer_set(attotime::from_double(lua_tonumber(L, 1)), timer_expired_delegate(FUNC(lua_engine::resume), engine), ref, nullptr); + return lua_yield(L, 0); + }); emu["lang_translate"] = &lang_translate; emu["pid"] = &osd_getpid; - emu["subst_env"] = [](const std::string &str) { + emu["subst_env"] = + [] (const std::string &str) + { std::string result; osd_subst_env(result, str); return result; }; + emu["device_enumerator"] = [] (device_t &d) { return devenum(d); }; + emu["screen_enumerator"] = [] (device_t &d) { return devenum(d); }; + emu["image_enumerator"] = [] (device_t &d) { return devenum(d); }; -/* emu_file library +/* emu_file library * * emu.file([opt] searchpath, flags) - flags can be as in osdcore "OPEN_FLAG_*" or lua style * with 'rwc' with addtional c for create *and truncate* @@ -820,7 +963,7 @@ void lua_engine::initialize() }); -/* core_options library +/* core_options library * * manager:options() * manager:machine():options() @@ -957,12 +1100,14 @@ void lua_engine::initialize() */ auto machine_type = sol().registry().new_usertype("machine", "new", sol::no_constructor); - machine_type.set("exit", &running_machine::schedule_exit); - machine_type.set("hard_reset", &running_machine::schedule_hard_reset); - machine_type.set("soft_reset", &running_machine::schedule_soft_reset); - machine_type.set("save", &running_machine::schedule_save); - machine_type.set("load", &running_machine::schedule_load); - machine_type.set("buffer_save", [](running_machine &m, sol::this_state s) { + machine_type["exit"] = &running_machine::schedule_exit; + machine_type["hard_reset"] = &running_machine::schedule_hard_reset; + machine_type["soft_reset"] = &running_machine::schedule_soft_reset; + machine_type["save"] = &running_machine::schedule_save; + machine_type["load"] = &running_machine::schedule_load; + machine_type["buffer_save"] = + [] (running_machine &m, sol::this_state s) + { lua_State *L = s; luaL_Buffer buff; int size = ram_state::get_size(m.save()); @@ -975,8 +1120,10 @@ void lua_engine::initialize() } luaL_error(L, "State save error."); return sol::make_reference(L, nullptr); - }); - machine_type.set("buffer_load", [](running_machine &m, sol::this_state s, std::string str) { + }; + machine_type["buffer_load"] = + [] (running_machine &m, sol::this_state s, std::string str) + { lua_State *L = s; save_error error = m.save().read_buffer((u8 *)str.data(), str.size()); if (error == STATERR_NONE) @@ -986,65 +1133,36 @@ void lua_engine::initialize() luaL_error(L,"State load error."); return false; } - }); - machine_type.set("system", &running_machine::system); - machine_type.set("video", &running_machine::video); - machine_type.set("sound", &running_machine::sound); - machine_type.set("render", &running_machine::render); - machine_type.set("ioport", &running_machine::ioport); - machine_type.set("parameters", &running_machine::parameters); - machine_type.set("memory", &running_machine::memory); - machine_type.set("options", [](running_machine &m) { return static_cast(&m.options()); }); - machine_type.set("outputs", &running_machine::output); - machine_type.set("input", &running_machine::input); - machine_type.set("uiinput", &running_machine::ui_input); - machine_type.set("debugger", [this](running_machine &m) -> sol::object { + }; + machine_type["system"] = &running_machine::system; + machine_type["video"] = &running_machine::video; + machine_type["sound"] = &running_machine::sound; + machine_type["render"] = &running_machine::render; + machine_type["ioport"] = &running_machine::ioport; + machine_type["parameters"] = &running_machine::parameters; + machine_type["memory"] = &running_machine::memory; + machine_type["options"] = [] (running_machine &m) { return static_cast(&m.options()); }; + machine_type["outputs"] = &running_machine::output; + machine_type["input"] = &running_machine::input; + machine_type["uiinput"] = &running_machine::ui_input; + machine_type["debugger"] = + [this] (running_machine &m) -> sol::object + { if(!(m.debug_flags & DEBUG_FLAG_ENABLED)) return sol::make_object(sol(), sol::lua_nil); return sol::make_object(sol(), &m.debugger()); - }); - machine_type.set("paused", sol::property(&running_machine::paused)); - machine_type.set("samplerate", sol::property(&running_machine::sample_rate)); - machine_type.set("exit_pending", sol::property(&running_machine::exit_pending)); - machine_type.set("hard_reset_pending", sol::property(&running_machine::hard_reset_pending)); - machine_type.set("devices", sol::property([this](running_machine &m) { - std::function tree; - sol::table table = sol().create_table(); - tree = [&tree](device_t &root, sol::table table) { - for(device_t &dev : root.subdevices()) - { - if(dev.configured() && dev.started()) - { - table[dev.tag()] = &dev; - tree(dev, table); - } - } - }; - tree(m.root_device(), table); - return table; - })); - machine_type.set("screens", sol::property([this](running_machine &r) { - sol::table table = sol().create_table(); - for (screen_device &sc : screen_device_iterator(r.root_device())) - { - if (sc.configured() && sc.started() && sc.type()) - table[sc.tag()] = ≻ - } - return table; - })); - machine_type.set("images", sol::property([this](running_machine &r) { - sol::table image_table = sol().create_table(); - for(device_image_interface &image : image_interface_iterator(r.root_device())) - { - image_table[image.brief_instance_name()] = ℑ - image_table[image.instance_name()] = ℑ - } - return image_table; - })); - machine_type.set("popmessage", sol::overload( + }; + machine_type["paused"] = sol::property(&running_machine::paused); + machine_type["samplerate"] = sol::property(&running_machine::sample_rate); + machine_type["exit_pending"] = sol::property(&running_machine::exit_pending); + machine_type["hard_reset_pending"] = sol::property(&running_machine::hard_reset_pending); + machine_type["devices"] = sol::property([] (running_machine &m) { return devenum(m.root_device()); }); + machine_type["screens"] = sol::property([] (running_machine &m) { return devenum(m.root_device()); }); + machine_type["images"] = sol::property([] (running_machine &m) { return devenum(m.root_device()); }); + machine_type["popmessage"] = sol::overload( [](running_machine &m, const char *str) { m.popmessage("%s", str); }, - [](running_machine &m) { m.popmessage(); })); - machine_type.set("logerror", [](running_machine &m, const char *str) { m.logerror("[luaengine] %s\n", str); } ); + [](running_machine &m) { m.popmessage(); }); + machine_type["logerror"] = [] (running_machine &m, const char *str) { m.logerror("[luaengine] %s\n", str); }; /* game_driver library @@ -1270,6 +1388,8 @@ void lua_engine::initialize() * device:owner() - device parent tag * device:debug() - debug interface, cpus only * + * device.configured - whether configuration is complete + * device.started - whether the device has been started * device.spaces[] - device address spaces table (k=name, v=addr_space) * device.state[] - device state entries table (k=name, v=device_state_entry) * device.items[] - device save state items table (k=name, v=index) @@ -1277,65 +1397,77 @@ void lua_engine::initialize() */ auto device_type = sol().registry().new_usertype("device", "new", sol::no_constructor); - device_type.set("name", &device_t::name); - device_type.set("shortname", &device_t::shortname); - device_type.set("tag", &device_t::tag); - device_type.set("owner", &device_t::owner); - device_type.set("debug", [this](device_t &dev) -> sol::object { - if(!(dev.machine().debug_flags & DEBUG_FLAG_ENABLED) || !dynamic_cast(&dev)) // debugger not enabled or not cpu + device_type["name"] = &device_t::name; + device_type["shortname"] = &device_t::shortname; + device_type["tag"] = &device_t::tag; + device_type["owner"] = &device_t::owner; + device_type["debug"] = + [this] (device_t &dev) -> sol::object + { + if (!(dev.machine().debug_flags & DEBUG_FLAG_ENABLED) || !dynamic_cast(&dev)) // debugger not enabled or not cpu return sol::make_object(sol(), sol::lua_nil); return sol::make_object(sol(), dev.debug()); - }); - device_type.set("spaces", sol::property([this](device_t &dev) { - device_memory_interface *memdev = dynamic_cast(&dev); - sol::table sp_table = sol().create_table(); - if(!memdev) + }; + device_type["configured"] = sol::property(&device_t::configured); + device_type["started"] = sol::property(&device_t::started); + device_type["spaces"] = sol::property( + [this] (device_t &dev) + { + device_memory_interface *memdev = dynamic_cast(&dev); + sol::table sp_table = sol().create_table(); + if(!memdev) + return sp_table; + for(int sp = 0; sp < memdev->max_space_count(); ++sp) + { + if(memdev->has_space(sp)) + sp_table[memdev->space(sp).name()] = addr_space(memdev->space(sp), *memdev); + } return sp_table; - for(int sp = 0; sp < memdev->max_space_count(); ++sp) + }); + device_type["state"] = sol::property( + [this] (device_t &dev) { - if(memdev->has_space(sp)) - sp_table[memdev->space(sp).name()] = addr_space(memdev->space(sp), *memdev); - } - return sp_table; - })); - device_type.set("state", sol::property([this](device_t &dev) { - sol::table st_table = sol().create_table(); - if(!dynamic_cast(&dev)) + sol::table st_table = sol().create_table(); + if(!dynamic_cast(&dev)) + return st_table; + // XXX: refrain from exporting non-visible entries? + for(auto &s : dev.state().state_entries()) + st_table[s->symbol()] = s.get(); return st_table; - // XXX: refrain from exporting non-visible entries? - for(auto &s : dev.state().state_entries()) - st_table[s->symbol()] = s.get(); - return st_table; - })); - device_type.set("items", sol::property([this](device_t &dev) { - sol::table table = sol().create_table(); - std::string tag = dev.tag(); - // 10000 is enough? - for(int i = 0; i < 10000; i++) + }); + device_type["items"] = sol::property( + [this] (device_t &dev) { - std::string name; - const char *item; - void *base; - uint32_t size, valcount, blockcount, stride; - item = dev.machine().save().indexed_item(i, base, size, valcount, blockcount, stride); - if(!item) - break; - name = &(strchr(item, '/')[1]); - if(name.substr(0, name.find('/')) == tag) + sol::table table = sol().create_table(); + std::string tag = dev.tag(); + // 10000 is enough? + for(int i = 0; i < 10000; i++) { - name = name.substr(name.find('/') + 1, std::string::npos); - table[name] = i; + std::string name; + const char *item; + void *base; + uint32_t size, valcount, blockcount, stride; + item = dev.machine().save().indexed_item(i, base, size, valcount, blockcount, stride); + if(!item) + break; + name = &(strchr(item, '/')[1]); + if(name.substr(0, name.find('/')) == tag) + { + name = name.substr(name.find('/') + 1, std::string::npos); + table[name] = i; + } } - } - return table; - })); - device_type.set("roms", sol::property([this](device_t &dev) { - sol::table table = sol().create_table(); - for(auto rom : dev.rom_region_vector()) - if(!rom.name().empty()) - table[rom.name()] = rom; - return table; - })); + return table; + }); + device_type["roms"] = sol::property( + [this] (device_t &dev) + { + sol::table table = sol().create_table(); + for(auto rom : dev.rom_region_vector()) + if(!rom.name().empty()) + table[rom.name()] = rom; + return table; + }); /* parameters_manager library @@ -1346,9 +1478,9 @@ void lua_engine::initialize() * parameters:lookup(tag) - get val for tag */ - sol().registry().new_usertype("parameters", "new", sol::no_constructor, - "add", ¶meters_manager::add, - "lookup", ¶meters_manager::lookup); + auto parameters_type = sol().registry().new_usertype("parameters", "new", sol::no_constructor); + parameters_type["add"] = ¶meters_manager::add; + parameters_type["lookup"] = ¶meters_manager::lookup; /* video_manager library @@ -1881,16 +2013,3 @@ void lua_engine::load_string(const char *value) { run(sol().load(value)); } - -//------------------------------------------------- -// invoke - invokes a function, wrapping profiler -//------------------------------------------------- - -template -sol::protected_function_result lua_engine::invoke(TFunc &&func, TArgs&&... args) -{ - g_profiler.start(PROFILER_LUA); - sol::protected_function_result result = func(std::forward(args)...); - g_profiler.stop(); - return result; -} diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index ed871d53287..3053de34b7d 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -33,6 +33,10 @@ struct lua_State; class lua_engine { public: + // helper structures + template struct devenum; + template struct immutable_container_helper; + // construction/destruction lua_engine(); ~lua_engine(); @@ -55,12 +59,12 @@ public: bool on_missing_mandatory_image(const std::string &instance_name); void on_machine_before_load_settings(); - template - bool call_plugin(const std::string &name, const T in, U &out) + template + bool call_plugin(const std::string &name, T &&in, U &out) { bool ret = false; - sol::object outobj = call_plugin(name, sol::make_object(sol(), in)); - if(outobj.is()) + sol::object outobj = call_plugin(name, sol::make_object(sol(), std::forward(in))); + if (outobj.is()) { out = outobj.as(); ret = true; @@ -68,16 +72,16 @@ public: return ret; } - template - bool call_plugin(const std::string &name, const T in, std::vector &out) + template + bool call_plugin(const std::string &name, T &&in, std::vector &out) { bool ret = false; - sol::object outobj = call_plugin(name, sol::make_object(sol(), in)); - if(outobj.is()) + sol::object outobj = call_plugin(name, sol::make_object(sol(), std::forward(in))); + if (outobj.is()) { - for(auto &entry : outobj.as()) + for (auto &entry : outobj.as()) { - if(entry.second.template is()) + if (entry.second.template is()) { out.push_back(entry.second.template as()); ret = true; @@ -88,26 +92,26 @@ public: } // this can also check if a returned table contains type T - template - bool call_plugin_check(const std::string &name, const U in, bool table = false) + template + bool call_plugin_check(const std::string &name, U &&in, bool table = false) { bool ret = false; - sol::object outobj = call_plugin(name, sol::make_object(sol(), in)); - if(outobj.is() && !table) + sol::object outobj = call_plugin(name, sol::make_object(sol(), std::forward(in))); + if (outobj.is() && !table) ret = true; - else if(outobj.is() && table) + else if (outobj.is() && table) { // check just one entry, checking the whole thing shouldn't be necessary as this only supports homogeneous tables - if(outobj.as().begin().operator*().second.template is()) + if (outobj.as().begin().operator*().second.template is()) ret = true; } return ret; } - template - void call_plugin_set(const std::string &name, const T in) + template + void call_plugin_set(const std::string &name, T &&in) { - call_plugin(name, sol::make_object(sol(), in)); + call_plugin(name, sol::make_object(sol(), std::forward(in))); } sol::state_view &sol() const { return *m_sol_state; } diff --git a/src/frontend/mame/luaengine.ipp b/src/frontend/mame/luaengine.ipp index cb6824dd262..78652d557e6 100644 --- a/src/frontend/mame/luaengine.ipp +++ b/src/frontend/mame/luaengine.ipp @@ -59,21 +59,98 @@ private: // don't convert core_optons to a table directly -template<> struct is_container : std::false_type { }; +template <> struct is_container : std::false_type { }; +// buffer customisation sol::buffer *sol_lua_get(sol::types, lua_State *L, int index, sol::stack::record &tracking); int sol_lua_push(sol::types, lua_State *L, buffer *value); +// lua_engine::devenum customisation +template struct is_container > : std::true_type { }; +template struct usertype_container >; + } // namespace sol +// osd_file::error customisation int sol_lua_push(sol::types, lua_State *L, osd_file::error &&value); template bool sol_lua_check(sol::types, lua_State *L, int index, Handler &&handler, sol::stack::record &tracking); +// map_handler_type customisation int sol_lua_push(sol::types, lua_State *L, map_handler_type &&value); +template +struct lua_engine::immutable_container_helper +{ +protected: + using iterator = I; + + static T &get_self(lua_State *L) + { + auto p(sol::stack::unqualified_check_get(L, 1)); + if (!p) + luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", sol::detail::demangle().c_str()); + if (!p.value()) + luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument with ':' or call on a '%s' type", sol::detail::demangle().c_str()); + return *p.value(); + } + + struct indexed_iterator + { + indexed_iterator(C &s, iterator i) : src(s), it(i), ix(0U) { } + + C &src; + iterator it; + std::size_t ix; + + indexed_iterator &operator++() + { + ++it; + ++ix; + return *this; + } + }; + +public: + static int set(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'set(key, value)' on type '%s': container is not modifiable", sol::detail::demangle().c_str()); + } + + static int index_set(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'container[key] = value' on type '%s': container is not modifiable", sol::detail::demangle().c_str()); + } + + static int add(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'add' on type '%s': container is not modifiable", sol::detail::demangle().c_str()); + } + + static int insert(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'insert' on type '%s': container is not modifiable", sol::detail::demangle().c_str()); + } + + static int find(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'find' on type '%s': no supported comparison operator for the value type", sol::detail::demangle().c_str()); + } + + static int clear(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'clear' on type '%s': container is not modifiable", sol::detail::demangle().c_str()); + } + + static int erase(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'erase' on type '%s': container is not modifiable", sol::detail::demangle().c_str()); + } +}; + + struct lua_engine::addr_space { addr_space(address_space &s, device_memory_interface &d) : space(s), dev(d) { } @@ -90,7 +167,7 @@ struct lua_engine::addr_space }; -template +template class lua_engine::enum_parser { public: @@ -121,4 +198,18 @@ private: std::array, SIZE> m_map; }; + +//------------------------------------------------- +// invoke - invokes a function, wrapping profiler +//------------------------------------------------- + +template +inline sol::protected_function_result lua_engine::invoke(TFunc &&func, TArgs &&... args) +{ + g_profiler.start(PROFILER_LUA); + sol::protected_function_result result = func(std::forward(args)...); + g_profiler.stop(); + return result; +} + #endif // MAME_FRONTEND_MAME_LUAENGINE_IPP diff --git a/src/frontend/mame/luaengine_render.cpp b/src/frontend/mame/luaengine_render.cpp index 01fdbe9add9..94945ad0bf1 100644 --- a/src/frontend/mame/luaengine_render.cpp +++ b/src/frontend/mame/luaengine_render.cpp @@ -1,8 +1,8 @@ // license:BSD-3-Clause -// copyright-holders:Miodrag Milanovic,Luca Bruno +// copyright-holders:Vas Crabb /*************************************************************************** - luaengine_input.cpp + luaengine_render.cpp Controls execution of the core MAME system. @@ -13,6 +13,304 @@ #include "render.h" +#include + + +namespace { + +struct layout_file_views +{ + layout_file_views(layout_file &f) : file(f) { } + + layout_file &file; +}; + + +struct layout_view_items +{ + layout_view_items(layout_view &v) : view(v) { } + + layout_view &view; +}; + + +struct render_manager_targets +{ + render_manager_targets(render_manager &m) : targets(m.targets()) { } + + simple_list const &targets; +}; + +} // anonymous namespace + +namespace sol { + +template <> struct is_container : std::true_type { }; +template <> struct is_container : std::true_type { }; +template <> struct is_container : std::true_type { }; + + +template <> +struct usertype_container : lua_engine::immutable_container_helper +{ +private: + using view_list = layout_file::view_list; + + template + static int next_pairs(lua_State *L) + { + indexed_iterator &i(stack::unqualified_get >(L, 1)); + if (i.src.end() == i.it) + return stack::push(L, lua_nil); + int result; + if constexpr (Indexed) + result = stack::push(L, i.ix + 1); + else + result = stack::push_reference(L, i.it->unqualified_name()); + result += stack::push_reference(L, *i.it); + ++i; + return result; + } + + template + static int start_pairs(lua_State *L) + { + layout_file_views &self(get_self(L)); + stack::push(L, next_pairs); + stack::push >(L, self.file.views(), self.file.views().begin()); + stack::push(L, lua_nil); + return 3; + } + +public: + static int at(lua_State *L) + { + layout_file_views &self(get_self(L)); + std::ptrdiff_t const index(stack::unqualified_get(L, 2)); + if ((0 >= index) || (self.file.views().size() < index)) + return stack::push(L, lua_nil); + else + return stack::push_reference(L, *std::next(self.file.views().begin(), index - 1)); + } + + static int get(lua_State *L) + { + layout_file_views &self(get_self(L)); + char const *const name(stack::unqualified_get(L)); + auto const found(std::find_if( + self.file.views().begin(), + self.file.views().end(), + [&name] (layout_view &v) { return v.unqualified_name() == name; })); + if (self.file.views().end() != found) + return stack::push_reference(L, *found); + else + return stack::push(L, lua_nil); + } + + static int index_get(lua_State *L) + { + return get(L); + } + + static int index_of(lua_State *L) + { + layout_file_views &self(get_self(L)); + layout_view &view(stack::unqualified_get(L, 2)); + auto it(self.file.views().begin()); + std::ptrdiff_t ix(0); + while ((self.file.views().end() != it) && (&view != &*it)) + { + ++it; + ++ix; + } + if (self.file.views().end() == it) + return stack::push(L, lua_nil); + else + return stack::push(L, ix + 1); + } + + static int size(lua_State *L) + { + layout_file_views &self(get_self(L)); + return stack::push(L, self.file.views().size()); + } + + static int empty(lua_State *L) + { + layout_file_views &self(get_self(L)); + return stack::push(L, self.file.views().empty()); + } + + static int next(lua_State *L) { return stack::push(L, next_pairs); } + static int pairs(lua_State *L) { return start_pairs(L); } + static int ipairs(lua_State *L) { return start_pairs(L); } +}; + + +template <> +struct usertype_container : lua_engine::immutable_container_helper +{ +private: + using item_list = layout_view::item_list; + + static int next_pairs(lua_State *L) + { + indexed_iterator &i(stack::unqualified_get >(L, 1)); + if (i.src.end() == i.it) + return stack::push(L, lua_nil); + int result; + result = stack::push(L, i.ix + 1); + result += stack::push_reference(L, *i.it); + ++i.it; + ++i.ix; + return result; + } + +public: + static int at(lua_State *L) + { + layout_view_items &self(get_self(L)); + std::ptrdiff_t const index(stack::unqualified_get(L, 2)); + if ((0 >= index) || (self.view.items().size() < index)) + return stack::push(L, lua_nil); + else + return stack::push_reference(L, *std::next(self.view.items().begin(), index - 1)); + } + + static int get(lua_State *L) + { + layout_view_items &self(get_self(L)); + char const *const id(stack::unqualified_get(L)); + layout_view::item *const item(self.view.get_item(id)); + if (item) + return stack::push_reference(L, *item); + else + return stack::push(L, lua_nil); + } + + static int index_get(lua_State *L) + { + return get(L); + } + + static int index_of(lua_State *L) + { + layout_view_items &self(get_self(L)); + layout_view::item &item(stack::unqualified_get(L, 2)); + auto it(self.view.items().begin()); + std::ptrdiff_t ix(0); + while ((self.view.items().end() != it) && (&item != &*it)) + { + ++it; + ++ix; + } + if (self.view.items().end() == it) + return stack::push(L, lua_nil); + else + return stack::push(L, ix + 1); + } + + static int size(lua_State *L) + { + layout_view_items &self(get_self(L)); + return stack::push(L, self.view.items().size()); + } + + static int empty(lua_State *L) + { + layout_view_items &self(get_self(L)); + return stack::push(L, self.view.items().empty()); + } + + static int next(lua_State *L) { return stack::push(L, next_pairs); } + + static int pairs(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'pairs' on type '%s': not iterable by ID", sol::detail::demangle().c_str()); + } + + static int ipairs(lua_State *L) + { + layout_view_items &self(get_self(L)); + stack::push(L, next_pairs); + stack::push >(L, self.view.items(), self.view.items().begin()); + stack::push(L, lua_nil); + return 3; + } +}; + + +template <> +struct usertype_container : lua_engine::immutable_container_helper const, simple_list::auto_iterator> +{ +private: + using target_list = simple_list; + + static int next_pairs(lua_State *L) + { + indexed_iterator &i(stack::unqualified_get >(L, 1)); + if (i.src.end() == i.it) + return stack::push(L, lua_nil); + int result; + result = stack::push(L, i.ix + 1); + result += stack::push_reference(L, *i.it); + ++i.it; + ++i.ix; + return result; + } + +public: + static int at(lua_State *L) + { + render_manager_targets &self(get_self(L)); + std::ptrdiff_t const index(stack::unqualified_get(L, 2)); + if ((0 >= index) || (self.targets.count() < index)) + return stack::push(L, lua_nil); + else + return stack::push_reference(L, *self.targets.find(index - 1)); + } + + static int get(lua_State *L) { return at(L); } + static int index_get(lua_State *L) { return at(L); } + + static int index_of(lua_State *L) + { + render_manager_targets &self(get_self(L)); + render_target &target(stack::unqualified_get(L, 2)); + int const found(self.targets.indexof(target)); + if (0 > found) + return stack::push(L, lua_nil); + else + return stack::push(L, found + 1); + } + + static int size(lua_State *L) + { + render_manager_targets &self(get_self(L)); + return stack::push(L, self.targets.count()); + } + + static int empty(lua_State *L) + { + render_manager_targets &self(get_self(L)); + return stack::push(L, self.targets.empty()); + } + + static int next(lua_State *L) { return stack::push(L, next_pairs); } + static int pairs(lua_State *L) { return ipairs(L); } + + static int ipairs(lua_State *L) + { + render_manager_targets &self(get_self(L)); + stack::push(L, next_pairs); + stack::push >(L, self.targets, self.targets.begin()); + stack::push(L, lua_nil); + return 3; + } +}; + +} // namespace sol + //------------------------------------------------- // initialize_render - register render user types @@ -21,12 +319,271 @@ void lua_engine::initialize_render() { +/* render_bounds library + * + * bounds:includes(x, y) - returns true if point is within bounds + * bounds:set_xy(left, top, right, bottom) - set bounds + * bounds:set_wh(left, top, width, height) - set bounds + * + * bounds.x0 - leftmost X coordinate + * bounds.y0 - topmost Y coordinate + * bounds.x1 - rightmost X coordinate + * bounds.y1 - bottommost Y coordinate + * bounds.width - get/set width + * bounds.height - get/set height + * bounds.aspect - read-only aspect ratio width:height + */ + auto bounds_type = sol().registry().new_usertype("bounds", sol::call_constructor, sol::initializers( + [] (render_bounds &b) { new (&b) render_bounds{ 0.0F, 0.0F, 1.0F, 1.0F }; }, + [] (render_bounds &b, float x0, float y0, float x1, float y1) { new (&b) render_bounds{ x0, y0, x1, y1 }; })); + bounds_type["includes"] = &render_bounds::includes; + bounds_type["set_xy"] = &render_bounds::includes; + bounds_type["set_wh"] = &render_bounds::includes; + bounds_type["x0"] = &render_bounds::x0; + bounds_type["y0"] = &render_bounds::y0; + bounds_type["x1"] = &render_bounds::x1; + bounds_type["y1"] = &render_bounds::y1; + bounds_type["width"] = sol::property(&render_bounds::width, [] (render_bounds &b, float w) { b.x1 = b.x0 + w; }); + bounds_type["height"] = sol::property(&render_bounds::height, [] (render_bounds &b, float h) { b.y1 = b.y0 + h; }); + bounds_type["aspect"] = sol::property(&render_bounds::aspect); + + +/* render_color library + * + * set(a, r, g, b) - set color + * + * color.a - alpha channel + * color.r - red channel + * color.g - green channel + * color.b - blue channel + */ + auto color_type = sol().registry().new_usertype("color", sol::call_constructor, sol::initializers( + [] (render_color &c) { new (&c) render_color{ 1.0F, 1.0F, 1.0F, 1.0F }; }, + [] (render_color &c, float a, float r, float g, float b) { new (&c) render_color{ a, r, g, b }; })); + color_type["set"] = &render_color::set; + color_type["a"] = &render_color::a; + color_type["r"] = &render_color::r; + color_type["g"] = &render_color::g; + color_type["b"] = &render_color::b; + + +/* layout_view library + * + * manager:machine():render().targets[target_index]:current_view() + * + * view:has_screen(screen) - returns whether a given screen is present in the view (including hidden screens) + * + * view.items - get the items in the view (including hidden items) + * view.name - display name for the view + * view.unqualified_name - name of the view as specified in the layout file + * view.visible_screen_count - number of screens items currently enabled + * view.effective_aspect - effective aspect ratio in current configuration + * view.bounds - effective bounds in current configuration + * view.has_art - true if the view has non-screen items + */ + + auto layout_view_type = sol().registry().new_usertype("layout_view", sol::no_constructor); + layout_view_type["has_screen"] = &layout_view::has_screen; + layout_view_type["items"] = sol::property([] (layout_view &v) { return layout_view_items(v); }); + layout_view_type["name"] = sol::property(&layout_view::name); + layout_view_type["unqualified_name"] = sol::property(&layout_view::unqualified_name); + layout_view_type["visible_screen_count"] = sol::property(&layout_view::visible_screen_count); + layout_view_type["effective_aspect"] = sol::property(&layout_view::effective_aspect); + layout_view_type["bounds"] = sol::property(&layout_view::bounds); + layout_view_type["has_art"] = sol::property(&layout_view::has_art); + + +/* layout_view::item library + * + * item:set_state(state) - set state value used in absence of bindings + * item.set_element_state_callback(cb) - set callback to obtain element state + * item.set_animation_state_callback(cb) - set callback to obtain animation state + * item.set_bounds_callback(cb) - set callback to obtain item bounds + * item.set_color_callback(cb) - set callback to obtain item color + * + * item.id - get optional item identifier + * item.bounds_animated - true if bounds depend on state + * item.color_animated - true if color depends on state + * item.bounds - get bounds for current state + * item.color - get color for current state + * item.blend_mode - get blend mode or -1 + * item.orientation - get item orientation + * item.element_state - get effective element state + * item.animation_state - get effective animation state + */ + + auto layout_view_item_type = sol().registry().new_usertype("layout_item", sol::no_constructor); + layout_view_item_type["set_state"] = &layout_view::item::set_state; + layout_view_item_type["set_element_state_callback"] = + [this] (layout_view::item &i, sol::object cb) + { + if (cb == sol::lua_nil) + { + i.set_element_state_callback(layout_view::item::state_delegate()); + } + else if (cb.is()) + { + i.set_element_state_callback(layout_view::item::state_delegate( + [this, cbfunc = cb.as()] () -> int + { + sol::optional result(invoke(cbfunc)); + if (result) + { + return result.value(); + } + else + { + osd_printf_error("[LUA ERROR] invalid return from element state callback\n"); + return 0; + } + })); + } + else + { + osd_printf_error("[LUA ERROR] must call set_element_state_callback with function or nil\n"); + } + }; + layout_view_item_type["set_animation_state_callback"] = + [this] (layout_view::item &i, sol::object cb) + { + if (cb == sol::lua_nil) + { + i.set_animation_state_callback(layout_view::item::state_delegate()); + } + else if (cb.is()) + { + i.set_animation_state_callback(layout_view::item::state_delegate( + [this, cbfunc = cb.as()] () -> int + { + sol::optional result(invoke(cbfunc)); + if (result) + { + return result.value(); + } + else + { + osd_printf_error("[LUA ERROR] invalid return from animation state callback\n"); + return 0; + } + })); + } + else + { + osd_printf_error("[LUA ERROR] must call set_animation_state_callback with function or nil\n"); + } + }; + layout_view_item_type["set_bounds_callback"] = + [this] (layout_view::item &i, sol::object cb) + { + if (cb == sol::lua_nil) + { + i.set_bounds_callback(layout_view::item::bounds_delegate()); + } + else if (cb.is()) + { + i.set_bounds_callback(layout_view::item::bounds_delegate( + [this, cbfunc = cb.as()] (render_bounds &b) + { + sol::optional result(invoke(cbfunc)); + if (result) + { + b = result.value(); + } + else + { + osd_printf_error("[LUA ERROR] invalid return from bounds callback\n"); + b = render_bounds{ 0.0, 0.0, 1.0, 1.0 }; + } + })); + } + else + { + osd_printf_error("[LUA ERROR] must call set_bounds_callback with function or nil\n"); + } + }; + layout_view_item_type["set_color_callback"] = + [this] (layout_view::item &i, sol::object cb) + { + if (cb == sol::lua_nil) + { + i.set_color_callback(layout_view::item::color_delegate()); + } + else if (cb.is()) + { + i.set_color_callback(layout_view::item::color_delegate( + [this, cbfunc = cb.as()] (render_color &c) + { + sol::optional result(invoke(cbfunc)); + if (result) + { + c = result.value(); + } + else + { + osd_printf_error("[LUA ERROR] invalid return from color callback\n"); + c = render_color{ 1.0, 1.0, 1.0, 1.0 }; + } + })); + } + else + { + osd_printf_error("[LUA ERROR] must call set_bounds_callback with function or nil\n"); + } + }; + layout_view_item_type["id"] = sol::property( + [this] (layout_view::item &i) -> sol::object + { + if (i.id().empty()) + return sol::make_object(sol(), sol::lua_nil); + else + return sol::make_object(sol(), i.id()); + }); + layout_view_item_type["bounds_animated"] = sol::property(&layout_view::item::bounds_animated); + layout_view_item_type["color_animated"] = sol::property(&layout_view::item::color_animated); + layout_view_item_type["bounds"] = sol::property(&layout_view::item::bounds); + layout_view_item_type["color"] = sol::property(&layout_view::item::color); + layout_view_item_type["blend_mode"] = sol::property(&layout_view::item::blend_mode); + layout_view_item_type["orientation"] = sol::property(&layout_view::item::orientation); + layout_view_item_type["element_state"] = sol::property(&layout_view::item::element_state); + layout_view_item_type["animation_state"] = sol::property(&layout_view::item::animation_state); + + +/* layout_file library + * + * file.set_resolve_tags_callback - set additional tasks after resolving tags + * + * file.device - get device that caused the file to be loaded + * file.views[] - get view table (k=name, v=layout_view) + */ + + auto layout_file_type = sol().registry().new_usertype("layout_file", sol::no_constructor); + layout_file_type["set_resolve_tags_callback"] = + [this] (layout_file &f, sol::object cb) + { + if (cb == sol::lua_nil) + { + f.set_resolve_tags_callback(layout_file::resolve_tags_delegate()); + } + else if (cb.is()) + { + f.set_resolve_tags_callback(layout_file::resolve_tags_delegate( + [this, cbfunc = cb.as()] () { invoke(cbfunc); })); + } + else + { + osd_printf_error("[LUA ERROR] must call set_resolve_tags_callback with function or nil\n"); + } + }; + layout_file_type["device"] = sol::property(&layout_file::device); + layout_file_type["views"] = sol::property([] (layout_file &f) { return layout_file_views(f); }); + + /* render_target library * * manager:machine():render().targets[target_index] * manager:machine():render():ui_target() * - * target:view_bounds() - get x0, x1, y0, y1 bounds for target + * target:current_view() - get current view for target * target:width() - get target width * target:height() - get target height * target:pixel_aspect() - get target aspect @@ -42,44 +599,41 @@ void lua_engine::initialize_render() * target.zoom - enable zoom */ - auto target_type = sol().registry().new_usertype("target", "new", sol::no_constructor); - target_type.set("view_bounds", [](render_target &rt) { - const render_bounds b = rt.current_view().bounds(); - return std::tuple(b.x0, b.x1, b.y0, b.y1); - }); - target_type.set("width", &render_target::width); - target_type.set("height", &render_target::height); - target_type.set("pixel_aspect", &render_target::pixel_aspect); - target_type.set("hidden", &render_target::hidden); - target_type.set("is_ui_target", &render_target::is_ui_target); - target_type.set("index", &render_target::index); - target_type.set("view_name", &render_target::view_name); - target_type.set("max_update_rate", sol::property(&render_target::max_update_rate, &render_target::set_max_update_rate)); - target_type.set("view", sol::property(&render_target::view, &render_target::set_view)); - target_type.set("orientation", sol::property(&render_target::orientation, &render_target::set_orientation)); - target_type.set("screen_overlay", sol::property(&render_target::screen_overlay_enabled, &render_target::set_screen_overlay_enabled)); - target_type.set("zoom", sol::property(&render_target::zoom_to_screen, &render_target::set_zoom_to_screen)); + auto target_type = sol().registry().new_usertype("target", sol::no_constructor); + target_type["current_view"] = &render_target::current_view; + target_type["width"] = &render_target::width; + target_type["height"] = &render_target::height; + target_type["pixel_aspect"] = &render_target::pixel_aspect; + target_type["hidden"] = &render_target::hidden; + target_type["is_ui_target"] = &render_target::is_ui_target; + target_type["index"] = &render_target::index; + target_type["view_name"] = &render_target::view_name; + target_type["max_update_rate"] = sol::property(&render_target::max_update_rate, &render_target::set_max_update_rate); + target_type["view"] = sol::property(&render_target::view, &render_target::set_view); + target_type["orientation"] = sol::property(&render_target::orientation, &render_target::set_orientation); + target_type["screen_overlay"] = sol::property(&render_target::screen_overlay_enabled, &render_target::set_screen_overlay_enabled); + target_type["zoom"] = sol::property(&render_target::zoom_to_screen, &render_target::set_zoom_to_screen); /* render_container library * * manager:machine():render():ui_container() * - * container:orientation() - * container:xscale() - * container:yscale() - * container:xoffset() - * container:yoffset() - * container:is_empty() + * container.orientation + * container.xscale + * container.yscale + * container.xoffset + * container.yoffset + * container.is_empty */ - auto render_container_type = sol().registry().new_usertype("render_container", "new", sol::no_constructor); - render_container_type.set("orientation", &render_container::orientation); - render_container_type.set("xscale", &render_container::xscale); - render_container_type.set("yscale", &render_container::yscale); - render_container_type.set("xoffset", &render_container::xoffset); - render_container_type.set("yoffset", &render_container::yoffset); - render_container_type.set("is_empty", &render_container::is_empty); + auto render_container_type = sol().registry().new_usertype("render_container", sol::no_constructor); + render_container_type["orientation"] = sol::property(&render_container::orientation); + render_container_type["xscale"] = sol::property(&render_container::xscale); + render_container_type["yscale"] = sol::property(&render_container::yscale); + render_container_type["xoffset"] = sol::property(&render_container::xoffset); + render_container_type["yoffset"] = sol::property(&render_container::yoffset); + render_container_type["is_empty"] = sol::property(&render_container::is_empty); /* render_manager library @@ -93,16 +647,10 @@ void lua_engine::initialize_render() * render.targets[] - render_target table */ - auto render_type = sol().registry().new_usertype("render", "new", sol::no_constructor); - render_type.set("max_update_rate", &render_manager::max_update_rate); - render_type.set("ui_target", &render_manager::ui_target); - render_type.set("ui_container", &render_manager::ui_container); - render_type.set("targets", sol::property([this](render_manager &r) { - sol::table target_table = sol().create_table(); - int tc = 0; - for(render_target &curr_rt : r.targets()) - target_table[tc++] = &curr_rt; - return target_table; - })); + auto render_type = sol().registry().new_usertype("render", sol::no_constructor); + render_type["max_update_rate"] = &render_manager::max_update_rate; + render_type["ui_target"] = &render_manager::ui_target; + render_type["ui_container"] = &render_manager::ui_container; + render_type["targets"] = sol::property([] (render_manager &m) { return render_manager_targets(m); }); } diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp index b996bae1dc0..a2a6a02f815 100644 --- a/src/frontend/mame/mame.cpp +++ b/src/frontend/mame/mame.cpp @@ -363,7 +363,7 @@ std::vector> mame_machine_manager::mis assert(m_machine); // make sure that any required image has a mounted file - for (device_image_interface &image : image_interface_iterator(m_machine->root_device())) + for (device_image_interface &image : image_interface_enumerator(m_machine->root_device())) { if (image.must_be_loaded()) { @@ -424,14 +424,20 @@ void emulator_info::sound_hook() return mame_machine_manager::instance()->lua()->on_sound_update(); } -void emulator_info::layout_file_cb(util::xml::data_node const &layout) +void emulator_info::layout_script_cb(layout_file &file, const char *script) { - util::xml::data_node const *const mamelayout = layout.get_child("mamelayout"); - if (mamelayout) + // TODO: come up with a better way to pass multiple arguments to plugin + //mame_machine_manager::instance()->lua()->call_plugin_set("layout", std::make_tuple(&file, script->get_value())); + auto &lua(mame_machine_manager::instance()->lua()->sol()); + sol::object obj = lua.registry()["cb_layout"]; + if (obj.is()) { - util::xml::data_node const *const script = mamelayout->get_child("script"); - if (script) - mame_machine_manager::instance()->lua()->call_plugin_set("layout", script->get_value()); + auto res = obj.as()(sol::make_reference(lua, &file), sol::make_reference(lua, script)); + if (!res.valid()) + { + sol::error err = res; + osd_printf_error("[LUA ERROR] in call_plugin: %s\n", err.what()); + } } } diff --git a/src/frontend/mame/mameopts.cpp b/src/frontend/mame/mameopts.cpp index 296d900d679..88ae9951cd9 100644 --- a/src/frontend/mame/mameopts.cpp +++ b/src/frontend/mame/mameopts.cpp @@ -68,7 +68,7 @@ void mame_options::parse_standard_inis(emu_options &options, std::ostream &error } machine_config config(*cursystem, options); - for (const screen_device &device : screen_device_iterator(config.root_device())) + for (const screen_device &device : screen_device_enumerator(config.root_device())) { // parse "raster.ini" for raster games if (device.screen_type() == SCREEN_TYPE_RASTER) diff --git a/src/frontend/mame/media_ident.cpp b/src/frontend/mame/media_ident.cpp index 44b4271a7e5..9aeb8765089 100644 --- a/src/frontend/mame/media_ident.cpp +++ b/src/frontend/mame/media_ident.cpp @@ -353,7 +353,7 @@ void media_identifier::match_hashes(std::vector &info) } // next iterate over softlists - for (software_list_device &swlistdev : software_list_device_iterator(device)) + for (software_list_device &swlistdev : software_list_device_enumerator(device)) { if (!listnames.insert(swlistdev.list_name()).second) continue; diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index bd39e72a6cd..daf5afe1953 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -24,6 +24,7 @@ namespace ui { + //------------------------------------------------- // ctor / dtor //------------------------------------------------- @@ -36,7 +37,7 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container , m_issoft(false) { - for (device_image_interface& image : image_interface_iterator(mui.machine().root_device())) + for (device_image_interface& image : image_interface_enumerator(mui.machine().root_device())) { if (image.filename()) { diff --git a/src/frontend/mame/ui/devctrl.h b/src/frontend/mame/ui/devctrl.h index ecdbeedf736..1be2385a66f 100644 --- a/src/frontend/mame/ui/devctrl.h +++ b/src/frontend/mame/ui/devctrl.h @@ -17,15 +17,15 @@ submenu listing available devices of the same kind. ***************************************************************************/ - -#pragma once - #ifndef MAME_FRONTEND_UI_DEVCTRL_H #define MAME_FRONTEND_UI_DEVCTRL_H +#pragma once + #include "ui/menu.h" namespace ui { + template class menu_device_control : public menu { @@ -43,8 +43,8 @@ protected: uint32_t current_display_flags(); private: - // device iterator - typedef device_type_iterator iterator; + // device enumerator + typedef device_type_enumerator enumerator; DeviceType * m_device; int m_count; @@ -59,7 +59,7 @@ template menu_device_control::menu_device_control(mame_ui_manager &mui, render_container &container, DeviceType *device) : menu(mui, container) { - iterator iter(mui.machine().root_device()); + enumerator iter(mui.machine().root_device()); m_count = iter.count(); m_device = device ? device : iter.first(); } @@ -72,7 +72,7 @@ menu_device_control::menu_device_control(mame_ui_manager &mui, rende template int menu_device_control::current_index() { - iterator iter(machine().root_device()); + enumerator iter(machine().root_device()); return iter.indexof(*m_device); } @@ -87,7 +87,7 @@ void menu_device_control::previous() // left arrow - rotate left through cassette devices if (m_device != nullptr) { - iterator iter(machine().root_device()); + enumerator iter(machine().root_device()); int index = iter.indexof(*m_device); if (index > 0) index--; @@ -108,7 +108,7 @@ void menu_device_control::next() // right arrow - rotate right through cassette devices if (m_device != nullptr) { - iterator iter(machine().root_device()); + enumerator iter(machine().root_device()); int index = iter.indexof(*m_device); if (index < m_count - 1) index++; @@ -154,4 +154,4 @@ uint32_t menu_device_control::current_display_flags() } // namespace ui -#endif /* MAME_FRONTEND_UI_DEVCTRL_H */ +#endif // MAME_FRONTEND_UI_DEVCTRL_H diff --git a/src/frontend/mame/ui/devopt.cpp b/src/frontend/mame/ui/devopt.cpp index 8688c513c6f..0172a65b3de 100644 --- a/src/frontend/mame/ui/devopt.cpp +++ b/src/frontend/mame/ui/devopt.cpp @@ -32,7 +32,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) machine_config &mconfig(const_cast(machine().config())); machine_config::token const tok(mconfig.begin_configuration(mconfig.root_device())); device_t *const dev = mconfig.device_add(m_option->name(), m_option->devtype(), 0); - for (device_t &d : device_iterator(*dev)) + for (device_t &d : device_enumerator(*dev)) if (!d.configured()) d.config_complete(); @@ -46,7 +46,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) dev->name()); // loop over all CPUs - execute_interface_iterator execiter(*dev); + execute_interface_enumerator execiter(*dev); if (execiter.count() > 0) { str << _("* CPU:\n"); @@ -90,7 +90,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) } // display screen information - screen_device_iterator scriter(*dev); + screen_device_enumerator scriter(*dev); if (scriter.count() > 0) { str << _("* Video:\n"); @@ -122,7 +122,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) } // loop over all sound chips - sound_interface_iterator snditer(*dev); + sound_interface_enumerator snditer(*dev); if (snditer.count() > 0) { str << _("* Sound:\n"); @@ -192,7 +192,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) std::string errors; std::ostringstream dips_opt, confs_opt; ioport_list portlist; - for (device_t &iptdev : device_iterator(*dev)) + for (device_t &iptdev : device_enumerator(*dev)) portlist.append(iptdev, errors); // check if the device adds inputs to the system @@ -272,7 +272,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) if (input_keyboard) util::stream_format(str, _(" Keyboard inputs [%1$d inputs]\n"), input_keyboard); - image_interface_iterator imgiter(*dev); + image_interface_enumerator imgiter(*dev); if (imgiter.count() > 0) { str << _("* Media Options:\n"); @@ -280,7 +280,7 @@ void menu_device_config::populate(float &customtop, float &custombottom) util::stream_format(str, _(" %1$s [tag: %2$s]\n"), imagedev.image_type_name(), imagedev.device().tag()); } - slot_interface_iterator slotiter(*dev); + slot_interface_enumerator slotiter(*dev); if (slotiter.count() > 0) { str << _("* Slot Options:\n"); diff --git a/src/frontend/mame/ui/filemngr.cpp b/src/frontend/mame/ui/filemngr.cpp index cb3243e0544..6c5423746f8 100644 --- a/src/frontend/mame/ui/filemngr.cpp +++ b/src/frontend/mame/ui/filemngr.cpp @@ -116,14 +116,14 @@ void menu_file_manager::populate(float &customtop, float &custombottom) // cycle through all devices for this system std::unordered_set devtags; - for (device_t &dev : device_iterator(machine().root_device())) + for (device_t &dev : device_enumerator(machine().root_device())) { bool tag_appended = false; if (!devtags.insert(dev.tag()).second) continue; // check whether it owns an image interface - image_interface_iterator subiter(dev); + image_interface_enumerator subiter(dev); if (subiter.first() != nullptr) { // if so, cycle through all its image interfaces diff --git a/src/frontend/mame/ui/info.cpp b/src/frontend/mame/ui/info.cpp index 6f30eea66f6..9bac109258a 100644 --- a/src/frontend/mame/ui/info.cpp +++ b/src/frontend/mame/ui/info.cpp @@ -82,7 +82,7 @@ machine_static_info::machine_static_info(const ui_options &options, machine_conf { ioport_list local_ports; std::string sink; - for (device_t &device : device_iterator(config.root_device())) + for (device_t &device : device_enumerator(config.root_device())) { // the "no sound hardware" warning doesn't make sense when you plug in a sound card if (dynamic_cast(&device)) @@ -343,7 +343,7 @@ std::string machine_info::game_info_string() const core_filename_extract_base(m_machine.system().type.source())); // loop over all CPUs - execute_interface_iterator execiter(m_machine.root_device()); + execute_interface_enumerator execiter(m_machine.root_device()); std::unordered_set exectags; for (device_execute_interface &exec : execiter) { @@ -382,7 +382,7 @@ std::string machine_info::game_info_string() const } // loop over all sound chips - sound_interface_iterator snditer(m_machine.root_device()); + sound_interface_enumerator snditer(m_machine.root_device()); std::unordered_set soundtags; bool found_sound = false; for (device_sound_interface &sound : snditer) @@ -426,7 +426,7 @@ std::string machine_info::game_info_string() const // display screen information buf << _("\nVideo:\n"); - screen_device_iterator scriter(m_machine.root_device()); + screen_device_enumerator scriter(m_machine.root_device()); int scrcount = scriter.count(); if (scrcount == 0) buf << _("None\n"); @@ -468,7 +468,7 @@ std::string machine_info::game_info_string() const std::string machine_info::get_screen_desc(screen_device &screen) const { - if (screen_device_iterator(m_machine.root_device()).count() > 1) + if (screen_device_enumerator(m_machine.root_device()).count() > 1) return string_format(_("Screen '%1$s'"), screen.tag()); else return _("Screen"); @@ -543,7 +543,7 @@ void menu_image_info::populate(float &customtop, float &custombottom) item_append(machine().system().type.fullname(), "", FLAG_DISABLE, nullptr); item_append("", "", FLAG_DISABLE, nullptr); - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) image_info(&image); } diff --git a/src/frontend/mame/ui/info_pty.cpp b/src/frontend/mame/ui/info_pty.cpp index deed38ae932..49d0737cbad 100644 --- a/src/frontend/mame/ui/info_pty.cpp +++ b/src/frontend/mame/ui/info_pty.cpp @@ -30,7 +30,7 @@ void menu_pty_info::populate(float &customtop, float &custombottom) item_append(_("Pseudo terminals"), "", FLAG_DISABLE, nullptr); item_append("", "", FLAG_DISABLE, nullptr); - for (device_pty_interface &pty : pty_interface_iterator(machine().root_device())) + for (device_pty_interface &pty : pty_interface_enumerator(machine().root_device())) { const char *port_name = pty.device().owner()->tag() + 1; if (pty.is_open()) diff --git a/src/frontend/mame/ui/inifile.cpp b/src/frontend/mame/ui/inifile.cpp index 028abc9c87b..253c52c07f3 100644 --- a/src/frontend/mame/ui/inifile.cpp +++ b/src/frontend/mame/ui/inifile.cpp @@ -470,7 +470,7 @@ void favorite_manager::apply_running_machine(running_machine &machine, T &&actio else { bool have_software(false); - for (device_image_interface &image_dev : image_interface_iterator(machine.root_device())) + for (device_image_interface &image_dev : image_interface_enumerator(machine.root_device())) { software_info const *const sw(image_dev.software_entry()); if (image_dev.exists() && image_dev.loaded_through_softlist() && sw) diff --git a/src/frontend/mame/ui/mainmenu.cpp b/src/frontend/mame/ui/mainmenu.cpp index b1a0e238935..5c129f76397 100644 --- a/src/frontend/mame/ui/mainmenu.cpp +++ b/src/frontend/mame/ui/mainmenu.cpp @@ -79,7 +79,7 @@ void menu_main::populate(float &customtop, float &custombottom) if (ui().found_machine_warnings()) item_append(_("Warning Information"), "", 0, (void *)WARN_INFO); - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { if (image.user_loadable()) { @@ -91,22 +91,22 @@ void menu_main::populate(float &customtop, float &custombottom) } } - if (cassette_device_iterator(machine().root_device()).first() != nullptr) + if (cassette_device_enumerator(machine().root_device()).first() != nullptr) item_append(_("Tape Control"), "", 0, (void *)TAPE_CONTROL); - if (pty_interface_iterator(machine().root_device()).first() != nullptr) + if (pty_interface_enumerator(machine().root_device()).first() != nullptr) item_append(_("Pseudo terminals"), "", 0, (void *)PTY_INFO); if (ui().machine_info().has_bioses()) item_append(_("BIOS Selection"), "", 0, (void *)BIOS_SELECTION); - if (slot_interface_iterator(machine().root_device()).first() != nullptr) + if (slot_interface_enumerator(machine().root_device()).first() != nullptr) item_append(_("Slot Devices"), "", 0, (void *)SLOT_DEVICES); - if (barcode_reader_device_iterator(machine().root_device()).first() != nullptr) + if (barcode_reader_device_enumerator(machine().root_device()).first() != nullptr) item_append(_("Barcode Reader"), "", 0, (void *)BARCODE_READ); - if (network_interface_iterator(machine().root_device()).first() != nullptr) + if (network_interface_enumerator(machine().root_device()).first() != nullptr) item_append(_("Network Devices"), "", 0, (void*)NETWORK_DEVICES); if (machine().ioport().natkeyboard().keyboard_count()) diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index e5c5d1862ae..1a6e95417ba 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -51,7 +51,7 @@ menu_bios_selection::menu_bios_selection(mame_ui_manager &mui, render_container void menu_bios_selection::populate(float &customtop, float &custombottom) { // cycle through all devices for this system - for (device_t &device : device_iterator(machine().root_device())) + for (device_t &device : device_enumerator(machine().root_device())) { device_t const *const parent(device.owner()); device_slot_interface const *const slot(dynamic_cast(parent)); @@ -132,7 +132,7 @@ menu_network_devices::~menu_network_devices() void menu_network_devices::populate(float &customtop, float &custombottom) { /* cycle through all devices for this system */ - for (device_network_interface &network : network_interface_iterator(machine().root_device())) + for (device_network_interface &network : network_interface_enumerator(machine().root_device())) { int curr = network.get_interface(); const char *title = nullptr; diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index 13a63965f65..116ead68f94 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -790,7 +790,7 @@ void menu_select_game::inkey_select(const event *menu_event) enumerator.next(); // if there are software entries, show a software selection menu - for (software_list_device &swlistdev : software_list_device_iterator(enumerator.config()->root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(enumerator.config()->root_device())) { if (!swlistdev.get_info().empty()) { @@ -863,7 +863,7 @@ void menu_select_game::inkey_select_favorite(const event *menu_event) enumerator.next(); // if there are software entries, show a software selection menu - for (software_list_device &swlistdev : software_list_device_iterator(enumerator.config()->root_device())) + for (software_list_device &swlistdev : software_list_device_enumerator(enumerator.config()->root_device())) { if (!swlistdev.get_info().empty()) { diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 5a14e3dac7f..ba3c33849e0 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -254,7 +254,7 @@ void menu_select_software::populate(float &customtop, float &custombottom) // FIXME: why does it do this relatively expensive operation every time? machine_config config(m_driver, machine().options()); - for (device_image_interface &image : image_interface_iterator(config.root_device())) + for (device_image_interface &image : image_interface_enumerator(config.root_device())) { if (!image.filename() && image.must_be_loaded()) { @@ -351,7 +351,7 @@ void menu_select_software::build_software_list() bool operator()(std::size_t a, std::size_t b) const { return swinfo[a].parentname < swinfo[b].parentname; }; }; orphan_less const orphan_cmp{ m_swinfo }; - for (software_list_device &swlist : software_list_device_iterator(config.root_device())) + for (software_list_device &swlist : software_list_device_enumerator(config.root_device())) { m_filter_data.add_list(swlist.list_name(), swlist.description()); check_for_icons(swlist.list_name().c_str()); @@ -381,7 +381,7 @@ void menu_select_software::build_software_list() { char const *instance_name(nullptr); char const *type_name(nullptr); - for (device_image_interface &image : image_interface_iterator(config.root_device())) + for (device_image_interface &image : image_interface_enumerator(config.root_device())) { char const *const interface = image.image_interface(); if (interface && part.matches_interface(interface)) diff --git a/src/frontend/mame/ui/slotopt.cpp b/src/frontend/mame/ui/slotopt.cpp index 01493173731..eac072bfa37 100644 --- a/src/frontend/mame/ui/slotopt.cpp +++ b/src/frontend/mame/ui/slotopt.cpp @@ -115,7 +115,7 @@ void menu_slot_devices::set_slot_device(device_slot_interface &slot, const char void menu_slot_devices::record_current_options() { - for (device_slot_interface &slot : slot_interface_iterator(m_config->root_device())) + for (device_slot_interface &slot : slot_interface_enumerator(m_config->root_device())) { // we're doing this out of a desire to honor user-selectable options; therefore it only // makes sense to record values for selectable options @@ -177,7 +177,7 @@ void menu_slot_devices::populate(float &customtop, float &custombottom) m_config = std::make_unique(machine().system(), machine().options()); // cycle through all devices for this system - for (device_slot_interface &slot : slot_interface_iterator(m_config->root_device())) + for (device_slot_interface &slot : slot_interface_enumerator(m_config->root_device())) { // does this slot have any selectable options? bool has_selectable_options = slot.has_selectable_options(); diff --git a/src/frontend/mame/ui/swlist.cpp b/src/frontend/mame/ui/swlist.cpp index bd2aa47aee5..d1e3f66da56 100644 --- a/src/frontend/mame/ui/swlist.cpp +++ b/src/frontend/mame/ui/swlist.cpp @@ -18,6 +18,7 @@ namespace ui { + /*************************************************************************** CONSTANTS ***************************************************************************/ @@ -355,7 +356,7 @@ void menu_software::populate(float &customtop, float &custombottom) bool have_compatible = false; // Add original software lists for this system - software_list_device_iterator iter(machine().config().root_device()); + software_list_device_enumerator iter(machine().config().root_device()); for (software_list_device &swlistdev : iter) if (swlistdev.is_original()) if (!swlistdev.get_info().empty() && m_interface != nullptr) diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index 90efcb04b7c..948be161a28 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -446,7 +446,7 @@ void mame_ui_manager::display_startup_screens(bool first_time) { // non-critical warnings - map current unemulated/imperfect features device_feature_set unemulated_features, imperfect_features; - for (device_t &device : device_iterator(machine().root_device())) + for (device_t &device : device_enumerator(machine().root_device())) { device_t::feature_type unemulated = device.type().unemulated_features(); for (std::underlying_type_t feature = 1U; unemulated; feature <<= 1) @@ -1167,7 +1167,7 @@ void mame_ui_manager::image_handler_ingame() auto layout = create_layout(machine().render().ui_container()); // loop through all devices, build their text into the layout - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { std::string str = image.call_display(); if (!str.empty()) @@ -1315,7 +1315,7 @@ uint32_t mame_ui_manager::handler_ingame(render_container &container) // handle a tape control key if (machine().ui_input().pressed(IPT_UI_TAPE_START)) { - for (cassette_image_device &cass : cassette_device_iterator(machine().root_device())) + for (cassette_image_device &cass : cassette_device_enumerator(machine().root_device())) { cass.change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE); return 0; @@ -1323,7 +1323,7 @@ uint32_t mame_ui_manager::handler_ingame(render_container &container) } if (machine().ui_input().pressed(IPT_UI_TAPE_STOP)) { - for (cassette_image_device &cass : cassette_device_iterator(machine().root_device())) + for (cassette_image_device &cass : cassette_device_enumerator(machine().root_device())) { cass.change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE); return 0; @@ -1541,13 +1541,13 @@ std::vector mame_ui_manager::slider_init(running_machine &machine slider_index = 0; if (machine.options().cheat()) { - for (device_execute_interface &exec : execute_interface_iterator(machine.root_device())) + for (device_execute_interface &exec : execute_interface_enumerator(machine.root_device())) { void *param = (void *)&exec.device(); std::string str = string_format(_("Overclock CPU %1$s"), exec.device().tag()); m_sliders.push_back(slider_alloc(SLIDER_ID_OVERCLOCK + slider_index++, str.c_str(), 100, 1000, 4000, 10, param)); } - for (device_sound_interface &snd : sound_interface_iterator(machine.root_device())) + for (device_sound_interface &snd : sound_interface_enumerator(machine.root_device())) { device_execute_interface *exec; if (!snd.device().interface(exec) && snd.device().unscaled_clock() != 0) @@ -1560,7 +1560,7 @@ std::vector mame_ui_manager::slider_init(running_machine &machine } // add screen parameters - screen_device_iterator scriter(machine.root_device()); + screen_device_enumerator scriter(machine.root_device()); slider_index = 0; for (screen_device &screen : scriter) { @@ -1599,7 +1599,7 @@ std::vector mame_ui_manager::slider_init(running_machine &machine } slider_index = 0; - for (laserdisc_device &laserdisc : laserdisc_device_iterator(machine.root_device())) + for (laserdisc_device &laserdisc : laserdisc_device_enumerator(machine.root_device())) { if (laserdisc.overlay_configured()) { diff --git a/src/frontend/mame/ui/viewgfx.cpp b/src/frontend/mame/ui/viewgfx.cpp index fb3ecc1cacd..188c939c011 100644 --- a/src/frontend/mame/ui/viewgfx.cpp +++ b/src/frontend/mame/ui/viewgfx.cpp @@ -198,7 +198,7 @@ void ui_gfx_init(running_machine &machine) static void ui_gfx_count_devices(running_machine &machine, ui_gfx_state &state) { // count the palette devices - state.palette.devcount = palette_interface_iterator(machine.root_device()).count(); + state.palette.devcount = palette_interface_enumerator(machine.root_device()).count(); // set the pointer to the first palette if (state.palette.devcount > 0) @@ -206,7 +206,7 @@ static void ui_gfx_count_devices(running_machine &machine, ui_gfx_state &state) // count the gfx devices state.gfxset.devcount = 0; - for (device_gfx_interface &interface : gfx_interface_iterator(machine.root_device())) + for (device_gfx_interface &interface : gfx_interface_enumerator(machine.root_device())) { // count the gfx sets in each device, skipping devices with none uint8_t count = 0; @@ -371,7 +371,7 @@ cancel: static void palette_set_device(running_machine &machine, ui_gfx_state &state) { - palette_interface_iterator pal_iter(machine.root_device()); + palette_interface_enumerator pal_iter(machine.root_device()); state.palette.interface = pal_iter.byindex(state.palette.devindex); } @@ -1337,7 +1337,7 @@ static void tilemap_update_bitmap(running_machine &machine, ui_gfx_state &state, { state.bitmap.fill(0); tilemap_t *tilemap = machine.tilemap().find(state.tilemap.which); - screen_device *first_screen = screen_device_iterator(machine.root_device()).first(); + screen_device *first_screen = screen_device_enumerator(machine.root_device()).first(); if (first_screen) { tilemap->draw_debug(*first_screen, state.bitmap, state.tilemap.xoffs, state.tilemap.yoffs, state.tilemap.flags); diff --git a/src/mame/drivers/apple2gs.cpp b/src/mame/drivers/apple2gs.cpp index e9a4e40f864..496e96489eb 100644 --- a/src/mame/drivers/apple2gs.cpp +++ b/src/mame/drivers/apple2gs.cpp @@ -4356,7 +4356,7 @@ u8 apple2gs_state::doc_adc_read() int apple2gs_state::apple2_fdc_has_35() { - return device_type_iterator(*this).count(); // - apple525_get_count(machine)) > 0; + return device_type_enumerator(*this).count(); // - apple525_get_count(machine)) > 0; } int apple2gs_state::apple2_fdc_has_525() diff --git a/src/mame/drivers/pc9801.cpp b/src/mame/drivers/pc9801.cpp index 558b06b916a..9d7dbb696ac 100644 --- a/src/mame/drivers/pc9801.cpp +++ b/src/mame/drivers/pc9801.cpp @@ -632,7 +632,7 @@ uint8_t pc9801_state::f0_r(offs_t offset) if(offset == 0) { // iterate thru all devices to check if an AMD98 is present - for (pc9801_amd98_device &amd98 : device_type_iterator(machine().root_device())) + for (pc9801_amd98_device &amd98 : device_type_enumerator(machine().root_device())) { logerror("Read AMD98 ID %s\n",amd98.tag()); return 0x18; // return the right ID diff --git a/src/mame/layout/mdndclab.lay b/src/mame/layout/mdndclab.lay index 224462c4afc..fe8c95d9883 100644 --- a/src/mame/layout/mdndclab.lay +++ b/src/mame/layout/mdndclab.lay @@ -7,93 +7,94 @@ license:CC0 - + + return layout + ]]> diff --git a/src/mame/layout/v4dbltak.lay b/src/mame/layout/v4dbltak.lay index 7ed917688b7..64b54f765fd 100644 --- a/src/mame/layout/v4dbltak.lay +++ b/src/mame/layout/v4dbltak.lay @@ -3,37 +3,45 @@ license:CC0 --> - - + + return layout + ]]> @@ -169,16 +177,16 @@ return layout, "v4dbltak" - + - + - + - + diff --git a/src/mame/machine/hp9845_optrom.cpp b/src/mame/machine/hp9845_optrom.cpp index 26f5a41cf3b..7f01abee7c7 100644 --- a/src/mame/machine/hp9845_optrom.cpp +++ b/src/mame/machine/hp9845_optrom.cpp @@ -75,7 +75,7 @@ image_init_result hp9845_optrom_device::call_load() logerror("hp9845_optrom: base_addr = %06x end_addr = %06x\n" , base_addr , end_addr); // Install ROM in address space of every CPU - for (hp_hybrid_cpu_device& cpu : device_interface_iterator(machine().root_device())) { + for (hp_hybrid_cpu_device& cpu : device_interface_enumerator(machine().root_device())) { logerror("hp9845_optrom: install in %s AS\n" , cpu.tag()); cpu.space(AS_PROGRAM).install_rom(base_addr , end_addr , get_software_region("rom")); } @@ -90,7 +90,7 @@ void hp9845_optrom_device::call_unload() { logerror("hp9845_optrom: call_unload\n"); if (m_base_addr != 0 && m_end_addr != 0) { - for (hp_hybrid_cpu_device& cpu : device_interface_iterator(machine().root_device())) { + for (hp_hybrid_cpu_device& cpu : device_interface_enumerator(machine().root_device())) { cpu.space(AS_PROGRAM).unmap_read(m_base_addr , m_end_addr); } m_base_addr = 0; diff --git a/src/mame/machine/msx.cpp b/src/mame/machine/msx.cpp index 784d891e8f3..7a174aa98cc 100644 --- a/src/mame/machine/msx.cpp +++ b/src/mame/machine/msx.cpp @@ -37,14 +37,8 @@ void msx2_state::machine_start() { msx_state::machine_start(); - for (device_t &device : device_iterator(*this)) - { - msx_switched_interface *switched; - if (device.interface(switched)) - { - m_switched.push_back(switched); - } - } + for (msx_switched_interface &switched : device_interface_enumerator(*this)) + m_switched.push_back(&switched); save_item(NAME(m_rtc_latch)); } diff --git a/src/osd/modules/debugger/debugimgui.cpp b/src/osd/modules/debugger/debugimgui.cpp index 5e1e7f5c080..6b1c52a7281 100644 --- a/src/osd/modules/debugger/debugimgui.cpp +++ b/src/osd/modules/debugger/debugimgui.cpp @@ -1059,7 +1059,7 @@ void debug_imgui::draw_images_menu() if(ImGui::BeginMenu("Images")) { int x = 0; - for (device_image_interface &img : image_interface_iterator(m_machine->root_device())) + for (device_image_interface &img : image_interface_enumerator(m_machine->root_device())) { x++; std::string str = string_format(" %s : %s##%i",img.device().name(),img.exists() ? img.filename() : "[Empty slot]",x); @@ -1417,7 +1417,7 @@ void debug_imgui::init_debugger(running_machine &machine) fatalerror("Error: ImGui debugger requires the BGFX renderer.\n"); // check for any image devices (cassette, floppy, etc...) - image_interface_iterator iter(m_machine->root_device()); + image_interface_enumerator iter(m_machine->root_device()); if (iter.first() != nullptr) m_has_images = true; diff --git a/src/osd/modules/debugger/qt/mainwindow.cpp b/src/osd/modules/debugger/qt/mainwindow.cpp index f2026db67e9..75e25c2670d 100644 --- a/src/osd/modules/debugger/qt/mainwindow.cpp +++ b/src/osd/modules/debugger/qt/mainwindow.cpp @@ -93,7 +93,7 @@ MainWindow::MainWindow(running_machine* machine, QWidget* parent) : // // Images menu // - image_interface_iterator imageIterTest(m_machine->root_device()); + image_interface_enumerator imageIterTest(m_machine->root_device()); if (imageIterTest.first() != nullptr) { createImagesMenu(); @@ -332,7 +332,7 @@ void MainWindow::mountImage(bool changedTo) { // The image interface index was assigned to the QAction's data memeber const int imageIndex = dynamic_cast(sender())->data().toInt(); - image_interface_iterator iter(m_machine->root_device()); + image_interface_enumerator iter(m_machine->root_device()); device_image_interface *img = iter.byindex(imageIndex); if (img == nullptr) { @@ -374,7 +374,7 @@ void MainWindow::unmountImage(bool changedTo) { // The image interface index was assigned to the QAction's data memeber const int imageIndex = dynamic_cast(sender())->data().toInt(); - image_interface_iterator iter(m_machine->root_device()); + image_interface_enumerator iter(m_machine->root_device()); device_image_interface *img = iter.byindex(imageIndex); img->unload(); @@ -455,7 +455,7 @@ void MainWindow::createImagesMenu() QMenu* imagesMenu = menuBar()->addMenu("&Images"); int interfaceIndex = 0; - for (device_image_interface &img : image_interface_iterator(m_machine->root_device())) + for (device_image_interface &img : image_interface_enumerator(m_machine->root_device())) { std::string menuName = string_format("%s : %s", img.device().name(), img.exists() ? img.filename() : "[empty slot]"); diff --git a/src/osd/modules/debugger/win/consolewininfo.cpp b/src/osd/modules/debugger/win/consolewininfo.cpp index 5589a48018a..1265417c61f 100644 --- a/src/osd/modules/debugger/win/consolewininfo.cpp +++ b/src/osd/modules/debugger/win/consolewininfo.cpp @@ -39,7 +39,7 @@ consolewin_info::consolewin_info(debugger_windows_interface &debugger) : { // Add image menu only if image devices exist - image_interface_iterator iter(machine().root_device()); + image_interface_enumerator iter(machine().root_device()); if (iter.first() != nullptr) { m_devices_menu = CreatePopupMenu(); @@ -167,7 +167,7 @@ void consolewin_info::update_menu() { // create the image menu uint32_t cnt = 0; - for (device_image_interface &img : image_interface_iterator(machine().root_device())) + for (device_image_interface &img : image_interface_enumerator(machine().root_device())) { if (!img.user_loadable()) continue; @@ -257,7 +257,7 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam) if ((HIWORD(wparam) == 0) && (LOWORD(wparam) >= ID_DEVICE_OPTIONS)) { uint32_t const devid = (LOWORD(wparam) - ID_DEVICE_OPTIONS) / DEVOPTION_MAX; - image_interface_iterator iter(machine().root_device()); + image_interface_enumerator iter(machine().root_device()); device_image_interface *const img = iter.byindex(devid); if (img != nullptr) { @@ -563,14 +563,14 @@ bool consolewin_info::get_softlist_info(device_image_interface *img) std::string sl_dir, opt_name = img->instance_name(); // Get the path to suitable software - for (software_list_device &swlist : software_list_device_iterator(machine().root_device())) + for (software_list_device &swlist : software_list_device_enumerator(machine().root_device())) { for (const software_info &swinfo : swlist.get_info()) { const software_part &part = swinfo.parts().front(); if (swlist.is_compatible(part) == SOFTWARE_IS_COMPATIBLE) { - for (device_image_interface &image : image_interface_iterator(machine().root_device())) + for (device_image_interface &image : image_interface_enumerator(machine().root_device())) { if (!image.user_loadable()) continue; diff --git a/src/osd/modules/debugger/win/debugwininfo.cpp b/src/osd/modules/debugger/win/debugwininfo.cpp index e3926a22139..fdd486f3e80 100644 --- a/src/osd/modules/debugger/win/debugwininfo.cpp +++ b/src/osd/modules/debugger/win/debugwininfo.cpp @@ -333,7 +333,7 @@ bool debugwin_info::handle_command(WPARAM wparam, LPARAM lparam) machine().rewind_step(); // clear all PC & memory tracks - for (device_t &device : device_iterator(machine().root_device())) + for (device_t &device : device_enumerator(machine().root_device())) { device.debug()->track_pc_data_clear(); device.debug()->track_mem_data_clear(); diff --git a/src/osd/modules/render/aviwrite.cpp b/src/osd/modules/render/aviwrite.cpp index b1a4a013af4..aff5429446e 100644 --- a/src/osd/modules/render/aviwrite.cpp +++ b/src/osd/modules/render/aviwrite.cpp @@ -56,7 +56,7 @@ void avi_write::begin_avi_recording(const char *name) m_frame = 0; m_next_frame_time = m_machine.time(); - const screen_device *primary_screen = screen_device_iterator(m_machine.root_device()).first(); + const screen_device *primary_screen = screen_device_enumerator(m_machine.root_device()).first(); // build up information about this new movie avi_file::movie_info info; info.video_format = 0; diff --git a/src/osd/modules/render/bgfx/chain.cpp b/src/osd/modules/render/bgfx/chain.cpp index 0efea9b6622..d75b9b296dd 100644 --- a/src/osd/modules/render/bgfx/chain.cpp +++ b/src/osd/modules/render/bgfx/chain.cpp @@ -78,7 +78,7 @@ void bgfx_chain::repopulate_targets() void bgfx_chain::process(chain_manager::screen_prim &prim, int view, int screen, texture_manager& textures, osd_window& window, uint64_t blend) { - screen_device_iterator screen_iterator(window.machine().root_device()); + screen_device_enumerator screen_iterator(window.machine().root_device()); screen_device* screen_device = screen_iterator.byindex(screen); uint16_t screen_count(window.target()->current_view().visible_screen_count()); diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index d7dac959e62..84014db5543 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -1163,7 +1163,7 @@ int shaders::scanline_pass(d3d_render_target *rt, int source_index, poly_info *p return next_index; auto win = d3d->assert_window(); - screen_device_iterator screen_iterator(machine->root_device()); + screen_device_enumerator screen_iterator(machine->root_device()); screen_device *screen = screen_iterator.byindex(curr_screen); render_container &screen_container = screen->container(); float xscale = 1.0f / screen_container.xscale(); @@ -1244,7 +1244,7 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, auto win = d3d->assert_window(); - screen_device_iterator screen_iterator(machine->root_device()); + screen_device_enumerator screen_iterator(machine->root_device()); screen_device *screen = screen_iterator.byindex(curr_screen); render_container &screen_container = screen->container(); @@ -1794,7 +1794,7 @@ bool shaders::add_render_target(renderer_d3d9* d3d, render_primitive *prim, int //============================================================ void shaders::enumerate_screens() { - screen_device_iterator iter(machine->root_device()); + screen_device_enumerator iter(machine->root_device()); num_screens = iter.count(); } @@ -2336,7 +2336,7 @@ void shaders::init_slider_list() } internal_sliders.clear(); - const screen_device *first_screen = screen_device_iterator(machine->root_device()).first();; + const screen_device *first_screen = screen_device_enumerator(machine->root_device()).first();; if (first_screen == nullptr) { return; @@ -2427,7 +2427,7 @@ void uniform::update() renderer_d3d9 *d3d = shadersys->d3d; auto win = d3d->assert_window(); - const screen_device *first_screen = screen_device_iterator(win->machine().root_device()).first(); + const screen_device *first_screen = screen_device_enumerator(win->machine().root_device()).first(); bool vector_screen = first_screen != nullptr && diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp index ee5dffdeaf0..a279034ef7d 100644 --- a/src/osd/modules/render/drawd3d.cpp +++ b/src/osd/modules/render/drawd3d.cpp @@ -1280,7 +1280,7 @@ void renderer_d3d9::pick_best_mode() auto win = assert_window(); // determine the refresh rate of the primary screen - const screen_device *primary_screen = screen_device_iterator(win->machine().root_device()).first(); + const screen_device *primary_screen = screen_device_enumerator(win->machine().root_device()).first(); if (primary_screen != nullptr) { target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds()); @@ -2621,7 +2621,7 @@ bool d3d_render_target::init(renderer_d3d9 *d3d, int source_width, int source_he auto win = d3d->assert_window(); - const screen_device *first_screen = screen_device_iterator(win->machine().root_device()).first(); + const screen_device *first_screen = screen_device_enumerator(win->machine().root_device()).first(); bool vector_screen = first_screen != nullptr && first_screen->screen_type() == SCREEN_TYPE_VECTOR; diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp index 9f07ce7cd49..712337b4dd7 100644 --- a/src/osd/sdl/window.cpp +++ b/src/osd/sdl/window.cpp @@ -607,7 +607,7 @@ void sdl_window_info::update() // Check whether window has vector screens { - const screen_device *screen = screen_device_iterator(machine().root_device()).byindex(m_index); + const screen_device *screen = screen_device_enumerator(machine().root_device()).byindex(m_index); if ((screen != nullptr) && (screen->screen_type() == SCREEN_TYPE_VECTOR)) renderer().set_flags(osd_renderer::FLAG_HAS_VECTOR_SCREEN); else -- cgit v1.2.3