summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/tilemap.h
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2019-10-26 12:47:04 +1100
committer Vas Crabb <vas@vastheman.com>2019-10-26 12:47:04 +1100
commitf81fbdb8d4356b7a526a902726463e2f1af00615 (patch)
treef73f8746dc3cd1feb81afdb3cb4e6b0b99141ea0 /src/emu/tilemap.h
parentbc7c6ea17e1b38f6fb488177e01c63577fbbcf71 (diff)
Make devdelegate more like devcb for configuration. This is a
fundamental change to show device delegates are configured. Device delegates are now aware of the current device during configuration and will resolve string tags relative to it. This means that device delegates need a device to be supplied on construction so they can find the machine configuration object. There's a one-dimensional array helper to make it easier to construct arrays of device delegates with the same owner. (I didn't make an n-dimensional one because I didn't hit a use case, but it would be a simple addition.) There's no more bind_relative_to member - just call resolve() like you would for a devcb. There's also no need to cast nullptr when creating a late bind device delegate. The flip side is that for an overloaded or non-capturing lambda you'll need to cast to the desired type. There is one less conditional branch in the hot path for calls for delegates bound to a function pointer of member function pointer. This comes at the cost of one additional unconditional branch in the hot path for calls to delegates bound to functoids (lambdas, functions that don't take an object reference, other callable objects). This applies to all delegates, not just device delegates. Address spaces will now print an error message if a late bind error is encountered while installing a handler. This will give the range and address range, hopefully making it easier to guess which memory map is faulty. For the simple case of allowing a device_delegate member to be configured, use a member like this: template <typename... T> void set_foo(T &&...args) { m_foo_cb.set(std::forward<T>(args)...); } For a case where different delegates need to be used depending on the function signature, see src/emu/screen.h (the screen update function setters). Device delegates now take a target specification and function pointer. The target may be: * Target omitted, implying the current device being configured. This can only be used during configuration. It will work as long as the current device is not removed/replaced. * A tag string relative to the current device being configured. This can only be used during configuration. It will not be callable until .resolve() is called. It will work as long as the current device is not removed/replaced. * A device finder (required_device/optional_device). The delegate will late bind to the current target of the device finder. It will not be callable until .resolve() is called. It will work properly if the target device is replaced, as long as the device finder's base object isn't removed/replaced. * A reference to an object. It will be callable immediately. It will work as long as the target object is not removed/replaced. The target types and restrictions are pretty similar to what you already have on object finders and devcb, so it shouldn't cause any surprises. Note that dereferencing a device finder will changes the effect. To illustrate this: ... required_device<some_device> m_dev; ... m_dev(*this, "dev") ... // will late bind to "dev" relative to *this // will work if "dev" hasn't been created yet or is replaced later // won't work if *this is removed/replaced // won't be callable until resolve() is called cb1.set(m_dev, FUNC(some_device::w)); ... // will bind to current target of m_dev // will not work if m_dev is not resolved // will not work if "dev" is replaced later // will be callable immediately cb2.set(*m_dev, FUNC(some_device::w)); ... The order of the target and name has been reversed for functoids (lambdas and other callable objects). This allows the NAME macro to be used on lambdas and functoids. For example: foo.set_something(NAME([this] (u8 data) { m_something = data; })); I realise the diagnostic messages get ugly if you use NAME on a large lambda. You can still give a literal name, you just have to place it after the lambda rather than before. This is uglier, but it's intentional. I'm trying to drive developers away from a certain style. While it's nice that you can put half the driver code in the memory map, it detracts from readability. It's hard to visualise the memory range mappings if the memory map functions are punctuated by large lambdas. There's also slightly higher overhead for calling a delegate bound to a functoid. If the code is prettier for trivial lambdas but uglier for non-trivial lambdas in address maps, it will hopefully steer people away from putting non-trivial lambdas in memory maps. There were some devices that were converted from using plain delegates without adding bind_relative_to calls. I fixed some of them (e.g. LaserDisc) but I probably missed some. These will likely crash on unresolved delegate calls. There are some devices that reset delegates at configuration complete or start time, preventing them from being set up during configuration (e.g. src/devices/video/ppu2c0x.cpp and src/devices/machine/68307.cpp). This goes against the design principles of how device delegates should be used, but I didn't change them because I don't trust myself to find all the places they're used. I've definitely broken some stuff with this (I know about asterix), so report issues and bear with me until I get it all fixed.
Diffstat (limited to 'src/emu/tilemap.h')
-rw-r--r--src/emu/tilemap.h55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/emu/tilemap.h b/src/emu/tilemap.h
index a116f019c6c..e9ed1a3b66d 100644
--- a/src/emu/tilemap.h
+++ b/src/emu/tilemap.h
@@ -303,6 +303,10 @@
#pragma once
+#include <type_traits>
+#include <utility>
+#include <vector>
+
//**************************************************************************
// CONSTANTS
@@ -419,17 +423,19 @@ class tilemap_t
// maximum index in each array
static const pen_t MAX_PEN_TO_FLAGS = 256;
+ void init_common(tilemap_manager &manager, device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, u16 tilewidth, u16 tileheight, u32 cols, u32 rows);
+
protected:
// tilemap_manager controls our allocations
- tilemap_t();
+ tilemap_t(device_t &owner);
virtual ~tilemap_t();
tilemap_t &init(tilemap_manager &manager, device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, tilemap_mapper_delegate mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows);
+ tilemap_t &init(tilemap_manager &manager, device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, tilemap_standard_mapper mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows);
public:
// getters
running_machine &machine() const;
- tilemap_device *device() const { return m_device; }
device_palette_interface &palette() const { return *m_palette; }
device_gfx_interface &decoder() const { return *m_tileinfo.decoder; }
@@ -554,7 +560,7 @@ private:
// managers and devices
tilemap_manager * m_manager; // reference to the owning manager
- tilemap_device * m_device; // pointer to our owning device
+ device_t * m_device; // pointer to our owning device
device_palette_interface * m_palette; // palette used for drawing
tilemap_t * m_next; // pointer to next tilemap
void * m_user_data; // user data value
@@ -621,8 +627,12 @@ public:
running_machine &machine() const { return m_machine; }
// tilemap creation
- tilemap_t &create(device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, tilemap_mapper_delegate mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows, tilemap_t *allocated = nullptr);
- tilemap_t &create(device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, tilemap_standard_mapper mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows, tilemap_t *allocated = nullptr);
+ template <typename T, typename U>
+ tilemap_t &create(device_gfx_interface &decoder, T &&tile_get_info, U &&mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows)
+ { return create(decoder, std::forward<T>(tile_get_info), std::forward<U>(mapper), tilewidth, tileheight, cols, rows, nullptr); }
+ template <typename T, typename U, class V>
+ std::enable_if_t<std::is_base_of<device_t, V>::value, tilemap_t &> create(device_gfx_interface &decoder, T &&tile_get_info, U &&mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows, V &allocated)
+ { return create(decoder, std::forward<T>(tile_get_info), std::forward<U>(mapper), tilewidth, tileheight, cols, rows, &static_cast<tilemap_t &>(allocated)); }
// tilemap list information
tilemap_t *find(int index) { return m_tilemap_list.find(index); }
@@ -633,6 +643,10 @@ public:
void set_flip_all(u32 attributes);
private:
+ // tilemap creation
+ tilemap_t &create(device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, tilemap_mapper_delegate mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows, tilemap_t *allocated);
+ tilemap_t &create(device_gfx_interface &decoder, tilemap_get_info_delegate tile_get_info, tilemap_standard_mapper mapper, u16 tilewidth, u16 tileheight, u32 cols, u32 rows, tilemap_t *allocated);
+
// allocate an instance index
int alloc_instance() { return ++m_instance; }
@@ -689,29 +703,28 @@ public:
template <typename T> void set_gfxdecode(T &&tag) { m_gfxdecode.set_tag(std::forward<T>(tag)); }
void set_bytes_per_entry(int bpe) { m_bytes_per_entry = bpe; }
- void set_info_callback(tilemap_get_info_delegate tile_get_info) { m_get_info = tile_get_info; }
- template <class FunctionClass> void set_info_callback(const char *devname, void (FunctionClass::*callback)(tilemap_t &, tile_data &, tilemap_memory_index), const char *name)
- {
- set_info_callback(tilemap_get_info_delegate(callback, name, devname, static_cast<FunctionClass *>(nullptr)));
- }
- template <class FunctionClass> void set_info_callback(void (FunctionClass::*callback)(tilemap_t &, tile_data &, tilemap_memory_index), const char *name)
- {
- set_info_callback(tilemap_get_info_delegate(callback, name, nullptr, static_cast<FunctionClass *>(nullptr)));
- }
+ template <typename... T> void set_info_callback(T &&... args) { m_get_info.set(std::forward<T>(args)...); }
- template <class FunctionClass> void set_layout(tilemap_memory_index (FunctionClass::*callback)(u32, u32, u32, u32), const char *name, u32 columns, u32 rows)
+ void set_layout(tilemap_standard_mapper mapper, u32 columns, u32 rows)
{
- set_layout(tilemap_mapper_delegate(callback, name, nullptr, static_cast<FunctionClass *>(nullptr)), columns, rows);
- }
-
- void set_layout(tilemap_standard_mapper mapper, u32 columns, u32 rows) {
+ assert(TILEMAP_STANDARD_COUNT > mapper);
m_standard_mapper = mapper;
m_num_columns = columns;
m_num_rows = rows;
}
- void set_layout(tilemap_mapper_delegate mapper, u32 columns, u32 rows) {
+ template <typename F>
+ void set_layout(F &&callback, const char *name, u32 columns, u32 rows)
+ {
+ m_standard_mapper = TILEMAP_STANDARD_COUNT;
+ m_mapper.set(std::forward<F>(callback), name);
+ m_num_columns = columns;
+ m_num_rows = rows;
+ }
+ template <typename T, typename F>
+ void set_layout(T &&target, F &&callback, const char *name, u32 columns, u32 rows)
+ {
m_standard_mapper = TILEMAP_STANDARD_COUNT;
- m_mapper = mapper;
+ m_mapper.set(std::forward<T>(target), std::forward<F>(callback), name);
m_num_columns = columns;
m_num_rows = rows;
}