Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use intern macro for getattr strings #39

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/sprite_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::geometry::are_polygons_intersecting_native;
use crate::hitbox::{HitBox, NativeAdjustedPoints, RotatableHitBox};
use pyo3::intern;
use pyo3::prelude::*;

#[pyfunction]
Expand All @@ -15,7 +16,7 @@ pub fn check_for_collision_with_list(
let main_points: &Vec<(f32, f32)>;
let mut hitbox1: HitBox;
let mut hitbox2: RotatableHitBox;
let hitbox_py_object: &PyAny = sprite.getattr("_hit_box").unwrap();
let hitbox_py_object: &PyAny = sprite.getattr(intern!(py, "_hit_box")).unwrap();

if hitbox_py_object.is_instance_of::<HitBox>() {
hitbox1 = hitbox_py_object.extract::<HitBox>().unwrap();
Expand All @@ -27,7 +28,7 @@ pub fn check_for_collision_with_list(
panic!("Unknown Hitbox Type")
}

let sprite_list_list = sprite_list.getattr("sprite_list").unwrap();
let sprite_list_list = sprite_list.getattr(intern!(py, "sprite_list")).unwrap();
let sprites_to_check: Vec<PyObject> = sprite_list_list.extract().unwrap();

for sprite2 in sprites_to_check.iter() {
Expand All @@ -36,7 +37,7 @@ pub fn check_for_collision_with_list(
let other_points: &Vec<(f32, f32)>;
let mut other_hitbox1: HitBox;
let mut other_hitbox2: RotatableHitBox;
let other_hitbox_py_object: &PyAny = other_sprite.getattr("_hit_box").unwrap();
let other_hitbox_py_object: &PyAny = other_sprite.getattr(intern!(py, "_hit_box")).unwrap();

if other_hitbox_py_object.is_instance_of::<HitBox>() {
other_hitbox1 = other_hitbox_py_object.extract::<HitBox>().unwrap();
Expand Down Expand Up @@ -69,7 +70,7 @@ pub fn check_for_collision_with_lists(
let main_points: &Vec<(f32, f32)>;
let mut hitbox1: HitBox;
let mut hitbox2: RotatableHitBox;
let hitbox_py_object: &PyAny = sprite.getattr("_hit_box").unwrap();
let hitbox_py_object: &PyAny = sprite.getattr(intern!(py, "_hit_box")).unwrap();

if hitbox_py_object.is_instance_of::<HitBox>() {
hitbox1 = hitbox_py_object.extract::<HitBox>().unwrap();
Expand All @@ -82,7 +83,7 @@ pub fn check_for_collision_with_lists(
}

for sprite_list in sprite_lists.iter() {
let sprite_list_list = sprite_list.getattr("sprite_list").unwrap();
let sprite_list_list = sprite_list.getattr(intern!(py, "sprite_list")).unwrap();
let sprites_to_check: Vec<PyObject> = sprite_list_list.extract().unwrap();

for sprite2 in sprites_to_check.iter() {
Expand All @@ -91,7 +92,8 @@ pub fn check_for_collision_with_lists(
let other_points: &Vec<(f32, f32)>;
let mut other_hitbox1: HitBox;
let mut other_hitbox2: RotatableHitBox;
let other_hitbox_py_object: &PyAny = other_sprite.getattr("_hit_box").unwrap();
let other_hitbox_py_object: &PyAny =
other_sprite.getattr(intern!(py, "_hit_box")).unwrap();

if other_hitbox_py_object.is_instance_of::<HitBox>() {
other_hitbox1 = other_hitbox_py_object.extract::<HitBox>().unwrap();
Expand Down
Loading