@@ -50,10 +50,10 @@ func (g *Game) Run() {
5050 g .handleCommand (cmd .Origin , cmd .Cmd )
5151 }
5252 g .update (deltaTime )
53- time .Sleep (targetFrameTime - time .Now ().Sub (frameStart ))
53+ time .Sleep (targetFrameTime - time .Since (frameStart ))
54+ deltaTime = time .Since (frameStart )
5455
55- deltaTime = time .Now ().Sub (frameStart )
56- // waited for countdown
56+ // correct time after waiting for countdown
5757 if deltaTime >= 5 * time .Second {
5858 deltaTime = targetFrameTime
5959 }
@@ -204,6 +204,10 @@ func (g *Game) update(delta time.Duration) {
204204 Hovercrafts : g .hovercrafts ,
205205 Time : time .Now ().UnixMilli (),
206206 })
207+
208+ if g .running && g .config .Timeout > 0 && time .Since (g .startTime ) > time .Duration (g .config .Timeout )* time .Second {
209+ g .finish ()
210+ }
207211}
208212
209213func (g * Game ) handleCommand (origin * cg.Player , cmd cg.Command ) {
@@ -320,6 +324,17 @@ func (g *Game) positionHovercrafts() {
320324}
321325
322326func (g * Game ) finish () {
327+ unfinishedPlayers := make ([]string , 0 )
328+ for _ , p := range g .players {
329+ if ! p .finished {
330+ unfinishedPlayers = append (unfinishedPlayers , p .id )
331+ }
332+ p .finished = true
333+ }
334+ g .cg .Send (RaceOverEvent , RaceOverEventData {
335+ FinishedPlayers : g .finishedPlayers ,
336+ UnfinishedPlayers : unfinishedPlayers ,
337+ })
323338 g .running = false
324339 g .checkpoints = g .checkpoints [:0 ]
325340}
0 commit comments