Compare commits
3 Commits
8637731c60
...
17e3e0397f
Author | SHA1 | Date | |
---|---|---|---|
17e3e0397f | |||
1486e5a9e0 | |||
deedd02efd |
@ -8,6 +8,10 @@
|
||||
|
||||
(import-macros { : define-tests : expect : expect= } :assert)
|
||||
|
||||
(local profile
|
||||
(and (os.getenv "IN_NIX_SHELL")
|
||||
(require :libluaperf)))
|
||||
|
||||
(macro with-timing [label & body]
|
||||
`(let [before# (ptime.clock_gettime ptime.CLOCK_PROCESS_CPUTIME_ID)
|
||||
ret# (table.pack (do ,body))]
|
||||
@ -58,13 +62,17 @@ label.readout {
|
||||
)
|
||||
(style_provider:load_from_data CSS)))
|
||||
|
||||
(fn main-quit []
|
||||
(when profile (profile:stop))
|
||||
(Gtk.main_quit))
|
||||
|
||||
(local window (Gtk.Window {
|
||||
:title "Map"
|
||||
:name "toplevel"
|
||||
:default_width viewport-width
|
||||
:default_height viewport-height
|
||||
|
||||
:on_destroy Gtk.main_quit
|
||||
:on_destroy main-quit
|
||||
}))
|
||||
|
||||
(local state-widgets { })
|
||||
@ -150,38 +158,38 @@ label.readout {
|
||||
|
||||
(local cq (cqueues.new))
|
||||
|
||||
(fn road-width-for [line offset]
|
||||
(+ (or offset 0)
|
||||
(case (?. line :tags :highway)
|
||||
:motorway 18
|
||||
:trunk 17
|
||||
:primary 16
|
||||
:secondary 14
|
||||
:cycleway 4
|
||||
:footway 4
|
||||
other 12)))
|
||||
|
||||
(fn cairo-road-path [g [[sx sy] & points] bounds width]
|
||||
(g:save)
|
||||
(g:set_line_width width)
|
||||
(g:move_to (* tile-size (- sx bounds.min.x))
|
||||
(* tile-size (- sy bounds.min.y)))
|
||||
(each [_ [x y] (ipairs points)]
|
||||
(let [x1 (* tile-size (- x bounds.min.x))
|
||||
y1 (* tile-size (- y bounds.min.y))]
|
||||
(g:line_to x1 y1)))
|
||||
(g:stroke)
|
||||
(g:restore))
|
||||
(fn road-width-for [line]
|
||||
(case (?. line :tags :highway)
|
||||
:motorway 18
|
||||
:trunk 17
|
||||
:primary 16
|
||||
:secondary 14
|
||||
:cycleway 4
|
||||
:footway 4
|
||||
other 12))
|
||||
|
||||
(fn cairo-road-path [g [[sx sy] & points] bounds]
|
||||
(let [min bounds.min
|
||||
{ : line_to } g]
|
||||
(g:move_to (* tile-size (- sx min.x))
|
||||
(* tile-size (- sy min.y)))
|
||||
(each [_ [x y] (ipairs points)]
|
||||
(let [x1 (* tile-size (- x min.x))
|
||||
y1 (* tile-size (- y min.y))]
|
||||
(line_to g x1 y1)))))
|
||||
|
||||
(fn cairo-roads [g lines bounds]
|
||||
(let [road-width 14]
|
||||
(g:set_source_rgb 0 0 0)
|
||||
(each [_ line (pairs lines)]
|
||||
(cairo-road-path g line.points bounds (road-width-for line)))
|
||||
(g:set_source_rgb 1 1 1)
|
||||
(each [_ line (pairs lines)]
|
||||
(cairo-road-path g line.points bounds (road-width-for line -2)))))
|
||||
(g:set_source_rgb 0 0 0)
|
||||
(each [_ line (pairs lines)]
|
||||
(g:set_line_width (road-width-for line))
|
||||
(cairo-road-path g line.points bounds )
|
||||
(g:stroke))
|
||||
(g:set_source_rgb 1 1 1)
|
||||
(each [_ line (pairs lines)]
|
||||
(g:set_line_width (- (road-width-for line) 2))
|
||||
(cairo-road-path g line.points bounds)
|
||||
(g:stroke)))
|
||||
|
||||
|
||||
(var map-surface nil)
|
||||
|
||||
@ -453,6 +461,15 @@ label.readout {
|
||||
true)
|
||||
nil nil)
|
||||
|
||||
(fn collect-profile []
|
||||
(GLib.timeout_add
|
||||
GLib.PRIORITY_DEFAULT
|
||||
(* 60 1000) main-quit
|
||||
nil nil)
|
||||
(print "profiling for 60 seconds")
|
||||
(profile.start 0))
|
||||
|
||||
|
||||
(window:add
|
||||
(doto (Gtk.Overlay {})
|
||||
(: :add (osm-widget))
|
||||
@ -463,4 +480,5 @@ label.readout {
|
||||
|
||||
(window:show_all)
|
||||
(styles)
|
||||
(when (os.getenv "MAP_PROFILE") (collect-profile))
|
||||
(Gtk:main)
|
||||
|
@ -16,13 +16,34 @@ let
|
||||
};
|
||||
};
|
||||
fennel-ls = pkgs.fennel-ls.override { inherit (package) lua luaPackages; };
|
||||
luaProfiler =
|
||||
let
|
||||
inherit (pkgs) stdenv cmake;
|
||||
inherit (package) lua;
|
||||
in stdenv.mkDerivation {
|
||||
name = "LuaProfiler";
|
||||
src = fetchFromGitHub {
|
||||
owner = "Patrick08T";
|
||||
repo = "LuaProfiler";
|
||||
rev = "abb989337f6f46b820c9d2eb1e1d339e8f6f3760";
|
||||
hash = "sha256-43kwZCZZmWD5ens1qCzD7LTg/jKMfcb9Vw/DBiN2sSo=";
|
||||
};
|
||||
buildInputs = [ lua ];
|
||||
installPhase = ''
|
||||
mkdir -p "$out/lib/lua/${lua.luaversion}"
|
||||
echo cp /build/source/bin/release/libluaperf.so "$out/lib/lua/${lua.luaversion}"
|
||||
cp /build/source/bin/release/libluaperf.so "$out/lib/lua/${lua.luaversion}"
|
||||
'';
|
||||
nativeBuildInputs = [ cmake ];
|
||||
};
|
||||
in
|
||||
package.overrideAttrs(o: {
|
||||
nativeBuildInputs = [ fennel-ls ] ++ o.nativeBuildInputs;
|
||||
nativeBuildInputs = [ fennel-ls luaProfiler flamegraph ] ++ o.nativeBuildInputs;
|
||||
shellHook = ''
|
||||
mkdir -p bin
|
||||
( cd bin && ln -sf `type -p fennel-ls` `type -p fennel` . )
|
||||
export LUA_CPATH=$(lua -e "print(package.cpath)")
|
||||
export LUA_CPATH=$(lua -e "print(package.cpath)")\;${luaProfiler}/lib/lua/${package.lua.luaversion}/\?.so
|
||||
export LUA_PATH=$(lua -e "print(package.path)")\;$RXI_JSON/share/lua/5.3/?.lua
|
||||
|
||||
'';
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user