add auto_state_update client & server
This commit is contained in:
parent
461d648ac9
commit
1850c5459d
4 changed files with 55 additions and 8 deletions
|
|
@ -105,7 +105,9 @@ let kb_handler ev =
|
|||
in
|
||||
Queue.add act input_queue
|
||||
|
||||
let rec game_loop state _timestamp =
|
||||
let last_auto_state_update = ref 0.
|
||||
|
||||
let rec game_loop state timestamp =
|
||||
draw state;
|
||||
let new_state =
|
||||
(* TODO repesct order of action *)
|
||||
|
|
@ -116,7 +118,16 @@ let rec game_loop state _timestamp =
|
|||
(* send input action to server *)
|
||||
Queue.iter (send_action state) input_queue;
|
||||
Queue.clear input_queue;
|
||||
state
|
||||
|
||||
(* auto_update *)
|
||||
if
|
||||
timestamp -. !last_auto_state_update
|
||||
>= float_of_int @@ (State.auto_state_update_rate * 1000)
|
||||
then (
|
||||
Format.printf "MANA: %d@." state.mana;
|
||||
last_auto_state_update := timestamp;
|
||||
State.auto_update state )
|
||||
else state
|
||||
in
|
||||
G.request_animation_frame (game_loop new_state)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue