//- 创建子弹 // // @param id 子弹id // @param dest 由谁发出来的子弹 // @param src 由谁发出来的子弹 // @param poShootStartPosition 子弹生成的位置 // @param poShootEndPosition 子弹要到达的位置 // @return none public void createBullet(LiveObject src, LiveObject dest, FixVector3 poShootStartPosition, FixVector3 poShootEndPosition) { BaseBullet bullet = null; //直射子弹 bullet = new DirectionShootBullet(); //根据名字加载资源 bullet.createBody(m_scBulletName); bullet.initData(src, dest, poShootStartPosition, poShootEndPosition); bullet.shoot(); if (null != bullet) { //刷新显示位置 bullet.updateRenderPosition(0); //立即记录最后的位置,否则通过vector3.lerp来进行移动动画时会出现画面抖动的bug bullet.recordLastPos(); //加入子弹列表 GameData.g_listBullet.Add(bullet); } }
public override void BeContact(LiveObject ContactObj) { Speed = 0; rotation = 0.44f; isBomb = true; base.BeContact(ContactObj); }
//添加正在攻击我的对象 //用于在死亡时通知对应对象 public void addAttackMeObj(LiveObject obj) { if (m_listAttackMe.Contains(obj)) { return; } m_listAttackMe.Add(obj); }
//- 初始化数据 // // @param src 发射源 // @param dest 射击目标 // @param poOri 发射的起始位置 // @param poDst 发射的目标位置 // @return none. public override void initData(LiveObject src, LiveObject dest, FixVector3 poOri, FixVector3 poDst) { base.initData(src, dest, poOri, poDst); Fix64 distance = FixVector3.Distance(poOri, poDst); m_fixMoveTime = distance / m_fixSpeed; }
public void VehicleMoveHandler(LiveObject lo, Rectangle prev) { //LibSys.StatusBar.Trace("IP: LayerVehicles:VehicleMoveHandler() veh=" + lo); lo.init(true); // provoke PutOnMap in Paint() prev.Inflate(1, 1); // it is likely that move is not too far, so do one bigger invalidate - save drawing time: PictureManager.Invalidate(Rectangle.Union(prev, lo.BoundingRect)); //PictureManager.Invalidate(lo.BoundingRect); //PictureManager.Invalidate(prev); }
//- 添加我正在攻击的对象 // 用于在死亡时通知对应对象 // @param obj 要攻击的对象 // @return none public void addAttackingObj(LiveObject obj) { //判断是否已经添加过 if (m_listAttackingList.Contains(obj)) { return; } //插入队列 m_listAttackingList.Add(obj); }
public virtual int countIntersections(IObjectsLayoutManager iOlm, LiveObject lo, Rectangle rect) { if (iOlm != null) { return(iOlm.countIntersections(lo, rect)); } else { return(0); } }
private void StopLiveItemExecute(object obj) { if (!CanStopLiveItem(obj)) { return; } if (LiveObject.RunningStatus == RunningStatus.Running) { LiveObject.Stop(); } }
internal void GetNextObject(ulong startId, ulong endId, out LiveObject o) { ulong id = FindObjectForward(startId, endId); o.id = id; id >>= alignShift; uint i = (uint)(id >> firstLevelShift); uint j = (uint)(id & secondLevelMask); ushort[] secondLevelTable = null; if (i < firstLevelTable.Length) { secondLevelTable = firstLevelTable[i]; } if (secondLevelTable != null) { ushort u1 = secondLevelTable[j]; if ((u1 & 0x8000) != 0) { j++; if (j >= secondLevelLength) { j = 0; i++; secondLevelTable = firstLevelTable[i]; } ushort u2 = secondLevelTable[j]; j++; if (j >= secondLevelLength) { j = 0; i++; secondLevelTable = firstLevelTable[i]; } ushort u3 = secondLevelTable[j]; o.allocTickIndex = (u2 >> 7) + (u3 << 8); o.typeSizeStacktraceIndex = (u1 & 0x7fff) + ((u2 & 0x7f) << 15); int[] stacktrace = readNewLog.stacktraceTable.IndexToStacktrace(o.typeSizeStacktraceIndex); o.typeIndex = stacktrace[0]; o.size = (uint)stacktrace[1]; return; } } o.size = 0; o.allocTickIndex = o.typeIndex = o.typeSizeStacktraceIndex = 0; }
/// <summary> /// 初始化数据 /// </summary> /// <param name="src">发射源</param> /// <param name="dest">射击目标</param> /// <param name="poSrc">发射的起始位置</param> /// <param name="poDst">发射的目标位置</param> public virtual void initData(LiveObject src, LiveObject dest, FixVector3 poSrc, FixVector3 poDst) { m_scType = "bullet"; loadProperties(); m_src = src; m_dest = dest; m_fixv3SrcPos = poSrc; m_fixv3DestPos = poDst; m_fixDamage = m_src.getDamageValue(); }
// actually counts intesections' total surface in pixels: public int countIntersections(LiveObject llo, Rectangle r) { int total = 0; try { foreach (LiveObject lo in WaypointsCache.WaypointsAll) { if (llo != lo) // self don't count { Rectangle sr = lo.intersectionSensitiveRect(); sr.Intersect(r); total += (sr.Width * sr.Height); sr = lo.intersectionSensitiveRect2(); sr.Intersect(r); total += (sr.Width * sr.Height / 2); // count only part of it, less important } } foreach (Track trk in WaypointsCache.TracksAll) { if (trk.Enabled) { for (int i = 0; i < trk.TrackpointsNamed.Count; i++) { Waypoint wpt = (Waypoint)trk.TrackpointsNamed[i]; bool hasContent = wpt.hasContent; bool hasUrl = wpt.Url.Length > 0; bool isPhoto = wpt.ThumbImage != null; if ((i == 0 || i == trk.Trackpoints.Count - 1 || hasContent || hasUrl || isPhoto) && llo != wpt) { Rectangle sr = wpt.intersectionSensitiveRect(); sr.Intersect(r); total += (sr.Width * sr.Height); sr = wpt.intersectionSensitiveRect2(); sr.Intersect(r); total += (sr.Width * sr.Height / 2); // count only part of it, less important } } } } //LibSys.StatusBar.Trace("Intersection total=" + total + " at pos " + llo.LabelPosition); } catch (Exception e) { LibSys.StatusBar.Error("LW:countIntersections " + e.Message); } return(total); }
//- 初始化数据 // // @param src 发射源 // @param dest 射击目标 // @param poOri 发射的起始位置 // @param poDst 发射的目标位置 // @return none. virtual public void initData(LiveObject src1, LiveObject dest1, FixVector3 poOri, FixVector3 poDst) { m_scType = "bullet"; loadProperties(); m_src = src1; m_dest = dest1; m_fixv3SrcPosition = poOri; m_fixv3DestPosition = poDst; m_fixDamage = m_src.getDamageValue(); m_dest.addAttackMeBulletObj(this); }
public override void BeContact(LiveObject ContactObj) { if (ContactObj is BBullet) { this.HP -= ((BBullet)ContactObj).Att; } if (ContactObj is BMissile) { this.HP -= ((BMissile)ContactObj).Att; } if (ContactObj is BBomb) { this.HP -= ((BBomb)ContactObj).Att; } }
public void Tile_Paint2(object sender, PaintEventArgs e) { //LibSys.StatusBar.Trace("Tile_Paint2(): " + m_baseName + " painting to " + e.ClipRectangle); try { //LibSys.StatusBar.Trace("Tile_Paint2(): tileFeatures=" + m_tileFeatures); if (m_tileFeatures != null && !m_tileFeatures.IsEmpty && m_tileFeatures.Count > 0) { if (!m_tileFeatures.HasPutOnMap) { //LibSys.StatusBar.Trace("Tile_Paint2(): " + m_baseName + " calling features.PutOnMap()"); m_tileFeatures.PutOnMap(m_tileSet, this, this); } // we need to paint backwards, so that important cities are painted last: int i = m_tileFeatures.Count - 1; Type cityType = City.city.GetType(); for ( ; i >= 0; i--) { LiveObject lo = (LiveObject)m_tileFeatures.List[i]; try { if (Project.drawCities || !lo.GetType().Equals(cityType)) { Point pixelPos = m_tileSet.toPixelLocation(lo.Location, this); Rectangle adjustedBoundingRect = lo.BoundingRect; adjustedBoundingRect.Offset(m_offset); if (e.ClipRectangle.IntersectsWith(adjustedBoundingRect)) { lo.Paint(e.Graphics, m_tileSet, this); } } } catch (Exception ee) { LibSys.StatusBar.Error("Tile:Tile_Paint2(): lo=" + lo + " " + ee); } } } } catch (Exception eee) { LibSys.StatusBar.Error("Tile:Tile_Paint(): " + m_baseName + " " + eee); } }
internal int GenerationOfObject(ref LiveObject o) { int generation = intervalTable.GenerationOfObject(o.id); if (generation < 0) { generation = 0; if (o.allocTickIndex <= gen2LimitTickIndex) { generation = 2; } else if (o.allocTickIndex <= gen1LimitTickIndex) { generation = 1; } } return(generation); }
private void StartLiveItemExecute(object obj) { if (!CanStartLiveItem(obj)) { return; } if (LiveObject.RunningStatus == RunningStatus.Stopped) { StartDependencyImpact impact = StartDependencyImpact.Unknown; if (obj != null && obj is StartDependencyImpact) { impact = (StartDependencyImpact)obj; } LiveObject.Start(impact); } }
public override void BeContact(LiveObject ContactObj) { DebugScene.Instance.WriteLine("a12s", "Spaceship Contact!"); if (ContactObj is BBullet) { this.HP -= ((BBullet)ContactObj).Att; } if (ContactObj is BMissile) { this.HP -= ((BMissile)ContactObj).Att; } if (ContactObj is BBomb) { this.HP -= ((BBomb)ContactObj).Att; } base.BeContact(ContactObj); }
public void Tile_Paint2Print(Graphics graphics) { //LibSys.StatusBar.Trace("Tile_Paint2Print(): " + m_baseName + " painting to " + ppe.ClipRectangle); int offsetSave = m_offset.X; m_offset.X = 0; // we use direct method of calculating print surface location, world offset does not apply. try { //LibSys.StatusBar.Trace("Tile_Paint2Print(): tileFeatures=" + m_tileFeatures); if (m_tileFeatures != null && !m_tileFeatures.IsEmpty && m_tileFeatures.Count > 0) { // we need to paint backwards, so that important cities are painted last: int i = m_tileFeatures.Count - 1; Type cityType = City.city.GetType(); for ( ; i >= 0; i--) { LiveObject lo = (LiveObject)m_tileFeatures.List[i]; try { if (Project.drawCities || !lo.GetType().Equals(cityType)) { Point pixelPosPrint = m_tileSet.toPixelLocationPrint(lo.Location, this); Point pixelPosDispl = lo.PixelLocation; int offsetX = pixelPosPrint.X - pixelPosDispl.X; int offsetY = pixelPosPrint.Y - pixelPosDispl.Y; lo.Paint(graphics, m_tileSet, this, offsetX, offsetY); } } catch (Exception ee) { LibSys.StatusBar.Error("Tile:Tile_Paint2Print(): lo=" + lo + " " + ee); } } } } catch (Exception eee) { LibSys.StatusBar.Error("Tile:Tile_Paint2Print(): " + m_baseName + " " + eee); } m_offset.X = offsetSave; }
// actually counts intesections' total surface in pixels: public int countIntersections(LiveObject llo, Rectangle r) { int total = 0; foreach (LiveObject lo in EarthquakesCache.EarthquakesAll) { if (llo != lo) // self don't count { Rectangle sr = lo.intersectionSensitiveRect(); sr.Intersect(r); total += (sr.Width * sr.Height); sr = lo.intersectionSensitiveRect2(); sr.Intersect(r); total += (sr.Width * sr.Height / 2); // count only part of it, less important } } //LibSys.StatusBar.Trace("Intersection total=" + total + " at pos " + llo.LabelPosition); return(total); }
void ServerThread() { Debug.Log("Starting server thread"); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPAddress ip = IPAddress.Parse("192.168.1.44"); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.44"), 0); IPEndPoint send_ipEndPoint = new IPEndPoint(ip, BLACK_BOX_SERVER_PORT); try { socket.Bind(ipEndPoint); } catch (SocketException e) { Debug.Log("Error binding socket: " + e.ToString()); sendingPackets = false; } while (sendingPackets) { update = new update_protocol_v3.Update(); update.label = "neuron"; update.mod_version = lastLoadedFrame; update.lhs_frame = false; lastLoadedFrame++; foreach (KeyValuePair <string, LiveObjectStorage> entry in liveObjects) { LiveObject o = entry.Value.ToLiveObject(); update.live_objects.Add(o); } using (MemoryStream stream = new MemoryStream()) { Serializer.Serialize <Update>(stream, update); packetBytes = stream.GetBuffer(); socket.SendTo(packetBytes, send_ipEndPoint); } if (!sendingPackets) { socket.Close(); break; } } }
/// <summary> /// 初始化数据 /// </summary> /// <param name="src">发射源</param> /// <param name="dest">射击目标</param> /// <param name="poSrc">发射的起始位置</param> /// <param name="poDst">发射的目标位置</param> public void createBullet(LiveObject src, LiveObject dest, FixVector3 poSrc, FixVector3 poDst) { BaseBullet bullet = null; //直射子弹 bullet = new DirectionShootBullet(); bullet.initData(src, dest, poSrc, poDst); bullet.createBody(m_scBulletName); bullet.shoot(); if (bullet != null) { //刷新显示位置 bullet.updateRenderPosition(0); //立即记录最后的位置,否则通过Vector3.lerp来进行移动动画是会出现画面抖动的bug bullet.recordLastPos(); //加入子弹列表 GameData.g_listBullet.Add(bullet); } }
//- 发送死亡信息给相关对象 // // @return none public void sendDeadInfoToRelativeObj() { //print("name . ", name) //print("#attackMeList . ", #attackMeList) //让所有攻击我的子弹失效 for (int i = m_listAttackMeBullet.Count - 1; i >= 0; i--) { m_listAttackMeBullet[i].uneffect = true; removeAttackMeBulletObj(m_listAttackMeBullet[i]); } //通知我正在攻击的对象,我已经死了,从我正在攻击的对象身上把自身移除 for (int i = m_listAttackingList.Count - 1; i >= 0; i--) { LiveObject obj = m_listAttackingList[i]; obj.removeAttackMeObj(this); removeAttackingObj(obj); } //通知正在攻击我的对象,我已经死了,别打了 for (int i = m_listAttackMe.Count - 1; i >= 0; i--) { LiveObject obj = m_listAttackMe[i]; obj.removeAttackingObj(this); removeAttackMeObj(obj); if (obj.m_scType == "tower") { //print("current state . ", obj.getState()) if (obj.getState() != "cooling") { obj.changeState("towerstand"); } else { obj.setPrevStateName("towerstand"); } } } }
public LiveObject EvalMouseClick(Point clickPoint, GeoCoord mouseGeoLocation, bool controlDown, bool shiftDown, bool altDown) { try { foreach (Layer layer in this) { if (layer.Enabled) { LiveObject lo = layer.EvalMouseClick(clickPoint, mouseGeoLocation, controlDown, shiftDown, altDown); if (lo != null) { return(lo); } } } } catch (Exception eee) { LibSys.StatusBar.Error("LM:EvalMouseClick(): " + eee.Message); } return(null); }
public LiveObject ToLiveObject() { LiveObject o = new LiveObject(); o.label = this.label; o.x = position.x; o.y = position.y; o.z = position.z; o.qx = rotation.x; o.qy = rotation.y; o.qz = rotation.z; o.qw = rotation.w; o.button_bits = bits; if (!string.IsNullOrEmpty(blob)) { o.extra_data = blob; } return(o); }
/// <summary> /// 创建时,进入的初始化函数 /// </summary> /// <param name="args">附加的创建信息</param> public virtual void onInit(LiveObject args) { }
public override int countIntersections(IObjectsLayoutManager olm, LiveObject lo, Rectangle rect) { return(olm.countIntersections(lo, rect)); }
public void Send() { //Debug.Log("Attempting to open send thread with ip/port: " + ip.ToString() + " " + port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); socket.SendTimeout = 1000; IPEndPoint ipEndPoint = new IPEndPoint(ip, 0); //string sendingIP = "192.168.1.44"; string sendingIP = address; IPEndPoint send_ipEndPoint = new IPEndPoint(IPAddress.Parse(sendingIP), port); try { socket.Bind(ipEndPoint); } catch (SocketException e) { Debug.LogWarning("Error binding socket: " + ip.ToString() + " " + port + " " + e.ToString()); isRunning = false; } //Checks if sending ip is local. If not, then we'll ping //the server for a unicast stream if (!sendingIP.StartsWith("192.")) { update = new update_protocol_v3.Update(); update.label = "ping"; update.mod_version = 0; update.lhs_frame = false; using (MemoryStream stream = new MemoryStream()) { Serializer.Serialize <Update> (stream, update); packetBytes = stream.ToArray(); socket.SendTo(packetBytes, send_ipEndPoint); } } while (isRunning) { System.Threading.Thread.Sleep(10); if (managedObjects.Values.Count == 0) { continue; } lock (lockObject) { update = new update_protocol_v3.Update(); update.label = "SendData"; update.mod_version = lastLoadedFrame; update.lhs_frame = false; lastLoadedFrame++; foreach (KeyValuePair <string, HolojamObject> entry in managedObjects) { LiveObject o = entry.Value.ToLiveObject(); update.live_objects.Add(o); } using (MemoryStream stream = new MemoryStream()) { packetCount++; Serializer.Serialize <Update>(stream, update); packetBytes = stream.ToArray(); socket.SendTo(packetBytes, send_ipEndPoint); } } if (!isRunning) { socket.Close(); break; } } }
public void Receive() { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); socket.Bind(new IPEndPoint(IPAddress.Any, port)); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(address))); socket.ReceiveTimeout = 1000; int nBytesReceived = 0; while (isRunning) { nBytesReceived = socket.Receive(currentPacket.bytes); currentPacket.stream.Position = 0; update = Serializer.Deserialize <update_protocol_v3.Update>( new MemoryStream(currentPacket.bytes, 0, nBytesReceived) ); //currentPacket.frame = update.mod_version; //if(currentPacket.frame>previousPacket.frame){ packetCount++; previousPacket.stream.Position = 0; currentPacket.stream.Position = 0; tempPacket.copyFrom(previousPacket); previousPacket.copyFrom(currentPacket); currentPacket.copyFrom(tempPacket); lock (lockObject) { //managedObjects.Clear(); for (int j = 0; j < update.live_objects.Count; j++) { LiveObject or = update.live_objects[j]; string label = or.label; objectTimers[label] = 0; //Reset timer--we received data for this object HolojamObject ho; //Reform managedObjects every frame. //Inefficient for now, but will allow us to determine //if an object is registered. ho = new HolojamObject(label); managedObjects[label] = ho; if (update.lhs_frame) { ho.position = new Vector3(-(float)or.x, (float)or.y, (float)or.z); ho.rotation = new Quaternion(-(float)or.qx, (float)or.qy, (float)or.qz, -(float)or.qw); } else { ho.position = new Vector3((float)or.x, (float)or.y, (float)or.z); ho.rotation = new Quaternion((float)or.qx, (float)or.qy, (float)or.qz, (float)or.qw); } ho.bits = or.button_bits; //Get blob if it's there. Inefficient ho.blob = or.extra_data; ho.isTracked = or.is_tracked; } } if (!isRunning) { socket.Close(); break; } } }
internal void GetNextObject(ulong startId, ulong endId, out LiveObject o) { ulong id = FindObjectForward(startId, endId); o.id = id; id >>= alignShift; uint i = (uint)(id >> firstLevelShift); uint j = (uint)(id & secondLevelMask); ushort[] secondLevelTable = null; if (i < firstLevelTable.Length) secondLevelTable = firstLevelTable[i]; if (secondLevelTable != null) { ushort u1 = secondLevelTable[j]; if ((u1 & 0x8000) != 0) { j++; if (j >= secondLevelLength) { j = 0; i++; secondLevelTable = firstLevelTable[i]; } ushort u2 = secondLevelTable[j]; j++; if (j >= secondLevelLength) { j = 0; i++; secondLevelTable = firstLevelTable[i]; } ushort u3 = secondLevelTable[j]; o.allocTickIndex = (u2 >> 7) + (u3 << 8); o.typeSizeStacktraceIndex = (u1 & 0x7fff) + ((u2 & 0x7f) << 15); int[] stacktrace = readNewLog.stacktraceTable.IndexToStacktrace(o.typeSizeStacktraceIndex); o.typeIndex = stacktrace[0]; o.size = (uint)stacktrace[1]; return; } } o.size = 0; o.allocTickIndex = o.typeIndex = o.typeSizeStacktraceIndex = 0; }
internal int GenerationOfObject(ref LiveObject o) { int generation = intervalTable.GenerationOfObject(o.id); if (generation < 0) { generation = 0; if (o.allocTickIndex <= gen2LimitTickIndex) generation = 2; else if (o.allocTickIndex <= gen1LimitTickIndex) generation = 1; } return generation; }
// This thread handles incoming NatNet packets. private void ThreadRun() { stopReceive = false; Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); ipEndPoint = new IPEndPoint(IPAddress.Any, BLACK_BOX_CLIENT_PORT); //Debug.Log("prebind"); socket.Bind(ipEndPoint); //Debug.Log("bind"); MulticastOption mo = new MulticastOption(IPAddress.Parse("224.1.1.1")); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mo); nBytesReceived = 0; lastLoadedBuffer = b1; lastLoadedBufferMS = b1ms; lastLoadedFrame = 0; byte[] newPacketBuffer = b2; MemoryStream newPacketBufferMS = b2ms; long newPacketFrame = 0; byte[] tempBuffer; MemoryStream tempBufferMS; while (true) { //Debug.Log("preRECV"); nBytesReceived = socket.Receive(newPacketBuffer); //Debug.Log("RECV"); nPackets++; newPacketBufferMS.Position = 0; //Debug.Log ("Deserializing data..."); update_protocol_v3.Update update = Serializer.Deserialize <update_protocol_v3.Update>(new MemoryStream(newPacketBuffer, 0, nBytesReceived)); //Debug.Log ("Data deserialized. Received update of type " + update.label); newPacketFrame = update.mod_version; if (newPacketFrame > lastLoadedFrame) { // Swap the buffers and reset the positions. lastLoadedBufferMS.Position = 0; newPacketBufferMS.Position = 0; tempBuffer = lastLoadedBuffer; tempBufferMS = lastLoadedBufferMS; lastLoadedBuffer = newPacketBuffer; lastLoadedBufferMS = newPacketBufferMS; newPacketBuffer = tempBuffer; newPacketBufferMS = tempBufferMS; lastLoadedFrame = newPacketFrame; for (int j = 0; j < update.live_objects.Count; j++) { LiveObject or = update.live_objects[j]; string label = or.label; if (label == "marker") { Debug.Log("marker at " + or.x + ", " + or.y + ", " + or.z); } LiveObjectStorage ow; lock (lock_object) { if (!labelToLiveObject.TryGetValue(label, out ow)) { ow = new LiveObjectStorage(); labelToLiveObject[label] = ow; } else { ow = labelToLiveObject[label]; } if (update.lhs_frame) { ow.pos = new Vector3(-(float)or.x, (float)or.y, (float)or.z); ow.rot = new Quaternion(-(float)or.qx, (float)or.qy, (float)or.qz, -(float)or.qw); } else { ow.pos = new Vector3((float)or.x, (float)or.y, (float)or.z); ow.rot = new Quaternion((float)or.qx, (float)or.qy, (float)or.qz, (float)or.qw); } ow.button_bits = or.button_bits; } } } if (stopReceive) { break; } } }
public override void BeContact(LiveObject ContactObj) { this.HP = 0; base.BeContact(ContactObj); }