Update deps

This commit is contained in:
Piotr Siuszko 2024-03-05 11:30:31 +01:00
parent 7b31a7eff1
commit 1cf71cec32
13 changed files with 346 additions and 610 deletions

699
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,23 +6,13 @@ edition = "2018"
[dependencies]
gl = "0.14.0"
imgui={version="0.7.0", optional=true}
imgui-winit-support = {version="0.7.0", optional=true}
imgui-opengl-renderer = {version="0.11.0", optional = true}
cgmath = {version="0.18.0", features=["serde"]}
imgui-inspect = {version="0.8.0", optional = true}
imgui-inspect-derive = {version="0.8.0", optional= true}
tobj = "2.0.2"
inline_tweak = "1.0.8"
log = "0.4.11"
simple-logging = "2.0.2"
image2 = { git = "https://github.com/Leinnan/image2-rs", branch="legacy", default-features = false, features=["io"] }
glutin = "0.26.0"
glutin = "0.28.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8"
[features]
default = ["imgui_inspect"]
imgui_inspect = ["imgui","imgui-inspect-derive","imgui-opengl-renderer", "imgui-inspect", "imgui-winit-support"]

View File

@ -1,13 +1,13 @@
use doppler::assets_cache::AssetsCache;
use doppler::client::Client;
use doppler::components::*;
use doppler::glutin::event::{ElementState, VirtualKeyCode};
use doppler::shader::Shader;
use doppler::components::*;
pub struct Client2D {
delta: f32,
models_2d: ModelComponent,
shader: Shader
shader: Shader,
}
impl Default for Client2D {
@ -18,12 +18,11 @@ impl Default for Client2D {
shader: Shader::from_file(
"resources/shaders/multiple_lights.vs",
"resources/shaders/multiple_lights.fs",
)
),
}
}
}
impl Client for Client2D {
fn on_keyboard(&mut self, code: &VirtualKeyCode, state: &ElementState) {
match (code, state) {
@ -55,14 +54,9 @@ impl Client for Client2D {
self.delta = delta;
}
fn debug_draw(&mut self, _ui: &doppler::imgui::Ui) {
}
fn on_mouse_scroll(&mut self, _yoffset: f32) {}
fn on_mouse_scroll(&mut self, _yoffset: f32) {
}
fn on_mouse_move(&mut self, _x: f32, _y: f32) {
}
fn on_mouse_move(&mut self, _x: f32, _y: f32) {}
}
pub fn main() {

View File

@ -1,21 +1,12 @@
use doppler::assets_cache::AssetsCache;
use doppler::camera::*;
use doppler::client::Client;
use doppler::components::Transform;
use doppler::glutin::event::{ElementState, VirtualKeyCode};
use doppler::imgui::*;
use doppler::light::*;
use doppler::map::*;
pub struct ExampleClient {
map: Map,
delta: f32,
show_object_info: bool,
show_camera_info: bool,
imgui_grabs_input: bool,
object_info_id: i32,
show_light_info: bool,
light_info_id: i32,
}
impl Default for ExampleClient {
@ -23,12 +14,6 @@ impl Default for ExampleClient {
ExampleClient {
delta: 0.0,
map: Map::default(),
object_info_id: 0,
show_camera_info: false,
show_object_info: false,
show_light_info: false,
imgui_grabs_input: false,
light_info_id: 0,
}
}
}
@ -72,140 +57,10 @@ impl Client for ExampleClient {
self.delta = delta;
}
fn debug_draw(&mut self, ui: &doppler::imgui::Ui) {
if let Some(menu_bar) = ui.begin_main_menu_bar() {
if let Some(menu) = ui.begin_menu(im_str!("Basic"), true) {
if MenuItem::new(im_str!("Show Object info"))
.selected(self.show_object_info)
.build(ui)
{
self.show_object_info = !self.show_object_info;
}
if MenuItem::new(im_str!("Show lights info"))
.selected(self.show_light_info)
.build(ui)
{
self.show_light_info = !self.show_light_info;
}
menu.end(ui);
}
if MenuItem::new(im_str!("Toggle Camera Info"))
.selected(self.show_camera_info)
.build(ui)
{
self.show_camera_info = !self.show_camera_info;
}
menu_bar.end(ui);
}
{
if self.show_camera_info {
Window::new(im_str!("CameraInfo"))
.size([260.0, 430.0], Condition::Always)
.position([20.0, 40.0], Condition::Always)
.title_bar(false)
.scroll_bar(false)
.no_inputs()
.bg_alpha(0.8)
.collapsible(false)
.build(&ui, || {
ui.text(im_str!("Camera info"));
ui.separator();
<Camera as imgui_inspect::InspectRenderDefault<Camera>>::render(
&[&self.map.camera],
&"CameraInfo",
ui,
&imgui_inspect::InspectArgsDefault {
header: Some(false),
..imgui_inspect::InspectArgsDefault::default()
},
);
});
}
if self.show_object_info {
let mut id = self.object_info_id;
let max: i32 = self.map.models.len() as i32 - 1;
let mut show_window = self.show_object_info;
Window::new(im_str!("Object info"))
.size([250.0, 250.0], Condition::FirstUseEver)
.opened(&mut show_window)
.build(&ui, || {
ui.input_int(im_str!("id"), &mut id).build();
id = if id < 0 {
0
} else if id > max {
max
} else {
id
};
let mut selected_mut = vec![&mut self.map.models[id as usize].transform];
<Transform as imgui_inspect::InspectRenderStruct<Transform>>::render_mut(
&mut selected_mut,
"Object info",
&ui,
&imgui_inspect::InspectArgsStruct::default(),
);
});
self.object_info_id = id;
self.show_object_info = show_window;
}
if self.show_light_info {
let mut id = self.light_info_id;
let max: i32 = self.map.lighting_system.point_lights.len() as i32 - 1;
let mut show_window = self.show_light_info;
Window::new(im_str!("Lights info"))
.size([250.0, 250.0], Condition::FirstUseEver)
.opened(&mut show_window)
.build(&ui, || {
{
let mut selected_mut = vec![&mut self.map.lighting_system.directional_light];
<DirectionalLight as imgui_inspect::InspectRenderStruct<
DirectionalLight,
>>::render_mut(
&mut selected_mut,
"DirectionalLightInfo",
&ui,
&imgui_inspect::InspectArgsStruct::default(),
);
}
ui.separator();
ui.input_int(im_str!("Light ID"), &mut id)
.build();
id = if id < 0 { 0 } else if id > max { max } else { id };
{
let mut selected_mut =
vec![&mut self.map.lighting_system.point_lights[id as usize]];
<PointLight as imgui_inspect::InspectRenderStruct<PointLight>>::render_mut(
&mut selected_mut,
"PointLightInfo",
&ui,
&imgui_inspect::InspectArgsStruct::default(),
);
}
});
self.light_info_id = id;
self.show_light_info = show_window;
}
}
self.imgui_grabs_input = ui.is_any_item_hovered() || ui.is_any_item_focused();
}
fn on_mouse_scroll(&mut self, yoffset: f32) {
if self.imgui_grabs_input {
println!("DD");
return;
}
self.map.camera.process_mouse_scroll(yoffset as f32);
self.map.camera.process_mouse_scroll(yoffset);
}
fn on_mouse_move(&mut self, x: f32, y: f32) {
if self.imgui_grabs_input {
println!("DD");
return;
}
self.map.camera.process_mouse_movement(x, y, true);
}
}

View File

@ -16,14 +16,9 @@ pub struct AssetsCache {
impl AssetsCache {
pub fn load_2d(&mut self, path: &str) -> Model {
let fullpath = Path::new(&path);
let dir = fullpath
.parent()
.unwrap()
.to_str()
.unwrap()
.to_string();
let dir = fullpath.parent().unwrap().to_str().unwrap().to_string();
let filename = fullpath.file_name().unwrap().to_str().unwrap();
let texture = self.get_material_texture(&dir, &filename, "texture_diffuse");
let texture = self.get_material_texture(&dir, filename, "texture_diffuse");
let mut model = Model::new_2d(self);
for ele in &mut model.meshes {
ele.textures.push(texture.clone())
@ -34,7 +29,7 @@ impl AssetsCache {
pub fn load_all_from_file(&mut self, path: &str) {
let path = std::path::Path::new(path);
let meta = std::fs::metadata(path);
if !meta.is_ok() {
if meta.is_err() {
error!("There is no assets file");
return;
}
@ -50,7 +45,7 @@ impl AssetsCache {
for line in lines {
let mut splitted = line.split_whitespace();
let path = splitted.next();
if path.is_none() || self.has_model(&path.unwrap()) {
if path.is_none() || self.has_model(path.unwrap()) {
error!("Skip wrong line: {}", line);
continue;
}
@ -79,10 +74,7 @@ impl AssetsCache {
}
pub fn get_model_by_hash(&mut self, hash: &u64) -> Option<Model> {
match self.models.get(hash) {
Some(model) => Some(model.clone()),
None => None,
}
self.models.get(hash).cloned()
}
fn load_model_ext(&mut self, path: &str, diff_texture: Option<&str>) {

View File

@ -41,27 +41,20 @@ impl Transform {
}
}
#[derive(Default)]
pub struct ModelComponent {
pub model: Model,
pub hash: u64,
pub transform: Transform,
}
impl Default for ModelComponent {
fn default() -> Self {
ModelComponent {
model: Model::default(),
hash: u64::default(),
transform: Transform::default(),
}
}
}
impl ModelComponent {
pub unsafe fn draw(&self, shader: &Shader) {
let matrix = self.transform.get_matrix();
shader.set_mat4(c_str!("model"), &matrix);
self.model.Draw(&shader);
self.model.Draw(shader);
}
}

View File

@ -22,6 +22,12 @@ pub struct TimeStep {
frames: VecDeque<f32>,
}
impl Default for TimeStep {
fn default() -> Self {
Self::new()
}
}
impl TimeStep {
pub fn frames(&self) -> Vec<f32> {
self.frames.clone().into()
@ -207,7 +213,7 @@ impl Engine {
info!("Creating AssetCache");
let mut assets_cache = AssetsCache::default();
info!("Creating client");
let mut client = Box::new(T::default());
let mut client = Box::<T>::default();
client.load_assets(&mut assets_cache);
let mut first_mouse = true;
let mut last_x: f32 = consts::SCR_WIDTH as f32 / 2.0;
@ -215,7 +221,7 @@ impl Engine {
// timing
let mut timestep = TimeStep::new();
let mut last_frame = std::time::Instant::now();
let _last_frame = std::time::Instant::now();
let mut screensize = self.size;
info!("Assets loaded");
@ -245,7 +251,7 @@ impl Engine {
.expect("Failed to prepare frame");
gl_window.window().request_redraw();
}
Event::LoopDestroyed => return,
Event::LoopDestroyed => (),
Event::WindowEvent { event, .. } => match event {
WindowEvent::MouseWheel { delta, .. } => {
use glutin::event::MouseScrollDelta;
@ -372,7 +378,7 @@ impl Engine {
ui.text(output);
});
platform.prepare_render(&ui, &gl_window.window());
platform.prepare_render(&ui, gl_window.window());
renderer.render(ui);
}
gl_window.swap_buffers().unwrap();

View File

@ -148,11 +148,11 @@ impl FramebufferSystem {
info!("New framebuffer generated");
FramebufferSystem {
texture_color_buffer: texture_color_buffer,
shader: shader,
texture_color_buffer,
shader,
vao: quad_vao,
vbo: quad_vbo,
framebuffer: framebuffer,
framebuffer,
}
}
}

View File

@ -1,10 +1,12 @@
pub extern crate gl;
#[cfg(feature = "imgui_inspect")]
pub extern crate imgui;
pub extern crate log;
pub extern crate simple_logging;
pub use cgmath as math;
pub use glutin;
#[cfg(feature = "imgui_inspect")]
pub use imgui_inspect;
pub use serde;

View File

@ -30,8 +30,8 @@ impl MapSave {
});
}
let ms = MapSave {
camera: map.camera.clone(),
objects: objects,
camera: map.camera,
objects,
};
match serde_yaml::to_string(&ms) {
Ok(result) => println!("{}", result),
@ -96,7 +96,7 @@ impl Default for Map {
..Camera::default()
},
lighting_system: LightingSystem::default(),
sky: sky,
sky,
}
}
}

View File

@ -149,7 +149,7 @@ impl Model {
} else if diffuse_path.is_some() {
let path = diffuse_path.unwrap();
println!("Loading {}", path);
let dir: String = if path.contains("/") {
let dir: String = if path.contains('/') {
Path::new(&path)
.parent()
.unwrap()
@ -159,11 +159,8 @@ impl Model {
} else {
self.directory.to_string()
};
let texture = cache.get_material_texture(
&dir,
&diffuse_path.unwrap(),
"texture_diffuse",
);
let texture =
cache.get_material_texture(&dir, diffuse_path.unwrap(), "texture_diffuse");
textures.push(texture);
} else {
warn!("There are no materials for: {}", path.display());

View File

@ -67,7 +67,7 @@ impl Sky {
shader.setInt(c_str!("skybox"), 0);
Sky {
shader: shader,
shader,
texture_id: cubemap_texture,
vao: skybox_vao,
vbo: skybox_vbo,

View File

@ -41,8 +41,8 @@ pub unsafe fn load_texture(path: &str, file_format: &str) -> u32 {
gl::TEXTURE_2D,
0,
format as i32,
dim.0 as i32,
dim.1 as i32,
dim.0,
dim.1,
0,
format,
gl::UNSIGNED_BYTE,
@ -69,10 +69,10 @@ pub unsafe fn load_texture_from_dir(filename: &str, directory: &str) -> u32 {
}
pub unsafe fn load_texture_from_fullpath(fullpath: &str) -> u32 {
let dot = fullpath.find(".").unwrap_or_default() + 1usize;
let dot = fullpath.find('.').unwrap_or_default() + 1usize;
let (_, format) = fullpath.split_at(dot);
load_texture(&fullpath, format)
load_texture(fullpath, format)
}
/// loads a cubemap texture from 6 individual texture faces