Skip to content

Commit

Permalink
Improved texture scaling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dawndus committed Mar 6, 2022
1 parent 05b9d9e commit 067bcc5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/texture_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;
use log::info;

use crate::common;
use crate::common::{FILE_TYPES, Rect};
use crate::common::{Rect, FILE_TYPES};
use crate::engine_constants::EngineConstants;
use crate::framework::backend::{BackendTexture, SpriteBatchCommand};
use crate::framework::context::Context;
Expand Down Expand Up @@ -429,10 +429,10 @@ impl TextureSet {
}
}

fn load_image(&self, ctx: &mut Context, roots: &Vec<String>, path: &str) -> GameResult<Box<dyn BackendTexture>> {
fn load_image(&self, ctx: &mut Context, roots: &Vec<String>, path: &str) -> GameResult<Box<dyn BackendTexture>> {
let img = {
let mut buf = [0u8; 8];
let mut reader = filesystem::open_find(ctx, roots,path)?;
let mut reader = filesystem::open_find(ctx, roots, path)?;
reader.read_exact(&mut buf)?;
reader.seek(SeekFrom::Start(0))?;

Expand Down Expand Up @@ -470,7 +470,20 @@ impl TextureSet {
let size = batch.dimensions();

let orig_dimensions = constants.tex_sizes.get(name).unwrap_or(&size);
let scale = orig_dimensions.0 as f32 / size.0 as f32;

let scale =
if f32::abs((orig_dimensions.0 as f32 / size.0 as f32) - (orig_dimensions.1 as f32 / size.1 as f32))
<= f32::EPSILON
{
orig_dimensions.0 as f32 / size.0 as f32
} else if constants.is_cs_plus && constants.base_paths.iter().any(|p| p.contains("/ogph")) {
1.0
} else if constants.is_cs_plus {
0.5
} else {
1.0
};

let width = (size.0 as f32 * scale) as _;
let height = (size.1 as f32 * scale) as _;

Expand Down

0 comments on commit 067bcc5

Please sign in to comment.