musing about config/savestate loading

master
mitchellhansen 4 years ago
parent d0a2893056
commit a1305bed2d

@ -14,7 +14,7 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
typed-arena = "2.0.1"
serde = { version = "1", features = ["derive"], optional = true }
log = "0.4"
simple_logger = "1.11.0"
env_logger = "0.8.3"
png = "0.16"
#winit = { version = "0.24.0"}
rand = { version = "0.7.2", features = ["wasm-bindgen"] }
@ -27,6 +27,7 @@ gilrs = "0.8.0"
gfx-backend-vulkan = { version = "0.6", features = ["x11"] }
lazy_static = "1.4.0"
crossbeam = "0.8.0"
config = "0.10.1"
cgmath = "0.18.0"
rapier3d = { version = "0.5.0", features = ["simd-nightly", "parallel"] }

@ -0,0 +1,13 @@
[[entities]]
[entities.entity1]
name = "terrain.1"
type = "Mesh"
mesh = "test-textured.obj"
[[entities]]
[entities.entity2]
name = "ball.1"
type = ""
mesh = "test-textured.obj"

File diff suppressed because it is too large Load Diff

@ -46,7 +46,7 @@ pub fn load_obj(obj_path: &str) -> Result<RawMesh, String> {
let (models, materials) = match tobj::load_obj(obj_path, true) {
Ok((a, b)) => {Ok((a, b))}
Err(load_error) => {Err(load_error.to_string())}
}.unwrap();
}?;
// println!("# of models: {}", models.len());
// println!("# of materials: {}", materials.len());
@ -78,8 +78,11 @@ pub fn load_obj(obj_path: &str) -> Result<RawMesh, String> {
if mesh.texcoords.len() % 2 != 0 {
return Err(format!("position array not % 3 : {}", mesh.positions.len()))
}
if mesh.normals.is_empty() {
return Err(format!("It would be best if this had normals"))
}
if mesh.texcoords.is_empty() {
log::info!("Mesh texture coordinates empty")
log::info!("\tMesh texture coordinates empty")
}
for v in 0..mesh.positions.len() / 3 {

@ -4,8 +4,8 @@ extern crate imgui_wgpu;
extern crate lazy_static;
extern crate tobj;
extern crate winit_24;
extern crate env_logger;
use simple_logger::SimpleLogger;
use std::f32::consts::PI;
use std::sync::{Arc, Mutex};
#[cfg(not(target_arch = "wasm32"))]
@ -42,15 +42,21 @@ use winit_24::{
event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop},
};
use config::File;
use crate::camera::{Camera, CameraController};
use crate::components::{Collider, ImguiWindow, LoopState, Physics, Position};
use crate::geometry::load_obj;
use crate::geometry::{load_obj, RawMesh};
use crate::imgui_supp::extended_winit_imgui_support;
use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
use crate::owned_event::{OwnedEvent, OwnedEventExtension};
use crate::physics::state::PhysicsState;
use std::fs;
use winit_24::event::{VirtualKeyCode, ElementState};
use std::collections::HashMap;
use futures::FutureExt;
use config::Config;
use log::LevelFilter;
mod camera;
mod components;
@ -60,6 +66,7 @@ mod light;
mod owned_event;
mod physics;
mod render;
mod runtime;
/*
@ -99,8 +106,14 @@ pub unsafe fn current_ui<'a>() -> Option<&'a imgui::Ui<'a>> {
fn main() {
let logger = SimpleLogger::new().with_level(log::LevelFilter::Info).init().unwrap();
let logger = env_logger::builder().filter(Some("minimal_viable_game_engine"), LevelFilter::Info).init();
let mut settings = Config::default();
settings
// File::with_name(..) is shorthand for File::from(Path::new(..))
.merge(File::with_name("conf/entity_spawns.toml")).unwrap();
log::info!("{:#?}", settings);
let mut world = World::default();
@ -294,6 +307,21 @@ fn main() {
.unwrap()
.resize(width, height);
}
event::Event::DeviceEvent {
event: winit_24::event::DeviceEvent::Key(keyboard_input),
..
} => {
match keyboard_input.virtual_keycode.unwrap() {
VirtualKeyCode::Escape => {
if keyboard_input.state == ElementState::Pressed {
*control_flow = ControlFlow::Exit;
} else {
//d
}
}
_ => ()
}
}
event::Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
@ -313,17 +341,22 @@ fn main() {
});
}
pub fn preload_meshes(resources_path: &str) -> (){
println!("Preloading meshes...");
pub fn preload_meshes(resources_path: &str) -> HashMap<String, RawMesh> {
log::info!("Preloading meshes...");
let mut output = HashMap::default();
let paths = fs::read_dir(resources_path).unwrap();
for file in paths {
let file = file.unwrap().file_name();
let filename = file.to_str().unwrap();
if filename.ends_with(".obj") {
println!("Loading {:?} ...", filename);
let filepath = file.unwrap().path().into_os_string();
let filepath = filepath.to_str().unwrap();
if filepath.ends_with(".obj") {
let mesh = load_obj(filepath).unwrap();
output.insert(filepath.to_string(), mesh);
}
}
}()
output
// I guess it's fine to have them loaded to the gpu
// But I also want to preserve the raw data
}

@ -278,16 +278,14 @@ pub fn event_dispatch(
}
match keyboard_input.virtual_keycode.unwrap() {
VirtualKeyCode::A => {
VirtualKeyCode::R => {
if keyboard_input.state == ElementState::Pressed {
winit_window.set_cursor_position(
LogicalPosition{ x: 100.0, y: 100.0 }
);
//winit_window.set_cursor_grab(true);
}
}
VirtualKeyCode::S => {
VirtualKeyCode::Escape => {
if keyboard_input.state == ElementState::Pressed {
//winit_window.set_cursor_grab(false);
}

@ -73,7 +73,6 @@ pub fn run_physics(
}
}
#[system]
#[write_component(Camera)]
#[write_component(CameraController)]

@ -0,0 +1,2 @@
pub mod state;
pub mod system;

@ -0,0 +1,22 @@
use std::time::Instant;
use cgmath::{Euler, Quaternion};
use legion::world::SubWorld;
use legion::IntoQuery;
use legion::*;
use nalgebra::Quaternion as naQuaternion;
use rapier3d::dynamics::{IntegrationParameters, JointSet, RigidBodySet};
use rapier3d::geometry::{BroadPhase, ColliderSet, NarrowPhase};
use rapier3d::pipeline::PhysicsPipeline;
use crate::camera::{Camera, CameraController};
use crate::components::{Collider, LoopState, Mesh, Physics, Position};
pub struct RuntimeState {
}
impl RuntimeState {
pub fn build() {
}
}

@ -0,0 +1,33 @@
use std::time::Instant;
use cgmath::{Euler, Quaternion};
use legion::world::SubWorld;
use legion::IntoQuery;
use legion::*;
use nalgebra::Quaternion as naQuaternion;
use rapier3d::dynamics::{IntegrationParameters, JointSet, RigidBodySet};
use rapier3d::geometry::{BroadPhase, ColliderSet, NarrowPhase};
use rapier3d::pipeline::{PhysicsPipeline, ChannelEventCollector};
use crate::camera::{Camera, CameraController};
use crate::components::{Collider, LoopState, Mesh, Physics, Position};
use imgui::FontSource;
use crate::physics::state::PhysicsState;
#[system]
#[write_component(Collider)]
#[write_component(Physics)]
#[write_component(Mesh)]
pub fn runtime_load(
world: &mut SubWorld,
#[resource] physics_state: &mut PhysicsState,
#[resource] physics_pipeline: &mut PhysicsPipeline,
) {
// Make sure all the entities we care about are added to the system
let mut query = <(&mut Collider, &mut Physics, &mut Mesh)>::query();
for (collider, physics, mesh) in query.iter_mut(world) {
}
}
Loading…
Cancel
Save