@ -1,16 +1,17 @@
extern crate env_logger ;
extern crate imgui ;
extern crate imgui_wgpu ;
#[ macro_use ]
extern crate lazy_static ;
extern crate tobj ;
extern crate winit_24 ;
extern crate env_logger ;
extern crate toml ;
#[ macro_use ]
extern crate serde_derive ;
extern crate tobj ;
extern crate toml ;
extern crate winit_24 ;
use std ::collections ::HashMap ;
use std ::f32 ::consts ::PI ;
use std ::fs ;
use std ::sync ::{ Arc , Mutex } ;
#[ cfg(not(target_arch = " wasm32 " )) ]
use std ::time ::{ Duration , Instant } ;
@ -20,6 +21,7 @@ use cgmath::{
} ;
use futures ::executor ::block_on ;
use futures ::task ::LocalSpawn ;
use futures ::FutureExt ;
use gilrs ::Event as GilEvent ;
use gilrs ::{ Gamepad , Gilrs } ;
use imgui ::FontSource ;
@ -28,6 +30,7 @@ use imgui::*;
use imgui_wgpu ::{ Renderer as ImguiRenderer , RendererConfig as ImguiRendererConfig } ;
use legion ::systems ::{ SyncResources , UnsafeResources } ;
use legion ::* ;
use log ::LevelFilter ;
use rapier3d ::counters ::Timer ;
use rapier3d ::dynamics ::{
IntegrationParameters , JointSet , RigidBody , RigidBodyBuilder , RigidBodyHandle , RigidBodySet ,
@ -40,6 +43,8 @@ use rapier3d::pipeline::PhysicsPipeline;
use wgpu ::{ BindGroup , Buffer , TextureView } ;
use wgpu_subscriber ;
use winit_24 ::event ::DeviceEvent ::MouseMotion ;
use winit_24 ::event ::{ ElementState , VirtualKeyCode } ;
use winit_24 ::event_loop ::EventLoopProxy ;
use winit_24 ::platform ::unix ::x11 ::ffi ::Time ;
use winit_24 ::window ::Window ;
use winit_24 ::{
@ -54,13 +59,8 @@ 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 log ::LevelFilter ;
use crate ::render ::system ::ImguiPerformanceProfiler ;
use crate ::runtime ::state ::RuntimeState ;
use winit_24 ::event_loop ::EventLoopProxy ;
mod camera ;
mod components ;
@ -112,15 +112,16 @@ Todo:
//log::info!("");
// ImGUI works on more or less a global state. which is MegaLame
// ImGUI works on more or less a n 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 ( )
}
fn main ( ) {
let logger = env_logger ::builder ( ) . filter ( Some ( "minimal_viable_game_engine" ) , LevelFilter ::Info ) . init ( ) ;
let logger = env_logger ::builder ( )
. filter ( Some ( "minimal_viable_game_engine" ) , LevelFilter ::Info )
. init ( ) ;
let mut world = World ::default ( ) ;
@ -134,6 +135,7 @@ fn main() {
. build ( ) ;
let mut render_schedule = Schedule ::builder ( )
. add_system ( render ::system ::render_imgui_system ( ) )
. add_system ( render ::system ::render_test_system ( ) )
. build ( ) ;
@ -156,6 +158,45 @@ fn main() {
let mut resources = Resources ::default ( ) ;
let entity : Entity = world . push ( (
ImguiWindow {
// a window that does everything for the performance profiler
window : | | {
imgui ::Window ::new ( im_str ! ( "Performance Profiler" ) )
. size ( [ 400.0 , 500.0 ] , Condition ::FirstUseEver )
. position ( [ 50.0 , 50.0 ] , Condition ::FirstUseEver )
} ,
func : | ui : & Ui , a : & ImguiPerformanceProfiler | {
ui . plot_lines ( im_str ! ( "blah" ) , & a . list_of_fps )
. graph_size ( [ 200.0 , 200.0 ] )
. scale_min ( 0.0 )
. scale_min ( 0.01 ) . build ( ) ;
ui . text ( im_str ! ( "blah blah blah {:?}" , a . top_text ) ) ;
let draw_list = ui . get_window_draw_list ( ) ;
let o = ui . cursor_screen_pos ( ) ;
let ws = ui . content_region_avail ( ) ;
a . list_of_fps . iter ( ) . fold ( ( 0 , 0.0 f32 ) , | accum , & b | {
let b = b / 10.0 ;
let x1 = accum . 0 as f32 * 1.0 + o [ 0 ] ;
let x2 = ( accum . 0 as f32 + 1.0 ) * 1.0 + o [ 0 ] ;
let p1 = [ x1 , accum . 1 + o [ 1 ] ] ;
let p2 = [ x2 , accum . 1 + b + o [ 1 ] ] ;
draw_list
. add_line ( p1 , p2 , [ 128.0 , 64.0 , 0.0 ] )
. thickness ( 1.0 )
. build ( ) ;
( accum . 0 + 1 , b )
} ) ;
} ,
} ,
ImguiPerformanceProfiler {
top_text : "FPS" . to_string ( ) ,
list_of_fps : [ 0.0 ; 400 ] ,
index : 0 ,
} ,
) ) ;
// Load up all the resources
{
let mut imgui_context = imgui ::Context ::create ( ) ;
@ -242,21 +283,26 @@ fn main() {
// conditionally, and run the fps locked renderer
event ::Event ::MainEventsCleared = > {
event_schedule . execute ( & mut world , & mut resources ) ;
imgui_prepare_schedule . execute ( & mut world , & mut resources ) ;
resources
. get_mut ::< Vec < OwnedEvent < OwnedEventExtension > > > ( )
. unwrap ( )
. clear ( ) ;
imgui_prepare_schedule . execute ( & mut world , & mut resources ) ;
let ( step_size , elapsed_time ) = {
// deltatime since last frame
let loop_state = resources . get ::< LoopState > ( ) . unwrap ( ) ;
let mut loop_state = resources . get_mut ::< LoopState > ( ) . unwrap ( ) ;
(
loop_state . step_size ,
loop_state . start_time . elapsed ( ) . as_secs_f32 ( ) ,
)
} ;
delta_time = elapsed_time - current_time ;
{
let mut loop_state = resources . get_mut ::< LoopState > ( ) . unwrap ( ) ;
loop_state . delta_time = Duration ::from_secs_f32 ( delta_time ) ;
}
current_time = elapsed_time ;
if delta_time > 0.02 {
delta_time = 0.02 ;
@ -265,10 +311,10 @@ fn main() {
while accumulator_time - step_size > = step_size {
accumulator_time - = step_size ;
// ==== DELTA TIME LOCKED ====
update_schedule . execute ( & mut world , & mut resources ) ;
}
// ==== FPS LOCKED ====
render_schedule . execute ( & mut world , & mut resources ) ;
}
@ -297,7 +343,7 @@ fn main() {
//d
}
}
_ = > ( )
_ = > ( ) ,
}
}
event ::Event ::WindowEvent {
@ -320,7 +366,6 @@ fn main() {
}
pub fn setup_gamepad ( event_loop : & EventLoop < OwnedEventExtension > ) {
let event_loop_proxy = event_loop . create_proxy ( ) ;
std ::thread ::spawn ( move | | {
@ -362,4 +407,3 @@ pub fn setup_gamepad(event_loop: &EventLoop<OwnedEventExtension>) {
}
} ) ;
}