implements PLN-0109
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use crate::asset_bridge::AssetBridge;
|
||||
use crate::audio_bridge::AudioBridge;
|
||||
use crate::composer_status::ComposerOpStatus;
|
||||
use crate::hardware_bridge::HardwareBridge;
|
||||
use crate::pad_bridge::PadBridge;
|
||||
use crate::render_submission::{Game2DFramePacket, RenderSubmission};
|
||||
use crate::sprite::Sprite;
|
||||
@@ -21,26 +20,6 @@ pub trait RenderSubmissionSink {
|
||||
) -> Result<(), RenderSubmitError>;
|
||||
}
|
||||
|
||||
pub struct LegacyHardwareRenderSubmissionSink<'a> {
|
||||
hw: &'a mut dyn HardwareBridge,
|
||||
}
|
||||
|
||||
impl<'a> LegacyHardwareRenderSubmissionSink<'a> {
|
||||
pub fn new(hw: &'a mut dyn HardwareBridge) -> Self {
|
||||
Self { hw }
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderSubmissionSink for LegacyHardwareRenderSubmissionSink<'_> {
|
||||
fn submit_render_submission(
|
||||
&mut self,
|
||||
submission: RenderSubmission,
|
||||
) -> Result<(), RenderSubmitError> {
|
||||
self.hw.publish_render_submission(&submission);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait RenderBackend {
|
||||
fn render_frame(&mut self);
|
||||
}
|
||||
@@ -54,138 +33,6 @@ pub trait Game2DFrameComposer {
|
||||
fn close_game2d_packet(&self) -> Game2DFramePacket;
|
||||
}
|
||||
|
||||
pub struct LegacyHardwareGame2DFrameComposer<'a> {
|
||||
hw: &'a mut dyn HardwareBridge,
|
||||
}
|
||||
|
||||
impl<'a> LegacyHardwareGame2DFrameComposer<'a> {
|
||||
pub fn new(hw: &'a mut dyn HardwareBridge) -> Self {
|
||||
Self { hw }
|
||||
}
|
||||
}
|
||||
|
||||
impl Game2DFrameComposer for LegacyHardwareGame2DFrameComposer<'_> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
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 {}
|
||||
|
||||
@@ -212,8 +59,6 @@ pub struct NoopTelemetryPlatform;
|
||||
|
||||
impl TelemetryPlatform for NoopTelemetryPlatform {}
|
||||
|
||||
static LEGACY_NOOP_TELEMETRY: NoopTelemetryPlatform = NoopTelemetryPlatform;
|
||||
|
||||
pub trait RuntimePlatform {
|
||||
fn display_size(&self) -> (usize, usize) {
|
||||
(480, 270)
|
||||
@@ -231,48 +76,6 @@ pub trait RuntimePlatform {
|
||||
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