Bowarc / chess_game

A multiplayer chess game made with ggez
1 stars 1 forks source link

State machine design #27

Closed Bowarc closed 12 months ago

Bowarc commented 1 year ago

Using enum_dispatch for the state machine could be really good instead of having a function per state like currently

Each state would have to impl a state machine trait that would have

A update function

fn update(mut self, state_ref: &mut State)

The state ref would be the dummy state set by std::mem::replace like currently to be able to switch state with non copy objects

Or the update function could return a state that would be the next one..

Should try both cases

Obviously the goal of the change is to be able to have multiple function, like a draw one could be specifically useful

Bowarc commented 1 year ago

https://github.com/Bowarc/chess_game/blob/main/client/src/game/mod.rs#L62

Isnt that inefficient?

I mean allocating a new variable every frame with potentially big sizes ?

We could use a buffer like self.dummy that we would yse for the mem::replace

Bowarc commented 1 year ago

https://github.com/Bowarc/chess_game/blob/main/client/src/game/mod.rs#L62

Isnt that inefficient?

I mean allocating a new variable every frame with potentially big sizes ?

We could use a buffer like self.dummy that we would yse for the mem::replace

We're only copying the pointer to that large data, so it's not inefficient, i think ?