summaryrefslogtreecommitdiff
path: root/pixel-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client/src')
-rw-r--r--pixel-client/src/game.rs5
-rw-r--r--pixel-client/src/main.rs26
-rw-r--r--pixel-client/src/render/font.rs2
3 files changed, 20 insertions, 13 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs
index 59b30ad0..1f74d491 100644
--- a/pixel-client/src/game.rs
+++ b/pixel-client/src/game.rs
@@ -116,7 +116,10 @@ impl Game {
keyboard: &KeyboardState,
layout: &AtlasLayout,
) -> Option<Box<State>> {
- self.network.poll().unwrap();
+ if let Err(e) = self.network.poll() {
+ eprintln!("network error: {e}");
+ return Some(Box::new(State::Quit));
+ }
// TODO perf
for packet in self.network.queue_in.drain(..).collect::<Vec<_>>() {
diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs
index a073d0ed..eee426b1 100644
--- a/pixel-client/src/main.rs
+++ b/pixel-client/src/main.rs
@@ -16,7 +16,7 @@
*/
#![feature(map_many_mut, path_add_extension)]
-use anyhow::Result;
+use anyhow::{anyhow, Result};
use clap::{Parser, Subcommand};
use config::Config;
use game::Game;
@@ -67,26 +67,26 @@ fn main() -> Result<()> {
rustls::crypto::ring::default_provider()
.install_default()
- .unwrap();
+ .expect("failed to initialize crypto things");
- let sdl_context = sdl2::init().unwrap();
+ let sdl_context = sdl2::init().map_err(|e| anyhow!("sdl2 init failed: {e}"))?;
- let video_subsystem = sdl_context.video().unwrap();
+ let video_subsystem = sdl_context
+ .video()
+ .map_err(|e| anyhow!("sdl2 video subsystem init failed: {e}"))?;
let window = video_subsystem
.window("Pixel Curry!", 1280, 720)
.position_centered()
.resizable()
.build()
- .map_err(|e| e.to_string())
- .unwrap();
+ .map_err(|e| anyhow!("sdl2 window creation failed: {e}"))?;
let mut canvas = window
.into_canvas()
.accelerated()
.present_vsync()
.build()
- .map_err(|e| e.to_string())
- .unwrap();
+ .map_err(|e| anyhow!("sdl2 canvas creation failed: {e}"))?;
let texture_creator = canvas.texture_creator();
@@ -95,18 +95,22 @@ fn main() -> Result<()> {
let mut state = match args.action.unwrap_or_default() {
Action::Menu => State::MainMenu(MainMenu::new(renderer.atlas_layout())),
Action::Join { server_address } => State::Ingame(Box::new(Game::new(
- Network::connect(&server_address).unwrap(),
+ Network::connect(&server_address)?,
&config,
renderer.atlas_layout(),
))),
};
- let mut events = sdl_context.event_pump().unwrap();
+ let mut events = sdl_context
+ .event_pump()
+ .map_err(|e| anyhow!("sdl2 event pump: {e}"))?;
let mut last_tick = Instant::now();
let mut profiler = ProfilerOverlay::new();
'mainloop: loop {
- let (width, height) = canvas.output_size().unwrap();
+ let (width, height) = canvas
+ .output_size()
+ .map_err(|_| anyhow!("cannot get canvas size"))?;
renderer.size = Vec2::new(width as f32, height as f32);
let keyboard = KeyboardState::new(&events);
diff --git a/pixel-client/src/render/font.rs b/pixel-client/src/render/font.rs
index f1e7f4d3..79e54753 100644
--- a/pixel-client/src/render/font.rs
+++ b/pixel-client/src/render/font.rs
@@ -36,7 +36,7 @@ impl FontTextures {
})
.collect::<Vec<_>>()
.try_into()
- .unwrap(),
+ .expect("some letters are missing in the font"),
}
}
}