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
3
3
import (
4
4
"github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
5
5
"log"
6
+ "time"
6
7
)
7
8
8
9
const configFileName = "config/ssl-game-controller.yaml"
@@ -52,15 +53,25 @@ func (c *GameController) Run() {
52
53
c .ApiServer .PublishState (* c .Engine .State )
53
54
c .ApiServer .PublishRefereeEvents (c .Engine .RefereeEvents )
54
55
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
+ }
64
75
}
65
76
66
77
func (c * GameController ) OnNewEvent (event Event ) {
@@ -97,5 +108,4 @@ func (c *GameController) publish() {
97
108
}
98
109
99
110
c .ApiServer .PublishState (* c .Engine .State )
100
- c .Publisher .Publish (c .Engine .State )
101
111
}
Original file line number Diff line number Diff line change @@ -107,3 +107,10 @@ func (t *Timer) WaitTillNextFullSecond() {
107
107
nextDuration := elapsed .Truncate (time .Second ) + time .Second
108
108
t .WaitTill (nextDuration )
109
109
}
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