core: Add BoundingBox and static data to Graphic
Add BoundingBox, which will store the AABB of dispaly objects. Added static_data to Graphic, which is a reference to constant data shared between each instance of a specific graphic. Currently holds the render handle, bounding box, and character ID.
This commit is contained in:
parent
2c7e3c835f
commit
2c4639eb6c
|
@ -1,20 +1,24 @@
|
|||
use crate::backend::render::{RenderBackend, ShapeHandle};
|
||||
use crate::backend::render::ShapeHandle;
|
||||
use crate::display_object::{DisplayObject, DisplayObjectBase};
|
||||
use crate::player::{RenderContext, UpdateContext};
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Graphic<'gc> {
|
||||
base: DisplayObjectBase<'gc>,
|
||||
|
||||
shape_handle: ShapeHandle,
|
||||
static_data: gc_arena::Gc<'gc, GraphicStatic>,
|
||||
}
|
||||
|
||||
impl<'gc> Graphic<'gc> {
|
||||
pub fn from_swf_tag(swf_shape: &swf::Shape, renderer: &mut dyn RenderBackend) -> Self {
|
||||
let shape_handle = renderer.register_shape(swf_shape);
|
||||
pub fn from_swf_tag(context: &mut UpdateContext<'_, 'gc, '_>, swf_shape: &swf::Shape) -> Self {
|
||||
let static_data = GraphicStatic {
|
||||
id: swf_shape.id,
|
||||
render_handle: context.renderer.register_shape(swf_shape),
|
||||
bounds: swf_shape.shape_bounds.clone().into(),
|
||||
};
|
||||
Graphic {
|
||||
base: Default::default(),
|
||||
shape_handle,
|
||||
static_data: gc_arena::Gc::allocate(context.gc_context, static_data),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +33,10 @@ impl<'gc> DisplayObject<'gc> for Graphic<'gc> {
|
|||
fn render(&self, context: &mut RenderContext) {
|
||||
context.transform_stack.push(self.transform());
|
||||
|
||||
context
|
||||
.renderer
|
||||
.render_shape(self.shape_handle, context.transform_stack.transform());
|
||||
context.renderer.render_shape(
|
||||
self.static_data.render_handle,
|
||||
context.transform_stack.transform(),
|
||||
);
|
||||
|
||||
context.transform_stack.pop();
|
||||
}
|
||||
|
@ -43,3 +48,18 @@ unsafe impl<'gc> gc_arena::Collect for Graphic<'gc> {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Static data shared between all instances of a graphic.
|
||||
#[allow(dead_code)]
|
||||
struct GraphicStatic {
|
||||
id: CharacterId,
|
||||
render_handle: ShapeHandle,
|
||||
bounds: BoundingBox,
|
||||
}
|
||||
|
||||
unsafe impl<'gc> gc_arena::Collect for GraphicStatic {
|
||||
#[inline]
|
||||
fn needs_trace() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
mod display_object;
|
||||
|
||||
mod avm1;
|
||||
mod bounding_box;
|
||||
mod button;
|
||||
mod character;
|
||||
mod color_transform;
|
||||
|
@ -21,5 +22,4 @@ mod transform;
|
|||
pub mod backend;
|
||||
|
||||
pub use player::Player;
|
||||
pub use swf::Color;
|
||||
pub use swf;
|
||||
pub use swf;pub use swf::Color;
|
||||
|
|
|
@ -405,7 +405,7 @@ impl<'gc, 'a> MovieClip<'gc> {
|
|||
version: u8,
|
||||
) -> DecodeResult {
|
||||
let swf_shape = reader.read_define_shape(version)?;
|
||||
let graphic = Graphic::from_swf_tag(&swf_shape, context.renderer);
|
||||
let graphic = Graphic::from_swf_tag(context, &swf_shape);
|
||||
context
|
||||
.library
|
||||
.register_character(swf_shape.id, Character::Graphic(Box::new(graphic)));
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub use crate::bounding_box::BoundingBox;
|
||||
pub use crate::color_transform::ColorTransform;
|
||||
pub use crate::display_object::{DisplayNode, DisplayObject};
|
||||
pub use crate::matrix::Matrix;
|
||||
|
|
Loading…
Reference in New Issue