fix(go): repair migration wire contracts and runtime lifecycle; document incomplete port
This commit is contained in:
1 parent
e43a310617
commit
32e47014b5
35 files changed
+16826
-438
No files matched your search
@@ -30,6 +30,7 @@ type RoadNetworkData struct {
|
||||
}
|
||||
|
||||
type CityTrafficEngine struct {
|
||||
wg sync.WaitGroup
|
||||
mu sync.RWMutex
|
||||
vehicles map[uint64]*TrafficVehicle
|
||||
lanes []RoadLane
|
||||
@@ -97,23 +98,29 @@ func (te *CityTrafficEngine) Start(ctx context.Context) {
|
||||
LaneLength: lane.Length,
|
||||
}
|
||||
}
|
||||
count := len(te.vehicles)
|
||||
te.wg.Add(1)
|
||||
te.mu.Unlock()
|
||||
|
||||
log.Printf("[TRAFFIC] CityTrafficEngine started with %d simulated AI vehicles", len(te.vehicles))
|
||||
log.Printf("[TRAFFIC] CityTrafficEngine started with %d simulated AI vehicles", count)
|
||||
go te.runLoop(ctx)
|
||||
}
|
||||
|
||||
func (te *CityTrafficEngine) Stop() {
|
||||
te.mu.Lock()
|
||||
defer te.mu.Unlock()
|
||||
if te.cancel != nil {
|
||||
te.cancel()
|
||||
}
|
||||
te.isRunning = false
|
||||
te.mu.Unlock()
|
||||
te.wg.Wait()
|
||||
te.mu.Lock()
|
||||
te.vehicles = make(map[uint64]*TrafficVehicle)
|
||||
te.mu.Unlock()
|
||||
}
|
||||
|
||||
func (te *CityTrafficEngine) runLoop(ctx context.Context) {
|
||||
defer te.wg.Done()
|
||||
ticker := time.NewTicker(150 * time.Millisecond) // ~6.7 Hz downsampled traffic lane updates
|
||||
defer ticker.Stop()
|
||||
|
||||
@@ -151,6 +158,9 @@ func (te *CityTrafficEngine) tick(dt float32) {
|
||||
methodID := protocol.MethodGetMethodIDDefault("SyncAetherAIVehicleLaneDatas", 68582850)
|
||||
sessions := te.server.GetActiveSessions()
|
||||
for _, sess := range sessions {
|
||||
if !sess.ready.Load() || sess.hangup.Load() {
|
||||
continue
|
||||
}
|
||||
_ = sess.NotifyData(methodID, payload)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user