implements PLN-0104
This commit is contained in:
@@ -103,6 +103,89 @@ impl Game2DFrameComposer for LegacyHardwareGame2DFrameComposer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LegacyHardwareRuntimePlatform<'a> {
|
||||
hw: &'a mut dyn HardwareBridge,
|
||||
}
|
||||
|
||||
impl<'a> LegacyHardwareRuntimePlatform<'a> {
|
||||
pub fn new(hw: &'a mut dyn HardwareBridge) -> Self {
|
||||
Self { hw }
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderSubmissionSink for LegacyHardwareRuntimePlatform<'_> {
|
||||
fn submit_render_submission(
|
||||
&mut self,
|
||||
submission: RenderSubmission,
|
||||
) -> Result<(), RenderSubmitError> {
|
||||
self.hw.publish_render_submission(&submission);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderBackend for LegacyHardwareRuntimePlatform<'_> {
|
||||
fn render_frame(&mut self) {
|
||||
self.hw.render_frame();
|
||||
}
|
||||
}
|
||||
|
||||
impl Game2DFrameComposer for LegacyHardwareRuntimePlatform<'_> {
|
||||
fn begin_frame(&mut self) {
|
||||
self.hw.begin_frame();
|
||||
}
|
||||
|
||||
fn bind_scene(&mut self, scene_bank_id: usize) -> ComposerOpStatus {
|
||||
if self.hw.bind_scene(scene_bank_id) {
|
||||
ComposerOpStatus::Ok
|
||||
} else {
|
||||
ComposerOpStatus::SceneUnavailable
|
||||
}
|
||||
}
|
||||
|
||||
fn unbind_scene(&mut self) {
|
||||
self.hw.unbind_scene();
|
||||
}
|
||||
|
||||
fn set_camera(&mut self, x: i32, y: i32) -> ComposerOpStatus {
|
||||
self.hw.set_camera(x, y);
|
||||
ComposerOpStatus::Ok
|
||||
}
|
||||
|
||||
fn emit_sprite(&mut self, sprite: Sprite) -> ComposerOpStatus {
|
||||
if !self.hw.has_glyph_bank(sprite.bank_id as usize) {
|
||||
return ComposerOpStatus::BankInvalid;
|
||||
}
|
||||
|
||||
if self.hw.emit_sprite(sprite) {
|
||||
ComposerOpStatus::Ok
|
||||
} else {
|
||||
ComposerOpStatus::SpriteOverflow
|
||||
}
|
||||
}
|
||||
|
||||
fn close_game2d_packet(&self) -> Game2DFramePacket {
|
||||
self.hw.close_game2d_packet()
|
||||
}
|
||||
}
|
||||
|
||||
impl InputPlatform for LegacyHardwareRuntimePlatform<'_> {
|
||||
fn pad(&self) -> &dyn PadBridge {
|
||||
self.hw.pad()
|
||||
}
|
||||
|
||||
fn pad_mut(&mut self) -> &mut dyn PadBridge {
|
||||
self.hw.pad_mut()
|
||||
}
|
||||
|
||||
fn touch(&self) -> &dyn TouchBridge {
|
||||
self.hw.touch()
|
||||
}
|
||||
|
||||
fn touch_mut(&mut self) -> &mut dyn TouchBridge {
|
||||
self.hw.touch_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AudioPlatform: AudioBridge {}
|
||||
impl<T: AudioBridge + ?Sized> AudioPlatform for T {}
|
||||
|
||||
@@ -129,19 +212,63 @@ pub struct NoopTelemetryPlatform;
|
||||
|
||||
impl TelemetryPlatform for NoopTelemetryPlatform {}
|
||||
|
||||
static LEGACY_NOOP_TELEMETRY: NoopTelemetryPlatform = NoopTelemetryPlatform;
|
||||
|
||||
pub trait RuntimePlatform {
|
||||
fn render_submission_sink(&mut self) -> &mut dyn RenderSubmissionSink;
|
||||
fn render_backend(&mut self) -> &mut dyn RenderBackend;
|
||||
fn game2d_frame_composer(&mut self) -> &mut dyn Game2DFrameComposer;
|
||||
fn audio(&self) -> &dyn AudioPlatform;
|
||||
fn audio_mut(&mut self) -> &mut dyn AudioPlatform;
|
||||
fn audio(&self) -> &dyn AudioBridge;
|
||||
fn audio_mut(&mut self) -> &mut dyn AudioBridge;
|
||||
fn input(&self) -> &dyn InputPlatform;
|
||||
fn input_mut(&mut self) -> &mut dyn InputPlatform;
|
||||
fn assets(&self) -> &dyn AssetStoragePlatform;
|
||||
fn assets_mut(&mut self) -> &mut dyn AssetStoragePlatform;
|
||||
fn assets(&self) -> &dyn AssetBridge;
|
||||
fn assets_mut(&mut self) -> &mut dyn AssetBridge;
|
||||
fn telemetry(&self) -> &dyn TelemetryPlatform;
|
||||
}
|
||||
|
||||
impl RuntimePlatform for LegacyHardwareRuntimePlatform<'_> {
|
||||
fn render_submission_sink(&mut self) -> &mut dyn RenderSubmissionSink {
|
||||
self
|
||||
}
|
||||
|
||||
fn render_backend(&mut self) -> &mut dyn RenderBackend {
|
||||
self
|
||||
}
|
||||
|
||||
fn game2d_frame_composer(&mut self) -> &mut dyn Game2DFrameComposer {
|
||||
self
|
||||
}
|
||||
|
||||
fn audio(&self) -> &dyn AudioBridge {
|
||||
self.hw.audio()
|
||||
}
|
||||
|
||||
fn audio_mut(&mut self) -> &mut dyn AudioBridge {
|
||||
self.hw.audio_mut()
|
||||
}
|
||||
|
||||
fn input(&self) -> &dyn InputPlatform {
|
||||
self
|
||||
}
|
||||
|
||||
fn input_mut(&mut self) -> &mut dyn InputPlatform {
|
||||
self
|
||||
}
|
||||
|
||||
fn assets(&self) -> &dyn AssetBridge {
|
||||
self.hw.assets()
|
||||
}
|
||||
|
||||
fn assets_mut(&mut self) -> &mut dyn AssetBridge {
|
||||
self.hw.assets_mut()
|
||||
}
|
||||
|
||||
fn telemetry(&self) -> &dyn TelemetryPlatform {
|
||||
&LEGACY_NOOP_TELEMETRY
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TestPlatform: RuntimePlatform {}
|
||||
impl<T: RuntimePlatform + ?Sized> TestPlatform for T {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user