feat(engine): 改进 Rust 纹理管理器

- 支持任意 ID 的纹理加载(非递增)
- 添加纹理状态追踪 API
- 优化纹理缓存清理机制
- 更新 TypeScript 绑定
This commit is contained in:
yhh
2025-12-16 11:25:28 +08:00
parent 01293590e8
commit 75be905f14
7 changed files with 335 additions and 28 deletions

View File

@@ -197,14 +197,6 @@ impl Engine {
colors: &[u32],
material_ids: &[u32],
) -> Result<()> {
// Debug: log once
use std::sync::atomic::{AtomicBool, Ordering};
static LOGGED: AtomicBool = AtomicBool::new(false);
if !LOGGED.swap(true, Ordering::Relaxed) {
let sprite_count = texture_ids.len();
log::info!("Engine submit_sprite_batch: {} sprites, texture_ids: {:?}", sprite_count, texture_ids);
}
self.renderer.submit_batch(
transforms,
texture_ids,
@@ -382,6 +374,24 @@ impl Engine {
self.texture_manager.clear_all();
}
/// 获取纹理加载状态
/// Get texture loading state
pub fn get_texture_state(&self, id: u32) -> crate::renderer::texture::TextureState {
self.texture_manager.get_texture_state(id)
}
/// 检查纹理是否已就绪
/// Check if texture is ready to use
pub fn is_texture_ready(&self, id: u32) -> bool {
self.texture_manager.is_texture_ready(id)
}
/// 获取正在加载中的纹理数量
/// Get the number of textures currently loading
pub fn get_texture_loading_count(&self) -> u32 {
self.texture_manager.get_loading_count()
}
/// Check if a key is currently pressed.
/// 检查某个键是否当前被按下。
pub fn is_key_down(&self, key_code: &str) -> bool {