mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 20:35:02 +01:00
Shorten the name of various scalar types
This commit is contained in:
parent
390a4d45d2
commit
e7c30d231b
4 changed files with 28 additions and 28 deletions
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
input::Input,
|
input::Input,
|
||||||
math::{center_offset, TILE_SIZE},
|
math::{center_offset, TILE_SIZE},
|
||||||
res::Res,
|
res::Res,
|
||||||
world::{TilePosScalar, CHUNK_EXTENT},
|
world::{TPosSc, CHUNK_EXTENT},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Application level state (includes game and ui state, etc.)
|
/// Application level state (includes game and ui state, etc.)
|
||||||
|
|
@ -217,8 +217,8 @@ impl App {
|
||||||
);
|
);
|
||||||
imm!(
|
imm!(
|
||||||
"@ chunk {}, {}",
|
"@ chunk {}, {}",
|
||||||
mouse_tpos.x / CHUNK_EXTENT as TilePosScalar,
|
mouse_tpos.x / CHUNK_EXTENT as TPosSc,
|
||||||
mouse_tpos.y / CHUNK_EXTENT as TilePosScalar
|
mouse_tpos.y / CHUNK_EXTENT as TPosSc
|
||||||
);
|
);
|
||||||
if self.debug.freecam && self.input.pressed(Key::P) {
|
if self.debug.freecam && self.input.pressed(Key::P) {
|
||||||
self.game.world.player.col_en.en.pos.x = wpos.x as i32;
|
self.game.world.player.col_en.en.pos.x = wpos.x as i32;
|
||||||
|
|
|
||||||
18
src/math.rs
18
src/math.rs
|
|
@ -1,14 +1,14 @@
|
||||||
use egui_inspect::derive::Inspect;
|
use egui_inspect::derive::Inspect;
|
||||||
use num_traits::{Num, Signed};
|
use num_traits::{Num, Signed};
|
||||||
|
|
||||||
use crate::world::{TilePos, TilePosScalar};
|
use crate::world::{TPosSc, TilePos};
|
||||||
|
|
||||||
pub type WorldPosScalar = u32;
|
pub type WPosSc = u32;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Inspect)]
|
#[derive(Clone, Copy, Debug, Inspect)]
|
||||||
pub struct WorldPos {
|
pub struct WorldPos {
|
||||||
pub x: WorldPosScalar,
|
pub x: WPosSc,
|
||||||
pub y: WorldPosScalar,
|
pub y: WPosSc,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tile size in pixels
|
/// Tile size in pixels
|
||||||
|
|
@ -29,7 +29,7 @@ pub fn px_per_frame_to_km_h(px_per_frame: f32) -> f32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// World extent in tiles. Roughly 50km*50km.
|
/// World extent in tiles. Roughly 50km*50km.
|
||||||
pub const WORLD_EXTENT: TilePosScalar = 100_000;
|
pub const WORLD_EXTENT: TPosSc = 100_000;
|
||||||
|
|
||||||
impl WorldPos {
|
impl WorldPos {
|
||||||
pub fn tile_pos(&self) -> TilePos {
|
pub fn tile_pos(&self) -> TilePos {
|
||||||
|
|
@ -39,18 +39,18 @@ impl WorldPos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Horizontal center of the world
|
/// Horizontal center of the world
|
||||||
pub const CENTER: WorldPosScalar = (WORLD_EXTENT / 2) * TILE_SIZE as WorldPosScalar;
|
pub const CENTER: WPosSc = (WORLD_EXTENT / 2) * TILE_SIZE as WPosSc;
|
||||||
/// Vertical surface level.
|
/// Vertical surface level.
|
||||||
/// You can build 10 km high.
|
/// You can build 10 km high.
|
||||||
pub const SURFACE: WorldPosScalar = 20_000 * TILE_SIZE as WorldPosScalar;
|
pub const SURFACE: WPosSc = 20_000 * TILE_SIZE as WPosSc;
|
||||||
pub const SURFACE_CENTER: Self = Self {
|
pub const SURFACE_CENTER: Self = Self {
|
||||||
x: Self::CENTER,
|
x: Self::CENTER,
|
||||||
y: Self::SURFACE,
|
y: Self::SURFACE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wp_to_tp(wp: WorldPosScalar) -> TilePosScalar {
|
pub fn wp_to_tp(wp: WPosSc) -> TPosSc {
|
||||||
(wp / TILE_SIZE as WorldPosScalar) as TilePosScalar
|
(wp / TILE_SIZE as WPosSc) as TPosSc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the offset required to center an object of `xw` width inside an object of `yw` width.
|
// Get the offset required to center an object of `xw` width inside an object of `yw` width.
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use s2dc::{vec2, MobileEntity};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
math::{WorldPos, TILE_SIZE},
|
math::{WorldPos, TILE_SIZE},
|
||||||
world::{TilePos, TilePosScalar},
|
world::{TPosSc, TilePos},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Inspect)]
|
#[derive(Debug, Inspect)]
|
||||||
|
|
@ -40,8 +40,8 @@ impl Player {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn center_tp(&self) -> TilePos {
|
pub fn center_tp(&self) -> TilePos {
|
||||||
TilePos {
|
TilePos {
|
||||||
x: (self.col_en.en.pos.x / TILE_SIZE as i32) as TilePosScalar,
|
x: (self.col_en.en.pos.x / TILE_SIZE as i32) as TPosSc,
|
||||||
y: (self.col_en.en.pos.y / TILE_SIZE as i32) as TilePosScalar,
|
y: (self.col_en.en.pos.y / TILE_SIZE as i32) as TPosSc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn can_jump(&self) -> bool {
|
pub fn can_jump(&self) -> bool {
|
||||||
|
|
|
||||||
26
src/world.rs
26
src/world.rs
|
|
@ -3,12 +3,12 @@ use fnv::FnvHashMap;
|
||||||
|
|
||||||
use crate::{math::WorldPos, player::Player, worldgen::Worldgen};
|
use crate::{math::WorldPos, player::Player, worldgen::Worldgen};
|
||||||
|
|
||||||
pub type ChunkPosScalar = u16;
|
pub type ChkPosSc = u16;
|
||||||
|
|
||||||
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy, Inspect)]
|
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy, Inspect)]
|
||||||
pub struct ChunkPos {
|
pub struct ChunkPos {
|
||||||
pub x: ChunkPosScalar,
|
pub x: ChkPosSc,
|
||||||
pub y: ChunkPosScalar,
|
pub y: ChkPosSc,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Inspect)]
|
#[derive(Debug, Inspect)]
|
||||||
|
|
@ -47,17 +47,17 @@ impl World {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct TilePos {
|
pub struct TilePos {
|
||||||
pub x: TilePosScalar,
|
pub x: TPosSc,
|
||||||
pub y: TilePosScalar,
|
pub y: TPosSc,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct ChunkLocalTilePos {
|
pub struct ChunkLocalTilePos {
|
||||||
pub x: ChunkLocalTilePosScalar,
|
pub x: ChkLocalTPosSc,
|
||||||
pub y: ChunkLocalTilePosScalar,
|
pub y: ChkLocalTPosSc,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChunkLocalTilePosScalar = u8;
|
type ChkLocalTPosSc = u8;
|
||||||
|
|
||||||
impl TilePos {
|
impl TilePos {
|
||||||
pub fn to_chunk_and_local(self) -> (ChunkPos, ChunkLocalTilePos) {
|
pub fn to_chunk_and_local(self) -> (ChunkPos, ChunkLocalTilePos) {
|
||||||
|
|
@ -73,8 +73,8 @@ impl TilePos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chk_pos(tile: TilePosScalar) -> ChunkPosScalar {
|
fn chk_pos(tile: TPosSc) -> ChkPosSc {
|
||||||
(tile / CHUNK_EXTENT as TilePosScalar) as ChunkPosScalar
|
(tile / CHUNK_EXTENT as TPosSc) as ChkPosSc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -85,8 +85,8 @@ fn test_chk_pos() {
|
||||||
assert_eq!(chk_pos(128), 1);
|
assert_eq!(chk_pos(128), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chunk_local(global: TilePosScalar) -> ChunkLocalTilePosScalar {
|
fn chunk_local(global: TPosSc) -> ChkLocalTPosSc {
|
||||||
(global % CHUNK_EXTENT as TilePosScalar) as ChunkLocalTilePosScalar
|
(global % CHUNK_EXTENT as TPosSc) as ChkLocalTPosSc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -107,7 +107,7 @@ fn test_to_chunk_and_local() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to support at least 4 million tiles long
|
// Need to support at least 4 million tiles long
|
||||||
pub type TilePosScalar = u32;
|
pub type TPosSc = u32;
|
||||||
|
|
||||||
pub const CHUNK_EXTENT: u16 = 128;
|
pub const CHUNK_EXTENT: u16 = 128;
|
||||||
const CHUNK_N_TILES: usize = CHUNK_EXTENT as usize * CHUNK_EXTENT as usize;
|
const CHUNK_N_TILES: usize = CHUNK_EXTENT as usize * CHUNK_EXTENT as usize;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue