chiark / gitweb /
wip gamestate before closure approach
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 May 2020 13:11:16 +0000 (14:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 May 2020 13:11:16 +0000 (14:11 +0100)
src/gamestate.rs [new file with mode: 0644]
src/pieces.rs [new file with mode: 0644]

diff --git a/src/gamestate.rs b/src/gamestate.rs
new file mode 100644 (file)
index 0000000..c0bea89
--- /dev/null
@@ -0,0 +1,66 @@
+
+pub trait Piece {
+}
+
+#[derive(Debug)]
+pub struct PieceRecord {
+  x : Coord,
+  y : Coord,
+  p : Box<dyn Piece>,
+  held : Option<PlayerRef>,
+}
+
+#[derive(Debug)]
+pub struct GameState {
+  gen : Counter,
+  data : GameStateData,
+  clients,
+}
+
+
+#[derive(Debug)]
+pub struct GameStateData {
+  pub pieces : Vec<PieceRecord>,
+  pub players : Vec<PlayerRecord>,
+}
+
+impl Deref for GameState {
+  type Output = GamStateData;
+  fn deref(&self) -> &GamStateData { &self.data }
+}
+
+impl GameState {
+  fn as_ref(&self) -> (&usize, &GameStateData) { (&self.gen, &self.data) }
+  fn gen(&self) -> usize { self.gen }
+}
+
+
+
+#[derive(Serialize)]
+enum MsgUpdate {
+  InsertPiece(usize, MsgPiece),
+  DeletePiece(usize),
+  UpdatePiece(usize, MsgPiece),
+}
+
+struct DataGuard<'gs> {
+  gs : &'gs mut GameState,
+  msg : MsgUpdate,
+}
+impl<'gs> Deref for DataGuard<'gs> {
+  type Output = GameState;
+  fn deref(&self) -> GameState<'gs> { self.gs }
+}
+impl<'gs> DerefMut for DataGuard<'gs> {
+  fn deref_mut(&mut self) -> GameState<'gs> { self.gs }
+}
+
+impl GameState {
+  fn update(&mut self, msg : MsgUpdate) -> DataGuard<'_> {
+    DataGuard { gs : self, msg }
+  }
+}
+
+impl Drop for DataGuard {
+  
+}
diff --git a/src/pieces.rs b/src/pieces.rs
new file mode 100644 (file)
index 0000000..6454ae1
--- /dev/null
@@ -0,0 +1,9 @@
+
+struct Disc {
+  colours : [Colour],
+  size : Coord,
+}
+
+impl Piece for Disc {
+}
+