chiark / gitweb /
Move special rendering instructions to PieceSpecialProperties
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 18 Apr 2022 10:20:12 +0000 (11:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 18 Apr 2022 12:18:05 +0000 (13:18 +0100)
This gets rid of an ipc method (meaning we get rid of one method call
during piece rendering) and is also more principled, than a call which
might conceivably give different answers at different times.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs
src/gamestate.rs
src/pcrender.rs

index 1701b52c4e92ceaa07ee30d694d458f386bb175b..76fb300a0a6b74c3d5b0199c2366d88afd91b3ab 100644 (file)
@@ -221,10 +221,14 @@ impl PieceSpec for Spec {
       image: image.into()
     };
 
+    let special = PieceSpecialProperties {
+      rendering: Some(SpecialClientRendering::Die{}),
+      ..default()
+    };
     SpecLoaded {
       p: Box::new(die) as _,
       occultable,
-      special: default(),
+      special,
     }
   }
 }
@@ -315,11 +319,6 @@ impl PieceBaseTrait for Die {
   fn nfaces(&self) -> RawFaceId { self.nfaces }
 
   fn itemname(&self) -> &str { &self.itemname }
-
-  #[throws(IE)]
-  fn special(&self) -> Option<SpecialClientRendering> {
-    Some(SpecialClientRendering::Die{})
-  }
 }
 
 #[typetag::serde(name="Die")]
index 85b7e011961c0030be70efc66466dce4753d7596..1eaf95b14a4515ec4d1e4cb057ca0e70f871b6b1 100644 (file)
@@ -181,12 +181,6 @@ pub trait PieceBaseTrait: OutlineTrait + Send + Debug + 'static {
   fn nfaces(&self) -> RawFaceId;
 
   fn itemname(&self) -> &str;
-
-  // Don't add an xdata argument to this.  Implementors must not make
-  // this depend on the piece state, because the piece state might change
-  // between svg() (which sets up information in the DOM) and special()
-  // (which arranges to use that information).
-  fn special(&self) -> Result<Option<SpecialClientRendering>,IE> { Ok(None) }
 }
 
 #[typetag::serde] // usual variable: p
@@ -300,6 +294,7 @@ pub type PieceSpecLoadedOccultable =
 /// so they are mostly "can/do we do this thing".
 #[derive(Debug,Clone,Default,Serialize,Deserialize)]
 pub struct PieceSpecialProperties {
+  pub rendering: Option<SpecialClientRendering>,
 }
 
 #[typetag::serde(tag="type")]
index f41aa71d7a2fe0872fe8d83e671db1411532a4e0..c29b338723315d4c57cfe4cf2f3291b25d1971c1 100644 (file)
@@ -13,7 +13,7 @@ pub struct VisibleAngleTransform(Html);
 
 const DEFKEY_FLIP: UoKey = 'f';
 
-#[derive(Serialize,Debug)]
+#[derive(Deserialize,Serialize,Clone,Debug)]
 #[serde(tag="kind")]
 pub enum SpecialClientRendering {
   Die { },
@@ -194,7 +194,6 @@ impl PieceRenderInstructions {
 
     let angle = pri.angle(gpc);
     let bbox = o.bbox_approx()?;
-    let special = o.special()?;
 
     let dragraise = match o.thresh_dragraise()? {
       Some(n) if n < 0 => throw!(SvgE::NegativeDragraise),
@@ -208,7 +207,7 @@ impl PieceRenderInstructions {
     hwrite!(&mut defs,
            r##"<g id="piece{}" transform="{}" data-dragraise="{}""##,
            pri.vpid, &transform.0, dragraise)?;
-    if let Some(special) = &special {
+    if let Some(special) = &ipc.special.rendering {
       let special = serde_json::to_string(&special).map_err(IE::JSONEncode)?;
       hwrite!(&mut defs,
               r##" data-special="{}""##,