File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed
Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package controller
33import (
44 "github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
55 "log"
6+ "time"
67)
78
89const 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
6677func (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}
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments