Skip to content

Commit ea04a8c

Browse files
committed
[feature] Allow to set current time via websocket interface
1 parent 163d077 commit ea04a8c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

internal/app/controller/engine.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
77
"github.com/pkg/errors"
88
"log"
9+
"math"
910
"math/rand"
1011
"strconv"
1112
"strings"
@@ -348,9 +349,12 @@ func (e *Engine) Process(event Event) error {
348349
if err != nil {
349350
return err
350351
}
351-
e.updateMaxBots()
352-
e.updateNextCommand()
353-
e.appendHistory()
352+
if event.Modify == nil || event.Modify.Timestamp == nil {
353+
// do not execute this for timestamp updates
354+
e.updateMaxBots()
355+
e.updateNextCommand()
356+
e.appendHistory()
357+
}
354358
return nil
355359
}
356360

@@ -458,12 +462,21 @@ func (e *Engine) processModify(m *EventModifyValue) error {
458462
return errors.Errorf("Game event id %d is too large.", i)
459463
}
460464
e.State.GameEvents = append(e.State.GameEvents[:i], e.State.GameEvents[i+1:]...)
465+
} else if m.Timestamp != nil {
466+
e.TimeProvider = timer.NewFixedTimeProviderFromNanoSeconds(*m.Timestamp)
467+
if math.Abs(e.TimeProvider().Sub(e.LastTimeUpdate).Seconds()) > 1 {
468+
// reset last time update - it might be in another time range
469+
e.LastTimeUpdate = e.TimeProvider()
470+
}
461471
} else if err := e.processTeamModify(m); err != nil {
462472
return err
463473
}
464474

465-
e.LogModify(*m)
466-
log.Printf("Processed %v", m)
475+
if m.Timestamp == nil {
476+
// do not log timestamp modification - it will be send very often, if sent
477+
e.LogModify(*m)
478+
log.Printf("Processed %v", m)
479+
}
467480
return nil
468481
}
469482

internal/app/controller/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type EventModifyValue struct {
122122
GameEventBehavior *EventModifyGameEventBehavior `json:"gameEventBehavior,omitempty" yaml:"gameEventBehavior"`
123123
BotSubstitutionIntend *bool `json:"botSubstitutionIntend,omitempty" yaml:"botSubstitutionIntend"`
124124
RemoveGameEvent *int `json:"removeGameEvent,omitempty" yaml:"removeGameEvent"`
125+
Timestamp *int64 `json:"timestamp,omitempty" yaml:"timestamp"`
125126
}
126127

127128
func (m EventModifyValue) String() string {

0 commit comments

Comments
 (0)