void SendSoundEvent(ViewServer sender, Vector3 pos, float radius) { if (sender == null) { return; } var p = WorldToBitmap(pos); var data = new Viewer.WorldEventSound(); data.x = p.x; data.y = p.y; // FIXME: This is only remapped in one direction. var worldSize = Utils.Distance(_worldMins.x, _worldMaxs.x); var rescaled = (radius / worldSize) * 512.0f; data.distance = (int)rescaled; Logger.Info("Distance {0}, Scaled: {1}", radius, data.distance); sender.Broadcast(Viewer.DataType.WorldEventSound, data); }
public void BroadcastMapData() { if (!_server.HasClients()) { return; } var now = DateTime.Now; if (now < _nextBroadcast) { return; } // Broadcast only with 20hz. _nextBroadcast = now.AddMilliseconds(1.0f / 20.0f); try { Viewer.MapData data = new Viewer.MapData(); data.w = 512; data.h = 512; data.mapW = Utils.Distance(_worldMins.x, _worldMaxs.x); data.mapH = Utils.Distance(_worldMins.z, _worldMaxs.z); data.density = _config.PopulationDensity; data.zombieSpeed = _worldState.GetZombieSpeed(); data.timescale = _timeScale; lock (_lock) { data.inactive = new List <Viewer.DataZombie>(); var inactive = _inactiveZombies; for (int i = 0; i < inactive.Count; i++) { var zombie = inactive[i]; Vector2i p = WorldToBitmap(zombie.pos); data.inactive.Add(new Viewer.DataZombie { id = zombie.id, x = p.x, y = p.y, }); } data.active = new List <Viewer.DataZombie>(); var active = _activeZombies; for (int i = 0; i < active.Count; i++) { var zombie = active[i]; Vector2i p = WorldToBitmap(zombie.pos); data.active.Add(new Viewer.DataZombie { id = zombie.id, x = p.x, y = p.y, }); } data.playerZones = _playerZones.GetSerializable(this); data.poiZones = _pois.GetSerializable(this); data.worldZones = _worldZones.GetSerializable(this); } _server.Broadcast(Viewer.DataType.MapData, data); } catch (Exception ex) { Log.Exception(ex); } }