mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-14 19:55:02 +01:00
Add some world defs
This commit is contained in:
parent
608f8f9f9f
commit
d78726eb5b
6 changed files with 61 additions and 0 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -108,6 +108,12 @@ dependencies = [
|
|||
"parking_lot",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.8"
|
||||
|
|
@ -177,6 +183,7 @@ name = "mantle-diver"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"egui-sfml",
|
||||
"fnv",
|
||||
"hecs",
|
||||
"rand",
|
||||
"s2dc",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
egui-sfml = "0.4.0"
|
||||
fnv = "1.0.7"
|
||||
hecs = "0.10.1"
|
||||
rand = "0.8.5"
|
||||
sfml = "0.20.0"
|
||||
|
|
|
|||
16
src/game.rs
Normal file
16
src/game.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use crate::{math::WorldPos, world::World};
|
||||
|
||||
pub struct GameState {
|
||||
transient: TransientGameState,
|
||||
persistent: PersistentGameState,
|
||||
}
|
||||
|
||||
/// Transient game state, not saved to disk
|
||||
pub struct TransientGameState {
|
||||
camera_offset: WorldPos,
|
||||
}
|
||||
|
||||
/// Persistent game state, saved to disk
|
||||
pub struct PersistentGameState {
|
||||
world: World,
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
mod app;
|
||||
mod game;
|
||||
mod graphics;
|
||||
mod math;
|
||||
mod world;
|
||||
|
||||
use app::App;
|
||||
|
||||
|
|
|
|||
6
src/math.rs
Normal file
6
src/math.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
pub type WorldPosScalar = i32;
|
||||
|
||||
pub struct WorldPos {
|
||||
x: WorldPosScalar,
|
||||
y: WorldPosScalar,
|
||||
}
|
||||
28
src/world.rs
Normal file
28
src/world.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use fnv::FnvHashMap;
|
||||
|
||||
type ChunkPosScalar = i16;
|
||||
|
||||
#[derive(Hash)]
|
||||
struct ChunkPos {
|
||||
x: ChunkPosScalar,
|
||||
y: ChunkPosScalar,
|
||||
}
|
||||
|
||||
pub struct World {
|
||||
chunks: FnvHashMap<ChunkPos, Chunk>,
|
||||
}
|
||||
|
||||
const CHUNK_EXTENT: u16 = 256;
|
||||
const CHUNK_N_BLOCKS: usize = CHUNK_EXTENT as usize * CHUNK_EXTENT as usize;
|
||||
|
||||
type ChunkBlocks = [Block; CHUNK_N_BLOCKS];
|
||||
|
||||
pub struct Chunk {
|
||||
blocks: ChunkBlocks,
|
||||
}
|
||||
|
||||
type BlockId = u16;
|
||||
|
||||
pub struct Block {
|
||||
id: BlockId,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue