Compare commits

..

1 commit

Author SHA1 Message Date
b47a962096 Update Rust crate itertools to 0.14.0 2025-02-26 19:12:13 +00:00
6 changed files with 86 additions and 39 deletions

View file

@ -24,12 +24,11 @@ use std::{
io::{Error, Write},
mem::swap,
net::SocketAddr,
sync::Mutex,
};
use chrono::Local;
static LOG_FILE: Mutex<Option<NetworkLogFile>> = Mutex::new(None);
static mut LOG_FILE: Option<NetworkLogFile> = None;
pub struct NetworkLogFile {
file: File,
@ -43,7 +42,9 @@ impl NetworkLogFile {
file.write_all(format!("{:?}\n", Local::now()).as_bytes())?;
file.write_all("================================================\n\n\n".as_bytes())?;
*LOG_FILE.lock().unwrap() = Some(NetworkLogFile { file });
unsafe {
LOG_FILE = Some(NetworkLogFile { file });
}
Ok(())
}
@ -51,13 +52,13 @@ impl NetworkLogFile {
pub(crate) fn log(mut message: String) -> std::result::Result<(), Error> {
message += "\n";
LOG_FILE
.lock()
.unwrap()
.as_mut()
.expect("log file not set!")
.file
.write_all(message.as_bytes())
unsafe {
LOG_FILE
.as_mut()
.expect("log file not set!")
.file
.write_all(message.as_bytes())
}
}
}

View file

@ -50,7 +50,7 @@ pub struct EntityObject {
pub debug_name: Option<String>,
// gltf file name
pub gltf_file: Option<String>,
pub(crate) gltf_file: Option<String>,
// activation state of Entity
pub(crate) activation_state: ActivationState,

View file

@ -125,11 +125,16 @@ impl AssetManager {
}
/// Creates an empty `EditableEntity`
pub fn load_asset_file(&mut self, world: &mut World, asset_file: &str) -> Result<EntityObject> {
pub fn load_asset_file(
&mut self,
context: &Arc<Context>,
entity_object_manager: &EntityObjectManager,
asset_file: &str,
) -> Result<EntityObject> {
// load asset
let asset = self.load_gltf_asset(world.resources.get::<Context>(), asset_file, true)?;
let asset = self.load_gltf_asset(context, asset_file, true)?;
let mut entity_object = world.new_entity();
let mut entity_object = entity_object_manager.create_entity();
entity_object.gltf_file = Some(asset.gltf_file);
@ -155,14 +160,13 @@ impl AssetManager {
/// Creates an empty `EditableEntity`
pub fn load_asset_file_absolute(
&mut self,
world: &mut World,
context: &Arc<Context>,
entity_object_manager: &EntityObjectManager,
asset_path: &str,
) -> Result<EntityObject> {
// load asset
let gltf_asset = GltfAsset::new(&AssetPath::from(("", asset_path)))?;
let context = world.resources.get::<Context>();
let asset = Asset::new(
context.device(),
context.queue(),
@ -171,7 +175,7 @@ impl AssetManager {
asset_path,
)?;
let mut entity_object = world.new_entity();
let mut entity_object = entity_object_manager.create_entity();
entity_object.gltf_file = Some(asset.gltf_file);
@ -264,7 +268,12 @@ impl AssetManager {
/// 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
fn load_gltf_asset(&mut self, context: &Context, gltf_file: &str, add: bool) -> Result<Asset> {
fn load_gltf_asset(
&mut self,
context: &Arc<Context>,
gltf_file: &str,
add: bool,
) -> Result<Asset> {
loop {
let queued_lock = self.queued_for_async_load.read().unwrap();

View file

@ -16,8 +16,12 @@ pub trait AssetLoader {
pub struct AssetHandler<'a> {
pub(crate) asset_manager: &'a RwLock<AssetManager>,
pub(crate) context: &'a Arc<Context>,
pub(crate) resource_base_path: &'a String,
pub(crate) entity_object_manager: &'a EntityObjectManager,
pub(crate) phantom_data: PhantomData<&'a ()>,
}

View file

@ -80,7 +80,7 @@ pub struct Engine {
input: Arc<RwLock<Input>>,
// loads and keeps track of raw data
asset_manager: AssetManager,
asset_manager: RwLock<AssetManager>,
resource_base_path: String,
}
@ -239,7 +239,7 @@ impl Engine {
gui_handler,
input: Arc::new(RwLock::new(input)),
asset_manager,
asset_manager: RwLock::new(asset_manager),
resource_base_path: create_info.resource_base_path,
@ -304,11 +304,13 @@ impl Engine {
pub fn assets(&self) -> AssetHandler<'_> {
AssetHandler {
asset_manager: &self.asset_manager,
asset_manager: &self.graphical.asset_manager,
context: &self.graphical.context,
resource_base_path: &self.resource_base_path,
resource_base_path: &self.graphical.resource_base_path,
entity_object_manager: &self.entity_object_manager,
phantom_data: PhantomData,
}

View file

@ -248,16 +248,49 @@ pub struct ParticleSystem {
}
impl ParticleSystem {
pub fn new(info: ParticleSystemInfo, world: &World, draw: &mut Draw) -> Result<Self> {
let context = world.resources.get::<Context>();
let scene = world.resources.get::<Scene>();
pub fn new(
info: ParticleSystemInfo,
engine: &Engine,
scene: &Scene,
draw: &mut Draw,
) -> Result<Self> {
Self::_new(
info,
context.device(),
context.queue(),
engine.device(),
engine.queue(),
scene.particle_system_vulkan_objects(),
scene.render_type(),
engine.settings().graphics_info()?.render_type,
draw,
)
}
pub fn new_from_scene<'a>(
info: ParticleSystemInfo,
scene: &Scene,
draw: &mut Draw,
) -> Result<Self> {
Self::_new(
info,
scene.device(),
scene.queue(),
scene.particle_system_vulkan_objects(),
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,
)
}
@ -536,22 +569,20 @@ impl EntityComponent for ParticleSystem {
let now = world.now();
self.start = now;
let context = world.resources.get::<Context>();
// 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.
{
let now_f32 = now.as_secs_f32();
let fence = Fence::builder().build(context.device().clone())?;
let fence = Fence::builder().build(world.device().clone())?;
let command_buffer = CommandBuffer::new_primary()
.build(context.device().clone(), context.queue().clone())?;
.build(world.device().clone(), world.queue().clone())?;
let cpu_buffer: Arc<Buffer<ParticleInfoBuffer>> = Buffer::builder()
.set_memory_usage(MemoryUsage::GpuToCpu)
.set_usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT)
.set_size(self.particle_buffer.size())
.build(context.device().clone())?;
.build(world.device().clone())?;
{
let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new(
@ -571,12 +602,12 @@ impl EntityComponent for ParticleSystem {
// submit
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
context
world
.queue()
.lock()
.unwrap()
.submit(Some(&fence), &[submit])?;
context
world
.device()
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
@ -622,12 +653,12 @@ impl EntityComponent for ParticleSystem {
// submit
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
context
world
.queue()
.lock()
.unwrap()
.submit(Some(&fence), &[submit])?;
context
world
.device()
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
}