Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08260cabd2 | ||
|
|
4316366f87 | ||
|
|
01697e32bd | ||
|
|
3e065a8838 | ||
|
|
1aa0aa128f | ||
|
|
098c967206 | ||
|
|
1bb0fdf056 | ||
|
|
9a341cfb39 |
No files matched your search
+8
-49
@@ -8,57 +8,16 @@
|
||||
|
||||
## 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.
|
||||
- Get familiar with the code base before you start. Feel free to reach out through [Discussions](https://github.com/meehl/rusty-path-of-building/discussions) if you have any questions.
|
||||
- Make sure the [API](https://github.com/meehl/rusty-path-of-building/blob/main/src/pob/api.rs) functions stay compatible with [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) (SG). A great place to ask questions about SG 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.
|
||||
|
||||
## macOS Development Setup
|
||||
## Code Ownership and AI-Assisted Contributions
|
||||
|
||||
### 1. Install Lua runtime dependencies
|
||||
Contributors are responsible for every line of code they submit, regardless of how it was written. Make sure to:
|
||||
|
||||
The application requires several Lua C libraries at runtime. Install them using LuaRocks with the LuaJIT backend:
|
||||
- **Understand your code** - You must be able to explain how your contribution works and why it is implemented the way it is.
|
||||
- **Review before submitting** - Carefully review all AI-generated code for correctness, security, maintainability, and consistency with the project's conventions.
|
||||
- **Maintain quality** - AI assistance is not an excuse for untested code, unnecessary complexity, duplicated logic, or careless implementations.
|
||||
|
||||
```bash
|
||||
brew install luajit luarocks
|
||||
|
||||
luarocks --lua-version 5.1 install luasocket
|
||||
luarocks --lua-version 5.1 install luautf8
|
||||
luarocks --lua-version 5.1 install lua-curl
|
||||
```
|
||||
|
||||
Build and install `lzip` from the bundled source (requires zlib, which is pre-installed on macOS):
|
||||
|
||||
```bash
|
||||
cd lua/libs/lzip && make LUA_IMPL=luajit install
|
||||
```
|
||||
|
||||
### 2. Configure LUA_CPATH
|
||||
|
||||
Add the following to your shell profile (`~/.zshrc` or `~/.bash_profile`) so the runtime can locate the installed libraries:
|
||||
|
||||
```bash
|
||||
eval $(luarocks --lua-version 5.1 path)
|
||||
```
|
||||
|
||||
Then reload your shell or run `source ~/.bash_profile`.
|
||||
|
||||
### 3. Startup
|
||||
|
||||
```bash
|
||||
cargo run <poe1|poe2>
|
||||
```
|
||||
|
||||
Path of Building files are automatically downloaded to the following directories on first startup:
|
||||
|
||||
- poe1: `~/Library/Application Support/RustyPathOfBuilding1`
|
||||
- poe2: `~/Library/Application Support/RustyPathOfBuilding2`
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
**Build fails with `library 'luajit-5.1' not found`**
|
||||
|
||||
This usually means the build cache points to an old LuaJIT version after a Homebrew upgrade. Run:
|
||||
|
||||
```bash
|
||||
cargo clean && cargo run <poe1|poe2>
|
||||
```
|
||||
If you cannot confidently explain and verify a piece of code, don't submit it.
|
||||
+16
-1
@@ -2,6 +2,19 @@
|
||||
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
## [0.3.4] - 2026-11-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix blurry text inside viewports with fractional scale factors
|
||||
- Fix crash on macOS
|
||||
|
||||
## [0.3.3] - 2026-10-23
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix error in built-in updater with new `bundled-lua-modules` feature
|
||||
|
||||
## [0.3.2] - 2026-10-22
|
||||
|
||||
### Changed
|
||||
@@ -246,8 +259,10 @@
|
||||
- First release
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.2...HEAD
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.4...HEAD
|
||||
|
||||
[0.3.4]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.3...v0.3.4
|
||||
[0.3.3]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.2...v0.3.3
|
||||
[0.3.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.1...v0.3.2
|
||||
[0.3.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.3.0...v0.3.1
|
||||
[0.3.0]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.18...v0.3.0
|
||||
|
||||
Generated
+1
-1
@@ -3502,7 +3502,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-path-of-building"
|
||||
version = "0.3.2"
|
||||
version = "0.3.4"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
|
||||
+1
-1
@@ -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.3.2"
|
||||
version = "0.3.4"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
|
||||
+27
-10
@@ -4,7 +4,8 @@ use ahash::AHasher;
|
||||
|
||||
use crate::{
|
||||
color::Srgba,
|
||||
dpi::{LogicalQuad, LogicalRect, LogicalSize},
|
||||
dpi::{LogicalPoint, LogicalQuad, LogicalRect, LogicalSize, ScaleFactor},
|
||||
fonts::{Layout, LayoutToLogical},
|
||||
math::Size,
|
||||
renderer::textures::TextureId,
|
||||
uv::{UvConstructors, UvQuad, UvRect},
|
||||
@@ -143,20 +144,36 @@ impl DrawCommandRecorder {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn draw_glyph(
|
||||
/// Records a laid-out string whose top-left corner is at `layout_origin`.
|
||||
pub fn draw_glyphs(
|
||||
&mut self,
|
||||
rect: LogicalRect<f32>,
|
||||
layout: &Layout,
|
||||
layout_origin: LogicalPoint<f32>,
|
||||
is_absolute_position: bool,
|
||||
scale_factor: ScaleFactor<f32>,
|
||||
) {
|
||||
// resolve the layout origin to screen space
|
||||
let origin = if is_absolute_position {
|
||||
layout_origin
|
||||
} else {
|
||||
layout_origin + self.current_viewport.min.to_vector()
|
||||
};
|
||||
// align the layout origin with the physical pixel grid to reduce blurriness
|
||||
let origin = (origin * scale_factor).round() / scale_factor;
|
||||
|
||||
for glyph in &layout.glyphs {
|
||||
let rect = LayoutToLogical::new(origin.x, origin.y).transform_box(&glyph.rect);
|
||||
self.draw_glyph(rect, glyph.uv, glyph.color, glyph.layer_idx);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_glyph(
|
||||
&mut self,
|
||||
positions: LogicalRect<f32>,
|
||||
uv: UvRect,
|
||||
color: Srgba,
|
||||
layer_idx: u32,
|
||||
is_absolute_position: bool,
|
||||
) {
|
||||
let positions = if is_absolute_position {
|
||||
rect
|
||||
} else {
|
||||
rect.translate(self.current_viewport.min.to_vector())
|
||||
};
|
||||
|
||||
// cull if outside of viewport
|
||||
if !positions.intersects(&self.current_viewport) {
|
||||
return;
|
||||
|
||||
+15
-4
@@ -174,7 +174,16 @@ impl GraphicsContext {
|
||||
pub fn render(&mut self, render_job: Option<RenderJob>) -> anyhow::Result<()> {
|
||||
profiling::scope!("render");
|
||||
|
||||
// apply textures delta
|
||||
if let Some(render_job) = &render_job {
|
||||
self.renderer
|
||||
.update_textures(&self.device, &self.queue, &render_job.textures_delta);
|
||||
}
|
||||
|
||||
if !self.is_surface_configured {
|
||||
if let Some(render_job) = &render_job {
|
||||
self.renderer.free_textures(&render_job.textures_delta);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -185,10 +194,16 @@ impl GraphicsContext {
|
||||
| wgpu::CurrentSurfaceTexture::Occluded
|
||||
| wgpu::CurrentSurfaceTexture::Validation => {
|
||||
// Skip frame
|
||||
if let Some(render_job) = &render_job {
|
||||
self.renderer.free_textures(&render_job.textures_delta);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => {
|
||||
self.surface.configure(&self.device, &self.config);
|
||||
if let Some(render_job) = &render_job {
|
||||
self.renderer.free_textures(&render_job.textures_delta);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@@ -208,10 +223,6 @@ impl GraphicsContext {
|
||||
if let Some(render_job) = render_job {
|
||||
let screen_size = PhysicalSize::new(self.config.width, self.config.height);
|
||||
|
||||
// upload new textures
|
||||
self.renderer
|
||||
.update_textures(&self.device, &self.queue, &render_job.textures_delta);
|
||||
|
||||
// upload vertex, index, and uniform buffers
|
||||
self.renderer.update_buffers(
|
||||
&self.device,
|
||||
|
||||
+4
-13
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
color::Srgba,
|
||||
dpi::LogicalPoint,
|
||||
fonts::{Alignment, FontStyle, LayoutJob, LayoutToLogical},
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
math::Point,
|
||||
pob::Context,
|
||||
};
|
||||
@@ -101,19 +101,10 @@ pub unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int
|
||||
let layout = ctx.fonts.borrow_mut().layout(job, scale_factor);
|
||||
|
||||
// apply offset to account for anchor position
|
||||
let position = position + layout.anchor_offset(halign);
|
||||
// align layout anchor with the physical pixel grid to reduce blurriness
|
||||
let position = (position * scale_factor).round() / scale_factor;
|
||||
let layout_origin = position + layout.anchor_offset(halign);
|
||||
|
||||
for glyph in &layout.glyphs {
|
||||
ctx.recorder.draw_glyph(
|
||||
LayoutToLogical::new(position.x, position.y).transform_box(&glyph.rect),
|
||||
glyph.uv,
|
||||
glyph.color,
|
||||
glyph.layer_idx,
|
||||
is_absolute_position,
|
||||
);
|
||||
}
|
||||
ctx.recorder
|
||||
.draw_glyphs(&layout, layout_origin, is_absolute_position, scale_factor);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
+100
-21
@@ -17,11 +17,59 @@ fn bad_argument(to: impl Into<String>, pos: usize, cause: &'static str) -> LuaEr
|
||||
}
|
||||
}
|
||||
|
||||
/// A Lua callback set via `setopt_*function`.
|
||||
///
|
||||
/// `context` is set when an object is passed to the callback setter. In that case `function` is
|
||||
/// the object's method and is invoked as `function(context, data)`.
|
||||
struct Callback {
|
||||
function: RegistryKey,
|
||||
context: Option<RegistryKey>,
|
||||
}
|
||||
|
||||
impl Callback {
|
||||
fn resolve(&self, lua: &Lua) -> LuaResult<(mlua::Function, Option<mlua::Value>)> {
|
||||
let function = lua.registry_value(&self.function)?;
|
||||
let context = self
|
||||
.context
|
||||
.as_ref()
|
||||
.map(|key| lua.registry_value::<mlua::Value>(key))
|
||||
.transpose()?;
|
||||
|
||||
Ok((function, context))
|
||||
}
|
||||
|
||||
fn remove(self, lua: &Lua) -> LuaResult<()> {
|
||||
lua.remove_registry_value(self.function)?;
|
||||
|
||||
if let Some(key) = self.context {
|
||||
lua.remove_registry_value(key)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Interprets write/header callback return values like Lua-cURL does.
|
||||
fn callback_size(data_len: usize, results: &mlua::MultiValue) -> usize {
|
||||
let Some(value) = results.front() else {
|
||||
return data_len;
|
||||
};
|
||||
|
||||
match value {
|
||||
mlua::Value::Nil => 0,
|
||||
mlua::Value::Integer(n) => (*n).max(0) as usize,
|
||||
mlua::Value::Number(n) if *n >= 0.0 => *n as usize,
|
||||
mlua::Value::Number(_) => 0,
|
||||
mlua::Value::Boolean(false) => 0,
|
||||
_ => data_len,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct EasyHandle {
|
||||
easy: Option<Easy>,
|
||||
write_callback: Option<RegistryKey>,
|
||||
header_callback: Option<RegistryKey>,
|
||||
write_callback: Option<Callback>,
|
||||
header_callback: Option<Callback>,
|
||||
}
|
||||
|
||||
impl EasyHandle {
|
||||
@@ -40,12 +88,12 @@ impl EasyHandle {
|
||||
}
|
||||
|
||||
pub fn close(&mut self, lua: &Lua) -> LuaResult<()> {
|
||||
if let Some(key) = self.write_callback.take() {
|
||||
lua.remove_registry_value(key)?;
|
||||
if let Some(callback) = self.write_callback.take() {
|
||||
callback.remove(lua)?;
|
||||
}
|
||||
|
||||
if let Some(key) = self.header_callback.take() {
|
||||
lua.remove_registry_value(key)?;
|
||||
if let Some(callback) = self.header_callback.take() {
|
||||
callback.remove(lua)?;
|
||||
}
|
||||
|
||||
self.easy = None;
|
||||
@@ -160,20 +208,37 @@ impl EasyHandle {
|
||||
|
||||
fn set_callback(
|
||||
lua: &Lua,
|
||||
slot: &mut Option<RegistryKey>,
|
||||
slot: &mut Option<Callback>,
|
||||
value: mlua::Value,
|
||||
method: &str,
|
||||
) -> LuaResult<()> {
|
||||
let new_key = match value {
|
||||
let new_callback = match value {
|
||||
mlua::Value::Nil => None,
|
||||
mlua::Value::Function(f) => Some(lua.create_registry_value(f)?),
|
||||
mlua::Value::Function(function) => Some(Callback {
|
||||
function: lua.create_registry_value(function)?,
|
||||
context: None,
|
||||
}),
|
||||
// Lua-cURL can also accept objects with a method of the given name,
|
||||
// e.g. a file handle returned by `io.open` with a `write` method.
|
||||
// looks a bit awkwards but it works...
|
||||
value @ (mlua::Value::Table(_) | mlua::Value::UserData(_)) => {
|
||||
let function: mlua::Function = lua
|
||||
.load("local object, key = ...; return object[key]")
|
||||
.call((value.clone(), method))?;
|
||||
|
||||
Some(Callback {
|
||||
function: lua.create_registry_value(function)?,
|
||||
context: Some(lua.create_registry_value(value)?),
|
||||
})
|
||||
}
|
||||
_ => return Err(LuaError::runtime("invalid object type")),
|
||||
};
|
||||
|
||||
if let Some(old_key) = slot.take() {
|
||||
lua.remove_registry_value(old_key)?;
|
||||
if let Some(old_callback) = slot.take() {
|
||||
old_callback.remove(lua)?;
|
||||
}
|
||||
|
||||
*slot = new_key;
|
||||
*slot = new_callback;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -182,41 +247,55 @@ impl EasyHandle {
|
||||
let write_fn = self
|
||||
.write_callback
|
||||
.as_ref()
|
||||
.map(|key| lua.registry_value::<mlua::Function>(key))
|
||||
.map(|callback| callback.resolve(lua))
|
||||
.transpose()?;
|
||||
|
||||
let header_fn = self
|
||||
.header_callback
|
||||
.as_ref()
|
||||
.map(|key| lua.registry_value::<mlua::Function>(key))
|
||||
.map(|callback| callback.resolve(lua))
|
||||
.transpose()?;
|
||||
|
||||
let transfer_result = {
|
||||
let mut transfer = self.curl()?.transfer();
|
||||
|
||||
if let Some(function) = write_fn {
|
||||
if let Some((function, context)) = write_fn {
|
||||
transfer
|
||||
.write_function(move |data| {
|
||||
let Ok(argument) = lua.create_string(data) else {
|
||||
return Ok(0);
|
||||
};
|
||||
|
||||
match function.call::<()>(argument) {
|
||||
Ok(()) => Ok(data.len()),
|
||||
let result = match &context {
|
||||
Some(context) => {
|
||||
function.call::<mlua::MultiValue>((context.clone(), argument))
|
||||
}
|
||||
None => function.call::<mlua::MultiValue>(argument),
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(results) => Ok(callback_size(data.len(), &results)),
|
||||
Err(_) => Ok(0),
|
||||
}
|
||||
})
|
||||
.map_err(LuaError::external)?;
|
||||
}
|
||||
|
||||
if let Some(function) = header_fn {
|
||||
if let Some((function, context)) = header_fn {
|
||||
transfer
|
||||
.header_function(move |data| {
|
||||
let Ok(argument) = lua.create_string(data) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
function.call::<bool>(argument).unwrap_or(false)
|
||||
match &context {
|
||||
Some(context) => {
|
||||
function.call::<mlua::MultiValue>((context.clone(), argument))
|
||||
}
|
||||
None => function.call::<mlua::MultiValue>(argument),
|
||||
}
|
||||
.map(|results| callback_size(data.len(), &results) == data.len())
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.map_err(LuaError::external)?;
|
||||
}
|
||||
@@ -272,11 +351,11 @@ impl UserData for EasyHandle {
|
||||
});
|
||||
|
||||
methods.add_method_mut("setopt_writefunction", |lua, this, value: mlua::Value| {
|
||||
Self::set_callback(lua, &mut this.write_callback, value)
|
||||
Self::set_callback(lua, &mut this.write_callback, value, "write")
|
||||
});
|
||||
|
||||
methods.add_method_mut("setopt_headerfunction", |lua, this, value: mlua::Value| {
|
||||
Self::set_callback(lua, &mut this.header_callback, value)
|
||||
Self::set_callback(lua, &mut this.header_callback, value, "header")
|
||||
});
|
||||
|
||||
methods.add_method_mut("perform", |lua, this, ()| this.perform(lua));
|
||||
|
||||
Reference in new issue
Block a user