Compare commits

...

2 commits

Author SHA1 Message Date
d590b2bc19 Update Rust crate mlua to 0.10.0 2025-02-27 06:02:29 +00:00
4e8f652ffd start unraveling engine 2025-02-27 06:29:28 +01:00
7 changed files with 39 additions and 86 deletions

View file

@ -44,7 +44,7 @@ iterchunks = "0.5.0"
reqwest = { version = "0.12.5", features = ["blocking"] }
shared_library = "0.1.9"
gltf = { version = "1.4.1", features = ["extras", "names"] }
mlua = { version = "0.9.9", features = ["lua54", "send", "vendored"] }
mlua = { version = "0.10.0", features = ["lua54", "send", "vendored"] }
public-ip = { version = "0.2.2", default-features = false, features = ["all-providers", "tokio-dns-resolver"] }
async-std = { version = "1.12.0" }
if-addrs = { version = "0.13.0" }

View file

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

View file

@ -125,16 +125,11 @@ impl AssetManager {
}
/// Creates an empty `EditableEntity`
pub fn load_asset_file(
&mut self,
context: &Arc<Context>,
entity_object_manager: &EntityObjectManager,
asset_file: &str,
) -> Result<EntityObject> {
pub fn load_asset_file(&mut self, world: &mut World, asset_file: &str) -> Result<EntityObject> {
// 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);
@ -160,13 +155,14 @@ impl AssetManager {
/// Creates an empty `EditableEntity`
pub fn load_asset_file_absolute(
&mut self,
context: &Arc<Context>,
entity_object_manager: &EntityObjectManager,
world: &mut World,
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(),
@ -175,7 +171,7 @@ impl AssetManager {
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);
@ -268,12 +264,7 @@ 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: &Arc<Context>,
gltf_file: &str,
add: bool,
) -> Result<Asset> {
fn load_gltf_asset(&mut self, context: &Context, gltf_file: &str, add: bool) -> Result<Asset> {
loop {
let queued_lock = self.queued_for_async_load.read().unwrap();

View file

@ -16,12 +16,8 @@ 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: RwLock<AssetManager>,
asset_manager: AssetManager,
resource_base_path: String,
}
@ -239,7 +239,7 @@ impl Engine {
gui_handler,
input: Arc::new(RwLock::new(input)),
asset_manager: RwLock::new(asset_manager),
asset_manager,
resource_base_path: create_info.resource_base_path,
@ -304,13 +304,11 @@ impl Engine {
pub fn assets(&self) -> AssetHandler<'_> {
AssetHandler {
asset_manager: &self.graphical.asset_manager,
asset_manager: &self.asset_manager,
context: &self.graphical.context,
resource_base_path: &self.graphical.resource_base_path,
entity_object_manager: &self.entity_object_manager,
resource_base_path: &self.resource_base_path,
phantom_data: PhantomData,
}

View file

@ -248,49 +248,16 @@ pub struct ParticleSystem {
}
impl ParticleSystem {
pub fn new(
info: ParticleSystemInfo,
engine: &Engine,
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(info: ParticleSystemInfo, world: &World, draw: &mut Draw) -> Result<Self> {
let context = world.resources.get::<Context>();
let scene = world.resources.get::<Scene>();
pub fn new_from_scene<'a>(
info: ParticleSystemInfo,
scene: &Scene,
draw: &mut Draw,
) -> Result<Self> {
Self::_new(
info,
scene.device(),
scene.queue(),
context.device(),
context.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,
scene.render_type(),
draw,
)
}
@ -569,20 +536,22 @@ 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(world.device().clone())?;
let fence = Fence::builder().build(context.device().clone())?;
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()
.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(world.device().clone())?;
.build(context.device().clone())?;
{
let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new(
@ -602,12 +571,12 @@ impl EntityComponent for ParticleSystem {
// submit
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
world
context
.queue()
.lock()
.unwrap()
.submit(Some(&fence), &[submit])?;
world
context
.device()
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
@ -653,12 +622,12 @@ impl EntityComponent for ParticleSystem {
// submit
let submit = SubmitInfo::default().add_command_buffer(&command_buffer);
world
context
.queue()
.lock()
.unwrap()
.submit(Some(&fence), &[submit])?;
world
context
.device()
.wait_for_fences(&[&fence], true, Duration::from_secs(1))?;
}