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