Add title screen with world selection and creation
The game opens on a vanilla-style title screen (logo, Singleplayer, Quit) over the spinning title panorama. Select World lists saves by last play with game mode; Create New World takes a name, a seed (numbers or text hashed like vanilla) and the game mode, and finds a free folder name. Save and Quit returns to the title. README and the parity status now describe the playable Rust game. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,25 @@
|
||||
# Horizon
|
||||
|
||||
Horizon is a Rust rewrite effort targeting one-to-one vanilla gameplay parity with Minecraft Java **26.3**, alongside client performance research. The Rust implementation has core primitives and world-data storage verified against pinned vanilla classes, plus a [native development client](docs/native-client.md) for inspecting a controlled block scene. It does not yet run a playable game. Existing playable downloads use Java performance packs. Not affiliated with Mojang or Microsoft.
|
||||
Horizon is a Rust rewrite of Minecraft Java **26.3** targeting one-to-one vanilla gameplay parity, alongside client performance research. Not affiliated with Mojang or Microsoft.
|
||||
|
||||
**First playable release:** pinned Java performance packs, distant terrain, an original frame/tick recorder, and Mac/client/server starter downloads. The M2 Pro/16 GB Mac is the first testing target. A Rust rewrite or custom renderer has not been completed; no M2 FPS improvement has been measured yet.
|
||||
**The Rust game is now playable.** The [native client](docs/native-client.md) opens on a vanilla-style title screen with world creation and selection, and generates worlds with the Rust port of the vanilla overworld generator: noise terrain, aquifers, surface rules, carvers, and the placed features ported so far, all checked against vanilla. It streams and lights chunks on worker threads and renders every vanilla block model with smooth lighting, biome tints, the vanilla sky, sun, moon, stars and clouds. Gameplay so far:
|
||||
- validated player physics, health and hunger;
|
||||
- mining with vanilla tool rules and loot tables;
|
||||
- placing, crafting, chests and furnaces;
|
||||
- dropped items and particles;
|
||||
- sounds;
|
||||
- passive and hostile mobs with combat;
|
||||
- Anvil saves.
|
||||
|
||||
Parity is **not** complete: block behaviours (fluids, redstone, crop growth), structures, many mobs, enchanting, the Nether and End, and multiplayer are still missing. See [Rust rewrite status](docs/rust-parity.md).
|
||||
|
||||
```sh
|
||||
python3 tools/prepare_native_client.py --prepare # needs JDK 25; extracts private vanilla resources
|
||||
python3 tools/fetch_sounds.py # optional: vanilla sounds
|
||||
cargo run --release -p horizon-client
|
||||
```
|
||||
|
||||
**Java performance packs (separate track):** pinned Java performance packs, distant terrain, an original frame/tick recorder, and Mac/client/server starter downloads. The M2 Pro/16 GB Mac is the first testing target.
|
||||
|
||||
The Rust rewrite’s final deliverables include **playable native builds for macOS, Linux and Windows**, with launch instructions and platform gameplay validation. Track implementation and acceptance criteria in [Rust rewrite status](docs/rust-parity.md).
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use horizon_client::{
|
||||
sprint::Keys,
|
||||
streaming::{Streaming, WorkerContext},
|
||||
save::{Level, Persistent, SaveDir},
|
||||
title::{Action, Title},
|
||||
testgen::TestTerrain,
|
||||
vanillagen::VanillaTerrain,
|
||||
world::World,
|
||||
@@ -55,7 +56,7 @@ struct Options {
|
||||
screenshot_after: Option<u64>,
|
||||
timeout: Duration,
|
||||
report: Option<PathBuf>,
|
||||
world: String,
|
||||
world: Option<String>,
|
||||
look: Option<(f32, f32)>,
|
||||
time: Option<i64>,
|
||||
}
|
||||
@@ -79,7 +80,7 @@ impl Options {
|
||||
screenshot_after: None,
|
||||
timeout: Duration::from_secs(120),
|
||||
report: None,
|
||||
world: "New World".into(),
|
||||
world: None,
|
||||
look: None,
|
||||
time: None,
|
||||
};
|
||||
@@ -117,7 +118,7 @@ impl Options {
|
||||
"--timeout-seconds" => o.timeout = Duration::from_secs(value.parse()?),
|
||||
"--smoke-report" => o.report = Some(value.into()),
|
||||
"--screenshot-after" => o.screenshot_after = Some(value.parse()?),
|
||||
"--world" => o.world = value,
|
||||
"--world" => o.world = Some(value),
|
||||
"--time" => o.time = Some(value.parse()?),
|
||||
"--look" => {
|
||||
let (y, p) = value.split_once(',').ok_or("--look takes YAW,PITCH")?;
|
||||
@@ -168,6 +169,8 @@ pub struct Resources {
|
||||
chest_model: Option<horizon_client::mobs::Part>,
|
||||
/// clouds.png: (width, height, filled cells).
|
||||
clouds: (u32, u32, Vec<bool>),
|
||||
context: Arc<WorkerContext>,
|
||||
threads: usize,
|
||||
}
|
||||
struct Game<'a> {
|
||||
res: &'a mut Resources,
|
||||
@@ -229,6 +232,7 @@ struct Game<'a> {
|
||||
chest_open: HashMap<(i32, i32, i32), (f32, f32)>,
|
||||
/// Item being used (eaten): hotbar slot and ticks used.
|
||||
using: Option<(usize, u32)>,
|
||||
title: Option<Title>,
|
||||
}
|
||||
fn view_vector(yaw: f32, pitch: f32) -> [f64; 3] {
|
||||
let (y, p) = (f64::from(yaw).to_radians(), f64::from(pitch).to_radians());
|
||||
@@ -1198,6 +1202,10 @@ impl Game<'_> {
|
||||
fn hud(&mut self, size: [u32; 2]) -> HudBatch {
|
||||
let mut batch = HudBatch::new(size);
|
||||
let (w, h) = (batch.width, batch.height);
|
||||
if let Some(title) = &self.title {
|
||||
title.draw(&self.res.atlas, &mut batch, self.cursor);
|
||||
return batch;
|
||||
}
|
||||
let atlas_ptr: *const HudAtlas = &self.res.atlas;
|
||||
let _ = atlas_ptr;
|
||||
if self.player.is_none() {
|
||||
@@ -2331,6 +2339,119 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Load (or create) a world folder under saves/ and start streaming it.
|
||||
fn open_world(&mut self, folder: &str, name: Option<&str>, seed: Option<i64>, creative: bool) -> Result<()> {
|
||||
let save_root = std::env::current_dir()?.join("saves").join(folder);
|
||||
let level = Level::read(&save_root).unwrap_or_else(|| Level {
|
||||
name: name.unwrap_or(folder).to_owned(),
|
||||
// WorldOptions.randomSeed when no seed was given.
|
||||
seed: seed.unwrap_or_else(|| {
|
||||
let t = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_nanos() as u64);
|
||||
(t ^ (t >> 29)).wrapping_mul(0x9E37_79B9_7F4A_7C15) as i64
|
||||
}),
|
||||
creative,
|
||||
day_time: 0,
|
||||
health: 20.0,
|
||||
food: 20,
|
||||
saturation: 5.0,
|
||||
..Level::default()
|
||||
});
|
||||
let save = Arc::new(SaveDir::new(save_root.clone()));
|
||||
let res = &*self.res;
|
||||
let mut streaming = if self.options.test_terrain {
|
||||
let inner = Arc::new(TestTerrain::new(res.assets.registry, &res.biomes)?);
|
||||
Streaming::new(Arc::new(Persistent { inner, save: save.clone(), registry: res.assets.clone(), biomes: res.biomes.clone() }), res.context.clone(), res.threads)
|
||||
} else {
|
||||
let inner = Arc::new(VanillaTerrain::new(&self.options.resources.join("worldgen"), res.assets.registry, &res.biomes, level.seed).map_err(|e| {
|
||||
format!("{e}\nPrepare the worldgen bundle with: python3 tools/prepare_native_client.py")
|
||||
})?);
|
||||
Streaming::new(Arc::new(Persistent { inner, save: save.clone(), registry: res.assets.clone(), biomes: res.biomes.clone() }), res.context.clone(), res.threads)
|
||||
};
|
||||
streaming.radius = self.options.distance;
|
||||
let mut world = World::new(self.res.facts.air, level.seed);
|
||||
world.game_time = level.time;
|
||||
world.day_time = self.options.time.unwrap_or(level.day_time);
|
||||
self.creative = level.creative;
|
||||
let mut inventory = vec![None; 36];
|
||||
for (slot, id, count, damage) in &level.inventory {
|
||||
if let Some(cell) = inventory.get_mut(usize::from(*slot)) {
|
||||
*cell = Some(ItemStack { item: Arc::from(id.as_str()), count: *count, damage: *damage });
|
||||
}
|
||||
}
|
||||
if self.creative && level.inventory.is_empty() && level.position.is_none() {
|
||||
for (i, name) in ["minecraft:grass_block", "minecraft:stone", "minecraft:oak_planks", "minecraft:glass", "minecraft:torch", "minecraft:oak_log", "minecraft:chest", "minecraft:furnace", "minecraft:diamond_pickaxe"].iter().enumerate() {
|
||||
inventory[i] = Some(ItemStack { item: Arc::from(*name), count: 1, damage: 0 });
|
||||
}
|
||||
}
|
||||
let (yaw, pitch) = self.options.look.unwrap_or((level.rotation[0], level.rotation[1]));
|
||||
self.yaw = yaw;
|
||||
self.pitch = pitch;
|
||||
self.streaming = streaming;
|
||||
self.world = world;
|
||||
self.inventory = inventory;
|
||||
self.save = save;
|
||||
self.level = level;
|
||||
self.player = None;
|
||||
self.spawn = None;
|
||||
self.spawn_search = 0;
|
||||
self.mobs.clear();
|
||||
self.arrows.clear();
|
||||
self.dropped.clear();
|
||||
self.particles.clear();
|
||||
self.mining = None;
|
||||
self.container = None;
|
||||
self.carried = None;
|
||||
self.using = None;
|
||||
self.screen = Screen::Playing;
|
||||
self.title = None;
|
||||
if let Some(r) = self.renderer.as_mut() {
|
||||
r.clear_sections();
|
||||
}
|
||||
// New worlds get their level.dat right away.
|
||||
if !save_root.join("level.dat").exists() {
|
||||
self.level.write(&save_root)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn close_world(&mut self) -> Result<()> {
|
||||
self.save_game()?;
|
||||
self.streaming.paused = true;
|
||||
self.world = World::new(self.res.facts.air, 0);
|
||||
self.player = None;
|
||||
self.mobs.clear();
|
||||
self.arrows.clear();
|
||||
self.dropped.clear();
|
||||
self.particles.clear();
|
||||
self.screen = Screen::Playing;
|
||||
if let Some(r) = self.renderer.as_mut() {
|
||||
r.clear_sections();
|
||||
}
|
||||
self.title = Some(Title::new(std::env::current_dir()?.join("saves")));
|
||||
self.capture(false);
|
||||
Ok(())
|
||||
}
|
||||
/// The title panorama as six camera-centred faces (panorama_0..5:
|
||||
/// front, right, back, left, up, down).
|
||||
fn panorama_geometry(&self) -> Vec<Vertex> {
|
||||
let mut out = Vec::new();
|
||||
let d = 100.0;
|
||||
let faces: [(&str, [glam::Vec3; 4]); 6] = [
|
||||
("0", [glam::Vec3::new(-d, d, -d), glam::Vec3::new(d, d, -d), glam::Vec3::new(d, -d, -d), glam::Vec3::new(-d, -d, -d)]),
|
||||
("1", [glam::Vec3::new(d, d, -d), glam::Vec3::new(d, d, d), glam::Vec3::new(d, -d, d), glam::Vec3::new(d, -d, -d)]),
|
||||
("2", [glam::Vec3::new(d, d, d), glam::Vec3::new(-d, d, d), glam::Vec3::new(-d, -d, d), glam::Vec3::new(d, -d, d)]),
|
||||
("3", [glam::Vec3::new(-d, d, d), glam::Vec3::new(-d, d, -d), glam::Vec3::new(-d, -d, -d), glam::Vec3::new(-d, -d, d)]),
|
||||
("4", [glam::Vec3::new(-d, d, d), glam::Vec3::new(d, d, d), glam::Vec3::new(d, d, -d), glam::Vec3::new(-d, d, -d)]),
|
||||
("5", [glam::Vec3::new(-d, -d, -d), glam::Vec3::new(d, -d, -d), glam::Vec3::new(d, -d, d), glam::Vec3::new(-d, -d, d)]),
|
||||
];
|
||||
for (index, corners) in faces {
|
||||
let Some(r) = self.res.atlas.sprites.get(&format!("gui/title/background/panorama_{index}")).copied() else { continue };
|
||||
let uv = [[r.u0, r.v0], [r.u1, r.v0], [r.u1, r.v1], [r.u0, r.v1]];
|
||||
for (p, uv) in corners.iter().zip(uv) {
|
||||
out.push(Vertex { pos: p.to_array(), uv, layer: 2, color: 0xFFFF_FFFF, light: 0 });
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
fn save_game(&mut self) -> Result<()> {
|
||||
let keys: Vec<_> = self.world.modified.drain().collect();
|
||||
let chunks: Vec<_> = keys
|
||||
@@ -2400,22 +2521,28 @@ impl Game<'_> {
|
||||
None
|
||||
};
|
||||
let hud = self.hud(size);
|
||||
let entities = self.entity_geometry(camera, alpha);
|
||||
let celestial = self.celestial_geometry(&sky);
|
||||
let title = self.title.is_some();
|
||||
let entities = if title { Vec::new() } else { self.entity_geometry(camera, alpha) };
|
||||
let celestial = if title { self.panorama_geometry() } else { self.celestial_geometry(&sky) };
|
||||
let mut entities = entities;
|
||||
self.cloud_geometry(&sky, camera, alpha, &mut entities);
|
||||
if !title {
|
||||
self.cloud_geometry(&sky, camera, alpha, &mut entities);
|
||||
}
|
||||
// PanoramaRenderer: the title cube spins at 0.1 degrees per tick, pitched 10 degrees.
|
||||
let (yaw, pitch) = if title { (-(self.started.elapsed().as_secs_f32() * 2.0) % 360.0, 10.0) } else { (self.yaw, self.pitch) };
|
||||
let water_fog = {
|
||||
let c = info.water_fog;
|
||||
[(c >> 16 & 255) as f32 / 255.0, (c >> 8 & 255) as f32 / 255.0, (c & 255) as f32 / 255.0]
|
||||
};
|
||||
let frame = Frame {
|
||||
camera,
|
||||
yaw: self.yaw,
|
||||
pitch: self.pitch,
|
||||
fov_degrees: 70.0,
|
||||
yaw,
|
||||
pitch,
|
||||
fov_degrees: if title { 85.0 } else { 70.0 },
|
||||
sky,
|
||||
distance: (self.streaming.radius * 16) as f32,
|
||||
underwater,
|
||||
title,
|
||||
water_fog,
|
||||
outline,
|
||||
hud: &hud,
|
||||
@@ -2500,7 +2627,9 @@ impl ApplicationHandler for Game<'_> {
|
||||
let result: Result<()> = (|| {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
self.save_game()?;
|
||||
if self.title.is_none() {
|
||||
self.save_game()?;
|
||||
}
|
||||
event_loop.exit();
|
||||
}
|
||||
WindowEvent::Resized(size) => {
|
||||
@@ -2535,6 +2664,20 @@ impl ApplicationHandler for Game<'_> {
|
||||
self.selected = (self.selected as i32 - d.signum() as i32).rem_euclid(9) as usize;
|
||||
}
|
||||
}
|
||||
WindowEvent::MouseInput { state, button: MouseButton::Left, .. }
|
||||
if self.title.is_some() && state == ElementState::Pressed =>
|
||||
{
|
||||
let size = self.renderer.as_ref().map(|r| [r.config.width, r.config.height]).unwrap_or([1, 1]);
|
||||
let b = HudBatch::new(size);
|
||||
let action = self.title.as_mut().map_or(Action::None, |t| t.click(self.cursor.0, self.cursor.1, (b.width, b.height)));
|
||||
match action {
|
||||
Action::Quit => event_loop.exit(),
|
||||
Action::Play { folder } => self.open_world(&folder, None, None, false)?,
|
||||
Action::Create { folder, name, seed, creative } => self.open_world(&folder, Some(&name), seed, creative)?,
|
||||
Action::None => {}
|
||||
}
|
||||
}
|
||||
WindowEvent::MouseInput { .. } if self.title.is_some() => {}
|
||||
WindowEvent::MouseInput { state, button, .. } => {
|
||||
let pressed = state == ElementState::Pressed;
|
||||
match self.screen {
|
||||
@@ -2585,8 +2728,7 @@ impl ApplicationHandler for Game<'_> {
|
||||
self.screen = Screen::Playing;
|
||||
self.capture(true);
|
||||
} else {
|
||||
self.save_game()?;
|
||||
event_loop.exit();
|
||||
self.close_world()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2600,6 +2742,22 @@ impl ApplicationHandler for Game<'_> {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
WindowEvent::KeyboardInput { event, .. } if self.title.is_some() => {
|
||||
if event.state == ElementState::Pressed
|
||||
&& let Some(title) = self.title.as_mut()
|
||||
{
|
||||
match event.physical_key {
|
||||
PhysicalKey::Code(KeyCode::Backspace) => title.backspace(),
|
||||
PhysicalKey::Code(KeyCode::Tab) => title.tab(),
|
||||
PhysicalKey::Code(KeyCode::Escape) => title.escape(),
|
||||
_ => {
|
||||
if let Some(text) = &event.text {
|
||||
title.type_text(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WindowEvent::KeyboardInput { event, .. } => {
|
||||
let PhysicalKey::Code(key) = event.physical_key else { return Ok(()) };
|
||||
if event.state != ElementState::Pressed {
|
||||
@@ -2665,11 +2823,15 @@ impl ApplicationHandler for Game<'_> {
|
||||
let secs = elapsed.as_secs_f32().min(0.1);
|
||||
self.yaw += (turn(KeyCode::ArrowRight) - turn(KeyCode::ArrowLeft)) * 90.0 * secs;
|
||||
self.pitch = (self.pitch + (turn(KeyCode::ArrowDown) - turn(KeyCode::ArrowUp)) * 90.0 * secs).clamp(-90.0, 90.0);
|
||||
self.update_world();
|
||||
self.spawn_player()?;
|
||||
if self.title.is_none() {
|
||||
self.update_world();
|
||||
self.spawn_player()?;
|
||||
}
|
||||
let steps = self.clock.advance(elapsed);
|
||||
for _ in 0..steps {
|
||||
self.tick()?;
|
||||
if self.title.is_none() {
|
||||
self.tick()?;
|
||||
}
|
||||
}
|
||||
if self.render()? {
|
||||
self.frames += 1;
|
||||
@@ -2757,37 +2919,6 @@ pub fn run() -> Result<()> {
|
||||
light,
|
||||
});
|
||||
let threads = std::thread::available_parallelism().map_or(2, |n| n.get()).saturating_sub(1).max(1);
|
||||
let save_root = std::env::current_dir()?.join("saves").join(&options.world);
|
||||
let level = Level::read(&save_root).unwrap_or_else(|| Level {
|
||||
name: options.world.clone(),
|
||||
seed: options.seed,
|
||||
creative: options.creative,
|
||||
day_time: 1000,
|
||||
health: 20.0,
|
||||
food: 20,
|
||||
saturation: 5.0,
|
||||
..Level::default()
|
||||
});
|
||||
let save = Arc::new(SaveDir::new(save_root));
|
||||
let mut streaming = if options.test_terrain {
|
||||
let inner = Arc::new(TestTerrain::new(assets.registry, &biomes)?);
|
||||
Streaming::new(
|
||||
Arc::new(Persistent { inner, save: save.clone(), registry: assets.clone(), biomes: biomes.clone() }),
|
||||
context,
|
||||
threads,
|
||||
)
|
||||
} else {
|
||||
let inner = Arc::new(VanillaTerrain::new(&root.join("worldgen"), assets.registry, &biomes, level.seed).map_err(|e| {
|
||||
format!("{e}\nPrepare the worldgen bundle with: python3 tools/prepare_native_client.py")
|
||||
})?);
|
||||
eprintln!("load worldgen: {:.2}s", started.elapsed().as_secs_f32());
|
||||
Streaming::new(
|
||||
Arc::new(Persistent { inner, save: save.clone(), registry: assets.clone(), biomes: biomes.clone() }),
|
||||
context,
|
||||
threads,
|
||||
)
|
||||
};
|
||||
streaming.radius = options.distance;
|
||||
eprintln!(
|
||||
"Horizon: resources loaded in {:.1}s; {} block states, {} items, {} biomes; {} worker threads",
|
||||
started.elapsed().as_secs_f32(),
|
||||
@@ -2796,11 +2927,18 @@ pub fn run() -> Result<()> {
|
||||
biomes.list.len(),
|
||||
threads
|
||||
);
|
||||
// Until a world is opened the streamer is idle.
|
||||
let mut streaming = Streaming::new(
|
||||
Arc::new(TestTerrain::new(assets.registry, &biomes)?),
|
||||
context.clone(),
|
||||
1,
|
||||
);
|
||||
streaming.paused = true;
|
||||
let level = Level::default();
|
||||
let save = Arc::new(SaveDir::new(std::env::current_dir()?.join("saves").join(".horizon-title")));
|
||||
let audio = Audio::new(&root);
|
||||
let mut world = World::new(facts.air, level.seed);
|
||||
world.game_time = level.time;
|
||||
world.day_time = options.time.unwrap_or(level.day_time);
|
||||
let creative = level.creative || options.creative;
|
||||
let world = World::new(facts.air, 0);
|
||||
let creative = options.creative;
|
||||
let mut resources = Resources {
|
||||
assets,
|
||||
facts,
|
||||
@@ -2817,19 +2955,10 @@ pub fn run() -> Result<()> {
|
||||
.map(|(w, h, px)| (w, h, px.chunks_exact(4).map(|p| p[3] > 0).collect()))
|
||||
.unwrap_or((1, 1, vec![false])),
|
||||
mob_types: MobTypes::load(&root)?.types.into_iter().map(|(k, v)| (k, Arc::new(v))).collect(),
|
||||
context,
|
||||
threads,
|
||||
};
|
||||
let mut inventory = vec![None; 36];
|
||||
for (slot, id, count, damage) in &level.inventory {
|
||||
if let Some(cell) = inventory.get_mut(usize::from(*slot)) {
|
||||
*cell = Some(ItemStack { item: Arc::from(id.as_str()), count: *count, damage: *damage });
|
||||
}
|
||||
}
|
||||
let fresh = level.inventory.is_empty() && level.position.is_none();
|
||||
if creative && fresh {
|
||||
for (i, name) in ["minecraft:grass_block", "minecraft:stone", "minecraft:oak_planks", "minecraft:glass", "minecraft:torch", "minecraft:oak_log", "minecraft:cobblestone", "minecraft:water_bucket", "minecraft:diamond_pickaxe"].iter().enumerate() {
|
||||
inventory[i] = Some(ItemStack { item: Arc::from(*name), count: 1, damage: 0 });
|
||||
}
|
||||
}
|
||||
let inventory = vec![None; 36];
|
||||
let now = Instant::now();
|
||||
let look = options.look;
|
||||
let mut game = Game {
|
||||
@@ -2890,7 +3019,15 @@ pub fn run() -> Result<()> {
|
||||
last_hurt_by_player: HashSet::new(),
|
||||
chest_open: HashMap::new(),
|
||||
using: None,
|
||||
title: None,
|
||||
};
|
||||
match game.options.world.clone() {
|
||||
Some(folder) => {
|
||||
let (seed, creative) = (game.options.seed, game.options.creative);
|
||||
game.open_world(&folder, None, Some(seed), creative)?;
|
||||
}
|
||||
None => game.title = Some(Title::new(std::env::current_dir()?.join("saves"))),
|
||||
}
|
||||
EventLoop::new()?.run_app(&mut game)?;
|
||||
if let Some(path) = &game.options.report {
|
||||
let report = serde_json::json!({
|
||||
|
||||
@@ -40,6 +40,8 @@ pub struct Frame<'a> {
|
||||
/// Render distance in blocks (fog end).
|
||||
pub distance: f32,
|
||||
pub underwater: bool,
|
||||
/// Title screen: only the panorama (in `celestial`) and the HUD.
|
||||
pub title: bool,
|
||||
pub water_fog: [f32; 3],
|
||||
pub outline: Option<[f64; 6]>,
|
||||
pub hud: &'a HudBatch,
|
||||
@@ -745,6 +747,9 @@ impl Renderer {
|
||||
},
|
||||
);
|
||||
}
|
||||
pub fn clear_sections(&mut self) {
|
||||
self.sections.clear();
|
||||
}
|
||||
pub fn remove(&mut self, key: SectionKey) {
|
||||
self.sections.remove(&key);
|
||||
}
|
||||
@@ -1026,11 +1031,15 @@ impl Renderer {
|
||||
resolve_target: None,
|
||||
depth_slice: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: f64::from(fog_color[0]),
|
||||
g: f64::from(fog_color[1]),
|
||||
b: f64::from(fog_color[2]),
|
||||
a: 1.0,
|
||||
load: wgpu::LoadOp::Clear(if frame.title {
|
||||
wgpu::Color::BLACK
|
||||
} else {
|
||||
wgpu::Color {
|
||||
r: f64::from(fog_color[0]),
|
||||
g: f64::from(fog_color[1]),
|
||||
b: f64::from(fog_color[2]),
|
||||
a: 1.0,
|
||||
}
|
||||
}),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
@@ -1050,8 +1059,10 @@ impl Renderer {
|
||||
});
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
if !frame.underwater {
|
||||
pass.set_pipeline(&self.sky);
|
||||
pass.draw(0..3, 0..1);
|
||||
if !frame.title {
|
||||
pass.set_pipeline(&self.sky);
|
||||
pass.draw(0..3, 0..1);
|
||||
}
|
||||
if celestial_vertices > 0 {
|
||||
pass.set_pipeline(&self.celestial_pipeline);
|
||||
pass.set_bind_group(0, &self.entity_group, &[]);
|
||||
@@ -1061,6 +1072,9 @@ impl Renderer {
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
}
|
||||
}
|
||||
if frame.title {
|
||||
visible.clear();
|
||||
}
|
||||
pass.set_pipeline(&self.solid);
|
||||
pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32);
|
||||
pass.set_vertex_buffer(1, self.instances.slice(..));
|
||||
|
||||
@@ -74,7 +74,7 @@ impl HudAtlas {
|
||||
walk(&textures.join("particle"), &mut files);
|
||||
files.retain(|p| {
|
||||
let s = p.to_string_lossy();
|
||||
!s.contains("title/background") && !s.contains("realms") && !s.contains("presets")
|
||||
(!s.contains("title/background") || s.contains("panorama_")) && !s.contains("realms") && !s.contains("presets")
|
||||
});
|
||||
let decode_one = |path: &PathBuf| -> Option<(String, u32, u32, Vec<u8>)> {
|
||||
let name = path
|
||||
@@ -91,7 +91,19 @@ impl HudAtlas {
|
||||
} else {
|
||||
pixels
|
||||
};
|
||||
(w <= 512 && h <= 512).then_some((name, w, h, pixels))
|
||||
// Title panorama faces are downsampled to 256 for the shared atlas.
|
||||
if name.contains("panorama_") && w >= 512 && w == h {
|
||||
let step = (w / 256) as usize;
|
||||
let mut small = Vec::with_capacity(256 * 256 * 4);
|
||||
for y in 0..256usize {
|
||||
for x in 0..256usize {
|
||||
let i = ((y * step) * w as usize + x * step) * 4;
|
||||
small.extend_from_slice(&pixels[i..i + 4]);
|
||||
}
|
||||
}
|
||||
return Some((name, 256, 256, small));
|
||||
}
|
||||
(w <= 1024 && h <= 512).then_some((name, w, h, pixels))
|
||||
};
|
||||
let threads = std::thread::available_parallelism().map_or(2, |n| n.get());
|
||||
let chunk = files.len().div_ceil(threads).max(1);
|
||||
|
||||
@@ -32,6 +32,7 @@ pub mod sprint;
|
||||
pub mod sprites;
|
||||
pub mod streaming;
|
||||
pub mod testgen;
|
||||
pub mod title;
|
||||
pub mod vanillagen;
|
||||
pub mod world;
|
||||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
@@ -104,6 +104,8 @@ pub struct Streaming {
|
||||
sequence: u64,
|
||||
pub center: (i32, i32),
|
||||
pub radius: i32,
|
||||
/// No work is scheduled while paused (title screen).
|
||||
pub paused: bool,
|
||||
pub generated_total: u64,
|
||||
pub meshed_total: u64,
|
||||
}
|
||||
@@ -193,6 +195,7 @@ impl Streaming {
|
||||
sequence: 0,
|
||||
center: (0, 0),
|
||||
radius: 8,
|
||||
paused: false,
|
||||
generated_total: 0,
|
||||
meshed_total: 0,
|
||||
}
|
||||
@@ -229,6 +232,9 @@ impl Streaming {
|
||||
/// Returns meshes ready for upload and columns that were unloaded.
|
||||
pub fn update(&mut self, world: &mut World) -> (Vec<((i32, i32, i32), SectionMesh)>, Vec<Arc<Chunk>>) {
|
||||
let mut uploads = Vec::new();
|
||||
if self.paused {
|
||||
return (uploads, Vec::new());
|
||||
}
|
||||
while let Ok(done) = self.results.try_recv() {
|
||||
match done {
|
||||
Done::Proto(x, z, proto) => {
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
//! Title, world selection and world creation screens (TitleScreen,
|
||||
//! SelectWorldScreen, CreateWorldScreen layouts), drawn as HUD quads.
|
||||
use crate::{
|
||||
hud::{HudAtlas, HudBatch, rgba},
|
||||
save::Level,
|
||||
};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WorldEntry {
|
||||
pub folder: String,
|
||||
pub name: String,
|
||||
pub creative: bool,
|
||||
pub modified: std::time::SystemTime,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Mode {
|
||||
Main,
|
||||
Select { worlds: Vec<WorldEntry>, selected: Option<usize> },
|
||||
Create { name: String, seed: String, creative: bool, focus: u8 },
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Action {
|
||||
None,
|
||||
Quit,
|
||||
Play { folder: String },
|
||||
Create { folder: String, name: String, seed: Option<i64>, creative: bool },
|
||||
}
|
||||
pub struct Title {
|
||||
pub mode: Mode,
|
||||
pub saves: PathBuf,
|
||||
pub started: std::time::Instant,
|
||||
}
|
||||
struct Button {
|
||||
x: f32,
|
||||
y: f32,
|
||||
w: f32,
|
||||
label: String,
|
||||
enabled: bool,
|
||||
id: u8,
|
||||
}
|
||||
/// Java String.hashCode for text seeds (WorldOptions.parseSeed).
|
||||
pub fn parse_seed(text: &str) -> Option<i64> {
|
||||
let t = text.trim();
|
||||
if t.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(t.parse::<i64>().unwrap_or_else(|_| i64::from(t.encode_utf16().fold(0i32, |h, c| h.wrapping_mul(31).wrapping_add(i32::from(c))))))
|
||||
}
|
||||
pub fn list_worlds(saves: &Path) -> Vec<WorldEntry> {
|
||||
let mut worlds: Vec<WorldEntry> = std::fs::read_dir(saves)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.filter_map(|e| {
|
||||
let path = e.path();
|
||||
let level = Level::read(&path)?;
|
||||
let modified = std::fs::metadata(path.join("level.dat")).and_then(|m| m.modified()).ok()?;
|
||||
Some(WorldEntry {
|
||||
folder: e.file_name().to_string_lossy().into_owned(),
|
||||
name: level.name,
|
||||
creative: level.creative,
|
||||
modified,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
worlds.sort_by(|a, b| b.modified.cmp(&a.modified));
|
||||
worlds
|
||||
}
|
||||
impl Title {
|
||||
pub fn new(saves: PathBuf) -> Self {
|
||||
Self { mode: Mode::Main, saves, started: std::time::Instant::now() }
|
||||
}
|
||||
fn buttons(&self, w: f32, h: f32) -> Vec<Button> {
|
||||
let b = |x: f32, y: f32, w: f32, label: &str, enabled: bool, id: u8| Button { x, y, w, label: label.into(), enabled, id };
|
||||
match &self.mode {
|
||||
Mode::Main => {
|
||||
let y = h / 4.0 + 48.0;
|
||||
vec![
|
||||
b(w / 2.0 - 100.0, y, 200.0, "Singleplayer", true, 1),
|
||||
b(w / 2.0 - 100.0, y + 24.0, 200.0, "Multiplayer", false, 0),
|
||||
b(w / 2.0 - 100.0, y + 48.0, 200.0, "Minecraft Realms", false, 0),
|
||||
b(w / 2.0 - 100.0, y + 84.0, 98.0, "Options...", false, 0),
|
||||
b(w / 2.0 + 2.0, y + 84.0, 98.0, "Quit Game", true, 2),
|
||||
]
|
||||
}
|
||||
Mode::Select { selected, .. } => vec![
|
||||
b(w / 2.0 - 154.0, h - 52.0, 150.0, "Play Selected World", selected.is_some(), 10),
|
||||
b(w / 2.0 + 4.0, h - 52.0, 150.0, "Create New World", true, 11),
|
||||
b(w / 2.0 + 4.0, h - 28.0, 150.0, "Back", true, 12),
|
||||
],
|
||||
Mode::Create { creative, .. } => vec![
|
||||
b(w / 2.0 - 75.0, 120.0, 150.0, if *creative { "Game Mode: Creative" } else { "Game Mode: Survival" }, true, 20),
|
||||
b(w / 2.0 - 155.0, h - 28.0, 150.0, "Create New World", true, 21),
|
||||
b(w / 2.0 + 5.0, h - 28.0, 150.0, "Cancel", true, 22),
|
||||
],
|
||||
}
|
||||
}
|
||||
pub fn draw(&self, atlas: &HudAtlas, batch: &mut HudBatch, cursor: (f32, f32)) {
|
||||
let (w, h) = (batch.width, batch.height);
|
||||
match &self.mode {
|
||||
Mode::Main => {
|
||||
// Logo: minecraft.png is a 1024x256 sheet drawn at 256x64.
|
||||
batch.sprite_scaled(atlas, "gui/title/minecraft", w / 2.0 - 128.0, 30.0, 256.0, 64.0, u32::MAX);
|
||||
batch.sprite_scaled(atlas, "gui/title/edition", w / 2.0 - 64.0, 30.0 + 64.0 - 7.0, 128.0, 14.0, u32::MAX);
|
||||
let version = "Horizon 26.3 (Rust)";
|
||||
batch.text(atlas, version, 2.0, h - 10.0, u32::MAX, true);
|
||||
let notice = "Not affiliated with Mojang or Microsoft";
|
||||
let tw = HudBatch::text_width(atlas, notice);
|
||||
batch.text(atlas, notice, w - tw - 2.0, h - 10.0, u32::MAX, true);
|
||||
}
|
||||
Mode::Select { worlds, selected } => {
|
||||
batch.fill(atlas, 0.0, 0.0, w, h, rgba(0, 0, 0, 120));
|
||||
let title = "Select World";
|
||||
let tw = HudBatch::text_width(atlas, title);
|
||||
batch.text(atlas, title, (w - tw) / 2.0, 8.0, u32::MAX, true);
|
||||
batch.fill(atlas, 0.0, 32.0, w, h - 32.0 - 64.0, rgba(0, 0, 0, 100));
|
||||
for (i, world) in worlds.iter().enumerate() {
|
||||
let y = 36.0 + i as f32 * 36.0;
|
||||
if y + 36.0 > h - 64.0 {
|
||||
break;
|
||||
}
|
||||
let x = w / 2.0 - 110.0;
|
||||
if *selected == Some(i) {
|
||||
batch.fill(atlas, x - 2.0, y - 2.0, 224.0, 36.0, rgba(128, 128, 128, 255));
|
||||
batch.fill(atlas, x - 1.0, y - 1.0, 222.0, 34.0, rgba(0, 0, 0, 255));
|
||||
}
|
||||
batch.text(atlas, &world.name, x + 34.0, y + 1.0, u32::MAX, false);
|
||||
let date = world.modified.duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_secs());
|
||||
let line = format!("{} ({})", world.folder, date_string(date));
|
||||
batch.text(atlas, &line, x + 34.0, y + 12.0, rgba(128, 128, 128, 255), false);
|
||||
let mode = if world.creative { "Creative Mode" } else { "Survival Mode" };
|
||||
batch.text(atlas, mode, x + 34.0, y + 22.0, rgba(128, 128, 128, 255), false);
|
||||
batch.sprite_scaled(atlas, "misc/unknown_server", x, y, 32.0, 32.0, u32::MAX);
|
||||
}
|
||||
if worlds.is_empty() {
|
||||
let empty = "No worlds yet: create one!";
|
||||
let tw = HudBatch::text_width(atlas, empty);
|
||||
batch.text(atlas, empty, (w - tw) / 2.0, h / 2.0 - 20.0, rgba(160, 160, 160, 255), true);
|
||||
}
|
||||
}
|
||||
Mode::Create { name, seed, focus, .. } => {
|
||||
batch.fill(atlas, 0.0, 0.0, w, h, rgba(0, 0, 0, 120));
|
||||
let title = "Create New World";
|
||||
let tw = HudBatch::text_width(atlas, title);
|
||||
batch.text(atlas, title, (w - tw) / 2.0, 8.0, u32::MAX, true);
|
||||
let blink = (self.started.elapsed().as_millis() / 300) % 2 == 0;
|
||||
for (i, (label, value)) in [("World Name", name), ("Seed for the World Generator (leave blank for random)", seed)].iter().enumerate() {
|
||||
let y = 40.0 + i as f32 * 40.0;
|
||||
batch.text(atlas, label, w / 2.0 - 100.0, y, rgba(160, 160, 160, 255), true);
|
||||
batch.fill(atlas, w / 2.0 - 100.0, y + 11.0, 200.0, 20.0, if *focus == i as u8 { u32::MAX } else { rgba(160, 160, 160, 255) });
|
||||
batch.fill(atlas, w / 2.0 - 99.0, y + 12.0, 198.0, 18.0, rgba(0, 0, 0, 255));
|
||||
let shown = if *focus == i as u8 && blink { format!("{value}_") } else { value.to_string() };
|
||||
batch.text(atlas, &shown, w / 2.0 - 96.0, y + 17.0, rgba(224, 224, 224, 255), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
for b in self.buttons(w, h) {
|
||||
let hover = b.enabled && cursor.0 >= b.x && cursor.0 < b.x + b.w && cursor.1 >= b.y && cursor.1 < b.y + 20.0;
|
||||
let sprite = if !b.enabled {
|
||||
"gui/sprites/widget/button_disabled"
|
||||
} else if hover {
|
||||
"gui/sprites/widget/button_highlighted"
|
||||
} else {
|
||||
"gui/sprites/widget/button"
|
||||
};
|
||||
// Nine-slice approximation: left and right halves of the 200-wide sprite.
|
||||
if let Some(r) = atlas.sprites.get(sprite).copied() {
|
||||
let half = b.w / 2.0;
|
||||
let mut left = r;
|
||||
left.u1 = r.u0 + (r.u1 - r.u0) * (half / r.w as f32);
|
||||
batch.rect_uv(b.x, b.y, half, 20.0, left, u32::MAX);
|
||||
let mut right = r;
|
||||
right.u0 = r.u1 - (r.u1 - r.u0) * (half / r.w as f32);
|
||||
batch.rect_uv(b.x + half, b.y, half, 20.0, right, u32::MAX);
|
||||
}
|
||||
let color = if b.enabled { u32::MAX } else { rgba(160, 160, 160, 255) };
|
||||
let tw = HudBatch::text_width(atlas, &b.label);
|
||||
batch.text(atlas, &b.label, b.x + (b.w - tw) / 2.0, b.y + 6.0, color, true);
|
||||
}
|
||||
}
|
||||
pub fn click(&mut self, x: f32, y: f32, size: (f32, f32)) -> Action {
|
||||
let (w, h) = size;
|
||||
let hit = self
|
||||
.buttons(w, h)
|
||||
.into_iter()
|
||||
.find(|b| b.enabled && x >= b.x && x < b.x + b.w && y >= b.y && y < b.y + 20.0)
|
||||
.map(|b| b.id);
|
||||
match (&mut self.mode, hit) {
|
||||
(Mode::Main, Some(1)) => {
|
||||
self.mode = Mode::Select { worlds: list_worlds(&self.saves), selected: None };
|
||||
Action::None
|
||||
}
|
||||
(Mode::Main, Some(2)) => Action::Quit,
|
||||
(Mode::Select { worlds, selected }, Some(10)) => match selected.and_then(|i| worlds.get(i)) {
|
||||
Some(world) => Action::Play { folder: world.folder.clone() },
|
||||
None => Action::None,
|
||||
},
|
||||
(Mode::Select { .. }, Some(11)) => {
|
||||
self.mode = Mode::Create { name: "New World".into(), seed: String::new(), creative: false, focus: 0 };
|
||||
Action::None
|
||||
}
|
||||
(Mode::Select { .. }, Some(12)) => {
|
||||
self.mode = Mode::Main;
|
||||
Action::None
|
||||
}
|
||||
(Mode::Select { worlds, selected }, None) => {
|
||||
// Clicking a list entry selects it; clicking it again plays it.
|
||||
let index = ((y - 36.0) / 36.0).floor();
|
||||
if y >= 36.0 && y < h - 64.0 && (x - w / 2.0).abs() < 112.0 && (index as usize) < worlds.len() {
|
||||
let index = index as usize;
|
||||
if *selected == Some(index) {
|
||||
return Action::Play { folder: worlds[index].folder.clone() };
|
||||
}
|
||||
*selected = Some(index);
|
||||
}
|
||||
Action::None
|
||||
}
|
||||
(Mode::Create { creative, .. }, Some(20)) => {
|
||||
*creative = !*creative;
|
||||
Action::None
|
||||
}
|
||||
(Mode::Create { name, seed, creative, .. }, Some(21)) => {
|
||||
let base: String = name
|
||||
.chars()
|
||||
.map(|c| if c.is_alphanumeric() || c == ' ' || c == '-' || c == '_' { c } else { '_' })
|
||||
.collect();
|
||||
let base = if base.trim().is_empty() { "World".to_owned() } else { base.trim().to_owned() };
|
||||
// FileUtil.findAvailableName: append (n) until unused.
|
||||
let mut folder = base.clone();
|
||||
let mut n = 1;
|
||||
while self.saves.join(&folder).exists() {
|
||||
folder = format!("{base} ({n})");
|
||||
n += 1;
|
||||
}
|
||||
Action::Create { folder, name: name.clone(), seed: parse_seed(seed), creative: *creative }
|
||||
}
|
||||
(Mode::Create { .. }, Some(22)) => {
|
||||
self.mode = Mode::Select { worlds: list_worlds(&self.saves), selected: None };
|
||||
Action::None
|
||||
}
|
||||
(Mode::Create { focus, .. }, None) => {
|
||||
for i in 0..2u8 {
|
||||
let fy = 40.0 + f32::from(i) * 40.0 + 11.0;
|
||||
if y >= fy && y < fy + 20.0 && (x - w / 2.0).abs() < 100.0 {
|
||||
*focus = i;
|
||||
}
|
||||
}
|
||||
Action::None
|
||||
}
|
||||
_ => Action::None,
|
||||
}
|
||||
}
|
||||
pub fn type_text(&mut self, text: &str) {
|
||||
if let Mode::Create { name, seed, focus, .. } = &mut self.mode {
|
||||
let field = if *focus == 0 { name } else { seed };
|
||||
for c in text.chars().filter(|c| !c.is_control()) {
|
||||
if field.chars().count() < 32 {
|
||||
field.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn backspace(&mut self) {
|
||||
if let Mode::Create { name, seed, focus, .. } = &mut self.mode {
|
||||
let field = if *focus == 0 { name } else { seed };
|
||||
field.pop();
|
||||
}
|
||||
}
|
||||
pub fn tab(&mut self) {
|
||||
if let Mode::Create { focus, .. } = &mut self.mode {
|
||||
*focus = (*focus + 1) % 2;
|
||||
}
|
||||
}
|
||||
pub fn escape(&mut self) {
|
||||
self.mode = match &self.mode {
|
||||
Mode::Create { .. } => Mode::Select { worlds: list_worlds(&self.saves), selected: None },
|
||||
_ => Mode::Main,
|
||||
};
|
||||
}
|
||||
}
|
||||
fn date_string(secs: u64) -> String {
|
||||
// Civil date from Unix time (days-from-civil inverse), UTC.
|
||||
let days = (secs / 86400) as i64;
|
||||
let (h, m) = ((secs % 86400) / 3600, (secs % 3600) / 60);
|
||||
let z = days + 719_468;
|
||||
let era = z.div_euclid(146_097);
|
||||
let doe = z - era * 146_097;
|
||||
let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146_096) / 365;
|
||||
let y = yoe + era * 400;
|
||||
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
|
||||
let mp = (5 * doy + 2) / 153;
|
||||
let d = doy - (153 * mp + 2) / 5 + 1;
|
||||
let mo = if mp < 10 { mp + 3 } else { mp - 9 };
|
||||
let y = if mo <= 2 { y + 1 } else { y };
|
||||
format!("{y}-{mo:02}-{d:02} {h:02}:{m:02}")
|
||||
}
|
||||
+5
-6
@@ -2,12 +2,11 @@
|
||||
|
||||
The behavior target is the repository's pinned **Minecraft Java Edition 26.3**.
|
||||
One-to-one vanilla gameplay parity is the acceptance criterion. It has **not**
|
||||
been reached. Horizon now has a [native development client](native-client.md)
|
||||
that renders a controlled resident-chunk scene with blockstate-selected models
|
||||
and an inspection camera with optional resident-block collisions. F5 now enables
|
||||
a dry walking test with fixed-rate gravity, jumping, stepping and native-checked
|
||||
keyboard input preparation over that scene. It does not run a
|
||||
complete game server or gameplay simulation.
|
||||
been reached, but the Rust game is now playable: the [native client](native-client.md)
|
||||
has a title screen and world management. It generates vanilla terrain with
|
||||
decoration and streams, lights and renders it. Survival play works: mining,
|
||||
placing, crafting, chests and furnaces, items, mobs, combat, hunger, health,
|
||||
sounds, and Anvil saves.
|
||||
The Rust workspace implements core arithmetic/random streams, world data and
|
||||
resident sections, scheduled tick ordering, geometry, contained fluid states,
|
||||
noise/density evaluation, biome and terrain generation kernels, material rules,
|
||||
|
||||
Reference in New Issue
Block a user