dev/scene-bank-glyph-runtime-binding-leak #21
@ -1186,47 +1186,46 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_scene() -> SceneBank {
|
fn test_scene() -> SceneBank {
|
||||||
let make_layer =
|
let make_layer = |glyph_asset_id: AssetId,
|
||||||
|glyph_asset_id: AssetId,
|
active: bool,
|
||||||
active: bool,
|
parallax_x: f32,
|
||||||
parallax_x: f32,
|
parallax_y: f32,
|
||||||
parallax_y: f32,
|
tile_size: TileSize| SceneLayer {
|
||||||
tile_size: TileSize| SceneLayer {
|
active,
|
||||||
active,
|
glyph_asset_id,
|
||||||
glyph_asset_id,
|
tile_size,
|
||||||
tile_size,
|
parallax_factor: ParallaxFactor { x: parallax_x, y: parallax_y },
|
||||||
parallax_factor: ParallaxFactor { x: parallax_x, y: parallax_y },
|
tilemap: TileMap {
|
||||||
tilemap: TileMap {
|
width: 2,
|
||||||
width: 2,
|
height: 2,
|
||||||
height: 2,
|
tiles: vec![
|
||||||
tiles: vec![
|
Tile {
|
||||||
Tile {
|
active: true,
|
||||||
active: true,
|
glyph: Glyph { glyph_id: 10, palette_id: 1 },
|
||||||
glyph: Glyph { glyph_id: 10, palette_id: 1 },
|
flip_x: false,
|
||||||
flip_x: false,
|
flip_y: false,
|
||||||
flip_y: false,
|
},
|
||||||
},
|
Tile {
|
||||||
Tile {
|
active: true,
|
||||||
active: true,
|
glyph: Glyph { glyph_id: 20, palette_id: 2 },
|
||||||
glyph: Glyph { glyph_id: 20, palette_id: 2 },
|
flip_x: true,
|
||||||
flip_x: true,
|
flip_y: false,
|
||||||
flip_y: false,
|
},
|
||||||
},
|
Tile {
|
||||||
Tile {
|
active: true,
|
||||||
active: true,
|
glyph: Glyph { glyph_id: 30, palette_id: 3 },
|
||||||
glyph: Glyph { glyph_id: 30, palette_id: 3 },
|
flip_x: false,
|
||||||
flip_x: false,
|
flip_y: true,
|
||||||
flip_y: true,
|
},
|
||||||
},
|
Tile {
|
||||||
Tile {
|
active,
|
||||||
active,
|
glyph: Glyph { glyph_id: 40, palette_id: 4 },
|
||||||
glyph: Glyph { glyph_id: 40, palette_id: 4 },
|
flip_x: true,
|
||||||
flip_x: true,
|
flip_y: true,
|
||||||
flip_y: true,
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
},
|
};
|
||||||
};
|
|
||||||
|
|
||||||
SceneBank {
|
SceneBank {
|
||||||
layers: [
|
layers: [
|
||||||
|
|||||||
@ -252,7 +252,8 @@ impl FrameComposer {
|
|||||||
let scene_bank_id = self.active_scene_id.expect("active scene id must exist");
|
let scene_bank_id = self.active_scene_id.expect("active scene id must exist");
|
||||||
let resolved_glyph_slots =
|
let resolved_glyph_slots =
|
||||||
self.resolve_glyph_slots(scene, scene_bank_id, "render_frame");
|
self.resolve_glyph_slots(scene, scene_bank_id, "render_frame");
|
||||||
let (Some(cache), Some(resolver)) = (self.cache.as_mut(), self.resolver.as_mut()) else {
|
let (Some(cache), Some(resolver)) = (self.cache.as_mut(), self.resolver.as_mut())
|
||||||
|
else {
|
||||||
panic!("SCENE runtime invariant broken: active scene without cache/resolver");
|
panic!("SCENE runtime invariant broken: active scene without cache/resolver");
|
||||||
};
|
};
|
||||||
let update = resolver.update(scene, self.camera_x_px, self.camera_y_px);
|
let update = resolver.update(scene, self.camera_x_px, self.camera_y_px);
|
||||||
@ -342,8 +343,8 @@ mod tests {
|
|||||||
use crate::memory_banks::{
|
use crate::memory_banks::{
|
||||||
GlyphBankPoolAccess, GlyphBankPoolInstaller, MemoryBanks, SceneBankPoolInstaller,
|
GlyphBankPoolAccess, GlyphBankPoolInstaller, MemoryBanks, SceneBankPoolInstaller,
|
||||||
};
|
};
|
||||||
use prometeu_hal::color::Color;
|
|
||||||
use prometeu_hal::asset::AssetId;
|
use prometeu_hal::asset::AssetId;
|
||||||
|
use prometeu_hal::color::Color;
|
||||||
use prometeu_hal::glyph_bank::{GlyphBank, TileSize};
|
use prometeu_hal::glyph_bank::{GlyphBank, TileSize};
|
||||||
use prometeu_hal::scene_layer::{ParallaxFactor, SceneLayer};
|
use prometeu_hal::scene_layer::{ParallaxFactor, SceneLayer};
|
||||||
use prometeu_hal::tile::Tile;
|
use prometeu_hal::tile::Tile;
|
||||||
@ -404,12 +405,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn frame_composer_starts_unbound_with_empty_owned_state() {
|
fn frame_composer_starts_unbound_with_empty_owned_state() {
|
||||||
let frame_composer = FrameComposer::new(
|
let frame_composer =
|
||||||
320,
|
FrameComposer::new(320, 180, Arc::new(MemoryBanks::new()), make_glyph_slot_index(&[]));
|
||||||
180,
|
|
||||||
Arc::new(MemoryBanks::new()),
|
|
||||||
make_glyph_slot_index(&[]),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(frame_composer.viewport_size(), (320, 180));
|
assert_eq!(frame_composer.viewport_size(), (320, 180));
|
||||||
assert_eq!(frame_composer.active_scene_id(), None);
|
assert_eq!(frame_composer.active_scene_id(), None);
|
||||||
@ -479,12 +476,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_camera_stores_top_left_pixel_coordinates() {
|
fn set_camera_stores_top_left_pixel_coordinates() {
|
||||||
let mut frame_composer = FrameComposer::new(
|
let mut frame_composer =
|
||||||
320,
|
FrameComposer::new(320, 180, Arc::new(MemoryBanks::new()), make_glyph_slot_index(&[]));
|
||||||
180,
|
|
||||||
Arc::new(MemoryBanks::new()),
|
|
||||||
make_glyph_slot_index(&[]),
|
|
||||||
);
|
|
||||||
|
|
||||||
frame_composer.set_camera(-12, 48);
|
frame_composer.set_camera(-12, 48);
|
||||||
|
|
||||||
@ -506,12 +499,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn missing_scene_binding_falls_back_to_no_scene_state() {
|
fn missing_scene_binding_falls_back_to_no_scene_state() {
|
||||||
let mut frame_composer = FrameComposer::new(
|
let mut frame_composer =
|
||||||
320,
|
FrameComposer::new(320, 180, Arc::new(MemoryBanks::new()), make_glyph_slot_index(&[]));
|
||||||
180,
|
|
||||||
Arc::new(MemoryBanks::new()),
|
|
||||||
make_glyph_slot_index(&[]),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(!frame_composer.bind_scene(7));
|
assert!(!frame_composer.bind_scene(7));
|
||||||
|
|
||||||
@ -525,8 +514,7 @@ mod tests {
|
|||||||
let banks = Arc::new(MemoryBanks::new());
|
let banks = Arc::new(MemoryBanks::new());
|
||||||
banks.install_scene_bank(0, Arc::new(make_scene()));
|
banks.install_scene_bank(0, Arc::new(make_scene()));
|
||||||
|
|
||||||
let mut frame_composer =
|
let mut frame_composer = FrameComposer::new(320, 180, banks, make_glyph_slot_index(&[]));
|
||||||
FrameComposer::new(320, 180, banks, make_glyph_slot_index(&[]));
|
|
||||||
|
|
||||||
let panic = catch_unwind(AssertUnwindSafe(|| frame_composer.bind_scene(0)))
|
let panic = catch_unwind(AssertUnwindSafe(|| frame_composer.bind_scene(0)))
|
||||||
.expect_err("bind_scene should panic when dependency is missing");
|
.expect_err("bind_scene should panic when dependency is missing");
|
||||||
@ -661,12 +649,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn frame_composer_emits_ordered_sprites_for_rendering() {
|
fn frame_composer_emits_ordered_sprites_for_rendering() {
|
||||||
let mut frame_composer = FrameComposer::new(
|
let mut frame_composer =
|
||||||
320,
|
FrameComposer::new(320, 180, Arc::new(MemoryBanks::new()), make_glyph_slot_index(&[]));
|
||||||
180,
|
|
||||||
Arc::new(MemoryBanks::new()),
|
|
||||||
make_glyph_slot_index(&[]),
|
|
||||||
);
|
|
||||||
frame_composer.begin_frame();
|
frame_composer.begin_frame();
|
||||||
|
|
||||||
assert!(frame_composer.emit_sprite(Sprite {
|
assert!(frame_composer.emit_sprite(Sprite {
|
||||||
@ -704,13 +688,12 @@ mod tests {
|
|||||||
let banks = Arc::new(MemoryBanks::new());
|
let banks = Arc::new(MemoryBanks::new());
|
||||||
banks.install_glyph_bank(1, Arc::new(make_glyph_bank(TileSize::Size8, 3, Color::WHITE)));
|
banks.install_glyph_bank(1, Arc::new(make_glyph_bank(TileSize::Size8, 3, Color::WHITE)));
|
||||||
|
|
||||||
let mut frame_composer =
|
let mut frame_composer = FrameComposer::new(
|
||||||
FrameComposer::new(
|
16,
|
||||||
16,
|
16,
|
||||||
16,
|
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
||||||
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
make_glyph_slot_index(&[]),
|
||||||
make_glyph_slot_index(&[]),
|
);
|
||||||
);
|
|
||||||
frame_composer.begin_frame();
|
frame_composer.begin_frame();
|
||||||
assert!(frame_composer.emit_sprite(Sprite {
|
assert!(frame_composer.emit_sprite(Sprite {
|
||||||
glyph: Glyph { glyph_id: 0, palette_id: 3 },
|
glyph: Glyph { glyph_id: 0, palette_id: 3 },
|
||||||
@ -740,13 +723,12 @@ mod tests {
|
|||||||
banks.install_glyph_bank(0, Arc::new(make_glyph_bank(TileSize::Size8, 2, Color::BLUE)));
|
banks.install_glyph_bank(0, Arc::new(make_glyph_bank(TileSize::Size8, 2, Color::BLUE)));
|
||||||
banks.install_scene_bank(0, Arc::new(make_scene_with_palette(0, 2, TileSize::Size8)));
|
banks.install_scene_bank(0, Arc::new(make_scene_with_palette(0, 2, TileSize::Size8)));
|
||||||
|
|
||||||
let mut frame_composer =
|
let mut frame_composer = FrameComposer::new(
|
||||||
FrameComposer::new(
|
16,
|
||||||
16,
|
16,
|
||||||
16,
|
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
||||||
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
make_glyph_slot_index(&[(0, 0)]),
|
||||||
make_glyph_slot_index(&[(0, 0)]),
|
);
|
||||||
);
|
|
||||||
assert!(frame_composer.bind_scene(0));
|
assert!(frame_composer.bind_scene(0));
|
||||||
|
|
||||||
let mut gfx = Gfx::new(16, 16, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
let mut gfx = Gfx::new(16, 16, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
||||||
@ -776,13 +758,12 @@ mod tests {
|
|||||||
banks.install_scene_bank(0, Arc::new(make_scene_with_palette(0, 1, TileSize::Size8)));
|
banks.install_scene_bank(0, Arc::new(make_scene_with_palette(0, 1, TileSize::Size8)));
|
||||||
banks.install_scene_bank(1, Arc::new(make_scene_with_palette(1, 2, TileSize::Size8)));
|
banks.install_scene_bank(1, Arc::new(make_scene_with_palette(1, 2, TileSize::Size8)));
|
||||||
|
|
||||||
let mut frame_composer =
|
let mut frame_composer = FrameComposer::new(
|
||||||
FrameComposer::new(
|
16,
|
||||||
16,
|
16,
|
||||||
16,
|
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
||||||
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
make_glyph_slot_index(&[(0, 0), (1, 1)]),
|
||||||
make_glyph_slot_index(&[(0, 0), (1, 1)]),
|
);
|
||||||
);
|
|
||||||
let mut gfx = Gfx::new(16, 16, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
let mut gfx = Gfx::new(16, 16, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
||||||
gfx.scene_fade_level = 31;
|
gfx.scene_fade_level = 31;
|
||||||
gfx.hud_fade_level = 31;
|
gfx.hud_fade_level = 31;
|
||||||
|
|||||||
@ -909,8 +909,8 @@ impl Gfx {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::asset::GlyphAssetSlotIndex;
|
|
||||||
use crate::FrameComposer;
|
use crate::FrameComposer;
|
||||||
|
use crate::asset::GlyphAssetSlotIndex;
|
||||||
use crate::memory_banks::{GlyphBankPoolInstaller, MemoryBanks, SceneBankPoolAccess};
|
use crate::memory_banks::{GlyphBankPoolInstaller, MemoryBanks, SceneBankPoolAccess};
|
||||||
use prometeu_hal::asset::AssetId;
|
use prometeu_hal::asset::AssetId;
|
||||||
use prometeu_hal::glyph_bank::TileSize;
|
use prometeu_hal::glyph_bank::TileSize;
|
||||||
@ -1080,13 +1080,12 @@ mod tests {
|
|||||||
fn overlay_state_is_separate_from_frame_composer_sprite_state() {
|
fn overlay_state_is_separate_from_frame_composer_sprite_state() {
|
||||||
let banks = Arc::new(MemoryBanks::new());
|
let banks = Arc::new(MemoryBanks::new());
|
||||||
let mut gfx = Gfx::new(32, 18, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
let mut gfx = Gfx::new(32, 18, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
||||||
let mut frame_composer =
|
let mut frame_composer = FrameComposer::new(
|
||||||
FrameComposer::new(
|
32,
|
||||||
32,
|
18,
|
||||||
18,
|
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
||||||
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
make_glyph_slot_index(&[]),
|
||||||
make_glyph_slot_index(&[]),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
gfx.begin_overlay_frame();
|
gfx.begin_overlay_frame();
|
||||||
frame_composer.begin_frame();
|
frame_composer.begin_frame();
|
||||||
|
|||||||
@ -15,7 +15,12 @@ mod tests {
|
|||||||
use crate::tile::Tile;
|
use crate::tile::Tile;
|
||||||
use crate::tilemap::TileMap;
|
use crate::tilemap::TileMap;
|
||||||
|
|
||||||
fn layer(glyph_asset_id: AssetId, parallax_x: f32, parallax_y: f32, glyph_id: u16) -> SceneLayer {
|
fn layer(
|
||||||
|
glyph_asset_id: AssetId,
|
||||||
|
parallax_x: f32,
|
||||||
|
parallax_y: f32,
|
||||||
|
glyph_id: u16,
|
||||||
|
) -> SceneLayer {
|
||||||
SceneLayer {
|
SceneLayer {
|
||||||
active: true,
|
active: true,
|
||||||
glyph_asset_id,
|
glyph_asset_id,
|
||||||
|
|||||||
@ -284,12 +284,7 @@ mod tests {
|
|||||||
let mut tiles = Vec::new();
|
let mut tiles = Vec::new();
|
||||||
for y in 0..4 {
|
for y in 0..4 {
|
||||||
for x in 0..4 {
|
for x in 0..4 {
|
||||||
tiles.push(make_tile(
|
tiles.push(make_tile(base_glyph + (y * 4 + x) as u16, 1, x % 2 == 0, y % 2 == 1));
|
||||||
base_glyph + (y * 4 + x) as u16,
|
|
||||||
1,
|
|
||||||
x % 2 == 0,
|
|
||||||
y % 2 == 1,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -191,11 +191,8 @@ impl NativeInterface for VirtualMachineRuntime {
|
|||||||
let bound = catch_unwind(AssertUnwindSafe(|| hw.bind_scene(scene_bank_id)))
|
let bound = catch_unwind(AssertUnwindSafe(|| hw.bind_scene(scene_bank_id)))
|
||||||
.map_err(|payload| VmFault::Panic(Self::panic_payload_to_string(payload)))?;
|
.map_err(|payload| VmFault::Panic(Self::panic_payload_to_string(payload)))?;
|
||||||
|
|
||||||
let status = if bound {
|
let status =
|
||||||
ComposerOpStatus::Ok
|
if bound { ComposerOpStatus::Ok } else { ComposerOpStatus::SceneUnavailable };
|
||||||
} else {
|
|
||||||
ComposerOpStatus::SceneUnavailable
|
|
||||||
};
|
|
||||||
ret.push_int(status as i64);
|
ret.push_int(status as i64);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,8 +180,7 @@ impl VirtualMachineRuntime {
|
|||||||
{
|
{
|
||||||
if let Err(payload) = catch_unwind(AssertUnwindSafe(|| hw.render_frame())) {
|
if let Err(payload) = catch_unwind(AssertUnwindSafe(|| hw.render_frame())) {
|
||||||
let message = Self::host_panic_payload_to_string(payload);
|
let message = Self::host_panic_payload_to_string(payload);
|
||||||
let report =
|
let report = CrashReport::VmPanic { message, pc: Some(vm.pc() as u32) };
|
||||||
CrashReport::VmPanic { message, pc: Some(vm.pc() as u32) };
|
|
||||||
self.log(
|
self.log(
|
||||||
LogLevel::Error,
|
LogLevel::Error,
|
||||||
LogSource::Vm,
|
LogSource::Vm,
|
||||||
|
|||||||
@ -4,9 +4,8 @@ use prometeu_bytecode::model::{
|
|||||||
BytecodeModule, ConstantPoolEntry, DebugInfo, Export, FunctionMeta, SyscallDecl,
|
BytecodeModule, ConstantPoolEntry, DebugInfo, Export, FunctionMeta, SyscallDecl,
|
||||||
};
|
};
|
||||||
use prometeu_hal::asset::{
|
use prometeu_hal::asset::{
|
||||||
AssetCodec, AssetEntry, AssetId, BankType, PreloadEntry,
|
AssetCodec, AssetEntry, AssetId, BankType, PreloadEntry, SCENE_DECODED_LAYER_OVERHEAD_BYTES_V1,
|
||||||
SCENE_DECODED_LAYER_OVERHEAD_BYTES_V1, SCENE_LAYER_COUNT_V1, SCENE_PAYLOAD_MAGIC_V1,
|
SCENE_LAYER_COUNT_V1, SCENE_PAYLOAD_MAGIC_V1, SCENE_PAYLOAD_VERSION_V1,
|
||||||
SCENE_PAYLOAD_VERSION_V1,
|
|
||||||
};
|
};
|
||||||
use prometeu_hal::cartridge::{
|
use prometeu_hal::cartridge::{
|
||||||
AssetsPackHeader, AssetsPackPrelude, ASSETS_PA_MAGIC, ASSETS_PA_PRELUDE_SIZE,
|
AssetsPackHeader, AssetsPackPrelude, ASSETS_PA_MAGIC, ASSETS_PA_PRELUDE_SIZE,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user