| @@ -24,9 +24,8 @@ use glyph_brush::{ | |||
| BrushAction, BrushError, FontId, GlyphBrush, GlyphBrushBuilder, GlyphVertex, OwnedSection, | |||
| OwnedText, Rectangle, | |||
| }; | |||
| use log::warn; | |||
| use ordered_float::OrderedFloat; | |||
| use space_crush_common::misc::{Vfs, WorldHelper as _}; | |||
| use space_crush_common::misc::{LogResult, Vfs, WorldHelper as _}; | |||
| use specs::World; | |||
| use crate::{misc::WorldHelper, Error}; | |||
| @@ -149,9 +148,7 @@ impl TextCache { | |||
| drop(inner); | |||
| if update_requested { | |||
| if let Err(err) = self.update() { | |||
| warn!("Unable to update text cache: {}", err); | |||
| } | |||
| self.update().error("Unable to update text cache"); | |||
| } | |||
| } | |||
| @@ -347,7 +344,7 @@ fn resize_texture(new_size: (u32, u32), cur_size: Option<(u32, u32)>) -> Result< | |||
| } | |||
| fn update_texture(texture: &Texture, rect: Rectangle<u32>, data: &[u8]) { | |||
| let ret = GlcError::checked(|| { | |||
| GlcError::checked(|| { | |||
| gl::texture_sub_image_2d( | |||
| texture.id(), | |||
| 0, | |||
| @@ -359,11 +356,8 @@ fn update_texture(texture: &Texture, rect: Rectangle<u32>, data: &[u8]) { | |||
| gl::UNSIGNED_BYTE, | |||
| data.as_ptr() as _, | |||
| ) | |||
| }); | |||
| if let Err(err) = ret { | |||
| warn!("Unable to update text texture: {}", err); | |||
| } | |||
| }) | |||
| .error("Unable to update text texture"); | |||
| } | |||
| fn create_vertex(data: GlyphVertex<Extra>) -> Vertex { | |||
| @@ -1,7 +1,6 @@ | |||
| use std::string::ToString; | |||
| use log::warn; | |||
| use space_crush_common::resources::Global; | |||
| use space_crush_common::{misc::LogResult, resources::Global}; | |||
| use specs::{ReadExpect, System}; | |||
| use crate::{ | |||
| @@ -88,8 +87,6 @@ where | |||
| if old != new { | |||
| *old = *new; | |||
| let s = update(old); | |||
| if let Err(err) = text.update(pos, s) { | |||
| warn!("Unable to update debug text: {}", err); | |||
| } | |||
| text.update(pos, s).error("Unable to update debug text"); | |||
| } | |||
| } | |||
| @@ -4,9 +4,8 @@ use glc::{ | |||
| shader::{Program, Type}, | |||
| vector::Vector3f, | |||
| }; | |||
| use log::error; | |||
| use shrev::{EventChannel, ReaderId}; | |||
| use space_crush_common::misc::WorldHelper as _; | |||
| use space_crush_common::misc::{LogResult, WorldHelper as _}; | |||
| use specs::{prelude::*, ReadExpect, System, World, WriteExpect}; | |||
| use crate::{ | |||
| @@ -75,9 +74,9 @@ impl<'a> System<'a> for Init { | |||
| gl::viewport(0, 0, self.resolution.0 as _, self.resolution.1 as _); | |||
| if let Err(err) = camera.resize(self.resolution.0 as _, self.resolution.1 as _) { | |||
| error!("Error while updating camera: {}", err); | |||
| } | |||
| camera | |||
| .resize(self.resolution.0 as _, self.resolution.1 as _) | |||
| .error("Error while updating camera"); | |||
| } | |||
| /* zoom */ | |||
| @@ -90,9 +89,9 @@ impl<'a> System<'a> for Init { | |||
| * Matrix4f::scale(z.into()) | |||
| * Matrix4f::translate((-state.mouse_pos.0, -state.mouse_pos.1, 0.0).into()); | |||
| if let Err(err) = camera.update_with(move |v| m * v) { | |||
| error!("Error while zooming camera: {}", err); | |||
| } | |||
| camera | |||
| .update_with(move |v| m * v) | |||
| .error("Error while zooming camera"); | |||
| } | |||
| } | |||
| @@ -111,14 +110,14 @@ impl<'a> System<'a> for Init { | |||
| ); | |||
| let m = Matrix4f::translate(translate); | |||
| if let Err(err) = camera.update_with(move |v| m * v) { | |||
| error!("Error while moving camera: {}", err); | |||
| } | |||
| camera | |||
| .update_with(move |v| m * v) | |||
| .error("Error while moving camera"); | |||
| } | |||
| if let Err(err) = uniform.update() { | |||
| error!("Error while updating global uniform data: {}", err); | |||
| } | |||
| uniform | |||
| .update() | |||
| .error("Error while updating global uniform data"); | |||
| /* render background */ | |||
| self.program.bind(); | |||
| @@ -5,8 +5,10 @@ use glc::{ | |||
| texture::Texture, | |||
| vector::Vector4f, | |||
| }; | |||
| use log::error; | |||
| use space_crush_common::components::{Owned, Planet, Position}; | |||
| use space_crush_common::{ | |||
| components::{Owned, Planet, Position}, | |||
| misc::LogResult, | |||
| }; | |||
| use specs::{prelude::*, ReadExpect, ReadStorage, System, World}; | |||
| use crate::{ | |||
| @@ -96,19 +98,12 @@ impl<'a> System<'a> for Planets { | |||
| Vector4f::new(p_x, p_y, 0.0, 1.0), | |||
| ); | |||
| if let Err(err) = self | |||
| .program | |||
| self.program | |||
| .uniform(self.location_glow_color, Uniform::Vector4f(&c)) | |||
| { | |||
| error!("Error while updating glow color: {}", err); | |||
| } | |||
| if let Err(err) = self | |||
| .program | |||
| .error("Error while updating glow color"); | |||
| self.program | |||
| .uniform(self.location_model, Uniform::Matrix4f(&m)) | |||
| { | |||
| error!("Error while updating model matrix: {}", err); | |||
| } | |||
| .error("Error while updating model matrix"); | |||
| geometry.render_quad(); | |||
| } | |||
| @@ -5,8 +5,10 @@ use glc::{ | |||
| texture::Texture, | |||
| vector::Vector4f, | |||
| }; | |||
| use log::error; | |||
| use space_crush_common::components::{Owned, Position, Ship, ShipType, Velocity}; | |||
| use space_crush_common::{ | |||
| components::{Owned, Position, Ship, ShipType, Velocity}, | |||
| misc::LogResult, | |||
| }; | |||
| use specs::{prelude::*, ReadExpect, ReadStorage, System, World}; | |||
| use crate::{ | |||
| @@ -111,19 +113,12 @@ impl<'a> System<'a> for Ships { | |||
| Vector4f::new(p_x, p_y, 0.0, 1.0), | |||
| ); | |||
| if let Err(err) = self | |||
| .program | |||
| self.program | |||
| .uniform(self.location_glow_color, Uniform::Vector4f(&c)) | |||
| { | |||
| error!("Error while updating glow color: {}", err); | |||
| } | |||
| if let Err(err) = self | |||
| .program | |||
| .error("Error while updating glow color"); | |||
| self.program | |||
| .uniform(self.location_model, Uniform::Matrix4f(&m)) | |||
| { | |||
| error!("Error while updating model matrix: {}", err); | |||
| } | |||
| .error("Error while updating model matrix"); | |||
| geometry.render_quad(); | |||
| } | |||
| @@ -0,0 +1,50 @@ | |||
| use std::fmt::Display; | |||
| use log::{error, warn}; | |||
| pub trait LogResult { | |||
| type Ok; | |||
| fn warn(self, s: &str) -> Option<Self::Ok>; | |||
| fn error(self, s: &str) -> Option<Self::Ok>; | |||
| fn panic(self, s: &str) -> Self::Ok; | |||
| } | |||
| impl<T, E> LogResult for Result<T, E> | |||
| where | |||
| E: Display, | |||
| { | |||
| type Ok = T; | |||
| fn warn(self, s: &str) -> Option<T> { | |||
| match self { | |||
| Ok(val) => Some(val), | |||
| Err(err) => { | |||
| warn!("{}: {}", s, err); | |||
| None | |||
| } | |||
| } | |||
| } | |||
| fn error(self, s: &str) -> Option<T> { | |||
| match self { | |||
| Ok(val) => Some(val), | |||
| Err(err) => { | |||
| error!("{}: {}", s, err); | |||
| None | |||
| } | |||
| } | |||
| } | |||
| fn panic(self, s: &str) -> T { | |||
| match self { | |||
| Ok(val) => val, | |||
| Err(err) => { | |||
| error!("{}: {}", s, err); | |||
| panic!("{}: {}", s, err); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,7 +1,9 @@ | |||
| mod log; | |||
| mod log_result; | |||
| mod vfs; | |||
| mod world; | |||
| pub use self::log::init as init_logger; | |||
| pub use self::vfs::{Vfs, VfsError}; | |||
| pub use log_result::LogResult; | |||
| pub use world::{Persistence, WorldHelper}; | |||