Compare commits
2 commits
c01162ebe3
...
b52cdaefab
Author | SHA1 | Date | |
---|---|---|---|
b52cdaefab | |||
4e8f652ffd |
7 changed files with 39 additions and 86 deletions
|
@ -37,7 +37,7 @@ chrono = { version = "0.4.35", features = ["serde"] }
|
||||||
anyhow = { version = "1.0.86", features = ["backtrace"] }
|
anyhow = { version = "1.0.86", features = ["backtrace"] }
|
||||||
indexmap = { version = "2.2.6", features = ["rayon"] }
|
indexmap = { version = "2.2.6", features = ["rayon"] }
|
||||||
shaderc = { version = "0.8.3", features = ["build-from-source"] }
|
shaderc = { version = "0.8.3", features = ["build-from-source"] }
|
||||||
rusqlite = { version = "0.32.0", features = ["bundled"] }
|
rusqlite = { version = "0.33.0", features = ["bundled"] }
|
||||||
cgmath = "0.18.0"
|
cgmath = "0.18.0"
|
||||||
http = "1.1.0"
|
http = "1.1.0"
|
||||||
iterchunks = "0.5.0"
|
iterchunks = "0.5.0"
|
||||||
|
|
|
@ -24,11 +24,12 @@ use std::{
|
||||||
io::{Error, Write},
|
io::{Error, Write},
|
||||||
mem::swap,
|
mem::swap,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
|
|
||||||
static mut LOG_FILE: Option<NetworkLogFile> = None;
|
static LOG_FILE: Mutex<Option<NetworkLogFile>> = Mutex::new(None);
|
||||||
|
|
||||||
pub struct NetworkLogFile {
|
pub struct NetworkLogFile {
|
||||||
file: File,
|
file: File,
|
||||||
|
@ -42,9 +43,7 @@ impl NetworkLogFile {
|
||||||
file.write_all(format!("{:?}\n", Local::now()).as_bytes())?;
|
file.write_all(format!("{:?}\n", Local::now()).as_bytes())?;
|
||||||
file.write_all("================================================\n\n\n".as_bytes())?;
|
file.write_all("================================================\n\n\n".as_bytes())?;
|
||||||
|
|
||||||
unsafe {
|
*LOG_FILE.lock().unwrap() = Some(NetworkLogFile { file });
|
||||||
LOG_FILE = Some(NetworkLogFile { file });
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -52,15 +51,15 @@ impl NetworkLogFile {
|
||||||
pub(crate) fn log(mut message: String) -> std::result::Result<(), Error> {
|
pub(crate) fn log(mut message: String) -> std::result::Result<(), Error> {
|
||||||
message += "\n";
|
message += "\n";
|
||||||
|
|
||||||
unsafe {
|
|
||||||
LOG_FILE
|
LOG_FILE
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.expect("log file not set!")
|
.expect("log file not set!")
|
||||||
.file
|
.file
|
||||||
.write_all(message.as_bytes())
|
.write_all(message.as_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn split_matches(s: &str, c: char) -> (&str, &str) {
|
pub fn split_matches(s: &str, c: char) -> (&str, &str) {
|
||||||
match s.find(c) {
|
match s.find(c) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub struct EntityObject {
|
||||||
pub debug_name: Option<String>,
|
pub debug_name: Option<String>,
|
||||||
|
|
||||||
// gltf file name
|
// gltf file name
|
||||||
pub(crate) gltf_file: Option<String>,
|
pub gltf_file: Option<String>,
|
||||||
|
|
||||||
// activation state of Entity
|
// activation state of Entity
|
||||||
pub(crate) activation_state: ActivationState,
|
pub(crate) activation_state: ActivationState,
|
||||||
|
|
|
@ -125,16 +125,11 @@ impl AssetManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an empty `EditableEntity`
|
/// Creates an empty `EditableEntity`
|
||||||
pub fn load_asset_file(
|
pub fn load_asset_file(&mut self, world: &mut World, asset_file: &str) -> Result<EntityObject> {
|
||||||
&mut self,
|
|
||||||
context: &Arc<Context>,
|
|
||||||
entity_object_manager: &EntityObjectManager,
|
|
||||||
asset_file: &str,
|
|
||||||
) -> Result<EntityObject> {
|
|
||||||
// load asset
|
// load asset
|
||||||
let asset = self.load_gltf_asset(context, asset_file, true)?;
|
let asset = self.load_gltf_asset(world.resources.get::<Context>(), asset_file, true)?;
|
||||||
|
|
||||||
let mut entity_object = entity_object_manager.create_entity();
|
let mut entity_object = world.new_entity();
|
||||||
|
|
||||||
entity_object.gltf_file = Some(asset.gltf_file);
|
entity_object.gltf_file = Some(asset.gltf_file);
|
||||||
|
|
||||||
|
@ -160,13 +155,14 @@ impl AssetManager {
|
||||||
/// Creates an empty `EditableEntity`
|
/// Creates an empty `EditableEntity`
|
||||||
pub fn load_asset_file_absolute(
|
pub fn load_asset_file_absolute(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: &Arc<Context>,
|
world: &mut World,
|
||||||
entity_object_manager: &EntityObjectManager,
|
|
||||||
asset_path: &str,
|
asset_path: &str,
|
||||||
) -> Result<EntityObject> {
|
) -> Result<EntityObject> {
|
||||||
// load asset
|
// load asset
|
||||||
let gltf_asset = GltfAsset::new(&AssetPath::from(("", asset_path)))?;
|
let gltf_asset = GltfAsset::new(&AssetPath::from(("", asset_path)))?;
|
||||||
|
|
||||||
|
let context = world.resources.get::<Context>();
|
||||||
|
|
||||||
let asset = Asset::new(
|
let asset = Asset::new(
|
||||||
context.device(),
|
context.device(),
|
||||||
context.queue(),
|
context.queue(),
|
||||||
|
@ -175,7 +171,7 @@ impl AssetManager {
|
||||||
asset_path,
|
asset_path,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut entity_object = entity_object_manager.create_entity();
|
let mut entity_object = world.new_entity();
|
||||||
|
|
||||||
entity_object.gltf_file = Some(asset.gltf_file);
|
entity_object.gltf_file = Some(asset.gltf_file);
|
||||||
|
|
||||||
|
@ -268,12 +264,7 @@ impl AssetManager {
|
||||||
|
|
||||||
/// checks if the '.gltf' file with given name is already loaded, if not, loads it
|
/// checks if the '.gltf' file with given name is already loaded, if not, loads it
|
||||||
/// add - if true, adds the asset to the internal map
|
/// add - if true, adds the asset to the internal map
|
||||||
fn load_gltf_asset(
|
fn load_gltf_asset(&mut self, context: &Context, gltf_file: &str, add: bool) -> Result<Asset> {
|
||||||
&mut self,
|
|
||||||
context: &Arc<Context>,
|
|
||||||
gltf_file: &str,
|
|
||||||
add: bool,
|
|
||||||
) -> Result<Asset> {
|
|
||||||
loop {
|
loop {
|
||||||
let queued_lock = self.queued_for_async_load.read().unwrap();
|
let queued_lock = self.queued_for_async_load.read().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,8 @@ pub trait AssetLoader {
|
||||||
pub struct AssetHandler<'a> {
|
pub struct AssetHandler<'a> {
|
||||||
pub(crate) asset_manager: &'a RwLock<AssetManager>,
|
pub(crate) asset_manager: &'a RwLock<AssetManager>,
|
||||||
|
|
||||||
pub(crate) context: &'a Arc<Context>,
|
|
||||||
|
|
||||||
pub(crate) resource_base_path: &'a String,
|
pub(crate) resource_base_path: &'a String,
|
||||||
|
|
||||||
pub(crate) entity_object_manager: &'a EntityObjectManager,
|
|
||||||
|
|
||||||
pub(crate) phantom_data: PhantomData<&'a ()>,
|
pub(crate) phantom_data: PhantomData<&'a ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub struct Engine {
|
||||||
input: Arc<RwLock<Input>>,
|
input: Arc<RwLock<Input>>,
|
||||||
|
|
||||||
// loads and keeps track of raw data
|
// loads and keeps track of raw data
|
||||||
asset_manager: RwLock<AssetManager>,
|
asset_manager: AssetManager,
|
||||||
|
|
||||||
resource_base_path: String,
|
resource_base_path: String,
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ impl Engine {
|
||||||
gui_handler,
|
gui_handler,
|
||||||
input: Arc::new(RwLock::new(input)),
|
input: Arc::new(RwLock::new(input)),
|
||||||
|
|
||||||
asset_manager: RwLock::new(asset_manager),
|
asset_manager,
|
||||||
|
|
||||||
resource_base_path: create_info.resource_base_path,
|
resource_base_path: create_info.resource_base_path,
|
||||||
|
|
||||||
|
@ -304,13 +304,11 @@ impl Engine {
|
||||||
|
|
||||||
pub fn assets(&self) -> AssetHandler<'_> {
|
pub fn assets(&self) -> AssetHandler<'_> {
|
||||||
AssetHandler {
|
AssetHandler {
|
||||||
asset_manager: &self.graphical.asset_manager,
|
asset_manager: &self.asset_manager,
|
||||||
|
|
||||||
context: &self.graphical.context,
|
context: &self.graphical.context,
|
||||||
|
|
||||||
resource_base_path: &self.graphical.resource_base_path,
|
resource_base_path: &self.resource_base_path,
|
||||||
|
|
||||||
entity_object_manager: &self.entity_object_manager,
|
|
||||||
|
|
||||||
phantom_data: PhantomData,
|
phantom_data: PhantomData,
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,49 +248,16 @@ pub struct ParticleSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParticleSystem {
|
impl ParticleSystem {
|
||||||
pub fn new(
|
pub fn new(info: ParticleSystemInfo, world: &World, draw: &mut Draw) -> Result<Self> {
|
||||||
info: ParticleSystemInfo,
|
let context = world.resources.get::<Context>();
|
||||||
engine: &Engine,
|
let scene = world.resources.get::<Scene>();
|
||||||
scene: &Scene,
|
|
||||||
draw: &mut Draw,
|
|
||||||
) -> Result<Self> {
|
|
||||||
Self::_new(
|
|
||||||
info,
|
|
||||||
engine.device(),
|
|
||||||
engine.queue(),
|
|
||||||
scene.particle_system_vulkan_objects(),
|
|
||||||
engine.settings().graphics_info()?.render_type,
|
|
||||||
draw,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_from_scene<'a>(
|
|
||||||
info: ParticleSystemInfo,
|
|
||||||
scene: &Scene,
|
|
||||||
draw: &mut Draw,
|
|
||||||
) -> Result<Self> {
|
|
||||||
Self::_new(
|
Self::_new(
|
||||||
info,
|
info,
|
||||||
scene.device(),
|
context.device(),
|
||||||
scene.queue(),
|
context.queue(),
|
||||||
scene.particle_system_vulkan_objects(),
|
scene.particle_system_vulkan_objects(),
|
||||||
scene.render_type,
|
scene.render_type(),
|
||||||
draw,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_with_vk_objects(
|
|
||||||
info: ParticleSystemInfo,
|
|
||||||
engine: &Engine,
|
|
||||||
particle_system_vulkan_objects: &ParticleSystemVulkanObjects,
|
|
||||||
draw: &mut Draw,
|
|
||||||
) -> Result<Self> {
|
|
||||||
Self::_new(
|
|
||||||
info,
|
|
||||||
engine.device(),
|
|
||||||
engine.queue(),
|
|
||||||
particle_system_vulkan_objects,
|
|
||||||
engine.settings().graphics_info()?.render_type,
|
|
||||||
draw,
|
draw,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -569,20 +536,22 @@ impl EntityComponent for ParticleSystem {
|
||||||
let now = world.now();
|
let now = world.now();
|
||||||
self.start = now;
|
self.start = now;
|
||||||
|
|
||||||
|
let context = world.resources.get::<Context>();
|
||||||
|
|
||||||
// Copy gpu only buffer into temporary cpu buffer to modify starting time
|
// Copy gpu only buffer into temporary cpu buffer to modify starting time
|
||||||
// of each particle. Then copy the data back into the gpu only buffer.
|
// of each particle. Then copy the data back into the gpu only buffer.
|
||||||
{
|
{
|
||||||
let now_f32 = now.as_secs_f32();
|
let now_f32 = now.as_secs_f32();
|
||||||
|
|
||||||
let fence = Fence::builder().build(world.device().clone())?;
|
let fence = Fence::builder().build(context.device().clone())?;
|
||||||
let command_buffer = CommandBuffer::new_primary()
|
let command_buffer = CommandBuffer::new_primary()
|
||||||
.build(world.device().clone(), world.queue().clone())?;
|
.build(context.device().clone(), context.queue().clone())?;
|
||||||
|
|
||||||
let cpu_buffer: Arc<Buffer<ParticleInfoBuffer>> = Buffer::builder()
|
let cpu_buffer: Arc<Buffer<ParticleInfoBuffer>> = Buffer::builder()
|
||||||
.set_memory_usage(MemoryUsage::GpuToCpu)
|
.set_memory_usage(MemoryUsage::GpuToCpu)
|
||||||
.set_usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT)
|
.set_usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT)
|
||||||
.set_size(self.particle_buffer.size())
|
.set_size(self.particle_buffer.size())
|
||||||
.build(world.device().clone())?;
|
.build(context.device().clone())?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new(
|
let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new(
|
||||||
|
@ -602,12 +571,12 @@ impl EntityComponent for ParticleSystem {
|
||||||
|
|
||||||
// submit
|
// submit
|
||||||
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
|
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
|
||||||
world
|
context
|
||||||
.queue()
|
.queue()
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.submit(Some(&fence), &[submit])?;
|
.submit(Some(&fence), &[submit])?;
|
||||||
world
|
context
|
||||||
.device()
|
.device()
|
||||||
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
|
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
|
||||||
|
|
||||||
|
@ -653,12 +622,12 @@ impl EntityComponent for ParticleSystem {
|
||||||
|
|
||||||
// submit
|
// submit
|
||||||
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
|
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
|
||||||
world
|
context
|
||||||
.queue()
|
.queue()
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.submit(Some(&fence), &[submit])?;
|
.submit(Some(&fence), &[submit])?;
|
||||||
world
|
context
|
||||||
.device()
|
.device()
|
||||||
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
|
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue