Skip to content

Commit d9f3d54

Browse files
committed
[feature] Increase the update rate of multicast network packets
1 parent 433c8a7 commit d9f3d54

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

internal/app/controller/controller.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controller
33
import (
44
"github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
55
"log"
6+
"time"
67
)
78

89
const configFileName = "config/ssl-game-controller.yaml"
@@ -52,15 +53,25 @@ func (c *GameController) Run() {
5253
c.ApiServer.PublishState(*c.Engine.State)
5354
c.ApiServer.PublishRefereeEvents(c.Engine.RefereeEvents)
5455

55-
go func() {
56-
defer c.historyPreserver.Close()
57-
for {
58-
c.timer.WaitTillNextFullSecond()
59-
c.Engine.Tick(c.timer.Delta())
60-
c.historyPreserver.Save(c.Engine.History)
61-
c.publish()
62-
}
63-
}()
56+
go c.publishApi()
57+
go c.publishNetwork()
58+
}
59+
60+
func (c *GameController) publishApi() {
61+
defer c.historyPreserver.Close()
62+
for {
63+
c.timer.WaitTillNextFullSecond()
64+
c.Engine.Tick(c.timer.Delta())
65+
c.historyPreserver.Save(c.Engine.History)
66+
c.publish()
67+
}
68+
}
69+
70+
func (c *GameController) publishNetwork() {
71+
for {
72+
c.timer.WaitTillNextFull(100 * time.Millisecond)
73+
c.Publisher.Publish(c.Engine.State)
74+
}
6475
}
6576

6677
func (c *GameController) OnNewEvent(event Event) {
@@ -97,5 +108,4 @@ func (c *GameController) publish() {
97108
}
98109

99110
c.ApiServer.PublishState(*c.Engine.State)
100-
c.Publisher.Publish(c.Engine.State)
101111
}

pkg/timer/timer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,10 @@ func (t *Timer) WaitTillNextFullSecond() {
107107
nextDuration := elapsed.Truncate(time.Second) + time.Second
108108
t.WaitTill(nextDuration)
109109
}
110+
111+
// WaitTillNextFull waits until the internal timer has reached the next full given duration
112+
func (t *Timer) WaitTillNextFull(d time.Duration) {
113+
elapsed := t.Elapsed()
114+
nextDuration := elapsed.Truncate(d) + d
115+
t.WaitTill(nextDuration)
116+
}

0 commit comments

Comments
 (0)