~mil/mepo-devel

mepo: Prefer name over @This() v2 PROPOSED

Nguyễn Gia Phong: 2
 Prefer name over @This()
 Signal unused param at function signature

 6 files changed, 85 insertions(+), 82 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/mepo-devel/patches/54531/mbox | git am -3
Learn more about email & git

[PATCH mepo v2 1/2] Prefer name over @This() Export this patch

---
On 2024-08-13 at 19:06-04:00, Miles Alan wrote:
> My only caveat would be that the token for the struct we use in
> this pattern should be consistent (e.g. both 'Self' in the case of
> EvictionHashMap is used but then 'Mepo' and 'TileCache' are used for
> Mepo/TileCache). We should follow one pattern or the other for naming.
> I'd say using 'Self' in all instances would be a bit better?

I think that's reasonable.
I've accordingly updated the type names to Self.

 src/Mepo.zig                          | 71 ++++++++++++++-------------
 src/TileCache.zig                     | 41 ++++++++--------
 src/datastructure/EvictionHashMap.zig | 19 +++----
 src/datastructure/QueueHashMap.zig    | 27 +++++-----
 src/types.zig                         |  6 +--
 5 files changed, 84 insertions(+), 80 deletions(-)

diff --git a/src/Mepo.zig b/src/Mepo.zig
index 40ded8004702..3b4e371bbf20 100644
--- a/src/Mepo.zig
+++ b/src/Mepo.zig
@@ -15,6 +15,7 @@ const shellpipe_sync = @import("api/shellpipe_sync.zig");
const zoom_relative = @import("./api/zoom_relative.zig").zoom_relative;
const FnTable = @import("./api/_FnTable.zig");

const Self = @This();
allocator: std.mem.Allocator,
blit_pinlayer_cache: datastructure.EvictionHashMap(types.XYZ, *sdl.SDL_Texture, evict_texture, &config.MaxTextures),
config: []const u8,
@@ -50,21 +51,21 @@ win_w: u32 = config.InitWindowW,
window: *sdl.SDL_Window = undefined,
quit_action: ?[]const u8 = null,

pub fn convert_latlon_to_xy(mepo: *@This(), lat_or_lon: enum { LonToX, LatToY }, lat_lon_value: f64) i32 {
pub fn convert_latlon_to_xy(mepo: *Self, lat_or_lon: enum { LonToX, LatToY }, lat_lon_value: f64) i32 {
    return switch (lat_or_lon) {
        .LonToX => -1 * (mepo.get_x() - @as(i32, @intCast(mepo.win_w / 2)) - utilconversion.lon_to_px_x(lat_lon_value, p.get(p.pref.zoom).u)),
        .LatToY => -1 * (mepo.get_y() - @as(i32, @intCast(mepo.win_h / 2)) - utilconversion.lat_to_px_y(lat_lon_value, p.get(p.pref.zoom).u)),
    };
}

fn event_fingerdown(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_fingerdown(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    for (mepo.fingers.items) |f| if (e.tfinger.fingerId == f) return .None;
    mepo.fingers.append(e.tfinger.fingerId) catch unreachable;
    if (mepo.fingers.items.len > 1) mepo.fingers_gesture_delta = 0;
    return .None;
}

fn event_fingerup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_fingerup(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    for (mepo.fingers.items, 0..) |f, i| {
        if (e.tfinger.fingerId == f) {
            _ = mepo.fingers.orderedRemove(i);
@@ -75,7 +76,7 @@ fn event_fingerup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_textinput(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_textinput(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    var idx: usize = 0;
    var pending: types.Pending = .None;
    const text = e.text.text;
@@ -94,7 +95,7 @@ fn event_textinput(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return pending;
}

fn event_multigesture(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_multigesture(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    const threshold_pan_dist = 0.004;
    const threshold_rotate_radians = 0.015;

@@ -126,7 +127,7 @@ fn event_multigesture(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_mousebuttondown(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_mousebuttondown(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    if (mepo.fingers.items.len > 1) return .None;

    const cursor = mepo.scaled_mouse_position();
@@ -142,7 +143,7 @@ fn event_mousebuttondown(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .Redraw;
}

fn event_mousebuttonup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_mousebuttonup(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    if (mepo.fingers.items.len > 1) return .None;
    defer mepo.drag = null;

@@ -207,7 +208,7 @@ fn event_mousebuttonup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_mousemotion(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_mousemotion(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    if (mepo.fingers.items.len > 1) return .None;

    const cursor = mepo.scaled_mouse_position();
@@ -225,16 +226,16 @@ fn event_mousemotion(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;
}

pub fn within_touch_bounds(mepo: *@This(), x: c_int, y: c_int) bool {
pub fn within_touch_bounds(mepo: *Self, x: c_int, y: c_int) bool {
    return x > 0 and y > 0 and x < mepo.win_w and y < mepo.win_h;
}

fn event_mousewheel(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_mousewheel(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    zoom_relative(mepo, e.wheel.y);
    return .Redraw;
}

fn event_keyup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_keyup(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    if (sdl.SDL_TRUE == sdl.SDL_IsTextInputActive() and
        e.key.keysym.mod == 0) return .None;
    const key = sdl.SDL_GetScancodeName(e.key.keysym.scancode);
@@ -270,7 +271,7 @@ fn event_keyup(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_signal(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_signal(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    if (mepo.table_signals.get(@intCast(e.user.code))) |run_expression| {
        utildbg.log("Got signals table function {s}\n", .{run_expression});
        mepo.jsonapi_execute(run_expression) catch unreachable;
@@ -279,7 +280,7 @@ fn event_signal(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_windowevent(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_windowevent(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    // Fix for certain platforms like Phosh like open keyboard on winevents
    defer if (utilplatform.supports_osk()) sdl.SDL_StopTextInput();

@@ -305,7 +306,7 @@ fn event_windowevent(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .Redraw;
}

fn event_jsonapiexecution(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_jsonapiexecution(mepo: *Self, e: sdl.SDL_Event) types.Pending {
    const heap_str = std.mem.sliceTo(@as([*c]u8, @ptrCast(e.user.data1)), 0);
    utildbg.log("SDL jsonapi event proccessing: <{s}>\n", .{heap_str});
    mepo.jsonapi_execute(heap_str) catch |err| {
@@ -315,7 +316,7 @@ fn event_jsonapiexecution(mepo: *@This(), e: sdl.SDL_Event) types.Pending {
    return .Redraw;
}

pub fn event_quit(mepo: *@This(), _: sdl.SDL_Event) types.Pending {
pub fn event_quit(mepo: *Self, _: sdl.SDL_Event) types.Pending {
    if (mepo.quit_action) |quit_action| {
        mepo.jsonapi_execute(quit_action) catch |err| {
            utildbg.log("Error with running jsonapi quit action: {}\n", .{err});
@@ -325,7 +326,7 @@ pub fn event_quit(mepo: *@This(), _: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_unhandled(_: *@This(), e: sdl.SDL_Event) types.Pending {
fn event_unhandled(_: *Self, e: sdl.SDL_Event) types.Pending {
    //utildbg.log("Unhandled SDL Event: {s}\n", .{@tagName(@intToEnum(sdl.SDL_EventType, @intCast(c_int, e.type)))});
    _ = e;
    return .None;
@@ -376,7 +377,7 @@ fn jsonapi_execute_parseargs(
    return args;
}

pub fn jsonapi_execute(mepo: *@This(), jsonapi_text: []const u8) !void {
pub fn jsonapi_execute(mepo: *Self, jsonapi_text: []const u8) !void {
    var arena = std.heap.ArenaAllocator.init(mepo.allocator);
    defer arena.deinit();

@@ -418,7 +419,7 @@ pub fn jsonapi_execute(mepo: *@This(), jsonapi_text: []const u8) !void {
    }
}

fn dispatch_check_click_hold(mepo: *@This()) void {
fn dispatch_check_click_hold(mepo: *Self) void {
    if (mepo.drag == null or mepo.fingers.items.len > 1) {
        mepo.drag = null;
        return;
@@ -450,7 +451,7 @@ fn dispatch_check_click_hold(mepo: *@This()) void {
    }
}

fn dispatch_check_timers(mepo: *@This()) !void {
fn dispatch_check_timers(mepo: *Self) !void {
    var it = mepo.table_timers.iterator();
    while (it.next()) |kv| {
        const timer_input = kv.key_ptr.*;
@@ -467,7 +468,7 @@ fn dispatch_check_timers(mepo: *@This()) !void {
    }
}

pub fn init_video_and_sdl_stdin_loop(mepo: *@This(), enable_stdin_jsonapi_repl: bool) !void {
pub fn init_video_and_sdl_stdin_loop(mepo: *Self, enable_stdin_jsonapi_repl: bool) !void {
    if (enable_stdin_jsonapi_repl) {
        const thread = sdl.SDL_CreateThread(
            mepo_sdl_loop_thread_boot,
@@ -491,7 +492,7 @@ pub fn init_video_and_sdl_stdin_loop(mepo: *@This(), enable_stdin_jsonapi_repl:
}

fn mepo_sdl_loop_thread_boot(userdata: ?*anyopaque) callconv(.C) c_int {
    const mepo: *@This() = @alignCast(@ptrCast(userdata.?));
    const mepo: *Self = @alignCast(@ptrCast(userdata.?));
    video_init(mepo) catch unreachable;
    mepo.jsonapi_execute(mepo.config) catch unreachable;
    mepo.initialized_video.set();
@@ -499,7 +500,7 @@ fn mepo_sdl_loop_thread_boot(userdata: ?*anyopaque) callconv(.C) c_int {
    return 0;
}

pub fn sdl_event_loop(mepo: *@This()) !void {
pub fn sdl_event_loop(mepo: *Self) !void {
    var pending: types.Pending = .None;
    var e: sdl.SDL_Event = undefined;

@@ -546,7 +547,7 @@ pub fn sdl_event_loop(mepo: *@This()) !void {
    }
}

pub fn update_debug_message(mepo: *@This(), new_msg_opt: ?[]const u8) !void {
pub fn update_debug_message(mepo: *Self, new_msg_opt: ?[]const u8) !void {
    if (mepo.debug_message) |dbg_msg| mepo.allocator.free(dbg_msg);
    if (new_msg_opt) |new_msg| {
        mepo.debug_message = try mepo.allocator.dupe(u8, new_msg);
@@ -563,7 +564,7 @@ pub fn update_debug_message(mepo: *@This(), new_msg_opt: ?[]const u8) !void {
// This is used in several places as its more reliable then motion/button
// events which seem to have some issue with SetLogicalSize in certain
// platforms as of SDL 2.0.22
pub fn scaled_mouse_position(mepo: *@This()) sdl.SDL_Point {
pub fn scaled_mouse_position(mepo: *Self) sdl.SDL_Point {
    var cursor_x: c_int = undefined;
    var cursor_y: c_int = undefined;
    var gl_w: c_int = undefined;
@@ -580,7 +581,7 @@ pub fn scaled_mouse_position(mepo: *@This()) sdl.SDL_Point {
    return .{ .x = @intFromFloat(scaled_x), .y = @intFromFloat(scaled_y) };
}

pub fn cursor_latlon(mepo: *@This()) struct { Lat: f64, Lon: f64 } {
pub fn cursor_latlon(mepo: *Self) struct { Lat: f64, Lon: f64 } {
    const cursor = mepo.scaled_mouse_position();

    const cursor_lat = utilconversion.px_y_to_lat(
@@ -598,23 +599,23 @@ pub fn cursor_latlon(mepo: *@This()) struct { Lat: f64, Lon: f64 } {
    };
}

pub fn get_x(_: *@This()) i32 {
pub fn get_x(_: *Self) i32 {
    return utilconversion.lon_to_px_x(p.get(p.pref.lon).f, p.get(p.pref.zoom).u);
}

pub fn get_y(_: *@This()) i32 {
pub fn get_y(_: *Self) i32 {
    return utilconversion.lat_to_px_y(p.get(p.pref.lat).f, p.get(p.pref.zoom).u);
}

pub fn set_x(_: *@This(), x: i32) void {
pub fn set_x(_: *Self, x: i32) void {
    p.set_n(p.pref.lon, utilconversion.px_x_to_lon(x, p.get(p.pref.zoom).u));
}

pub fn set_y(_: *@This(), y: i32) void {
pub fn set_y(_: *Self, y: i32) void {
    p.set_n(p.pref.lat, utilconversion.px_y_to_lat(y, p.get(p.pref.zoom).u));
}

pub fn bounding_box(mepo: *@This()) types.LatLonBox {
pub fn bounding_box(mepo: *Self) types.LatLonBox {
    return .{
        .topleft_lat = utilconversion.px_y_to_lat(mepo.get_y() - @as(i32, @intCast(mepo.win_h / 2)), p.get(p.pref.zoom).u),
        .topleft_lon = utilconversion.px_x_to_lon(mepo.get_x() - @as(i32, @intCast(mepo.win_w / 2)), p.get(p.pref.zoom).u),
@@ -737,11 +738,11 @@ fn setup_sdl_video_and_window(allocator: std.mem.Allocator) !*sdl.SDL_Window {
    };
}

pub fn blit(mepo: *@This()) !void {
pub fn blit(mepo: *Self) !void {
    return blitfns.blit(mepo);
}

pub fn video_init(mepo: *@This()) !void {
pub fn video_init(mepo: *Self) !void {
    mepo.window = try setup_sdl_video_and_window(mepo.allocator);
    mepo.renderer = renderer: {
        const r = try utilsdl.errorcheck_ptr(sdl.SDL_Renderer, sdl.SDL_CreateRenderer(
@@ -780,8 +781,8 @@ fn init_create_fonts_array(bold: bool) ![50]*sdl.TTF_Font {
    return fonts;
}

pub fn init(allocator: std.mem.Allocator, tile_cache: *TileCache, use_config: []const u8, renderer_type: types.RendererType) anyerror!@This() {
    return @as(@This(), .{
pub fn init(allocator: std.mem.Allocator, tile_cache: *TileCache, use_config: []const u8, renderer_type: types.RendererType) anyerror!Self {
    return Self{
        .allocator = allocator,
        .blit_pinlayer_cache = datastructure.EvictionHashMap(
            types.XYZ,
@@ -821,5 +822,5 @@ pub fn init(allocator: std.mem.Allocator, tile_cache: *TileCache, use_config: []
            break :b uibuttons;
        },
        .renderer_type = renderer_type,
    });
    };
}
diff --git a/src/TileCache.zig b/src/TileCache.zig
index a4a415343c35..f1fcb20a14ef 100644
--- a/src/TileCache.zig
+++ b/src/TileCache.zig
@@ -40,6 +40,7 @@ const TileData = union(TileDataTag) {
const TileDataTag = enum { transfer_datum, texture, queued_position, error_type };
const QueuedInfo = struct { n_queued: usize, n_cached: usize };

const Self = @This();
allocator: std.mem.Allocator,
dev_null_fd: ?*cstdio.FILE,
thread_download: ?*sdl.SDL_Thread = null,
@@ -57,7 +58,7 @@ transfer_map: datastructure.QueueHashMap(types.XYZ, *TransferDatum),
/// Downloads tiles continuously
/// If graphical_mode is true, will idle even when queue_lifo is empty.
/// If graphical_mode is false, will terminate once queue_lifo is empty.
pub fn download_loop(tile_cache: *@This(), graphical_mode: bool) !void {
pub fn download_loop(tile_cache: *Self, graphical_mode: bool) !void {
    const initial_queue_bg_size = tile_cache.queue_lifo_bg.count();
    var ui_last_update_ticks = sdl.SDL_GetTicks();
    var running: c_int = undefined;
@@ -117,7 +118,7 @@ pub fn download_loop(tile_cache: *@This(), graphical_mode: bool) !void {

/// Sets the cache URL, making copy of str
/// Caller passed ptr url may be safely freed
pub fn set_cache_url(tile_cache: *@This(), url: [:0]const u8) !void {
pub fn set_cache_url(tile_cache: *Self, url: [:0]const u8) !void {
    if (tile_cache.thread_download != null) {
        // Set's network off (cancels inprogress transfers, resumes on switch)
        tile_cache.set_network(false);
@@ -133,7 +134,7 @@ pub fn set_cache_url(tile_cache: *@This(), url: [:0]const u8) !void {
    try p.set_t(tile_cache.allocator, p.pref.tile_cache_url, url);
}

pub fn set_cache_dir(tile_cache: *@This(), path: [:0]const u8) !void {
pub fn set_cache_dir(tile_cache: *Self, path: [:0]const u8) !void {
    try p.set_t(tile_cache.allocator, p.pref.tile_cache_dir, path);

    const expanded_path = try utilfile.wordexp_filepath(tile_cache.allocator, p.get(p.pref.tile_cache_dir).t.?);
@@ -144,7 +145,7 @@ pub fn set_cache_dir(tile_cache: *@This(), path: [:0]const u8) !void {

/// E.g. esentially the one function responsibel for launching/termination
/// of the download thread
pub fn set_network(tile_cache: *@This(), enable: bool) void {
pub fn set_network(tile_cache: *Self, enable: bool) void {
    tile_cache.set_queue(null);
    if (!enable and tile_cache.thread_download != null) {
        const orphan_thread = tile_cache.thread_download.?;
@@ -161,7 +162,7 @@ pub fn set_network(tile_cache: *@This(), enable: bool) void {

/// E.g. essentially the one function responsible for launching/termination
/// of the queuer thread
pub fn set_queue(tile_cache: *@This(), dl_req_opt: ?DownloadBBoxRequest) void {
pub fn set_queue(tile_cache: *Self, dl_req_opt: ?DownloadBBoxRequest) void {
    // Cancel any existing queueing thread
    if (tile_cache.thread_queuebbox) |thread_queuebbox| {
        const orphan_thread = thread_queuebbox;
@@ -184,7 +185,7 @@ pub fn set_queue(tile_cache: *@This(), dl_req_opt: ?DownloadBBoxRequest) void {
    }
}

pub fn tile_bg_bbox_queue(tile_cache: *@This(), dl_req: DownloadBBoxRequest, cancellable: bool) !QueuedInfo {
pub fn tile_bg_bbox_queue(tile_cache: *Self, dl_req: DownloadBBoxRequest, cancellable: bool) !QueuedInfo {
    if (cancellable and tile_cache.thread_download == null) return error.NoDownloadThread;

    const lat_min = if (dl_req.a_lat < dl_req.b_lat) dl_req.a_lat else dl_req.b_lat;
@@ -238,7 +239,7 @@ pub fn tile_bg_bbox_queue(tile_cache: *@This(), dl_req: DownloadBBoxRequest, can
/// thread and thus is safe to use renderer functions within (e.g. we transfer
/// the SDL surface into a texture here)
/// TODO: maybe just move this fn/code wholesale into Mepo.zig?
pub fn tile_ui_retreive_or_queue(tile_cache: *@This(), coords: types.XYZ) !TileData {
pub fn tile_ui_retreive_or_queue(tile_cache: *Self, coords: types.XYZ) !TileData {
    var file_cached_png_opt: ?[]u8 = null;

    if (tile_cache.texture_map.get(coords)) |texture| {
@@ -281,7 +282,7 @@ pub fn tile_ui_retreive_or_queue(tile_cache: *@This(), coords: types.XYZ) !TileD
// ////////////////////////////////////////////////////////////////////////////
// Private

fn curl_add_to_multi_and_register_transfer(tile_cache: *@This(), coords: types.XYZ, load_to_texture: bool) !void {
fn curl_add_to_multi_and_register_transfer(tile_cache: *Self, coords: types.XYZ, load_to_texture: bool) !void {
    if (tile_cache.transfer_map.get(coords)) |_| return;

    const transfer_datum: *TransferDatum = datum: {
@@ -360,7 +361,7 @@ fn curl_errorcheck(response: curl.CURLMcode) !void {
    return error.CurlMultiFail;
}

fn curl_client_to_coords(tile_cache: *@This(), client: ?*curl.CURL) ?types.XYZ {
fn curl_client_to_coords(tile_cache: *Self, client: ?*curl.CURL) ?types.XYZ {
    var it = tile_cache.transfer_map.iterator();
    while (it.next()) |kv| {
        if (kv.value_ptr.*.client == client) {
@@ -376,7 +377,7 @@ fn curl_setopt(client: *curl.CURL, opt: c_int, value: anytype) !void {
}

/// Show progress indicator for the download loop (for non interactive downloading)
fn download_loop_progress_indicator(tile_cache: *@This(), initial_queue_size: usize) void {
fn download_loop_progress_indicator(tile_cache: *Self, initial_queue_size: usize) void {
    std.debug.print("\x1b[1;1H\x1b[2J", .{});
    std.debug.print(
        \\Mepo - download mode
@@ -396,13 +397,13 @@ fn download_loop_progress_indicator(tile_cache: *@This(), initial_queue_size: us

/// Determine whether the download loop should continue based on either
/// if in graphical mode or non-empty queu
fn download_loop_should_continue(tile_cache: *@This(), graphical_mode: bool) bool {
fn download_loop_should_continue(tile_cache: *Self, graphical_mode: bool) bool {
    const graphical_and_online = (graphical_mode and tile_cache.thread_download != null);
    const nongraphical_and_pending = (!graphical_mode and (tile_cache.queue_lifo_bg.count() > 0 or tile_cache.transfer_map.count() > 0));
    return graphical_and_online or nongraphical_and_pending;
}

fn download_loop_transfer_complete(tile_cache: *@This(), msg: *curl.CURLMsg) !void {
fn download_loop_transfer_complete(tile_cache: *Self, msg: *curl.CURLMsg) !void {
    switch (msg.data.result) {
        curl.CURLE_OPERATION_TIMEDOUT => {
            utildbg.log("Curl timed out for msg: {}\n", .{msg});
@@ -447,7 +448,7 @@ fn download_loop_transfer_complete(tile_cache: *@This(), msg: *curl.CURLMsg) !vo
/// SDL resize (refresh event). By effect, if tile is loaded in texture
/// map rendering thread fetches and updates it; if CURLE_OK wasn't
/// there - the item will get repushed back into queue
fn download_loop_transfer_cleanup(tile_cache: *@This(), client: ?*curl.CURL) !void {
fn download_loop_transfer_cleanup(tile_cache: *Self, client: ?*curl.CURL) !void {
    if (tile_cache.curl_client_to_coords(client)) |coords| {
        const transfer_datum = tile_cache.transfer_map.get(coords).?;
        tile_cache.transfer_map.get(coords).?.data_arraylist.deinit();
@@ -463,7 +464,7 @@ fn evict_texture(_: types.XYZ, texture: *sdl.SDL_Texture) void {
    sdl.SDL_DestroyTexture(texture);
}

fn load_data_to_surface(_: *@This(), data: []u8) !*sdl.SDL_Surface {
fn load_data_to_surface(_: *Self, data: []u8) !*sdl.SDL_Surface {
    if (data.len == 0) return error.LoadToSurfaceFailEmptyData;

    const memory = try utilsdl.errorcheck_ptr(sdl.SDL_RWops, sdl.SDL_RWFromConstMem(@ptrCast(&data[0]), @intCast(data.len)));
@@ -482,7 +483,7 @@ fn png_path(allocator: std.mem.Allocator, source: []const u8, coords: types.XYZ)

/// Check whether tile is already in the filesystem and not expired according
/// to creation time & expiry seconds setting
fn tile_exists_in_fs_and_non_expired(tile_cache: *@This(), coords: types.XYZ) !bool {
fn tile_exists_in_fs_and_non_expired(tile_cache: *Self, coords: types.XYZ) !bool {
    if (tile_cache.cache_dir) |cache_dir| {
        const png = try png_path(tile_cache.allocator, p.get(p.pref.tile_cache_url).t.?, coords);
        defer tile_cache.allocator.free(png);
@@ -497,7 +498,7 @@ fn tile_exists_in_fs_and_non_expired(tile_cache: *@This(), coords: types.XYZ) !b
}

fn threadable_tile_bg_bbox_queue(userdata: ?*anyopaque) callconv(.C) c_int {
    const tile_cache: *@This() = @alignCast(@ptrCast(userdata.?));
    const tile_cache: *Self = @alignCast(@ptrCast(userdata.?));
    if (tile_cache.tile_bg_bbox_queue(tile_cache.bbox_queue.?, true)) |q| {
        utildbg.log("Done: {}\n", .{q});
    } else |err| {
@@ -508,16 +509,16 @@ fn threadable_tile_bg_bbox_queue(userdata: ?*anyopaque) callconv(.C) c_int {
}

fn threadable_download_loop_sdl(userdata: ?*anyopaque) callconv(.C) c_int {
    const tile_cache: *@This() = @alignCast(@ptrCast(userdata.?));
    const tile_cache: *Self = @alignCast(@ptrCast(userdata.?));
    tile_cache.download_loop(true) catch |e| {
        utildbg.log("Error running download loop: {}\n", .{e});
    };
    return 0;
}

pub fn init(allocator: std.mem.Allocator) anyerror!@This() {
pub fn init(allocator: std.mem.Allocator) anyerror!Self {
    if (curl.curl_multi_init()) |_| {
        var tc = @as(@This(), .{
        var tc = Self{
            .allocator = allocator,
            .dev_null_fd = cstdio.fopen("/dev/null", "wb"),
            .curl_multi = curl.curl_multi_init().?,
@@ -525,7 +526,7 @@ pub fn init(allocator: std.mem.Allocator) anyerror!@This() {
            .queue_lifo_bg = datastructure.QueueHashMap(types.XYZ, void).init(allocator),
            .texture_map = datastructure.EvictionHashMap(types.XYZ, *sdl.SDL_Texture, evict_texture, &config.MaxTextures).init(allocator),
            .transfer_map = datastructure.QueueHashMap(types.XYZ, *TransferDatum).init(allocator),
        });
        };
        try tc.set_cache_url(try allocator.dupeZ(u8, "https://tile.openstreetmap.org/%3$d/%1$d/%2$d.png"));
        return tc;
    } else {
diff --git a/src/datastructure/EvictionHashMap.zig b/src/datastructure/EvictionHashMap.zig
index 9ee65c0a0889..ee3246ca7945 100644
--- a/src/datastructure/EvictionHashMap.zig
+++ b/src/datastructure/EvictionHashMap.zig
@@ -2,29 +2,30 @@ const std = @import("std");

pub fn EvictionHashMap(comptime key_type: type, comptime metadata_type: type, comptime eviction_function: fn (key_type, metadata_type) void, comptime size: *usize) type {
    return struct {
        const Self = @This();
        array_hash_map: std.array_hash_map.AutoArrayHashMap(key_type, metadata_type),
        size: *usize,
        mutex: std.Thread.Mutex,

        pub fn count(self: *@This()) usize {
        pub fn count(self: *Self) usize {
            self.mutex.lock();
            defer self.mutex.unlock();
            return self.array_hash_map.count();
        }

        pub fn get(self: *@This(), key: key_type) ?metadata_type {
        pub fn get(self: *Self, key: key_type) ?metadata_type {
            self.mutex.lock();
            defer self.mutex.unlock();
            return self.array_hash_map.get(key);
        }

        pub fn values(self: *@This()) []metadata_type {
        pub fn values(self: *Self) []metadata_type {
            self.mutex.lock();
            defer self.mutex.unlock();
            return self.array_hash_map.values();
        }

        pub fn put(self: *@This(), k: key_type, v: metadata_type) !?metadata_type {
        pub fn put(self: *Self, k: key_type, v: metadata_type) !?metadata_type {
            self.mutex.lock();
            defer self.mutex.unlock();

@@ -32,7 +33,7 @@ pub fn EvictionHashMap(comptime key_type: type, comptime metadata_type: type, co
            return if (self.array_hash_map.count() > self.size.*) return self.shift() else null;
        }

        fn shift(self: *@This()) !metadata_type {
        fn shift(self: *Self) !metadata_type {
            const shifted_key = self.array_hash_map.keys()[0];
            const shifted_val = self.array_hash_map.values()[0];
            self.array_hash_map.orderedRemoveAt(0);
@@ -40,7 +41,7 @@ pub fn EvictionHashMap(comptime key_type: type, comptime metadata_type: type, co
            return shifted_val;
        }

        pub fn clearAndFree(self: *@This()) void {
        pub fn clearAndFree(self: *Self) void {
            self.mutex.lock();
            defer self.mutex.unlock();
            var it = self.array_hash_map.iterator();
@@ -48,12 +49,12 @@ pub fn EvictionHashMap(comptime key_type: type, comptime metadata_type: type, co
            self.array_hash_map.clearAndFree();
        }

        pub fn init(allocator: std.mem.Allocator) @This() {
            return @as(@This(), .{
        pub fn init(allocator: std.mem.Allocator) Self {
            return .{
                .size = size,
                .mutex = std.Thread.Mutex{},
                .array_hash_map = std.array_hash_map.AutoArrayHashMap(key_type, metadata_type).init(allocator),
            });
            };
        }
    };
}
diff --git a/src/datastructure/QueueHashMap.zig b/src/datastructure/QueueHashMap.zig
index a76b64926979..9cb7996a6123 100644
--- a/src/datastructure/QueueHashMap.zig
+++ b/src/datastructure/QueueHashMap.zig
@@ -10,31 +10,32 @@ const std = @import("std");
//      running put() and then pop() ensures the same item is referenced
pub fn QueueHashMap(comptime key_type: type, comptime metadata_type: type) type {
    return struct {
        const Self = @This();
        array_hash_map: std.array_hash_map.AutoArrayHashMap(key_type, metadata_type),
        mutex: std.Thread.Mutex,

        pub fn count(self: *@This()) usize {
        pub fn count(self: *Self) usize {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.count();
        }

        pub fn get(self: *@This(), key: key_type) ?metadata_type {
        pub fn get(self: *Self, key: key_type) ?metadata_type {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.get(key);
        }

        pub fn getPtr(self: *@This(), key: key_type) ?*metadata_type {
        pub fn getPtr(self: *Self, key: key_type) ?*metadata_type {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.getPtr(key);
        }

        pub fn pop(self: *@This()) struct { key: key_type, value: metadata_type } {
        pub fn pop(self: *Self) struct { key: key_type, value: metadata_type } {
            self.mutex.lock();
            defer self.mutex.unlock();

@@ -42,35 +43,35 @@ pub fn QueueHashMap(comptime key_type: type, comptime metadata_type: type) type
            return .{ .key = popped.key, .value = popped.value };
        }

        pub fn getIndex(self: *@This(), key: key_type) ?usize {
        pub fn getIndex(self: *Self, key: key_type) ?usize {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.getIndex(key);
        }

        pub fn swapRemove(self: *@This(), key: key_type) bool {
        pub fn swapRemove(self: *Self, key: key_type) bool {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.swapRemove(key);
        }

        pub fn values(self: *@This()) []metadata_type {
        pub fn values(self: *Self) []metadata_type {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.values();
        }

        pub fn iterator(self: *@This()) std.array_hash_map.AutoArrayHashMap(key_type, metadata_type).Iterator {
        pub fn iterator(self: *Self) std.array_hash_map.AutoArrayHashMap(key_type, metadata_type).Iterator {
            self.mutex.lock();
            defer self.mutex.unlock();

            return self.array_hash_map.iterator();
        }

        pub fn put(self: *@This(), k: key_type, v: metadata_type) !void {
        pub fn put(self: *Self, k: key_type, v: metadata_type) !void {
            self.mutex.lock();
            defer self.mutex.unlock();

@@ -82,18 +83,18 @@ pub fn QueueHashMap(comptime key_type: type, comptime metadata_type: type) type
            try self.array_hash_map.put(k, v);
        }

        pub fn clearAndFree(self: *@This()) void {
        pub fn clearAndFree(self: *Self) void {
            self.mutex.lock();
            defer self.mutex.unlock();

            self.array_hash_map.clearAndFree();
        }

        pub fn init(allocator: std.mem.Allocator) @This() {
            return @as(@This(), .{
        pub fn init(allocator: std.mem.Allocator) Self {
            return .{
                .mutex = std.Thread.Mutex{},
                .array_hash_map = std.array_hash_map.AutoArrayHashMap(key_type, metadata_type).init(allocator),
            });
            };
        }
    };
}
diff --git a/src/types.zig b/src/types.zig
index 9af0158b35b7..aa01170b01ef 100644
--- a/src/types.zig
+++ b/src/types.zig
@@ -66,7 +66,7 @@ pub const Color = struct {

    const RGBA = packed struct { r: u8, g: u8, b: u8, a: u8 };

    fn to_rgba(self: @This()) RGBA {
    fn to_rgba(self: Color) RGBA {
        return .{
            .r = @intCast(self.value >> 16),
            .g = @intCast(self.value >> 8 & 0xff),
@@ -75,12 +75,12 @@ pub const Color = struct {
        };
    }

    pub fn to_sdl(self: @This()) sdl.SDL_Color {
    pub fn to_sdl(self: Color) sdl.SDL_Color {
        const rgba = self.to_rgba();
        return .{ .r = rgba.r, .g = rgba.g, .b = rgba.b, .a = rgba.a };
    }

    pub fn to_u32(self: @This()) u32 {
    pub fn to_u32(self: Color) u32 {
        return @bitCast(self.to_rgba());
    }
};
-- 
2.45.2







      
      

[PATCH mepo v2 2/2] Signal unused param at function signature Export this patch

---
 src/Mepo.zig | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/Mepo.zig b/src/Mepo.zig
index 3b4e371bbf20..d8c28d6a360d 100644
--- a/src/Mepo.zig
+++ b/src/Mepo.zig
@@ -326,9 +326,8 @@ pub fn event_quit(mepo: *Self, _: sdl.SDL_Event) types.Pending {
    return .None;
}

fn event_unhandled(_: *Self, e: sdl.SDL_Event) types.Pending {
fn event_unhandled(_: *Self, _: sdl.SDL_Event) types.Pending {
    //utildbg.log("Unhandled SDL Event: {s}\n", .{@tagName(@intToEnum(sdl.SDL_EventType, @intCast(c_int, e.type)))});
    _ = e;
    return .None;
}

-- 
2.45.2