Compare commits

..
14 Commits
Author SHA1 Message Date
meehl 3eacd43837 chore: Release rusty-path-of-building version 0.2.9
Release / create-release (push) Successful in 6s
2025-12-03 16:10:25 +01:00
meehl 523d5ffe29 Update CHANGELOG 2025-12-03 16:09:53 +01:00
meehl e18623edb4 Update README 2025-11-30 11:22:18 +01:00
meehl 1812edcbe9 Implement UI scale overriding
Closes #16
2025-11-30 11:16:04 +01:00
meehl df06c8f9c6 installer: Download highest supported version instead of latest version
Closes #17
2025-11-30 10:05:43 +01:00
meehl ae6a24f82c Reduce CPU usage while window is unfocused and not hovered over
Only render if window is focused, hovered, subscript is running,
or coroutine is active.

Closes #18
2025-11-28 18:30:25 +01:00
meehl 0066a05e13 Register AbortSubscript function under right name 2025-11-27 10:54:43 +01:00
meehl 3d8143c4d1 Add help text to import url argument 2025-11-27 10:54:43 +01:00
meehl a3ef4b39d0 Remove unneeded 'return' statement 2025-11-27 10:54:43 +01:00
meehl f48ab50633 Create CONTRIBUTING.md 2025-11-23 20:51:17 +01:00
meehl b86486d5aa Move config.yml into right directory 2025-11-23 18:05:05 +01:00
meehl 1f1a331cc2 Create config.yml 2025-11-23 18:01:45 +01:00
meehl 27b93c4a9d Update issue templates 2025-11-23 17:48:35 +01:00
meehl c95514036f Fix compiler warning caused by uninitialized variable 2025-11-22 13:48:13 +01:00
19 changed files with 437 additions and 69 deletions

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
# Contributing to Rusty Path Of Building
## Reporting bugs
- Ensure the bug was not already reported by searching through existing [issues](https://github.com/meehl/rusty-path-of-building/issues).
- If the bug can also be reproduced with the official runtime (e.g. by running through wine), please open an issue in the [PoB1](https://github.com/PathOfBuildingCommunity/PathOfBuilding) or [PoB2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2) repo instead. If you're unsure, feel free to just open it here.
- If possible, use the bug report template to create the issue and provide as much information as possible.
## Contributing code
- Get familiar with the code base before you start. I'll try to add more documentation providing a high-level overview of the architecture in the future. Until then, feel free to reach out through [Discussions](https://github.com/meehl/rusty-path-of-building/discussions) if you have any questions.
- If you intend to work on the API functions, also check out the [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) code base. A great place to ask questions about it is the PoB dev discord server. [Here](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) is more info on how to join.
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
+30
View File
@@ -0,0 +1,30 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A description of what you expected to happen.
**System information:**
- OS: [e.g. Linux, Windows, macOS]
- Desktop Environment/Compositor: [e.g. KDE, Gnome, sway, etc.] (only on Linux)
- Rusty Path of Building Version: [e.g. v0.2.8]
- Path of Building Version: [e.g. PoB1 v2.59.0 or PoB2 v0.12.2]
**Additional context**
Add any other context about the problem here. Feel free to add screenshots or any other info like PoB build codes if relevant.
+5
View File
@@ -0,0 +1,5 @@
blank_issues_enabled: yes
contact_links:
- name: GitHub Discussions
url: https://github.com/meehl/rusty-path-of-building/discussions
about: Please ask questions unrelated to actual bugs/issues here.
+17 -1
View File
@@ -2,6 +2,21 @@
## [Unreleased] - ReleaseDate
## [0.2.9] - 2025-12-03
### Added
- Implement UI scale overriding
### Changed
- Reduce CPU usage while window is unfocused and not hovered over
- Download highest compatible PoB version instead of latest version
### Fixed
- Register `AbortSubscript` function under right name
## [0.2.8] - 2025-11-07
### Changed
@@ -118,8 +133,9 @@
- First release
<!-- next-url -->
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...HEAD
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.9...HEAD
[0.2.9]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...v0.2.9
[0.2.8]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...v0.2.8
[0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7
[0.2.6]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.5...v0.2.6
Generated
+1 -1
View File
@@ -2506,7 +2506,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "rusty-path-of-building"
version = "0.2.8"
version = "0.2.9"
dependencies = [
"ahash",
"anyhow",
+1 -1
View File
@@ -4,7 +4,7 @@ authors = ["meehl"]
description = "Cross-platform runtime for Path of Building"
repository = "https://github.com/meehl/rusty-path-of-building"
license = "MIT"
version = "0.2.8"
version = "0.2.9"
edition = "2024"
publish = false
-1
View File
@@ -43,5 +43,4 @@ Please refer to the [Lua documentation](https://www.lua.org/manual/5.1/manual.ht
## Known Issues
- Overriding UI scaling through the options is currently not implemented.
- If automatic updates fail, navigate to `~/.local/share/RustyPathOfBuilding{1,2}/` and delete both the `rpob.version` file and the `Update` directory. This will force a complete re-download of PoB's latest assets and Lua code on the next startup. (Note: Third-party backends, like this project, face challenges supporting PoB's update mechanism. To make it work, fragile workarounds had to be implemented that can break unexpectedly)
+1 -1
View File
@@ -646,7 +646,7 @@ static int l_zipFile_Read(lua_State* L)
if (n < 1) {
luaL_error(L, "Usage: zipFile:Read(count) or zipFile:read(\"*a\")");
}
int count;
int count = 0;
if (lua_isnumber(L, 1)) {
count = lua_tointeger(L, 1);
} else {
+4 -7
View File
@@ -390,9 +390,8 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
ctx.layers().set_draw_color(last_segment.color);
}
let layout = ctx.fonts().layout(job, ctx.window().scale_factor);
ctx
.layers()
let layout = ctx.fonts().layout(job, ctx.window().scale_factor());
ctx.layers()
.draw_text(position, layout, is_absolute_position);
0
@@ -415,9 +414,7 @@ unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_in
};
let job = build_layout_job(text, Srgba::WHITE, font_type, line_height, None);
let width = ctx
.fonts()
.get_text_width(job, ctx.window().scale_factor);
let width = ctx.fonts().get_text_width(job, ctx.window().scale_factor());
unsafe { ffi::lua_pushnumber(state, width as f64) };
1
@@ -436,7 +433,7 @@ fn get_index_at_cur(
let index = ctx.fonts().get_text_index_at_cursor(
job,
Point::new(cur_x, cur_y),
ctx.window().scale_factor,
ctx.window().scale_factor(),
);
// convert to lua's 1-based indexing
+14 -6
View File
@@ -18,7 +18,7 @@ pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> {
let ctx = l.app_data_ref::<&'static Context>().unwrap();
let scale_factor = ctx.window().scale_factor;
let scale_factor = ctx.window().scale_factor();
Ok(scale_factor)
}
@@ -34,12 +34,20 @@ pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> {
Ok(())
}
pub fn set_dpi_scale_override(_: &Lua, _percent: i32) -> LuaResult<()> {
// TODO:
pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
let socket = l.app_data_ref::<&'static Context>().unwrap();
match percent {
0 => socket.window().scale_factor_override = None,
p if p > 0 => socket.window().scale_factor_override = Some(p as f32 / 100.0),
_ => {}
}
Ok(())
}
pub fn get_dpi_scale_override(_: &Lua, _: ()) -> LuaResult<i32> {
// TODO:
Ok(0)
pub fn get_dpi_scale_override(l: &Lua, _: ()) -> LuaResult<i32> {
let socket = l.app_data_ref::<&'static Context>().unwrap();
match socket.window().scale_factor_override {
Some(scale_factor) => Ok((scale_factor * 100.0) as i32),
None => Ok(0),
}
}
+66 -29
View File
@@ -19,6 +19,7 @@ use winit::{
struct FrameOutput {
pub render_job: RenderJob,
pub should_continue: bool,
}
pub struct AppState {
@@ -31,7 +32,7 @@ pub struct AppState {
impl AppState {
fn set_mouse_pos(&mut self, pos: PhysicalPoint<f32>) {
self.input
.set_mouse_pos(pos.to_logical(self.window.scale_factor));
.set_mouse_pos(pos.to_logical(self.window.scale_factor()));
}
}
@@ -39,6 +40,7 @@ pub struct App {
gfx_context: Option<GraphicsContext>,
state: AppState,
tessellator: Tessellator,
needs_reconfigure: bool,
force_render: bool,
current_mode: AppMode,
}
@@ -54,7 +56,8 @@ impl App {
texture_manager: WrappedTextureManager::new(),
},
tessellator: Tessellator::default(),
force_render: false,
needs_reconfigure: true,
force_render: true,
current_mode: AppMode::Install(InstallMode::new()),
})
}
@@ -92,12 +95,10 @@ impl App {
{
RenderJob::Skip
} else {
self.force_render = false;
let meshes = self.tessellator.convert_clipped_primitives(
mode_output.primitives,
font_atlas_size,
self.state.window.scale_factor,
self.state.window.scale_factor(),
);
RenderJob::Render {
@@ -106,7 +107,10 @@ impl App {
}
};
Ok(FrameOutput { render_job })
Ok(FrameOutput {
render_job,
should_continue: mode_output.should_continue,
})
}
fn handle_event(&mut self, event: AppEvent) {
@@ -154,7 +158,6 @@ impl ApplicationHandler<GraphicsContext> for App {
if let Err(err) = self.create_window(event_loop) {
log::error!("{err}");
event_loop.exit();
return;
}
}
@@ -178,26 +181,50 @@ impl ApplicationHandler<GraphicsContext> for App {
return;
}
let render_job = match self.frame() {
Ok(FrameOutput { render_job }) => render_job,
Err(err) => {
log::error!("{err}");
event_loop.exit();
return;
if self.needs_reconfigure {
if let Some(ref mut gfx) = self.gfx_context {
let size = gfx.window.inner_size();
gfx.resize(size.width, size.height);
}
};
self.needs_reconfigure = false;
// Render at least one frame after reconfigure
self.force_render = true;
}
if let Some(ref mut gfx) = self.gfx_context {
match gfx.render(render_job) {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
let size = gfx.window.inner_size();
gfx.resize(size.width, size.height);
self.force_render = true;
}
let is_focused = self.state.window.is_focused;
let is_hovered = self.state.window.is_hovered;
let should_render = is_focused || is_hovered || self.force_render;
if should_render {
let FrameOutput {
render_job,
should_continue,
} = match self.frame() {
Ok(frame_output) => frame_output,
Err(err) => {
log::error!("Unable to render: {err}");
log::error!("{err}");
event_loop.exit();
return;
}
};
if let Some(ref mut gfx) = self.gfx_context {
match gfx.render(render_job, self.state.window.scale_factor()) {
Ok(_) => {
self.force_render = should_continue;
if is_focused || is_hovered || should_continue {
self.state.window.request_redraw();
}
}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
self.needs_reconfigure = true;
self.state.window.request_redraw();
}
Err(err) => {
log::error!("Unable to render: {err}");
}
}
}
}
@@ -205,14 +232,17 @@ impl ApplicationHandler<GraphicsContext> for App {
profiling::finish_frame!();
}
WindowEvent::Resized(size) => {
if let Some(ref mut gfx) = self.gfx_context {
gfx.resize(size.width, size.height);
self.force_render = true;
}
self.state.window.size = PhysicalSize::new(size.width, size.height);
self.needs_reconfigure = true;
}
WindowEvent::Focused(focused) => {
self.state.window.is_focused = focused;
if focused {
self.state.window.request_redraw();
}
}
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
self.state.window.scale_factor = scale_factor as f32;
self.state.window.set_scale_factor(scale_factor as f32);
}
WindowEvent::KeyboardInput {
event:
@@ -265,6 +295,13 @@ impl ApplicationHandler<GraphicsContext> for App {
let pos = PhysicalPoint::new(position.x as f32, position.y as f32);
self.state.set_mouse_pos(pos);
}
WindowEvent::CursorEntered { .. } => {
self.state.window.is_hovered = true;
self.state.window.request_redraw();
}
WindowEvent::CursorLeft { .. } => {
self.state.window.is_hovered = false;
}
WindowEvent::MouseWheel { delta, .. } => {
let delta = match delta {
MouseScrollDelta::LineDelta(_, y) => y,
+4 -1
View File
@@ -9,7 +9,10 @@ pub struct Args {
#[arg(value_enum)]
pub game: Game,
pub build_path: Option<String>,
#[arg(
help = "URL of build to import on startup. Needs to use custom protocol schema, e.g. `pob://pobbin/<id>`"
)]
pub import_url: Option<String>,
}
#[derive(Debug, Clone, ValueEnum)]
+8 -7
View File
@@ -144,11 +144,13 @@ impl GraphicsContext {
}
}
pub fn render(&mut self, render_job: RenderJob) -> Result<(), wgpu::SurfaceError> {
pub fn render(
&mut self,
render_job: RenderJob,
scale_factor: f32,
) -> Result<(), wgpu::SurfaceError> {
profiling::scope!("render");
self.window.request_redraw();
if !self.is_surface_configured {
return Ok(());
}
@@ -174,7 +176,6 @@ impl GraphicsContext {
} = render_job
{
let screen_size = PhysicalSize::new(self.config.width, self.config.height);
let pixels_per_point = self.window.as_ref().scale_factor() as f32;
// upload new textures
self.renderer
@@ -186,7 +187,7 @@ impl GraphicsContext {
&self.queue,
&meshes,
screen_size,
pixels_per_point,
scale_factor,
);
let rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
@@ -214,10 +215,10 @@ impl GraphicsContext {
&mut rpass.forget_lifetime(),
&meshes,
screen_size,
pixels_per_point,
scale_factor,
);
self.renderer.free_textures(&textures_delta)
self.renderer.free_textures(&textures_delta);
}
{
+214 -8
View File
@@ -7,7 +7,6 @@ use crate::{
mode::{AppEvent, ModeFrameOutput, ModeTransition},
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
};
use anyhow::bail;
use flate2::read::GzDecoder;
use parley::{FontFamily, GenericFamily};
use regex::Regex;
@@ -73,6 +72,7 @@ impl InstallMode {
Ok(ModeFrameOutput {
primitives,
can_elide: false,
should_continue: true,
})
}
@@ -137,7 +137,7 @@ impl InstallMode {
};
job.append(&progress_text, Srgba::WHITE);
let layout = app_state.fonts.layout(job, app_state.window.scale_factor);
let layout = app_state.fonts.layout(job, app_state.window.scale_factor());
// center text vertically and horizontally
let screen_size = app_state.window.logical_size().cast::<f32>();
@@ -160,10 +160,10 @@ fn install<P: AsRef<Path>>(
progress_tx: &mpsc::Sender<Progress>,
) -> anyhow::Result<()> {
// Skip installation if version file exists
let current_version = env!("CARGO_PKG_VERSION");
let version_file_path = target_dir.as_ref().join("rpob.version");
if version_file_path.exists() {
let old_version = fs::read_to_string(&version_file_path).unwrap();
let current_version = env!("CARGO_PKG_VERSION");
if old_version != current_version {
log::info!("New version detected: {old_version} -> {current_version}");
@@ -173,7 +173,11 @@ fn install<P: AsRef<Path>>(
return Ok(());
}
download_path_of_building(&target_dir, progress_tx)?;
let compatibility_info = fetch_compatibility_info()?;
let needed_pob_version = highest_supported_pob_version(&compatibility_info, current_version)
.ok_or_else(|| anyhow::anyhow!("Unable to determine supported PoB version"))?;
download_path_of_building(&target_dir, needed_pob_version, progress_tx)?;
replace_updatecheck(&target_dir)?;
set_branch_and_platform(&target_dir)?;
@@ -183,9 +187,73 @@ fn install<P: AsRef<Path>>(
Ok(())
}
/// Downloads latest release of Path of Building
#[derive(Debug)]
struct VersionReq {
pob_ver: String,
min_rpob_ver: String,
}
/// Fetches and evaluates compatibility table
fn fetch_compatibility_info() -> anyhow::Result<Vec<VersionReq>> {
let compatibility_info_file_name = match Game::current() {
Game::Poe1 => "Compatibility_pob1.lua",
Game::Poe2 => "Compatibility_pob2.lua",
};
let compatibility_info_file_url = &format!(
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
compatibility_info_file_name
);
let compatibility_info_file = download_file_contents(compatibility_info_file_url)?;
// Load and evaluate compatibility file contents as Lua code
let lua = mlua::Lua::new();
let compatibility_table = lua.load(compatibility_info_file).eval::<mlua::Table>()?;
// Compatibility table maps PoB version to minimum required Rusty PoB version
Ok(compatibility_table
.pairs::<String, String>()
.filter_map(|p| p.ok())
.map(|(pob_version, min_req_rpob_ver)| VersionReq {
pob_ver: pob_version,
min_rpob_ver: min_req_rpob_ver,
})
.collect())
}
/// Determines highest PoB version supported by given Rusty PoB version
fn highest_supported_pob_version<'a>(
compatibility_info: &'a Vec<VersionReq>,
rpob_version: &str,
) -> Option<&'a str> {
let mut highest_pob_version = None;
for VersionReq {
pob_ver,
min_rpob_ver,
} in compatibility_info
{
if is_higher_version(min_rpob_ver, rpob_version).unwrap_or(false) {
// found PoB version that meets our minimum requirements
match highest_pob_version {
// make sure it is the highest PoB version possible
Some(h_pob_version) => {
if is_higher_version(h_pob_version, pob_ver).unwrap_or(false) {
highest_pob_version = Some(pob_ver.as_str());
}
}
None => highest_pob_version = Some(pob_ver.as_str()),
}
}
}
highest_pob_version
}
/// Downloads specified version of Path of Building
fn download_path_of_building<P: AsRef<Path>>(
target_dir: P,
pob_version: &str,
progress_tx: &mpsc::Sender<Progress>,
) -> anyhow::Result<()> {
log::info!("Downloading Path of Building assets...");
@@ -195,8 +263,8 @@ fn download_path_of_building<P: AsRef<Path>>(
Game::Poe2 => "PathOfBuildingCommunity/PathOfBuilding-PoE2",
};
let url = format!(
"https://github.com/{}/archive/refs/heads/master.tar.gz",
repo
"https://github.com/{}/archive/refs/tags/v{}.tar.gz",
repo, pob_version
);
let mut response = http_get_with_backoff(&url)?;
@@ -302,6 +370,7 @@ fn set_branch_and_platform<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()>
Ok(())
}
/// Downloads file and saves it to given path
fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()> {
let mut response = http_get_with_backoff(url)?;
@@ -311,7 +380,19 @@ fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()>
copy(&mut body.as_reader(), &mut file)?;
Ok(())
} else {
bail!("Unable to download: {}", url);
anyhow::bail!("Unable to download: {}", url);
}
}
/// Downloads file and returns contents as string
fn download_file_contents(url: &str) -> anyhow::Result<String> {
let mut response = http_get_with_backoff(url)?;
if response.status().is_success() {
let body = response.body_mut();
Ok(body.read_to_string()?)
} else {
anyhow::bail!("Unable to download: {}", url);
}
}
@@ -432,3 +513,128 @@ fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
return Ok(resp);
}
}
/// Compares two SemVer versions and returns true if v2 is higher or equal than v1
fn is_higher_version(v1: &str, v2: &str) -> anyhow::Result<bool> {
let re = Regex::new(r"^(\d+)\.(\d+)\.(\d+)$").unwrap();
let parse_version = |v: &str| -> anyhow::Result<(u32, u32, u32)> {
let caps = re
.captures(v)
.ok_or_else(|| anyhow::anyhow!("Invalid semver format: {}", v))?;
let major = caps[1].parse::<u32>().unwrap();
let minor = caps[2].parse::<u32>().unwrap();
let patch = caps[3].parse::<u32>().unwrap();
Ok((major, minor, patch))
};
let (major1, minor1, patch1) = parse_version(v1)?;
let (major2, minor2, patch2) = parse_version(v2)?;
Ok(major2 > major1
|| (major2 == major1 && minor2 > minor1)
|| (major2 == major1 && minor2 == minor1 && patch2 >= patch1))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_major_version() {
assert_eq!(is_higher_version("1.0.0", "2.0.0").unwrap(), true);
assert_eq!(is_higher_version("2.0.0", "1.0.0").unwrap(), false);
}
#[test]
fn test_minor_version() {
assert_eq!(is_higher_version("1.5.0", "1.6.0").unwrap(), true);
assert_eq!(is_higher_version("1.10.0", "1.9.0").unwrap(), false);
}
#[test]
fn test_patch_version() {
assert_eq!(is_higher_version("1.0.3", "1.0.4").unwrap(), true);
assert_eq!(is_higher_version("1.0.10", "1.0.9").unwrap(), false);
}
#[test]
fn test_same_version() {
assert_eq!(is_higher_version("1.5.3", "1.5.3").unwrap(), true);
}
#[test]
fn test_invalid_semver_format() {
assert!(is_higher_version("1.0", "2.0.0").is_err());
assert!(is_higher_version("1.0.0", "2.0").is_err());
assert!(is_higher_version("invalid", "2.0.0").is_err());
assert!(is_higher_version("1.0.0", "a.bb.ccc").is_err());
}
#[test]
fn test_highest_supported_pob_ver() {
let compat_info = vec![
VersionReq {
pob_ver: String::from("2.56.0"),
min_rpob_ver: String::from("0.1.0"),
},
// compat info might not be sorted by pob_version
VersionReq {
pob_ver: String::from("2.58.0"),
min_rpob_ver: String::from("0.2.6"),
},
VersionReq {
pob_ver: String::from("2.57.0"),
min_rpob_ver: String::from("0.2.6"),
},
VersionReq {
pob_ver: String::from("2.58.1"),
min_rpob_ver: String::from("0.2.8"),
},
VersionReq {
pob_ver: String::from("2.59.0"),
min_rpob_ver: String::from("0.2.9"),
},
VersionReq {
pob_ver: String::from("2.59.1"),
min_rpob_ver: String::from("0.2.10"),
},
VersionReq {
pob_ver: String::from("2.59.2"),
min_rpob_ver: String::from("0.2.10"),
},
];
assert_eq!(highest_supported_pob_version(&compat_info, "0.0.2"), None);
assert_eq!(highest_supported_pob_version(&compat_info, "a.b.c"), None);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.1.0"),
Some("2.56.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.0"),
Some("2.56.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.6"),
Some("2.58.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.7"),
Some("2.58.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.8"),
Some("2.58.1")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.9"),
Some("2.59.0")
);
assert_eq!(
highest_supported_pob_version(&compat_info, "0.2.10"),
Some("2.59.2")
);
}
}
+26 -3
View File
@@ -13,7 +13,7 @@ use crate::{
window::WindowState,
};
use clap::Parser;
use mlua::{Lua, Result as LuaResult, Table};
use mlua::{Function, Lua, Result as LuaResult, Table, ThreadStatus};
use std::{
cell::{Cell, RefCell},
path::PathBuf,
@@ -170,9 +170,9 @@ impl LuaInstance {
// SAFETY: use `unsafe_new` to allow loading of C modules
let lua = unsafe { Lua::unsafe_new() };
// expose build arg to lua
// expose import url to lua
let args = Args::parse();
let args_table = lua.create_sequence_from(std::iter::once(args.build_path))?;
let args_table = lua.create_sequence_from(std::iter::once(args.import_url))?;
lua.globals().set("arg", args_table)?;
Self::register_package_paths(&lua)?;
@@ -228,6 +228,29 @@ impl LuaInstance {
}
}
pub fn has_running_subscripts(&self) -> bool {
self.subscript_manager.borrow().has_running_subscripts()
}
pub fn has_active_coroutine(&self) -> bool {
self.get_coroutines().is_ok_and(|coroutines| {
coroutines.pairs::<mlua::Thread, bool>().any(|pair| {
pair.is_ok_and(|(thread, _)| {
matches!(
thread.status(),
ThreadStatus::Resumable | ThreadStatus::Running
)
})
})
})
}
fn get_coroutines(&self) -> LuaResult<Table> {
let coroutine_module: Table = self.lua.globals().get("coroutine")?;
let list_func: Function = coroutine_module.get("_list")?;
list_func.call::<Table>(())
}
pub fn handle_event(&self, event: PoBEvent, pob_ctx: &mut PoBContext) -> LuaResult<()> {
profiling::scope!("handle_event", format!("{}", event));
+3
View File
@@ -34,6 +34,9 @@ pub enum ModeTransition {
pub struct ModeFrameOutput {
pub primitives: Box<dyn Iterator<Item = ClippedPrimitive>>,
pub can_elide: bool,
/// Indicates that this should be redrawn again next frame even if user is not interacting with
/// window
pub should_continue: bool,
}
pub enum AppMode {
+5
View File
@@ -68,9 +68,14 @@ impl PoBMode {
let identical = layers_hash == self.previous_layers_hash;
self.previous_layers_hash = layers_hash;
let has_active_subscript = self.lua_instance.has_running_subscripts();
let has_active_coroutine = self.lua_instance.has_active_coroutine();
let should_continue = has_active_subscript || has_active_coroutine;
Ok(ModeFrameOutput {
primitives: self.state.layers.consume_layers(),
can_elide: identical,
should_continue,
})
}
+5 -1
View File
@@ -74,6 +74,10 @@ impl SubscriptManager {
results
}
pub fn has_running_subscripts(&self) -> bool {
!self.scripts.is_empty()
}
}
enum SubscriptCall {
@@ -305,7 +309,7 @@ pub fn register_subscript_globals(
"IsSubScriptRunning",
lua.create_function(is_subscript_running)?,
)?;
globals.set("IsSubScriptRunning", lua.create_function(abort_subscript)?)?;
globals.set("AbortSubScript", lua.create_function(abort_subscript)?)?;
Ok(())
}
+22 -2
View File
@@ -11,8 +11,11 @@ pub struct WindowState {
clipboard: Option<Clipboard>,
pub window: Option<Arc<Window>>,
pub size: PhysicalSize<u32>,
pub scale_factor: f32,
scale_factor: f32,
pub scale_factor_override: Option<f32>,
pending_window_title: std::cell::Cell<Option<String>>,
pub is_hovered: bool,
pub is_focused: bool,
}
impl Default for WindowState {
@@ -21,8 +24,11 @@ impl Default for WindowState {
window: None,
size: Default::default(),
scale_factor: 1.0,
scale_factor_override: None,
pending_window_title: std::cell::Cell::new(None),
clipboard: None,
is_hovered: true,
is_focused: true,
}
}
}
@@ -51,7 +57,15 @@ impl WindowState {
}
pub fn logical_size(&self) -> LogicalSize<u32> {
self.size.to_logical(self.scale_factor)
self.size.to_logical(self.scale_factor())
}
pub fn scale_factor(&self) -> f32 {
self.scale_factor_override.unwrap_or(self.scale_factor)
}
pub fn set_scale_factor(&mut self, scale_factor: f32) {
self.scale_factor = scale_factor;
}
pub fn focus(&self) {
@@ -73,4 +87,10 @@ impl WindowState {
None
}
}
pub fn request_redraw(&self) {
if let Some(ref window) = self.window {
window.request_redraw();
}
}
}