compiles, doesn't run. Not sure where I left this...

This commit is contained in:
2021-12-23 03:17:04 -08:00
parent b98c7312cc
commit 7527694fd2
22 changed files with 3165 additions and 19 deletions

View File

@@ -10,8 +10,9 @@ use wgpu::{BindGroup, Buffer, TextureView};
use crate::runtime::state::{TomlPositionDescription, TomlRotationDescription};
use imgui::Ui;
// a component is any type that is 'static, sized, send and sync
/// a component is any type that is 'static, sized, send and sync
/// ImguiWindow contains a single handle and lifetime to an Imgui window, along with
/// a function which takes a UI, as well as a vector of a user defined type T
pub struct ImguiWindow<'a, T> {
pub window: fn() -> imgui::Window<'a>,
pub func: fn(&Ui, Vec<&T>),

View File

@@ -35,6 +35,8 @@ pub struct RawMesh {
}
/// We use meshes in a few different places. To keep things simple, we return
/// the most basic, direct-to-memory version. If something fancy needs to be done
/// with it, the fancy stays there

View File

@@ -110,13 +110,28 @@ Todo:
I need to figure out the way that I want to do 2d graphics in a 3d engine...
I suppose I will need sprites. And those are just 2 polygons which are textured
*/
/**
Notes:
(Im)GUI,
* I have to hold onto an ImGUI window and it's lifetime
* I have to execute a bunch of function calls to build
the immediate mode UI each and every frame
It looks like my solution was to have an entity describing
the window
*/
//log::info!("");
// ImGUI works on more or less an unsafe global state. which is MegaLame
/// ImGUI works on more or less an unsafe global state. which is MegaLame
static mut CURRENT_UI: Option<imgui::Ui<'static>> = None;
pub unsafe fn current_ui<'a>() -> Option<&'a imgui::Ui<'a>> {
CURRENT_UI.as_ref()
@@ -143,7 +158,7 @@ fn main() {
let mut render_schedule = Schedule::builder()
.add_system(render::system::render_imgui_system())
.add_system(render::system::render_test_system())
//.add_system(render::system::render_test_system())
.add_system(render::system::render_performance_flag_system())
.build();

View File

@@ -12,15 +12,18 @@ use rapier3d::pipeline::PhysicsPipeline;
use crate::camera::{Camera, CameraController};
use crate::components::{Collider, LoopState, Mesh, Physics, Position};
use imgui::FontSource;
use rapier3d::prelude::{IslandManager, CCDSolver};
pub struct PhysicsState {
pub(in crate::physics) gravity: rapier3d::math::Vector<f32>,
pub(in crate::physics) integration_parameters: IntegrationParameters,
pub(in crate::physics) island_manager: IslandManager,
pub(in crate::physics) broad_phase: BroadPhase,
pub(in crate::physics) narrow_phase: NarrowPhase,
pub(in crate::physics) bodies: RigidBodySet,
pub(in crate::physics) colliders: ColliderSet,
pub(in crate::physics) joints: JointSet,
pub(in crate::physics) ccd_solver: CCDSolver,
}
impl PhysicsState {
@@ -30,11 +33,13 @@ impl PhysicsState {
PhysicsState {
gravity,
integration_parameters: IntegrationParameters::default(),
island_manager: IslandManager::new(),
broad_phase: BroadPhase::new(),
narrow_phase: NarrowPhase::new(),
bodies: RigidBodySet::new(),
colliders: ColliderSet::new(),
joints: JointSet::new(),
ccd_solver: CCDSolver::new(),
},
)
}

View File

@@ -40,8 +40,8 @@ pub fn run_physics(
if collider.collider_handle == None {
let handle = physics_state.colliders.insert(
collider.collider.clone(),
rigid_body_handle,
&mut physics_state.bodies,
//rigid_body_handle,
//&mut physics_state.bodies,
);
collider.collider_handle = Some(handle);
}
@@ -56,13 +56,14 @@ pub fn run_physics(
physics_pipeline.step(
&physics_state.gravity,
&physics_state.integration_parameters,
&mut physics_state.island_manager,
&mut physics_state.broad_phase,
&mut physics_state.narrow_phase,
&mut physics_state.bodies,
&mut physics_state.colliders,
&mut physics_state.joints,
None,
None,
&mut physics_state.ccd_solver,
&(),
&event_handler,
);

View File

@@ -16,7 +16,6 @@ use imgui::*;
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
use legion::world::SubWorld;
use legion::*;
use rapier3d::parry::motion::RigidMotionComposition;
use wgpu::util::DeviceExt;
use wgpu::{BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, Device, FragmentState, Instance, Queue, Surface, SwapChain, SwapChainDescriptor, SwapChainFrame, TextureView, VertexState, CommandEncoder};
use winit_24::dpi::PhysicalSize;

View File

@@ -18,7 +18,6 @@ use imgui::*;
use imgui_wgpu::{Renderer as ImguiRenderer, RendererConfig as ImguiRendererConfig};
use legion::world::SubWorld;
use legion::*;
use rapier3d::parry::motion::RigidMotionComposition;
use wgpu::util::DeviceExt;
use wgpu::{
BackendBit, BindGroup, BindGroupLayout, Buffer, BufferBindingType, CommandEncoder, Device,
@@ -39,6 +38,7 @@ use crate::render::{
insert_debug_marker_checked, pop_debug_group_checked, push_debug_group_checked, EntityUniforms,
};
#[system]
#[write_component(Camera)]
pub fn imgui_prepare(
@@ -80,6 +80,7 @@ fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld,
.build(&ui, || (window_func.unwrap())(ui, v));
}
}
/// Go through each "global" window-data component and render it's data
#[system]
#[write_component(ImguiWindow<ImguiPerformanceProfilerLine>)]
@@ -87,13 +88,33 @@ fn run_imgui_render_step<G: 'static + Sized + Send + Sync>(world: &mut SubWorld,
#[write_component(ImguiWindow<ImguiGenericOutputLine>)]
#[write_component(ImguiGenericOutputLine)]
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
// This is a global that we have to grab for imgui
let ui = unsafe { crate::current_ui().unwrap() };
// Pull out the window associated with this type, and render each of the components in the sytem
// Pull out the window associated with this type, and render each of the components in the system
run_imgui_render_step::<ImguiGenericOutputLine>(world, &ui);
run_imgui_render_step::<ImguiPerformanceProfilerLine>(world, &ui);
}
/**
Oh boy, now I need to remember this interface that I wrote...
The (Im)GUI System
* Each window is a static type, like ImguiGenericOutputLine, and ImguiPerformanceProfilerLine.
* Each window is also an entity that we do a query on
*/
// This would be the shared state for all imgui generic output things
pub struct ImguiGenericOutputLine {
pub label: String,
@@ -114,6 +135,7 @@ pub struct ImguiPerformanceProfilerLine {
pub scale_max: f32,
}
/// Adding samples, iterating, and calculating profiler lines
impl ImguiPerformanceProfilerLine {
fn add_sample(&mut self, sample: f32) {
self.list_of_fps[self.index] = sample;
@@ -160,6 +182,7 @@ impl ImguiPerformanceProfilerLine {
}
}
/// Take the current delta time from the loop state and add it to the profile line
#[system]
#[write_component(ImguiPerformanceProfilerLine)]
pub fn render_performance_flag(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
@@ -178,7 +201,7 @@ pub fn render_performance_flag(world: &mut SubWorld, #[resource] loop_state: &mu
#[write_component(Point3<f32>)]
#[write_component(Mesh)]
#[write_component(DirectionalLight)]
pub fn render_test(
pub fn render_function(
world: &mut SubWorld,
#[resource] loop_state: &mut LoopState,
#[resource] renderer: &mut RenderState,
@@ -334,6 +357,7 @@ pub fn render_test(
pass.draw_indexed(0..mesh.index_count as u32, 0, 0..1);
}
}
pop_debug_group_checked(&mut encoder);
pop_debug_group_checked(&mut encoder);

View File

@@ -16,7 +16,7 @@ use crate::camera::{Camera, CameraController};
use crate::components::{Collider, LoopState, Mesh, Physics, Position};
use crate::geometry::{load_obj, RawMesh};
use std::io::Read;
use imgui_wgpu::Texture;
#[derive(Deserialize, Clone)]
@@ -71,8 +71,28 @@ pub struct TomlEntityContainer {
pub struct RuntimeState {
config_db: TomlEntityContainer,
mesh_cache: HashMap<String, RawMesh>,
texture_cache: HashMap<String, RawMesh>,
}
pub struct Model {
pub meshes: Vec<RawMesh>,
pub materials: Vec<Material>,
}
pub struct Material {
pub name: String,
pub diffuse_texture: Texture,
}
// pub struct Mesh {
// pub name: String,
// pub vertex_buffer: wgpu::Buffer,
// pub index_buffer: wgpu::Buffer,
// pub num_elements: u32,
// pub material: usize,
// }
impl RuntimeState {
pub fn new() -> RuntimeState {
// TODO: Hook this file to the gui
@@ -86,6 +106,7 @@ impl RuntimeState {
RuntimeState {
config_db: settings,
mesh_cache: Default::default(),
texture_cache: Default::default(),
}
}
@@ -112,6 +133,6 @@ impl RuntimeState {
}
}
panic!("nah");
//panic!("nah");
}
}

View File

@@ -219,7 +219,7 @@ pub fn runtime_spawn(
let mut dynamic_body = RigidBodyBuilder::new_dynamic()
.can_sleep(false)
.mass(100.0)
.translation(position.x, position.y, position.z)
.translation(Vector3::new(position.x, position.y, position.z))
.build();
let entity: Entity = cmd.push((