mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 20:35: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
|
.player
|
||||||
.vspeed
|
.vspeed
|
||||||
.clamp(-terminal_velocity, terminal_velocity);
|
.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
|
self.game
|
||||||
.player
|
.player
|
||||||
.col_en
|
.col_en
|
||||||
.move_y(self.game.player.vspeed, |player_en, off| {
|
.move_y(self.game.player.vspeed, |player_en, off| {
|
||||||
let mut col = false;
|
let mut col = false;
|
||||||
for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| {
|
for en in &on_screen_tile_ents {
|
||||||
let tid = self.game.world.tile_at_mut(tp).mid;
|
if player_en.would_collide(en, off) {
|
||||||
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) {
|
|
||||||
col = true;
|
col = true;
|
||||||
if self.game.player.vspeed > 0. {
|
if self.game.player.vspeed > 0. {
|
||||||
self.game.player.jumps_left = 1;
|
self.game.player.jumps_left = 1;
|
||||||
}
|
}
|
||||||
self.game.player.vspeed = 0.;
|
self.game.player.vspeed = 0.;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
col
|
col
|
||||||
});
|
});
|
||||||
self.game
|
self.game
|
||||||
|
|
@ -127,20 +132,12 @@ impl App {
|
||||||
.col_en
|
.col_en
|
||||||
.move_x(self.game.player.hspeed, |player_en, off| {
|
.move_x(self.game.player.hspeed, |player_en, off| {
|
||||||
let mut col = false;
|
let mut col = false;
|
||||||
for_each_tile_on_screen(self.game.camera_offset, |tp, _sp| {
|
for en in &on_screen_tile_ents {
|
||||||
let tid = self.game.world.tile_at_mut(tp).mid;
|
if player_en.would_collide(en, off) {
|
||||||
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) {
|
|
||||||
col = true;
|
col = true;
|
||||||
self.game.player.hspeed = 0.;
|
self.game.player.hspeed = 0.;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
col
|
col
|
||||||
});
|
});
|
||||||
self.game.player.vspeed += self.game.gravity;
|
self.game.player.vspeed += self.game.gravity;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue