mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-14 19:55:02 +01:00
Precalculate tile collision entities for increased coll check perf
This commit is contained in:
parent
ffcd4e3418
commit
0f34f18bc0
1 changed files with 19 additions and 22 deletions
41
src/app.rs
41
src/app.rs
|
|
@ -98,28 +98,33 @@ impl App {
|
|||
.player
|
||||
.vspeed
|
||||
.clamp(-terminal_velocity, terminal_velocity);
|
||||
let mut on_screen_tile_ents = Vec::new();
|
||||
for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| {
|
||||
let tid = self.game.world.tile_at_mut(tp).mid;
|
||||
if tid == Tile::EMPTY {
|
||||
return;
|
||||
}
|
||||
let tsize = TILE_SIZE as i32;
|
||||
let x = tp.x as i32 * TILE_SIZE as i32;
|
||||
let y = tp.y as i32 * TILE_SIZE as i32;
|
||||
let en = s2dc::Entity::from_rect_corners(x, y, x + tsize, y + tsize);
|
||||
on_screen_tile_ents.push(en);
|
||||
});
|
||||
imm_dbg!(on_screen_tile_ents.len());
|
||||
self.game
|
||||
.player
|
||||
.col_en
|
||||
.move_y(self.game.player.vspeed, |player_en, off| {
|
||||
let mut col = false;
|
||||
for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| {
|
||||
let tid = self.game.world.tile_at_mut(tp).mid;
|
||||
if tid == Tile::EMPTY {
|
||||
return;
|
||||
}
|
||||
let tsize = TILE_SIZE as i32;
|
||||
let x = tp.x as i32 * TILE_SIZE as i32;
|
||||
let y = tp.y as i32 * TILE_SIZE as i32;
|
||||
let en = s2dc::Entity::from_rect_corners(x, y, x + tsize, y + tsize);
|
||||
if player_en.would_collide(&en, off) {
|
||||
for en in &on_screen_tile_ents {
|
||||
if player_en.would_collide(en, off) {
|
||||
col = true;
|
||||
if self.game.player.vspeed > 0. {
|
||||
self.game.player.jumps_left = 1;
|
||||
}
|
||||
self.game.player.vspeed = 0.;
|
||||
}
|
||||
});
|
||||
}
|
||||
col
|
||||
});
|
||||
self.game
|
||||
|
|
@ -127,20 +132,12 @@ impl App {
|
|||
.col_en
|
||||
.move_x(self.game.player.hspeed, |player_en, off| {
|
||||
let mut col = false;
|
||||
for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| {
|
||||
let tid = self.game.world.tile_at_mut(tp).mid;
|
||||
if tid == Tile::EMPTY {
|
||||
return;
|
||||
}
|
||||
let tsize = TILE_SIZE as i32;
|
||||
let x = tp.x as i32 * TILE_SIZE as i32;
|
||||
let y = tp.y as i32 * TILE_SIZE as i32;
|
||||
let en = s2dc::Entity::from_rect_corners(x, y, x + tsize, y + tsize);
|
||||
if player_en.would_collide(&en, off) {
|
||||
for en in &on_screen_tile_ents {
|
||||
if player_en.would_collide(en, off) {
|
||||
col = true;
|
||||
self.game.player.hspeed = 0.;
|
||||
}
|
||||
});
|
||||
}
|
||||
col
|
||||
});
|
||||
self.game.player.vspeed += self.game.gravity;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue