Skip to content

Commit

Permalink
improved collision based movement for low fps, also #10 better lakes
Browse files Browse the repository at this point in the history
  • Loading branch information
justanothercell committed Jun 9, 2023
1 parent 5c5bef3 commit ae832be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/client_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ClientRuntime {
log!(ERROR, "{e}");
exit(1);
});
std::thread::sleep(Duration::from_millis((MAX_CLIENT_TIMEOUT - 2000) as u64))
std::thread::sleep(Duration::from_millis((MAX_CLIENT_TIMEOUT / 2) as u64))
}
});
log!("started timeout preventer");
Expand Down
21 changes: 13 additions & 8 deletions mods/world/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Mul;

use aeonetica_engine::nanoserde::{SerBin, DeBin};
use aeonetica_engine::nanoserde;
use aeonetica_engine::math::vector::Vector2;
Expand Down Expand Up @@ -111,14 +113,17 @@ pub trait WorldView {

/// Tries to slide along walls instead of stopping movement alltogether.
fn calc_move(&self, pos: &mut Vector2<f32>, size: Vector2<f32>, delta: Vector2<f32>) {
let delta_x = (delta.x, 0.0).into();
let delta_y = (0.0, delta.y).into();
if !self.overlap_aabb(*pos + delta, size) {
*pos += delta;
} else if !self.overlap_aabb(*pos + delta_x, size) {
*pos += delta_x;
} else if !self.overlap_aabb(*pos + delta_y, size) {
*pos += delta_y;
let i = delta.mag().mul(25.0).ceil();
let delta_x = (delta.x / i, 0.0).into();
let delta_y = (0.0, delta.y / i).into();
for _ in 0..i as i32 {
if !self.overlap_aabb(*pos + delta, size) {
*pos += delta / i;
} else if !self.overlap_aabb(*pos + delta_x, size) {
*pos += delta_x;
} else if !self.overlap_aabb(*pos + delta_y, size) {
*pos += delta_y;
}
}
}
}
3 changes: 2 additions & 1 deletion mods/world/src/server/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ impl World {
}
h = h.min(k-2);
if h < 3 || k == 12 { return }
for i in start+1..start+size-2 {
for i in start+1..start+size-1 {
for j in h-3..h {
if j == h-3 && (i < start + 4 || i > start+size-4) { continue; }
let p = Vector2::new(i, pos.y - j);
self.set_init_water_tile_at(p, population, (h - j) as u8);
let t = self.get_initial_terrain_tile(p, false);
Expand Down

0 comments on commit ae832be

Please sign in to comment.